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.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> {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue