Example usage for org.hibernate.criterion Restrictions le

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

Introduction

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

Prototype

public static SimpleExpression le(String propertyName, Object value) 

Source Link

Document

Apply a "less than or equal" constraint to the named property

Usage

From source file:de.forsthaus.backend.dao.impl.MyCalendarEventDAOImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override//from   ww w .  java2s .c om
public List<MyCalendarEvent> getCalendarEventsFromToDate(Date beginDate, Date endDate, long usrId) {
    DetachedCriteria criteria = DetachedCriteria.forClass(MyCalendarEvent.class);
    criteria.add(Restrictions.ge("beginDate", beginDate));
    criteria.add(Restrictions.le("endDate", endDate));
    criteria.add(Restrictions.eq("secUser.id", usrId));
    criteria.setFetchMode("secUser", FetchMode.JOIN);

    return getHibernateTemplate().findByCriteria(criteria);
}

From source file:de.iteratec.iteraplan.businesslogic.reports.query.node.AbstractLeafNode.java

License:Open Source License

/**
 * Returns the {@link Criterion} for the specified {@code effectivePropertyName} and {@code comparator}.
 * /*from   w w  w .  j a v a  2s . co  m*/
 * @param effectivePropertyName the property name path
 * @param comparator the comparator describing the compare operation
 * @param attrType string representation of the property's attribute type as in {@link BBAttribute#getTypeOfAttribute(String)} 
 * @return the newly created {@link Criterion} for the specified {@code comparator} or {@code null} if the 
 *    comparator is not supported
 */
protected Criterion getCriterionForComparator(String effectivePropertyName, Comparator comparator,
        String attrType) {
    Criterion criterion = null;
    switch (comparator) {
    case EQ:
        criterion = Restrictions.eq(effectivePropertyName, getProcessedPattern());
        break;
    case GEQ:
        criterion = Restrictions.ge(effectivePropertyName, getProcessedPattern());
        break;
    case LEQ:
        criterion = Restrictions.le(effectivePropertyName, getProcessedPattern());
        break;
    case GT:
        criterion = Restrictions.gt(effectivePropertyName, getProcessedPattern());
        break;
    case LT:
        criterion = Restrictions.lt(effectivePropertyName, getProcessedPattern());
        break;
    case LIKE:
        criterion = new IteraplanLikeExpression(effectivePropertyName, getProcessedPattern().toString(), true);
        break;
    case NOT_LIKE:
        criterion = Restrictions.not(
                new IteraplanLikeExpression(effectivePropertyName, getProcessedPattern().toString(), true));
        break;
    case IS:
        // see Type#getSpecialPropertyHQLStrings
        criterion = "null".equals(getPattern()) ? Restrictions.isNull(effectivePropertyName)
                : Restrictions.isNotNull(effectivePropertyName);
        break;
    case ANY_ASSIGNMENT:
        criterion = getAnyAssignmentCriterion(effectivePropertyName, attrType);
        break;
    case NO_ASSIGNMENT:
        criterion = getNoAssignmentCriterion(effectivePropertyName, attrType);
        break;
    case NEQ:
        criterion = Restrictions.ne(effectivePropertyName, getProcessedPattern());
        break;
    default:
        break;
    }

    return criterion;
}

From source file:de.iteratec.iteraplan.businesslogic.reports.query.node.NumberAttributeLeafNode.java

License:Open Source License

/** {@inheritDoc} */
@Override// w  w  w  .j  a va  2 s.  c o  m
protected Criterion getCriterionForComparator() {
    String value = "value";

    Criterion criterion = null;
    switch (getComparator()) {
    case GT:
        criterion = Restrictions.gt(value, getPattern());
        break;
    case GEQ:
        criterion = Restrictions.ge(value, getPattern());
        break;
    case EQ:
        criterion = Restrictions.eq(value, getPattern());
        break;
    case LEQ:
        criterion = Restrictions.le(value, getPattern());
        break;
    case LT:
        criterion = Restrictions.lt(value, getPattern());
        break;
    case ANY_ASSIGNMENT:
        criterion = Restrictions.naturalId();
        break;
    default:
        throw new IteraplanTechnicalException(IteraplanErrorMessages.INTERNAL_ERROR);
    }

    return criterion;
}

From source file:de.iteratec.iteraplan.businesslogic.reports.query.node.SealLeafNode.java

License:Open Source License

/**
 * Returns the Criterion for the outdated entities.
 * /*w  ww  . j  ava  2  s .  com*/
 * @param effectivePropertyName the field name representing the seal state
 * @return the Criterion for the outdated entities
 */
private Criterion getOutdatedCriterion(String effectivePropertyName) {
    int expirationInDays = IteraplanProperties.getIntProperty(IteraplanProperties.SEAL_EXPIRATION_DAYS);
    Date minusDays = new DateTime().minusDays(expirationInDays).toDate();
    String idPropertyName = String.format("%s.%s", getResultTypeDBNameShortWithSuffix(), "id");

    final DetachedCriteria maxSealDate = DetachedCriteria.forClass(Seal.class, "seal");
    maxSealDate.setProjection(Projections.max("seal.date"));
    maxSealDate.add(Restrictions.eqProperty("seal.bb", idPropertyName));

    final DetachedCriteria lastSeal = DetachedCriteria.forClass(Seal.class, "lastSeal");
    lastSeal.add(Subqueries.propertyEq("lastSeal.date", maxSealDate));
    lastSeal.add(Restrictions.eqProperty("lastSeal.bb", idPropertyName));
    lastSeal.add(Restrictions.le("lastSeal.date", minusDays));
    lastSeal.setProjection(Projections.distinct(Property.forName("lastSeal.bb")));

    Criterion outdatedCriterion = Subqueries.propertyIn(idPropertyName, lastSeal);
    Criterion valid = Restrictions.eq(effectivePropertyName, SealState.VALID.toString());

    return Restrictions.and(valid, outdatedCriterion);
}

