package org.sigmah.server.domain.profile;
/*
* #%L
* Sigmah
* %%
* Copyright (C) 2010 - 2016 URD
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L%
*/
import java.util.List;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import org.sigmah.server.domain.OrgUnit;
import org.sigmah.server.domain.User;
import org.sigmah.server.domain.base.AbstractEntityId;
import org.sigmah.server.domain.util.EntityConstants;
/**
* <p>
* Organization Unit Profile domain entity.
* </p>
* <p>
* A profile which associates a user to an organizational unit.
* </p>
*
* @author Denis Colliot (dcolliot@ideia.fr)
*/
@Entity
@Table(name = EntityConstants.ORG_UNIT_PROFILE_TABLE)
public class OrgUnitProfile extends AbstractEntityId<Integer> {
/**
* Serial version UID.
*/
private static final long serialVersionUID = -6006586638356971306L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = EntityConstants.ORG_UNIT_PROFILE_COLUMN_ID)
@NotNull
private Integer id;
// --------------------------------------------------------------------------------
//
// FOREIGN KEYS.
//
// --------------------------------------------------------------------------------
@ManyToOne(optional = false, fetch = FetchType.LAZY)
@JoinColumn(name = EntityConstants.ORG_UNIT_PROFILE_COLUMN_USER, nullable = false)
@NotNull
private User user;
@ManyToOne(optional = false, fetch = FetchType.LAZY)
@JoinColumn(name = EntityConstants.ORG_UNIT_PROFILE_COLUMN_ORG_UNIT, nullable = false)
@NotNull
private OrgUnit orgUnit;
@ManyToMany(cascade = CascadeType.ALL)
@JoinTable(
name = EntityConstants.ORG_UNIT_PROFILE_PROFILE_LINK_TABLE,
joinColumns = @JoinColumn(name = EntityConstants.ORG_UNIT_PROFILE_COLUMN_ID),
inverseJoinColumns = @JoinColumn(name = EntityConstants.PROFILE_COLUMN_ID),
uniqueConstraints = @UniqueConstraint(columnNames = {
EntityConstants.ORG_UNIT_PROFILE_COLUMN_ID,
EntityConstants.PROFILE_COLUMN_ID
})
)
private List<Profile> profiles;
@Column(name = EntityConstants.ORG_UNIT_PROFILE_COLUMN_TYPE)
@Enumerated(value = EnumType.STRING)
private OrgUnitProfileType type;
public OrgUnitProfile() {
}
// --------------------------------------------------------------------------------
//
// METHODS.
//
// --------------------------------------------------------------------------------
// Add methods here.
// --------------------------------------------------------------------------------
//
// GETTERS & SETTERS.
//
// --------------------------------------------------------------------------------
@Override
public Integer getId() {
return id;
}
@Override
public void setId(Integer id) {
this.id = id;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public OrgUnit getOrgUnit() {
return orgUnit;
}
public void setOrgUnit(OrgUnit orgUnit) {
this.orgUnit = orgUnit;
}
public List<Profile> getProfiles() {
return profiles;
}
public void setProfiles(List<Profile> profiles) {
this.profiles = profiles;
}
public OrgUnitProfileType getType() {
return type;
}
public void setType(OrgUnitProfileType type) {
this.type = type;
}
public enum OrgUnitProfileType {
MAIN, SECONDARY
}
}