diff --git a/ccm-core/src/main/java/org/libreccm/categorization/Categorization.java b/ccm-core/src/main/java/org/libreccm/categorization/Categorization.java index a86d0a234..51cb96e39 100644 --- a/ccm-core/src/main/java/org/libreccm/categorization/Categorization.java +++ b/ccm-core/src/main/java/org/libreccm/categorization/Categorization.java @@ -19,6 +19,8 @@ package org.libreccm.categorization; import com.fasterxml.jackson.annotation.JsonBackReference; +import com.fasterxml.jackson.annotation.JsonIdentityInfo; +import com.fasterxml.jackson.annotation.JsonIdentityReference; import org.libreccm.core.CcmObject; import org.libreccm.portation.Portable; @@ -96,6 +98,8 @@ import javax.persistence.FetchType; + "WHERE c.category = :category " + "AND c.index = TRUE") }) +@JsonIdentityInfo(generator = CategorizationIdGenerator.class, + property = "customCatId") public class Categorization implements Serializable, Relation, Portable { private static final long serialVersionUID = 201504301320L; @@ -113,7 +117,7 @@ public class Categorization implements Serializable, Relation, Portable { */ @ManyToOne @JoinColumn(name = "CATEGORY_ID") - @JsonBackReference(value = "category-categorization") + @JsonIdentityReference(alwaysAsId = true) private Category category; /** @@ -121,7 +125,7 @@ public class Categorization implements Serializable, Relation, Portable { */ @ManyToOne @JoinColumn(name = "OBJECT_ID") - @JsonBackReference(value = "object-categorization") + @JsonIdentityReference(alwaysAsId = true) private CcmObject categorizedObject; /** diff --git a/ccm-core/src/main/java/org/libreccm/categorization/CategorizationIdGenerator.java b/ccm-core/src/main/java/org/libreccm/categorization/CategorizationIdGenerator.java new file mode 100644 index 000000000..ea1d12d4b --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/categorization/CategorizationIdGenerator.java @@ -0,0 +1,69 @@ +/* + * 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 org.libreccm.categorization; + +import com.fasterxml.jackson.annotation.ObjectIdGenerator; + +/** + * @author objects; /** @@ -228,7 +232,7 @@ public class Category extends CcmObject implements Serializable, Portable { @OneToMany(mappedBy = "parentCategory", fetch = FetchType.LAZY) @XmlElementWrapper(name = "subcategories", namespace = CAT_XML_NS) @XmlElement(name = "category") - @JsonManagedReference(value = "subcategory-parentcategory") + @JsonIgnore private List subCategories; /** @@ -237,7 +241,7 @@ public class Category extends CcmObject implements Serializable, Portable { */ @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "PARENT_CATEGORY_ID") - @JsonBackReference(value = "subcategory-parentcategory") + @JsonIdentityReference(alwaysAsId = true) private Category parentCategory; /** diff --git a/ccm-core/src/main/java/org/libreccm/categorization/CategoryIdResolver.java b/ccm-core/src/main/java/org/libreccm/categorization/CategoryIdResolver.java new file mode 100644 index 000000000..ab2c23d68 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/categorization/CategoryIdResolver.java @@ -0,0 +1,58 @@ +/* + * 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 org.libreccm.categorization; + +import com.fasterxml.jackson.annotation.ObjectIdGenerator; +import com.fasterxml.jackson.annotation.ObjectIdResolver; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; + +/** + * @author permissions; /** @@ -131,7 +135,7 @@ public class CcmObject implements Identifiable, Serializable { @OneToMany(mappedBy = "categorizedObject") @XmlElementWrapper(name = "categories", namespace = CORE_XML_NS) @XmlElement(name = "category", namespace = CORE_XML_NS) - @JsonManagedReference(value = "object-categorization") + @JsonIgnore private List categories; public CcmObject() { diff --git a/ccm-core/src/main/java/org/libreccm/core/CcmObjectIdResolver.java b/ccm-core/src/main/java/org/libreccm/core/CcmObjectIdResolver.java new file mode 100644 index 000000000..9aca9e336 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/core/CcmObjectIdResolver.java @@ -0,0 +1,51 @@ +/* + * 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 org.libreccm.core; + +import com.fasterxml.jackson.annotation.ObjectIdGenerator; +import com.fasterxml.jackson.annotation.ObjectIdResolver; + +/** + * @author memberships = new HashSet<>(); public Group() { diff --git a/ccm-core/src/main/java/org/libreccm/security/GroupIdResolver.java b/ccm-core/src/main/java/org/libreccm/security/GroupIdResolver.java new file mode 100644 index 000000000..d531f4f31 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/security/GroupIdResolver.java @@ -0,0 +1,51 @@ +/* + * 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 org.libreccm.security; + +import com.fasterxml.jackson.annotation.ObjectIdGenerator; +import com.fasterxml.jackson.annotation.ObjectIdResolver; + +/** + * @author roleMemberships = new HashSet<>(); protected Party() { diff --git a/ccm-core/src/main/java/org/libreccm/security/PartyIdResolver.java b/ccm-core/src/main/java/org/libreccm/security/PartyIdResolver.java new file mode 100644 index 000000000..7192059c9 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/security/PartyIdResolver.java @@ -0,0 +1,52 @@ +/* + * 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 org.libreccm.security; + +import com.fasterxml.jackson.annotation.ObjectIdGenerator; +import com.fasterxml.jackson.annotation.ObjectIdResolver; + +/** + * @author memberships = new HashSet<>(); /** @@ -175,27 +192,13 @@ public class Role implements Serializable, Portable { @OneToMany(mappedBy = "grantee") @XmlElementWrapper(name = "permissions", namespace = CORE_XML_NS) @XmlElement(name = "permission", namespace = CORE_XML_NS) - @JsonManagedReference(value = "role-permission") + @JsonIgnore private List permissions = new ArrayList<>(); @OneToMany(mappedBy = "role") - @JsonManagedReference(value = "role-taskassignment") + @JsonIgnore private List assignedTasks = new ArrayList<>(); - /** - * An optional description for a role. - */ - @Embedded - @AssociationOverride( - name = "values", - joinTable = @JoinTable(name = "ROLE_DESCRIPTIONS", - schema = DB_SCHEMA, - joinColumns = { - @JoinColumn(name = "ROLE_ID") - })) - @XmlElement(name = "description", namespace = CORE_XML_NS) - private LocalizedString description = new LocalizedString(); - public Role() { super(); } diff --git a/ccm-core/src/main/java/org/libreccm/security/RoleIdResolver.java b/ccm-core/src/main/java/org/libreccm/security/RoleIdResolver.java new file mode 100644 index 000000000..061cca93a --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/security/RoleIdResolver.java @@ -0,0 +1,52 @@ +/* + * 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 org.libreccm.security; + +import com.fasterxml.jackson.annotation.ObjectIdGenerator; +import com.fasterxml.jackson.annotation.ObjectIdResolver; + +/** + * @author final RoleMembership roleMembership = save(portableObject); LOGGER.debug("Saved RoleMembership with id {}.", roleMembership.getMembershipId()); -// } else { -// entityManager.merge(portableObject); -// } } @Transactional(Transactional.TxType.REQUIRES_NEW) diff --git a/ccm-core/src/main/java/org/libreccm/security/User.java b/ccm-core/src/main/java/org/libreccm/security/User.java index c7a437b8e..a678bce96 100644 --- a/ccm-core/src/main/java/org/libreccm/security/User.java +++ b/ccm-core/src/main/java/org/libreccm/security/User.java @@ -18,7 +18,10 @@ */ package org.libreccm.security; +import com.fasterxml.jackson.annotation.JsonIdentityInfo; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonManagedReference; +import com.fasterxml.jackson.annotation.ObjectIdGenerators; import org.libreccm.core.EmailAddress; import org.libreccm.portation.Portable; @@ -46,7 +49,6 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlTransient; - import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; @@ -126,6 +128,9 @@ import static org.libreccm.core.CoreConstants.DB_SCHEMA; //Supressing a few warnings from PMD because they misleading here. //User is perfectly fine class name, and the complexity is not to high... @SuppressWarnings({"PMD.ShortClassName", "PMD.LongVariable"}) +@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, + resolver = UserIdResolver.class, + property = "name") public class User extends Party implements Serializable, Portable { private static final long serialVersionUID = 4035223413596611393L; @@ -203,7 +208,7 @@ public class User extends Party implements Serializable, Portable { @OneToMany(mappedBy = "member") @XmlElementWrapper(name = "group-memberships", namespace = CORE_XML_NS) @XmlElement(name = "group-membership", namespace = CORE_XML_NS) - @JsonManagedReference(value = "user-groupmembership") + @JsonIgnore private Set groupMemberships = new HashSet<>(); protected User() { diff --git a/ccm-core/src/main/java/org/libreccm/security/UserIdResolver.java b/ccm-core/src/main/java/org/libreccm/security/UserIdResolver.java new file mode 100644 index 000000000..cea3c2768 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/security/UserIdResolver.java @@ -0,0 +1,52 @@ +/* + * 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 org.libreccm.security; + +import com.fasterxml.jackson.annotation.ObjectIdGenerator; +import com.fasterxml.jackson.annotation.ObjectIdResolver; + +/** + * @author assignments; public AssignableTask() { diff --git a/ccm-core/src/main/java/org/libreccm/workflow/AssignableTaskIdResolver.java b/ccm-core/src/main/java/org/libreccm/workflow/AssignableTaskIdResolver.java new file mode 100644 index 000000000..c1bb90df4 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/workflow/AssignableTaskIdResolver.java @@ -0,0 +1,52 @@ +/* + * 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 org.libreccm.workflow; + +import com.fasterxml.jackson.annotation.ObjectIdGenerator; +import com.fasterxml.jackson.annotation.ObjectIdResolver; + +/** + * @author dependentTasks; /** @@ -181,9 +183,7 @@ public class Task implements Identifiable, Serializable { @JoinColumn(name = "DEPENDS_ON_TASK_ID")}, inverseJoinColumns = { @JoinColumn(name = "DEPENDENT_TASK_ID")}) - @JsonIdentityInfo( - generator = ObjectIdGenerators.PropertyGenerator.class, - property = "taskId") + @JsonIdentityReference(alwaysAsId = true) private List dependsOn; /** diff --git a/ccm-core/src/main/java/org/libreccm/workflow/TaskAssignment.java b/ccm-core/src/main/java/org/libreccm/workflow/TaskAssignment.java index e6bd89be6..e55b1016d 100644 --- a/ccm-core/src/main/java/org/libreccm/workflow/TaskAssignment.java +++ b/ccm-core/src/main/java/org/libreccm/workflow/TaskAssignment.java @@ -18,8 +18,8 @@ */ package org.libreccm.workflow; -import com.fasterxml.jackson.annotation.JsonBackReference; -import com.fasterxml.jackson.annotation.JsonManagedReference; +import com.fasterxml.jackson.annotation.JsonIdentityInfo; +import com.fasterxml.jackson.annotation.JsonIdentityReference; import org.libreccm.portation.Portable; import org.libreccm.security.Role; @@ -43,6 +43,8 @@ import static org.libreccm.core.CoreConstants.DB_SCHEMA; */ @Entity @Table(name = "WORKFLOW_TASK_ASSIGNMENTS", schema = DB_SCHEMA) +@JsonIdentityInfo(generator = TaskAssignmentIdGenerator.class, + property = "customAssignId") public class TaskAssignment implements Serializable, Portable { private static final long serialVersionUID = -4427537363301565707L; @@ -60,7 +62,7 @@ public class TaskAssignment implements Serializable, Portable { */ @ManyToOne @JoinColumn(name = "TASK_ID") - @JsonBackReference(value = "assignabletask-taskassignment") + @JsonIdentityReference(alwaysAsId = true) private AssignableTask task; /** @@ -68,7 +70,7 @@ public class TaskAssignment implements Serializable, Portable { */ @ManyToOne @JoinColumn(name = "ROLE_ID") - @JsonBackReference(value = "role-taskassignment") + @JsonIdentityReference(alwaysAsId = true) private Role role; public long getTaskAssignmentId() { diff --git a/ccm-core/src/main/java/org/libreccm/workflow/TaskAssignmentIdGenerator.java b/ccm-core/src/main/java/org/libreccm/workflow/TaskAssignmentIdGenerator.java new file mode 100644 index 000000000..c59574c8e --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/workflow/TaskAssignmentIdGenerator.java @@ -0,0 +1,69 @@ +/* + * 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 org.libreccm.workflow; + +import com.fasterxml.jackson.annotation.ObjectIdGenerator; + +/** + * @author tasks; public Workflow() { diff --git a/ccm-core/src/main/java/org/libreccm/workflow/WorkflowIdResolver.java b/ccm-core/src/main/java/org/libreccm/workflow/WorkflowIdResolver.java new file mode 100644 index 000000000..65de496ef --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/workflow/WorkflowIdResolver.java @@ -0,0 +1,52 @@ +/* + * 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 org.libreccm.workflow; + +import com.fasterxml.jackson.annotation.ObjectIdGenerator; +import com.fasterxml.jackson.annotation.ObjectIdResolver; + +/** + * @author