Added a reload method to the interface of the AbstractImExporter class
Former-commit-id: 6fd4e177cf
pull/7/head
parent
1ddff7a54a
commit
e1137ae2e9
|
|
@ -10,6 +10,7 @@ import org.libreccm.imexport.AbstractEntityImExporter;
|
|||
import org.libreccm.imexport.Exportable;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
|
@ -20,26 +21,41 @@ import javax.transaction.Transactional;
|
|||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
* @param <T>
|
||||
*/
|
||||
public abstract class AbstractContentItemImExporter<T extends ContentItem>
|
||||
public abstract class AbstractContentItemImExporter<T extends ContentItem>
|
||||
extends AbstractEntityImExporter<T> {
|
||||
|
||||
|
||||
@Inject
|
||||
private ContentItemRepository itemRepository;
|
||||
|
||||
private ContentItemRepository itemRepository;
|
||||
|
||||
@Override
|
||||
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
||||
|
||||
|
||||
final Set<Class<? extends Exportable>> entities = new HashSet<>();
|
||||
entities.add(Category.class);
|
||||
entities.add(ContentSection.class);
|
||||
|
||||
|
||||
return entities;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public void saveImportedEntity(final T entity) {
|
||||
itemRepository.save(entity);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected T reloadEntity(final T entity) {
|
||||
return itemRepository
|
||||
.findById(
|
||||
Objects.requireNonNull(entity).getObjectId(), getEntityClass()
|
||||
).orElseThrow(
|
||||
() -> new IllegalArgumentException(
|
||||
String.format(
|
||||
"ContentItem entity %s not found in database.",
|
||||
Objects.toString(entity)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import org.libreccm.imexport.Exportable;
|
|||
import org.libreccm.imexport.Processes;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
|
|
@ -44,4 +45,18 @@ public class ContentSectionImExporter
|
|||
sectionRepository.save(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ContentSection reloadEntity(final ContentSection entity) {
|
||||
return sectionRepository
|
||||
.findById(Objects.requireNonNull(entity).getObjectId())
|
||||
.orElseThrow(
|
||||
() -> new IllegalArgumentException(
|
||||
String.format(
|
||||
"ContentSection entity %s not found in database.",
|
||||
Objects.toString(entity)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,6 +54,11 @@ import javax.persistence.Table;
|
|||
@Entity
|
||||
@Table(name = "CATEGORIZATIONS", schema = DB_SCHEMA)
|
||||
@NamedQueries({
|
||||
@NamedQuery(
|
||||
name = "Categorization.findById",
|
||||
query
|
||||
= "SELECT c FROM Categorization c WHERE c.categorizationId = :categorizationId"
|
||||
),
|
||||
@NamedQuery(
|
||||
name = "Categorization.findByUuid",
|
||||
query = "SELECT c FROM Categorization c WHERE c.uuid = :uuid"
|
||||
|
|
@ -62,36 +67,31 @@ import javax.persistence.Table;
|
|||
name = "Categorization.find",
|
||||
query = "SELECT c FROM Categorization c "
|
||||
+ "WHERE c.category = :category "
|
||||
+ "AND c.categorizedObject = :object")
|
||||
,
|
||||
+ "AND c.categorizedObject = :object"),
|
||||
@NamedQuery(
|
||||
name = "Categorization.isAssignedTo",
|
||||
query = "SELECT (CASE WHEN COUNT(c) > 0 THEN true ELSE false END) "
|
||||
+ "FROM Categorization c "
|
||||
+ "WHERE c.category = :category "
|
||||
+ "AND c.categorizedObject = :object")
|
||||
,
|
||||
+ "AND c.categorizedObject = :object"),
|
||||
@NamedQuery(
|
||||
name = "Categorization.isAssignedToWithType",
|
||||
query = "SELECT (CASE WHEN COUNT(c) > 0 THEN true ELSE false END) "
|
||||
+ "FROM Categorization c "
|
||||
+ "WHERE c.category = :category "
|
||||
+ "AND c.categorizedObject = :object "
|
||||
+ "AND c.type = :type")
|
||||
,
|
||||
+ "AND c.type = :type"),
|
||||
@NamedQuery(
|
||||
name = "Categorization.findIndexObject",
|
||||
query = "SELECT c.categorizedObject FROM Categorization c "
|
||||
+ "WHERE c.category = :category "
|
||||
+ "AND c.indexObject = TRUE")
|
||||
,
|
||||
+ "AND c.indexObject = TRUE"),
|
||||
@NamedQuery(
|
||||
name = "Categorization.findIndexObjectCategorization",
|
||||
query = "SELECT c FROM Categorization c "
|
||||
+ "WHERE c.category = :category "
|
||||
+ "AND c.indexObject = TRUE"
|
||||
)
|
||||
,
|
||||
),
|
||||
@NamedQuery(
|
||||
name = "Categorization.hasIndexObject",
|
||||
query = "SELECT (CASE WHEN COUNT(c.categorizedObject) > 0 THEN true "
|
||||
|
|
|
|||
|
|
@ -23,17 +23,20 @@ import org.libreccm.imexport.Exportable;
|
|||
import org.libreccm.imexport.Processes;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.enterprise.inject.Instance;
|
||||
import javax.inject.Inject;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.NoResultException;
|
||||
import javax.persistence.TypedQuery;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
/**
|
||||
* Exporter/Importer for {@link Categorization} entities.
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@RequestScoped
|
||||
|
|
@ -54,10 +57,9 @@ public class CategorizationImExporter
|
|||
|
||||
@Override
|
||||
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
||||
|
||||
final Set<Class<? extends Exportable>> entities = new HashSet<>();
|
||||
entities.add(Category.class);
|
||||
|
||||
|
||||
dependenciesProviders.forEach(
|
||||
provider -> entities.addAll(provider.getCategorizableEntities())
|
||||
);
|
||||
|
|
@ -68,8 +70,27 @@ public class CategorizationImExporter
|
|||
@Override
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
protected void saveImportedEntity(final Categorization entity) {
|
||||
|
||||
entityManager.persist(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Categorization reloadEntity(final Categorization entity) {
|
||||
try {
|
||||
return entityManager.createNamedQuery(
|
||||
"Categorization.findById",
|
||||
Categorization.class
|
||||
).setParameter(
|
||||
"categorizationId",
|
||||
Objects.requireNonNull(entity).getCategorizationId()
|
||||
).getSingleResult();
|
||||
} catch (NoResultException ex) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format(
|
||||
"Categorization entity %s was not found in the database.",
|
||||
Objects.toString(entity)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import org.libreccm.imexport.Exportable;
|
|||
import org.libreccm.imexport.Processes;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
|
|
@ -60,4 +61,18 @@ public class CategoryImExporter extends AbstractEntityImExporter<Category> {
|
|||
categoryRepository.save(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Category reloadEntity(final Category entity) {
|
||||
return categoryRepository
|
||||
.findById(Objects.requireNonNull(entity).getObjectId())
|
||||
.orElseThrow(
|
||||
() -> new IllegalArgumentException(
|
||||
String.format(
|
||||
"Category entity %s does not exist in the database.",
|
||||
Objects.toString(entity)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import org.libreccm.imexport.Exportable;
|
|||
import org.libreccm.imexport.Processes;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
|
|
@ -30,7 +31,7 @@ import javax.inject.Inject;
|
|||
|
||||
/**
|
||||
* Exporter/Importer for {@link Domain} entities.
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@RequestScoped
|
||||
|
|
@ -39,10 +40,10 @@ public class DomainImExporter extends AbstractEntityImExporter<Domain> {
|
|||
|
||||
@Inject
|
||||
private DomainRepository domainRepository;
|
||||
|
||||
|
||||
@Override
|
||||
public Class<Domain> getEntityClass() {
|
||||
|
||||
|
||||
return Domain.class;
|
||||
}
|
||||
|
||||
|
|
@ -54,10 +55,22 @@ public class DomainImExporter extends AbstractEntityImExporter<Domain> {
|
|||
|
||||
@Override
|
||||
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
||||
|
||||
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected Domain reloadEntity(final Domain entity) {
|
||||
return domainRepository
|
||||
.findById(Objects.requireNonNull(entity).getObjectId())
|
||||
.orElseThrow(
|
||||
() -> new IllegalArgumentException(
|
||||
String.format(
|
||||
"Domain entity %s was not found in the database.",
|
||||
Objects.toString(entity)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,11 +54,15 @@ import javax.xml.bind.annotation.XmlElement;
|
|||
@Entity
|
||||
@Table(name = "DOMAIN_OWNERSHIPS", schema = DB_SCHEMA)
|
||||
@NamedQueries({
|
||||
@NamedQuery(
|
||||
name = "DomainOwnership.findById",
|
||||
query
|
||||
= "SELECT o FROM DomainOwnership o WHERE o.ownershipId = :ownershipId"
|
||||
),
|
||||
@NamedQuery(
|
||||
name = "DomainOwnership.findByUuid",
|
||||
query = "SELECT o FROM DomainOwnership o WHERE o.uuid = :uuid"
|
||||
)
|
||||
,
|
||||
),
|
||||
@NamedQuery(
|
||||
name = "DomainOwnership.findByOwnerAndDomain",
|
||||
query = "SELECT o FROM DomainOwnership o "
|
||||
|
|
@ -77,7 +81,7 @@ public class DomainOwnership implements Serializable, Exportable {
|
|||
@Column(name = "OWNERSHIP_ID")
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private long ownershipId;
|
||||
|
||||
|
||||
@Column(name = "UUID", unique = true, nullable = false)
|
||||
@XmlElement(name = "uuid", namespace = CoreConstants.CORE_XML_NS)
|
||||
private String uuid;
|
||||
|
|
@ -132,7 +136,7 @@ public class DomainOwnership implements Serializable, Exportable {
|
|||
public void setUuid(final String uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
|
||||
public CcmApplication getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,17 +24,19 @@ import org.libreccm.imexport.Processes;
|
|||
import org.libreccm.web.CcmApplication;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
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 DomainOwnership} entities.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@RequestScoped
|
||||
|
|
@ -47,20 +49,17 @@ public class DomainOwnershipImExporter
|
|||
|
||||
@Override
|
||||
public Class<DomainOwnership> getEntityClass() {
|
||||
|
||||
return DomainOwnership.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
protected void saveImportedEntity(final DomainOwnership entity) {
|
||||
|
||||
entityManager.persist(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
||||
|
||||
final Set<Class<? extends Exportable>> classes = new HashSet<>();
|
||||
classes.add(CcmApplication.class);
|
||||
classes.add(Domain.class);
|
||||
|
|
@ -68,4 +67,26 @@ public class DomainOwnershipImExporter
|
|||
return classes;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DomainOwnership reloadEntity(final DomainOwnership entity) {
|
||||
try {
|
||||
return entityManager
|
||||
.createNamedQuery(
|
||||
"DomainOwnership.findById",
|
||||
DomainOwnership.class
|
||||
)
|
||||
.setParameter(
|
||||
"ownershipId",
|
||||
Objects.requireNonNull(entity.getOwnershipId())
|
||||
).getSingleResult();
|
||||
} catch (NoResultException ex) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format(
|
||||
"DomainOwnership entity %s not found in database.",
|
||||
Objects.toString(entity)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import org.libreccm.imexport.Exportable;
|
|||
import org.libreccm.imexport.Processes;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
|
@ -45,15 +46,30 @@ public class ResourceTypeImExporter
|
|||
|
||||
@Override
|
||||
protected void saveImportedEntity(final ResourceType entity) {
|
||||
|
||||
repository.save(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
||||
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResourceType reloadEntity(final ResourceType entity) {
|
||||
return repository
|
||||
.findById(
|
||||
Objects.requireNonNull(entity).getResourceTypeId()
|
||||
)
|
||||
.orElseThrow(
|
||||
() -> new IllegalArgumentException(
|
||||
String.format(
|
||||
"The provided ResourceType %s was not found in the "
|
||||
+ "database.",
|
||||
Objects.toString(entity)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -62,7 +62,6 @@ public abstract class AbstractEntityImExporter<T extends Exportable> {
|
|||
* containers usually create a {@link java.lang.reflect.Proxy} class and
|
||||
* there is no portable way to unproxy a class.
|
||||
*
|
||||
*
|
||||
* @return A {@link Set} of exportable entity classes which should be
|
||||
* processed before the entities which are processed by this
|
||||
* implementation. If the implementation has no dependencies an
|
||||
|
|
@ -72,7 +71,6 @@ public abstract class AbstractEntityImExporter<T extends Exportable> {
|
|||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public T importEntity(final String data) throws ImportExpection {
|
||||
|
||||
try {
|
||||
final T entity = objectMapper.readValue(data, getEntityClass());
|
||||
saveImportedEntity(entity);
|
||||
|
|
@ -80,13 +78,26 @@ public abstract class AbstractEntityImExporter<T extends Exportable> {
|
|||
} catch (IOException ex) {
|
||||
throw new ImportExpection(ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected abstract void saveImportedEntity(T entity);
|
||||
|
||||
/**
|
||||
* Export an entity (as JSON). There should be no need to overwrite this
|
||||
* method.
|
||||
*
|
||||
* @param entity The entity to export.
|
||||
*
|
||||
* @return The entity as JSON
|
||||
*
|
||||
* @throws ExportException If an error occurs.
|
||||
*/
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public String exportEntity(final Exportable entity) throws ExportException {
|
||||
@SuppressWarnings("unchecked")
|
||||
final T export = reloadEntity((T) entity);
|
||||
try {
|
||||
return objectMapper.writeValueAsString(entity);
|
||||
return objectMapper.writeValueAsString(export);
|
||||
} catch (JsonProcessingException ex) {
|
||||
throw new ExportException(String.format(
|
||||
"Failed to export entity \"%s\" of type \"%s\".",
|
||||
|
|
@ -94,9 +105,17 @@ public abstract class AbstractEntityImExporter<T extends Exportable> {
|
|||
getEntityClass().getName()),
|
||||
ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected abstract void saveImportedEntity(T entity);
|
||||
/**
|
||||
* Reloads the entity to export. Entities become detacted for several
|
||||
* reasons before they are passed to the null {@link #exportEntity(org.libreccm.imexport.Exportable) method. The
|
||||
* implementation of this should reload the passed entity.
|
||||
*
|
||||
* @param entity The entity to reload.
|
||||
*
|
||||
* @return The reloaded entity
|
||||
*/
|
||||
protected abstract T reloadEntity(final T entity);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import org.libreccm.imexport.Exportable;
|
|||
import org.libreccm.imexport.Processes;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
|
|
@ -32,37 +33,48 @@ import javax.transaction.Transactional;
|
|||
|
||||
/**
|
||||
* Exporter/Importer for {@link Group}s.
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@RequestScoped
|
||||
@Processes(Group.class)
|
||||
public class GroupImExporter extends AbstractEntityImExporter<Group> {
|
||||
|
||||
|
||||
@Inject
|
||||
private EntityManager entityManager;
|
||||
|
||||
|
||||
@Inject
|
||||
private GroupRepository groupRepository;
|
||||
|
||||
|
||||
@Override
|
||||
public Class<Group> getEntityClass() {
|
||||
return Group.class;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
protected void saveImportedEntity(final Group entity) {
|
||||
|
||||
entity.setPartyId(0);
|
||||
// groupRepository.save(entity);
|
||||
entityManager.persist(entity);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
||||
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Group reloadEntity(final Group entity) {
|
||||
return groupRepository
|
||||
.findById(Objects.requireNonNull(entity).getPartyId())
|
||||
.orElseThrow(
|
||||
() -> new IllegalArgumentException(
|
||||
String.format(
|
||||
"Group entity %s was not found in database.",
|
||||
Objects.toString(entity)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,14 +56,25 @@ import javax.persistence.Table;
|
|||
@Entity
|
||||
@Table(name = "GROUP_MEMBERSHIPS", schema = DB_SCHEMA)
|
||||
@NamedQueries({
|
||||
@NamedQuery(name = "GroupMembership.findByUuid",
|
||||
query = "SELECT m FROM GroupMembership m WHERE m.uuid = :uuid"),
|
||||
@NamedQuery(name = "GroupMembership.findByGroupAndUser",
|
||||
query = "SELECT m FROM GroupMembership m "
|
||||
+ "WHERE m.member = :member AND m.group = :group")})
|
||||
@NamedQuery(
|
||||
name = "GroupMembership.findById",
|
||||
query
|
||||
= "SELECT m FROM GroupMembership m WHERE m.membershipId = :membershipId"
|
||||
),
|
||||
@NamedQuery(
|
||||
name = "GroupMembership.findByUuid",
|
||||
query = "SELECT m FROM GroupMembership m WHERE m.uuid = :uuid"
|
||||
),
|
||||
@NamedQuery(
|
||||
name = "GroupMembership.findByGroupAndUser",
|
||||
query = "SELECT m FROM GroupMembership m "
|
||||
+ "WHERE m.member = :member AND m.group = :group")
|
||||
})
|
||||
@XmlRootElement(name = "group-membership", namespace = CORE_XML_NS)
|
||||
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class,
|
||||
property = "uuid")
|
||||
@JsonIdentityInfo(
|
||||
generator = ObjectIdGenerators.PropertyGenerator.class,
|
||||
property = "uuid"
|
||||
)
|
||||
public class GroupMembership implements Serializable, Exportable {
|
||||
|
||||
private static final long serialVersionUID = 83192968306850665L;
|
||||
|
|
|
|||
|
|
@ -23,10 +23,12 @@ import org.libreccm.imexport.Exportable;
|
|||
import org.libreccm.imexport.Processes;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.NoResultException;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
/**
|
||||
|
|
@ -36,9 +38,9 @@ import javax.transaction.Transactional;
|
|||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@Processes(GroupMembership.class)
|
||||
public class GroupMembershipImExporter
|
||||
public class GroupMembershipImExporter
|
||||
extends AbstractEntityImExporter<GroupMembership> {
|
||||
|
||||
|
||||
@Inject
|
||||
private EntityManager entityManager;
|
||||
|
||||
|
|
@ -49,7 +51,6 @@ public class GroupMembershipImExporter
|
|||
|
||||
@Override
|
||||
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
||||
|
||||
final Set<Class<? extends Exportable>> entities = new HashSet<>();
|
||||
entities.add(User.class);
|
||||
entities.add(Group.class);
|
||||
|
|
@ -60,9 +61,30 @@ public class GroupMembershipImExporter
|
|||
@Override
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
protected void saveImportedEntity(final GroupMembership entity) {
|
||||
|
||||
entity.setMembershipId(0);
|
||||
entityManager.persist(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GroupMembership reloadEntity(final GroupMembership entity) {
|
||||
try {
|
||||
return entityManager
|
||||
.createNamedQuery(
|
||||
"GroupMembership.findById", GroupMembership.class
|
||||
)
|
||||
.setParameter(
|
||||
"membershipId",
|
||||
Objects.requireNonNull(entity).getMembershipId()
|
||||
)
|
||||
.getSingleResult();
|
||||
} catch (NoResultException ex) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format(
|
||||
"GroupMembership entity %s does not exist in the database.",
|
||||
Objects.toString(entity)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import org.libreccm.imexport.Exportable;
|
|||
import org.libreccm.imexport.Processes;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
|
|
@ -30,16 +31,16 @@ import javax.inject.Inject;
|
|||
|
||||
/**
|
||||
* Exporter/Importer for {@link Permission}s.
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@RequestScoped
|
||||
@Processes(Permission.class)
|
||||
public class PermissionImExporter extends AbstractEntityImExporter<Permission>{
|
||||
public class PermissionImExporter extends AbstractEntityImExporter<Permission> {
|
||||
|
||||
@Inject
|
||||
private PermissionRepository permissionRepository;
|
||||
|
||||
|
||||
@Override
|
||||
public Class<Permission> getEntityClass() {
|
||||
return Permission.class;
|
||||
|
|
@ -47,19 +48,29 @@ public class PermissionImExporter extends AbstractEntityImExporter<Permission>{
|
|||
|
||||
@Override
|
||||
protected void saveImportedEntity(final Permission entity) {
|
||||
|
||||
permissionRepository.save(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
||||
|
||||
final Set<Class<? extends Exportable>> classes = new HashSet<>();
|
||||
classes.add(Role.class);
|
||||
|
||||
|
||||
return classes;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected Permission reloadEntity(final Permission entity) {
|
||||
return permissionRepository
|
||||
.findById(Objects.requireNonNull(entity).getPermissionId())
|
||||
.orElseThrow(
|
||||
() -> new IllegalArgumentException(
|
||||
String.format(
|
||||
"Permission entity %s not found in the database.",
|
||||
Objects.toString(entity)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,44 +18,85 @@
|
|||
*/
|
||||
package org.libreccm.security;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.libreccm.core.UnexpectedErrorException;
|
||||
import org.libreccm.imexport.AbstractEntityImExporter;
|
||||
import org.libreccm.imexport.ExportException;
|
||||
import org.libreccm.imexport.Exportable;
|
||||
import org.libreccm.imexport.Processes;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.enterprise.context.Dependent;
|
||||
import javax.inject.Inject;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
/**
|
||||
* Exporter/Importer for {@link Role}s.
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@Dependent
|
||||
@Processes(Role.class)
|
||||
public class RoleImExporter extends AbstractEntityImExporter<Role> {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(
|
||||
RoleImExporter.class);
|
||||
|
||||
@Inject
|
||||
private EntityManager entityManager;
|
||||
|
||||
@Inject
|
||||
private RoleRepository roleRepository;
|
||||
|
||||
|
||||
@Override
|
||||
public Class<Role> getEntityClass() {
|
||||
return Role.class;
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
@Override
|
||||
public String exportEntity(final Exportable entity) throws ExportException {
|
||||
final Role role = roleRepository
|
||||
.findById(((Role) entity).getRoleId())
|
||||
.orElseThrow(
|
||||
() -> new IllegalArgumentException(
|
||||
String.format(
|
||||
"Provided entity %d does not exist in database.",
|
||||
entity)
|
||||
)
|
||||
);
|
||||
role.getDescription().getValues().forEach((locale, value) -> LOGGER
|
||||
.info("{}: {}", locale, value));
|
||||
return super.exportEntity(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveImportedEntity(final Role entity) {
|
||||
|
||||
roleRepository.save(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
||||
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected Role reloadEntity(final Role entity) {
|
||||
return roleRepository
|
||||
.findById(Objects.requireNonNull(entity).getRoleId())
|
||||
.orElseThrow(
|
||||
() -> new IllegalArgumentException(
|
||||
String.format(
|
||||
"Role entity %s not found in database.",
|
||||
Objects.toString(entity)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,11 +56,20 @@ import javax.persistence.Table;
|
|||
@Entity
|
||||
@Table(name = "ROLE_MEMBERSHIPS", schema = DB_SCHEMA)
|
||||
@NamedQueries({
|
||||
@NamedQuery(name = "RoleMembership.findByUuid",
|
||||
query = "SELECT m FROM RoleMembership m WHERE m.uuid = :uuid"),
|
||||
@NamedQuery(name = "RoleMembership.findByRoleAndMember",
|
||||
query = "SELECT m FROM RoleMembership m "
|
||||
+ "WHERE m.member = :member AND m.role = :role")
|
||||
@NamedQuery(
|
||||
name = "RoleMembership.findById",
|
||||
query
|
||||
= "SELECT m FROM RoleMembership m WHERE m.membershipId = :membershipId"
|
||||
),
|
||||
@NamedQuery(
|
||||
name = "RoleMembership.findByUuid",
|
||||
query = "SELECT m FROM RoleMembership m WHERE m.uuid = :uuid"
|
||||
),
|
||||
@NamedQuery(
|
||||
name = "RoleMembership.findByRoleAndMember",
|
||||
query
|
||||
= "SELECT m FROM RoleMembership m WHERE m.member = :member AND m.role = :role"
|
||||
)
|
||||
})
|
||||
@XmlRootElement(name = "role-membership", namespace = CORE_XML_NS)
|
||||
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class,
|
||||
|
|
|
|||
|
|
@ -23,15 +23,17 @@ import org.libreccm.imexport.Exportable;
|
|||
import org.libreccm.imexport.Processes;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.NoResultException;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
/**
|
||||
* Exporter/Importer for {@link RoleMembership}s.
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@Processes(RoleMembership.class)
|
||||
|
|
@ -49,19 +51,38 @@ public class RoleMembershipImExporter
|
|||
@Override
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
protected void saveImportedEntity(final RoleMembership entity) {
|
||||
|
||||
entityManager.persist(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
||||
|
||||
final Set<Class<? extends Exportable>> classes = new HashSet<>();
|
||||
classes.add(User.class);
|
||||
classes.add(Group.class);
|
||||
classes.add(Role.class);
|
||||
|
||||
|
||||
return classes;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RoleMembership reloadEntity(final RoleMembership entity) {
|
||||
try {
|
||||
return entityManager
|
||||
.createNamedQuery(
|
||||
"RoleMembership.findById", RoleMembership.class
|
||||
)
|
||||
.setParameter(
|
||||
"membershipId",
|
||||
Objects.requireNonNull(entity).getMembershipId()
|
||||
).getSingleResult();
|
||||
} catch (NoResultException ex) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format(
|
||||
"RoleMembeship entity %s not found in database.",
|
||||
Objects.toString(entity)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import org.libreccm.imexport.Exportable;
|
|||
import org.libreccm.imexport.Processes;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
|
|
@ -32,7 +33,7 @@ import javax.transaction.Transactional;
|
|||
|
||||
/**
|
||||
* Exporter/Importer for users.
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@RequestScoped
|
||||
|
|
@ -41,7 +42,7 @@ public class UserImExporter extends AbstractEntityImExporter<User> {
|
|||
|
||||
@Inject
|
||||
private EntityManager entityManager;
|
||||
|
||||
|
||||
@Inject
|
||||
private UserRepository userRepository;
|
||||
|
||||
|
|
@ -53,7 +54,6 @@ public class UserImExporter extends AbstractEntityImExporter<User> {
|
|||
@Override
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
protected void saveImportedEntity(final User entity) {
|
||||
|
||||
// Reset partyId.
|
||||
entity.setPartyId(0);
|
||||
// userRepository.save(entity);
|
||||
|
|
@ -62,8 +62,21 @@ public class UserImExporter extends AbstractEntityImExporter<User> {
|
|||
|
||||
@Override
|
||||
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
||||
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected User reloadEntity(final User entity) {
|
||||
return userRepository
|
||||
.findById(Objects.requireNonNull(entity).getPartyId())
|
||||
.orElseThrow(
|
||||
() -> new IllegalArgumentException(
|
||||
String.format(
|
||||
"User entity %s was not found in database.",
|
||||
Objects.toString(entity)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Copyright (C) 2020 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.libreccm.ui.admin.imexport;
|
||||
|
||||
import org.libreccm.imexport.Exportable;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class ExportTask {
|
||||
|
||||
private final String name;
|
||||
|
||||
private final LocalDate started;
|
||||
|
||||
private final Collection<Exportable> entities;
|
||||
|
||||
private final ExportTaskStatus status;
|
||||
|
||||
public ExportTask(
|
||||
final String name,
|
||||
final LocalDate started,
|
||||
final Collection<Exportable> entities,
|
||||
final ExportTaskStatus status
|
||||
) {
|
||||
this.name = name;
|
||||
this.started = started;
|
||||
this.entities = entities;
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public LocalDate getStarted() {
|
||||
return started;
|
||||
}
|
||||
|
||||
public Collection<Exportable> getEntities() {
|
||||
return Collections.unmodifiableCollection(entities);
|
||||
}
|
||||
|
||||
public ExportTaskStatus getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,140 @@
|
|||
/*
|
||||
* Copyright (C) 2020 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.libreccm.ui.admin.imexport;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Comparator;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class ExportTaskStatus implements Comparable<ExportTaskStatus> {
|
||||
|
||||
private String name;
|
||||
|
||||
private LocalDateTime started;
|
||||
|
||||
private ImExportTaskStatusEnum status;
|
||||
|
||||
private Throwable exception;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
protected void setName(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public LocalDateTime getStarted() {
|
||||
return started;
|
||||
}
|
||||
|
||||
protected void setStarted(final LocalDateTime started) {
|
||||
this.started = started;
|
||||
}
|
||||
|
||||
public ImExportTaskStatusEnum getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
protected void setStatus(final ImExportTaskStatusEnum status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public Throwable getException() {
|
||||
return exception;
|
||||
}
|
||||
|
||||
protected void setException(final Throwable exception) {
|
||||
this.exception = exception;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 7;
|
||||
hash = 97 * hash + Objects.hashCode(name);
|
||||
hash = 97 * hash + Objects.hashCode(started);
|
||||
hash = 97 * hash + Objects.hashCode(status);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (!(obj instanceof ExportTaskStatus)) {
|
||||
return false;
|
||||
}
|
||||
final ExportTaskStatus other = (ExportTaskStatus) obj;
|
||||
if (!other.canEqual(this)) {
|
||||
return false;
|
||||
}
|
||||
if (!Objects.equals(name, other.getName())) {
|
||||
return false;
|
||||
}
|
||||
if (!Objects.equals(started, other.getStarted())) {
|
||||
return false;
|
||||
}
|
||||
return status == other.getStatus();
|
||||
}
|
||||
|
||||
public boolean canEqual(final Object obj) {
|
||||
return obj instanceof ImExportTaskStatus;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(final ExportTaskStatus other) {
|
||||
return Comparator
|
||||
.nullsFirst(Comparator
|
||||
.comparing(ExportTaskStatus::getName)
|
||||
.thenComparing(ExportTaskStatus::getStarted)
|
||||
.thenComparing(ExportTaskStatus::getStatus)
|
||||
)
|
||||
.compare(this, other);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format(
|
||||
"%s{ "
|
||||
+ "name = %s, "
|
||||
+ "started = %s, "
|
||||
+ "status = %s, "
|
||||
+ "expection = %s"
|
||||
+ " }",
|
||||
super.toString(),
|
||||
name,
|
||||
DateTimeFormatter.ISO_DATE_TIME.withZone(
|
||||
ZoneId.systemDefault()
|
||||
).format(started),
|
||||
Objects.toString(status),
|
||||
Objects.toString(exception)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
package org.libreccm.ui.admin.imexport;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
|
@ -30,7 +29,7 @@ import java.util.concurrent.Future;
|
|||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class ImExportTask implements Comparable<ImExportTask> {
|
||||
public class ImExportTaskStatus implements Comparable<ImExportTaskStatus> {
|
||||
|
||||
private String name;
|
||||
|
||||
|
|
@ -92,10 +91,10 @@ public class ImExportTask implements Comparable<ImExportTask> {
|
|||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (!(obj instanceof ImExportTask)) {
|
||||
if (!(obj instanceof ImExportTaskStatus)) {
|
||||
return false;
|
||||
}
|
||||
final ImExportTask other = (ImExportTask) obj;
|
||||
final ImExportTaskStatus other = (ImExportTaskStatus) obj;
|
||||
if (!other.canEqual(this)) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -106,15 +105,15 @@ public class ImExportTask implements Comparable<ImExportTask> {
|
|||
}
|
||||
|
||||
public boolean canEqual(final Object obj) {
|
||||
return obj instanceof ImExportTask;
|
||||
return obj instanceof ImExportTaskStatus;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(final ImExportTask other) {
|
||||
public int compareTo(final ImExportTaskStatus other) {
|
||||
return Comparator
|
||||
.nullsFirst(Comparator
|
||||
.comparing(ImExportTask::getName)
|
||||
.thenComparing(ImExportTask::getStarted)
|
||||
.comparing(ImExportTaskStatus::getName)
|
||||
.thenComparing(ImExportTaskStatus::getStarted)
|
||||
)
|
||||
.compare(this, other);
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright (C) 2020 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.libreccm.ui.admin.imexport;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public enum ImExportTaskStatusEnum {
|
||||
|
||||
ERROR,
|
||||
FINISHED,
|
||||
RUNNING,
|
||||
|
||||
}
|
||||
|
|
@ -26,9 +26,12 @@ import java.util.concurrent.Future;
|
|||
|
||||
import javax.ejb.AsyncResult;
|
||||
import javax.ejb.Asynchronous;
|
||||
import javax.ejb.Singleton;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.ejb.TransactionAttribute;
|
||||
import javax.ejb.TransactionAttributeType;
|
||||
import javax.enterprise.context.ApplicationScoped;
|
||||
import javax.enterprise.event.ObservesAsync;
|
||||
import javax.inject.Inject;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
|
|
@ -36,29 +39,45 @@ import javax.transaction.Transactional;
|
|||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@Stateless
|
||||
@ApplicationScoped
|
||||
public class ImExportTasks {
|
||||
|
||||
@Inject
|
||||
private ImportExport importExport;
|
||||
|
||||
@Asynchronous
|
||||
@Transactional(Transactional.TxType.REQUIRES_NEW)
|
||||
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
|
||||
public Future<?> startExport(
|
||||
final Collection<Exportable> entities,
|
||||
final String exportName
|
||||
) {
|
||||
// @Asynchronous
|
||||
// @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
|
||||
// public Future<?> startExport(
|
||||
// final Collection<Exportable> entities,
|
||||
// final String exportName
|
||||
// ) {
|
||||
// importExport.exportEntities(entities, exportName);
|
||||
// return new AsyncResult<>(null);
|
||||
// }
|
||||
//
|
||||
// @Asynchronous
|
||||
// @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
|
||||
// public Future<?> startImport(final String importName) {
|
||||
// importExport.importEntities(importName);
|
||||
// return new AsyncResult<>(null);
|
||||
// }
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public ExportTask exportEntities(@ObservesAsync final ExportTask task) {
|
||||
final Collection<Exportable> entities = task.getEntities();
|
||||
final String exportName = task.getName();
|
||||
|
||||
importExport.exportEntities(entities, exportName);
|
||||
return new AsyncResult<>(null);
|
||||
task.getStatus().setStatus(ImExportTaskStatusEnum.FINISHED);
|
||||
return task;
|
||||
}
|
||||
|
||||
@Asynchronous
|
||||
@Transactional(Transactional.TxType.REQUIRES_NEW)
|
||||
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
|
||||
public Future<?> startImport(final String importName) {
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public void importEntitites(@ObservesAsync final ImExportTaskStatus task) {
|
||||
final String importName = task.getName();
|
||||
|
||||
importExport.importEntities(importName);
|
||||
return new AsyncResult<>(null);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,23 +18,22 @@
|
|||
*/
|
||||
package org.libreccm.ui.admin.imexport;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.libreccm.imexport.Exportable;
|
||||
import org.libreccm.imexport.ImportExport;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import javax.ejb.AsyncResult;
|
||||
import javax.ejb.Asynchronous;
|
||||
import javax.ejb.Schedule;
|
||||
import javax.enterprise.context.ApplicationScoped;
|
||||
import javax.enterprise.event.Event;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.persistence.EntityManager;
|
||||
|
|
@ -51,34 +50,47 @@ import javax.transaction.Transactional;
|
|||
@Named("ImportExportTaskManager")
|
||||
public class ImportExportTaskManager {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(
|
||||
ImportExportTaskManager.class
|
||||
);
|
||||
|
||||
@Inject
|
||||
private EntityManager entityManager;
|
||||
|
||||
@Inject
|
||||
private ImExportTasks imExportTasks;
|
||||
private Event<ExportTask> exportTaskSender;
|
||||
|
||||
private SortedSet<ImExportTask> exportTasks;
|
||||
@Inject
|
||||
private Event<ImportTask> importTaskSender;
|
||||
|
||||
private SortedSet<ImExportTask> importTasks;
|
||||
// @Inject
|
||||
// private ImExportTasks imExportTasks;
|
||||
|
||||
// private SortedSet<ImExportTaskStatus> exportTasks;
|
||||
//
|
||||
// private SortedSet<ImExportTaskStatus> importTasks;
|
||||
private final SortedSet<ExportTaskStatus> exportTasks;
|
||||
|
||||
private final SortedSet<ImportTaskStatus> importTasks;
|
||||
|
||||
public ImportExportTaskManager() {
|
||||
exportTasks = new TreeSet<>(
|
||||
Comparator.comparing(
|
||||
ImExportTask::getStarted)
|
||||
.thenComparing(ImExportTask::getName)
|
||||
ExportTaskStatus::getStarted)
|
||||
.thenComparing(ExportTaskStatus::getName)
|
||||
);
|
||||
importTasks = new TreeSet<>(
|
||||
Comparator.comparing(
|
||||
ImExportTask::getStarted)
|
||||
.thenComparing(ImExportTask::getName)
|
||||
ImportTaskStatus::getStarted)
|
||||
.thenComparing(ImportTaskStatus::getName)
|
||||
);
|
||||
}
|
||||
|
||||
public SortedSet<ImExportTask> getExportTasks() {
|
||||
public SortedSet<ExportTaskStatus> getExportTasks() {
|
||||
return Collections.unmodifiableSortedSet(exportTasks);
|
||||
}
|
||||
|
||||
public SortedSet<ImExportTask> getImportTasks() {
|
||||
public SortedSet<ImportTaskStatus> getImportTasks() {
|
||||
return Collections.unmodifiableSortedSet(importTasks);
|
||||
}
|
||||
|
||||
|
|
@ -96,20 +108,24 @@ public class ImportExportTaskManager {
|
|||
entities.addAll(entitiesOfType);
|
||||
}
|
||||
|
||||
final ImExportTask task = new ImExportTask();
|
||||
task.setName(exportName);
|
||||
task.setStarted(LocalDateTime.now());
|
||||
final Future<?> status = imExportTasks.startExport(
|
||||
entities, exportName
|
||||
);
|
||||
task.setStatus(status);
|
||||
exportTasks.add(task);
|
||||
final ExportTaskStatus taskStatus = new ExportTaskStatus();
|
||||
taskStatus.setName(exportName);
|
||||
taskStatus.setStarted(LocalDateTime.now());
|
||||
// final Future<?> status = imExportTasks.startExport(
|
||||
// entities, exportName
|
||||
// );
|
||||
exportTaskSender.fireAsync(
|
||||
new ExportTask(exportName, LocalDate.now(), entities, taskStatus)
|
||||
).handle((task , ex) -> handleExportTaskResult(task, ex, taskStatus));
|
||||
|
||||
taskStatus.setStatus(ImExportTaskStatusEnum.RUNNING);
|
||||
exportTasks.add(taskStatus);
|
||||
}
|
||||
|
||||
// public void exportEntities(
|
||||
// final Collection<Exportable> entities, final String exportName
|
||||
// ) {
|
||||
// final ImExportTask task = new ImExportTask();
|
||||
// final ImExportTaskStatus task = new ImExportTaskStatus();
|
||||
// task.setName(exportName);
|
||||
// task.setStarted(LocalDate.now());
|
||||
// final Future<?> status = startExport(entities, exportName);
|
||||
|
|
@ -117,21 +133,22 @@ public class ImportExportTaskManager {
|
|||
// exportTasks.add(task);
|
||||
// }
|
||||
public void importEntities(final String importName) {
|
||||
final ImExportTask task = new ImExportTask();
|
||||
task.setName(importName);
|
||||
task.setStarted(LocalDateTime.now());
|
||||
final Future<?> status = imExportTasks.startImport(importName);
|
||||
task.setStatus(status);
|
||||
importTasks.add(task);
|
||||
// final ImExportTaskStatus task = new ImExportTaskStatus();
|
||||
// task.setName(importName);
|
||||
// task.setStarted(LocalDateTime.now());
|
||||
// final Future<?> status = imExportTasks.startImport(importName);
|
||||
// task.setStatus(status);
|
||||
// importTasks.add(task);
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Schedule(hour = "*", minute = "*/5", persistent = false)
|
||||
protected void removeFinishedTasks() {
|
||||
exportTasks.removeIf(ImExportTask::isDone);
|
||||
importTasks.removeIf(ImExportTask::isDone);
|
||||
exportTasks.removeIf(taskStatus -> taskStatus.getStatus() == ImExportTaskStatusEnum.FINISHED);
|
||||
// importTasks.removeIf(taskStatus -> taskStatus.getStatus() == ImExportTaskStatusEnum.FINISHED);
|
||||
}
|
||||
|
||||
public void cancelTask(final ImExportTask task) {
|
||||
public void cancelTask(final ImExportTaskStatus task) {
|
||||
task.cancel();
|
||||
}
|
||||
|
||||
|
|
@ -149,4 +166,18 @@ public class ImportExportTaskManager {
|
|||
);
|
||||
}
|
||||
|
||||
private Object handleExportTaskResult(
|
||||
final ExportTask task, final Throwable ex, final ExportTaskStatus status
|
||||
) {
|
||||
if (ex == null) {
|
||||
status.setStatus(ImExportTaskStatusEnum.FINISHED);
|
||||
} else {
|
||||
status.setStatus(ImExportTaskStatusEnum.ERROR);
|
||||
status.setException(ex);
|
||||
LOGGER.error("Export Task {} failed ", task);
|
||||
LOGGER.error("with exception:", ex);
|
||||
}
|
||||
return task;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Copyright (C) 2020 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.libreccm.ui.admin.imexport;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class ImportTask {
|
||||
|
||||
private final String name;
|
||||
|
||||
private final LocalDate started;
|
||||
|
||||
public ImportTask(final String name, final LocalDate started) {
|
||||
this.name = name;
|
||||
this.started = started;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public LocalDate getStarted() {
|
||||
return started;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
* Copyright (C) 2020 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.libreccm.ui.admin.imexport;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Comparator;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.CompletionStage;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class ImportTaskStatus implements Comparable<ImportTaskStatus> {
|
||||
|
||||
private String name;
|
||||
|
||||
private LocalDateTime started;
|
||||
|
||||
private CompletionStage<ImportTask> status;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
protected void setName(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public LocalDateTime getStarted() {
|
||||
return started;
|
||||
}
|
||||
|
||||
protected void setStarted(final LocalDateTime started) {
|
||||
this.started = started;
|
||||
}
|
||||
|
||||
public CompletionStage<ImportTask> getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
protected void setStatus(final CompletionStage<ImportTask> status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public boolean canEqual(final Object obj) {
|
||||
return obj instanceof ImExportTaskStatus;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(final ImportTaskStatus other) {
|
||||
return Comparator
|
||||
.nullsFirst(Comparator
|
||||
.comparing(ImportTaskStatus::getName)
|
||||
.thenComparing(ImportTaskStatus::getStarted)
|
||||
)
|
||||
.compare(this, other);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format(
|
||||
"%s{ "
|
||||
+ "name = %s, "
|
||||
+ "started = %s, "
|
||||
+ "status = %s"
|
||||
+ " }",
|
||||
super.toString(),
|
||||
name,
|
||||
DateTimeFormatter.ISO_DATE_TIME.withZone(
|
||||
ZoneId.systemDefault()
|
||||
).format(started),
|
||||
Objects.toString(status)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -23,6 +23,7 @@ import org.libreccm.imexport.Exportable;
|
|||
import org.libreccm.imexport.Processes;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
|
|
@ -50,14 +51,26 @@ public class ApplicationImExporter
|
|||
@Override
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
protected void saveImportedEntity(final CcmApplication entity) {
|
||||
|
||||
applicationRepository.save(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
||||
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CcmApplication reloadEntity(final CcmApplication entity) {
|
||||
return applicationRepository
|
||||
.findById(Objects.requireNonNull(entity).getObjectId())
|
||||
.orElseThrow(
|
||||
() -> new IllegalArgumentException(
|
||||
String.format(
|
||||
"CcmApplication entity %s not found in database.",
|
||||
Objects.toString(entity)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import org.libreccm.imexport.Exportable;
|
|||
import org.libreccm.imexport.Processes;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
|
|
@ -31,7 +32,7 @@ import javax.transaction.Transactional;
|
|||
|
||||
/**
|
||||
* Exporter/Importer for {@link AssignableTask}s.
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*
|
||||
|
|
@ -51,7 +52,6 @@ public class AssignableTaskImExporter
|
|||
|
||||
@Override
|
||||
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
||||
|
||||
final Set<Class<? extends Exportable>> entities = new HashSet<>();
|
||||
entities.add(Workflow.class);
|
||||
|
||||
|
|
@ -61,8 +61,21 @@ public class AssignableTaskImExporter
|
|||
@Override
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
protected void saveImportedEntity(final AssignableTask entity) {
|
||||
|
||||
assignableTaskRepository.save(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AssignableTask reloadEntity(final AssignableTask entity) {
|
||||
return assignableTaskRepository
|
||||
.findById(Objects.requireNonNull(entity).getTaskId())
|
||||
.orElseThrow(
|
||||
() -> new IllegalArgumentException(
|
||||
String.format(
|
||||
"AssignableTask entity %s not found in database.",
|
||||
Objects.toString(entity)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,17 +37,39 @@ 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;
|
||||
|
||||
/**
|
||||
* Represents the assignment of a {@link AssignableTask} to a {@link Role}.
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "WORKFLOW_TASK_ASSIGNMENTS", schema = DB_SCHEMA)
|
||||
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class,
|
||||
property = "customAssignId")
|
||||
@NamedQueries({
|
||||
@NamedQuery(
|
||||
name = "TaskAssignment.findById",
|
||||
query = "SELECT t FROM TaskAssignment t WHERE t.taskAssignmentId = :assignmentId"
|
||||
),
|
||||
@NamedQuery(
|
||||
name = "TaskAssignment.findByUuid",
|
||||
query = "SELECT t FROM TaskAssignment t WHERE t.uuid = :uuid"
|
||||
),
|
||||
@NamedQuery(
|
||||
name = "TaskAssignment.findByTask",
|
||||
query = "SELECT t FROM TaskAssignment t WHERE t.task = :task"
|
||||
),
|
||||
@NamedQuery(
|
||||
name = "TaskAssignment.findByRole",
|
||||
query = "SELECT t FROM TaskAssignment t WHERE t.role = :role"
|
||||
)
|
||||
})
|
||||
@JsonIdentityInfo(
|
||||
generator = ObjectIdGenerators.PropertyGenerator.class,
|
||||
property = "customAssignId"
|
||||
)
|
||||
public class TaskAssignment implements Serializable, Exportable {
|
||||
|
||||
private static final long serialVersionUID = -4427537363301565707L;
|
||||
|
|
@ -62,7 +84,7 @@ public class TaskAssignment implements Serializable, Exportable {
|
|||
|
||||
@Column(name = "UUID", unique = true, nullable = false)
|
||||
private String uuid;
|
||||
|
||||
|
||||
/**
|
||||
* The task.
|
||||
*/
|
||||
|
|
@ -86,7 +108,7 @@ public class TaskAssignment implements Serializable, Exportable {
|
|||
protected void setTaskAssignmentId(final long taskAssignmentId) {
|
||||
this.taskAssignmentId = taskAssignmentId;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getUuid() {
|
||||
return uuid;
|
||||
|
|
@ -95,7 +117,6 @@ public class TaskAssignment implements Serializable, Exportable {
|
|||
public void setUuid(final String uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
|
||||
public AssignableTask getTask() {
|
||||
return task;
|
||||
|
|
|
|||
|
|
@ -23,22 +23,24 @@ import org.libreccm.imexport.Exportable;
|
|||
import org.libreccm.imexport.Processes;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
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 TaskAssignment}s.
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@RequestScoped
|
||||
@Processes(TaskAssignment.class)
|
||||
public class TaskAssignmentImExporter
|
||||
public class TaskAssignmentImExporter
|
||||
extends AbstractEntityImExporter<TaskAssignment> {
|
||||
|
||||
@Inject
|
||||
|
|
@ -46,24 +48,44 @@ public class TaskAssignmentImExporter
|
|||
|
||||
@Override
|
||||
public Class<TaskAssignment> getEntityClass() {
|
||||
|
||||
return TaskAssignment.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
protected void saveImportedEntity(final TaskAssignment entity) {
|
||||
|
||||
entityManager.persist(entity);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
||||
|
||||
|
||||
final Set<Class<? extends Exportable>> classes = new HashSet<>();
|
||||
classes.add(AssignableTask.class);
|
||||
|
||||
|
||||
return classes;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TaskAssignment reloadEntity(final TaskAssignment entity) {
|
||||
try {
|
||||
return entityManager
|
||||
.createNamedQuery(
|
||||
"TaskAssignment.findById", TaskAssignment.class
|
||||
)
|
||||
.setParameter(
|
||||
"assignmentId",
|
||||
Objects.requireNonNull(entity).getTaskAssignmentId()
|
||||
).getSingleResult();
|
||||
} catch (NoResultException ex) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format(
|
||||
"TaskAssignment entity %s not found in database.",
|
||||
Objects.toString(entity)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import org.libreccm.imexport.Exportable;
|
|||
import org.libreccm.imexport.Processes;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
|
|
@ -55,12 +56,25 @@ public class TaskCommentImExporter extends AbstractEntityImExporter<TaskComment>
|
|||
|
||||
@Override
|
||||
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
||||
|
||||
final Set<Class<? extends Exportable>> classes = new HashSet<>();
|
||||
classes.add(AssignableTask.class);
|
||||
|
||||
return classes;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TaskComment reloadEntity(final TaskComment entity) {
|
||||
return taskCommentRepository
|
||||
.findById(Objects.requireNonNull(entity).getCommentId())
|
||||
.orElseThrow(
|
||||
() -> new IllegalArgumentException(
|
||||
String.format(
|
||||
"TaskComment entity %s not found in database.",
|
||||
Objects.toString(entity)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,6 +34,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;
|
||||
|
||||
/**
|
||||
|
|
@ -43,8 +45,28 @@ import javax.persistence.Table;
|
|||
*/
|
||||
@Entity
|
||||
@Table(name = "WORKFLOW_TASK_DEPENDENCIES", schema = CoreConstants.DB_SCHEMA)
|
||||
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class,
|
||||
property = "uuid")
|
||||
@NamedQueries({
|
||||
@NamedQuery(
|
||||
name = "TaskDependency.findById",
|
||||
query = "SELECT d FROM TaskDependency d WHERE d.taskDependencyId = :dependencyId"
|
||||
),
|
||||
@NamedQuery(
|
||||
name = "TaskDependency.findByUuid",
|
||||
query = "SELECT d FROM TaskDependency d WHERE d.uuid = :uuid"
|
||||
),
|
||||
@NamedQuery(
|
||||
name = "TaskDependency.findByBlockedTask",
|
||||
query = "SELECT d FROM TaskDependency d WHERE d.blockedTask = :task"
|
||||
),
|
||||
@NamedQuery(
|
||||
name = "TaskDependency.findByBlockingTask",
|
||||
query = "SELECT d FROM TaskDependency d WHERE d.blockingTask = :task"
|
||||
)
|
||||
})
|
||||
@JsonIdentityInfo(
|
||||
generator = ObjectIdGenerators.PropertyGenerator.class,
|
||||
property = "uuid"
|
||||
)
|
||||
public class TaskDependency implements Serializable, Exportable {
|
||||
|
||||
private static final long serialVersionUID = -4383255770131633943L;
|
||||
|
|
|
|||
|
|
@ -23,22 +23,24 @@ import org.libreccm.imexport.Exportable;
|
|||
import org.libreccm.imexport.Processes;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
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 TaskDependency} entities.
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers<\a>
|
||||
* @version created the 12/12/17
|
||||
*/
|
||||
@RequestScoped
|
||||
@Processes(TaskDependency.class)
|
||||
public class TaskDependencyImExporter
|
||||
public class TaskDependencyImExporter
|
||||
extends AbstractEntityImExporter<TaskDependency> {
|
||||
|
||||
@Inject
|
||||
|
|
@ -52,19 +54,36 @@ public class TaskDependencyImExporter
|
|||
@Override
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
protected void saveImportedEntity(final TaskDependency entity) {
|
||||
|
||||
entityManager.persist(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
||||
|
||||
final Set<Class<? extends Exportable>> classes = new HashSet<>();
|
||||
classes.add(AssignableTask.class);
|
||||
|
||||
|
||||
return classes;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected TaskDependency reloadEntity(final TaskDependency entity) {
|
||||
try {
|
||||
return entityManager
|
||||
.createNamedQuery(
|
||||
"TaskDependency.findById", TaskDependency.class
|
||||
)
|
||||
.setParameter(
|
||||
"dependencyId",
|
||||
Objects.requireNonNull(entity).getTaskDependencyId()
|
||||
).getSingleResult();
|
||||
} catch (NoResultException ex) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format(
|
||||
"TaskDependency entity %s not found in database.",
|
||||
Objects.toString(entity)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import org.libreccm.imexport.Exportable;
|
|||
import org.libreccm.imexport.Processes;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
|
|
@ -31,7 +32,7 @@ import javax.transaction.Transactional;
|
|||
|
||||
/**
|
||||
* Importer/Exporter for {@link Workflow}s.
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@RequestScoped
|
||||
|
|
@ -50,14 +51,26 @@ public class WorkflowImExporter extends AbstractEntityImExporter<Workflow> {
|
|||
@Override
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
protected void saveImportedEntity(final Workflow entity) {
|
||||
|
||||
workflowRepository.save(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
||||
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Workflow reloadEntity(final Workflow entity) {
|
||||
return workflowRepository
|
||||
.findById(Objects.requireNonNull(entity).getWorkflowId())
|
||||
.orElseThrow(
|
||||
() -> new IllegalArgumentException(
|
||||
String.format(
|
||||
"Workflow entity %s not found in database.",
|
||||
Objects.toString(entity)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -88,20 +88,12 @@
|
|||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<c:forEach items="#{ImportExportTaskManager.exportTasks}" var="task">
|
||||
<c:forEach items="#{ImportExportTaskManager.exportTasks}"
|
||||
var="task">
|
||||
<tr>
|
||||
<td>#{task.name}</td>
|
||||
<td>#{task.started}</td>
|
||||
<td>
|
||||
<c:choose>
|
||||
<c:when test="#{task.done}">
|
||||
#{AdminMessages['imexport.activeexports.table.columns.status.finished']}
|
||||
</c:when>
|
||||
<c:otherwise>
|
||||
#{AdminMessages['imexport.activeexports.table.columns.status.running']}
|
||||
</c:otherwise>
|
||||
</c:choose>
|
||||
</td>
|
||||
<td>#{task.status}</td>
|
||||
<td>
|
||||
<a class="btn btn-warning" href="#">
|
||||
#{AdminMessages['imexport.activeexports.table.columns.actions.button_label']}
|
||||
|
|
@ -135,7 +127,8 @@
|
|||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<c:forEach items="#{ImportExportTaskManager.importTasks}" var="task">
|
||||
<c:forEach items="#{ImportExportTaskManager.importTasks}"
|
||||
var="task">
|
||||
<tr>
|
||||
<td>#{task.name}</td>
|
||||
<td>#{task.started}</td>
|
||||
|
|
|
|||
|
|
@ -23,9 +23,10 @@ import org.libreccm.imexport.Exportable;
|
|||
import org.libreccm.imexport.Processes;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.faces.bean.RequestScoped;
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
|
|
@ -45,7 +46,7 @@ public class BlobObjectImExporter extends AbstractEntityImExporter<BlobObject> {
|
|||
private BlobObjectRepository blobObjectRepository;
|
||||
|
||||
@Override
|
||||
protected Class<BlobObject> getEntityClass() {
|
||||
public Class<BlobObject> getEntityClass() {
|
||||
return BlobObject.class;
|
||||
}
|
||||
|
||||
|
|
@ -61,4 +62,18 @@ public class BlobObjectImExporter extends AbstractEntityImExporter<BlobObject> {
|
|||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlobObject reloadEntity(final BlobObject entity) {
|
||||
return blobObjectRepository
|
||||
.findById(Objects.requireNonNull(entity).getBlobObjectId())
|
||||
.orElseThrow(
|
||||
() -> new IllegalArgumentException(
|
||||
String.format(
|
||||
"BlobObject entity %s not found in database.",
|
||||
Objects.toString(entity)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,17 +23,17 @@ import org.libreccm.imexport.Exportable;
|
|||
import org.libreccm.imexport.Processes;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
/**
|
||||
* Im/Exporter for importing and exporting {@code File}s from the
|
||||
* system into a specified file and the other way around.
|
||||
* Im/Exporter for importing and exporting {@code File}s from the system into a
|
||||
* specified file and the other way around.
|
||||
*
|
||||
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
|
|
@ -46,7 +46,7 @@ public class FileImExporter extends AbstractEntityImExporter<File> {
|
|||
private FileRepository fileRepository;
|
||||
|
||||
@Override
|
||||
protected Class<File> getEntityClass() {
|
||||
public Class<File> getEntityClass() {
|
||||
return File.class;
|
||||
}
|
||||
|
||||
|
|
@ -60,6 +60,19 @@ public class FileImExporter extends AbstractEntityImExporter<File> {
|
|||
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected File reloadEntity(final File entity) {
|
||||
return fileRepository
|
||||
.findById(Objects.requireNonNull(entity).getObjectId())
|
||||
.orElseThrow(
|
||||
() -> new IllegalArgumentException(
|
||||
String.format(
|
||||
"File entity %s not found in database",
|
||||
Objects.toString(entity)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,9 +22,10 @@ import org.libreccm.imexport.Exportable;
|
|||
import org.libreccm.imexport.Processes;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.faces.bean.RequestScoped;
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
|
|
@ -43,7 +44,7 @@ public class FolderImExporter extends AbstractResourceImExporter<Folder> {
|
|||
private FolderRepository folderRepository;
|
||||
|
||||
@Override
|
||||
protected Class<Folder> getEntityClass() {
|
||||
public Class<Folder> getEntityClass() {
|
||||
return Folder.class;
|
||||
}
|
||||
|
||||
|
|
@ -58,4 +59,18 @@ public class FolderImExporter extends AbstractResourceImExporter<Folder> {
|
|||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Folder reloadEntity(final Folder entity) {
|
||||
return folderRepository
|
||||
.findById(Objects.requireNonNull(entity).getObjectId())
|
||||
.orElseThrow(
|
||||
() -> new IllegalArgumentException(
|
||||
String.format(
|
||||
"Folder entity %s not found in database.",
|
||||
Objects.toString(entity)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,9 +23,10 @@ import org.libreccm.imexport.Exportable;
|
|||
import org.libreccm.imexport.Processes;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.faces.bean.RequestScoped;
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
|
|
@ -40,7 +41,7 @@ public class RepositoryImExporter extends AbstractEntityImExporter<Repository> {
|
|||
private RepositoryRepository repositoryRepository;
|
||||
|
||||
@Override
|
||||
protected Class<Repository> getEntityClass() {
|
||||
public Class<Repository> getEntityClass() {
|
||||
return Repository.class;
|
||||
}
|
||||
|
||||
|
|
@ -53,7 +54,19 @@ public class RepositoryImExporter extends AbstractEntityImExporter<Repository> {
|
|||
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected Repository reloadEntity(final Repository entity) {
|
||||
return repositoryRepository
|
||||
.findById(Objects.requireNonNull(entity).getObjectId())
|
||||
.orElseThrow(
|
||||
() -> new IllegalArgumentException(
|
||||
String.format(
|
||||
"Repository entity %s not found in database.",
|
||||
Objects.toString(entity)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue