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 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); } }