Added a reload method to the interface of the AbstractImExporter class
parent
0acc7f17b4
commit
6fd4e177cf
|
|
@ -10,6 +10,7 @@ import org.libreccm.imexport.AbstractEntityImExporter;
|
||||||
import org.libreccm.imexport.Exportable;
|
import org.libreccm.imexport.Exportable;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
@ -42,4 +43,19 @@ public abstract class AbstractContentItemImExporter<T extends ContentItem>
|
||||||
itemRepository.save(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 org.libreccm.imexport.Processes;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
|
@ -44,4 +45,18 @@ public class ContentSectionImExporter
|
||||||
sectionRepository.save(entity);
|
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
|
@Entity
|
||||||
@Table(name = "CATEGORIZATIONS", schema = DB_SCHEMA)
|
@Table(name = "CATEGORIZATIONS", schema = DB_SCHEMA)
|
||||||
@NamedQueries({
|
@NamedQueries({
|
||||||
|
@NamedQuery(
|
||||||
|
name = "Categorization.findById",
|
||||||
|
query
|
||||||
|
= "SELECT c FROM Categorization c WHERE c.categorizationId = :categorizationId"
|
||||||
|
),
|
||||||
@NamedQuery(
|
@NamedQuery(
|
||||||
name = "Categorization.findByUuid",
|
name = "Categorization.findByUuid",
|
||||||
query = "SELECT c FROM Categorization c WHERE c.uuid = :uuid"
|
query = "SELECT c FROM Categorization c WHERE c.uuid = :uuid"
|
||||||
|
|
@ -62,36 +67,31 @@ import javax.persistence.Table;
|
||||||
name = "Categorization.find",
|
name = "Categorization.find",
|
||||||
query = "SELECT c FROM Categorization c "
|
query = "SELECT c FROM Categorization c "
|
||||||
+ "WHERE c.category = :category "
|
+ "WHERE c.category = :category "
|
||||||
+ "AND c.categorizedObject = :object")
|
+ "AND c.categorizedObject = :object"),
|
||||||
,
|
|
||||||
@NamedQuery(
|
@NamedQuery(
|
||||||
name = "Categorization.isAssignedTo",
|
name = "Categorization.isAssignedTo",
|
||||||
query = "SELECT (CASE WHEN COUNT(c) > 0 THEN true ELSE false END) "
|
query = "SELECT (CASE WHEN COUNT(c) > 0 THEN true ELSE false END) "
|
||||||
+ "FROM Categorization c "
|
+ "FROM Categorization c "
|
||||||
+ "WHERE c.category = :category "
|
+ "WHERE c.category = :category "
|
||||||
+ "AND c.categorizedObject = :object")
|
+ "AND c.categorizedObject = :object"),
|
||||||
,
|
|
||||||
@NamedQuery(
|
@NamedQuery(
|
||||||
name = "Categorization.isAssignedToWithType",
|
name = "Categorization.isAssignedToWithType",
|
||||||
query = "SELECT (CASE WHEN COUNT(c) > 0 THEN true ELSE false END) "
|
query = "SELECT (CASE WHEN COUNT(c) > 0 THEN true ELSE false END) "
|
||||||
+ "FROM Categorization c "
|
+ "FROM Categorization c "
|
||||||
+ "WHERE c.category = :category "
|
+ "WHERE c.category = :category "
|
||||||
+ "AND c.categorizedObject = :object "
|
+ "AND c.categorizedObject = :object "
|
||||||
+ "AND c.type = :type")
|
+ "AND c.type = :type"),
|
||||||
,
|
|
||||||
@NamedQuery(
|
@NamedQuery(
|
||||||
name = "Categorization.findIndexObject",
|
name = "Categorization.findIndexObject",
|
||||||
query = "SELECT c.categorizedObject FROM Categorization c "
|
query = "SELECT c.categorizedObject FROM Categorization c "
|
||||||
+ "WHERE c.category = :category "
|
+ "WHERE c.category = :category "
|
||||||
+ "AND c.indexObject = TRUE")
|
+ "AND c.indexObject = TRUE"),
|
||||||
,
|
|
||||||
@NamedQuery(
|
@NamedQuery(
|
||||||
name = "Categorization.findIndexObjectCategorization",
|
name = "Categorization.findIndexObjectCategorization",
|
||||||
query = "SELECT c FROM Categorization c "
|
query = "SELECT c FROM Categorization c "
|
||||||
+ "WHERE c.category = :category "
|
+ "WHERE c.category = :category "
|
||||||
+ "AND c.indexObject = TRUE"
|
+ "AND c.indexObject = TRUE"
|
||||||
)
|
),
|
||||||
,
|
|
||||||
@NamedQuery(
|
@NamedQuery(
|
||||||
name = "Categorization.hasIndexObject",
|
name = "Categorization.hasIndexObject",
|
||||||
query = "SELECT (CASE WHEN COUNT(c.categorizedObject) > 0 THEN true "
|
query = "SELECT (CASE WHEN COUNT(c.categorizedObject) > 0 THEN true "
|
||||||
|
|
|
||||||
|
|
@ -23,12 +23,15 @@ import org.libreccm.imexport.Exportable;
|
||||||
import org.libreccm.imexport.Processes;
|
import org.libreccm.imexport.Processes;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
import javax.enterprise.inject.Instance;
|
import javax.enterprise.inject.Instance;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.NoResultException;
|
||||||
|
import javax.persistence.TypedQuery;
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -54,7 +57,6 @@ public class CategorizationImExporter
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
||||||
|
|
||||||
final Set<Class<? extends Exportable>> entities = new HashSet<>();
|
final Set<Class<? extends Exportable>> entities = new HashSet<>();
|
||||||
entities.add(Category.class);
|
entities.add(Category.class);
|
||||||
|
|
||||||
|
|
@ -68,8 +70,27 @@ public class CategorizationImExporter
|
||||||
@Override
|
@Override
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
protected void saveImportedEntity(final Categorization entity) {
|
protected void saveImportedEntity(final Categorization entity) {
|
||||||
|
|
||||||
entityManager.persist(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 org.libreccm.imexport.Processes;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
|
@ -60,4 +61,18 @@ public class CategoryImExporter extends AbstractEntityImExporter<Category> {
|
||||||
categoryRepository.save(entity);
|
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 org.libreccm.imexport.Processes;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
|
@ -58,6 +59,18 @@ public class DomainImExporter extends AbstractEntityImExporter<Domain> {
|
||||||
return Collections.emptySet();
|
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
|
@Entity
|
||||||
@Table(name = "DOMAIN_OWNERSHIPS", schema = DB_SCHEMA)
|
@Table(name = "DOMAIN_OWNERSHIPS", schema = DB_SCHEMA)
|
||||||
@NamedQueries({
|
@NamedQueries({
|
||||||
|
@NamedQuery(
|
||||||
|
name = "DomainOwnership.findById",
|
||||||
|
query
|
||||||
|
= "SELECT o FROM DomainOwnership o WHERE o.ownershipId = :ownershipId"
|
||||||
|
),
|
||||||
@NamedQuery(
|
@NamedQuery(
|
||||||
name = "DomainOwnership.findByUuid",
|
name = "DomainOwnership.findByUuid",
|
||||||
query = "SELECT o FROM DomainOwnership o WHERE o.uuid = :uuid"
|
query = "SELECT o FROM DomainOwnership o WHERE o.uuid = :uuid"
|
||||||
)
|
),
|
||||||
,
|
|
||||||
@NamedQuery(
|
@NamedQuery(
|
||||||
name = "DomainOwnership.findByOwnerAndDomain",
|
name = "DomainOwnership.findByOwnerAndDomain",
|
||||||
query = "SELECT o FROM DomainOwnership o "
|
query = "SELECT o FROM DomainOwnership o "
|
||||||
|
|
|
||||||
|
|
@ -24,11 +24,13 @@ import org.libreccm.imexport.Processes;
|
||||||
import org.libreccm.web.CcmApplication;
|
import org.libreccm.web.CcmApplication;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.NoResultException;
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -47,20 +49,17 @@ public class DomainOwnershipImExporter
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<DomainOwnership> getEntityClass() {
|
public Class<DomainOwnership> getEntityClass() {
|
||||||
|
|
||||||
return DomainOwnership.class;
|
return DomainOwnership.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
protected void saveImportedEntity(final DomainOwnership entity) {
|
protected void saveImportedEntity(final DomainOwnership entity) {
|
||||||
|
|
||||||
entityManager.persist(entity);
|
entityManager.persist(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
||||||
|
|
||||||
final Set<Class<? extends Exportable>> classes = new HashSet<>();
|
final Set<Class<? extends Exportable>> classes = new HashSet<>();
|
||||||
classes.add(CcmApplication.class);
|
classes.add(CcmApplication.class);
|
||||||
classes.add(Domain.class);
|
classes.add(Domain.class);
|
||||||
|
|
@ -68,4 +67,26 @@ public class DomainOwnershipImExporter
|
||||||
return classes;
|
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 org.libreccm.imexport.Processes;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
@ -45,16 +46,31 @@ public class ResourceTypeImExporter
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void saveImportedEntity(final ResourceType entity) {
|
protected void saveImportedEntity(final ResourceType entity) {
|
||||||
|
|
||||||
repository.save(entity);
|
repository.save(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
||||||
|
|
||||||
return Collections.emptySet();
|
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
|
* containers usually create a {@link java.lang.reflect.Proxy} class and
|
||||||
* there is no portable way to unproxy a class.
|
* there is no portable way to unproxy a class.
|
||||||
*
|
*
|
||||||
*
|
|
||||||
* @return A {@link Set} of exportable entity classes which should be
|
* @return A {@link Set} of exportable entity classes which should be
|
||||||
* processed before the entities which are processed by this
|
* processed before the entities which are processed by this
|
||||||
* implementation. If the implementation has no dependencies an
|
* implementation. If the implementation has no dependencies an
|
||||||
|
|
@ -72,7 +71,6 @@ public abstract class AbstractEntityImExporter<T extends Exportable> {
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
public T importEntity(final String data) throws ImportExpection {
|
public T importEntity(final String data) throws ImportExpection {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final T entity = objectMapper.readValue(data, getEntityClass());
|
final T entity = objectMapper.readValue(data, getEntityClass());
|
||||||
saveImportedEntity(entity);
|
saveImportedEntity(entity);
|
||||||
|
|
@ -80,13 +78,26 @@ public abstract class AbstractEntityImExporter<T extends Exportable> {
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
throw new ImportExpection(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)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
public String exportEntity(final Exportable entity) throws ExportException {
|
public String exportEntity(final Exportable entity) throws ExportException {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
final T export = reloadEntity((T) entity);
|
||||||
try {
|
try {
|
||||||
return objectMapper.writeValueAsString(entity);
|
return objectMapper.writeValueAsString(export);
|
||||||
} catch (JsonProcessingException ex) {
|
} catch (JsonProcessingException ex) {
|
||||||
throw new ExportException(String.format(
|
throw new ExportException(String.format(
|
||||||
"Failed to export entity \"%s\" of type \"%s\".",
|
"Failed to export entity \"%s\" of type \"%s\".",
|
||||||
|
|
@ -94,9 +105,17 @@ public abstract class AbstractEntityImExporter<T extends Exportable> {
|
||||||
getEntityClass().getName()),
|
getEntityClass().getName()),
|
||||||
ex);
|
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 org.libreccm.imexport.Processes;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
|
@ -53,16 +54,27 @@ public class GroupImExporter extends AbstractEntityImExporter<Group> {
|
||||||
@Override
|
@Override
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
protected void saveImportedEntity(final Group entity) {
|
protected void saveImportedEntity(final Group entity) {
|
||||||
|
|
||||||
entity.setPartyId(0);
|
entity.setPartyId(0);
|
||||||
// groupRepository.save(entity);
|
|
||||||
entityManager.persist(entity);
|
entityManager.persist(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
||||||
|
|
||||||
return Collections.emptySet();
|
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
|
@Entity
|
||||||
@Table(name = "GROUP_MEMBERSHIPS", schema = DB_SCHEMA)
|
@Table(name = "GROUP_MEMBERSHIPS", schema = DB_SCHEMA)
|
||||||
@NamedQueries({
|
@NamedQueries({
|
||||||
@NamedQuery(name = "GroupMembership.findByUuid",
|
@NamedQuery(
|
||||||
query = "SELECT m FROM GroupMembership m WHERE m.uuid = :uuid"),
|
name = "GroupMembership.findById",
|
||||||
@NamedQuery(name = "GroupMembership.findByGroupAndUser",
|
query
|
||||||
query = "SELECT m FROM GroupMembership m "
|
= "SELECT m FROM GroupMembership m WHERE m.membershipId = :membershipId"
|
||||||
+ "WHERE m.member = :member AND m.group = :group")})
|
),
|
||||||
|
@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)
|
@XmlRootElement(name = "group-membership", namespace = CORE_XML_NS)
|
||||||
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class,
|
@JsonIdentityInfo(
|
||||||
property = "uuid")
|
generator = ObjectIdGenerators.PropertyGenerator.class,
|
||||||
|
property = "uuid"
|
||||||
|
)
|
||||||
public class GroupMembership implements Serializable, Exportable {
|
public class GroupMembership implements Serializable, Exportable {
|
||||||
|
|
||||||
private static final long serialVersionUID = 83192968306850665L;
|
private static final long serialVersionUID = 83192968306850665L;
|
||||||
|
|
|
||||||
|
|
@ -23,10 +23,12 @@ import org.libreccm.imexport.Exportable;
|
||||||
import org.libreccm.imexport.Processes;
|
import org.libreccm.imexport.Processes;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.NoResultException;
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -49,7 +51,6 @@ public class GroupMembershipImExporter
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
||||||
|
|
||||||
final Set<Class<? extends Exportable>> entities = new HashSet<>();
|
final Set<Class<? extends Exportable>> entities = new HashSet<>();
|
||||||
entities.add(User.class);
|
entities.add(User.class);
|
||||||
entities.add(Group.class);
|
entities.add(Group.class);
|
||||||
|
|
@ -60,9 +61,30 @@ public class GroupMembershipImExporter
|
||||||
@Override
|
@Override
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
protected void saveImportedEntity(final GroupMembership entity) {
|
protected void saveImportedEntity(final GroupMembership entity) {
|
||||||
|
|
||||||
entity.setMembershipId(0);
|
entity.setMembershipId(0);
|
||||||
entityManager.persist(entity);
|
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 org.libreccm.imexport.Processes;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
|
@ -35,7 +36,7 @@ import javax.inject.Inject;
|
||||||
*/
|
*/
|
||||||
@RequestScoped
|
@RequestScoped
|
||||||
@Processes(Permission.class)
|
@Processes(Permission.class)
|
||||||
public class PermissionImExporter extends AbstractEntityImExporter<Permission>{
|
public class PermissionImExporter extends AbstractEntityImExporter<Permission> {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private PermissionRepository permissionRepository;
|
private PermissionRepository permissionRepository;
|
||||||
|
|
@ -47,19 +48,29 @@ public class PermissionImExporter extends AbstractEntityImExporter<Permission>{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void saveImportedEntity(final Permission entity) {
|
protected void saveImportedEntity(final Permission entity) {
|
||||||
|
|
||||||
permissionRepository.save(entity);
|
permissionRepository.save(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
||||||
|
|
||||||
final Set<Class<? extends Exportable>> classes = new HashSet<>();
|
final Set<Class<? extends Exportable>> classes = new HashSet<>();
|
||||||
classes.add(Role.class);
|
classes.add(Role.class);
|
||||||
|
|
||||||
return classes;
|
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,24 +18,38 @@
|
||||||
*/
|
*/
|
||||||
package org.libreccm.security;
|
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.AbstractEntityImExporter;
|
||||||
import org.libreccm.imexport.ExportException;
|
import org.libreccm.imexport.ExportException;
|
||||||
import org.libreccm.imexport.Exportable;
|
import org.libreccm.imexport.Exportable;
|
||||||
import org.libreccm.imexport.Processes;
|
import org.libreccm.imexport.Processes;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.enterprise.context.Dependent;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exporter/Importer for {@link Role}s.
|
* Exporter/Importer for {@link Role}s.
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
*/
|
*/
|
||||||
|
@Dependent
|
||||||
@Processes(Role.class)
|
@Processes(Role.class)
|
||||||
public class RoleImExporter extends AbstractEntityImExporter<Role> {
|
public class RoleImExporter extends AbstractEntityImExporter<Role> {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LogManager.getLogger(
|
||||||
|
RoleImExporter.class);
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private EntityManager entityManager;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private RoleRepository roleRepository;
|
private RoleRepository roleRepository;
|
||||||
|
|
||||||
|
|
@ -44,18 +58,45 @@ public class RoleImExporter extends AbstractEntityImExporter<Role> {
|
||||||
return Role.class;
|
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
|
@Override
|
||||||
protected void saveImportedEntity(final Role entity) {
|
protected void saveImportedEntity(final Role entity) {
|
||||||
|
|
||||||
roleRepository.save(entity);
|
roleRepository.save(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
||||||
|
|
||||||
return Collections.emptySet();
|
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
|
@Entity
|
||||||
@Table(name = "ROLE_MEMBERSHIPS", schema = DB_SCHEMA)
|
@Table(name = "ROLE_MEMBERSHIPS", schema = DB_SCHEMA)
|
||||||
@NamedQueries({
|
@NamedQueries({
|
||||||
@NamedQuery(name = "RoleMembership.findByUuid",
|
@NamedQuery(
|
||||||
query = "SELECT m FROM RoleMembership m WHERE m.uuid = :uuid"),
|
name = "RoleMembership.findById",
|
||||||
@NamedQuery(name = "RoleMembership.findByRoleAndMember",
|
query
|
||||||
query = "SELECT m FROM RoleMembership m "
|
= "SELECT m FROM RoleMembership m WHERE m.membershipId = :membershipId"
|
||||||
+ "WHERE m.member = :member AND m.role = :role")
|
),
|
||||||
|
@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)
|
@XmlRootElement(name = "role-membership", namespace = CORE_XML_NS)
|
||||||
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class,
|
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class,
|
||||||
|
|
|
||||||
|
|
@ -23,10 +23,12 @@ import org.libreccm.imexport.Exportable;
|
||||||
import org.libreccm.imexport.Processes;
|
import org.libreccm.imexport.Processes;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.NoResultException;
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -49,13 +51,11 @@ public class RoleMembershipImExporter
|
||||||
@Override
|
@Override
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
protected void saveImportedEntity(final RoleMembership entity) {
|
protected void saveImportedEntity(final RoleMembership entity) {
|
||||||
|
|
||||||
entityManager.persist(entity);
|
entityManager.persist(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
||||||
|
|
||||||
final Set<Class<? extends Exportable>> classes = new HashSet<>();
|
final Set<Class<? extends Exportable>> classes = new HashSet<>();
|
||||||
classes.add(User.class);
|
classes.add(User.class);
|
||||||
classes.add(Group.class);
|
classes.add(Group.class);
|
||||||
|
|
@ -64,4 +64,25 @@ public class RoleMembershipImExporter
|
||||||
return classes;
|
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 org.libreccm.imexport.Processes;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
|
@ -53,7 +54,6 @@ public class UserImExporter extends AbstractEntityImExporter<User> {
|
||||||
@Override
|
@Override
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
protected void saveImportedEntity(final User entity) {
|
protected void saveImportedEntity(final User entity) {
|
||||||
|
|
||||||
// Reset partyId.
|
// Reset partyId.
|
||||||
entity.setPartyId(0);
|
entity.setPartyId(0);
|
||||||
// userRepository.save(entity);
|
// userRepository.save(entity);
|
||||||
|
|
@ -62,8 +62,21 @@ public class UserImExporter extends AbstractEntityImExporter<User> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
||||||
|
|
||||||
return Collections.emptySet();
|
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;
|
package org.libreccm.ui.admin.imexport;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.time.format.DateTimeFormatter;
|
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>
|
* @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;
|
private String name;
|
||||||
|
|
||||||
|
|
@ -92,10 +91,10 @@ public class ImExportTask implements Comparable<ImExportTask> {
|
||||||
if (obj == null) {
|
if (obj == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!(obj instanceof ImExportTask)) {
|
if (!(obj instanceof ImExportTaskStatus)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final ImExportTask other = (ImExportTask) obj;
|
final ImExportTaskStatus other = (ImExportTaskStatus) obj;
|
||||||
if (!other.canEqual(this)) {
|
if (!other.canEqual(this)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -106,15 +105,15 @@ public class ImExportTask implements Comparable<ImExportTask> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canEqual(final Object obj) {
|
public boolean canEqual(final Object obj) {
|
||||||
return obj instanceof ImExportTask;
|
return obj instanceof ImExportTaskStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(final ImExportTask other) {
|
public int compareTo(final ImExportTaskStatus other) {
|
||||||
return Comparator
|
return Comparator
|
||||||
.nullsFirst(Comparator
|
.nullsFirst(Comparator
|
||||||
.comparing(ImExportTask::getName)
|
.comparing(ImExportTaskStatus::getName)
|
||||||
.thenComparing(ImExportTask::getStarted)
|
.thenComparing(ImExportTaskStatus::getStarted)
|
||||||
)
|
)
|
||||||
.compare(this, other);
|
.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.AsyncResult;
|
||||||
import javax.ejb.Asynchronous;
|
import javax.ejb.Asynchronous;
|
||||||
|
import javax.ejb.Singleton;
|
||||||
import javax.ejb.Stateless;
|
import javax.ejb.Stateless;
|
||||||
import javax.ejb.TransactionAttribute;
|
import javax.ejb.TransactionAttribute;
|
||||||
import javax.ejb.TransactionAttributeType;
|
import javax.ejb.TransactionAttributeType;
|
||||||
|
import javax.enterprise.context.ApplicationScoped;
|
||||||
|
import javax.enterprise.event.ObservesAsync;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
|
|
@ -36,29 +39,45 @@ import javax.transaction.Transactional;
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
*/
|
*/
|
||||||
@Stateless
|
@ApplicationScoped
|
||||||
public class ImExportTasks {
|
public class ImExportTasks {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private ImportExport importExport;
|
private ImportExport importExport;
|
||||||
|
|
||||||
@Asynchronous
|
// @Asynchronous
|
||||||
@Transactional(Transactional.TxType.REQUIRES_NEW)
|
// @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
|
||||||
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
|
// public Future<?> startExport(
|
||||||
public Future<?> startExport(
|
// final Collection<Exportable> entities,
|
||||||
final Collection<Exportable> entities,
|
// final String exportName
|
||||||
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);
|
importExport.exportEntities(entities, exportName);
|
||||||
return new AsyncResult<>(null);
|
task.getStatus().setStatus(ImExportTaskStatusEnum.FINISHED);
|
||||||
|
return task;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Asynchronous
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
@Transactional(Transactional.TxType.REQUIRES_NEW)
|
public void importEntitites(@ObservesAsync final ImExportTaskStatus task) {
|
||||||
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
|
final String importName = task.getName();
|
||||||
public Future<?> startImport(final String importName) {
|
|
||||||
importExport.importEntities(importName);
|
importExport.importEntities(importName);
|
||||||
return new AsyncResult<>(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,23 +18,22 @@
|
||||||
*/
|
*/
|
||||||
package org.libreccm.ui.admin.imexport;
|
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.Exportable;
|
||||||
import org.libreccm.imexport.ImportExport;
|
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
import java.util.concurrent.Future;
|
|
||||||
|
|
||||||
import javax.ejb.AsyncResult;
|
|
||||||
import javax.ejb.Asynchronous;
|
|
||||||
import javax.ejb.Schedule;
|
import javax.ejb.Schedule;
|
||||||
import javax.enterprise.context.ApplicationScoped;
|
import javax.enterprise.context.ApplicationScoped;
|
||||||
|
import javax.enterprise.event.Event;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
|
|
@ -51,34 +50,47 @@ import javax.transaction.Transactional;
|
||||||
@Named("ImportExportTaskManager")
|
@Named("ImportExportTaskManager")
|
||||||
public class ImportExportTaskManager {
|
public class ImportExportTaskManager {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LogManager.getLogger(
|
||||||
|
ImportExportTaskManager.class
|
||||||
|
);
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private EntityManager entityManager;
|
private EntityManager entityManager;
|
||||||
|
|
||||||
@Inject
|
@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() {
|
public ImportExportTaskManager() {
|
||||||
exportTasks = new TreeSet<>(
|
exportTasks = new TreeSet<>(
|
||||||
Comparator.comparing(
|
Comparator.comparing(
|
||||||
ImExportTask::getStarted)
|
ExportTaskStatus::getStarted)
|
||||||
.thenComparing(ImExportTask::getName)
|
.thenComparing(ExportTaskStatus::getName)
|
||||||
);
|
);
|
||||||
importTasks = new TreeSet<>(
|
importTasks = new TreeSet<>(
|
||||||
Comparator.comparing(
|
Comparator.comparing(
|
||||||
ImExportTask::getStarted)
|
ImportTaskStatus::getStarted)
|
||||||
.thenComparing(ImExportTask::getName)
|
.thenComparing(ImportTaskStatus::getName)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SortedSet<ImExportTask> getExportTasks() {
|
public SortedSet<ExportTaskStatus> getExportTasks() {
|
||||||
return Collections.unmodifiableSortedSet(exportTasks);
|
return Collections.unmodifiableSortedSet(exportTasks);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SortedSet<ImExportTask> getImportTasks() {
|
public SortedSet<ImportTaskStatus> getImportTasks() {
|
||||||
return Collections.unmodifiableSortedSet(importTasks);
|
return Collections.unmodifiableSortedSet(importTasks);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -96,20 +108,24 @@ public class ImportExportTaskManager {
|
||||||
entities.addAll(entitiesOfType);
|
entities.addAll(entitiesOfType);
|
||||||
}
|
}
|
||||||
|
|
||||||
final ImExportTask task = new ImExportTask();
|
final ExportTaskStatus taskStatus = new ExportTaskStatus();
|
||||||
task.setName(exportName);
|
taskStatus.setName(exportName);
|
||||||
task.setStarted(LocalDateTime.now());
|
taskStatus.setStarted(LocalDateTime.now());
|
||||||
final Future<?> status = imExportTasks.startExport(
|
// final Future<?> status = imExportTasks.startExport(
|
||||||
entities, exportName
|
// entities, exportName
|
||||||
);
|
// );
|
||||||
task.setStatus(status);
|
exportTaskSender.fireAsync(
|
||||||
exportTasks.add(task);
|
new ExportTask(exportName, LocalDate.now(), entities, taskStatus)
|
||||||
|
).handle((task , ex) -> handleExportTaskResult(task, ex, taskStatus));
|
||||||
|
|
||||||
|
taskStatus.setStatus(ImExportTaskStatusEnum.RUNNING);
|
||||||
|
exportTasks.add(taskStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
// public void exportEntities(
|
// public void exportEntities(
|
||||||
// final Collection<Exportable> entities, final String exportName
|
// final Collection<Exportable> entities, final String exportName
|
||||||
// ) {
|
// ) {
|
||||||
// final ImExportTask task = new ImExportTask();
|
// final ImExportTaskStatus task = new ImExportTaskStatus();
|
||||||
// task.setName(exportName);
|
// task.setName(exportName);
|
||||||
// task.setStarted(LocalDate.now());
|
// task.setStarted(LocalDate.now());
|
||||||
// final Future<?> status = startExport(entities, exportName);
|
// final Future<?> status = startExport(entities, exportName);
|
||||||
|
|
@ -117,21 +133,22 @@ public class ImportExportTaskManager {
|
||||||
// exportTasks.add(task);
|
// exportTasks.add(task);
|
||||||
// }
|
// }
|
||||||
public void importEntities(final String importName) {
|
public void importEntities(final String importName) {
|
||||||
final ImExportTask task = new ImExportTask();
|
// final ImExportTaskStatus task = new ImExportTaskStatus();
|
||||||
task.setName(importName);
|
// task.setName(importName);
|
||||||
task.setStarted(LocalDateTime.now());
|
// task.setStarted(LocalDateTime.now());
|
||||||
final Future<?> status = imExportTasks.startImport(importName);
|
// final Future<?> status = imExportTasks.startImport(importName);
|
||||||
task.setStatus(status);
|
// task.setStatus(status);
|
||||||
importTasks.add(task);
|
// importTasks.add(task);
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Schedule(hour = "*", minute = "*/5", persistent = false)
|
@Schedule(hour = "*", minute = "*/5", persistent = false)
|
||||||
protected void removeFinishedTasks() {
|
protected void removeFinishedTasks() {
|
||||||
exportTasks.removeIf(ImExportTask::isDone);
|
exportTasks.removeIf(taskStatus -> taskStatus.getStatus() == ImExportTaskStatusEnum.FINISHED);
|
||||||
importTasks.removeIf(ImExportTask::isDone);
|
// importTasks.removeIf(taskStatus -> taskStatus.getStatus() == ImExportTaskStatusEnum.FINISHED);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cancelTask(final ImExportTask task) {
|
public void cancelTask(final ImExportTaskStatus task) {
|
||||||
task.cancel();
|
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 org.libreccm.imexport.Processes;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
|
@ -50,14 +51,26 @@ public class ApplicationImExporter
|
||||||
@Override
|
@Override
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
protected void saveImportedEntity(final CcmApplication entity) {
|
protected void saveImportedEntity(final CcmApplication entity) {
|
||||||
|
|
||||||
applicationRepository.save(entity);
|
applicationRepository.save(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
||||||
|
|
||||||
return Collections.emptySet();
|
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 org.libreccm.imexport.Processes;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
|
@ -51,7 +52,6 @@ public class AssignableTaskImExporter
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
||||||
|
|
||||||
final Set<Class<? extends Exportable>> entities = new HashSet<>();
|
final Set<Class<? extends Exportable>> entities = new HashSet<>();
|
||||||
entities.add(Workflow.class);
|
entities.add(Workflow.class);
|
||||||
|
|
||||||
|
|
@ -61,8 +61,21 @@ public class AssignableTaskImExporter
|
||||||
@Override
|
@Override
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
protected void saveImportedEntity(final AssignableTask entity) {
|
protected void saveImportedEntity(final AssignableTask entity) {
|
||||||
|
|
||||||
assignableTaskRepository.save(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,6 +37,8 @@ import javax.persistence.GenerationType;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.JoinColumn;
|
import javax.persistence.JoinColumn;
|
||||||
import javax.persistence.ManyToOne;
|
import javax.persistence.ManyToOne;
|
||||||
|
import javax.persistence.NamedQueries;
|
||||||
|
import javax.persistence.NamedQuery;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -46,8 +48,28 @@ import javax.persistence.Table;
|
||||||
*/
|
*/
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "WORKFLOW_TASK_ASSIGNMENTS", schema = DB_SCHEMA)
|
@Table(name = "WORKFLOW_TASK_ASSIGNMENTS", schema = DB_SCHEMA)
|
||||||
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class,
|
@NamedQueries({
|
||||||
property = "customAssignId")
|
@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 {
|
public class TaskAssignment implements Serializable, Exportable {
|
||||||
|
|
||||||
private static final long serialVersionUID = -4427537363301565707L;
|
private static final long serialVersionUID = -4427537363301565707L;
|
||||||
|
|
@ -96,7 +118,6 @@ public class TaskAssignment implements Serializable, Exportable {
|
||||||
this.uuid = uuid;
|
this.uuid = uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public AssignableTask getTask() {
|
public AssignableTask getTask() {
|
||||||
return task;
|
return task;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,11 +23,13 @@ import org.libreccm.imexport.Exportable;
|
||||||
import org.libreccm.imexport.Processes;
|
import org.libreccm.imexport.Processes;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.NoResultException;
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -46,14 +48,12 @@ public class TaskAssignmentImExporter
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<TaskAssignment> getEntityClass() {
|
public Class<TaskAssignment> getEntityClass() {
|
||||||
|
|
||||||
return TaskAssignment.class;
|
return TaskAssignment.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
protected void saveImportedEntity(final TaskAssignment entity) {
|
protected void saveImportedEntity(final TaskAssignment entity) {
|
||||||
|
|
||||||
entityManager.persist(entity);
|
entityManager.persist(entity);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -66,4 +66,26 @@ public class TaskAssignmentImExporter
|
||||||
|
|
||||||
return classes;
|
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 org.libreccm.imexport.Processes;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
|
@ -55,12 +56,25 @@ public class TaskCommentImExporter extends AbstractEntityImExporter<TaskComment>
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
||||||
|
|
||||||
final Set<Class<? extends Exportable>> classes = new HashSet<>();
|
final Set<Class<? extends Exportable>> classes = new HashSet<>();
|
||||||
classes.add(AssignableTask.class);
|
classes.add(AssignableTask.class);
|
||||||
|
|
||||||
return classes;
|
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.Id;
|
||||||
import javax.persistence.JoinColumn;
|
import javax.persistence.JoinColumn;
|
||||||
import javax.persistence.ManyToOne;
|
import javax.persistence.ManyToOne;
|
||||||
|
import javax.persistence.NamedQueries;
|
||||||
|
import javax.persistence.NamedQuery;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -43,8 +45,28 @@ import javax.persistence.Table;
|
||||||
*/
|
*/
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "WORKFLOW_TASK_DEPENDENCIES", schema = CoreConstants.DB_SCHEMA)
|
@Table(name = "WORKFLOW_TASK_DEPENDENCIES", schema = CoreConstants.DB_SCHEMA)
|
||||||
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class,
|
@NamedQueries({
|
||||||
property = "uuid")
|
@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 {
|
public class TaskDependency implements Serializable, Exportable {
|
||||||
|
|
||||||
private static final long serialVersionUID = -4383255770131633943L;
|
private static final long serialVersionUID = -4383255770131633943L;
|
||||||
|
|
|
||||||
|
|
@ -23,11 +23,13 @@ import org.libreccm.imexport.Exportable;
|
||||||
import org.libreccm.imexport.Processes;
|
import org.libreccm.imexport.Processes;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.NoResultException;
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -52,19 +54,36 @@ public class TaskDependencyImExporter
|
||||||
@Override
|
@Override
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
protected void saveImportedEntity(final TaskDependency entity) {
|
protected void saveImportedEntity(final TaskDependency entity) {
|
||||||
|
|
||||||
entityManager.persist(entity);
|
entityManager.persist(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
||||||
|
|
||||||
final Set<Class<? extends Exportable>> classes = new HashSet<>();
|
final Set<Class<? extends Exportable>> classes = new HashSet<>();
|
||||||
classes.add(AssignableTask.class);
|
classes.add(AssignableTask.class);
|
||||||
|
|
||||||
return classes;
|
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 org.libreccm.imexport.Processes;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
|
@ -50,14 +51,26 @@ public class WorkflowImExporter extends AbstractEntityImExporter<Workflow> {
|
||||||
@Override
|
@Override
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
protected void saveImportedEntity(final Workflow entity) {
|
protected void saveImportedEntity(final Workflow entity) {
|
||||||
|
|
||||||
workflowRepository.save(entity);
|
workflowRepository.save(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
protected Set<Class<? extends Exportable>> getRequiredEntities() {
|
||||||
|
|
||||||
return Collections.emptySet();
|
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>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<c:forEach items="#{ImportExportTaskManager.exportTasks}" var="task">
|
<c:forEach items="#{ImportExportTaskManager.exportTasks}"
|
||||||
|
var="task">
|
||||||
<tr>
|
<tr>
|
||||||
<td>#{task.name}</td>
|
<td>#{task.name}</td>
|
||||||
<td>#{task.started}</td>
|
<td>#{task.started}</td>
|
||||||
<td>
|
<td>#{task.status}</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>
|
<td>
|
||||||
<a class="btn btn-warning" href="#">
|
<a class="btn btn-warning" href="#">
|
||||||
#{AdminMessages['imexport.activeexports.table.columns.actions.button_label']}
|
#{AdminMessages['imexport.activeexports.table.columns.actions.button_label']}
|
||||||
|
|
@ -135,7 +127,8 @@
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<c:forEach items="#{ImportExportTaskManager.importTasks}" var="task">
|
<c:forEach items="#{ImportExportTaskManager.importTasks}"
|
||||||
|
var="task">
|
||||||
<tr>
|
<tr>
|
||||||
<td>#{task.name}</td>
|
<td>#{task.name}</td>
|
||||||
<td>#{task.started}</td>
|
<td>#{task.started}</td>
|
||||||
|
|
|
||||||
|
|
@ -23,9 +23,10 @@ import org.libreccm.imexport.Exportable;
|
||||||
import org.libreccm.imexport.Processes;
|
import org.libreccm.imexport.Processes;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.faces.bean.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
|
|
@ -45,7 +46,7 @@ public class BlobObjectImExporter extends AbstractEntityImExporter<BlobObject> {
|
||||||
private BlobObjectRepository blobObjectRepository;
|
private BlobObjectRepository blobObjectRepository;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Class<BlobObject> getEntityClass() {
|
public Class<BlobObject> getEntityClass() {
|
||||||
return BlobObject.class;
|
return BlobObject.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -61,4 +62,18 @@ public class BlobObjectImExporter extends AbstractEntityImExporter<BlobObject> {
|
||||||
return Collections.emptySet();
|
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 org.libreccm.imexport.Processes;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Im/Exporter for importing and exporting {@code File}s from the
|
* Im/Exporter for importing and exporting {@code File}s from the system into a
|
||||||
* system into a specified file and the other way around.
|
* specified file and the other way around.
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
|
* @author <a href="mailto:tosmers@uni-bremen.de">Tobias Osmers</a>
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</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;
|
private FileRepository fileRepository;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Class<File> getEntityClass() {
|
public Class<File> getEntityClass() {
|
||||||
return File.class;
|
return File.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -61,5 +61,18 @@ public class FileImExporter extends AbstractEntityImExporter<File> {
|
||||||
return Collections.emptySet();
|
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 org.libreccm.imexport.Processes;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.faces.bean.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
|
|
@ -43,7 +44,7 @@ public class FolderImExporter extends AbstractResourceImExporter<Folder> {
|
||||||
private FolderRepository folderRepository;
|
private FolderRepository folderRepository;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Class<Folder> getEntityClass() {
|
public Class<Folder> getEntityClass() {
|
||||||
return Folder.class;
|
return Folder.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -58,4 +59,18 @@ public class FolderImExporter extends AbstractResourceImExporter<Folder> {
|
||||||
return Collections.emptySet();
|
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 org.libreccm.imexport.Processes;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.faces.bean.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -40,7 +41,7 @@ public class RepositoryImExporter extends AbstractEntityImExporter<Repository> {
|
||||||
private RepositoryRepository repositoryRepository;
|
private RepositoryRepository repositoryRepository;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Class<Repository> getEntityClass() {
|
public Class<Repository> getEntityClass() {
|
||||||
return Repository.class;
|
return Repository.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -54,6 +55,18 @@ public class RepositoryImExporter extends AbstractEntityImExporter<Repository> {
|
||||||
return Collections.emptySet();
|
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