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.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.*;
|
||||||
|
|
@ -32,6 +34,12 @@ import static org.scientificcms.publications.SciPublicationsConstants.*;
|
||||||
property = "uuid",
|
property = "uuid",
|
||||||
scope = VolumeInSeries.class
|
scope = VolumeInSeries.class
|
||||||
)
|
)
|
||||||
|
@NamedQueries({
|
||||||
|
@NamedQuery(
|
||||||
|
name = "VolumeInSeries",
|
||||||
|
query = "SELECT v FROM VolumeInSeries v WHERE v.uuid = :uuid"
|
||||||
|
)
|
||||||
|
})
|
||||||
public class VolumeInSeries implements Exportable, Serializable {
|
public class VolumeInSeries implements Exportable, Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
@ -23,7 +24,6 @@ import javax.enterprise.context.RequestScoped;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.NoResultException;
|
import javax.persistence.NoResultException;
|
||||||
import javax.transaction.Transactional;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
@ -64,11 +64,44 @@ public class VolumeInSeriesImExporter
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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) {
|
protected void saveImportedEntity(final VolumeInSeries entity) {
|
||||||
entityManager.merge(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
|
@Override
|
||||||
protected VolumeInSeries reloadEntity(final VolumeInSeries entity) {
|
protected VolumeInSeries reloadEntity(final VolumeInSeries entity) {
|
||||||
try {
|
try {
|
||||||
|
|
@ -76,7 +109,7 @@ public class VolumeInSeriesImExporter
|
||||||
VolumeInSeries.class,
|
VolumeInSeries.class,
|
||||||
entity.getVolumeId()
|
entity.getVolumeId()
|
||||||
);
|
);
|
||||||
} catch(NoResultException ex) {
|
} catch (NoResultException ex) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
String.format(
|
String.format(
|
||||||
"The VolumeInSeries entity %s was not found in "
|
"The VolumeInSeries entity %s was not found in "
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue