private void deleteSampleWhenError(String sampleName) throws Exception { Sample sample = this.findFullyLoadedSampleByName(sampleName); CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider.getApplicationService(); // delete characterizations if (sample.getCharacterizationCollection() != null) { for (Characterization achar : sample.getCharacterizationCollection()) { charService.deleteCharacterization(achar); } } // delete composition if (sample.getSampleComposition() != null) { compService.deleteComposition(sample.getSampleComposition()); } sample.setSampleComposition(null); // remove publication associations if (sample.getPublicationCollection() != null) { sample.setPublicationCollection(null); } // remove keyword associations if (sample.getKeywordCollection() != null) { sample.setKeywordCollection(null); } appService.saveOrUpdate(sample); appService.delete(sample); // remove all csm entries associated with sample this.accessUtils.removeCSMEntries(sample.getId().toString()); }
public void removeAccessibility(AccessibilityBean access, Sample sample) throws SampleException, NoAccessException { if (!isOwnerByCreatedBy(sample.getCreatedBy())) { throw new NoAccessException(); } String sampleId = sample.getId().toString(); try { super.deleteAccessibility(access, sampleId); // fully load sample sample = this.findFullyLoadedSampleByName(sample.getName()); // keep POC public // remove characterization accessibility if (sample.getCharacterizationCollection() != null) { for (Characterization achar : sample.getCharacterizationCollection()) { accessUtils.removeAccessibility(access, achar, false); } } // remove composition accessibility if (sample.getSampleComposition() != null) { accessUtils.removeAccessibility(access, sample.getSampleComposition(), false); } } catch (NoAccessException e) { throw e; } catch (Exception e) { String err = "Error in deleting the access for sample " + sampleId; logger.error(err, e); throw new SampleException(err, e); } }
public List<String> removeAccesses(Sample sample, Boolean removeLater) throws SampleException, NoAccessException { List<String> ids = new ArrayList<String>(); try { if (!securityService.checkCreatePermission(sample.getId().toString())) { throw new NoAccessException(); } ids.add(sample.getId().toString()); // fully load sample Sample fullSample = this.findFullyLoadedSampleByName(sample.getName()); // find sample accesses List<AccessibilityBean> sampleAccesses = super.findSampleAccesses(sample.getId().toString()); for (AccessibilityBean access : sampleAccesses) { if (fullSample.getCharacterizationCollection() != null) { for (Characterization achar : fullSample.getCharacterizationCollection()) { ids.addAll(accessUtils.removeAccessibility(access, achar, removeLater)); } } if (fullSample.getSampleComposition() != null) { ids.addAll( accessUtils.removeAccessibility( access, fullSample.getSampleComposition(), removeLater)); } } } catch (NoAccessException e) { throw e; } catch (Exception e) { String error = "Error in removing sample accesses"; throw new SampleException(error, e); } return ids; }
public void deleteSample(String sampleName) throws SampleException, NoAccessException, NotExistException { if (user == null) { throw new NoAccessException(); } Sample sample = null; try { // / / fully load original sample sample = findFullyLoadedSampleByName(sampleName); CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider.getApplicationService(); // / / delete characterizations if (sample.getCharacterizationCollection() != null) { for (Characterization achar : sample.getCharacterizationCollection()) { charService.deleteCharacterization(achar); } } // / / delete composition if (sample.getSampleComposition() != null) { compService.deleteComposition(sample.getSampleComposition()); } sample.setSampleComposition(null); // / / remove publication associations if (sample.getPublicationCollection() != null) { sample.setPublicationCollection(null); } // / / remove keyword associations if (sample.getKeywordCollection() != null) { sample.setKeywordCollection(null); } appService.saveOrUpdate(sample); appService.delete(sample); } catch (NotExistException e) { throw e; } catch (Exception e) { String err = "Error in deleting the sample " + sampleName; logger.error(err, e); throw new SampleException(err, e); } }
public void assignAccessibility(AccessibilityBean access, Sample sample) throws SampleException, NoAccessException { if (!isOwnerByCreatedBy(sample.getCreatedBy())) { throw new NoAccessException(); } String sampleId = sample.getId().toString(); try { if (!isOwnerByCreatedBy(sample.getCreatedBy())) { throw new NoAccessException(); } // get existing accessibilities List<AccessibilityBean> groupAccesses = this.findGroupAccessibilities(sampleId); List<AccessibilityBean> userAccesses = this.findUserAccessibilities(sampleId); // if access is Public, remove all other access except Public // Curator and owner if (access.getGroupName().equals(AccessibilityBean.CSM_PUBLIC_GROUP)) { for (AccessibilityBean acc : groupAccesses) { // remove group accesses that are not public or curator if (!acc.getGroupName().equals(AccessibilityBean.CSM_PUBLIC_GROUP) && !acc.getGroupName().equals((AccessibilityBean.CSM_DATA_CURATOR))) { this.removeAccessibility(acc, sample); } } SecuredDataBean securedDataBean = new SecuredDataBean(); for (AccessibilityBean acc : userAccesses) { // remove accesses that are not owner if (!securedDataBean.retrieveUserIsOwner(acc.getUserBean(), sample.getCreatedBy())) { this.removeAccessibility(acc, sample); } } } // if sample is already public, retract from public else { if (groupAccesses.contains(AccessibilityBean.CSM_PUBLIC_ACCESS)) { this.removeAccessibility(AccessibilityBean.CSM_PUBLIC_ACCESS, sample); } } super.saveAccessibility(access, sampleId); // fully load sample sample = this.findFullyLoadedSampleByName(sample.getName()); // assign POC to public is handled when adding POC // TODO check this logic when working with COPPA on organization // assign characterization accessibility if (sample.getCharacterizationCollection() != null) { for (Characterization achar : sample.getCharacterizationCollection()) { accessUtils.assignAccessibility(access, achar); } } // assign composition accessibility if (sample.getSampleComposition() != null) { accessUtils.assignAccessibility(access, sample.getSampleComposition()); } } catch (NoAccessException e) { throw e; } catch (Exception e) { String err = "Error in assigning accessibility to the sample " + sampleId; logger.error(err, e); throw new SampleException(err, e); } }