[TRUNK][FEATURE]
- sorts the categories to guarantee, that the parents will be listed before their childs in the export git-svn-id: https://svn.libreccm.org/ccm/trunk@4842 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
906654b460
commit
a121efe40a
|
|
@ -51,28 +51,6 @@ class ExportHelper {
|
||||||
pathName = path;
|
pathName = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void exportCategories() {
|
|
||||||
System.out.printf("\tExporting categories...");
|
|
||||||
CategoryMarshaller categoryMarshaller = new
|
|
||||||
CategoryMarshaller();
|
|
||||||
categoryMarshaller.prepare(Format.XML, pathName,
|
|
||||||
"categories", indentation);
|
|
||||||
categoryMarshaller.exportList(new ArrayList<>(
|
|
||||||
NgCollection.categories.values()));
|
|
||||||
System.out.printf("\t\tdone.\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void exportCategorizations() {
|
|
||||||
System.out.printf("\tExporting categorizations...");
|
|
||||||
CategorizationMarshaller categorizationMarshaller = new
|
|
||||||
CategorizationMarshaller();
|
|
||||||
categorizationMarshaller.prepare(Format.XML, pathName,
|
|
||||||
"categorizations", indentation);
|
|
||||||
categorizationMarshaller.exportList(new ArrayList<>(
|
|
||||||
NgCollection.categorizations.values()));
|
|
||||||
System.out.printf("\tdone.\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void exportUsers() {
|
static void exportUsers() {
|
||||||
System.out.printf("\tExporting users...");
|
System.out.printf("\tExporting users...");
|
||||||
UserMarshaller userMarshaller = new UserMarshaller();
|
UserMarshaller userMarshaller = new UserMarshaller();
|
||||||
|
|
@ -125,6 +103,27 @@ class ExportHelper {
|
||||||
System.out.printf("\tdone.\n");
|
System.out.printf("\tdone.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void exportCategories() {
|
||||||
|
System.out.printf("\tExporting categories...");
|
||||||
|
CategoryMarshaller categoryMarshaller = new
|
||||||
|
CategoryMarshaller();
|
||||||
|
categoryMarshaller.prepare(Format.XML, pathName,
|
||||||
|
"categories", indentation);
|
||||||
|
categoryMarshaller.exportList(NgCollection.getSortedCategories());
|
||||||
|
System.out.printf("\t\tdone.\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void exportCategorizations() {
|
||||||
|
System.out.printf("\tExporting categorizations...");
|
||||||
|
CategorizationMarshaller categorizationMarshaller = new
|
||||||
|
CategorizationMarshaller();
|
||||||
|
categorizationMarshaller.prepare(Format.XML, pathName,
|
||||||
|
"categorizations", indentation);
|
||||||
|
categorizationMarshaller.exportList(new ArrayList<>(
|
||||||
|
NgCollection.categorizations.values()));
|
||||||
|
System.out.printf("\tdone.\n");
|
||||||
|
}
|
||||||
|
|
||||||
static void exportWorkflowTemplates() {
|
static void exportWorkflowTemplates() {
|
||||||
System.out.printf("\tExporting workflow templates...");
|
System.out.printf("\tExporting workflow templates...");
|
||||||
WorkflowTemplateMarshaller workflowTemplateMarshaller = new
|
WorkflowTemplateMarshaller workflowTemplateMarshaller = new
|
||||||
|
|
|
||||||
|
|
@ -45,12 +45,17 @@ public class MainConverter {
|
||||||
* already been created.
|
* already been created.
|
||||||
*/
|
*/
|
||||||
public static void startConversionToNg() {
|
public static void startConversionToNg() {
|
||||||
CategoryConversion.convertAll();
|
|
||||||
UserConversion.convertAll();
|
UserConversion.convertAll();
|
||||||
GroupConversion.convertAll();
|
GroupConversion.convertAll();
|
||||||
|
|
||||||
RoleConversion.convertAll();
|
RoleConversion.convertAll();
|
||||||
|
|
||||||
|
CategoryConversion.convertAll();
|
||||||
|
System.out.println(NgCollection.categories.toString());
|
||||||
|
|
||||||
WorkflowConversion.convertAll();
|
WorkflowConversion.convertAll();
|
||||||
AssignableTaskConversion.convertAll();
|
AssignableTaskConversion.convertAll();
|
||||||
|
|
||||||
PermissionConversion.convertAll();
|
PermissionConversion.convertAll();
|
||||||
|
|
||||||
//Verify permissions
|
//Verify permissions
|
||||||
|
|
|
||||||
|
|
@ -33,9 +33,9 @@ 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.HashMap;
|
import java.util.*;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Storage class for all ng-objects after conversion. This also helps for an
|
* Storage class for all ng-objects after conversion. This also helps for an
|
||||||
|
|
@ -47,7 +47,7 @@ import java.util.Map;
|
||||||
public class NgCollection {
|
public class NgCollection {
|
||||||
|
|
||||||
public static Map<Long, CcmObject> ccmObjects = new HashMap<>();
|
public static Map<Long, CcmObject> ccmObjects = new HashMap<>();
|
||||||
public static Map<Long, Category> categories = new HashMap<>();
|
public static Map<Long, Category> categories = new TreeMap<>();
|
||||||
public static Map<Long, Categorization> categorizations = new HashMap<>();
|
public static Map<Long, Categorization> categorizations = new HashMap<>();
|
||||||
|
|
||||||
public static Map<Long, Party> parties = new HashMap<>();
|
public static Map<Long, Party> parties = new HashMap<>();
|
||||||
|
|
@ -70,4 +70,48 @@ public class NgCollection {
|
||||||
* Private constructor to prevent the instantiation of this class.
|
* Private constructor to prevent the instantiation of this class.
|
||||||
*/
|
*/
|
||||||
private NgCollection() {}
|
private NgCollection() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sorts values of category-map to ensure that the parent-categories will
|
||||||
|
* be listed befor their childs in the export file.
|
||||||
|
*
|
||||||
|
* Runs once over the unsorted list and iterates over each their parents
|
||||||
|
* 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());
|
||||||
|
|
||||||
|
for (Category anUnsorted : unsorted) {
|
||||||
|
addTree(unsorted, sorted, anUnsorted);
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.assertEquals(unsorted.size(), sorted.size());
|
||||||
|
|
||||||
|
return sorted;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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());
|
||||||
|
}
|
||||||
|
sorted.add(category);
|
||||||
|
unsorted.remove(category);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue