Updated VolumeInSeriesImExporter to implement new interface
parent
d8b5483325
commit
05abf25373
|
|
@ -16,6 +16,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.*;
|
||||
|
|
@ -32,6 +34,12 @@ import static org.scientificcms.publications.SciPublicationsConstants.*;
|
|||
property = "uuid",
|
||||
scope = VolumeInSeries.class
|
||||
)
|
||||
@NamedQueries({
|
||||
@NamedQuery(
|
||||
name = "VolumeInSeries",
|
||||
query = "SELECT v FROM VolumeInSeries v WHERE v.uuid = :uuid"
|
||||
)
|
||||
})
|
||||
public class VolumeInSeries implements Exportable, Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -23,7 +24,6 @@ import javax.enterprise.context.RequestScoped;
|
|||
import javax.inject.Inject;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.NoResultException;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -64,19 +64,52 @@ public class VolumeInSeriesImExporter
|
|||
}
|
||||
|
||||
@Override
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
protected Optional<VolumeInSeries> findExistingEntity(final String uuid) {
|
||||
try {
|
||||
return Optional.of(
|
||||
entityManager
|
||||
.createNamedQuery(
|
||||
"VolumeInSeries.findByUuid",
|
||||
VolumeInSeries.class
|
||||
)
|
||||
.setParameter("uuid", uuid)
|
||||
.getSingleResult()
|
||||
);
|
||||
} catch (NoResultException ex) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveImportedEntity(final VolumeInSeries entity) {
|
||||
entityManager.merge(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateExistingEntity(
|
||||
final VolumeInSeries existingEntity,
|
||||
final VolumeInSeries importedEntity
|
||||
) {
|
||||
if (!Objects.equals(
|
||||
existingEntity.getVolumeOfSeries(),
|
||||
importedEntity.getVolumeOfSeries()
|
||||
)) {
|
||||
existingEntity.setVolumeOfSeries(
|
||||
importedEntity.getVolumeOfSeries()
|
||||
);
|
||||
}
|
||||
|
||||
entityManager.merge(existingEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected VolumeInSeries reloadEntity(final VolumeInSeries entity) {
|
||||
try {
|
||||
return entityManager.find(
|
||||
VolumeInSeries.class,
|
||||
VolumeInSeries.class,
|
||||
entity.getVolumeId()
|
||||
);
|
||||
} catch(NoResultException ex) {
|
||||
} catch (NoResultException ex) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format(
|
||||
"The VolumeInSeries entity %s was not found in "
|
||||
|
|
|
|||
Loading…
Reference in New Issue