List of usage examples for org.hibernate.criterion DetachedCriteria setResultTransformer
public DetachedCriteria setResultTransformer(ResultTransformer resultTransformer)
From source file:gov.nih.nci.cananolab.service.sample.helper.AdvancedSampleServiceHelper.java
License:BSD License
private List<NanomaterialEntity> findNanomaterialEntitiesBy(String sampleId, AdvancedSampleSearchBean searchBean) throws Exception { List<NanomaterialEntity> entities = new ArrayList<NanomaterialEntity>(); Long id = new Long(sampleId); if (!searchBean.getHasNanomaterial()) { return entities; }//w w w.j a va 2s.com DetachedCriteria crit = DetachedCriteria.forClass(NanomaterialEntity.class); CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider .getApplicationService(); Junction junction = getNanomaterialEntityJunction(searchBean, crit); if (junction != null) { // join nanomaterialEntity if (searchBean.getHasNanomaterial() && !searchBean.getHasFunction()) { if (searchBean.getHasChemicalName()) { crit.createAlias("composingElementCollection", "compElement", CriteriaSpecification.LEFT_JOIN); } } crit.createAlias("sampleComposition", "comp"); crit.createAlias("comp.sample", "sample"); crit.add(Restrictions.eq("sample.id", id)); crit.add(junction); crit.setFetchMode("fileCollection", FetchMode.JOIN); crit.setFetchMode("fileCollection.keywordCollection", FetchMode.JOIN); crit.setFetchMode("composingElementCollection", FetchMode.JOIN); crit.setFetchMode("composingElementCollection.inherentFunctionCollection", FetchMode.JOIN); crit.setFetchMode("composingElementCollection.inherentFunctionCollection.targetCollection", FetchMode.JOIN); crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); List results = appService.query(crit); for (int i = 0; i < results.size(); i++) { NanomaterialEntity entity = (NanomaterialEntity) results.get(i); entities.add(entity); } } else if (searchBean.getNanoEntityCount() > 1) { // Hibernate Criteria API doesn't support union, union in java for (CompositionQueryBean query : searchBean.getCompositionQueries()) { if (query.getCompositionType().equals("nanomaterial entity")) { crit = DetachedCriteria.forClass(NanomaterialEntity.class); crit.createAlias("sampleComposition", "comp", CriteriaSpecification.LEFT_JOIN); crit.createAlias("comp.sample", "sample", CriteriaSpecification.LEFT_JOIN); if (!StringUtils.isEmpty(query.getChemicalName())) { crit.createAlias("composingElementCollection", "compElement"); } crit.add(Restrictions.eq("sample.id", id)); crit.setFetchMode("fileCollection", FetchMode.JOIN); crit.setFetchMode("fileCollection.keywordCollection", FetchMode.JOIN); crit.setFetchMode("composingElementCollection", FetchMode.JOIN); crit.setFetchMode("composingElementCollection.inherentFunctionCollection", FetchMode.JOIN); crit.setFetchMode("composingElementCollection.inherentFunctionCollection.targetCollection", FetchMode.JOIN); DetachedCriteria subCrit = getNanomaterialEntitySubquery(query, "", "id"); crit.add(Subqueries.exists(subCrit)); crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); List results = appService.query(crit); for (int i = 0; i < results.size(); i++) { NanomaterialEntity entity = (NanomaterialEntity) results.get(i); if (!entities.contains(entity)) { entities.add(entity); } } } } } return entities; }
From source file:gov.nih.nci.cananolab.service.sample.helper.CharacterizationServiceHelper.java
License:BSD License
public List<Characterization> findCharacterizationsBySampleId(String sampleId) throws Exception { List<Characterization> chars = new ArrayList<Characterization>(); CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider .getApplicationService();// w w w . j av a2 s. c o m DetachedCriteria crit = DetachedCriteria.forClass(Characterization.class); crit.createAlias("sample", "sample"); crit.add(Property.forName("sample.id").eq(new Long(sampleId))); // fully load characterization crit.setFetchMode("pointOfContact", FetchMode.JOIN); crit.setFetchMode("pointOfContact.organization", FetchMode.JOIN); crit.setFetchMode("protocol", FetchMode.JOIN); crit.setFetchMode("protocol.file", FetchMode.JOIN); crit.setFetchMode("protocol.file.keywordCollection", FetchMode.JOIN); crit.setFetchMode("experimentConfigCollection", FetchMode.JOIN); crit.setFetchMode("experimentConfigCollection.technique", FetchMode.JOIN); crit.setFetchMode("experimentConfigCollection.instrumentCollection", FetchMode.JOIN); crit.setFetchMode("findingCollection", FetchMode.JOIN); crit.setFetchMode("findingCollection.datumCollection", FetchMode.JOIN); crit.setFetchMode("findingCollection.datumCollection.conditionCollection", FetchMode.JOIN); crit.setFetchMode("findingCollection.fileCollection", FetchMode.JOIN); crit.setFetchMode("findingCollection.fileCollection.keywordCollection", FetchMode.JOIN); 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); if (springSecurityAclService.currentUserHasReadPermission(achar.getId(), SecureClassesEnum.CHAR.getClazz()) || springSecurityAclService.currentUserHasWritePermission(achar.getId(), SecureClassesEnum.CHAR.getClazz())) { checkAssociatedVisibility(achar); chars.add(achar); } else { logger.debug("User doesn't have access ot characterization with id " + achar.getId()); } } return chars; }
From source file:gov.nih.nci.cananolab.service.sample.helper.CharacterizationServiceHelper.java
License:BSD License
public Characterization findCharacterizationById(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); }/*w w w . j av a2 s . co m*/ Characterization achar = null; CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider .getApplicationService(); DetachedCriteria crit = DetachedCriteria.forClass(Characterization.class) .add(Property.forName("id").eq(new Long(charId))); // fully load characterization crit.setFetchMode("pointOfContact", FetchMode.JOIN); crit.setFetchMode("pointOfContact.organization", FetchMode.JOIN); crit.setFetchMode("protocol", FetchMode.JOIN); crit.setFetchMode("protocol.file", FetchMode.JOIN); crit.setFetchMode("protocol.file.keywordCollection", FetchMode.JOIN); crit.setFetchMode("experimentConfigCollection", FetchMode.JOIN); crit.setFetchMode("experimentConfigCollection.technique", FetchMode.JOIN); crit.setFetchMode("experimentConfigCollection.instrumentCollection", FetchMode.JOIN); crit.setFetchMode("findingCollection", FetchMode.JOIN); crit.setFetchMode("findingCollection.datumCollection", FetchMode.JOIN); crit.setFetchMode("findingCollection.datumCollection.conditionCollection", FetchMode.JOIN); crit.setFetchMode("findingCollection.fileCollection", FetchMode.JOIN); crit.setFetchMode("findingCollection.fileCollection.keywordCollection", FetchMode.JOIN); crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); List result = appService.query(crit); if (!result.isEmpty()) { achar = (Characterization) result.get(0); checkAssociatedVisibility(achar); } return achar; }
From source file:gov.nih.nci.cananolab.service.sample.helper.CompositionServiceHelper.java
License:BSD License
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); }/* w w w. ja v a 2 s .c o m*/ 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; }
From source file:gov.nih.nci.cananolab.service.sample.helper.CompositionServiceHelper.java
License:BSD License
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); }/* ww w . jav a2 s . c o m*/ 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; }
From source file:gov.nih.nci.cananolab.service.sample.helper.CompositionServiceHelper.java
License:BSD License
public SampleComposition findCompositionBySampleId(String sampleId) 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 sample " + sampleId); }//from www .java 2s. co m SampleComposition composition = null; CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider .getApplicationService(); DetachedCriteria crit = DetachedCriteria.forClass(SampleComposition.class); crit.createAlias("sample", "sample"); crit.add(Property.forName("sample.id").eq(new Long(sampleId))); crit.setFetchMode("nanomaterialEntityCollection", FetchMode.JOIN); crit.setFetchMode("nanomaterialEntityCollection.fileCollection", FetchMode.JOIN); crit.setFetchMode("nanomaterialEntityCollection.fileCollection.keywordCollection", FetchMode.JOIN); crit.setFetchMode("nanomaterialEntityCollection.composingElementCollection", FetchMode.JOIN); crit.setFetchMode("nanomaterialEntityCollection.composingElementCollection.inherentFunctionCollection", FetchMode.JOIN); crit.setFetchMode( "nanomaterialEntityCollection.composingElementCollection.inherentFunctionCollection.targetCollection", FetchMode.JOIN); crit.setFetchMode("functionalizingEntityCollection", FetchMode.JOIN); crit.setFetchMode("functionalizingEntityCollection.fileCollection", FetchMode.JOIN); crit.setFetchMode("functionalizingEntityCollection.fileCollection.keywordCollection", FetchMode.JOIN); crit.setFetchMode("functionalizingEntityCollection.functionCollection", FetchMode.JOIN); crit.setFetchMode("functionalizingEntityCollection.functionCollection.targetCollection", FetchMode.JOIN); crit.setFetchMode("functionalizingEntityCollection.activationMethod", FetchMode.JOIN); crit.setFetchMode("chemicalAssociationCollection", FetchMode.JOIN); crit.setFetchMode("chemicalAssociationCollection.fileCollection", FetchMode.JOIN); crit.setFetchMode("chemicalAssociationCollection.fileCollection.keywordCollection", FetchMode.JOIN); crit.setFetchMode("chemicalAssociationCollection.associatedElementA", FetchMode.JOIN); crit.setFetchMode("chemicalAssociationCollection.associatedElementB", FetchMode.JOIN); crit.setFetchMode("fileCollection", FetchMode.JOIN); crit.setFetchMode("fileCollection.keywordCollection", FetchMode.JOIN); crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); List result = appService.query(crit); if (!result.isEmpty()) { composition = (SampleComposition) result.get(0); /*if (!springSecurityAclService.currentUserHasReadPermission(composition.getId(), SecureClassesEnum.COMPOSITION.getClazz()) && !springSecurityAclService.currentUserHasWritePermission(composition.getId(), SecureClassesEnum.COMPOSITION.getClazz())) { throw new NoAccessException("User doesn't have access to the composition " + composition.getId()); }*/ } return composition; }
From source file:gov.nih.nci.cananolab.service.sample.helper.CompositionServiceHelper.java
License:BSD License
public NanomaterialEntity findNanomaterialEntityById(String sampleId, String entityId) throws Exception { NanomaterialEntity entity = null;/*from ww w. java 2 s .c o m*/ 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 nanomaterial entity " + entityId); } CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider .getApplicationService(); DetachedCriteria crit = DetachedCriteria.forClass(NanomaterialEntity.class) .add(Property.forName("id").eq(new Long(entityId))); crit.setFetchMode("sampleComposition", FetchMode.JOIN); crit.setFetchMode("sampleComposition.chemicalAssociationCollection", FetchMode.JOIN); crit.setFetchMode("sampleComposition.chemicalAssociationCollection.associatedElementA", FetchMode.JOIN); crit.setFetchMode("sampleComposition.chemicalAssociationCollection.associatedElementB", FetchMode.JOIN); crit.setFetchMode("fileCollection", FetchMode.JOIN); crit.setFetchMode("fileCollection.keywordCollection", FetchMode.JOIN); crit.setFetchMode("composingElementCollection", FetchMode.JOIN); crit.setFetchMode("composingElementCollection.inherentFunctionCollection", FetchMode.JOIN); crit.setFetchMode("composingElementCollection.inherentFunctionCollection.targetCollection", FetchMode.JOIN); crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); List result = appService.query(crit); if (!result.isEmpty()) { entity = (NanomaterialEntity) result.get(0); } return entity; }
From source file:gov.nih.nci.cananolab.service.sample.helper.CompositionServiceHelper.java
License:BSD License
public FunctionalizingEntity findFunctionalizingEntityById(String sampleId, String entityId) 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 functionalizing entity " + entityId); }/*w w w .java 2 s .com*/ FunctionalizingEntity entity = null; CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider .getApplicationService(); DetachedCriteria crit = DetachedCriteria.forClass(FunctionalizingEntity.class) .add(Property.forName("id").eq(new Long(entityId))); crit.setFetchMode("activationMethod", FetchMode.JOIN); crit.setFetchMode("fileCollection", FetchMode.JOIN); crit.setFetchMode("fileCollection.keywordCollection", FetchMode.JOIN); crit.setFetchMode("functionCollection", FetchMode.JOIN); crit.setFetchMode("functionCollection.targetCollection", FetchMode.JOIN); crit.setFetchMode("sampleComposition", FetchMode.JOIN); crit.setFetchMode("sampleComposition.chemicalAssociationCollection", FetchMode.JOIN); crit.setFetchMode("sampleComposition.chemicalAssociationCollection.associatedElementA", FetchMode.JOIN); crit.setFetchMode("sampleComposition.chemicalAssociationCollection.associatedElementB", FetchMode.JOIN); crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); List result = appService.query(crit); if (!result.isEmpty()) { entity = (FunctionalizingEntity) result.get(0); } return entity; }
From source file:gov.nih.nci.cananolab.service.sample.helper.CompositionServiceHelper.java
License:BSD License
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); }//from www .j a v a 2 s . com 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; }
From source file:gov.nih.nci.cananolab.service.sample.helper.SampleServiceHelper.java
License:BSD License
public Sample findSampleByName(String sampleName) throws Exception { Sample sample = null;//from w w w.j av a2 s .c om CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider .getApplicationService(); DetachedCriteria crit = DetachedCriteria.forClass(Sample.class) .add(Property.forName("name").eq(sampleName).ignoreCase()); crit.setFetchMode("primaryPointOfContact", FetchMode.JOIN); crit.setFetchMode("primaryPointOfContact.organization", FetchMode.JOIN); crit.setFetchMode("otherPointOfContactCollection", FetchMode.JOIN); crit.setFetchMode("otherPointOfContactCollection.organization", FetchMode.JOIN); crit.setFetchMode("keywordCollection", FetchMode.JOIN); crit.setFetchMode("characterizationCollection", FetchMode.JOIN); crit.setFetchMode("sampleComposition.chemicalAssociationCollection", FetchMode.JOIN); crit.setFetchMode("sampleComposition.nanomaterialEntityCollection", FetchMode.JOIN); crit.setFetchMode("sampleComposition.nanomaterialEntityCollection.composingElementCollection", FetchMode.JOIN); crit.setFetchMode( "sampleComposition.nanomaterialEntityCollection.composingElementCollection.inherentFunctionCollection", FetchMode.JOIN); crit.setFetchMode("sampleComposition.functionalizingEntityCollection", FetchMode.JOIN); crit.setFetchMode("sampleComposition.functionalizingEntityCollection.functionCollection", FetchMode.JOIN); crit.setFetchMode("publicationCollection", FetchMode.JOIN); crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); List<Object> result = appService.query(crit); if (!result.isEmpty()) { sample = (Sample) result.get(0); if (!springSecurityAclService.currentUserHasReadPermission(sample.getId(), SecureClassesEnum.SAMPLE.getClazz()) && !springSecurityAclService.currentUserHasWritePermission(sample.getId(), SecureClassesEnum.SAMPLE.getClazz())) { throw new NoAccessException("User has no access to the sample " + sampleName); } } return sample; }