Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
nosi.webapps.igrp.dao.Application Maven / Gradle / Ivy
Go to download
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;
import static nosi.core.i18n.Translator.gt;
/**
* @author: Emanuel Pereira
* 29 Jun 2017
*/
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import javax.persistence.CascadeType;
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.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import nosi.core.webapp.Core;
@Entity
@Table(name = "tbl_env")
public class Application extends IGRPBaseActiveRecord implements Serializable {
/*
*
*/
private static final long serialVersionUID = 1261352599073552072L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Column(nullable = false, unique = true)
private String dad;
@Column(nullable = false)
private String name;
private String img_src;
private String description;
private int status;
private String template;
private int externo;
private String url;
private String plsql_code;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "action_fk", foreignKey = @ForeignKey(name = "ENV_ACTION_FK"))
private Action action;
@OneToMany(cascade = CascadeType.REMOVE, mappedBy = "application")
private Set actions;
@OneToMany(cascade = CascadeType.REMOVE, mappedBy = "application")
private Set configs;
@OneToMany(cascade = CascadeType.REMOVE, mappedBy = "application")
private Set menus;
@OneToMany(cascade = CascadeType.REMOVE, mappedBy = "application")
private Set profilesType;
@OneToMany(cascade = CascadeType.REMOVE, mappedBy = "application")
private Set organizations;
@OneToMany(cascade = CascadeType.REMOVE, mappedBy = "application")
private Set repsources;
@OneToMany(cascade = CascadeType.REMOVE, mappedBy = "application")
private Set repTemplates;
@OneToMany(cascade = CascadeType.REMOVE, mappedBy = "application")
private Set transactions;
@OneToMany(cascade = CascadeType.REMOVE, mappedBy = "application")
private Set repinstances;
@OneToMany(cascade = CascadeType.REMOVE, mappedBy = "application")
private List modulo;
public Application() {
super();
}
public Application(String dad, String name, String img_src, String description, int status, Action action) {
this();
this.dad = dad;
this.name = name;
this.img_src = img_src;
this.description = description;
this.status = status;
this.action = action;
}
public Application(String dad, String name, String img_src, String description, int status, Action action,
String template) {
this(dad, name, img_src, description, status, action);
this.template = template;
}
public int getExternal() {
return externo;
}
public void setExternal(int external) {
this.externo = external;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getDad() {
return dad;
}
public void setDad(String dad) {
this.dad = dad.replaceAll("\\s+", "_").toLowerCase();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getImg_src() {
return img_src;
}
public void setImg_src(String img_src) {
this.img_src = img_src;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public Action getAction() {
return action;
}
public void setAction(Action action) {
this.action = action;
}
public String getTemplate() {
return template;
}
public void setTemplate(String template) {
this.template = template;
}
public Set getActions() {
return actions;
}
public void setActions(Set actions) {
this.actions = actions;
}
public Set getConfigs() {
return configs;
}
public void setConfigs(Set configs) {
this.configs = configs;
}
public Set getMenus() {
return menus;
}
public void setMenus(Set menus) {
this.menus = menus;
}
public Set getProfilesType() {
return profilesType;
}
public void setProfilesType(Set profilesType) {
this.profilesType = profilesType;
}
public Set getOrganizations() {
return organizations;
}
public void setOrganizations(Set organizations) {
this.organizations = organizations;
}
public Set getRepsources() {
return repsources;
}
public void setRepsources(Set repsources) {
this.repsources = repsources;
}
public Set getRepTemplates() {
return repTemplates;
}
public void setRepTemplates(Set repTemplates) {
this.repTemplates = repTemplates;
}
public Set getTransactions() {
return transactions;
}
public void setTransactions(Set transactions) {
this.transactions = transactions;
}
public Set getRepinstances() {
return repinstances;
}
public void setRepinstances(Set repinstances) {
this.repinstances = repinstances;
}
public List getModulo() {
return modulo;
}
public void setModulo(List modulo) {
this.modulo = modulo;
}
@Override
public String toString() {
return "Application [dad=" + dad + ", name=" + name + ", description=" + description + ", status=" + status
+ ", url=" + url + ", action=" + action + "]";
}
public Map getListApps() {
User user = (User) Core.getCurrentUser();
return Core.toMap(getListMyApp(user.getId()), "id", "name", gt("-- Selecionar --"));
}
public Map getAllApps() {
return Core.toMap(this.findAll(), "id", "name", gt("-- Selecionar --"));
}
public Map getAllAppsActiveByFilterId(int appId) {
return Core.toMap(this.find().andWhere("id", "<>", appId).andWhere("status", "=", 1).all(), "id", "name", gt("-- Selecionar --"));
}
public List getListMyApp(int idUser) {
return getListMyApp(idUser, false);
}
public List getListMyApp(int idUser, boolean allInative){
List listApp = new ArrayList<>();
List list = new ArrayList<>();
if(Core.getCurrentUser().getEmail().compareTo("[email protected] ")==0) {//User master
list = new Profile().find()
.andWhere("type", "=", "ENV")
//.groupBy("type_fk")
.all();
}else {
Profile p = new Profile();
list = p.find()
.andWhere("type", "=", "ENV")
.andWhere("user", "=", idUser)
.andWhere("type_fk", ">", 3) // Oculta IGRP Core,IGRP Tutorial,Oculta IGRP Studio
.all();
}
if(!list.isEmpty()){
list=list.stream()
.filter(distinctByKey(p -> p.getType_fk()))
.collect(Collectors.toList());
list.sort(Comparator.comparing(Profile::getType_fk));
if(allInative) {
list.stream().peek(e->listApp.add(e.getProfileType().getApplication()))
.collect(Collectors.toList());
}else {
list.stream().filter(profile->profile.getOrganization().getApplication().getStatus()==1)
.peek(e->listApp.add(e.getProfileType().getApplication()))
.collect(Collectors.toList());
}
listApp.sort(Comparator.comparing(Application::getId).reversed());
}
return listApp;
}
public boolean getPermissionApp(String dad) {
User u = (User) Core.getCurrentUser();
Profile p = new Profile().find()
.andWhere("type", "=", "ENV")
.andWhere("user", "=", u.getId())
.andWhere("type_fk", "=",Core.findApplicationByDad(dad).getId())
.one() ;
return p != null;
}
public List getMyApp() {
User u = (User) Core.getCurrentUser();
List list = new Profile().find()
.andWhere("type", "=", "ENV")
.andWhere("user", "=", u.getId())
.andWhere("type_fk", ">", 1).all();
list=list.stream()
.filter(distinctByKey(p -> p.getType_fk()))
.collect(Collectors.toList());
list.sort(Comparator.comparing(Profile::getType_fk));
return list;
}
public List getMyAppByEmail(String email) {
List list = new Profile().find()
.andWhere("type", "=", "ENV")
.andWhere("user.email", "=", email)
.andWhere("type_fk", ">", 1).all();
if(list!=null && !list.isEmpty()) {
list=list.stream()
.filter(distinctByKey(p -> p.getType_fk()))
.collect(Collectors.toList());
list.sort(Comparator.comparing(Profile::getType_fk));
return list;
}
return null;
}
public List getAllProfile(String dad) {
List list = new Profile().find()
.andWhere("type", "=", "ENV")
.andWhere("type_fk", ">", 1)
.andWhere("organization.application.dad", "=", dad)
.all();
return list;
}
public List getAllUsers(String dad) {
List list = this.getAllProfile(dad);
List users = null;
if(list != null)
users = list.stream().filter(p->p.getUser() != null && !p.getUser().getUser_name().equals("root")).map(m->m.getUser()).distinct().collect(Collectors.toList());
return users;
}
public List getUsersByIds(String dad, Integer[] ids) {
List users = null;
if (ids != null && ids.length > 0) {
Predicate super User> predicate = u -> Arrays.stream(ids).anyMatch(e -> e.equals(u.getId()));
users = Optional.ofNullable(this.getAllUsers(dad))
.orElse(new ArrayList())
.stream()
.filter(predicate)
.collect(Collectors.toList());
}
return users != null && !users.isEmpty() ? users : null;
}
public static Predicate distinctByKey(Function super T, ?> keyExtractor)
{
Map map = new ConcurrentHashMap<>();
return t -> map.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
}
public List getOtherApp() {
List list = this.find().andWhere("id", "<>", 1).andWhere("status", "=", 1).all();
return list;
}
@Override
public Application insert() {
this.setStatus(1);
Application app = super.insert();
if (app != null) {
User user = new User();
user = user.findOne(Core.getCurrentUser().getIdentityId());
Organization org = new Organization();
org.setCode("Org." + app.getDad());
org.setName("IGRP"); // + app.getName()
org.setUser(user);
org.setApplication(app);
org.setStatus(1);
org = org.insert();
if (org != null) {
ProfileType proty = new ProfileType();
proty.setCode("admin." + app.getDad());
proty.setDescr("Admin");
proty.setOrganization(org);
proty.setApplication(app);
proty.setStatus(1);
proty = proty.insert();
if (proty != null) {
Profile p1 = new Profile(app.getId(), "ENV", proty, user, org);
p1.insert();
Profile p2 = new Profile(proty.getId(), "PROF", proty, user, org);
p2.insert();
}
ProfileType proty2 = new ProfileType();
proty2.setCode("user." + app.getDad());
proty2.setDescr("User");
proty2.setOrganization(org);
proty2.setApplication(app);
proty2.setStatus(1);
proty2 = proty2.insert();
if (proty2 != null) {
Profile p2 = new Profile(proty2.getId(), "PROF", proty2, user, org);
p2.insert();
}
// Organization - Access Management (Gestão de acesso) is ID 10,
new Profile(10, "MEN", new ProfileType().getProfileAdmin(), new User().getUserAdmin(), org).insert();
// Profile/Perfil - Access Management (Gestão de acesso) is ID 10, ignores USER
// by using 0 to facilitates delete
new Profile(10, "MEN", proty, new User().getUserAdmin(), org).insert();
//
}
}
return app;
}
public Application insertOnly() {
return super.insert();
}
public Application findByDad(String dad) {
return new Application().find().andWhere("dad", "=", dad).one();
}
public int getExterno() {
return externo;
}
public void setExterno(int externo) {
this.externo = externo;
}
public String getPlsql_code() {
return plsql_code;
}
public void setPlsql_code(String plsql_code) {
this.plsql_code = plsql_code;
}
public LinkedHashMap getAtivesEstadoRegisto() {
LinkedHashMap m = new LinkedHashMap();
m.put(null, "--- Selecionar ---");
m.put("1", "Externo");
m.put("2", "Custom host folder");
return m;
}
}