From 1b40547cb0ec6ae67910b1722fe0762d45b89b04 Mon Sep 17 00:00:00 2001 From: tosmers Date: Thu, 3 Aug 2017 14:29:33 +0000 Subject: [PATCH] [TRUNK][FEATURE] - adds funktionalaty to convert trunks domain-, resourceType- and application-objects to their ng's counterparts - adds funktionality to export converted domains, resourceTypes and ccmApplications git-svn-id: https://svn.libreccm.org/ccm/trunk@4895 8810af33-2d31-482b-a856-94f89814c4df --- .../com/arsdigita/kernel/ResourceType.java | 50 +++--- .../src/com/arsdigita/portation/Portable.java | 28 ++++ .../portation/cmd/ExportCliTool.java | 112 ++++---------- .../core/security/GroupConversion.java | 6 +- .../core/security/PermissionConversion.java | 1 - .../core/workflow/WorkflowConversion.java | 9 +- .../portation/modules/CoreExporter.java | 144 ++++++++++-------- .../modules/core/core/CcmObject.java | 8 +- .../src/com/arsdigita/web/Application.java | 27 +++- .../conversion/LdnTermsConverter.java | 4 + .../conversion/NgCoreCollection.java | 7 + .../core/categorization/DomainConversion.java | 7 + .../core/core/ResourceTypeConversion.java | 53 +++++++ .../core/web/CcmApplicationConversion.java | 116 ++++++++++++++ .../portation/modules/LdnTermsExporter.java | 42 ++++- .../modules/core/categorization/Domain.java | 14 +- .../core/categorization/DomainIdResolver.java | 50 ++++++ .../core/categorization/DomainOwnership.java | 7 + .../portation/modules/core/core/Resource.java | 37 ++++- .../modules/core/core/ResourceIdResolver.java | 50 ++++++ .../modules/core/core/ResourceType.java | 26 +++- .../core/core/ResourceTypeIdResolver.java | 50 ++++++ .../core/core/ResourceTypeMarshaller.java | 29 ++++ .../modules/core/web/CcmApplication.java | 23 ++- .../core/web/CcmApplicationIdResolver.java | 50 ++++++ .../core/web/CcmApplicationMarshaller.java | 28 ++++ 26 files changed, 776 insertions(+), 202 deletions(-) create mode 100644 ccm-core/src/com/arsdigita/portation/Portable.java create mode 100644 ccm-ldn-terms/src/com/arsdigita/london/terms/portation/conversion/core/core/ResourceTypeConversion.java create mode 100644 ccm-ldn-terms/src/com/arsdigita/london/terms/portation/conversion/core/web/CcmApplicationConversion.java create mode 100644 ccm-ldn-terms/src/com/arsdigita/london/terms/portation/modules/core/categorization/DomainIdResolver.java create mode 100644 ccm-ldn-terms/src/com/arsdigita/london/terms/portation/modules/core/core/ResourceIdResolver.java create mode 100644 ccm-ldn-terms/src/com/arsdigita/london/terms/portation/modules/core/core/ResourceTypeIdResolver.java create mode 100644 ccm-ldn-terms/src/com/arsdigita/london/terms/portation/modules/core/core/ResourceTypeMarshaller.java create mode 100644 ccm-ldn-terms/src/com/arsdigita/london/terms/portation/modules/core/web/CcmApplicationIdResolver.java create mode 100644 ccm-ldn-terms/src/com/arsdigita/london/terms/portation/modules/core/web/CcmApplicationMarshaller.java diff --git a/ccm-core/src/com/arsdigita/kernel/ResourceType.java b/ccm-core/src/com/arsdigita/kernel/ResourceType.java index 312b95b6b..5533aad15 100755 --- a/ccm-core/src/com/arsdigita/kernel/ResourceType.java +++ b/ccm-core/src/com/arsdigita/kernel/ResourceType.java @@ -19,28 +19,19 @@ package com.arsdigita.kernel; import com.arsdigita.bebop.RequestLocal; -import com.arsdigita.kernel.ui.ResourceConfigFormSection; -import com.arsdigita.kernel.ui.ResourceConfigComponent; -import com.arsdigita.kernel.permissions.PrivilegeDescriptor; -import com.arsdigita.domain.DomainObject; -import com.arsdigita.persistence.DataObject; -import com.arsdigita.persistence.OID; -import com.arsdigita.persistence.SessionManager; -import com.arsdigita.persistence.DataCollection; -import com.arsdigita.persistence.DataAssociation; -import com.arsdigita.persistence.DataAssociationCursor; -import com.arsdigita.persistence.PersistenceException; import com.arsdigita.db.Sequences; +import com.arsdigita.domain.DomainCollection; +import com.arsdigita.domain.DomainObject; +import com.arsdigita.kernel.permissions.PrivilegeDescriptor; +import com.arsdigita.kernel.ui.ResourceConfigComponent; +import com.arsdigita.kernel.ui.ResourceConfigFormSection; +import com.arsdigita.persistence.*; import com.arsdigita.util.Assert; -import java.util.LinkedList; -import java.util.Iterator; -import java.util.Map; -import java.util.HashMap; -import java.util.Collections; -import java.util.Collection; +import org.apache.log4j.Logger; + import java.math.BigDecimal; import java.sql.SQLException; -import org.apache.log4j.Logger; +import java.util.*; /** * XXX JAVADOC XXX @@ -431,4 +422,27 @@ public class ResourceType extends DomainObject { return getConfig().getModifyComponent(resource); } + + /** + * Retrieves all objects of this type stored in the database. Very + * necessary for exporting all entities of the current work environment. + * + * @return List of all resource types + */ + public static List getAllObjectResourceTypes() { + List resourceTypeList = new ArrayList<>(); + + ResourceTypeCollection collection = ResourceType + .retrieveAllResourceTypes(); + + while (collection.next()) { + ResourceType resourceType = (ResourceType) collection.getDomainObject(); + if (resourceType != null) { + resourceTypeList.add(resourceType); + } + } + + collection.close(); + return resourceTypeList; + } } diff --git a/ccm-core/src/com/arsdigita/portation/Portable.java b/ccm-core/src/com/arsdigita/portation/Portable.java new file mode 100644 index 000000000..b2aab266f --- /dev/null +++ b/ccm-core/src/com/arsdigita/portation/Portable.java @@ -0,0 +1,28 @@ +/* + * 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; + +/** + * Interface for the ex-/import routine. With this interface any object class + * can declare itself ex- or im{@code portable}. + * + * @author trunkGroups, - roleGroups = new ArrayList<>(); - trunkGroups = com.arsdigita.kernel.Group.getAllObjectGroups(); + List trunkGroups = com.arsdigita.kernel + .Group.getAllObjectGroups(); System.err.println("done."); System.err.printf("\tConverting groups and group memberships...\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 31ae95e4e..8e83719a4 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 @@ -125,7 +125,6 @@ public class PermissionConversion { processed++; } - System.err.printf("\t\tCreated %d permissions and skipped: %d.\n", processed, skipped); } 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 78147f7e9..bd425480e 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 @@ -67,16 +67,17 @@ public class WorkflowConversion { trunkWorkflowTemplate = trunkWorkflow.getWorkflowTemplate(); if (trunkWorkflowTemplate != null) { WorkflowTemplate workflowTemplate = NgCoreCollection - .workflowTemplates.get(trunkWorkflowTemplate.getID() - .longValue()); + .workflowTemplates + .get(trunkWorkflowTemplate.getID().longValue()); workflow.setTemplate(workflowTemplate); } // set object association ACSObject trunkObject = trunkWorkflow.getObject(); if (trunkObject != null) { - CcmObject object = NgCoreCollection.ccmObjects.get(trunkObject - .getID().longValue()); + CcmObject object = NgCoreCollection + .ccmObjects + .get(trunkObject.getID().longValue()); workflow.setObject(object); } diff --git a/ccm-core/src/com/arsdigita/portation/modules/CoreExporter.java b/ccm-core/src/com/arsdigita/portation/modules/CoreExporter.java index 15fe6f4fa..917f54396 100644 --- a/ccm-core/src/com/arsdigita/portation/modules/CoreExporter.java +++ b/ccm-core/src/com/arsdigita/portation/modules/CoreExporter.java @@ -39,138 +39,148 @@ import java.util.ArrayList; * @version created on 25.07.2016 */ public class CoreExporter extends AbstractExporter { + public static void startExport() { + exportUsers(); + exportGroups(); + exportGroupMemberships(); + exportRoles(); + exportRoleMemberships(); - public static void exportUsers() { + exportCategories(); + exportCategorizations(); + + exportWorkflows(); + exportWorkflowTemplates(); + exportAssignableTasks(); + exportTaskAssignments(); + + exportPermissions(); + } + + + private static void exportUsers() { System.out.printf("\tExporting users..."); UserMarshaller userMarshaller = new UserMarshaller(); - userMarshaller - .prepare(Format.XML, pathName, "users", indentation); - userMarshaller - .exportList(new ArrayList<>(NgCoreCollection.users.values())); + userMarshaller.prepare( + Format.XML, pathName, "users", indentation); + userMarshaller.exportList( + new ArrayList<>(NgCoreCollection.users.values())); System.out.printf("\t\tdone.\n"); } - public static void exportGroups() { + private static void exportGroups() { System.out.printf("\tExporting groups..."); GroupMarshaller groupMarshaller = new GroupMarshaller(); - groupMarshaller - .prepare(Format.XML, pathName, "groups", indentation); - groupMarshaller - .exportList(new ArrayList<>(NgCoreCollection.groups.values())); + groupMarshaller.prepare( + Format.XML, pathName, "groups", indentation); + groupMarshaller.exportList( + new ArrayList<>(NgCoreCollection.groups.values())); System.out.printf("\t\tdone.\n"); } - public static void exportGroupMemberships() { + private static void exportGroupMemberships() { System.out.printf("\tExporting group memberships..."); GroupMembershipMarshaller groupMembershipMarshaller = new GroupMembershipMarshaller(); - groupMembershipMarshaller - .prepare(Format.XML, pathName, "groupMemberships", - indentation); - groupMembershipMarshaller - .exportList(new ArrayList<>(NgCoreCollection.groupMemberships - .values())); + groupMembershipMarshaller.prepare( + Format.XML, pathName, "groupMemberships", indentation); + groupMembershipMarshaller.exportList( + new ArrayList<>(NgCoreCollection.groupMemberships.values())); System.out.printf("\tdone.\n"); } - public static void exportRoles() { + private static void exportRoles() { System.out.printf("\tExporting roles..."); RoleMarshaller roleMarshaller = new RoleMarshaller(); - roleMarshaller - .prepare(Format.XML, pathName, "roles", indentation); - roleMarshaller - .exportList(new ArrayList<>(NgCoreCollection.roles.values())); + roleMarshaller.prepare( + Format.XML, pathName, "roles", indentation); + roleMarshaller.exportList( + new ArrayList<>(NgCoreCollection.roles.values())); System.out.printf("\t\tdone.\n"); } - public static void exportRoleMemberships() { + private static void exportRoleMemberships() { System.out.printf("\tExporting role memberships..."); RoleMembershipMarshaller roleMembershipMarshaller = new RoleMembershipMarshaller(); - roleMembershipMarshaller - .prepare(Format.XML, pathName, "roleMemberships", indentation); - roleMembershipMarshaller.exportList(new ArrayList<> - (NgCoreCollection.roleMemberships.values())); + roleMembershipMarshaller.prepare( + Format.XML, pathName, "roleMemberships", indentation); + roleMembershipMarshaller.exportList( + new ArrayList<>(NgCoreCollection.roleMemberships.values())); System.out.printf("\tdone.\n"); } - public static void exportCategories() { + private static void exportCategories() { System.out.printf("\tExporting categories..."); CategoryMarshaller categoryMarshaller = new CategoryMarshaller(); - categoryMarshaller - .prepare(Format.XML, pathName, "categories", indentation); - categoryMarshaller - .exportList(NgCoreCollection.sortedCategories); + categoryMarshaller.prepare( + Format.XML, pathName, "categories", indentation); + categoryMarshaller.exportList(NgCoreCollection.sortedCategories); System.out.printf("\t\tdone.\n"); } - public static void exportCategorizations() { + private static void exportCategorizations() { System.out.printf("\tExporting categorizations..."); CategorizationMarshaller categorizationMarshaller = new CategorizationMarshaller(); - categorizationMarshaller - .prepare(Format.XML, pathName, "categorizations", indentation); - categorizationMarshaller - .exportList(new ArrayList<>(NgCoreCollection.categorizations - .values())); + categorizationMarshaller.prepare( + Format.XML, pathName, "categorizations", indentation); + categorizationMarshaller.exportList( + new ArrayList<>(NgCoreCollection.categorizations.values())); System.out.printf("\tdone.\n"); } - public static void exportWorkflowTemplates() { + 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())); + workflowTemplateMarshaller.prepare( + Format.XML, pathName, "workflowTemplates", indentation); + workflowTemplateMarshaller.exportList( + new ArrayList<>(NgCoreCollection.workflowTemplates.values())); System.out.printf("\tdone.\n"); } - public static void exportWorkflows() { + 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())); + workflowMarshaller.prepare( + Format.XML, pathName, "workflows", indentation); + workflowMarshaller.exportList( + new ArrayList<>(NgCoreCollection.workflows.values())); System.out.printf("\t\tdone.\n"); } - public static void exportAssignableTasks() { + private static void exportAssignableTasks() { System.out.printf("\tExporting assignable tasks..."); AssignableTaskMarshaller assignableTaskMarshaller = new AssignableTaskMarshaller(); - assignableTaskMarshaller - .prepare(Format.XML, pathName, "assignableTasks", indentation); - assignableTaskMarshaller - .exportList(new ArrayList<>(NgCoreCollection.assignableTasks - .values())); + assignableTaskMarshaller.prepare( + Format.XML, pathName, "assignableTasks", indentation); + assignableTaskMarshaller.exportList( + new ArrayList<>(NgCoreCollection.assignableTasks.values())); System.out.printf("\tdone.\n"); } - public static void exportTaskAssignments() { + private static void exportTaskAssignments() { System.out.printf("\tExporting task assignments..."); TaskAssignmentMarshaller taskAssignmentMarshaller = new TaskAssignmentMarshaller(); - taskAssignmentMarshaller - .prepare(Format.XML, pathName, "taskAssignments", indentation); - taskAssignmentMarshaller - .exportList(new ArrayList<>(NgCoreCollection.taskAssignments - .values())); + taskAssignmentMarshaller.prepare( + Format.XML, pathName, "taskAssignments", indentation); + taskAssignmentMarshaller.exportList( + new ArrayList<>(NgCoreCollection.taskAssignments.values())); System.out.printf("\tdone.\n"); } - public static void exportPermissions() { + private static void exportPermissions() { System.out.printf("\tExporting permissions..."); PermissionMarshaller permissionMarshaller = new PermissionMarshaller(); - permissionMarshaller - .prepare(Format.XML, pathName, "permissions", indentation); - permissionMarshaller - .exportList(new ArrayList<>(NgCoreCollection.permissions.values())); + permissionMarshaller.prepare( + Format.XML, pathName, "permissions", indentation); + permissionMarshaller.exportList( + new ArrayList<>(NgCoreCollection.permissions.values())); System.out.printf("\tdone.\n"); } } diff --git a/ccm-core/src/com/arsdigita/portation/modules/core/core/CcmObject.java b/ccm-core/src/com/arsdigita/portation/modules/core/core/CcmObject.java index dec3f39c3..50d1b97c6 100644 --- a/ccm-core/src/com/arsdigita/portation/modules/core/core/CcmObject.java +++ b/ccm-core/src/com/arsdigita/portation/modules/core/core/CcmObject.java @@ -74,18 +74,18 @@ public class CcmObject { NgCoreCollection.ccmObjects.put(this.objectId, this); } - public CcmObject() {} - /*public CcmObject(final Domain trunkDomain) { + // specific constructor for ldn-terms' domain + public CcmObject(String domainKey) { this.objectId = ACSObject.generateID().longValue(); this.uuid = UUID.randomUUID().toString(); - this.displayName = trunkDomain.getKey() + "_DName"; + this.displayName = domainKey + "_DName"; this.permissions = new ArrayList<>(); this.categories = new ArrayList<>(); NgCoreCollection.ccmObjects.put(this.objectId, this); - }*/ + } public long getObjectId() { return objectId; diff --git a/ccm-core/src/com/arsdigita/web/Application.java b/ccm-core/src/com/arsdigita/web/Application.java index 5b0a3386a..5ae4dffaf 100755 --- a/ccm-core/src/com/arsdigita/web/Application.java +++ b/ccm-core/src/com/arsdigita/web/Application.java @@ -24,10 +24,7 @@ import com.arsdigita.kernel.ACSObject; import com.arsdigita.kernel.Group; import com.arsdigita.kernel.Kernel; import com.arsdigita.kernel.Resource; -import com.arsdigita.persistence.DataCollection; -import com.arsdigita.persistence.DataObject; -import com.arsdigita.persistence.OID; -import com.arsdigita.persistence.SessionManager; +import com.arsdigita.persistence.*; import com.arsdigita.util.Assert; import java.math.BigDecimal; @@ -784,4 +781,26 @@ public class Application extends Resource { (DataObject) get("containerGroup")); } + /** + * Retrieves all objects of this type stored in the database. Very + * necessary for exporting all entities of the current work environment. + * + * @return List of all applications + */ + public static List getAllApplicationObjects() { + List applicationList = new ArrayList<>(); + + ApplicationCollection collection = Application + .retrieveAllApplications(); + + while (collection.next()) { + Application application = (Application) collection.getDomainObject(); + if (application != null) { + applicationList.add(application); + } + } + + collection.close(); + return applicationList; + } } diff --git a/ccm-ldn-terms/src/com/arsdigita/london/terms/portation/conversion/LdnTermsConverter.java b/ccm-ldn-terms/src/com/arsdigita/london/terms/portation/conversion/LdnTermsConverter.java index 67b10fbd6..122e365ef 100644 --- a/ccm-ldn-terms/src/com/arsdigita/london/terms/portation/conversion/LdnTermsConverter.java +++ b/ccm-ldn-terms/src/com/arsdigita/london/terms/portation/conversion/LdnTermsConverter.java @@ -19,6 +19,8 @@ package com.arsdigita.london.terms.portation.conversion; import com.arsdigita.london.terms.portation.conversion.core.categorization.DomainConversion; +import com.arsdigita.london.terms.portation.conversion.core.core.ResourceTypeConversion; +import com.arsdigita.london.terms.portation.conversion.core.web.CcmApplicationConversion; import com.arsdigita.portation.AbstractConverter; /** @@ -46,6 +48,8 @@ public class LdnTermsConverter extends AbstractConverter { @Override public void startConversionToNg() { DomainConversion.convertAll(); + ResourceTypeConversion.convertAll(); + CcmApplicationConversion.convertAll(); } /** 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 4ff4aaad8..128367ff3 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 @@ -19,6 +19,9 @@ package com.arsdigita.london.terms.portation.conversion; import com.arsdigita.london.terms.portation.modules.core.categorization.Domain; +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.HashMap; import java.util.Map; @@ -30,6 +33,10 @@ import java.util.Map; public class NgCoreCollection { public static Map domains = new HashMap<>(); + public static Map resourceTypes = new HashMap<>(); + public static Map resources = new HashMap<>(); + public static Map ccmApplications = new HashMap<>(); + /** * Private constructor to prevent the instantiation of this class. */ 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 ef4d309cc..17da6cbd8 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 @@ -51,6 +51,13 @@ public class DomainConversion { System.err.printf("\tdone.\n"); } + /** + * Creates the equivalent ng-class of the {@code Domain} and restores + * the associations to other classes. + * + * @param trunkDomains List of all {@link com.arsdigita.london.terms.Domain}s + * from this old trunk-system. + */ private static void createDomainsAndSetAssociations( List trunkDomains) { long processed = 0; 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 new file mode 100644 index 000000000..efcf28566 --- /dev/null +++ b/ccm-ldn-terms/src/com/arsdigita/london/terms/portation/conversion/core/core/ResourceTypeConversion.java @@ -0,0 +1,53 @@ +/* + * 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.london.terms.portation.conversion.core.core; + +import com.arsdigita.london.terms.portation.modules.core.core.ResourceType; + +import java.util.List; + +/** + * @author trunkResourceTypes = com + .arsdigita.kernel.ResourceType.getAllObjectResourceTypes(); + System.err.println("done."); + + System.err.printf("\tConverting domains...\n"); + // create resource types + long processed = 0; + for (com.arsdigita.kernel.ResourceType trunkResourceType : + trunkResourceTypes) { + new ResourceType(trunkResourceType); + processed++; + } + System.out.printf("\t\tCreated %d resource types.\n", processed); + System.err.printf("\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 new file mode 100644 index 000000000..e169cac3e --- /dev/null +++ b/ccm-ldn-terms/src/com/arsdigita/london/terms/portation/conversion/core/web/CcmApplicationConversion.java @@ -0,0 +1,116 @@ +/* + * 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.london.terms.portation.conversion.core.web; + + +import com.arsdigita.london.terms.portation.conversion.NgCoreCollection; +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 com.arsdigita.web.Application; + +import java.util.List; + +/** + * @author trunkApplications = Application + .getAllApplicationObjects(); + System.err.println("done."); + + System.err.printf("\tConverting ccm applications...\n"); + // create ccm applications + createCcmApplicationsAndSetAssociations(trunkApplications); + setRingAssociations(trunkApplications); + System.err.printf("\tdone.\n"); + } + + /** + * Creates the equivalent ng-class of the {@code Application} and restores + * the associations to other classes. + * + * @param trunkApplications List of all {@link Application}s + * from this old trunk-system. + */ + private static void createCcmApplicationsAndSetAssociations( + List trunkApplications) { + long processed = 0; + + for (Application trunkApplication : trunkApplications) { + // create applications + CcmApplication ccmApplication = new CcmApplication + (trunkApplication); + + // set resource type + com.arsdigita.kernel.ResourceType trunkResourceType = trunkApplication + .getResourceType(); + if (trunkResourceType != null) { + ResourceType resourceType = NgCoreCollection + .resourceTypes + .get(trunkResourceType.getID().longValue()); + ccmApplication.setResourceType(resourceType); + } + + //System.err.println(String.format( + // "ccm application id: %d", ccmApplication.getObjectId())); + processed++; + } + System.err.printf("\t\tCreated %d ccm applications.\n", processed); + } + + /** + * Method for setting the parent {@link Resource} on the one side and the + * sub-{@link Resource}s on the other side. Attribute of class + * {@link Resource}. + * + * @param trunkApplications List of all {@link Application} from the old + * trunk-system. + */ + private static void setRingAssociations(List trunkApplications) { + for (Application trunkApplication : trunkApplications) { + CcmApplication ccmApplication = NgCoreCollection + .ccmApplications + .get(trunkApplication.getID().longValue()); + + // set parent Resource and opposed association + CcmApplication parentResource = null; + + Application trunkParent = trunkApplication + .getParentApplication(); + if (trunkParent != null) { + parentResource = NgCoreCollection + .ccmApplications + .get(trunkParent.getID().longValue()); + + ccmApplication.setParent(parentResource); + parentResource.addChild(ccmApplication); + } + } + } +} 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 0cfc01908..b7f89cde0 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 @@ -19,7 +19,9 @@ package com.arsdigita.london.terms.portation.modules; import com.arsdigita.london.terms.portation.conversion.NgCoreCollection; +import com.arsdigita.london.terms.portation.modules.core.core.ResourceTypeMarshaller; import com.arsdigita.london.terms.portation.modules.core.categorization.DomainMarshaller; +import com.arsdigita.london.terms.portation.modules.core.web.CcmApplicationMarshaller; import com.arsdigita.portation.AbstractExporter; import com.arsdigita.portation.Format; @@ -29,19 +31,49 @@ import java.util.ArrayList; * Helper to implement the specifics for the exportation. Makes source code * in the cli-tool shorter and more readable. * + * Their exists no direct usage of this class. It is used via reflections in + * the ccm-core package to start export of these classes. + * * @author (NgCoreCollection.domains.values())); + 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 + ResourceTypeMarshaller(); + resourceTypeMarshaller.prepare( + Format.XML, pathName, "resourceTypes", indentation); + resourceTypeMarshaller.exportList( + new ArrayList<>(NgCoreCollection.resourceTypes.values())); + System.out.printf("\tdone.\n"); + } + + private static void exportCcmApplications() { + System.out.printf("\tExporting ccm applications..."); + CcmApplicationMarshaller ccmApplicationMarshaller = new + CcmApplicationMarshaller(); + ccmApplicationMarshaller.prepare( + Format.XML, pathName, "ccmApplications", indentation); + ccmApplicationMarshaller.exportList( + new ArrayList<>(NgCoreCollection.ccmApplications.values())); + System.out.printf("\tdone.\n"); + } } diff --git a/ccm-ldn-terms/src/com/arsdigita/london/terms/portation/modules/core/categorization/Domain.java b/ccm-ldn-terms/src/com/arsdigita/london/terms/portation/modules/core/categorization/Domain.java index 9929c6b19..2a3811c64 100644 --- a/ccm-ldn-terms/src/com/arsdigita/london/terms/portation/modules/core/categorization/Domain.java +++ b/ccm-ldn-terms/src/com/arsdigita/london/terms/portation/modules/core/categorization/Domain.java @@ -18,12 +18,14 @@ */ package com.arsdigita.london.terms.portation.modules.core.categorization; +import com.arsdigita.kernel.ACSObject; import com.arsdigita.london.terms.portation.conversion.NgCoreCollection; import com.arsdigita.london.terms.portation.modules.core.web.CcmApplication; import com.arsdigita.portation.Portable; import com.arsdigita.portation.modules.core.categorization.Category; import com.arsdigita.portation.modules.core.core.CcmObject; import com.arsdigita.portation.modules.core.l10n.LocalizedString; +import com.fasterxml.jackson.annotation.*; import java.util.ArrayList; import java.util.Date; @@ -44,6 +46,9 @@ import java.util.Locale; * @author owners; public Domain(com.arsdigita.london.terms.Domain trunkDomain) { - super(); + super(trunkDomain.getKey()); + this.domainKey = trunkDomain.getKey(); this.uri = trunkDomain.getURL().toString(); @@ -65,8 +73,8 @@ public class Domain extends CcmObject implements Portable { this.title = new LocalizedString(); this.title.addValue(Locale.getDefault(), trunkDomain.getTitle()); this.description = new LocalizedString(); - this.description.addValue(Locale.getDefault(), trunkDomain - .getDescription()); + this.description + .addValue(Locale.getDefault(), trunkDomain.getDescription()); this.version = trunkDomain.getVersion(); this.released = trunkDomain.getReleased(); diff --git a/ccm-ldn-terms/src/com/arsdigita/london/terms/portation/modules/core/categorization/DomainIdResolver.java b/ccm-ldn-terms/src/com/arsdigita/london/terms/portation/modules/core/categorization/DomainIdResolver.java new file mode 100644 index 000000000..72a629a2f --- /dev/null +++ b/ccm-ldn-terms/src/com/arsdigita/london/terms/portation/modules/core/categorization/DomainIdResolver.java @@ -0,0 +1,50 @@ +/* + * 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.london.terms.portation.modules.core.categorization; + +import com.fasterxml.jackson.annotation.ObjectIdGenerator; +import com.fasterxml.jackson.annotation.ObjectIdResolver; + +/** + * @author Tobias Osmers<\a> * @version created the 7/27/17 */ +@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, + resolver = ResourceIdResolver.class, + property = "uuid") public class Resource extends CcmObject { private LocalizedString title; private LocalizedString description; + @JsonIdentityReference(alwaysAsId = true) private ResourceType resourceType; private Date created; + @JsonIgnore private List childs; + @JsonIdentityReference(alwaysAsId = true) private Resource parent; - public Resource(ACSObject trunkObject) { + public Resource(com.arsdigita.kernel.Resource trunkObject) { super(trunkObject); + + this.title = new LocalizedString(); + this.title.addValue(Locale.getDefault(), trunkObject.getTitle()); + this.description = new LocalizedString(); + this.description + .addValue(Locale.getDefault(), trunkObject.getDescription()); + + //this.resourceType; + this.created = trunkObject.getTimestamp(); + this.childs = new ArrayList<>(); + //this.parent + + NgCoreCollection.resources.put(this.getObjectId(), this); } @@ -95,6 +120,14 @@ public class Resource extends CcmObject { this.childs = childs; } + public void addChild(final Resource child) { + this.childs.add(child); + } + + public void removeChild(final Resource child) { + this.childs.remove(child); + } + public Resource getParent() { return parent; } diff --git a/ccm-ldn-terms/src/com/arsdigita/london/terms/portation/modules/core/core/ResourceIdResolver.java b/ccm-ldn-terms/src/com/arsdigita/london/terms/portation/modules/core/core/ResourceIdResolver.java new file mode 100644 index 000000000..8d0b1c2ad --- /dev/null +++ b/ccm-ldn-terms/src/com/arsdigita/london/terms/portation/modules/core/core/ResourceIdResolver.java @@ -0,0 +1,50 @@ +/* + * 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.london.terms.portation.modules.core.core; + +import com.fasterxml.jackson.annotation.ObjectIdGenerator; +import com.fasterxml.jackson.annotation.ObjectIdResolver; + +/** + * @author Tobias Osmers<\a> * @version created the 7/27/17 */ -public class ResourceType { +@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, + resolver = ResourceTypeIdResolver.class, + property = "title") +public class ResourceType implements Portable { private long resourceTypeId; private String title; @@ -43,6 +52,21 @@ public class ResourceType { private boolean viewableAsEmbedded; private boolean singleton; + public ResourceType(com.arsdigita.kernel.ResourceType trunkObject) { + this.resourceTypeId = trunkObject.getID().longValue(); + + this.title = trunkObject.getTitle(); + this.description = new LocalizedString(); + this.description + .addValue(Locale.getDefault(), trunkObject.getDescription()); + + this.workspaceApplication = false; + this.viewableAsFullPage = false; + this.viewableAsEmbedded = false; + this.singleton = false; + + NgCoreCollection.resourceTypes.put(this.resourceTypeId, this); + } public long getResourceTypeId() { return resourceTypeId; diff --git a/ccm-ldn-terms/src/com/arsdigita/london/terms/portation/modules/core/core/ResourceTypeIdResolver.java b/ccm-ldn-terms/src/com/arsdigita/london/terms/portation/modules/core/core/ResourceTypeIdResolver.java new file mode 100644 index 000000000..c56f45baf --- /dev/null +++ b/ccm-ldn-terms/src/com/arsdigita/london/terms/portation/modules/core/core/ResourceTypeIdResolver.java @@ -0,0 +1,50 @@ +/* + * 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.london.terms.portation.modules.core.core; + +import com.fasterxml.jackson.annotation.ObjectIdGenerator; +import com.fasterxml.jackson.annotation.ObjectIdResolver; + +/** + * @author Tobias Osmers<\a> + * @version created the 8/3/17 + */ +public class ResourceTypeMarshaller extends AbstractMarshaller { +} diff --git a/ccm-ldn-terms/src/com/arsdigita/london/terms/portation/modules/core/web/CcmApplication.java b/ccm-ldn-terms/src/com/arsdigita/london/terms/portation/modules/core/web/CcmApplication.java index 1696c7c70..c1a8990da 100644 --- a/ccm-ldn-terms/src/com/arsdigita/london/terms/portation/modules/core/web/CcmApplication.java +++ b/ccm-ldn-terms/src/com/arsdigita/london/terms/portation/modules/core/web/CcmApplication.java @@ -18,25 +18,42 @@ */ package com.arsdigita.london.terms.portation.modules.core.web; -import com.arsdigita.kernel.ACSObject; +import com.arsdigita.london.terms.portation.conversion.NgCoreCollection; import com.arsdigita.london.terms.portation.modules.core.categorization.DomainOwnership; import com.arsdigita.london.terms.portation.modules.core.core.Resource; +import com.arsdigita.portation.Portable; +import com.arsdigita.web.Application; +import com.fasterxml.jackson.annotation.JsonIdentityInfo; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.ObjectIdGenerators; +import java.util.ArrayList; import java.util.List; /** * @author domains; - public CcmApplication(ACSObject trunkObject) { + public CcmApplication(Application trunkObject) { super(trunkObject); + + this.applicationType = trunkObject.getApplicationType().toString(); + this.primaryUrl = trunkObject.getPrimaryURL(); + + this.domains = new ArrayList<>(); + + NgCoreCollection.ccmApplications.put(getObjectId(), this); } diff --git a/ccm-ldn-terms/src/com/arsdigita/london/terms/portation/modules/core/web/CcmApplicationIdResolver.java b/ccm-ldn-terms/src/com/arsdigita/london/terms/portation/modules/core/web/CcmApplicationIdResolver.java new file mode 100644 index 000000000..a2464079e --- /dev/null +++ b/ccm-ldn-terms/src/com/arsdigita/london/terms/portation/modules/core/web/CcmApplicationIdResolver.java @@ -0,0 +1,50 @@ +/* + * 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.london.terms.portation.modules.core.web; + +import com.fasterxml.jackson.annotation.ObjectIdGenerator; +import com.fasterxml.jackson.annotation.ObjectIdResolver; + +/** + * @author Tobias Osmers<\a> + * @version created the 8/3/17 + */ +public class CcmApplicationMarshaller extends AbstractMarshaller { +}