Example usage for org.hibernate.criterion Restrictions isNull

List of usage examples for org.hibernate.criterion Restrictions isNull

Introduction

In this page you can find the example usage for org.hibernate.criterion Restrictions isNull.

Prototype

public static Criterion isNull(String propertyName) 

Source Link

Document

Apply an "is null" constraint to the named property

Usage

From source file:es.sm2.openppm.core.dao.ProjectFollowupDAO.java

License:Open Source License

/**
 * Find follow ups for notify// ww w . j a va2s  .  c om
 * @return
 */
@SuppressWarnings("unchecked")
public List<Projectfollowup> findForNotify() {

    Calendar actualDate = DateUtil.getCalendar();

    Criteria crit = getSession().createCriteria(getPersistentClass())
            .add(Restrictions.le(Projectfollowup.FOLLOWUPDATE, actualDate.getTime()))
            .add(Restrictions.isNull(Projectfollowup.GENERALFLAG))
            .add(Restrictions.isNull(Projectfollowup.RISKFLAG))
            .add(Restrictions.isNull(Projectfollowup.COSTFLAG))
            .add(Restrictions.isNull(Projectfollowup.SCHEDULEFLAG))
            .setFetchMode(Projectfollowup.PROJECT, FetchMode.JOIN)
            .setFetchMode(Projectfollowup.PROJECT + "." + Project.EMPLOYEEBYPROJECTMANAGER, FetchMode.JOIN)
            .setFetchMode(
                    Projectfollowup.PROJECT + "." + Project.EMPLOYEEBYPROJECTMANAGER + "." + Employee.CONTACT,
                    FetchMode.JOIN);

    Criteria crit2 = crit.createCriteria(Projectfollowup.PROJECT);
    crit2.add(Restrictions.eq(Project.STATUS, Constants.STATUS_CONTROL));

    return crit.list();
}

From source file:es.sm2.openppm.core.dao.ProjectKpiDAO.java

License:Open Source License

/**
 * Find if a project KPIS empty/*  w  w  w. ja v  a2  s.c o m*/
 * @param project
 * @return
 */
public boolean thereKPISEmpty(Project project) {

    Criteria crit = getSession().createCriteria(getPersistentClass()).setProjection(Projections.rowCount())
            .add(Restrictions.eq(Projectkpi.PROJECT, project)).add(Restrictions.isNull(Projectkpi.VALUE));

    Integer count = (Integer) crit.uniqueResult();

    return (count != null && count > 0);
}

From source file:es.sm2.openppm.core.dao.TeamMemberDAO.java

License:Open Source License

/**
 * Search Team Members by filter//from   www. j a v  a  2  s.c  om
 * 
 * @param idResourcePools 
 * @param idProjects
 * @param idPMs
 * @param idJobCategories
 * @param statusList
 * @param fullName
 * @param since
 * @param until
 * @param nameOrder 
 * @param order
 * @param idEmployee 
 * @param user 
 * @param idSellers 
 * @param idCategories 
 * @param settings 
 * @return
 */
