[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-94f89814c4df
master
tosmers 2017-07-12 18:17:36 +00:00
parent 7cf4927da8
commit 717a4c324b
12 changed files with 99 additions and 61 deletions

View File

@ -42,7 +42,7 @@ import java.util.ArrayList;
* @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a> * @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a>
* @version created on 25.07.2016 * @version created on 25.07.2016
*/ */
class ExportHelper { class CoreExporter {
private static String pathName; private static String pathName;
private static boolean indentation = false; private static boolean indentation = false;
@ -109,7 +109,7 @@ class ExportHelper {
CategoryMarshaller(); CategoryMarshaller();
categoryMarshaller.prepare(Format.XML, pathName, categoryMarshaller.prepare(Format.XML, pathName,
"categories", indentation); "categories", indentation);
categoryMarshaller.exportList(NgCollection.getSortedCategories()); categoryMarshaller.exportList(NgCollection.sortedCategories);
System.out.printf("\t\tdone.\n"); System.out.printf("\t\tdone.\n");
} }
@ -176,6 +176,6 @@ class ExportHelper {
"permissions", indentation); "permissions", indentation);
permissionMarshaller.exportList(new ArrayList<> permissionMarshaller.exportList(new ArrayList<>
(NgCollection.permissions.values())); (NgCollection.permissions.values()));
System.out.printf("\t\tdone.\n"); System.out.printf("\tdone.\n");
} }
} }

View File

