Java 类org.hibernate.criterion.Property 实例源码

项目:SandBoxNGSB    文件:QuoteDAOImpl.java   
@Override
public QuotePE getLast(String sigle) {
    Session session = getSession();

    DetachedCriteria  maxDate = DetachedCriteria.forClass(QuotePE.class);
    maxDate.add(Restrictions.eq("symbol", sigle));
    maxDate.setProjection(Projections.max("creationDateTime"));

    Criteria criteria = session.createCriteria(QuotePE.class);
    criteria.add(Restrictions.eq("symbol", sigle));
    criteria.add(Property.forName("creationDateTime").eq(maxDate));

    QuotePE pe = (QuotePE) criteria.uniqueResult();
    session.close();

    return pe;
}
项目:bdf2    文件:MessageTemplateServiceImpl.java   
public void loadMessageTemplates(Page<MessageTemplate> page,Criteria criteria,String type){
    IUser user=ContextHolder.getLoginUser();
    if(user==null){
        throw new RuntimeException("Please login first!");
    }
    String companyId=user.getCompanyId();
    if(StringUtils.isNotEmpty(getFixedCompanyId())){
        companyId=getFixedCompanyId();
    }
    DetachedCriteria dc=this.buildDetachedCriteria(criteria, MessageTemplate.class);
    if(StringUtils.isNotEmpty(type)){
        dc.add(Property.forName("type").eq(type));
    }
    Property p=Property.forName("companyId");
    dc.add(p.eq(companyId));
    this.pagingQuery(page, dc);
}
项目:cacheonix-core    文件:ComponentTest.java   
public void afterConfigurationBuilt(Mappings mappings, Dialect dialect) {
    super.afterConfigurationBuilt( mappings, dialect );
    // Oracle and Postgres do not have year() functions, so we need to
    // redefine the 'User.person.yob' formula
    //
    // consider temporary until we add the capability to define
    // mapping foprmulas which can use dialect-registered functions...
    PersistentClass user = mappings.getClass( User.class.getName() );
    org.hibernate.mapping.Property personProperty = user.getProperty( "person" );
    Component component = ( Component ) personProperty.getValue();
    Formula f = ( Formula ) component.getProperty( "yob" ).getValue().getColumnIterator().next();

    SQLFunction yearFunction = ( SQLFunction ) dialect.getFunctions().get( "year" );
    if ( yearFunction == null ) {
        // the dialect not know to support a year() function, so rely on the
        // ANSI SQL extract function
        f.setFormula( "extract( year from dob )");
    }
    else {
        List args = new ArrayList();
        args.add( "dob" );
        f.setFormula( yearFunction.render( args, null ) );
    }
}
项目:cacheonix-core    文件:ComponentTest.java   
public void testComponentFormulaQuery() {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    s.createQuery("from User u where u.person.yob = 1999").list();
    s.createCriteria(User.class)
        .add( Property.forName("person.yob").between( new Integer(1999), new Integer(2002) ) )
        .list();
    if ( getDialect().supportsRowValueConstructorSyntax() ) {
        s.createQuery("from User u where u.person = ('gavin', :dob, 'Peachtree Rd', 'Karbarook Ave', 1974, 'Peachtree Rd')")
            .setDate("dob", new Date("March 25, 1974")).list();
        s.createQuery("from User where person = ('gavin', :dob, 'Peachtree Rd', 'Karbarook Ave', 1974, 'Peachtree Rd')")
            .setDate("dob", new Date("March 25, 1974")).list();
    }
    t.commit();
    s.close();
}
项目:eMonocot    文件:ResourceDaoImpl.java   
@Override
public List<Resource> listResourcesToHarvest(Integer limit, DateTime now, String fetch) {
    Criteria criteria = getSession().createCriteria(type);
    criteria.add(Restrictions.isNotNull("resourceType"));
    criteria.add(Restrictions.in("status", Arrays.asList(new BatchStatus[] {BatchStatus.COMPLETED, BatchStatus.FAILED,BatchStatus.ABANDONED, BatchStatus.STOPPED})));
    criteria.add(Restrictions.eq("scheduled", Boolean.TRUE));
    criteria.add(Restrictions.disjunction().add(Restrictions.lt("nextAvailableDate", now)).add(Restrictions.isNull("nextAvailableDate")));

    if (limit != null) {
        criteria.setMaxResults(limit);
    }
    enableProfilePreQuery(criteria, fetch);
    criteria.addOrder( Property.forName("nextAvailableDate").asc() );
    List<Resource> result = (List<Resource>) criteria.list();
    for(Resource t : result) {
        enableProfilePostQuery(t, fetch);
    }
    return result;
}
项目:powop    文件:ResourceDaoImpl.java   
@Override
public List<Resource> listResourcesToHarvest(Integer limit, DateTime now, String fetch) {
    Criteria criteria = getSession().createCriteria(type);
    criteria.add(Restrictions.isNotNull("resourceType"));
    criteria.add(Restrictions.in("status", Arrays.asList(new BatchStatus[] {BatchStatus.COMPLETED, BatchStatus.FAILED,BatchStatus.ABANDONED, BatchStatus.STOPPED})));
    criteria.add(Restrictions.eq("scheduled", Boolean.TRUE));
    criteria.add(Restrictions.disjunction().add(Restrictions.lt("nextAvailableDate", now)).add(Restrictions.isNull("nextAvailableDate")));

    if (limit != null) {
        criteria.setMaxResults(limit);
    }
    enableProfilePreQuery(criteria, fetch);
    criteria.addOrder( Property.forName("nextAvailableDate").asc() );
    List<Resource> result = (List<Resource>) criteria.list();
    for(Resource t : result) {
        enableProfilePostQuery(t, fetch);
    }
    return result;
}
项目:onecmdb    文件:QueryHandler.java   
private DetachedCriteria getAttributeOrderCriteria(String template, DetachedCriteria ciCrit, DetachedCriteria ci2Crit,
        OrderInfo info) {

    if (info.getAttrType().equals("complex")) {
        return(getComplexAttributeOrderCriteria2(template, ciCrit, ci2Crit, info));
    }

    DetachedCriteria crit = DetachedCriteria.forClass(BasicAttribute.class);
    DetachedCriteria ciIdProjection = ciCrit.setProjection(Projections.property("longId"));
    crit.add(Property.forName("ownerId").in(ciIdProjection));
    crit.add(Expression.eq("alias", info.getAttrAlias()));
    if (info.isDescenden()) {
        crit.addOrder(Order.desc(info.getAttrType()));
    } else {
        crit.addOrder(Order.asc(info.getAttrType()));
    }
    return(crit);
}
项目:onecmdb    文件:QueryHandler.java   
private DetachedCriteria getComplexAttributeOrderCriteria(String template, DetachedCriteria ciCrit,
        OrderInfo info) {
    DetachedCriteria crit = DetachedCriteria.forClass(BasicAttribute.class);
    DetachedCriteria ciIdProjection = ciCrit.setProjection(Projections.property("longId"));
    crit.add(Property.forName("ownerId").in(ciIdProjection));
    crit.add(Expression.eq("alias", info.getAttrAlias()));
    //crit.add(Expression.isNotEmpty("valueAsLong"));

    ICi ci = this.msvc.findCi(new Path(template));
    IAttribute attr = ci.getAttributeDefinitionWithAlias(info.getAttrAlias());
    IType type = attr.getValueType();
    String targetTemplate = type.getAlias();

    DetachedCriteria refCrit = DetachedCriteria.forClass(ConfigurationItem.class);
    refCrit.add(Property.forName("longId").in(crit.setProjection(Projections.property("valueAsLong"))));

    DetachedCriteria refCiCrit = DetachedCriteria.forClass(ConfigurationItem.class);
    refCiCrit.add(Property.forName("longId").in(refCrit.setProjection(Projections.property("targetId"))));

    return(getDisplayNameOrder(targetTemplate, refCiCrit, info));
}
项目:onecmdb    文件:QueryHandler.java   
private DetachedCriteria getBackComplexAttributeOrder(List<Long> attrOwnerId, DetachedCriteria ci2Crit,
        OrderInfo info) {

    DetachedCriteria targetCrit = DetachedCriteria.forClass(ConfigurationItem.class);
    targetCrit.add(Property.forName("longId").in(attrOwnerId));

    DetachedCriteria refCrit = DetachedCriteria.forClass(ConfigurationItem.class);
    refCrit.add(Property.forName("targetId").in(targetCrit.setProjection(Projections.property("longId")))); 


    DetachedCriteria attrCrit = DetachedCriteria.forClass(BasicAttribute.class);
    attrCrit.add(Property.forName("valueAsLong").in(refCrit.setProjection(Projections.property("longId"))));
    attrCrit.add(Property.forName("ownerId").in(ci2Crit.setProjection(Projections.property("longId"))));
    attrCrit.add(Expression.eq("alias", info.getAttrAlias()));

    attrCrit.addOrder(Order.desc("longId"));
    return(attrCrit);
}
项目:onecmdb    文件:RelationExpression.java   
@Override
public DetachedCriteria getCriteria() {
    DetachedCriteria crit = getObjectCriteria(); //DetachedCriteria.forClass(ConfigurationItem.class);

    if (getTargetIds() != null) {
        crit.add(Property.forName(getRelationTargetProperty()).in(targetIds));
    } else {
        DetachedCriteria targetCrit = target.setProjection(Projections.property(getTargetProjection()));
        crit.add(Property.forName(getRelationTargetProperty()).in(targetCrit));
    }

    if (getSourceIds() != null) {
        crit.add(Property.forName(getRelationSourceProperty()).in(sourceIds));
    } else {
        DetachedCriteria sourceCrit = source.setProjection(Projections.property(getSourceProjection()));
        crit.add(Property.forName(getRelationSourceProperty()).in(sourceCrit));
    }
    return(crit);
}
项目:onecmdb    文件:ConstrainGroupExpression.java   
@Override
public DetachedCriteria getCriteria() {
    DetachedCriteria crit = getParent().getCriteria();
    Junction junction = null;
    if (disjunction) {
        junction = Restrictions.disjunction();
    } else {
        junction = Restrictions.conjunction();
    }
    for (Iterator iter = attributeExpressions.iterator(); iter.hasNext();) {
        AttributeExpression aExpr = (AttributeExpression) iter.next();
        DetachedCriteria attrCriteria = aExpr.getCriteria();
        junction.add(Property.forName("longId").in(attrCriteria.setProjection(Projections.property("ownerId"))));
    }
    crit.add(junction);

    return(crit);
}
项目:onecmdb    文件:SourceTemplateRelationExpression.java   
@Override
protected DetachedCriteria getCriteria() {
    // Select Target/Source attribute id.
    DetachedCriteria attrTarget = DetachedCriteria.forClass(BasicAttribute.class);
    attrTarget.add(Expression.eq("valueAsLong", targetId));
    attrTarget.add(Expression.eq("alias", "target"));
    DetachedCriteria relOwnerCrit = attrTarget.setProjection(Projections.property("ownerId"));

    DetachedCriteria relCi = DetachedCriteria.forClass(ConfigurationItem.class);
    relCi.add(Property.forName("longId").in(relOwnerCrit));
    relCi.add(Expression.eq("derivedFromId", referenceTemplateId));

    DetachedCriteria targetOwnerCrit = relCi.setProjection(Projections.property("longId"));

    DetachedCriteria attrSource = DetachedCriteria.forClass(BasicAttribute.class);
    attrSource.add(Expression.eq("alias", "source"));
    attrSource.add(Property.forName("ownerId").in(targetOwnerCrit));

    DetachedCriteria sourceIdCrit = attrSource.setProjection(Projections.property("valueAsLong"));

    DetachedCriteria sourceCi = DetachedCriteria.forClass(ConfigurationItem.class);
    sourceCi.add(Property.forName("longId").in(sourceIdCrit));

    return(sourceCi);
}
项目:cmdit    文件:LogDAO.java   
private Criteria prepareCriteria(String user, String act, Date fechaIni, Date fechaFin){
    Criteria criteria = this.getCurrentSession().createCriteria(Log.class);

    if(fechaIni != null)
        criteria.add(Property.forName("stamp").ge(fechaIni));

    if(fechaFin != null)
        criteria.add(Property.forName("stamp").le(fechaFin));

    if(user != null && !user.isEmpty())
        criteria
            .createCriteria("user")
            .add(Property.forName("pid").eq(user));

    if(act != null && !act.isEmpty())
        criteria.add(Property.forName("action").eq(act));

    return criteria;
}
项目:OneCMDBwithMaven    文件:QueryHandler.java   
private DetachedCriteria getAttributeOrderCriteria(String template, DetachedCriteria ciCrit, DetachedCriteria ci2Crit,
        OrderInfo info) {

    if (info.getAttrType().equals("complex")) {
        return(getComplexAttributeOrderCriteria2(template, ciCrit, ci2Crit, info));
    }

    DetachedCriteria crit = DetachedCriteria.forClass(BasicAttribute.class);
    DetachedCriteria ciIdProjection = ciCrit.setProjection(Projections.property("longId"));
    crit.add(Property.forName("ownerId").in(ciIdProjection));
    crit.add(Expression.eq("alias", info.getAttrAlias()));
    if (info.isDescenden()) {
        crit.addOrder(Order.desc(info.getAttrType()));
    } else {
        crit.addOrder(Order.asc(info.getAttrType()));
    }
    return(crit);
}
项目:OneCMDBwithMaven    文件:QueryHandler.java   
private DetachedCriteria getComplexAttributeOrderCriteria(String template, DetachedCriteria ciCrit,
        OrderInfo info) {
    DetachedCriteria crit = DetachedCriteria.forClass(BasicAttribute.class);
    DetachedCriteria ciIdProjection = ciCrit.setProjection(Projections.property("longId"));
    crit.add(Property.forName("ownerId").in(ciIdProjection));
    crit.add(Expression.eq("alias", info.getAttrAlias()));
    //crit.add(Expression.isNotEmpty("valueAsLong"));

    ICi ci = this.msvc.findCi(new Path(template));
    IAttribute attr = ci.getAttributeDefinitionWithAlias(info.getAttrAlias());
    IType type = attr.getValueType();
    String targetTemplate = type.getAlias();

    DetachedCriteria refCrit = DetachedCriteria.forClass(ConfigurationItem.class);
    refCrit.add(Property.forName("longId").in(crit.setProjection(Projections.property("valueAsLong"))));

    DetachedCriteria refCiCrit = DetachedCriteria.forClass(ConfigurationItem.class);
    refCiCrit.add(Property.forName("longId").in(refCrit.setProjection(Projections.property("targetId"))));

    return(getDisplayNameOrder(targetTemplate, refCiCrit, info));
}
项目:OneCMDBwithMaven    文件:QueryHandler.java   
private DetachedCriteria getBackComplexAttributeOrder(List<Long> attrOwnerId, DetachedCriteria ci2Crit,
        OrderInfo info) {

    DetachedCriteria targetCrit = DetachedCriteria.forClass(ConfigurationItem.class);
    targetCrit.add(Property.forName("longId").in(attrOwnerId));

    DetachedCriteria refCrit = DetachedCriteria.forClass(ConfigurationItem.class);
    refCrit.add(Property.forName("targetId").in(targetCrit.setProjection(Projections.property("longId")))); 


    DetachedCriteria attrCrit = DetachedCriteria.forClass(BasicAttribute.class);
    attrCrit.add(Property.forName("valueAsLong").in(refCrit.setProjection(Projections.property("longId"))));
    attrCrit.add(Property.forName("ownerId").in(ci2Crit.setProjection(Projections.property("longId"))));
    attrCrit.add(Expression.eq("alias", info.getAttrAlias()));

    attrCrit.addOrder(Order.desc("longId"));
    return(attrCrit);
}
项目:OneCMDBwithMaven    文件:RelationExpression.java   
@Override
public DetachedCriteria getCriteria() {
    DetachedCriteria crit = getObjectCriteria(); //DetachedCriteria.forClass(ConfigurationItem.class);

    if (getTargetIds() != null) {
        crit.add(Property.forName(getRelationTargetProperty()).in(targetIds));
    } else {
        DetachedCriteria targetCrit = target.setProjection(Projections.property(getTargetProjection()));
        crit.add(Property.forName(getRelationTargetProperty()).in(targetCrit));
    }

    if (getSourceIds() != null) {
        crit.add(Property.forName(getRelationSourceProperty()).in(sourceIds));
    } else {
        DetachedCriteria sourceCrit = source.setProjection(Projections.property(getSourceProjection()));
        crit.add(Property.forName(getRelationSourceProperty()).in(sourceCrit));
    }
    return(crit);
}
项目:OneCMDBwithMaven    文件:ConstrainGroupExpression.java   
@Override
public DetachedCriteria getCriteria() {
    DetachedCriteria crit = getParent().getCriteria();
    Junction junction = null;
    if (disjunction) {
        junction = Restrictions.disjunction();
    } else {
        junction = Restrictions.conjunction();
    }
    for (Iterator iter = attributeExpressions.iterator(); iter.hasNext();) {
        AttributeExpression aExpr = (AttributeExpression) iter.next();
        DetachedCriteria attrCriteria = aExpr.getCriteria();
        junction.add(Property.forName("longId").in(attrCriteria.setProjection(Projections.property("ownerId"))));
    }
    crit.add(junction);

    return(crit);
}
项目:OneCMDBwithMaven    文件:SourceTemplateRelationExpression.java   
@Override
protected DetachedCriteria getCriteria() {
    // Select Target/Source attribute id.
    DetachedCriteria attrTarget = DetachedCriteria.forClass(BasicAttribute.class);
    attrTarget.add(Expression.eq("valueAsLong", targetId));
    attrTarget.add(Expression.eq("alias", "target"));
    DetachedCriteria relOwnerCrit = attrTarget.setProjection(Projections.property("ownerId"));

    DetachedCriteria relCi = DetachedCriteria.forClass(ConfigurationItem.class);
    relCi.add(Property.forName("longId").in(relOwnerCrit));
    relCi.add(Expression.eq("derivedFromId", referenceTemplateId));

    DetachedCriteria targetOwnerCrit = relCi.setProjection(Projections.property("longId"));

    DetachedCriteria attrSource = DetachedCriteria.forClass(BasicAttribute.class);
    attrSource.add(Expression.eq("alias", "source"));
    attrSource.add(Property.forName("ownerId").in(targetOwnerCrit));

    DetachedCriteria sourceIdCrit = attrSource.setProjection(Projections.property("valueAsLong"));

    DetachedCriteria sourceCi = DetachedCriteria.forClass(ConfigurationItem.class);
    sourceCi.add(Property.forName("longId").in(sourceIdCrit));

    return(sourceCi);
}
项目:cananolab    文件:ProtocolServiceHelper.java   
public Protocol findProtocolById(String protocolId) throws Exception {
    if (!springSecurityAclService.currentUserHasReadPermission(Long.valueOf(protocolId), SecureClassesEnum.PROTOCOL.getClazz()) &&
        !springSecurityAclService.currentUserHasWritePermission(Long.valueOf(protocolId), SecureClassesEnum.PROTOCOL.getClazz())) {
        new NoAccessException("User has no access to the protocol " + protocolId);
    }
    Protocol protocol = null;

    CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider.getApplicationService();
    DetachedCriteria crit = DetachedCriteria.forClass(Protocol.class).add(Property.forName("id").eq(new Long(protocolId)));
    crit.setFetchMode("file", FetchMode.JOIN);
    crit.setFetchMode("file.keywordCollection", FetchMode.JOIN);
    List result = appService.query(crit);
    if (!result.isEmpty()) {
        protocol = (Protocol) result.get(0);
    }
    return protocol;
}
项目:cananolab    文件:PublicationServiceHelper.java   
public Publication findPublicationById(String publicationId) throws Exception
{
    Long pubId = Long.valueOf(publicationId);
    if (!springSecurityAclService.currentUserHasReadPermission(pubId, SecureClassesEnum.PUBLICATION.getClazz()) &&
        !springSecurityAclService.currentUserHasWritePermission(pubId, SecureClassesEnum.PUBLICATION.getClazz())) {
        throw new NoAccessException("User has no access to the publication " + publicationId);
    }
    CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider.getApplicationService();

    DetachedCriteria crit = DetachedCriteria.forClass(Publication.class).add(Property.forName("id").eq(pubId));
    crit.setFetchMode("authorCollection", FetchMode.JOIN);
    crit.setFetchMode("keywordCollection", FetchMode.JOIN);
    crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    List result = appService.query(crit);
    Publication publication = null;
    if (!result.isEmpty()) {
        publication = (Publication) result.get(0);
    }
    return publication;
}
项目:cananolab    文件:PublicationServiceHelper.java   
public Publication findPublicationByKey(String keyName, Object keyValue)
        throws Exception {
    CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider
            .getApplicationService();

    DetachedCriteria crit = DetachedCriteria.forClass(Publication.class)
            .add(Property.forName(keyName).eq(keyValue));
    crit.setFetchMode("authorCollection", FetchMode.JOIN);
    crit.setFetchMode("keywordCollection", FetchMode.JOIN);
    crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    List result = appService.query(crit);
    Publication publication = null;
    if (!result.isEmpty()) {
        publication = (Publication) result.get(0);
        if (springSecurityAclService.currentUserHasReadPermission(publication.getId(), SecureClassesEnum.PUBLICATION.getClazz()) ||
            springSecurityAclService.currentUserHasWritePermission(publication.getId(), SecureClassesEnum.PUBLICATION.getClazz())) {
            return publication;
        } else {
            throw new NoAccessException();
        }
    }
    return publication;
}
项目:cananolab    文件:CharacterizationServiceHelper.java   
public List<ExperimentConfig> findExperimentConfigsByCharacterizationId(String charId) throws Exception
{
    if (!springSecurityAclService.currentUserHasReadPermission(Long.valueOf(charId), SecureClassesEnum.CHAR.getClazz()) &&
        !springSecurityAclService.currentUserHasWritePermission(Long.valueOf(charId), SecureClassesEnum.CHAR.getClazz())) {
        new NoAccessException("User has no access to the characterization " + charId);
    }
    List<ExperimentConfig> configs = new ArrayList<ExperimentConfig>();
    CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider.getApplicationService();
    DetachedCriteria crit = DetachedCriteria.forClass(
            Characterization.class).add(
            Property.forName("id").eq(new Long(charId)));
    crit.setFetchMode("experimentConfigCollection", FetchMode.JOIN);
    crit.setFetchMode("experimentConfigCollection.technique",
            FetchMode.JOIN);
    crit.setFetchMode("experimentConfigCollection.instrumentCollection",
            FetchMode.JOIN);
    List result = appService.query(crit);
    if (!result.isEmpty()) {
        Characterization achar = (Characterization) result.get(0);
        configs.addAll(achar.getExperimentConfigCollection());
    }
    return configs;
}
项目:cananolab    文件:CharacterizationServiceHelper.java   
public ExperimentConfig findExperimentConfigById(String sampleId, String id) throws Exception 
{
    if (!springSecurityAclService.currentUserHasReadPermission(Long.valueOf(sampleId), SecureClassesEnum.SAMPLE.getClazz()) &&
        !springSecurityAclService.currentUserHasWritePermission(Long.valueOf(sampleId), SecureClassesEnum.SAMPLE.getClazz())) {
        new NoAccessException("User has no access to the experiment config " + id);
    }
    ExperimentConfig config = null;

    CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider.getApplicationService();
    DetachedCriteria crit = DetachedCriteria.forClass(
            ExperimentConfig.class).add(
            Property.forName("id").eq(new Long(id)));
    crit.setFetchMode("technique", FetchMode.JOIN);
    crit.setFetchMode("instrumentCollection", FetchMode.JOIN);
    List result = appService.query(crit);
    if (!result.isEmpty()) {
        config = (ExperimentConfig) result.get(0);
    }
    return config;
}
项目:cananolab    文件:CharacterizationServiceHelper.java   
public Finding findFindingById(String findingId) throws Exception
{
    if (!springSecurityAclService.currentUserHasReadPermission(Long.valueOf(findingId), SecureClassesEnum.FINDING.getClazz()) &&
        !springSecurityAclService.currentUserHasWritePermission(Long.valueOf(findingId), SecureClassesEnum.FINDING.getClazz())) {
        new NoAccessException("User has no access to the finding " + findingId);
    }
    CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider.getApplicationService();
    DetachedCriteria crit = DetachedCriteria.forClass(Finding.class).add(Property.forName("id").eq(new Long(findingId)));
    crit.setFetchMode("datumCollection", FetchMode.JOIN);
    crit.setFetchMode("datumCollection.conditionCollection", FetchMode.JOIN);
    crit.setFetchMode("fileCollection", FetchMode.JOIN);
    crit.setFetchMode("fileCollection.keywordCollection", FetchMode.JOIN);
    List result = appService.query(crit);
    Finding finding = null;
    if (!result.isEmpty()) {
        finding = (Finding) result.get(0);
        if (finding.getFileCollection() != null) {
            removeUnaccessibleFiles(finding.getFileCollection());
        }
    }
    return finding;
}
项目:cananolab    文件:CompositionServiceHelper.java   
public Function findFunctionById(String funcId) throws Exception {
    if (!springSecurityAclService.currentUserHasReadPermission(Long.valueOf(funcId), SecureClassesEnum.FUNCTION.getClazz()) &&
        !springSecurityAclService.currentUserHasWritePermission(Long.valueOf(funcId), SecureClassesEnum.FUNCTION.getClazz())) {
        new NoAccessException("User has no access to the function " + funcId);
    }
    CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider.getApplicationService();

    DetachedCriteria crit = DetachedCriteria.forClass(Function.class).add(
            Property.forName("id").eq(new Long(funcId)));
    crit.setFetchMode("targetCollection", FetchMode.JOIN);
    crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    List result = appService.query(crit);
    Function func = null;
    if (!result.isEmpty()) {
        func = (Function) result.get(0);
    }
    return func;
}
项目:cananolab    文件:CompositionServiceHelper.java   
public ComposingElement findComposingElementById(String ceId) throws Exception
{
    if (!springSecurityAclService.currentUserHasReadPermission(Long.valueOf(ceId), SecureClassesEnum.COMPOSINGELEMENT.getClazz()) &&
        !springSecurityAclService.currentUserHasWritePermission(Long.valueOf(ceId), SecureClassesEnum.COMPOSINGELEMENT.getClazz())) {
        new NoAccessException("User has no access to the composing element " + ceId);
    }
    CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider.getApplicationService();

    DetachedCriteria crit = DetachedCriteria.forClass(ComposingElement.class).add(Property.forName("id").eq(new Long(ceId)));
    crit.setFetchMode("inherentFunctionCollection", FetchMode.JOIN);
    crit.setFetchMode("inherentFunctionCollection.targetCollection", FetchMode.JOIN);
    crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    List result = appService.query(crit);
    ComposingElement ce = null;
    if (!result.isEmpty()) {
        ce = (ComposingElement) result.get(0);
    }
    return ce;
}
项目:cananolab    文件:CompositionServiceHelper.java   
public ChemicalAssociation findChemicalAssociationById(String sampleId, String assocId) throws Exception
{
    if (!springSecurityAclService.currentUserHasReadPermission(Long.valueOf(sampleId), SecureClassesEnum.SAMPLE.getClazz()) &&
        !springSecurityAclService.currentUserHasWritePermission(Long.valueOf(sampleId), SecureClassesEnum.SAMPLE.getClazz())) {
        new NoAccessException("User has no access to the chemical association " + assocId);
    }
    ChemicalAssociation assoc = null;

    CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider.getApplicationService();

    DetachedCriteria crit = DetachedCriteria.forClass(ChemicalAssociation.class).add(Property.forName("id").eq(new Long(assocId)));
    crit.setFetchMode("fileCollection", FetchMode.JOIN);
    crit.setFetchMode("fileCollection.keywordCollection", FetchMode.JOIN);
    crit.setFetchMode("associatedElementA", FetchMode.JOIN);
    crit.setFetchMode("associatedElementA.nanomaterialEntity", FetchMode.JOIN);
    crit.setFetchMode("associatedElementB", FetchMode.JOIN);
    crit.setFetchMode("associatedElementB.nanomaterialEntity", FetchMode.JOIN);
    crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);

    List result = appService.query(crit);
    if (!result.isEmpty()) {
        assoc = (ChemicalAssociation) result.get(0);
    }
    return assoc;
}
项目:cananolab    文件:AdvancedSampleServiceHelper.java   
private DetachedCriteria getCharacterizationSubquery(
        CharacterizationQueryBean charQuery, String projectionProperty) {
    DetachedCriteria subCrit = DetachedCriteria.forClass(
            Characterization.class, "subCrit");
    subCrit.setProjection(Projections.distinct(Property
            .forName(projectionProperty)));
    // join finding and datum
    if (!StringUtils.isEmpty(charQuery.getDatumName())) {
        subCrit.createAlias("subCrit.findingCollection", "finding",
                CriteriaSpecification.LEFT_JOIN);
        subCrit.createAlias("finding.datumCollection", "datum",
                CriteriaSpecification.LEFT_JOIN);
    }
    Criterion charCrit = getCharacterizationCriterion(charQuery, "");
    subCrit.add(charCrit);
    subCrit.add(Restrictions.eqProperty("subCrit." + projectionProperty,
            "rootCrit.id"));
    return subCrit;
}
项目:cananolab    文件:AdvancedSampleServiceHelper.java   
private DetachedCriteria getFunctionSubquery(CompositionQueryBean query,
        String funcAlias1, String funcAlias2, String projectionProperty)
        throws Exception {
    DetachedCriteria subCrit = DetachedCriteria.forClass(Function.class,
            "subCrit");
    subCrit.setProjection(Projections.distinct(Property
            .forName(projectionProperty)));
    Criterion funcCrit = getFunctionCriterion(query, "", "");
    subCrit.add(funcCrit);
    if (funcAlias1.equals(funcAlias2)) {
        subCrit.add(Restrictions.eqProperty(
                "subCrit." + projectionProperty, funcAlias1 + "id"));
    } else {
        subCrit.add(Restrictions.or(Restrictions.eqProperty("subCrit."
                + projectionProperty, funcAlias1 + "id"), Restrictions
                .eqProperty("subCrit." + projectionProperty, funcAlias2
                        + "id")));
    }
    return subCrit;
}
项目:cananolab    文件:AdvancedSampleServiceHelper.java   
private DetachedCriteria getNanomaterialEntitySubquery(
        CompositionQueryBean query, String nanoEntityAlias,
        String projectionProperty) throws Exception {
    DetachedCriteria subCrit = DetachedCriteria.forClass(
            NanomaterialEntity.class, "subCrit");
    subCrit.setProjection(Projections.distinct(Property
            .forName(projectionProperty)));
    // join composing element
    if (!StringUtils.isEmpty(query.getChemicalName())) {
        subCrit.createAlias("subCrit.composingElementCollection",
                "compElement", CriteriaSpecification.LEFT_JOIN);
    }
    Criterion nanoCrit = getNanomaterialEntityCriterion(query, "");
    subCrit.add(nanoCrit);
    subCrit.add(Restrictions.eqProperty("subCrit." + projectionProperty,
            nanoEntityAlias + "id"));
    return subCrit;
}
项目:cananolab    文件:AdvancedSampleServiceHelper.java   
private DetachedCriteria getPointOfContactSubquery(SampleQueryBean query,
        String pocAlias1, String pocAlias2, String projectionProperty) {
    DetachedCriteria subCrit = DetachedCriteria.forClass(
            PointOfContact.class, "subCrit");
    subCrit.createAlias("subCrit.organization", "organization",
            CriteriaSpecification.LEFT_JOIN);
    subCrit.setProjection(Projections.distinct(Property.forName("id")));
    Disjunction pocDisjunction = getPointOfContactDisjunctionPerQuery(
            query, "", "");
    subCrit.add(pocDisjunction);
    if (pocAlias1.equals(pocAlias2)) {
        subCrit.add(Restrictions.eqProperty(
                "subCrit." + projectionProperty, pocAlias1 + "id"));
    } else {
        subCrit.add(Restrictions.or(Restrictions.eqProperty("subCrit."
                + projectionProperty, pocAlias1 + "id"), Restrictions
                .eqProperty("subCrit." + projectionProperty, pocAlias2
                        + "id")));
    }
    return subCrit;
}
项目:cananolab    文件:SampleServiceHelper.java   
public List<Keyword> findKeywordsBySampleId(String sampleId) throws Exception
{
    // check whether user has access to the sample

    if (!springSecurityAclService.currentUserHasReadPermission(Long.valueOf(sampleId), SecureClassesEnum.SAMPLE.getClazz()) &&
        !springSecurityAclService.currentUserHasWritePermission(Long.valueOf(sampleId), SecureClassesEnum.SAMPLE.getClazz())) {
        throw new NoAccessException("User doesn't have access to the sample : " + sampleId);
    }
    List<Keyword> keywords = new ArrayList<Keyword>();

    CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider.getApplicationService();
    DetachedCriteria crit = DetachedCriteria.forClass(Sample.class).add(Property.forName("id").eq(new Long(sampleId)));
    crit.setFetchMode("keywordCollection", FetchMode.JOIN);
    List result = appService.query(crit);
    Sample sample = null;
    if (!result.isEmpty()) {
        sample = (Sample) result.get(0);
        keywords.addAll(sample.getKeywordCollection());
    }
    return keywords;
}
项目:cananolab    文件:SampleServiceHelper.java   
public PointOfContact findPrimaryPointOfContactBySampleId(String sampleId) throws Exception
{
    if (!springSecurityAclService.currentUserHasReadPermission(Long.valueOf(sampleId), SecureClassesEnum.SAMPLE.getClazz()) &&
        !springSecurityAclService.currentUserHasWritePermission(Long.valueOf(sampleId), SecureClassesEnum.SAMPLE.getClazz())) {
        throw new NoAccessException("User has no access to the sample " + sampleId);
    }
    CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider.getApplicationService();
    DetachedCriteria crit = DetachedCriteria.forClass(Sample.class).add(
            Property.forName("id").eq(new Long(sampleId)));
    crit.setFetchMode("primaryPointOfContact", FetchMode.JOIN);
    crit.setFetchMode("primaryPointOfContact.organization", FetchMode.JOIN);
    crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    List results = appService.query(crit);
    PointOfContact poc = null;
    for(int i = 0; i < results.size(); i++){
        Sample sample = (Sample) results.get(i);
        poc = sample.getPrimaryPointOfContact();
    }
    return poc;
}
项目:cananolab    文件:SampleServiceHelper.java   
public List<PointOfContact> findOtherPointOfContactsBySampleId(String sampleId) throws Exception {
    if (!springSecurityAclService.currentUserHasReadPermission(Long.valueOf(sampleId), SecureClassesEnum.SAMPLE.getClazz()) &&
        !springSecurityAclService.currentUserHasWritePermission(Long.valueOf(sampleId), SecureClassesEnum.SAMPLE.getClazz())) {
        throw new NoAccessException("User has no access to the sample " + sampleId);
    }
    CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider
            .getApplicationService();
    DetachedCriteria crit = DetachedCriteria.forClass(Sample.class).add(
            Property.forName("id").eq(new Long(sampleId)));
    crit.setFetchMode("otherPointOfContactCollection", FetchMode.JOIN);
    crit.setFetchMode("otherPointOfContactCollection.organization",
            FetchMode.JOIN);
    crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    List results = appService.query(crit);
    List<PointOfContact> pointOfContacts = new ArrayList<PointOfContact>();
    for(int i = 0; i < results.size(); i++){
        Sample sample = (Sample) results.get(i);
        Collection<PointOfContact> otherPOCs = sample
                .getOtherPointOfContactCollection();
        for (PointOfContact poc : otherPOCs) {
            pointOfContacts.add(poc);
        }
    }
    return pointOfContacts;
}
项目:cananolab    文件:SampleServiceHelper.java   
public Sample findSampleBasicById(String sampleId) throws Exception {
    if (!springSecurityAclService.currentUserHasReadPermission(Long.valueOf(sampleId), SecureClassesEnum.SAMPLE.getClazz()) &&
        !springSecurityAclService.currentUserHasWritePermission(Long.valueOf(sampleId), SecureClassesEnum.SAMPLE.getClazz())) {
        throw new NoAccessException("User has no access to the sample " + sampleId);
    }
    Sample sample = null;
    CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider
            .getApplicationService();

    DetachedCriteria crit = DetachedCriteria.forClass(Sample.class).add(
            Property.forName("id").eq(new Long(sampleId)));

    crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);

    List result = appService.query(crit);
    if (!result.isEmpty()) {
        sample = (Sample) result.get(0);
    }
    return sample;
}
项目:cananolab    文件:CharacterizationServiceLocalImpl.java   
private Technique findTechniqueByType(String type) throws ExperimentConfigException
{
    Technique technique = null;
    try {
        CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider.getApplicationService();
        DetachedCriteria crit = DetachedCriteria.forClass(Technique.class)
                .add(Property.forName("type").eq(new String(type)).ignoreCase());
        List results = appService.query(crit);
        for (int i = 0; i < results.size(); i++) {
            technique = (Technique) results.get(i);
        }
    } catch (Exception e) {
        String err = "Problem to retrieve technique by type.";
        logger.error(err, e);
        throw new ExperimentConfigException(err);
    }
    return technique;
}
项目:cananolab    文件:CharacterizationServiceLocalImpl.java   
public List<String> findOtherCharacterizationByAssayCategory(
        String assayCategory) throws CharacterizationException {
    List<String> charNames = new ArrayList<String>();
    try {
        CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider.getApplicationService();
        DetachedCriteria crit = DetachedCriteria.forClass(OtherCharacterization.class).add(
                Property.forName("assayCategory").eq(assayCategory).ignoreCase());
        List result = appService.query(crit);
        for (Object obj : result) {
            String charName = ((OtherCharacterization) obj).getName();
            if (!charNames.contains(charName)) {
                charNames.add(charName);
            }
        }
    } catch (Exception e) {
        String err = "Error finding other characterizations by assay cateogry " + assayCategory;
        logger.error(err, e);
        throw new CharacterizationException(err, e);
    }
    return charNames;
}
项目:cananolab    文件:SampleServiceLocalImpl.java   
public void updatePOCAssociatedWithCharacterizations(String sampleName, Long oldPOCId, Long newPOCId) throws SampleException
{
    try {
        CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider.getApplicationService();
        DetachedCriteria crit = DetachedCriteria.forClass(Characterization.class);
        crit.createAlias("sample", "sample");
        crit.createAlias("pointOfContact", "poc");
        crit.add(Property.forName("poc.id").eq(oldPOCId));
        crit.add(Property.forName("sample.name").eq(sampleName));
        crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
        List results = appService.query(crit);
        for (int i = 0; i < results.size(); i++){
            Characterization achar = (Characterization) results.get(i);
            // update POC to the new ID
            achar.getPointOfContact().setId(newPOCId);
            appService.saveOrUpdate(achar);
        }
    } catch (Exception e) {
        String err = "Error in updating POC associated sample characterizations "
                + sampleName + ". " + e.getMessage();
        logger.error(err, e);
        throw new SampleException(err, e);
    }
}
项目:cananolab    文件:LookupService.java   
public static Map<String, String> findSingleAttributeLookupMap(
        String attribute) throws BaseException {
    Map<String, String> lookup = new HashMap<String, String>();
    try {
        CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider
                .getApplicationService();
        DetachedCriteria crit = DetachedCriteria
                .forClass(CommonLookup.class);
        crit.add(Property.forName("attribute").eq(attribute));
        List results = appService.query(crit);
        for (int i = 0; i < results.size(); i++) {
            lookup.put(((CommonLookup) results.get(i)).getName(), ((CommonLookup) results.get(i))
                    .getValue());
        }
    } catch (Exception e) {
        logger.error("Error in retrieving " + attribute
                + " from CommonLookup", e);
        throw new BaseException();
    }
    return lookup;
}