public List<Teammember> consStaffinFtes(Integer[] idResourcePools, Integer[] idProjects, Integer[] idPMs,
        Integer[] idJobCategories, String[] statusList, String fullName, Date since, Date until,
        String nameOrder, String order, Integer idEmployee, Employee user, Integer[] idSellers,
        Integer[] idCategories, HashMap<String, String> settings) {

    Criteria crit = getSession().createCriteria(getPersistentClass(), "t");

    if (nameOrder == null && ValidateUtil.isNull(idJobCategories)) {

        crit.add(Restrictions.isNull(Teammember.JOBCATEGORY));
    }

    Criteria projActCrit = crit.createCriteria(Teammember.PROJECTACTIVITY);

    // Filter by sellers
    if (ValidateUtil.isNotNull(idSellers)) {

        projActCrit.createCriteria(Projectactivity.ACTIVITYSELLERS).createCriteria(Activityseller.SELLER)
                .add(Restrictions.in(Seller.IDSELLER, idSellers));
    }

    Criteria projCrit = projActCrit.createCriteria(Projectactivity.PROJECT);

    // Filter by category
    if (ValidateUtil.isNotNull(idCategories)) {

        projCrit.createCriteria(Project.CATEGORY).add(Restrictions.in(Category.IDCATEGORY, idCategories));
    }

    // Filter by Project
    if (ValidateUtil.isNotNull(idProjects)) {
        projCrit.add(Restrictions.in(Project.IDPROJECT, idProjects));
    }

    // Remove information if project is closed
    if (!SettingUtil.getBoolean(settings, SettingType.CLOSED_PROJECTS_CAPACITY_PLANNING)) {
        projCrit.add(Restrictions.and(Restrictions.ne(Project.STATUS, Constants.STATUS_CLOSED),
                Restrictions.ne(Project.STATUS, Constants.STATUS_ARCHIVED)));
    }

    // Filter by Project Manager
    if (user.getResourceprofiles().getIdProfile() == Constants.ROLE_PM) {

        projCrit.createCriteria(Project.EMPLOYEEBYPROJECTMANAGER)
                .add(Restrictions.eq(Employee.IDEMPLOYEE, user.getIdEmployee()));
    } else if (user.getResourceprofiles().getIdProfile() != Constants.ROLE_PM
            && ValidateUtil.isNotNull(idPMs)) {

        projCrit.createCriteria(Project.EMPLOYEEBYPROJECTMANAGER)
                .add(Restrictions.in(Employee.IDEMPLOYEE, idPMs));
    }

    // Filter by Status
    if (ValidateUtil.isNotNull(statusList)) {
        crit.add(Restrictions.in(Teammember.STATUS, statusList));
    }

    // Filter by Skill
    Criteria jobCrit = null;
    if (Jobcategory.IDJOBCATEGORY.equals(nameOrder) || ValidateUtil.isNotNull(idJobCategories)) {
        jobCrit = crit.createCriteria(Teammember.JOBCATEGORY);
    }
    if (ValidateUtil.isNotNull(idJobCategories)) {
        jobCrit.add(Restrictions.in(Jobcategory.IDJOBCATEGORY, idJobCategories));
    }

    // Filter by dates (since && until)
    if (since != null && until != null) {

        crit.add(Restrictions.disjunction().add(Restrictions.between(Teammember.DATEIN, since, until))
                .add(Restrictions.between(Teammember.DATEOUT, since, until))
                .add(Restrictions.and(Restrictions.le(Teammember.DATEIN, since),
                        Restrictions.ge(Teammember.DATEOUT, until))));
    } else if (since != null) {
        crit.add(Restrictions.and(Restrictions.le(Teammember.DATEIN, since),
                Restrictions.ge(Teammember.DATEOUT, since)));
    } else if (until != null) {
        crit.add(Restrictions.and(Restrictions.le(Teammember.DATEIN, until),
                Restrictions.ge(Teammember.DATEOUT, until)));
    }

    // Filter By Employee
    Criteria employeeCrit = crit.createCriteria(Teammember.EMPLOYEE);

    if (idEmployee != null) {
        employeeCrit.add(Restrictions.idEq(idEmployee));
    }

    // Filter by resource pool
    if (ValidateUtil.isNotNull(idResourcePools)) {

        employeeCrit.createCriteria(Employee.RESOURCEPOOL)
                .add(Restrictions.in(Resourcepool.IDRESOURCEPOOL, idResourcePools));
    }

    // Filter by po
    if (user != null) {
        employeeCrit.add(Restrictions.eq(Employee.PERFORMINGORG, user.getPerformingorg()));
    }

    // Filter by Full Name
    Criteria contactCrit = employeeCrit.createCriteria(Employee.CONTACT);
    if (ValidateUtil.isNotNull(fullName)) {
        contactCrit.add(Restrictions.ilike(Contact.FULLNAME, "%" + fullName + "%"));
    }

    // Apply Order
    Criteria orderCrit = null;
    if (Project.IDPROJECT.equals(nameOrder)) {
        orderCrit = projCrit;
    } else if (Jobcategory.IDJOBCATEGORY.equals(nameOrder)) {
        orderCrit = jobCrit;
    } else {
        orderCrit = contactCrit;
    }

    if (nameOrder != null) {
        if (Constants.DESCENDENT.equals(order)) {
            orderCrit.addOrder(Order.desc(nameOrder));
        } else {
            orderCrit.addOrder(Order.asc(nameOrder));
        }
    }

    contactCrit.addOrder(Order.asc(Contact.IDCONTACT));

    List<String> joins = new ArrayList<String>();
    joins.add(Teammember.PROJECTACTIVITY);
    joins.add(Teammember.PROJECTACTIVITY + "." + Projectactivity.PROJECT);
    joins.add(Teammember.PROJECTACTIVITY + "." + Projectactivity.PROJECT + "."
            + Project.EMPLOYEEBYPROJECTMANAGER);
    joins.add(Teammember.PROJECTACTIVITY + "." + Projectactivity.PROJECT + "."
            + Project.EMPLOYEEBYPROJECTMANAGER + "." + Employee.CONTACT);

    addJoins(crit, joins);

    return crit.list();
}

From source file:es.sm2.openppm.core.dao.TimesheetDAO.java

License:Open Source License

/**
 * //from w w w  .j  a  va2  s  . c o m
 * @param employee
 * @param initDate
 * @param endDate
 * @param joins
 * @return
 */
@SuppressWarnings("unchecked")
public List<Timesheet> findWithOperationByResource(Employee employee, Date initDate, Date endDate,
        List<String> joins) {

    Criteria crit = getSession().createCriteria(getPersistentClass())
            .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)
            .add(Restrictions.isNull(Timesheet.PROJECTACTIVITY))
            .add(Restrictions.eq(Timesheet.EMPLOYEE, employee))
            .add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP3))
            .add(Restrictions.ge(Timesheet.INITDATE, initDate)).add(Restrictions.le(Timesheet.ENDDATE, endDate))
            .addOrder(Order.asc(Timesheet.OPERATION)).addOrder(Order.asc(Timesheet.INITDATE));

    addJoins(crit, joins);

    return crit.list();
}

From source file:es.sm2.openppm.core.dao.TimesheetDAO.java

License:Open Source License

/**
 * Is in status//  w w w.  ja v a2  s .c  om
 * @param idEmployee
 * @param id
 * @param initDate
 * @param endDate
 * @param status
 * @param filterUser 
 * @return
 */
public boolean isStatusResource(Integer idEmployee, Integer id, Date initDate, Date endDate, String status,
        Employee filterUser) {

    Criteria crit = getSession().createCriteria(getPersistentClass()).setProjection(Projections.rowCount())
            .add(Restrictions.eq(Timesheet.STATUS, status)).add(Restrictions.eq(Timesheet.INITDATE, initDate))
            .add(Restrictions.eq(Timesheet.ENDDATE, endDate))
            .add(Restrictions.eq(Timesheet.EMPLOYEE, new Employee(idEmployee)));

    if (Constants.TIMESTATUS_APP1.equals(status)) {

        if (id.equals(0)) {
            crit.add(Restrictions.isNull(Timesheet.PROJECTACTIVITY));
        } else {
            crit.createCriteria(Timesheet.PROJECTACTIVITY)
                    .add(Restrictions.eq(Projectactivity.PROJECT, new Project(id)));
        }
    } else if (Constants.TIMESTATUS_APP2.equals(status)) {
        Criteria critFilter = crit.createCriteria(Timesheet.PROJECTACTIVITY)
                .createCriteria(Projectactivity.PROJECT);

        // Filter by User. Settings by company for last approval.

        Resourceprofiles profile = filterUser.getResourceprofiles();

        if (profile.getIdProfile() == Constants.ROLE_FM) {

            critFilter.add(Restrictions.eq(Project.EMPLOYEEBYFUNCTIONALMANAGER, filterUser));
        } else if (profile.getIdProfile() == Constants.ROLE_PM) {

            critFilter.add(Restrictions.eq(Project.EMPLOYEEBYPROJECTMANAGER, filterUser));
        } else {

            critFilter.add(Restrictions.eq(Project.PERFORMINGORG, filterUser.getPerformingorg()));
        }
    }

    Integer count = (Integer) crit.uniqueResult();

    return (count != null && count > 0);
}

From source file:es.sm2.openppm.core.dao.WBSNodeDAO.java

License:Open Source License

/**
 * Return WBS family Parent/*from  w w w.  j  a  v a  2s .  c  om*/
 * @param proj
 * @return
 */
@SuppressWarnings("unchecked")
public Wbsnode findFirstNode(Project proj) {

    Wbsnode wbsNode = null;

    Criteria crit = getSession().createCriteria(getPersistentClass()).add(Restrictions.isNull(Wbsnode.WBSNODE))
            .addOrder(Order.asc(Wbsnode.CODE)).add(Restrictions.eq(Wbsnode.PROJECT, proj));

    List<Wbsnode> list = crit.list();
    if (!list.isEmpty()) {
        wbsNode = list.get(0);
    }
    return wbsNode;
}

From source file:es.sm2.openppm.core.dao.WBSNodeDAO.java

License:Open Source License

/**
 * Check if one or more wbsnodes have budget null or 0
 * /*from www  .  ja  v a 2 s  . co m*/
 * @param project
 * @return
 */
public boolean isBudgetEmpty(Project project) {

    Criteria crit = getSession().createCriteria(getPersistentClass()).setProjection(Projections.rowCount())
            .add(Restrictions.eq(Wbsnode.ISCONTROLACCOUNT, true)).add(Restrictions.eq(Wbsnode.PROJECT, project))
            .add(Restrictions.or(Restrictions.isNull(Wbsnode.BUDGET),
                    Restrictions.eq(Wbsnode.BUDGET, new Double(0))));

    //TODO http://192.168.65.102/redmine/issues/1688 .add(Restrictions.isNull(Wbsnode.BUDGET));

    Integer rows = (Integer) crit.uniqueResult();

    return (rows != null && rows > 0);
}

