Java Code Examples for javax.persistence.criteria.CriteriaBuilder#isTrue()

The following examples show how to use javax.persistence.criteria.CriteriaBuilder#isTrue() . 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: CmsPermissionService.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 查询所有未设置发布权限的AppInfo的ID列表( with List copy ) 判断 allPeoplePublish
 * 
 * @param emc
 * @return
 * @throws Exception
 */
private List<String> listAllPeoplePublishAppIds(EntityManagerContainer emc, String documentType, String appType) throws Exception {
	List<String> appInfoIds = null;
	List<String> appInfoIds_out = new ArrayList<>();
	EntityManager em = emc.get(AppInfo.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<AppInfo> root = cq.from(AppInfo.class);
	cq.select(root.get(AppInfo.id_FIELDNAME));
	Predicate p = cb.isTrue(root.get(AppInfo.allPeoplePublish_FIELDNAME));
	if( StringUtils.isNotEmpty( appType ) && !"all".equalsIgnoreCase( appType ) && !"全部".equalsIgnoreCase( appType )  ){
		p = CriteriaBuilderTools.predicate_and(cb, p, cb.equal(root.get(AppInfo.appType_FIELDNAME), appType));
	}
	if (StringUtils.isNotEmpty(documentType) && !"全部".equals(documentType) && !"all".equalsIgnoreCase(documentType)) {
		p = cb.and(p, cb.equal(root.get(AppInfo.documentType_FIELDNAME), documentType));
	}
	appInfoIds = em.createQuery(cq.where(p)).getResultList();
	if (appInfoIds == null) {
		appInfoIds = new ArrayList<>();
	}
	appInfoIds_out.addAll(appInfoIds);
	return appInfoIds_out;
}
 
Example 2
Source File: CmsPermissionService.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 查询所有未设置可见权限的AppInfo的ID列表( with List copy ) 全员可发布的栏目也包含在内:判断allPeopleView or
 * allPeoplePublish
 * 
 * @return
 * @throws Exception
 */
private List<String> listAllPeopleViewAppIds(EntityManagerContainer emc, String documentType, String appType ) throws Exception {
	List<String> appInfoIds = null;
	List<String> appInfoIds_out = new ArrayList<>();
	EntityManager em = emc.get(AppInfo.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<AppInfo> root = cq.from(AppInfo.class);
	cq.select(root.get(AppInfo.id_FIELDNAME));

	Predicate p = cb.isTrue(root.get(AppInfo.allPeopleView_FIELDNAME));
	if( StringUtils.isNotEmpty( appType ) && !"all".equalsIgnoreCase( appType ) && !"全部".equalsIgnoreCase( appType )   ){
		p = CriteriaBuilderTools.predicate_and(cb, p, cb.equal(root.get(AppInfo.appType_FIELDNAME), appType));
	}
	if (StringUtils.isNotEmpty(documentType) && !"全部".equals(documentType) && !"all".equalsIgnoreCase(documentType)) {
		p = CriteriaBuilderTools.predicate_and(cb, p, cb.equal(root.get(AppInfo.documentType_FIELDNAME), documentType));
	}
	appInfoIds = em.createQuery(cq.where(p)).getResultList();
	if (appInfoIds == null) {
		appInfoIds = new ArrayList<>();
	}
	appInfoIds_out.addAll(appInfoIds);
	return appInfoIds_out;
}
 
Example 3
Source File: CategoryInfoFactory.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 查询所有用户都可以发布的分类ID列表
 * @param inAppInfoIds
 * @param inCategoryIds
 * @param excludCategoryIds
 * @return
 * @throws Exception 
 */
public List<String> listAllPeoplePublishableCategoryInfoIds(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);
	cq.select(root.get(CategoryInfo_.id));
	Predicate p = cb.isTrue( root.get( CategoryInfo_.allPeoplePublish ) );
	if( ListTools.isNotEmpty( inAppInfoIds )) {
		p = cb.and( p,  root.get( CategoryInfo_.appId ).in( inAppInfoIds ) );
	}
	if( ListTools.isNotEmpty( inCategoryIds )) {
		p = cb.and( p, root.get( CategoryInfo_.id ).in( inCategoryIds ));
	}
	if( ListTools.isNotEmpty( excludCategoryIds )) {
		p = cb.and( p, cb.not( root.get( CategoryInfo_.id ).in( excludCategoryIds )));
	}
	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: BBSSubjectInfoFactory.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
public List<BBSSubjectInfo> listRecommendedSubjectForBBSIndex( List<String> forumIds, List<String> mainSectionIds, List<String> sectionIds, Integer count ) throws Exception {
	if( count == null ){
		count = 10;
	}
	EntityManager em = this.entityManagerContainer().get(BBSSubjectInfo.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<BBSSubjectInfo> cq = cb.createQuery(BBSSubjectInfo.class);
	Root<BBSSubjectInfo> root = cq.from(BBSSubjectInfo.class);
	Predicate p = cb.isTrue( root.get( BBSSubjectInfo_.recommendToBBSIndex ) );
	if( ListTools.isNotEmpty( forumIds ) ){
		p = cb.and( p, root.get( BBSSubjectInfo_.forumId ).in( forumIds ) );
	}
	if( ListTools.isNotEmpty( mainSectionIds ) ){
		p = cb.and( p, root.get( BBSSubjectInfo_.mainSectionId ).in( mainSectionIds ) );
	}
	if( ListTools.isNotEmpty( sectionIds ) ){
		p = cb.and( p, root.get( BBSSubjectInfo_.sectionId ).in( sectionIds ) );
	}
	cq.orderBy( cb.desc( root.get( BBSSubjectInfo_.updateTime ) ) );
	return em.createQuery(cq.where(p)).setMaxResults( count ).getResultList();
}
 
Example 5
Source File: BBSSubjectInfoFactory.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
public List<BBSSubjectInfo> listRecommendedSubjectForForumIndex( List<String> forumIds, List<String> mainSectionIds, List<String> sectionIds, Integer count) throws Exception {
	if( count == null ){
		count = 10;
	}
	EntityManager em = this.entityManagerContainer().get(BBSSubjectInfo.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<BBSSubjectInfo> cq = cb.createQuery(BBSSubjectInfo.class);
	Root<BBSSubjectInfo> root = cq.from(BBSSubjectInfo.class);
	Predicate p = cb.isTrue( root.get( BBSSubjectInfo_.recommendToForumIndex ) );
	if( ListTools.isNotEmpty( forumIds ) ){
		p = cb.and( p, root.get( BBSSubjectInfo_.forumId ).in( forumIds ) );
	}
	if( ListTools.isNotEmpty( mainSectionIds ) ){
		p = cb.and( p, root.get( BBSSubjectInfo_.mainSectionId ).in( mainSectionIds ) );
	}
	if( ListTools.isNotEmpty( sectionIds ) ){
		p = cb.and( p, root.get( BBSSubjectInfo_.sectionId ).in( sectionIds ) );
	}
	cq.orderBy( cb.desc( root.get( BBSSubjectInfo_.updateTime ) ) );
	return em.createQuery(cq.where(p)).setMaxResults( count ).getResultList();
}
 
Example 6
Source File: BBSSubjectInfoFactory.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
public List<BBSSubjectInfo> listCreamedSubjectInSectionForPage( String forumId, String mainSectionId, String sectionId, String creatorName, Integer count ) throws Exception {
	if( count == null ){
		count = 10;
	}
	EntityManager em = this.entityManagerContainer().get(BBSSubjectInfo.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<BBSSubjectInfo> cq = cb.createQuery(BBSSubjectInfo.class);
	Root<BBSSubjectInfo> root = cq.from(BBSSubjectInfo.class);
	Predicate p = cb.isTrue( root.get( BBSSubjectInfo_.isCreamSubject ) );
	if( StringUtils.isNotEmpty( forumId ) ){
		p = cb.and( p, cb.equal( root.get( BBSSubjectInfo_.forumId ), forumId ) );
	}
	if( StringUtils.isNotEmpty( mainSectionId ) ){
		p = cb.and( p, cb.equal( root.get( BBSSubjectInfo_.mainSectionId ), mainSectionId ) );
	}
	if( StringUtils.isNotEmpty( sectionId ) ){
		p = cb.and( p, cb.equal( root.get( BBSSubjectInfo_.sectionId ), sectionId ) );
	}
	if( StringUtils.isNotEmpty( creatorName ) ){
		p = cb.and( p, cb.equal( root.get( BBSSubjectInfo_.creatorName ), creatorName ) );
	}
	cq.orderBy( cb.desc( root.get( BBSSubjectInfo_.updateTime ) ) );
	return em.createQuery(cq.where(p)).setMaxResults( count ).getResultList();
}
 
Example 7
Source File: AttendanceDetailFactory.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 迟到、缺勤、早退、工时不足、异常打卡,但未申诉通过的
 * @param year
 * @param month
 * @return
 * @throws Exception
 */
//@MethodDescribe("获取所有需要导出所有异常数据(未申诉的、申诉未通过的)")
public List<String> getDetailsWithAllAbnormalCase( String year, String month ) throws Exception {
	if( year == null || month == null ){
		return null;
	}
	EntityManager em = this.entityManagerContainer().get( AttendanceDetail.class );
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<AttendanceDetail> root = cq.from( AttendanceDetail.class);
	cq.select( root.get(AttendanceDetail_.id ));
	
	Predicate p = cb.lessThan( root.get(AttendanceDetail_.appealStatus), 9); //如果等于9就是申诉通过
	p = cb.and(p, cb.equal( root.get(AttendanceDetail_.cycleYear), year ));
	p = cb.and(p, cb.equal( root.get(AttendanceDetail_.cycleMonth), month ));
	
	Predicate orCase = cb.isTrue(root.get(AttendanceDetail_.isLate)); //迟到
	orCase = cb.or( orCase, cb.isTrue( root.get(AttendanceDetail_.isLeaveEarlier)) ); //或者早退
	orCase = cb.or( orCase, cb.isTrue( root.get(AttendanceDetail_.isAbnormalDuty) )); //或者异常打卡
	orCase = cb.or( orCase, cb.isTrue( root.get(AttendanceDetail_.isAbsent) )); //或者缺勤
	orCase = cb.or( orCase, cb.isTrue( root.get(AttendanceDetail_.isLackOfTime) )); //或者工时不足
	
	Predicate where = cb.and( p, orCase );
	
	return em.createQuery(cq.where(where)).setMaxResults(20000).getResultList();
}
 
Example 8
Source File: BBSSubjectInfoFactory.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
public List<BBSSubjectInfo> listRecommendedSubjectInSectionForPage( String searchForumId, String searchMainSectionId,
		String searchSectionId, String creatorName, Integer count) throws Exception {
	if( count == null ){
		count = 10;
	}
	EntityManager em = this.entityManagerContainer().get( BBSSubjectInfo.class );
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<BBSSubjectInfo> cq = cb.createQuery(BBSSubjectInfo.class);
	Root<BBSSubjectInfo> root = cq.from(BBSSubjectInfo.class);
	Predicate p = cb.isTrue( root.get( BBSSubjectInfo_.recommendToBBSIndex ) );
	if( StringUtils.isNotEmpty( searchForumId ) ){
		p = cb.and( p, cb.equal( root.get( BBSSubjectInfo_.forumId ), searchForumId ) );
	}
	if( StringUtils.isNotEmpty( searchMainSectionId ) ){
		p = cb.and( p, cb.equal( root.get( BBSSubjectInfo_.mainSectionId ), searchMainSectionId ) );
	}
	if( StringUtils.isNotEmpty( searchSectionId ) ){
		p = cb.and( p, cb.equal( root.get( BBSSubjectInfo_.sectionId ), searchSectionId ) );
	}
	if( StringUtils.isNotEmpty( creatorName ) ){
		p = cb.and( p, cb.equal( root.get( BBSSubjectInfo_.creatorName ), creatorName ) );
	}
	cq.orderBy( cb.desc( root.get( BBSSubjectInfo_.updateTime ) ) );
	return em.createQuery(cq.where(p)).setMaxResults( count ).getResultList();
}
 
Example 9
Source File: CurrentVariantRollbackService.java    From mojito with Apache License 2.0 5 votes vote down vote up
/**
 * Builds the query to delete {@link com.box.l10n.mojito.entity.TMTextUnitCurrentVariant}s that will be rolled back
 *
 * @param tmId            ID of the TM the {@link TMTextUnitCurrentVariant}s to be rolled back should belong to
 * @param extraParameters Extra parameters to filter what to rollback
 * @return The delete query
 */
protected Query buildDeleteQuery(Long tmId, CurrentVariantRollbackParameters extraParameters) {

    logger.trace("Building the delete tmTextUnitCurrentVariants query");

    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaDelete<TMTextUnitCurrentVariant> deleteCriteria = criteriaBuilder.createCriteriaDelete(TMTextUnitCurrentVariant.class);
    Root<TMTextUnitCurrentVariant> root = deleteCriteria.from(TMTextUnitCurrentVariant.class);

    Predicate whereClause = criteriaBuilder.conjunction();

    Predicate tmPredicate = criteriaBuilder.equal(root.get(TMTextUnitCurrentVariant_.tm), tmId);
    whereClause = criteriaBuilder.and(whereClause, tmPredicate);

    List<Long> localeIdsToRollback = extraParameters.getLocaleIds();
    if (localeIdsToRollback != null && !localeIdsToRollback.isEmpty()) {
        Predicate localesPredicate = criteriaBuilder.isTrue(root.get(TMTextUnitCurrentVariant_.locale).in(localeIdsToRollback));
        whereClause = criteriaBuilder.and(whereClause, localesPredicate);
    }

    List<Long> tmTextUnitIdsToRollback = extraParameters.getTmTextUnitIds();
    if (tmTextUnitIdsToRollback != null && !tmTextUnitIdsToRollback.isEmpty()) {
        Predicate tmTextUnitPredicate = criteriaBuilder.isTrue(root.get(TMTextUnitCurrentVariant_.tmTextUnit).in(tmTextUnitIdsToRollback));
        whereClause = criteriaBuilder.and(whereClause, tmTextUnitPredicate);
    }

    deleteCriteria.where(whereClause);

    return entityManager.createQuery(deleteCriteria);
}
 
Example 10
Source File: CategoryInfoFactory.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 查询所有用户都可以发布的分类ID列表(检测allPeopleView和allPeoplePublish)
 * @param inAppInfoIds
 * @param inCategoryIds
 * @param excludCategoryIds
 * @return
 * @throws Exception 
 */
public List<String> listAllPeopleViewableCategoryInfoIds(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);
	cq.select(root.get(CategoryInfo_.id));
	
	Predicate p_all = cb.isTrue( root.get( CategoryInfo_.allPeopleView ) );
	p_all = cb.or( p_all,  cb.isTrue( root.get( CategoryInfo_.allPeoplePublish )));
	
	Predicate p = root.get( CategoryInfo_.id ).isNotNull();
	if( ListTools.isNotEmpty( inAppInfoIds )) {
		p = cb.and( p,  root.get( CategoryInfo_.appId ).in( inAppInfoIds ) );
	}
	if( ListTools.isNotEmpty( inCategoryIds )) {
		p = cb.and( p, root.get( CategoryInfo_.id ).in( inCategoryIds ));
	}
	if( ListTools.isNotEmpty( excludCategoryIds )) {
		p = cb.and( p, cb.not( root.get( CategoryInfo_.id ).in( excludCategoryIds )));
	}
	p = cb.and( p, p_all );
	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 11
Source File: DropSpecification.java    From mojito with Apache License 2.0 5 votes vote down vote up
/**
 * A {@link Specification} to filter Drops that have been canceled or not.
 *
 * @param canceled {@code true} to get Drops that have been canceled,
 * {@code false} to get Drops that have not been canceled
 *
 * @return {@link Specification}
 */
public static SingleParamSpecification<Drop> isCanceled(final Boolean canceled) {
    return new SingleParamSpecification<Drop>(canceled) {
        @Override
        public Predicate toPredicate(Root<Drop> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
            if (canceled) {
                return builder.isTrue(root.get(Drop_.canceled));
            } else {
                return builder.or(builder.isNull(root.get(Drop_.canceled)),
                       builder.isFalse(root.get(Drop_.canceled)));
            }
        }
    };
}
 
Example 12
Source File: AppInfoFactory.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public List<String> listAllPeoplePublishAppInfoIds(String documentType) 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);
	cq.select(root.get(AppInfo_.id));
	Predicate p = cb.isTrue(root.get(AppInfo_.allPeoplePublish));
	if (StringUtils.isNotEmpty(documentType) && !"全部".equals(documentType) && !"all".equalsIgnoreCase(documentType)) {
		p = cb.and(p, cb.equal(root.get(AppInfo_.documentType), documentType));
	}
	return em.createQuery(cq.where(p)).getResultList();
}
 
Example 13
Source File: CmsPermissionService.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 查询所有用户都可以发布的分类ID列表(检测allPeoplePublish)
 * 
 * @param inAppInfoIds      - 过滤栏目ID列表
 * @param inCategoryIds     - 过滤分类ID列表
 * @param excludCategoryIds - 排队分类ID列表
 * @return
 * @throws Exception
 */
private List<String> listAllPeoplePublishCategoryIds(EntityManagerContainer emc, List<String> inAppInfoIds,
		List<String> inCategoryIds, List<String> excludCategoryIds, String documentType, Integer maxCount)
		throws Exception {
	List<String> categoryInfoIds = null;
	List<String> categoryInfoIds_out = new ArrayList<>();

	EntityManager em = emc.get(CategoryInfo.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<CategoryInfo> root = cq.from(CategoryInfo.class);
	cq.select(root.get(CategoryInfo.id_FIELDNAME));

	Predicate p = cb.isTrue(root.get(CategoryInfo.allPeoplePublish_FIELDNAME));
	if (ListTools.isNotEmpty(inAppInfoIds)) {
		p = cb.and(p, root.get(CategoryInfo.appId_FIELDNAME).in(inAppInfoIds));
	}
	if (ListTools.isNotEmpty(inCategoryIds)) {
		p = cb.and(p, root.get(CategoryInfo.id_FIELDNAME).in(inCategoryIds));
	}
	if (ListTools.isNotEmpty(excludCategoryIds)) {
		p = cb.and(p, cb.not(root.get(CategoryInfo.id_FIELDNAME).in(excludCategoryIds)));
	}
	if (StringUtils.isNotEmpty(documentType) && !"全部".equals(documentType)
			&& !"all".equalsIgnoreCase(documentType)) {
		p = cb.and(p, cb.equal(root.get(CategoryInfo.documentType_FIELDNAME), documentType));
	}
	categoryInfoIds = em.createQuery(cq.where(p)).setMaxResults(maxCount).getResultList();
	if (categoryInfoIds == null) {
		categoryInfoIds = new ArrayList<>();
	}
	categoryInfoIds_out.addAll(categoryInfoIds);
	categoryInfoIds_out = excludListContent(categoryInfoIds_out, excludCategoryIds);
	return categoryInfoIds_out;
}
 
Example 14
Source File: BBSSubjectInfoFactory.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public Long countOriginalSubjectByUserName( String userName ) throws Exception {
	EntityManager em = this.entityManagerContainer().get( BBSSubjectInfo.class );
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Long> cq = cb.createQuery(Long.class);
	Root<BBSSubjectInfo> root = cq.from(BBSSubjectInfo.class);
	Predicate p = cb.isTrue( root.get( BBSSubjectInfo_.isCreamSubject ) );
	if( StringUtils.isNotEmpty( userName ) ){
		p = cb.and( p, cb.equal( root.get( BBSSubjectInfo_.creatorName ), userName ) );
	}
	cq.select( cb.count( root ) );		
	return em.createQuery(cq.where(p)).getSingleResult();
}
 
Example 15
Source File: BBSSubjectInfoFactory.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public Long countCreamSubjectByUserName( String userName ) throws Exception {
	EntityManager em = this.entityManagerContainer().get( BBSSubjectInfo.class );
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Long> cq = cb.createQuery(Long.class);
	Root<BBSSubjectInfo> root = cq.from(BBSSubjectInfo.class);
	Predicate p = cb.isTrue( root.get( BBSSubjectInfo_.isCreamSubject ) );
	if( StringUtils.isNotEmpty( userName ) ){
		p = cb.and( p, cb.equal( root.get( BBSSubjectInfo_.creatorName ), userName ) );
	}
	cq.select( cb.count( root ) );		
	return em.createQuery(cq.where(p)).getSingleResult();
}
 
Example 16
Source File: CalendarFactory.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public List<String> listPublicCalendar() throws Exception {
	EntityManager em = this.entityManagerContainer().get(Calendar.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<Calendar> root = cq.from(Calendar.class);
	Predicate permission = cb.isTrue( root.get(Calendar_.isPublic) );
	cq.select(root.get(Calendar_.id));
	return em.createQuery(cq.where(permission)).getResultList();
}
 
Example 17
Source File: AppInfoFactory.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * 根据权限查询用户可以发布文档的栏目ID列表(检测allPeoplePublish )
 * 
 * @param personName
 * @param unitNames
 * @param groupNames
 * @param inAppInfoIds
 *            - 栏目ID的最大范围
 * @param excludAppInfoIds
 *            - 需要排队的栏目ID
 * @return
 * @throws Exception
 */
public List<String> listPublishableAppInfoIds(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;
	p_permission = cb.isTrue(root.get(AppInfo_.allPeoplePublish));

	if (StringUtils.isNotEmpty(personName)) {
		// 可以管理的栏目,肯定可以发布信息
		p_permission = cb.or(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 18
Source File: AppInfoFactory.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * 查询用户有权限访问的所有栏目ID列表(检测allPeopleView 和 allPeoplePublish )
 * 
 * @param personName
 * @param unitNames
 * @param groupNames
 * @param inAppInfoIds
 * @param excludAppInfoIds
 * @return
 * @throws Exception
 */
public List<String> listViewableAppInfoIds(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;
	p_permission = cb.isTrue(root.get(AppInfo_.allPeopleView));
	p_permission = cb.or(p_permission, cb.isTrue(root.get(AppInfo_.allPeoplePublish)));
	if (StringUtils.isNotEmpty(personName)) {
		// 可以管理的栏目,肯定可以发布信息
		p_permission = cb.or(p_permission, cb.isMember(personName, root.get(AppInfo_.manageablePersonList)));
		p_permission = cb.or(p_permission, cb.isMember(personName, root.get(AppInfo_.publishablePersonList)));
		p_permission = cb.or(p_permission, cb.isMember(personName, root.get(AppInfo_.viewablePersonList)));
	}
	if (ListTools.isNotEmpty(unitNames)) {
		p_permission = cb.or(p_permission, root.get(AppInfo_.publishableUnitList).in(unitNames));
		p_permission = cb.or(p_permission, root.get(AppInfo_.viewableUnitList).in(unitNames));
	}
	if (ListTools.isNotEmpty(groupNames)) {
		p_permission = cb.or(p_permission, root.get(AppInfo_.publishableGroupList).in(groupNames));
		p_permission = cb.or(p_permission, root.get(AppInfo_.viewableGroupList).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 19
Source File: BBSSubjectInfoFactory.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
public List<String> listAllTopSubject( String forumId, String mainSectionId, String sectionId, String creatorName ) throws Exception {
	if( forumId == null || forumId.isEmpty() ){
		throw new Exception( "forumId is null!" );
	}
	EntityManager em = this.entityManagerContainer().get( BBSSubjectInfo.class );
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery( String.class);
	Root<BBSSubjectInfo> root = cq.from( BBSSubjectInfo.class );
	cq.select(root.get( BBSSubjectInfo_.id));
	
	Predicate p = cb.isTrue( root.get( BBSSubjectInfo_.isTopSubject ) );
	
	if( StringUtils.isNotEmpty( creatorName ) ){
		p = cb.and( p,  cb.equal( root.get( BBSSubjectInfo_.creatorName ), creatorName ) );
	}
	
	Predicate top_or = null;
	Predicate top_toforum_or = null;
	Predicate top_tomainsection_or = null;
	Predicate top_tosection_or = null;
	if( StringUtils.isNotEmpty( forumId ) ){
		top_toforum_or = cb.equal( root.get( BBSSubjectInfo_.forumId ), forumId );
		top_toforum_or = cb.and( top_toforum_or, cb.isTrue( root.get( BBSSubjectInfo_.topToForum )) );
		top_or = top_toforum_or;
	}
	
	if( StringUtils.isNotEmpty( mainSectionId ) ){//在指定的主版块中的所有置顶主题
		top_tomainsection_or = cb.equal( root.get( BBSSubjectInfo_.mainSectionId ), mainSectionId );
		top_tomainsection_or = cb.and( top_tomainsection_or, cb.isTrue( root.get( BBSSubjectInfo_.topToMainSection )) );
		if( top_or != null ){
			top_or = cb.or( top_or, top_tomainsection_or );
		}else{
			top_or = top_tomainsection_or;
		}
	}
	
	if( StringUtils.isNotEmpty( sectionId ) ){//在指定的版块中的所有置顶主题
		top_tosection_or = cb.equal( root.get( BBSSubjectInfo_.sectionId ), sectionId );
		top_tosection_or = cb.and( top_tosection_or, cb.isTrue( root.get( BBSSubjectInfo_.topToSection )) );
		if( top_or != null ){
			top_or = cb.or( top_or, top_tosection_or );
		}else{
			top_or = top_tosection_or;
		}
	}
	
	if( top_or != null ){
		p = cb.and( p, top_or );
	}
	return em.createQuery(cq.where(p)).getResultList();
}
 
Example 20
Source File: CmsPermissionService.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * 查询所有用户都可以访问的分类ID列表(检测allPeopleView和allPeoplePublish)
 * 
 * @param inAppInfoIds      - 过滤栏目ID列表
 * @param inCategoryIds     - 过滤分类ID列表
 * @param excludCategoryIds - 排队分类ID列表
 * @return
 * @throws Exception
 */
private List<String> listAllPeopleViewCategoryIds(EntityManagerContainer emc, List<String> inAppInfoIds,
		List<String> inCategoryIds, List<String> excludCategoryIds, String documentType, Integer maxCount)
		throws Exception {
	List<String> categoryInfoIds = null;
	List<String> categoryInfoIds_out = new ArrayList<>();
	EntityManager em = emc.get(CategoryInfo.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<String> cq = cb.createQuery(String.class);
	Root<CategoryInfo> root = cq.from(CategoryInfo.class);
	cq.select(root.get(CategoryInfo.id_FIELDNAME));

	Predicate p_all = cb.isTrue(root.get(CategoryInfo.allPeopleView_FIELDNAME));
	p_all = cb.or(p_all, cb.isTrue(root.get(CategoryInfo.allPeoplePublish_FIELDNAME)));

	Predicate p = null;
	if (ListTools.isNotEmpty(inAppInfoIds)) {
		p = CriteriaBuilderTools.predicate_and(cb, p, root.get(CategoryInfo.appId_FIELDNAME).in(inAppInfoIds));
	}
	if (ListTools.isNotEmpty(inCategoryIds)) {
		p = CriteriaBuilderTools.predicate_and(cb, p, root.get(CategoryInfo.id_FIELDNAME).in(inCategoryIds));
	}
	if (ListTools.isNotEmpty(excludCategoryIds)) {
		p = CriteriaBuilderTools.predicate_and(cb, p,
				cb.not(root.get(CategoryInfo.id_FIELDNAME).in(excludCategoryIds)));
	}
	if (StringUtils.isNotEmpty(documentType) && !"全部".equals(documentType)
			&& !"all".equalsIgnoreCase(documentType)) {
		p = CriteriaBuilderTools.predicate_and(cb, p,
				cb.equal(root.get(CategoryInfo.documentType_FIELDNAME), documentType));
	}

	p = CriteriaBuilderTools.predicate_and(cb, p, p_all);

	categoryInfoIds = em.createQuery(cq.where(p)).setMaxResults(maxCount).getResultList();
	if (categoryInfoIds == null) {
		categoryInfoIds = new ArrayList<>();
	}
	categoryInfoIds_out.addAll(categoryInfoIds);
	categoryInfoIds_out = excludListContent(categoryInfoIds_out, excludCategoryIds);
	return categoryInfoIds_out;
}