diff --git a/sci-publications/src/main/java/org/scientificcms/publications/AbstractPublicationImExporter.java b/sci-publications/src/main/java/org/scientificcms/publications/AbstractPublicationImExporter.java index a275b12..ee11ed6 100644 --- a/sci-publications/src/main/java/org/scientificcms/publications/AbstractPublicationImExporter.java +++ b/sci-publications/src/main/java/org/scientificcms/publications/AbstractPublicationImExporter.java @@ -2,6 +2,8 @@ package org.scientificcms.publications; import org.libreccm.imexport.AbstractEntityImExporter; +import java.util.Objects; + import javax.inject.Inject; /** @@ -14,12 +16,122 @@ public abstract class AbstractPublicationImExporter @Inject private PublicationRepository publicationRepo; - + @Override protected void saveImportedEntity(final Publication publication) { publicationRepo.save(publication); } + @Override + protected final void updateExistingEntity( + final T existingEntity, + final T importedEntity + ) { + if (!Objects.equals( + existingEntity.getYearOfPublication(), + importedEntity.getYearOfPublication() + )) { + existingEntity.setYearOfPublication( + importedEntity.getYearOfPublication() + ); + } + + if (!Objects.equals( + existingEntity.getTitle(), + importedEntity.getTitle() + )) { + syncLocalizedStrings( + importedEntity.getTitle(), + existingEntity.getTitle() + ); + } + + if (!Objects.equals( + existingEntity.getShortDescription(), + importedEntity.getShortDescription() + )) { + syncLocalizedStrings( + importedEntity.getShortDescription(), + existingEntity.getShortDescription() + ); + } + + if (!Objects.equals( + existingEntity.getPublicationAbstract(), + importedEntity.getPublicationAbstract() + )) { + syncLocalizedStrings( + importedEntity.getPublicationAbstract(), + existingEntity.getPublicationAbstract() + ); + } + + if (!Objects.equals( + existingEntity.getMisc(), + importedEntity.getMisc() + )) { + syncLocalizedStrings( + importedEntity.getMisc(), + existingEntity.getMisc() + ); + } + + if (!Objects.equals( + existingEntity.getPeerReviewed(), + importedEntity.getPeerReviewed() + )) { + existingEntity.setPeerReviewed(importedEntity.getPeerReviewed()); + } + + if (!Objects.equals( + existingEntity.getYearFirstPublished(), + importedEntity.getYearFirstPublished() + )) { + existingEntity.setYearFirstPublished( + importedEntity.getYearFirstPublished() + ); + } + + if (!Objects.equals( + existingEntity.getLanguageOfPublication(), + importedEntity.getLanguageOfPublication() + )) { + existingEntity.setLanguageOfPublication( + importedEntity.getLanguageOfPublication() + ); + } + + updateExistingPublication(existingEntity, importedEntity); + + publicationRepo.save(existingEntity); + } + + /** + * Update the special properties of a publication type using the values from + * the imported entity. + * + * Implementations should only update relevant properties. For assocations + * only not existing values should be added, but no values should be removed + * from the existing enitity. + * + * For other properties, implementation MUST check if an update is + * neccessary but comparing the the values of the property, and only update + * the property of the existing publication if the values are different. + * + * Implementations MUST not save the updated existing entity. The calling + * method + * {@link AbstractPublicationImExporter#updateExistingEntity(org.scientificcms.publications.Publication, org.scientificcms.publications.Publication)} + * takes care of saving the updated existing publication. + * + * @param existingPublication The existing publication to update. + * @param withImportedPublication The imported publication with the updated + * values. + */ + protected abstract void updateExistingPublication( + final T existingPublication, + final T withImportedPublication + ); + @Override protected T reloadEntity(final T publication) { return publicationRepo