From source file:de.lemo.dms.connectors.moodle_1_9.ExtractAndMapMoodle.java

License:Open Source License

@Override
@SuppressWarnings("unchecked")
public void getLMStables(final DBConfigObject dbConf, final long readingfromtimestamp,
        final long readingtotimestamp, List<Long> courses, List<String> logins) {
    final Session session = HibernateUtil.getSessionFactory(dbConf).openSession();
    final Transaction tx = session.beginTransaction();

    boolean hasCR = false;
    if (courses != null && courses.size() > 0)
        hasCR = true;/*  ww w. ja  v a  2  s .co m*/

    boolean empty = false;
    // reading the LMS Database, create tables as lists of instances of the DB-table classes

    Criteria criteria;

    if (this.userLms == null) {

        criteria = session.createCriteria(ResourceLMS.class, "obj");
        if (hasCR)
            criteria.add(Restrictions.in("obj.course", courses));
        criteria.addOrder(Property.forName("obj.id").asc());
        this.resourceLms = criteria.list();
        logger.info("ResourceLMS tables: " + this.resourceLms.size());

        criteria = session.createCriteria(CourseLMS.class, "obj");
        if (hasCR)
            criteria.add(Restrictions.in("obj.id", courses));
        criteria.addOrder(Property.forName("obj.id").asc());
        this.courseLms = criteria.list();
        logger.info("CourseLMS tables: " + this.courseLms.size());

        criteria = session.createCriteria(ChatLMS.class, "obj");
        if (hasCR)
            criteria.add(Restrictions.in("obj.course", courses));
        criteria.addOrder(Property.forName("obj.id").asc());
        this.chatLms = criteria.list();
        logger.info("ChatLMS tables: " + this.chatLms.size());

        criteria = session.createCriteria(CourseCategoriesLMS.class, "obj");
        criteria.addOrder(Property.forName("obj.id").asc());
        this.courseCategoriesLms = criteria.list();
        logger.info("CourseCategoriesLMS tables: " + this.courseCategoriesLms.size());

        criteria = session.createCriteria(ForumLMS.class, "obj");
        if (hasCR)
            criteria.add(Restrictions.in("obj.course", courses));
        criteria.addOrder(Property.forName("obj.id").asc());
        this.forumLms = criteria.list();
        logger.info("ForumLMS tables: " + this.forumLms.size());

        criteria = session.createCriteria(CourseModulesLMS.class, "obj");
        if (hasCR)
            criteria.add(Restrictions.in("obj.course", courses));
        criteria.addOrder(Property.forName("obj.id").asc());
        this.courseModulesLms = criteria.list();
        logger.info("CourseModulesLMS tables: " + this.courseModulesLms.size());

        criteria = session.createCriteria(GroupsLMS.class, "obj");
        if (hasCR)
            criteria.add(Restrictions.in("obj.courseid", courses));
        criteria.addOrder(Property.forName("obj.id").asc());
        this.groupLms = criteria.list();
        logger.info("GroupsLMS tables: " + this.groupLms.size());

        criteria = session.createCriteria(QuizLMS.class, "obj");
        if (hasCR)
            criteria.add(Restrictions.in("obj.course", courses));
        criteria.addOrder(Property.forName("obj.id").asc());
        this.quizLms = criteria.list();
        logger.info("QuizLMS tables: " + this.quizLms.size());

        criteria = session.createCriteria(WikiLMS.class, "obj");
        if (hasCR)
            criteria.add(Restrictions.in("obj.course", courses));
        criteria.addOrder(Property.forName("obj.id").asc());
        this.wikiLms = criteria.list();
        logger.info("WikiLMS tables: " + this.wikiLms.size());

        criteria = session.createCriteria(QuizQuestionInstancesLMS.class, "obj");
        if (hasCR) {
            ArrayList<Long> ids = new ArrayList<Long>();
            for (QuizLMS e : this.quizLms)
                ids.add(e.getId());
            if (!(empty = ids.isEmpty()))
                criteria.add(Restrictions.in("obj.quiz", ids));
        }
        criteria.addOrder(Property.forName("obj.id").asc());
        if (!(hasCR && empty))
            this.quizQuestionInstancesLms = criteria.list();
        else
            this.quizQuestionInstancesLms = new ArrayList<QuizQuestionInstancesLMS>();
        logger.info("QuizQuestionInstancesLMS tables: " + this.quizQuestionInstancesLms.size());

        criteria = session.createCriteria(QuestionLMS.class, "obj");
        if (hasCR) {
            ArrayList<Long> ids = new ArrayList<Long>();
            for (QuizQuestionInstancesLMS e : this.quizQuestionInstancesLms)
                ids.add(e.getQuestion());
            if (!(empty = ids.isEmpty()))
                criteria.add(Restrictions.in("obj.id", ids));
        }
        criteria.addOrder(Property.forName("obj.id").asc());
        if (!(hasCR && empty))
            this.questionLms = criteria.list();
        else
            this.questionLms = new ArrayList<QuestionLMS>();
        empty = false;
        logger.info("QuestionLMS tables: " + this.questionLms.size());

        criteria = session.createCriteria(RoleLMS.class, "obj");
        criteria.addOrder(Property.forName("obj.id").asc());
        this.roleLms = criteria.list();
        logger.info("RoleLMS tables: " + this.roleLms.size());

        session.clear();

        criteria = session.createCriteria(ContextLMS.class, "obj");
        if (hasCR)
            criteria.add(Restrictions.in("obj.instanceid", courses));
        criteria.addOrder(Property.forName("obj.id").asc());

        this.contextLms = criteria.list();
        logger.info("ContextLMS tables: " + this.contextLms.size());

        criteria = session.createCriteria(AssignmentLMS.class, "obj");
        if (hasCR) {
            criteria.add(Restrictions.in("obj.course", courses));
        }
        criteria.addOrder(Property.forName("obj.id").asc());
        this.assignmentLms = criteria.list();
        logger.info("AssignmentLMS tables: " + this.assignmentLms.size());

        criteria = session.createCriteria(ScormLMS.class, "obj");
        if (hasCR) {
            criteria.add(Restrictions.in("obj.course", courses));
        }
        criteria.addOrder(Property.forName("obj.id").asc());
        this.scormLms = criteria.list();
        logger.info("ScormLMS tables: " + this.scormLms.size());

        criteria = session.createCriteria(GradeItemsLMS.class, "obj");
        if (hasCR) {
            criteria.add(Restrictions.in("obj.courseid", courses));
        }
        criteria.addOrder(Property.forName("obj.id").asc());
        this.gradeItemsLms = criteria.list();
        logger.info("GradeItemsLMS tables: " + this.gradeItemsLms.size());
    }

    criteria = session.createCriteria(LogLMS.class, "obj");
    if (hasCR)
        criteria.add(Restrictions.in("obj.course", courses));
    criteria.add(Restrictions.le("obj.time", readingtotimestamp));
    criteria.add(Restrictions.ge("obj.time", readingfromtimestamp));
    criteria.addOrder(Property.forName("obj.id").asc());
    this.logLms = criteria.list();
    logger.info("LogLMS tables: " + this.logLms.size());

    criteria = session.createCriteria(ChatLogLMS.class, "obj");
    if (hasCR) {
        ArrayList<Long> ids = new ArrayList<Long>();
        for (ChatLMS e : this.chatLms)
            ids.add(e.getId());
        if (!(empty = ids.isEmpty()))
            criteria.add(Restrictions.in("obj.chat", ids));
    }
    criteria.add(Restrictions.le("obj.timestamp", readingtotimestamp));
    criteria.add(Restrictions.ge("obj.timestamp", readingfromtimestamp));
    criteria.addOrder(Property.forName("obj.id").asc());
    if (!(hasCR && empty))
        this.chatLogLms = criteria.list();
    else
        this.chatLogLms = new ArrayList<ChatLogLMS>();
    empty = false;
    logger.info("ChatLogLMS tables: " + this.chatLogLms.size());

    final Query forumPosts;
    if (!hasCR) {
        forumPosts = session.createQuery(
                "from ForumPostsLMS x where x.created>=:readingtimestamp and x.created<=:ceiling order by x.id asc");
        forumPosts.setParameter("readingtimestamp", readingfromtimestamp);
        forumPosts.setParameter("ceiling", readingtotimestamp);
        this.forumPostsLms = forumPosts.list();
    } else {
        String courseClause = "(";
        for (int i = 0; i < courses.size(); i++) {
            courseClause += courses.get(i);
            if (i < courses.size() - 1)
                courseClause += ",";
            else
                courseClause += ")";
        }
        forumPosts = session.createSQLQuery(
                "SELECT posts.id,posts.userid,posts.created,posts.modified,posts.subject,posts.message,posts.discussion from forum_posts as posts JOIN log as logs ON posts.userid = logs.userid Where logs.course in "
                        + courseClause
                        + " and (posts.created = logs.time or posts.modified = logs.time) AND posts.created>=:readingtimestamp and posts.created<=:ceiling");
        forumPosts.setParameter("readingtimestamp", readingfromtimestamp);
        forumPosts.setParameter("ceiling", readingtotimestamp);
        List<Object[]> tmpl = forumPosts.list();
        if (this.forumPostsLms == null)
            this.forumPostsLms = new ArrayList<ForumPostsLMS>();
        for (Object[] obj : tmpl) {
            ForumPostsLMS p = new ForumPostsLMS();
            if (obj[0].getClass().equals(BigInteger.class)) {
                p.setId(((BigInteger) obj[0]).longValue());
            } else {
                p.setId(((Integer) obj[0]).longValue());
            }
            if (obj[0].getClass().equals(BigInteger.class)) {
                p.setUserid(((BigInteger) obj[1]).longValue());
            } else {
                p.setUserid(((Integer) obj[1]).longValue());
            }
            if (obj[0].getClass().equals(BigInteger.class)) {
                p.setCreated(((BigInteger) obj[2]).longValue());
            } else {
                p.setCreated(((Integer) obj[2]).longValue());
            }
            if (obj[0].getClass().equals(BigInteger.class)) {
                p.setModified(((BigInteger) obj[3]).longValue());
            } else {
                p.setModified(((Integer) obj[3]).longValue());
            }
            p.setSubject((String) obj[4]);
            p.setMessage((String) obj[5]);
            if (obj[0].getClass().equals(BigInteger.class)) {
                p.setDiscussion(((BigInteger) obj[6]).longValue());
            } else {
                p.setDiscussion(((Integer) obj[6]).longValue());
            }
            this.forumPostsLms.add(p);

            this.forumPostsLms.add(p);

        }
    }
    logger.info("ForumPostsLMS tables: " + this.forumPostsLms.size());

    final Query forumPostsModified;
    if (!hasCR) {
        forumPostsModified = session.createQuery(
                "from ForumPostsLMS x where x.modified>=:readingtimestamp and x.modified<=:ceiling order by x.id asc");
        forumPostsModified.setParameter("readingtimestamp", readingfromtimestamp);
        forumPostsModified.setParameter("ceiling", readingtotimestamp);
        this.forumPostsLms.addAll(forumPostsModified.list());
    } else {
        String courseClause = "(";
        for (int i = 0; i < courses.size(); i++) {
            courseClause += courses.get(i);
            if (i < courses.size() - 1)
                courseClause += ",";
            else
                courseClause += ")";
        }
        forumPostsModified = session.createSQLQuery(
                "SELECT posts.id,posts.userid,posts.created,posts.modified,posts.subject,posts.message from forum_posts as posts JOIN log as logs ON posts.userid = logs.userid Where logs.course in "
                        + courseClause
                        + " and (posts.created = logs.time or posts.modified = logs.time) AND posts.modified>=:readingtimestamp and posts.modified<=:ceiling");
        forumPostsModified.setParameter("readingtimestamp", readingfromtimestamp);
        forumPostsModified.setParameter("ceiling", readingtotimestamp);
        List<Object[]> tmpl = forumPostsModified.list();
        if (this.forumPostsLms == null)
            this.forumPostsLms = new ArrayList<ForumPostsLMS>();
        for (Object[] obj : tmpl) {
            ForumPostsLMS p = new ForumPostsLMS();
            p.setId(((Integer) obj[0]).longValue());
            p.setUserid(((Integer) obj[1]).longValue());
            p.setCreated(((Integer) obj[2]).longValue());
            p.setModified(((Integer) obj[3]).longValue());
            p.setSubject((String) obj[4]);
            p.setMessage((String) obj[5]);

            this.forumPostsLms.add(p);

        }
    }
    logger.info("ForumPostsLMS tables: " + this.forumPostsLms.size());

    session.clear();

    criteria = session.createCriteria(GroupsMembersLMS.class, "obj");
    if (hasCR) {
        ArrayList<Long> ids = new ArrayList<Long>();
        for (GroupsLMS e : this.groupLms)
            ids.add(e.getId());
        if (!(empty = ids.isEmpty()))
            criteria.add(Restrictions.in("obj.groupid", ids));
    }
    criteria.add(Restrictions.le("obj.timeadded", readingtotimestamp));
    criteria.add(Restrictions.ge("obj.timeadded", readingfromtimestamp));
    criteria.addOrder(Property.forName("obj.id").asc());
    if (!(hasCR && empty))
        this.groupMembersLms = criteria.list();
    else
        this.groupMembersLms = new ArrayList<GroupsMembersLMS>();
    empty = false;
    logger.info("GroupsMembersLMS tables: " + this.groupMembersLms.size());

    criteria = session.createCriteria(QuestionStatesLMS.class, "obj");
    if (hasCR) {
        ArrayList<Long> ids = new ArrayList<Long>();
        for (QuizQuestionInstancesLMS e : this.quizQuestionInstancesLms)
            ids.add(e.getQuestion());
        if (!(empty = ids.isEmpty()))
            criteria.add(Restrictions.in("obj.question", ids));
    }
    criteria.add(Restrictions.le("obj.timestamp", readingtotimestamp));
    criteria.add(Restrictions.ge("obj.timestamp", readingfromtimestamp));
    criteria.addOrder(Property.forName("obj.id").asc());
    if (!(hasCR && empty))
        this.questionStatesLms = criteria.list();
    else
        this.questionStatesLms = new ArrayList<QuestionStatesLMS>();
    empty = false;
    logger.info("QuestionStatesLMS tables: " + this.questionStatesLms.size());

    if (this.userLms == null) {
        criteria = session.createCriteria(RoleAssignmentsLMS.class, "obj");
        if (hasCR) {
            ArrayList<Long> ids = new ArrayList<Long>();
            for (ContextLMS c : this.contextLms) {
                if (c.getContextlevel() == 50 && courses.contains(c.getInstanceid()))
                    ids.add(c.getId());
            }
            if (!(empty = ids.isEmpty()))
                criteria.add(Restrictions.in("obj.contextid", ids));
        }
        criteria.addOrder(Property.forName("obj.id").asc());
        if (!empty)
            this.roleAssignmentsLms = criteria.list();
        else
            this.roleAssignmentsLms = new ArrayList<RoleAssignmentsLMS>();
        criteria = session.createCriteria(UserLMS.class, "obj");
        if (hasCR) {
            ArrayList<Long> ids = new ArrayList<Long>();
            for (RoleAssignmentsLMS e : this.roleAssignmentsLms)
                ids.add(e.getUserid());
            if (!(empty = ids.isEmpty()))
                criteria.add(Restrictions.in("obj.id", ids));
        }
        criteria.addOrder(Property.forName("obj.id").asc());
        if (!empty)
            this.userLms = criteria.list();
        else
            this.userLms = new ArrayList<UserLMS>();
        logger.info("UserLMS tables: " + this.userLms.size());
        this.roleAssignmentsLms = null;
    }

    criteria = session.createCriteria(RoleAssignmentsLMS.class, "obj");
    if (hasCR) {
        ArrayList<Long> ids = new ArrayList<Long>();
        for (ContextLMS c : this.contextLms) {
            if (c.getContextlevel() == 50 && courses.contains(c.getInstanceid()))
                ids.add(c.getId());
            if (!(empty = ids.isEmpty()))
                criteria.add(Restrictions.in("obj.contextid", ids));
        }
    }
    criteria.add(Restrictions.le("obj.timemodified", readingtotimestamp));
    criteria.add(Restrictions.ge("obj.timemodified", readingfromtimestamp));
    criteria.addOrder(Property.forName("obj.id").asc());
    if (!(hasCR && empty))
        this.roleAssignmentsLms = criteria.list();
    else
        this.roleAssignmentsLms = new ArrayList<RoleAssignmentsLMS>();
    empty = false;
    logger.info("RoleAssignmentsLMS tables: " + this.roleAssignmentsLms.size());

    criteria = session.createCriteria(AssignmentSubmissionsLMS.class, "obj");
    if (hasCR) {
        ArrayList<Long> ids = new ArrayList<Long>();
        for (AssignmentLMS e : this.assignmentLms)
            ids.add(e.getId());
        if (!(empty = ids.isEmpty()))
            criteria.add(Restrictions.in("obj.assignment", ids));
    }
    criteria.add(Restrictions.le("obj.timemodified", readingtotimestamp));
    criteria.add(Restrictions.ge("obj.timemodified", readingfromtimestamp));
    criteria.addOrder(Property.forName("obj.id").asc());
    if (!(hasCR && empty))
        this.assignmentSubmissionLms = criteria.list();
    else
        this.assignmentSubmissionLms = new ArrayList<AssignmentSubmissionsLMS>();
    empty = false;
    logger.info("AssignmentSubmissionsLMS tables: " + this.assignmentSubmissionLms.size());

    criteria = session.createCriteria(QuizGradesLMS.class, "obj");
    if (hasCR) {
        ArrayList<Long> ids = new ArrayList<Long>();
        for (QuizLMS e : this.quizLms)
            ids.add(e.getId());
        if (!(empty = ids.isEmpty()))
            criteria.add(Restrictions.in("obj.quiz", ids));
    }
    criteria.add(Restrictions.le("obj.timemodified", readingtotimestamp));
    criteria.add(Restrictions.ge("obj.timemodified", readingfromtimestamp));
    criteria.addOrder(Property.forName("obj.id").asc());
    if (!(hasCR && empty))
        this.quizGradesLms = criteria.list();
    else
        this.quizGradesLms = new ArrayList<QuizGradesLMS>();
    empty = false;
    logger.info("QuizGradesLMS tables: " + this.quizGradesLms.size());

    criteria = session.createCriteria(ForumDiscussionsLMS.class, "obj");
    if (hasCR) {
        ArrayList<Long> ids = new ArrayList<Long>();
        for (ForumLMS e : this.forumLms)
            ids.add(e.getId());
        if (!(empty = ids.isEmpty()))
            criteria.add(Restrictions.in("obj.forum", ids));
    }
    criteria.add(Restrictions.le("obj.timemodified", readingtotimestamp));
    criteria.add(Restrictions.ge("obj.timemodified", readingfromtimestamp));
    criteria.addOrder(Property.forName("obj.id").asc());
    if (!(hasCR && empty))
        this.forumDiscussionsLms = criteria.list();
    else
        this.forumDiscussionsLms = new ArrayList<ForumDiscussionsLMS>();
    empty = false;
    logger.info("ForumDiscussionsLMS tables: " + this.forumDiscussionsLms.size());

    criteria = session.createCriteria(GradeGradesLMS.class, "obj");
    if (hasCR) {
        ArrayList<Long> ids = new ArrayList<Long>();
        for (GradeItemsLMS e : this.gradeItemsLms)
            ids.add(e.getId());
        if (!(empty = ids.isEmpty()))
            criteria.add(Restrictions.in("obj.itemid", ids));
    }
    criteria.add(Restrictions.le("obj.timemodified", readingtotimestamp));
    criteria.add(Restrictions.ge("obj.timemodified", readingfromtimestamp));
    criteria.addOrder(Property.forName("obj.id").asc());
    if (!(hasCR && empty))
        this.gradeGradesLms = criteria.list();
    else
        this.gradeGradesLms = new ArrayList<GradeGradesLMS>();
    empty = false;
    logger.info("GradeGradesLMS tables: " + this.gradeGradesLms.size());

    session.clear();

    // hibernate session finish and close
    tx.commit();
    session.close();

}

