Updated AuthorshipImExporter to implement new interface
parent
b3070f8ff8
commit
d8b5483325
|
|
@ -22,6 +22,8 @@ import javax.persistence.GenerationType;
|
|||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.NamedQueries;
|
||||
import javax.persistence.NamedQuery;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import static org.scientificcms.publications.SciPublicationsConstants.*;
|
||||
|
|
@ -38,7 +40,13 @@ import static org.scientificcms.publications.SciPublicationsConstants.*;
|
|||
property = "uuid",
|
||||
scope = Authorship.class
|
||||
)
|
||||
public class Authorship
|
||||
@NamedQueries({
|
||||
@NamedQuery(
|
||||
name = "Authorhship.findByUuid",
|
||||
query = "SELECT a FROM Authorship a WHERE a.uuid = :uuid"
|
||||
)
|
||||
})
|
||||
public class Authorship
|
||||
implements Exportable, Serializable, Comparable<Authorship> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
|
@ -171,7 +179,7 @@ public class Authorship
|
|||
return String.format("%s{ "
|
||||
+ "authorshipId = %d, "
|
||||
+ "uuid = %s, "
|
||||
+ "author = %s "
|
||||
+ "author = %s "
|
||||
+ "editor = %b, "
|
||||
+ "authorOrder = %d%s "
|
||||
+ "}",
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import org.scientificcms.publications.contenttypes.TalkItem;
|
|||
import org.scientificcms.publications.contenttypes.WorkingPaperItem;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
|
@ -64,19 +65,48 @@ public class AuthorshipImExporter
|
|||
}
|
||||
|
||||
@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) {
|
||||
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
|
||||
protected Authorship reloadEntity(final Authorship entity) {
|
||||
try {
|
||||
return entityManager.find(
|
||||
Authorship.class,
|
||||
Authorship.class,
|
||||
entity.getAuthorshipId()
|
||||
);
|
||||
} catch(NoResultException ex) {
|
||||
} catch (NoResultException ex) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format(
|
||||
"The Authorship entity %s was not found in the database.",
|
||||
|
|
|
|||
Loading…
Reference in New Issue