Example usage for org.hibernate.criterion ProjectionList add

List of usage examples for org.hibernate.criterion ProjectionList add

Introduction

In this page you can find the example usage for org.hibernate.criterion ProjectionList add.

Prototype

public ProjectionList add(Projection projection) 

Source Link

Document

Add a projection to this list of projections

Usage

From source file:org.eurekastreams.server.persistence.mappers.GetPendingDomainGroupsForOrg.java

License:Apache License

/**
 * Execute getting the groups pending for an org.
 * /*from w  ww.  j ava2s  .c  om*/
 * @param inRequest
 *            the request for the data.
 * @return A pageset of Groups pending for the Org in the request.
 */
@SuppressWarnings("unchecked")
@Override
public PagedSet<DomainGroupModelView> execute(final GetPendingDomainGroupsForOrgRequest inRequest) {
    // create our query
    Criteria criteria = getHibernateSession().createCriteria(DomainGroup.class);

    // tell hibernate which fields we want back
    ProjectionList fields = Projections.projectionList();

    fields.add(getColumn("id"));
    fields.add(getColumn("shortName"));
    fields.add(getColumn("name"));
    fields.add(getColumn("description"));
    fields.add(Projections.property("publicGroup").as("isPublic"));

    fields.add(Projections.property("createdBy.id").as("personCreatedById"));

    fields.add(getColumn("dateAdded"));

    criteria.setProjection(fields);

    // add restrictions (where clauses)

    // pending groups
    criteria.add(Restrictions.eq("isPending", true));

    // set the sort order
    criteria.addOrder(Order.asc("dateAdded"));

    // set the result transformer - transforms tuples into
    // DomainGroupModelViews
    ModelViewResultTransformer<DomainGroupModelView> resultTransformer;
    resultTransformer = new ModelViewResultTransformer<DomainGroupModelView>(new DomainGroupModelViewFactory());
    criteria.setResultTransformer(resultTransformer);

    criteria.setFirstResult(inRequest.getPageStart());
    criteria.setMaxResults(inRequest.getMaxResults());

    // get the results
    List<DomainGroupModelView> results = criteria.list();

    // populate info from the cache
    populateCachedFields(results);

    // Get Total Row Count
    Criteria rowCountCriteria = getHibernateSession().createCriteria(DomainGroup.class);
    rowCountCriteria.setProjection(Projections.rowCount());
    rowCountCriteria.add(Restrictions.eq("isPending", true));

    // Create Page Set
    PagedSet<DomainGroupModelView> pagedSet = new PagedSet<DomainGroupModelView>();
    pagedSet.setPagedSet(results);
    pagedSet.setFromIndex(inRequest.getPageStart());
    pagedSet.setToIndex(inRequest.getPageStart() + results.size() - 1);
    pagedSet.setTotal((Integer) rowCountCriteria.list().get(0));

    return pagedSet;

}

From source file:org.eurekastreams.server.persistence.mappers.GetPendingDomainGroupsMapper.java

License:Apache License

/**
 * Execute getting the groups pending for an org.
 * //  w  ww .  j  a v a 2 s .c  om
 * @param inRequest
 *            the request for the data.
 * @return A pageset of Groups pending for the Org in the request.
 */
@SuppressWarnings("unchecked")
@Override
public PagedSet<DomainGroupModelView> execute(final GetPendingDomainGroupsRequest inRequest) {
    // create our query
    Criteria criteria = getHibernateSession().createCriteria(DomainGroup.class);

    // tell hibernate which fields we want back
    ProjectionList fields = Projections.projectionList();

    fields.add(getColumn("id"));
    fields.add(getColumn("shortName"));
    fields.add(getColumn("name"));
    fields.add(getColumn("description"));
    fields.add(Projections.property("publicGroup").as("isPublic"));

    fields.add(Projections.property("createdBy.id").as("personCreatedById"));

    fields.add(getColumn("dateAdded"));

    criteria.setProjection(fields);

    // add restrictions (where clauses)

    // pending groups
    criteria.add(Restrictions.eq("isPending", true));

    // set the sort order
    criteria.addOrder(Order.asc("dateAdded"));

    // set the result transformer - transforms tuples into
    // DomainGroupModelViews
    ModelViewResultTransformer<DomainGroupModelView> resultTransformer;
    resultTransformer = new ModelViewResultTransformer<DomainGroupModelView>(new DomainGroupModelViewFactory());
    criteria.setResultTransformer(resultTransformer);

    //The First result sets the start row offset for the dataset 
    //The Max result denotes the no. of rows fetched from the dataset
    criteria.setFirstResult(inRequest.getPageStart());
    criteria.setMaxResults(MAX_RESULTS);

    // get the results
    List<DomainGroupModelView> results = criteria.list();

    // populate info from the cache
    populateCachedFields(results);

    // Get Total Row Count
    Criteria rowCountCriteria = getHibernateSession().createCriteria(DomainGroup.class);
    rowCountCriteria.setProjection(Projections.rowCount());
    rowCountCriteria.add(Restrictions.eq("isPending", true));

    // Create Page Set
    PagedSet<DomainGroupModelView> pagedSet = new PagedSet<DomainGroupModelView>();
    pagedSet.setPagedSet(results);
    pagedSet.setFromIndex(inRequest.getPageStart());
    pagedSet.setToIndex(inRequest.getPageStart() + results.size() - 1);
    pagedSet.setTotal((Integer) rowCountCriteria.list().get(0));

    return pagedSet;

}

From source file:org.eurekastreams.server.persistence.mappers.stream.BulkActivitiesDbMapper.java

License:Apache License

/**
 * Looks in cache for the necessary activity DTOs and returns them if found. Otherwise, makes a database call, puts
 * them in cache, and returns them.//from w  w w  .j a va2  s  . c  om
 * 
 * @param activityIds
 *            the list of ids that should be found.
 * @return list of ActivityDTO objects.
 */
@SuppressWarnings("unchecked")
public List<ActivityDTO> execute(final List<Long> activityIds) {
    Criteria criteria = getHibernateSession().createCriteria(Activity.class);
    ProjectionList fields = Projections.projectionList();
    fields.add(getColumn("id"));
    fields.add(getColumn("verb"));
    fields.add(getColumn("baseObjectType"));
    fields.add(Projections.property("baseObject").as("baseObjectProperties"));
    fields.add(Projections.property("recipStreamScope.destinationEntityId").as("destinationStreamEntityId"));
    fields.add(Projections.property("recipStreamScope.id").as("destinationStreamScopeId"));
    fields.add(Projections.property("recipStreamScope.scopeType").as("destinationStreamScopeType"));
    fields.add(Projections.property("recipStreamScope.uniqueKey").as("destinationStreamUniqueKey"));
    fields.add(Projections.property("recipientParentOrg.id").as("recipientParentOrgId"));
    fields.add(getColumn("isDestinationStreamPublic"));
    fields.add(getColumn("actorType"));
    fields.add(getColumn("originalActorType"));
    fields.add(Projections.property("actorId").as("actorUniqueIdentifier"));
    fields.add(Projections.property("originalActorId").as("originalActorUniqueIdentifier"));
    fields.add(getColumn("postedTime"));
    fields.add(getColumn("mood"));
    fields.add(getColumn("location"));
    fields.add(getColumn("annotation"));
    fields.add(getColumn("appId"));
    fields.add(getColumn("appSource"));
    fields.add(getColumn("appName"));
    fields.add(getColumn("showInStream"));
    criteria.createAlias("recipientStreamScope", "recipStreamScope");
    criteria.setProjection(fields);
    criteria.add(Restrictions.in("this.id", activityIds));

    final Map<Long, ActivityDTO> activityMap = new HashMap<Long, ActivityDTO>();

    ModelViewResultTransformer<ActivityDTO> resultTransformer = new ModelViewResultTransformer<ActivityDTO>(
            new ActivityDTOFactory());
    criteria.setResultTransformer(resultTransformer);
    List<ActivityDTO> results = criteria.list();
    for (ActivityDTO activity : results) {
        activityMap.put(activity.getId(), activity);

        // fills in data from cached view of stream
        List<Long> streamIds = new ArrayList<Long>();
        streamIds.add(activity.getDestinationStream().getId());

        // get the display name for the destination stream
        if (activity.getDestinationStream().getUniqueIdentifier() != null) {
            if (activity.getDestinationStream().getType() == EntityType.PERSON) {
                PersonModelView person = getPersonModelViewByAccountIdMapper
                        .execute(activity.getDestinationStream().getUniqueIdentifier());
                activity.getDestinationStream().setDisplayName(person.getDisplayName());

            } else if (activity.getDestinationStream().getType() == EntityType.GROUP) {
                DomainGroupModelView group = groupMapper
                        .fetchUniqueResult(activity.getDestinationStream().getUniqueIdentifier());
                activity.getDestinationStream().setDisplayName(group.getName());
            }
        }

        if (activity.getActor().getType() == EntityType.PERSON) {
            List<String> peopleIds = new ArrayList<String>();
            peopleIds.add(activity.getActor().getUniqueIdentifier());
            List<PersonModelView> people = getPersonModelViewsByAccountIdsMapper.execute(peopleIds);
            if (people.size() > 0) {
                activity.getActor().setId(people.get(0).getEntityId());
                activity.getActor().setDisplayName(people.get(0).getDisplayName());
                activity.getActor().setAvatarId(people.get(0).getAvatarId());
            }
        } else if (activity.getActor().getType() == EntityType.GROUP) {
            List<String> groupIds = new ArrayList<String>();
            groupIds.add(activity.getActor().getUniqueIdentifier());
            List<DomainGroupModelView> groups = groupMapper.execute(groupIds);
            if (groups.size() > 0) {
                activity.getActor().setId(groups.get(0).getEntityId());
                activity.getActor().setDisplayName(groups.get(0).getName());
                activity.getActor().setAvatarId(groups.get(0).getAvatarId());
            }
        }
        // fills in data from cached view of original actor
        if (activity.getOriginalActor().getType() == EntityType.PERSON) {
            List<String> peopleIds = new ArrayList<String>();
            peopleIds.add(activity.getOriginalActor().getUniqueIdentifier());
            List<PersonModelView> people = getPersonModelViewsByAccountIdsMapper.execute(peopleIds);
            if (people.size() > 0) {
                activity.getOriginalActor().setId(people.get(0).getEntityId());
                activity.getOriginalActor().setDisplayName(people.get(0).getDisplayName());
                activity.getOriginalActor().setAvatarId(people.get(0).getAvatarId());
            }
        }

        loadCommentInfo(activity); // set the first/last comment and comment count.
    }

    final List<ActivityDTO> orderedResults = new LinkedList<ActivityDTO>();

    for (int i = 0; i < activityIds.size(); i++) {
        if (activityMap.containsKey(activityIds.get(i))) {
            orderedResults.add(activityMap.get(activityIds.get(i)));
        }
    }

    return orderedResults;
}

From source file:org.eurekastreams.server.persistence.mappers.stream.GetCommentsById.java

License:Apache License

/**
 * Queries DB to get CommentDTOs associated with ids passed in.
 * /*from   w w w  .  j  a  va 2s. c  o m*/
 * @param unCachedIds
 *            Ids for DTOs to be returned.
 * @return List of CommentDTOs associated with ids passed in.
 */
@SuppressWarnings("unchecked")
private List<CommentDTO> getCommentDTOsFromDataSource(final List<Long> unCachedIds) {
    List<CommentDTO> results = null;

    // One or more of the activities were missing in the cache so go to the database
    if (unCachedIds.size() != 0) {
        Criteria criteria = getHibernateSession().createCriteria(Comment.class);
        ProjectionList fields = Projections.projectionList();
        fields.add(getColumn("id"));
        fields.add(getColumn("body"));
        fields.add(getColumn("timeSent"));
        fields.add(Projections.property("author.id").as("authorId"));
        fields.add(Projections.property("target.id").as("activityId"));
        criteria.setProjection(fields);

        criteria.setResultTransformer(resultTransformer);

        criteria.add(Restrictions.in("this.id", unCachedIds));

        results = criteria.list();
    }
    return (results == null) ? new ArrayList<CommentDTO>(0) : results;
}

From source file:org.eurekastreams.server.persistence.strategies.DomainGroupQueryStrategy.java

License:Apache License

/**
 * Build the base Criteria object./*from  www  .ja va  2s  .c  o m*/
 * 
 * @param hibernateSession
 *            the hibernate session used to create the criteria.
 * @return the base criteria object.
 */
public Criteria getCriteria(final Session hibernateSession) {
    Criteria criteria = hibernateSession.createCriteria(DomainGroup.class);
    ProjectionList fields = Projections.projectionList();
    fields.add(getColumn("id"));
    fields.add(getColumn("description"));
    fields.add(getColumn("name"));
    fields.add(getColumn("shortName"));
    fields.add(Projections.property("publicGroup").as("isPublic"));
    fields.add(getColumn("updatesCount"));
    fields.add(getColumn("followersCount"));
    fields.add(getColumn("dateAdded"));
    fields.add(getColumn("avatarId"));
    fields.add(getColumn("avatarCropSize"));
    fields.add(getColumn("avatarCropX"));
    fields.add(getColumn("avatarCropY"));
    fields.add(getColumn("bannerId"));
    fields.add(getColumn("url"));
    fields.add(getColumn("overview"));
    fields.add(getColumn("commentable"));
    fields.add(getColumn("streamPostable"));
    fields.add(getColumn("suppressPostNotifToMember"));
    fields.add(getColumn("suppressPostNotifToCoordinator"));
    fields.add(Projections.property("cb.accountId").as("personCreatedByAccountId"));
    fields.add(Projections.property("cb.displayName").as("personCreatedByDisplayName"));
    fields.add(Projections.property("stream.id").as("streamId"));
    criteria.setProjection(fields);
    criteria.createAlias("createdBy", "cb");
    criteria.createAlias("streamScope", "stream");

    // We don't currently cache pending groups
    // TODO: this needs to change - we should figure out how to remove this rule
    criteria.add(Restrictions.eq("isPending", false));

    ModelViewResultTransformer<DomainGroupModelView> resultTransformer = //
            new ModelViewResultTransformer<DomainGroupModelView>(new DomainGroupModelViewFactory());
    criteria.setResultTransformer(resultTransformer);

    return criteria;
}