From source file:de.powerstaff.business.dao.hibernate.StatistikDAOHibernateImpl.java

License:Open Source License

@Override
public List<KontakthistorieEntry> kontakthistorie(final Date aDatumVon, final Date aDatumBis,
        final User aBenutzer) {
    return (List<KontakthistorieEntry>) getHibernateTemplate().execute(new HibernateCallback() {

        @Override//from  w  w  w .ja  v a 2 s .  c  o m
        public Object doInHibernate(Session aSession) throws SQLException {
            List<KontakthistorieEntry> theResult = new ArrayList<KontakthistorieEntry>();

            Conjunction theRestrictions = Restrictions.conjunction();
            if (aDatumVon != null) {
                theRestrictions.add(Restrictions.ge("h.creationDate", aDatumVon));
            }
            if (aDatumBis != null) {
                theRestrictions.add(Restrictions.le("h.creationDate", aDatumBis));
            }
            if (aBenutzer != null) {
                theRestrictions.add(Restrictions.eq("h.creationUserID", aBenutzer.getUsername()));
            }

            // Freiberufler
            Criteria theCriteria = aSession.createCriteria(Freelancer.class, "p");
            theCriteria.createCriteria("history", "h");
            theCriteria.add(theRestrictions);

            ProjectionList theProjections = Projections.projectionList();
            theProjections.add(Projections.property("p.name1"));
            theProjections.add(Projections.property("p.name2"));
            theProjections.add(Projections.property("p.code"));
            theProjections.add(Projections.property("h.creationDate"));
            theProjections.add(Projections.property("h.creationUserID"));
            theProjections.add(Projections.property("h.type"));
            theProjections.add(Projections.property("h.description"));

            theCriteria.setProjection(theProjections);
            for (Object theResultObject : theCriteria.list()) {
                Object[] theResultArray = (Object[]) theResultObject;

                KontakthistorieEntry theEntry = new KontakthistorieEntry();
                theEntry.setName1((String) theResultArray[0]);
                theEntry.setName2((String) theResultArray[1]);
                theEntry.setCode((String) theResultArray[2]);
                Timestamp theTimestamp = (Timestamp) theResultArray[3];
                theEntry.setDatum(new Date(theTimestamp.getTime()));
                theEntry.setUserid((String) theResultArray[4]);
                theEntry.setType((HistoryType) theResultArray[5]);
                theEntry.setDescription((String) theResultArray[6]);

                theResult.add(theEntry);
            }

            // Partner
            theCriteria = aSession.createCriteria(Partner.class, "p");
            theCriteria.createCriteria("history", "h");
            theCriteria.add(theRestrictions);

            theProjections = Projections.projectionList();
            theProjections.add(Projections.property("p.name1"));
            theProjections.add(Projections.property("p.name2"));
            theProjections.add(Projections.property("h.creationDate"));
            theProjections.add(Projections.property("h.creationUserID"));
            theProjections.add(Projections.property("h.type"));
            theProjections.add(Projections.property("h.description"));

            theCriteria.setProjection(theProjections);
            for (Object theResultObject : theCriteria.list()) {
                Object[] theResultArray = (Object[]) theResultObject;

                KontakthistorieEntry theEntry = new KontakthistorieEntry();
                theEntry.setName1((String) theResultArray[0]);
                theEntry.setName2((String) theResultArray[1]);
                Timestamp theTimestamp = (Timestamp) theResultArray[2];
                theEntry.setDatum(new Date(theTimestamp.getTime()));
                theEntry.setUserid((String) theResultArray[3]);
                theEntry.setType((HistoryType) theResultArray[4]);
                theEntry.setDescription((String) theResultArray[5]);

                theResult.add(theEntry);
            }

            // Kunden
            theCriteria = aSession.createCriteria(Customer.class, "p");
            theCriteria.createCriteria("history", "h");
            theCriteria.add(theRestrictions);

            theProjections = Projections.projectionList();
            theProjections.add(Projections.property("p.name1"));
            theProjections.add(Projections.property("p.name2"));
            theProjections.add(Projections.property("h.creationDate"));
            theProjections.add(Projections.property("h.creationUserID"));
            theProjections.add(Projections.property("h.type"));
            theProjections.add(Projections.property("h.description"));

            theCriteria.setProjection(theProjections);
            for (Object theResultObject : theCriteria.list()) {
                Object[] theResultArray = (Object[]) theResultObject;

                KontakthistorieEntry theEntry = new KontakthistorieEntry();
                theEntry.setName1((String) theResultArray[0]);
                theEntry.setName2((String) theResultArray[1]);
                Timestamp theTimestamp = (Timestamp) theResultArray[2];
                theEntry.setDatum(new Date(theTimestamp.getTime()));
                theEntry.setUserid((String) theResultArray[3]);
                theEntry.setType((HistoryType) theResultArray[4]);
                theEntry.setDescription((String) theResultArray[5]);

                theResult.add(theEntry);
            }

            Collections.sort(theResult, new ReverseComparator(new BeanComparator("datum")));

            return theResult;
        }
    });
}

