private MaterialRevision filterUnsaved(MaterialRevision materialRevision) { ArrayList<Modification> unsavedModifications = new ArrayList<>(); for (Modification modification : materialRevision.getModifications()) { if (!modification.hasId()) { unsavedModifications.add(modification); } } return new MaterialRevision(materialRevision.getMaterial(), unsavedModifications); }
public MaterialRevision addRevisionsWithModifications( Material material, Modification... modifications) { final MaterialRevision revision = filterUnsaved(new MaterialRevision(material, modifications)); if (revision.getModifications().isEmpty()) { return revision; } transactionTemplate.execute( new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) { materialRepository.saveMaterialRevision(revision); } }); return revision; }