ACS-5506 Add PMD fixes

This commit is contained in:
MichalKinas
2024-01-17 13:47:40 +01:00
parent 1f72faa90c
commit ecfeb77fb0
6 changed files with 21 additions and 11 deletions

View File

@@ -160,7 +160,7 @@ public class GroupsImpl implements Groups
authorityDisplayName = group.getDisplayName(); authorityDisplayName = group.getDisplayName();
} }
HashMap<QName, Serializable> props = new HashMap<>(); Map<QName, Serializable> props = new HashMap<>();
if (StringUtils.isNotEmpty(group.getDescription())) if (StringUtils.isNotEmpty(group.getDescription()))
{ {
props.put(ContentModel.PROP_DESCRIPTION, group.getDescription()); props.put(ContentModel.PROP_DESCRIPTION, group.getDescription());
@@ -194,7 +194,7 @@ public class GroupsImpl implements Groups
if (StringUtils.isNotEmpty(group.getDescription())) if (StringUtils.isNotEmpty(group.getDescription()))
{ {
HashMap<QName, Serializable> props = new HashMap<>(); Map<QName, Serializable> props = new HashMap<>();
props.put(ContentModel.PROP_DESCRIPTION, group.getDescription()); props.put(ContentModel.PROP_DESCRIPTION, group.getDescription());
authorityDAO.setAuthorityProperties(authorityService.getName(AuthorityType.GROUP, groupId), props); authorityDAO.setAuthorityProperties(authorityService.getName(AuthorityType.GROUP, groupId), props);
} }
@@ -617,7 +617,8 @@ public class GroupsImpl implements Groups
group.setIsRoot(isRootAuthority(rootAuthorities, authorityInfo.getAuthorityName())); group.setIsRoot(isRootAuthority(rootAuthorities, authorityInfo.getAuthorityName()));
Set<String> containedAuthorities; Set<String> containedAuthorities;
try { try
{
containedAuthorities = authorityService.getContainedAuthorities(AuthorityType.GROUP, authorityInfo.getAuthorityName(), true); containedAuthorities = authorityService.getContainedAuthorities(AuthorityType.GROUP, authorityInfo.getAuthorityName(), true);
} catch (UnknownAuthorityException e) } catch (UnknownAuthorityException e)
{ {
@@ -627,8 +628,9 @@ public class GroupsImpl implements Groups
NodeRef groupNodeRef = authorityService.getAuthorityNodeRef(authorityInfo.getAuthorityName()); NodeRef groupNodeRef = authorityService.getAuthorityNodeRef(authorityInfo.getAuthorityName());
String description; String description;
try { try
description = nodeService.getProperty(groupNodeRef, ContentModel.PROP_DESCRIPTION) != null ? {
description = groupNodeRef != null && nodeService.getProperty(groupNodeRef, ContentModel.PROP_DESCRIPTION) != null ?
nodeService.getProperty(groupNodeRef, ContentModel.PROP_DESCRIPTION).toString() : nodeService.getProperty(groupNodeRef, ContentModel.PROP_DESCRIPTION).toString() :
null; null;
} catch (InvalidNodeRefException e) } catch (InvalidNodeRefException e)

View File

@@ -181,6 +181,6 @@ public class Group implements Comparable<Group>
public boolean wasSet(String fieldName) public boolean wasSet(String fieldName)
{ {
Boolean b = setFields.get(fieldName); Boolean b = setFields.get(fieldName);
return b != null ? b : false; return b != null && b;
} }
} }

View File

@@ -379,13 +379,15 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor
} }
} }
@Override
public void createAuthority(String name, String authorityDisplayName, Set<String> authorityZones) { public void createAuthority(String name, String authorityDisplayName, Set<String> authorityZones) {
createAuthority(name, authorityDisplayName, authorityZones, null); createAuthority(name, authorityDisplayName, authorityZones, null);
} }
@Override
public void createAuthority(String name, String authorityDisplayName, Set<String> authorityZones, Map<QName, Serializable> properties) public void createAuthority(String name, String authorityDisplayName, Set<String> authorityZones, Map<QName, Serializable> properties)
{ {
HashMap<QName, Serializable> props = new HashMap<>(); Map<QName, Serializable> props = new HashMap<>();
/* MNT-11749 : Alfresco allows to create authorities with different char cases, but disallow duplicates */ /* 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_NAME, DigestUtils.md5Hex(name));
props.put(ContentModel.PROP_AUTHORITY_NAME, 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<QName, Serializable> properties) public void setAuthorityProperties(String authorityName, Map<QName, Serializable> properties)
{ {
NodeRef ref = getAuthorityOrNull(authorityName); NodeRef ref = getAuthorityOrNull(authorityName);

View File

@@ -550,6 +550,7 @@ public class AuthorityServiceImpl implements AuthorityService, InitializingBean
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override
public String createAuthority(AuthorityType type, String shortName, Map<QName, Serializable> properties) public String createAuthority(AuthorityType type, String shortName, Map<QName, Serializable> properties)
{ {
return createAuthority(type, shortName, shortName, getDefaultZones(), properties); return createAuthority(type, shortName, shortName, getDefaultZones(), properties);
@@ -661,6 +662,7 @@ public class AuthorityServiceImpl implements AuthorityService, InitializingBean
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override
public String createAuthority(AuthorityType type, String shortName, String authorityDisplayName, public String createAuthority(AuthorityType type, String shortName, String authorityDisplayName,
Set<String> authorityZones, Map<QName, Serializable> properties) Set<String> authorityZones, Map<QName, Serializable> properties)
{ {

View File

@@ -244,7 +244,7 @@ public interface AuthorityService
* associated with the type appended with the short name) * associated with the type appended with the short name)
*/ */
@Auditable(parameters = {"type", "shortName"}) @Auditable(parameters = {"type", "shortName"})
public String createAuthority(AuthorityType type, String shortName, Map<QName, Serializable> properties); String createAuthority(AuthorityType type, String shortName, Map<QName, Serializable> properties);
/** /**
* Create an authority with a display name and zone. * Create an authority with a display name and zone.
@@ -282,7 +282,7 @@ public interface AuthorityService
* the short name) * the short name)
*/ */
@Auditable(parameters = {"type", "shortName", "authorityDisplayName", "authorityZones"}) @Auditable(parameters = {"type", "shortName", "authorityDisplayName", "authorityZones"})
public String createAuthority(AuthorityType type, String shortName, String authorityDisplayName, Set<String> authorityZones, Map<QName, Serializable> properties); String createAuthority(AuthorityType type, String shortName, String authorityDisplayName, Set<String> authorityZones, Map<QName, Serializable> properties);
/** /**
* Set an authority to include another authority. For example, adding a * Set an authority to include another authority. For example, adding a

View File

@@ -86,6 +86,7 @@ import org.alfresco.util.ApplicationContextHelper;
import org.alfresco.util.testing.category.LuceneTests; import org.alfresco.util.testing.category.LuceneTests;
import org.alfresco.util.testing.category.RedundantTests; import org.alfresco.util.testing.category.RedundantTests;
import org.junit.FixMethodOrder; import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.experimental.categories.Category; import org.junit.experimental.categories.Category;
import org.junit.runners.MethodSorters; import org.junit.runners.MethodSorters;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
@@ -582,6 +583,7 @@ public class AuthorityServiceTest extends TestCase
} }
} }
@Test
public void testCreateGroupAuthWithProperties() public void testCreateGroupAuthWithProperties()
{ {
String auth; String auth;
@@ -589,7 +591,7 @@ public class AuthorityServiceTest extends TestCase
String prefixedGroupName = "GROUP_TESTGROUP"; String prefixedGroupName = "GROUP_TESTGROUP";
String description = "testDesc"; String description = "testDesc";
String title = "testTitle"; String title = "testTitle";
HashMap<QName, Serializable> props = new HashMap<>(); Map<QName, Serializable> props = new HashMap<>();
props.put(ContentModel.PROP_DESCRIPTION, description); props.put(ContentModel.PROP_DESCRIPTION, description);
props.put(ContentModel.PROP_TITLE, title); props.put(ContentModel.PROP_TITLE, title);
@@ -614,6 +616,7 @@ public class AuthorityServiceTest extends TestCase
pubAuthorityService.deleteAuthority(auth); pubAuthorityService.deleteAuthority(auth);
} }
@Test
public void testUpdateAuthorityProperties() public void testUpdateAuthorityProperties()
{ {
String auth; String auth;
@@ -621,7 +624,7 @@ public class AuthorityServiceTest extends TestCase
String prefixedGroupName = "GROUP_TESTGROUP"; String prefixedGroupName = "GROUP_TESTGROUP";
String description = "testDesc"; String description = "testDesc";
String title = "testTitle"; String title = "testTitle";
HashMap<QName, Serializable> props = new HashMap<>(); Map<QName, Serializable> props = new HashMap<>();
props.put(ContentModel.PROP_DESCRIPTION, description); props.put(ContentModel.PROP_DESCRIPTION, description);
props.put(ContentModel.PROP_TITLE, title); props.put(ContentModel.PROP_TITLE, title);