From source file:de.sub.goobi.forms.AktuelleSchritteForm.java

License:Open Source License

/**
 * Report the problem./*from  w ww.j  a  v a  2  s . co  m*/
 *
 * @return problem as String
 */
@SuppressWarnings("unchecked")
public String ReportProblem() {
    User ben = (User) Helper.getManagedBeanValue("#{LoginForm.myBenutzer}");
    if (ben == null) {
        Helper.setFehlerMeldung("userNotFound");
        return "";
    }
    if (myLogger.isDebugEnabled()) {
        myLogger.debug("mySchritt.ID: " + this.mySchritt.getId());
        myLogger.debug("Korrekturschritt.ID: " + this.myProblemID);
    }
    this.myDav.UploadFromHome(this.mySchritt.getProcess());
    Date myDate = new Date();
    this.mySchritt.setProcessingStatusEnum(TaskStatus.LOCKED);
    this.mySchritt.setEditTypeEnum(TaskEditType.MANUAL_SINGLE);
    mySchritt.setProcessingTime(new Date());
    mySchritt.setProcessingUser(ben);
    this.mySchritt.setProcessingBegin(null);

    try {
        Task temp = serviceManager.getTaskService().find(this.myProblemID);
        temp.setProcessingStatusEnum(TaskStatus.OPEN);
        temp = serviceManager.getTaskService().setCorrectionStep(temp);
        temp.setProcessingEnd(null);

        org.kitodo.data.database.beans.ProcessProperty pe = new org.kitodo.data.database.beans.ProcessProperty();
        pe.setTitle(Helper.getTranslation("Korrektur notwendig"));
        pe.setValue("[" + this.formatter.format(new Date()) + ", "
                + serviceManager.getUserService().getFullName(ben) + "] " + this.problemMessage);
        pe.setType(PropertyType.messageError);
        pe.setProcess(this.mySchritt.getProcess());
        this.mySchritt.getProcess().getProperties().add(pe);

        String message = Helper.getTranslation("KorrekturFuer") + " " + temp.getTitle() + ": "
                + this.problemMessage + " (" + serviceManager.getUserService().getFullName(ben) + ")";
        this.mySchritt.getProcess().setWikiField(WikiFieldHelper.getWikiMessage(this.mySchritt.getProcess(),
                this.mySchritt.getProcess().getWikiField(), "error", message));
        serviceManager.getTaskService().save(temp);
        serviceManager.getProcessService().getHistoryInitialized(this.mySchritt.getProcess())
                .add(new History(myDate, temp.getOrdering().doubleValue(), temp.getTitle(),
                        HistoryType.taskError, temp.getProcess()));
        /*
         * alle Schritte zwischen dem aktuellen und dem Korrekturschritt
         * wieder schliessen
         */
        List<Task> alleSchritteDazwischen = Helper.getHibernateSession().createCriteria(Task.class)
                .add(Restrictions.le("ordering", this.mySchritt.getOrdering()))
                .add(Restrictions.gt("ordering", temp.getOrdering())).addOrder(Order.asc("ordering"))
                .createCriteria("process").add(Restrictions.idEq(this.mySchritt.getProcess().getId())).list();
        for (Iterator<Task> iter = alleSchritteDazwischen.iterator(); iter.hasNext();) {
            Task step = iter.next();
            step.setProcessingStatusEnum(TaskStatus.LOCKED);
            step = serviceManager.getTaskService().setCorrectionStep(step);
            step.setProcessingEnd(null);
            serviceManager.getTaskService().save(step);
        }

        /*
         * den Prozess aktualisieren, so dass der Sortierungshelper
         * gespeichert wird
         */
        this.serviceManager.getProcessService().save(this.mySchritt.getProcess());
    } catch (DAOException | IOException | ResponseException e) {
        myLogger.error("task couldn't get saved/inserted", e);
    }

    this.problemMessage = "";
    this.myProblemID = 0;
    return FilterAlleStart();
}

From source file:de.sub.goobi.forms.AktuelleSchritteForm.java

License:Open Source License

/**
 * Solve problem./*w w w  .j av  a  2 s.c  om*/
 *
 * @return String
 */
@SuppressWarnings("unchecked")
public String SolveProblem() {
    User ben = (User) Helper.getManagedBeanValue("#{LoginForm.myBenutzer}");
    if (ben == null) {
        Helper.setFehlerMeldung("userNotFound");
        return "";
    }
    Date now = new Date();
    this.myDav.UploadFromHome(this.mySchritt.getProcess());
    this.mySchritt.setProcessingStatusEnum(TaskStatus.DONE);
    this.mySchritt.setProcessingEnd(now);
    this.mySchritt.setEditTypeEnum(TaskEditType.MANUAL_SINGLE);
    mySchritt.setProcessingTime(new Date());
    mySchritt.setProcessingUser(ben);

    try {
        Task temp = serviceManager.getTaskService().find(this.mySolutionID);
        /*
         * alle Schritte zwischen dem aktuellen und dem Korrekturschritt
         * wieder schliessen
         */
        List<Task> alleSchritteDazwischen = Helper.getHibernateSession().createCriteria(Task.class)
                .add(Restrictions.ge("ordering", this.mySchritt.getOrdering()))
                .add(Restrictions.le("ordering", temp.getOrdering())).addOrder(Order.asc("ordering"))
                .createCriteria("process").add(Restrictions.idEq(this.mySchritt.getProcess().getId())).list();
        for (Iterator<Task> iter = alleSchritteDazwischen.iterator(); iter.hasNext();) {
            Task step = iter.next();
            step.setProcessingStatusEnum(TaskStatus.DONE);
            step.setProcessingEnd(now);
            step.setPriority(0);
            if (step.getId().intValue() == temp.getId().intValue()) {
                step.setProcessingStatusEnum(TaskStatus.OPEN);
                step = serviceManager.getTaskService().setCorrectionStep(step);
                step.setProcessingEnd(null);
                // step.setBearbeitungsbeginn(null);
                step.setProcessingTime(now);
            }
            mySchritt.setProcessingTime(new Date());
            mySchritt.setProcessingUser(ben);
            serviceManager.getTaskService().save(step);
        }

        /*
         * den Prozess aktualisieren, so dass der Sortierungshelper
         * gespeichert wird
         */
        String message = Helper.getTranslation("KorrekturloesungFuer") + " " + temp.getTitle() + ": "
                + this.solutionMessage + " (" + serviceManager.getUserService().getFullName(ben) + ")";
        this.mySchritt.getProcess().setWikiField(WikiFieldHelper.getWikiMessage(this.mySchritt.getProcess(),
                this.mySchritt.getProcess().getWikiField(), "info", message));

        org.kitodo.data.database.beans.ProcessProperty pe = new org.kitodo.data.database.beans.ProcessProperty();
        pe.setTitle(Helper.getTranslation("Korrektur durchgefuehrt"));
        pe.setValue("[" + this.formatter.format(new Date()) + ", "
                + serviceManager.getUserService().getFullName(ben) + "] "
                + Helper.getTranslation("KorrekturloesungFuer") + " " + temp.getTitle() + ": "
                + this.solutionMessage);
        pe.setType(PropertyType.messageImportant);
        pe.setProcess(this.mySchritt.getProcess());
        this.mySchritt.getProcess().getProperties().add(pe);

        this.serviceManager.getProcessService().save(this.mySchritt.getProcess());
    } catch (DAOException | IOException | ResponseException e) {
        myLogger.error("task couldn't get saved/inserted", e);
    }

    this.solutionMessage = "";
    this.mySolutionID = 0;
    return FilterAlleStart();
}

From source file:de.sub.goobi.helper.BatchStepHelper.java

License:Open Source License

private void reportProblem() {
    Date myDate = new Date();
    this.currentStep.setProcessingStatusEnum(TaskStatus.LOCKED);
    this.currentStep.setEditTypeEnum(TaskEditType.MANUAL_SINGLE);
    currentStep.setProcessingTime(new Date());
    User ben = (User) Helper.getManagedBeanValue("#{LoginForm.myBenutzer}");
    if (ben != null) {
        currentStep.setProcessingUser(ben);
    }/* www  .  ja  va2 s. c om*/
    this.currentStep.setProcessingBegin(null);

    try {
        Task temp = null;
        for (Task s : this.currentStep.getProcess().getTasks()) {
            if (s.getTitle().equals(this.myProblemStep)) {
                temp = s;
            }
        }
        if (temp != null) {
            temp.setProcessingStatusEnum(TaskStatus.OPEN);
            temp = serviceManager.getTaskService().setCorrectionStep(temp);
            temp.setProcessingEnd(null);

            Property processProperty = new Property();
            processProperty.setTitle(Helper.getTranslation("Korrektur notwendig"));
            processProperty.setValue("[" + this.formatter.format(new Date()) + ", "
                    + serviceManager.getUserService().getFullName(ben) + "] " + this.problemMessage);
            processProperty.setType(PropertyType.messageError);
            processProperty.getProcesses().add(this.currentStep.getProcess());
            this.currentStep.getProcess().getProperties().add(processProperty);

            String message = Helper.getTranslation("KorrekturFuer") + " " + temp.getTitle() + ": "
                    + this.problemMessage + " (" + serviceManager.getUserService().getFullName(ben) + ")";
            this.currentStep.getProcess()
                    .setWikiField(WikiFieldHelper.getWikiMessage(this.currentStep.getProcess(),
                            this.currentStep.getProcess().getWikiField(), "error", message));

            this.serviceManager.getTaskService().save(temp);
            this.serviceManager.getProcessService().getHistoryInitialized(this.currentStep.getProcess())
                    .add(new History(myDate, temp.getOrdering().doubleValue(), temp.getTitle(),
                            HistoryTypeEnum.taskError, temp.getProcess()));
            /*
             * alle Schritte zwischen dem aktuellen und dem Korrekturschritt
             * wieder schliessen
             */
            @SuppressWarnings("unchecked")
            List<Task> alleSchritteDazwischen = Helper.getHibernateSession().createCriteria(Task.class)
                    .add(Restrictions.le("ordering", this.currentStep.getOrdering()))
                    .add(Restrictions.gt("ordering", temp.getOrdering())).addOrder(Order.asc("ordering"))
                    .createCriteria("process").add(Restrictions.idEq(this.currentStep.getProcess().getId()))
                    .list();
            for (Task task : alleSchritteDazwischen) {
                task.setProcessingStatusEnum(TaskStatus.LOCKED);
                task = serviceManager.getTaskService().setCorrectionStep(task);
                task.setProcessingEnd(null);
            }
        }
        /*
         * den Prozess aktualisieren, so dass der Sortierungshelper
         * gespeichert wird
         */
    } catch (DataException e) {
        logger.error(e);
    }
}