From source file:org.eurekastreams.server.persistence.strategies.PersonQueryStrategy.java

License:Apache License

/**
 * Build the base Criteria object./*from   www .  j  a  va  2  s.co m*/
 * 
 * @param hibernateSession
 *            the hibernate session used to create the criteria.
 * @return the base criteria object.
 */
public Criteria getCriteria(final Session hibernateSession) {
    Criteria criteria = hibernateSession.createCriteria(Person.class);
    ProjectionList fields = Projections.projectionList();
    fields.add(getColumn("id"));
    fields.add(getColumn("dateAdded"));
    fields.add(getColumn("accountId"));
    fields.add(getColumn("openSocialId"));
    fields.add(getColumn("avatarId"));
    fields.add(getColumn("avatarCropX"));
    fields.add(getColumn("avatarCropY"));
    fields.add(getColumn("avatarCropSize"));
    fields.add(getColumn("lastName"));
    fields.add(getColumn("preferredName"));
    fields.add(getColumn("jobDescription"));
    fields.add(getColumn("title"));
    fields.add(getColumn("overview"));
    fields.add(getColumn("followersCount"));
    fields.add(getColumn("followingCount"));
    fields.add(getColumn("groupsCount"));
    fields.add(getColumn("optOutVideoIds"));
    fields.add(getColumn("updatesCount"));
    fields.add(getColumn("email"));
    fields.add(getColumn("commentable"));
    fields.add(getColumn("companyName"));
    fields.add(getColumn("streamPostable"));
    fields.add(getColumn("additionalProperties"));
    fields.add(getColumn("groupStreamHiddenLineIndex"));
    fields.add(getColumn("lastAcceptedTermsOfService"));
    fields.add(getColumn("accountLocked"));
    fields.add(getColumn("workPhone"));
    fields.add(getColumn("cellPhone"));
    fields.add(getColumn("fax"));
    fields.add(getColumn("biography"));
    fields.add(Projections.property("streamViewHiddenLineIndex").as("compositeStreamHiddenLineIndex"));
    fields.add(Projections.property("stream.id").as("streamId"));
    criteria.setProjection(fields);
    criteria.createAlias("streamScope", "stream");

    ModelViewResultTransformer<PersonModelView> resultTransformer = new ModelViewResultTransformer<PersonModelView>(
            new PersonModelViewFactory());
    criteria.setResultTransformer(resultTransformer);

    return criteria;
}

From source file:org.eurocarbdb.action.hplc.digestAssign.java

License:Open Source License

