Updated AuthorshipImExporter to implement new interface

master
Jens Pelzetter 2023-01-22 09:33:17 +01:00
parent b3070f8ff8
commit d8b5483325
2 changed files with 43 additions and 5 deletions

View File

@ -22,6 +22,8 @@ import javax.persistence.GenerationType;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table; import javax.persistence.Table;
import static org.scientificcms.publications.SciPublicationsConstants.*; import static org.scientificcms.publications.SciPublicationsConstants.*;
@ -38,6 +40,12 @@ import static org.scientificcms.publications.SciPublicationsConstants.*;
property = "uuid", property = "uuid",
scope = Authorship.class scope = Authorship.class
) )
@NamedQueries({
@NamedQuery(
name = "Authorhship.findByUuid",
query = "SELECT a FROM Authorship a WHERE a.uuid = :uuid"
)
})
public class Authorship public class Authorship
implements Exportable, Serializable, Comparable<Authorship> { implements Exportable, Serializable, Comparable<Authorship> {

View File

@ -16,6 +16,7 @@ import org.scientificcms.publications.contenttypes.TalkItem;
import org.scientificcms.publications.contenttypes.WorkingPaperItem; import org.scientificcms.publications.contenttypes.WorkingPaperItem;
import java.util.Objects; import java.util.Objects;
import java.util.Optional;
import java.util.Set; import java.util.Set;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
@ -64,11 +65,40 @@ public class AuthorshipImExporter
} }
@Override @Override
@Transactional(Transactional.TxType.REQUIRED) protected Optional<Authorship> findExistingEntity(final String uuid) {
try {
return Optional.of(
entityManager
.createNamedQuery("Authorhship.findByUuid", Authorship.class)
.setParameter("uuid", uuid)
.getSingleResult()
);
} catch (NoResultException ex) {
return Optional.empty();
}
}
@Override
protected void saveImportedEntity(final Authorship entity) { protected void saveImportedEntity(final Authorship entity) {
entityManager.merge(entity); entityManager.merge(entity);
} }
@Override
protected void updateExistingEntity(
final Authorship existingEntity,
final Authorship importedEntity
) {
if (existingEntity.isEditor() != importedEntity.isEditor()) {
existingEntity.setEditor(importedEntity.isEditor());
}
if (existingEntity.getAuthorOrder() != importedEntity.getAuthorOrder()) {
existingEntity.setAuthorOrder(importedEntity.getAuthorOrder());
}
entityManager.merge(existingEntity);
}
@Override @Override
protected Authorship reloadEntity(final Authorship entity) { protected Authorship reloadEntity(final Authorship entity) {
try { try {
@ -76,7 +106,7 @@ public class AuthorshipImExporter
Authorship.class, Authorship.class,
entity.getAuthorshipId() entity.getAuthorshipId()
); );
} catch(NoResultException ex) { } catch (NoResultException ex) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
String.format( String.format(
"The Authorship entity %s was not found in the database.", "The Authorship entity %s was not found in the database.",