From source file:de.sub.goobi.helper.BatchStepHelper.java

License:Open Source License

private void solveProblem() throws AuthenticationException {
    User ben = (User) Helper.getManagedBeanValue("#{LoginForm.myBenutzer}");
    if (ben == null) {
        throw new AuthenticationException("userNotFound");
    }//from  www  .  ja v  a 2s .com
    Date now = new Date();
    this.myDav.uploadFromHome(this.currentStep.getProcess());
    this.currentStep.setProcessingStatusEnum(TaskStatus.DONE);
    this.currentStep.setProcessingEnd(now);
    this.currentStep.setEditTypeEnum(TaskEditType.MANUAL_SINGLE);
    currentStep.setProcessingTime(new Date());
    currentStep.setProcessingUser(ben);

    try {
        Task temp = null;
        for (Task s : this.currentStep.getProcess().getTasks()) {
            if (s.getTitle().equals(this.mySolutionStep)) {
                temp = s;
            }
        }
        if (temp != null) {
            /*
             * alle Schritte zwischen dem aktuellen und dem Korrekturschritt
             * wieder schliessen
             */
            @SuppressWarnings("unchecked")
            List<Task> alleSchritteDazwischen = Helper.getHibernateSession().createCriteria(Task.class)
                    .add(Restrictions.ge("ordering", this.currentStep.getOrdering()))
                    .add(Restrictions.le("ordering", temp.getOrdering())).addOrder(Order.asc("ordering"))
                    .createCriteria("process").add(Restrictions.idEq(this.currentStep.getProcess().getId()))
                    .list();
            for (Task task : alleSchritteDazwischen) {
                task.setProcessingStatusEnum(TaskStatus.DONE);
                task.setProcessingEnd(now);
                task.setPriority(0);
                if (task.getId().intValue() == temp.getId().intValue()) {
                    task.setProcessingStatusEnum(TaskStatus.OPEN);
                    task = serviceManager.getTaskService().setCorrectionStep(task);
                    task.setProcessingEnd(null);
                    task.setProcessingTime(now);
                }
                this.serviceManager.getTaskService().save(task);
            }

            Property processProperty = new Property();
            processProperty.setTitle(Helper.getTranslation("Korrektur durchgefuehrt"));
            processProperty.setValue("[" + this.formatter.format(new Date()) + ", "
                    + serviceManager.getUserService().getFullName(ben) + "] "
                    + Helper.getTranslation("KorrekturloesungFuer") + " " + temp.getTitle() + ": "
                    + this.solutionMessage);
            processProperty.getProcesses().add(this.currentStep.getProcess());
            processProperty.setType(PropertyType.messageImportant);
            this.currentStep.getProcess().getProperties().add(processProperty);

            String message = Helper.getTranslation("KorrekturloesungFuer") + " " + temp.getTitle() + ": "
                    + this.solutionMessage + " (" + serviceManager.getUserService().getFullName(ben) + ")";
            this.currentStep.getProcess()
                    .setWikiField(WikiFieldHelper.getWikiMessage(this.currentStep.getProcess(),
                            this.currentStep.getProcess().getWikiField(), "info", message));
            /*
             * den Prozess aktualisieren, so dass der Sortierungshelper
             * gespeichert wird
             */
        }
    } catch (DataException e) {
        logger.error(e);
    }
}