From 06487845bb8e982a7de313fcc71acf5845aefe34 Mon Sep 17 00:00:00 2001 From: tosmers Date: Wed, 6 Sep 2017 13:43:17 +0000 Subject: [PATCH] [TRUNK][FEATURE] - adds working export of ldn-terms' ResourceType, CcmApplication, Domain and DomainOwnership - optimizes imports of some core packages git-svn-id: https://svn.libreccm.org/ccm/trunk@4986 8810af33-2d31-482b-a856-94f89814c4df --- .../portation/cmd/ExportCliTool.java | 6 +-- .../portation/conversion/CoreConverter.java | 17 ++----- .../conversion/NgCoreCollection.java | 35 +++++--------- .../categorization/CategoryConversion.java | 6 ++- .../core/security/GroupConversion.java | 2 +- .../core/security/PermissionConversion.java | 6 +-- .../core/security/RoleConversion.java | 2 +- .../core/security/UserConversion.java | 2 +- .../workflow/AssignableTaskConversion.java | 2 +- .../core/workflow/WorkflowConversion.java | 2 +- .../workflow/WorkflowTemplateConversion.java | 4 +- .../modules/core/categorization/Category.java | 5 +- .../conversion/NgCoreCollection.java | 46 +++++++++++++++++++ .../core/categorization/DomainConversion.java | 2 +- .../core/core/ResourceTypeConversion.java | 2 +- .../core/web/CcmApplicationConversion.java | 6 ++- .../portation/modules/LdnTermsExporter.java | 22 ++++----- .../DomainOwnershipIdGenerator.java | 3 +- 18 files changed, 103 insertions(+), 67 deletions(-) diff --git a/ccm-core/src/com/arsdigita/portation/cmd/ExportCliTool.java b/ccm-core/src/com/arsdigita/portation/cmd/ExportCliTool.java index 0fdc1004a..c2149ad1e 100644 --- a/ccm-core/src/com/arsdigita/portation/cmd/ExportCliTool.java +++ b/ccm-core/src/com/arsdigita/portation/cmd/ExportCliTool.java @@ -108,7 +108,7 @@ public class ExportCliTool extends Program { private void convert() { try { System.err.println("Started conversions of systems objects to " + - "ng-objects..."); + "ng-objects:"); // Core conversions CoreConverter.getInstance().startConversionToNg(); @@ -148,13 +148,13 @@ public class ExportCliTool extends Program { //final String moduleClass = args[1]; //System.err.printf("module-class: %s\n", moduleClass); final String pathName = args[1]; - System.err.printf("path: %s\n", pathName); + System.err.printf("path for export: %s\n", pathName); CoreExporter.setPath(pathName); System.err.printf("\n"); try { - System.out.println("Started exporting all ng-objects..."); + System.out.println("Started exporting all ng-objects:"); // Core CoreExporter.startExport(); diff --git a/ccm-core/src/com/arsdigita/portation/conversion/CoreConverter.java b/ccm-core/src/com/arsdigita/portation/conversion/CoreConverter.java index d4a50c141..e7b7fc609 100644 --- a/ccm-core/src/com/arsdigita/portation/conversion/CoreConverter.java +++ b/ccm-core/src/com/arsdigita/portation/conversion/CoreConverter.java @@ -26,6 +26,7 @@ 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.conversion.core.workflow.WorkflowTemplateConversion; import com.arsdigita.portation.modules.core.security.Permission; @@ -55,23 +56,11 @@ public class CoreConverter extends AbstractConverter { public void startConversionToNg() { UserConversion.convertAll(); GroupConversion.convertAll(); - RoleConversion.convertAll(); CategoryConversion.convertAll(); - NgCoreCollection.sortCategories(); - // Verify categories - /*for (Category category : NgCoreCollection.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 : NgCoreCollection.permissions.values()) { if (permission.getGrantee() == null) { @@ -80,6 +69,10 @@ public class CoreConverter extends AbstractConverter { System.exit(-1); } } + + WorkflowConversion.convertAll(); + WorkflowTemplateConversion.convertAll(); + AssignableTaskConversion.convertAll(); } /** diff --git a/ccm-core/src/com/arsdigita/portation/conversion/NgCoreCollection.java b/ccm-core/src/com/arsdigita/portation/conversion/NgCoreCollection.java index 4a619529a..e8d984114 100644 --- a/ccm-core/src/com/arsdigita/portation/conversion/NgCoreCollection.java +++ b/ccm-core/src/com/arsdigita/portation/conversion/NgCoreCollection.java @@ -61,6 +61,7 @@ public class NgCoreCollection { // if lists need to be sorted in specific way to work with import public static ArrayList sortedCategories; + /** * Private constructor to prevent the instantiation of this class. */ @@ -68,26 +69,24 @@ public class NgCoreCollection { /** * Sorts values of category-map to ensure that the parent-categories will - * be listed befor their childs in the export file. + * be listed before 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 + * to add them to the sorted list. After being added to the sorted list the * category will be removed from the unsorted list and therefore ignored * in this foreach run. */ - static void sortCategories() { - ArrayList unsortedCategories = new ArrayList<>(categories.values()); + public static void sortCategories() { + ArrayList unsortedCategories = + new ArrayList<>(categories.values()); sortedCategories = new ArrayList<>(unsortedCategories.size()); - System.err.printf("\tSorting categorizes...\n"); - int count = 1; + int runs = 0; 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(""); + add(anUnsorted); + runs++; } - System.err.printf("\tdone. Count: %d\n", sortedCategories.size()); + System.err.printf("\t\tSorted categories in %d runs.\n", runs); } /** @@ -96,25 +95,15 @@ public class NgCoreCollection { * * @param category the current category in the unsorted list */ - private static void add(Category category, String indent) { + private static void add(Category category) { 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."); + add(parent); } - //System.err.printf("%sAdded to sorted list?...", indent); if (!sortedCategories.contains(category)) { sortedCategories.add(category); - //System.err.println("YES."); - } else { - //System.err.println("NO."); } } } diff --git a/ccm-core/src/com/arsdigita/portation/conversion/core/categorization/CategoryConversion.java b/ccm-core/src/com/arsdigita/portation/conversion/core/categorization/CategoryConversion.java index a94a3f034..32c071f3a 100644 --- a/ccm-core/src/com/arsdigita/portation/conversion/core/categorization/CategoryConversion.java +++ b/ccm-core/src/com/arsdigita/portation/conversion/core/categorization/CategoryConversion.java @@ -53,7 +53,11 @@ public class CategoryConversion { System.err.printf("\tConverting categories and categorizations...\n"); createCategoryAndCategorizations(trunkCategories); setRingAssociations(trunkCategories); - System.err.printf("\tdone.\n"); + + System.err.printf("\tSorting categories...\n"); + NgCoreCollection.sortCategories(); + + System.err.println("\tdone.\n"); } /** diff --git a/ccm-core/src/com/arsdigita/portation/conversion/core/security/GroupConversion.java b/ccm-core/src/com/arsdigita/portation/conversion/core/security/GroupConversion.java index bf8915b8f..1792b0e65 100644 --- a/ccm-core/src/com/arsdigita/portation/conversion/core/security/GroupConversion.java +++ b/ccm-core/src/com/arsdigita/portation/conversion/core/security/GroupConversion.java @@ -51,7 +51,7 @@ public class GroupConversion { System.err.printf("\tConverting groups and group memberships...\n"); createGroupsAndSetAssociations(trunkGroups); - System.err.printf("\tdone.\n"); + System.err.println("\tdone.\n"); } /** diff --git a/ccm-core/src/com/arsdigita/portation/conversion/core/security/PermissionConversion.java b/ccm-core/src/com/arsdigita/portation/conversion/core/security/PermissionConversion.java index 8e83719a4..aa6894719 100644 --- a/ccm-core/src/com/arsdigita/portation/conversion/core/security/PermissionConversion.java +++ b/ccm-core/src/com/arsdigita/portation/conversion/core/security/PermissionConversion.java @@ -68,7 +68,7 @@ public class PermissionConversion { System.exit(-1); } - System.err.printf("\tdone.\n"); + System.err.println("\tdone.\n"); } /** @@ -254,9 +254,9 @@ public class PermissionConversion { permission.getPermissionId());*/ } } - System.err.printf("\t\tCreated %d duplicate permissions.\n", + System.err.printf("\t\t(Created %d duplicates.)\n", duplicates); - System.err.printf("\t\tCreated %d new roles.\n", + System.err.printf("\t\t(Created %d new roles.)\n", rolesCreated); } diff --git a/ccm-core/src/com/arsdigita/portation/conversion/core/security/RoleConversion.java b/ccm-core/src/com/arsdigita/portation/conversion/core/security/RoleConversion.java index bca8a7def..c298e4207 100644 --- a/ccm-core/src/com/arsdigita/portation/conversion/core/security/RoleConversion.java +++ b/ccm-core/src/com/arsdigita/portation/conversion/core/security/RoleConversion.java @@ -51,7 +51,7 @@ public class RoleConversion { System.err.printf("\tCreating roles and role memberships...\n"); createRolesAndSetAssociations(trunkRoles); - System.err.printf("\tdone.\n"); + System.err.println("\tdone.\n"); } /** diff --git a/ccm-core/src/com/arsdigita/portation/conversion/core/security/UserConversion.java b/ccm-core/src/com/arsdigita/portation/conversion/core/security/UserConversion.java index b71551013..dbeaee255 100644 --- a/ccm-core/src/com/arsdigita/portation/conversion/core/security/UserConversion.java +++ b/ccm-core/src/com/arsdigita/portation/conversion/core/security/UserConversion.java @@ -51,6 +51,6 @@ public class UserConversion { processed++; } System.out.printf("\t\tCreated %d users.\n", processed); - System.err.printf("\tdone.\n"); + System.err.println("\tdone.\n"); } } diff --git a/ccm-core/src/com/arsdigita/portation/conversion/core/workflow/AssignableTaskConversion.java b/ccm-core/src/com/arsdigita/portation/conversion/core/workflow/AssignableTaskConversion.java index 8d582fb96..0a05853bb 100644 --- a/ccm-core/src/com/arsdigita/portation/conversion/core/workflow/AssignableTaskConversion.java +++ b/ccm-core/src/com/arsdigita/portation/conversion/core/workflow/AssignableTaskConversion.java @@ -61,7 +61,7 @@ public class AssignableTaskConversion { "assignments...\n"); createAssignableTasksAndSetAssociations(trunkUserTasks); setTaskRingDependencies(trunkUserTasks); - System.err.printf("\tdone.\n"); + System.err.println("\tdone.\n"); } diff --git a/ccm-core/src/com/arsdigita/portation/conversion/core/workflow/WorkflowConversion.java b/ccm-core/src/com/arsdigita/portation/conversion/core/workflow/WorkflowConversion.java index bd425480e..d453e0e11 100644 --- a/ccm-core/src/com/arsdigita/portation/conversion/core/workflow/WorkflowConversion.java +++ b/ccm-core/src/com/arsdigita/portation/conversion/core/workflow/WorkflowConversion.java @@ -50,7 +50,7 @@ public class WorkflowConversion { System.err.printf("\tConverting workflows...\n"); createWorkflowAndSetAssociations(trunkWorkflows); - System.err.printf("\tdone.\n"); + System.err.println("\tdone.\n"); } private static void createWorkflowAndSetAssociations( diff --git a/ccm-core/src/com/arsdigita/portation/conversion/core/workflow/WorkflowTemplateConversion.java b/ccm-core/src/com/arsdigita/portation/conversion/core/workflow/WorkflowTemplateConversion.java index f8373a078..3e8603e10 100644 --- a/ccm-core/src/com/arsdigita/portation/conversion/core/workflow/WorkflowTemplateConversion.java +++ b/ccm-core/src/com/arsdigita/portation/conversion/core/workflow/WorkflowTemplateConversion.java @@ -54,7 +54,7 @@ public class WorkflowTemplateConversion { new WorkflowTemplate(trunkWorkflowTemplate); processed++; } - System.out.printf("\t\t Created %d workflow templates.", processed); - System.err.printf("\tdone.\n"); + System.out.printf("\t\t Created %d workflow templates.\n", processed); + System.err.println("\tdone.\n"); } } diff --git a/ccm-core/src/com/arsdigita/portation/modules/core/categorization/Category.java b/ccm-core/src/com/arsdigita/portation/modules/core/categorization/Category.java index 86fce8560..2e78359ad 100644 --- a/ccm-core/src/com/arsdigita/portation/modules/core/categorization/Category.java +++ b/ccm-core/src/com/arsdigita/portation/modules/core/categorization/Category.java @@ -72,9 +72,10 @@ public class Category extends CcmObject implements Portable { this.uniqueId = trunkCategory.getID().toString(); this.name = trunkCategory.getName(); + this.title = new LocalizedString(); + this.description = new LocalizedString(); CategoryLocalizationCollection categoryLocalizationCollection = trunkCategory.getCategoryLocalizationCollection(); - if (categoryLocalizationCollection != null && categoryLocalizationCollection.next()) { @@ -82,9 +83,7 @@ public class Category extends CcmObject implements Portable { categoryLocalizationCollection.getCategoryLocalization(); if (categoryLocalization != null) { Locale locale = new Locale(categoryLocalization.getLocale()); - this.title = new LocalizedString(); this.title.addValue(locale, categoryLocalization.getName()); - this.description = new LocalizedString(); this.description.addValue(locale, categoryLocalization.getDescription()); } } diff --git a/ccm-ldn-terms/src/com/arsdigita/london/terms/portation/conversion/NgCoreCollection.java b/ccm-ldn-terms/src/com/arsdigita/london/terms/portation/conversion/NgCoreCollection.java index 9f41ea260..bc6b03ce1 100644 --- a/ccm-ldn-terms/src/com/arsdigita/london/terms/portation/conversion/NgCoreCollection.java +++ b/ccm-ldn-terms/src/com/arsdigita/london/terms/portation/conversion/NgCoreCollection.java @@ -24,6 +24,7 @@ import com.arsdigita.london.terms.portation.modules.core.core.Resource; import com.arsdigita.london.terms.portation.modules.core.core.ResourceType; import com.arsdigita.london.terms.portation.modules.core.web.CcmApplication; +import java.util.ArrayList; import java.util.HashMap; import java.util.Map; @@ -39,8 +40,53 @@ public class NgCoreCollection { public static Map domains = new HashMap<>(); public static Map domainOwnerships = new HashMap<>(); + + // if lists need to be sorted in specific way to work with import + public static ArrayList sortedCcmApplications; + + /** * Private constructor to prevent the instantiation of this class. */ private NgCoreCollection() {} + + /** + * Sorts values of resource-map to ensure that the parent-resources will + * be listed before 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 the sorted list the + * resource will be removed from the unsorted list and therefore ignored + * in this foreach run. + */ + public static void sortCcmApplications() { + ArrayList unsortedCcmApplications = + new ArrayList<>(ccmApplications.values()); + sortedCcmApplications = new ArrayList<>(unsortedCcmApplications.size()); + + int runs = 0; + for (CcmApplication anUnsorted : unsortedCcmApplications) { + add(anUnsorted); + runs++; + } + System.err.printf("\t\tSorted ccm applications in %d runs.\n", runs); + } + + /** + * Helper method to recursively add all parent resources before their + * childs. + * + * @param ccmApplication the current resource in the unsorted list + */ + private static void add(CcmApplication ccmApplication) { + CcmApplication parent = (CcmApplication) ccmApplication.getParent(); + + if (parent != null && !sortedCcmApplications.contains(parent)) { + add(parent); + } + + if (!sortedCcmApplications.contains(ccmApplication)) { + sortedCcmApplications.add(ccmApplication); + } + } } diff --git a/ccm-ldn-terms/src/com/arsdigita/london/terms/portation/conversion/core/categorization/DomainConversion.java b/ccm-ldn-terms/src/com/arsdigita/london/terms/portation/conversion/core/categorization/DomainConversion.java index a07308621..5e360a8e9 100644 --- a/ccm-ldn-terms/src/com/arsdigita/london/terms/portation/conversion/core/categorization/DomainConversion.java +++ b/ccm-ldn-terms/src/com/arsdigita/london/terms/portation/conversion/core/categorization/DomainConversion.java @@ -55,7 +55,7 @@ public class DomainConversion { System.err.printf("\tConverting domains and domain ownerships...\n"); createDomainsAndSetAssociations(trunkDomains); - System.err.printf("\tdone.\n"); + System.err.println("\tdone.\n"); } /** diff --git a/ccm-ldn-terms/src/com/arsdigita/london/terms/portation/conversion/core/core/ResourceTypeConversion.java b/ccm-ldn-terms/src/com/arsdigita/london/terms/portation/conversion/core/core/ResourceTypeConversion.java index 60f58613f..a841ea3e2 100644 --- a/ccm-ldn-terms/src/com/arsdigita/london/terms/portation/conversion/core/core/ResourceTypeConversion.java +++ b/ccm-ldn-terms/src/com/arsdigita/london/terms/portation/conversion/core/core/ResourceTypeConversion.java @@ -52,6 +52,6 @@ public class ResourceTypeConversion { processed++; } System.out.printf("\t\tCreated %d resource types.\n", processed); - System.err.printf("\tdone.\n"); + System.err.println("\tdone.\n"); } } diff --git a/ccm-ldn-terms/src/com/arsdigita/london/terms/portation/conversion/core/web/CcmApplicationConversion.java b/ccm-ldn-terms/src/com/arsdigita/london/terms/portation/conversion/core/web/CcmApplicationConversion.java index a63e3a6ae..b121757f3 100644 --- a/ccm-ldn-terms/src/com/arsdigita/london/terms/portation/conversion/core/web/CcmApplicationConversion.java +++ b/ccm-ldn-terms/src/com/arsdigita/london/terms/portation/conversion/core/web/CcmApplicationConversion.java @@ -52,7 +52,11 @@ public class CcmApplicationConversion { // create ccm applications createCcmApplicationsAndSetAssociations(trunkApplications); setRingAssociations(trunkApplications); - System.err.printf("\tdone.\n"); + + System.err.printf("\tSorting ccm applications...\n"); + NgCoreCollection.sortCcmApplications(); + + System.err.println("\tdone.\n"); } /** diff --git a/ccm-ldn-terms/src/com/arsdigita/london/terms/portation/modules/LdnTermsExporter.java b/ccm-ldn-terms/src/com/arsdigita/london/terms/portation/modules/LdnTermsExporter.java index 1b760e9e9..35ae66cd1 100644 --- a/ccm-ldn-terms/src/com/arsdigita/london/terms/portation/modules/LdnTermsExporter.java +++ b/ccm-ldn-terms/src/com/arsdigita/london/terms/portation/modules/LdnTermsExporter.java @@ -41,22 +41,12 @@ import java.util.ArrayList; public class LdnTermsExporter extends AbstractExporter { public static void startExport() { - exportDomains(); exportResourceTypes(); exportCcmApplications(); + exportDomains(); exportDomainOwnerships(); } - private static void exportDomains() { - System.out.printf("\tExporting domains..."); - DomainMarshaller domainMarshaller = new DomainMarshaller(); - domainMarshaller.prepare( - Format.XML, pathName, "domains", indentation); - domainMarshaller.exportList( - new ArrayList<>(NgCoreCollection.domains.values())); - System.out.printf("\t\tdone.\n"); - } - private static void exportResourceTypes() { System.out.printf("\tExporting resource types..."); ResourceTypeMarshaller resourceTypeMarshaller = new @@ -79,6 +69,16 @@ public class LdnTermsExporter extends AbstractExporter { System.out.printf("\tdone.\n"); } + private static void exportDomains() { + System.out.printf("\tExporting domains..."); + DomainMarshaller domainMarshaller = new DomainMarshaller(); + domainMarshaller.prepare( + Format.XML, pathName, "domains", indentation); + domainMarshaller.exportList( + new ArrayList<>(NgCoreCollection.domains.values())); + System.out.printf("\t\tdone.\n"); + } + private static void exportDomainOwnerships() { System.out.printf("\tExporting domain ownerships..."); DomainOwnershipMarshaller domainOwnershipMarshaller = new diff --git a/ccm-ldn-terms/src/com/arsdigita/london/terms/portation/modules/core/categorization/DomainOwnershipIdGenerator.java b/ccm-ldn-terms/src/com/arsdigita/london/terms/portation/modules/core/categorization/DomainOwnershipIdGenerator.java index ea51d1b51..023c8e4e0 100644 --- a/ccm-ldn-terms/src/com/arsdigita/london/terms/portation/modules/core/categorization/DomainOwnershipIdGenerator.java +++ b/ccm-ldn-terms/src/com/arsdigita/london/terms/portation/modules/core/categorization/DomainOwnershipIdGenerator.java @@ -32,7 +32,8 @@ public class DomainOwnershipIdGenerator extends ObjectIdGenerator { @Override public boolean canUseFor(ObjectIdGenerator gen) { - return gen instanceof DomainOwnershipIdGenerator; + if (gen instanceof DomainOwnershipIdGenerator) return true; + else return false; } @Override