Importers/Exporters for relatation entities of SciDepartment
parent
5f5b310899
commit
261704fa47
|
|
@ -1,8 +1,6 @@
|
||||||
package org.scientificcms.contenttypes.scidepartment;
|
package org.scientificcms.contenttypes.scidepartment;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIdentityReference;
|
import com.fasterxml.jackson.annotation.JsonIdentityReference;
|
||||||
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
|
|
||||||
import org.hibernate.envers.Audited;
|
import org.hibernate.envers.Audited;
|
||||||
import org.libreccm.core.CcmObjects;
|
import org.libreccm.core.CcmObjects;
|
||||||
import org.libreccm.imexport.Exportable;
|
import org.libreccm.imexport.Exportable;
|
||||||
|
|
@ -30,10 +28,6 @@ import static org.scientificcms.contenttypes.scidepartment.SciDepartmentConstant
|
||||||
@Entity(name = "DepartmentContact")
|
@Entity(name = "DepartmentContact")
|
||||||
@Audited
|
@Audited
|
||||||
@Table(name = "DEPARTMENT_CONTACTS", schema = DB_SCHEMA)
|
@Table(name = "DEPARTMENT_CONTACTS", schema = DB_SCHEMA)
|
||||||
@JsonIdentityInfo(
|
|
||||||
generator = ObjectIdGenerators.PropertyGenerator.class,
|
|
||||||
property = "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;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,68 @@
|
||||||
|
package org.scientificcms.contenttypes.scidepartment;
|
||||||
|
|
||||||
|
import org.libreccm.imexport.AbstractEntityImExporter;
|
||||||
|
import org.libreccm.imexport.Processes;
|
||||||
|
import org.librecms.assets.Organization;
|
||||||
|
import org.librecms.assets.Person;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.NoResultException;
|
||||||
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exporter/Importer for {@link Contact} entities.
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
@RequestScoped
|
||||||
|
@Processes(Contact.class)
|
||||||
|
public class ContactImExporter
|
||||||
|
extends AbstractEntityImExporter<Contact> {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private ContactRepository contactRepo;
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
@Override
|
||||||
|
protected void init() {
|
||||||
|
addRequiredEntities(
|
||||||
|
Set.of(
|
||||||
|
SciDepartment.class,
|
||||||
|
Organization.class,
|
||||||
|
Person.class
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<Contact> getEntityClass() {
|
||||||
|
return Contact.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
protected void saveImportedEntity(final Contact entity) {
|
||||||
|
contactRepo.save(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Contact reloadEntity(final Contact entity) {
|
||||||
|
return contactRepo
|
||||||
|
.findById(entity.getContactId())
|
||||||
|
.orElseThrow(
|
||||||
|
() -> new IllegalArgumentException(
|
||||||
|
String.format(
|
||||||
|
"Contact entity %s was not found in the database.",
|
||||||
|
Objects.toString(entity)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,67 @@
|
||||||
|
package org.scientificcms.contenttypes.scidepartment;
|
||||||
|
|
||||||
|
import org.libreccm.imexport.AbstractEntityImExporter;
|
||||||
|
import org.libreccm.imexport.Processes;
|
||||||
|
import org.scientificcms.contenttypes.sciproject.SciProject;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Importer/Exporter for {@link DepartmentProject} entities.
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
@RequestScoped
|
||||||
|
@Processes(DepartmentProject.class)
|
||||||
|
public class DepartmentProjectImExporter
|
||||||
|
extends AbstractEntityImExporter<DepartmentProject> {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private DepartmentProjectRepository projectRepo;
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
@Override
|
||||||
|
protected void init() {
|
||||||
|
addRequiredEntities(
|
||||||
|
Set.of(
|
||||||
|
SciDepartment.class,
|
||||||
|
SciProject.class
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<DepartmentProject> getEntityClass() {
|
||||||
|
return DepartmentProject.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void saveImportedEntity(
|
||||||
|
final DepartmentProject departmentProject
|
||||||
|
) {
|
||||||
|
projectRepo.save(departmentProject);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected DepartmentProject reloadEntity(
|
||||||
|
final DepartmentProject entity
|
||||||
|
) {
|
||||||
|
return projectRepo
|
||||||
|
.findById(entity.getDepartmentProjectId())
|
||||||
|
.orElseThrow(
|
||||||
|
() -> new IllegalArgumentException(
|
||||||
|
String.format(
|
||||||
|
"The DepartmentProject entity %s was not found in "
|
||||||
|
+ "the database.",
|
||||||
|
Objects.toString(entity)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,60 @@
|
||||||
|
package org.scientificcms.contenttypes.scidepartment;
|
||||||
|
|
||||||
|
import org.libreccm.imexport.AbstractEntityImExporter;
|
||||||
|
import org.librecms.assets.Person;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Importer/Exporter for {@link Membership} entities.
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
public class MembershipImExporter
|
||||||
|
extends AbstractEntityImExporter<Membership> {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private MembershipRepository membershipRepo;
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
@Override
|
||||||
|
protected void init() {
|
||||||
|
addRequiredEntities(
|
||||||
|
Set.of(
|
||||||
|
SciDepartment.class,
|
||||||
|
Person.class
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<Membership> getEntityClass() {
|
||||||
|
return Membership.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
protected void saveImportedEntity(final Membership entity) {
|
||||||
|
membershipRepo.save(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Membership reloadEntity(final Membership entity) {
|
||||||
|
return membershipRepo
|
||||||
|
.findById(entity.getMembershipId())
|
||||||
|
.orElseThrow(
|
||||||
|
() -> new IllegalArgumentException(
|
||||||
|
String.format(
|
||||||
|
"Membership entity %s was not found in the database.",
|
||||||
|
Objects.toString(entity)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue