List of usage examples for org.hibernate.criterion Restrictions and
public static LogicalExpression and(Criterion lhs, Criterion rhs)
From source file:es.sm2.openppm.core.dao.TimesheetDAO.java
License:Open Source License
/** * Find time sheets of the resource/* w ww . j a va 2 s .c o m*/ * * @param employee * @param initDate * @param endDate * @param joins * @param project * @param minStatus * @param maxStatus * @param filterUser * @param statusResource * @param settings * @return */ @SuppressWarnings("unchecked") public List<Timesheet> findByCriteria(Employee employee, Date initDate, Date endDate, List<String> joins, Project project, String minStatus, String maxStatus, Employee filterUser, String statusResource, boolean includeClosed, HashMap<String, String> settings) { Criteria crit = getSession().createCriteria(getPersistentClass()) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY) .add(Restrictions.eq(Timesheet.EMPLOYEE, employee)) .add(Restrictions.eq(Timesheet.INITDATE, initDate)) .add(Restrictions.eq(Timesheet.ENDDATE, endDate)); if (minStatus != null && maxStatus != null) { Disjunction disjunction = Restrictions.disjunction(); disjunction.add(Restrictions.eq(Timesheet.STATUS, minStatus)); disjunction.add(Restrictions.eq(Timesheet.STATUS, maxStatus)); if (Constants.TIMESTATUS_APP0.equals(minStatus) && (Constants.TIMESTATUS_APP2.equals(maxStatus) || Constants.TIMESTATUS_APP3.equals(maxStatus))) { disjunction.add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP1)); } if (Constants.TIMESTATUS_APP3.equals(maxStatus) && (Constants.TIMESTATUS_APP0.equals(minStatus) || Constants.TIMESTATUS_APP1.equals(minStatus))) { disjunction.add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP2)); } //TODO 21/04/2015 - jordi.ripoll- tarea 1095 -pendiente de confirmacion // Last level be approved hours app1 by setting // // String lastLevelForApprove = SettingUtil.getString(settings, Settings.SETTING_LAST_LEVEL_FOR_APPROVE_SHEET, // Settings.DEFAULT_LAST_LEVEL_FOR_APPROVE_SHEET); // // if ((filterUser != null && lastLevelForApprove.equals(String.valueOf(filterUser.getResourceprofiles().getIdProfile()))) && // (settings != null && SettingUtil.getBoolean(settings, GeneralSetting.LAST_LEVEL_APPROVED_APP1))) { // // disjunction.add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP1)); // } crit.add(disjunction); } Criteria critEmployee = crit.createCriteria(Timesheet.EMPLOYEE); critEmployee.createCriteria(Employee.CONTACT); Criteria critActivity = crit.createCriteria(Timesheet.PROJECTACTIVITY); Criteria critMembers = critActivity.createCriteria(Projectactivity.TEAMMEMBERS) .add(Restrictions.eq(Teammember.EMPLOYEE, employee)); if (ValidateUtil.isNotNull(statusResource)) { critMembers.add(Restrictions.eq(Teammember.STATUS, statusResource)); } Criteria critProject = critActivity.createCriteria(Projectactivity.PROJECT); if (!includeClosed) { critProject.add(Restrictions.and(Restrictions.ne(Project.STATUS, Constants.STATUS_CLOSED), Restrictions.ne(Project.STATUS, Constants.STATUS_ARCHIVED))); } if (project != null) { critProject.add(Restrictions.eq(Project.IDPROJECT, project.getIdProject())); } else if (filterUser != null) { // Filter by User. Settings by company for last approval. Resourceprofiles profile = filterUser.getResourceprofiles(); if (profile.getIdProfile() == Constants.ROLE_FM) { critProject.add(Restrictions.eq(Project.EMPLOYEEBYFUNCTIONALMANAGER, filterUser)); } else if (profile.getIdProfile() == Constants.ROLE_PMO) { critProject.add(Restrictions.eq(Project.PERFORMINGORG, filterUser.getPerformingorg())); } } addJoins(crit, joins); return crit.list(); }
From source file:es.sm2.openppm.core.dao.TimesheetDAO.java
License:Open Source License
public double getHoursResourceInDates(Project project, Employee member, Date since, Date until, Integer idResourcePool, Operation operation, Projectactivity activity) { Criteria crit = getSession().createCriteria(getPersistentClass()); Criteria employeeCrit = null;//from w w w . ja va2s. c om if (member != null || idResourcePool != null) { employeeCrit = crit.createCriteria(Timesheet.EMPLOYEE); } if (idResourcePool != null) { employeeCrit.add(Restrictions.eq(Employee.RESOURCEPOOL, new Resourcepool(idResourcePool))); } if (member != null) { employeeCrit.add(Restrictions.idEq(member.getIdEmployee())); } if (since != null && until != null) { crit.add(Restrictions.disjunction().add(Restrictions.between(Timesheet.INITDATE, since, until)) .add(Restrictions.between(Timesheet.ENDDATE, since, until)) .add(Restrictions.and(Restrictions.le(Timesheet.INITDATE, since), Restrictions.ge(Timesheet.ENDDATE, until)))); } if (project != null) { crit.add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP3)); Criteria activitiesCrit = crit.createCriteria(Timesheet.PROJECTACTIVITY) .add(Restrictions.eq(Projectactivity.PROJECT, project)); // Select only timesheet whose activity is control account Criteria wbsnodeCrit = activitiesCrit.createCriteria(Projectactivity.WBSNODE) .add(Restrictions.eq(Wbsnode.ISCONTROLACCOUNT, true)); } else if (operation != null) { crit.add(Restrictions.or(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP2), Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP3))) .add(Restrictions.eq(Timesheet.OPERATION, operation)); } else if (activity != null) { crit.add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP3)) .add(Restrictions.eq(Timesheet.PROJECTACTIVITY, activity)); } return calcHours(crit.list(), since, until); }
From source file:eu.interedition.text.query.AnnotationNameCriterion.java
License:Apache License
@Override Criterion restrict() {//from w w w .j a v a 2s .c om final URI namespace = name.getNamespace(); return Restrictions.and(Restrictions.eq("name.localName", name.getLocalName()), (namespace == null ? Restrictions.isNull("name.namespaceURI") : Restrictions.eq("name.namespaceURI", namespace.toString()))); }
From source file:eu.interedition.text.query.RangeFitsWithinCriterion.java
License:Apache License
@Override Criterion restrict() { return Restrictions.and(Restrictions.ge("target.start", range.getStart()), Restrictions.le("target.end", range.getEnd())); }
From source file:eu.interedition.text.query.RangeOverlapCriterion.java
License:Apache License
@Override Criterion restrict() { return Restrictions.and(Restrictions.lt("target.start", range.getEnd()), Restrictions.gt("target.end", range.getStart())); }
From source file:eu.ist_phosphorus.harmony.idb.database.hibernate.Reservation.java
License:Open Source License
/** * load all reservations from DB which lie in a given time-period. */// w ww . j av a 2s . c o m @SuppressWarnings("unchecked") public static final Set<Reservation> loadAllInPeriod(Date startTime, Date endTime) throws DatabaseException { return (Set<Reservation>) (new TransactionManager(new Tuple<Date, Date>(startTime, endTime)) { @Override protected void dbOperation() { Set<Reservation> result = new HashSet<Reservation>(); Tuple<Date, Date> times = (Tuple<Date, Date>) this.arg; // select all reservation-IDs from ReservationPeriod-view, which // lie in the given time-period DetachedCriteria ids = DetachedCriteria.forClass(VIEW_ReservationPeriod.class) .setProjection(Property.forName("reservationId")) .add(Restrictions.disjunction() .add(Restrictions.between("startTime", times.getFirstElement(), times.getSecondElement())) .add(Restrictions.between("endTime", times.getFirstElement(), times.getSecondElement())) .add(Restrictions.and(Restrictions.le("startTime", times.getFirstElement()), Restrictions.ge("endTime", times.getSecondElement())))); // select all reservations from DB accoring to the IDs from step // one final List<Reservation> tmpReservation = this.session.createCriteria(Reservation.class) .add(Subqueries.propertyIn("reservationId", ids)) // use join-select, because all infos will be // needed later .setFetchMode("Reservation", FetchMode.JOIN).list(); for (Reservation r : tmpReservation) { result.add(r); } this.result = result; } }).getResult(); }
From source file:eu.jangos.manager.controller.AccountService.java
License:Apache License
/** * This method will login the account based on the given parameters. * /*from w w w . j av a 2 s. co m*/ * @param name The name of the account to log in. * @param password The password of the account trying to log in. * @return The logged in account. * @throws LoginException is thrown if there is an issue while authenticating this account. */ public Account login(String name, char[] password) throws LoginException { String hashpass = null; try { hashpass = Utils.createHashPass(name, new String(password)); } catch (NoSuchAlgorithmException ex) { throw new LoginException("There was an error while generating the hashpass."); } Account account = null; name = name.replaceAll("[^\\dA-Za-z ]", "").replaceAll("\\s+", "+"); try (Session session = HibernateUtil.getSessionFactory().openSession()) { account = (Account) session.createCriteria(Account.class).setFetchMode("locale", FetchMode.JOIN) .setFetchMode("realm", FetchMode.JOIN) .setFetchMode("bannedaccountsForFkBannedaccount", FetchMode.JOIN) .add(Restrictions.and(Restrictions.like("name", name), Restrictions.like("hashPass", hashpass))) .uniqueResult(); } catch (HibernateException he) { throw new LoginException( "There was an error while trying to retrieve the account information from the database."); } if (account == null) { throw new LoginException("This account does not exist"); } if (account.isLocked()) { throw new LoginException( "This account is locked, we don't think you should be allowed to manage the database."); } if (isAccountBanned(account)) { throw new LoginException( "This account is banned, we don't think you should be allowed to manage the database."); } return account; }
From source file:eu.jangos.manager.controller.BannedAccountService.java
License:Apache License
/** * This method checks whether an account is banned or not into the database. * * @param account The account to be checked. * @return true if the account is banned, false otherwise. *//*w w w . j av a2 s .co m*/ public boolean isAccountBanned(Account account) { if (account == null) { logger.debug("Account parameter is null. ban = true."); return true; } try (Session session = HibernateUtil.getSessionFactory().openSession()) { return (session.createCriteria(Bannedaccount.class) .add(Restrictions.and(Restrictions.eq("accountByFkBannedaccount.id", account.getId()), Restrictions.eq("active", true))) .uniqueResult() != null); } catch (HibernateException he) { logger.error("There was an error connecting to the database."); return true; } }
From source file:eu.jangos.manager.controller.BannedAccountService.java
License:Apache License
/** * This method will return the active ban record for the given account. * /*from w ww. java2 s .co m*/ * @param account The account for which the active ban must be returned. * @return */ public Bannedaccount getActiveBan(Account account) { if (account == null) { logger.debug("Account parameter is null. Returning null."); return null; } try (Session session = HibernateUtil.getSessionFactory().openSession()) { return (Bannedaccount) (session.createCriteria(Bannedaccount.class) .add(Restrictions.and(Restrictions.eq("accountByFkBannedaccount.id", account.getId()), Restrictions.eq("active", true))) .uniqueResult()); } catch (HibernateException he) { logger.error("There was an error connecting to the database."); return null; } }
From source file:eu.jangos.realm.controller.auth.BannedAccountService.java
License:Apache License
/** * This method checks whether an account is banned or not into the database. * * @param account The account to be checked. * @return true if the account is banned, false otherwise. *///w w w .j a v a 2 s. c o m public boolean isAccountBanned(Account account) { if (account == null) { logger.debug("Account parameter is null. ban = true."); return true; } try (Session session = HibernateUtil.getAuthSession().openSession()) { return (session.createCriteria(Bannedaccount.class) .add(Restrictions.and(Restrictions.eq("accountByFkBannedaccount.id", account.getId()), Restrictions.eq("active", true))) .uniqueResult() != null); } catch (HibernateException he) { logger.error("There was an error connecting to the database."); return true; } }