mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
ACS-9023 Implement PUT method - Preferences API (#3075)
* ACS-9023 Implement PUT method - Preferences API * ACS-9023 Fix testUserPreferences * ACS-9023 Add override * ACS-9023 Update license header
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* Copyright (C) 2005 - 2024 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
@@ -23,14 +23,17 @@
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.rest.api;
|
||||
|
||||
import org.alfresco.rest.api.model.Preference;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
import org.alfresco.rest.framework.resource.parameters.Paging;
|
||||
|
||||
public interface Preferences
|
||||
{
|
||||
public Preference getPreference(String personId, String preferenceName);
|
||||
public CollectionWithPagingInfo<Preference> getPreferences(String personId, Paging paging);
|
||||
}
|
||||
package org.alfresco.rest.api;
|
||||
|
||||
import org.alfresco.rest.api.model.Preference;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
import org.alfresco.rest.framework.resource.parameters.Paging;
|
||||
|
||||
public interface Preferences
|
||||
{
|
||||
Preference getPreference(String personId, String preferenceName);
|
||||
|
||||
CollectionWithPagingInfo<Preference> getPreferences(String personId, Paging paging);
|
||||
|
||||
Preference updatePreference(String personId, Preference preference);
|
||||
}
|
||||
|
@@ -2,7 +2,7 @@
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* Copyright (C) 2005 - 2024 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
@@ -23,69 +23,92 @@
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.rest.api.impl;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.query.PagingResults;
|
||||
import org.alfresco.rest.api.People;
|
||||
import org.alfresco.rest.api.Preferences;
|
||||
import org.alfresco.rest.api.model.Preference;
|
||||
import org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
import org.alfresco.rest.framework.resource.parameters.Paging;
|
||||
import org.alfresco.service.cmr.preference.PreferenceService;
|
||||
import org.alfresco.util.Pair;
|
||||
|
||||
/**
|
||||
* Centralises access to preference services and maps between representations.
|
||||
*
|
||||
* @author steveglover
|
||||
* @since publicapi1.0
|
||||
*/
|
||||
public class PreferencesImpl implements Preferences
|
||||
{
|
||||
private People people;
|
||||
private PreferenceService preferenceService;
|
||||
|
||||
public void setPeople(People people)
|
||||
{
|
||||
this.people = people;
|
||||
}
|
||||
|
||||
public void setPreferenceService(PreferenceService preferenceService)
|
||||
{
|
||||
this.preferenceService = preferenceService;
|
||||
}
|
||||
|
||||
public Preference getPreference(String personId, String preferenceName)
|
||||
{
|
||||
personId = people.validatePerson(personId);
|
||||
Serializable preferenceValue = preferenceService.getPreference(personId, preferenceName);
|
||||
if(preferenceValue != null)
|
||||
{
|
||||
return new Preference(preferenceName, preferenceValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new RelationshipResourceNotFoundException(personId, preferenceName);
|
||||
}
|
||||
}
|
||||
|
||||
public CollectionWithPagingInfo<Preference> getPreferences(String personId, Paging paging)
|
||||
{
|
||||
personId = people.validatePerson(personId);
|
||||
|
||||
PagingResults<Pair<String, Serializable>> preferences = preferenceService.getPagedPreferences(personId, null, Util.getPagingRequest(paging));
|
||||
List<Preference> ret = new ArrayList<Preference>(preferences.getPage().size());
|
||||
for(Pair<String, Serializable> prefEntity : preferences.getPage())
|
||||
{
|
||||
Preference pref = new Preference(prefEntity.getFirst(), prefEntity.getSecond());
|
||||
ret.add(pref);
|
||||
}
|
||||
|
||||
return CollectionWithPagingInfo.asPaged(paging, ret, preferences.hasMoreItems(), preferences.getTotalResultCount().getFirst());
|
||||
}
|
||||
}
|
||||
package org.alfresco.rest.api.impl;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.query.PagingResults;
|
||||
import org.alfresco.rest.api.People;
|
||||
import org.alfresco.rest.api.Preferences;
|
||||
import org.alfresco.rest.api.model.Preference;
|
||||
import org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
import org.alfresco.rest.framework.resource.parameters.Paging;
|
||||
import org.alfresco.service.cmr.preference.PreferenceService;
|
||||
import org.alfresco.util.Pair;
|
||||
|
||||
/**
|
||||
* Centralises access to preference services and maps between representations.
|
||||
*
|
||||
* @author steveglover
|
||||
* @since publicapi1.0
|
||||
*/
|
||||
public class PreferencesImpl implements Preferences
|
||||
{
|
||||
private People people;
|
||||
private PreferenceService preferenceService;
|
||||
|
||||
public void setPeople(People people)
|
||||
{
|
||||
this.people = people;
|
||||
}
|
||||
|
||||
public void setPreferenceService(PreferenceService preferenceService)
|
||||
{
|
||||
this.preferenceService = preferenceService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Preference getPreference(String personId, String preferenceName)
|
||||
{
|
||||
personId = people.validatePerson(personId);
|
||||
Serializable preferenceValue = preferenceService.getPreference(personId, preferenceName);
|
||||
if (preferenceValue != null)
|
||||
{
|
||||
return new Preference(preferenceName, preferenceValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new RelationshipResourceNotFoundException(personId, preferenceName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CollectionWithPagingInfo<Preference> getPreferences(String personId, Paging paging)
|
||||
{
|
||||
personId = people.validatePerson(personId);
|
||||
|
||||
PagingResults<Pair<String, Serializable>> preferences = preferenceService.getPagedPreferences(personId, null, Util.getPagingRequest(paging));
|
||||
List<Preference> ret = new ArrayList<>(preferences.getPage().size());
|
||||
for (Pair<String, Serializable> prefEntity : preferences.getPage())
|
||||
{
|
||||
Preference pref = new Preference(prefEntity.getFirst(), prefEntity.getSecond());
|
||||
ret.add(pref);
|
||||
}
|
||||
|
||||
return CollectionWithPagingInfo.asPaged(paging, ret, preferences.hasMoreItems(), preferences.getTotalResultCount().getFirst());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Preference updatePreference(String personId, Preference preference)
|
||||
{
|
||||
personId = people.validatePerson(personId, true);
|
||||
final Map<String, Serializable> preferencesToSet;
|
||||
if (preference.getValue() == null || "".equals(preference.getValue()))
|
||||
{
|
||||
preferencesToSet = new HashMap<>(1);
|
||||
preferencesToSet.put(preference.getName(), null);
|
||||
}
|
||||
else
|
||||
{
|
||||
preferencesToSet = Map.of(preference.getName(), preference.getValue());
|
||||
}
|
||||
|
||||
preferenceService.setPreferences(personId, preferencesToSet);
|
||||
return new Preference(preference.getName(), preferenceService.getPreference(personId, preference.getName()));
|
||||
}
|
||||
}
|
||||
|
@@ -1,93 +1,105 @@
|
||||
/*
|
||||
* #%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 <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.rest.api.people;
|
||||
|
||||
import org.alfresco.rest.api.Preferences;
|
||||
import org.alfresco.rest.api.model.Preference;
|
||||
import org.alfresco.rest.framework.WebApiDescription;
|
||||
import org.alfresco.rest.framework.resource.RelationshipResource;
|
||||
import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
||||
import org.alfresco.util.ParameterCheck;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
|
||||
@RelationshipResource(name = "preferences", entityResource = PeopleEntityResource.class, title = "Person Preferences")
|
||||
public class PersonPreferencesRelation implements RelationshipResourceAction.Read<Preference>, RelationshipResourceAction.ReadById<Preference>, InitializingBean
|
||||
{
|
||||
private static final Log logger = LogFactory.getLog(PersonPreferencesRelation.class);
|
||||
|
||||
private Preferences preferences;
|
||||
|
||||
public void setPreferences(Preferences preferences)
|
||||
{
|
||||
this.preferences = preferences;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet()
|
||||
{
|
||||
ParameterCheck.mandatory("preferences", this.preferences);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a paged list of preferences for the user personId.
|
||||
*
|
||||
* If personId does not exist, NotFoundException (status 404).
|
||||
*
|
||||
* @see org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction.Read#readAll(java.lang.String, org.alfresco.rest.framework.resource.parameters.Parameters)
|
||||
*/
|
||||
@Override
|
||||
@WebApiDescription(title = "A paged list of the persons preferences.")
|
||||
public CollectionWithPagingInfo<Preference> readAll(String personId, Parameters parameters)
|
||||
{
|
||||
return preferences.getPreferences(personId, parameters.getPaging());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information regarding the preference 'preferenceName' for user personId.
|
||||
*
|
||||
* If personId does not exist, NotFoundException (status 404).
|
||||
*
|
||||
* @see org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction.ReadById#readById(String, String, org.alfresco.rest.framework.resource.parameters.Parameters)
|
||||
*/
|
||||
@Override
|
||||
@WebApiDescription(title = "Preference value for preference 'preferenceName' for person 'personId'.")
|
||||
public Preference readById(String personId, String preferenceName, Parameters parameters)
|
||||
{
|
||||
// fix for REPO-855
|
||||
String url = parameters.getRequest().getURL();
|
||||
if(url.matches(".*workspace://SpacesStore/.*")){
|
||||
preferenceName += url.substring(url.indexOf("//SpacesStore/"));
|
||||
}
|
||||
//
|
||||
|
||||
return preferences.getPreference(personId, preferenceName);
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2024 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 <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.rest.api.people;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
|
||||
import org.alfresco.rest.api.Preferences;
|
||||
import org.alfresco.rest.api.model.Preference;
|
||||
import org.alfresco.rest.framework.WebApiDescription;
|
||||
import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
|
||||
import org.alfresco.rest.framework.resource.RelationshipResource;
|
||||
import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
||||
import org.alfresco.util.ParameterCheck;
|
||||
|
||||
@RelationshipResource(name = "preferences", entityResource = PeopleEntityResource.class, title = "Person Preferences")
|
||||
public class PersonPreferencesRelation implements RelationshipResourceAction.Read<Preference>, RelationshipResourceAction.ReadById<Preference>, RelationshipResourceAction.Update<Preference>, InitializingBean
|
||||
{
|
||||
private static final Log logger = LogFactory.getLog(PersonPreferencesRelation.class);
|
||||
|
||||
private Preferences preferences;
|
||||
|
||||
public void setPreferences(Preferences preferences)
|
||||
{
|
||||
this.preferences = preferences;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet()
|
||||
{
|
||||
ParameterCheck.mandatory("preferences", this.preferences);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a paged list of preferences for the user personId.
|
||||
*
|
||||
* If personId does not exist, NotFoundException (status 404).
|
||||
*
|
||||
* @see org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction.Read#readAll(java.lang.String, org.alfresco.rest.framework.resource.parameters.Parameters)
|
||||
*/
|
||||
@Override
|
||||
@WebApiDescription(title = "A paged list of the persons preferences.")
|
||||
public CollectionWithPagingInfo<Preference> readAll(String personId, Parameters parameters)
|
||||
{
|
||||
return preferences.getPreferences(personId, parameters.getPaging());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information regarding the preference 'preferenceName' for user personId.
|
||||
*
|
||||
* If personId does not exist, NotFoundException (status 404).
|
||||
*
|
||||
* @see org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction.ReadById#readById(String, String, org.alfresco.rest.framework.resource.parameters.Parameters)
|
||||
*/
|
||||
@Override
|
||||
@WebApiDescription(title = "Preference value for preference 'preferenceName' for person 'personId'.")
|
||||
public Preference readById(String personId, String preferenceName, Parameters parameters)
|
||||
{
|
||||
// fix for REPO-855
|
||||
String url = parameters.getRequest().getURL();
|
||||
if (url.matches(".*workspace://SpacesStore/.*"))
|
||||
{
|
||||
preferenceName += url.substring(url.indexOf("//SpacesStore/"));
|
||||
}
|
||||
//
|
||||
|
||||
return preferences.getPreference(personId, preferenceName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Preference update(String personId, Preference preference, Parameters parameters)
|
||||
{
|
||||
if (preference.getName() == null || preference.getName().isBlank())
|
||||
{
|
||||
throw new InvalidArgumentException();
|
||||
}
|
||||
return preferences.updatePreference(personId, preference);
|
||||
}
|
||||
}
|
||||
|
@@ -2,7 +2,7 @@
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2020 Alfresco Software Limited
|
||||
* Copyright (C) 2005 - 2024 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
@@ -30,6 +30,15 @@ import java.io.InputStream;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
import org.springframework.extensions.webscripts.WrappingWebScriptRequest;
|
||||
import org.springframework.extensions.webscripts.servlet.WebScriptServletRequest;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.rest.framework.core.ResourceLocator;
|
||||
import org.alfresco.rest.framework.core.ResourceMetadata;
|
||||
@@ -47,14 +56,7 @@ import org.alfresco.rest.framework.resource.parameters.Params;
|
||||
import org.alfresco.rest.framework.resource.parameters.Params.RecognizedParams;
|
||||
import org.alfresco.rest.framework.tools.RecognizedParamsExtractor;
|
||||
import org.alfresco.rest.framework.tools.RequestReader;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
import org.springframework.extensions.webscripts.WrappingWebScriptRequest;
|
||||
import org.springframework.extensions.webscripts.servlet.WebScriptServletRequest;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
/**
|
||||
* Handles the HTTP PUT for a Resource, equivalent to CRUD Update
|
||||
*
|
||||
@@ -64,15 +66,15 @@ public class ResourceWebScriptPut extends AbstractResourceWebScript implements P
|
||||
RecognizedParamsExtractor, RequestReader
|
||||
{
|
||||
|
||||
private static Log logger = LogFactory.getLog(ResourceWebScriptPut.class);
|
||||
|
||||
private static final Log logger = LogFactory.getLog(ResourceWebScriptPut.class);
|
||||
|
||||
public ResourceWebScriptPut()
|
||||
{
|
||||
super();
|
||||
setHttpMethod(HttpMethod.PUT);
|
||||
setParamsExtractor(this);
|
||||
super();
|
||||
setHttpMethod(HttpMethod.PUT);
|
||||
setParamsExtractor(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Params extractParams(ResourceMetadata resourceMeta, WebScriptRequest req)
|
||||
{
|
||||
@@ -86,81 +88,87 @@ public class ResourceWebScriptPut extends AbstractResourceWebScript implements P
|
||||
|
||||
switch (resourceMeta.getType())
|
||||
{
|
||||
case ENTITY:
|
||||
if (StringUtils.isBlank(entityId))
|
||||
{
|
||||
throw new UnsupportedResourceOperationException("PUT is executed against the instance URL");
|
||||
} else
|
||||
{
|
||||
case ENTITY:
|
||||
if (StringUtils.isBlank(entityId))
|
||||
{
|
||||
throw new UnsupportedResourceOperationException("PUT is executed against the instance URL");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Object putEnt = extractJsonContent(req, assistant.getJsonHelper(), resourceMeta.getObjectType(operation));
|
||||
return Params.valueOf(entityId,params,putEnt, req);
|
||||
}
|
||||
case RELATIONSHIP:
|
||||
if (StringUtils.isBlank(relationshipId))
|
||||
Object putEnt = extractJsonContent(req, assistant.getJsonHelper(), resourceMeta.getObjectType(operation));
|
||||
return Params.valueOf(entityId, params, putEnt, req);
|
||||
}
|
||||
case RELATIONSHIP:
|
||||
if (StringUtils.isBlank(relationshipId))
|
||||
{
|
||||
throw new UnsupportedResourceOperationException("PUT is executed against the instance URL");
|
||||
}
|
||||
Object putRel = extractJsonContent(req, assistant.getJsonHelper(), resourceMeta.getObjectType(operation));
|
||||
if (StringUtils.isNotBlank(relationship2Id))
|
||||
{
|
||||
ResourceWebScriptHelper.setUniqueId(putRel, relationship2Id);
|
||||
return Params.valueOf(false, entityId, relationshipId, relationship2Id,
|
||||
putRel, null, null, params, null, req);
|
||||
}
|
||||
else
|
||||
{
|
||||
ResourceWebScriptHelper.setUniqueId(putRel, relationshipId);
|
||||
return Params.valueOf(entityId, relationshipId, params, putRel, req);
|
||||
}
|
||||
case PROPERTY:
|
||||
final String resourceName = resourceVars.get(ResourceLocator.RELATIONSHIP_RESOURCE);
|
||||
final String propertyName = resourceVars.get(ResourceLocator.PROPERTY);
|
||||
|
||||
if (StringUtils.isNotBlank(entityId) && StringUtils.isNotBlank(resourceName))
|
||||
{
|
||||
if (StringUtils.isNotBlank(propertyName))
|
||||
{
|
||||
throw new UnsupportedResourceOperationException("PUT is executed against the instance URL");
|
||||
}
|
||||
Object putRel = extractJsonContent(req, assistant.getJsonHelper(), resourceMeta.getObjectType(operation));
|
||||
if (StringUtils.isNotBlank(relationship2Id))
|
||||
{
|
||||
ResourceWebScriptHelper.setUniqueId(putRel, relationship2Id);
|
||||
return Params.valueOf(false, entityId, relationshipId, relationship2Id,
|
||||
putRel, null, null, params, null, req);
|
||||
return Params.valueOf(entityId, relationshipId, null, getStream(req), propertyName, params, getContentInfo(req), req);
|
||||
}
|
||||
else
|
||||
{
|
||||
ResourceWebScriptHelper.setUniqueId(putRel,relationshipId);
|
||||
return Params.valueOf(entityId, params, putRel, req);
|
||||
return Params.valueOf(entityId, null, null, getStream(req), resourceName, params, getContentInfo(req), req);
|
||||
}
|
||||
case PROPERTY:
|
||||
final String resourceName = resourceVars.get(ResourceLocator.RELATIONSHIP_RESOURCE);
|
||||
final String propertyName = resourceVars.get(ResourceLocator.PROPERTY);
|
||||
|
||||
if (StringUtils.isNotBlank(entityId) && StringUtils.isNotBlank(resourceName))
|
||||
{
|
||||
if (StringUtils.isNotBlank(propertyName))
|
||||
{
|
||||
return Params.valueOf(entityId, relationshipId, null, getStream(req), propertyName, params, getContentInfo(req), req);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Params.valueOf(entityId, null, null, getStream(req), resourceName, params, getContentInfo(req), req);
|
||||
}
|
||||
|
||||
}
|
||||
//Fall through to unsupported.
|
||||
default:
|
||||
throw new UnsupportedResourceOperationException("PUT not supported for this request.");
|
||||
}
|
||||
// Fall through to unsupported.
|
||||
default:
|
||||
throw new UnsupportedResourceOperationException("PUT not supported for this request.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Returns the basic content info from the request.
|
||||
* @param req WebScriptRequest
|
||||
*
|
||||
* @param req
|
||||
* WebScriptRequest
|
||||
* @return BasicContentInfo
|
||||
*/
|
||||
private BasicContentInfo getContentInfo(WebScriptRequest req) {
|
||||
|
||||
String encoding = "UTF-8";
|
||||
String contentType = MimetypeMap.MIMETYPE_BINARY;
|
||||
|
||||
if (StringUtils.isNotEmpty(req.getContentType()))
|
||||
{
|
||||
MediaType media = MediaType.parseMediaType(req.getContentType());
|
||||
contentType = media.getType()+'/'+media.getSubtype();
|
||||
if (media.getCharset() != null)
|
||||
{
|
||||
encoding = media.getCharset().toString();
|
||||
}
|
||||
}
|
||||
private BasicContentInfo getContentInfo(WebScriptRequest req)
|
||||
{
|
||||
|
||||
String encoding = "UTF-8";
|
||||
String contentType = MimetypeMap.MIMETYPE_BINARY;
|
||||
|
||||
if (StringUtils.isNotEmpty(req.getContentType()))
|
||||
{
|
||||
MediaType media = MediaType.parseMediaType(req.getContentType());
|
||||
contentType = media.getType() + '/' + media.getSubtype();
|
||||
if (media.getCharset() != null)
|
||||
{
|
||||
encoding = media.getCharset().toString();
|
||||
}
|
||||
}
|
||||
|
||||
return new ContentInfoImpl(contentType, encoding, -1, Locale.getDefault());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Returns the input stream for the request
|
||||
* @param req WebScriptRequest
|
||||
*
|
||||
* @param req
|
||||
* WebScriptRequest
|
||||
* @return InputStream
|
||||
*/
|
||||
private InputStream getStream(WebScriptRequest req)
|
||||
@@ -186,11 +194,14 @@ public class ResourceWebScriptPut extends AbstractResourceWebScript implements P
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Executes the action on the resource
|
||||
* @param resource ResourceWithMetadata
|
||||
* @param params parameters to use
|
||||
*
|
||||
* @param resource
|
||||
* ResourceWithMetadata
|
||||
* @param params
|
||||
* parameters to use
|
||||
* @return anObject the result of the execute
|
||||
*/
|
||||
@Override
|
||||
@@ -198,87 +209,87 @@ public class ResourceWebScriptPut extends AbstractResourceWebScript implements P
|
||||
{
|
||||
switch (resource.getMetaData().getType())
|
||||
{
|
||||
case ENTITY:
|
||||
if (EntityResourceAction.Update.class.isAssignableFrom(resource.getResource().getClass()))
|
||||
case ENTITY:
|
||||
if (EntityResourceAction.Update.class.isAssignableFrom(resource.getResource().getClass()))
|
||||
{
|
||||
if (resource.getMetaData().isDeleted(EntityResourceAction.Update.class))
|
||||
{
|
||||
if (resource.getMetaData().isDeleted(EntityResourceAction.Update.class))
|
||||
{
|
||||
throw new DeletedResourceException("(UPDATE) "+resource.getMetaData().getUniqueId());
|
||||
}
|
||||
EntityResourceAction.Update<Object> updateEnt = (EntityResourceAction.Update<Object>) resource.getResource();
|
||||
Object result = updateEnt.update(params.getEntityId(), params.getPassedIn(), params);
|
||||
return result;
|
||||
throw new DeletedResourceException("(UPDATE) " + resource.getMetaData().getUniqueId());
|
||||
}
|
||||
else
|
||||
EntityResourceAction.Update<Object> updateEnt = (EntityResourceAction.Update<Object>) resource.getResource();
|
||||
Object result = updateEnt.update(params.getEntityId(), params.getPassedIn(), params);
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (resource.getMetaData().isDeleted(EntityResourceAction.UpdateWithResponse.class))
|
||||
{
|
||||
if (resource.getMetaData().isDeleted(EntityResourceAction.UpdateWithResponse.class))
|
||||
{
|
||||
throw new DeletedResourceException("(UPDATE) "+resource.getMetaData().getUniqueId());
|
||||
}
|
||||
EntityResourceAction.UpdateWithResponse<Object> updateEnt = (EntityResourceAction.UpdateWithResponse<Object>) resource.getResource();
|
||||
Object result = updateEnt.update(params.getEntityId(), params.getPassedIn(), params, withResponse);
|
||||
return result;
|
||||
throw new DeletedResourceException("(UPDATE) " + resource.getMetaData().getUniqueId());
|
||||
}
|
||||
case RELATIONSHIP:
|
||||
if (RelationshipResourceAction.UpdateWithResponse.class.isAssignableFrom(resource.getResource().getClass()))
|
||||
EntityResourceAction.UpdateWithResponse<Object> updateEnt = (EntityResourceAction.UpdateWithResponse<Object>) resource.getResource();
|
||||
Object result = updateEnt.update(params.getEntityId(), params.getPassedIn(), params, withResponse);
|
||||
return result;
|
||||
}
|
||||
case RELATIONSHIP:
|
||||
if (RelationshipResourceAction.UpdateWithResponse.class.isAssignableFrom(resource.getResource().getClass()))
|
||||
{
|
||||
if (resource.getMetaData().isDeleted(RelationshipResourceAction.UpdateWithResponse.class))
|
||||
{
|
||||
if (resource.getMetaData().isDeleted(RelationshipResourceAction.UpdateWithResponse.class))
|
||||
{
|
||||
throw new DeletedResourceException("(UPDATE) "+resource.getMetaData().getUniqueId());
|
||||
}
|
||||
RelationshipResourceAction.UpdateWithResponse<Object> relationUpdater = (RelationshipResourceAction.UpdateWithResponse<Object>) resource.getResource();
|
||||
Object relResult = relationUpdater.update(params.getEntityId(), params.getPassedIn(), params, withResponse);
|
||||
return relResult;
|
||||
throw new DeletedResourceException("(UPDATE) " + resource.getMetaData().getUniqueId());
|
||||
}
|
||||
else
|
||||
RelationshipResourceAction.UpdateWithResponse<Object> relationUpdater = (RelationshipResourceAction.UpdateWithResponse<Object>) resource.getResource();
|
||||
Object relResult = relationUpdater.update(params.getEntityId(), params.getPassedIn(), params, withResponse);
|
||||
return relResult;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (resource.getMetaData().isDeleted(RelationshipResourceAction.Update.class))
|
||||
{
|
||||
if (resource.getMetaData().isDeleted(RelationshipResourceAction.Update.class))
|
||||
{
|
||||
throw new DeletedResourceException("(UPDATE) "+resource.getMetaData().getUniqueId());
|
||||
}
|
||||
RelationshipResourceAction.Update<Object> relationUpdater = (RelationshipResourceAction.Update<Object>) resource.getResource();
|
||||
Object relResult = relationUpdater.update(params.getEntityId(), params.getPassedIn(), params);
|
||||
return relResult;
|
||||
throw new DeletedResourceException("(UPDATE) " + resource.getMetaData().getUniqueId());
|
||||
}
|
||||
case PROPERTY:
|
||||
if (BinaryResourceAction.Update.class.isAssignableFrom(resource.getResource().getClass()))
|
||||
RelationshipResourceAction.Update<Object> relationUpdater = (RelationshipResourceAction.Update<Object>) resource.getResource();
|
||||
Object relResult = relationUpdater.update(params.getEntityId(), params.getPassedIn(), params);
|
||||
return relResult;
|
||||
}
|
||||
case PROPERTY:
|
||||
if (BinaryResourceAction.Update.class.isAssignableFrom(resource.getResource().getClass()))
|
||||
{
|
||||
if (resource.getMetaData().isDeleted(BinaryResourceAction.Update.class))
|
||||
{
|
||||
if (resource.getMetaData().isDeleted(BinaryResourceAction.Update.class))
|
||||
{
|
||||
throw new DeletedResourceException("(UPDATE) "+resource.getMetaData().getUniqueId());
|
||||
}
|
||||
BinaryResourceAction.Update<Object> binUpdater = (BinaryResourceAction.Update<Object>) resource.getResource();
|
||||
return binUpdater.updateProperty(params.getEntityId(), params.getContentInfo(), params.getStream(), params);
|
||||
throw new DeletedResourceException("(UPDATE) " + resource.getMetaData().getUniqueId());
|
||||
}
|
||||
if (BinaryResourceAction.UpdateWithResponse.class.isAssignableFrom(resource.getResource().getClass()))
|
||||
BinaryResourceAction.Update<Object> binUpdater = (BinaryResourceAction.Update<Object>) resource.getResource();
|
||||
return binUpdater.updateProperty(params.getEntityId(), params.getContentInfo(), params.getStream(), params);
|
||||
}
|
||||
if (BinaryResourceAction.UpdateWithResponse.class.isAssignableFrom(resource.getResource().getClass()))
|
||||
{
|
||||
if (resource.getMetaData().isDeleted(BinaryResourceAction.UpdateWithResponse.class))
|
||||
{
|
||||
if (resource.getMetaData().isDeleted(BinaryResourceAction.UpdateWithResponse.class))
|
||||
{
|
||||
throw new DeletedResourceException("(UPDATE) "+resource.getMetaData().getUniqueId());
|
||||
}
|
||||
BinaryResourceAction.UpdateWithResponse<Object> binUpdater = (BinaryResourceAction.UpdateWithResponse<Object>) resource.getResource();
|
||||
return binUpdater.updateProperty(params.getEntityId(), params.getContentInfo(), params.getStream(), params, withResponse);
|
||||
throw new DeletedResourceException("(UPDATE) " + resource.getMetaData().getUniqueId());
|
||||
}
|
||||
if (RelationshipResourceBinaryAction.Update.class.isAssignableFrom(resource.getResource().getClass()))
|
||||
BinaryResourceAction.UpdateWithResponse<Object> binUpdater = (BinaryResourceAction.UpdateWithResponse<Object>) resource.getResource();
|
||||
return binUpdater.updateProperty(params.getEntityId(), params.getContentInfo(), params.getStream(), params, withResponse);
|
||||
}
|
||||
if (RelationshipResourceBinaryAction.Update.class.isAssignableFrom(resource.getResource().getClass()))
|
||||
{
|
||||
if (resource.getMetaData().isDeleted(RelationshipResourceBinaryAction.Update.class))
|
||||
{
|
||||
if (resource.getMetaData().isDeleted(RelationshipResourceBinaryAction.Update.class))
|
||||
{
|
||||
throw new DeletedResourceException("(UPDATE) "+resource.getMetaData().getUniqueId());
|
||||
}
|
||||
RelationshipResourceBinaryAction.Update<Object> binUpdater = (RelationshipResourceBinaryAction.Update<Object>) resource.getResource();
|
||||
return binUpdater.updateProperty(params.getEntityId(), params.getRelationshipId(), params.getContentInfo(), params.getStream(), params);
|
||||
throw new DeletedResourceException("(UPDATE) " + resource.getMetaData().getUniqueId());
|
||||
}
|
||||
if (RelationshipResourceBinaryAction.UpdateWithResponse.class.isAssignableFrom(resource.getResource().getClass()))
|
||||
RelationshipResourceBinaryAction.Update<Object> binUpdater = (RelationshipResourceBinaryAction.Update<Object>) resource.getResource();
|
||||
return binUpdater.updateProperty(params.getEntityId(), params.getRelationshipId(), params.getContentInfo(), params.getStream(), params);
|
||||
}
|
||||
if (RelationshipResourceBinaryAction.UpdateWithResponse.class.isAssignableFrom(resource.getResource().getClass()))
|
||||
{
|
||||
if (resource.getMetaData().isDeleted(RelationshipResourceBinaryAction.UpdateWithResponse.class))
|
||||
{
|
||||
if (resource.getMetaData().isDeleted(RelationshipResourceBinaryAction.UpdateWithResponse.class))
|
||||
{
|
||||
throw new DeletedResourceException("(UPDATE) "+resource.getMetaData().getUniqueId());
|
||||
}
|
||||
RelationshipResourceBinaryAction.UpdateWithResponse<Object> binUpdater = (RelationshipResourceBinaryAction.UpdateWithResponse<Object>) resource.getResource();
|
||||
return binUpdater.updateProperty(params.getEntityId(), params.getRelationshipId(), params.getContentInfo(), params.getStream(), params, withResponse);
|
||||
throw new DeletedResourceException("(UPDATE) " + resource.getMetaData().getUniqueId());
|
||||
}
|
||||
default:
|
||||
throw new UnsupportedResourceOperationException("PUT not supported for Actions");
|
||||
RelationshipResourceBinaryAction.UpdateWithResponse<Object> binUpdater = (RelationshipResourceBinaryAction.UpdateWithResponse<Object>) resource.getResource();
|
||||
return binUpdater.updateProperty(params.getEntityId(), params.getRelationshipId(), params.getContentInfo(), params.getStream(), params, withResponse);
|
||||
}
|
||||
default:
|
||||
throw new UnsupportedResourceOperationException("PUT not supported for Actions");
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,416 +1,411 @@
|
||||
/*
|
||||
* #%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 <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.rest.api.tests;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import org.alfresco.repo.tenant.TenantUtil;
|
||||
import org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork;
|
||||
import org.alfresco.rest.api.tests.RepoService.TestNetwork;
|
||||
import org.alfresco.rest.api.tests.RepoService.TestPerson;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiClient.Paging;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiClient.People;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiException;
|
||||
import org.alfresco.rest.api.tests.client.RequestContext;
|
||||
import org.alfresco.rest.api.tests.client.data.Preference;
|
||||
import org.alfresco.util.GUID;
|
||||
import org.apache.commons.httpclient.HttpStatus;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestUserPreferences extends EnterpriseTestApi
|
||||
{
|
||||
@Test
|
||||
public void testUserPreferences() throws Exception
|
||||
{
|
||||
Iterator<TestNetwork> networksIt = getTestFixture().getNetworksIt();
|
||||
assertTrue(networksIt.hasNext());
|
||||
final TestNetwork network1 = networksIt.next();
|
||||
assertTrue(networksIt.hasNext());
|
||||
final TestNetwork network2 = networksIt.next();
|
||||
|
||||
final List<TestPerson> people = new ArrayList<TestPerson>(3);
|
||||
|
||||
// create users and some preferences
|
||||
TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void doWork() throws Exception
|
||||
{
|
||||
TestPerson person = network1.createUser();
|
||||
people.add(person);
|
||||
person = network1.createUser();
|
||||
people.add(person);
|
||||
return null;
|
||||
}
|
||||
}, network1.getId());
|
||||
|
||||
TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void doWork() throws Exception
|
||||
{
|
||||
TestPerson person = network2.createUser();
|
||||
people.add(person);
|
||||
return null;
|
||||
}
|
||||
}, network2.getId());
|
||||
|
||||
final TestPerson person1 = people.get(0);
|
||||
final TestPerson person2 = people.get(1);
|
||||
final TestPerson person3 = people.get(2);
|
||||
|
||||
final List<Preference> expectedPreferences = new ArrayList<Preference>();
|
||||
expectedPreferences.add(new Preference("org.alfresco.share.documentList.testPreference2", String.valueOf(true)));
|
||||
expectedPreferences.add(new Preference("org.alfresco.share.documentList.testPreference1", String.valueOf(true)));
|
||||
expectedPreferences.add(new Preference("org.alfresco.share.documentList.sortAscending", String.valueOf(true)));
|
||||
expectedPreferences.add(new Preference("org.alfresco.share.documentList.testPreference3", String.valueOf(true)));
|
||||
// new preference name for issue REPO-855
|
||||
expectedPreferences.add(new Preference("org.alfresco.ext.folders.favourites.workspace://SpacesStore/4e3d0779-388a-4b94-91e1-eab588a7da3d.createdAt", String.valueOf(true)));
|
||||
|
||||
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void doWork() throws Exception
|
||||
{
|
||||
for(Preference pref : expectedPreferences)
|
||||
{
|
||||
// TODO add preferences thru api
|
||||
repoService.addPreference(person1.getId(), pref.getId(), pref.getValue());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}, person1.getId(), network1.getId());
|
||||
|
||||
Collections.sort(expectedPreferences);
|
||||
|
||||
People peopleProxy = publicApiClient.people();
|
||||
|
||||
// GET preferences
|
||||
// Test case: cloud-1492
|
||||
|
||||
// unknown user
|
||||
try
|
||||
{
|
||||
int skipCount = 0;
|
||||
int maxItems = 2;
|
||||
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
|
||||
Paging paging = getPaging(skipCount, maxItems, expectedPreferences.size(), expectedPreferences.size());
|
||||
peopleProxy.getPreferences(GUID.generate(), createParams(paging, null));
|
||||
|
||||
fail();
|
||||
}
|
||||
catch(PublicApiException e)
|
||||
{
|
||||
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
|
||||
}
|
||||
|
||||
// test paging
|
||||
{
|
||||
int skipCount = 0;
|
||||
int maxItems = 2;
|
||||
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
|
||||
Paging paging = getPaging(skipCount, maxItems, expectedPreferences.size(), expectedPreferences.size());
|
||||
ListResponse<Preference> resp = peopleProxy.getPreferences(person1.getId(), createParams(paging, null));
|
||||
checkList(expectedPreferences.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
|
||||
}
|
||||
|
||||
{
|
||||
int skipCount = 2;
|
||||
int maxItems = 10;
|
||||
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
|
||||
Paging paging = getPaging(skipCount, maxItems, expectedPreferences.size(), expectedPreferences.size());
|
||||
ListResponse<Preference> resp = peopleProxy.getPreferences(person1.getId(), createParams(paging, null));
|
||||
checkList(expectedPreferences.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
|
||||
}
|
||||
|
||||
// "-me-" user
|
||||
{
|
||||
int skipCount = 0;
|
||||
int maxItems = 2;
|
||||
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
|
||||
Paging paging = getPaging(skipCount, maxItems, expectedPreferences.size(), expectedPreferences.size());
|
||||
ListResponse<Preference> resp = peopleProxy.getPreferences(org.alfresco.rest.api.People.DEFAULT_USER, createParams(paging, null));
|
||||
checkList(expectedPreferences.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
|
||||
}
|
||||
|
||||
// invalid user - 404
|
||||
try
|
||||
{
|
||||
int skipCount = 2;
|
||||
int maxItems = 10;
|
||||
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
|
||||
Paging paging = getPaging(skipCount, maxItems, expectedPreferences.size(), expectedPreferences.size());
|
||||
peopleProxy.getPreferences("invalid.user", createParams(paging, null));
|
||||
fail("");
|
||||
}
|
||||
catch(PublicApiException e)
|
||||
{
|
||||
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
|
||||
}
|
||||
|
||||
// user from another account - 401
|
||||
try
|
||||
{
|
||||
int skipCount = 0;
|
||||
int maxItems = 2;
|
||||
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person3.getId()));
|
||||
Paging paging = getPaging(skipCount, maxItems, expectedPreferences.size(), expectedPreferences.size());
|
||||
// ListResponse<Preference> resp = peopleProxy.getPreferences(person1.getId(), createParams(paging, null));
|
||||
// checkList(expectedPreferences.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
|
||||
peopleProxy.getPreferences(person1.getId(), createParams(paging, null));
|
||||
fail();
|
||||
}
|
||||
catch(PublicApiException e)
|
||||
{
|
||||
assertEquals(e.getHttpResponse().getStatusCode(), HttpStatus.SC_UNAUTHORIZED);
|
||||
}
|
||||
|
||||
// another user from the same account - 403
|
||||
try
|
||||
{
|
||||
int skipCount = 0;
|
||||
int maxItems = 2;
|
||||
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
|
||||
Paging paging = getPaging(skipCount, maxItems, expectedPreferences.size(), expectedPreferences.size());
|
||||
peopleProxy.getPreferences(person1.getId(), createParams(paging, null));
|
||||
fail();
|
||||
}
|
||||
catch(PublicApiException e)
|
||||
{
|
||||
assertEquals(HttpStatus.SC_FORBIDDEN, e.getHttpResponse().getStatusCode());
|
||||
}
|
||||
|
||||
// get a single preference
|
||||
// Test Case: cloud-1493
|
||||
|
||||
{
|
||||
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
|
||||
Preference pref = expectedPreferences.get(0);
|
||||
Preference ret = peopleProxy.getPreference(person1.getId(), pref.getId());
|
||||
pref.expected(ret);
|
||||
}
|
||||
|
||||
// unknown person id
|
||||
try
|
||||
{
|
||||
Preference pref = expectedPreferences.get(0);
|
||||
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
|
||||
peopleProxy.getPreference(GUID.generate(), pref.getId());
|
||||
fail();
|
||||
}
|
||||
catch(PublicApiException e)
|
||||
{
|
||||
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
|
||||
}
|
||||
|
||||
// unknown preference id
|
||||
try
|
||||
{
|
||||
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
|
||||
peopleProxy.getPreference(person1.getId(), GUID.generate());
|
||||
fail();
|
||||
}
|
||||
catch(PublicApiException e)
|
||||
{
|
||||
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
|
||||
}
|
||||
|
||||
// Invalid methods
|
||||
// Test case: cloud-1968
|
||||
try
|
||||
{
|
||||
Preference pref = expectedPreferences.get(0);
|
||||
|
||||
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
|
||||
peopleProxy.create("people", person1.getId(), "preferences", pref.getId(), pref.toJSON().toString(), "Unable to POST to a preference");
|
||||
fail();
|
||||
}
|
||||
catch(PublicApiException e)
|
||||
{
|
||||
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Preference pref = expectedPreferences.get(0);
|
||||
|
||||
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
|
||||
peopleProxy.update("people", person1.getId(), "preferences", pref.getId(), pref.toJSON().toString(), "Unable to PUT a preference");
|
||||
fail();
|
||||
}
|
||||
catch(PublicApiException e)
|
||||
{
|
||||
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Preference pref = expectedPreferences.get(0);
|
||||
|
||||
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
|
||||
peopleProxy.remove("people", person1.getId(), "preferences", pref.getId(), "Unable to DELETE a preference");
|
||||
fail();
|
||||
}
|
||||
catch(PublicApiException e)
|
||||
{
|
||||
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Preference pref = expectedPreferences.get(0);
|
||||
|
||||
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
|
||||
peopleProxy.create("people", person1.getId(), "preferences", null, pref.toJSON().toString(), "Unable to POST to preferences");
|
||||
fail();
|
||||
}
|
||||
catch(PublicApiException e)
|
||||
{
|
||||
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Preference pref = expectedPreferences.get(0);
|
||||
|
||||
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
|
||||
peopleProxy.update("people", person1.getId(), "preferences", null, pref.toJSON().toString(), "Unable to PUT preferences");
|
||||
fail();
|
||||
}
|
||||
catch(PublicApiException e)
|
||||
{
|
||||
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
|
||||
peopleProxy.remove("people", person1.getId(), "preferences", null, "Unable to DELETE preferences");
|
||||
fail();
|
||||
}
|
||||
catch(PublicApiException e)
|
||||
{
|
||||
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
|
||||
}
|
||||
|
||||
{
|
||||
// REPO-1061, REPO-890
|
||||
try
|
||||
{
|
||||
String skipCount = "a";
|
||||
String maxItems = "hi";
|
||||
HashMap<String, String> params = new HashMap<String, String>();
|
||||
params.put("skipCount", skipCount);
|
||||
params.put("maxItems", maxItems);
|
||||
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
|
||||
peopleProxy.getPreferences(person1.getId(), params);
|
||||
fail();
|
||||
}
|
||||
catch (PublicApiException e)
|
||||
{
|
||||
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
String skipCount = "a";
|
||||
String maxItems = "null";
|
||||
HashMap<String, String> params = new HashMap<String, String>();
|
||||
params.put("skipCount", skipCount);
|
||||
params.put("maxItems", maxItems);
|
||||
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
|
||||
peopleProxy.getPreferences(person1.getId(), params);
|
||||
fail();
|
||||
}
|
||||
catch (PublicApiException e)
|
||||
{
|
||||
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
String maxItems = "Red";
|
||||
HashMap<String, String> params = new HashMap<String, String>();
|
||||
params.put("maxItems", maxItems);
|
||||
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
|
||||
peopleProxy.getPreferences(person1.getId(), params);
|
||||
fail();
|
||||
}
|
||||
catch (PublicApiException e)
|
||||
{
|
||||
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
String skipCount = "yuck";
|
||||
HashMap<String, String> params = new HashMap<String, String>();
|
||||
params.put("skipCount", skipCount);
|
||||
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
|
||||
peopleProxy.getPreferences(person1.getId(), params);
|
||||
fail();
|
||||
}
|
||||
catch (PublicApiException e)
|
||||
{
|
||||
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
String skipCount = "-1";
|
||||
HashMap<String, String> params = new HashMap<String, String>();
|
||||
params.put("skipCount", skipCount);
|
||||
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
|
||||
peopleProxy.getPreferences(person1.getId(), params);
|
||||
fail();
|
||||
}
|
||||
catch (PublicApiException e)
|
||||
{
|
||||
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
String maxItems = "0";
|
||||
HashMap<String, String> params = new HashMap<String, String>();
|
||||
params.put("maxItems", maxItems);
|
||||
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
|
||||
peopleProxy.getPreferences(person1.getId(), params);
|
||||
fail();
|
||||
}
|
||||
catch (PublicApiException e)
|
||||
{
|
||||
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2024 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 <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.rest.api.tests;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import org.apache.commons.httpclient.HttpStatus;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.alfresco.repo.tenant.TenantUtil;
|
||||
import org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork;
|
||||
import org.alfresco.rest.api.tests.RepoService.TestNetwork;
|
||||
import org.alfresco.rest.api.tests.RepoService.TestPerson;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiClient.Paging;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiClient.People;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiException;
|
||||
import org.alfresco.rest.api.tests.client.RequestContext;
|
||||
import org.alfresco.rest.api.tests.client.data.Preference;
|
||||
import org.alfresco.util.GUID;
|
||||
|
||||
public class TestUserPreferences extends EnterpriseTestApi
|
||||
{
|
||||
@Test
|
||||
public void testUserPreferences() throws Exception
|
||||
{
|
||||
Iterator<TestNetwork> networksIt = getTestFixture().getNetworksIt();
|
||||
assertTrue(networksIt.hasNext());
|
||||
final TestNetwork network1 = networksIt.next();
|
||||
assertTrue(networksIt.hasNext());
|
||||
final TestNetwork network2 = networksIt.next();
|
||||
|
||||
final List<TestPerson> people = new ArrayList<TestPerson>(3);
|
||||
|
||||
// create users and some preferences
|
||||
TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>() {
|
||||
@Override
|
||||
public Void doWork() throws Exception
|
||||
{
|
||||
TestPerson person = network1.createUser();
|
||||
people.add(person);
|
||||
person = network1.createUser();
|
||||
people.add(person);
|
||||
return null;
|
||||
}
|
||||
}, network1.getId());
|
||||
|
||||
TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>() {
|
||||
@Override
|
||||
public Void doWork() throws Exception
|
||||
{
|
||||
TestPerson person = network2.createUser();
|
||||
people.add(person);
|
||||
return null;
|
||||
}
|
||||
}, network2.getId());
|
||||
|
||||
final TestPerson person1 = people.get(0);
|
||||
final TestPerson person2 = people.get(1);
|
||||
final TestPerson person3 = people.get(2);
|
||||
|
||||
final List<Preference> expectedPreferences = new ArrayList<Preference>();
|
||||
expectedPreferences.add(new Preference("org.alfresco.share.documentList.testPreference2", String.valueOf(true)));
|
||||
expectedPreferences.add(new Preference("org.alfresco.share.documentList.testPreference1", String.valueOf(true)));
|
||||
expectedPreferences.add(new Preference("org.alfresco.share.documentList.sortAscending", String.valueOf(true)));
|
||||
expectedPreferences.add(new Preference("org.alfresco.share.documentList.testPreference3", String.valueOf(true)));
|
||||
// new preference name for issue REPO-855
|
||||
expectedPreferences.add(new Preference("org.alfresco.ext.folders.favourites.workspace://SpacesStore/4e3d0779-388a-4b94-91e1-eab588a7da3d.createdAt", String.valueOf(true)));
|
||||
|
||||
TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() {
|
||||
@Override
|
||||
public Void doWork() throws Exception
|
||||
{
|
||||
for (Preference pref : expectedPreferences)
|
||||
{
|
||||
// TODO add preferences thru api
|
||||
repoService.addPreference(person1.getId(), pref.getId(), pref.getValue());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}, person1.getId(), network1.getId());
|
||||
|
||||
Collections.sort(expectedPreferences);
|
||||
|
||||
People peopleProxy = publicApiClient.people();
|
||||
|
||||
// GET preferences
|
||||
// Test case: cloud-1492
|
||||
|
||||
// unknown user
|
||||
try
|
||||
{
|
||||
int skipCount = 0;
|
||||
int maxItems = 2;
|
||||
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
|
||||
Paging paging = getPaging(skipCount, maxItems, expectedPreferences.size(), expectedPreferences.size());
|
||||
peopleProxy.getPreferences(GUID.generate(), createParams(paging, null));
|
||||
|
||||
fail();
|
||||
}
|
||||
catch (PublicApiException e)
|
||||
{
|
||||
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
|
||||
}
|
||||
|
||||
// test paging
|
||||
{
|
||||
int skipCount = 0;
|
||||
int maxItems = 2;
|
||||
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
|
||||
Paging paging = getPaging(skipCount, maxItems, expectedPreferences.size(), expectedPreferences.size());
|
||||
ListResponse<Preference> resp = peopleProxy.getPreferences(person1.getId(), createParams(paging, null));
|
||||
checkList(expectedPreferences.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
|
||||
}
|
||||
|
||||
{
|
||||
int skipCount = 2;
|
||||
int maxItems = 10;
|
||||
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
|
||||
Paging paging = getPaging(skipCount, maxItems, expectedPreferences.size(), expectedPreferences.size());
|
||||
ListResponse<Preference> resp = peopleProxy.getPreferences(person1.getId(), createParams(paging, null));
|
||||
checkList(expectedPreferences.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
|
||||
}
|
||||
|
||||
// "-me-" user
|
||||
{
|
||||
int skipCount = 0;
|
||||
int maxItems = 2;
|
||||
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
|
||||
Paging paging = getPaging(skipCount, maxItems, expectedPreferences.size(), expectedPreferences.size());
|
||||
ListResponse<Preference> resp = peopleProxy.getPreferences(org.alfresco.rest.api.People.DEFAULT_USER, createParams(paging, null));
|
||||
checkList(expectedPreferences.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
|
||||
}
|
||||
|
||||
// invalid user - 404
|
||||
try
|
||||
{
|
||||
int skipCount = 2;
|
||||
int maxItems = 10;
|
||||
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
|
||||
Paging paging = getPaging(skipCount, maxItems, expectedPreferences.size(), expectedPreferences.size());
|
||||
peopleProxy.getPreferences("invalid.user", createParams(paging, null));
|
||||
fail("");
|
||||
}
|
||||
catch (PublicApiException e)
|
||||
{
|
||||
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
|
||||
}
|
||||
|
||||
// user from another account - 401
|
||||
try
|
||||
{
|
||||
int skipCount = 0;
|
||||
int maxItems = 2;
|
||||
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person3.getId()));
|
||||
Paging paging = getPaging(skipCount, maxItems, expectedPreferences.size(), expectedPreferences.size());
|
||||
// ListResponse<Preference> resp = peopleProxy.getPreferences(person1.getId(), createParams(paging, null));
|
||||
// checkList(expectedPreferences.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), resp);
|
||||
peopleProxy.getPreferences(person1.getId(), createParams(paging, null));
|
||||
fail();
|
||||
}
|
||||
catch (PublicApiException e)
|
||||
{
|
||||
assertEquals(e.getHttpResponse().getStatusCode(), HttpStatus.SC_UNAUTHORIZED);
|
||||
}
|
||||
|
||||
// another user from the same account - 403
|
||||
try
|
||||
{
|
||||
int skipCount = 0;
|
||||
int maxItems = 2;
|
||||
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
|
||||
Paging paging = getPaging(skipCount, maxItems, expectedPreferences.size(), expectedPreferences.size());
|
||||
peopleProxy.getPreferences(person1.getId(), createParams(paging, null));
|
||||
fail();
|
||||
}
|
||||
catch (PublicApiException e)
|
||||
{
|
||||
assertEquals(HttpStatus.SC_FORBIDDEN, e.getHttpResponse().getStatusCode());
|
||||
}
|
||||
|
||||
// get a single preference
|
||||
// Test Case: cloud-1493
|
||||
|
||||
{
|
||||
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
|
||||
Preference pref = expectedPreferences.get(0);
|
||||
Preference ret = peopleProxy.getPreference(person1.getId(), pref.getId());
|
||||
pref.expected(ret);
|
||||
}
|
||||
|
||||
// unknown person id
|
||||
try
|
||||
{
|
||||
Preference pref = expectedPreferences.get(0);
|
||||
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId()));
|
||||
peopleProxy.getPreference(GUID.generate(), pref.getId());
|
||||
fail();
|
||||
}
|
||||
catch (PublicApiException e)
|
||||
{
|
||||
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
|
||||
}
|
||||
|
||||
// unknown preference id
|
||||
try
|
||||
{
|
||||
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
|
||||
peopleProxy.getPreference(person1.getId(), GUID.generate());
|
||||
fail();
|
||||
}
|
||||
catch (PublicApiException e)
|
||||
{
|
||||
assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode());
|
||||
}
|
||||
|
||||
// Invalid methods
|
||||
// Test case: cloud-1968
|
||||
try
|
||||
{
|
||||
Preference pref = expectedPreferences.get(0);
|
||||
|
||||
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
|
||||
peopleProxy.create("people", person1.getId(), "preferences", pref.getId(), pref.toJSON().toString(), "Unable to POST to a preference");
|
||||
fail();
|
||||
}
|
||||
catch (PublicApiException e)
|
||||
{
|
||||
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
|
||||
}
|
||||
|
||||
{
|
||||
Preference updatedPref = new Preference("preference.to.update", "updated.value");
|
||||
|
||||
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
|
||||
Preference response = peopleProxy.updatePreference(person1.getId(), updatedPref);
|
||||
|
||||
assertEquals(updatedPref.getId(), response.getId());
|
||||
assertEquals(updatedPref.getValue(), response.getValue());
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Preference pref = expectedPreferences.get(0);
|
||||
|
||||
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
|
||||
peopleProxy.remove("people", person1.getId(), "preferences", pref.getId(), "Unable to DELETE a preference");
|
||||
fail();
|
||||
}
|
||||
catch (PublicApiException e)
|
||||
{
|
||||
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Preference pref = expectedPreferences.get(0);
|
||||
|
||||
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
|
||||
peopleProxy.create("people", person1.getId(), "preferences", null, pref.toJSON().toString(), "Unable to POST to preferences");
|
||||
fail();
|
||||
}
|
||||
catch (PublicApiException e)
|
||||
{
|
||||
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Preference pref = expectedPreferences.get(0);
|
||||
|
||||
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
|
||||
peopleProxy.update("people", person1.getId(), "preferences", null, pref.toJSON().toString(), "Unable to PUT preferences");
|
||||
fail();
|
||||
}
|
||||
catch (PublicApiException e)
|
||||
{
|
||||
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
|
||||
peopleProxy.remove("people", person1.getId(), "preferences", null, "Unable to DELETE preferences");
|
||||
fail();
|
||||
}
|
||||
catch (PublicApiException e)
|
||||
{
|
||||
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
|
||||
}
|
||||
|
||||
{
|
||||
// REPO-1061, REPO-890
|
||||
try
|
||||
{
|
||||
String skipCount = "a";
|
||||
String maxItems = "hi";
|
||||
HashMap<String, String> params = new HashMap<String, String>();
|
||||
params.put("skipCount", skipCount);
|
||||
params.put("maxItems", maxItems);
|
||||
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
|
||||
peopleProxy.getPreferences(person1.getId(), params);
|
||||
fail();
|
||||
}
|
||||
catch (PublicApiException e)
|
||||
{
|
||||
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
String skipCount = "a";
|
||||
String maxItems = "null";
|
||||
HashMap<String, String> params = new HashMap<String, String>();
|
||||
params.put("skipCount", skipCount);
|
||||
params.put("maxItems", maxItems);
|
||||
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
|
||||
peopleProxy.getPreferences(person1.getId(), params);
|
||||
fail();
|
||||
}
|
||||
catch (PublicApiException e)
|
||||
{
|
||||
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
String maxItems = "Red";
|
||||
HashMap<String, String> params = new HashMap<String, String>();
|
||||
params.put("maxItems", maxItems);
|
||||
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
|
||||
peopleProxy.getPreferences(person1.getId(), params);
|
||||
fail();
|
||||
}
|
||||
catch (PublicApiException e)
|
||||
{
|
||||
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
String skipCount = "yuck";
|
||||
HashMap<String, String> params = new HashMap<String, String>();
|
||||
params.put("skipCount", skipCount);
|
||||
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
|
||||
peopleProxy.getPreferences(person1.getId(), params);
|
||||
fail();
|
||||
}
|
||||
catch (PublicApiException e)
|
||||
{
|
||||
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
String skipCount = "-1";
|
||||
HashMap<String, String> params = new HashMap<String, String>();
|
||||
params.put("skipCount", skipCount);
|
||||
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
|
||||
peopleProxy.getPreferences(person1.getId(), params);
|
||||
fail();
|
||||
}
|
||||
catch (PublicApiException e)
|
||||
{
|
||||
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
String maxItems = "0";
|
||||
HashMap<String, String> params = new HashMap<String, String>();
|
||||
params.put("maxItems", maxItems);
|
||||
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId()));
|
||||
peopleProxy.getPreferences(person1.getId(), params);
|
||||
fail();
|
||||
}
|
||||
catch (PublicApiException e)
|
||||
{
|
||||
assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user