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.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.contenttypes.scidepartment.SciDepartmentConstants.DB_SCHEMA;
|
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>
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
*/
|
*/
|
||||||
@Entity(name = "DepartmentContact")
|
@Entity(name = "SciDepartmentContact")
|
||||||
@Audited
|
@Audited
|
||||||
@Table(name = "DEPARTMENT_CONTACTS", schema = DB_SCHEMA)
|
@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 {
|
public class Contact implements Exportable, Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
|
||||||
|
|
@ -8,12 +8,12 @@ import org.librecms.assets.Organization;
|
||||||
import org.librecms.assets.Person;
|
import org.librecms.assets.Person;
|
||||||
|
|
||||||
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;
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.transaction.Transactional;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exporter/Importer for {@link Contact} entities.
|
* Exporter/Importer for {@link Contact} entities.
|
||||||
|
|
@ -50,7 +50,11 @@ public class ContactImExporter
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
protected Optional<Contact> findExistingEntity(final String uuid) {
|
||||||
|
return contactRepo.findByUuid(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void saveImportedEntity(final Contact entity) {
|
protected void saveImportedEntity(final Contact entity) {
|
||||||
LOGGER.info(
|
LOGGER.info(
|
||||||
"Saving {}: {}",
|
"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 org.libreccm.auditing.AbstractAuditedEntityRepository;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
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());
|
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.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.contenttypes.scidepartment.SciDepartmentConstants.DB_SCHEMA;
|
import static org.scientificcms.contenttypes.scidepartment.SciDepartmentConstants.DB_SCHEMA;
|
||||||
|
|
@ -28,6 +30,12 @@ import static org.scientificcms.contenttypes.scidepartment.SciDepartmentConstant
|
||||||
@Entity
|
@Entity
|
||||||
@Audited
|
@Audited
|
||||||
@Table(name = "DEPARTMENT_PROJECTS", schema = DB_SCHEMA)
|
@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 {
|
public class DepartmentProject implements Exportable, Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,12 @@ import org.libreccm.imexport.Processes;
|
||||||
import org.scientificcms.contenttypes.sciproject.SciProject;
|
import org.scientificcms.contenttypes.sciproject.SciProject;
|
||||||
|
|
||||||
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;
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.transaction.Transactional;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Importer/Exporter for {@link DepartmentProject} entities.
|
* Importer/Exporter for {@link DepartmentProject} entities.
|
||||||
|
|
@ -42,13 +42,27 @@ public class DepartmentProjectImExporter
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
protected Optional<DepartmentProject> findExistingEntity(
|
||||||
|
final String uuid
|
||||||
|
) {
|
||||||
|
return projectRepo.findByUuid(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void saveImportedEntity(
|
protected void saveImportedEntity(
|
||||||
final DepartmentProject departmentProject
|
final DepartmentProject departmentProject
|
||||||
) {
|
) {
|
||||||
projectRepo.save(departmentProject);
|
projectRepo.save(departmentProject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void updateExistingEntity(
|
||||||
|
final DepartmentProject existingEntity,
|
||||||
|
final DepartmentProject importedEntity
|
||||||
|
) {
|
||||||
|
// Nothing
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected DepartmentProject reloadEntity(
|
protected DepartmentProject reloadEntity(
|
||||||
final DepartmentProject entity
|
final DepartmentProject entity
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,12 @@ package org.scientificcms.contenttypes.scidepartment;
|
||||||
|
|
||||||
import org.libreccm.auditing.AbstractAuditedEntityRepository;
|
import org.libreccm.auditing.AbstractAuditedEntityRepository;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
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());
|
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.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.contenttypes.scidepartment.SciDepartmentConstants.DB_SCHEMA;
|
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>
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
*/
|
*/
|
||||||
@Entity(name = "DepartmentMembership")
|
@Entity(name = "SciDepartmentMembership")
|
||||||
@Audited
|
@Audited
|
||||||
@Table(name = "DEPARTMENT_MEMBERSHIPS", schema = DB_SCHEMA)
|
@Table(name = "DEPARTMENT_MEMBERSHIPS", schema = DB_SCHEMA)
|
||||||
@JsonIdentityInfo(
|
@JsonIdentityInfo(
|
||||||
|
|
@ -37,6 +39,12 @@ import static org.scientificcms.contenttypes.scidepartment.SciDepartmentConstant
|
||||||
property = "uuid",
|
property = "uuid",
|
||||||
scope = Membership.class
|
scope = Membership.class
|
||||||
)
|
)
|
||||||
|
@NamedQueries({
|
||||||
|
@NamedQuery(
|
||||||
|
name = "SciDepartmentMembership.findByUuid",
|
||||||
|
query = "SELECT m FROM SciDepartmentMembership m WHERE m.uuid = :uuid"
|
||||||
|
)
|
||||||
|
})
|
||||||
public class Membership implements Exportable, Serializable {
|
public class Membership implements Exportable, Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,12 @@ import org.libreccm.imexport.Processes;
|
||||||
import org.librecms.assets.Person;
|
import org.librecms.assets.Person;
|
||||||
|
|
||||||
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;
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.transaction.Transactional;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Importer/Exporter for {@link Membership} entities.
|
* Importer/Exporter for {@link Membership} entities.
|
||||||
|
|
@ -42,11 +42,34 @@ public class MembershipImExporter
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
protected Optional<Membership> findExistingEntity(final String uuid) {
|
||||||
|
return membershipRepo.findByUuid(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void saveImportedEntity(final Membership entity) {
|
protected void saveImportedEntity(final Membership entity) {
|
||||||
membershipRepo.save(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
|
@Override
|
||||||
protected Membership reloadEntity(final Membership entity) {
|
protected Membership reloadEntity(final Membership entity) {
|
||||||
return membershipRepo
|
return membershipRepo
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,12 @@ package org.scientificcms.contenttypes.scidepartment;
|
||||||
|
|
||||||
import org.libreccm.auditing.AbstractAuditedEntityRepository;
|
import org.libreccm.auditing.AbstractAuditedEntityRepository;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
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
|
public class MembershipRepository
|
||||||
extends AbstractAuditedEntityRepository<Long, Membership> {
|
extends AbstractAuditedEntityRepository<Long, Membership> {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long getEntityId(final Membership membership) {
|
public Long getEntityId(final Membership membership) {
|
||||||
return membership.getMembershipId();
|
return membership.getMembershipId();
|
||||||
|
|
@ -44,4 +49,21 @@ public class MembershipRepository
|
||||||
membership.setUuid(UUID.randomUUID().toString());
|
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.libreccm.imexport.Processes;
|
||||||
import org.librecms.contentsection.AbstractContentItemImExporter;
|
import org.librecms.contentsection.AbstractContentItemImExporter;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -19,10 +21,45 @@ public class SciDepartmentImExporter
|
||||||
// Nothing
|
// Nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<SciDepartment> getEntityClass() {
|
public Class<SciDepartment> getEntityClass() {
|
||||||
return SciDepartment.class;
|
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