@ -18,7 +18,7 @@
*/ */
package com.arsdigita.portation.cmd; package com.arsdigita.portation.cmd;
import com.arsdigita.portation.conversion.MainConverter; import com.arsdigita.portation.conversion.CoreConverter;
import com.arsdigita.util.cmd.Program; import com.arsdigita.util.cmd.Program;
import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLine;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
@ -87,6 +87,10 @@ public class ExportCliTool extends Program {
export(args); export(args);
break; break;
case "convert":
convert();
break;
default: default:
printUsage(); printUsage();
break; break;
@ -109,7 +113,7 @@ public class ExportCliTool extends Program {
System.err.printf("module-class: %s\n", moduleClass); System.err.printf("module-class: %s\n", moduleClass);
final String pathName = args[2]; final String pathName = args[2];
System.err.printf("path: %s\n", pathName); System.err.printf("path: %s\n", pathName);
ExportHelper.setPath(pathName); CoreExporter.setPath(pathName);
System.err.printf("\n"); System.err.printf("\n");
@ -117,79 +121,79 @@ public class ExportCliTool extends Program {
switch (moduleClass) { switch (moduleClass) {
case "categories": case "categories":
convert(); convert();
ExportHelper.exportCategories(); CoreExporter.exportCategories();
break; break;
case "categorizations": case "categorizations":
convert(); convert();
ExportHelper.exportCategorizations(); CoreExporter.exportCategorizations();
break; break;
case "users": case "users":
convert(); convert();
ExportHelper.exportUsers(); CoreExporter.exportUsers();
break; break;
case "groups": case "groups":
convert(); convert();
ExportHelper.exportGroups(); CoreExporter.exportGroups();
break; break;
case "groupMemberships": case "groupMemberships":
convert(); convert();
ExportHelper.exportGroupMemberships(); CoreExporter.exportGroupMemberships();
break; break;
case "roles": case "roles":
convert(); convert();
ExportHelper.exportRoles(); CoreExporter.exportRoles();
break; break;
case "roleMemberships": case "roleMemberships":
convert(); convert();
ExportHelper.exportRoleMemberships(); CoreExporter.exportRoleMemberships();
break; break;
case "workflowTemplates": case "workflowTemplates":
convert(); convert();
ExportHelper.exportWorkflowTemplates(); CoreExporter.exportWorkflowTemplates();
break; break;
case "workflows": case "workflows":
convert(); convert();
ExportHelper.exportWorkflows(); CoreExporter.exportWorkflows();
break; break;
case "assignableTasks": case "assignableTasks":
convert(); convert();
ExportHelper.exportAssignableTasks(); CoreExporter.exportAssignableTasks();
break; break;
case "taskAssignments": case "taskAssignments":
convert(); convert();
ExportHelper.exportTaskAssignments(); CoreExporter.exportTaskAssignments();
break; break;
case "permissions": case "permissions":
convert(); convert();
ExportHelper.exportPermissions(); CoreExporter.exportPermissions();
break; break;
case "all_core": case "all_core":
convert(); convert();
System.out.println("Started exporting all ng-objects..."); System.out.println("Started exporting all ng-objects...");
ExportHelper.exportCategories(); CoreExporter.exportCategories();
ExportHelper.exportCategorizations(); CoreExporter.exportCategorizations();
ExportHelper.exportUsers(); CoreExporter.exportUsers();
ExportHelper.exportGroups(); CoreExporter.exportGroups();
ExportHelper.exportGroupMemberships(); CoreExporter.exportGroupMemberships();
ExportHelper.exportRoles(); CoreExporter.exportRoles();
ExportHelper.exportRoleMemberships(); CoreExporter.exportRoleMemberships();
ExportHelper.exportWorkflows(); CoreExporter.exportWorkflows();
ExportHelper.exportWorkflowTemplates(); CoreExporter.exportWorkflowTemplates();
ExportHelper.exportAssignableTasks(); CoreExporter.exportAssignableTasks();
ExportHelper.exportTaskAssignments(); CoreExporter.exportTaskAssignments();
ExportHelper.exportPermissions(); CoreExporter.exportPermissions();
System.out.println("Finished exports."); System.out.println("Finished exports.");
System.out.printf("\n"); System.out.printf("\n");
break; break;
@ -210,7 +214,7 @@ public class ExportCliTool extends Program {
try { try {
System.err.println("Started conversions of systems objects to " + System.err.println("Started conversions of systems objects to " +
"ng-objects..."); "ng-objects...");
MainConverter.startConversionToNg(); CoreConverter.startConversionToNg();
System.err.println("Finished conversions."); System.err.println("Finished conversions.");
System.out.printf("\n"); System.out.printf("\n");
} catch (Exception e) { } catch (Exception e) {

View File

@ -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.security.UserConversion;
import com.arsdigita.portation.conversion.core.workflow.AssignableTaskConversion; import com.arsdigita.portation.conversion.core.workflow.AssignableTaskConversion;
import com.arsdigita.portation.conversion.core.workflow.WorkflowConversion; import com.arsdigita.portation.conversion.core.workflow.WorkflowConversion;
import com.arsdigita.portation.modules.core.categorization.Category;
import com.arsdigita.portation.modules.core.security.Permission; 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 * 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 * 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. * 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> * @author <a href="mailto:tosmers@uni-bremen.de>Tobias Osmers</a>
* @version created on 6/27/16 * @version created on 6/27/16
*/ */
public class MainConverter { public class CoreConverter {
/** /**
* Method, to start all the different converter classes in a specific * Method, to start all the different converter classes in a specific
@ -51,17 +52,24 @@ public class MainConverter {
RoleConversion.convertAll(); RoleConversion.convertAll();
CategoryConversion.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(); WorkflowConversion.convertAll();
AssignableTaskConversion.convertAll(); AssignableTaskConversion.convertAll();
PermissionConversion.convertAll(); PermissionConversion.convertAll();
//Verify permissions // Verify permissions
for(Permission permission : NgCollection.permissions.values()) { for (Permission permission : NgCollection.permissions.values()) {
if (permission.getGrantee() == null) { 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()); "is null.%n", permission.getPermissionId());
System.exit(-1); System.exit(-1);
} }

View File

@ -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.TaskAssignment;
import com.arsdigita.portation.modules.core.workflow.Workflow; import com.arsdigita.portation.modules.core.workflow.Workflow;
import com.arsdigita.portation.modules.core.workflow.WorkflowTemplate; import com.arsdigita.portation.modules.core.workflow.WorkflowTemplate;
import com.arsdigita.util.Assert;
import java.util.*; import java.util.*;
@ -66,6 +65,10 @@ public class NgCollection {
public static Map<Long, Permission> permissions = new HashMap<>(); 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. * 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 * to add them to the sorted list. After being added to sorted the
* category will be removed from the unsorted list and therefore ignored * category will be removed from the unsorted list and therefore ignored
* in this foreach run. * in this foreach run.
*
* @return a sorted array list of categories
*/ */
public static ArrayList<Category> getSortedCategories() { static void sortCategories() {
ArrayList<Category> unsorted = new ArrayList<>(categories.values()); unsortedCategories = new ArrayList<>(categories.values());
ArrayList<Category> sorted = new ArrayList<>(unsorted.size()); sortedCategories = new ArrayList<>(unsortedCategories.size());
for (Category anUnsorted : unsorted) { System.err.printf("\tSorting categorizes...\n");
addTree(unsorted, sorted, anUnsorted); 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("");
} }
System.err.printf("\tdone. Count: %d\n", sortedCategories.size());
Assert.assertEquals(unsorted.size(), sorted.size());
return sorted;
} }
/** /**
* Helper method to recursively add all parent categories before their * Helper method to recursively add all parent categories before their
* childs. * childs.
* *
* @param unsorted the unsorted list of categories
* @param sorted the sorted list of categories
* @param category the current category in the unsorted list * @param category the current category in the unsorted list
*/ */
private static void addTree(ArrayList<Category> unsorted, private static void add(Category category, String indent) {
ArrayList<Category> sorted, Category parent = category.getParentCategory();
Category category) {
if (category.getParentCategory() != null System.err.printf("%s\tHas missing parent?...", indent);
&& unsorted.contains(category.getParentCategory())) { if (parent != null && !sortedCategories.contains(parent)) {
addTree(unsorted, sorted, category.getParentCategory()); 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);
} }
} }

View File

@ -45,14 +45,15 @@ public class CategoryConversion {
* associations in tact. * associations in tact.
*/ */
public static void convertAll() { public static void convertAll() {
System.err.printf("\tFetching categories from database...");
List<com.arsdigita.categorization.Category> trunkCategories = com List<com.arsdigita.categorization.Category> trunkCategories = com
.arsdigita.categorization.Category.getAllObjectCategories(); .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); createCategoryAndCategorizations(trunkCategories);
setRingAssociations(trunkCategories); setRingAssociations(trunkCategories);
System.err.printf("\tdone.\n"); System.err.printf("\tdone.\n");
} }
/** /**

View File

@ -45,9 +45,11 @@ public class GroupConversion {
* focusing on keeping all the associations in tact. * focusing on keeping all the associations in tact.
*/ */
public static void convertAll() { public static void convertAll() {
System.err.printf("\tFetching groups from database...");
List<com.arsdigita.kernel.Group> trunkGroups, List<com.arsdigita.kernel.Group> trunkGroups,
roleGroups = new ArrayList<>(); roleGroups = new ArrayList<>();
trunkGroups = com.arsdigita.kernel.Group.getAllObjectGroups(); trunkGroups = com.arsdigita.kernel.Group.getAllObjectGroups();
System.err.println("done.");
System.err.printf("\tConverting groups and group memberships...\n"); System.err.printf("\tConverting groups and group memberships...\n");
createGroupsAndSetAssociations(trunkGroups); createGroupsAndSetAssociations(trunkGroups);

View File

@ -56,9 +56,11 @@ public class PermissionConversion {
* grantee}-{@link Role} has to be recreated separately. * grantee}-{@link Role} has to be recreated separately.
*/ */
public static void convertAll() { public static void convertAll() {
System.err.printf("\tFetching permissions from database...");
List<com.arsdigita.kernel.permissions.Permission> trunkPermissions = List<com.arsdigita.kernel.permissions.Permission> trunkPermissions =
com.arsdigita.kernel.permissions.Permission com.arsdigita.kernel.permissions.Permission
.getAllObjectPermissions(); .getAllObjectPermissions();
System.err.println("done.");
System.err.printf("\tConverting permissions...\n"); System.err.printf("\tConverting permissions...\n");
createPermissionsAndSetAssociations(trunkPermissions); createPermissionsAndSetAssociations(trunkPermissions);

View File

@ -44,8 +44,10 @@ public class RoleConversion {
* associations in tact. * associations in tact.
*/ */
public static void convertAll() { public static void convertAll() {
System.err.printf("\tFetching roles from database...");
List<com.arsdigita.kernel.Role> trunkRoles = com.arsdigita.kernel List<com.arsdigita.kernel.Role> trunkRoles = com.arsdigita.kernel
.Role.getAllObjectRoles(); .Role.getAllObjectRoles();
System.err.println("done.");
System.err.printf("\tCreating roles and role memberships...\n"); System.err.printf("\tCreating roles and role memberships...\n");
createRolesAndSetAssociations(trunkRoles); createRolesAndSetAssociations(trunkRoles);

View File

@ -38,8 +38,10 @@ public class UserConversion {
* creating the equivalent ng-{@link User}s. * creating the equivalent ng-{@link User}s.
*/ */
public static void convertAll() { public static void convertAll() {
System.err.printf("\tFetching users from database...");
List<com.arsdigita.kernel.User> trunkUsers = com.arsdigita.kernel List<com.arsdigita.kernel.User> trunkUsers = com.arsdigita.kernel
.User.getAllObjectUsers(); .User.getAllObjectUsers();
System.err.println("done.");
System.err.printf("\tConverting users...\n"); System.err.printf("\tConverting users...\n");
// create users // create users

View File

@ -52,8 +52,10 @@ public class AssignableTaskConversion {
* to be recreated once all ng-{@link AssignableTask}s have been created. * to be recreated once all ng-{@link AssignableTask}s have been created.
*/ */
public static void convertAll() { public static void convertAll() {
System.err.printf("\tFetching assignable tasks from database...");
List<com.arsdigita.workflow.simple.UserTask> trunkUserTasks = com List<com.arsdigita.workflow.simple.UserTask> trunkUserTasks = com
.arsdigita.workflow.simple.UserTask.getAllObjectUserTasks(); .arsdigita.workflow.simple.UserTask.getAllObjectUserTasks();
System.err.println("done.");
System.err.printf("\tConverting assignable tasks and task " + System.err.printf("\tConverting assignable tasks and task " +
"assignments...\n"); "assignments...\n");

View File

@ -43,8 +43,10 @@ public class WorkflowConversion {
* creating the equivalent ng-{@link Workflow}s. * creating the equivalent ng-{@link Workflow}s.
*/ */
public static void convertAll() { public static void convertAll() {
System.err.printf("\tFetching workflows from database...");
List<com.arsdigita.workflow.simple.Workflow> trunkWorkflows = List<com.arsdigita.workflow.simple.Workflow> trunkWorkflows =
com.arsdigita.workflow.simple.Workflow.getAllObjectWorkflows(); com.arsdigita.workflow.simple.Workflow.getAllObjectWorkflows();
System.err.println("done.");
System.err.printf("\tConverting workflows...\n"); System.err.printf("\tConverting workflows...\n");
createWorkflowAndSetAssociations(trunkWorkflows); createWorkflowAndSetAssociations(trunkWorkflows);

View File

@ -40,9 +40,11 @@ public class WorkflowTemplateConversion {
* creating the equivalent ng-{@link WorkflowTemplate}s. * creating the equivalent ng-{@link WorkflowTemplate}s.
*/ */
public static void convertAll() { public static void convertAll() {
System.err.printf("\tFetching workflow templates from database...");
List<com.arsdigita.workflow.simple.WorkflowTemplate> List<com.arsdigita.workflow.simple.WorkflowTemplate>
trunkWorkflowTemplates = com.arsdigita.workflow.simple trunkWorkflowTemplates = com.arsdigita.workflow.simple
.WorkflowTemplate.getAllObjectWorkflowTemplates(); .WorkflowTemplate.getAllObjectWorkflowTemplates();
System.err.println("done.");
System.err.printf("\tConverting workflow templates...\n"); System.err.printf("\tConverting workflow templates...\n");
trunkWorkflowTemplates.forEach(WorkflowTemplate::new); trunkWorkflowTemplates.forEach(WorkflowTemplate::new);