/**
* C-Nery - A home automation web application for C-Bus.
* Copyright (C) 2008,2009,2012 Dave Oxley <dave@daveoxley.co.uk>.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.daveoxley.cnery.entities;
import com.daveoxley.cnery.constraints.FieldsNotEqual;
import com.daveoxley.cnery.constraints.TimeNotChildOfOr;
import java.io.Serializable;
import java.util.Collection;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.jboss.seam.annotations.Name;
/**
*
* @author Dave Oxley <dave@daveoxley.co.uk>
*/
@Entity
@Name("sceneConditionEntity")
@Table(name="scene_condition")
@FieldsNotEqual(first = "scene", second = "dependScene", message = "{cnery.condition_dependant_on_self_scene}")
@TimeNotChildOfOr
public class SceneCondition extends AbstractCondition<SceneCondition> implements ConditionProvider<SceneCondition>, Serializable {
public enum Action {
ALLOW("cn.enum.SceneCondition.Action.Allow"),
DISALLOW("cn.enum.SceneCondition.Action.Disallow");
private final String description;
Action(String description) {
this.description = description;
}
public String getDescription() {
return description;
}
};
private Scene scene;
private Action action;
private Set<SceneCondition> sceneConditions;
@ManyToOne
@JoinColumn(name="scene_id")
public Scene getScene() { return scene; }
public void setScene(Scene scene) { this.scene = scene; }
@Column(name="action")
@Enumerated(EnumType.STRING)
public Action getAction() { return action; }
public void setAction(Action action) { this.action = action; }
@OneToMany(mappedBy="parent",cascade = CascadeType.ALL)
public Set<SceneCondition> getSceneConditions() { return sceneConditions; }
public void setSceneConditions(Set<SceneCondition> sceneConditions) { this.sceneConditions = sceneConditions; }
@Override
@Transient
public Collection<SceneCondition> getConditions() {
return getSceneConditions();
}
}