Updated AbstractPublicationImExporter to support new interface.

master
Jens Pelzetter 2023-01-22 09:28:08 +01:00
parent 90210b5fdc
commit b3070f8ff8
1 changed files with 113 additions and 1 deletions

View File

@ -2,6 +2,8 @@ package org.scientificcms.publications;
import org.libreccm.imexport.AbstractEntityImExporter; import org.libreccm.imexport.AbstractEntityImExporter;
import java.util.Objects;
import javax.inject.Inject; import javax.inject.Inject;
/** /**
@ -20,6 +22,116 @@ public abstract class AbstractPublicationImExporter<T extends Publication>
publicationRepo.save(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 @Override
protected T reloadEntity(final T publication) { protected T reloadEntity(final T publication) {
return publicationRepo return publicationRepo