From ecfeb77fb0136581f052c93e75da3035d9d2a00d Mon Sep 17 00:00:00 2001 From: MichalKinas Date: Wed, 17 Jan 2024 13:47:40 +0100 Subject: [PATCH] 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 e657e44357..92c1cf1818 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 class GroupsImpl implements Groups 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 class GroupsImpl implements Groups 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 @@ public class GroupsImpl implements Groups 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 @@ public class GroupsImpl implements Groups 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 0eccdf856e..87ae009564 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 class Group implements Comparable 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 7625965836..86c96957e8 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 class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor } } + @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 class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor } + @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 08a9a8d83c..8efd66b507 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 class AuthorityServiceImpl implements AuthorityService, InitializingBean /** * {@inheritDoc} */ + @Override public String createAuthority(AuthorityType type, String shortName, Map properties) { return createAuthority(type, shortName, shortName, getDefaultZones(), properties); @@ -661,6 +662,7 @@ public class AuthorityServiceImpl implements AuthorityService, InitializingBean /** * {@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 25b5c2a294..e1cd6ac1ff 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 5299932802..2dc6af536f 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.ApplicationContextHelper; 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 class AuthorityServiceTest extends TestCase } } + @Test public void testCreateGroupAuthWithProperties() { String auth; @@ -589,7 +591,7 @@ public class AuthorityServiceTest extends TestCase 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 class AuthorityServiceTest extends TestCase pubAuthorityService.deleteAuthority(auth); } + @Test public void testUpdateAuthorityProperties() { String auth; @@ -621,7 +624,7 @@ public class AuthorityServiceTest extends TestCase 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);