nosi.webapps.igrp.dao.Profile Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of igrp-core Show documentation
Show all versions of igrp-core Show documentation
IGRP Framework is a powerful and highly customizable platform developed by the Operational Nucleus for the Information Society (NOSi) to create web applications, it provides out of box, several modules to make easy to create stand-alone, production-grade web applications: authentication and access-control, business processes automation, reporting, page builder with automatic code generation and incorporation of the Once-Only-Principle, written in Java. IGRP Framework WAR - Contains some keys resources that give UI to IGRP Framework and others supports files.
package nosi.webapps.igrp.dao;
/*
@author: Emanuel Pereira
* 29 Jun 2017
*/
import java.io.Serializable;
import java.util.List;
import java.util.Objects;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.persistence.criteria.CriteriaQuery;
import nosi.core.webapp.Core;
@Entity
@Table(name="tbl_profile",uniqueConstraints={
@UniqueConstraint(name="PROFILE_UNIQUE_FK",columnNames = {"type", "type_fk","user_fk","org_fk","prof_type_fk"})},
indexes = @Index(columnList = "type_fk, type, user_fk") )
public class Profile extends IGRPBaseActiveRecord implements Serializable{
/**
*
*/
private static final long serialVersionUID = -3033627274691354839L;
/**
*
*/
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Integer id;
@Column(nullable=false)
private Integer type_fk;
@Column(nullable=false)
private String type;
@ManyToOne( fetch = FetchType.EAGER)
@JoinColumn(name="prof_type_fk",foreignKey=@ForeignKey(name="PROFILE_PROF_TYPE_FK"),nullable=false)
private ProfileType profileType;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name="user_fk",foreignKey=@ForeignKey(name="PROFILE_USER_FK"),nullable=true)
private User user;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name="org_fk",foreignKey=@ForeignKey(name="PROFILE_ORGANIZATION_FK"),nullable=false)
private Organization organization;
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Profile that = (Profile) o;
return Objects.equals(this.user, that.getUser()) && Objects.equals(this.organization, that.getOrganization()) && Objects.equals(this.profileType, that.getProfileType()) && Objects.equals(this.type, that.getType()) && Objects.equals(this.type_fk, that.getType_fk());
}
@Override
public int hashCode() {
return Objects.hash(this.user,this.organization,this.profileType,this.type,this.type_fk);
}
public Profile(){
super();
}
public Profile(Integer type_fk, String type, ProfileType profileType, User user, Organization organization) {
super();
this.type_fk = type_fk;
this.type = type;
this.profileType = profileType;
this.user = user;
this.organization = organization;
}
public Integer getType_fk() {
return type_fk;
}
public void setType_fk(Integer type_fk) {
this.type_fk = type_fk;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public ProfileType getProfileType() {
return profileType;
}
public void setProfileType(ProfileType profileType) {
this.profileType = profileType;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public Organization getOrganization() {
return organization;
}
public void setOrganization(Organization organization) {
this.organization = organization;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Profile getByUserPerfil(int id_user, int id_app) {
return this.findOne(this.getCriteria().where(
this.getBuilder().equal(this.getRoot().get("type"), "PROF"),
this.getBuilder().equal(this.getRoot().get("user"), id_user),
this.getBuilder().equal(this.getRoot().join("profileType").get("application"), id_app)
).orderBy(this.getBuilder().asc(this.getRoot().get("id"))));
}
public Profile getByUser(Integer id) {
final CriteriaQuery cq = this.getCriteria().where(
this.getBuilder().equal(this.getRoot().get("type"), "PROF"),
this.getBuilder().equal(this.getRoot().get("user"),id)
);
return this.findOne(cq.orderBy(this.getBuilder().asc(this.getRoot().get("id"))));
}
public List getMyPerfile() {
return this.findAll(this.getCriteria().where(
this.getBuilder().equal(this.getRoot().get("type"), "PROF"),
this.getBuilder().equal(this.getRoot().get("user"), Core.getCurrentUser().getIdentityId()),
this.getBuilder().equal(this.getRoot().join("profileType").join("application").get("dad"),Core.getCurrentDad())
));
}
public void deleteAllProfile() {
Core.delete(this.getConnectionName(),"tbl_profile")
.where("prof_type_fk=:prof_type_fk AND user_fk=:user_fk AND type=:type AND org_fk=:org_fk")
.addInt("prof_type_fk", this.getProfileType().getId())
.addInt("user_fk", this.getUser().getId())
.addString("type", this.type)
.addInt("org_fk", this.getOrganization().getId())
.execute();
}
@Override
public String toString() {
return "Profile [id=" + id + ", type_fk=" + type_fk + ", type=" + type + ", profileType=" + profileType
+ ", user=" + user + ", organization=" + organization + "]";
}
}