提交 481b7c67 编写于 作者: Z zhourui

x_processplatform_assemble_designer fixed

上级 1f1dab7e
package com.x.processplatform.assemble.designer.content.factory;
import java.util.List;
import java.util.stream.Collectors;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
......@@ -45,7 +46,8 @@ public class WorkCompletedFactory extends AbstractFactory {
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<WorkCompleted> root = cq.from(WorkCompleted.class);
Predicate p = cb.equal(root.get(WorkCompleted_.application), applicationId);
return em.createQuery(cq.select(root.get(WorkCompleted_.job)).where(p).distinct(true)).getResultList();
return em.createQuery(cq.select(root.get(WorkCompleted_.job)).where(p)).getResultList().stream().distinct()
.collect(Collectors.toList());
}
public List<String> listJobWithProcess(String processId) throws Exception {
......@@ -54,6 +56,7 @@ public class WorkCompletedFactory extends AbstractFactory {
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<WorkCompleted> root = cq.from(WorkCompleted.class);
Predicate p = cb.equal(root.get(WorkCompleted_.process), processId);
return em.createQuery(cq.select(root.get(WorkCompleted_.job)).where(p).distinct(true)).getResultList();
return em.createQuery(cq.select(root.get(WorkCompleted_.job)).where(p)).getResultList().stream().distinct()
.collect(Collectors.toList());
}
}
\ No newline at end of file
package com.x.processplatform.assemble.designer.content.factory;
import java.util.List;
import java.util.stream.Collectors;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
......@@ -45,7 +46,8 @@ public class WorkFactory extends AbstractFactory {
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<Work> root = cq.from(Work.class);
Predicate p = cb.equal(root.get(Work_.application), applicationId);
return em.createQuery(cq.select(root.get(Work_.job)).where(p).distinct(true)).getResultList();
return em.createQuery(cq.select(root.get(Work_.job)).where(p)).getResultList().stream().distinct()
.collect(Collectors.toList());
}
public List<String> listJobWithProcess(String processId) throws Exception {
......@@ -54,6 +56,7 @@ public class WorkFactory extends AbstractFactory {
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<Work> root = cq.from(Work.class);
Predicate p = cb.equal(root.get(Work_.process), processId);
return em.createQuery(cq.select(root.get(Work_.job)).where(p).distinct(true)).getResultList();
return em.createQuery(cq.select(root.get(Work_.job)).where(p)).getResultList().stream().distinct()
.collect(Collectors.toList());
}
}
......@@ -57,25 +57,7 @@ public class ApplicationFactory extends AbstractFactory {
return em.createQuery(cq).getResultList();
}
// /* 如果是isManager列示所有应用,如果不是则判断权限 */
// public List<String> listApplicationCategoryWithPerson(EffectivePerson
// effectivePerson) throws Exception {
// EntityManager em = this.entityManagerContainer().get(Application.class);
// CriteriaBuilder cb = em.getCriteriaBuilder();
// CriteriaQuery<String> cq = cb.createQuery(String.class);
// Root<Application> root = cq.from(Application.class);
// cq.select(root.get(Application_.applicationCategory)).distinct(true);
// if (!effectivePerson.isManager()) {
// Predicate p = cb.isMember(effectivePerson.getDistinguishedName(),
// root.get(Application_.controllerList));
// p = cb.or(p, cb.equal(root.get(Application_.creatorPerson),
// effectivePerson.getDistinguishedName()));
// cq.where(p);
// }
// return em.createQuery(cq).getResultList();
// }
/* 如果是isManager列示所有应用,如果不是则判断权限 */
// 如果是isManager列示所有应用,如果不是则判断权限
public Long countWithPersonWithApplicationCategory(EffectivePerson effectivePerson, String applicationCategory)
throws Exception {
EntityManager em = this.entityManagerContainer().get(Application.class);
......@@ -88,8 +70,8 @@ public class ApplicationFactory extends AbstractFactory {
cb.or(cb.isMember(effectivePerson.getDistinguishedName(), root.get(Application_.controllerList)),
cb.equal(root.get(Application_.creatorPerson), effectivePerson.getDistinguishedName())));
}
cq.select(root.get(Application_.id)).where(p).distinct(true);
List<String> list = em.createQuery(cq).getResultList();
cq.select(root.get(Application_.id)).where(p);
List<String> list = em.createQuery(cq).getResultList().stream().distinct().collect(Collectors.toList());
return new Long(list.size());
}
......
......@@ -26,8 +26,7 @@ public class ProcessFactory extends AbstractFactory {
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<Process> root = cq.from(Process.class);
Predicate p = cb.equal(root.get(Process_.application), application);
p = cb.and(p, cb.or(cb.isTrue(root.get(Process_.editionEnable)),
cb.isNull(root.get(Process_.editionEnable))));
p = cb.and(p, cb.or(cb.isTrue(root.get(Process_.editionEnable)), cb.isNull(root.get(Process_.editionEnable))));
cq.select(root.get(Process_.id)).where(p);
return em.createQuery(cq).getResultList();
}
......@@ -38,8 +37,7 @@ public class ProcessFactory extends AbstractFactory {
CriteriaQuery<Process> cq = cb.createQuery(Process.class);
Root<Process> root = cq.from(Process.class);
Predicate p = cb.equal(root.get(Process_.application), application);
p = cb.and(p, cb.or(cb.isTrue(root.get(Process_.editionEnable)),
cb.isNull(root.get(Process_.editionEnable))));
p = cb.and(p, cb.or(cb.isTrue(root.get(Process_.editionEnable)), cb.isNull(root.get(Process_.editionEnable))));
cq.select(root).where(p);
return em.createQuery(cq).getResultList();
}
......@@ -74,7 +72,6 @@ public class ProcessFactory extends AbstractFactory {
Predicate p = cb.equal(root.get(Process_.application), application);
p = cb.and(p, cb.isNotNull(root.get(Process_.edition)));
p = cb.and(p, cb.notEqual(root.get(Process_.edition), ""));
Subquery<Process> subquery = cq.subquery(Process.class);
Root<Process> subRoot = subquery.from(Process.class);
Predicate subP = cb.conjunction();
......@@ -82,9 +79,8 @@ public class ProcessFactory extends AbstractFactory {
subP = cb.and(subP, cb.isTrue(subRoot.get(Process_.editionEnable)));
subquery.select(subRoot).where(subP);
p = cb.and(p, cb.not(cb.exists(subquery)));
cq.distinct(true).select(root.get(Process_.edition)).where(p);
return em.createQuery(cq).getResultList();
cq.select(root.get(Process_.edition)).where(p);
return em.createQuery(cq).getResultList().stream().distinct().collect(Collectors.toList());
}
public Process getEnabledProcess(String application, String edition) throws Exception {
......@@ -97,7 +93,7 @@ public class ProcessFactory extends AbstractFactory {
p = cb.and(p, cb.isTrue(root.get(Process_.editionEnable)));
cq.select(root).where(p).orderBy(cb.desc(root.get(Process_.editionNumber)));
List<Process> list = em.createQuery(cq).getResultList();
if(list!=null && !list.isEmpty()){
if (list != null && !list.isEmpty()) {
return list.get(0);
}
return null;
......@@ -110,16 +106,16 @@ public class ProcessFactory extends AbstractFactory {
}
public Double getMaxEditionNumber(String application, String edition) throws Exception {
if (StringUtils.isNotEmpty(edition)){
if (StringUtils.isNotEmpty(edition)) {
EntityManager em = this.entityManagerContainer().get(Process.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Double> cq = cb.createQuery(Double.class);
Root<Process> root = cq.from(Process.class);
Predicate p = cb.equal(root.get(Process_.application), application);
p = cb.and(p,cb.equal(root.get(Process_.edition), edition));
p = cb.and(p, cb.equal(root.get(Process_.edition), edition));
cq.select(cb.max(root.get(Process_.editionNumber))).where(p);
Double max = em.createQuery(cq).getSingleResult();
if(max == null || max < 1.0){
if (max == null || max < 1.0) {
max = 1.0;
}
return max;
......
......@@ -2,6 +2,7 @@ package com.x.processplatform.assemble.designer.jaxrs.elementtool;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
......@@ -49,8 +50,8 @@ class ActionApplicationDictOrphan extends BaseAction {
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<ApplicationDict> root = cq.from(ApplicationDict.class);
Predicate p = cb.not(root.get(ApplicationDict_.application).in(applicationIds));
cq.select(root.get(ApplicationDict_.id)).where(p).distinct(true);
return em.createQuery(cq).getResultList();
cq.select(root.get(ApplicationDict_.id)).where(p);
return em.createQuery(cq).getResultList().stream().distinct().collect(Collectors.toList());
}
private List<String> listOrphanApplicationDictItem(Business business, List<String> applicationDictIds)
......@@ -60,8 +61,8 @@ class ActionApplicationDictOrphan extends BaseAction {
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<ApplicationDictItem> root = cq.from(ApplicationDictItem.class);
Predicate p = cb.not(root.get(ApplicationDictItem_.bundle).in(applicationDictIds));
cq.select(root.get(ApplicationDictItem_.id)).where(p).distinct(true);
return em.createQuery(cq).getResultList();
cq.select(root.get(ApplicationDictItem_.id)).where(p);
return em.createQuery(cq).getResultList().stream().distinct().collect(Collectors.toList());
}
public static class WoApplicationDict extends ApplicationDict {
......
......@@ -2,6 +2,7 @@ package com.x.processplatform.assemble.designer.jaxrs.elementtool;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
......@@ -47,8 +48,8 @@ class ActionFormOrphan extends BaseAction {
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<Form> root = cq.from(Form.class);
Predicate p = cb.not(root.get(Form_.application).in(applicationIds));
cq.select(root.get(Form_.id)).where(p).distinct(true);
return em.createQuery(cq).getResultList();
cq.select(root.get(Form_.id)).where(p);
return em.createQuery(cq).getResultList().stream().distinct().collect(Collectors.toList());
}
private List<String> listOrphanFormField(Business business, List<String> formIds) throws Exception {
......@@ -57,8 +58,8 @@ class ActionFormOrphan extends BaseAction {
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<FormField> root = cq.from(FormField.class);
Predicate p = cb.not(root.get(FormField_.form).in(formIds));
cq.select(root.get(FormField_.id)).where(p).distinct(true);
return em.createQuery(cq).getResultList();
cq.select(root.get(FormField_.id)).where(p);
return em.createQuery(cq).getResultList().stream().distinct().collect(Collectors.toList());
}
public static class WoForm extends Form {
......
......@@ -2,6 +2,7 @@ package com.x.processplatform.assemble.designer.jaxrs.elementtool;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
......@@ -88,8 +89,8 @@ class ActionProcessOrphan extends BaseAction {
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<Process> root = cq.from(Process.class);
Predicate p = cb.not(root.get(Process_.application).in(applicationIds));
cq.select(root.get(Process_.id)).where(p).distinct(true);
return em.createQuery(cq).getResultList();
cq.select(root.get(Process_.id)).where(p);
return em.createQuery(cq).getResultList().stream().distinct().collect(Collectors.toList());
}
private <T extends JpaObject, W> List<String> listOrphanProcessElement(Business business, List<String> processIds,
......@@ -99,8 +100,8 @@ class ActionProcessOrphan extends BaseAction {
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<T> root = cq.from(copier.getOrigClass());
Predicate p = cb.not(root.get(Agent.process_FIELDNAME).in(processIds));
cq.select(root.get(JpaObject.id_FIELDNAME)).where(p).distinct(true);
return em.createQuery(cq).getResultList();
cq.select(root.get(JpaObject.id_FIELDNAME)).where(p);
return em.createQuery(cq).getResultList().stream().distinct().collect(Collectors.toList());
}
public static class WoProcess extends Process {
......
......@@ -2,6 +2,7 @@ package com.x.processplatform.assemble.designer.jaxrs.elementtool;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
......@@ -43,8 +44,8 @@ class ActionScriptOrphan extends BaseAction {
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<Script> root = cq.from(Script.class);
Predicate p = cb.not(root.get(Script_.application).in(applicationIds));
cq.select(root.get(Script_.id)).where(p).distinct(true);
return em.createQuery(cq).getResultList();
cq.select(root.get(Script_.id)).where(p);
return em.createQuery(cq).getResultList().stream().distinct().collect(Collectors.toList());
}
public static class WoScript extends Script {
......
......@@ -24,8 +24,8 @@ abstract class BaseAction extends StandardJaxrsAction {
// protected Ehcache inputCache = ApplicationCache.instance().getCache(BaseAction.class.getName(), 100,
// ApplicationCache.MINUTES_20, ApplicationCache.MINUTES_20);
protected CacheCategory cacheCategory= new CacheCategory(BaseAction.class);
protected CacheCategory cacheCategory = new CacheCategory(BaseAction.class);
public enum Method {
cover, create, ignore;
......@@ -51,7 +51,7 @@ abstract class BaseAction extends StandardJaxrsAction {
CriteriaQuery<Application> cq = cb.createQuery(Application.class);
Root<Application> root = cq.from(Application.class);
Predicate p = cb.equal(root.get(Application_.alias), alias);
List<Application> os = em.createQuery(cq.select(root).where(p).distinct(true)).getResultList();
List<Application> os = em.createQuery(cq.select(root).where(p)).getResultList();
if (os.size() == 1) {
return os.get(0);
} else {
......@@ -68,7 +68,7 @@ abstract class BaseAction extends StandardJaxrsAction {
CriteriaQuery<Application> cq = cb.createQuery(Application.class);
Root<Application> root = cq.from(Application.class);
Predicate p = cb.equal(root.get(Application_.name), name);
List<Application> os = em.createQuery(cq.select(root).where(p).distinct(true)).getResultList();
List<Application> os = em.createQuery(cq.select(root).where(p)).getResultList();
if (os.size() == 1) {
return os.get(0);
} else {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册