Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • DM/dm-docs
  • hammonds/dm-docs
  • hparraga/dm-docs
3 results
Show changes
Showing
with 2210 additions and 0 deletions
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package gov.anl.aps.dm.portal.model.entities;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
/**
*
* @author sveseli
*/
@Entity
@Table(name = "experiment_policy")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "ExperimentPolicy.findAll", query = "SELECT e FROM ExperimentPolicy e"),
@NamedQuery(name = "ExperimentPolicy.findById", query = "SELECT e FROM ExperimentPolicy e WHERE e.id = :id"),
@NamedQuery(name = "ExperimentPolicy.findByPolicyValue", query = "SELECT e FROM ExperimentPolicy e WHERE e.policyValue = :policyValue"),
@NamedQuery(name = "ExperimentPolicy.findByDescription", query = "SELECT e FROM ExperimentPolicy e WHERE e.description = :description")})
public class ExperimentPolicy extends CloneableEntity
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id")
private Integer id;
@Basic(optional = false)
@Size(min = 1, max = 2147483647)
@Column(name = "policy_value")
private String policyValue;
@Size(max = 2147483647)
@Column(name = "description")
private String description;
@JoinColumn(name = "policy_type_id", referencedColumnName = "id")
@ManyToOne(optional = false)
private PolicyType policyType;
@JoinColumn(name = "experiment_id", referencedColumnName = "id")
@ManyToOne(optional = false)
private Experiment experiment;
public ExperimentPolicy() {
}
public ExperimentPolicy(Integer id) {
this.id = id;
}
public ExperimentPolicy(Integer id, String value) {
this.id = id;
this.policyValue = value;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getPolicyValue() {
return policyValue;
}
public void setPolicyValue(String policyValue) {
this.policyValue = policyValue;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public PolicyType getPolicyType() {
return policyType;
}
public void setPolicyType(PolicyType policyType) {
this.policyType = policyType;
}
public Experiment getExperiment() {
return experiment;
}
public void setExperiment(Experiment experiment) {
this.experiment = experiment;
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof ExperimentPolicy)) {
return false;
}
ExperimentPolicy other = (ExperimentPolicy) object;
return (this.id != null || other.id == null) && (this.id == null || this.id.equals(other.id));
}
@Override
public String toString() {
return "gov.anl.aps.dm.portal.model.entities.ExperimentPolicy[ id=" + id + " ]";
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package gov.anl.aps.dm.portal.model.entities;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
/**
*
* @author sveseli
*/
@Entity
@Table(name = "experiment_type")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "ExperimentType.findAll", query = "SELECT e FROM ExperimentType e"),
@NamedQuery(name = "ExperimentType.findById", query = "SELECT e FROM ExperimentType e WHERE e.id = :id"),
@NamedQuery(name = "ExperimentType.findByName", query = "SELECT e FROM ExperimentType e WHERE e.name = :name"),
@NamedQuery(name = "ExperimentType.findByDescription", query = "SELECT e FROM ExperimentType e WHERE e.description = :description"),
@NamedQuery(name = "ExperimentType.findByRootDataPath", query = "SELECT e FROM ExperimentType e WHERE e.rootDataPath = :rootDataPath")})
public class ExperimentType extends CloneableEntity
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id")
private Integer id;
@Basic(optional = false)
@NotNull
@Size(max = 64)
@Column(name = "name")
private String name;
@Size(max = 2147483647)
@Column(name = "description")
private String description;
@Size(max = 2147483647)
@Column(name = "root_data_path")
private String rootDataPath;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "experimentType")
private List<Experiment> experimentList;
public ExperimentType() {
}
public ExperimentType(Integer id) {
this.id = id;
}
public ExperimentType(Integer id, String name) {
this.id = id;
this.name = name;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getRootDataPath() {
return rootDataPath;
}
public void setRootDataPath(String rootDataPath) {
this.rootDataPath = rootDataPath;
}
@XmlTransient
public List<Experiment> getExperimentList() {
return experimentList;
}
public void setExperimentList(List<Experiment> experimentList) {
this.experimentList = experimentList;
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof ExperimentType)) {
return false;
}
ExperimentType other = (ExperimentType) object;
return (this.id != null || other.id == null) && (this.id == null || this.id.equals(other.id));
}
@Override
public String toString() {
return "gov.anl.aps.dm.portal.model.entities.ExperimentType[ id=" + id + " ]";
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package gov.anl.aps.dm.portal.model.entities;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
/**
*
* @author sveseli
*/
@Entity
@Table(name = "policy_type")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "PolicyType.findAll", query = "SELECT p FROM PolicyType p"),
@NamedQuery(name = "PolicyType.findById", query = "SELECT p FROM PolicyType p WHERE p.id = :id"),
@NamedQuery(name = "PolicyType.findByName", query = "SELECT p FROM PolicyType p WHERE p.name = :name"),
@NamedQuery(name = "PolicyType.findByDescription", query = "SELECT p FROM PolicyType p WHERE p.description = :description"),
@NamedQuery(name = "PolicyType.findByHandlerName", query = "SELECT p FROM PolicyType p WHERE p.handlerName = :handlerName"),
@NamedQuery(name = "PolicyType.findByDefaultPolicyValue", query = "SELECT p FROM PolicyType p WHERE p.defaultPolicyValue = :defaultPolicyValue")})
public class PolicyType extends CloneableEntity
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id")
private Integer id;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 2147483647)
@Column(name = "name")
private String name;
@Size(max = 2147483647)
@Column(name = "description")
private String description;
@Size(max = 2147483647)
@Column(name = "handler_name")
private String handlerName;
@Size(max = 2147483647)
@JoinColumn(name = "default_policy_value", referencedColumnName = "policy_value")
@OneToOne
private AllowedPolicyValue defaultPolicyValue;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "policyType")
private List<ExperimentPolicy> experimentPolicyList;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "policyType")
private List<TemplatePolicy> templatePolicyList;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "policyType")
private List<AllowedPolicyValue> allowedPolicyValueList;
public PolicyType() {
}
public PolicyType(Integer id) {
this.id = id;
}
public PolicyType(Integer id, String name) {
this.id = id;
this.name = name;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getHandlerName() {
return handlerName;
}
public void setHandlerName(String handlerName) {
this.handlerName = handlerName;
}
public AllowedPolicyValue getDefaultPolicyValue() {
return defaultPolicyValue;
}
public void setDefaultPolicyValue(AllowedPolicyValue defaultPolicyValue) {
this.defaultPolicyValue = defaultPolicyValue;
}
@XmlTransient
public List<ExperimentPolicy> getExperimentPolicyList() {
return experimentPolicyList;
}
public void setExperimentPolicyList(List<ExperimentPolicy> experimentPolicyList) {
this.experimentPolicyList = experimentPolicyList;
}
@XmlTransient
public List<TemplatePolicy> getTemplatePolicyList() {
return templatePolicyList;
}
public void setTemplatePolicyList(List<TemplatePolicy> templatePolicyList) {
this.templatePolicyList = templatePolicyList;
}
@XmlTransient
public List<AllowedPolicyValue> getAllowedPolicyValueList() {
return allowedPolicyValueList;
}
public void setAllowedPolicyValueList(List<AllowedPolicyValue> allowedPolicyValueList) {
this.allowedPolicyValueList = allowedPolicyValueList;
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof PolicyType)) {
return false;
}
PolicyType other = (PolicyType) object;
return (this.id != null || other.id == null) && (this.id == null || this.id.equals(other.id));
}
@Override
public String toString() {
return "gov.anl.aps.dm.portal.model.entities.PolicyType[ id=" + id + " ]";
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package gov.anl.aps.dm.portal.model.entities;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
/**
*
* @author sveseli
*/
@Entity
@Table(name = "role_type")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "RoleType.findAll", query = "SELECT r FROM RoleType r"),
@NamedQuery(name = "RoleType.findById", query = "SELECT r FROM RoleType r WHERE r.id = :id"),
@NamedQuery(name = "RoleType.findByName", query = "SELECT r FROM RoleType r WHERE r.name = :name"),
@NamedQuery(name = "RoleType.findByDescription", query = "SELECT r FROM RoleType r WHERE r.description = :description")})
public class RoleType extends CloneableEntity
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id")
private Integer id;
@Basic(optional = false)
@NotNull
@Size(max = 64)
@Column(name = "name")
private String name;
@Size(max = 2147483647)
@Column(name = "description")
private String description;
@NotNull
@Column(name = "is_system_role")
private boolean isSystemRole;
@JoinTable(name = "user_system_role", joinColumns = {
@JoinColumn(name = "role_type_id", referencedColumnName = "id")}, inverseJoinColumns = {
@JoinColumn(name = "user_id", referencedColumnName = "id")})
@ManyToMany
private List<UserInfo> userInfoList;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "roleType")
private List<UserExperimentRole> userExperimentRoleList;
public RoleType() {
}
public RoleType(Integer id) {
this.id = id;
}
public RoleType(Integer id, String name) {
this.id = id;
this.name = name;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public boolean isIsSystemRole() {
return isSystemRole;
}
public void setIsSystemRole(boolean isSystemRole) {
this.isSystemRole = isSystemRole;
}
@XmlTransient
public List<UserInfo> getUserInfoList() {
return userInfoList;
}
public void setUserInfoList(List<UserInfo> userInfoList) {
this.userInfoList = userInfoList;
}
public void addRoleTypeToUser(UserInfo userInfo) {
if (userInfoList == null)
userInfoList = new ArrayList();
if (!userInfoList.contains(userInfo)) {
userInfoList.add(userInfo);
}
}
public void removeRoleTypeFromUser(UserInfo userInfo) {
userInfoList.remove(userInfo);
}
public boolean isAdmin(String userName) {
for (UserInfo userInfo : getUserInfoList())
{
if (userInfo.getUsername().equals(userName))
return true;
}
return false;
}
@XmlTransient
public List<UserExperimentRole> getUserExperimentRoleList() {
return userExperimentRoleList;
}
public void setUserExperimentRoleList(List<UserExperimentRole> userExperimentRoleList) {
this.userExperimentRoleList = userExperimentRoleList;
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof RoleType)) {
return false;
}
RoleType other = (RoleType) object;
return (this.id != null || other.id == null) && (this.id == null || this.id.equals(other.id));
}
@Override
public String toString() {
return "gov.anl.aps.dm.portal.model.entities.RoleType[ id=" + id + " ]";
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package gov.anl.aps.dm.portal.model.entities;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
/**
*
* @author sveseli
*/
@Entity
@Table(name = "setting_type")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "SettingType.findAll", query = "SELECT s FROM SettingType s"),
@NamedQuery(name = "SettingType.findById", query = "SELECT s FROM SettingType s WHERE s.id = :id"),
@NamedQuery(name = "SettingType.findByName", query = "SELECT s FROM SettingType s WHERE s.name = :name"),
@NamedQuery(name = "SettingType.findByDescription", query = "SELECT s FROM SettingType s WHERE s.description = :description"),
@NamedQuery(name = "SettingType.findByDefaultValue", query = "SELECT s FROM SettingType s WHERE s.defaultValue = :defaultValue"),
@NamedQuery(name = "SettingType.findByIsUserModifiable", query = "SELECT s FROM SettingType s WHERE s.isUserModifiable = :isUserModifiable")})
public class SettingType extends CloneableEntity
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id")
private Integer id;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 2147483647)
@Column(name = "name")
private String name;
@Size(max = 2147483647)
@Column(name = "description")
private String description;
@Size(max = 2147483647)
@Column(name = "default_value")
private String defaultValue;
@Column(name = "is_user_modifiable")
private Boolean isUserModifiable;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "settingType")
private List<AllowedSettingValue> allowedSettingValueList;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "settingType")
private List<UserSetting> userSettingList;
public SettingType() {
}
public SettingType(Integer id) {
this.id = id;
}
public SettingType(Integer id, String name) {
this.id = id;
this.name = name;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getDefaultValue() {
return defaultValue;
}
public void setDefaultValue(String defaultValue) {
this.defaultValue = defaultValue;
}
public Boolean getIsUserModifiable() {
return isUserModifiable;
}
public void setIsUserModifiable(Boolean isUserModifiable) {
this.isUserModifiable = isUserModifiable;
}
@XmlTransient
public List<AllowedSettingValue> getAllowedSettingValueList() {
return allowedSettingValueList;
}
public void setAllowedSettingValueList(List<AllowedSettingValue> allowedSettingValueList) {
this.allowedSettingValueList = allowedSettingValueList;
}
@XmlTransient
public List<UserSetting> getUserSettingList() {
return userSettingList;
}
public void setUserSettingList(List<UserSetting> userSettingList) {
this.userSettingList = userSettingList;
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof SettingType)) {
return false;
}
SettingType other = (SettingType) object;
return (this.id != null || other.id == null) && (this.id == null || this.id.equals(other.id));
}
@Override
public String toString() {
return "gov.anl.aps.dm.portal.model.entities.SettingType[ id=" + id + " ]";
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package gov.anl.aps.dm.portal.model.entities;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
/**
*
* @author sveseli
*/
@Entity
@Table(name = "template_policy")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "TemplatePolicy.findAll", query = "SELECT t FROM TemplatePolicy t"),
@NamedQuery(name = "TemplatePolicy.findById", query = "SELECT t FROM TemplatePolicy t WHERE t.id = :id"),
@NamedQuery(name = "TemplatePolicy.findByPolicyValue", query = "SELECT t FROM TemplatePolicy t WHERE t.policyValue = :policyValue"),
@NamedQuery(name = "TemplatePolicy.findByDescription", query = "SELECT t FROM TemplatePolicy t WHERE t.description = :description")})
public class TemplatePolicy extends CloneableEntity
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id")
private Integer id;
@Basic(optional = false)
@Size(min = 1, max = 2147483647)
@Column(name = "policy_value")
private String policyValue;
@Size(max = 2147483647)
@Column(name = "description")
private String description;
@JoinColumn(name = "template_policy_set_id", referencedColumnName = "id")
@ManyToOne(optional = false)
private TemplatePolicySet templatePolicySet;
@JoinColumn(name = "policy_type_id", referencedColumnName = "id")
@ManyToOne(optional = false)
private PolicyType policyType;
public TemplatePolicy() {
}
public TemplatePolicy(Integer id) {
this.id = id;
}
public TemplatePolicy(Integer id, String value) {
this.id = id;
this.policyValue = value;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getPolicyValue() {
return policyValue;
}
public void setPolicyValue(String policyValue) {
this.policyValue = policyValue;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public TemplatePolicySet getTemplatePolicySet() {
return templatePolicySet;
}
public void setTemplatePolicySet(TemplatePolicySet templatePolicySet) {
this.templatePolicySet = templatePolicySet;
}
public PolicyType getPolicyType() {
return policyType;
}
public void setPolicyType(PolicyType policyType) {
this.policyType = policyType;
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof TemplatePolicy)) {
return false;
}
TemplatePolicy other = (TemplatePolicy) object;
return (this.id != null || other.id == null) && (this.id == null || this.id.equals(other.id));
}
@Override
public String toString() {
return "gov.anl.aps.dm.portal.model.entities.TemplatePolicy[ id=" + id + " ]";
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package gov.anl.aps.dm.portal.model.entities;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
/**
*
* @author sveseli
*/
@Entity
@Table(name = "template_policy_set")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "TemplatePolicySet.findAll", query = "SELECT t FROM TemplatePolicySet t"),
@NamedQuery(name = "TemplatePolicySet.findById", query = "SELECT t FROM TemplatePolicySet t WHERE t.id = :id"),
@NamedQuery(name = "TemplatePolicySet.findByName", query = "SELECT t FROM TemplatePolicySet t WHERE t.name = :name"),
@NamedQuery(name = "TemplatePolicySet.findByDescription", query = "SELECT t FROM TemplatePolicySet t WHERE t.description = :description")})
public class TemplatePolicySet extends CloneableEntity
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id")
private Integer id;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 2147483647)
@Column(name = "name")
private String name;
@Size(max = 2147483647)
@Column(name = "description")
private String description;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "templatePolicySet")
private List<TemplatePolicy> templatePolicyList;
public TemplatePolicySet() {
}
public TemplatePolicySet(Integer id) {
this.id = id;
}
public TemplatePolicySet(Integer id, String name) {
this.id = id;
this.name = name;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@XmlTransient
public List<TemplatePolicy> getTemplatePolicyList() {
return templatePolicyList;
}
public void setTemplatePolicyList(List<TemplatePolicy> templatePolicyList) {
this.templatePolicyList = templatePolicyList;
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof TemplatePolicySet)) {
return false;
}
TemplatePolicySet other = (TemplatePolicySet) object;
return (this.id != null || other.id == null) && (this.id == null || this.id.equals(other.id));
}
@Override
public String toString() {
return "gov.anl.aps.dm.portal.model.entities.TemplatePolicySet[ id=" + id + " ]";
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package gov.anl.aps.dm.portal.model.entities;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
/**
*
* @author sveseli
*/
@Entity
@Table(name = "user_experiment_role")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "UserExperimentRole.findAll", query = "SELECT u FROM UserExperimentRole u"),
@NamedQuery(name = "UserExperimentRole.findByUserId", query = "SELECT u FROM UserExperimentRole u WHERE u.userExperimentRolePK.userId = :userId"),
@NamedQuery(name = "UserExperimentRole.findByExperimentId", query = "SELECT u FROM UserExperimentRole u WHERE u.userExperimentRolePK.experimentId = :experimentId"),
@NamedQuery(name = "UserExperimentRole.findByRoleTypeId", query = "SELECT u FROM UserExperimentRole u WHERE u.userExperimentRolePK.roleTypeId = :roleTypeId"),
@NamedQuery(name = "UserExperimentRole.findByUserExperimentRole", query = "SELECT u FROM UserExperimentRole u WHERE u.userExperimentRolePK.userId = :userId AND u.userExperimentRolePK.experimentId = :experimentId AND u.userExperimentRolePK.roleTypeId = :roleTypeId")})
public class UserExperimentRole extends CloneableEntity
{
@EmbeddedId
protected UserExperimentRolePK userExperimentRolePK;
@JoinColumn(name = "user_id", referencedColumnName = "id", insertable = false, updatable = false)
@ManyToOne(optional = false)
private UserInfo userInfo;
@JoinColumn(name = "role_type_id", referencedColumnName = "id", insertable = false, updatable = false)
@ManyToOne(optional = false)
private RoleType roleType;
@JoinColumn(name = "experiment_id", referencedColumnName = "id", insertable = false, updatable = false)
@ManyToOne(optional = false)
private Experiment experiment;
public UserExperimentRole() {
}
public UserExperimentRole(UserExperimentRolePK userExperimentRolePK) {
this.userExperimentRolePK = userExperimentRolePK;
}
public UserExperimentRole(int userId, int experimentId, int roleTypeId) {
this.userExperimentRolePK = new UserExperimentRolePK(userId, experimentId, roleTypeId);
}
public UserExperimentRolePK getUserExperimentRolePK() {
return userExperimentRolePK;
}
public void setUserExperimentRolePK(UserExperimentRolePK userExperimentRolePK) {
this.userExperimentRolePK = userExperimentRolePK;
}
public UserInfo getUserInfo() {
return userInfo;
}
public void setUserInfo(UserInfo userInfo) {
this.userInfo = userInfo;
}
public RoleType getRoleType() {
return roleType;
}
public void setRoleType(RoleType roleType) {
this.roleType = roleType;
}
public Experiment getExperiment() {
return experiment;
}
public void setExperiment(Experiment experiment) {
this.experiment = experiment;
}
@Override
public int hashCode() {
int hash = 0;
hash += (userExperimentRolePK != null ? userExperimentRolePK.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof UserExperimentRole)) {
return false;
}
UserExperimentRole other = (UserExperimentRole) object;
return (this.userExperimentRolePK != null || other.userExperimentRolePK == null) && (this.userExperimentRolePK == null || this.userExperimentRolePK.equals(other.userExperimentRolePK));
}
@Override
public String toString() {
return "gov.anl.aps.dm.portal.model.entities.UserExperimentRole[ userExperimentRolePK=" + userExperimentRolePK + " ]";
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package gov.anl.aps.dm.portal.model.entities;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.validation.constraints.NotNull;
/**
*
* @author sveseli
*/
@Embeddable
public class UserExperimentRolePK implements Serializable
{
@Basic(optional = false)
@NotNull
@Column(name = "user_id")
private int userId;
@Basic(optional = false)
@NotNull
@Column(name = "experiment_id")
private int experimentId;
@Basic(optional = false)
@NotNull
@Column(name = "role_type_id")
private int roleTypeId;
public UserExperimentRolePK() {
}
public UserExperimentRolePK(int userId, int experimentId, int roleTypeId) {
this.userId = userId;
this.experimentId = experimentId;
this.roleTypeId = roleTypeId;
}
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public int getExperimentId() {
return experimentId;
}
public void setExperimentId(int experimentId) {
this.experimentId = experimentId;
}
public int getRoleTypeId() {
return roleTypeId;
}
public void setRoleTypeId(int roleTypeId) {
this.roleTypeId = roleTypeId;
}
@Override
public int hashCode() {
int hash = 0;
hash += (int) userId;
hash += (int) experimentId * 100;
hash += (int) roleTypeId * 10000;
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof UserExperimentRolePK)) {
return false;
}
UserExperimentRolePK other = (UserExperimentRolePK) object;
if (this.userId != other.userId) {
return false;
}
if (this.experimentId != other.experimentId) {
return false;
}
return this.roleTypeId == other.roleTypeId;
}
@Override
public String toString() {
return "gov.anl.aps.dm.portal.model.entities.UserExperimentRolePK[ userId=" + userId + ", experimentId=" + experimentId + ", roleTypeId=" + roleTypeId + " ]";
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package gov.anl.aps.dm.portal.model.entities;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
/**
*
* @author sveseli
*/
@Entity
@Table(name = "user_info")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "UserInfo.findAll", query = "SELECT u FROM UserInfo u"),
@NamedQuery(name = "UserInfo.findById", query = "SELECT u FROM UserInfo u WHERE u.id = :id"),
@NamedQuery(name = "UserInfo.findByUsername", query = "SELECT u FROM UserInfo u WHERE u.username = :username"),
@NamedQuery(name = "UserInfo.findByFirstName", query = "SELECT u FROM UserInfo u WHERE u.firstName = :firstName"),
@NamedQuery(name = "UserInfo.findByLastName", query = "SELECT u FROM UserInfo u WHERE u.lastName = :lastName"),
@NamedQuery(name = "UserInfo.findByMiddleName", query = "SELECT u FROM UserInfo u WHERE u.middleName = :middleName"),
@NamedQuery(name = "UserInfo.findByEmail", query = "SELECT u FROM UserInfo u WHERE u.email = :email"),
@NamedQuery(name = "UserInfo.findByDescription", query = "SELECT u FROM UserInfo u WHERE u.description = :description"),
@NamedQuery(name = "UserInfo.findByPassword", query = "SELECT u FROM UserInfo u WHERE u.password = :password"),
@NamedQuery(name = "UserInfo.findNonAdmins", query = "SELECT u FROM UserInfo u WHERE u.id NOT IN (SELECT u2.id from UserInfo u2 JOIN u2.roleTypeList rt WHERE rt.id = :roleTypeId)"),
@NamedQuery(name = "UserInfo.findUsersInRole", query = "SELECT u FROM UserInfo u WHERE u.id IN (SELECT u2.id from UserInfo u2 JOIN u2.roleTypeList rt WHERE rt.id = :roleTypeId)"),
@NamedQuery(name = "UserInfo.findUsersInExperiment", query = "SELECT DISTINCT u FROM UserInfo u WHERE u.id IN (SELECT u2.id from UserInfo u2 JOIN u2.userExperimentRoleList r WHERE r.experiment.id = :experimentId)"),
@NamedQuery(name = "UserInfo.findNoUsersInExperiment", query = "SELECT u FROM UserInfo u WHERE u.id NOT IN (SELECT u2.id from UserInfo u2 JOIN u2.userExperimentRoleList r WHERE r.experiment.id = :experimentId)"),
@NamedQuery(name = "UserInfo.findExperimentsInUser", query = "SELECT DISTINCT e FROM Experiment e WHERE e.id IN (SELECT e2.id from Experiment e2 JOIN e2.userExperimentRoleList r WHERE r.userInfo.id = :userId)")})
public class UserInfo extends CloneableEntity
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id")
private Integer id;
@Basic(optional = false)
@NotNull
@Size(max = 64)
@Column(name = "username")
private String username;
@Basic(optional = false)
@NotNull
@Size(max = 64)
@Column(name = "first_name")
private String firstName;
@Basic(optional = false)
@NotNull
@Size(max = 64)
@Column(name = "last_name")
private String lastName;
@Size(max = 64)
@Column(name = "middle_name")
private String middleName;
// @Pattern(regexp="[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?", message="Invalid email")//if the field contains email address consider using this annotation to enforce field validation
@Size(max = 2147483647)
@Column(name = "email")
private String email;
@Size(max = 120)
@Column(name = "badge")
private String badge;
@Size(max = 120)
@Column(name = "globus_username")
private String globusUsername;
@Size(max = 120)
@Column(name = "description")
private String description;
@Size(max = 64)
@Column(name = "password")
private String password;
@ManyToMany(mappedBy = "userInfoList")
private List<RoleType> roleTypeList;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "userInfo")
private List<UserExperimentRole> userExperimentRoleList;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "userInfo")
private List<UserSetting> userSettingList;
public UserInfo() {
}
public UserInfo(Integer id) {
this.id = id;
}
public UserInfo(Integer id, String username, String firstName, String lastName) {
this.id = id;
this.username = username;
this.firstName = firstName;
this.lastName = lastName;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getMiddleName() {
return middleName;
}
public void setMiddleName(String middleName) {
this.middleName = middleName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getBadge() {
return badge;
}
public void setBadge(String badge) {
this.badge = badge;
}
public String getGlobusUsername() {
return globusUsername;
}
public void setGlobusUsername(String globusUsername) {
this.globusUsername = globusUsername;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@XmlTransient
public List<RoleType> getRoleTypeList() {
return roleTypeList;
}
public void setRoleTypeList(List<RoleType> roleTypeList) {
this.roleTypeList = roleTypeList;
}
@XmlTransient
public List<UserExperimentRole> getUserExperimentRoleList() {
return userExperimentRoleList;
}
public void setUserExperimentRoleList(List<UserExperimentRole> userExperimentRoleList) {
this.userExperimentRoleList = userExperimentRoleList;
}
@XmlTransient
public List<UserSetting> getUserSettingList() {
return userSettingList;
}
public void setUserSettingList(List<UserSetting> userSettingList) {
this.userSettingList = userSettingList;
}
public void removeExperimentRole(int roleId, int experimentId) {
UserExperimentRole roleToRemove = null;
for (UserExperimentRole experimentRole : userExperimentRoleList) {
if ((experimentRole.getUserExperimentRolePK().getRoleTypeId() == roleId) && (experimentRole.getUserExperimentRolePK().getExperimentId() == experimentId)) {
roleToRemove = experimentRole;
break;
}
}
if (roleToRemove != null) {
userExperimentRoleList.remove(roleToRemove);
}
}
public List<UserExperimentRole> getUserExperimentRoles(int experimentId) {
List<UserExperimentRole> roleList = new ArrayList<>();
for (UserExperimentRole experimentRole : userExperimentRoleList) {
if (experimentRole.getUserExperimentRolePK().getExperimentId() == experimentId) {
roleList.add(experimentRole);
}
}
return roleList;
}
public void addUserExperimentRole(UserExperimentRole userExperimentRole) {
userExperimentRoleList.add(userExperimentRole);
}
public UserExperimentRole getExperimetRole(int roleId, int experimentId) {
for (UserExperimentRole experimentRole : userExperimentRoleList) {
if ((experimentRole.getUserExperimentRolePK().getRoleTypeId() == roleId) && (experimentRole.getUserExperimentRolePK().getExperimentId() == experimentId))
return experimentRole;
}
return null;
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof UserInfo)) {
return false;
}
UserInfo other = (UserInfo) object;
return (this.id != null || other.id == null) && (this.id == null || this.id.equals(other.id));
}
@Override
public String toString() {
return "gov.anl.aps.dm.portal.model.entities.UserInfo[ id=" + id + " ]";
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package gov.anl.aps.dm.portal.model.entities;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
/**
*
* @author sveseli
*/
@Entity
@Table(name = "user_setting")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "UserSetting.findAll", query = "SELECT u FROM UserSetting u"),
@NamedQuery(name = "UserSetting.findById", query = "SELECT u FROM UserSetting u WHERE u.id = :id"),
@NamedQuery(name = "UserSetting.findBySettingValue", query = "SELECT u FROM UserSetting u WHERE u.settingValue = :settingValue")})
public class UserSetting extends CloneableEntity
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id")
private Integer id;
@Size(max = 2147483647)
@Column(name = "setting_value")
private String settingValue;
@JoinColumn(name = "user_id", referencedColumnName = "id")
@ManyToOne(optional = false)
private UserInfo userInfo;
@JoinColumn(name = "setting_type_id", referencedColumnName = "id")
@ManyToOne(optional = false)
private SettingType settingType;
public UserSetting() {
}
public UserSetting(Integer id) {
this.id = id;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getSettingValue() {
return settingValue;
}
public void setSettingValue(String settingValue) {
this.settingValue = settingValue;
}
public UserInfo getUserInfo() {
return userInfo;
}
public void setUserInfo(UserInfo userInfo) {
this.userInfo = userInfo;
}
public SettingType getSettingType() {
return settingType;
}
public void setSettingType(SettingType settingType) {
this.settingType = settingType;
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof UserSetting)) {
return false;
}
UserSetting other = (UserSetting) object;
return (this.id != null || other.id == null) && (this.id == null || this.id.equals(other.id));
}
@Override
public String toString() {
return "gov.anl.aps.dm.portal.model.entities.UserSetting[ id=" + id + " ]";
}
}
package gov.anl.aps.dm.portal.utilities;
import java.util.List;
import java.util.ListIterator;
import javax.faces.model.SelectItem;
public class CollectionUtility
{
public static SelectItem[] getSelectItems(List<?> entities, boolean selectOne) {
int size = selectOne ? entities.size() + 1 : entities.size();
SelectItem[] items = new SelectItem[size];
int i = 0;
if (selectOne) {
items[0] = new SelectItem("", "Select");
i++;
}
for (Object x : entities) {
items[i++] = new SelectItem(x, x.toString());
}
return items;
}
public static String displayItemList(List<?> list, String beginDelimiter, String itemDelimiter, String endDelimiter) {
String result = beginDelimiter;
boolean addItemDelimiter = false;
if (list != null) {
for (Object item : list) {
if (!addItemDelimiter) {
addItemDelimiter = true;
}
else {
result += itemDelimiter;
}
result += item.toString();
}
}
result += endDelimiter;
return result;
}
public static String displayItemListWithoutOutsideDelimiters(List<?> list, String itemDelimiter) {
String beginDelimiter = "";
String endDelimiter = "";
return displayItemList(list, beginDelimiter, itemDelimiter, endDelimiter);
}
public static String displayItemListWithoutDelimiters(List<?> list) {
String beginDelimiter = "";
String itemDelimiter = "";
String endDelimiter = "";
return displayItemList(list, beginDelimiter, itemDelimiter, endDelimiter);
}
public static void removeNullReferencesFromList(List<?> list) {
if (list == null) {
return;
}
ListIterator iterator = list.listIterator();
while (iterator.hasNext()) {
if (iterator.next() == null) {
iterator.remove();
}
}
}
}
package gov.anl.aps.dm.portal.utilities;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import org.apache.log4j.Logger;
public class ConfigurationUtility {
public static final String PropertiesPath = "dm.portal.properties";
public static final String PropertiesDelimiter = ",";
private static final Logger logger = Logger.getLogger(ConfigurationUtility.class.getName());
private static final Properties portalProperties = loadProperties(PropertiesPath);
public Properties getPortalProperties() {
return portalProperties;
}
public static String getPortalProperty(String propertyName) {
return portalProperties.getProperty(propertyName, "");
}
public static String getPortalProperty(String propertyName, String defaultValue) {
return portalProperties.getProperty(propertyName, defaultValue);
}
public static List<String> getPortalPropertyList(String propertyName) {
return getPortalPropertyList(propertyName, "");
}
public static List<String> getPortalPropertyList(String propertyName, String defaultValue) {
String[] propertyArray = portalProperties.getProperty(propertyName, defaultValue).split(PropertiesDelimiter);
logger.debug("Looking for property " + propertyName);
ArrayList propertyList = new ArrayList();
for (String property : propertyArray) {
String p = property.trim();
if (p.length() > 0) {
propertyList.add(property.trim());
}
}
logger.debug("Resulting property list: " + propertyList);
return propertyList;
}
/**
* Load properties.
*
* @param path
* @return loaded properties
*/
public static Properties loadProperties(String path) {
Properties properties = new Properties();
if (path != null) {
try {
logger.debug("Loading properties from " + path);
InputStream inputStream = ConfigurationUtility.class.getClassLoader().getResourceAsStream(path);
properties.load(inputStream);
} catch (IOException ex) {
logger.warn("Could not load properties from file " + path + ": " + ex);
}
} else {
logger.warn("Properties path not specified.");
}
return properties;
}
/**
* Get system property.
*
* @param propertyName property name
* @return property value
*/
public static String getSystemProperty(String propertyName) {
Properties p = System.getProperties();
return p.getProperty(propertyName);
}
/**
* Get system property.
*
* @param propertyName property name
* @param defaultValue default property value
* @return property value
*/
public static String getSystemProperty(String propertyName, String defaultValue) {
Properties p = System.getProperties();
return p.getProperty(propertyName, defaultValue);
}
/**
* Get environment variable.
*
* @param name Environment variable name
* @return environment variable value, or null if it is not defined
*/
public static String getEnvVar(String name) {
return System.getenv(name);
}
}
package gov.anl.aps.dm.portal.utilities;
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateUtility
{
private static final SimpleDateFormat DateTimeFormat = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public static String getCurrentDateTime() {
return DateTimeFormat.format(new Date());
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package gov.anl.aps.dm.portal.utilities;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
import org.apache.log4j.Logger;
/**
*
* @author sveseli
*/
public class LdapUtility
{
private static final String LdapUrlPropertyName = "dm.portal.ldapUrl";
private static final String LdapDnStringPropertyName = "dm.portal.ldapDnString";
private static final String ldapUrl = ConfigurationUtility.getPortalProperty(LdapUrlPropertyName);
private static final String ldapDnString = ConfigurationUtility.getPortalProperty(LdapDnStringPropertyName);
private static final Logger logger = Logger.getLogger(LdapUtility.class.getName());
/**
* Use username and password to attempt initial connection and bind with APS
* LDAP server. Successful connection implies that credentials are accepted.
*
* @param username username
* @param password password
*
* @return true if valid, false otherwise
*/
public static boolean validateCredentials(String username, String password) {
// dump out immediately if not given password
if (password.isEmpty()) {
return false;
}
boolean validated = false;
Hashtable env = new Hashtable();
String dn = ldapDnString.replace("USERNAME", username);
logger.debug("Authenticating: " + dn);
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, ldapUrl);
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, dn);
env.put(Context.SECURITY_CREDENTIALS, password);
// the below property allows us to circumvent server certificate checks
env.put("java.naming.ldap.factory.socket", "gov.anl.aps.dm.portal.utilities.NoServerVerificationSSLSocketFactory");
try {
DirContext ctx = new InitialDirContext(env);
validated = true;
}
catch (NamingException ex) {
ex.printStackTrace();
}
return validated;
}
}
package gov.anl.aps.dm.portal.utilities;
import java.security.cert.X509Certificate;
import javax.net.ssl.X509TrustManager;
/**
* A trivial implementation of <code>X509TrustManager</code> that doesn't
* actually check the validity of a certificate. This allows us to make
* SSL connections to internal servers without requiring the installation
* and maintenance of certificates in the client keystore.
*
* @see NoServerVerificationSSLSocketFactory
*/
public class NoOpTrustManager implements X509TrustManager
{
@Override
public void checkClientTrusted(X509Certificate[] cert, String authType)
{
}
@Override
public void checkServerTrusted(X509Certificate[] cert, String authType)
{
}
@Override
public X509Certificate[] getAcceptedIssuers()
{
return new X509Certificate[0];
}
}
package gov.anl.aps.dm.portal.utilities;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import javax.net.SocketFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
/**
* A minor extension of <code>SSLSocketFactory</code> that installs
* a dummy trust manager. This allows creation of SSL sockets that don't
* verify the server certificates.
*
* @see NoOpTrustManager
*/
public class NoServerVerificationSSLSocketFactory extends SSLSocketFactory
{
private SSLSocketFactory factory;
public NoServerVerificationSSLSocketFactory()
{
try {
TrustManager tm = new NoOpTrustManager();
SSLContext sslcontext = SSLContext.getInstance("TLS");
sslcontext.init( null, // No KeyManager required
new TrustManager[] {tm},
new java.security.SecureRandom());
factory = (SSLSocketFactory)sslcontext.getSocketFactory();
}
catch(KeyManagementException | NoSuchAlgorithmException ex) {
ex.printStackTrace();
}
}
public static SocketFactory getDefault() {
return new NoServerVerificationSSLSocketFactory();
}
@Override
public Socket createSocket(Socket socket, String s, int i, boolean flag)
throws IOException
{
return factory.createSocket( socket, s, i, flag);
}
@Override
public Socket createSocket(InetAddress inaddr, int i, InetAddress inaddr1, int j)
throws IOException
{
return factory.createSocket(inaddr, i, inaddr1, j);
}
@Override
public Socket createSocket(InetAddress inaddr, int i) throws IOException
{
return factory.createSocket(inaddr, i);
}
@Override
public Socket createSocket(String s, int i, InetAddress inaddr, int j)
throws IOException
{
return factory.createSocket(s, i, inaddr, j);
}
@Override
public Socket createSocket(String s, int i) throws IOException
{
return factory.createSocket(s, i);
}
@Override
public String[] getDefaultCipherSuites()
{
return factory.getSupportedCipherSuites();
}
@Override
public String[] getSupportedCipherSuites()
{
return factory.getSupportedCipherSuites();
}
}
package gov.anl.aps.dm.portal.utilities;
public class ObjectUtility
{
public static <Type> boolean equals(Type object1, Type object2) {
if (object1 == null && object2 == null) {
return true;
}
if (object1 == null || object2 == null) {
return false;
}
return object1.equals(object2);
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package gov.anl.aps.dm.portal.utilities;
import java.util.HashMap;
import java.util.regex.Pattern;
/**
*
* @author sveseli
*/
public class SearchResult
{
private final Integer objectId;
private final String objectName;
private HashMap<String, String> objectAttributeMatchMap = new HashMap();
public SearchResult(Integer objectId, String objectName) {
this.objectId = objectId;
this.objectName = objectName;
}
public Integer getObjectId() {
return objectId;
}
public String getObjectName() {
return objectName;
}
public void addAttributeMatch(String key, String value) {
objectAttributeMatchMap.put(key, value);
}
public HashMap<String, String> getObjectAttributeMatchMap() {
return objectAttributeMatchMap;
}
public void setObjectAttributeMatchMap(HashMap<String, String> objectAttributeMatchMap) {
this.objectAttributeMatchMap = objectAttributeMatchMap;
}
public boolean isEmpty() {
return objectAttributeMatchMap.isEmpty();
}
public boolean doesValueContainPattern(String key, String value, Pattern searchPattern) {
if (value == null || value.isEmpty()) {
return false;
}
boolean searchResult = searchPattern.matcher(value).find();
if (searchResult) {
addAttributeMatch(key, value);
}
return searchResult;
}
public String getDisplay() {
String result = "";
String keyDelimiter = ": ";
String entryDelimiter = "";
for (String key : objectAttributeMatchMap.keySet()) {
result += entryDelimiter + key + keyDelimiter + objectAttributeMatchMap.get(key);
entryDelimiter = "; ";
}
return result;
}
}
package gov.anl.aps.dm.portal.utilities;
import java.util.Map;
import java.util.Stack;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
/**
* Session utility class.
*/
public class SessionUtility
{
/**
* Keys.
*/
public static final String MessagesKey = "messages";
public static final String UserKey = "user";
public static final String ViewStackKey = "viewStack";
/**
* Constructor.
*/
public SessionUtility() {
}
/**
* Add error message.
*
* @param summary message summary
* @param detail detailed message
*/
public static void addErrorMessage(String summary, String detail) {
FacesContext context = FacesContext.getCurrentInstance();
context.getExternalContext().getFlash().setKeepMessages(true);
context.addMessage(MessagesKey, new FacesMessage(FacesMessage.SEVERITY_ERROR, summary, detail));
}
/**
* Add warning message.
*
* @param summary message summary
* @param detail detailed message
*/
public static void addWarningMessage(String summary, String detail) {
FacesContext context = FacesContext.getCurrentInstance();
context.getExternalContext().getFlash().setKeepMessages(true);
context.addMessage(MessagesKey, new FacesMessage(FacesMessage.SEVERITY_WARN, summary, detail));
}
/**
* Add info message.
*
* @param summary message summary
* @param detail detailed message
*/
public static void addInfoMessage(String summary, String detail) {
FacesContext context = FacesContext.getCurrentInstance();
context.getExternalContext().getFlash().setKeepMessages(true);
context.addMessage(MessagesKey, new FacesMessage(FacesMessage.SEVERITY_INFO, summary, detail));
}
/**
* Get request parameter value.
*
* @param parameterName parameter name
* @return parameter value
*/
public static String getRequestParameterValue(String parameterName) {
Map parameterMap = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
return (String) parameterMap.get(parameterName);
}
/**
* Set user.
*
* @param user user
*/
public static void setUser(Object user) {
Map sessionMap = FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
sessionMap.put(UserKey, user);
}
/**
* Get user.
*
* @return user
*/
public static Object getUser() {
Map sessionMap = FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
return sessionMap.get(UserKey);
}
public static void pushViewOnStack(String viewId) {
Map sessionMap = FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
Stack<String> viewStack = (Stack) sessionMap.get(ViewStackKey);
if (viewStack == null) {
viewStack = new Stack<>();
sessionMap.put(ViewStackKey, viewStack);
}
viewStack.push(viewId);
}
public static String popViewFromStack() {
Map sessionMap = FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
Stack<String> viewStack = (Stack) sessionMap.get(ViewStackKey);
if (viewStack != null && !viewStack.empty()) {
return viewStack.pop();
}
return null;
}
public static String getCurrentViewId() {
FacesContext context = FacesContext.getCurrentInstance();
return context.getViewRoot().getViewId();
}
public static String getReferrerViewId() {
String referrer = FacesContext.getCurrentInstance().getExternalContext().getRequestHeaderMap().get("referer");
if (referrer != null) {
int beginViewId = referrer.indexOf("/views");
if (beginViewId >= 0) {
return referrer.substring(beginViewId);
}
}
return null;
}
public static void clearSession() {
Map sessionMap = FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
sessionMap.clear();
}
}