MNT-24146 -backport fix & precommit changes

This commit is contained in:
DurgDineshsai
2025-05-15 17:30:20 +05:30
parent 686ffcb19c
commit 71849cd4ac

View File

@@ -25,6 +25,20 @@
*/
package org.alfresco.rest.api.impl;
import java.io.InputStream;
import java.io.Serializable;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.alfresco.model.ContentModel;
import org.alfresco.query.PagingRequest;
import org.alfresco.query.PagingResults;
@@ -75,19 +89,6 @@ import org.alfresco.service.cmr.usage.ContentUsageService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.Pair;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.InputStream;
import java.io.Serializable;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* Centralises access to people services and maps between representations.
@@ -106,8 +107,7 @@ public class PeopleImpl implements People
private static final List<QName> EXCLUDED_ASPECTS = Arrays.asList();
private static final List<QName> EXCLUDED_PROPS = Arrays.asList();
private static final int USERNAME_MAXLENGTH = 100;
private static final String[] RESERVED_AUTHORITY_PREFIXES =
{
private static final String[] RESERVED_AUTHORITY_PREFIXES = {
PermissionService.GROUP_PREFIX,
PermissionService.ROLE_PREFIX
};
@@ -223,27 +223,27 @@ public class PeopleImpl implements People
public String validatePerson(final String requestedPersonId, boolean validateIsCurrentUser)
{
String personId = requestedPersonId;
if(personId == null)
if (personId == null)
{
throw new InvalidArgumentException("personId is null.");
}
if(personId.equalsIgnoreCase(DEFAULT_USER))
if (personId.equalsIgnoreCase(DEFAULT_USER))
{
personId = AuthenticationUtil.getFullyAuthenticatedUser();
}
personId = personService.getUserIdentifier(personId);
if(personId == null)
if (personId == null)
{
// Could not find canonical user ID by case-sensitive ID.
throw new EntityNotFoundException(requestedPersonId);
}
if(validateIsCurrentUser)
if (validateIsCurrentUser)
{
String currentUserId = AuthenticationUtil.getFullyAuthenticatedUser();
if(!currentUserId.equalsIgnoreCase(personId))
if (!currentUserId.equalsIgnoreCase(personId))
{
throw new EntityNotFoundException(personId);
}
@@ -254,7 +254,7 @@ public class PeopleImpl implements People
protected void processPersonProperties(String userName, final Map<QName, Serializable> nodeProps)
{
if(!contentUsageService.getEnabled())
if (!contentUsageService.getEnabled())
{
// quota used will always be 0 in this case so remove from the person properties
nodeProps.remove(ContentModel.PROP_SIZE_QUOTA);
@@ -264,18 +264,17 @@ public class PeopleImpl implements People
// The person description is located in a separate content file located at cm:persondescription
// "Inline" this data, by removing the cm:persondescription property and adding a temporary property
// (Person.PROP_PERSON_DESCRIPTION) containing the actual content as a string.
final ContentData personDescription = (ContentData)nodeProps.get(ContentModel.PROP_PERSONDESC);
if(personDescription != null)
final ContentData personDescription = (ContentData) nodeProps.get(ContentModel.PROP_PERSONDESC);
if (personDescription != null)
{
nodeProps.remove(ContentModel.PROP_PERSONDESC);
AuthenticationUtil.runAsSystem(new RunAsWork<Void>()
{
AuthenticationUtil.runAsSystem(new RunAsWork<Void>() {
@Override
public Void doWork() throws Exception
{
ContentReader reader = contentService.getRawReader(personDescription.getContentUrl());
if(reader != null && reader.exists())
if (reader != null && reader.exists())
{
String description = reader.getContentString();
nodeProps.put(Person.PROP_PERSON_DESCRIPTION, description);
@@ -298,7 +297,7 @@ public class PeopleImpl implements People
NodeRef avatar = null;
personId = validatePerson(personId);
NodeRef personNode = personService.getPerson(personId);
if(personNode != null)
if (personNode != null)
{
NodeRef avatarOrig = getAvatarOriginal(personNode);
avatar = thumbnailService.getThumbnailByName(avatarOrig, ContentModel.PROP_CONTENT, "avatar");
@@ -379,7 +378,7 @@ public class PeopleImpl implements People
if (mimeType.indexOf("image/") != 0)
{
throw new InvalidArgumentException(
"Uploaded content must be an image (content type determined to be '"+mimeType+"')");
"Uploaded content must be an image (content type determined to be '" + mimeType + "')");
}
// create thumbnail synchronously
@@ -416,7 +415,6 @@ public class PeopleImpl implements People
nodeService.deleteNode(avatarOrigNodeRef);
}
/**
* Get a full representation of a person.
*
@@ -459,8 +457,7 @@ public class PeopleImpl implements People
final List<PersonService.PersonInfo> page = pagingResult.getPage();
int totalItems = pagingResult.getTotalResultCount().getFirst();
final String personId = AuthenticationUtil.getFullyAuthenticatedUser();
List<Person> people = new AbstractList<Person>()
{
List<Person> people = new AbstractList<Person>() {
@Override
public Person get(int index)
{
@@ -513,8 +510,7 @@ public class PeopleImpl implements People
processPersonProperties(personId, nodeProps);
// TODO this needs to be run as admin but should we do this here?
final String pId = personId;
Boolean enabled = AuthenticationUtil.runAsSystem(new RunAsWork<Boolean>()
{
Boolean enabled = AuthenticationUtil.runAsSystem(new RunAsWork<Boolean>() {
public Boolean doWork() throws Exception
{
return authenticationService.getAuthenticationEnabled(pId);
@@ -576,7 +572,7 @@ public class PeopleImpl implements People
{
validateCreatePersonData(person);
if (! isAdminAuthority())
if (!isAdminAuthority())
{
// note: do an explict check for admin here (since personExists does not throw 403 unlike createPerson,
// hence next block would cause 409 to be returned)
@@ -627,16 +623,14 @@ public class PeopleImpl implements People
}
/**
* Write the description to a content file and store the content URL in
* ContentModel.PROP_PERSONDESC
* Write the description to a content file and store the content URL in ContentModel.PROP_PERSONDESC
*
* @param description
* @param nodeRef
*/
private void savePersonDescription(final String description, final NodeRef nodeRef)
{
AuthenticationUtil.runAsSystem(new RunAsWork<Void>()
{
AuthenticationUtil.runAsSystem(new RunAsWork<Void>() {
@Override
public Void doWork() throws Exception
{
@@ -678,7 +672,7 @@ public class PeopleImpl implements People
{
if (username.toUpperCase().startsWith(prefix))
{
throw new IllegalArgumentException("Username cannot start with the reserved prefix '"+prefix+"'.");
throw new IllegalArgumentException("Username cannot start with the reserved prefix '" + prefix + "'.");
}
}
}
@@ -687,13 +681,13 @@ public class PeopleImpl implements People
{
if (fieldValue == null)
{
throw new InvalidArgumentException("Field '"+fieldName+"' is null, but is required.");
throw new InvalidArgumentException("Field '" + fieldName + "' is null, but is required.");
}
// belts-and-braces - note: should not see empty string (since converted to null via custom json deserializer)
if ((fieldValue instanceof String) && ((String)fieldValue).isEmpty())
if ((fieldValue instanceof String) && ((String) fieldValue).isEmpty())
{
throw new InvalidArgumentException("Field '"+fieldName+"' is empty, but is required.");
throw new InvalidArgumentException("Field '" + fieldName + "' is empty, but is required.");
}
}
@@ -766,11 +760,11 @@ public class PeopleImpl implements People
});
// The person service only allows admin users to set the properties by default.
if(!properties.isEmpty())
if (!properties.isEmpty())
{
AuthenticationUtil.runAsSystem(new RunAsWork<Void>()
{
@Override public Void doWork() throws Exception
AuthenticationUtil.runAsSystem(new RunAsWork<Void>() {
@Override
public Void doWork() throws Exception
{
personService.setPersonProperties(personIdToUpdate, properties, false);
return null;