From a19c9787fbd7f94efad967938e37c018938b5394 Mon Sep 17 00:00:00 2001 From: tosmers Date: Fri, 27 Oct 2017 15:47:58 +0000 Subject: [PATCH] [TRUNK][UPDATE] - removes WorkflowTemplate - modifies workflow because of removed templates - modifies conversions git-svn-id: https://svn.libreccm.org/ccm/trunk@5088 8810af33-2d31-482b-a856-94f89814c4df --- .../portation/conversion/CoreConverter.java | 2 - .../conversion/NgCoreCollection.java | 82 ++++++------- .../categorization/CategoryConversion.java | 57 ++++++++- .../core/security/PermissionConversion.java | 12 +- .../workflow/AssignableTaskConversion.java | 78 ++++++++++-- .../core/workflow/WorkflowConversion.java | 110 ++++++++++++++--- .../workflow/WorkflowTemplateConversion.java | 59 ---------- .../portation/modules/CoreExporter.java | 19 +-- .../L10NConstants.java} | 18 +-- .../modules/core/l10n/LocalizedString.java | 10 ++ .../core/l10n/jaxb/LocalizedStringValue.java | 111 ++++++++++++++++++ .../core/l10n/jaxb/LocalizedStringValues.java | 97 +++++++++++++++ .../jaxb/LocalizedStringValuesAdapter.java | 77 ++++++++++++ .../modules/core/workflow/Workflow.java | 22 ++-- .../core/workflow/WorkflowTemplate.java | 40 ------- .../workflow/WorkflowTemplateIdResolver.java | 50 -------- .../conversion/NgCoreCollection.java | 40 ------- .../core/web/CcmApplicationConversion.java | 48 +++++++- .../portation/modules/LdnTermsExporter.java | 2 +- 19 files changed, 624 insertions(+), 310 deletions(-) delete mode 100644 ccm-core/src/com/arsdigita/portation/conversion/core/workflow/WorkflowTemplateConversion.java rename ccm-core/src/com/arsdigita/portation/modules/core/{workflow/WorkflowTemplateMarshaller.java => l10n/L10NConstants.java} (72%) create mode 100644 ccm-core/src/com/arsdigita/portation/modules/core/l10n/jaxb/LocalizedStringValue.java create mode 100644 ccm-core/src/com/arsdigita/portation/modules/core/l10n/jaxb/LocalizedStringValues.java create mode 100644 ccm-core/src/com/arsdigita/portation/modules/core/l10n/jaxb/LocalizedStringValuesAdapter.java delete mode 100644 ccm-core/src/com/arsdigita/portation/modules/core/workflow/WorkflowTemplate.java delete mode 100644 ccm-core/src/com/arsdigita/portation/modules/core/workflow/WorkflowTemplateIdResolver.java diff --git a/ccm-core/src/com/arsdigita/portation/conversion/CoreConverter.java b/ccm-core/src/com/arsdigita/portation/conversion/CoreConverter.java index 86fdcd616..e607a5bce 100644 --- a/ccm-core/src/com/arsdigita/portation/conversion/CoreConverter.java +++ b/ccm-core/src/com/arsdigita/portation/conversion/CoreConverter.java @@ -27,7 +27,6 @@ import com.arsdigita.portation.conversion.core.security.UserConversion; import com.arsdigita.portation.conversion.core.workflow.AssignableTaskConversion; import com.arsdigita.portation.conversion.core.workflow.TaskCommentConversion; import com.arsdigita.portation.conversion.core.workflow.WorkflowConversion; -import com.arsdigita.portation.conversion.core.workflow.WorkflowTemplateConversion; import com.arsdigita.portation.modules.core.security.Permission; @@ -71,7 +70,6 @@ public class CoreConverter extends AbstractConverter { } } - WorkflowTemplateConversion.convertAll(); WorkflowConversion.convertAll(); TaskCommentConversion.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 83e70232c..50e81e7d0 100644 --- a/ccm-core/src/com/arsdigita/portation/conversion/NgCoreCollection.java +++ b/ccm-core/src/com/arsdigita/portation/conversion/NgCoreCollection.java @@ -21,13 +21,22 @@ package com.arsdigita.portation.conversion; import com.arsdigita.portation.modules.core.categorization.Categorization; import com.arsdigita.portation.modules.core.categorization.Category; import com.arsdigita.portation.modules.core.core.CcmObject; -import com.arsdigita.portation.modules.core.security.*; -import com.arsdigita.portation.modules.core.workflow.*; +import com.arsdigita.portation.modules.core.security.Group; +import com.arsdigita.portation.modules.core.security.GroupMembership; +import com.arsdigita.portation.modules.core.security.Party; +import com.arsdigita.portation.modules.core.security.Permission; +import com.arsdigita.portation.modules.core.security.Role; +import com.arsdigita.portation.modules.core.security.RoleMembership; +import com.arsdigita.portation.modules.core.security.User; +import com.arsdigita.portation.modules.core.workflow.AssignableTask; +import com.arsdigita.portation.modules.core.workflow.Task; +import com.arsdigita.portation.modules.core.workflow.TaskAssignment; +import com.arsdigita.portation.modules.core.workflow.TaskComment; +import com.arsdigita.portation.modules.core.workflow.Workflow; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; -import java.util.TreeMap; /** * Storage class for all ng-objects after conversion. This also helps for an @@ -46,11 +55,10 @@ public class NgCoreCollection { public static Map roleMemberships = new HashMap<>(); public static Map ccmObjects = new HashMap<>(); - public static Map categories = new TreeMap<>(); + public static Map categories = new HashMap<>(); public static Map categorizations = new HashMap<>(); public static Map workflows = new HashMap<>(); - public static Map workflowTemplates = new HashMap<>(); public static Map taskComments = new HashMap<>(); public static Map tasks = new HashMap<>(); public static Map assignableTasks = new HashMap<>(); @@ -58,70 +66,46 @@ public class NgCoreCollection { public static Map permissions = new HashMap<>(); - - // if lists need to be sorted in specific way to work with import + // in case maps need to be sorted for export public static ArrayList sortedCategories; - + public static ArrayList sortedWorkflows; + public static ArrayList sortedAssignableTasks; /** * Private constructor to prevent the instantiation of this class. */ private NgCoreCollection() {} - /** - * Sorts values of category-map to ensure that the parent-categories will - * be listed before their childs in the export file. + /* + * Sorts values of task-map to ensure that the dependsOn-tasks will + * be listed before their dependant task 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 - * category will be removed from the unsorted list and therefore ignored + * task will be removed from the unsorted list and therefore ignored * in this foreach run. - */ - public static void sortCategories() { - ArrayList unsortedCategories = - new ArrayList<>(categories.values()); - sortedCategories = new ArrayList<>(unsortedCategories.size()); + * + public static void sortAssignableTasks() { + ArrayList unsortedAssignableTasks = + new ArrayList<>(assignableTasks.values()); + sortedAssignableTasks = new ArrayList<>(unsortedAssignableTasks.size()); int runs = 0; - for (Category anUnsorted : unsortedCategories) { - add(anUnsorted); + for (AssignableTask anUnsorted : unsortedAssignableTasks) { + addDependencyTasks(anUnsorted); runs++; } System.err.printf("\t\tSorted categories in %d runs.\n", runs); } - /** - * Helper method to recursively add all parent categories before their - * childs. - * - * @param category the current category in the unsorted list - */ - private static void add(Category category) { - Category parent = category.getParentCategory(); + private static void addDependencyTasks(AssignableTask anUnsorted) { + List dependencies = anUnsorted.getDependsOn(); + + for (Task task : dependencies) { + AssignableTask assignableTask = (AssignableTask) task; - if (parent != null && !sortedCategories.contains(parent)) { - add(parent); } - if (!sortedCategories.contains(category)) { - sortedCategories.add(category); - } - } - - /** - * Removes the workflow templates from the list of all workflows for - * easier importation in ng as workflow is the parent class of all - * templates. Now you don't have to consider the already imported - * templates while importing all other workflows and being in danger of - * duplications. - */ - public static void removeTemplatesFromWorkflows() { - int removed = 0; - for (long templateId : workflowTemplates.keySet()) { - workflows.remove(templateId); - removed++; - } - System.err.printf("\t\tRemoved %d templates from over all workflows." + - "\n", removed); } + */ } 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 ac925a2ca..44bb10cbf 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 @@ -25,6 +25,7 @@ import com.arsdigita.portation.modules.core.categorization.Categorization; import com.arsdigita.portation.modules.core.categorization.Category; import com.arsdigita.portation.modules.core.core.CcmObject; +import java.util.ArrayList; import java.util.List; /** @@ -54,7 +55,7 @@ public class CategoryConversion { createCategoryAndCategorizations(trunkCategories); setRingAssociations(trunkCategories); System.err.printf("\tSorting categories...\n"); - NgCoreCollection.sortCategories(); + sortCategoryMap(); System.err.println("\tdone.\n"); } @@ -144,8 +145,9 @@ public class CategoryConversion { for (com.arsdigita.categorization.Category trunkCategory : trunkCategories) { - Category category = NgCoreCollection.categories.get(trunkCategory - .getID().longValue()); + Category category = NgCoreCollection + .categories + .get(trunkCategory.getID().longValue()); // set parent and opposed association Category parentCategory = null; @@ -154,14 +156,59 @@ public class CategoryConversion { trunkCategory.getDefaultParentCategory(); if (defaultParent != null) { - parentCategory = NgCoreCollection.categories.get( + parentCategory = NgCoreCollection + .categories + .get( defaultParent.getID().longValue()); } - } catch (Exception e) {} + } catch (Exception ignored) {} if (category != null && parentCategory != null) { category.setParentCategory(parentCategory); parentCategory.addSubCategory(category); } } } + + /** + * Sorts values of category-map to ensure that the parent-categories will + * be listed before their childs in the export file. + * + * Runs once over the unsorted map and iterates over each their parents + * to add them to the sorted list. + */ + private static void sortCategoryMap() { + ArrayList sortedList = new ArrayList<>(); + + int runs = 0; + for (Category category : NgCoreCollection.categories.values()) { + addParent(sortedList, category); + + if (!sortedList.contains(category)) + sortedList.add(category); + + runs++; + } + NgCoreCollection.sortedCategories = sortedList; + + System.err.printf("\t\tSorted categories in %d runs.\n", runs); + } + + /** + * Recursively adds the parents of the given category to the sorted list + * to guaranty that the parents will be imported before their childs. + * + * @param sortedList Map of already sorted categories + * @param category Current category + */ + private static void addParent(ArrayList sortedList, Category + category) { + Category parent = category.getParentCategory(); + + if (parent != null) { + addParent(sortedList, parent); + + if (!sortedList.contains(parent)) + sortedList.add(parent); + } + } } 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 287f09f22..cda63046b 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 @@ -164,8 +164,6 @@ public class PermissionConversion { .get("id")).longValue() || -200 == ((BigDecimal) trunkPermission.getPartyOID() .get("id")).longValue()) { - /*System.err.println( - "Skiping because it is a internal permission");*/ continue; } @@ -248,16 +246,10 @@ public class PermissionConversion { System.err.printf("PermissionConversation: No Grantee for " + "permission with database id %d%n", ((BigDecimal) trunkPermission.getACSObject().get("id")).longValue()); - //System.exit(-1); - } else { - /*System.out.printf("Set grantee for permission %d%n%n", - permission.getPermissionId());*/ } } - System.err.printf("\t\t(Created %d duplicates.)\n", - duplicates); - System.err.printf("\t\t(Created %d new roles.)\n", - rolesCreated); + System.err.printf("\t\t(Created %d duplicates and created %d new " + + "roles.)\n", duplicates, rolesCreated); } /** 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 cc55cad9d..23272d1a2 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 @@ -25,11 +25,13 @@ import com.arsdigita.portation.conversion.NgCoreCollection; import com.arsdigita.portation.modules.core.security.Role; import com.arsdigita.portation.modules.core.security.User; import com.arsdigita.portation.modules.core.workflow.AssignableTask; +import com.arsdigita.portation.modules.core.workflow.Task; import com.arsdigita.portation.modules.core.workflow.TaskAssignment; import com.arsdigita.portation.modules.core.workflow.TaskComment; import com.arsdigita.portation.modules.core.workflow.Workflow; -import com.arsdigita.workflow.simple.Task; + +import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -57,10 +59,12 @@ public class AssignableTaskConversion { .arsdigita.workflow.simple.UserTask.getAllObjectUserTasks(); System.err.println("done."); - System.err.printf("\tConverting assignable tasks and task " + - "assignments...\n"); + System.err.printf("\tConverting assignable tasks and task assignments...\n"); createAssignableTasksAndSetAssociations(trunkUserTasks); setTaskRingDependencies(trunkUserTasks); + System.err.printf("\tSorting task assignments...\n"); + sortAssignableTaskMap(); + System.err.println("\tdone.\n"); } @@ -84,7 +88,7 @@ public class AssignableTaskConversion { AssignableTask assignableTask = new AssignableTask(trunkUserTask); // set workflow and opposed associations - com.arsdigita.workflow.simple.Workflow userTaskWorkflow = null; + com.arsdigita.workflow.simple.Workflow userTaskWorkflow; try { userTaskWorkflow = trunkUserTask.getWorkflow(); if (userTaskWorkflow != null) { @@ -95,7 +99,7 @@ public class AssignableTaskConversion { workflow.addTask(assignableTask); } } - } catch (Exception e) {} + } catch (Exception ignored) {} // set taskComments Iterator commentsIt = trunkUserTask.getComments(); @@ -197,14 +201,16 @@ public class AssignableTaskConversion { for (com.arsdigita.workflow.simple.UserTask trunkUserTask : trunkUserTasks) { - AssignableTask assignableTask = NgCoreCollection.assignableTasks.get(trunkUserTask.getID() - .longValue()); + AssignableTask assignableTask = NgCoreCollection + .assignableTasks + .get(trunkUserTask.getID().longValue()); Iterator it = trunkUserTask.getDependencies(); while (it.hasNext()) { - AssignableTask dependency = NgCoreCollection.assignableTasks.get(((Task) it - .next()) - .getID().longValue()); + AssignableTask dependency = NgCoreCollection + .assignableTasks + .get(((com.arsdigita.workflow.simple + .Task) it.next()).getID().longValue()); if (assignableTask != null && dependency != null) { // set dependencies and opposed @@ -214,4 +220,56 @@ public class AssignableTaskConversion { } } } + + /** + * Sorts values of assignable-task-map to ensure that the dependencies will + * be listed before their dependant tasks in the export file. + * + * Runs once over the unsorted map and iterates over each their dependencies + * to add them to the sorted list. + */ + private static void sortAssignableTaskMap() { + ArrayList sortedList = new ArrayList<>(); + + int runs = 0; + for (AssignableTask assignableTask : + NgCoreCollection.assignableTasks.values()) { + + addDependencies(sortedList, assignableTask); + + if (!sortedList.contains(assignableTask)) { + sortedList.add(assignableTask); + } + + runs++; + } + NgCoreCollection.sortedAssignableTasks = sortedList; + + System.err.printf("\t\tSorted assignable tasks in %d runs.\n", runs); + } + + /** + * Recursively adds the dependencies of the given assignable task to the + * sorted list to guaranty that the dependencies will be imported before + * their dependant task. + * + * @param sortedList List of already sorted tasks + * @param assignableTask Current assignable task + */ + private static void addDependencies(ArrayList sortedList, + AssignableTask assignableTask) { + List dependencies = assignableTask.getDependsOn(); + + if (!dependencies.isEmpty()) { + for (Task dependsOnTask : dependencies) { + AssignableTask dependency = (AssignableTask) dependsOnTask; + if (dependency != null) { + addDependencies(sortedList, dependency); + + if (!sortedList.contains(dependency)) + sortedList.add(dependency); + } + } + } + } } 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 ba17a6d38..77ac5af26 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 @@ -20,11 +20,15 @@ package com.arsdigita.portation.conversion.core.workflow; import com.arsdigita.kernel.ACSObject; import com.arsdigita.portation.conversion.NgCoreCollection; +import com.arsdigita.portation.modules.core.categorization.Category; import com.arsdigita.portation.modules.core.core.CcmObject; import com.arsdigita.portation.modules.core.workflow.Workflow; -import com.arsdigita.portation.modules.core.workflow.WorkflowTemplate; +import com.arsdigita.workflow.simple.WorkflowTemplate; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * Class for converting all @@ -50,12 +54,21 @@ public class WorkflowConversion { System.err.printf("\tConverting workflows...\n"); createWorkflowAndSetAssociations(trunkWorkflows); - System.err.printf("\tRemoving workflow templates...\n"); - NgCoreCollection.removeTemplatesFromWorkflows(); + setTemplateAssociations(trunkWorkflows); + System.err.printf("\tSorting workflows...\n"); + sortWorkflowMap(); System.err.println("\tdone.\n"); } + /** + * Creates the equivalent ng-class of the {@code Workflow} and restores + * the associations to other classes. + * + * @param trunkWorkflows List of all + * {@link com.arsdigita.workflow.simple.Workflow}s + * from this old trunk-system. + */ private static void createWorkflowAndSetAssociations( List trunkWorkflows) { int processed = 0; @@ -63,17 +76,7 @@ public class WorkflowConversion { for (com.arsdigita.workflow.simple.Workflow trunkWorkflow : trunkWorkflows) { // create workflows - Workflow workflow = new Workflow(trunkWorkflow, false); - - // set template association - com.arsdigita.workflow.simple.WorkflowTemplate - trunkWorkflowTemplate = trunkWorkflow.getWorkflowTemplate(); - if (trunkWorkflowTemplate != null) { - WorkflowTemplate workflowTemplate = NgCoreCollection - .workflowTemplates - .get(trunkWorkflowTemplate.getID().longValue()); - workflow.setTemplate(workflowTemplate); - } + Workflow workflow = new Workflow(trunkWorkflow); // set object association ACSObject trunkObject = trunkWorkflow.getObject(); @@ -89,4 +92,83 @@ public class WorkflowConversion { System.err.printf("\t\tCreated %d workflows.\n", processed); } + + /** + * Set the template associations, because an equivalent class for + * templates does not exists in the ng-system. + * + * @param trunkWorkflows List of all + * {@link com.arsdigita.workflow.simple.Workflow}s + * from this old trunk-system. + */ + private static void setTemplateAssociations( + List trunkWorkflows) { + int processed = 0; + + for (com.arsdigita.workflow.simple.Workflow trunkWorkflow : + trunkWorkflows) { + Workflow workflow = NgCoreCollection + .workflows + .get(trunkWorkflow.getID().longValue()); + + // set template associations + WorkflowTemplate trunkWorkflowTemplate = trunkWorkflow + .getWorkflowTemplate(); + if (trunkWorkflowTemplate != null) { + Workflow template = NgCoreCollection + .workflows + .get(trunkWorkflowTemplate.getID().longValue()); + workflow.setTemplate(template); + template.setAbstractWorkflow(true); + } else + processed++; + } + System.err.printf("\t\tFound %d templates.\n", processed); + } + + /** + * Sorts values of workflow-map to ensure that the template-workflows will + * be listed before the workflows constructed with this templates in the + * export file. + * + * Runs once over the unsorted list and iterates over each their templates + * to add them to the sorted list. + */ + private static void sortWorkflowMap() { + ArrayList sortedList = new ArrayList<>(); + + int runs = 0; + for (Workflow workflow : NgCoreCollection.workflows.values()) { + + addTemplate(sortedList, workflow); + + if (!sortedList.contains(workflow)) { + sortedList.add(workflow); + } + + runs++; + } + NgCoreCollection.sortedWorkflows = sortedList; + + System.err.printf("\t\tSorted workflows in %d runs.\n", runs); + } + + /** + * Recursively adds the template of the given workflow to the sorted list + * to guaranty that the templates will be imported before their workflows. + * + * @param sortedList List of already sorted workflows + * @param workflow Current workflow + */ + private static void addTemplate(ArrayList sortedList, Workflow + workflow) { + Workflow template = workflow.getTemplate(); + + if (template != null) { + addTemplate(sortedList, template); + + if (!sortedList.contains(template)) + sortedList.add(template); + } + } } 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 deleted file mode 100644 index c13f14c43..000000000 --- a/ccm-core/src/com/arsdigita/portation/conversion/core/workflow/WorkflowTemplateConversion.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2015 LibreCCM Foundation. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ -package com.arsdigita.portation.conversion.core.workflow; - -import com.arsdigita.portation.modules.core.workflow.WorkflowTemplate; - -import java.util.List; - -/** - * Class for converting all - * trunk-{@link com.arsdigita.workflow.simple.WorkflowTemplate}s into - * ng-{@link WorkflowTemplate}s as preparation for a successful export of all - * trunk classes into the new ng-system. - * - * @author - trunkWorkflowTemplates = com.arsdigita.workflow.simple - .WorkflowTemplate.getAllObjectWorkflowTemplates(); - System.err.println("done."); - - System.err.printf("\tConverting workflow templates...\n"); - int processed = 0; - for (com.arsdigita.workflow.simple.WorkflowTemplate - trunkWorkflowTemplate : trunkWorkflowTemplates) { - new WorkflowTemplate(trunkWorkflowTemplate); - processed++; - } - System.out.printf("\t\tCreated %d workflow templates.\n", processed); - System.err.println("\tdone.\n"); - } -} diff --git a/ccm-core/src/com/arsdigita/portation/modules/CoreExporter.java b/ccm-core/src/com/arsdigita/portation/modules/CoreExporter.java index 61354cda8..0f2f284df 100644 --- a/ccm-core/src/com/arsdigita/portation/modules/CoreExporter.java +++ b/ccm-core/src/com/arsdigita/portation/modules/CoreExporter.java @@ -48,7 +48,6 @@ public class CoreExporter extends AbstractExporter { exportPermissions(); - exportWorkflowTemplates(); exportWorkflows(); exportTaskComments(); exportAssignableTasks(); @@ -113,7 +112,8 @@ public class CoreExporter extends AbstractExporter { CategoryMarshaller categoryMarshaller = new CategoryMarshaller(); categoryMarshaller.prepare( Format.XML, pathName, "categories", indentation); - categoryMarshaller.exportList(NgCoreCollection.sortedCategories); + categoryMarshaller.exportList( + NgCoreCollection.sortedCategories); System.out.printf("\t\tdone.\n"); } @@ -139,24 +139,13 @@ public class CoreExporter extends AbstractExporter { System.out.printf("\tdone.\n"); } - private static void exportWorkflowTemplates() { - System.out.printf("\tExporting workflow templates..."); - WorkflowTemplateMarshaller workflowTemplateMarshaller = new - WorkflowTemplateMarshaller(); - workflowTemplateMarshaller.prepare( - Format.XML, pathName, "workflowTemplates", indentation); - workflowTemplateMarshaller.exportList( - new ArrayList<>(NgCoreCollection.workflowTemplates.values())); - System.out.printf("\tdone.\n"); - } - private static void exportWorkflows() { System.out.printf("\tExporting workflows..."); WorkflowMarshaller workflowMarshaller = new WorkflowMarshaller(); workflowMarshaller.prepare( Format.XML, pathName, "workflows", indentation); workflowMarshaller.exportList( - new ArrayList<>(NgCoreCollection.workflows.values())); + NgCoreCollection.sortedWorkflows); System.out.printf("\t\tdone.\n"); } @@ -178,7 +167,7 @@ public class CoreExporter extends AbstractExporter { assignableTaskMarshaller.prepare( Format.XML, pathName, "assignableTasks", indentation); assignableTaskMarshaller.exportList( - new ArrayList<>(NgCoreCollection.assignableTasks.values())); + NgCoreCollection.sortedAssignableTasks); System.out.printf("\tdone.\n"); } diff --git a/ccm-core/src/com/arsdigita/portation/modules/core/workflow/WorkflowTemplateMarshaller.java b/ccm-core/src/com/arsdigita/portation/modules/core/l10n/L10NConstants.java similarity index 72% rename from ccm-core/src/com/arsdigita/portation/modules/core/workflow/WorkflowTemplateMarshaller.java rename to ccm-core/src/com/arsdigita/portation/modules/core/l10n/L10NConstants.java index ff1edfa9f..45b749502 100644 --- a/ccm-core/src/com/arsdigita/portation/modules/core/workflow/WorkflowTemplateMarshaller.java +++ b/ccm-core/src/com/arsdigita/portation/modules/core/l10n/L10NConstants.java @@ -16,14 +16,18 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301 USA */ -package com.arsdigita.portation.modules.core.workflow; - -import com.arsdigita.portation.AbstractMarshaller; +package com.arsdigita.portation.modules.core.l10n; /** - * @author Jens Pelzetter */ -public class WorkflowTemplateMarshaller extends - AbstractMarshaller { +public final class L10NConstants { + + public static final String L10N_XML_NS = "http://l10n.libreccm.org"; + + private L10NConstants() { + //Nothing + } + } diff --git a/ccm-core/src/com/arsdigita/portation/modules/core/l10n/LocalizedString.java b/ccm-core/src/com/arsdigita/portation/modules/core/l10n/LocalizedString.java index e8790d22d..e067cb994 100644 --- a/ccm-core/src/com/arsdigita/portation/modules/core/l10n/LocalizedString.java +++ b/ccm-core/src/com/arsdigita/portation/modules/core/l10n/LocalizedString.java @@ -18,10 +18,17 @@ */ package com.arsdigita.portation.modules.core.l10n; +import com.arsdigita.portation.modules.core.l10n.jaxb.LocalizedStringValuesAdapter; import com.fasterxml.jackson.annotation.JsonIgnore; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import java.util.*; +import static com.arsdigita.portation.modules.core.l10n.L10NConstants.L10N_XML_NS; + /** * A helper class for localisable string properties. This class is declared as * embeddable, so that it can be used in every other entity. The localised @@ -31,8 +38,11 @@ import java.util.*; * @author values; /** diff --git a/ccm-core/src/com/arsdigita/portation/modules/core/l10n/jaxb/LocalizedStringValue.java b/ccm-core/src/com/arsdigita/portation/modules/core/l10n/jaxb/LocalizedStringValue.java new file mode 100644 index 000000000..a68ebb9df --- /dev/null +++ b/ccm-core/src/com/arsdigita/portation/modules/core/l10n/jaxb/LocalizedStringValue.java @@ -0,0 +1,111 @@ +/* + * Copyright (C) 2017 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package com.arsdigita.portation.modules.core.l10n.jaxb; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlValue; +import java.io.Serializable; +import java.util.Objects; + +import static com.arsdigita.portation.modules.core.l10n.L10NConstants.L10N_XML_NS; + +/** + * + * @author Jens Pelzetter + */ +@XmlAccessorType(XmlAccessType.FIELD) +public class LocalizedStringValue implements Serializable { + + private static final long serialVersionUID = 8435485565736441379L; + + @XmlAttribute(name = "lang", namespace = L10N_XML_NS) + private String locale; + + @XmlValue + private String value; + + public String getLocale() { + return locale; + } + + public void setLocale(final String locale) { + this.locale = locale; + } + + public String getValue() { + return value; + } + + public void setValue(final String value) { + this.value = value; + } + + @Override + public int hashCode() { + int hash = 3; + hash = 97 * hash + Objects.hashCode(locale); + hash = 97 * hash + Objects.hashCode(value); + return hash; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (!(obj instanceof LocalizedStringValue)) { + return false; + } + final LocalizedStringValue other = (LocalizedStringValue) obj; + if (!other.canEqual(this)) { + return false; + } + if (!Objects.equals(locale, other.getLocale())) { + return false; + } + return Objects.equals(value, other.getValue()); + } + + public boolean canEqual(final Object obj) { + return obj instanceof LocalizedStringValue; + } + + @Override + public final String toString() { + return toString(""); + } + + public String toString(final String data) { + + return String.format("%s{ " + + "locale = %s, " + + "value = \"%s\"%s" + + " }", + super.toString(), + Objects.toString(locale), + value, + data); + } + +} diff --git a/ccm-core/src/com/arsdigita/portation/modules/core/l10n/jaxb/LocalizedStringValues.java b/ccm-core/src/com/arsdigita/portation/modules/core/l10n/jaxb/LocalizedStringValues.java new file mode 100644 index 000000000..5f3636e6f --- /dev/null +++ b/ccm-core/src/com/arsdigita/portation/modules/core/l10n/jaxb/LocalizedStringValues.java @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2017 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package com.arsdigita.portation.modules.core.l10n.jaxb; + +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +import static com.arsdigita.portation.modules.core.l10n.L10NConstants.L10N_XML_NS; + +/** + * + * @author Jens Pelzetter + */ +@XmlAccessorType(XmlAccessType.FIELD) +public class LocalizedStringValues implements Serializable { + + private static final long serialVersionUID = 1L; + + @JacksonXmlElementWrapper(useWrapping = false) + @XmlElement(name = "value", namespace = L10N_XML_NS) + private List values; + + public List getValues() { + return new ArrayList<>(values); + } + + public void setValues(final List values) { + this.values = new ArrayList<>(values); + } + + @Override + public int hashCode() { + int hash = 3; + hash = 41 * hash + Objects.hashCode(values); + return hash; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (!(obj instanceof LocalizedStringValues)) { + return false; + } + final LocalizedStringValues other = (LocalizedStringValues) obj; + if (!other.canEqual(this)) { + return false; + } + return Objects.equals(values, other.getValues()); + } + + public boolean canEqual(final Object obj) { + return obj instanceof LocalizedStringValues; + } + + @Override + public final String toString() { + return toString(""); + } + + public String toString(final String data) { + return String.format("%s{ " + + "values = %s%s" + + " }", + super.toString(), + Objects.toString(values), + data); + } + +} diff --git a/ccm-core/src/com/arsdigita/portation/modules/core/l10n/jaxb/LocalizedStringValuesAdapter.java b/ccm-core/src/com/arsdigita/portation/modules/core/l10n/jaxb/LocalizedStringValuesAdapter.java new file mode 100644 index 000000000..a396e5910 --- /dev/null +++ b/ccm-core/src/com/arsdigita/portation/modules/core/l10n/jaxb/LocalizedStringValuesAdapter.java @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2017 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package com.arsdigita.portation.modules.core.l10n.jaxb; + + +import com.arsdigita.portation.modules.core.l10n.LocalizedString; + +import javax.xml.bind.annotation.adapters.XmlAdapter; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * JAXB adapter for {@link LocalizedString#values} to produce a more compact XML + * for the values map. + * + * @author Jens Pelzetter + */ +public class LocalizedStringValuesAdapter + extends XmlAdapter> { + + @Override + public Map unmarshal(final LocalizedStringValues values) + throws Exception { + + return values + .getValues() + .stream() + .collect(Collectors.toMap(value -> new Locale(value.getLocale()), + value -> value.getValue())); + + } + + @Override + public LocalizedStringValues marshal(final Map values) + throws Exception { + + final List list = values + .entrySet() + .stream() + .map(this::generateValue) + .collect(Collectors.toList()); + + final LocalizedStringValues result = new LocalizedStringValues(); + result.setValues(list); + + return result; + } + + private LocalizedStringValue generateValue( + final Map.Entry entry) { + + final LocalizedStringValue value = new LocalizedStringValue(); + value.setLocale(entry.getKey().toString()); + value.setValue(entry.getValue()); + + return value; + } + +} diff --git a/ccm-core/src/com/arsdigita/portation/modules/core/workflow/Workflow.java b/ccm-core/src/com/arsdigita/portation/modules/core/workflow/Workflow.java index 385e50fb8..d15f668c3 100644 --- a/ccm-core/src/com/arsdigita/portation/modules/core/workflow/Workflow.java +++ b/ccm-core/src/com/arsdigita/portation/modules/core/workflow/Workflow.java @@ -44,8 +44,9 @@ public class Workflow implements Portable { private long workflowId; private String uuid; + private boolean abstractWorkflow; @JsonIdentityReference(alwaysAsId = true) - private WorkflowTemplate template; + private Workflow template; private LocalizedString name; private LocalizedString description; private WorkflowState state; @@ -57,11 +58,11 @@ public class Workflow implements Portable { private List tasks; - public Workflow(final com.arsdigita.workflow.simple.Workflow - trunkWorkFlow, boolean template) { + public Workflow(final com.arsdigita.workflow.simple.Workflow trunkWorkFlow) { this.workflowId = trunkWorkFlow.getID().longValue(); this.uuid = UUID.randomUUID().toString(); + this.abstractWorkflow = false; //this.template this.name = new LocalizedString(); @@ -79,8 +80,7 @@ public class Workflow implements Portable { this.tasks = new ArrayList<>(); - if (!template) - NgCoreCollection.workflows.put(this.workflowId, this); + NgCoreCollection.workflows.put(this.workflowId, this); } @@ -100,11 +100,19 @@ public class Workflow implements Portable { this.uuid = uuid; } - public WorkflowTemplate getTemplate() { + public boolean isAbstractWorkflow() { + return abstractWorkflow; + } + + public void setAbstractWorkflow(boolean abstractWorkflow) { + this.abstractWorkflow = abstractWorkflow; + } + + public Workflow getTemplate() { return template; } - public void setTemplate(final WorkflowTemplate template) { + public void setTemplate(Workflow template) { this.template = template; } diff --git a/ccm-core/src/com/arsdigita/portation/modules/core/workflow/WorkflowTemplate.java b/ccm-core/src/com/arsdigita/portation/modules/core/workflow/WorkflowTemplate.java deleted file mode 100644 index 2166ecd2b..000000000 --- a/ccm-core/src/com/arsdigita/portation/modules/core/workflow/WorkflowTemplate.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2015 LibreCCM Foundation. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ -package com.arsdigita.portation.modules.core.workflow; - -import com.arsdigita.portation.conversion.NgCoreCollection; -import com.fasterxml.jackson.annotation.JsonIdentityInfo; -import com.fasterxml.jackson.annotation.ObjectIdGenerators; - -/** - * @author sortedList = new ArrayList<>(); + + int runs = 0; + for (CcmApplication application : NgCoreCollection.ccmApplications + .values()) { + addResourceParent(sortedList, application); + + if (!sortedList.contains(application)) + sortedList.add(application); + + runs++; + } + NgCoreCollection.sortedCcmApplications = sortedList; + + System.err.printf("\t\tSorted ccm applications in %d runs.\n", runs); + } + + /** + * Helper method to recursively add all parent resources before their + * childs. + * + * @param sortedList List of already sorted assignable tasks + * @param ccmApplication Current assignable task + */ + private static void addResourceParent(ArrayList sortedList, + CcmApplication ccmApplication) { + CcmApplication resourceParent = (CcmApplication) ccmApplication + .getParent(); + + if (resourceParent != null) { + addResourceParent(sortedList, resourceParent); + + if (!sortedList.contains(resourceParent)) + sortedList.add(resourceParent); + } + } } 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 35ae66cd1..533b5e69b 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 @@ -65,7 +65,7 @@ public class LdnTermsExporter extends AbstractExporter { ccmApplicationMarshaller.prepare( Format.XML, pathName, "ccmApplications", indentation); ccmApplicationMarshaller.exportList( - new ArrayList<>(NgCoreCollection.ccmApplications.values())); + NgCoreCollection.sortedCcmApplications); System.out.printf("\tdone.\n"); }