Java Code Examples for javax.persistence.criteria.CriteriaBuilder#isMember()
The following examples show how to use
javax.persistence.criteria.CriteriaBuilder#isMember() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ActionGet.java From o2oa with GNU Affero General Public License v3.0 | 6 votes |
private void referenceGroup(Business business, Wo wo) throws Exception { EntityManager em = business.entityManagerContainer().get(Group.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Group> cq = cb.createQuery(Group.class); Root<Group> root = cq.from(Group.class); Predicate p = cb.isMember(wo.getId(), root.get(Group_.personList)); List<Group> os = em.createQuery(cq.select(root).where(p)).getResultList(); ListOrderedSet<Group> set = new ListOrderedSet<>(); os.stream().forEach(o -> { set.add(o); try { set.addAll(business.group().listSupNestedObject(o)); } catch (Exception e) { e.printStackTrace(); } }); List<WoGroup> wos = WoGroup.copier.copy(set.asList()); wos = business.group().sort(wos); wo.setWoGroupList(wos); }
Example 2
Source File: ActionGet.java From o2oa with GNU Affero General Public License v3.0 | 6 votes |
private void referenceGroup(Business business, Wo wo) throws Exception { EntityManager em = business.entityManagerContainer().get(Group.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Group> cq = cb.createQuery(Group.class); Root<Group> root = cq.from(Group.class); Predicate p = cb.isMember(wo.getId(), root.get(Group_.personList)); List<Group> os = em.createQuery(cq.select(root).where(p)).getResultList(); ListOrderedSet<Group> set = new ListOrderedSet<>(); os.stream().forEach(o -> { set.add(o); try { set.addAll(business.group().listSupNestedObject(o)); } catch (Exception e) { e.printStackTrace(); } }); List<WoGroup> wos = WoGroup.copier.copy(set.asList()); wos = business.group().sort(wos); wo.setWoGroupList(wos); }
Example 3
Source File: CategoryInfoFactory.java From o2oa with GNU Affero General Public License v3.0 | 6 votes |
/** * 查询指定用户,组织,群组可以管理的分类列表 * @param personName * @param unitNames * @param groupNames * @param inAppInfoIds * @return * @throws Exception */ public List<String> listManageableCategoryIds( String personName, List<String> unitNames, List<String> groupNames, List<String> inAppInfoIds, String documentType, Integer maxCount ) throws Exception { EntityManager em = this.entityManagerContainer().get(CategoryInfo.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<String> cq = cb.createQuery(String.class); Root<CategoryInfo> root = cq.from(CategoryInfo.class); Predicate p = cb.isMember( personName, root.get( CategoryInfo_.manageablePersonList )); if( ListTools.isNotEmpty( inAppInfoIds )) { p = cb.and( p, root.get( CategoryInfo_.appId ).in( inAppInfoIds ) ); } if( ListTools.isNotEmpty( unitNames )) { p = cb.or( p, root.get( CategoryInfo_.manageableUnitList).in(unitNames)); } if( ListTools.isNotEmpty( groupNames )) { p = cb.or( p, root.get( CategoryInfo_.manageableGroupList).in(groupNames)); } cq.select(root.get( CategoryInfo_.id )); if( StringUtils.isNotEmpty( documentType) && !"全部".equals(documentType) && !"all".equalsIgnoreCase(documentType)) { p = cb.and( p, cb.equal( root.get( CategoryInfo_.documentType), documentType)); } return em.createQuery( cq.where( p ) ).setMaxResults(maxCount).getResultList(); }
Example 4
Source File: ShareFactory.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
public List<String> listWithShareOrg1(String org, String fileType) throws Exception { EntityManager em = this.entityManagerContainer().get(Share.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<String> cq = cb.createQuery(String.class); Root<Share> root = cq.from(Share.class); Predicate p = cb.isMember(org, root.get(Share_.shareOrgList)); if(StringUtils.isNotBlank(fileType)){ p = cb.and(p, cb.equal(root.get(Share_.fileType), fileType)); } cq.select(root.get(Share_.id)).where(p); return em.createQuery(cq).getResultList(); }
Example 5
Source File: RoleFactory.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
public List<String> listWithPerson(String id) throws Exception { EntityManager em = this.entityManagerContainer().get(Role.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<String> cq = cb.createQuery(String.class); Root<Role> root = cq.from(Role.class); Predicate p = cb.isMember(id, root.get(Role_.personList)); cq.select(root.get(Role_.id)).where(p); return em.createQuery(cq).getResultList(); }
Example 6
Source File: ActionHasRole.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
private Wo get(Business business, Wi wi) throws Exception { Wo wo = new Wo(); wo.setValue(false); if (StringUtils.isEmpty(wi.getPerson()) || ListTools.isEmpty(wi.getRoleList())) { return wo; } Person person = business.person().pick(wi.getPerson()); if (null == person) { return wo; } List<Role> roles = business.role().pick(wi.getRoleList()); if (ListTools.isEmpty(roles)) { return wo; } List<String> groupIds = new ArrayList<>(); groupIds.addAll(business.group().listSupNestedWithPerson(person.getId())); groupIds = ListTools.trim(groupIds, true, true); EntityManager em = business.entityManagerContainer().get(Role.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<String> cq = cb.createQuery(String.class); Root<Role> root = cq.from(Role.class); Predicate p = cb.isMember(person.getId(), root.get(Role_.personList)); p = cb.or(p, root.get(Role_.groupList).in(groupIds)); List<String> os = em.createQuery(cq.select(root.get(Role_.id)).where(p).distinct(true)).getResultList(); boolean value = ListTools.containsAny(os, ListTools.extractProperty(roles, JpaObject.id_FIELDNAME, String.class, true, true)); wo.setValue(value); return wo; }
Example 7
Source File: AttachmentFactory.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
public Long countWithPersonWithShare(String owner, String person) throws Exception { EntityManager em = this.entityManagerContainer().get(Attachment.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Long> cq = cb.createQuery(Long.class); Root<Attachment> root = cq.from(Attachment.class); Predicate p = cb.isMember(person, root.get(Attachment_.shareList)); p = cb.and(p, cb.equal(root.get(Attachment_.person), owner)); cq.select(cb.count(root)).where(p); return em.createQuery(cq).getSingleResult(); }
Example 8
Source File: MeetingFactory.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
public List<String> listWithInvitedRejected(String person) throws Exception { EntityManager em = this.entityManagerContainer().get(Meeting.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<String> cq = cb.createQuery(String.class); Root<Meeting> root = cq.from(Meeting.class); Predicate p = cb.isMember(person, root.get(Meeting_.invitePersonList)); p = cb.and(p, cb.isMember(person, root.get(Meeting_.rejectPersonList))); p = cb.and(p, cb.lessThan(root.get(Meeting_.completedTime), new Date())); cq.select(root.get(Meeting_.id)).where(p); return em.createQuery(cq).getResultList(); }
Example 9
Source File: MeetingFactory.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
public List<String> listWithInvitedProcessing(String person) throws Exception { EntityManager em = this.entityManagerContainer().get(Meeting.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<String> cq = cb.createQuery(String.class); Root<Meeting> root = cq.from(Meeting.class); Date date = new Date(); Predicate p = cb.isMember(person, root.get(Meeting_.invitePersonList)); p = cb.and(p, cb.notEqual(root.get(Meeting_.manualCompleted), true)); p = cb.and(p, cb.lessThanOrEqualTo(root.get(Meeting_.startTime), date)); p = cb.and(p, cb.greaterThanOrEqualTo(root.get(Meeting_.completedTime), date)); cq.select(root.get(Meeting_.id)).where(p); return em.createQuery(cq).getResultList(); }
Example 10
Source File: MeetingFactory.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
public List<String> listWithInvitedWait(String person) throws Exception { EntityManager em = this.entityManagerContainer().get(Meeting.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<String> cq = cb.createQuery(String.class); Root<Meeting> root = cq.from(Meeting.class); Predicate p = cb.isMember(person, root.get(Meeting_.invitePersonList)); p = cb.and(p, cb.notEqual(root.get(Meeting_.manualCompleted), true)); p = cb.and(p, cb.greaterThan(root.get(Meeting_.startTime), new Date())); cq.select(root.get(Meeting_.id)).where(p); return em.createQuery(cq).getResultList(); }
Example 11
Source File: ActionDelete.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
private void checkDepended(Business business, Script script) throws Exception { EntityManager em = business.entityManagerContainer().get(Script.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Script> cq = cb.createQuery(Script.class); Root<Script> root = cq.from(Script.class); Predicate p = cb.isMember(script.getId(), root.get(Script_.dependScriptList)); p = cb.and(p, cb.equal(root.get(Script_.portal), script.getPortal())); List<Script> list = em.createQuery(cq.select(root).where(p)).getResultList(); if (!list.isEmpty()) { List<String> names = ListTools.extractProperty(list, "name", String.class, true, false); throw new DependedException(script.getName(), script.getId(), StringUtils.join(names, ",")); } }
Example 12
Source File: ApplicationFactory.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
public List<String> listWithPerson(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_.id)); if (effectivePerson.isNotManager() && (!this.business().organization().person().hasRole(effectivePerson, OrganizationDefinition.Manager, OrganizationDefinition.ProcessPlatformManager))) { 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(); }
Example 13
Source File: ActionListWithUnitWithType.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
private List<Wo> listWithUnitWithType(EffectivePerson effectivePerson, Business business, Wi wi) throws Exception { List<Wo> wos = new ArrayList<>(); List<String> unitIds = new ArrayList<>(); for (Unit o : business.unit().pick(wi.getUnitList())) { if (null != o) { unitIds.add(o.getId()); } } if (ListTools.isEmpty(unitIds)) { return wos; } List<String> expendUnitIds = business.expendUnitToUnit(unitIds); /** 搜索范围不包含自己 */ expendUnitIds.removeAll(unitIds); EntityManager em = business.entityManagerContainer().get(Unit.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<String> cq = cb.createQuery(String.class); Root<Unit> root = cq.from(Unit.class); Predicate p = cb.isMember(wi.getType(), root.get(Unit_.typeList)); p = cb.and(p, root.get(Unit_.id).in(expendUnitIds)); List<String> os = em.createQuery(cq.select(root.get(Unit_.id)).where(p).distinct(true)).getResultList(); List<String> referenceUnitIds = new ArrayList<String>(os); for (String str : os) { referenceUnitIds.addAll(business.unit().listSupNested(str)); } referenceUnitIds = ListTools.trim(referenceUnitIds, true, true); List<Wo> list = Wo.copier.copy(business.entityManagerContainer().list(Unit.class, referenceUnitIds)); list = business.unit().sort(list); this.format(list); for (Wo wo : list) { if (unitIds.contains(wo.getId())) { wos.add(wo); } } return wos; }
Example 14
Source File: ActionDelete.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
private void removeRoleMember(Business business, Group group) throws Exception { EntityManager em = business.entityManagerContainer().get(Role.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Role> cq = cb.createQuery(Role.class); Root<Role> root = cq.from(Role.class); Predicate p = cb.isMember(group.getId(), root.get(Role_.groupList)); List<Role> os = em.createQuery(cq.select(root).where(p)).getResultList(); for (Role o : os) { o.getGroupList().remove(group.getId()); } }
Example 15
Source File: ActionHasRole.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
private Wo get(Business business, Wi wi) throws Exception { Wo wo = new Wo(); wo.setValue(false); if (StringUtils.isEmpty(wi.getPerson()) || ListTools.isEmpty(wi.getRoleList())) { return wo; } Person person = business.person().pick(wi.getPerson()); if (null == person) { return wo; } List<Role> roles = business.role().pick(wi.getRoleList()); if (ListTools.isEmpty(roles)) { return wo; } List<String> groupIds = new ArrayList<>(); groupIds.addAll(business.group().listSupNestedWithPerson(person.getId())); groupIds = ListTools.trim(groupIds, true, true); EntityManager em = business.entityManagerContainer().get(Role.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<String> cq = cb.createQuery(String.class); Root<Role> root = cq.from(Role.class); Predicate p = cb.isMember(person.getId(), root.get(Role_.personList)); p = cb.or(p, root.get(Role_.groupList).in(groupIds)); List<String> os = em.createQuery(cq.select(root.get(Role_.id)).where(p).distinct(true)).getResultList(); boolean value = ListTools.containsAny(os, ListTools.extractProperty(roles, JpaObject.id_FIELDNAME, String.class, true, true)); wo.setValue(value); return wo; }
Example 16
Source File: AttachmentFactory.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
public List<String> listPersonWithEditor(String person) throws Exception { EntityManager em = this.entityManagerContainer().get(Attachment.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<String> cq = cb.createQuery(String.class); Root<Attachment> root = cq.from(Attachment.class); Predicate p = cb.isMember(person, root.get(Attachment_.editorList)); cq.distinct(true).select(root.get(Attachment_.person)).where(p); return em.createQuery(cq).getResultList(); }
Example 17
Source File: AttachmentFactory.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
public Long countWithPersonWithEditor(String owner, String person) throws Exception { EntityManager em = this.entityManagerContainer().get(Attachment.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Long> cq = cb.createQuery(Long.class); Root<Attachment> root = cq.from(Attachment.class); Predicate p = cb.isMember(person, root.get(Attachment_.editorList)); p = cb.and(p, cb.equal(root.get(Attachment_.person), owner)); cq.select(cb.count(root)).where(p); return em.createQuery(cq).getSingleResult(); }
Example 18
Source File: GroupFactory.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
public List<String> listSupDirectWithPerson(String id) throws Exception { EntityManager em = this.entityManagerContainer().get(Group.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<String> cq = cb.createQuery(String.class); Root<Group> root = cq.from(Group.class); Predicate p = cb.isMember(id, root.get(Group_.personList)); cq.select(root.get(Group_.id)).where(p); return em.createQuery(cq).getResultList(); }
Example 19
Source File: AppInfoFactory.java From o2oa with GNU Affero General Public License v3.0 | 4 votes |
/** * 根据权限查询用户可以发布文档的栏目ID列表(不检测allPeopleView 和 allPeoplePublish ) * * @param personName * @param unitNames * @param groupNames * @param inAppInfoIds * - 栏目ID的最大范围 * @param excludAppInfoIds * - 需要排队的栏目ID * @return * @throws Exception */ public List<String> listPublishableAppIdsInPermission(String personName, List<String> unitNames, List<String> groupNames, List<String> inAppInfoIds, List<String> excludAppInfoIds, String documentType, Integer maxCount) throws Exception { EntityManager em = this.entityManagerContainer().get(AppInfo.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<String> cq = cb.createQuery(String.class); Root<AppInfo> root = cq.from(AppInfo.class); Predicate p = null; Predicate p_filter = null; // 限定范围 if (ListTools.isNotEmpty(inAppInfoIds)) { p_filter = root.get(AppInfo_.id).in(inAppInfoIds); } // 排队指定的ID列表 if (ListTools.isNotEmpty(excludAppInfoIds)) { if (p_filter == null) { p_filter = cb.not(root.get(AppInfo_.id).in(excludAppInfoIds)); } else { p_filter = cb.and(p_filter, cb.not(root.get(AppInfo_.id).in(excludAppInfoIds))); } } Predicate p_permission = null; if (StringUtils.isNotEmpty(personName)) { // 可以管理的栏目,肯定可以发布信息 p_permission = cb.isMember(personName, root.get(AppInfo_.manageablePersonList)); p_permission = cb.or(p_permission, cb.isMember(personName, root.get(AppInfo_.publishablePersonList))); } if (ListTools.isNotEmpty(unitNames)) { p_permission = cb.or(p_permission, root.get(AppInfo_.publishableUnitList).in(unitNames)); } if (ListTools.isNotEmpty(groupNames)) { p_permission = cb.or(p_permission, root.get(AppInfo_.publishableGroupList).in(groupNames)); } // 使用新的条件将两个条件组合起来 if (p_filter != null) { p = p_filter; } if (p != null) { if (p_permission != null) { p = cb.and(p, p_permission); } } else { if (p_permission != null) { p = p_permission; } } if (StringUtils.isNotEmpty(documentType) && !"全部".equals(documentType) && !"all".equalsIgnoreCase(documentType)) { p = cb.and(p, cb.equal(root.get(AppInfo_.documentType), documentType)); } cq.select(root.get(AppInfo_.id)); return em.createQuery(cq.where(p)).setMaxResults(maxCount).getResultList(); }
Example 20
Source File: CategoryInfoFactory.java From o2oa with GNU Affero General Public License v3.0 | 4 votes |
/** * 根据权限查询用户可以发布文档的分类ID列表(根据权限, 不检测allPeopleView和allPeoplePublish) * 可管理的分类也属于可发布的分类 * @param personName * @param unitNames * @param groupNames * @param inAppInfoIds - 需要限定的栏目ID列表 * @param inCategoryIds - 栏目ID的最大范围 * @param excludCategoryIds - 需要排除的栏目ID * @return * @throws Exception */ public List<String> listPublishableCategoryInfoIdsWithPermission(String personName, List<String> unitNames, List<String> groupNames, List<String> inAppInfoIds, List<String> inCategoryIds, List<String> excludCategoryIds, String documentType, Integer maxCount ) throws Exception { EntityManager em = this.entityManagerContainer().get(CategoryInfo.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<String> cq = cb.createQuery(String.class); Root<CategoryInfo> root = cq.from(CategoryInfo.class); Predicate p = null; Predicate p_filter = null; //限定栏目范围 if( ListTools.isNotEmpty( inAppInfoIds )) { p_filter = root.get( CategoryInfo_.appId ).in( inAppInfoIds ); } //限定范围 if( ListTools.isNotEmpty( inCategoryIds )) { if( p_filter == null ) { p_filter = root.get( CategoryInfo_.id ).in( inCategoryIds ); }else { p_filter = cb.and( p_filter, root.get( CategoryInfo_.id ).in( inCategoryIds )); } } //排除指定的ID列表 if( ListTools.isNotEmpty( excludCategoryIds )) { if( p_filter == null ) { p_filter = cb.not( root.get( CategoryInfo_.id ).in( excludCategoryIds )); }else { p_filter = cb.and( p_filter, cb.not( root.get( CategoryInfo_.id ).in( excludCategoryIds ))); } } Predicate p_permission = null; if( StringUtils.isNotEmpty( personName )) { //可以管理的栏目,肯定可以发布信息 p_permission = cb.isMember( personName, root.get( CategoryInfo_.manageablePersonList )); p_permission = cb.or( p_permission, cb.isMember( personName, root.get( CategoryInfo_.publishablePersonList ))); } if( ListTools.isNotEmpty( unitNames )) { if( p_permission == null ) { p_permission = root.get( CategoryInfo_.publishableUnitList).in(unitNames); }else { p_permission = cb.or( p_permission, root.get( CategoryInfo_.publishableUnitList).in(unitNames)); } } if( ListTools.isNotEmpty( groupNames )) { if( p_permission == null ) { p_permission = root.get( CategoryInfo_.publishableGroupList).in(groupNames); }else { p_permission = cb.or( p_permission, root.get( CategoryInfo_.publishableGroupList).in(groupNames)); } } //使用新的条件将两个条件组合起来 if( p_filter != null ) { p = p_filter; } if( p != null ) { if( p_permission != null ) { p = cb.and(p, p_permission); } }else { if( p_permission != null ) { p = p_permission; } } if( StringUtils.isNotEmpty( documentType) && !"全部".equals(documentType)&& !"all".equalsIgnoreCase(documentType)) { p = cb.and( p, cb.equal( root.get( CategoryInfo_.documentType), documentType)); } cq.select(root.get( CategoryInfo_.id )); return em.createQuery( cq.where( p ) ).setMaxResults(maxCount).getResultList(); }