From source file:es.sm2.openppm.core.dao.WbstemplateDAO.java

License:Open Source License

/**
 * Find by company and property equal to null
 * @param company//  w w  w  . j a  v a2 s. c  o m
 * @param parent
 * @return
 */
@SuppressWarnings("unchecked")
public List<Wbstemplate> findByCompanyAndRelationNull(Company company, String property) {

    Criteria crit = getSession().createCriteria(getPersistentClass()).addOrder(Order.asc(Wbstemplate.NAME))
            .add(Restrictions.isNull(property)).add(Restrictions.eq(Company.ENTITY, company));

    return crit.list();
}

From source file:es.sm2.openppm.core.model.impl.Projectfollowup.java

License:Open Source License

public Integer getDaysToDate() throws Exception {

    if (daysToDate == null) {

        ProjectLogic projectLogic = new ProjectLogic(settings, null);
        ProjectActivityLogic activityLogic = new ProjectActivityLogic(settings, null);
        ProjectCalendarExceptionsLogic projectCalendarExceptionsLogic = new ProjectCalendarExceptionsLogic();
        ProjectcalendarLogic projectCalendarLogic = new ProjectcalendarLogic();

        Project project = projectLogic.findByFollowup(this);
        Projectactivity rootAct = project.getRootActivity();

        Projectcalendar projectCalendar = projectCalendarLogic.consCalendarByProject(project);
        List<Projectcalendarexceptions> exceptions = projectCalendarExceptionsLogic
                .findByRelation(Projectcalendarexceptions.PROJECTCALENDAR, projectCalendar);

        List<Date> exceptionDates = ProjectCalendarExceptionsLogic.getExceptionDates(exceptions);

        Junction restrictions = Restrictions.conjunction()
                .add(Restrictions.eq(Projectactivity.PROJECT, project))
                .add(Restrictions.isNull(Projectactivity.ACTUALINITDATE));

        if (rootAct != null && rootAct.getActualInitDate() != null && rootAct.getPlanInitDate() != null
                && activityLogic.rowCount(restrictions) == 0
                && rootAct.getActualInitDate().before(rootAct.getPlanInitDate())) {

            daysToDate = ValidateUtil.calculateWorkDays(rootAct.getActualInitDate(), getFollowupDate(),
                    exceptionDates);/*from   w  ww  . j a  va2s.  c o m*/
        } else if (rootAct != null && rootAct.getPlanInitDate() != null) {
            daysToDate = ValidateUtil.calculateWorkDays(rootAct.getPlanInitDate(), getFollowupDate(),
                    exceptionDates);
        } else {
            daysToDate = ValidateUtil.calculateWorkDays(project.getPlannedInitDate(), getFollowupDate(),
                    exceptionDates);
        }
    }

    return daysToDate;
}

From source file:es.tekniker.framework.ktek.questionnaire.mng.db.QuestionnaireManagerDB.java

License:Open Source License

public Ktek_questionnaire getQuestionnaireModel(int idquestionnaire) {

    Ktek_questionnaire instance = null;// w w  w .  j a v  a 2  s .c o m

    PersistentSession session = null;
    DAOFactory lDAOFactory = null;
    Ktek_questionnaireDAO instanceDAO = null;
    Ktek_questionnaireCriteria objKtek_questionnaireCriteria = null;
    long nowInMillis = 0;
    try {
        nowInMillis = Utils.getCalendarGMT().getTimeInMillis();

        session = es.tekniker.framework.ktek.questionnaire.KTEKPersistentManager.instance().getSession();
        session.beginTransaction();

        lDAOFactory = es.tekniker.framework.ktek.questionnaire.DAOFactory.getDAOFactory();
        instanceDAO = lDAOFactory.getKtek_questionnaireDAO();

        objKtek_questionnaireCriteria = new Ktek_questionnaireCriteria();
        objKtek_questionnaireCriteria.isdeleted.eq((short) 0);
        objKtek_questionnaireCriteria.datevalidfrom.lt(nowInMillis);

        objKtek_questionnaireCriteria.add(Restrictions.or(Restrictions.isNull("datevalidto"),
                Restrictions.gt("datevalidto", nowInMillis)));

        objKtek_questionnaireCriteria.ktek_pk_idquestionnaire.eq(idquestionnaire);
        instance = instanceDAO.loadKtek_questionnaireByCriteria(objKtek_questionnaireCriteria);

        session.close();

        if (instance != null) {
            log.debug("getQuestionnaireModel is not null ");
        } else {
            log.debug("getQuestionnaireModel is null ");
        }

    } catch (Exception e) {
        log.error("getQuestionnaireModel Exception " + e.getMessage());
        e.printStackTrace();
        try {
            if (session != null)
                session.close();
        } catch (PersistentException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
    }
    return instance;
}