From aa0a3f8838f60435f6a12c59529d15148a697ea1 Mon Sep 17 00:00:00 2001 From: tosmers Date: Wed, 29 Jun 2016 17:31:17 +0000 Subject: [PATCH] adds converter methods for converting workflow, category and task objects from trunk-POJOs into NG-POJOs; adds retrieveAll method for workflow objects git-svn-id: https://svn.libreccm.org/ccm/trunk@4178 8810af33-2d31-482b-a856-94f89814c4df --- .../arsdigita/portation/cmd/CoreExport.java | 74 --------------- .../portation/cmd/ExportCliTool.java | 46 +++------ .../core/categorization/Categorization.java | 14 ++- .../modules/core/categorization/Category.java | 67 ++++++++++--- .../utils/CollectionConverter.java | 81 ---------------- .../modules/core/core/CcmObject.java | 34 ++++++- .../portation/modules/core/workflow/Task.java | 67 +++++++++++-- .../modules/core/workflow/Workflow.java | 27 ++++-- .../modules/utils/CollectionConverter.java | 95 ------------------- .../arsdigita/workflow/simple/Workflow.java | 24 ++++- 10 files changed, 213 insertions(+), 316 deletions(-) delete mode 100644 ccm-core/src/com/arsdigita/portation/cmd/CoreExport.java delete mode 100644 ccm-core/src/com/arsdigita/portation/modules/core/categorization/utils/CollectionConverter.java delete mode 100644 ccm-core/src/com/arsdigita/portation/modules/utils/CollectionConverter.java diff --git a/ccm-core/src/com/arsdigita/portation/cmd/CoreExport.java b/ccm-core/src/com/arsdigita/portation/cmd/CoreExport.java deleted file mode 100644 index 51b65a2d7..000000000 --- a/ccm-core/src/com/arsdigita/portation/cmd/CoreExport.java +++ /dev/null @@ -1,74 +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.cmd; - -import com.arsdigita.portation.Format; -import com.arsdigita.portation.modules.core.security.Group; -import com.arsdigita.portation.modules.core.security.GroupMarshaller; -import com.arsdigita.portation.modules.core.security.Party; -import com.arsdigita.portation.modules.core.security.PartyMarshaller; -import com.arsdigita.portation.modules.core.security.User; -import com.arsdigita.portation.modules.core.security.UserMarshaller; -import com.arsdigita.portation.modules.utils.CollectionConverter; -import org.apache.log4j.Logger; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author []\n" + - "\n" + - "Available commands:\n" + - "\tlist \t\t Shows information on how to use this tool.\n" + - "\texportUsers \t\t Exports the chosen category to xml file.\n" + - "\n" + - "Available categories for exportUsers:\n" + - " \t\t users \t all users of the system\n" + - " \t\t groups \t all groups of the system\n" + - "Use for exporting java objects of a specified class to a xml-file.\n" + "\t\t\t--- ExportCliTool ---\n" + + "usage:\t []\n" + + "\n" + + "Available commands:\n" + + "\tlist \t\t Shows information on how to use this tool.\n" + + "\texportUsers \t\t Exports the chosen category to xml file.\n" + + "\n" + + "Available categories for exportUsers:\n" + + " \t\t users \t all users of the system\n" + + " \t\t groups \t all groups of the system\n" + + "Use for exporting java objects of a specified class to a xml-file.\n" ); } } diff --git a/ccm-core/src/com/arsdigita/portation/modules/core/categorization/Categorization.java b/ccm-core/src/com/arsdigita/portation/modules/core/categorization/Categorization.java index a3bc7ed64..746d6792d 100644 --- a/ccm-core/src/com/arsdigita/portation/modules/core/categorization/Categorization.java +++ b/ccm-core/src/com/arsdigita/portation/modules/core/categorization/Categorization.java @@ -18,9 +18,9 @@ */ package com.arsdigita.portation.modules.core.categorization; -import com.arsdigita.kernel.ACSObject; import com.arsdigita.portation.AbstractMarshaller; import com.arsdigita.portation.Identifiable; +import com.arsdigita.portation.conversion.NgCollection; import com.arsdigita.portation.modules.core.core.CcmObject; /** @@ -41,7 +41,17 @@ public class Categorization implements Identifiable { private long objectOrder; - public Categorization(final ACSObject acsObject) { + public Categorization(Category category, CcmObject categorizedObject) { + this.categorizationId = NgCollection.categorizations.size() + 1; + + this.category = category; + this.categorizedObject = categorizedObject; + + this.index = false; + this.categoryOrder = categorizedObject.getCategories().size() + 1; + this.objectOrder = category.getObjects().size() + 1; + + NgCollection.categorizations.put(this.categorizationId, this); } 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 e1a47c106..a96f41b38 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 @@ -18,12 +18,16 @@ */ package com.arsdigita.portation.modules.core.categorization; +import com.arsdigita.categorization.CategoryLocalization; import com.arsdigita.portation.AbstractMarshaller; import com.arsdigita.portation.Identifiable; +import com.arsdigita.portation.conversion.NgCollection; import com.arsdigita.portation.modules.core.core.CcmObject; import com.arsdigita.portation.modules.core.l10n.LocalizedString; +import java.util.ArrayList; import java.util.List; +import java.util.Locale; /** * The category entity represents a single category. Each category is part of a @@ -50,14 +54,37 @@ public class Category extends CcmObject { private boolean abstractCategory; private List objects; - private List subCategories; + private Category parentCategory; private long categoryOrder; public Category(final com.arsdigita.categorization.Category trunkCategory) { super(trunkCategory); + + this.uniqueId = trunkCategory.getID().toString(); + this.name = trunkCategory.getName(); + + CategoryLocalization categoryLocalization = trunkCategory + .getCategoryLocalizationCollection().getCategoryLocalization(); + Locale locale = new Locale(categoryLocalization.getLocale()); + this.title.addValue(locale, categoryLocalization.getName()); + this.description.addValue(locale, categoryLocalization.getDescription()); + + this.enabled = trunkCategory.isEnabled(); + this.visible = trunkCategory.isVisible(); + this.abstractCategory = trunkCategory.isAbstract(); + + this.objects = new ArrayList<>(); + this.subCategories = new ArrayList<>(); + + //this.parentCategory + + this.categoryOrder = trunkCategory.getDefaultParentCategory() + .getNumberOfChildCategories() + 1; + + NgCollection.categories.put(this.getObjectId(), this); } @@ -70,7 +97,7 @@ public class Category extends CcmObject { return uniqueId; } - public void setUniqueId(String uniqueId) { + public void setUniqueId(final String uniqueId) { this.uniqueId = uniqueId; } @@ -78,7 +105,7 @@ public class Category extends CcmObject { return name; } - public void setName(String name) { + public void setName(final String name) { this.name = name; } @@ -86,7 +113,7 @@ public class Category extends CcmObject { return this.title; } - public void setTitle(LocalizedString title) { + public void setTitle(final LocalizedString title) { this.title = title; } @@ -94,7 +121,7 @@ public class Category extends CcmObject { return this.description; } - public void setDescription(LocalizedString description) { + public void setDescription(final LocalizedString description) { this.description = description; } @@ -102,7 +129,7 @@ public class Category extends CcmObject { return enabled; } - public void setEnabled(boolean enabled) { + public void setEnabled(final boolean enabled) { this.enabled = enabled; } @@ -110,7 +137,7 @@ public class Category extends CcmObject { return visible; } - public void setVisible(boolean visible) { + public void setVisible(final boolean visible) { this.visible = visible; } @@ -118,7 +145,7 @@ public class Category extends CcmObject { return abstractCategory; } - public void setAbstractCategory(boolean abstractCategory) { + public void setAbstractCategory(final boolean abstractCategory) { this.abstractCategory = abstractCategory; } @@ -126,23 +153,39 @@ public class Category extends CcmObject { return objects; } - public void setObjects(List objects) { + public void setObjects(final List objects) { this.objects = objects; } + public void addObject(final Categorization object) { + this.objects.add(object); + } + + public void removeObject(final Categorization object) { + this.objects.remove(object); + } + public List getSubCategories() { return subCategories; } - public void setSubCategories(List subCategories) { + public void setSubCategories(final List subCategories) { this.subCategories = subCategories; } + public void addSubCategory(final Category subCategory) { + this.subCategories.add(subCategory); + } + + public void removeSubCategory(final Category subCategory) { + this.subCategories.remove(subCategory); + } + public Category getParentCategory() { return parentCategory; } - public void setParentCategory(Category parentCategory) { + public void setParentCategory(final Category parentCategory) { this.parentCategory = parentCategory; } @@ -150,7 +193,7 @@ public class Category extends CcmObject { return categoryOrder; } - public void setCategoryOrder(long categoryOrder) { + public void setCategoryOrder(final long categoryOrder) { this.categoryOrder = categoryOrder; } } diff --git a/ccm-core/src/com/arsdigita/portation/modules/core/categorization/utils/CollectionConverter.java b/ccm-core/src/com/arsdigita/portation/modules/core/categorization/utils/CollectionConverter.java deleted file mode 100644 index f45dc3e1b..000000000 --- a/ccm-core/src/com/arsdigita/portation/modules/core/categorization/utils/CollectionConverter.java +++ /dev/null @@ -1,81 +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.categorization.utils; - -import com.arsdigita.categorization.CategorizedCollection; -import com.arsdigita.categorization.CategoryCollection; -import com.arsdigita.portation.modules.core.categorization.Categorization; -import com.arsdigita.portation.modules.core.categorization.Category; -import org.apache.log4j.Logger; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author convertCategories(CategoryCollection - categoryCollection) { - List categories = new ArrayList<>(); - if (categoryCollection != null) { - while (categoryCollection.next()) { - //.add(new Category()); - } - categoryCollection.close(); - } else { - logger.error("Failed to convertCategories, cause " + - "categoryCollection is null."); - } - return categories; - } -} 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 0d3c07dfd..edcfceeb7 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 @@ -25,7 +25,9 @@ import com.arsdigita.portation.modules.core.categorization.Categorization; import com.arsdigita.portation.modules.core.categorization.Category; import com.arsdigita.portation.modules.core.security.Permission; +import java.util.ArrayList; import java.util.List; +import java.util.UUID; /** * Root class of all entities in LibreCCM which need categorisation and @@ -54,7 +56,13 @@ public class CcmObject implements Identifiable { public CcmObject(final ACSObject trunkObject) { + this.objectId = trunkObject.getID().longValue(); + this.uuid = UUID.randomUUID().toString(); + this.displayName = trunkObject.getDisplayName(); + this.permissions = new ArrayList<>(); + this.categories = new ArrayList<>(); + //NgCollection.ccmObjects.put(this.objectId, this); } @Override @@ -66,7 +74,7 @@ public class CcmObject implements Identifiable { return objectId; } - public void setObjectId(long objectId) { + public void setObjectId(final long objectId) { this.objectId = objectId; } @@ -74,7 +82,7 @@ public class CcmObject implements Identifiable { return uuid; } - public void setUuid(String uuid) { + public void setUuid(final String uuid) { this.uuid = uuid; } @@ -82,7 +90,7 @@ public class CcmObject implements Identifiable { return displayName; } - public void setDisplayName(String displayName) { + public void setDisplayName(final String displayName) { this.displayName = displayName; } @@ -90,15 +98,31 @@ public class CcmObject implements Identifiable { return permissions; } - public void setPermissions(List permissions) { + public void setPermissions(final List permissions) { this.permissions = permissions; } + public void addPermission(final Permission permission) { + permissions.add(permission); + } + + public void removePermission(final Permission permission) { + permissions.remove(permission); + } + public List getCategories() { return categories; } - public void setCategories(List categories) { + public void setCategories(final List categories) { this.categories = categories; } + + public void addCategory(final Categorization category) { + categories.add(category); + } + + public void removeCategory(final Categorization category) { + categories.remove(category); + } } diff --git a/ccm-core/src/com/arsdigita/portation/modules/core/workflow/Task.java b/ccm-core/src/com/arsdigita/portation/modules/core/workflow/Task.java index b3e1554ea..af9e690c3 100644 --- a/ccm-core/src/com/arsdigita/portation/modules/core/workflow/Task.java +++ b/ccm-core/src/com/arsdigita/portation/modules/core/workflow/Task.java @@ -20,9 +20,13 @@ package com.arsdigita.portation.modules.core.workflow; import com.arsdigita.portation.AbstractMarshaller; import com.arsdigita.portation.Identifiable; +import com.arsdigita.portation.conversion.NgCollection; import com.arsdigita.portation.modules.core.l10n.LocalizedString; +import java.util.ArrayList; +import java.util.Iterator; import java.util.List; +import java.util.Locale; /** * @author Tobias Osmers<\a> @@ -35,9 +38,13 @@ public class Workflow implements Identifiable { private LocalizedString description; private List tasks; - public Workflow(final com.arsdigita.workflow.simple.Workflow - trunkWorkFlow) { + public Workflow(final com.arsdigita.workflow.simple.Workflow trunkWorkFlow) { + this.workflowId = trunkWorkFlow.getID().longValue(); + this.name.addValue(Locale.ENGLISH, trunkWorkFlow.getDisplayName()); + this.description.addValue(Locale.ENGLISH, trunkWorkFlow.getDescription()); + this.tasks = new ArrayList<>(); + NgCollection.workflows.put(this.workflowId, this); } @Override @@ -49,7 +56,7 @@ public class Workflow implements Identifiable { return workflowId; } - public void setWorkflowId(long workflowId) { + public void setWorkflowId(final long workflowId) { this.workflowId = workflowId; } @@ -57,7 +64,7 @@ public class Workflow implements Identifiable { return name; } - public void setName(LocalizedString name) { + public void setName(final LocalizedString name) { this.name = name; } @@ -65,7 +72,7 @@ public class Workflow implements Identifiable { return description; } - public void setDescription(LocalizedString description) { + public void setDescription(final LocalizedString description) { this.description = description; } @@ -73,7 +80,15 @@ public class Workflow implements Identifiable { return tasks; } - public void setTasks(List tasks) { + public void setTasks(final List tasks) { this.tasks = tasks; } + + public void addTask(final Task task) { + tasks.add(task); + } + + public void removeTask(final Task task) { + tasks.remove(task); + } } diff --git a/ccm-core/src/com/arsdigita/portation/modules/utils/CollectionConverter.java b/ccm-core/src/com/arsdigita/portation/modules/utils/CollectionConverter.java deleted file mode 100644 index 35761734e..000000000 --- a/ccm-core/src/com/arsdigita/portation/modules/utils/CollectionConverter.java +++ /dev/null @@ -1,95 +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.utils; - -import com.arsdigita.kernel.EmailAddress; -import com.arsdigita.kernel.GroupCollection; -import com.arsdigita.kernel.PartyCollection; -import com.arsdigita.kernel.UserCollection; -import com.arsdigita.portation.modules.core.security.Group; -import com.arsdigita.portation.modules.core.security.Party; -import com.arsdigita.portation.modules.core.security.User; -import org.apache.log4j.Logger; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -/** - * @author convertUsers(UserCollection userCollection) { - List users = new ArrayList<>(); - if (userCollection != null) { - while (userCollection.next()) { - users.add(new User()); - } - userCollection.close(); - } else { - logger.error("A Failed to exportUsers, cause user collection is null."); - } - return users; - } - - public static List convertGroups(GroupCollection groupCollection) { - List groups = new ArrayList<>(); - if (groupCollection != null) { - while (groupCollection.next()) { - groups.add(new Group()); - } - groupCollection.close(); - } else { - logger.error("A Failed to exportUsers, cause group collection is null."); - } - return groups; - } - - public static List convertMailAddresses(Iterator it) { - List mailAddresses = new ArrayList<>(); - if (it != null) { - while (it.hasNext()) { - mailAddresses.add(((EmailAddress) it.next()).getEmailAddress()); - } - } else { - logger.error("A Failed to exportUsers, cause mail collection is null."); - } - return mailAddresses; - } -} diff --git a/ccm-core/src/com/arsdigita/workflow/simple/Workflow.java b/ccm-core/src/com/arsdigita/workflow/simple/Workflow.java index 4bf8bba61..dd261657b 100755 --- a/ccm-core/src/com/arsdigita/workflow/simple/Workflow.java +++ b/ccm-core/src/com/arsdigita/workflow/simple/Workflow.java @@ -34,14 +34,17 @@ import com.arsdigita.persistence.Session; import com.arsdigita.persistence.SessionManager; import com.arsdigita.persistence.metadata.ObjectType; import com.arsdigita.util.UncheckedWrapperException; +import org.apache.log4j.Logger; + import java.math.BigDecimal; +import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; +import java.util.List; import java.util.Map; -import org.apache.log4j.Logger; /** * Represents a process instance that is assigned to a particular process that @@ -856,4 +859,23 @@ public class Workflow extends Task { public static Workflow getObjectWorkflow(ACSObject o) { return getObjectWorkflow(o.getID()); } + + public static List getObjectWorkflows() { + List workflowList = new ArrayList<>(); + + final Session session = SessionManager.getSession(); + final DataQuery query = session.retrieveQuery("com.arsdigita.workflow.simple.getProcesses"); + + BigDecimal workflowID = null; + while (query.next()) { + workflowID = (BigDecimal) query.get("processID"); + + if (workflowID != null) { + workflowList.add(new Workflow(workflowID)); + } + } + + query.close(); + return workflowList; + } }