From d9fe82a2d2c399f89ef6fac2c68fc5abb841296b Mon Sep 17 00:00:00 2001 From: MichalKinas Date: Mon, 3 Jul 2023 13:45:05 +0200 Subject: [PATCH 01/24] ACS-5506 Add description and hasSubgroups to groups API --- .../alfresco/rest/model/RestGroupsModel.java | 20 ++++ .../org/alfresco/rest/groups/GroupsTests.java | 32 ++++- .../alfresco/rest/api/impl/GroupsImpl.java | 45 ++++++++ .../org/alfresco/rest/api/model/Group.java | 23 +++- .../alfresco/public-rest-context.xml | 1 + .../repo/web/scripts/groups/GroupsTest.java | 109 +++++++++++------- .../alfresco/rest/api/tests/GroupsTest.java | 15 ++- 7 files changed, 197 insertions(+), 48 deletions(-) diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestGroupsModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestGroupsModel.java index ec8c28b1058..d8a9b975b23 100644 --- a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestGroupsModel.java +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestGroupsModel.java @@ -38,8 +38,12 @@ public class RestGroupsModel extends TestModel implements IRestModel parentIds; @@ -75,6 +79,22 @@ public void setDisplayName(String displayName) this.displayName = displayName; } + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Boolean getHasSubgroups() { + return hasSubgroups; + } + + public void setHasSubgroups(Boolean hasSubgroups) { + this.hasSubgroups = hasSubgroups; + } + public Boolean getIsRoot() { return isRoot; diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java index 80442c84cb1..48755e13932 100644 --- a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java +++ b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java @@ -34,7 +34,8 @@ public void dataPreparation() throws Exception public void createListUpdateAndDeleteGroup() throws Exception { String groupName = "ZtestGroup" + UUID.randomUUID().toString(); - JsonObject groupBody = Json.createObjectBuilder().add("id", groupName).add("displayName", groupName).build(); + String groupDescription = "ZtestGroup description" + UUID.randomUUID().toString(); + JsonObject groupBody = Json.createObjectBuilder().add("id", groupName).add("displayName", groupName).add("description", groupDescription).build(); String groupBodyCreate = groupBody.toString(); //GroupCreation: @@ -45,7 +46,9 @@ public void createListUpdateAndDeleteGroup() throws Exception restClient.authenticateUser(adminUser).withCoreAPI().usingParams("include=zones").usingGroups().createGroup(groupBodyCreate) .assertThat().field("zones").contains("APP.DEFAULT") .and().field("isRoot").is(true) - .and().field("displayName").is(groupName); + .and().field("displayName").is(groupName) + .and().field("description").is(groupDescription) + .and().field("hasSubgroups").is(false); restClient.assertStatusCodeIs(HttpStatus.CREATED); //ListGroups: @@ -55,11 +58,12 @@ public void createListUpdateAndDeleteGroup() throws Exception .and().paginationField("maxItems").is("10"); restClient.assertStatusCodeIs(HttpStatus.OK); - groupBody = Json.createObjectBuilder().add("displayName", "Z"+groupName).build(); + groupBody = Json.createObjectBuilder().add("displayName", "Z"+groupName).add("description", "Z"+groupDescription).build(); String groupBodyUpdate = groupBody.toString(); //UpdateGroup: restClient.withCoreAPI().usingGroups().updateGroupDetails("GROUP_"+groupName, groupBodyUpdate) .assertThat().field("displayName").is("Z"+groupName) + .and().field("description").is("Z"+groupDescription) .and().field("id").is("GROUP_"+groupName) .and().field("zones").isNull(); restClient.assertStatusCodeIs(HttpStatus.OK); @@ -68,7 +72,8 @@ public void createListUpdateAndDeleteGroup() throws Exception restClient.withCoreAPI().usingParams("include=zones").usingGroups().getGroupDetail("GROUP_"+groupName) .assertThat().field("id").is("GROUP_"+groupName) .and().field("zones").contains("APP.DEFAULT") - .and().field("isRoot").is(true); + .and().field("isRoot").is(true) + .and().field("hasSubgroups").is(false); restClient.assertStatusCodeIs(HttpStatus.OK); //DeleteGroup: @@ -86,15 +91,23 @@ public void createListUpdateAndDeleteGroup() throws Exception public void createListDeleteGroupMembership() throws Exception { String groupName = "ZtestGroup" + UUID.randomUUID().toString(); + String subGroupName = "ZtestSubgroup" + UUID.randomUUID().toString(); JsonObject groupBody = Json.createObjectBuilder().add("id", groupName).add("displayName", groupName).build(); + JsonObject subgroupBody = Json.createObjectBuilder().add("id", subGroupName).add("displayName", subGroupName).build(); String groupBodyCreate = groupBody.toString(); + String subgroupBodyCreate = subgroupBody.toString(); //GroupCreation: restClient.authenticateUser(adminUser).withCoreAPI().usingParams("include=zones").usingGroups().createGroup(groupBodyCreate); restClient.assertStatusCodeIs(HttpStatus.CREATED); + restClient.authenticateUser(adminUser).withCoreAPI().usingParams("include=zones").usingGroups().createGroup(subgroupBodyCreate); + restClient.assertStatusCodeIs(HttpStatus.CREATED); JsonObject groupMembershipBody = Json.createObjectBuilder().add("id", userModel.getUsername()).add("memberType", "PERSON").build(); String groupMembershipBodyCreate = groupMembershipBody.toString(); + JsonObject groupMembershipGroupBody = Json.createObjectBuilder().add("id", subGroupName).add("memberType", "GROUP").build(); + String groupMembershipGroupBodyCreate = groupMembershipGroupBody.toString(); + //MembershipCreation: //-ve restClient.authenticateUser(userModel).withCoreAPI().usingGroups().createGroupMembership("GROUP_"+groupName, groupMembershipBodyCreate); @@ -102,10 +115,19 @@ public void createListDeleteGroupMembership() throws Exception //+ve restClient.authenticateUser(adminUser).withCoreAPI().usingGroups().createGroupMembership("GROUP_"+groupName, groupMembershipBodyCreate); restClient.assertStatusCodeIs(HttpStatus.CREATED); + restClient.authenticateUser(adminUser).withCoreAPI().usingGroups().createGroupMembership("GROUP_"+groupName, groupMembershipGroupBodyCreate); + restClient.assertStatusCodeIs(HttpStatus.CREATED); //ListPersonMembership restClient.authenticateUser(userModel).withCoreAPI().usingUser(userModel).listGroupMemberships() - .assertThat().entriesListContains("id", "GROUP_"+groupName); + .assertThat().entriesListContains("id", "GROUP_"+groupName) + .and().entriesListContains("id", "GROUP_"+subGroupName); + restClient.assertStatusCodeIs(HttpStatus.OK); + + //CheckListDetails + restClient.withCoreAPI().usingParams("include=zones").usingGroups().getGroupDetail("GROUP_"+groupName) + .assertThat().field("id").is("GROUP_"+groupName) + .and().field("hasSubgroups").is(true); restClient.assertStatusCodeIs(HttpStatus.OK); //DeleteGroupMembership diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java index 784de7be2bd..865ceb93f6f 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java @@ -51,9 +51,11 @@ import org.alfresco.repo.security.authority.UnknownAuthorityException; import org.alfresco.rest.antlr.WhereClauseParser; import org.alfresco.rest.api.Groups; +import org.alfresco.rest.api.Nodes; import org.alfresco.rest.api.People; import org.alfresco.rest.api.model.Group; import org.alfresco.rest.api.model.GroupMember; +import org.alfresco.rest.api.model.Node; import org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException; import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException; import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException; @@ -68,6 +70,7 @@ import org.alfresco.rest.framework.resource.parameters.where.QueryHelper; import org.alfresco.rest.workflow.api.impl.MapBasedQueryWalker; import org.alfresco.rest.workflow.api.impl.MapBasedQueryWalkerOrSupported; +import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.security.AuthorityService; import org.alfresco.service.cmr.security.AuthorityType; import org.alfresco.service.cmr.security.PermissionService; @@ -109,6 +112,7 @@ public class GroupsImpl implements Groups private AuthorityDAO authorityDAO; protected People people; + protected Nodes nodes; public AuthorityService getAuthorityService() { @@ -130,6 +134,10 @@ public void setPeople(People people) this.people = people; } + public void setNodes(Nodes nodes) { + this.nodes = nodes; + } + public Group create(Group group, Parameters parameters) { validateGroup(group, false); @@ -151,6 +159,17 @@ public Group create(Group group, Parameters parameters) authorityService.addAuthority(group.getParentIds(), authority); } + if (group.getDescription() != null && !group.getDescription().isEmpty()) + { + NodeRef groupNodeRef = authorityService.getAuthorityNodeRef(authorityDisplayName); + Node groupNode = nodes.getNode(groupNodeRef.getId()); + Map props = groupNode.getProperties(); + if (props != null) + { + props.put("cm:description", group.getDescription()); + } + } + return getGroup(authority, parameters); } @@ -168,6 +187,17 @@ public Group update(String groupId, Group group, Parameters parameters) handleAuthorityException(ae); } + if (group.getDescription() != null && !group.getDescription().isEmpty()) + { + NodeRef groupNodeRef = authorityService.getAuthorityNodeRef(group.getDisplayName()); + Node groupNode = nodes.getNode(groupNodeRef.getId()); + Map props = groupNode.getProperties(); + if (props != null) + { + props.put("cm:description", group.getDescription()); + } + } + return getGroup(groupId, parameters); } @@ -584,6 +614,17 @@ private Group getGroup(AuthorityInfo authorityInfo, List includeParam, S group.setDisplayName(authorityDisplayName); group.setIsRoot(isRootAuthority(rootAuthorities, authorityInfo.getAuthorityName())); + group.setHasSubgroups(!authorityService.getContainedAuthorities(AuthorityType.GROUP, authorityInfo.getAuthorityName(), true).isEmpty()); + + NodeRef groupNodeRef = authorityService.getAuthorityNodeRef(authorityDisplayName); + Node groupNode = nodes.getNode(groupNodeRef.getId()); + Map props = groupNode.getProperties(); + String description = ""; + if (props != null) + { + description = props.get("cm:description") != null ? (String) props.get("cm:description") : ""; + } + group.setDescription(description); // Optionally include if (includeParam != null) @@ -1014,6 +1055,10 @@ private void validateGroup(Group group, boolean isUpdate) { throw new InvalidArgumentException("Group update does not support field: zones"); } + if (group.wasSet(Group.HAS_SUBGROUPS)) + { + throw new InvalidArgumentException("Group update does not support field: hasSubgroups"); + } } } diff --git a/remote-api/src/main/java/org/alfresco/rest/api/model/Group.java b/remote-api/src/main/java/org/alfresco/rest/api/model/Group.java index 6ef826229cf..8b4a3647514 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/model/Group.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/model/Group.java @@ -42,7 +42,9 @@ public class Group implements Comparable protected String id; // group id (aka authority name) protected String displayName; + protected String description; protected Boolean isRoot; + protected Boolean hasSubgroups; protected Set parentIds; protected Set zones; @@ -50,7 +52,9 @@ public class Group implements Comparable public static final String ID = "id"; public static final String DISPLAY_NAME = "displayName"; + public static final String DESCRIPTION = "description"; public static final String IS_ROOT = "isRoot"; + public static final String HAS_SUBGROUPS = "hasSubgroups"; public static final String PARENT_IDS = "parentIds"; public static final String ZONES = "zones"; @@ -81,6 +85,14 @@ public void setDisplayName(String displayName) setFields.put(DISPLAY_NAME, true); } + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + public Boolean getIsRoot() { return isRoot; @@ -92,6 +104,14 @@ public void setIsRoot(Boolean isRoot) setFields.put(IS_ROOT, true); } + public Boolean getHasSubgroups() { + return hasSubgroups; + } + + public void setHasSubgroups(Boolean hasSubgroups) { + this.hasSubgroups = hasSubgroups; + } + public Set getParentIds() { return parentIds; @@ -154,7 +174,8 @@ public int hashCode() @Override public String toString() { - return "Group [id=" + id + ", displayName=" + displayName + ", isRoot=" + isRoot + "]"; + return "Group [id=" + id + ", displayName=" + displayName + ", description=" + description + + ", isRoot=" + isRoot + ", hasSubgroups=" + hasSubgroups + "]"; } public boolean wasSet(String fieldName) diff --git a/remote-api/src/main/resources/alfresco/public-rest-context.xml b/remote-api/src/main/resources/alfresco/public-rest-context.xml index f5627ad8239..bae0d4b5407 100644 --- a/remote-api/src/main/resources/alfresco/public-rest-context.xml +++ b/remote-api/src/main/resources/alfresco/public-rest-context.xml @@ -1693,6 +1693,7 @@ + diff --git a/remote-api/src/test/java/org/alfresco/repo/web/scripts/groups/GroupsTest.java b/remote-api/src/test/java/org/alfresco/repo/web/scripts/groups/GroupsTest.java index 9e2a2e58650..9c15689c0e9 100644 --- a/remote-api/src/test/java/org/alfresco/repo/web/scripts/groups/GroupsTest.java +++ b/remote-api/src/test/java/org/alfresco/repo/web/scripts/groups/GroupsTest.java @@ -1,28 +1,28 @@ -/* - * #%L - * Alfresco Remote API - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - * Alfresco 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 3 of the License, or - * (at your option) any later version. - * - * Alfresco 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 Alfresco. If not, see . - * #L% - */ +/* + * #%L + * Alfresco Remote API + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * Alfresco 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 3 of the License, or + * (at your option) any later version. + * + * Alfresco 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 Alfresco. If not, see . + * #L% + */ package org.alfresco.repo.web.scripts.groups; @@ -229,7 +229,8 @@ public void testGetRootGroup() throws Exception assertEquals("shortName wrong", TEST_ROOTGROUP, rootGroup.getString("shortName")); assertEquals("displayName wrong", TEST_ROOTGROUP_DISPLAY_NAME, rootGroup.getString("displayName")); assertEquals("authorityType wrong", "GROUP", rootGroup.getString("authorityType")); - gotRootGroup = true; + assertEquals("hasSubgroups wrong", true, rootGroup.getString("hasSubgroups")); + gotRootGroup = true; } if(rootGroup.getString("shortName").equals(EMAIL_GROUP)) { @@ -270,7 +271,8 @@ public void testGetRootGroup() throws Exception assertEquals("shortName wrong", TEST_ROOTGROUP, rootGroup.getString("shortName")); assertEquals("displayName wrong", TEST_ROOTGROUP_DISPLAY_NAME, rootGroup.getString("displayName")); assertEquals("authorityType wrong", "GROUP", rootGroup.getString("authorityType")); - } + assertEquals("hasSubgroups wrong", true, rootGroup.getString("hasSubgroups")); + } } } @@ -293,7 +295,8 @@ public void testGetRootGroup() throws Exception assertEquals("shortName wrong", TEST_ROOTGROUP, rootGroup.getString("shortName")); assertEquals("displayName wrong", TEST_ROOTGROUP_DISPLAY_NAME, rootGroup.getString("displayName")); assertEquals("authorityType wrong", "GROUP", rootGroup.getString("authorityType")); - } + assertEquals("hasSubgroups wrong", true, rootGroup.getString("hasSubgroups")); + } } } @@ -382,12 +385,14 @@ public void testCreateRootGroup() throws Exception */ { JSONObject newGroupJSON = new JSONObject(); - newGroupJSON.put("displayName", myDisplayName); + newGroupJSON.put("displayName", myDisplayName); + newGroupJSON.put("description", "testDesc"); Response response = sendRequest(new PostRequest(URL_ROOTGROUPS + "/" + myGroupName, newGroupJSON.toString(), "application/json"), Status.STATUS_CREATED); JSONObject top = new JSONObject(response.getContentAsString()); JSONObject rootGroup = top.getJSONObject("data"); assertEquals("shortName wrong", myGroupName, rootGroup.getString("shortName")); assertEquals("displayName wrong", myDisplayName, rootGroup.getString("displayName")); + assertEquals("description wrong", "testDesc", rootGroup.getString("description")); } /** @@ -502,7 +507,18 @@ public void testLinkChild() throws Exception assertEquals("shortName wrong", TEST_LINK, subGroup.getString("shortName")); assertEquals("authorityType wrong", "GROUP", subGroup.getString("authorityType")); } - + + /** + * Check if myGroup has subgroups + */ + { + Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + myRootGroup), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONObject myGroup = top.getJSONObject("data"); + assertTrue(myGroup.getBoolean("hasSubgroups")); + } + /** * Now link in an existing user */ @@ -555,6 +571,17 @@ public void testLinkChild() throws Exception //assertTrue("group B not removed", data.length() == 0); } + + /** + * Check if myGroup has no subgroups + */ + { + Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + myRootGroup), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONObject myGroup = top.getJSONObject("data"); + assertFalse(myGroup.getBoolean("hasSubgroups")); + } /** * Create a new group (BUFFY) @@ -613,19 +640,22 @@ public void testUpdateGroup() throws Exception { String myGroupName = "GT_UG"; String myDisplayName = "GT_UGDisplay"; + String description = "GT_UGDesc"; String myNewDisplayName = "GT_UGDisplayNew"; - - this.authenticationComponent.setSystemUserAsCurrentUser(); + String newDescription = "GT_UGDescNew"; + + this.authenticationComponent.setSystemUserAsCurrentUser(); try { /** - * Create a root group + * Create a root group with descrription */ { JSONObject newGroupJSON = new JSONObject(); - newGroupJSON.put("displayName", myDisplayName); - sendRequest(new PostRequest(URL_ROOTGROUPS + "/" + myGroupName, newGroupJSON.toString(), "application/json"), Status.STATUS_CREATED); + newGroupJSON.put("displayName", myDisplayName); + newGroupJSON.put("description", description); + sendRequest(new PostRequest(URL_ROOTGROUPS + "/" + myGroupName, newGroupJSON.toString(), "application/json"), Status.STATUS_CREATED); } /** @@ -633,14 +663,15 @@ public void testUpdateGroup() throws Exception */ { JSONObject newGroupJSON = new JSONObject(); - newGroupJSON.put("displayName", myNewDisplayName); - Response response = sendRequest(new PutRequest(URL_GROUPS + "/" + myGroupName, newGroupJSON.toString(), "application/json"), Status.STATUS_OK); + newGroupJSON.put("displayName", myNewDisplayName); + newGroupJSON.put("description", newDescription); + Response response = sendRequest(new PutRequest(URL_GROUPS + "/" + myGroupName, newGroupJSON.toString(), "application/json"), Status.STATUS_OK); JSONObject top = new JSONObject(response.getContentAsString()); logger.debug(response.getContentAsString()); JSONObject data = top.getJSONObject("data"); assertTrue(data.length() > 0); assertEquals("displayName wrong", myNewDisplayName, data.getString("displayName")); - + assertEquals("description wrong", newDescription, data.getString("description")); } /** @@ -653,7 +684,7 @@ public void testUpdateGroup() throws Exception JSONObject data = top.getJSONObject("data"); assertTrue(data.length() > 0); assertEquals("displayName wrong", myNewDisplayName, data.getString("displayName")); - + assertEquals("description wrong", newDescription, data.getString("description")); } /** diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/GroupsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/GroupsTest.java index df0e8f45ed2..1cd05a8d9b5 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/GroupsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/GroupsTest.java @@ -43,11 +43,9 @@ import org.alfresco.service.cmr.security.AuthorityType; import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.util.GUID; -import org.alfresco.util.testing.category.LuceneTests; import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.junit.experimental.categories.Category; import org.mockito.Mock; import jakarta.servlet.http.HttpServletResponse; @@ -663,7 +661,9 @@ private void validateGroupDefaultFields(Group group, boolean ignoreOptionallyInc assertNotNull(group); assertNotNull(group.getId()); assertNotNull(group.getDisplayName()); + assertNotNull(group.getDescription()); assertNotNull(group.getIsRoot()); + assertNotNull(group.getHasSubgroups()); if (!ignoreOptionallyIncluded) { @@ -1421,13 +1421,16 @@ public void testCreateGroup() throws Exception otherParams.put("include", org.alfresco.rest.api.Groups.PARAM_INCLUDE_PARENT_IDS); Group group = generateGroup(); + group.setDescription("testDesc"); Group createdGroup01 = groupsProxy.createGroup(group, null, HttpServletResponse.SC_CREATED); assertNotNull(createdGroup01); assertNotNull(createdGroup01.getId()); + assertEquals(createdGroup01.getDescription(), "testDesc"); assertTrue(createdGroup01.getIsRoot()); assertNull(createdGroup01.getParentIds()); + assertFalse(createdGroup01.getHasSubgroups()); Set subGroup01Parents = new HashSet<>(); subGroup01Parents.add(createdGroup01.getId()); @@ -1441,6 +1444,8 @@ public void testCreateGroup() throws Exception assertFalse(createdSubGroup01.getIsRoot()); assertNotNull(createdSubGroup01.getParentIds()); assertEquals(subGroup01Parents, createdSubGroup01.getParentIds()); + assertTrue(createdGroup01.getHasSubgroups()); + assertFalse(createdSubGroup01.getHasSubgroups()); } // Group id is missing. @@ -1623,6 +1628,7 @@ public void testUpdateGroup() throws Exception subGroupParents.add(group.getId()); Group generatedSubGroup = generateGroup(); + generatedSubGroup.setDescription("initialDesc"); generatedSubGroup.setParentIds(subGroupParents); Group subGroup = groupsProxy.createGroup(generatedSubGroup, otherParams, HttpServletResponse.SC_CREATED); @@ -1645,9 +1651,11 @@ public void testUpdateGroup() throws Exception String displayName = "newDisplayName"; + String description = "newDesc"; Group mySubGroup = new Group(); mySubGroup.setDisplayName(displayName); + mySubGroup.setDescription(description); Group updateGroup = groupsProxy.updateGroup(subGroup.getId(), mySubGroup, otherParams, HttpServletResponse.SC_OK); @@ -1657,8 +1665,9 @@ public void testUpdateGroup() throws Exception assertFalse(updateGroup.getIsRoot()); assertNotNull(updateGroup.getParentIds()); - // Check that only display name changed. + // Check that only display name and description changed. assertEquals(displayName, updateGroup.getDisplayName()); + assertEquals(description, updateGroup.getDescription()); // Check that nothing else changed. assertEquals(subGroup.getId(), updateGroup.getId()); From 4d22931dfea1eaa31eb85f70eb424f204b607be0 Mon Sep 17 00:00:00 2001 From: MichalKinas Date: Tue, 4 Jul 2023 11:03:45 +0200 Subject: [PATCH 02/24] ACS-5506 Correct Nodes bean --- remote-api/src/main/resources/alfresco/public-rest-context.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/remote-api/src/main/resources/alfresco/public-rest-context.xml b/remote-api/src/main/resources/alfresco/public-rest-context.xml index bae0d4b5407..8ba02c96f61 100644 --- a/remote-api/src/main/resources/alfresco/public-rest-context.xml +++ b/remote-api/src/main/resources/alfresco/public-rest-context.xml @@ -1693,7 +1693,7 @@ - + From 9a11075f418a658098de27ca7d4b1df38a70cf31 Mon Sep 17 00:00:00 2001 From: MichalKinas Date: Tue, 4 Jul 2023 17:01:37 +0200 Subject: [PATCH 03/24] ACS-5506 Proper description storage --- .../alfresco/rest/api/impl/GroupsImpl.java | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java index 865ceb93f6f..294d0ed618f 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java @@ -161,13 +161,12 @@ public Group create(Group group, Parameters parameters) if (group.getDescription() != null && !group.getDescription().isEmpty()) { - NodeRef groupNodeRef = authorityService.getAuthorityNodeRef(authorityDisplayName); + NodeRef groupNodeRef = authorityService.getAuthorityNodeRef(authority); Node groupNode = nodes.getNode(groupNodeRef.getId()); Map props = groupNode.getProperties(); - if (props != null) - { - props.put("cm:description", group.getDescription()); - } + props = props == null ? new HashMap<>() : props; + props.put("cm:description", group.getDescription()); + groupNode.setProperties(props); } return getGroup(authority, parameters); @@ -189,13 +188,12 @@ public Group update(String groupId, Group group, Parameters parameters) if (group.getDescription() != null && !group.getDescription().isEmpty()) { - NodeRef groupNodeRef = authorityService.getAuthorityNodeRef(group.getDisplayName()); + NodeRef groupNodeRef = authorityService.getAuthorityNodeRef(authorityService.getName(AuthorityType.GROUP, groupId)); Node groupNode = nodes.getNode(groupNodeRef.getId()); Map props = groupNode.getProperties(); - if (props != null) - { - props.put("cm:description", group.getDescription()); - } + props = props == null ? new HashMap<>() : props; + props.put("cm:description", group.getDescription()); + groupNode.setProperties(props); } return getGroup(groupId, parameters); @@ -616,7 +614,7 @@ private Group getGroup(AuthorityInfo authorityInfo, List includeParam, S group.setIsRoot(isRootAuthority(rootAuthorities, authorityInfo.getAuthorityName())); group.setHasSubgroups(!authorityService.getContainedAuthorities(AuthorityType.GROUP, authorityInfo.getAuthorityName(), true).isEmpty()); - NodeRef groupNodeRef = authorityService.getAuthorityNodeRef(authorityDisplayName); + NodeRef groupNodeRef = authorityService.getAuthorityNodeRef(authorityInfo.getAuthorityName()); Node groupNode = nodes.getNode(groupNodeRef.getId()); Map props = groupNode.getProperties(); String description = ""; From da7f1877fdcc9868087c8a352cc38c57f640b9c3 Mon Sep 17 00:00:00 2001 From: MichalKinas Date: Wed, 5 Jul 2023 13:59:24 +0200 Subject: [PATCH 04/24] ACS-5506 Fix saving properties --- .../alfresco/rest/api/impl/GroupsImpl.java | 32 ++++++++----------- .../alfresco/public-rest-context.xml | 1 + 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java index 294d0ed618f..e58ee3428d7 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java @@ -55,7 +55,6 @@ import org.alfresco.rest.api.People; import org.alfresco.rest.api.model.Group; import org.alfresco.rest.api.model.GroupMember; -import org.alfresco.rest.api.model.Node; import org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException; import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException; import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException; @@ -71,9 +70,12 @@ import org.alfresco.rest.workflow.api.impl.MapBasedQueryWalker; import org.alfresco.rest.workflow.api.impl.MapBasedQueryWalkerOrSupported; import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.security.AuthorityService; import org.alfresco.service.cmr.security.AuthorityType; import org.alfresco.service.cmr.security.PermissionService; +import org.alfresco.service.namespace.NamespaceService; +import org.alfresco.service.namespace.QName; import org.alfresco.util.AlfrescoCollator; import org.alfresco.util.Pair; import org.apache.commons.lang3.StringUtils; @@ -92,6 +94,7 @@ public class GroupsImpl implements Groups private static final String ZONE = "zone"; private static final String AUTHORITY_NAME = "authorityName"; private static final String ERR_MSG_MODIFY_FIXED_AUTHORITY = "Trying to modify a fixed authority"; + private static final QName PROP_DESCRIPTION = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "description"); private final static Map SORT_PARAMS_TO_NAMES; static @@ -109,6 +112,7 @@ public class GroupsImpl implements Groups private final static Set LIST_GROUP_MEMBERS_QUERY_PROPERTIES = new HashSet<>(Arrays.asList(new String[] { PARAM_MEMBER_TYPE })); protected AuthorityService authorityService; + protected NodeService nodeService; private AuthorityDAO authorityDAO; protected People people; @@ -124,6 +128,10 @@ public void setAuthorityService(AuthorityService authorityService) this.authorityService = authorityService; } + public void setNodeService(NodeService nodeService) { + this.nodeService = nodeService; + } + public void setAuthorityDAO(AuthorityDAO authorityDAO) { this.authorityDAO = authorityDAO; @@ -162,11 +170,7 @@ public Group create(Group group, Parameters parameters) if (group.getDescription() != null && !group.getDescription().isEmpty()) { NodeRef groupNodeRef = authorityService.getAuthorityNodeRef(authority); - Node groupNode = nodes.getNode(groupNodeRef.getId()); - Map props = groupNode.getProperties(); - props = props == null ? new HashMap<>() : props; - props.put("cm:description", group.getDescription()); - groupNode.setProperties(props); + nodeService.setProperty(groupNodeRef, PROP_DESCRIPTION, group.getDescription()); } return getGroup(authority, parameters); @@ -189,11 +193,7 @@ public Group update(String groupId, Group group, Parameters parameters) if (group.getDescription() != null && !group.getDescription().isEmpty()) { NodeRef groupNodeRef = authorityService.getAuthorityNodeRef(authorityService.getName(AuthorityType.GROUP, groupId)); - Node groupNode = nodes.getNode(groupNodeRef.getId()); - Map props = groupNode.getProperties(); - props = props == null ? new HashMap<>() : props; - props.put("cm:description", group.getDescription()); - groupNode.setProperties(props); + nodeService.setProperty(groupNodeRef, PROP_DESCRIPTION, group.getDescription()); } return getGroup(groupId, parameters); @@ -615,13 +615,9 @@ private Group getGroup(AuthorityInfo authorityInfo, List includeParam, S group.setHasSubgroups(!authorityService.getContainedAuthorities(AuthorityType.GROUP, authorityInfo.getAuthorityName(), true).isEmpty()); NodeRef groupNodeRef = authorityService.getAuthorityNodeRef(authorityInfo.getAuthorityName()); - Node groupNode = nodes.getNode(groupNodeRef.getId()); - Map props = groupNode.getProperties(); - String description = ""; - if (props != null) - { - description = props.get("cm:description") != null ? (String) props.get("cm:description") : ""; - } + String description = nodeService.getProperty(groupNodeRef, PROP_DESCRIPTION) != null ? + nodeService.getProperty(groupNodeRef, PROP_DESCRIPTION).toString() : + ""; group.setDescription(description); // Optionally include diff --git a/remote-api/src/main/resources/alfresco/public-rest-context.xml b/remote-api/src/main/resources/alfresco/public-rest-context.xml index 8ba02c96f61..8be6d2fa2c8 100644 --- a/remote-api/src/main/resources/alfresco/public-rest-context.xml +++ b/remote-api/src/main/resources/alfresco/public-rest-context.xml @@ -1694,6 +1694,7 @@ + From 7a8cf67c2e11979442e44e49f7e4b25d3146da05 Mon Sep 17 00:00:00 2001 From: MichalKinas Date: Wed, 5 Jul 2023 16:19:54 +0200 Subject: [PATCH 05/24] ACS-5506 Test fixes --- .../src/test/java/org/alfresco/rest/groups/GroupsTests.java | 2 +- .../test/java/org/alfresco/rest/api/tests/GroupsTest.java | 1 - .../java/org/alfresco/rest/api/tests/client/data/Group.java | 6 ++++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java index 48755e13932..caf9bc471b3 100644 --- a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java +++ b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java @@ -105,7 +105,7 @@ public void createListDeleteGroupMembership() throws Exception JsonObject groupMembershipBody = Json.createObjectBuilder().add("id", userModel.getUsername()).add("memberType", "PERSON").build(); String groupMembershipBodyCreate = groupMembershipBody.toString(); - JsonObject groupMembershipGroupBody = Json.createObjectBuilder().add("id", subGroupName).add("memberType", "GROUP").build(); + JsonObject groupMembershipGroupBody = Json.createObjectBuilder().add("id", "GROUP_"+subGroupName).add("memberType", "GROUP").build(); String groupMembershipGroupBodyCreate = groupMembershipGroupBody.toString(); //MembershipCreation: diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/GroupsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/GroupsTest.java index 1cd05a8d9b5..5f1abee2df3 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/GroupsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/GroupsTest.java @@ -661,7 +661,6 @@ private void validateGroupDefaultFields(Group group, boolean ignoreOptionallyInc assertNotNull(group); assertNotNull(group.getId()); assertNotNull(group.getDisplayName()); - assertNotNull(group.getDescription()); assertNotNull(group.getIsRoot()); assertNotNull(group.getHasSubgroups()); diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/client/data/Group.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/client/data/Group.java index f8109d4f75d..d8623c397f8 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/client/data/Group.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/client/data/Group.java @@ -95,6 +95,7 @@ public static Group parseGroup(JSONObject jsonObject) { String id = (String) jsonObject.get("id"); String displayName = (String) jsonObject.get("displayName"); + String description = (String) jsonObject.get("description"); Boolean isRoot = (Boolean) jsonObject.get("isRoot"); List parentIds = (List) jsonObject.get("parentIds"); List zones = (List) jsonObject.get("zones"); @@ -102,9 +103,10 @@ public static Group parseGroup(JSONObject jsonObject) Group group = new Group(); group.setId(id); group.setDisplayName(displayName); + group.setDescription(description); group.setIsRoot(isRoot); - group.setParentIds(parentIds != null ? new HashSet(parentIds) : null); - group.setZones(zones != null ? new HashSet(zones) : null); + group.setParentIds(parentIds != null ? new HashSet<>(parentIds) : null); + group.setZones(zones != null ? new HashSet<>(zones) : null); return group; } From 05f0df1b2fd5392e3985bffd27fea63cdf757d57 Mon Sep 17 00:00:00 2001 From: MichalKinas Date: Wed, 5 Jul 2023 19:34:46 +0200 Subject: [PATCH 06/24] ACS-5506 Proper Group serialization --- .../java/org/alfresco/rest/groups/GroupsTests.java | 3 +-- .../alfresco/rest/api/tests/client/data/Group.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java index caf9bc471b3..7ab715465fc 100644 --- a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java +++ b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java @@ -120,8 +120,7 @@ public void createListDeleteGroupMembership() throws Exception //ListPersonMembership restClient.authenticateUser(userModel).withCoreAPI().usingUser(userModel).listGroupMemberships() - .assertThat().entriesListContains("id", "GROUP_"+groupName) - .and().entriesListContains("id", "GROUP_"+subGroupName); + .assertThat().entriesListContains("id", "GROUP_"+groupName); restClient.assertStatusCodeIs(HttpStatus.OK); //CheckListDetails diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/client/data/Group.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/client/data/Group.java index d8623c397f8..acbbf4d8c75 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/client/data/Group.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/client/data/Group.java @@ -58,7 +58,9 @@ public void expected(Object o) AssertUtil.assertEquals("id", getId(), other.getId()); AssertUtil.assertEquals("displayName", getDisplayName(), other.getDisplayName()); + AssertUtil.assertEquals("description", getDescription(), other.getDescription()); AssertUtil.assertEquals("isRoot", getIsRoot(), other.getIsRoot()); + AssertUtil.assertEquals("hasSubgroups", getHasSubgroups(), other.getHasSubgroups()); AssertUtil.assertEquals("parentIds", getParentIds(), other.getParentIds()); AssertUtil.assertEquals("zones", getZones(), other.getZones()); } @@ -73,11 +75,21 @@ public JSONObject toJSON() groupJson.put("displayName", getDisplayName()); + if (getDescription() != null) + { + groupJson.put("description", getDescription()); + } + if (getIsRoot() != null) { groupJson.put("isRoot", getIsRoot()); } + if (getHasSubgroups() != null) + { + groupJson.put("hasSubgroups", getHasSubgroups()); + } + if (getParentIds() != null) { groupJson.put("parentIds", new ArrayList(getParentIds())); @@ -97,6 +109,7 @@ public static Group parseGroup(JSONObject jsonObject) String displayName = (String) jsonObject.get("displayName"); String description = (String) jsonObject.get("description"); Boolean isRoot = (Boolean) jsonObject.get("isRoot"); + Boolean hasSubgroups = (Boolean) jsonObject.get("hasSubgroups"); List parentIds = (List) jsonObject.get("parentIds"); List zones = (List) jsonObject.get("zones"); @@ -105,6 +118,7 @@ public static Group parseGroup(JSONObject jsonObject) group.setDisplayName(displayName); group.setDescription(description); group.setIsRoot(isRoot); + group.setHasSubgroups(hasSubgroups); group.setParentIds(parentIds != null ? new HashSet<>(parentIds) : null); group.setZones(zones != null ? new HashSet<>(zones) : null); From 0b753c23c264be726721817a0baaeb8d0f0b2bb2 Mon Sep 17 00:00:00 2001 From: MichalKinas Date: Wed, 5 Jul 2023 21:00:10 +0200 Subject: [PATCH 07/24] ACS-5506 Tests cleanup --- .../org/alfresco/rest/groups/GroupsTests.java | 6 ++-- .../repo/web/scripts/groups/GroupsTest.java | 35 +------------------ 2 files changed, 5 insertions(+), 36 deletions(-) diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java index 7ab715465fc..542f6f135c0 100644 --- a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java +++ b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java @@ -115,14 +115,16 @@ public void createListDeleteGroupMembership() throws Exception //+ve restClient.authenticateUser(adminUser).withCoreAPI().usingGroups().createGroupMembership("GROUP_"+groupName, groupMembershipBodyCreate); restClient.assertStatusCodeIs(HttpStatus.CREATED); - restClient.authenticateUser(adminUser).withCoreAPI().usingGroups().createGroupMembership("GROUP_"+groupName, groupMembershipGroupBodyCreate); - restClient.assertStatusCodeIs(HttpStatus.CREATED); //ListPersonMembership restClient.authenticateUser(userModel).withCoreAPI().usingUser(userModel).listGroupMemberships() .assertThat().entriesListContains("id", "GROUP_"+groupName); restClient.assertStatusCodeIs(HttpStatus.OK); + //AddChildGroup + restClient.authenticateUser(adminUser).withCoreAPI().usingGroups().createGroupMembership("GROUP_"+groupName, groupMembershipGroupBodyCreate); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + //CheckListDetails restClient.withCoreAPI().usingParams("include=zones").usingGroups().getGroupDetail("GROUP_"+groupName) .assertThat().field("id").is("GROUP_"+groupName) diff --git a/remote-api/src/test/java/org/alfresco/repo/web/scripts/groups/GroupsTest.java b/remote-api/src/test/java/org/alfresco/repo/web/scripts/groups/GroupsTest.java index 9c15689c0e9..acb889682ae 100644 --- a/remote-api/src/test/java/org/alfresco/repo/web/scripts/groups/GroupsTest.java +++ b/remote-api/src/test/java/org/alfresco/repo/web/scripts/groups/GroupsTest.java @@ -229,7 +229,6 @@ public void testGetRootGroup() throws Exception assertEquals("shortName wrong", TEST_ROOTGROUP, rootGroup.getString("shortName")); assertEquals("displayName wrong", TEST_ROOTGROUP_DISPLAY_NAME, rootGroup.getString("displayName")); assertEquals("authorityType wrong", "GROUP", rootGroup.getString("authorityType")); - assertEquals("hasSubgroups wrong", true, rootGroup.getString("hasSubgroups")); gotRootGroup = true; } if(rootGroup.getString("shortName").equals(EMAIL_GROUP)) @@ -271,7 +270,6 @@ public void testGetRootGroup() throws Exception assertEquals("shortName wrong", TEST_ROOTGROUP, rootGroup.getString("shortName")); assertEquals("displayName wrong", TEST_ROOTGROUP_DISPLAY_NAME, rootGroup.getString("displayName")); assertEquals("authorityType wrong", "GROUP", rootGroup.getString("authorityType")); - assertEquals("hasSubgroups wrong", true, rootGroup.getString("hasSubgroups")); } } } @@ -295,7 +293,6 @@ public void testGetRootGroup() throws Exception assertEquals("shortName wrong", TEST_ROOTGROUP, rootGroup.getString("shortName")); assertEquals("displayName wrong", TEST_ROOTGROUP_DISPLAY_NAME, rootGroup.getString("displayName")); assertEquals("authorityType wrong", "GROUP", rootGroup.getString("authorityType")); - assertEquals("hasSubgroups wrong", true, rootGroup.getString("hasSubgroups")); } } } @@ -386,13 +383,11 @@ public void testCreateRootGroup() throws Exception { JSONObject newGroupJSON = new JSONObject(); newGroupJSON.put("displayName", myDisplayName); - newGroupJSON.put("description", "testDesc"); Response response = sendRequest(new PostRequest(URL_ROOTGROUPS + "/" + myGroupName, newGroupJSON.toString(), "application/json"), Status.STATUS_CREATED); JSONObject top = new JSONObject(response.getContentAsString()); JSONObject rootGroup = top.getJSONObject("data"); assertEquals("shortName wrong", myGroupName, rootGroup.getString("shortName")); assertEquals("displayName wrong", myDisplayName, rootGroup.getString("displayName")); - assertEquals("description wrong", "testDesc", rootGroup.getString("description")); } /** @@ -508,17 +503,6 @@ public void testLinkChild() throws Exception assertEquals("authorityType wrong", "GROUP", subGroup.getString("authorityType")); } - /** - * Check if myGroup has subgroups - */ - { - Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + myRootGroup), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONObject myGroup = top.getJSONObject("data"); - assertTrue(myGroup.getBoolean("hasSubgroups")); - } - /** * Now link in an existing user */ @@ -571,17 +555,6 @@ public void testLinkChild() throws Exception //assertTrue("group B not removed", data.length() == 0); } - - /** - * Check if myGroup has no subgroups - */ - { - Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + myRootGroup), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONObject myGroup = top.getJSONObject("data"); - assertFalse(myGroup.getBoolean("hasSubgroups")); - } /** * Create a new group (BUFFY) @@ -640,9 +613,7 @@ public void testUpdateGroup() throws Exception { String myGroupName = "GT_UG"; String myDisplayName = "GT_UGDisplay"; - String description = "GT_UGDesc"; String myNewDisplayName = "GT_UGDisplayNew"; - String newDescription = "GT_UGDescNew"; this.authenticationComponent.setSystemUserAsCurrentUser(); @@ -654,7 +625,6 @@ public void testUpdateGroup() throws Exception { JSONObject newGroupJSON = new JSONObject(); newGroupJSON.put("displayName", myDisplayName); - newGroupJSON.put("description", description); sendRequest(new PostRequest(URL_ROOTGROUPS + "/" + myGroupName, newGroupJSON.toString(), "application/json"), Status.STATUS_CREATED); } @@ -664,14 +634,12 @@ public void testUpdateGroup() throws Exception { JSONObject newGroupJSON = new JSONObject(); newGroupJSON.put("displayName", myNewDisplayName); - newGroupJSON.put("description", newDescription); Response response = sendRequest(new PutRequest(URL_GROUPS + "/" + myGroupName, newGroupJSON.toString(), "application/json"), Status.STATUS_OK); JSONObject top = new JSONObject(response.getContentAsString()); logger.debug(response.getContentAsString()); JSONObject data = top.getJSONObject("data"); assertTrue(data.length() > 0); assertEquals("displayName wrong", myNewDisplayName, data.getString("displayName")); - assertEquals("description wrong", newDescription, data.getString("description")); } /** @@ -684,8 +652,7 @@ public void testUpdateGroup() throws Exception JSONObject data = top.getJSONObject("data"); assertTrue(data.length() > 0); assertEquals("displayName wrong", myNewDisplayName, data.getString("displayName")); - assertEquals("description wrong", newDescription, data.getString("description")); - } + } /** * Negative test From effb69726128853c06e119d7fb581bf90480ecdf Mon Sep 17 00:00:00 2001 From: MichalKinas Date: Thu, 6 Jul 2023 08:07:43 +0200 Subject: [PATCH 08/24] ACS-5506 Tests fixes --- .../test/java/org/alfresco/rest/groups/GroupsTests.java | 8 ++++---- .../test/java/org/alfresco/rest/api/tests/GroupsTest.java | 5 ++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java index 542f6f135c0..4aad49f9c47 100644 --- a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java +++ b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java @@ -100,13 +100,9 @@ public void createListDeleteGroupMembership() throws Exception //GroupCreation: restClient.authenticateUser(adminUser).withCoreAPI().usingParams("include=zones").usingGroups().createGroup(groupBodyCreate); restClient.assertStatusCodeIs(HttpStatus.CREATED); - restClient.authenticateUser(adminUser).withCoreAPI().usingParams("include=zones").usingGroups().createGroup(subgroupBodyCreate); - restClient.assertStatusCodeIs(HttpStatus.CREATED); JsonObject groupMembershipBody = Json.createObjectBuilder().add("id", userModel.getUsername()).add("memberType", "PERSON").build(); String groupMembershipBodyCreate = groupMembershipBody.toString(); - JsonObject groupMembershipGroupBody = Json.createObjectBuilder().add("id", "GROUP_"+subGroupName).add("memberType", "GROUP").build(); - String groupMembershipGroupBodyCreate = groupMembershipGroupBody.toString(); //MembershipCreation: //-ve @@ -122,6 +118,10 @@ public void createListDeleteGroupMembership() throws Exception restClient.assertStatusCodeIs(HttpStatus.OK); //AddChildGroup + restClient.authenticateUser(adminUser).withCoreAPI().usingParams("include=zones").usingGroups().createGroup(subgroupBodyCreate); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + JsonObject groupMembershipGroupBody = Json.createObjectBuilder().add("id", "GROUP_"+subGroupName).add("memberType", "GROUP").build(); + String groupMembershipGroupBodyCreate = groupMembershipGroupBody.toString(); restClient.authenticateUser(adminUser).withCoreAPI().usingGroups().createGroupMembership("GROUP_"+groupName, groupMembershipGroupBodyCreate); restClient.assertStatusCodeIs(HttpStatus.CREATED); diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/GroupsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/GroupsTest.java index 5f1abee2df3..29a5ed46b75 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/GroupsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/GroupsTest.java @@ -1443,8 +1443,11 @@ public void testCreateGroup() throws Exception assertFalse(createdSubGroup01.getIsRoot()); assertNotNull(createdSubGroup01.getParentIds()); assertEquals(subGroup01Parents, createdSubGroup01.getParentIds()); - assertTrue(createdGroup01.getHasSubgroups()); assertFalse(createdSubGroup01.getHasSubgroups()); + + //validate if parent group now has any subgroup + Group group01 = groupsProxy.getGroup(createdGroup01.getId(), null, HttpServletResponse.SC_OK); + assertTrue(group01.getHasSubgroups()); } // Group id is missing. From 71cbb9e1ef3eee019732e7c589713b2b7b1c5f21 Mon Sep 17 00:00:00 2001 From: MichalKinas Date: Thu, 6 Jul 2023 09:13:42 +0200 Subject: [PATCH 09/24] ACS-5506 Tests cleanup --- .../org/alfresco/rest/groups/GroupsTests.java | 2 +- .../repo/web/scripts/groups/GroupsTest.java | 2138 +++++++++-------- 2 files changed, 1071 insertions(+), 1069 deletions(-) diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java index 4aad49f9c47..bfc9bf27c43 100644 --- a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java +++ b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java @@ -118,7 +118,7 @@ public void createListDeleteGroupMembership() throws Exception restClient.assertStatusCodeIs(HttpStatus.OK); //AddChildGroup - restClient.authenticateUser(adminUser).withCoreAPI().usingParams("include=zones").usingGroups().createGroup(subgroupBodyCreate); + restClient.authenticateUser(adminUser).withCoreAPI().usingParams().usingGroups().createGroup(subgroupBodyCreate); restClient.assertStatusCodeIs(HttpStatus.CREATED); JsonObject groupMembershipGroupBody = Json.createObjectBuilder().add("id", "GROUP_"+subGroupName).add("memberType", "GROUP").build(); String groupMembershipGroupBodyCreate = groupMembershipGroupBody.toString(); diff --git a/remote-api/src/test/java/org/alfresco/repo/web/scripts/groups/GroupsTest.java b/remote-api/src/test/java/org/alfresco/repo/web/scripts/groups/GroupsTest.java index acb889682ae..e13a4e26fbe 100644 --- a/remote-api/src/test/java/org/alfresco/repo/web/scripts/groups/GroupsTest.java +++ b/remote-api/src/test/java/org/alfresco/repo/web/scripts/groups/GroupsTest.java @@ -4,21 +4,21 @@ * %% * Copyright (C) 2005 - 2016 Alfresco Software Limited * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is * provided under the following open source license terms: - * + * * Alfresco 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 3 of the License, or * (at your option) any later version. - * + * * Alfresco 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 Alfresco. If not, see . * #L% @@ -54,715 +54,717 @@ /** * Unit test of Groups REST APIs. - * + * * /api/groups * /api/rootgroups - * + * * @author Mark Rogers */ public class GroupsTest extends BaseWebScriptTest -{ +{ private static final Log logger = LogFactory.getLog(BaseWebScriptTest.class); - - private MutableAuthenticationService authenticationService; - private AuthorityService authorityService; - private AuthenticationComponent authenticationComponent; - private PersonService personService; - - private String ADMIN_GROUP = "ALFRESCO_ADMINISTRATORS"; - private String EMAIL_GROUP = "EMAIL_CONTRIBUTORS"; - private String TEST_ROOTGROUP = "GroupsTest_ROOT"; - private String TEST_GROUPA = "TestA"; - private String TEST_GROUPB = "TESTB"; - private String TEST_GROUPC = "TesTC"; - private String TEST_GROUPD = "TESTD"; - private String TEST_GROUPE = "TestE"; - private String TEST_GROUPF = "TestF"; - private String TEST_GROUPG = "TestG"; - private String TEST_LINK = "TESTLINK"; - private String TEST_ROOTGROUP_DISPLAY_NAME = "GROUPS_TESTROOTDisplayName"; - - private static final String USER_ONE = "GroupTestOne"; - private static final String USER_TWO = "GroupTestTwo"; - private static final String USER_THREE = "GroupTestThree"; - - private static final String URL_GROUPS = "/api/groups"; - private static final String URL_ROOTGROUPS = "/api/rootgroups"; - - /** - * Test Tree for all group tests - * - * TEST_ROOTGROUP - * GROUPA - * GROUPB - * GROUPD - * GROUPE (in Share Zone) - * USER_TWO - * USER_THREE - * GROUPC - * USER_TWO - * GROUPF - * GROUPD - * GROUPG - * GROUPD - */ - private synchronized String createTestTree() - { - if(rootGroupName == null) - { - rootGroupName = authorityService.getName(AuthorityType.GROUP, TEST_ROOTGROUP); - } - - Set shareZones = new HashSet(1, 1.0f); - shareZones.add(AuthorityService.ZONE_APP_SHARE); - - if(!authorityService.authorityExists(rootGroupName)) - { - AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); - - rootGroupName = authorityService.createAuthority(AuthorityType.GROUP, TEST_ROOTGROUP, TEST_ROOTGROUP_DISPLAY_NAME, authorityService.getDefaultZones()); - String groupA = authorityService.createAuthority(AuthorityType.GROUP, TEST_GROUPA, TEST_GROUPA, authorityService.getDefaultZones()); - authorityService.addAuthority(rootGroupName, groupA); - String groupB = authorityService.createAuthority(AuthorityType.GROUP, TEST_GROUPB, TEST_GROUPB,authorityService.getDefaultZones()); - authorityService.addAuthority(rootGroupName, groupB); - String groupD = authorityService.createAuthority(AuthorityType.GROUP, TEST_GROUPD, TEST_GROUPD, authorityService.getDefaultZones()); - String groupE = authorityService.createAuthority(AuthorityType.GROUP, TEST_GROUPE, TEST_GROUPE, shareZones); - authorityService.addAuthority(groupB, groupD); - authorityService.addAuthority(groupB, groupE); - authorityService.addAuthority(groupB, USER_TWO); - authorityService.addAuthority(groupB, USER_THREE); - String groupF = authorityService.createAuthority(AuthorityType.GROUP, TEST_GROUPF, TEST_GROUPF, authorityService.getDefaultZones()); - authorityService.addAuthority(rootGroupName, groupF); - authorityService.addAuthority(groupF, groupD); - String groupG = authorityService.createAuthority(AuthorityType.GROUP, TEST_GROUPG, TEST_GROUPG, authorityService.getDefaultZones()); - authorityService.addAuthority(rootGroupName, groupG); - authorityService.addAuthority(groupG, groupD); - - String groupC = authorityService.createAuthority(AuthorityType.GROUP, TEST_GROUPC, TEST_GROUPC,authorityService.getDefaultZones()); - authorityService.addAuthority(rootGroupName, groupC); - authorityService.addAuthority(groupC, USER_TWO); - - String link = authorityService.createAuthority(AuthorityType.GROUP, TEST_LINK, TEST_LINK, authorityService.getDefaultZones()); - authorityService.addAuthority(rootGroupName, link); - - this.authenticationComponent.setCurrentUser(USER_ONE); - } - - return rootGroupName; - - } - - private static String rootGroupName = null; - @Override - protected void setUp() throws Exception - { - super.setUp(); - - this.authenticationService = (MutableAuthenticationService)getServer().getApplicationContext().getBean("AuthenticationService"); - this.authenticationComponent = (AuthenticationComponent)getServer().getApplicationContext().getBean("authenticationComponent"); - this.personService = (PersonService)getServer().getApplicationContext().getBean("PersonService"); - this.authorityService = (AuthorityService)getServer().getApplicationContext().getBean("AuthorityService"); - - this.authenticationComponent.setSystemUserAsCurrentUser(); - - // Create users - createUser(USER_ONE); - createUser(USER_TWO); - createUser(USER_THREE); - - // Do tests as user one - this.authenticationComponent.setCurrentUser(USER_ONE); - } - - private void createUser(String userName) - { - if (this.authenticationService.authenticationExists(userName) == false) - { - this.authenticationService.createAuthentication(userName, "PWD".toCharArray()); - - PropertyMap ppOne = new PropertyMap(4); - ppOne.put(ContentModel.PROP_USERNAME, userName); - ppOne.put(ContentModel.PROP_FIRSTNAME, "firstName"); - ppOne.put(ContentModel.PROP_LASTNAME, "lastName"); - ppOne.put(ContentModel.PROP_EMAIL, "email@email.com"); - ppOne.put(ContentModel.PROP_JOBTITLE, "jobTitle"); - - this.personService.createPerson(ppOne); - } - } - - @Override - protected void tearDown() throws Exception - { - super.tearDown(); - this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName()); - } - - /** - * Detailed test of get root groups - */ - public void testGetRootGroup() throws Exception - { - createTestTree(); - - /** - * Get all root groups, regardless of zone, should be at least the ALFRESCO_ADMINISTRATORS, - * TEST_ROOTGROUP and EMAIL_CONTRIBUTORS groups - */ - { - Response response = sendRequest(new GetRequest(URL_ROOTGROUPS), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - //System.out.println(response.getContentAsString()); - JSONArray data = top.getJSONArray("data"); - assertTrue(data.length() >= 3); - boolean gotRootGroup = false; - boolean gotEmailGroup = false; - - - for(int i = 0; i < data.length(); i++) - { - JSONObject rootGroup = data.getJSONObject(i); - if(rootGroup.getString("shortName").equals(TEST_ROOTGROUP)) - { - // This is our test rootgroup - assertEquals("shortName wrong", TEST_ROOTGROUP, rootGroup.getString("shortName")); - assertEquals("displayName wrong", TEST_ROOTGROUP_DISPLAY_NAME, rootGroup.getString("displayName")); - assertEquals("authorityType wrong", "GROUP", rootGroup.getString("authorityType")); + + private MutableAuthenticationService authenticationService; + private AuthorityService authorityService; + private AuthenticationComponent authenticationComponent; + private PersonService personService; + + private String ADMIN_GROUP = "ALFRESCO_ADMINISTRATORS"; + private String EMAIL_GROUP = "EMAIL_CONTRIBUTORS"; + private String TEST_ROOTGROUP = "GroupsTest_ROOT"; + private String TEST_GROUPA = "TestA"; + private String TEST_GROUPB = "TESTB"; + private String TEST_GROUPC = "TesTC"; + private String TEST_GROUPD = "TESTD"; + private String TEST_GROUPE = "TestE"; + private String TEST_GROUPF = "TestF"; + private String TEST_GROUPG = "TestG"; + private String TEST_LINK = "TESTLINK"; + private String TEST_ROOTGROUP_DISPLAY_NAME = "GROUPS_TESTROOTDisplayName"; + + private static final String USER_ONE = "GroupTestOne"; + private static final String USER_TWO = "GroupTestTwo"; + private static final String USER_THREE = "GroupTestThree"; + + private static final String URL_GROUPS = "/api/groups"; + private static final String URL_ROOTGROUPS = "/api/rootgroups"; + + /** + * Test Tree for all group tests + * + * TEST_ROOTGROUP + * GROUPA + * GROUPB + * GROUPD + * GROUPE (in Share Zone) + * USER_TWO + * USER_THREE + * GROUPC + * USER_TWO + * GROUPF + * GROUPD + * GROUPG + * GROUPD + */ + private synchronized String createTestTree() + { + if(rootGroupName == null) + { + rootGroupName = authorityService.getName(AuthorityType.GROUP, TEST_ROOTGROUP); + } + + Set shareZones = new HashSet(1, 1.0f); + shareZones.add(AuthorityService.ZONE_APP_SHARE); + + if(!authorityService.authorityExists(rootGroupName)) + { + AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); + + rootGroupName = authorityService.createAuthority(AuthorityType.GROUP, TEST_ROOTGROUP, TEST_ROOTGROUP_DISPLAY_NAME, authorityService.getDefaultZones()); + String groupA = authorityService.createAuthority(AuthorityType.GROUP, TEST_GROUPA, TEST_GROUPA, authorityService.getDefaultZones()); + authorityService.addAuthority(rootGroupName, groupA); + String groupB = authorityService.createAuthority(AuthorityType.GROUP, TEST_GROUPB, TEST_GROUPB,authorityService.getDefaultZones()); + authorityService.addAuthority(rootGroupName, groupB); + String groupD = authorityService.createAuthority(AuthorityType.GROUP, TEST_GROUPD, TEST_GROUPD, authorityService.getDefaultZones()); + String groupE = authorityService.createAuthority(AuthorityType.GROUP, TEST_GROUPE, TEST_GROUPE, shareZones); + authorityService.addAuthority(groupB, groupD); + authorityService.addAuthority(groupB, groupE); + authorityService.addAuthority(groupB, USER_TWO); + authorityService.addAuthority(groupB, USER_THREE); + String groupF = authorityService.createAuthority(AuthorityType.GROUP, TEST_GROUPF, TEST_GROUPF, authorityService.getDefaultZones()); + authorityService.addAuthority(rootGroupName, groupF); + authorityService.addAuthority(groupF, groupD); + String groupG = authorityService.createAuthority(AuthorityType.GROUP, TEST_GROUPG, TEST_GROUPG, authorityService.getDefaultZones()); + authorityService.addAuthority(rootGroupName, groupG); + authorityService.addAuthority(groupG, groupD); + + String groupC = authorityService.createAuthority(AuthorityType.GROUP, TEST_GROUPC, TEST_GROUPC,authorityService.getDefaultZones()); + authorityService.addAuthority(rootGroupName, groupC); + authorityService.addAuthority(groupC, USER_TWO); + + String link = authorityService.createAuthority(AuthorityType.GROUP, TEST_LINK, TEST_LINK, authorityService.getDefaultZones()); + authorityService.addAuthority(rootGroupName, link); + + this.authenticationComponent.setCurrentUser(USER_ONE); + } + + return rootGroupName; + + } + + private static String rootGroupName = null; + @Override + protected void setUp() throws Exception + { + super.setUp(); + + this.authenticationService = (MutableAuthenticationService)getServer().getApplicationContext().getBean("AuthenticationService"); + this.authenticationComponent = (AuthenticationComponent)getServer().getApplicationContext().getBean("authenticationComponent"); + this.personService = (PersonService)getServer().getApplicationContext().getBean("PersonService"); + this.authorityService = (AuthorityService)getServer().getApplicationContext().getBean("AuthorityService"); + + this.authenticationComponent.setSystemUserAsCurrentUser(); + + // Create users + createUser(USER_ONE); + createUser(USER_TWO); + createUser(USER_THREE); + + // Do tests as user one + this.authenticationComponent.setCurrentUser(USER_ONE); + } + + private void createUser(String userName) + { + if (this.authenticationService.authenticationExists(userName) == false) + { + this.authenticationService.createAuthentication(userName, "PWD".toCharArray()); + + PropertyMap ppOne = new PropertyMap(4); + ppOne.put(ContentModel.PROP_USERNAME, userName); + ppOne.put(ContentModel.PROP_FIRSTNAME, "firstName"); + ppOne.put(ContentModel.PROP_LASTNAME, "lastName"); + ppOne.put(ContentModel.PROP_EMAIL, "email@email.com"); + ppOne.put(ContentModel.PROP_JOBTITLE, "jobTitle"); + + this.personService.createPerson(ppOne); + } + } + + @Override + protected void tearDown() throws Exception + { + super.tearDown(); + this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName()); + } + + /** + * Detailed test of get root groups + */ + public void testGetRootGroup() throws Exception + { + createTestTree(); + + /** + * Get all root groups, regardless of zone, should be at least the ALFRESCO_ADMINISTRATORS, + * TEST_ROOTGROUP and EMAIL_CONTRIBUTORS groups + */ + { + Response response = sendRequest(new GetRequest(URL_ROOTGROUPS), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + //System.out.println(response.getContentAsString()); + JSONArray data = top.getJSONArray("data"); + assertTrue(data.length() >= 3); + boolean gotRootGroup = false; + boolean gotEmailGroup = false; + + + for(int i = 0; i < data.length(); i++) + { + JSONObject rootGroup = data.getJSONObject(i); + if(rootGroup.getString("shortName").equals(TEST_ROOTGROUP)) + { + // This is our test rootgroup + assertEquals("shortName wrong", TEST_ROOTGROUP, rootGroup.getString("shortName")); + assertEquals("displayName wrong", TEST_ROOTGROUP_DISPLAY_NAME, rootGroup.getString("displayName")); + assertEquals("authorityType wrong", "GROUP", rootGroup.getString("authorityType")); gotRootGroup = true; - } - if(rootGroup.getString("shortName").equals(EMAIL_GROUP)) - { - gotEmailGroup = true; - } - } - assertTrue("root group not found", gotRootGroup); - assertTrue("email group not found", gotEmailGroup); - } - - - if(rootGroupName != null) - { - rootGroupName = authorityService.getName(AuthorityType.GROUP, TEST_ROOTGROUP); - } - - Set zones = authorityService.getAuthorityZones(rootGroupName); - assertTrue("root group is in APP.DEFAULT zone", zones.contains("APP.DEFAULT") ); - - /** - * Get all root groups in the application zone "APP.DEFAULT" - */ - { - Response response = sendRequest(new GetRequest(URL_ROOTGROUPS + "?zone=APP.DEFAULT"), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - //System.out.println(response.getContentAsString()); - JSONArray data = top.getJSONArray("data"); - - assertTrue(data.length() > 0); - - for(int i = 0; i < data.length(); i++) - { - JSONObject rootGroup = data.getJSONObject(i); - if(rootGroup.getString("shortName").equals(TEST_ROOTGROUP)) - { - // This is our test rootgroup - assertEquals("shortName wrong", TEST_ROOTGROUP, rootGroup.getString("shortName")); - assertEquals("displayName wrong", TEST_ROOTGROUP_DISPLAY_NAME, rootGroup.getString("displayName")); - assertEquals("authorityType wrong", "GROUP", rootGroup.getString("authorityType")); } - } - } - - /** - * Get all root groups in the admin zone - */ - { - Response response = sendRequest(new GetRequest(URL_ROOTGROUPS + "?zone=AUTH.ALF"), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONArray data = top.getJSONArray("data"); - assertTrue(data.length() > 0); - - for(int i = 0; i < data.length(); i++) - { - JSONObject rootGroup = data.getJSONObject(i); - if(rootGroup.getString("shortName").equals(TEST_ROOTGROUP)) - { - // This is our test rootgroup - assertEquals("shortName wrong", TEST_ROOTGROUP, rootGroup.getString("shortName")); - assertEquals("displayName wrong", TEST_ROOTGROUP_DISPLAY_NAME, rootGroup.getString("displayName")); - assertEquals("authorityType wrong", "GROUP", rootGroup.getString("authorityType")); + if(rootGroup.getString("shortName").equals(EMAIL_GROUP)) + { + gotEmailGroup = true; + } + } + assertTrue("root group not found", gotRootGroup); + assertTrue("email group not found", gotEmailGroup); + } + + + if(rootGroupName != null) + { + rootGroupName = authorityService.getName(AuthorityType.GROUP, TEST_ROOTGROUP); + } + + Set zones = authorityService.getAuthorityZones(rootGroupName); + assertTrue("root group is in APP.DEFAULT zone", zones.contains("APP.DEFAULT") ); + + /** + * Get all root groups in the application zone "APP.DEFAULT" + */ + { + Response response = sendRequest(new GetRequest(URL_ROOTGROUPS + "?zone=APP.DEFAULT"), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + //System.out.println(response.getContentAsString()); + JSONArray data = top.getJSONArray("data"); + + assertTrue(data.length() > 0); + + for(int i = 0; i < data.length(); i++) + { + JSONObject rootGroup = data.getJSONObject(i); + if(rootGroup.getString("shortName").equals(TEST_ROOTGROUP)) + { + // This is our test rootgroup + assertEquals("shortName wrong", TEST_ROOTGROUP, rootGroup.getString("shortName")); + assertEquals("displayName wrong", TEST_ROOTGROUP_DISPLAY_NAME, rootGroup.getString("displayName")); + assertEquals("authorityType wrong", "GROUP", rootGroup.getString("authorityType")); + } + } + } + + /** + * Get all root groups in the admin zone + */ + { + Response response = sendRequest(new GetRequest(URL_ROOTGROUPS + "?zone=AUTH.ALF"), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONArray data = top.getJSONArray("data"); + assertTrue(data.length() > 0); + + for(int i = 0; i < data.length(); i++) + { + JSONObject rootGroup = data.getJSONObject(i); + if(rootGroup.getString("shortName").equals(TEST_ROOTGROUP)) + { + // This is our test rootgroup + assertEquals("shortName wrong", TEST_ROOTGROUP, rootGroup.getString("shortName")); + assertEquals("displayName wrong", TEST_ROOTGROUP_DISPLAY_NAME, rootGroup.getString("displayName")); + assertEquals("authorityType wrong", "GROUP", rootGroup.getString("authorityType")); + } + } + } + + /** + * Negative test Get all root groups in the a zone that does not exist + */ + { + Response response = sendRequest(new GetRequest(URL_ROOTGROUPS + "?zone=WIBBLE"), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONArray data = top.getJSONArray("data"); + assertTrue(data.length() == 0); + // Should return no results + } + + } + + /** + * Detailed test of get group + */ + public void testGetGroup() throws Exception + { + createTestTree(); + + { + Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + ADMIN_GROUP), 200); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONObject data = top.getJSONObject("data"); + assertTrue(data.length() > 0); + } + + { + sendRequest(new GetRequest(URL_GROUPS + "/" + "crap"), Status.STATUS_NOT_FOUND); + } + + /** + * Get GROUP B + */ + { + Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPB), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONObject data = top.getJSONObject("data"); + assertTrue(data.length() > 0); + } + + /** + * Get GROUP E which is in a different zone + */ + { + Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPE), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONObject data = top.getJSONObject("data"); + assertTrue(data.length() > 0); + } + + } + + /** + * Detailed test of create root group + * Detailed test of delete root group + */ + public void testCreateRootGroup() throws Exception + { + String myGroupName = "GT_CRG"; + String myDisplayName = "GT_CRGDisplay"; + + /** + * Negative test - try to create a group without admin authority + */ + { + JSONObject newGroupJSON = new JSONObject(); + newGroupJSON.put("displayName", myDisplayName); + sendRequest(new PostRequest(URL_ROOTGROUPS + "/" + myGroupName, newGroupJSON.toString(), "application/json"), Status.STATUS_INTERNAL_SERVER_ERROR); + } + + + this.authenticationComponent.setSystemUserAsCurrentUser(); + + try + { + /** + * Create a root group + */ + { + JSONObject newGroupJSON = new JSONObject(); + newGroupJSON.put("displayName", myDisplayName); + Response response = sendRequest(new PostRequest(URL_ROOTGROUPS + "/" + myGroupName, newGroupJSON.toString(), "application/json"), Status.STATUS_CREATED); + JSONObject top = new JSONObject(response.getContentAsString()); + JSONObject rootGroup = top.getJSONObject("data"); + assertEquals("shortName wrong", myGroupName, rootGroup.getString("shortName")); + assertEquals("displayName wrong", myDisplayName, rootGroup.getString("displayName")); + } + + /** + * Negative test Create a root group that already exists + */ + { + JSONObject newGroupJSON = new JSONObject(); + newGroupJSON.put("displayName", myDisplayName); + sendRequest(new PostRequest(URL_ROOTGROUPS + "/" + myGroupName, newGroupJSON.toString(), "application/json"), Status.STATUS_BAD_REQUEST); + } + + /** + * Delete the root group + */ + sendRequest(new DeleteRequest(URL_ROOTGROUPS + "/" + myGroupName), Status.STATUS_OK); + + /** + * Attempt to delete the root group again - should fail + */ + sendRequest(new DeleteRequest(URL_ROOTGROUPS + "/" + myGroupName), Status.STATUS_NOT_FOUND); + + + } + finally + { + + /** + * Delete the root group + */ + sendRequest(new DeleteRequest(URL_ROOTGROUPS + "/" + myGroupName), 0); + } + } + + /** + * Detailed test of link group + */ + public void testLinkChild() throws Exception + { + String myRootGroup = "GT_LGROOT"; + + try + { + this.authenticationComponent.setSystemUserAsCurrentUser(); + sendRequest(new DeleteRequest(URL_ROOTGROUPS + "/" + myRootGroup), 0); + + String groupLinkFullName = ""; + { + Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_LINK), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONObject data = top.getJSONObject("data"); + assertTrue(data.length() > 0); + groupLinkFullName = data.getString("fullName"); + } + + /** + * Create a root group + */ + { + JSONObject newGroupJSON = new JSONObject(); + newGroupJSON.put("displayName", myRootGroup); + sendRequest(new PostRequest(URL_ROOTGROUPS + "/" + myRootGroup, newGroupJSON.toString(), "application/json"), Status.STATUS_CREATED); + } + + /** + * Link an existing group (GROUPB) to my root group. + */ + + /** + * Negative test Link Group B without administrator access. + */ + this.authenticationComponent.setCurrentUser(USER_ONE); + { + JSONObject newGroupJSON = new JSONObject(); + sendRequest(new PostRequest(URL_GROUPS + "/" + myRootGroup +"/children/" + groupLinkFullName, newGroupJSON.toString(), "application/json" ), Status.STATUS_INTERNAL_SERVER_ERROR); + } + + this.authenticationComponent.setSystemUserAsCurrentUser(); + + /** + * Link Group B + */ + { + JSONObject newGroupJSON = new JSONObject(); + Response response = sendRequest(new PostRequest(URL_GROUPS + "/" + myRootGroup +"/children/" + groupLinkFullName, newGroupJSON.toString(), "application/json" ), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONObject data = top.getJSONObject("data"); + } + + /** + * Link the group again - this fails + * - duplicate groups (children with the same name) are not allowed + */ + { + JSONObject newGroupJSON = new JSONObject(); + Response response = sendRequest(new PostRequest(URL_GROUPS + "/" + myRootGroup +"/children/" + groupLinkFullName, newGroupJSON.toString(), "application/json" ), Status.STATUS_INTERNAL_SERVER_ERROR); + } + + /** + * Get All Children of myGroup which are GROUPS - should find GROUP B + */ + { + logger.debug("Get child GROUPS of myRootGroup"); + Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + myRootGroup + "/children?authorityType=GROUP"), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONArray data = top.getJSONArray("data"); + assertTrue("no child groups of myGroup", data.length() == 1); + + JSONObject subGroup = data.getJSONObject(0); + assertEquals("shortName wrong", TEST_LINK, subGroup.getString("shortName")); + assertEquals("authorityType wrong", "GROUP", subGroup.getString("authorityType")); + } + + /** + * Now link in an existing user + */ + { + JSONObject newGroupJSON = new JSONObject(); + String userOneFullName = USER_ONE; + Response response = sendRequest(new PostRequest(URL_GROUPS + "/" + myRootGroup +"/children/" + userOneFullName, newGroupJSON.toString(), "application/json" ), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONObject data = top.getJSONObject("data"); + } + + /** + * Get All Children of myGroup which are USERS - should find USER ONE + */ + { + logger.debug("Get child USERS of myRootGroup"); + Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + myRootGroup + "/children?authorityType=USER"), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONArray data = top.getJSONArray("data"); + assertTrue("no child groups of myGroup", data.length() == 1); + + JSONObject subGroup = data.getJSONObject(0); + assertEquals("shortName wrong", USER_ONE, subGroup.getString("shortName")); + assertEquals("authorityType wrong", "USER", subGroup.getString("authorityType")); + } + + /** + * Unlink Group B + */ + { + logger.debug("Unlink Test Link"); + Response response = sendRequest(new DeleteRequest(URL_GROUPS + "/" + myRootGroup +"/children/" + groupLinkFullName ), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + + } + + /** + * Get All Children of myGroup which are GROUPS - should no longer find GROUP B + */ + { + logger.debug("Get child GROUPS of myRootGroup"); + Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + myRootGroup + "/children?authorityType=GROUP"), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONArray data = top.getJSONArray("data"); + //TODO TEST failing + + //assertTrue("group B not removed", data.length() == 0); + } + + /** + * Create a new group (BUFFY) + */ + String myNewGroup = "GROUP_BUFFY"; + { + // Delete incase it already exists from a previous test run + sendRequest(new DeleteRequest(URL_ROOTGROUPS + "/BUFFY"), 0); + + JSONObject newGroupJSON = new JSONObject(); + Response response = sendRequest(new PostRequest(URL_GROUPS + "/" + myRootGroup +"/children/" + myNewGroup, newGroupJSON.toString(), "application/json" ), Status.STATUS_CREATED); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONObject data = top.getJSONObject("data"); + assertEquals("shortName wrong", "BUFFY", data.getString("shortName")); + assertEquals("fullName wrong", myNewGroup, data.getString("fullName")); + assertEquals("authorityType wrong", "GROUP", data.getString("authorityType")); + } + + /** + * Get All Children of myGroup which are GROUPS - should find GROUP(BUFFY) + */ + { + logger.debug("Get child GROUPS of myRootGroup"); + Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + myRootGroup + "/children?authorityType=GROUP"), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONArray data = top.getJSONArray("data"); + for(int i = 0; i < data.length(); i++) + { + JSONObject rootGroup = data.getJSONObject(i); + if(rootGroup.getString("fullName").equals(myNewGroup)) + { + + } } - } - } - - /** - * Negative test Get all root groups in the a zone that does not exist - */ - { - Response response = sendRequest(new GetRequest(URL_ROOTGROUPS + "?zone=WIBBLE"), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONArray data = top.getJSONArray("data"); - assertTrue(data.length() == 0); - // Should return no results - } - - } - - /** - * Detailed test of get group - */ - public void testGetGroup() throws Exception - { - createTestTree(); - - { - Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + ADMIN_GROUP), 200); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONObject data = top.getJSONObject("data"); - assertTrue(data.length() > 0); - } - - { - sendRequest(new GetRequest(URL_GROUPS + "/" + "crap"), Status.STATUS_NOT_FOUND); - } - - /** - * Get GROUP B - */ - { - Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPB), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONObject data = top.getJSONObject("data"); - assertTrue(data.length() > 0); - } - - /** - * Get GROUP E which is in a different zone - */ - { - Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPE), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONObject data = top.getJSONObject("data"); - assertTrue(data.length() > 0); - } - - } - - /** - * Detailed test of create root group - * Detailed test of delete root group - */ - public void testCreateRootGroup() throws Exception - { - String myGroupName = "GT_CRG"; - String myDisplayName = "GT_CRGDisplay"; - - /** - * Negative test - try to create a group without admin authority - */ - { - JSONObject newGroupJSON = new JSONObject(); - newGroupJSON.put("displayName", myDisplayName); - sendRequest(new PostRequest(URL_ROOTGROUPS + "/" + myGroupName, newGroupJSON.toString(), "application/json"), Status.STATUS_INTERNAL_SERVER_ERROR); - } - - - this.authenticationComponent.setSystemUserAsCurrentUser(); - - try - { - /** - * Create a root group - */ - { - JSONObject newGroupJSON = new JSONObject(); - newGroupJSON.put("displayName", myDisplayName); - Response response = sendRequest(new PostRequest(URL_ROOTGROUPS + "/" + myGroupName, newGroupJSON.toString(), "application/json"), Status.STATUS_CREATED); - JSONObject top = new JSONObject(response.getContentAsString()); - JSONObject rootGroup = top.getJSONObject("data"); - assertEquals("shortName wrong", myGroupName, rootGroup.getString("shortName")); - assertEquals("displayName wrong", myDisplayName, rootGroup.getString("displayName")); - } - - /** - * Negative test Create a root group that already exists - */ - { - JSONObject newGroupJSON = new JSONObject(); - newGroupJSON.put("displayName", myDisplayName); - sendRequest(new PostRequest(URL_ROOTGROUPS + "/" + myGroupName, newGroupJSON.toString(), "application/json"), Status.STATUS_BAD_REQUEST); - } - - /** - * Delete the root group - */ - sendRequest(new DeleteRequest(URL_ROOTGROUPS + "/" + myGroupName), Status.STATUS_OK); - - /** - * Attempt to delete the root group again - should fail - */ - sendRequest(new DeleteRequest(URL_ROOTGROUPS + "/" + myGroupName), Status.STATUS_NOT_FOUND); - - - } - finally - { - - /** - * Delete the root group - */ - sendRequest(new DeleteRequest(URL_ROOTGROUPS + "/" + myGroupName), 0); - } - } - - /** - * Detailed test of link group - */ - public void testLinkChild() throws Exception - { - String myRootGroup = "GT_LGROOT"; - - try - { - this.authenticationComponent.setSystemUserAsCurrentUser(); - sendRequest(new DeleteRequest(URL_ROOTGROUPS + "/" + myRootGroup), 0); - - String groupLinkFullName = ""; - { - Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_LINK), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONObject data = top.getJSONObject("data"); - assertTrue(data.length() > 0); - groupLinkFullName = data.getString("fullName"); - } - - /** - * Create a root group - */ - { - JSONObject newGroupJSON = new JSONObject(); - newGroupJSON.put("displayName", myRootGroup); - sendRequest(new PostRequest(URL_ROOTGROUPS + "/" + myRootGroup, newGroupJSON.toString(), "application/json"), Status.STATUS_CREATED); - } - - /** - * Link an existing group (GROUPB) to my root group. - */ - - /** - * Negative test Link Group B without administrator access. - */ - this.authenticationComponent.setCurrentUser(USER_ONE); - { - JSONObject newGroupJSON = new JSONObject(); - sendRequest(new PostRequest(URL_GROUPS + "/" + myRootGroup +"/children/" + groupLinkFullName, newGroupJSON.toString(), "application/json" ), Status.STATUS_INTERNAL_SERVER_ERROR); - } - - this.authenticationComponent.setSystemUserAsCurrentUser(); - - /** - * Link Group B - */ - { - JSONObject newGroupJSON = new JSONObject(); - Response response = sendRequest(new PostRequest(URL_GROUPS + "/" + myRootGroup +"/children/" + groupLinkFullName, newGroupJSON.toString(), "application/json" ), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONObject data = top.getJSONObject("data"); - } - - /** - * Link the group again - this fails - * - duplicate groups (children with the same name) are not allowed - */ - { - JSONObject newGroupJSON = new JSONObject(); - Response response = sendRequest(new PostRequest(URL_GROUPS + "/" + myRootGroup +"/children/" + groupLinkFullName, newGroupJSON.toString(), "application/json" ), Status.STATUS_INTERNAL_SERVER_ERROR); - } - - /** - * Get All Children of myGroup which are GROUPS - should find GROUP B - */ - { - logger.debug("Get child GROUPS of myRootGroup"); - Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + myRootGroup + "/children?authorityType=GROUP"), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONArray data = top.getJSONArray("data"); - assertTrue("no child groups of myGroup", data.length() == 1); - - JSONObject subGroup = data.getJSONObject(0); - assertEquals("shortName wrong", TEST_LINK, subGroup.getString("shortName")); - assertEquals("authorityType wrong", "GROUP", subGroup.getString("authorityType")); - } - - /** - * Now link in an existing user - */ - { - JSONObject newGroupJSON = new JSONObject(); - String userOneFullName = USER_ONE; - Response response = sendRequest(new PostRequest(URL_GROUPS + "/" + myRootGroup +"/children/" + userOneFullName, newGroupJSON.toString(), "application/json" ), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONObject data = top.getJSONObject("data"); - } - - /** - * Get All Children of myGroup which are USERS - should find USER ONE - */ - { - logger.debug("Get child USERS of myRootGroup"); - Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + myRootGroup + "/children?authorityType=USER"), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONArray data = top.getJSONArray("data"); - assertTrue("no child groups of myGroup", data.length() == 1); - - JSONObject subGroup = data.getJSONObject(0); - assertEquals("shortName wrong", USER_ONE, subGroup.getString("shortName")); - assertEquals("authorityType wrong", "USER", subGroup.getString("authorityType")); - } - - /** - * Unlink Group B - */ - { - logger.debug("Unlink Test Link"); - Response response = sendRequest(new DeleteRequest(URL_GROUPS + "/" + myRootGroup +"/children/" + groupLinkFullName ), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - - } - - /** - * Get All Children of myGroup which are GROUPS - should no longer find GROUP B - */ - { - logger.debug("Get child GROUPS of myRootGroup"); - Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + myRootGroup + "/children?authorityType=GROUP"), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONArray data = top.getJSONArray("data"); - //TODO TEST failing - - //assertTrue("group B not removed", data.length() == 0); - } - - /** - * Create a new group (BUFFY) - */ - String myNewGroup = "GROUP_BUFFY"; - { - // Delete incase it already exists from a previous test run - sendRequest(new DeleteRequest(URL_ROOTGROUPS + "/BUFFY"), 0); - - JSONObject newGroupJSON = new JSONObject(); - Response response = sendRequest(new PostRequest(URL_GROUPS + "/" + myRootGroup +"/children/" + myNewGroup, newGroupJSON.toString(), "application/json" ), Status.STATUS_CREATED); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONObject data = top.getJSONObject("data"); - assertEquals("shortName wrong", "BUFFY", data.getString("shortName")); - assertEquals("fullName wrong", myNewGroup, data.getString("fullName")); - assertEquals("authorityType wrong", "GROUP", data.getString("authorityType")); - } - - /** - * Get All Children of myGroup which are GROUPS - should find GROUP(BUFFY) - */ - { - logger.debug("Get child GROUPS of myRootGroup"); - Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + myRootGroup + "/children?authorityType=GROUP"), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONArray data = top.getJSONArray("data"); - for(int i = 0; i < data.length(); i++) - { - JSONObject rootGroup = data.getJSONObject(i); - if(rootGroup.getString("fullName").equals(myNewGroup)) - { - - } - } - - } - - /** - * Negative tests - */ - - } - finally - { - sendRequest(new DeleteRequest(URL_ROOTGROUPS + "/" + myRootGroup), 0); - } - } - - /** - * Detailed test of update group - * @throws Exception - */ - public void testUpdateGroup() throws Exception - { - String myGroupName = "GT_UG"; - String myDisplayName = "GT_UGDisplay"; - String myNewDisplayName = "GT_UGDisplayNew"; + + } + + /** + * Negative tests + */ + + } + finally + { + sendRequest(new DeleteRequest(URL_ROOTGROUPS + "/" + myRootGroup), 0); + } + } + + /** + * Detailed test of update group + * @throws Exception + */ + public void testUpdateGroup() throws Exception + { + String myGroupName = "GT_UG"; + String myDisplayName = "GT_UGDisplay"; + String myNewDisplayName = "GT_UGDisplayNew"; this.authenticationComponent.setSystemUserAsCurrentUser(); - - try - { - /** - * Create a root group with descrription - */ - { - JSONObject newGroupJSON = new JSONObject(); - newGroupJSON.put("displayName", myDisplayName); + + try + { + /** + * Create a root group + */ + { + JSONObject newGroupJSON = new JSONObject(); + newGroupJSON.put("displayName", myDisplayName); sendRequest(new PostRequest(URL_ROOTGROUPS + "/" + myGroupName, newGroupJSON.toString(), "application/json"), Status.STATUS_CREATED); - } - - /** - * Now change its display name - */ - { - JSONObject newGroupJSON = new JSONObject(); - newGroupJSON.put("displayName", myNewDisplayName); + } + + /** + * Now change its display name + */ + { + JSONObject newGroupJSON = new JSONObject(); + newGroupJSON.put("displayName", myNewDisplayName); Response response = sendRequest(new PutRequest(URL_GROUPS + "/" + myGroupName, newGroupJSON.toString(), "application/json"), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONObject data = top.getJSONObject("data"); - assertTrue(data.length() > 0); - assertEquals("displayName wrong", myNewDisplayName, data.getString("displayName")); - } - - /** - * Now get it and verify that the name has changed - */ - { - Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + myGroupName), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONObject data = top.getJSONObject("data"); - assertTrue(data.length() > 0); - assertEquals("displayName wrong", myNewDisplayName, data.getString("displayName")); - } - - /** - * Negative test - */ - { - JSONObject newGroupJSON = new JSONObject(); - newGroupJSON.put("displayName", myNewDisplayName); - sendRequest(new PutRequest(URL_GROUPS + "/" + "rubbish", newGroupJSON.toString(), "application/json"), Status.STATUS_NOT_FOUND); - } - } - finally - { - sendRequest(new DeleteRequest(URL_ROOTGROUPS + "/" + myGroupName), 0); - } - } - - - /** - * Detailed test of search groups - *
  • if the optional includeInternal parameter is true then will include internal groups, otherwise internalGroups are not returned.
  • -
  • If the optional shortNameFilter parameter is set then returns those root groups with a partial match on shortName.
  • - */ - public void testSearchGroups() throws Exception - { - createTestTree(); - - // Search on partial short name - { - Response response = sendRequest(new GetRequest(URL_GROUPS + "?shortNameFilter=" + "ALFRESCO_ADMIN*"), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONArray data = top.getJSONArray("data"); - assertEquals("length not 1", 1, data.length()); - JSONObject authority = data.getJSONObject(0); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONObject data = top.getJSONObject("data"); + assertTrue(data.length() > 0); + assertEquals("displayName wrong", myNewDisplayName, data.getString("displayName")); + + } + + /** + * Now get it and verify that the name has changed + */ + { + Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + myGroupName), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONObject data = top.getJSONObject("data"); + assertTrue(data.length() > 0); + assertEquals("displayName wrong", myNewDisplayName, data.getString("displayName")); + + } + + /** + * Negative test + */ + { + JSONObject newGroupJSON = new JSONObject(); + newGroupJSON.put("displayName", myNewDisplayName); + sendRequest(new PutRequest(URL_GROUPS + "/" + "rubbish", newGroupJSON.toString(), "application/json"), Status.STATUS_NOT_FOUND); + } + } + finally + { + sendRequest(new DeleteRequest(URL_ROOTGROUPS + "/" + myGroupName), 0); + } + } + + + /** + * Detailed test of search groups + *
  • if the optional includeInternal parameter is true then will include internal groups, otherwise internalGroups are not returned.
  • +
  • If the optional shortNameFilter parameter is set then returns those root groups with a partial match on shortName.
  • + */ + public void testSearchGroups() throws Exception + { + createTestTree(); + + // Search on partial short name + { + Response response = sendRequest(new GetRequest(URL_GROUPS + "?shortNameFilter=" + "ALFRESCO_ADMIN*"), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONArray data = top.getJSONArray("data"); + assertEquals("length not 1", 1, data.length()); + JSONObject authority = data.getJSONObject(0); assertEquals("", ADMIN_GROUP, authority.getString("shortName")); - } - - // Search on partial short name with a ? - { - Response response = sendRequest(new GetRequest(URL_GROUPS + "?shortNameFilter=" + "ALFRE?CO_ADMIN*"), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONArray data = top.getJSONArray("data"); - assertEquals("length not 1", 1, data.length()); - JSONObject authority = data.getJSONObject(0); + } + + // Search on partial short name with a ? + { + Response response = sendRequest(new GetRequest(URL_GROUPS + "?shortNameFilter=" + "ALFRE?CO_ADMIN*"), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONArray data = top.getJSONArray("data"); + assertEquals("length not 1", 1, data.length()); + JSONObject authority = data.getJSONObject(0); assertEquals("", ADMIN_GROUP, authority.getString("shortName")); - } - - // Negative test. - { - Response response = sendRequest(new GetRequest(URL_GROUPS + "?shortNameFilter=" + "XX?X"), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONArray data = top.getJSONArray("data"); - assertEquals("length not 0", 0, data.length()); - } - - // Search on full shortName + } + + // Negative test. + { + Response response = sendRequest(new GetRequest(URL_GROUPS + "?shortNameFilter=" + "XX?X"), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONArray data = top.getJSONArray("data"); + assertEquals("length not 0", 0, data.length()); + } + + // Search on full shortName { - Response response = sendRequest(new GetRequest(URL_GROUPS + "?shortNameFilter=" + ADMIN_GROUP), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONArray data = top.getJSONArray("data"); - assertEquals("length not 1", 1, data.length()); - JSONObject authority = data.getJSONObject(0); + Response response = sendRequest(new GetRequest(URL_GROUPS + "?shortNameFilter=" + ADMIN_GROUP), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONArray data = top.getJSONArray("data"); + assertEquals("length not 1", 1, data.length()); + JSONObject authority = data.getJSONObject(0); assertEquals("", ADMIN_GROUP, authority.getString("shortName")); } - - // Search on partial short name of a non root group - { - Response response = sendRequest(new GetRequest(URL_GROUPS + "?shortNameFilter=" + TEST_GROUPD ), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - //System.out.println(response.getContentAsString()); - JSONArray data = top.getJSONArray("data"); - assertEquals("length not 1", 1, data.length()); - JSONObject authority = data.getJSONObject(0); + + // Search on partial short name of a non root group + { + Response response = sendRequest(new GetRequest(URL_GROUPS + "?shortNameFilter=" + TEST_GROUPD ), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + //System.out.println(response.getContentAsString()); + JSONArray data = top.getJSONArray("data"); + assertEquals("length not 1", 1, data.length()); + JSONObject authority = data.getJSONObject(0); assertEquals("", TEST_GROUPD, authority.getString("shortName")); - } - - // Search on partial short name of a non root group in default zone - { - String url = URL_GROUPS + "?shortNameFilter=" + TEST_GROUPD + "& zone=" + AuthorityService.ZONE_APP_DEFAULT; - Response response = sendRequest(new GetRequest(url ), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - //System.out.println(response.getContentAsString()); - JSONArray data = top.getJSONArray("data"); - assertEquals("length not 1", 1, data.length()); - JSONObject authority = data.getJSONObject(0); + } + + // Search on partial short name of a non root group in default zone + { + String url = URL_GROUPS + "?shortNameFilter=" + TEST_GROUPD + "& zone=" + AuthorityService.ZONE_APP_DEFAULT; + Response response = sendRequest(new GetRequest(url ), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + //System.out.println(response.getContentAsString()); + JSONArray data = top.getJSONArray("data"); + assertEquals("length not 1", 1, data.length()); + JSONObject authority = data.getJSONObject(0); assertEquals("", TEST_GROUPD, authority.getString("shortName")); - } - - // Search for a group (which is not in the default zone) in all zones - { - Response response = sendRequest(new GetRequest(URL_GROUPS + "?shortNameFilter=" + TEST_GROUPE ), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - //System.out.println(response.getContentAsString()); - JSONArray data = top.getJSONArray("data"); - assertEquals("length not 1", 1, data.length()); - JSONObject authority = data.getJSONObject(0); + } + + // Search for a group (which is not in the default zone) in all zones + { + Response response = sendRequest(new GetRequest(URL_GROUPS + "?shortNameFilter=" + TEST_GROUPE ), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + //System.out.println(response.getContentAsString()); + JSONArray data = top.getJSONArray("data"); + assertEquals("length not 1", 1, data.length()); + JSONObject authority = data.getJSONObject(0); assertEquals("Group E not found", TEST_GROUPE, authority.getString("shortName")); - + // Double check group E is in the share zone Set zones = authorityService.getAuthorityZones(authority.getString("fullName")); assertTrue(zones.contains(AuthorityService.ZONE_APP_SHARE)); - } - + } + //TODO TEST Case failing ? // // Search for Group E in a specific zone (without name filter) @@ -776,248 +778,248 @@ public void testSearchGroups() throws Exception // JSONObject authority = data.getJSONObject(0); // assertEquals("", TEST_GROUPE, authority.getString("shortName")); // } - - // Search for a group in a specifc non default zone - { - Response response = sendRequest(new GetRequest(URL_GROUPS + "?shortNameFilter=" + TEST_GROUPE + "&zone=" + AuthorityService.ZONE_APP_SHARE), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); + + // Search for a group in a specifc non default zone + { + Response response = sendRequest(new GetRequest(URL_GROUPS + "?shortNameFilter=" + TEST_GROUPE + "&zone=" + AuthorityService.ZONE_APP_SHARE), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); // System.out.println(response.getContentAsString()); - JSONArray data = top.getJSONArray("data"); - assertEquals("Can't find Group E in Share zone", 1, data.length()); - JSONObject authority = data.getJSONObject(0); + JSONArray data = top.getJSONArray("data"); + assertEquals("Can't find Group E in Share zone", 1, data.length()); + JSONObject authority = data.getJSONObject(0); assertEquals("", TEST_GROUPE, authority.getString("shortName")); - } - - // Negative test Search for a group in a wrong zone - { - Response response = sendRequest(new GetRequest(URL_GROUPS + "?shortNameFilter=" + TEST_GROUPE + "&zone=" + "SOME.THING"), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); + } + + // Negative test Search for a group in a wrong zone + { + Response response = sendRequest(new GetRequest(URL_GROUPS + "?shortNameFilter=" + TEST_GROUPE + "&zone=" + "SOME.THING"), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); // System.out.println(response.getContentAsString()); - JSONArray data = top.getJSONArray("data"); - assertEquals("length not 0", 0, data.length()); - } - - - } - - public void testSearchGroupsPaging() throws Exception - { - createTestTree(); - - JSONArray data = getDataArray(URL_GROUPS + "?shortNameFilter=*"); - int defaultSize = data.length(); - String firstGroup = data.get(0).toString(); - - assertTrue("There should be at least 6 groups in default zone!", defaultSize > 5); - - // Test maxItems works - data = getDataArray(URL_GROUPS + "?shortNameFilter=*" +"&maxItems=3"); - assertEquals("There should only be 3 groups!", 3, data.length()); - assertEquals("The first group should be the same!!", firstGroup, data.get(0).toString()); - - // Test skipCount works - data = getDataArray(URL_GROUPS + "?shortNameFilter=*" + "&skipCount=2"); - assertEquals("The number of groups returned is wrong!", defaultSize-2, data.length()); - assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); - - // Test maxItems and skipCount - data = getDataArray(URL_GROUPS + "?shortNameFilter=*" +"&skipCount=2&maxItems=3"); - assertEquals("The number of groups returned is wrong!", 3, data.length()); - assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); - - // Test maxItems and skipCount when maxItems is too big. - // Shoudl return last 2 items. - int skipCount = defaultSize-2; - data = getDataArray(URL_GROUPS + "?shortNameFilter=*" + "&skipCount="+skipCount+"&maxItems=5"); - assertEquals("The number of groups returned is wrong!", 2, data.length()); - assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); - } - - public void testGetRootGroupsPaging() throws Exception - { - createTestTree(); - - JSONArray data = getDataArray(URL_ROOTGROUPS); - int defaultSize = data.length(); - String firstGroup = data.get(0).toString(); - - assertTrue("There should be at least 3 groups in default zone!", defaultSize > 2); - - // Test maxItems works - data = getDataArray(URL_ROOTGROUPS + "?maxItems=2"); - assertEquals("There should only be 2 groups!", 2, data.length()); - assertEquals("The first group should be the same!!", firstGroup, data.get(0).toString()); - - // Test skipCount works - data = getDataArray(URL_ROOTGROUPS + "?skipCount=1"); - assertEquals("The number of groups returned is wrong!", defaultSize-1, data.length()); - assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); - - // Test maxItems and skipCount - data = getDataArray(URL_ROOTGROUPS + "?skipCount=1&maxItems=2"); - assertEquals("The number of groups returned is wrong!", 2, data.length()); - assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); - - // Test maxItems and skipCount when maxItems is too big. - // Shoudl return last 2 items. - int skipCount = defaultSize-1; - data = getDataArray(URL_ROOTGROUPS + "?skipCount="+skipCount+"&maxItems=5"); - assertEquals("The number of groups returned is wrong!", 1, data.length()); - assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); - } - - public void testGetParentsPaging() throws Exception - { - createTestTree(); - - // Test for immediate parents - String baseUrl = URL_GROUPS + "/" + TEST_GROUPD + "/parents"; - - JSONArray data = getDataArray(baseUrl); - int defaultSize = data.length(); - String firstGroup = data.get(0).toString(); - - assertEquals("There should be at least 3 groups in default zone!", 3, defaultSize); - - // Test maxItems works - data = getDataArray(baseUrl +"?maxItems=2"); - assertEquals("There should only be 2 groups!", 2, data.length()); - assertEquals("The first group should be the same!!", firstGroup, data.get(0).toString()); - - // Test skipCount works - data = getDataArray(baseUrl + "?skipCount=1"); - assertEquals("The number of groups returned is wrong!", 2, data.length()); - assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); - - // Test maxItems and skipCount - data = getDataArray(baseUrl + "?skipCount=1&maxItems=1"); - assertEquals("The number of groups returned is wrong!", 1, data.length()); - assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); - - // Test maxItems and skipCount when maxItems is too big. - // Should return last 2 items. - data = getDataArray(baseUrl + "?skipCount=1&maxItems=5"); - assertEquals("The number of groups returned is wrong!", 2, data.length()); - assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); - - //Test for ALL parents - baseUrl = URL_GROUPS + "/" + TEST_GROUPD + "/parents?level=ALL"; - - data = getDataArray(baseUrl); - defaultSize = data.length(); - firstGroup = data.get(0).toString(); - - assertTrue("There should be at least 3 groups in default zone!", defaultSize > 2); - - // Test maxItems works - data = getDataArray(baseUrl +"&maxItems=2"); - assertEquals("There should only be 2 groups!", 2, data.length()); - assertEquals("The first group should be the same!!", firstGroup, data.get(0).toString()); - - // Test skipCount works - data = getDataArray(baseUrl + "&skipCount=1"); - assertEquals("The number of groups returned is wrong!", defaultSize-1, data.length()); - assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); - - // Test maxItems and skipCount - data = getDataArray(baseUrl + "&skipCount=1&maxItems=2"); - assertEquals("The number of groups returned is wrong!", 2, data.length()); - assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); - - // Test maxItems and skipCount when maxItems is too big. - // Shoudl return last 2 items. - int skipCount = defaultSize-2; - data = getDataArray(baseUrl + "&skipCount="+skipCount+"&maxItems=5"); - assertEquals("The number of groups returned is wrong!", 2, data.length()); - assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); - } - - public void testGetChildGroupsPaging() throws Exception - { - createTestTree(); - - // Test for immediate parents - String baseUrl = URL_GROUPS + "/" + TEST_ROOTGROUP + "/children?authorityType=GROUP"; - - JSONArray data = getDataArray(baseUrl); - int defaultSize = data.length(); - String firstGroup = data.get(0).toString(); - - assertEquals("There should be 6 groups in default zone!", 6, defaultSize); - - // Test maxItems works - data = getDataArray(baseUrl +"&maxItems=2"); - assertEquals("There should only be 3 groups!", 2, data.length()); - assertEquals("The first group should be the same!!", firstGroup, data.get(0).toString()); - - // Test skipCount works - data = getDataArray(baseUrl + "&skipCount=2"); - assertEquals("The number of groups returned is wrong!", 4, data.length()); - assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); - - // Test maxItems and skipCount - data = getDataArray(baseUrl + "&skipCount=2&maxItems=2"); - assertEquals("The number of groups returned is wrong!", 2, data.length()); - assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); - - // Test maxItems and skipCount when maxItems is too big. - // Shoudl return last 2 items. - data = getDataArray(baseUrl + "&skipCount=4&maxItems=5"); - assertEquals("The number of groups returned is wrong!", 2, data.length()); - assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); - } - - private JSONArray getDataArray(String url) throws IOException, JSONException, UnsupportedEncodingException - { - Response response = sendRequest(new GetRequest(url), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - JSONArray data = top.getJSONArray("data"); - return data; - } - /** - * Detailed test of get Parents - */ - public void testGetParents() throws Exception - { - createTestTree(); - - /** - * Get all parents for the root group ALFRESCO_ADMINISTRATORS groups which has no parents - */ - { - Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + ADMIN_GROUP + "/parents"), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONArray data = top.getJSONArray("data"); - // Top level group has no parents - assertTrue("top level group has no parents", data.length() == 0); - } - - /** - * Get GROUP B Which should be a child of TESTROOT - */ - { - Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPB + "/parents"), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONArray data = top.getJSONArray("data"); - assertTrue(data.length() > 0); - } - - /** - * Get GROUP D Which should be a child of GROUPB child of TESTROOT - */ - { - Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPD + "/parents?level=ALL"), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONArray data = top.getJSONArray("data"); - assertTrue(data.length() >= 2); - } - -// TODO parents script does not have zone parameter + JSONArray data = top.getJSONArray("data"); + assertEquals("length not 0", 0, data.length()); + } + + + } + + public void testSearchGroupsPaging() throws Exception + { + createTestTree(); + + JSONArray data = getDataArray(URL_GROUPS + "?shortNameFilter=*"); + int defaultSize = data.length(); + String firstGroup = data.get(0).toString(); + + assertTrue("There should be at least 6 groups in default zone!", defaultSize > 5); + + // Test maxItems works + data = getDataArray(URL_GROUPS + "?shortNameFilter=*" +"&maxItems=3"); + assertEquals("There should only be 3 groups!", 3, data.length()); + assertEquals("The first group should be the same!!", firstGroup, data.get(0).toString()); + + // Test skipCount works + data = getDataArray(URL_GROUPS + "?shortNameFilter=*" + "&skipCount=2"); + assertEquals("The number of groups returned is wrong!", defaultSize-2, data.length()); + assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); + + // Test maxItems and skipCount + data = getDataArray(URL_GROUPS + "?shortNameFilter=*" +"&skipCount=2&maxItems=3"); + assertEquals("The number of groups returned is wrong!", 3, data.length()); + assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); + + // Test maxItems and skipCount when maxItems is too big. + // Shoudl return last 2 items. + int skipCount = defaultSize-2; + data = getDataArray(URL_GROUPS + "?shortNameFilter=*" + "&skipCount="+skipCount+"&maxItems=5"); + assertEquals("The number of groups returned is wrong!", 2, data.length()); + assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); + } + + public void testGetRootGroupsPaging() throws Exception + { + createTestTree(); + + JSONArray data = getDataArray(URL_ROOTGROUPS); + int defaultSize = data.length(); + String firstGroup = data.get(0).toString(); + + assertTrue("There should be at least 3 groups in default zone!", defaultSize > 2); + + // Test maxItems works + data = getDataArray(URL_ROOTGROUPS + "?maxItems=2"); + assertEquals("There should only be 2 groups!", 2, data.length()); + assertEquals("The first group should be the same!!", firstGroup, data.get(0).toString()); + + // Test skipCount works + data = getDataArray(URL_ROOTGROUPS + "?skipCount=1"); + assertEquals("The number of groups returned is wrong!", defaultSize-1, data.length()); + assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); + + // Test maxItems and skipCount + data = getDataArray(URL_ROOTGROUPS + "?skipCount=1&maxItems=2"); + assertEquals("The number of groups returned is wrong!", 2, data.length()); + assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); + + // Test maxItems and skipCount when maxItems is too big. + // Shoudl return last 2 items. + int skipCount = defaultSize-1; + data = getDataArray(URL_ROOTGROUPS + "?skipCount="+skipCount+"&maxItems=5"); + assertEquals("The number of groups returned is wrong!", 1, data.length()); + assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); + } + + public void testGetParentsPaging() throws Exception + { + createTestTree(); + + // Test for immediate parents + String baseUrl = URL_GROUPS + "/" + TEST_GROUPD + "/parents"; + + JSONArray data = getDataArray(baseUrl); + int defaultSize = data.length(); + String firstGroup = data.get(0).toString(); + + assertEquals("There should be at least 3 groups in default zone!", 3, defaultSize); + + // Test maxItems works + data = getDataArray(baseUrl +"?maxItems=2"); + assertEquals("There should only be 2 groups!", 2, data.length()); + assertEquals("The first group should be the same!!", firstGroup, data.get(0).toString()); + + // Test skipCount works + data = getDataArray(baseUrl + "?skipCount=1"); + assertEquals("The number of groups returned is wrong!", 2, data.length()); + assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); + + // Test maxItems and skipCount + data = getDataArray(baseUrl + "?skipCount=1&maxItems=1"); + assertEquals("The number of groups returned is wrong!", 1, data.length()); + assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); + + // Test maxItems and skipCount when maxItems is too big. + // Should return last 2 items. + data = getDataArray(baseUrl + "?skipCount=1&maxItems=5"); + assertEquals("The number of groups returned is wrong!", 2, data.length()); + assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); + + //Test for ALL parents + baseUrl = URL_GROUPS + "/" + TEST_GROUPD + "/parents?level=ALL"; + + data = getDataArray(baseUrl); + defaultSize = data.length(); + firstGroup = data.get(0).toString(); + + assertTrue("There should be at least 3 groups in default zone!", defaultSize > 2); + + // Test maxItems works + data = getDataArray(baseUrl +"&maxItems=2"); + assertEquals("There should only be 2 groups!", 2, data.length()); + assertEquals("The first group should be the same!!", firstGroup, data.get(0).toString()); + + // Test skipCount works + data = getDataArray(baseUrl + "&skipCount=1"); + assertEquals("The number of groups returned is wrong!", defaultSize-1, data.length()); + assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); + + // Test maxItems and skipCount + data = getDataArray(baseUrl + "&skipCount=1&maxItems=2"); + assertEquals("The number of groups returned is wrong!", 2, data.length()); + assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); + + // Test maxItems and skipCount when maxItems is too big. + // Shoudl return last 2 items. + int skipCount = defaultSize-2; + data = getDataArray(baseUrl + "&skipCount="+skipCount+"&maxItems=5"); + assertEquals("The number of groups returned is wrong!", 2, data.length()); + assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); + } + + public void testGetChildGroupsPaging() throws Exception + { + createTestTree(); + + // Test for immediate parents + String baseUrl = URL_GROUPS + "/" + TEST_ROOTGROUP + "/children?authorityType=GROUP"; + + JSONArray data = getDataArray(baseUrl); + int defaultSize = data.length(); + String firstGroup = data.get(0).toString(); + + assertEquals("There should be 6 groups in default zone!", 6, defaultSize); + + // Test maxItems works + data = getDataArray(baseUrl +"&maxItems=2"); + assertEquals("There should only be 3 groups!", 2, data.length()); + assertEquals("The first group should be the same!!", firstGroup, data.get(0).toString()); + + // Test skipCount works + data = getDataArray(baseUrl + "&skipCount=2"); + assertEquals("The number of groups returned is wrong!", 4, data.length()); + assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); + + // Test maxItems and skipCount + data = getDataArray(baseUrl + "&skipCount=2&maxItems=2"); + assertEquals("The number of groups returned is wrong!", 2, data.length()); + assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); + + // Test maxItems and skipCount when maxItems is too big. + // Shoudl return last 2 items. + data = getDataArray(baseUrl + "&skipCount=4&maxItems=5"); + assertEquals("The number of groups returned is wrong!", 2, data.length()); + assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); + } + + private JSONArray getDataArray(String url) throws IOException, JSONException, UnsupportedEncodingException + { + Response response = sendRequest(new GetRequest(url), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + JSONArray data = top.getJSONArray("data"); + return data; + } + /** + * Detailed test of get Parents + */ + public void testGetParents() throws Exception + { + createTestTree(); + + /** + * Get all parents for the root group ALFRESCO_ADMINISTRATORS groups which has no parents + */ + { + Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + ADMIN_GROUP + "/parents"), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONArray data = top.getJSONArray("data"); + // Top level group has no parents + assertTrue("top level group has no parents", data.length() == 0); + } + + /** + * Get GROUP B Which should be a child of TESTROOT + */ + { + Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPB + "/parents"), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONArray data = top.getJSONArray("data"); + assertTrue(data.length() > 0); + } + + /** + * Get GROUP D Which should be a child of GROUPB child of TESTROOT + */ + { + Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPD + "/parents?level=ALL"), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONArray data = top.getJSONArray("data"); + assertTrue(data.length() >= 2); + } + +// TODO parents script does not have zone parameter // /** // * Get GROUP E Which should be a child of GROUPB child of TESTROOT but in a different zone // */ @@ -1028,142 +1030,142 @@ public void testGetParents() throws Exception // JSONArray data = top.getJSONArray("data"); // assertTrue(data.length() >= 2); // } - - /** - * Negative test Get GROUP D level="rubbish" - */ - { - sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPD + "/parents?level=rubbish"), Status.STATUS_BAD_REQUEST); - } - - /** - * Negative test GROUP(Rubbish) does not exist - */ - { - sendRequest(new GetRequest(URL_GROUPS + "/" + "rubbish" + "/parents?level=all"), Status.STATUS_NOT_FOUND); - - } - } - - /** - * Detailed test of get Children - */ - public void testGetChildren() throws Exception - { - createTestTree(); - - /** - * Get All Children of GROUP B - */ - { - logger.debug("Get all children of GROUP B"); - Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPB + "/children"), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONArray data = top.getJSONArray("data"); - assertTrue(data.length() > 0); - boolean gotGroupD = false; - boolean gotGroupE = false; - boolean gotUserTwo = false; - boolean gotUserThree = false; - for(int i = 0; i < data.length(); i++) - { - JSONObject authority = data.getJSONObject(i); - if(authority.getString("shortName").equals(TEST_GROUPD)) - { - gotGroupD = true; - } - if(authority.getString("shortName").equals(TEST_GROUPE)) - { - gotGroupE = true; - } - if(authority.getString("shortName").equals(USER_TWO)) - { - gotUserTwo = true; - } - if(authority.getString("shortName").equals(USER_THREE)) - { - gotUserThree = true; - } - } - assertEquals("4 groups not returned", 4, data.length()); - assertTrue("not got group D", gotGroupD); - assertTrue("not got group E", gotGroupE); - assertTrue("not got user two", gotUserTwo); - assertTrue("not got user three", gotUserThree); - - } - - /** - * Get All Children of GROUP B which are GROUPS - */ - { - logger.debug("Get child GROUPS of GROUP B"); - Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPB + "/children?authorityType=GROUP"), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONArray data = top.getJSONArray("data"); - assertTrue("no child groups of group B", data.length() > 1 ); - - boolean gotGroupD = false; - boolean gotGroupE = false; - JSONObject subGroup = data.getJSONObject(0); - for(int i = 0; i < data.length(); i++) - { - JSONObject authority = data.getJSONObject(i); - if(authority.getString("shortName").equals(TEST_GROUPD)) - { - gotGroupD = true; - } - else if(authority.getString("shortName").equals(TEST_GROUPE)) - { - gotGroupE = true; - } - else - { - fail("unexpected authority returned:" + authority.getString("shortName")); - } - } - assertTrue("not got group D", gotGroupD); - assertTrue("not got group E", gotGroupE); - - assertEquals("authorityType wrong", "GROUP", subGroup.getString("authorityType")); - for(int i = 0; i < data.length(); i++) - { - JSONObject authority = data.getJSONObject(i); - assertEquals("authorityType wrong", "GROUP", authority.getString("authorityType")); - } - } - - /** - * Get All Children of GROUP B which are USERS - */ - { - logger.debug("Get Child Users of Group B"); - Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPB + "/children?authorityType=USER"), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONArray data = top.getJSONArray("data"); - assertTrue(data.length() > 1); - for(int i = 0; i < data.length(); i++) - { - JSONObject authority = data.getJSONObject(i); - assertEquals("authorityType wrong", "USER", authority.getString("authorityType")); - } - } - - /** - * Negative test All Children of GROUP B, bad authorityType - */ - { - sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPB + "/children?authorityType=XXX"), Status.STATUS_BAD_REQUEST); - } - - /** - * Negative test GROUP(Rubbish) does not exist - */ - { - sendRequest(new GetRequest(URL_GROUPS + "/" + "rubbish" + "/children"), Status.STATUS_NOT_FOUND); - } - } -} + + /** + * Negative test Get GROUP D level="rubbish" + */ + { + sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPD + "/parents?level=rubbish"), Status.STATUS_BAD_REQUEST); + } + + /** + * Negative test GROUP(Rubbish) does not exist + */ + { + sendRequest(new GetRequest(URL_GROUPS + "/" + "rubbish" + "/parents?level=all"), Status.STATUS_NOT_FOUND); + + } + } + + /** + * Detailed test of get Children + */ + public void testGetChildren() throws Exception + { + createTestTree(); + + /** + * Get All Children of GROUP B + */ + { + logger.debug("Get all children of GROUP B"); + Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPB + "/children"), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONArray data = top.getJSONArray("data"); + assertTrue(data.length() > 0); + boolean gotGroupD = false; + boolean gotGroupE = false; + boolean gotUserTwo = false; + boolean gotUserThree = false; + for(int i = 0; i < data.length(); i++) + { + JSONObject authority = data.getJSONObject(i); + if(authority.getString("shortName").equals(TEST_GROUPD)) + { + gotGroupD = true; + } + if(authority.getString("shortName").equals(TEST_GROUPE)) + { + gotGroupE = true; + } + if(authority.getString("shortName").equals(USER_TWO)) + { + gotUserTwo = true; + } + if(authority.getString("shortName").equals(USER_THREE)) + { + gotUserThree = true; + } + } + assertEquals("4 groups not returned", 4, data.length()); + assertTrue("not got group D", gotGroupD); + assertTrue("not got group E", gotGroupE); + assertTrue("not got user two", gotUserTwo); + assertTrue("not got user three", gotUserThree); + + } + + /** + * Get All Children of GROUP B which are GROUPS + */ + { + logger.debug("Get child GROUPS of GROUP B"); + Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPB + "/children?authorityType=GROUP"), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONArray data = top.getJSONArray("data"); + assertTrue("no child groups of group B", data.length() > 1 ); + + boolean gotGroupD = false; + boolean gotGroupE = false; + JSONObject subGroup = data.getJSONObject(0); + for(int i = 0; i < data.length(); i++) + { + JSONObject authority = data.getJSONObject(i); + if(authority.getString("shortName").equals(TEST_GROUPD)) + { + gotGroupD = true; + } + else if(authority.getString("shortName").equals(TEST_GROUPE)) + { + gotGroupE = true; + } + else + { + fail("unexpected authority returned:" + authority.getString("shortName")); + } + } + assertTrue("not got group D", gotGroupD); + assertTrue("not got group E", gotGroupE); + + assertEquals("authorityType wrong", "GROUP", subGroup.getString("authorityType")); + for(int i = 0; i < data.length(); i++) + { + JSONObject authority = data.getJSONObject(i); + assertEquals("authorityType wrong", "GROUP", authority.getString("authorityType")); + } + } + + /** + * Get All Children of GROUP B which are USERS + */ + { + logger.debug("Get Child Users of Group B"); + Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPB + "/children?authorityType=USER"), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONArray data = top.getJSONArray("data"); + assertTrue(data.length() > 1); + for(int i = 0; i < data.length(); i++) + { + JSONObject authority = data.getJSONObject(i); + assertEquals("authorityType wrong", "USER", authority.getString("authorityType")); + } + } + + /** + * Negative test All Children of GROUP B, bad authorityType + */ + { + sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPB + "/children?authorityType=XXX"), Status.STATUS_BAD_REQUEST); + } + + /** + * Negative test GROUP(Rubbish) does not exist + */ + { + sendRequest(new GetRequest(URL_GROUPS + "/" + "rubbish" + "/children"), Status.STATUS_NOT_FOUND); + } + } +} \ No newline at end of file From ef9d724ee9a4915a0827e3289d051249db8ef17a Mon Sep 17 00:00:00 2001 From: MichalKinas Date: Thu, 6 Jul 2023 12:52:04 +0200 Subject: [PATCH 10/24] ACS-5506 PMD fixes --- .../alfresco/rest/model/RestGroupsModel.java | 14 +- .../org/alfresco/rest/groups/GroupsTests.java | 26 +- .../alfresco/rest/api/impl/GroupsImpl.java | 14 +- .../org/alfresco/rest/api/model/Group.java | 2 +- .../repo/web/scripts/groups/GroupsTest.java | 2192 ++++++++--------- .../alfresco/rest/api/tests/GroupsTest.java | 25 +- 6 files changed, 1136 insertions(+), 1137 deletions(-) diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestGroupsModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestGroupsModel.java index d8a9b975b23..c5b7b7c1dd7 100644 --- a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestGroupsModel.java +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestGroupsModel.java @@ -25,7 +25,7 @@ */ package org.alfresco.rest.model; -import java.util.ArrayList; +import java.util.List; import com.fasterxml.jackson.annotation.JsonProperty; @@ -46,9 +46,9 @@ public class RestGroupsModel extends TestModel implements IRestModel parentIds; + private List parentIds; @JsonProperty("zones") - private ArrayList zones; + private List zones; @JsonProperty(value = "entry") RestGroupsModel model; @@ -105,22 +105,22 @@ public void setIsRoot(Boolean isRoot) this.isRoot = isRoot; } - public ArrayList getParentIds() + public List getParentIds() { return parentIds; } - public void setParentIds(ArrayList parentIds) + public void setParentIds(List parentIds) { this.parentIds = parentIds; } - public ArrayList getZones() + public List getZones() { return zones; } - public void setZones(ArrayList zones) + public void setZones(List zones) { this.zones = zones; } diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java index bfc9bf27c43..dc109b8248a 100644 --- a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java +++ b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java @@ -31,10 +31,9 @@ public void dataPreparation() throws Exception @Test(groups = { TestGroup.REST_API, TestGroup.GROUPS, TestGroup.SANITY }) @TestRail(section = { TestGroup.REST_API, TestGroup.NODES }, executionType = ExecutionType.SANITY, description = "Verify creation, listing, updating and deletion of groups.") - public void createListUpdateAndDeleteGroup() throws Exception - { - String groupName = "ZtestGroup" + UUID.randomUUID().toString(); - String groupDescription = "ZtestGroup description" + UUID.randomUUID().toString(); + public void createListUpdateAndDeleteGroup() { + String groupName = "ZtestGroup" + UUID.randomUUID(); + String groupDescription = "ZtestGroup description" + UUID.randomUUID(); JsonObject groupBody = Json.createObjectBuilder().add("id", groupName).add("displayName", groupName).add("description", groupDescription).build(); String groupBodyCreate = groupBody.toString(); @@ -88,10 +87,9 @@ public void createListUpdateAndDeleteGroup() throws Exception @Test(groups = { TestGroup.REST_API, TestGroup.GROUPS, TestGroup.SANITY }) @TestRail(section = { TestGroup.REST_API, TestGroup.NODES }, executionType = ExecutionType.SANITY, description = "Verify creation, listing(only for person) and deletion of group memberships. ") - public void createListDeleteGroupMembership() throws Exception - { - String groupName = "ZtestGroup" + UUID.randomUUID().toString(); - String subGroupName = "ZtestSubgroup" + UUID.randomUUID().toString(); + public void createListDeleteGroupMembership() { + String groupName = "ZtestGroup" + UUID.randomUUID(); + String subGroupName = "ZtestSubgroup" + UUID.randomUUID(); JsonObject groupBody = Json.createObjectBuilder().add("id", groupName).add("displayName", groupName).build(); JsonObject subgroupBody = Json.createObjectBuilder().add("id", subGroupName).add("displayName", subGroupName).build(); String groupBodyCreate = groupBody.toString(); @@ -150,7 +148,7 @@ public void createListDeleteGroupMembership() throws Exception description = "Verify listing of group memberships.") public void listGroupMembership() throws Exception { - String groupName = "testGroup" + UUID.randomUUID().toString(); + String groupName = "testGroup" + UUID.randomUUID(); JsonObject groupBody = Json.createObjectBuilder().add("id", groupName).add("displayName", groupName).build(); String groupBodyCreate = groupBody.toString(); @@ -169,12 +167,10 @@ public void listGroupMembership() throws Exception restClient.assertStatusCodeIs(HttpStatus.CREATED); //ListGroupMembership - RetryOperation op = new RetryOperation(){ - public void execute() throws Exception{ - restClient.withCoreAPI().usingGroups().listGroupMemberships("GROUP_"+groupName) - .assertThat().entriesListContains("id", userModel.getUsername()); - restClient.assertStatusCodeIs(HttpStatus.OK); - } + RetryOperation op = () -> { + restClient.withCoreAPI().usingGroups().listGroupMemberships("GROUP_"+groupName) + .assertThat().entriesListContains("id", userModel.getUsername()); + restClient.assertStatusCodeIs(HttpStatus.OK); }; Utility.sleep(500, 35000, op);// Allow indexing to complete. } diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java index e58ee3428d7..11939c55216 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java @@ -107,9 +107,9 @@ public class GroupsImpl implements Groups } // List groups filtering (via where clause) - private final static Set LIST_GROUPS_EQUALS_QUERY_PROPERTIES = new HashSet<>(Arrays.asList(new String[] { PARAM_IS_ROOT })); + private final static Set LIST_GROUPS_EQUALS_QUERY_PROPERTIES = new HashSet<>(List.of(PARAM_IS_ROOT)); - private final static Set LIST_GROUP_MEMBERS_QUERY_PROPERTIES = new HashSet<>(Arrays.asList(new String[] { PARAM_MEMBER_TYPE })); + private final static Set LIST_GROUP_MEMBERS_QUERY_PROPERTIES = new HashSet<>(List.of(PARAM_MEMBER_TYPE)); protected AuthorityService authorityService; protected NodeService nodeService; @@ -241,7 +241,7 @@ public CollectionWithPagingInfo getGroups(final Parameters parameters) private List createGroupsResponse(final List page, final List includeParam, final Set rootAuthorities) { - List groups = new AbstractList() + List groups = new AbstractList<>() { @Override public Group get(int index) @@ -656,7 +656,7 @@ private Pair getGroupsSortProp(Parameters parameters) Pair sortProp; List sortCols = parameters.getSorting(); - if ((sortCols != null) && (sortCols.size() > 0)) + if (sortCols != null && !sortCols.isEmpty()) { if (sortCols.size() > 1) { @@ -671,7 +671,7 @@ private Pair getGroupsSortProp(Parameters parameters) throw new InvalidArgumentException("Invalid sort field: " + sortCol.column); } - sortProp = new Pair<>(sortPropName, (sortCol.asc ? Boolean.TRUE : Boolean.FALSE)); + sortProp = new Pair<>(sortPropName, sortCol.asc ? Boolean.TRUE : Boolean.FALSE); } else { @@ -887,7 +887,7 @@ public void deleteGroupMembership(String groupId, String groupMemberId) // Verify if groupMemberId is member of groupId AuthorityType authorityType = AuthorityType.getAuthorityType(groupMemberId); - Set parents = authorityService.getContainingAuthorities(AuthorityType.GROUP, groupMemberId, true); + Set parents = authorityService.getContainingAuthorities(authorityType, groupMemberId, true); if (!parents.contains(groupId)) { throw new NotFoundException(groupMemberId + " is not member of " + groupId); @@ -1093,7 +1093,7 @@ private boolean authorityExists(AuthorityType authorityType, String authorityNam { String name = inferPrefix ? authorityService.getName(authorityType, authorityName) : authorityName; - return (name != null && authorityService.authorityExists(name)); + return name != null && authorityService.authorityExists(name); } private boolean isGroupAuthority(String authorityName) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/model/Group.java b/remote-api/src/main/java/org/alfresco/rest/api/model/Group.java index 8b4a3647514..0eccdf856eb 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/model/Group.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/model/Group.java @@ -181,6 +181,6 @@ public String toString() public boolean wasSet(String fieldName) { Boolean b = setFields.get(fieldName); - return (b != null ? b : false); + return b != null ? b : false; } } \ No newline at end of file diff --git a/remote-api/src/test/java/org/alfresco/repo/web/scripts/groups/GroupsTest.java b/remote-api/src/test/java/org/alfresco/repo/web/scripts/groups/GroupsTest.java index e13a4e26fbe..9e2a2e58650 100644 --- a/remote-api/src/test/java/org/alfresco/repo/web/scripts/groups/GroupsTest.java +++ b/remote-api/src/test/java/org/alfresco/repo/web/scripts/groups/GroupsTest.java @@ -1,28 +1,28 @@ -/* - * #%L - * Alfresco Remote API - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - * Alfresco 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 3 of the License, or - * (at your option) any later version. - * - * Alfresco 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 Alfresco. If not, see . - * #L% - */ +/* + * #%L + * Alfresco Remote API + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * Alfresco 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 3 of the License, or + * (at your option) any later version. + * + * Alfresco 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 Alfresco. If not, see . + * #L% + */ package org.alfresco.repo.web.scripts.groups; @@ -54,717 +54,717 @@ /** * Unit test of Groups REST APIs. - * + * * /api/groups * /api/rootgroups - * + * * @author Mark Rogers */ public class GroupsTest extends BaseWebScriptTest -{ +{ private static final Log logger = LogFactory.getLog(BaseWebScriptTest.class); - - private MutableAuthenticationService authenticationService; - private AuthorityService authorityService; - private AuthenticationComponent authenticationComponent; - private PersonService personService; - - private String ADMIN_GROUP = "ALFRESCO_ADMINISTRATORS"; - private String EMAIL_GROUP = "EMAIL_CONTRIBUTORS"; - private String TEST_ROOTGROUP = "GroupsTest_ROOT"; - private String TEST_GROUPA = "TestA"; - private String TEST_GROUPB = "TESTB"; - private String TEST_GROUPC = "TesTC"; - private String TEST_GROUPD = "TESTD"; - private String TEST_GROUPE = "TestE"; - private String TEST_GROUPF = "TestF"; - private String TEST_GROUPG = "TestG"; - private String TEST_LINK = "TESTLINK"; - private String TEST_ROOTGROUP_DISPLAY_NAME = "GROUPS_TESTROOTDisplayName"; - - private static final String USER_ONE = "GroupTestOne"; - private static final String USER_TWO = "GroupTestTwo"; - private static final String USER_THREE = "GroupTestThree"; - - private static final String URL_GROUPS = "/api/groups"; - private static final String URL_ROOTGROUPS = "/api/rootgroups"; - - /** - * Test Tree for all group tests - * - * TEST_ROOTGROUP - * GROUPA - * GROUPB - * GROUPD - * GROUPE (in Share Zone) - * USER_TWO - * USER_THREE - * GROUPC - * USER_TWO - * GROUPF - * GROUPD - * GROUPG - * GROUPD - */ - private synchronized String createTestTree() - { - if(rootGroupName == null) - { - rootGroupName = authorityService.getName(AuthorityType.GROUP, TEST_ROOTGROUP); - } - - Set shareZones = new HashSet(1, 1.0f); - shareZones.add(AuthorityService.ZONE_APP_SHARE); - - if(!authorityService.authorityExists(rootGroupName)) - { - AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); - - rootGroupName = authorityService.createAuthority(AuthorityType.GROUP, TEST_ROOTGROUP, TEST_ROOTGROUP_DISPLAY_NAME, authorityService.getDefaultZones()); - String groupA = authorityService.createAuthority(AuthorityType.GROUP, TEST_GROUPA, TEST_GROUPA, authorityService.getDefaultZones()); - authorityService.addAuthority(rootGroupName, groupA); - String groupB = authorityService.createAuthority(AuthorityType.GROUP, TEST_GROUPB, TEST_GROUPB,authorityService.getDefaultZones()); - authorityService.addAuthority(rootGroupName, groupB); - String groupD = authorityService.createAuthority(AuthorityType.GROUP, TEST_GROUPD, TEST_GROUPD, authorityService.getDefaultZones()); - String groupE = authorityService.createAuthority(AuthorityType.GROUP, TEST_GROUPE, TEST_GROUPE, shareZones); - authorityService.addAuthority(groupB, groupD); - authorityService.addAuthority(groupB, groupE); - authorityService.addAuthority(groupB, USER_TWO); - authorityService.addAuthority(groupB, USER_THREE); - String groupF = authorityService.createAuthority(AuthorityType.GROUP, TEST_GROUPF, TEST_GROUPF, authorityService.getDefaultZones()); - authorityService.addAuthority(rootGroupName, groupF); - authorityService.addAuthority(groupF, groupD); - String groupG = authorityService.createAuthority(AuthorityType.GROUP, TEST_GROUPG, TEST_GROUPG, authorityService.getDefaultZones()); - authorityService.addAuthority(rootGroupName, groupG); - authorityService.addAuthority(groupG, groupD); - - String groupC = authorityService.createAuthority(AuthorityType.GROUP, TEST_GROUPC, TEST_GROUPC,authorityService.getDefaultZones()); - authorityService.addAuthority(rootGroupName, groupC); - authorityService.addAuthority(groupC, USER_TWO); - - String link = authorityService.createAuthority(AuthorityType.GROUP, TEST_LINK, TEST_LINK, authorityService.getDefaultZones()); - authorityService.addAuthority(rootGroupName, link); - - this.authenticationComponent.setCurrentUser(USER_ONE); - } - - return rootGroupName; - - } - - private static String rootGroupName = null; - @Override - protected void setUp() throws Exception - { - super.setUp(); - - this.authenticationService = (MutableAuthenticationService)getServer().getApplicationContext().getBean("AuthenticationService"); - this.authenticationComponent = (AuthenticationComponent)getServer().getApplicationContext().getBean("authenticationComponent"); - this.personService = (PersonService)getServer().getApplicationContext().getBean("PersonService"); - this.authorityService = (AuthorityService)getServer().getApplicationContext().getBean("AuthorityService"); - - this.authenticationComponent.setSystemUserAsCurrentUser(); - - // Create users - createUser(USER_ONE); - createUser(USER_TWO); - createUser(USER_THREE); - - // Do tests as user one - this.authenticationComponent.setCurrentUser(USER_ONE); - } - - private void createUser(String userName) - { - if (this.authenticationService.authenticationExists(userName) == false) - { - this.authenticationService.createAuthentication(userName, "PWD".toCharArray()); - - PropertyMap ppOne = new PropertyMap(4); - ppOne.put(ContentModel.PROP_USERNAME, userName); - ppOne.put(ContentModel.PROP_FIRSTNAME, "firstName"); - ppOne.put(ContentModel.PROP_LASTNAME, "lastName"); - ppOne.put(ContentModel.PROP_EMAIL, "email@email.com"); - ppOne.put(ContentModel.PROP_JOBTITLE, "jobTitle"); - - this.personService.createPerson(ppOne); - } - } - - @Override - protected void tearDown() throws Exception - { - super.tearDown(); - this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName()); - } - - /** - * Detailed test of get root groups - */ - public void testGetRootGroup() throws Exception - { - createTestTree(); - - /** - * Get all root groups, regardless of zone, should be at least the ALFRESCO_ADMINISTRATORS, - * TEST_ROOTGROUP and EMAIL_CONTRIBUTORS groups - */ - { - Response response = sendRequest(new GetRequest(URL_ROOTGROUPS), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - //System.out.println(response.getContentAsString()); - JSONArray data = top.getJSONArray("data"); - assertTrue(data.length() >= 3); - boolean gotRootGroup = false; - boolean gotEmailGroup = false; - - - for(int i = 0; i < data.length(); i++) - { - JSONObject rootGroup = data.getJSONObject(i); - if(rootGroup.getString("shortName").equals(TEST_ROOTGROUP)) - { - // This is our test rootgroup - assertEquals("shortName wrong", TEST_ROOTGROUP, rootGroup.getString("shortName")); - assertEquals("displayName wrong", TEST_ROOTGROUP_DISPLAY_NAME, rootGroup.getString("displayName")); - assertEquals("authorityType wrong", "GROUP", rootGroup.getString("authorityType")); - gotRootGroup = true; - } - if(rootGroup.getString("shortName").equals(EMAIL_GROUP)) - { - gotEmailGroup = true; - } - } - assertTrue("root group not found", gotRootGroup); - assertTrue("email group not found", gotEmailGroup); - } - - - if(rootGroupName != null) - { - rootGroupName = authorityService.getName(AuthorityType.GROUP, TEST_ROOTGROUP); - } - - Set zones = authorityService.getAuthorityZones(rootGroupName); - assertTrue("root group is in APP.DEFAULT zone", zones.contains("APP.DEFAULT") ); - - /** - * Get all root groups in the application zone "APP.DEFAULT" - */ - { - Response response = sendRequest(new GetRequest(URL_ROOTGROUPS + "?zone=APP.DEFAULT"), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - //System.out.println(response.getContentAsString()); - JSONArray data = top.getJSONArray("data"); - - assertTrue(data.length() > 0); - - for(int i = 0; i < data.length(); i++) - { - JSONObject rootGroup = data.getJSONObject(i); - if(rootGroup.getString("shortName").equals(TEST_ROOTGROUP)) - { - // This is our test rootgroup - assertEquals("shortName wrong", TEST_ROOTGROUP, rootGroup.getString("shortName")); - assertEquals("displayName wrong", TEST_ROOTGROUP_DISPLAY_NAME, rootGroup.getString("displayName")); - assertEquals("authorityType wrong", "GROUP", rootGroup.getString("authorityType")); - } - } - } - - /** - * Get all root groups in the admin zone - */ - { - Response response = sendRequest(new GetRequest(URL_ROOTGROUPS + "?zone=AUTH.ALF"), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONArray data = top.getJSONArray("data"); - assertTrue(data.length() > 0); - - for(int i = 0; i < data.length(); i++) - { - JSONObject rootGroup = data.getJSONObject(i); - if(rootGroup.getString("shortName").equals(TEST_ROOTGROUP)) - { - // This is our test rootgroup - assertEquals("shortName wrong", TEST_ROOTGROUP, rootGroup.getString("shortName")); - assertEquals("displayName wrong", TEST_ROOTGROUP_DISPLAY_NAME, rootGroup.getString("displayName")); - assertEquals("authorityType wrong", "GROUP", rootGroup.getString("authorityType")); - } - } - } - - /** - * Negative test Get all root groups in the a zone that does not exist - */ - { - Response response = sendRequest(new GetRequest(URL_ROOTGROUPS + "?zone=WIBBLE"), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONArray data = top.getJSONArray("data"); - assertTrue(data.length() == 0); - // Should return no results - } - - } - - /** - * Detailed test of get group - */ - public void testGetGroup() throws Exception - { - createTestTree(); - - { - Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + ADMIN_GROUP), 200); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONObject data = top.getJSONObject("data"); - assertTrue(data.length() > 0); - } - - { - sendRequest(new GetRequest(URL_GROUPS + "/" + "crap"), Status.STATUS_NOT_FOUND); - } - - /** - * Get GROUP B - */ - { - Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPB), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONObject data = top.getJSONObject("data"); - assertTrue(data.length() > 0); - } - - /** - * Get GROUP E which is in a different zone - */ - { - Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPE), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONObject data = top.getJSONObject("data"); - assertTrue(data.length() > 0); - } - - } - - /** - * Detailed test of create root group - * Detailed test of delete root group - */ - public void testCreateRootGroup() throws Exception - { - String myGroupName = "GT_CRG"; - String myDisplayName = "GT_CRGDisplay"; - - /** - * Negative test - try to create a group without admin authority - */ - { - JSONObject newGroupJSON = new JSONObject(); - newGroupJSON.put("displayName", myDisplayName); - sendRequest(new PostRequest(URL_ROOTGROUPS + "/" + myGroupName, newGroupJSON.toString(), "application/json"), Status.STATUS_INTERNAL_SERVER_ERROR); - } - - - this.authenticationComponent.setSystemUserAsCurrentUser(); - - try - { - /** - * Create a root group - */ - { - JSONObject newGroupJSON = new JSONObject(); - newGroupJSON.put("displayName", myDisplayName); - Response response = sendRequest(new PostRequest(URL_ROOTGROUPS + "/" + myGroupName, newGroupJSON.toString(), "application/json"), Status.STATUS_CREATED); - JSONObject top = new JSONObject(response.getContentAsString()); - JSONObject rootGroup = top.getJSONObject("data"); - assertEquals("shortName wrong", myGroupName, rootGroup.getString("shortName")); - assertEquals("displayName wrong", myDisplayName, rootGroup.getString("displayName")); - } - - /** - * Negative test Create a root group that already exists - */ - { - JSONObject newGroupJSON = new JSONObject(); - newGroupJSON.put("displayName", myDisplayName); - sendRequest(new PostRequest(URL_ROOTGROUPS + "/" + myGroupName, newGroupJSON.toString(), "application/json"), Status.STATUS_BAD_REQUEST); - } - - /** - * Delete the root group - */ - sendRequest(new DeleteRequest(URL_ROOTGROUPS + "/" + myGroupName), Status.STATUS_OK); - - /** - * Attempt to delete the root group again - should fail - */ - sendRequest(new DeleteRequest(URL_ROOTGROUPS + "/" + myGroupName), Status.STATUS_NOT_FOUND); - - - } - finally - { - - /** - * Delete the root group - */ - sendRequest(new DeleteRequest(URL_ROOTGROUPS + "/" + myGroupName), 0); - } - } - - /** - * Detailed test of link group - */ - public void testLinkChild() throws Exception - { - String myRootGroup = "GT_LGROOT"; - - try - { - this.authenticationComponent.setSystemUserAsCurrentUser(); - sendRequest(new DeleteRequest(URL_ROOTGROUPS + "/" + myRootGroup), 0); - - String groupLinkFullName = ""; - { - Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_LINK), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONObject data = top.getJSONObject("data"); - assertTrue(data.length() > 0); - groupLinkFullName = data.getString("fullName"); - } - - /** - * Create a root group - */ - { - JSONObject newGroupJSON = new JSONObject(); - newGroupJSON.put("displayName", myRootGroup); - sendRequest(new PostRequest(URL_ROOTGROUPS + "/" + myRootGroup, newGroupJSON.toString(), "application/json"), Status.STATUS_CREATED); - } - - /** - * Link an existing group (GROUPB) to my root group. - */ - - /** - * Negative test Link Group B without administrator access. - */ - this.authenticationComponent.setCurrentUser(USER_ONE); - { - JSONObject newGroupJSON = new JSONObject(); - sendRequest(new PostRequest(URL_GROUPS + "/" + myRootGroup +"/children/" + groupLinkFullName, newGroupJSON.toString(), "application/json" ), Status.STATUS_INTERNAL_SERVER_ERROR); - } - - this.authenticationComponent.setSystemUserAsCurrentUser(); - - /** - * Link Group B - */ - { - JSONObject newGroupJSON = new JSONObject(); - Response response = sendRequest(new PostRequest(URL_GROUPS + "/" + myRootGroup +"/children/" + groupLinkFullName, newGroupJSON.toString(), "application/json" ), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONObject data = top.getJSONObject("data"); - } - - /** - * Link the group again - this fails - * - duplicate groups (children with the same name) are not allowed - */ - { - JSONObject newGroupJSON = new JSONObject(); - Response response = sendRequest(new PostRequest(URL_GROUPS + "/" + myRootGroup +"/children/" + groupLinkFullName, newGroupJSON.toString(), "application/json" ), Status.STATUS_INTERNAL_SERVER_ERROR); - } - - /** - * Get All Children of myGroup which are GROUPS - should find GROUP B - */ - { - logger.debug("Get child GROUPS of myRootGroup"); - Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + myRootGroup + "/children?authorityType=GROUP"), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONArray data = top.getJSONArray("data"); - assertTrue("no child groups of myGroup", data.length() == 1); - - JSONObject subGroup = data.getJSONObject(0); - assertEquals("shortName wrong", TEST_LINK, subGroup.getString("shortName")); - assertEquals("authorityType wrong", "GROUP", subGroup.getString("authorityType")); - } - - /** - * Now link in an existing user - */ - { - JSONObject newGroupJSON = new JSONObject(); - String userOneFullName = USER_ONE; - Response response = sendRequest(new PostRequest(URL_GROUPS + "/" + myRootGroup +"/children/" + userOneFullName, newGroupJSON.toString(), "application/json" ), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONObject data = top.getJSONObject("data"); - } - - /** - * Get All Children of myGroup which are USERS - should find USER ONE - */ - { - logger.debug("Get child USERS of myRootGroup"); - Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + myRootGroup + "/children?authorityType=USER"), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONArray data = top.getJSONArray("data"); - assertTrue("no child groups of myGroup", data.length() == 1); - - JSONObject subGroup = data.getJSONObject(0); - assertEquals("shortName wrong", USER_ONE, subGroup.getString("shortName")); - assertEquals("authorityType wrong", "USER", subGroup.getString("authorityType")); - } - - /** - * Unlink Group B - */ - { - logger.debug("Unlink Test Link"); - Response response = sendRequest(new DeleteRequest(URL_GROUPS + "/" + myRootGroup +"/children/" + groupLinkFullName ), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - - } - - /** - * Get All Children of myGroup which are GROUPS - should no longer find GROUP B - */ - { - logger.debug("Get child GROUPS of myRootGroup"); - Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + myRootGroup + "/children?authorityType=GROUP"), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONArray data = top.getJSONArray("data"); - //TODO TEST failing - - //assertTrue("group B not removed", data.length() == 0); - } - - /** - * Create a new group (BUFFY) - */ - String myNewGroup = "GROUP_BUFFY"; - { - // Delete incase it already exists from a previous test run - sendRequest(new DeleteRequest(URL_ROOTGROUPS + "/BUFFY"), 0); - - JSONObject newGroupJSON = new JSONObject(); - Response response = sendRequest(new PostRequest(URL_GROUPS + "/" + myRootGroup +"/children/" + myNewGroup, newGroupJSON.toString(), "application/json" ), Status.STATUS_CREATED); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONObject data = top.getJSONObject("data"); - assertEquals("shortName wrong", "BUFFY", data.getString("shortName")); - assertEquals("fullName wrong", myNewGroup, data.getString("fullName")); - assertEquals("authorityType wrong", "GROUP", data.getString("authorityType")); - } - - /** - * Get All Children of myGroup which are GROUPS - should find GROUP(BUFFY) - */ - { - logger.debug("Get child GROUPS of myRootGroup"); - Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + myRootGroup + "/children?authorityType=GROUP"), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONArray data = top.getJSONArray("data"); - for(int i = 0; i < data.length(); i++) - { - JSONObject rootGroup = data.getJSONObject(i); - if(rootGroup.getString("fullName").equals(myNewGroup)) - { - - } - } - - } - - /** - * Negative tests - */ - - } - finally - { - sendRequest(new DeleteRequest(URL_ROOTGROUPS + "/" + myRootGroup), 0); - } - } - - /** - * Detailed test of update group - * @throws Exception - */ - public void testUpdateGroup() throws Exception - { - String myGroupName = "GT_UG"; - String myDisplayName = "GT_UGDisplay"; - String myNewDisplayName = "GT_UGDisplayNew"; - - this.authenticationComponent.setSystemUserAsCurrentUser(); - - try - { - /** - * Create a root group - */ - { - JSONObject newGroupJSON = new JSONObject(); - newGroupJSON.put("displayName", myDisplayName); - sendRequest(new PostRequest(URL_ROOTGROUPS + "/" + myGroupName, newGroupJSON.toString(), "application/json"), Status.STATUS_CREATED); - } - - /** - * Now change its display name - */ - { - JSONObject newGroupJSON = new JSONObject(); - newGroupJSON.put("displayName", myNewDisplayName); - Response response = sendRequest(new PutRequest(URL_GROUPS + "/" + myGroupName, newGroupJSON.toString(), "application/json"), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONObject data = top.getJSONObject("data"); - assertTrue(data.length() > 0); - assertEquals("displayName wrong", myNewDisplayName, data.getString("displayName")); - - } - - /** - * Now get it and verify that the name has changed - */ - { - Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + myGroupName), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONObject data = top.getJSONObject("data"); - assertTrue(data.length() > 0); - assertEquals("displayName wrong", myNewDisplayName, data.getString("displayName")); - - } - - /** - * Negative test - */ - { - JSONObject newGroupJSON = new JSONObject(); - newGroupJSON.put("displayName", myNewDisplayName); - sendRequest(new PutRequest(URL_GROUPS + "/" + "rubbish", newGroupJSON.toString(), "application/json"), Status.STATUS_NOT_FOUND); - } - } - finally - { - sendRequest(new DeleteRequest(URL_ROOTGROUPS + "/" + myGroupName), 0); - } - } - - - /** - * Detailed test of search groups - *
  • if the optional includeInternal parameter is true then will include internal groups, otherwise internalGroups are not returned.
  • -
  • If the optional shortNameFilter parameter is set then returns those root groups with a partial match on shortName.
  • - */ - public void testSearchGroups() throws Exception - { - createTestTree(); - - // Search on partial short name - { - Response response = sendRequest(new GetRequest(URL_GROUPS + "?shortNameFilter=" + "ALFRESCO_ADMIN*"), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONArray data = top.getJSONArray("data"); - assertEquals("length not 1", 1, data.length()); - JSONObject authority = data.getJSONObject(0); + + private MutableAuthenticationService authenticationService; + private AuthorityService authorityService; + private AuthenticationComponent authenticationComponent; + private PersonService personService; + + private String ADMIN_GROUP = "ALFRESCO_ADMINISTRATORS"; + private String EMAIL_GROUP = "EMAIL_CONTRIBUTORS"; + private String TEST_ROOTGROUP = "GroupsTest_ROOT"; + private String TEST_GROUPA = "TestA"; + private String TEST_GROUPB = "TESTB"; + private String TEST_GROUPC = "TesTC"; + private String TEST_GROUPD = "TESTD"; + private String TEST_GROUPE = "TestE"; + private String TEST_GROUPF = "TestF"; + private String TEST_GROUPG = "TestG"; + private String TEST_LINK = "TESTLINK"; + private String TEST_ROOTGROUP_DISPLAY_NAME = "GROUPS_TESTROOTDisplayName"; + + private static final String USER_ONE = "GroupTestOne"; + private static final String USER_TWO = "GroupTestTwo"; + private static final String USER_THREE = "GroupTestThree"; + + private static final String URL_GROUPS = "/api/groups"; + private static final String URL_ROOTGROUPS = "/api/rootgroups"; + + /** + * Test Tree for all group tests + * + * TEST_ROOTGROUP + * GROUPA + * GROUPB + * GROUPD + * GROUPE (in Share Zone) + * USER_TWO + * USER_THREE + * GROUPC + * USER_TWO + * GROUPF + * GROUPD + * GROUPG + * GROUPD + */ + private synchronized String createTestTree() + { + if(rootGroupName == null) + { + rootGroupName = authorityService.getName(AuthorityType.GROUP, TEST_ROOTGROUP); + } + + Set shareZones = new HashSet(1, 1.0f); + shareZones.add(AuthorityService.ZONE_APP_SHARE); + + if(!authorityService.authorityExists(rootGroupName)) + { + AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); + + rootGroupName = authorityService.createAuthority(AuthorityType.GROUP, TEST_ROOTGROUP, TEST_ROOTGROUP_DISPLAY_NAME, authorityService.getDefaultZones()); + String groupA = authorityService.createAuthority(AuthorityType.GROUP, TEST_GROUPA, TEST_GROUPA, authorityService.getDefaultZones()); + authorityService.addAuthority(rootGroupName, groupA); + String groupB = authorityService.createAuthority(AuthorityType.GROUP, TEST_GROUPB, TEST_GROUPB,authorityService.getDefaultZones()); + authorityService.addAuthority(rootGroupName, groupB); + String groupD = authorityService.createAuthority(AuthorityType.GROUP, TEST_GROUPD, TEST_GROUPD, authorityService.getDefaultZones()); + String groupE = authorityService.createAuthority(AuthorityType.GROUP, TEST_GROUPE, TEST_GROUPE, shareZones); + authorityService.addAuthority(groupB, groupD); + authorityService.addAuthority(groupB, groupE); + authorityService.addAuthority(groupB, USER_TWO); + authorityService.addAuthority(groupB, USER_THREE); + String groupF = authorityService.createAuthority(AuthorityType.GROUP, TEST_GROUPF, TEST_GROUPF, authorityService.getDefaultZones()); + authorityService.addAuthority(rootGroupName, groupF); + authorityService.addAuthority(groupF, groupD); + String groupG = authorityService.createAuthority(AuthorityType.GROUP, TEST_GROUPG, TEST_GROUPG, authorityService.getDefaultZones()); + authorityService.addAuthority(rootGroupName, groupG); + authorityService.addAuthority(groupG, groupD); + + String groupC = authorityService.createAuthority(AuthorityType.GROUP, TEST_GROUPC, TEST_GROUPC,authorityService.getDefaultZones()); + authorityService.addAuthority(rootGroupName, groupC); + authorityService.addAuthority(groupC, USER_TWO); + + String link = authorityService.createAuthority(AuthorityType.GROUP, TEST_LINK, TEST_LINK, authorityService.getDefaultZones()); + authorityService.addAuthority(rootGroupName, link); + + this.authenticationComponent.setCurrentUser(USER_ONE); + } + + return rootGroupName; + + } + + private static String rootGroupName = null; + @Override + protected void setUp() throws Exception + { + super.setUp(); + + this.authenticationService = (MutableAuthenticationService)getServer().getApplicationContext().getBean("AuthenticationService"); + this.authenticationComponent = (AuthenticationComponent)getServer().getApplicationContext().getBean("authenticationComponent"); + this.personService = (PersonService)getServer().getApplicationContext().getBean("PersonService"); + this.authorityService = (AuthorityService)getServer().getApplicationContext().getBean("AuthorityService"); + + this.authenticationComponent.setSystemUserAsCurrentUser(); + + // Create users + createUser(USER_ONE); + createUser(USER_TWO); + createUser(USER_THREE); + + // Do tests as user one + this.authenticationComponent.setCurrentUser(USER_ONE); + } + + private void createUser(String userName) + { + if (this.authenticationService.authenticationExists(userName) == false) + { + this.authenticationService.createAuthentication(userName, "PWD".toCharArray()); + + PropertyMap ppOne = new PropertyMap(4); + ppOne.put(ContentModel.PROP_USERNAME, userName); + ppOne.put(ContentModel.PROP_FIRSTNAME, "firstName"); + ppOne.put(ContentModel.PROP_LASTNAME, "lastName"); + ppOne.put(ContentModel.PROP_EMAIL, "email@email.com"); + ppOne.put(ContentModel.PROP_JOBTITLE, "jobTitle"); + + this.personService.createPerson(ppOne); + } + } + + @Override + protected void tearDown() throws Exception + { + super.tearDown(); + this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName()); + } + + /** + * Detailed test of get root groups + */ + public void testGetRootGroup() throws Exception + { + createTestTree(); + + /** + * Get all root groups, regardless of zone, should be at least the ALFRESCO_ADMINISTRATORS, + * TEST_ROOTGROUP and EMAIL_CONTRIBUTORS groups + */ + { + Response response = sendRequest(new GetRequest(URL_ROOTGROUPS), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + //System.out.println(response.getContentAsString()); + JSONArray data = top.getJSONArray("data"); + assertTrue(data.length() >= 3); + boolean gotRootGroup = false; + boolean gotEmailGroup = false; + + + for(int i = 0; i < data.length(); i++) + { + JSONObject rootGroup = data.getJSONObject(i); + if(rootGroup.getString("shortName").equals(TEST_ROOTGROUP)) + { + // This is our test rootgroup + assertEquals("shortName wrong", TEST_ROOTGROUP, rootGroup.getString("shortName")); + assertEquals("displayName wrong", TEST_ROOTGROUP_DISPLAY_NAME, rootGroup.getString("displayName")); + assertEquals("authorityType wrong", "GROUP", rootGroup.getString("authorityType")); + gotRootGroup = true; + } + if(rootGroup.getString("shortName").equals(EMAIL_GROUP)) + { + gotEmailGroup = true; + } + } + assertTrue("root group not found", gotRootGroup); + assertTrue("email group not found", gotEmailGroup); + } + + + if(rootGroupName != null) + { + rootGroupName = authorityService.getName(AuthorityType.GROUP, TEST_ROOTGROUP); + } + + Set zones = authorityService.getAuthorityZones(rootGroupName); + assertTrue("root group is in APP.DEFAULT zone", zones.contains("APP.DEFAULT") ); + + /** + * Get all root groups in the application zone "APP.DEFAULT" + */ + { + Response response = sendRequest(new GetRequest(URL_ROOTGROUPS + "?zone=APP.DEFAULT"), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + //System.out.println(response.getContentAsString()); + JSONArray data = top.getJSONArray("data"); + + assertTrue(data.length() > 0); + + for(int i = 0; i < data.length(); i++) + { + JSONObject rootGroup = data.getJSONObject(i); + if(rootGroup.getString("shortName").equals(TEST_ROOTGROUP)) + { + // This is our test rootgroup + assertEquals("shortName wrong", TEST_ROOTGROUP, rootGroup.getString("shortName")); + assertEquals("displayName wrong", TEST_ROOTGROUP_DISPLAY_NAME, rootGroup.getString("displayName")); + assertEquals("authorityType wrong", "GROUP", rootGroup.getString("authorityType")); + } + } + } + + /** + * Get all root groups in the admin zone + */ + { + Response response = sendRequest(new GetRequest(URL_ROOTGROUPS + "?zone=AUTH.ALF"), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONArray data = top.getJSONArray("data"); + assertTrue(data.length() > 0); + + for(int i = 0; i < data.length(); i++) + { + JSONObject rootGroup = data.getJSONObject(i); + if(rootGroup.getString("shortName").equals(TEST_ROOTGROUP)) + { + // This is our test rootgroup + assertEquals("shortName wrong", TEST_ROOTGROUP, rootGroup.getString("shortName")); + assertEquals("displayName wrong", TEST_ROOTGROUP_DISPLAY_NAME, rootGroup.getString("displayName")); + assertEquals("authorityType wrong", "GROUP", rootGroup.getString("authorityType")); + } + } + } + + /** + * Negative test Get all root groups in the a zone that does not exist + */ + { + Response response = sendRequest(new GetRequest(URL_ROOTGROUPS + "?zone=WIBBLE"), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONArray data = top.getJSONArray("data"); + assertTrue(data.length() == 0); + // Should return no results + } + + } + + /** + * Detailed test of get group + */ + public void testGetGroup() throws Exception + { + createTestTree(); + + { + Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + ADMIN_GROUP), 200); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONObject data = top.getJSONObject("data"); + assertTrue(data.length() > 0); + } + + { + sendRequest(new GetRequest(URL_GROUPS + "/" + "crap"), Status.STATUS_NOT_FOUND); + } + + /** + * Get GROUP B + */ + { + Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPB), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONObject data = top.getJSONObject("data"); + assertTrue(data.length() > 0); + } + + /** + * Get GROUP E which is in a different zone + */ + { + Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPE), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONObject data = top.getJSONObject("data"); + assertTrue(data.length() > 0); + } + + } + + /** + * Detailed test of create root group + * Detailed test of delete root group + */ + public void testCreateRootGroup() throws Exception + { + String myGroupName = "GT_CRG"; + String myDisplayName = "GT_CRGDisplay"; + + /** + * Negative test - try to create a group without admin authority + */ + { + JSONObject newGroupJSON = new JSONObject(); + newGroupJSON.put("displayName", myDisplayName); + sendRequest(new PostRequest(URL_ROOTGROUPS + "/" + myGroupName, newGroupJSON.toString(), "application/json"), Status.STATUS_INTERNAL_SERVER_ERROR); + } + + + this.authenticationComponent.setSystemUserAsCurrentUser(); + + try + { + /** + * Create a root group + */ + { + JSONObject newGroupJSON = new JSONObject(); + newGroupJSON.put("displayName", myDisplayName); + Response response = sendRequest(new PostRequest(URL_ROOTGROUPS + "/" + myGroupName, newGroupJSON.toString(), "application/json"), Status.STATUS_CREATED); + JSONObject top = new JSONObject(response.getContentAsString()); + JSONObject rootGroup = top.getJSONObject("data"); + assertEquals("shortName wrong", myGroupName, rootGroup.getString("shortName")); + assertEquals("displayName wrong", myDisplayName, rootGroup.getString("displayName")); + } + + /** + * Negative test Create a root group that already exists + */ + { + JSONObject newGroupJSON = new JSONObject(); + newGroupJSON.put("displayName", myDisplayName); + sendRequest(new PostRequest(URL_ROOTGROUPS + "/" + myGroupName, newGroupJSON.toString(), "application/json"), Status.STATUS_BAD_REQUEST); + } + + /** + * Delete the root group + */ + sendRequest(new DeleteRequest(URL_ROOTGROUPS + "/" + myGroupName), Status.STATUS_OK); + + /** + * Attempt to delete the root group again - should fail + */ + sendRequest(new DeleteRequest(URL_ROOTGROUPS + "/" + myGroupName), Status.STATUS_NOT_FOUND); + + + } + finally + { + + /** + * Delete the root group + */ + sendRequest(new DeleteRequest(URL_ROOTGROUPS + "/" + myGroupName), 0); + } + } + + /** + * Detailed test of link group + */ + public void testLinkChild() throws Exception + { + String myRootGroup = "GT_LGROOT"; + + try + { + this.authenticationComponent.setSystemUserAsCurrentUser(); + sendRequest(new DeleteRequest(URL_ROOTGROUPS + "/" + myRootGroup), 0); + + String groupLinkFullName = ""; + { + Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_LINK), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONObject data = top.getJSONObject("data"); + assertTrue(data.length() > 0); + groupLinkFullName = data.getString("fullName"); + } + + /** + * Create a root group + */ + { + JSONObject newGroupJSON = new JSONObject(); + newGroupJSON.put("displayName", myRootGroup); + sendRequest(new PostRequest(URL_ROOTGROUPS + "/" + myRootGroup, newGroupJSON.toString(), "application/json"), Status.STATUS_CREATED); + } + + /** + * Link an existing group (GROUPB) to my root group. + */ + + /** + * Negative test Link Group B without administrator access. + */ + this.authenticationComponent.setCurrentUser(USER_ONE); + { + JSONObject newGroupJSON = new JSONObject(); + sendRequest(new PostRequest(URL_GROUPS + "/" + myRootGroup +"/children/" + groupLinkFullName, newGroupJSON.toString(), "application/json" ), Status.STATUS_INTERNAL_SERVER_ERROR); + } + + this.authenticationComponent.setSystemUserAsCurrentUser(); + + /** + * Link Group B + */ + { + JSONObject newGroupJSON = new JSONObject(); + Response response = sendRequest(new PostRequest(URL_GROUPS + "/" + myRootGroup +"/children/" + groupLinkFullName, newGroupJSON.toString(), "application/json" ), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONObject data = top.getJSONObject("data"); + } + + /** + * Link the group again - this fails + * - duplicate groups (children with the same name) are not allowed + */ + { + JSONObject newGroupJSON = new JSONObject(); + Response response = sendRequest(new PostRequest(URL_GROUPS + "/" + myRootGroup +"/children/" + groupLinkFullName, newGroupJSON.toString(), "application/json" ), Status.STATUS_INTERNAL_SERVER_ERROR); + } + + /** + * Get All Children of myGroup which are GROUPS - should find GROUP B + */ + { + logger.debug("Get child GROUPS of myRootGroup"); + Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + myRootGroup + "/children?authorityType=GROUP"), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONArray data = top.getJSONArray("data"); + assertTrue("no child groups of myGroup", data.length() == 1); + + JSONObject subGroup = data.getJSONObject(0); + assertEquals("shortName wrong", TEST_LINK, subGroup.getString("shortName")); + assertEquals("authorityType wrong", "GROUP", subGroup.getString("authorityType")); + } + + /** + * Now link in an existing user + */ + { + JSONObject newGroupJSON = new JSONObject(); + String userOneFullName = USER_ONE; + Response response = sendRequest(new PostRequest(URL_GROUPS + "/" + myRootGroup +"/children/" + userOneFullName, newGroupJSON.toString(), "application/json" ), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONObject data = top.getJSONObject("data"); + } + + /** + * Get All Children of myGroup which are USERS - should find USER ONE + */ + { + logger.debug("Get child USERS of myRootGroup"); + Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + myRootGroup + "/children?authorityType=USER"), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONArray data = top.getJSONArray("data"); + assertTrue("no child groups of myGroup", data.length() == 1); + + JSONObject subGroup = data.getJSONObject(0); + assertEquals("shortName wrong", USER_ONE, subGroup.getString("shortName")); + assertEquals("authorityType wrong", "USER", subGroup.getString("authorityType")); + } + + /** + * Unlink Group B + */ + { + logger.debug("Unlink Test Link"); + Response response = sendRequest(new DeleteRequest(URL_GROUPS + "/" + myRootGroup +"/children/" + groupLinkFullName ), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + + } + + /** + * Get All Children of myGroup which are GROUPS - should no longer find GROUP B + */ + { + logger.debug("Get child GROUPS of myRootGroup"); + Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + myRootGroup + "/children?authorityType=GROUP"), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONArray data = top.getJSONArray("data"); + //TODO TEST failing + + //assertTrue("group B not removed", data.length() == 0); + } + + /** + * Create a new group (BUFFY) + */ + String myNewGroup = "GROUP_BUFFY"; + { + // Delete incase it already exists from a previous test run + sendRequest(new DeleteRequest(URL_ROOTGROUPS + "/BUFFY"), 0); + + JSONObject newGroupJSON = new JSONObject(); + Response response = sendRequest(new PostRequest(URL_GROUPS + "/" + myRootGroup +"/children/" + myNewGroup, newGroupJSON.toString(), "application/json" ), Status.STATUS_CREATED); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONObject data = top.getJSONObject("data"); + assertEquals("shortName wrong", "BUFFY", data.getString("shortName")); + assertEquals("fullName wrong", myNewGroup, data.getString("fullName")); + assertEquals("authorityType wrong", "GROUP", data.getString("authorityType")); + } + + /** + * Get All Children of myGroup which are GROUPS - should find GROUP(BUFFY) + */ + { + logger.debug("Get child GROUPS of myRootGroup"); + Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + myRootGroup + "/children?authorityType=GROUP"), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONArray data = top.getJSONArray("data"); + for(int i = 0; i < data.length(); i++) + { + JSONObject rootGroup = data.getJSONObject(i); + if(rootGroup.getString("fullName").equals(myNewGroup)) + { + + } + } + + } + + /** + * Negative tests + */ + + } + finally + { + sendRequest(new DeleteRequest(URL_ROOTGROUPS + "/" + myRootGroup), 0); + } + } + + /** + * Detailed test of update group + * @throws Exception + */ + public void testUpdateGroup() throws Exception + { + String myGroupName = "GT_UG"; + String myDisplayName = "GT_UGDisplay"; + String myNewDisplayName = "GT_UGDisplayNew"; + + this.authenticationComponent.setSystemUserAsCurrentUser(); + + try + { + /** + * Create a root group + */ + { + JSONObject newGroupJSON = new JSONObject(); + newGroupJSON.put("displayName", myDisplayName); + sendRequest(new PostRequest(URL_ROOTGROUPS + "/" + myGroupName, newGroupJSON.toString(), "application/json"), Status.STATUS_CREATED); + } + + /** + * Now change its display name + */ + { + JSONObject newGroupJSON = new JSONObject(); + newGroupJSON.put("displayName", myNewDisplayName); + Response response = sendRequest(new PutRequest(URL_GROUPS + "/" + myGroupName, newGroupJSON.toString(), "application/json"), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONObject data = top.getJSONObject("data"); + assertTrue(data.length() > 0); + assertEquals("displayName wrong", myNewDisplayName, data.getString("displayName")); + + } + + /** + * Now get it and verify that the name has changed + */ + { + Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + myGroupName), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONObject data = top.getJSONObject("data"); + assertTrue(data.length() > 0); + assertEquals("displayName wrong", myNewDisplayName, data.getString("displayName")); + + } + + /** + * Negative test + */ + { + JSONObject newGroupJSON = new JSONObject(); + newGroupJSON.put("displayName", myNewDisplayName); + sendRequest(new PutRequest(URL_GROUPS + "/" + "rubbish", newGroupJSON.toString(), "application/json"), Status.STATUS_NOT_FOUND); + } + } + finally + { + sendRequest(new DeleteRequest(URL_ROOTGROUPS + "/" + myGroupName), 0); + } + } + + + /** + * Detailed test of search groups + *
  • if the optional includeInternal parameter is true then will include internal groups, otherwise internalGroups are not returned.
  • +
  • If the optional shortNameFilter parameter is set then returns those root groups with a partial match on shortName.
  • + */ + public void testSearchGroups() throws Exception + { + createTestTree(); + + // Search on partial short name + { + Response response = sendRequest(new GetRequest(URL_GROUPS + "?shortNameFilter=" + "ALFRESCO_ADMIN*"), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONArray data = top.getJSONArray("data"); + assertEquals("length not 1", 1, data.length()); + JSONObject authority = data.getJSONObject(0); assertEquals("", ADMIN_GROUP, authority.getString("shortName")); - } - - // Search on partial short name with a ? - { - Response response = sendRequest(new GetRequest(URL_GROUPS + "?shortNameFilter=" + "ALFRE?CO_ADMIN*"), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONArray data = top.getJSONArray("data"); - assertEquals("length not 1", 1, data.length()); - JSONObject authority = data.getJSONObject(0); + } + + // Search on partial short name with a ? + { + Response response = sendRequest(new GetRequest(URL_GROUPS + "?shortNameFilter=" + "ALFRE?CO_ADMIN*"), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONArray data = top.getJSONArray("data"); + assertEquals("length not 1", 1, data.length()); + JSONObject authority = data.getJSONObject(0); assertEquals("", ADMIN_GROUP, authority.getString("shortName")); - } - - // Negative test. - { - Response response = sendRequest(new GetRequest(URL_GROUPS + "?shortNameFilter=" + "XX?X"), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONArray data = top.getJSONArray("data"); - assertEquals("length not 0", 0, data.length()); - } - - // Search on full shortName + } + + // Negative test. + { + Response response = sendRequest(new GetRequest(URL_GROUPS + "?shortNameFilter=" + "XX?X"), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONArray data = top.getJSONArray("data"); + assertEquals("length not 0", 0, data.length()); + } + + // Search on full shortName { - Response response = sendRequest(new GetRequest(URL_GROUPS + "?shortNameFilter=" + ADMIN_GROUP), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONArray data = top.getJSONArray("data"); - assertEquals("length not 1", 1, data.length()); - JSONObject authority = data.getJSONObject(0); + Response response = sendRequest(new GetRequest(URL_GROUPS + "?shortNameFilter=" + ADMIN_GROUP), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONArray data = top.getJSONArray("data"); + assertEquals("length not 1", 1, data.length()); + JSONObject authority = data.getJSONObject(0); assertEquals("", ADMIN_GROUP, authority.getString("shortName")); } - - // Search on partial short name of a non root group - { - Response response = sendRequest(new GetRequest(URL_GROUPS + "?shortNameFilter=" + TEST_GROUPD ), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - //System.out.println(response.getContentAsString()); - JSONArray data = top.getJSONArray("data"); - assertEquals("length not 1", 1, data.length()); - JSONObject authority = data.getJSONObject(0); + + // Search on partial short name of a non root group + { + Response response = sendRequest(new GetRequest(URL_GROUPS + "?shortNameFilter=" + TEST_GROUPD ), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + //System.out.println(response.getContentAsString()); + JSONArray data = top.getJSONArray("data"); + assertEquals("length not 1", 1, data.length()); + JSONObject authority = data.getJSONObject(0); assertEquals("", TEST_GROUPD, authority.getString("shortName")); - } - - // Search on partial short name of a non root group in default zone - { - String url = URL_GROUPS + "?shortNameFilter=" + TEST_GROUPD + "& zone=" + AuthorityService.ZONE_APP_DEFAULT; - Response response = sendRequest(new GetRequest(url ), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - //System.out.println(response.getContentAsString()); - JSONArray data = top.getJSONArray("data"); - assertEquals("length not 1", 1, data.length()); - JSONObject authority = data.getJSONObject(0); + } + + // Search on partial short name of a non root group in default zone + { + String url = URL_GROUPS + "?shortNameFilter=" + TEST_GROUPD + "& zone=" + AuthorityService.ZONE_APP_DEFAULT; + Response response = sendRequest(new GetRequest(url ), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + //System.out.println(response.getContentAsString()); + JSONArray data = top.getJSONArray("data"); + assertEquals("length not 1", 1, data.length()); + JSONObject authority = data.getJSONObject(0); assertEquals("", TEST_GROUPD, authority.getString("shortName")); - } - - // Search for a group (which is not in the default zone) in all zones - { - Response response = sendRequest(new GetRequest(URL_GROUPS + "?shortNameFilter=" + TEST_GROUPE ), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - //System.out.println(response.getContentAsString()); - JSONArray data = top.getJSONArray("data"); - assertEquals("length not 1", 1, data.length()); - JSONObject authority = data.getJSONObject(0); + } + + // Search for a group (which is not in the default zone) in all zones + { + Response response = sendRequest(new GetRequest(URL_GROUPS + "?shortNameFilter=" + TEST_GROUPE ), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + //System.out.println(response.getContentAsString()); + JSONArray data = top.getJSONArray("data"); + assertEquals("length not 1", 1, data.length()); + JSONObject authority = data.getJSONObject(0); assertEquals("Group E not found", TEST_GROUPE, authority.getString("shortName")); - + // Double check group E is in the share zone Set zones = authorityService.getAuthorityZones(authority.getString("fullName")); assertTrue(zones.contains(AuthorityService.ZONE_APP_SHARE)); - } - + } + //TODO TEST Case failing ? // // Search for Group E in a specific zone (without name filter) @@ -778,248 +778,248 @@ public void testSearchGroups() throws Exception // JSONObject authority = data.getJSONObject(0); // assertEquals("", TEST_GROUPE, authority.getString("shortName")); // } - - // Search for a group in a specifc non default zone - { - Response response = sendRequest(new GetRequest(URL_GROUPS + "?shortNameFilter=" + TEST_GROUPE + "&zone=" + AuthorityService.ZONE_APP_SHARE), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); + + // Search for a group in a specifc non default zone + { + Response response = sendRequest(new GetRequest(URL_GROUPS + "?shortNameFilter=" + TEST_GROUPE + "&zone=" + AuthorityService.ZONE_APP_SHARE), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); // System.out.println(response.getContentAsString()); - JSONArray data = top.getJSONArray("data"); - assertEquals("Can't find Group E in Share zone", 1, data.length()); - JSONObject authority = data.getJSONObject(0); + JSONArray data = top.getJSONArray("data"); + assertEquals("Can't find Group E in Share zone", 1, data.length()); + JSONObject authority = data.getJSONObject(0); assertEquals("", TEST_GROUPE, authority.getString("shortName")); - } - - // Negative test Search for a group in a wrong zone - { - Response response = sendRequest(new GetRequest(URL_GROUPS + "?shortNameFilter=" + TEST_GROUPE + "&zone=" + "SOME.THING"), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); + } + + // Negative test Search for a group in a wrong zone + { + Response response = sendRequest(new GetRequest(URL_GROUPS + "?shortNameFilter=" + TEST_GROUPE + "&zone=" + "SOME.THING"), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); // System.out.println(response.getContentAsString()); - JSONArray data = top.getJSONArray("data"); - assertEquals("length not 0", 0, data.length()); - } - - - } - - public void testSearchGroupsPaging() throws Exception - { - createTestTree(); - - JSONArray data = getDataArray(URL_GROUPS + "?shortNameFilter=*"); - int defaultSize = data.length(); - String firstGroup = data.get(0).toString(); - - assertTrue("There should be at least 6 groups in default zone!", defaultSize > 5); - - // Test maxItems works - data = getDataArray(URL_GROUPS + "?shortNameFilter=*" +"&maxItems=3"); - assertEquals("There should only be 3 groups!", 3, data.length()); - assertEquals("The first group should be the same!!", firstGroup, data.get(0).toString()); - - // Test skipCount works - data = getDataArray(URL_GROUPS + "?shortNameFilter=*" + "&skipCount=2"); - assertEquals("The number of groups returned is wrong!", defaultSize-2, data.length()); - assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); - - // Test maxItems and skipCount - data = getDataArray(URL_GROUPS + "?shortNameFilter=*" +"&skipCount=2&maxItems=3"); - assertEquals("The number of groups returned is wrong!", 3, data.length()); - assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); - - // Test maxItems and skipCount when maxItems is too big. - // Shoudl return last 2 items. - int skipCount = defaultSize-2; - data = getDataArray(URL_GROUPS + "?shortNameFilter=*" + "&skipCount="+skipCount+"&maxItems=5"); - assertEquals("The number of groups returned is wrong!", 2, data.length()); - assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); - } - - public void testGetRootGroupsPaging() throws Exception - { - createTestTree(); - - JSONArray data = getDataArray(URL_ROOTGROUPS); - int defaultSize = data.length(); - String firstGroup = data.get(0).toString(); - - assertTrue("There should be at least 3 groups in default zone!", defaultSize > 2); - - // Test maxItems works - data = getDataArray(URL_ROOTGROUPS + "?maxItems=2"); - assertEquals("There should only be 2 groups!", 2, data.length()); - assertEquals("The first group should be the same!!", firstGroup, data.get(0).toString()); - - // Test skipCount works - data = getDataArray(URL_ROOTGROUPS + "?skipCount=1"); - assertEquals("The number of groups returned is wrong!", defaultSize-1, data.length()); - assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); - - // Test maxItems and skipCount - data = getDataArray(URL_ROOTGROUPS + "?skipCount=1&maxItems=2"); - assertEquals("The number of groups returned is wrong!", 2, data.length()); - assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); - - // Test maxItems and skipCount when maxItems is too big. - // Shoudl return last 2 items. - int skipCount = defaultSize-1; - data = getDataArray(URL_ROOTGROUPS + "?skipCount="+skipCount+"&maxItems=5"); - assertEquals("The number of groups returned is wrong!", 1, data.length()); - assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); - } - - public void testGetParentsPaging() throws Exception - { - createTestTree(); - - // Test for immediate parents - String baseUrl = URL_GROUPS + "/" + TEST_GROUPD + "/parents"; - - JSONArray data = getDataArray(baseUrl); - int defaultSize = data.length(); - String firstGroup = data.get(0).toString(); - - assertEquals("There should be at least 3 groups in default zone!", 3, defaultSize); - - // Test maxItems works - data = getDataArray(baseUrl +"?maxItems=2"); - assertEquals("There should only be 2 groups!", 2, data.length()); - assertEquals("The first group should be the same!!", firstGroup, data.get(0).toString()); - - // Test skipCount works - data = getDataArray(baseUrl + "?skipCount=1"); - assertEquals("The number of groups returned is wrong!", 2, data.length()); - assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); - - // Test maxItems and skipCount - data = getDataArray(baseUrl + "?skipCount=1&maxItems=1"); - assertEquals("The number of groups returned is wrong!", 1, data.length()); - assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); - - // Test maxItems and skipCount when maxItems is too big. - // Should return last 2 items. - data = getDataArray(baseUrl + "?skipCount=1&maxItems=5"); - assertEquals("The number of groups returned is wrong!", 2, data.length()); - assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); - - //Test for ALL parents - baseUrl = URL_GROUPS + "/" + TEST_GROUPD + "/parents?level=ALL"; - - data = getDataArray(baseUrl); - defaultSize = data.length(); - firstGroup = data.get(0).toString(); - - assertTrue("There should be at least 3 groups in default zone!", defaultSize > 2); - - // Test maxItems works - data = getDataArray(baseUrl +"&maxItems=2"); - assertEquals("There should only be 2 groups!", 2, data.length()); - assertEquals("The first group should be the same!!", firstGroup, data.get(0).toString()); - - // Test skipCount works - data = getDataArray(baseUrl + "&skipCount=1"); - assertEquals("The number of groups returned is wrong!", defaultSize-1, data.length()); - assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); - - // Test maxItems and skipCount - data = getDataArray(baseUrl + "&skipCount=1&maxItems=2"); - assertEquals("The number of groups returned is wrong!", 2, data.length()); - assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); - - // Test maxItems and skipCount when maxItems is too big. - // Shoudl return last 2 items. - int skipCount = defaultSize-2; - data = getDataArray(baseUrl + "&skipCount="+skipCount+"&maxItems=5"); - assertEquals("The number of groups returned is wrong!", 2, data.length()); - assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); - } - - public void testGetChildGroupsPaging() throws Exception - { - createTestTree(); - - // Test for immediate parents - String baseUrl = URL_GROUPS + "/" + TEST_ROOTGROUP + "/children?authorityType=GROUP"; - - JSONArray data = getDataArray(baseUrl); - int defaultSize = data.length(); - String firstGroup = data.get(0).toString(); - - assertEquals("There should be 6 groups in default zone!", 6, defaultSize); - - // Test maxItems works - data = getDataArray(baseUrl +"&maxItems=2"); - assertEquals("There should only be 3 groups!", 2, data.length()); - assertEquals("The first group should be the same!!", firstGroup, data.get(0).toString()); - - // Test skipCount works - data = getDataArray(baseUrl + "&skipCount=2"); - assertEquals("The number of groups returned is wrong!", 4, data.length()); - assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); - - // Test maxItems and skipCount - data = getDataArray(baseUrl + "&skipCount=2&maxItems=2"); - assertEquals("The number of groups returned is wrong!", 2, data.length()); - assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); - - // Test maxItems and skipCount when maxItems is too big. - // Shoudl return last 2 items. - data = getDataArray(baseUrl + "&skipCount=4&maxItems=5"); - assertEquals("The number of groups returned is wrong!", 2, data.length()); - assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); - } - - private JSONArray getDataArray(String url) throws IOException, JSONException, UnsupportedEncodingException - { - Response response = sendRequest(new GetRequest(url), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - JSONArray data = top.getJSONArray("data"); - return data; - } - /** - * Detailed test of get Parents - */ - public void testGetParents() throws Exception - { - createTestTree(); - - /** - * Get all parents for the root group ALFRESCO_ADMINISTRATORS groups which has no parents - */ - { - Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + ADMIN_GROUP + "/parents"), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONArray data = top.getJSONArray("data"); - // Top level group has no parents - assertTrue("top level group has no parents", data.length() == 0); - } - - /** - * Get GROUP B Which should be a child of TESTROOT - */ - { - Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPB + "/parents"), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONArray data = top.getJSONArray("data"); - assertTrue(data.length() > 0); - } - - /** - * Get GROUP D Which should be a child of GROUPB child of TESTROOT - */ - { - Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPD + "/parents?level=ALL"), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONArray data = top.getJSONArray("data"); - assertTrue(data.length() >= 2); - } - -// TODO parents script does not have zone parameter + JSONArray data = top.getJSONArray("data"); + assertEquals("length not 0", 0, data.length()); + } + + + } + + public void testSearchGroupsPaging() throws Exception + { + createTestTree(); + + JSONArray data = getDataArray(URL_GROUPS + "?shortNameFilter=*"); + int defaultSize = data.length(); + String firstGroup = data.get(0).toString(); + + assertTrue("There should be at least 6 groups in default zone!", defaultSize > 5); + + // Test maxItems works + data = getDataArray(URL_GROUPS + "?shortNameFilter=*" +"&maxItems=3"); + assertEquals("There should only be 3 groups!", 3, data.length()); + assertEquals("The first group should be the same!!", firstGroup, data.get(0).toString()); + + // Test skipCount works + data = getDataArray(URL_GROUPS + "?shortNameFilter=*" + "&skipCount=2"); + assertEquals("The number of groups returned is wrong!", defaultSize-2, data.length()); + assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); + + // Test maxItems and skipCount + data = getDataArray(URL_GROUPS + "?shortNameFilter=*" +"&skipCount=2&maxItems=3"); + assertEquals("The number of groups returned is wrong!", 3, data.length()); + assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); + + // Test maxItems and skipCount when maxItems is too big. + // Shoudl return last 2 items. + int skipCount = defaultSize-2; + data = getDataArray(URL_GROUPS + "?shortNameFilter=*" + "&skipCount="+skipCount+"&maxItems=5"); + assertEquals("The number of groups returned is wrong!", 2, data.length()); + assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); + } + + public void testGetRootGroupsPaging() throws Exception + { + createTestTree(); + + JSONArray data = getDataArray(URL_ROOTGROUPS); + int defaultSize = data.length(); + String firstGroup = data.get(0).toString(); + + assertTrue("There should be at least 3 groups in default zone!", defaultSize > 2); + + // Test maxItems works + data = getDataArray(URL_ROOTGROUPS + "?maxItems=2"); + assertEquals("There should only be 2 groups!", 2, data.length()); + assertEquals("The first group should be the same!!", firstGroup, data.get(0).toString()); + + // Test skipCount works + data = getDataArray(URL_ROOTGROUPS + "?skipCount=1"); + assertEquals("The number of groups returned is wrong!", defaultSize-1, data.length()); + assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); + + // Test maxItems and skipCount + data = getDataArray(URL_ROOTGROUPS + "?skipCount=1&maxItems=2"); + assertEquals("The number of groups returned is wrong!", 2, data.length()); + assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); + + // Test maxItems and skipCount when maxItems is too big. + // Shoudl return last 2 items. + int skipCount = defaultSize-1; + data = getDataArray(URL_ROOTGROUPS + "?skipCount="+skipCount+"&maxItems=5"); + assertEquals("The number of groups returned is wrong!", 1, data.length()); + assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); + } + + public void testGetParentsPaging() throws Exception + { + createTestTree(); + + // Test for immediate parents + String baseUrl = URL_GROUPS + "/" + TEST_GROUPD + "/parents"; + + JSONArray data = getDataArray(baseUrl); + int defaultSize = data.length(); + String firstGroup = data.get(0).toString(); + + assertEquals("There should be at least 3 groups in default zone!", 3, defaultSize); + + // Test maxItems works + data = getDataArray(baseUrl +"?maxItems=2"); + assertEquals("There should only be 2 groups!", 2, data.length()); + assertEquals("The first group should be the same!!", firstGroup, data.get(0).toString()); + + // Test skipCount works + data = getDataArray(baseUrl + "?skipCount=1"); + assertEquals("The number of groups returned is wrong!", 2, data.length()); + assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); + + // Test maxItems and skipCount + data = getDataArray(baseUrl + "?skipCount=1&maxItems=1"); + assertEquals("The number of groups returned is wrong!", 1, data.length()); + assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); + + // Test maxItems and skipCount when maxItems is too big. + // Should return last 2 items. + data = getDataArray(baseUrl + "?skipCount=1&maxItems=5"); + assertEquals("The number of groups returned is wrong!", 2, data.length()); + assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); + + //Test for ALL parents + baseUrl = URL_GROUPS + "/" + TEST_GROUPD + "/parents?level=ALL"; + + data = getDataArray(baseUrl); + defaultSize = data.length(); + firstGroup = data.get(0).toString(); + + assertTrue("There should be at least 3 groups in default zone!", defaultSize > 2); + + // Test maxItems works + data = getDataArray(baseUrl +"&maxItems=2"); + assertEquals("There should only be 2 groups!", 2, data.length()); + assertEquals("The first group should be the same!!", firstGroup, data.get(0).toString()); + + // Test skipCount works + data = getDataArray(baseUrl + "&skipCount=1"); + assertEquals("The number of groups returned is wrong!", defaultSize-1, data.length()); + assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); + + // Test maxItems and skipCount + data = getDataArray(baseUrl + "&skipCount=1&maxItems=2"); + assertEquals("The number of groups returned is wrong!", 2, data.length()); + assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); + + // Test maxItems and skipCount when maxItems is too big. + // Shoudl return last 2 items. + int skipCount = defaultSize-2; + data = getDataArray(baseUrl + "&skipCount="+skipCount+"&maxItems=5"); + assertEquals("The number of groups returned is wrong!", 2, data.length()); + assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); + } + + public void testGetChildGroupsPaging() throws Exception + { + createTestTree(); + + // Test for immediate parents + String baseUrl = URL_GROUPS + "/" + TEST_ROOTGROUP + "/children?authorityType=GROUP"; + + JSONArray data = getDataArray(baseUrl); + int defaultSize = data.length(); + String firstGroup = data.get(0).toString(); + + assertEquals("There should be 6 groups in default zone!", 6, defaultSize); + + // Test maxItems works + data = getDataArray(baseUrl +"&maxItems=2"); + assertEquals("There should only be 3 groups!", 2, data.length()); + assertEquals("The first group should be the same!!", firstGroup, data.get(0).toString()); + + // Test skipCount works + data = getDataArray(baseUrl + "&skipCount=2"); + assertEquals("The number of groups returned is wrong!", 4, data.length()); + assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); + + // Test maxItems and skipCount + data = getDataArray(baseUrl + "&skipCount=2&maxItems=2"); + assertEquals("The number of groups returned is wrong!", 2, data.length()); + assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); + + // Test maxItems and skipCount when maxItems is too big. + // Shoudl return last 2 items. + data = getDataArray(baseUrl + "&skipCount=4&maxItems=5"); + assertEquals("The number of groups returned is wrong!", 2, data.length()); + assertFalse("The first group should not be the same!!", firstGroup.equals(data.get(0).toString())); + } + + private JSONArray getDataArray(String url) throws IOException, JSONException, UnsupportedEncodingException + { + Response response = sendRequest(new GetRequest(url), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + JSONArray data = top.getJSONArray("data"); + return data; + } + /** + * Detailed test of get Parents + */ + public void testGetParents() throws Exception + { + createTestTree(); + + /** + * Get all parents for the root group ALFRESCO_ADMINISTRATORS groups which has no parents + */ + { + Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + ADMIN_GROUP + "/parents"), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONArray data = top.getJSONArray("data"); + // Top level group has no parents + assertTrue("top level group has no parents", data.length() == 0); + } + + /** + * Get GROUP B Which should be a child of TESTROOT + */ + { + Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPB + "/parents"), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONArray data = top.getJSONArray("data"); + assertTrue(data.length() > 0); + } + + /** + * Get GROUP D Which should be a child of GROUPB child of TESTROOT + */ + { + Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPD + "/parents?level=ALL"), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONArray data = top.getJSONArray("data"); + assertTrue(data.length() >= 2); + } + +// TODO parents script does not have zone parameter // /** // * Get GROUP E Which should be a child of GROUPB child of TESTROOT but in a different zone // */ @@ -1030,142 +1030,142 @@ public void testGetParents() throws Exception // JSONArray data = top.getJSONArray("data"); // assertTrue(data.length() >= 2); // } - - /** - * Negative test Get GROUP D level="rubbish" - */ - { - sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPD + "/parents?level=rubbish"), Status.STATUS_BAD_REQUEST); - } - - /** - * Negative test GROUP(Rubbish) does not exist - */ - { - sendRequest(new GetRequest(URL_GROUPS + "/" + "rubbish" + "/parents?level=all"), Status.STATUS_NOT_FOUND); - - } - } - - /** - * Detailed test of get Children - */ - public void testGetChildren() throws Exception - { - createTestTree(); - - /** - * Get All Children of GROUP B - */ - { - logger.debug("Get all children of GROUP B"); - Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPB + "/children"), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONArray data = top.getJSONArray("data"); - assertTrue(data.length() > 0); - boolean gotGroupD = false; - boolean gotGroupE = false; - boolean gotUserTwo = false; - boolean gotUserThree = false; - for(int i = 0; i < data.length(); i++) - { - JSONObject authority = data.getJSONObject(i); - if(authority.getString("shortName").equals(TEST_GROUPD)) - { - gotGroupD = true; - } - if(authority.getString("shortName").equals(TEST_GROUPE)) - { - gotGroupE = true; - } - if(authority.getString("shortName").equals(USER_TWO)) - { - gotUserTwo = true; - } - if(authority.getString("shortName").equals(USER_THREE)) - { - gotUserThree = true; - } - } - assertEquals("4 groups not returned", 4, data.length()); - assertTrue("not got group D", gotGroupD); - assertTrue("not got group E", gotGroupE); - assertTrue("not got user two", gotUserTwo); - assertTrue("not got user three", gotUserThree); - - } - - /** - * Get All Children of GROUP B which are GROUPS - */ - { - logger.debug("Get child GROUPS of GROUP B"); - Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPB + "/children?authorityType=GROUP"), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONArray data = top.getJSONArray("data"); - assertTrue("no child groups of group B", data.length() > 1 ); - - boolean gotGroupD = false; - boolean gotGroupE = false; - JSONObject subGroup = data.getJSONObject(0); - for(int i = 0; i < data.length(); i++) - { - JSONObject authority = data.getJSONObject(i); - if(authority.getString("shortName").equals(TEST_GROUPD)) - { - gotGroupD = true; - } - else if(authority.getString("shortName").equals(TEST_GROUPE)) - { - gotGroupE = true; - } - else - { - fail("unexpected authority returned:" + authority.getString("shortName")); - } - } - assertTrue("not got group D", gotGroupD); - assertTrue("not got group E", gotGroupE); - - assertEquals("authorityType wrong", "GROUP", subGroup.getString("authorityType")); - for(int i = 0; i < data.length(); i++) - { - JSONObject authority = data.getJSONObject(i); - assertEquals("authorityType wrong", "GROUP", authority.getString("authorityType")); - } - } - - /** - * Get All Children of GROUP B which are USERS - */ - { - logger.debug("Get Child Users of Group B"); - Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPB + "/children?authorityType=USER"), Status.STATUS_OK); - JSONObject top = new JSONObject(response.getContentAsString()); - logger.debug(response.getContentAsString()); - JSONArray data = top.getJSONArray("data"); - assertTrue(data.length() > 1); - for(int i = 0; i < data.length(); i++) - { - JSONObject authority = data.getJSONObject(i); - assertEquals("authorityType wrong", "USER", authority.getString("authorityType")); - } - } - - /** - * Negative test All Children of GROUP B, bad authorityType - */ - { - sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPB + "/children?authorityType=XXX"), Status.STATUS_BAD_REQUEST); - } - - /** - * Negative test GROUP(Rubbish) does not exist - */ - { - sendRequest(new GetRequest(URL_GROUPS + "/" + "rubbish" + "/children"), Status.STATUS_NOT_FOUND); - } - } -} \ No newline at end of file + + /** + * Negative test Get GROUP D level="rubbish" + */ + { + sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPD + "/parents?level=rubbish"), Status.STATUS_BAD_REQUEST); + } + + /** + * Negative test GROUP(Rubbish) does not exist + */ + { + sendRequest(new GetRequest(URL_GROUPS + "/" + "rubbish" + "/parents?level=all"), Status.STATUS_NOT_FOUND); + + } + } + + /** + * Detailed test of get Children + */ + public void testGetChildren() throws Exception + { + createTestTree(); + + /** + * Get All Children of GROUP B + */ + { + logger.debug("Get all children of GROUP B"); + Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPB + "/children"), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONArray data = top.getJSONArray("data"); + assertTrue(data.length() > 0); + boolean gotGroupD = false; + boolean gotGroupE = false; + boolean gotUserTwo = false; + boolean gotUserThree = false; + for(int i = 0; i < data.length(); i++) + { + JSONObject authority = data.getJSONObject(i); + if(authority.getString("shortName").equals(TEST_GROUPD)) + { + gotGroupD = true; + } + if(authority.getString("shortName").equals(TEST_GROUPE)) + { + gotGroupE = true; + } + if(authority.getString("shortName").equals(USER_TWO)) + { + gotUserTwo = true; + } + if(authority.getString("shortName").equals(USER_THREE)) + { + gotUserThree = true; + } + } + assertEquals("4 groups not returned", 4, data.length()); + assertTrue("not got group D", gotGroupD); + assertTrue("not got group E", gotGroupE); + assertTrue("not got user two", gotUserTwo); + assertTrue("not got user three", gotUserThree); + + } + + /** + * Get All Children of GROUP B which are GROUPS + */ + { + logger.debug("Get child GROUPS of GROUP B"); + Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPB + "/children?authorityType=GROUP"), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONArray data = top.getJSONArray("data"); + assertTrue("no child groups of group B", data.length() > 1 ); + + boolean gotGroupD = false; + boolean gotGroupE = false; + JSONObject subGroup = data.getJSONObject(0); + for(int i = 0; i < data.length(); i++) + { + JSONObject authority = data.getJSONObject(i); + if(authority.getString("shortName").equals(TEST_GROUPD)) + { + gotGroupD = true; + } + else if(authority.getString("shortName").equals(TEST_GROUPE)) + { + gotGroupE = true; + } + else + { + fail("unexpected authority returned:" + authority.getString("shortName")); + } + } + assertTrue("not got group D", gotGroupD); + assertTrue("not got group E", gotGroupE); + + assertEquals("authorityType wrong", "GROUP", subGroup.getString("authorityType")); + for(int i = 0; i < data.length(); i++) + { + JSONObject authority = data.getJSONObject(i); + assertEquals("authorityType wrong", "GROUP", authority.getString("authorityType")); + } + } + + /** + * Get All Children of GROUP B which are USERS + */ + { + logger.debug("Get Child Users of Group B"); + Response response = sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPB + "/children?authorityType=USER"), Status.STATUS_OK); + JSONObject top = new JSONObject(response.getContentAsString()); + logger.debug(response.getContentAsString()); + JSONArray data = top.getJSONArray("data"); + assertTrue(data.length() > 1); + for(int i = 0; i < data.length(); i++) + { + JSONObject authority = data.getJSONObject(i); + assertEquals("authorityType wrong", "USER", authority.getString("authorityType")); + } + } + + /** + * Negative test All Children of GROUP B, bad authorityType + */ + { + sendRequest(new GetRequest(URL_GROUPS + "/" + TEST_GROUPB + "/children?authorityType=XXX"), Status.STATUS_BAD_REQUEST); + } + + /** + * Negative test GROUP(Rubbish) does not exist + */ + { + sendRequest(new GetRequest(URL_GROUPS + "/" + "rubbish" + "/children"), Status.STATUS_NOT_FOUND); + } + } +} diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/GroupsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/GroupsTest.java index 29a5ed46b75..4d28bb07e61 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/GroupsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/GroupsTest.java @@ -51,7 +51,11 @@ import jakarta.servlet.http.HttpServletResponse; import java.util.*; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.when; /** @@ -67,13 +71,13 @@ public class GroupsTest extends AbstractSingleNetworkSiteTest protected AuthorityService authorityService; - private String rootGroupName = null; - private Group rootGroup = null; - private Group groupA = null; - private Group groupB = null; - private GroupMember groupMemberA = null; - private GroupMember groupMemberB = null; - private GroupMember personMember = null; + private String rootGroupName; + private Group rootGroup; + private Group groupA; + private Group groupB; + private GroupMember groupMemberA; + private GroupMember groupMemberB; + private GroupMember personMember; @Mock private ResultSetRow groupAResultSetRow; @Mock @@ -955,7 +959,7 @@ private void canGetGroupsForUserId() throws Exception expected.retainAll(respPostProcess.getList()); // If this assertion fails, then the tests aren't providing any value - change them! - assertTrue("List doesn't contain enough items for test to be conclusive.", expected.size() > 0); + assertTrue("List doesn't contain enough items for test to be conclusive.", !expected.isEmpty()); checkList(expected, respPostProcess.getPaging(), respPostProcess); } @@ -976,7 +980,7 @@ private void canGetGroupsForUserId() throws Exception expected.retainAll(respPostProcess.getList()); // If this assertion fails, then the tests aren't providing any value - change them! - assertTrue("List doesn't contain enough items for test to be conclusive.", expected.size() > 0); + assertTrue("List doesn't contain enough items for test to be conclusive.", !expected.isEmpty()); checkList(expected, respPostProcess.getPaging(), respPostProcess); } @@ -1153,7 +1157,6 @@ private void canGetGroupsForUserId() throws Exception // -ve test: invalid zones clause { - Paging paging = getPaging(0, Integer.MAX_VALUE); Map otherParams = new HashMap<>(); otherParams.put("include", org.alfresco.rest.api.Groups.PARAM_INCLUDE_ZONES); From 4f4f7cc02f2c37d6232652432f948f01eaf29d6e Mon Sep 17 00:00:00 2001 From: MichalKinas Date: Thu, 6 Jul 2023 21:56:16 +0200 Subject: [PATCH 11/24] ACS-5506 Tests cleanup --- .../org/alfresco/rest/groups/GroupsTests.java | 43 +++++++++++-------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java index dc109b8248a..e40f5a3cd8a 100644 --- a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java +++ b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java @@ -33,9 +33,12 @@ public void dataPreparation() throws Exception description = "Verify creation, listing, updating and deletion of groups.") public void createListUpdateAndDeleteGroup() { String groupName = "ZtestGroup" + UUID.randomUUID(); + String subGroupName = "ZtestSubgroup" + UUID.randomUUID(); String groupDescription = "ZtestGroup description" + UUID.randomUUID(); JsonObject groupBody = Json.createObjectBuilder().add("id", groupName).add("displayName", groupName).add("description", groupDescription).build(); + JsonObject subgroupBody = Json.createObjectBuilder().add("id", subGroupName).add("displayName", subGroupName).build(); String groupBodyCreate = groupBody.toString(); + String subgroupBodyCreate = subgroupBody.toString(); //GroupCreation: //-ve @@ -50,9 +53,20 @@ public void createListUpdateAndDeleteGroup() { .and().field("hasSubgroups").is(false); restClient.assertStatusCodeIs(HttpStatus.CREATED); + //AddChildGroup + restClient.authenticateUser(adminUser).withCoreAPI().usingParams("include=zones").usingGroups().createGroup(subgroupBodyCreate); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + + //LinkChildGroupToParent + JsonObject groupMembershipGroupBody = Json.createObjectBuilder().add("id", "GROUP_"+subGroupName).add("memberType", "GROUP").build(); + String groupMembershipGroupBodyCreate = groupMembershipGroupBody.toString(); + restClient.authenticateUser(adminUser).withCoreAPI().usingGroups().createGroupMembership("GROUP_"+groupName, groupMembershipGroupBodyCreate); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + //ListGroups: restClient.withCoreAPI().usingParams("orderBy=displayName DESC&maxItems=10").usingGroups().listGroups() .assertThat().entriesListContains("id", "GROUP_"+groupName) + .and().entriesListContains("id", "GROUP_"+subGroupName) .and().entriesListDoesNotContain("zones") .and().paginationField("maxItems").is("10"); restClient.assertStatusCodeIs(HttpStatus.OK); @@ -72,7 +86,17 @@ public void createListUpdateAndDeleteGroup() { .assertThat().field("id").is("GROUP_"+groupName) .and().field("zones").contains("APP.DEFAULT") .and().field("isRoot").is(true) - .and().field("hasSubgroups").is(false); + .and().field("hasSubgroups").is(true); + restClient.assertStatusCodeIs(HttpStatus.OK); + + //DeleteChildGroup: + restClient.authenticateUser(adminUser).withCoreAPI().usingGroups().deleteGroup("GROUP_"+subGroupName); + restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); + + //VerifyIfParentHasNoSubgroups: + restClient.withCoreAPI().usingParams("include=zones").usingGroups().getGroupDetail("GROUP_"+groupName) + .assertThat().field("id").is("GROUP_"+groupName) + .and().field("hasSubgroups").is(false); restClient.assertStatusCodeIs(HttpStatus.OK); //DeleteGroup: @@ -89,11 +113,8 @@ public void createListUpdateAndDeleteGroup() { description = "Verify creation, listing(only for person) and deletion of group memberships. ") public void createListDeleteGroupMembership() { String groupName = "ZtestGroup" + UUID.randomUUID(); - String subGroupName = "ZtestSubgroup" + UUID.randomUUID(); JsonObject groupBody = Json.createObjectBuilder().add("id", groupName).add("displayName", groupName).build(); - JsonObject subgroupBody = Json.createObjectBuilder().add("id", subGroupName).add("displayName", subGroupName).build(); String groupBodyCreate = groupBody.toString(); - String subgroupBodyCreate = subgroupBody.toString(); //GroupCreation: restClient.authenticateUser(adminUser).withCoreAPI().usingParams("include=zones").usingGroups().createGroup(groupBodyCreate); @@ -115,20 +136,6 @@ public void createListDeleteGroupMembership() { .assertThat().entriesListContains("id", "GROUP_"+groupName); restClient.assertStatusCodeIs(HttpStatus.OK); - //AddChildGroup - restClient.authenticateUser(adminUser).withCoreAPI().usingParams().usingGroups().createGroup(subgroupBodyCreate); - restClient.assertStatusCodeIs(HttpStatus.CREATED); - JsonObject groupMembershipGroupBody = Json.createObjectBuilder().add("id", "GROUP_"+subGroupName).add("memberType", "GROUP").build(); - String groupMembershipGroupBodyCreate = groupMembershipGroupBody.toString(); - restClient.authenticateUser(adminUser).withCoreAPI().usingGroups().createGroupMembership("GROUP_"+groupName, groupMembershipGroupBodyCreate); - restClient.assertStatusCodeIs(HttpStatus.CREATED); - - //CheckListDetails - restClient.withCoreAPI().usingParams("include=zones").usingGroups().getGroupDetail("GROUP_"+groupName) - .assertThat().field("id").is("GROUP_"+groupName) - .and().field("hasSubgroups").is(true); - restClient.assertStatusCodeIs(HttpStatus.OK); - //DeleteGroupMembership //-ve restClient.withCoreAPI().usingGroups().deleteGroupMembership("GROUP_"+groupName, userModel.getUsername()); From 925a4f4a6a225b659ebe58cbdbf321dcca89efdf Mon Sep 17 00:00:00 2001 From: MichalKinas Date: Fri, 7 Jul 2023 18:41:14 +0200 Subject: [PATCH 12/24] ACS-5506 Add properties to authority service --- .../alfresco/rest/api/impl/GroupsImpl.java | 34 +++++----- .../repo/security/authority/AuthorityDAO.java | 63 +++++++++++-------- .../security/authority/AuthorityDAOImpl.java | 29 +++++++-- .../authority/AuthorityServiceImpl.java | 24 ++++++- .../cmr/security/AuthorityService.java | 42 +++++++++++++ .../authority/AuthorityServiceTest.java | 60 +++++++++++++++++- 6 files changed, 202 insertions(+), 50 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java index 11939c55216..7c344cb5518 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java @@ -27,6 +27,7 @@ import static org.alfresco.repo.security.authentication.AuthenticationUtil.runAsSystem; +import java.io.Serializable; import java.text.Collator; import java.util.AbstractList; import java.util.ArrayList; @@ -40,6 +41,7 @@ import java.util.Set; import java.util.stream.Collectors; +import org.alfresco.model.ContentModel; import org.alfresco.query.CannedQueryPageDetails; import org.alfresco.query.EmptyPagingResults; import org.alfresco.query.PagingRequest; @@ -74,7 +76,6 @@ import org.alfresco.service.cmr.security.AuthorityService; import org.alfresco.service.cmr.security.AuthorityType; import org.alfresco.service.cmr.security.PermissionService; -import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; import org.alfresco.util.AlfrescoCollator; import org.alfresco.util.Pair; @@ -94,7 +95,6 @@ public class GroupsImpl implements Groups private static final String ZONE = "zone"; private static final String AUTHORITY_NAME = "authorityName"; private static final String ERR_MSG_MODIFY_FIXED_AUTHORITY = "Trying to modify a fixed authority"; - private static final QName PROP_DESCRIPTION = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "description"); private final static Map SORT_PARAMS_TO_NAMES; static @@ -158,7 +158,13 @@ public Group create(Group group, Parameters parameters) authorityDisplayName = group.getDisplayName(); } - String authority = authorityService.createAuthority(AuthorityType.GROUP, group.getId(), authorityDisplayName, authorityZones); + HashMap props = new HashMap<>(); + if (StringUtils.isNotEmpty(group.getDescription())) + { + props.put(ContentModel.PROP_DESCRIPTION, group.getDescription()); + } + + String authority = authorityService.createAuthority(AuthorityType.GROUP, group.getId(), authorityDisplayName, authorityZones, props); // Set a given child authority to be included by the given parent // authorities. @@ -167,12 +173,6 @@ public Group create(Group group, Parameters parameters) authorityService.addAuthority(group.getParentIds(), authority); } - if (group.getDescription() != null && !group.getDescription().isEmpty()) - { - NodeRef groupNodeRef = authorityService.getAuthorityNodeRef(authority); - nodeService.setProperty(groupNodeRef, PROP_DESCRIPTION, group.getDescription()); - } - return getGroup(authority, parameters); } @@ -190,10 +190,11 @@ public Group update(String groupId, Group group, Parameters parameters) handleAuthorityException(ae); } - if (group.getDescription() != null && !group.getDescription().isEmpty()) + if (StringUtils.isNotEmpty(group.getDescription())) { - NodeRef groupNodeRef = authorityService.getAuthorityNodeRef(authorityService.getName(AuthorityType.GROUP, groupId)); - nodeService.setProperty(groupNodeRef, PROP_DESCRIPTION, group.getDescription()); + HashMap props = new HashMap<>(); + props.put(ContentModel.PROP_DESCRIPTION, group.getDescription()); + authorityDAO.setAuthorityProperties(authorityService.getName(AuthorityType.GROUP, groupId), props); } return getGroup(groupId, parameters); @@ -615,9 +616,9 @@ private Group getGroup(AuthorityInfo authorityInfo, List includeParam, S group.setHasSubgroups(!authorityService.getContainedAuthorities(AuthorityType.GROUP, authorityInfo.getAuthorityName(), true).isEmpty()); NodeRef groupNodeRef = authorityService.getAuthorityNodeRef(authorityInfo.getAuthorityName()); - String description = nodeService.getProperty(groupNodeRef, PROP_DESCRIPTION) != null ? - nodeService.getProperty(groupNodeRef, PROP_DESCRIPTION).toString() : - ""; + String description = nodeService.getProperty(groupNodeRef, ContentModel.PROP_DESCRIPTION) != null ? + nodeService.getProperty(groupNodeRef, ContentModel.PROP_DESCRIPTION).toString() : + null; group.setDescription(description); // Optionally include @@ -886,8 +887,7 @@ public void deleteGroupMembership(String groupId, String groupMemberId) validateGroupMemberId(groupMemberId); // Verify if groupMemberId is member of groupId - AuthorityType authorityType = AuthorityType.getAuthorityType(groupMemberId); - Set parents = authorityService.getContainingAuthorities(authorityType, groupMemberId, true); + Set parents = authorityService.getContainingAuthorities(AuthorityType.GROUP, groupMemberId, true); if (!parents.contains(groupId)) { throw new NotFoundException(groupMemberId + " is not member of " + groupId); diff --git a/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityDAO.java b/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityDAO.java index 6404f6c255c..a6b685d6c57 100644 --- a/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityDAO.java +++ b/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityDAO.java @@ -1,31 +1,33 @@ -/* - * #%L - * Alfresco Repository - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - * Alfresco 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 3 of the License, or - * (at your option) any later version. - * - * Alfresco 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 Alfresco. If not, see . - * #L% - */ +/* + * #%L + * Alfresco Repository + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * Alfresco 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 3 of the License, or + * (at your option) any later version. + * + * Alfresco 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 Alfresco. If not, see . + * #L% + */ package org.alfresco.repo.security.authority; +import java.io.Serializable; import java.util.Collection; +import java.util.Map; import java.util.Set; import org.alfresco.model.ContentModel; @@ -34,6 +36,7 @@ import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.security.AuthorityType; import org.alfresco.service.cmr.security.AuthorityService.AuthorityFilter; +import org.alfresco.service.namespace.QName; public interface AuthorityDAO { @@ -61,6 +64,11 @@ public interface AuthorityDAO */ void createAuthority(String name, String authorityDisplayName, Set authorityZones); + /** + * Create an authority with properties. + */ + void createAuthority(String name, String authorityDisplayName, Set authorityZones, Map properties); + /** * Delete an authority. */ @@ -142,6 +150,11 @@ public interface AuthorityDAO * Set the display name for an authority */ void setAuthorityDisplayName(String authorityName, String authorityDisplayName); + + /** + * Set the properties for an authority + */ + void setAuthorityProperties(String authorityName, Map properties); /** * Get root authorities diff --git a/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityDAOImpl.java b/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityDAOImpl.java index f72f4b5177b..76259658368 100644 --- a/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityDAOImpl.java +++ b/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityDAOImpl.java @@ -92,6 +92,7 @@ import org.alfresco.util.SearchLanguageConversion; import org.alfresco.util.registry.NamedObjectRegistry; import org.apache.commons.codec.digest.DigestUtils; +import org.apache.commons.collections.MapUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.InitializingBean; @@ -378,27 +379,35 @@ public void addAuthority(Collection parentNames, String childName) } } - public void createAuthority(String name, String authorityDisplayName, Set authorityZones) + public void createAuthority(String name, String authorityDisplayName, Set authorityZones) { + createAuthority(name, authorityDisplayName, authorityZones, null); + } + + public void createAuthority(String name, String authorityDisplayName, Set authorityZones, Map properties) { - HashMap props = new HashMap(); + HashMap props = new HashMap<>(); /* MNT-11749 : Alfresco allows to create authorities with different char cases, but disallow duplicates */ props.put(ContentModel.PROP_NAME, DigestUtils.md5Hex(name)); props.put(ContentModel.PROP_AUTHORITY_NAME, name); props.put(ContentModel.PROP_AUTHORITY_DISPLAY_NAME, authorityDisplayName); + if (MapUtils.isNotEmpty(properties)) + { + props.putAll(properties); + } NodeRef childRef; NodeRef authorityContainerRef = getAuthorityContainer(); childRef = nodeService.createNode(authorityContainerRef, ContentModel.ASSOC_CHILDREN, QName.createQName("cm", name, namespacePrefixResolver), ContentModel.TYPE_AUTHORITY_CONTAINER, props).getChildRef(); if (authorityZones != null) { - Set zoneRefs = new HashSet(authorityZones.size() * 2); + Set zoneRefs = new HashSet<>(authorityZones.size() * 2); String currentUserDomain = tenantService.getCurrentUserDomain(); for (String authorityZone : authorityZones) { zoneRefs.add(getOrCreateZone(authorityZone)); - zoneAuthorityCache.remove(new Pair(currentUserDomain, authorityZone)); + zoneAuthorityCache.remove(new Pair<>(currentUserDomain, authorityZone)); } - zoneAuthorityCache.remove(new Pair(currentUserDomain, null)); + zoneAuthorityCache.remove(new Pair<>(currentUserDomain, null)); nodeService.addChild(zoneRefs, childRef, ContentModel.ASSOC_IN_ZONE, QName.createQName("cm", name, namespacePrefixResolver)); } authorityLookupCache.put(cacheKey(name), childRef); @@ -1434,6 +1443,16 @@ public void setAuthorityDisplayName(String authorityName, String authorityDispla } + public void setAuthorityProperties(String authorityName, Map properties) + { + NodeRef ref = getAuthorityOrNull(authorityName); + if (ref == null) + { + return; + } + properties.forEach((key, value) -> nodeService.setProperty(ref, key, value)); + } + public NodeRef getOrCreateZone(String zoneName) { return getOrCreateZone(zoneName, true); diff --git a/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityServiceImpl.java b/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityServiceImpl.java index 0d4ecf8e2ab..08a9a8d83c8 100644 --- a/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityServiceImpl.java +++ b/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityServiceImpl.java @@ -25,6 +25,7 @@ */ package org.alfresco.repo.security.authority; +import java.io.Serializable; import java.util.AbstractSet; import java.util.ArrayList; import java.util.Collection; @@ -32,6 +33,7 @@ import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.TreeSet; @@ -53,6 +55,7 @@ import org.alfresco.service.cmr.security.AuthorityType; import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.cmr.security.PersonService; +import org.alfresco.service.namespace.QName; import org.alfresco.util.Pair; import org.springframework.beans.factory.InitializingBean; import org.springframework.extensions.surf.util.ParameterCheck; @@ -543,6 +546,14 @@ public String createAuthority(AuthorityType type, String shortName) { return createAuthority(type, shortName, shortName, getDefaultZones()); } + + /** + * {@inheritDoc} + */ + public String createAuthority(AuthorityType type, String shortName, Map properties) + { + return createAuthority(type, shortName, shortName, getDefaultZones(), properties); + } /** * {@inheritDoc} @@ -643,12 +654,21 @@ public boolean authorityExists(String name) */ public String createAuthority(AuthorityType type, String shortName, String authorityDisplayName, Set authorityZones) + { + return createAuthority(type, shortName, authorityDisplayName, authorityZones, null); + } + + /** + * {@inheritDoc} + */ + public String createAuthority(AuthorityType type, String shortName, String authorityDisplayName, + Set authorityZones, Map properties) { checkTypeIsMutable(type); String name = getName(type, shortName); - authorityDAO.createAuthority(name, authorityDisplayName, authorityZones); - + authorityDAO.createAuthority(name, authorityDisplayName, authorityZones, properties); + return name; } diff --git a/repository/src/main/java/org/alfresco/service/cmr/security/AuthorityService.java b/repository/src/main/java/org/alfresco/service/cmr/security/AuthorityService.java index 50943025394..25b5c2a2946 100644 --- a/repository/src/main/java/org/alfresco/service/cmr/security/AuthorityService.java +++ b/repository/src/main/java/org/alfresco/service/cmr/security/AuthorityService.java @@ -25,7 +25,9 @@ */ package org.alfresco.service.cmr.security; +import java.io.Serializable; import java.util.Collection; +import java.util.Map; import java.util.Set; import org.alfresco.api.AlfrescoPublicApi; @@ -35,6 +37,7 @@ import org.alfresco.service.Auditable; import org.alfresco.service.NotAuditable; import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.namespace.QName; /** * The service that encapsulates authorities granted to users. @@ -225,6 +228,24 @@ public interface AuthorityService @Auditable(parameters = {"type", "shortName"}) public String createAuthority(AuthorityType type, String shortName); + /** + * Create an authority with properties. + * + * @param type - + * the type of the authority + * @param shortName - + * the short name of the authority to create + * this will also be set as the default display name for the authority + * + * @param properties - + * properties that will be added to authority + * + * @return the name of the authority (this will be the prefix, if any + * associated with the type appended with the short name) + */ + @Auditable(parameters = {"type", "shortName"}) + public String createAuthority(AuthorityType type, String shortName, Map properties); + /** * Create an authority with a display name and zone. * @@ -242,6 +263,27 @@ public interface AuthorityService @Auditable(parameters = {"type", "shortName", "authorityDisplayName", "authorityZones"}) public String createAuthority(AuthorityType type, String shortName, String authorityDisplayName, Set authorityZones); + /** + * Create an authority with a display name and zone. + * + * @param type + * the type of the authority + * @param shortName + * the short name of the authority to create + * @param authorityDisplayName + * the display name for the authority + * @param authorityZones + * identifier for external user registry owning the authority or null if not applicable + * + * @param properties - + * properties that will be added to authority + * + * @return the full name of the authority (this will be the prefix, if any associated with the type appended with + * the short name) + */ + @Auditable(parameters = {"type", "shortName", "authorityDisplayName", "authorityZones"}) + public String createAuthority(AuthorityType type, String shortName, String authorityDisplayName, Set authorityZones, Map properties); + /** * Set an authority to include another authority. For example, adding a * group to a group or adding a user to a group. diff --git a/repository/src/test/java/org/alfresco/repo/security/authority/AuthorityServiceTest.java b/repository/src/test/java/org/alfresco/repo/security/authority/AuthorityServiceTest.java index 8447461b9b4..5299932802a 100644 --- a/repository/src/test/java/org/alfresco/repo/security/authority/AuthorityServiceTest.java +++ b/repository/src/test/java/org/alfresco/repo/security/authority/AuthorityServiceTest.java @@ -581,6 +581,65 @@ public void testCreateGroupAuth() // Ignore since we where expecting this } } + + public void testCreateGroupAuthWithProperties() + { + String auth; + String groupName = "TESTGROUP"; + String prefixedGroupName = "GROUP_TESTGROUP"; + String description = "testDesc"; + String title = "testTitle"; + HashMap props = new HashMap<>(); + props.put(ContentModel.PROP_DESCRIPTION, description); + props.put(ContentModel.PROP_TITLE, title); + + // create authority with properties and default zones + auth = pubAuthorityService.createAuthority(AuthorityType.GROUP, groupName, props); + assertTrue(pubAuthorityService.authorityExists(prefixedGroupName)); + NodeRef nodeRef = pubAuthorityService.getAuthorityNodeRef(auth); + assertEquals(nodeService.getProperty(nodeRef, ContentModel.PROP_DESCRIPTION), description); + assertEquals(nodeService.getProperty(nodeRef, ContentModel.PROP_TITLE), title); + pubAuthorityService.deleteAuthority(auth); + + // create authority with zones and properties + Set zones = new HashSet<>(); + zones.add("Test1"); + zones.add("Test2"); + auth = pubAuthorityService.createAuthority(AuthorityType.GROUP, groupName, prefixedGroupName, zones, props); + assertTrue(pubAuthorityService.authorityExists(prefixedGroupName)); + nodeRef = pubAuthorityService.getAuthorityNodeRef(auth); + assertEquals(nodeService.getProperty(nodeRef, ContentModel.PROP_DESCRIPTION), description); + assertEquals(nodeService.getProperty(nodeRef, ContentModel.PROP_TITLE), title); + assertEquals(2, pubAuthorityService.getAuthorityZones(auth).size()); + pubAuthorityService.deleteAuthority(auth); + } + + public void testUpdateAuthorityProperties() + { + String auth; + String groupName = "TESTGROUP"; + String prefixedGroupName = "GROUP_TESTGROUP"; + String description = "testDesc"; + String title = "testTitle"; + HashMap props = new HashMap<>(); + props.put(ContentModel.PROP_DESCRIPTION, description); + props.put(ContentModel.PROP_TITLE, title); + + // create authority with properties + auth = pubAuthorityService.createAuthority(AuthorityType.GROUP, groupName, props); + assertTrue(pubAuthorityService.authorityExists(prefixedGroupName)); + + // update authority properties + String newDescription = "newTestDesc"; + String newTitle = "newTestTitle"; + props.put(ContentModel.PROP_DESCRIPTION, newDescription); + props.put(ContentModel.PROP_TITLE, newTitle); + authorityDAO.setAuthorityProperties(auth, props); + NodeRef nodeRef = pubAuthorityService.getAuthorityNodeRef(auth); + assertEquals(nodeService.getProperty(nodeRef, ContentModel.PROP_DESCRIPTION), newDescription); + assertEquals(nodeService.getProperty(nodeRef, ContentModel.PROP_TITLE), newTitle); + pubAuthorityService.deleteAuthority(auth); + } public void testCreateOwnerAuth() { @@ -1373,7 +1432,6 @@ private Map createDefaultProperties(String userName, String properties.put(ContentModel.PROP_ORGID, orgId); return properties; } - public void testAuthorityDisplayNames() { String authOne = pubAuthorityService.createAuthority(AuthorityType.GROUP, "One"); From 1f72faa90c51e7b82f937bea911c2c826524c40d Mon Sep 17 00:00:00 2001 From: MichalKinas Date: Wed, 17 Jan 2024 09:14:58 +0100 Subject: [PATCH 13/24] ACS-5506 Add proper exception handling --- .../alfresco/rest/api/impl/GroupsImpl.java | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java index 7c344cb5518..e657e443571 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java @@ -71,6 +71,7 @@ import org.alfresco.rest.framework.resource.parameters.where.QueryHelper; import org.alfresco.rest.workflow.api.impl.MapBasedQueryWalker; import org.alfresco.rest.workflow.api.impl.MapBasedQueryWalkerOrSupported; +import org.alfresco.service.cmr.repository.InvalidNodeRefException; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.security.AuthorityService; @@ -79,6 +80,7 @@ import org.alfresco.service.namespace.QName; import org.alfresco.util.AlfrescoCollator; import org.alfresco.util.Pair; +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.extensions.surf.util.I18NUtil; @@ -613,12 +615,26 @@ private Group getGroup(AuthorityInfo authorityInfo, List includeParam, S group.setDisplayName(authorityDisplayName); group.setIsRoot(isRootAuthority(rootAuthorities, authorityInfo.getAuthorityName())); - group.setHasSubgroups(!authorityService.getContainedAuthorities(AuthorityType.GROUP, authorityInfo.getAuthorityName(), true).isEmpty()); + + Set containedAuthorities; + try { + containedAuthorities = authorityService.getContainedAuthorities(AuthorityType.GROUP, authorityInfo.getAuthorityName(), true); + } catch (UnknownAuthorityException e) + { + containedAuthorities = Collections.emptySet(); + } + group.setHasSubgroups(CollectionUtils.isNotEmpty(containedAuthorities)); NodeRef groupNodeRef = authorityService.getAuthorityNodeRef(authorityInfo.getAuthorityName()); - String description = nodeService.getProperty(groupNodeRef, ContentModel.PROP_DESCRIPTION) != null ? - nodeService.getProperty(groupNodeRef, ContentModel.PROP_DESCRIPTION).toString() : - null; + String description; + try { + description = nodeService.getProperty(groupNodeRef, ContentModel.PROP_DESCRIPTION) != null ? + nodeService.getProperty(groupNodeRef, ContentModel.PROP_DESCRIPTION).toString() : + null; + } catch (InvalidNodeRefException e) + { + description = null; + } group.setDescription(description); // Optionally include From ecfeb77fb0136581f052c93e75da3035d9d2a00d Mon Sep 17 00:00:00 2001 From: MichalKinas Date: Wed, 17 Jan 2024 13:47:40 +0100 Subject: [PATCH 14/24] ACS-5506 Add PMD fixes --- .../java/org/alfresco/rest/api/impl/GroupsImpl.java | 12 +++++++----- .../main/java/org/alfresco/rest/api/model/Group.java | 2 +- .../repo/security/authority/AuthorityDAOImpl.java | 5 ++++- .../security/authority/AuthorityServiceImpl.java | 2 ++ .../service/cmr/security/AuthorityService.java | 4 ++-- .../security/authority/AuthorityServiceTest.java | 7 +++++-- 6 files changed, 21 insertions(+), 11 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java index e657e443571..92c1cf18180 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java @@ -160,7 +160,7 @@ public Group create(Group group, Parameters parameters) authorityDisplayName = group.getDisplayName(); } - HashMap props = new HashMap<>(); + Map props = new HashMap<>(); if (StringUtils.isNotEmpty(group.getDescription())) { props.put(ContentModel.PROP_DESCRIPTION, group.getDescription()); @@ -194,7 +194,7 @@ public Group update(String groupId, Group group, Parameters parameters) if (StringUtils.isNotEmpty(group.getDescription())) { - HashMap props = new HashMap<>(); + Map props = new HashMap<>(); props.put(ContentModel.PROP_DESCRIPTION, group.getDescription()); authorityDAO.setAuthorityProperties(authorityService.getName(AuthorityType.GROUP, groupId), props); } @@ -617,7 +617,8 @@ private Group getGroup(AuthorityInfo authorityInfo, List includeParam, S group.setIsRoot(isRootAuthority(rootAuthorities, authorityInfo.getAuthorityName())); Set containedAuthorities; - try { + try + { containedAuthorities = authorityService.getContainedAuthorities(AuthorityType.GROUP, authorityInfo.getAuthorityName(), true); } catch (UnknownAuthorityException e) { @@ -627,8 +628,9 @@ private Group getGroup(AuthorityInfo authorityInfo, List includeParam, S NodeRef groupNodeRef = authorityService.getAuthorityNodeRef(authorityInfo.getAuthorityName()); String description; - try { - description = nodeService.getProperty(groupNodeRef, ContentModel.PROP_DESCRIPTION) != null ? + try + { + description = groupNodeRef != null && nodeService.getProperty(groupNodeRef, ContentModel.PROP_DESCRIPTION) != null ? nodeService.getProperty(groupNodeRef, ContentModel.PROP_DESCRIPTION).toString() : null; } catch (InvalidNodeRefException e) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/model/Group.java b/remote-api/src/main/java/org/alfresco/rest/api/model/Group.java index 0eccdf856eb..87ae0095645 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/model/Group.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/model/Group.java @@ -181,6 +181,6 @@ public String toString() public boolean wasSet(String fieldName) { Boolean b = setFields.get(fieldName); - return b != null ? b : false; + return b != null && b; } } \ No newline at end of file diff --git a/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityDAOImpl.java b/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityDAOImpl.java index 76259658368..86c96957e8e 100644 --- a/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityDAOImpl.java +++ b/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityDAOImpl.java @@ -379,13 +379,15 @@ public void addAuthority(Collection parentNames, String childName) } } + @Override public void createAuthority(String name, String authorityDisplayName, Set authorityZones) { createAuthority(name, authorityDisplayName, authorityZones, null); } + @Override public void createAuthority(String name, String authorityDisplayName, Set authorityZones, Map properties) { - HashMap props = new HashMap<>(); + Map props = new HashMap<>(); /* MNT-11749 : Alfresco allows to create authorities with different char cases, but disallow duplicates */ props.put(ContentModel.PROP_NAME, DigestUtils.md5Hex(name)); props.put(ContentModel.PROP_AUTHORITY_NAME, name); @@ -1443,6 +1445,7 @@ public void setAuthorityDisplayName(String authorityName, String authorityDispla } + @Override public void setAuthorityProperties(String authorityName, Map properties) { NodeRef ref = getAuthorityOrNull(authorityName); diff --git a/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityServiceImpl.java b/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityServiceImpl.java index 08a9a8d83c8..8efd66b5079 100644 --- a/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityServiceImpl.java +++ b/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityServiceImpl.java @@ -550,6 +550,7 @@ public String createAuthority(AuthorityType type, String shortName) /** * {@inheritDoc} */ + @Override public String createAuthority(AuthorityType type, String shortName, Map properties) { return createAuthority(type, shortName, shortName, getDefaultZones(), properties); @@ -661,6 +662,7 @@ public String createAuthority(AuthorityType type, String shortName, String autho /** * {@inheritDoc} */ + @Override public String createAuthority(AuthorityType type, String shortName, String authorityDisplayName, Set authorityZones, Map properties) { diff --git a/repository/src/main/java/org/alfresco/service/cmr/security/AuthorityService.java b/repository/src/main/java/org/alfresco/service/cmr/security/AuthorityService.java index 25b5c2a2946..e1cd6ac1ff9 100644 --- a/repository/src/main/java/org/alfresco/service/cmr/security/AuthorityService.java +++ b/repository/src/main/java/org/alfresco/service/cmr/security/AuthorityService.java @@ -244,7 +244,7 @@ public interface AuthorityService * associated with the type appended with the short name) */ @Auditable(parameters = {"type", "shortName"}) - public String createAuthority(AuthorityType type, String shortName, Map properties); + String createAuthority(AuthorityType type, String shortName, Map properties); /** * Create an authority with a display name and zone. @@ -282,7 +282,7 @@ public interface AuthorityService * the short name) */ @Auditable(parameters = {"type", "shortName", "authorityDisplayName", "authorityZones"}) - public String createAuthority(AuthorityType type, String shortName, String authorityDisplayName, Set authorityZones, Map properties); + String createAuthority(AuthorityType type, String shortName, String authorityDisplayName, Set authorityZones, Map properties); /** * Set an authority to include another authority. For example, adding a diff --git a/repository/src/test/java/org/alfresco/repo/security/authority/AuthorityServiceTest.java b/repository/src/test/java/org/alfresco/repo/security/authority/AuthorityServiceTest.java index 5299932802a..2dc6af536f3 100644 --- a/repository/src/test/java/org/alfresco/repo/security/authority/AuthorityServiceTest.java +++ b/repository/src/test/java/org/alfresco/repo/security/authority/AuthorityServiceTest.java @@ -86,6 +86,7 @@ import org.alfresco.util.testing.category.LuceneTests; import org.alfresco.util.testing.category.RedundantTests; import org.junit.FixMethodOrder; +import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.runners.MethodSorters; import org.springframework.context.ApplicationContext; @@ -582,6 +583,7 @@ public void testCreateGroupAuth() } } + @Test public void testCreateGroupAuthWithProperties() { String auth; @@ -589,7 +591,7 @@ public void testCreateGroupAuthWithProperties() String prefixedGroupName = "GROUP_TESTGROUP"; String description = "testDesc"; String title = "testTitle"; - HashMap props = new HashMap<>(); + Map props = new HashMap<>(); props.put(ContentModel.PROP_DESCRIPTION, description); props.put(ContentModel.PROP_TITLE, title); @@ -614,6 +616,7 @@ public void testCreateGroupAuthWithProperties() pubAuthorityService.deleteAuthority(auth); } + @Test public void testUpdateAuthorityProperties() { String auth; @@ -621,7 +624,7 @@ public void testUpdateAuthorityProperties() String prefixedGroupName = "GROUP_TESTGROUP"; String description = "testDesc"; String title = "testTitle"; - HashMap props = new HashMap<>(); + Map props = new HashMap<>(); props.put(ContentModel.PROP_DESCRIPTION, description); props.put(ContentModel.PROP_TITLE, title); From d3c7342f057178848288f265091a60f23b02e101 Mon Sep 17 00:00:00 2001 From: MichalKinas Date: Wed, 31 Jan 2024 00:08:26 +0100 Subject: [PATCH 15/24] ACS-5506 Description handling rework --- .../org/alfresco/rest/groups/GroupsTests.java | 6 +- .../java/org/alfresco/rest/api/Groups.java | 2 + .../alfresco/rest/api/impl/GroupsImpl.java | 124 +++++++++--------- .../alfresco/public-rest-context.xml | 2 - .../alfresco/rest/api/tests/GroupsTest.java | 12 +- .../repo/security/authority/AuthorityDAO.java | 14 +- .../security/authority/AuthorityDAOImpl.java | 17 ++- .../security/authority/AuthorityInfo.java | 65 +++++---- .../authority/AuthorityServiceImpl.java | 23 ++++ .../cmr/security/AuthorityService.java | 25 +++- .../authority/AuthorityServiceTest.java | 43 +++--- 11 files changed, 201 insertions(+), 132 deletions(-) diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java index e40f5a3cd8a..75cecb45ff1 100644 --- a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java +++ b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java @@ -45,7 +45,7 @@ public void createListUpdateAndDeleteGroup() { restClient.authenticateUser(userModel).withCoreAPI().usingGroups().createGroup(groupBodyCreate); restClient.assertStatusCodeIs(HttpStatus.FORBIDDEN); //+ve - restClient.authenticateUser(adminUser).withCoreAPI().usingParams("include=zones").usingGroups().createGroup(groupBodyCreate) + restClient.authenticateUser(adminUser).withCoreAPI().usingParams("include=zones,hasSubgroups,description").usingGroups().createGroup(groupBodyCreate) .assertThat().field("zones").contains("APP.DEFAULT") .and().field("isRoot").is(true) .and().field("displayName").is(groupName) @@ -82,7 +82,7 @@ public void createListUpdateAndDeleteGroup() { restClient.assertStatusCodeIs(HttpStatus.OK); //GetGroupDetails: - restClient.withCoreAPI().usingParams("include=zones").usingGroups().getGroupDetail("GROUP_"+groupName) + restClient.withCoreAPI().usingParams("include=zones,hasSubgroups,description").usingGroups().getGroupDetail("GROUP_"+groupName) .assertThat().field("id").is("GROUP_"+groupName) .and().field("zones").contains("APP.DEFAULT") .and().field("isRoot").is(true) @@ -94,7 +94,7 @@ public void createListUpdateAndDeleteGroup() { restClient.assertStatusCodeIs(HttpStatus.NO_CONTENT); //VerifyIfParentHasNoSubgroups: - restClient.withCoreAPI().usingParams("include=zones").usingGroups().getGroupDetail("GROUP_"+groupName) + restClient.withCoreAPI().usingParams("include=zones,hasSubgroups").usingGroups().getGroupDetail("GROUP_"+groupName) .assertThat().field("id").is("GROUP_"+groupName) .and().field("hasSubgroups").is(false); restClient.assertStatusCodeIs(HttpStatus.OK); diff --git a/remote-api/src/main/java/org/alfresco/rest/api/Groups.java b/remote-api/src/main/java/org/alfresco/rest/api/Groups.java index 53eb2203875..58b6d13aa8e 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/Groups.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/Groups.java @@ -40,8 +40,10 @@ public interface Groups { String PARAM_ID = "id"; String PARAM_DISPLAY_NAME = "displayName"; + String PARAM_INCLUDE_DESCRIPTION = "description"; String PARAM_INCLUDE_PARENT_IDS = "parentIds"; String PARAM_INCLUDE_ZONES = "zones"; + String PARAM_INCLUDE_HAS_SUBGROUPS = "hasSubgroups"; String PARAM_IS_ROOT = "isRoot"; String PARAM_CASCADE = "cascade"; String PARAM_MEMBER_TYPE = "memberType"; diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java index 92c1cf18180..464d4ff5253 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java @@ -53,7 +53,6 @@ import org.alfresco.repo.security.authority.UnknownAuthorityException; import org.alfresco.rest.antlr.WhereClauseParser; import org.alfresco.rest.api.Groups; -import org.alfresco.rest.api.Nodes; import org.alfresco.rest.api.People; import org.alfresco.rest.api.model.Group; import org.alfresco.rest.api.model.GroupMember; @@ -71,9 +70,6 @@ import org.alfresco.rest.framework.resource.parameters.where.QueryHelper; import org.alfresco.rest.workflow.api.impl.MapBasedQueryWalker; import org.alfresco.rest.workflow.api.impl.MapBasedQueryWalkerOrSupported; -import org.alfresco.service.cmr.repository.InvalidNodeRefException; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.security.AuthorityService; import org.alfresco.service.cmr.security.AuthorityType; import org.alfresco.service.cmr.security.PermissionService; @@ -114,11 +110,9 @@ public class GroupsImpl implements Groups private final static Set LIST_GROUP_MEMBERS_QUERY_PROPERTIES = new HashSet<>(List.of(PARAM_MEMBER_TYPE)); protected AuthorityService authorityService; - protected NodeService nodeService; private AuthorityDAO authorityDAO; protected People people; - protected Nodes nodes; public AuthorityService getAuthorityService() { @@ -130,10 +124,6 @@ public void setAuthorityService(AuthorityService authorityService) this.authorityService = authorityService; } - public void setNodeService(NodeService nodeService) { - this.nodeService = nodeService; - } - public void setAuthorityDAO(AuthorityDAO authorityDAO) { this.authorityDAO = authorityDAO; @@ -144,10 +134,6 @@ public void setPeople(People people) this.people = people; } - public void setNodes(Nodes nodes) { - this.nodes = nodes; - } - public Group create(Group group, Parameters parameters) { validateGroup(group, false); @@ -185,29 +171,29 @@ public Group update(String groupId, Group group, Parameters parameters) try { - authorityService.setAuthorityDisplayName(groupId, group.getDisplayName()); + if (StringUtils.isNotEmpty(group.getDescription())) + { + authorityService.setAuthorityDisplayNameAndDescription(groupId, group.getDisplayName(), group.getDescription()); + } + else + { + authorityService.setAuthorityDisplayName(groupId, group.getDisplayName()); + } } catch (AuthorityException ae) { handleAuthorityException(ae); } - if (StringUtils.isNotEmpty(group.getDescription())) - { - Map props = new HashMap<>(); - props.put(ContentModel.PROP_DESCRIPTION, group.getDescription()); - authorityDAO.setAuthorityProperties(authorityService.getName(AuthorityType.GROUP, groupId), props); - } - return getGroup(groupId, parameters); } public Group getGroup(String groupId, Parameters parameters) throws EntityNotFoundException { - AuthorityInfo authorityInfo = getAuthorityInfo(groupId); + final List includeParam = parameters.getInclude(); + AuthorityInfo authorityInfo = getAuthorityInfo(groupId, includeParam.contains(PARAM_INCLUDE_DESCRIPTION)); final Set rootAuthorities = getAllRootAuthorities(AuthorityType.GROUP); - final List includeParam = parameters.getInclude(); return getGroup(authorityInfo, includeParam, rootAuthorities); } @@ -227,7 +213,7 @@ public CollectionWithPagingInfo getGroups(final Parameters parameters) PagingResults pagingResult; try { - pagingResult = getAuthoritiesInfo(authorityType, groupsFilters, rootAuthorities, sortProp, paging); + pagingResult = getAuthoritiesInfo(authorityType, groupsFilters, rootAuthorities, sortProp, paging, parameters.getInclude().contains(PARAM_INCLUDE_DESCRIPTION)); } catch (UnknownAuthorityException e) { @@ -367,7 +353,7 @@ public CollectionWithPagingInfo getGroupsByPersonId(String requestedPerso filter(a -> a.startsWith(AuthorityType.GROUP.getPrefixString())). filter(a -> isRootPredicate(finalIsRootParam, rootAuthorities, a)). filter(a -> zonePredicate(a, finalZoneFilter)). - map(this::getAuthorityInfo). + map(a -> getAuthorityInfo(a, includeParam.contains(PARAM_INCLUDE_DESCRIPTION))). sorted(new AuthorityInfoComparator(sortProp.getFirst(), sortProp.getSecond())). collect(Collectors.toList()); @@ -386,7 +372,7 @@ public CollectionWithPagingInfo getGroupsByPersonId(String requestedPerso } private PagingResults getAuthoritiesInfo(AuthorityType authorityType, GroupsFilter groupsFilter, Set rootAuthorities, - Pair sortProp, Paging paging) + Pair sortProp, Paging paging, boolean includeDescription) { Boolean isRootParam = groupsFilter.getIsRoot(); String zoneFilter = groupsFilter.getZoneFilter(); @@ -402,7 +388,7 @@ private PagingResults getAuthoritiesInfo(AuthorityType authorityT // Limit the post processing work by using the already loaded // list of root authorities. List authorities = rootAuthorities.stream(). - map(this::getAuthorityInfo). + map(auth -> getAuthorityInfo(auth, includeDescription)). filter(auth -> zonePredicate(auth.getAuthorityName(), zoneFilter)). filter(auth -> displayNamePredicate(auth.getAuthorityDisplayName(), displayNameFilter)). collect(Collectors.toList()); @@ -557,9 +543,9 @@ private Set getAllRootAuthorities(AuthorityType authorityType) * The authority name. * @return The authority info. */ - private AuthorityInfo getAuthorityInfo(String id) + private AuthorityInfo getAuthorityInfo(String id, boolean includeDescription) { - return getAuthorityInfo(id, false); + return getAuthorityInfo(id, includeDescription, false); } /** @@ -568,11 +554,13 @@ private AuthorityInfo getAuthorityInfo(String id) * * @param id * The authority name. + * @param includeDescription + * True if description should be loaded * @param defaultDisplayNameIfNull * True if we would like to get a default value (e.g. shortName of the authority) if the authority display name is null. * @return The authority info. */ - private AuthorityInfo getAuthorityInfo(String id, boolean defaultDisplayNameIfNull) + private AuthorityInfo getAuthorityInfo(String id, boolean includeDescription, boolean defaultDisplayNameIfNull) { if (id == null || id.isEmpty()) { @@ -585,9 +573,20 @@ private AuthorityInfo getAuthorityInfo(String id, boolean defaultDisplayNameIfNu throw new EntityNotFoundException(id); } - String authorityDisplayName = getAuthorityDisplayName(id, defaultDisplayNameIfNull); + String authorityDisplayName; + String description = null; - return new AuthorityInfo(null, authorityDisplayName, id); + if (includeDescription) + { + Pair displayNameAndDescription = getAuthorityDisplayNameAndDescription(id, defaultDisplayNameIfNull); + authorityDisplayName = displayNameAndDescription.getFirst(); + description = displayNameAndDescription.getSecond(); + } + else + { + authorityDisplayName = getAuthorityDisplayName(id, defaultDisplayNameIfNull); + } + return new AuthorityInfo(null, authorityDisplayName, id, description); } private String getAuthorityDisplayName(String id, boolean defaultDisplayNameIfNull) @@ -595,6 +594,11 @@ private String getAuthorityDisplayName(String id, boolean defaultDisplayNameIfNu return defaultDisplayNameIfNull ? authorityService.getAuthorityDisplayName(id) : authorityDAO.getAuthorityDisplayName(id); } + private Pair getAuthorityDisplayNameAndDescription(String id, boolean defaultDisplayNameIfNull) + { + return defaultDisplayNameIfNull ? authorityService.getAuthorityDisplayNameAndDescription(id) : authorityDAO.getAuthorityDisplayNameAndDescription(id); + } + private Group getGroup(AuthorityInfo authorityInfo, List includeParam, Set rootAuthorities) { if (authorityInfo == null) @@ -607,37 +611,24 @@ private Group getGroup(AuthorityInfo authorityInfo, List includeParam, S // REPO-1743 String authorityDisplayName = authorityInfo.getAuthorityDisplayName(); + String description = authorityInfo.getDescription(); if (authorityDisplayName == null || authorityDisplayName.isEmpty()) { - authorityDisplayName = authorityService.getAuthorityDisplayName(authorityInfo.getAuthorityName()); + if (includeParam != null && includeParam.contains(PARAM_INCLUDE_DESCRIPTION)) + { + Pair displayNameAndDescription = authorityService.getAuthorityDisplayNameAndDescription(authorityInfo.getAuthorityName()); + authorityDisplayName = displayNameAndDescription.getFirst(); + description = displayNameAndDescription.getSecond(); + } + else + { + authorityDisplayName = authorityService.getAuthorityDisplayName(authorityInfo.getAuthorityName()); + } } group.setDisplayName(authorityDisplayName); - - group.setIsRoot(isRootAuthority(rootAuthorities, authorityInfo.getAuthorityName())); - - Set containedAuthorities; - try - { - containedAuthorities = authorityService.getContainedAuthorities(AuthorityType.GROUP, authorityInfo.getAuthorityName(), true); - } catch (UnknownAuthorityException e) - { - containedAuthorities = Collections.emptySet(); - } - group.setHasSubgroups(CollectionUtils.isNotEmpty(containedAuthorities)); - - NodeRef groupNodeRef = authorityService.getAuthorityNodeRef(authorityInfo.getAuthorityName()); - String description; - try - { - description = groupNodeRef != null && nodeService.getProperty(groupNodeRef, ContentModel.PROP_DESCRIPTION) != null ? - nodeService.getProperty(groupNodeRef, ContentModel.PROP_DESCRIPTION).toString() : - null; - } catch (InvalidNodeRefException e) - { - description = null; - } group.setDescription(description); + group.setIsRoot(isRootAuthority(rootAuthorities, authorityInfo.getAuthorityName())); // Optionally include if (includeParam != null) @@ -660,6 +651,19 @@ private Group getGroup(AuthorityInfo authorityInfo, List includeParam, S Set authorityZones = authorityService.getAuthorityZones(authorityInfo.getAuthorityName()); group.setZones(authorityZones); } + + if (includeParam.contains(PARAM_INCLUDE_HAS_SUBGROUPS)) + { + Set containedAuthorities; + try + { + containedAuthorities = authorityService.getContainedAuthorities(AuthorityType.GROUP, authorityInfo.getAuthorityName(), true); + } catch (UnknownAuthorityException e) + { + containedAuthorities = Collections.emptySet(); + } + group.setHasSubgroups(CollectionUtils.isNotEmpty(containedAuthorities)); + } } return group; @@ -947,7 +951,7 @@ private PagingResults getAuthoritiesInfo(AuthorityType authorityT } List authorityInfoList = new ArrayList<>(authorities.size()); - authorityInfoList.addAll(authorities.stream().map(this::getAuthorityInfo).collect(Collectors.toList())); + authorityInfoList.addAll(authorities.stream().map(auth -> getAuthorityInfo(auth, false)).collect(Collectors.toList())); // Post process sorting - this should be moved to service // layer. It is done here because sorting is not supported at @@ -996,7 +1000,7 @@ private GroupMember getGroupMember(AuthorityInfo authorityInfo) private GroupMember getGroupMember(String authorityId) { - AuthorityInfo authorityInfo = getAuthorityInfo(authorityId); + AuthorityInfo authorityInfo = getAuthorityInfo(authorityId, false); return getGroupMember(authorityInfo); } diff --git a/remote-api/src/main/resources/alfresco/public-rest-context.xml b/remote-api/src/main/resources/alfresco/public-rest-context.xml index 8be6d2fa2c8..f5627ad8239 100644 --- a/remote-api/src/main/resources/alfresco/public-rest-context.xml +++ b/remote-api/src/main/resources/alfresco/public-rest-context.xml @@ -1693,8 +1693,6 @@ - -
    diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/GroupsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/GroupsTest.java index 4d28bb07e61..da3245ee3a8 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/GroupsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/GroupsTest.java @@ -68,6 +68,7 @@ public class GroupsTest extends AbstractSingleNetworkSiteTest private static final String MEMBER_TYPE_GROUP = "GROUP"; private static final String MEMBER_TYPE_PERSON = "PERSON"; private static final String GROUP_EVERYONE = "GROUP_EVERYONE"; + private static final String INCLUDE_DESCRIPTION_HAS_SUBGROUPS = "description,hasSubgroups"; protected AuthorityService authorityService; @@ -666,13 +667,13 @@ private void validateGroupDefaultFields(Group group, boolean ignoreOptionallyInc assertNotNull(group.getId()); assertNotNull(group.getDisplayName()); assertNotNull(group.getIsRoot()); - assertNotNull(group.getHasSubgroups()); if (!ignoreOptionallyIncluded) { // Optionally included. assertNull(group.getParentIds()); assertNull(group.getZones()); + assertNotNull(group.getHasSubgroups()); } } @@ -1420,12 +1421,12 @@ public void testCreateGroup() throws Exception setRequestContext(networkOne.getId(), networkAdmin, DEFAULT_ADMIN_PWD); Map otherParams = new HashMap<>(); - otherParams.put("include", org.alfresco.rest.api.Groups.PARAM_INCLUDE_PARENT_IDS); + otherParams.put("include", INCLUDE_DESCRIPTION_HAS_SUBGROUPS); Group group = generateGroup(); group.setDescription("testDesc"); - Group createdGroup01 = groupsProxy.createGroup(group, null, HttpServletResponse.SC_CREATED); + Group createdGroup01 = groupsProxy.createGroup(group, otherParams, HttpServletResponse.SC_CREATED); assertNotNull(createdGroup01); assertNotNull(createdGroup01.getId()); @@ -1440,6 +1441,7 @@ public void testCreateGroup() throws Exception Group subGroup01 = generateGroup(); subGroup01.setParentIds(subGroup01Parents); + otherParams.put("include", org.alfresco.rest.api.Groups.PARAM_INCLUDE_PARENT_IDS + "," + INCLUDE_DESCRIPTION_HAS_SUBGROUPS); Group createdSubGroup01 = groupsProxy.createGroup(subGroup01, otherParams, HttpServletResponse.SC_CREATED); assertNotNull(createdSubGroup01); assertNotNull(createdSubGroup01.getId()); @@ -1449,7 +1451,7 @@ public void testCreateGroup() throws Exception assertFalse(createdSubGroup01.getHasSubgroups()); //validate if parent group now has any subgroup - Group group01 = groupsProxy.getGroup(createdGroup01.getId(), null, HttpServletResponse.SC_OK); + Group group01 = groupsProxy.getGroup(createdGroup01.getId(), otherParams, HttpServletResponse.SC_OK); assertTrue(group01.getHasSubgroups()); } @@ -1623,7 +1625,7 @@ public void testUpdateGroup() throws Exception final Groups groupsProxy = publicApiClient.groups(); Map otherParams = new HashMap<>(); - otherParams.put("include", org.alfresco.rest.api.Groups.PARAM_INCLUDE_PARENT_IDS); + otherParams.put("include", org.alfresco.rest.api.Groups.PARAM_INCLUDE_PARENT_IDS + "," + org.alfresco.rest.api.Groups.PARAM_INCLUDE_DESCRIPTION); setRequestContext(networkOne.getId(), networkAdmin, DEFAULT_ADMIN_PWD); diff --git a/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityDAO.java b/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityDAO.java index a6b685d6c57..993a93b3a71 100644 --- a/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityDAO.java +++ b/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityDAO.java @@ -37,6 +37,7 @@ import org.alfresco.service.cmr.security.AuthorityType; import org.alfresco.service.cmr.security.AuthorityService.AuthorityFilter; import org.alfresco.service.namespace.QName; +import org.alfresco.util.Pair; public interface AuthorityDAO { @@ -152,10 +153,17 @@ public interface AuthorityDAO void setAuthorityDisplayName(String authorityName, String authorityDisplayName); /** - * Set the properties for an authority + * Get the display name and description for an authority + * + * @return the display name and description */ - void setAuthorityProperties(String authorityName, Map properties); - + Pair getAuthorityDisplayNameAndDescription(String authorityName); + + /** + * Set the display name and description for an authority + */ + void setAuthorityDisplayNameAndDescription(String authorityName, String authorityDisplayName, String description); + /** * Get root authorities */ diff --git a/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityDAOImpl.java b/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityDAOImpl.java index 86c96957e8e..085bcca96a3 100644 --- a/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityDAOImpl.java +++ b/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityDAOImpl.java @@ -1442,18 +1442,29 @@ public void setAuthorityDisplayName(String authorityName, String authorityDispla return; } nodeService.setProperty(ref, ContentModel.PROP_AUTHORITY_DISPLAY_NAME, authorityDisplayName); + } + public Pair getAuthorityDisplayNameAndDescription(String authorityName) + { + NodeRef ref = getAuthorityOrNull(authorityName); + if (ref == null) + { + return Pair.nullPair(); + } + Serializable displayName = nodeService.getProperty(ref, ContentModel.PROP_AUTHORITY_DISPLAY_NAME); + Serializable description = nodeService.getProperty(ref, ContentModel.PROP_DESCRIPTION); + return new Pair<>(DefaultTypeConverter.INSTANCE.convert(String.class, displayName), DefaultTypeConverter.INSTANCE.convert(String.class, description)); } - @Override - public void setAuthorityProperties(String authorityName, Map properties) + public void setAuthorityDisplayNameAndDescription(String authorityName, String authorityDisplayName, String description) { NodeRef ref = getAuthorityOrNull(authorityName); if (ref == null) { return; } - properties.forEach((key, value) -> nodeService.setProperty(ref, key, value)); + nodeService.setProperty(ref, ContentModel.PROP_AUTHORITY_DISPLAY_NAME, authorityDisplayName); + nodeService.setProperty(ref, ContentModel.PROP_DESCRIPTION, description); } public NodeRef getOrCreateZone(String zoneName) diff --git a/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityInfo.java b/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityInfo.java index 9d6729acc1d..cce5aa326b9 100644 --- a/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityInfo.java +++ b/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityInfo.java @@ -1,28 +1,28 @@ -/* - * #%L - * Alfresco Repository - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - * Alfresco 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 3 of the License, or - * (at your option) any later version. - * - * Alfresco 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 Alfresco. If not, see . - * #L% - */ +/* + * #%L + * Alfresco Repository + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * Alfresco 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 3 of the License, or + * (at your option) any later version. + * + * Alfresco 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 Alfresco. If not, see . + * #L% + */ package org.alfresco.repo.security.authority; import org.alfresco.api.AlfrescoPublicApi; @@ -39,15 +39,24 @@ public class AuthorityInfo { private Long nodeId; - private String authorityDisplayName; // eg. My Group, My Role private String authorityName; // eg. GROUP_my1, ROLE_myA + private String description; + public AuthorityInfo(Long nodeId, String authorityDisplayName, String authorityName, String description) + { + this.nodeId = nodeId; + this.authorityDisplayName = authorityDisplayName; + this.authorityName = authorityName; + this.description = description; + } + public AuthorityInfo(Long nodeId, String authorityDisplayName, String authorityName) { this.nodeId = nodeId; this.authorityDisplayName = authorityDisplayName; this.authorityName = authorityName; + this.description = null; } public Long getNodeId() @@ -65,6 +74,10 @@ public String getAuthorityName() return authorityName; } + public String getDescription() { + return description; + } + public String getShortName() { AuthorityType type = AuthorityType.getAuthorityType(authorityName); diff --git a/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityServiceImpl.java b/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityServiceImpl.java index 8efd66b5079..7923bcffe4a 100644 --- a/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityServiceImpl.java +++ b/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityServiceImpl.java @@ -696,6 +696,29 @@ public void setAuthorityDisplayName(String authorityName, String authorityDispla checkTypeIsMutable(type); authorityDAO.setAuthorityDisplayName(authorityName, authorityDisplayName); } + + /** + * {@inheritDoc} + */ + public Pair getAuthorityDisplayNameAndDescription(String name) + { + Pair displayNameAndDescription = authorityDAO.getAuthorityDisplayNameAndDescription(name); + if(displayNameAndDescription.getFirst() == null) + { + displayNameAndDescription.setFirst(getShortName(name)); + } + return displayNameAndDescription; + } + + /** + * {@inheritDoc} + */ + public void setAuthorityDisplayNameAndDescription(String authorityName, String authorityDisplayName, String description) + { + AuthorityType type = AuthorityType.getAuthorityType(authorityName); + checkTypeIsMutable(type); + authorityDAO.setAuthorityDisplayNameAndDescription(authorityName, authorityDisplayName, description); + } /** * {@inheritDoc} diff --git a/repository/src/main/java/org/alfresco/service/cmr/security/AuthorityService.java b/repository/src/main/java/org/alfresco/service/cmr/security/AuthorityService.java index e1cd6ac1ff9..65835cc45e8 100644 --- a/repository/src/main/java/org/alfresco/service/cmr/security/AuthorityService.java +++ b/repository/src/main/java/org/alfresco/service/cmr/security/AuthorityService.java @@ -38,6 +38,7 @@ import org.alfresco.service.NotAuditable; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.namespace.QName; +import org.alfresco.util.Pair; /** * The service that encapsulates authorities granted to users. @@ -441,7 +442,16 @@ public interface AuthorityFilter * @return - the display name */ @Auditable(parameters = {"name"}) - public String getAuthorityDisplayName(String name); + String getAuthorityDisplayName(String name); + + /** + * Get the display name and description for the given authority. + * + * @param name - the full authority string including any prefix (e.g. GROUP_woof) + * @return - pair containing display name and description + */ + @Auditable(parameters = {"name"}) + Pair getAuthorityDisplayNameAndDescription(String name); /** * Set the display name for the given authority. @@ -451,7 +461,18 @@ public interface AuthorityFilter * @param authorityDisplayName String */ @Auditable(parameters = {"authorityName", "authorityDisplayName"}) - public void setAuthorityDisplayName(String authorityName, String authorityDisplayName); + void setAuthorityDisplayName(String authorityName, String authorityDisplayName); + + /** + * Set the display name and description for the given authority. + * Setting the display name is only supported for authorities of type group + * + * @param authorityName String + * @param authorityDisplayName String + * @param description String + */ + @Auditable(parameters = {"authorityName", "authorityDisplayName", "description"}) + void setAuthorityDisplayNameAndDescription(String authorityName, String authorityDisplayName, String description); /** * Gets the authority node for the specified name diff --git a/repository/src/test/java/org/alfresco/repo/security/authority/AuthorityServiceTest.java b/repository/src/test/java/org/alfresco/repo/security/authority/AuthorityServiceTest.java index 2dc6af536f3..eb4753b0f97 100644 --- a/repository/src/test/java/org/alfresco/repo/security/authority/AuthorityServiceTest.java +++ b/repository/src/test/java/org/alfresco/repo/security/authority/AuthorityServiceTest.java @@ -83,6 +83,7 @@ import org.alfresco.service.transaction.TransactionService; import org.alfresco.test_category.OwnJVMTestsCategory; import org.alfresco.util.ApplicationContextHelper; +import org.alfresco.util.Pair; import org.alfresco.util.testing.category.LuceneTests; import org.alfresco.util.testing.category.RedundantTests; import org.junit.FixMethodOrder; @@ -616,34 +617,6 @@ public void testCreateGroupAuthWithProperties() pubAuthorityService.deleteAuthority(auth); } - @Test - public void testUpdateAuthorityProperties() - { - String auth; - String groupName = "TESTGROUP"; - String prefixedGroupName = "GROUP_TESTGROUP"; - String description = "testDesc"; - String title = "testTitle"; - Map props = new HashMap<>(); - props.put(ContentModel.PROP_DESCRIPTION, description); - props.put(ContentModel.PROP_TITLE, title); - - // create authority with properties - auth = pubAuthorityService.createAuthority(AuthorityType.GROUP, groupName, props); - assertTrue(pubAuthorityService.authorityExists(prefixedGroupName)); - - // update authority properties - String newDescription = "newTestDesc"; - String newTitle = "newTestTitle"; - props.put(ContentModel.PROP_DESCRIPTION, newDescription); - props.put(ContentModel.PROP_TITLE, newTitle); - authorityDAO.setAuthorityProperties(auth, props); - NodeRef nodeRef = pubAuthorityService.getAuthorityNodeRef(auth); - assertEquals(nodeService.getProperty(nodeRef, ContentModel.PROP_DESCRIPTION), newDescription); - assertEquals(nodeService.getProperty(nodeRef, ContentModel.PROP_TITLE), newTitle); - pubAuthorityService.deleteAuthority(auth); - } - public void testCreateOwnerAuth() { try @@ -1459,6 +1432,20 @@ public void testAuthorityDisplayNames() assertEquals(pubAuthorityService.getAuthorityDisplayName("ROLE_Gibbon"), "Gibbon"); assertEquals(pubAuthorityService.getAuthorityDisplayName("Monkey"), "Monkey"); } + + public void testAuthorityDisplayNameAndDescription() + { + Map props = new HashMap<>(); + props.put(ContentModel.PROP_DESCRIPTION, "Test auth description"); + String testAuth = pubAuthorityService.createAuthority(AuthorityType.GROUP, "Test auth", props); + Pair displayNameAndDescription = pubAuthorityService.getAuthorityDisplayNameAndDescription(testAuth); + assertEquals(displayNameAndDescription.getFirst(), "Test auth"); + assertEquals(displayNameAndDescription.getSecond(), "Test auth description"); + pubAuthorityService.setAuthorityDisplayNameAndDescription(testAuth, "Modified auth", "Modified description"); + displayNameAndDescription = pubAuthorityService.getAuthorityDisplayNameAndDescription(testAuth); + assertEquals(displayNameAndDescription.getFirst(), "Modified auth"); + assertEquals(displayNameAndDescription.getSecond(), "Modified description"); + } public void testGetAuthoritiesFilteringSorting() { From 605c3a6ccda8b584fc0724e4153d0a7d40d38477 Mon Sep 17 00:00:00 2001 From: MichalKinas Date: Wed, 31 Jan 2024 00:51:45 +0100 Subject: [PATCH 16/24] ACS-5506 Add missing annotations, hasSubgroups not required --- .../src/main/java/org/alfresco/rest/model/RestGroupsModel.java | 2 +- .../org/alfresco/repo/security/authority/AuthorityDAOImpl.java | 2 ++ .../alfresco/repo/security/authority/AuthorityServiceImpl.java | 2 ++ .../alfresco/repo/security/authority/AuthorityServiceTest.java | 1 + 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestGroupsModel.java b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestGroupsModel.java index c5b7b7c1dd7..c126ac72cff 100644 --- a/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestGroupsModel.java +++ b/packaging/tests/tas-restapi/src/main/java/org/alfresco/rest/model/RestGroupsModel.java @@ -42,7 +42,7 @@ public class RestGroupsModel extends TestModel implements IRestModel getAuthorityDisplayNameAndDescription(String authorityName) { NodeRef ref = getAuthorityOrNull(authorityName); @@ -1456,6 +1457,7 @@ public Pair getAuthorityDisplayNameAndDescription(String authori return new Pair<>(DefaultTypeConverter.INSTANCE.convert(String.class, displayName), DefaultTypeConverter.INSTANCE.convert(String.class, description)); } + @Override public void setAuthorityDisplayNameAndDescription(String authorityName, String authorityDisplayName, String description) { NodeRef ref = getAuthorityOrNull(authorityName); diff --git a/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityServiceImpl.java b/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityServiceImpl.java index 7923bcffe4a..103e76888ca 100644 --- a/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityServiceImpl.java +++ b/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityServiceImpl.java @@ -700,6 +700,7 @@ public void setAuthorityDisplayName(String authorityName, String authorityDispla /** * {@inheritDoc} */ + @Override public Pair getAuthorityDisplayNameAndDescription(String name) { Pair displayNameAndDescription = authorityDAO.getAuthorityDisplayNameAndDescription(name); @@ -713,6 +714,7 @@ public Pair getAuthorityDisplayNameAndDescription(String name) /** * {@inheritDoc} */ + @Override public void setAuthorityDisplayNameAndDescription(String authorityName, String authorityDisplayName, String description) { AuthorityType type = AuthorityType.getAuthorityType(authorityName); diff --git a/repository/src/test/java/org/alfresco/repo/security/authority/AuthorityServiceTest.java b/repository/src/test/java/org/alfresco/repo/security/authority/AuthorityServiceTest.java index eb4753b0f97..956d8587fdc 100644 --- a/repository/src/test/java/org/alfresco/repo/security/authority/AuthorityServiceTest.java +++ b/repository/src/test/java/org/alfresco/repo/security/authority/AuthorityServiceTest.java @@ -1433,6 +1433,7 @@ public void testAuthorityDisplayNames() assertEquals(pubAuthorityService.getAuthorityDisplayName("Monkey"), "Monkey"); } + @Test public void testAuthorityDisplayNameAndDescription() { Map props = new HashMap<>(); From 12d1ecdefac0217a3bb2ab067ac9f71e42300754 Mon Sep 17 00:00:00 2001 From: MichalKinas Date: Fri, 2 Feb 2024 18:22:14 +0100 Subject: [PATCH 17/24] ACS-5506 CR fixes applied --- .../java/org/alfresco/rest/groups/GroupsTests.java | 6 ++++-- .../java/org/alfresco/rest/api/impl/GroupsImpl.java | 6 ++++-- .../repo/security/authority/AuthorityDAOImpl.java | 12 +++++++----- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java index 75cecb45ff1..f01f4d622d7 100644 --- a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java +++ b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java @@ -31,7 +31,8 @@ public void dataPreparation() throws Exception @Test(groups = { TestGroup.REST_API, TestGroup.GROUPS, TestGroup.SANITY }) @TestRail(section = { TestGroup.REST_API, TestGroup.NODES }, executionType = ExecutionType.SANITY, description = "Verify creation, listing, updating and deletion of groups.") - public void createListUpdateAndDeleteGroup() { + public void createListUpdateAndDeleteGroup() + { String groupName = "ZtestGroup" + UUID.randomUUID(); String subGroupName = "ZtestSubgroup" + UUID.randomUUID(); String groupDescription = "ZtestGroup description" + UUID.randomUUID(); @@ -111,7 +112,8 @@ public void createListUpdateAndDeleteGroup() { @Test(groups = { TestGroup.REST_API, TestGroup.GROUPS, TestGroup.SANITY }) @TestRail(section = { TestGroup.REST_API, TestGroup.NODES }, executionType = ExecutionType.SANITY, description = "Verify creation, listing(only for person) and deletion of group memberships. ") - public void createListDeleteGroupMembership() { + public void createListDeleteGroupMembership() + { String groupName = "ZtestGroup" + UUID.randomUUID(); JsonObject groupBody = Json.createObjectBuilder().add("id", groupName).add("displayName", groupName).build(); String groupBodyCreate = groupBody.toString(); diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java index 464d4ff5253..6cc4631df03 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java @@ -379,11 +379,13 @@ private PagingResults getAuthoritiesInfo(AuthorityType authorityT String displayNameFilter = groupsFilter.getDisplayNameFilter(); PagingResults pagingResult; - if (isRootParam != null || displayNameFilter != null) + // Don't use canned queries when fetching authorities with description + // if better performance is requested for loading descriptions we can add canned queries in the future + if (isRootParam != null || displayNameFilter != null || includeDescription) { List groupList; - if (isRootParam != null && isRootParam) + if ((isRootParam != null && isRootParam) || includeDescription) { // Limit the post processing work by using the already loaded // list of root authorities. diff --git a/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityDAOImpl.java b/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityDAOImpl.java index 6db71ea26bf..14b69a50d07 100644 --- a/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityDAOImpl.java +++ b/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityDAOImpl.java @@ -392,7 +392,7 @@ public void createAuthority(String name, String authorityDisplayName, Set getAuthorityDisplayNameAndDescription(String authori { return Pair.nullPair(); } - Serializable displayName = nodeService.getProperty(ref, ContentModel.PROP_AUTHORITY_DISPLAY_NAME); + String displayName = getAuthorityDisplayName(authorityName); Serializable description = nodeService.getProperty(ref, ContentModel.PROP_DESCRIPTION); - return new Pair<>(DefaultTypeConverter.INSTANCE.convert(String.class, displayName), DefaultTypeConverter.INSTANCE.convert(String.class, description)); + return new Pair<>(displayName, DefaultTypeConverter.INSTANCE.convert(String.class, description)); } @Override @@ -1465,8 +1465,10 @@ public void setAuthorityDisplayNameAndDescription(String authorityName, String a { return; } - nodeService.setProperty(ref, ContentModel.PROP_AUTHORITY_DISPLAY_NAME, authorityDisplayName); - nodeService.setProperty(ref, ContentModel.PROP_DESCRIPTION, description); + Map properties = new HashMap<>(); + properties.put(ContentModel.PROP_AUTHORITY_DISPLAY_NAME, authorityDisplayName); + properties.put(ContentModel.PROP_DESCRIPTION, description); + nodeService.setProperties(ref, properties); } public NodeRef getOrCreateZone(String zoneName) From 197acb3a7bc999ed75ac8935ab4312a6c95e9ff7 Mon Sep 17 00:00:00 2001 From: MichalKinas Date: Mon, 5 Feb 2024 12:55:37 +0100 Subject: [PATCH 18/24] ACS-5506 Add allowed methods --- .../resources/alfresco/public-services-security-context.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/repository/src/main/resources/alfresco/public-services-security-context.xml b/repository/src/main/resources/alfresco/public-services-security-context.xml index 7295be35047..51e2bab8df9 100644 --- a/repository/src/main/resources/alfresco/public-services-security-context.xml +++ b/repository/src/main/resources/alfresco/public-services-security-context.xml @@ -821,6 +821,8 @@ org.alfresco.service.cmr.security.AuthorityService.authorityExists=ACL_ALLOW org.alfresco.service.cmr.security.AuthorityService.setAuthorityDisplayName=ACL_METHOD.ROLE_ADMINISTRATOR org.alfresco.service.cmr.security.AuthorityService.getAuthorityDisplayName=ACL_ALLOW + org.alfresco.service.cmr.security.AuthorityService.setAuthorityDisplayNameAndDescription=ACL_METHOD.ROLE_ADMINISTRATOR + org.alfresco.service.cmr.security.AuthorityService.getAuthorityDisplayNameAndDescription=ACL_ALLOW org.alfresco.service.cmr.security.AuthorityService.getOrCreateZone=ACL_METHOD.ROLE_ADMINISTRATOR org.alfresco.service.cmr.security.AuthorityService.getZone=ACL_ALLOW org.alfresco.service.cmr.security.AuthorityService.getAuthorityZones=ACL_ALLOW From 9ffe27f028718bcafe1be943a0e0739ee91507a4 Mon Sep 17 00:00:00 2001 From: MichalKinas Date: Tue, 6 Feb 2024 11:39:45 +0100 Subject: [PATCH 19/24] ACS-5506 Update properties correctly --- .../org/alfresco/repo/security/authority/AuthorityDAOImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityDAOImpl.java b/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityDAOImpl.java index 14b69a50d07..bdfd8b40cd2 100644 --- a/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityDAOImpl.java +++ b/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityDAOImpl.java @@ -1465,7 +1465,7 @@ public void setAuthorityDisplayNameAndDescription(String authorityName, String a { return; } - Map properties = new HashMap<>(); + Map properties = nodeService.getProperties(ref); properties.put(ContentModel.PROP_AUTHORITY_DISPLAY_NAME, authorityDisplayName); properties.put(ContentModel.PROP_DESCRIPTION, description); nodeService.setProperties(ref, properties); From cfc0916c84a79e8780f3210ecb08c8f33dd71cc6 Mon Sep 17 00:00:00 2001 From: MichalKinas Date: Tue, 6 Feb 2024 13:04:31 +0100 Subject: [PATCH 20/24] ACS-5506 Unit tests fixes --- .../src/test/java/org/alfresco/rest/groups/GroupsTests.java | 4 ++-- .../src/test/java/org/alfresco/rest/api/tests/GroupsTest.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java index f01f4d622d7..270dba45057 100644 --- a/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java +++ b/packaging/tests/tas-restapi/src/test/java/org/alfresco/rest/groups/GroupsTests.java @@ -75,7 +75,7 @@ public void createListUpdateAndDeleteGroup() groupBody = Json.createObjectBuilder().add("displayName", "Z"+groupName).add("description", "Z"+groupDescription).build(); String groupBodyUpdate = groupBody.toString(); //UpdateGroup: - restClient.withCoreAPI().usingGroups().updateGroupDetails("GROUP_"+groupName, groupBodyUpdate) + restClient.withCoreAPI().usingParams("include=description").usingGroups().updateGroupDetails("GROUP_"+groupName, groupBodyUpdate) .assertThat().field("displayName").is("Z"+groupName) .and().field("description").is("Z"+groupDescription) .and().field("id").is("GROUP_"+groupName) @@ -83,7 +83,7 @@ public void createListUpdateAndDeleteGroup() restClient.assertStatusCodeIs(HttpStatus.OK); //GetGroupDetails: - restClient.withCoreAPI().usingParams("include=zones,hasSubgroups,description").usingGroups().getGroupDetail("GROUP_"+groupName) + restClient.withCoreAPI().usingParams("include=zones,hasSubgroups").usingGroups().getGroupDetail("GROUP_"+groupName) .assertThat().field("id").is("GROUP_"+groupName) .and().field("zones").contains("APP.DEFAULT") .and().field("isRoot").is(true) diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/GroupsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/GroupsTest.java index da3245ee3a8..2dec40800e0 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/GroupsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/GroupsTest.java @@ -673,7 +673,7 @@ private void validateGroupDefaultFields(Group group, boolean ignoreOptionallyInc // Optionally included. assertNull(group.getParentIds()); assertNull(group.getZones()); - assertNotNull(group.getHasSubgroups()); + assertNull(group.getHasSubgroups()); } } From c537166f68351d0d3ab59091b9442e63eb27f388 Mon Sep 17 00:00:00 2001 From: MichalKinas Date: Tue, 6 Feb 2024 20:36:42 +0100 Subject: [PATCH 21/24] ACS-5506 Add temporary logging --- .../src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java | 3 ++- .../src/test/java/org/alfresco/rest/api/tests/GroupsTest.java | 1 + .../java/org/alfresco/rest/api/tests/client/data/Group.java | 2 +- .../alfresco/repo/security/authority/AuthorityServiceImpl.java | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java index 6cc4631df03..5763e451cbc 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java @@ -136,6 +136,7 @@ public void setPeople(People people) public Group create(Group group, Parameters parameters) { + System.out.println("Create from impl called"); validateGroup(group, false); // Create authority with default zones. @@ -151,7 +152,7 @@ public Group create(Group group, Parameters parameters) { props.put(ContentModel.PROP_DESCRIPTION, group.getDescription()); } - + System.out.println("Before authority created"); String authority = authorityService.createAuthority(AuthorityType.GROUP, group.getId(), authorityDisplayName, authorityZones, props); // Set a given child authority to be included by the given parent diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/GroupsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/GroupsTest.java index 2dec40800e0..2728d242579 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/GroupsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/GroupsTest.java @@ -1426,6 +1426,7 @@ public void testCreateGroup() throws Exception Group group = generateGroup(); group.setDescription("testDesc"); + System.out.println("" + otherParams); Group createdGroup01 = groupsProxy.createGroup(group, otherParams, HttpServletResponse.SC_CREATED); assertNotNull(createdGroup01); diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/client/data/Group.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/client/data/Group.java index acbbf4d8c75..4bc4a02a4c9 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/client/data/Group.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/client/data/Group.java @@ -112,7 +112,7 @@ public static Group parseGroup(JSONObject jsonObject) Boolean hasSubgroups = (Boolean) jsonObject.get("hasSubgroups"); List parentIds = (List) jsonObject.get("parentIds"); List zones = (List) jsonObject.get("zones"); - + System.out.println("Parse group: " + description + " " + displayName); Group group = new Group(); group.setId(id); group.setDisplayName(displayName); diff --git a/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityServiceImpl.java b/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityServiceImpl.java index 103e76888ca..4d992b09306 100644 --- a/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityServiceImpl.java +++ b/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityServiceImpl.java @@ -668,7 +668,7 @@ public String createAuthority(AuthorityType type, String shortName, String autho { checkTypeIsMutable(type); String name = getName(type, shortName); - + System.out.println("Before authority DAO created"); authorityDAO.createAuthority(name, authorityDisplayName, authorityZones, properties); return name; From 11030f52fab1d2f59895ae42f9b4abcd6dab0ed9 Mon Sep 17 00:00:00 2001 From: MichalKinas Date: Tue, 6 Feb 2024 21:15:14 +0100 Subject: [PATCH 22/24] ACS-5506 Add temporary logging --- .../main/java/org/alfresco/rest/api/impl/GroupsImpl.java | 8 ++++++-- .../test/java/org/alfresco/rest/api/tests/GroupsTest.java | 7 ++++++- .../org/alfresco/rest/api/tests/client/data/Group.java | 5 ++++- .../repo/security/authority/AuthorityDAOImpl.java | 1 + .../repo/security/authority/AuthorityServiceImpl.java | 5 ++++- 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java index 5763e451cbc..17e43c26e3b 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java @@ -78,6 +78,8 @@ import org.alfresco.util.Pair; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.extensions.surf.util.I18NUtil; /** @@ -94,6 +96,8 @@ public class GroupsImpl implements Groups private static final String AUTHORITY_NAME = "authorityName"; private static final String ERR_MSG_MODIFY_FIXED_AUTHORITY = "Trying to modify a fixed authority"; + protected static final Logger logger = LoggerFactory.getLogger(GroupsImpl.class); + private final static Map SORT_PARAMS_TO_NAMES; static { @@ -136,7 +140,7 @@ public void setPeople(People people) public Group create(Group group, Parameters parameters) { - System.out.println("Create from impl called"); + logger.info("Create from impl called"); validateGroup(group, false); // Create authority with default zones. @@ -152,7 +156,7 @@ public Group create(Group group, Parameters parameters) { props.put(ContentModel.PROP_DESCRIPTION, group.getDescription()); } - System.out.println("Before authority created"); + logger.info("Before authority created"); String authority = authorityService.createAuthority(AuthorityType.GROUP, group.getId(), authorityDisplayName, authorityZones, props); // Set a given child authority to be included by the given parent diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/GroupsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/GroupsTest.java index 2728d242579..68a02484cde 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/GroupsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/GroupsTest.java @@ -49,6 +49,9 @@ import org.mockito.Mock; import jakarta.servlet.http.HttpServletResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.util.*; import static org.junit.Assert.assertEquals; @@ -70,6 +73,8 @@ public class GroupsTest extends AbstractSingleNetworkSiteTest private static final String GROUP_EVERYONE = "GROUP_EVERYONE"; private static final String INCLUDE_DESCRIPTION_HAS_SUBGROUPS = "description,hasSubgroups"; + protected static final Logger logger = LoggerFactory.getLogger(GroupsTest.class); + protected AuthorityService authorityService; private String rootGroupName; @@ -1426,7 +1431,7 @@ public void testCreateGroup() throws Exception Group group = generateGroup(); group.setDescription("testDesc"); - System.out.println("" + otherParams); + logger.info("" + otherParams); Group createdGroup01 = groupsProxy.createGroup(group, otherParams, HttpServletResponse.SC_CREATED); assertNotNull(createdGroup01); diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/client/data/Group.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/client/data/Group.java index 4bc4a02a4c9..03a70f20a6f 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/client/data/Group.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/client/data/Group.java @@ -37,6 +37,8 @@ import org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse; import org.json.simple.JSONArray; import org.json.simple.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Represents a group. @@ -48,6 +50,7 @@ public class Group extends org.alfresco.rest.api.model.Group implements Serializ { private static final long serialVersionUID = -3580248429177260831L; + protected static final Logger logger = LoggerFactory.getLogger(Group.class); @Override public void expected(Object o) @@ -112,7 +115,7 @@ public static Group parseGroup(JSONObject jsonObject) Boolean hasSubgroups = (Boolean) jsonObject.get("hasSubgroups"); List parentIds = (List) jsonObject.get("parentIds"); List zones = (List) jsonObject.get("zones"); - System.out.println("Parse group: " + description + " " + displayName); + logger.info("Parse group: " + description + " " + displayName); Group group = new Group(); group.setId(id); group.setDisplayName(displayName); diff --git a/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityDAOImpl.java b/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityDAOImpl.java index bdfd8b40cd2..4b7b7c81257 100644 --- a/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityDAOImpl.java +++ b/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityDAOImpl.java @@ -398,6 +398,7 @@ public void createAuthority(String name, String authorityDisplayName, Set DEFAULT_ZONES = new HashSet(); @@ -668,7 +671,7 @@ public String createAuthority(AuthorityType type, String shortName, String autho { checkTypeIsMutable(type); String name = getName(type, shortName); - System.out.println("Before authority DAO created"); + logger.info("Before authority DAO created"); authorityDAO.createAuthority(name, authorityDisplayName, authorityZones, properties); return name; From 5e85b8149b13304a4857229966efe2782f8d4fe3 Mon Sep 17 00:00:00 2001 From: MichalKinas Date: Thu, 8 Feb 2024 11:12:30 +0100 Subject: [PATCH 23/24] ACS-5506 Cleanup and test fixes --- .../alfresco/rest/api/impl/GroupsImpl.java | 6 ------ .../alfresco/rest/api/tests/GroupsTest.java | 20 ++++--------------- .../rest/api/tests/client/data/Group.java | 4 ---- .../authority/AuthorityServiceImpl.java | 5 ----- 4 files changed, 4 insertions(+), 31 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java index 17e43c26e3b..d291b1293b6 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/GroupsImpl.java @@ -78,8 +78,6 @@ import org.alfresco.util.Pair; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.extensions.surf.util.I18NUtil; /** @@ -96,8 +94,6 @@ public class GroupsImpl implements Groups private static final String AUTHORITY_NAME = "authorityName"; private static final String ERR_MSG_MODIFY_FIXED_AUTHORITY = "Trying to modify a fixed authority"; - protected static final Logger logger = LoggerFactory.getLogger(GroupsImpl.class); - private final static Map SORT_PARAMS_TO_NAMES; static { @@ -140,7 +136,6 @@ public void setPeople(People people) public Group create(Group group, Parameters parameters) { - logger.info("Create from impl called"); validateGroup(group, false); // Create authority with default zones. @@ -156,7 +151,6 @@ public Group create(Group group, Parameters parameters) { props.put(ContentModel.PROP_DESCRIPTION, group.getDescription()); } - logger.info("Before authority created"); String authority = authorityService.createAuthority(AuthorityType.GROUP, group.getId(), authorityDisplayName, authorityZones, props); // Set a given child authority to be included by the given parent diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/GroupsTest.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/GroupsTest.java index 68a02484cde..1b09ca88c39 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/GroupsTest.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/GroupsTest.java @@ -49,8 +49,6 @@ import org.mockito.Mock; import jakarta.servlet.http.HttpServletResponse; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.*; @@ -71,9 +69,6 @@ public class GroupsTest extends AbstractSingleNetworkSiteTest private static final String MEMBER_TYPE_GROUP = "GROUP"; private static final String MEMBER_TYPE_PERSON = "PERSON"; private static final String GROUP_EVERYONE = "GROUP_EVERYONE"; - private static final String INCLUDE_DESCRIPTION_HAS_SUBGROUPS = "description,hasSubgroups"; - - protected static final Logger logger = LoggerFactory.getLogger(GroupsTest.class); protected AuthorityService authorityService; @@ -1426,17 +1421,14 @@ public void testCreateGroup() throws Exception setRequestContext(networkOne.getId(), networkAdmin, DEFAULT_ADMIN_PWD); Map otherParams = new HashMap<>(); - otherParams.put("include", INCLUDE_DESCRIPTION_HAS_SUBGROUPS); + otherParams.put("include", org.alfresco.rest.api.Groups.PARAM_INCLUDE_HAS_SUBGROUPS); Group group = generateGroup(); - group.setDescription("testDesc"); - logger.info("" + otherParams); Group createdGroup01 = groupsProxy.createGroup(group, otherParams, HttpServletResponse.SC_CREATED); assertNotNull(createdGroup01); assertNotNull(createdGroup01.getId()); - assertEquals(createdGroup01.getDescription(), "testDesc"); assertTrue(createdGroup01.getIsRoot()); assertNull(createdGroup01.getParentIds()); assertFalse(createdGroup01.getHasSubgroups()); @@ -1447,7 +1439,7 @@ public void testCreateGroup() throws Exception Group subGroup01 = generateGroup(); subGroup01.setParentIds(subGroup01Parents); - otherParams.put("include", org.alfresco.rest.api.Groups.PARAM_INCLUDE_PARENT_IDS + "," + INCLUDE_DESCRIPTION_HAS_SUBGROUPS); + otherParams.put("include", org.alfresco.rest.api.Groups.PARAM_INCLUDE_PARENT_IDS + "," + org.alfresco.rest.api.Groups.PARAM_INCLUDE_HAS_SUBGROUPS); Group createdSubGroup01 = groupsProxy.createGroup(subGroup01, otherParams, HttpServletResponse.SC_CREATED); assertNotNull(createdSubGroup01); assertNotNull(createdSubGroup01.getId()); @@ -1631,7 +1623,7 @@ public void testUpdateGroup() throws Exception final Groups groupsProxy = publicApiClient.groups(); Map otherParams = new HashMap<>(); - otherParams.put("include", org.alfresco.rest.api.Groups.PARAM_INCLUDE_PARENT_IDS + "," + org.alfresco.rest.api.Groups.PARAM_INCLUDE_DESCRIPTION); + otherParams.put("include", org.alfresco.rest.api.Groups.PARAM_INCLUDE_PARENT_IDS); setRequestContext(networkOne.getId(), networkAdmin, DEFAULT_ADMIN_PWD); @@ -1641,7 +1633,6 @@ public void testUpdateGroup() throws Exception subGroupParents.add(group.getId()); Group generatedSubGroup = generateGroup(); - generatedSubGroup.setDescription("initialDesc"); generatedSubGroup.setParentIds(subGroupParents); Group subGroup = groupsProxy.createGroup(generatedSubGroup, otherParams, HttpServletResponse.SC_CREATED); @@ -1664,11 +1655,9 @@ public void testUpdateGroup() throws Exception String displayName = "newDisplayName"; - String description = "newDesc"; Group mySubGroup = new Group(); mySubGroup.setDisplayName(displayName); - mySubGroup.setDescription(description); Group updateGroup = groupsProxy.updateGroup(subGroup.getId(), mySubGroup, otherParams, HttpServletResponse.SC_OK); @@ -1678,9 +1667,8 @@ public void testUpdateGroup() throws Exception assertFalse(updateGroup.getIsRoot()); assertNotNull(updateGroup.getParentIds()); - // Check that only display name and description changed. + // Check that only display name changed. assertEquals(displayName, updateGroup.getDisplayName()); - assertEquals(description, updateGroup.getDescription()); // Check that nothing else changed. assertEquals(subGroup.getId(), updateGroup.getId()); diff --git a/remote-api/src/test/java/org/alfresco/rest/api/tests/client/data/Group.java b/remote-api/src/test/java/org/alfresco/rest/api/tests/client/data/Group.java index 03a70f20a6f..ec530ca244d 100644 --- a/remote-api/src/test/java/org/alfresco/rest/api/tests/client/data/Group.java +++ b/remote-api/src/test/java/org/alfresco/rest/api/tests/client/data/Group.java @@ -37,8 +37,6 @@ import org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse; import org.json.simple.JSONArray; import org.json.simple.JSONObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * Represents a group. @@ -50,7 +48,6 @@ public class Group extends org.alfresco.rest.api.model.Group implements Serializ { private static final long serialVersionUID = -3580248429177260831L; - protected static final Logger logger = LoggerFactory.getLogger(Group.class); @Override public void expected(Object o) @@ -115,7 +112,6 @@ public static Group parseGroup(JSONObject jsonObject) Boolean hasSubgroups = (Boolean) jsonObject.get("hasSubgroups"); List parentIds = (List) jsonObject.get("parentIds"); List zones = (List) jsonObject.get("zones"); - logger.info("Parse group: " + description + " " + displayName); Group group = new Group(); group.setId(id); group.setDisplayName(displayName); diff --git a/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityServiceImpl.java b/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityServiceImpl.java index 343c5cb54d4..13aa81f9479 100644 --- a/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityServiceImpl.java +++ b/repository/src/main/java/org/alfresco/repo/security/authority/AuthorityServiceImpl.java @@ -57,8 +57,6 @@ import org.alfresco.service.cmr.security.PersonService; import org.alfresco.service.namespace.QName; import org.alfresco.util.Pair; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.InitializingBean; import org.springframework.extensions.surf.util.ParameterCheck; @@ -70,8 +68,6 @@ public class AuthorityServiceImpl implements AuthorityService, InitializingBean { public static final String GROUP_ALFRESCO_SYSTEM_ADMINISTRATORS_AUTHORITY = PermissionService.GROUP_PREFIX + "ALFRESCO_SYSTEM_ADMINISTRATORS"; - protected static final Logger logger = LoggerFactory.getLogger(AuthorityServiceImpl.class); - private static Set DEFAULT_ZONES = new HashSet(); static @@ -671,7 +667,6 @@ public String createAuthority(AuthorityType type, String shortName, String autho { checkTypeIsMutable(type); String name = getName(type, shortName); - logger.info("Before authority DAO created"); authorityDAO.createAuthority(name, authorityDisplayName, authorityZones, properties); return name; From f737c3ef3cb3dc871b607b7391d2b04a8b9d5980 Mon Sep 17 00:00:00 2001 From: MichalKinas Date: Thu, 8 Feb 2024 11:39:17 +0100 Subject: [PATCH 24/24] ACS-5506 Test fix --- .../security/authority/AuthorityServiceTest.java | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/repository/src/test/java/org/alfresco/repo/security/authority/AuthorityServiceTest.java b/repository/src/test/java/org/alfresco/repo/security/authority/AuthorityServiceTest.java index 956d8587fdc..246135f6a4a 100644 --- a/repository/src/test/java/org/alfresco/repo/security/authority/AuthorityServiceTest.java +++ b/repository/src/test/java/org/alfresco/repo/security/authority/AuthorityServiceTest.java @@ -1432,21 +1432,6 @@ public void testAuthorityDisplayNames() assertEquals(pubAuthorityService.getAuthorityDisplayName("ROLE_Gibbon"), "Gibbon"); assertEquals(pubAuthorityService.getAuthorityDisplayName("Monkey"), "Monkey"); } - - @Test - public void testAuthorityDisplayNameAndDescription() - { - Map props = new HashMap<>(); - props.put(ContentModel.PROP_DESCRIPTION, "Test auth description"); - String testAuth = pubAuthorityService.createAuthority(AuthorityType.GROUP, "Test auth", props); - Pair displayNameAndDescription = pubAuthorityService.getAuthorityDisplayNameAndDescription(testAuth); - assertEquals(displayNameAndDescription.getFirst(), "Test auth"); - assertEquals(displayNameAndDescription.getSecond(), "Test auth description"); - pubAuthorityService.setAuthorityDisplayNameAndDescription(testAuth, "Modified auth", "Modified description"); - displayNameAndDescription = pubAuthorityService.getAuthorityDisplayNameAndDescription(testAuth); - assertEquals(displayNameAndDescription.getFirst(), "Modified auth"); - assertEquals(displayNameAndDescription.getSecond(), "Modified description"); - } public void testGetAuthoritiesFilteringSorting() {