From f2403b0ce644bacdc10fb722d7b38aab98c63c2e Mon Sep 17 00:00:00 2001 From: tosmers Date: Thu, 13 Oct 2016 14:03:28 +0000 Subject: [PATCH] [UPDATE] - adds json annotations in package portation to avoid infinite recursion - removes the manually solved infinite recursion problems git-svn-id: https://svn.libreccm.org/ccm/trunk@4373 8810af33-2d31-482b-a856-94f89814c4df --- ccm-core/src/com/arsdigita/kernel/Party.java | 2 +- .../categorization/CategoryConversion.java | 11 +--- .../core/security/PermissionConversion.java | 14 ++++- .../core/categorization/Categorization.java | 3 + .../modules/core/categorization/Category.java | 62 +++---------------- .../modules/core/core/CcmObject.java | 3 + .../modules/core/security/Group.java | 2 + .../core/security/GroupMembership.java | 3 + .../modules/core/security/Party.java | 2 + .../modules/core/security/Permission.java | 14 ++++- .../portation/modules/core/security/Role.java | 4 ++ .../modules/core/security/RoleMembership.java | 3 + .../portation/modules/core/security/User.java | 2 + .../portation/modules/core/workflow/Task.java | 5 ++ .../modules/core/workflow/TaskAssignment.java | 3 + .../modules/core/workflow/UserTask.java | 2 + .../modules/core/workflow/Workflow.java | 2 + 17 files changed, 70 insertions(+), 67 deletions(-) diff --git a/ccm-core/src/com/arsdigita/kernel/Party.java b/ccm-core/src/com/arsdigita/kernel/Party.java index fb4dabff8..a7fce5617 100755 --- a/ccm-core/src/com/arsdigita/kernel/Party.java +++ b/ccm-core/src/com/arsdigita/kernel/Party.java @@ -326,7 +326,7 @@ public abstract class Party extends ACSObject { * 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 groups + * @return List of all parties */ public static List getAllObjectParties() { List partyList = new ArrayList<>(); 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 babec1075..c297a1908 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 @@ -98,8 +98,7 @@ public class CategoryConversion { categorizedObject); // set opposed associations - //category.addObject(categorization); Todo - category.addObjectId(categorization.getCategorizationId()); + category.addObject(categorization); categorizedObject.addCategory(categorization); } } @@ -133,12 +132,8 @@ public class CategoryConversion { } } catch (Exception e) {} if (category != null && parentCategory != null) { - //category.setParentCategory(parentCategory); - //parentCategory.addSubCategory(category); - - // to avoid infinite recursion Todo - category.setParentCategoryId(parentCategory.getUniqueId()); - parentCategory.addSubCategoryId(category.getUniqueId()); + category.setParentCategory(parentCategory); + parentCategory.addSubCategory(category); } } } 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 7cc09bcf0..2b1eb5145 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 @@ -27,6 +27,7 @@ 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.security.util.PermissionIdMapper; import java.math.BigDecimal; import java.util.List; @@ -120,8 +121,11 @@ public class PermissionConversion { .permissions.Permission> trunkPermissions) { for (com.arsdigita.kernel.permissions.Permission trunkPermission : trunkPermissions) { - Permission permission = NgCollection.permissions.get - (trunkPermission.getID().longValue()); + long permissionId = PermissionIdMapper.map.get( + ((BigDecimal) trunkPermission.getACSObject().get("id")).longValue() + + ((BigDecimal) trunkPermission.getPartyOID().get("id")).longValue() + ); + Permission permission = NgCollection.permissions.get(permissionId); BigDecimal trunkGranteeId = (BigDecimal) trunkPermission .getPartyOID().get("id"); @@ -149,6 +153,12 @@ public class PermissionConversion { (permission); duplicatePermission.setGrantee(role); role.addPermission(duplicatePermission); + + long oldId = duplicatePermission.getObject().getObjectId() + + duplicatePermission.getGrantee().getRoleId(); + PermissionIdMapper.map.put(oldId, + duplicatePermission.getPermissionId()); + } } // grantee instance of User, new Role necessary 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 af8871cf5..9064816db 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 @@ -22,6 +22,7 @@ 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.fasterxml.jackson.annotation.JsonBackReference; /** * Association class describing the association between a category and an @@ -35,7 +36,9 @@ public class Categorization implements Identifiable { private long categorizationId; + @JsonBackReference private Category category; + @JsonBackReference private CcmObject categorizedObject; private boolean index; 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 6dfef2701..8f9fdcf18 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 @@ -25,6 +25,8 @@ 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 com.fasterxml.jackson.annotation.JsonBackReference; +import com.fasterxml.jackson.annotation.JsonManagedReference; import java.util.ArrayList; import java.util.List; @@ -54,16 +56,15 @@ public class Category extends CcmObject { private boolean visible; private boolean abstractCategory; + @JsonManagedReference private List objects; + + @JsonManagedReference private List subCategories; - + @JsonBackReference private Category parentCategory; - private long categoryOrder; - // to avoid infinite recursion Todo - private List objectIds; - private List subCategoryIds; - private String parentCategoryId; + private long categoryOrder; public Category(final com.arsdigita.categorization.Category trunkCategory) { @@ -106,13 +107,6 @@ public class Category extends CcmObject { ? defaultParent.getNumberOfChildCategories() + 1 : 0; - - // to avoid infinite recursion Todo - this.objectIds = new ArrayList<>(); - this.subCategoryIds = new ArrayList<>(); - //this.parantCategoryId - - NgCollection.categories.put(this.getObjectId(), this); } @@ -225,46 +219,4 @@ public class Category extends CcmObject { public void setCategoryOrder(final long categoryOrder) { this.categoryOrder = categoryOrder; } - - - - public List getObjectIds() { - return objectIds; - } - - public void setObjectIds(final List objectIds) { - this.objectIds = objectIds; - } - - public void addObjectId(final long object) { - this.objectIds.add(object); - } - - public void removeObjectId(final long object) { - this.objectIds.remove(object); - } - - public List getSubCategoryIds() { - return subCategoryIds; - } - - public void setSubCategoryIds(final List subCategoryIds) { - this.subCategoryIds = subCategoryIds; - } - - public void addSubCategoryId(final String subCategoryId) { - this.subCategoryIds.add(subCategoryId); - } - - public void removeSubCategoryId(final String subCategoryId) { - this.subCategoryIds.remove(subCategoryId); - } - - public String getParentCategoryId() { - return parentCategoryId; - } - - public void setParentCategoryId(final String parentCategoryId) { - this.parentCategoryId = parentCategoryId; - } } 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 98aa33b95..58b459ebb 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,6 +25,7 @@ import com.arsdigita.portation.conversion.NgCollection; 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 com.fasterxml.jackson.annotation.JsonManagedReference; import java.util.ArrayList; import java.util.List; @@ -54,7 +55,9 @@ public class CcmObject implements Identifiable { private String uuid; private String displayName; + @JsonManagedReference private List permissions; + @JsonManagedReference private List categories; diff --git a/ccm-core/src/com/arsdigita/portation/modules/core/security/Group.java b/ccm-core/src/com/arsdigita/portation/modules/core/security/Group.java index 36740590f..72ed2e832 100644 --- a/ccm-core/src/com/arsdigita/portation/modules/core/security/Group.java +++ b/ccm-core/src/com/arsdigita/portation/modules/core/security/Group.java @@ -21,6 +21,7 @@ package com.arsdigita.portation.modules.core.security; import com.arsdigita.portation.AbstractMarshaller; import com.arsdigita.portation.Identifiable; import com.arsdigita.portation.conversion.NgCollection; +import com.fasterxml.jackson.annotation.JsonManagedReference; import java.util.HashSet; import java.util.Set; @@ -31,6 +32,7 @@ import java.util.Set; */ public class Group extends Party { + @JsonManagedReference private Set memberships; public Group(final com.arsdigita.kernel.Group trunkGroup) { diff --git a/ccm-core/src/com/arsdigita/portation/modules/core/security/GroupMembership.java b/ccm-core/src/com/arsdigita/portation/modules/core/security/GroupMembership.java index d3c1402a5..f8bff8273 100644 --- a/ccm-core/src/com/arsdigita/portation/modules/core/security/GroupMembership.java +++ b/ccm-core/src/com/arsdigita/portation/modules/core/security/GroupMembership.java @@ -21,6 +21,7 @@ package com.arsdigita.portation.modules.core.security; import com.arsdigita.portation.AbstractMarshaller; import com.arsdigita.portation.Identifiable; import com.arsdigita.portation.conversion.NgCollection; +import com.fasterxml.jackson.annotation.JsonBackReference; /** * @author memberships; + @JsonManagedReference private List permissions; + @JsonManagedReference private List assignedTasks; public Role(final com.arsdigita.kernel.Role trunkRole) { diff --git a/ccm-core/src/com/arsdigita/portation/modules/core/security/RoleMembership.java b/ccm-core/src/com/arsdigita/portation/modules/core/security/RoleMembership.java index 4200688ae..3c6c6e03a 100644 --- a/ccm-core/src/com/arsdigita/portation/modules/core/security/RoleMembership.java +++ b/ccm-core/src/com/arsdigita/portation/modules/core/security/RoleMembership.java @@ -21,6 +21,7 @@ package com.arsdigita.portation.modules.core.security; import com.arsdigita.portation.AbstractMarshaller; import com.arsdigita.portation.Identifiable; import com.arsdigita.portation.conversion.NgCollection; +import com.fasterxml.jackson.annotation.JsonBackReference; /** * @author Tobias Osmers<\a> @@ -31,7 +32,9 @@ public class TaskAssignment implements Identifiable { private long taskAssignmentId; + @JsonBackReference private UserTask task; + @JsonBackReference private Role role; public TaskAssignment(final UserTask task, final Role role) { diff --git a/ccm-core/src/com/arsdigita/portation/modules/core/workflow/UserTask.java b/ccm-core/src/com/arsdigita/portation/modules/core/workflow/UserTask.java index 1c637c914..4ac2467f9 100644 --- a/ccm-core/src/com/arsdigita/portation/modules/core/workflow/UserTask.java +++ b/ccm-core/src/com/arsdigita/portation/modules/core/workflow/UserTask.java @@ -22,6 +22,7 @@ import com.arsdigita.portation.AbstractMarshaller; import com.arsdigita.portation.Identifiable; import com.arsdigita.portation.conversion.NgCollection; import com.arsdigita.portation.modules.core.security.User; +import com.fasterxml.jackson.annotation.JsonManagedReference; import java.util.ArrayList; import java.util.Date; @@ -42,6 +43,7 @@ public class UserTask extends Task { private User notificationSender; + @JsonManagedReference private List assignments; public UserTask(final com.arsdigita.workflow.simple.UserTask 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 1e845e044..0f400ca00 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 @@ -22,6 +22,7 @@ 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 com.fasterxml.jackson.annotation.JsonManagedReference; import java.util.ArrayList; import java.util.List; @@ -38,6 +39,7 @@ public class Workflow implements Identifiable { private LocalizedString name; private LocalizedString description; + @JsonManagedReference private List tasks; public Workflow(final com.arsdigita.workflow.simple.Workflow trunkWorkFlow) {