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.SampleServiceHelper.java
License:BSD License
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); }/*from w w w. j ava 2 s. c o m*/ 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; }
From source file:gov.nih.nci.cananolab.service.sample.helper.SampleServiceHelper.java
License:BSD License
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); }/*from w w w .j ava 2 s . co m*/ 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; }
From source file:gov.nih.nci.cananolab.service.sample.helper.SampleServiceHelper.java
License:BSD License
public Sample findSampleById(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); }/*from w w w. j ava 2s .c o m*/ logger.debug("===============Finding a sample by id: " + System.currentTimeMillis()); Sample sample = null; 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.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 result = appService.query(crit); if (!result.isEmpty() || result.size() > 0) { sample = (Sample) result.get(0); } return sample; }
From source file:gov.nih.nci.cananolab.service.sample.helper.SampleServiceHelper.java
License:BSD License
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); }//from w w w . j a v a 2 s . c om 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; }
From source file:gov.nih.nci.cananolab.service.sample.helper.SampleServiceHelper.java
License:BSD License
public Organization findOrganizationByName(String orgName) throws Exception { CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider .getApplicationService();/*from ww w . j a v a 2 s . co m*/ DetachedCriteria crit = DetachedCriteria.forClass(Organization.class); crit.add(Restrictions.eq("name", orgName).ignoreCase()); crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); List results = appService.query(crit); Organization org = null; for (int i = 0; i < results.size(); i++) { org = (Organization) results.get(i); } return org; }
From source file:gov.nih.nci.cananolab.service.sample.helper.SampleServiceHelper.java
License:BSD License
public List<PointOfContact> findPointOfContactsBySampleId(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); }//from w w w. j ava 2 s . c o m 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.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); PointOfContact primaryPOC = sample.getPrimaryPointOfContact(); pointOfContacts.add(primaryPOC); Collection<PointOfContact> otherPOCs = sample.getOtherPointOfContactCollection(); pointOfContacts.addAll(otherPOCs); } return pointOfContacts; }
From source file:gov.nih.nci.cananolab.service.sample.helper.SampleServiceHelper.java
License:BSD License
public PointOfContact findPointOfContactByNameAndOrg(String firstName, String lastName, String orgName) throws Exception { PointOfContact poc = null;/*from w ww . j a v a2 s .c o m*/ CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider .getApplicationService(); DetachedCriteria crit = DetachedCriteria.forClass(PointOfContact.class); crit.createAlias("organization", "organization"); if (!StringUtils.isEmpty(lastName)) crit.add(Restrictions.eq("lastName", lastName)); if (!StringUtils.isEmpty(firstName)) crit.add(Restrictions.eq("firstName", firstName)); if (!StringUtils.isEmpty(orgName)) crit.add(Restrictions.eq("organization.name", orgName)); crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); List results = appService.query(crit); for (int i = 0; i < results.size(); i++) { poc = (PointOfContact) results.get(i); } return poc; }
From source file:gov.nih.nci.cananolab.service.sample.impl.SampleServiceLocalImpl.java
License:BSD License
private Sample findFullyLoadedSampleByName(String sampleName) throws Exception { CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider .getApplicationService();/*from w w w.j a v a 2 s.c o m*/ // load composition and characterization separate because of Hibernate // join limitation DetachedCriteria crit = DetachedCriteria.forClass(Sample.class) .add(Property.forName("name").eq(sampleName).ignoreCase()); Sample sample = null; // load composition and characterization separate because of // Hibernate join limitation 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("publicationCollection", FetchMode.JOIN); crit.setFetchMode("publicationCollection.authorCollection", FetchMode.JOIN); crit.setFetchMode("publicationCollection.keywordCollection", FetchMode.JOIN); crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); List result = appService.query(crit); if (!result.isEmpty()) { sample = (Sample) result.get(0); } if (sample == null) { throw new NotExistException("Sample doesn't exist in the database"); } // fully load composition SampleComposition comp = this.loadComposition(sample.getId().toString()); sample.setSampleComposition(comp); // fully load characterizations List<Characterization> chars = this.loadCharacterizations(sample.getId().toString()); if (chars != null && !chars.isEmpty()) { sample.setCharacterizationCollection(new HashSet<Characterization>(chars)); } else { sample.setCharacterizationCollection(null); } return sample; }
From source file:gov.nih.nci.cananolab.service.sample.impl.SampleServiceLocalImpl.java
License:BSD License
public List<PointOfContactBean> findPointOfContactsBySampleId(String sampleId) throws PointOfContactException { try {/*from w ww. ja v a 2s . co m*/ 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.setFetchMode("otherPointOfContactCollection", FetchMode.JOIN); crit.setFetchMode("otherPointOfContactCollection.organization", FetchMode.JOIN); crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); List results = appService.query(crit); List<PointOfContactBean> pointOfContactCollection = new ArrayList<PointOfContactBean>(); for (int i = 0; i < results.size(); i++) { Sample particle = (Sample) results.get(i); PointOfContact primaryPOC = particle.getPrimaryPointOfContact(); Collection<PointOfContact> otherPOCs = particle.getOtherPointOfContactCollection(); pointOfContactCollection.add(new PointOfContactBean(primaryPOC)); for (PointOfContact poc : otherPOCs) { pointOfContactCollection.add(new PointOfContactBean(poc)); } } return pointOfContactCollection; } catch (Exception e) { String err = "Problem finding all PointOfContact collections with the given sample ID."; logger.error(err, e); throw new PointOfContactException(err, e); } }
From source file:gov.nih.nci.cananolab.service.sample.impl.SampleServiceLocalImpl.java
License:BSD License
public void updatePOCAssociatedWithCharacterizations(String sampleName, Long oldPOCId, Long newPOCId) throws SampleException { try {/* w w w . j a va2 s. c o m*/ 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); } }