Updated ImExporters for SciDepartment to implement new interfaces
parent
0487a8d9b1
commit
764689066a
|
|
@ -17,6 +17,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.contenttypes.scidepartment.SciDepartmentConstants.DB_SCHEMA;
|
||||
|
|
@ -25,9 +27,15 @@ import static org.scientificcms.contenttypes.scidepartment.SciDepartmentConstant
|
|||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@Entity(name = "DepartmentContact")
|
||||
@Entity(name = "SciDepartmentContact")
|
||||
@Audited
|
||||
@Table(name = "DEPARTMENT_CONTACTS", schema = DB_SCHEMA)
|
||||
@NamedQueries({
|
||||
@NamedQuery(
|
||||
name = "SciDepartmentContact.findByUuid",
|
||||
query = "SELECT c FROM SciDepartmentContact c WHERE c.uuid = :uuid"
|
||||
)
|
||||
})
|
||||
public class Contact implements Exportable, Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
|
|
|||
|
|
@ -8,12 +8,12 @@ import org.librecms.assets.Organization;
|
|||
import org.librecms.assets.Person;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
/**
|
||||
* Exporter/Importer for {@link Contact} entities.
|
||||
|
|
@ -50,7 +50,11 @@ public class ContactImExporter
|
|||
}
|
||||
|
||||
@Override
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
protected Optional<Contact> findExistingEntity(final String uuid) {
|
||||
return contactRepo.findByUuid(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveImportedEntity(final Contact entity) {
|
||||
LOGGER.info(
|
||||
"Saving {}: {}",
|
||||
|
|
@ -74,4 +78,23 @@ public class ContactImExporter
|
|||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateExistingEntity(
|
||||
final Contact existingEntity,
|
||||
final Contact importedEntity
|
||||
) {
|
||||
if (!Objects.equals(
|
||||
existingEntity.getContactType(),
|
||||
importedEntity.getContactType()
|
||||
)) {
|
||||
existingEntity.setContactType(importedEntity.getContactType());
|
||||
}
|
||||
|
||||
if (existingEntity.getOrder() != importedEntity.getOrder()) {
|
||||
existingEntity.setOrder(importedEntity.getOrder());
|
||||
}
|
||||
|
||||
contactRepo.save(existingEntity);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,9 +2,12 @@ package org.scientificcms.contenttypes.scidepartment;
|
|||
|
||||
import org.libreccm.auditing.AbstractAuditedEntityRepository;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.persistence.NoResultException;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -46,4 +49,19 @@ public class ContactRepository
|
|||
contact.setUuid(UUID.randomUUID().toString());
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public Optional<Contact> findByUuid(final String uuid) {
|
||||
try {
|
||||
return Optional.of(
|
||||
getEntityManager()
|
||||
.createNamedQuery("SciDepartmentContact.findByUuid",
|
||||
Contact.class)
|
||||
.setParameter("uuid", uuid)
|
||||
.getSingleResult()
|
||||
);
|
||||
} catch (NoResultException ex) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,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.contenttypes.scidepartment.SciDepartmentConstants.DB_SCHEMA;
|
||||
|
|
@ -28,6 +30,12 @@ import static org.scientificcms.contenttypes.scidepartment.SciDepartmentConstant
|
|||
@Entity
|
||||
@Audited
|
||||
@Table(name = "DEPARTMENT_PROJECTS", schema = DB_SCHEMA)
|
||||
@NamedQueries({
|
||||
@NamedQuery(
|
||||
name = "DepartmentProject.findByUuid",
|
||||
query = "SELECT p FROM DepartmentProject p WHERE p.uuid = :uuid"
|
||||
)
|
||||
})
|
||||
public class DepartmentProject implements Exportable, Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
|
|
|||
|
|
@ -5,12 +5,12 @@ import org.libreccm.imexport.Processes;
|
|||
import org.scientificcms.contenttypes.sciproject.SciProject;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
/**
|
||||
* Importer/Exporter for {@link DepartmentProject} entities.
|
||||
|
|
@ -42,13 +42,27 @@ public class DepartmentProjectImExporter
|
|||
}
|
||||
|
||||
@Override
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
protected Optional<DepartmentProject> findExistingEntity(
|
||||
final String uuid
|
||||
) {
|
||||
return projectRepo.findByUuid(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveImportedEntity(
|
||||
final DepartmentProject departmentProject
|
||||
) {
|
||||
projectRepo.save(departmentProject);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateExistingEntity(
|
||||
final DepartmentProject existingEntity,
|
||||
final DepartmentProject importedEntity
|
||||
) {
|
||||
// Nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DepartmentProject reloadEntity(
|
||||
final DepartmentProject entity
|
||||
|
|
|
|||
|
|
@ -2,9 +2,12 @@ package org.scientificcms.contenttypes.scidepartment;
|
|||
|
||||
import org.libreccm.auditing.AbstractAuditedEntityRepository;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.persistence.NoResultException;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -46,4 +49,21 @@ public class DepartmentProjectRepository
|
|||
project.setUuid(UUID.randomUUID().toString());
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public Optional<DepartmentProject> findByUuid(final String uuid) {
|
||||
try {
|
||||
return Optional.of(
|
||||
getEntityManager()
|
||||
.createNamedQuery(
|
||||
"DepartmentProject.findByUuid",
|
||||
DepartmentProject.class
|
||||
)
|
||||
.setParameter("uuid", uuid)
|
||||
.getSingleResult()
|
||||
);
|
||||
} catch (NoResultException ex) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,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.contenttypes.scidepartment.SciDepartmentConstants.DB_SCHEMA;
|
||||
|
|
@ -29,7 +31,7 @@ import static org.scientificcms.contenttypes.scidepartment.SciDepartmentConstant
|
|||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@Entity(name = "DepartmentMembership")
|
||||
@Entity(name = "SciDepartmentMembership")
|
||||
@Audited
|
||||
@Table(name = "DEPARTMENT_MEMBERSHIPS", schema = DB_SCHEMA)
|
||||
@JsonIdentityInfo(
|
||||
|
|
@ -37,6 +39,12 @@ import static org.scientificcms.contenttypes.scidepartment.SciDepartmentConstant
|
|||
property = "uuid",
|
||||
scope = Membership.class
|
||||
)
|
||||
@NamedQueries({
|
||||
@NamedQuery(
|
||||
name = "SciDepartmentMembership.findByUuid",
|
||||
query = "SELECT m FROM SciDepartmentMembership m WHERE m.uuid = :uuid"
|
||||
)
|
||||
})
|
||||
public class Membership implements Exportable, Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
|
|
|||
|
|
@ -5,12 +5,12 @@ import org.libreccm.imexport.Processes;
|
|||
import org.librecms.assets.Person;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
/**
|
||||
* Importer/Exporter for {@link Membership} entities.
|
||||
|
|
@ -42,11 +42,34 @@ public class MembershipImExporter
|
|||
}
|
||||
|
||||
@Override
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
protected Optional<Membership> findExistingEntity(final String uuid) {
|
||||
return membershipRepo.findByUuid(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveImportedEntity(final Membership entity) {
|
||||
membershipRepo.save(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateExistingEntity(
|
||||
final Membership existingEntity,
|
||||
final Membership importedEntity
|
||||
) {
|
||||
if (!Objects.equals(
|
||||
existingEntity.getRole(),
|
||||
importedEntity.getRole()
|
||||
)) {
|
||||
existingEntity.setRole(importedEntity.getRole());
|
||||
}
|
||||
|
||||
if (existingEntity.getStatus() != importedEntity.getStatus()) {
|
||||
existingEntity.setStatus(importedEntity.getStatus());
|
||||
}
|
||||
|
||||
membershipRepo.save(existingEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Membership reloadEntity(final Membership entity) {
|
||||
return membershipRepo
|
||||
|
|
|
|||
|
|
@ -2,9 +2,12 @@ package org.scientificcms.contenttypes.scidepartment;
|
|||
|
||||
import org.libreccm.auditing.AbstractAuditedEntityRepository;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.persistence.NoResultException;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -14,6 +17,8 @@ import javax.enterprise.context.RequestScoped;
|
|||
public class MembershipRepository
|
||||
extends AbstractAuditedEntityRepository<Long, Membership> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public Long getEntityId(final Membership membership) {
|
||||
return membership.getMembershipId();
|
||||
|
|
@ -44,4 +49,21 @@ public class MembershipRepository
|
|||
membership.setUuid(UUID.randomUUID().toString());
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public Optional<Membership> findByUuid(final String uuid) {
|
||||
try {
|
||||
return Optional.of(
|
||||
getEntityManager()
|
||||
.createNamedQuery(
|
||||
"SciProjectMembership.findByUuid",
|
||||
Membership.class
|
||||
)
|
||||
.setParameter("uuid", uuid)
|
||||
.getSingleResult()
|
||||
);
|
||||
} catch (NoResultException ex) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ package org.scientificcms.contenttypes.scidepartment;
|
|||
import org.libreccm.imexport.Processes;
|
||||
import org.librecms.contentsection.AbstractContentItemImExporter;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
|
||||
/**
|
||||
|
|
@ -19,10 +21,45 @@ public class SciDepartmentImExporter
|
|||
// Nothing
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Class<SciDepartment> getEntityClass() {
|
||||
return SciDepartment.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateExistingContentItem(
|
||||
final SciDepartment existingContentItem,
|
||||
final SciDepartment importedContentItem
|
||||
) {
|
||||
if (!Objects.equals(
|
||||
existingContentItem.getShortDescription(),
|
||||
importedContentItem.getShortDescription()
|
||||
)) {
|
||||
syncLocalizedStrings(
|
||||
importedContentItem.getShortDescription(),
|
||||
existingContentItem.getShortDescription()
|
||||
);
|
||||
}
|
||||
|
||||
if (!Objects.equals(
|
||||
existingContentItem.getDepartmentDescription(),
|
||||
importedContentItem.getDepartmentDescription()
|
||||
)) {
|
||||
syncLocalizedStrings(
|
||||
importedContentItem.getDepartmentDescription(),
|
||||
existingContentItem.getDepartmentDescription()
|
||||
);
|
||||
}
|
||||
|
||||
if (!Objects.equals(
|
||||
existingContentItem.getAddendum(),
|
||||
importedContentItem.getAddendum()
|
||||
)) {
|
||||
syncLocalizedStrings(
|
||||
importedContentItem.getAddendum(),
|
||||
existingContentItem.getAddendum()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue