Some fixes
parent
0c85d4e704
commit
0487a8d9b1
|
|
@ -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.sciproject.SciProjectConstants.*;
|
||||
|
|
@ -29,9 +31,15 @@ import static org.scientificcms.contenttypes.sciproject.SciProjectConstants.*;
|
|||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@Entity(name = "ProjectContact")
|
||||
@Entity(name = "SciProjectContact")
|
||||
@Audited
|
||||
@Table(name = "PROJECT_CONTACTS", schema = DB_SCHEMA)
|
||||
@NamedQueries({
|
||||
@NamedQuery(
|
||||
name = "SciProjectContact.findByUuid",
|
||||
query = "SELECT c FROM SciProjectContact c WHERE c.uuid = :uuid"
|
||||
)
|
||||
})
|
||||
public class Contact implements Exportable, Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
|
|
|||
|
|
@ -9,12 +9,12 @@ import org.librecms.assets.Person;
|
|||
import org.librecms.contentsection.ContentItemRepository;
|
||||
|
||||
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 Contact} entities.
|
||||
|
|
@ -25,14 +25,14 @@ import javax.transaction.Transactional;
|
|||
@Processes(Contact.class)
|
||||
public class ContactImExporter
|
||||
extends AbstractEntityImExporter<Contact> {
|
||||
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(
|
||||
ContactImExporter.class
|
||||
);
|
||||
|
||||
@Inject
|
||||
private ContactRepository contactRepo;
|
||||
|
||||
|
||||
@Inject
|
||||
private ContentItemRepository itemRepo;
|
||||
|
||||
|
|
@ -54,10 +54,34 @@ 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) {
|
||||
contactRepo.save(entity);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Contact reloadEntity(final Contact entity) {
|
||||
|
|
|
|||
|
|
@ -2,9 +2,12 @@ package org.scientificcms.contenttypes.sciproject;
|
|||
|
||||
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;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -45,5 +48,19 @@ public class ContactRepository
|
|||
public void initNewEntity(final Contact contact) {
|
||||
contact.setUuid(UUID.randomUUID().toString());
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public Optional<Contact> findByUuid(final String uuid) {
|
||||
try {
|
||||
return Optional.of(
|
||||
getEntityManager()
|
||||
.createNamedQuery("SciProjectContact.findByUuid", Contact.class)
|
||||
.setParameter("uuid", uuid)
|
||||
.getSingleResult()
|
||||
);
|
||||
} catch(NoResultException ex) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,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.sciproject.SciProjectConstants.*;
|
||||
|
|
@ -28,7 +30,7 @@ import static org.scientificcms.contenttypes.sciproject.SciProjectConstants.*;
|
|||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@Entity(name = "PROJECT_MEMBERSHIP")
|
||||
@Entity(name = "SciProjectMembership")
|
||||
@Audited
|
||||
@Table(name = "PROJECT_MEMBERSHIPS", schema = DB_SCHEMA)
|
||||
@JsonIdentityInfo(
|
||||
|
|
@ -36,6 +38,12 @@ import static org.scientificcms.contenttypes.sciproject.SciProjectConstants.*;
|
|||
property = "uuid",
|
||||
scope = Membership.class
|
||||
)
|
||||
@NamedQueries({
|
||||
@NamedQuery(
|
||||
name = "SciProjectMembership.findByUuid",
|
||||
query = "SELECT m FROM SciProjectMembership m WHERE m.uuid = :uuid"
|
||||
)
|
||||
})
|
||||
public class Membership implements Exportable, Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
|
|
|||
|
|
@ -6,12 +6,12 @@ import org.librecms.assets.Person;
|
|||
import org.librecms.contentsection.ContentItemRepository;
|
||||
|
||||
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.
|
||||
|
|
@ -25,7 +25,7 @@ public class MembershipImExporter
|
|||
|
||||
@Inject
|
||||
private ContentItemRepository itemRepo;
|
||||
|
||||
|
||||
@Inject
|
||||
private MembershipRepository membershipRepo;
|
||||
|
||||
|
|
@ -46,11 +46,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,7 +2,12 @@ package org.scientificcms.contenttypes.sciproject;
|
|||
|
||||
import org.libreccm.auditing.AbstractAuditedEntityRepository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.ejb.TransactionAttribute;
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.persistence.NoResultException;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -39,4 +44,21 @@ public class MembershipRepository
|
|||
return membership.getMembershipId() == 0;
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ package org.scientificcms.contenttypes.sciproject;
|
|||
import org.libreccm.imexport.Processes;
|
||||
import org.librecms.contentsection.AbstractContentItemImExporter;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
|
||||
/**
|
||||
|
|
@ -16,16 +18,77 @@ import javax.enterprise.context.RequestScoped;
|
|||
*/
|
||||
@RequestScoped
|
||||
@Processes(SciProject.class)
|
||||
public class SciProjectImExporter extends AbstractContentItemImExporter<SciProject>{
|
||||
public class SciProjectImExporter
|
||||
extends AbstractContentItemImExporter<SciProject> {
|
||||
|
||||
@Override
|
||||
protected void initContentItemImExporter() {
|
||||
// Nothing
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Class<SciProject> getEntityClass() {
|
||||
return SciProject.class;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void updateExistingContentItem(
|
||||
final SciProject existingContentItem,
|
||||
final SciProject importedContentItem
|
||||
) {
|
||||
if (!Objects.equals(
|
||||
existingContentItem.getBegin(),
|
||||
importedContentItem.getBegin()
|
||||
)) {
|
||||
existingContentItem.setBegin(importedContentItem.getBegin());
|
||||
}
|
||||
|
||||
if (!Objects.equals(
|
||||
existingContentItem.getEnd(),
|
||||
importedContentItem.getEnd()
|
||||
)) {
|
||||
existingContentItem.setEnd(importedContentItem.getEnd());
|
||||
}
|
||||
|
||||
if (!Objects.equals(
|
||||
existingContentItem.getShortDescription(),
|
||||
importedContentItem.getShortDescription()
|
||||
)) {
|
||||
syncLocalizedStrings(
|
||||
importedContentItem.getShortDescription(),
|
||||
existingContentItem.getShortDescription()
|
||||
);
|
||||
}
|
||||
|
||||
if (!Objects.equals(
|
||||
existingContentItem.getDescription(),
|
||||
importedContentItem.getDescription()
|
||||
)) {
|
||||
syncLocalizedStrings(
|
||||
importedContentItem.getDescription(),
|
||||
existingContentItem.getDescription()
|
||||
);
|
||||
}
|
||||
|
||||
if (!Objects.equals(
|
||||
existingContentItem.getFunding(),
|
||||
importedContentItem.getFunding()
|
||||
)) {
|
||||
syncLocalizedStrings(
|
||||
importedContentItem.getFunding(),
|
||||
existingContentItem.getFunding()
|
||||
);
|
||||
}
|
||||
|
||||
if (!Objects.equals(
|
||||
existingContentItem.getFundingVolume(),
|
||||
importedContentItem.getFundingVolume()
|
||||
)) {
|
||||
syncLocalizedStrings(
|
||||
importedContentItem.getFundingVolume(),
|
||||
existingContentItem.getFundingVolume()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.contenttypes.sciproject.SciProjectConstants.*;
|
||||
|
|
@ -27,6 +29,12 @@ import static org.scientificcms.contenttypes.sciproject.SciProjectConstants.*;
|
|||
@Entity
|
||||
@Audited
|
||||
@Table(name = "SPONSORING", schema = DB_SCHEMA)
|
||||
@NamedQueries({
|
||||
@NamedQuery(
|
||||
name = "Sponsoring.findByUuid",
|
||||
query = "SELECT s FROM Sponsoring s WHERE s.uuid = :uuid"
|
||||
)
|
||||
})
|
||||
public class Sponsoring implements Exportable, Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
|
|
|||
|
|
@ -5,12 +5,12 @@ import org.libreccm.imexport.Processes;
|
|||
import org.librecms.assets.Organization;
|
||||
|
||||
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.
|
||||
|
|
@ -40,12 +40,33 @@ public class SponsoringImExporter
|
|||
public Class<Sponsoring> getEntityClass() {
|
||||
return Sponsoring.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<Sponsoring> findExistingEntity(final String uuid) {
|
||||
return sponsoringRepo.findByUuid(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
protected void saveImportedEntity(final Sponsoring entity) {
|
||||
sponsoringRepo.save(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateExistingEntity(
|
||||
final Sponsoring existingEntity,
|
||||
final Sponsoring importedEntity
|
||||
) {
|
||||
if (!Objects.equals(
|
||||
existingEntity.getFundingCode(),
|
||||
importedEntity.getFundingCode()
|
||||
)) {
|
||||
existingEntity.setFundingCode(importedEntity.getFundingCode());
|
||||
}
|
||||
|
||||
if (existingEntity.getOrder() != importedEntity.getOrder()) {
|
||||
existingEntity.setOrder(importedEntity.getOrder());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Sponsoring reloadEntity(final Sponsoring entity) {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,11 @@ package org.scientificcms.contenttypes.sciproject;
|
|||
|
||||
import org.libreccm.auditing.AbstractAuditedEntityRepository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.persistence.NoResultException;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -36,8 +40,22 @@ public class SponsoringRepository
|
|||
|
||||
@Override
|
||||
public boolean isNew(final Sponsoring sponsoring) {
|
||||
return sponsoring.getSponsoringId() == 0
|
||||
|| sponsoring.getUuid() == null;
|
||||
return sponsoring.getSponsoringId() == 0
|
||||
|| sponsoring.getUuid() == null;
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public Optional<Sponsoring> findByUuid(final String uuid) {
|
||||
try {
|
||||
return Optional.of(
|
||||
getEntityManager()
|
||||
.createNamedQuery("Sponsoring.findByUuid", Sponsoring.class)
|
||||
.setParameter("uuid", uuid)
|
||||
.getSingleResult()
|
||||
);
|
||||
} catch (NoResultException ex) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue