[TRUNK][UPDATE]
- renames ExportHelper class to CoreExport, to specify that it is used with core - renames MainConverter class to CoreConverter, to specify that it is used with core - sorts ng-Categories after its conversion to garantie that parent categories can be imported befor their childs git-svn-id: https://svn.libreccm.org/ccm/trunk@4869 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
7cf4927da8
commit
717a4c324b
|
|
@ -42,7 +42,7 @@ import java.util.ArrayList;
|
|||
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a>
|
||||
* @version created on 25.07.2016
|
||||
*/
|
||||
class ExportHelper {
|
||||
class CoreExporter {
|
||||
|
||||
private static String pathName;
|
||||
private static boolean indentation = false;
|
||||
|
|
@ -109,7 +109,7 @@ class ExportHelper {
|
|||
CategoryMarshaller();
|
||||
categoryMarshaller.prepare(Format.XML, pathName,
|
||||
"categories", indentation);
|
||||
categoryMarshaller.exportList(NgCollection.getSortedCategories());
|
||||
categoryMarshaller.exportList(NgCollection.sortedCategories);
|
||||
System.out.printf("\t\tdone.\n");
|
||||
}
|
||||
|
||||
|
|
@ -176,6 +176,6 @@ class ExportHelper {
|
|||
"permissions", indentation);
|
||||
permissionMarshaller.exportList(new ArrayList<>
|
||||
(NgCollection.permissions.values()));
|
||||
System.out.printf("\t\tdone.\n");
|
||||
System.out.printf("\tdone.\n");
|
||||
}
|
||||
}
|
||||
|
|
@ -18,7 +18,7 @@
|
|||
*/
|
||||
package com.arsdigita.portation.cmd;
|
||||
|
||||
import com.arsdigita.portation.conversion.MainConverter;
|
||||
import com.arsdigita.portation.conversion.CoreConverter;
|
||||
import com.arsdigita.util.cmd.Program;
|
||||
import org.apache.commons.cli.CommandLine;
|
||||
import org.apache.log4j.Logger;
|
||||
|
|
@ -87,6 +87,10 @@ public class ExportCliTool extends Program {
|
|||
export(args);
|
||||
break;
|
||||
|
||||
case "convert":
|
||||
convert();
|
||||
break;
|
||||
|
||||
default:
|
||||
printUsage();
|
||||
break;
|
||||
|
|
@ -109,7 +113,7 @@ public class ExportCliTool extends Program {
|
|||
System.err.printf("module-class: %s\n", moduleClass);
|
||||
final String pathName = args[2];
|
||||
System.err.printf("path: %s\n", pathName);
|
||||
ExportHelper.setPath(pathName);
|
||||
CoreExporter.setPath(pathName);
|
||||
System.err.printf("\n");
|
||||
|
||||
|
||||
|
|
@ -117,79 +121,79 @@ public class ExportCliTool extends Program {
|
|||
switch (moduleClass) {
|
||||
case "categories":
|
||||
convert();
|
||||
ExportHelper.exportCategories();
|
||||
CoreExporter.exportCategories();
|
||||
break;
|
||||
|
||||
case "categorizations":
|
||||
convert();
|
||||
ExportHelper.exportCategorizations();
|
||||
CoreExporter.exportCategorizations();
|
||||
break;
|
||||
|
||||
case "users":
|
||||
convert();
|
||||
ExportHelper.exportUsers();
|
||||
CoreExporter.exportUsers();
|
||||
break;
|
||||
|
||||
case "groups":
|
||||
convert();
|
||||
ExportHelper.exportGroups();
|
||||
CoreExporter.exportGroups();
|
||||
break;
|
||||
|
||||
case "groupMemberships":
|
||||
convert();
|
||||
ExportHelper.exportGroupMemberships();
|
||||
CoreExporter.exportGroupMemberships();
|
||||
break;
|
||||
|
||||
case "roles":
|
||||
convert();
|
||||
ExportHelper.exportRoles();
|
||||
CoreExporter.exportRoles();
|
||||
break;
|
||||
|
||||
case "roleMemberships":
|
||||
convert();
|
||||
ExportHelper.exportRoleMemberships();
|
||||
CoreExporter.exportRoleMemberships();
|
||||
break;
|
||||
|
||||
case "workflowTemplates":
|
||||
convert();
|
||||
ExportHelper.exportWorkflowTemplates();
|
||||
CoreExporter.exportWorkflowTemplates();
|
||||
break;
|
||||
|
||||
case "workflows":
|
||||
convert();
|
||||
ExportHelper.exportWorkflows();
|
||||
CoreExporter.exportWorkflows();
|
||||
break;
|
||||
|
||||
case "assignableTasks":
|
||||
convert();
|
||||
ExportHelper.exportAssignableTasks();
|
||||
CoreExporter.exportAssignableTasks();
|
||||
break;
|
||||
|
||||
case "taskAssignments":
|
||||
convert();
|
||||
ExportHelper.exportTaskAssignments();
|
||||
CoreExporter.exportTaskAssignments();
|
||||
break;
|
||||
|
||||
case "permissions":
|
||||
convert();
|
||||
ExportHelper.exportPermissions();
|
||||
CoreExporter.exportPermissions();
|
||||
break;
|
||||
|
||||
case "all_core":
|
||||
convert();
|
||||
System.out.println("Started exporting all ng-objects...");
|
||||
ExportHelper.exportCategories();
|
||||
ExportHelper.exportCategorizations();
|
||||
ExportHelper.exportUsers();
|
||||
ExportHelper.exportGroups();
|
||||
ExportHelper.exportGroupMemberships();
|
||||
ExportHelper.exportRoles();
|
||||
ExportHelper.exportRoleMemberships();
|
||||
ExportHelper.exportWorkflows();
|
||||
ExportHelper.exportWorkflowTemplates();
|
||||
ExportHelper.exportAssignableTasks();
|
||||
ExportHelper.exportTaskAssignments();
|
||||
ExportHelper.exportPermissions();
|
||||
CoreExporter.exportCategories();
|
||||
CoreExporter.exportCategorizations();
|
||||
CoreExporter.exportUsers();
|
||||
CoreExporter.exportGroups();
|
||||
CoreExporter.exportGroupMemberships();
|
||||
CoreExporter.exportRoles();
|
||||
CoreExporter.exportRoleMemberships();
|
||||
CoreExporter.exportWorkflows();
|
||||
CoreExporter.exportWorkflowTemplates();
|
||||
CoreExporter.exportAssignableTasks();
|
||||
CoreExporter.exportTaskAssignments();
|
||||
CoreExporter.exportPermissions();
|
||||
System.out.println("Finished exports.");
|
||||
System.out.printf("\n");
|
||||
break;
|
||||
|
|
@ -210,7 +214,7 @@ public class ExportCliTool extends Program {
|
|||
try {
|
||||
System.err.println("Started conversions of systems objects to " +
|
||||
"ng-objects...");
|
||||
MainConverter.startConversionToNg();
|
||||
CoreConverter.startConversionToNg();
|
||||
System.err.println("Finished conversions.");
|
||||
System.out.printf("\n");
|
||||
} catch (Exception e) {
|
||||
|
|
|
|||
|
|
@ -25,11 +25,12 @@ import com.arsdigita.portation.conversion.core.security.RoleConversion;
|
|||
import com.arsdigita.portation.conversion.core.security.UserConversion;
|
||||
import com.arsdigita.portation.conversion.core.workflow.AssignableTaskConversion;
|
||||
import com.arsdigita.portation.conversion.core.workflow.WorkflowConversion;
|
||||
import com.arsdigita.portation.modules.core.categorization.Category;
|
||||
import com.arsdigita.portation.modules.core.security.Permission;
|
||||
|
||||
|
||||
/**
|
||||
* This main converter class calls all the conversions from trunk-objects
|
||||
* This core converter class calls all the conversions from trunk-objects
|
||||
* to ng-objects in a specific order to guarantee a correct dependency
|
||||
* recreation in the ng-objects. All the created objects are going to be
|
||||
* stored in maps as <id, object>-pairs in the {@link NgCollection}-class.
|
||||
|
|
@ -37,7 +38,7 @@ import com.arsdigita.portation.modules.core.security.Permission;
|
|||
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a>
|
||||
* @version created on 6/27/16
|
||||
*/
|
||||
public class MainConverter {
|
||||
public class CoreConverter {
|
||||
|
||||
/**
|
||||
* Method, to start all the different converter classes in a specific
|
||||
|
|
@ -51,17 +52,24 @@ public class MainConverter {
|
|||
RoleConversion.convertAll();
|
||||
|
||||
CategoryConversion.convertAll();
|
||||
System.out.println(NgCollection.categories.toString());
|
||||
NgCollection.sortCategories();
|
||||
// Verify categories
|
||||
/*for (Category category : NgCollection.sortedCategories) {
|
||||
System.err.printf("\t\t\tCategory %s with parent category %s\n",
|
||||
category.getName(), category.getParentCategory().getName()
|
||||
);
|
||||
}*/
|
||||
|
||||
|
||||
WorkflowConversion.convertAll();
|
||||
AssignableTaskConversion.convertAll();
|
||||
|
||||
PermissionConversion.convertAll();
|
||||
|
||||
//Verify permissions
|
||||
for(Permission permission : NgCollection.permissions.values()) {
|
||||
// Verify permissions
|
||||
for (Permission permission : NgCollection.permissions.values()) {
|
||||
if (permission.getGrantee() == null) {
|
||||
System.err.printf("MainConverter: Grantee for permission %d " +
|
||||
System.err.printf("CoreConverter: Grantee for permission %d " +
|
||||
"is null.%n", permission.getPermissionId());
|
||||
System.exit(-1);
|
||||
}
|
||||
|
|
@ -33,7 +33,6 @@ import com.arsdigita.portation.modules.core.workflow.Task;
|
|||
import com.arsdigita.portation.modules.core.workflow.TaskAssignment;
|
||||
import com.arsdigita.portation.modules.core.workflow.Workflow;
|
||||
import com.arsdigita.portation.modules.core.workflow.WorkflowTemplate;
|
||||
import com.arsdigita.util.Assert;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
|
@ -66,6 +65,10 @@ public class NgCollection {
|
|||
|
||||
public static Map<Long, Permission> permissions = new HashMap<>();
|
||||
|
||||
// if lists need to be sorted in specific way to work with import
|
||||
private static ArrayList<Category> unsortedCategories;
|
||||
public static ArrayList<Category> sortedCategories;
|
||||
|
||||
/**
|
||||
* Private constructor to prevent the instantiation of this class.
|
||||
*/
|
||||
|
|
@ -79,39 +82,47 @@ public class NgCollection {
|
|||
* to add them to the sorted list. After being added to sorted the
|
||||
* category will be removed from the unsorted list and therefore ignored
|
||||
* in this foreach run.
|
||||
*
|
||||
* @return a sorted array list of categories
|
||||
*/
|
||||
public static ArrayList<Category> getSortedCategories() {
|
||||
ArrayList<Category> unsorted = new ArrayList<>(categories.values());
|
||||
ArrayList<Category> sorted = new ArrayList<>(unsorted.size());
|
||||
static void sortCategories() {
|
||||
unsortedCategories = new ArrayList<>(categories.values());
|
||||
sortedCategories = new ArrayList<>(unsortedCategories.size());
|
||||
|
||||
for (Category anUnsorted : unsorted) {
|
||||
addTree(unsorted, sorted, anUnsorted);
|
||||
System.err.printf("\tSorting categorizes...\n");
|
||||
int count = 1;
|
||||
for (Category anUnsorted : unsortedCategories) {
|
||||
System.err.printf("\t\tNumber: %d\n", count++);
|
||||
System.err.printf("\t\tCategory: %s\n", anUnsorted.getName());
|
||||
add(anUnsorted, "\t\t");
|
||||
//System.err.println("");
|
||||
}
|
||||
|
||||
Assert.assertEquals(unsorted.size(), sorted.size());
|
||||
|
||||
return sorted;
|
||||
|
||||
System.err.printf("\tdone. Count: %d\n", sortedCategories.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to recursively add all parent categories before their
|
||||
* childs.
|
||||
*
|
||||
* @param unsorted the unsorted list of categories
|
||||
* @param sorted the sorted list of categories
|
||||
* @param category the current category in the unsorted list
|
||||
*/
|
||||
private static void addTree(ArrayList<Category> unsorted,
|
||||
ArrayList<Category> sorted,
|
||||
Category category) {
|
||||
if (category.getParentCategory() != null
|
||||
&& unsorted.contains(category.getParentCategory())) {
|
||||
addTree(unsorted, sorted, category.getParentCategory());
|
||||
private static void add(Category category, String indent) {
|
||||
Category parent = category.getParentCategory();
|
||||
|
||||
System.err.printf("%s\tHas missing parent?...", indent);
|
||||
if (parent != null && !sortedCategories.contains(parent)) {
|
||||
System.err.println("YES.");
|
||||
System.err.printf("%s\tParent: %s\n", indent, parent.getName());
|
||||
|
||||
add(parent, String.format("%s\t", indent));
|
||||
} else {
|
||||
System.err.println("NO.");
|
||||
}
|
||||
|
||||
System.err.printf("%sAdded to sorted list?...", indent);
|
||||
if (!sortedCategories.contains(category)) {
|
||||
sortedCategories.add(category);
|
||||
System.err.println("YES.");
|
||||
} else {
|
||||
System.err.println("NO.");
|
||||
}
|
||||
sorted.add(category);
|
||||
unsorted.remove(category);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,14 +45,15 @@ public class CategoryConversion {
|
|||
* associations in tact.
|
||||
*/
|
||||
public static void convertAll() {
|
||||
System.err.printf("\tFetching categories from database...");
|
||||
List<com.arsdigita.categorization.Category> trunkCategories = com
|
||||
.arsdigita.categorization.Category.getAllObjectCategories();
|
||||
System.err.println("done.");
|
||||
|
||||
System.err.printf("\tConverting categorizes and categorizations...\n");
|
||||
System.err.printf("\tConverting categories and categorizations...\n");
|
||||
createCategoryAndCategorizations(trunkCategories);
|
||||
setRingAssociations(trunkCategories);
|
||||
System.err.printf("\tdone.\n");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -45,9 +45,11 @@ public class GroupConversion {
|
|||
* focusing on keeping all the associations in tact.
|
||||
*/
|
||||
public static void convertAll() {
|
||||
System.err.printf("\tFetching groups from database...");
|
||||
List<com.arsdigita.kernel.Group> trunkGroups,
|
||||
roleGroups = new ArrayList<>();
|
||||
trunkGroups = com.arsdigita.kernel.Group.getAllObjectGroups();
|
||||
System.err.println("done.");
|
||||
|
||||
System.err.printf("\tConverting groups and group memberships...\n");
|
||||
createGroupsAndSetAssociations(trunkGroups);
|
||||
|
|
|
|||
|
|
@ -56,9 +56,11 @@ public class PermissionConversion {
|
|||
* grantee}-{@link Role} has to be recreated separately.
|
||||
*/
|
||||
public static void convertAll() {
|
||||
System.err.printf("\tFetching permissions from database...");
|
||||
List<com.arsdigita.kernel.permissions.Permission> trunkPermissions =
|
||||
com.arsdigita.kernel.permissions.Permission
|
||||
.getAllObjectPermissions();
|
||||
System.err.println("done.");
|
||||
|
||||
System.err.printf("\tConverting permissions...\n");
|
||||
createPermissionsAndSetAssociations(trunkPermissions);
|
||||
|
|
|
|||
|
|
@ -44,8 +44,10 @@ public class RoleConversion {
|
|||
* associations in tact.
|
||||
*/
|
||||
public static void convertAll() {
|
||||
System.err.printf("\tFetching roles from database...");
|
||||
List<com.arsdigita.kernel.Role> trunkRoles = com.arsdigita.kernel
|
||||
.Role.getAllObjectRoles();
|
||||
System.err.println("done.");
|
||||
|
||||
System.err.printf("\tCreating roles and role memberships...\n");
|
||||
createRolesAndSetAssociations(trunkRoles);
|
||||
|
|
|
|||
|
|
@ -38,8 +38,10 @@ public class UserConversion {
|
|||
* creating the equivalent ng-{@link User}s.
|
||||
*/
|
||||
public static void convertAll() {
|
||||
System.err.printf("\tFetching users from database...");
|
||||
List<com.arsdigita.kernel.User> trunkUsers = com.arsdigita.kernel
|
||||
.User.getAllObjectUsers();
|
||||
System.err.println("done.");
|
||||
|
||||
System.err.printf("\tConverting users...\n");
|
||||
// create users
|
||||
|
|
|
|||
|
|
@ -52,8 +52,10 @@ public class AssignableTaskConversion {
|
|||
* to be recreated once all ng-{@link AssignableTask}s have been created.
|
||||
*/
|
||||
public static void convertAll() {
|
||||
System.err.printf("\tFetching assignable tasks from database...");
|
||||
List<com.arsdigita.workflow.simple.UserTask> trunkUserTasks = com
|
||||
.arsdigita.workflow.simple.UserTask.getAllObjectUserTasks();
|
||||
System.err.println("done.");
|
||||
|
||||
System.err.printf("\tConverting assignable tasks and task " +
|
||||
"assignments...\n");
|
||||
|
|
|
|||
|
|
@ -43,8 +43,10 @@ public class WorkflowConversion {
|
|||
* creating the equivalent ng-{@link Workflow}s.
|
||||
*/
|
||||
public static void convertAll() {
|
||||
System.err.printf("\tFetching workflows from database...");
|
||||
List<com.arsdigita.workflow.simple.Workflow> trunkWorkflows =
|
||||
com.arsdigita.workflow.simple.Workflow.getAllObjectWorkflows();
|
||||
System.err.println("done.");
|
||||
|
||||
System.err.printf("\tConverting workflows...\n");
|
||||
createWorkflowAndSetAssociations(trunkWorkflows);
|
||||
|
|
|
|||
|
|
@ -40,9 +40,11 @@ public class WorkflowTemplateConversion {
|
|||
* creating the equivalent ng-{@link WorkflowTemplate}s.
|
||||
*/
|
||||
public static void convertAll() {
|
||||
System.err.printf("\tFetching workflow templates from database...");
|
||||
List<com.arsdigita.workflow.simple.WorkflowTemplate>
|
||||
trunkWorkflowTemplates = com.arsdigita.workflow.simple
|
||||
.WorkflowTemplate.getAllObjectWorkflowTemplates();
|
||||
System.err.println("done.");
|
||||
|
||||
System.err.printf("\tConverting workflow templates...\n");
|
||||
trunkWorkflowTemplates.forEach(WorkflowTemplate::new);
|
||||
|
|
|
|||
Loading…
Reference in New Issue