public String execute() throws Exception {

    refineDigestId = digest_id;//from  w  ww .  j  a v  a2  s.  co  m

    if (classA1 == 0) {
        classA1 = replaceSearch;
    }

    if (classA2 == 0) {
        classA2 = replaceSearch;
    }

    if (classA3 == 0) {
        classA3 = replaceSearch;
    }

    if (classA4 == 0) {
        classA4 = replaceSearch;
    }

    if (refineAssignment != null) {
        SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
        Session session = sessionFactory.openSession();
        logger.info("user whats a refinement displayed");
        logger.info("confirm digest id for criteria" + refineDigestId);

        Criteria criteria = session.createCriteria(HplcPeaksAnnotated.class);
        Disjunction disjunction = Restrictions.disjunction();
        ProjectionList proList = Projections.projectionList();
        criteria.add(Expression.eq("profileId", profile_id));
        criteria.add(Expression.eq("digestId", refineDigestId));
        criteria.createAlias("glycan", "G");
        proList.add(Projections.property("nameAbbreviation"));
        proList.add(Projections.property("gu"));
        proList.add(Projections.property("dbGu"));
        proList.add(Projections.property("peakArea"));
        proList.add(Projections.property("G.ogbitranslation"));
        proList.add(Projections.property("hplcPeaksAnnotatedId"));

        criteria.setProjection(proList);

        if (assignA3S == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a3", classA3), Expression.eq("G.s", assignA3S)));
        }
        if (assignA3F == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a3", classA3), Expression.eq("G.f6", assignA3F)));
            logger.info("assigned a3 f");
        }

        if (assignA3FOUTERARM == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a3", classA3),
                    Expression.eq("G.fouterarm", assignA3FOUTERARM)));
        }

        if (assignA3B == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a3", classA3), Expression.eq("G.b", assignA3B)));
            logger.info("assigned a3 b");
        }

        if (assignA3BGAL == 1) {
            disjunction.add(
                    Restrictions.and(Expression.eq("G.a3", classA3), Expression.eq("G.bgal", assignA3BGAL)));
        }

        if (assignA3AGAL == 1) {
            disjunction.add(
                    Restrictions.and(Expression.eq("G.a3", classA3), Expression.eq("G.agal", assignA3AGAL)));
        }
        if (assignA3GALNAC == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a3", classA3),
                    Expression.eq("G.galnac", assignA3GALNAC)));
        }

        if (assignA3POLYLAC == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a3", classA3),
                    Expression.eq("G.polylac", assignA3POLYLAC)));
        }
        if (assignA3HYBRID == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a3", classA3),
                    Expression.eq("G.hybrid", assignA3HYBRID)));
        }
        if (assignA3MANNOSE == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a3", classA3),
                    Expression.eq("G.mannose", assignA3MANNOSE)));
        }
        if (assignA2S == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a2", classA2), Expression.eq("G.s", assignA2S)));
        }
        if (assignA2F == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a2", classA2), Expression.eq("G.f6", assignA2F)));
        }
        if (assignA2FOUTERARM == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a2", classA2),
                    Expression.eq("G.fouterarm", assignA2FOUTERARM)));
        }
        if (assignA2B == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a2", classA2), Expression.eq("G.b", assignA2B)));
        }
        if (assignA2BGAL == 1) {
            disjunction.add(
                    Restrictions.and(Expression.eq("G.a2", classA2), Expression.eq("G.bgal", assignA2BGAL)));
        }
        if (assignA2AGAL == 1) {
            disjunction.add(
                    Restrictions.and(Expression.eq("G.a2", classA2), Expression.eq("G.agal", assignA2AGAL)));
        }
        if (assignA2GALNAC == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a2", classA2),
                    Expression.eq("G.galnac", assignA2GALNAC)));
        }
        if (assignA2POLYLAC == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a2", classA2),
                    Expression.eq("G.polylac", assignA2POLYLAC)));
        }
        if (assignA2HYBRID == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a2", classA2),
                    Expression.eq("G.hybrid", assignA2HYBRID)));
        }
        if (assignA2MANNOSE == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a2", classA2),
                    Expression.eq("G.mannose", assignA2MANNOSE)));
        }

        if (assignA1S == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a1", classA1), Expression.eq("G.s", assignA1S)));
        }
        if (assignA1F == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a1", classA1), Expression.eq("G.f6", assignA1F)));
        }
        if (assignA1FOUTERARM == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a1", classA1),
                    Expression.eq("G.fouterarm", assignA1FOUTERARM)));
        }
        if (assignA1B == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a1", classA1), Expression.eq("G.b", assignA1B)));
        }
        if (assignA1BGAL == 1) {
            disjunction.add(
                    Restrictions.and(Expression.eq("G.a1", classA1), Expression.eq("G.bgal", assignA1BGAL)));
        }
        if (assignA1AGAL == 1) {
            disjunction.add(
                    Restrictions.and(Expression.eq("G.a1", classA1), Expression.eq("G.agal", assignA1AGAL)));
        }
        if (assignA1GALNAC == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a1", classA1),
                    Expression.eq("G.galnac", assignA1GALNAC)));
        }
        if (assignA1POLYLAC == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a1", classA1),
                    Expression.eq("G.polylac", assignA1POLYLAC)));
        }
        if (assignA1HYBRID == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a1", classA1),
                    Expression.eq("G.hybrid", assignA1HYBRID)));
        }
        if (assignA1MANNOSE == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a1", classA1),
                    Expression.eq("G.mannose", assignA1MANNOSE)));
        }
        if (assignA4S == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a4", classA4), Expression.eq("G.s", assignA4S)));
        }
        if (assignA4F == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a4", classA4), Expression.eq("G.f6", assignA4F)));
        }
        if (assignA4FOUTERARM == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a4", classA4),
                    Expression.eq("G.fouterarm", assignA4FOUTERARM)));
        }
        if (assignA4B == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a4", classA4), Expression.eq("G.b", assignA4B)));
        }
        if (assignA4BGAL == 1) {
            disjunction.add(
                    Restrictions.and(Expression.eq("G.a4", classA4), Expression.eq("G.bgal", assignA4BGAL)));
        }
        if (assignA4AGAL == 1) {
            disjunction.add(
                    Restrictions.and(Expression.eq("G.a4", classA4), Expression.eq("G.agal", assignA4AGAL)));
        }
        if (assignA4GALNAC == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a4", classA4),
                    Expression.eq("G.galnac", assignA4GALNAC)));
        }
        if (assignA4POLYLAC == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a4", classA4),
                    Expression.eq("G.polylac", assignA4POLYLAC)));
        }
        if (assignA4HYBRID == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a4", classA4),
                    Expression.eq("G.hybrid", assignA4HYBRID)));
        }
        if (assignA4MANNOSE == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a4", classA4),
                    Expression.eq("G.mannose", assignA4MANNOSE)));
        }

        criteria.add(disjunction);

        List displayCriteria = criteria.list();

        showCriteria = displayCriteria;

        int criteriaSelection = showCriteria.size();
        logger.info("lets lookup at refinement" + criteriaSelection);

        //What if the refinement lists nothing
        if (criteriaSelection <= 0) {
            logger.info("selection criteria generated no results");
            criteriaResults = 0;
            List display = getEntityManager()
                    .getQuery("org.eurocarbdb.dataaccess.hplc.HplcPeaksAnnotated.DIGEST_DISPLAY")
                    .setParameter("parent", profile_id).setParameter("digest", digest_id).list();

            displayDigest = display;
        }

        Iterator iterCrit = showCriteria.iterator();
        while (iterCrit.hasNext()) {
            Object[] tempcrit = (Object[]) iterCrit.next();
            String namecrit = (String) tempcrit[0];

        }

    }

    if (refineAssignment == null && delete_entry > 0) {
        logger.info("record for deleting" + delete_entry);
        HplcPeaksAnnotated deletedRecord = HplcPeaksAnnotated.deleteById(delete_entry);
        List afterDelete = getEntityManager()
                .getQuery("org.eurocarbdb.dataaccess.hplc.HplcPeaksAnnotated.DIGEST_ASSIGN_DISPLAY")
                .setParameter("parent", profile_id).setParameter("digest", refineDigestId).list();
        displayDigest = afterDelete;
    }

    if (refineAssignment == null && delete_entry == 0) {

        File file = new File("/tmp/digest" + profile_id + digest_id + ".txt");
        //Session s = HibernateUtil.getSession();
        //Transaction tx = s.beginTransaction();

        EntityManager em = getEntityManager();
        ArrayList<Double> arrayGu = new ArrayList<Double>();

        FileReader input = new FileReader(file);

        BufferedReader bufRead = new BufferedReader(input);

        String line; // String that holds current file line
        int count = 0; // Line number of count 

        // Read first line
        line = bufRead.readLine();

        while (line != null) {

            String rec = line;
            String[] gu = rec.split("\t");
            double gu_c = Double.parseDouble(gu[1]);
            arrayGu.add(gu_c);
            double area = Double.parseDouble(gu[0]);
            line = bufRead.readLine();

            // for (Double gu_value : arrayGu) {

            // logger.info("print gu value" + gu_c);
            List list = getEntityManager().getQuery("org.eurocarbdb.dataaccess.hplc.Glycan.PRELIM_ASSIGN")
                    .setParameter("gu_value", gu_c).list();

            preliminary = list;
            logger.info("sizeofprel" + preliminary.size());

            Iterator iter = preliminary.iterator();
            while (iter.hasNext()) {

                Glycan temp = (Glycan) iter.next();
                //logger.info("print contents" + temp);
                peaksannotated = new HplcPeaksAnnotated();
                //peaksannotated.setGlycan(temp);
                peaksannotated.setPeakArea(area);
                peaksannotated.setGu(gu_c);
                peaksannotated.setDbGu(temp.getGu());
                peaksannotated.setProfileId(profile_id);
                peaksannotated.setDigestId(digest_id);
                //peaksannotated.setGlycanId(temp.getGlycanId());
                //modification to support relationship change
                peaksannotated.setGlycan(temp);
                peaksannotated.setNameAbbreviation(temp.getName());
                //getEntityManager().store(peaksannotated);
                //peaksannotated.setContributor(Contributor.getCurrentContributor());
                //peaksannotated.setTechnique(Technique.lookupAbbrev("hplc"));
                getEntityManager().store(peaksannotated);
                logger.info("check storage process");
            } //close the iteration over the query result 

        } // end gu value loop

        bufRead.close(); //close the gu file

        Profile p = Profile.lookupById(profile_id);
        logger.info("themagic is" + p);
        DigestProfile dp = new DigestProfile();
        dp.setDigestId(digest_id);
        dp.setSequentialDigest(enzyme);
        dp.setProfile(p);
        getEntityManager().store(dp);

        int idTest = p.getProfileId();
        logger.info("the value of idTest:" + idTest);
        //note: due to use of evidenceId relationships the profileId in DIgestProfile is the evidenceId
        //to get the corresponfing profileId from  Profile use the getProfileId()

        //get the enzymes used
        logger.info("check profile id" + profile_id);
        logger.info("check digest id" + digest_id);

        List enzymelist = getEntityManager()
                .getQuery("org.eurocarbdb.dataaccess.hplc.DigestProfile.GET_ENZYMES") //.setParameter("parent", parent) .list(); // .setParameter("digest_id", digest_id) .list();
                //recurring problem with the use of evidence id
                //if use evidence id instead of profile id for HplcPeaks... will cause core probs
                .setParameter("parent", p).list();
        logger.info("enzymelist" + enzymelist);

        //loop over the enzymes

        preliminaryenz = enzymelist;
        logger.info("size report" + preliminaryenz.size());

        //delete records which have a digest product for that given enzyme

        for (Object enzymeused : enzymelist) {
            logger.info("loopstufftoheckenz" + enzymeused);
            List annolist = getEntityManager()
                    .getQuery("org.eurocarbdb.dataaccess.hplc.HplcPeaksAnnotated.ATTEMPT")
                    .setParameter("parent", profile_id).setParameter("digest", digest_id)
                    .setParameter("enzymeused", enzymeused).list();

            logger.info("what now");

            Iterator iteraa = annolist.iterator();
            while (iteraa.hasNext()) {
                HplcPeaksAnnotated tempanno = (HplcPeaksAnnotated) iteraa.next();
                logger.info("whatshouldberemoved" + tempanno);
                //tx.begin();
                //s.delete( tempanno );
                Eurocarb.getEntityManager().remove(tempanno);
                //tx.commit();
            }

        }

        //preview the results
        List display = getEntityManager()
                .getQuery("org.eurocarbdb.dataaccess.hplc.HplcPeaksAnnotated.DIGEST_DISPLAY")
                .setParameter("parent", profile_id).setParameter("digest", digest_id).list();

        displayDigest = display;
        logger.info(displayDigest.size());

        digest_id++;

    }
    return SUCCESS;
}

From source file:org.eurocarbdb.action.hplc.preAssign.java

License:Open Source License

public String execute() throws Exception {

    logger.info("before zeros" + classA3);

    if (classA1 == 0) {
        classA1 = replaceSearch;/*w ww . j  a  v a2 s. c o  m*/
    }

    if (classA2 == 0) {
        classA2 = replaceSearch;
    }

    if (classA3 == 0) {
        classA3 = replaceSearch;
    }

    if (classA4 == 0) {
        classA4 = replaceSearch;
    }

    logger.info("some zeros" + classA1 + classA2 + classA3 + classA4);

    if (refineAssignment != null) {
        logger.info("user whats a refinement displayed");
        logger.info("was a2f assigned = " + assignA2F + "ws a2 class done" + classA2 + "just to insure"
                + assignA4F);
        String queryRefine = A2S + A2F + A2B + A2BGAL + A2AGAL + A2GALNAC + A2POLYLAC + A2FOUTERARM + A2HYBRID
                + A2MANNOSE + A1B + A1BGAL + A1AGAL + A1GALNAC + A1POLYLAC + A1FOUTERARM + A1HYBRID + A1MANNOSE
                + A1S + A1F + A3S + A3F + A3B + A3BGAL + A3AGAL + A3GALNAC + A3POLYLAC + A3FOUTERARM + A3HYBRID
                + A3MANNOSE + A4S + A4F + A4B + A4BGAL + A4AGAL + A4GALNAC + A4POLYLAC + A4FOUTERARM + A4HYBRID
                + A4MANNOSE;

        String queryReplace = queryRefine.replaceAll("null", "");
        String queryAnd = queryReplace.replaceAll("\\)\\(", ") OR (");
        logger.info("query string again:" + queryAnd);
        int len = queryAnd.length();

        //String queryRefineComplete = "SELECT HP.glycan, HP.peakArea, HP.gu, HP.dbGu, HP.nameAbbreviation, (select g.ogbitranslation from Glycan g where g.glycanId = HP.glycan) as ogbitranslation from HplcPeaksAnnotated HP where HP.profileId = " + profile_id + " and HP.digestId = 0 and HP.glycan IN (SELECT G.glycanId from Glycan G WHERE " + queryAnd + " and G.glycanId = HP.glycan) ORDER BY HP.gu";

        String queryRefineComplete = "from HplcPeaksAnnotated HP join HP.glycan G where HP.profileId = 46 and "
                + queryAnd + " order by HP.gu";

        logger.info("check new query" + queryRefineComplete);

        SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
        Session session = sessionFactory.openSession();

        Query query = session.createQuery(queryRefineComplete);

        List<HplcPeaksAnnotated> display = query.list();
        //display = query.list();
        //prelimarytwo = display;

        int tempint = 1140;
        int tempprofile = 48;
        short tempintr = 1;

        /*Disjunction disc = Expression.disjunction();    */
        /*List displaytest = session.createCriteria(HplcPeaksAnnotated.class)
                
                   .createAlias("glycan", "G")
                   .add( Expression.eq("profileId", tempprofile))
                   .add(Restrictions.and(
        Expression.eq("G.a3", classA3),
         Expression.eq("G.s", assignA3S)
        ))
                .add(Restrictions.and(
         Expression.eq("G.a3", classA3),
         Expression.eq("G.f6", assignA3F)
         ))//.add ( Expression.eq("G.glycanId", tempint))
                           
        .add(Expression.or(
        Expression.eq("G.a1", classA1),
         Expression.eq("G.s", assignA1S)
        ))
        .add(Expression.or(
         Expression.eq("G.a2", classA2),
         Expression.eq("G.s", assignA2S)
         ))
                
        .add(Expression.or(
        Expression.and(
         Expression.eq("G.a3", classA3),
         Expression.eq("G.s", assignA3S)
         )
        .add(Expression.and(
         Expression.eq("G.a3", classA3),
         Expression.eq("G.f6", assignA3F)
         ))
        ))
        .add(Expression.or(
         Expression.eq("G.a4", classA4),
         Expression.eq("G.s", assignA4S)
         ))
        //.AddOrder( Order.Asc("gu") )
            //       .list();
        */

        logger.info("variables check" + classA3 + "core f" + assignA3F + "s" + assignA3S);

        Criteria criteria = session.createCriteria(HplcPeaksAnnotated.class);
        Disjunction disjunction = Restrictions.disjunction();
        ProjectionList proList = Projections.projectionList();
        criteria.add(Expression.eq("profileId", profile_id));
        criteria.createAlias("glycan", "G");
        proList.add(Projections.property("nameAbbreviation"));
        proList.add(Projections.property("gu"));
        proList.add(Projections.property("dbGu"));
        proList.add(Projections.property("peakArea"));
        proList.add(Projections.property("G.ogbitranslation"));
        proList.add(Projections.property("hplcPeaksAnnotatedId"));

        criteria.setProjection(proList);

        if (assignA3S == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a3", classA3), Expression.eq("G.s", assignA3S)));
        }
        if (assignA3F == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a3", classA3), Expression.eq("G.f6", assignA3F)));
            logger.info("assigned a3 f");
        }

        if (assignA3FOUTERARM == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a3", classA3),
                    Expression.eq("G.fouterarm", assignA3FOUTERARM)));
        }

        if (assignA3B == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a3", classA3), Expression.eq("G.b", assignA3B)));
            logger.info("assigned a3 b");
        }

        if (assignA3BGAL == 1) {
            disjunction.add(
                    Restrictions.and(Expression.eq("G.a3", classA3), Expression.eq("G.bgal", assignA3BGAL)));
        }

        if (assignA3AGAL == 1) {
            disjunction.add(
                    Restrictions.and(Expression.eq("G.a3", classA3), Expression.eq("G.agal", assignA3AGAL)));
        }
        if (assignA3GALNAC == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a3", classA3),
                    Expression.eq("G.galnac", assignA3GALNAC)));
        }

        if (assignA3POLYLAC == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a3", classA3),
                    Expression.eq("G.polylac", assignA3POLYLAC)));
        }
        if (assignA3HYBRID == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a3", classA3),
                    Expression.eq("G.hybrid", assignA3HYBRID)));
        }
        if (assignA3MANNOSE == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a3", classA3),
                    Expression.eq("G.mannose", assignA3MANNOSE)));
        }
        if (assignA2S == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a2", classA2), Expression.eq("G.s", assignA2S)));
        }
        if (assignA2F == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a2", classA2), Expression.eq("G.f6", assignA2F)));
        }
        if (assignA2FOUTERARM == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a2", classA2),
                    Expression.eq("G.fouterarm", assignA2FOUTERARM)));
        }
        if (assignA2B == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a2", classA2), Expression.eq("G.b", assignA2B)));
        }
        if (assignA2BGAL == 1) {
            disjunction.add(
                    Restrictions.and(Expression.eq("G.a2", classA2), Expression.eq("G.bgal", assignA2BGAL)));
        }
        if (assignA2AGAL == 1) {
            disjunction.add(
                    Restrictions.and(Expression.eq("G.a2", classA2), Expression.eq("G.agal", assignA2AGAL)));
        }
        if (assignA2GALNAC == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a2", classA2),
                    Expression.eq("G.galnac", assignA2GALNAC)));
        }
        if (assignA2POLYLAC == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a2", classA2),
                    Expression.eq("G.polylac", assignA2POLYLAC)));
        }
        if (assignA2HYBRID == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a2", classA2),
                    Expression.eq("G.hybrid", assignA2HYBRID)));
        }
        if (assignA2MANNOSE == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a2", classA2),
                    Expression.eq("G.mannose", assignA2MANNOSE)));
        }

        if (assignA1S == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a1", classA1), Expression.eq("G.s", assignA1S)));
        }
        if (assignA1F == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a1", classA1), Expression.eq("G.f6", assignA1F)));
        }
        if (assignA1FOUTERARM == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a1", classA1),
                    Expression.eq("G.fouterarm", assignA1FOUTERARM)));
        }
        if (assignA1B == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a1", classA1), Expression.eq("G.b", assignA1B)));
        }
        if (assignA1BGAL == 1) {
            disjunction.add(
                    Restrictions.and(Expression.eq("G.a1", classA1), Expression.eq("G.bgal", assignA1BGAL)));
        }
        if (assignA1AGAL == 1) {
            disjunction.add(
                    Restrictions.and(Expression.eq("G.a1", classA1), Expression.eq("G.agal", assignA1AGAL)));
        }
        if (assignA1GALNAC == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a1", classA1),
                    Expression.eq("G.galnac", assignA1GALNAC)));
        }
        if (assignA1POLYLAC == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a1", classA1),
                    Expression.eq("G.polylac", assignA1POLYLAC)));
        }
        if (assignA1HYBRID == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a1", classA1),
                    Expression.eq("G.hybrid", assignA1HYBRID)));
        }
        if (assignA1MANNOSE == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a1", classA1),
                    Expression.eq("G.mannose", assignA1MANNOSE)));
        }
        if (assignA4S == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a4", classA4), Expression.eq("G.s", assignA4S)));
        }
        if (assignA4F == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a4", classA4), Expression.eq("G.f6", assignA4F)));
        }
        if (assignA4FOUTERARM == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a4", classA4),
                    Expression.eq("G.fouterarm", assignA4FOUTERARM)));
        }
        if (assignA4B == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a4", classA4), Expression.eq("G.b", assignA4B)));
        }
        if (assignA4BGAL == 1) {
            disjunction.add(
                    Restrictions.and(Expression.eq("G.a4", classA4), Expression.eq("G.bgal", assignA4BGAL)));
        }
        if (assignA4AGAL == 1) {
            disjunction.add(
                    Restrictions.and(Expression.eq("G.a4", classA4), Expression.eq("G.agal", assignA4AGAL)));
        }
        if (assignA4GALNAC == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a4", classA4),
                    Expression.eq("G.galnac", assignA4GALNAC)));
        }
        if (assignA4POLYLAC == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a4", classA4),
                    Expression.eq("G.polylac", assignA4POLYLAC)));
        }
        if (assignA4HYBRID == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a4", classA4),
                    Expression.eq("G.hybrid", assignA4HYBRID)));
        }
        if (assignA4MANNOSE == 1) {
            disjunction.add(Restrictions.and(Expression.eq("G.a4", classA4),
                    Expression.eq("G.mannose", assignA4MANNOSE)));
        }
        criteria.add(disjunction);

        List displayCriteria = criteria.list();

        showCriteria = displayCriteria;

        int criteriaSelection = showCriteria.size();
        logger.info("lets lookup at refinement" + criteriaSelection);

        //What if the refinement lists nothing
        if (criteriaSelection <= 0) {
            logger.info("selection criteria generated no results");
            display = getEntityManager()
                    .getQuery("org.eurocarbdb.dataaccess.hplc.HplcPeaksAnnotated.PRE_ASSIGN_DISPLAY")
                    .setParameter("parent", profile_id).list();
            prelimarytwo = display;
        }

        Iterator iterCrit = showCriteria.iterator();
        while (iterCrit.hasNext()) {
            Object[] tempcrit = (Object[]) iterCrit.next();
            String namecrit = (String) tempcrit[0];
            logger.info("here" + namecrit);
        }

    }

    //test deleting records

    if (refineAssignment == null && delete_entry > 0) {
        logger.info("record for deleting" + delete_entry);
        HplcPeaksAnnotated deletedRecord = HplcPeaksAnnotated.deleteById(delete_entry);
        List afterDelete = getEntityManager()
                .getQuery("org.eurocarbdb.dataaccess.hplc.HplcPeaksAnnotated.PRE_ASSIGN_DISPLAY")
                .setParameter("parent", profile_id).list();
        prelimarytwo = afterDelete;
    }

    if (refineAssignment == null && delete_entry == 0) {
        logger.info("i shouldnt be seeing this message");
        File file = new File("/tmp/undigested" + profile_id + ".txt");
        EntityManager em = getEntityManager();
        ArrayList<Double> arrayGu = new ArrayList<Double>();

        FileReader input = new FileReader(file);

        BufferedReader bufRead = new BufferedReader(input);

        String line; // String that holds current file line
        int count = 0; // Line number of count 

        // Read first line
        line = bufRead.readLine();

        while (line != null) {

            String rec = line;
            String[] gu = rec.split("\t");
            double gu_c = Double.parseDouble(gu[1]);
            double area = Double.parseDouble(gu[0]);
            arrayGu.add(gu_c);
            line = bufRead.readLine();
            // }

            // for (Double gu_value : arrayGu) {
            //       logger.info("the value is" + gu_value);
            List list = getEntityManager().getQuery("org.eurocarbdb.dataaccess.hplc.Glycan.PRELIM_ASSIGN")
                    .setParameter("gu_value", gu_c).list();
            preliminary = list;
            //  logger.info("gu value print" + gu_value);
            logger.info(preliminary.size());

            Iterator iter = preliminary.iterator();
            while (iter.hasNext()) {
                Glycan temp = (Glycan) iter.next();
                peaksannotated = new HplcPeaksAnnotated();
                //peaksannotated.setGlycan(temp);
                // peaksannotated.setGu(gu_value);
                peaksannotated.setPeakArea(area);
                peaksannotated.setGu(gu_c);
                peaksannotated.setDbGu(temp.getGu());
                peaksannotated.setProfileId(profile_id);
                peaksannotated.setGlycan(temp);
                peaksannotated.setNameAbbreviation(temp.getName());
                peaksannotated.setDigestId(digest_id);
                //peaksannotated.setContributor(Contributor.getCurrentContributor());
                //peaksannotated.setTechnique(Technique.lookupAbbrev("hplc"));
                getEntityManager().store(peaksannotated);
            }

        }

        bufRead.close();

        /* test
        ArrayList <Double> test = new ArrayList();
        test.addAll(arrayGu);
        for (Double testing : test) {}
        */

        //need to do a query to grap inserted data above for displaying to user
        //logger.info("check the profile id number here:" + profile_id);

        display = getEntityManager()
                .getQuery("org.eurocarbdb.dataaccess.hplc.HplcPeaksAnnotated.PRE_ASSIGN_DISPLAY")
                .setParameter("parent", profile_id).list();

        prelimarytwo = display;
        logger.info(prelimarytwo.size());

    }
    return SUCCESS;

}

From source file:org.eurocarbdb.action.hplc.showGlycobaseRefine.java

License:Open Source License

public String execute() throws Exception {

    if (classA1 == 0) {
        classA1 = replaceSearch;/*from  www  .  java2s .com*/
    }

    if (classA2 == 0) {
        classA2 = replaceSearch;
    }

    if (classA3 == 0) {
        classA3 = replaceSearch;
    }

    if (classA4 == 0) {
        classA4 = replaceSearch;
    }

    EntityManager em = getEntityManager();
    HibernateEntityManager hem = (HibernateEntityManager) getEntityManager();
    Session session = hem.getHibernateSession();

    Criteria criteria = session.createCriteria(Glycan.class);
    Disjunction disjunction = Restrictions.disjunction();
    ProjectionList proList = Projections.projectionList();
    proList.add(Projections.property("name"));
    proList.add(Projections.property("ogbitranslation"));
    proList.add(Projections.property("gu"));
    proList.add(Projections.property("glycanId"));

    criteria.setProjection(proList);
    criteria.addOrder(Order.asc("gu"));

    if (assignA3S == 1) {
        disjunction.add(Restrictions.and(Expression.eq("a3", classA3), Expression.eq("s", assignA3S)));
    }
    if (assignA3F == 1) {
        disjunction.add(Restrictions.and(Expression.eq("a3", classA3), Expression.eq("f6", assignA3F)));

    }

    if (assignA3FOUTERARM == 1) {
        disjunction.add(
                Restrictions.and(Expression.eq("a3", classA3), Expression.eq("fouterarm", assignA3FOUTERARM)));
    }

    if (assignA3B == 1) {
        disjunction.add(Restrictions.and(Expression.eq("a3", classA3), Expression.eq("b", assignA3B)));

    }

    if (assignA3BGAL == 1) {
        disjunction.add(Restrictions.and(Expression.eq("a3", classA3), Expression.eq("bgal", assignA3BGAL)));
    }

    if (assignA3AGAL == 1) {
        disjunction.add(Restrictions.and(Expression.eq("a3", classA3), Expression.eq("agal", assignA3AGAL)));
    }
    if (assignA3GALNAC == 1) {
        disjunction
                .add(Restrictions.and(Expression.eq("a3", classA3), Expression.eq("galnac", assignA3GALNAC)));
    }

    if (assignA3POLYLAC == 1) {
        disjunction
                .add(Restrictions.and(Expression.eq("a3", classA3), Expression.eq("polylac", assignA3POLYLAC)));
    }
    if (assignA3HYBRID == 1) {
        disjunction
                .add(Restrictions.and(Expression.eq("a3", classA3), Expression.eq("hybrid", assignA3HYBRID)));
    }
    if (assignA3MANNOSE == 1) {
        disjunction
                .add(Restrictions.and(Expression.eq("a3", classA3), Expression.eq("mannose", assignA3MANNOSE)));
    }
    if (assignA2S == 1) {
        disjunction.add(Restrictions.and(Expression.eq("a2", classA2), Expression.eq("s", assignA2S)));
    }
    if (assignA2F == 1) {
        disjunction.add(Restrictions.and(Expression.eq("a2", classA2), Expression.eq("f6", assignA2F)));
    }
    if (assignA2FOUTERARM == 1) {
        disjunction.add(
                Restrictions.and(Expression.eq("a2", classA2), Expression.eq("fouterarm", assignA2FOUTERARM)));
    }
    if (assignA2B == 1) {
        disjunction.add(Restrictions.and(Expression.eq("a2", classA2), Expression.eq("b", assignA2B)));
    }
    if (assignA2BGAL == 1) {
        disjunction.add(Restrictions.and(Expression.eq("a2", classA2), Expression.eq("bgal", assignA2BGAL)));
    }
    if (assignA2AGAL == 1) {
        disjunction.add(Restrictions.and(Expression.eq("a2", classA2), Expression.eq("agal", assignA2AGAL)));
    }
    if (assignA2GALNAC == 1) {
        disjunction
                .add(Restrictions.and(Expression.eq("a2", classA2), Expression.eq("galnac", assignA2GALNAC)));
    }
    if (assignA2POLYLAC == 1) {
        disjunction
                .add(Restrictions.and(Expression.eq("a2", classA2), Expression.eq("polylac", assignA2POLYLAC)));
    }
    if (assignA2HYBRID == 1) {
        disjunction
                .add(Restrictions.and(Expression.eq("a2", classA2), Expression.eq("hybrid", assignA2HYBRID)));
    }
    if (assignA2MANNOSE == 1) {
        disjunction
                .add(Restrictions.and(Expression.eq("a2", classA2), Expression.eq("mannose", assignA2MANNOSE)));
    }

    if (assignA1S == 1) {
        disjunction.add(Restrictions.and(Expression.eq("a1", classA1), Expression.eq("s", assignA1S)));
    }
    if (assignA1F == 1) {
        disjunction.add(Restrictions.and(Expression.eq("a1", classA1), Expression.eq("f6", assignA1F)));
    }
    if (assignA1FOUTERARM == 1) {
        disjunction.add(
                Restrictions.and(Expression.eq("a1", classA1), Expression.eq("fouterarm", assignA1FOUTERARM)));
    }
    if (assignA1B == 1) {
        disjunction.add(Restrictions.and(Expression.eq("a1", classA1), Expression.eq("b", assignA1B)));
    }
    if (assignA1BGAL == 1) {
        disjunction.add(Restrictions.and(Expression.eq("a1", classA1), Expression.eq("bgal", assignA1BGAL)));
    }
    if (assignA1AGAL == 1) {
        disjunction.add(Restrictions.and(Expression.eq("a1", classA1), Expression.eq("agal", assignA1AGAL)));
    }
    if (assignA1GALNAC == 1) {
        disjunction
                .add(Restrictions.and(Expression.eq("a1", classA1), Expression.eq("galnac", assignA1GALNAC)));
    }
    if (assignA1POLYLAC == 1) {
        disjunction
                .add(Restrictions.and(Expression.eq("a1", classA1), Expression.eq("polylac", assignA1POLYLAC)));
    }
    if (assignA1HYBRID == 1) {
        disjunction
                .add(Restrictions.and(Expression.eq("a1", classA1), Expression.eq("hybrid", assignA1HYBRID)));
    }
    if (assignA1MANNOSE == 1) {
        disjunction
                .add(Restrictions.and(Expression.eq("a1", classA1), Expression.eq("mannose", assignA1MANNOSE)));
    }
    if (assignA4S == 1) {
        disjunction.add(Restrictions.and(Expression.eq("a4", classA4), Expression.eq("s", assignA4S)));
    }
    if (assignA4F == 1) {
        disjunction.add(Restrictions.and(Expression.eq("a4", classA4), Expression.eq("f6", assignA4F)));
    }
    if (assignA4FOUTERARM == 1) {
        disjunction.add(
                Restrictions.and(Expression.eq("a4", classA4), Expression.eq("fouterarm", assignA4FOUTERARM)));
    }
    if (assignA4B == 1) {
        disjunction.add(Restrictions.and(Expression.eq("a4", classA4), Expression.eq("b", assignA4B)));
    }
    if (assignA4BGAL == 1) {
        disjunction.add(Restrictions.and(Expression.eq("a4", classA4), Expression.eq("bgal", assignA4BGAL)));
    }
    if (assignA4AGAL == 1) {
        disjunction.add(Restrictions.and(Expression.eq("a4", classA4), Expression.eq("agal", assignA4AGAL)));
    }
    if (assignA4GALNAC == 1) {
        disjunction
                .add(Restrictions.and(Expression.eq("a4", classA4), Expression.eq("galnac", assignA4GALNAC)));
    }
    if (assignA4POLYLAC == 1) {
        disjunction
                .add(Restrictions.and(Expression.eq("a4", classA4), Expression.eq("polylac", assignA4POLYLAC)));
    }
    if (assignA4HYBRID == 1) {
        disjunction
                .add(Restrictions.and(Expression.eq("a4", classA4), Expression.eq("hybrid", assignA4HYBRID)));
    }
    if (assignA4MANNOSE == 1) {
        disjunction
                .add(Restrictions.and(Expression.eq("a4", classA4), Expression.eq("mannose", assignA4MANNOSE)));
    }

    if (serum == 1 && IgG == 1) {
        disjunction.add(Restrictions.and(Expression.eq("serum", serum), Expression.eq("normalIgG", IgG)));
    }

    if (serum == 1 && IgG == 0) {
        criteria.add(Expression.eq("serum", serum));
    }

    if (serum == 0 && IgG == 1) {
        criteria.add(Expression.eq("normalIgg", IgG));
    }

    criteria.add(disjunction);

    List displayCriteria = criteria.list();

    int listSize = displayCriteria.size();

    if (listSize > 0) {
        setAllResults(displayCriteria);

        return SUCCESS;
    } else {
        return ERROR;
    }

}

From source file:org.fireflow.engine.persistence.hibernate.PersistenceServiceHibernateImpl.java

License:Open Source License

public Integer getAliveTokenCountForNode(final String processInstanceId, final String nodeId) {
    Integer result = (Integer) this.getHibernateTemplate().execute(new HibernateCallback() {

        public Object doInHibernate(Session arg0) throws HibernateException, SQLException {

            Criteria criteria = arg0.createCriteria(Token.class);

            criteria.add(Expression.eq("processInstanceId", processInstanceId));

            criteria.add(Expression.eq("nodeId", nodeId));

            criteria.add(Expression.eq("alive", java.lang.Boolean.TRUE));

            ProjectionList prolist = Projections.projectionList();
            prolist.add(Projections.rowCount());
            criteria.setProjection(prolist);

            return criteria.uniqueResult();
        }// w ww.  jav a  2 s  . c  o m
    });
    return result;
}