Source:
private void saveSample(Sample sample) throws IOException { if (sample.getId() != Sample.UNSAVED_ID) { return; } log.debug("Saving sample " + sample.getAlias()); if (LimsUtils.isDetailedSample(sample)) { DetailedSample detailed = (DetailedSample) sample; if (hasUnsavedParent(detailed)) { if (detailed.getParent().getSampleClass() == null && detailed.getParent().getPreMigrationId() != null) { detailed.setParent((DetailedSample) serviceManager.getSampleDao().getByPreMigrationId(detailed.getParent().getPreMigrationId())); if (detailed.getParent() == null) { throw new IOException("No Sample found with pre-migration ID " + detailed.getParent().getPreMigrationId()); } } else { saveSample(((DetailedSample) sample).getParent()); } } } sample.inheritPermissions(sample.getProject()); valueTypeLookup.resolveAll(sample); Collection<SampleQC> qcs = new TreeSet<>(sample.getSampleQCs()); Collection<Note> notes = new HashSet<>(sample.getNotes()); if (LimsUtils.isDetailedSample(sample)) { DetailedSample detailed = (DetailedSample) sample; if (detailed.getSubproject() != null && detailed.getSubproject().getId() == null) { createSubproject(detailed.getSubproject(), detailed.getProject().getReferenceGenomeId()); } if (sample.getAlias() != null) { List<Sample> dupes = serviceManager.getSampleService().getByAlias(sample.getAlias()); if (!dupes.isEmpty()) { for (Sample dupe : dupes) { ((DetailedSample) dupe).setNonStandardAlias(true); serviceManager.getSampleService().update(dupe); } detailed.setNonStandardAlias(true); } } } if (replaceChangeLogs) { Collection<ChangeLog> changes = new ArrayList<>(sample.getChangeLog()); sample.setId(serviceManager.getSampleService().create(sample)); sessionFactory.getCurrentSession().flush(); saveSampleChangeLog(sample, changes); } else { sample.setId(serviceManager.getSampleService().create(sample)); } saveSampleQcs(sample, qcs); saveSampleNotes(sample, notes); log.debug("Saved sample " + sample.getAlias()); }

Target:
private void saveSample(Sample sample) throws IOException { if (sample.getId() != Sample.UNSAVED_ID) { return; } if (LimsUtils.isDetailedSample(sample)) { DetailedSample detailed = (DetailedSample) sample; if (hasUnsavedParent(detailed)) { if (detailed.getParent().getSampleClass() == null && detailed.getParent().getPreMigrationId() != null) { detailed.setParent((DetailedSample) serviceManager.getSampleDao().getByPreMigrationId(detailed.getParent().getPreMigrationId())); if (detailed.getParent() == null) { throw new IOException("No Sample found with pre-migration ID " + detailed.getParent().getPreMigrationId()); } } else { saveSample(((DetailedSample) sample).getParent()); } } } log.debug("Saving sample " + sample.getAlias()); sample.inheritPermissions(sample.getProject()); valueTypeLookup.resolveAll(sample); Collection<SampleQC> qcs = new TreeSet<>(sample.getSampleQCs()); Collection<Note> notes = new HashSet<>(sample.getNotes()); if (LimsUtils.isDetailedSample(sample)) { DetailedSample detailed = (DetailedSample) sample; if (detailed.getSubproject() != null && detailed.getSubproject().getId() == null) { createSubproject(detailed.getSubproject(), detailed.getProject()); } if (sample.getAlias() != null) { List<Sample> dupes = serviceManager.getSampleService().getByAlias(sample.getAlias()); if (!dupes.isEmpty()) { for (Sample dupe : dupes) { ((DetailedSample) dupe).setNonStandardAlias(true); serviceManager.getSampleService().update(dupe); } detailed.setNonStandardAlias(true); } } } if (replaceChangeLogs) { Collection<ChangeLog> changes = new ArrayList<>(sample.getChangeLog()); sample.setId(serviceManager.getSampleService().create(sample)); sessionFactory.getCurrentSession().flush(); saveSampleChangeLog(sample, changes); } else { sample.setId(serviceManager.getSampleService().create(sample)); } saveSampleQcs(sample, qcs); saveSampleNotes(sample, notes); log.debug("Saved sample " + sample.getAlias()); }