Bugfix
parent
20ba08580a
commit
f9a129cd39
|
|
@ -29,7 +29,7 @@ public class ContentSectionImExporter
|
|||
private ContentSectionRepository sectionRepository;
|
||||
|
||||
@Override
|
||||
protected Class<ContentSection> getEntityClass() {
|
||||
public Class<ContentSection> getEntityClass() {
|
||||
return ContentSection.class;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ import javax.enterprise.context.RequestScoped;
|
|||
public class ArticleImExporter extends AbstractContentItemImExporter<Article> {
|
||||
|
||||
@Override
|
||||
protected Class<Article> getEntityClass() {
|
||||
public Class<Article> getEntityClass() {
|
||||
return Article.class;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ import javax.enterprise.context.RequestScoped;
|
|||
public class EventImExporter extends AbstractContentItemImExporter<Event> {
|
||||
|
||||
@Override
|
||||
protected Class<Event> getEntityClass() {
|
||||
public Class<Event> getEntityClass() {
|
||||
return Event.class;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ public class MultiPartArticleImExporter
|
|||
extends AbstractContentItemImExporter<MultiPartArticle> {
|
||||
|
||||
@Override
|
||||
protected Class<MultiPartArticle> getEntityClass() {
|
||||
public Class<MultiPartArticle> getEntityClass() {
|
||||
return MultiPartArticle.class;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ import javax.enterprise.context.RequestScoped;
|
|||
public class NewsImExporter extends AbstractContentItemImExporter<News> {
|
||||
|
||||
@Override
|
||||
protected Class<News> getEntityClass() {
|
||||
public Class<News> getEntityClass() {
|
||||
return News.class;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -48,8 +48,7 @@ public class CategorizationImExporter
|
|||
private Instance<CategorizationImExporterDependenciesProvider> dependenciesProviders;
|
||||
|
||||
@Override
|
||||
protected Class<Categorization> getEntityClass() {
|
||||
|
||||
public Class<Categorization> getEntityClass() {
|
||||
return Categorization.class;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ public class CategoryImExporter extends AbstractEntityImExporter<Category> {
|
|||
private CategoryRepository categoryRepository;
|
||||
|
||||
@Override
|
||||
protected Class<Category> getEntityClass() {
|
||||
public Class<Category> getEntityClass() {
|
||||
return Category.class;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ public class DomainImExporter extends AbstractEntityImExporter<Domain> {
|
|||
private DomainRepository domainRepository;
|
||||
|
||||
@Override
|
||||
protected Class<Domain> getEntityClass() {
|
||||
public Class<Domain> getEntityClass() {
|
||||
|
||||
return Domain.class;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ public class DomainOwnershipImExporter
|
|||
private EntityManager entityManager;
|
||||
|
||||
@Override
|
||||
protected Class<DomainOwnership> getEntityClass() {
|
||||
public Class<DomainOwnership> getEntityClass() {
|
||||
|
||||
return DomainOwnership.class;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,8 +39,7 @@ public class ResourceTypeImExporter
|
|||
private ResourceTypeRepository repository;
|
||||
|
||||
@Override
|
||||
protected Class<ResourceType> getEntityClass() {
|
||||
|
||||
public Class<ResourceType> getEntityClass() {
|
||||
return ResourceType.class;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ public abstract class AbstractEntityImExporter<T extends Exportable> {
|
|||
*
|
||||
* @return The Entity class which is handled by the implementation.
|
||||
*/
|
||||
protected abstract Class<T> getEntityClass();
|
||||
public abstract Class<T> getEntityClass();
|
||||
|
||||
/**
|
||||
* A set of entities which should be processed before this implementation is
|
||||
|
|
|
|||
|
|
@ -75,6 +75,23 @@ public class ImportExport {
|
|||
@Any
|
||||
private Instance<AbstractEntityImExporter<?>> imExporters;
|
||||
|
||||
public List<EntityImExporterTreeNode> getExportableEntityTypes() {
|
||||
try {
|
||||
final EntityImExporterTreeManager treeManager
|
||||
= new EntityImExporterTreeManager();
|
||||
final List<EntityImExporterTreeNode> tree = treeManager
|
||||
.generateTree(
|
||||
imExporters
|
||||
.stream()
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
|
||||
return tree;
|
||||
} catch (DependencyException ex) {
|
||||
throw new UnexpectedErrorException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Exports the provided entities. The export will be written to a to the
|
||||
* {@code exports} directory in the CCM files directory. If {@code split} is
|
||||
|
|
@ -151,84 +168,6 @@ public class ImportExport {
|
|||
entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getExportableEntityTypes() {
|
||||
return imExporters
|
||||
.stream()
|
||||
.map(imexporter -> imexporter.getEntityClass().getName())
|
||||
.sorted()
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private JsonArrayBuilder createExportedEntities(
|
||||
final String exportName,
|
||||
final String type,
|
||||
final List<Exportable> entities) {
|
||||
|
||||
final JsonArrayBuilder filesArrayBuilder = Json.createArrayBuilder();
|
||||
|
||||
final Class<? extends Exportable> clazz;
|
||||
try {
|
||||
clazz = (Class<? extends Exportable>) Class.forName(type);
|
||||
} catch (ClassNotFoundException ex) {
|
||||
throw new UnexpectedErrorException(ex);
|
||||
}
|
||||
|
||||
final Instance<AbstractEntityImExporter<?>> instance = imExporters
|
||||
.select(new ProcessesLiteral(clazz));
|
||||
|
||||
final AbstractEntityImExporter<?> imExporter;
|
||||
if (instance.isUnsatisfied()) {
|
||||
throw new UnexpectedErrorException(String.format(
|
||||
"No EntityImExporter for entity type \"%s\" available.",
|
||||
type));
|
||||
} else if (instance.isAmbiguous()) {
|
||||
throw new UnexpectedErrorException(String.format(
|
||||
"Instance reference for EntityImExporter for entity "
|
||||
+ "type \"%s\" is ambiguous.",
|
||||
type));
|
||||
} else {
|
||||
imExporter = instance.get();
|
||||
}
|
||||
|
||||
for (Exportable entity : entities) {
|
||||
|
||||
final String filename = String.format("%s.json", entity.getUuid());
|
||||
final OutputStream outputStream;
|
||||
try {
|
||||
outputStream = ccmFiles.createOutputStream(String.format(
|
||||
"exports/%s/%s/%s",
|
||||
exportName,
|
||||
type,
|
||||
filename));
|
||||
filesArrayBuilder.add(filename);
|
||||
} catch (FileAccessException
|
||||
| InsufficientPermissionsException ex) {
|
||||
throw new UnexpectedErrorException(ex);
|
||||
}
|
||||
|
||||
final String exportedEntity;
|
||||
try {
|
||||
exportedEntity = imExporter.exportEntity(entity);
|
||||
} catch (ExportException ex) {
|
||||
throw new UnexpectedErrorException(ex);
|
||||
}
|
||||
try (final OutputStreamWriter writer = new OutputStreamWriter(
|
||||
outputStream, StandardCharsets.UTF_8)) {
|
||||
|
||||
writer.write(exportedEntity);
|
||||
|
||||
} catch (IOException ex) {
|
||||
throw new UnexpectedErrorException(ex);
|
||||
}
|
||||
// try (JsonWriter writer = Json.createWriter(outputStream)) {
|
||||
// writer.writeObject(exportedEntity);
|
||||
// }
|
||||
}
|
||||
|
||||
return filesArrayBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Imports all entities from the files in the {@link imports} directory
|
||||
|
|
@ -261,15 +200,15 @@ public class ImportExport {
|
|||
throw new UnexpectedErrorException(ex);
|
||||
}
|
||||
|
||||
final List<AbstractEntityImExporter<?>> imExportersList
|
||||
= new ArrayList<>();
|
||||
imExporters.forEach(imExporter -> imExportersList.add(imExporter));
|
||||
|
||||
try {
|
||||
final EntityImExporterTreeManager treeManager
|
||||
= new EntityImExporterTreeManager();
|
||||
final List<EntityImExporterTreeNode> tree = treeManager
|
||||
.generateTree(imExportersList);
|
||||
.generateTree(
|
||||
imExporters
|
||||
.stream()
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
final List<EntityImExporterTreeNode> orderedNodes = treeManager
|
||||
.orderImExporters(tree);
|
||||
|
||||
|
|
@ -347,8 +286,6 @@ public class ImportExport {
|
|||
.lines()
|
||||
.collect(Collectors.joining("\n"));
|
||||
|
||||
// final JsonReader reader = Json.createReader(inputStream);
|
||||
// final JsonObject data = reader.readObject();
|
||||
imExporter.importEntity(data);
|
||||
|
||||
} catch (IOException
|
||||
|
|
@ -380,6 +317,71 @@ public class ImportExport {
|
|||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private JsonArrayBuilder createExportedEntities(
|
||||
final String exportName,
|
||||
final String type,
|
||||
final List<Exportable> entities) {
|
||||
|
||||
final Class<? extends Exportable> clazz;
|
||||
try {
|
||||
clazz = (Class<? extends Exportable>) Class.forName(type);
|
||||
} catch (ClassNotFoundException ex) {
|
||||
throw new UnexpectedErrorException(ex);
|
||||
}
|
||||
|
||||
final Instance<AbstractEntityImExporter<?>> instance = imExporters
|
||||
.select(new ProcessesLiteral(clazz));
|
||||
|
||||
final AbstractEntityImExporter<?> imExporter;
|
||||
if (instance.isUnsatisfied()) {
|
||||
throw new UnexpectedErrorException(String.format(
|
||||
"No EntityImExporter for entity type \"%s\" available.",
|
||||
type));
|
||||
} else if (instance.isAmbiguous()) {
|
||||
throw new UnexpectedErrorException(String.format(
|
||||
"Instance reference for EntityImExporter for entity "
|
||||
+ "type \"%s\" is ambiguous.",
|
||||
type));
|
||||
} else {
|
||||
imExporter = instance.get();
|
||||
}
|
||||
|
||||
final JsonArrayBuilder filesArrayBuilder = Json.createArrayBuilder();
|
||||
for (Exportable entity : entities) {
|
||||
final String filename = String.format("%s.json", entity.getUuid());
|
||||
final OutputStream outputStream;
|
||||
try {
|
||||
outputStream = ccmFiles.createOutputStream(String.format(
|
||||
"exports/%s/%s/%s",
|
||||
exportName,
|
||||
type,
|
||||
filename));
|
||||
filesArrayBuilder.add(filename);
|
||||
} catch (FileAccessException
|
||||
| InsufficientPermissionsException ex) {
|
||||
throw new UnexpectedErrorException(ex);
|
||||
}
|
||||
|
||||
final String exportedEntity;
|
||||
try {
|
||||
exportedEntity = imExporter.exportEntity(entity);
|
||||
} catch (ExportException ex) {
|
||||
throw new UnexpectedErrorException(ex);
|
||||
}
|
||||
try (final OutputStreamWriter writer = new OutputStreamWriter(
|
||||
outputStream, StandardCharsets.UTF_8)) {
|
||||
|
||||
writer.write(exportedEntity);
|
||||
|
||||
} catch (IOException ex) {
|
||||
throw new UnexpectedErrorException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
return filesArrayBuilder;
|
||||
}
|
||||
|
||||
private boolean isImportArchive(final String path) {
|
||||
|
||||
final String manifestPath = String.format("imports/%s/ccm-export.json",
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ public class GroupImExporter extends AbstractEntityImExporter<Group> {
|
|||
private GroupRepository groupRepository;
|
||||
|
||||
@Override
|
||||
protected Class<Group> getEntityClass() {
|
||||
public Class<Group> getEntityClass() {
|
||||
return Group.class;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -43,8 +43,7 @@ public class GroupMembershipImExporter
|
|||
private EntityManager entityManager;
|
||||
|
||||
@Override
|
||||
protected Class<GroupMembership> getEntityClass() {
|
||||
|
||||
public Class<GroupMembership> getEntityClass() {
|
||||
return GroupMembership.class;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ public class PermissionImExporter extends AbstractEntityImExporter<Permission>{
|
|||
private PermissionRepository permissionRepository;
|
||||
|
||||
@Override
|
||||
protected Class<Permission> getEntityClass() {
|
||||
public Class<Permission> getEntityClass() {
|
||||
return Permission.class;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,8 +39,7 @@ public class RoleImExporter extends AbstractEntityImExporter<Role> {
|
|||
private RoleRepository roleRepository;
|
||||
|
||||
@Override
|
||||
protected Class<Role> getEntityClass() {
|
||||
|
||||
public Class<Role> getEntityClass() {
|
||||
return Role.class;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -42,8 +42,7 @@ public class RoleMembershipImExporter
|
|||
private EntityManager entityManager;
|
||||
|
||||
@Override
|
||||
protected Class<RoleMembership> getEntityClass() {
|
||||
|
||||
public Class<RoleMembership> getEntityClass() {
|
||||
return RoleMembership.class;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ public class UserImExporter extends AbstractEntityImExporter<User> {
|
|||
private UserRepository userRepository;
|
||||
|
||||
@Override
|
||||
protected Class<User> getEntityClass() {
|
||||
public Class<User> getEntityClass() {
|
||||
return User.class;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ public class AssignableTaskImExporter
|
|||
private AssignableTaskRepository assignableTaskRepository;
|
||||
|
||||
@Override
|
||||
protected Class<AssignableTask> getEntityClass() {
|
||||
public Class<AssignableTask> getEntityClass() {
|
||||
return AssignableTask.class;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ public class TaskAssignmentImExporter
|
|||
private EntityManager entityManager;
|
||||
|
||||
@Override
|
||||
protected Class<TaskAssignment> getEntityClass() {
|
||||
public Class<TaskAssignment> getEntityClass() {
|
||||
|
||||
return TaskAssignment.class;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ public class TaskCommentImExporter extends AbstractEntityImExporter<TaskComment>
|
|||
private TaskCommentRepository taskCommentRepository;
|
||||
|
||||
@Override
|
||||
protected Class<TaskComment> getEntityClass() {
|
||||
public Class<TaskComment> getEntityClass() {
|
||||
return TaskComment.class;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ public class TaskDependencyImExporter
|
|||
private EntityManager entityManager;
|
||||
|
||||
@Override
|
||||
protected Class<TaskDependency> getEntityClass() {
|
||||
public Class<TaskDependency> getEntityClass() {
|
||||
return TaskDependency.class;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ public class WorkflowImExporter extends AbstractEntityImExporter<Workflow> {
|
|||
private WorkflowRepository workflowRepository;
|
||||
|
||||
@Override
|
||||
protected Class<Workflow> getEntityClass() {
|
||||
public Class<Workflow> getEntityClass() {
|
||||
|
||||
return Workflow.class;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue