mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged FILE-FOLDER-API (5.2.0) to HEAD (5.2)
122518 gjames: RA-211: Added the webscriptrequest to the Params interface git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@126477 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -66,7 +66,7 @@ public class NetworkWebScriptGet extends ApiWebScript
|
|||||||
{
|
{
|
||||||
// TODO this is not ideal, but the only way to populate the embedded network entities (this would normally be
|
// TODO this is not ideal, but the only way to populate the embedded network entities (this would normally be
|
||||||
// done automatically by the api framework).
|
// done automatically by the api framework).
|
||||||
Object wrapped = helper.processAdditionsToTheResponse(Api.ALFRESCO_PUBLIC, NetworksEntityResource.NAME, Params.valueOf(personId, null), networkMembership);
|
Object wrapped = helper.processAdditionsToTheResponse(Api.ALFRESCO_PUBLIC, NetworksEntityResource.NAME, Params.valueOf(personId, null, req), networkMembership);
|
||||||
|
|
||||||
objectMapper.writeValue(generator, wrapped);
|
objectMapper.writeValue(generator, wrapped);
|
||||||
}
|
}
|
||||||
|
@@ -95,7 +95,7 @@ public class NetworksWebScriptGet extends ApiWebScript
|
|||||||
{
|
{
|
||||||
// TODO this is not ideal, but the only way to populate the embedded network entities (this would normally be
|
// TODO this is not ideal, but the only way to populate the embedded network entities (this would normally be
|
||||||
// done automatically by the api framework).
|
// done automatically by the api framework).
|
||||||
Object wrapped = helper.processAdditionsToTheResponse(Api.ALFRESCO_PUBLIC, NetworksEntityResource.NAME, Params.valueOf(personId, null), networkMember);
|
Object wrapped = helper.processAdditionsToTheResponse(Api.ALFRESCO_PUBLIC, NetworksEntityResource.NAME, Params.valueOf(personId, null, req), networkMember);
|
||||||
entities.add(wrapped);
|
entities.add(wrapped);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -8,6 +8,7 @@ import org.alfresco.rest.framework.resource.content.BasicContentInfo;
|
|||||||
import org.alfresco.rest.framework.resource.parameters.where.Query;
|
import org.alfresco.rest.framework.resource.parameters.where.Query;
|
||||||
import org.apache.poi.ss.formula.functions.T;
|
import org.apache.poi.ss.formula.functions.T;
|
||||||
import org.springframework.extensions.webscripts.Status;
|
import org.springframework.extensions.webscripts.Status;
|
||||||
|
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -91,5 +92,11 @@ public interface Parameters
|
|||||||
* Gets the basic information about content, typically taken from a HTTPServletRequest.
|
* Gets the basic information about content, typically taken from a HTTPServletRequest.
|
||||||
* @return BasicContentInfo the content info
|
* @return BasicContentInfo the content info
|
||||||
*/
|
*/
|
||||||
BasicContentInfo getContentInfo();
|
public BasicContentInfo getContentInfo();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets access to the entire webscript request.
|
||||||
|
* @return WebScriptRequest
|
||||||
|
*/
|
||||||
|
public WebScriptRequest getRequest();
|
||||||
}
|
}
|
||||||
|
@@ -14,7 +14,7 @@ import org.alfresco.rest.framework.resource.parameters.where.Query;
|
|||||||
import org.alfresco.rest.framework.resource.parameters.where.QueryImpl;
|
import org.alfresco.rest.framework.resource.parameters.where.QueryImpl;
|
||||||
import org.apache.commons.beanutils.ConvertUtils;
|
import org.apache.commons.beanutils.ConvertUtils;
|
||||||
import org.apache.poi.ss.formula.functions.T;
|
import org.apache.poi.ss.formula.functions.T;
|
||||||
import org.springframework.extensions.webscripts.Status;
|
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parameters passed in from a Rest client for use in calls to the rest api.
|
* Parameters passed in from a Rest client for use in calls to the rest api.
|
||||||
@@ -30,12 +30,13 @@ public class Params implements Parameters
|
|||||||
private final RecognizedParams recognizedParams;
|
private final RecognizedParams recognizedParams;
|
||||||
private final String addressedProperty;
|
private final String addressedProperty;
|
||||||
private final BasicContentInfo contentInfo;
|
private final BasicContentInfo contentInfo;
|
||||||
|
private final WebScriptRequest request;
|
||||||
|
|
||||||
//Constants
|
//Constants
|
||||||
private static final RecognizedParams NULL_PARAMS = new RecognizedParams(null, null, null, null, null, null, null, false);
|
private static final RecognizedParams NULL_PARAMS = new RecognizedParams(null, null, null, null, null, null, null, false);
|
||||||
private static final BasicContentInfo DEFAULT_CONTENT_INFO = new ContentInfoImpl(MimetypeMap.MIMETYPE_BINARY, "UTF-8", -1, null);
|
private static final BasicContentInfo DEFAULT_CONTENT_INFO = new ContentInfoImpl(MimetypeMap.MIMETYPE_BINARY, "UTF-8", -1, null);
|
||||||
|
|
||||||
protected Params(String entityId, String relationshipId, Object passedIn, InputStream stream, String addressedProperty, RecognizedParams recognizedParams, BasicContentInfo contentInfo)
|
protected Params(String entityId, String relationshipId, Object passedIn, InputStream stream, String addressedProperty, RecognizedParams recognizedParams, BasicContentInfo contentInfo, WebScriptRequest request)
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
this.entityId = entityId;
|
this.entityId = entityId;
|
||||||
@@ -44,37 +45,39 @@ public class Params implements Parameters
|
|||||||
this.stream = stream;
|
this.stream = stream;
|
||||||
this.recognizedParams = recognizedParams;
|
this.recognizedParams = recognizedParams;
|
||||||
this.addressedProperty = addressedProperty;
|
this.addressedProperty = addressedProperty;
|
||||||
|
this.request = request;
|
||||||
this.contentInfo = contentInfo==null?DEFAULT_CONTENT_INFO:contentInfo;
|
this.contentInfo = contentInfo==null?DEFAULT_CONTENT_INFO:contentInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Params valueOf(BeanPropertiesFilter paramFilter, String entityId)
|
public static Params valueOf(BeanPropertiesFilter paramFilter, String entityId, WebScriptRequest request)
|
||||||
{
|
{
|
||||||
return new Params(entityId, null, null, null, null, new RecognizedParams(null, null, paramFilter, null, null, null, null, false), null);
|
return new Params(entityId, null, null, null, null, new RecognizedParams(null, null, paramFilter, null, null, null, null, false), null, request);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Params valueOf(String entityId, String relationshipId)
|
public static Params valueOf(String entityId, String relationshipId, WebScriptRequest request)
|
||||||
{
|
{
|
||||||
return new Params(entityId, relationshipId, null, null, null, NULL_PARAMS, null);
|
return new Params(entityId, relationshipId, null, null, null, NULL_PARAMS, null, request);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Params valueOf(RecognizedParams recognizedParams, String entityId, String relationshipId)
|
public static Params valueOf(RecognizedParams recognizedParams, String entityId, String relationshipId, WebScriptRequest request)
|
||||||
{
|
{
|
||||||
return new Params(entityId, relationshipId, null, null, null, recognizedParams, null);
|
return new Params(entityId, relationshipId, null, null, null, recognizedParams, null, request);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Params valueOf(String entityId, RecognizedParams recognizedParams, Object passedIn)
|
public static Params valueOf(String entityId, RecognizedParams recognizedParams, Object passedIn, WebScriptRequest request)
|
||||||
{
|
{
|
||||||
return new Params(entityId, null, passedIn, null, null, recognizedParams, null);
|
return new Params(entityId, null, passedIn, null, null, recognizedParams, null, request);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Params valueOf(String entityId, String relationshipId, RecognizedParams recognizedParams, Object passedIn)
|
public static Params valueOf(String entityId, String relationshipId, RecognizedParams recognizedParams, Object passedIn, WebScriptRequest request)
|
||||||
{
|
{
|
||||||
return new Params(entityId, relationshipId, passedIn, null, null, recognizedParams, null);
|
return new Params(entityId, relationshipId, passedIn, null, null, recognizedParams, null, request);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Params valueOf(String entityId, String relationshipId, Object passedIn, InputStream stream, String addressedProperty, RecognizedParams recognizedParams, BasicContentInfo contentInfo)
|
public static Params valueOf(String entityId, String relationshipId, Object passedIn, InputStream stream,
|
||||||
|
String addressedProperty, RecognizedParams recognizedParams, BasicContentInfo contentInfo, WebScriptRequest request)
|
||||||
{
|
{
|
||||||
return new Params(entityId, relationshipId, passedIn, stream, addressedProperty, recognizedParams, contentInfo);
|
return new Params(entityId, relationshipId, passedIn, stream, addressedProperty, recognizedParams, contentInfo, request);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getEntityId()
|
public String getEntityId()
|
||||||
@@ -214,6 +217,12 @@ public class Params implements Parameters
|
|||||||
return contentInfo;
|
return contentInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WebScriptRequest getRequest()
|
||||||
|
{
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A formal set of params that any rest service could potentially have passed in as request params
|
* A formal set of params that any rest service could potentially have passed in as request params
|
||||||
*/
|
*/
|
||||||
|
@@ -48,7 +48,7 @@ public class ResourceWebScriptDelete extends AbstractResourceWebScript implement
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return Params.valueOf(entityId, relationshipId);
|
return Params.valueOf(entityId, relationshipId, req);
|
||||||
|
|
||||||
}
|
}
|
||||||
case RELATIONSHIP:
|
case RELATIONSHIP:
|
||||||
@@ -59,7 +59,7 @@ public class ResourceWebScriptDelete extends AbstractResourceWebScript implement
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return Params.valueOf(entityId, relationshipId);
|
return Params.valueOf(entityId, relationshipId, req);
|
||||||
}
|
}
|
||||||
case PROPERTY:
|
case PROPERTY:
|
||||||
final String resourceName = req.getServiceMatch().getTemplateVars().get(ResourceLocator.RELATIONSHIP_RESOURCE);
|
final String resourceName = req.getServiceMatch().getTemplateVars().get(ResourceLocator.RELATIONSHIP_RESOURCE);
|
||||||
@@ -69,11 +69,11 @@ public class ResourceWebScriptDelete extends AbstractResourceWebScript implement
|
|||||||
{
|
{
|
||||||
if (StringUtils.isNotBlank(propertyName))
|
if (StringUtils.isNotBlank(propertyName))
|
||||||
{
|
{
|
||||||
return Params.valueOf(entityId, relationshipId, null, null, propertyName, null, null);
|
return Params.valueOf(entityId, relationshipId, null, null, propertyName, null, null, req);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return Params.valueOf(entityId, null, null, null, resourceName, null, null);
|
return Params.valueOf(entityId, null, null, null, resourceName, null, null, req);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Fall through to unsupported.
|
//Fall through to unsupported.
|
||||||
|
@@ -73,20 +73,20 @@ public class ResourceWebScriptGet extends AbstractResourceWebScript implements P
|
|||||||
case ENTITY:
|
case ENTITY:
|
||||||
if (StringUtils.isNotBlank(entityId))
|
if (StringUtils.isNotBlank(entityId))
|
||||||
{
|
{
|
||||||
return Params.valueOf(params, entityId, null);
|
return Params.valueOf(params, entityId, null, req);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return Params.valueOf(params, null, null);// collection resource
|
return Params.valueOf(params, null, null, req);// collection resource
|
||||||
}
|
}
|
||||||
case RELATIONSHIP:
|
case RELATIONSHIP:
|
||||||
if (StringUtils.isNotBlank(relationshipId))
|
if (StringUtils.isNotBlank(relationshipId))
|
||||||
{
|
{
|
||||||
return Params.valueOf(params, entityId, relationshipId);
|
return Params.valueOf(params, entityId, relationshipId, req);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return Params.valueOf(params, entityId, null); //relationship collection resource
|
return Params.valueOf(params, entityId, null, req); //relationship collection resource
|
||||||
}
|
}
|
||||||
case PROPERTY:
|
case PROPERTY:
|
||||||
final String resourceName = req.getServiceMatch().getTemplateVars().get(ResourceLocator.RELATIONSHIP_RESOURCE);
|
final String resourceName = req.getServiceMatch().getTemplateVars().get(ResourceLocator.RELATIONSHIP_RESOURCE);
|
||||||
@@ -96,11 +96,11 @@ public class ResourceWebScriptGet extends AbstractResourceWebScript implements P
|
|||||||
{
|
{
|
||||||
if (StringUtils.isNotBlank(propertyName))
|
if (StringUtils.isNotBlank(propertyName))
|
||||||
{
|
{
|
||||||
return Params.valueOf(entityId, relationshipId, null, null, propertyName, params, null);
|
return Params.valueOf(entityId, relationshipId, null, null, propertyName, params, null, req);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return Params.valueOf(entityId, null, null, null, resourceName, params, null);
|
return Params.valueOf(entityId, null, null, null, resourceName, params, null, req);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Fall through to unsupported.
|
//Fall through to unsupported.
|
||||||
|
@@ -478,7 +478,7 @@ public class ResourceWebScriptHelper
|
|||||||
if (objectToWrap instanceof SerializablePagedCollection<?>)
|
if (objectToWrap instanceof SerializablePagedCollection<?>)
|
||||||
{
|
{
|
||||||
SerializablePagedCollection<?> collectionToWrap = (SerializablePagedCollection<?>) objectToWrap;
|
SerializablePagedCollection<?> collectionToWrap = (SerializablePagedCollection<?>) objectToWrap;
|
||||||
Object sourceEntity = executeIncludedSource(api,entityCollectionName,params.getEntityId(),params.includeSource());
|
Object sourceEntity = executeIncludedSource(api, params, entityCollectionName);
|
||||||
Collection<Object> resultCollection = new ArrayList(collectionToWrap.getCollection().size());
|
Collection<Object> resultCollection = new ArrayList(collectionToWrap.getCollection().size());
|
||||||
if (!collectionToWrap.getCollection().isEmpty())
|
if (!collectionToWrap.getCollection().isEmpty())
|
||||||
{
|
{
|
||||||
@@ -510,7 +510,7 @@ public class ResourceWebScriptHelper
|
|||||||
{
|
{
|
||||||
Map<String, ResourceWithMetadata> relationshipResources = locator.locateRelationResource(api,entityCollectionName, params.getRelationsFilter().keySet(), HttpMethod.GET);
|
Map<String, ResourceWithMetadata> relationshipResources = locator.locateRelationResource(api,entityCollectionName, params.getRelationsFilter().keySet(), HttpMethod.GET);
|
||||||
String uniqueEntityId = ResourceInspector.findUniqueId(objectToWrap);
|
String uniqueEntityId = ResourceInspector.findUniqueId(objectToWrap);
|
||||||
Map<String,Object> relatedResources = executeRelatedResources(api,params.getRelationsFilter(), relationshipResources, uniqueEntityId);
|
Map<String,Object> relatedResources = executeRelatedResources(api, params, relationshipResources, uniqueEntityId);
|
||||||
execRes.addRelated(relatedResources);
|
execRes.addRelated(relatedResources);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -519,14 +519,14 @@ public class ResourceWebScriptHelper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object executeIncludedSource(Api api, String entityCollectionName, String uniqueEntityId, boolean includeSource)
|
private Object executeIncludedSource(Api api, Params params, String entityCollectionName)
|
||||||
{
|
{
|
||||||
if (includeSource)
|
if (params.includeSource())
|
||||||
{
|
{
|
||||||
ResourceWithMetadata res = locator.locateEntityResource(api, entityCollectionName, HttpMethod.GET);
|
ResourceWithMetadata res = locator.locateEntityResource(api, entityCollectionName, HttpMethod.GET);
|
||||||
if (res != null)
|
if (res != null)
|
||||||
{
|
{
|
||||||
Object result = executeRelatedResource(api, null, uniqueEntityId, null, res);
|
Object result = executeRelatedResource(api, params, params.getEntityId(), null, res);
|
||||||
if (result!=null && result instanceof ExecutionResult) return ((ExecutionResult) result).getRoot();
|
if (result!=null && result instanceof ExecutionResult) return ((ExecutionResult) result).getRoot();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -554,7 +554,7 @@ public class ResourceWebScriptHelper
|
|||||||
Object id = ResourceInspectorUtil.invokeMethod(embeddedEntry.getValue().getSecond(), objectToWrap);
|
Object id = ResourceInspectorUtil.invokeMethod(embeddedEntry.getValue().getSecond(), objectToWrap);
|
||||||
if (id != null)
|
if (id != null)
|
||||||
{
|
{
|
||||||
Object execEmbeddedResult = executeRelatedResource(api, params.getRelationsFilter(), String.valueOf(id), embeddedEntry.getKey(), res);
|
Object execEmbeddedResult = executeRelatedResource(api, params, String.valueOf(id), embeddedEntry.getKey(), res);
|
||||||
if (execEmbeddedResult != null)
|
if (execEmbeddedResult != null)
|
||||||
{
|
{
|
||||||
if (execEmbeddedResult instanceof ExecutionResult)
|
if (execEmbeddedResult instanceof ExecutionResult)
|
||||||
@@ -584,14 +584,14 @@ public class ResourceWebScriptHelper
|
|||||||
* @param uniqueEntityId String
|
* @param uniqueEntityId String
|
||||||
* @return Map
|
* @return Map
|
||||||
*/
|
*/
|
||||||
private Map<String,Object> executeRelatedResources(final Api api, Map<String, BeanPropertiesFilter> filters,
|
private Map<String,Object> executeRelatedResources(final Api api, Params params,
|
||||||
Map<String, ResourceWithMetadata> relatedResources,
|
Map<String, ResourceWithMetadata> relatedResources,
|
||||||
String uniqueEntityId)
|
String uniqueEntityId)
|
||||||
{
|
{
|
||||||
final Map<String,Object> results = new HashMap<String,Object>(relatedResources.size());
|
final Map<String,Object> results = new HashMap<String,Object>(relatedResources.size());
|
||||||
for (final Entry<String, ResourceWithMetadata> relation : relatedResources.entrySet())
|
for (final Entry<String, ResourceWithMetadata> relation : relatedResources.entrySet())
|
||||||
{
|
{
|
||||||
Object execResult = executeRelatedResource(api, filters, uniqueEntityId, relation.getKey(), relation.getValue());
|
Object execResult = executeRelatedResource(api, params, uniqueEntityId, relation.getKey(), relation.getValue());
|
||||||
if (execResult != null)
|
if (execResult != null)
|
||||||
{
|
{
|
||||||
results.put(relation.getKey(), execResult);
|
results.put(relation.getKey(), execResult);
|
||||||
@@ -611,19 +611,19 @@ public class ResourceWebScriptHelper
|
|||||||
* @param resource ResourceWithMetadata
|
* @param resource ResourceWithMetadata
|
||||||
* @return Object
|
* @return Object
|
||||||
*/
|
*/
|
||||||
private Object executeRelatedResource(final Api api, final Map<String, BeanPropertiesFilter> filters,
|
private Object executeRelatedResource(final Api api, Params params,
|
||||||
final String uniqueEntityId, final String resourceKey, final ResourceWithMetadata resource)
|
final String uniqueEntityId, final String resourceKey, final ResourceWithMetadata resource)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
BeanPropertiesFilter paramFilter = null;
|
BeanPropertiesFilter paramFilter = null;
|
||||||
final Object[] resultOfExecution = new Object[1];
|
final Object[] resultOfExecution = new Object[1];
|
||||||
|
Map<String, BeanPropertiesFilter> filters = params.getRelationsFilter();
|
||||||
if (filters!=null)
|
if (filters!=null)
|
||||||
{
|
{
|
||||||
paramFilter = filters.get(resourceKey);
|
paramFilter = filters.get(resourceKey);
|
||||||
}
|
}
|
||||||
final Params executionParams = Params.valueOf(paramFilter, uniqueEntityId);
|
final Params executionParams = Params.valueOf(paramFilter, uniqueEntityId, params.getRequest());
|
||||||
executor.execute(resource, executionParams, new ExecutionCallback()
|
executor.execute(resource, executionParams, new ExecutionCallback()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
|
@@ -83,7 +83,7 @@ public class ResourceWebScriptPost extends AbstractResourceWebScript implements
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
Object postedObj = processRequest(resourceMeta, operation, req);
|
Object postedObj = processRequest(resourceMeta, operation, req);
|
||||||
return Params.valueOf(null, params, postedObj);
|
return Params.valueOf(null, params, postedObj, req);
|
||||||
}
|
}
|
||||||
case RELATIONSHIP:
|
case RELATIONSHIP:
|
||||||
if (StringUtils.isNotBlank(relationshipId))
|
if (StringUtils.isNotBlank(relationshipId))
|
||||||
@@ -93,7 +93,7 @@ public class ResourceWebScriptPost extends AbstractResourceWebScript implements
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
Object postedRel = processRequest(resourceMeta, operation, req);
|
Object postedRel = processRequest(resourceMeta, operation, req);
|
||||||
return Params.valueOf(entityId, params, postedRel);
|
return Params.valueOf(entityId, params, postedRel, req);
|
||||||
}
|
}
|
||||||
case OPERATION:
|
case OPERATION:
|
||||||
final String operationName = req.getServiceMatch().getTemplateVars().get(ResourceLocator.RELATIONSHIP_RESOURCE);
|
final String operationName = req.getServiceMatch().getTemplateVars().get(ResourceLocator.RELATIONSHIP_RESOURCE);
|
||||||
@@ -111,11 +111,11 @@ public class ResourceWebScriptPost extends AbstractResourceWebScript implements
|
|||||||
|
|
||||||
if (StringUtils.isNotBlank(propertyName))
|
if (StringUtils.isNotBlank(propertyName))
|
||||||
{
|
{
|
||||||
return Params.valueOf(entityId, relationshipId, params, postedObj);
|
return Params.valueOf(entityId, relationshipId, params, postedObj, req);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return Params.valueOf(entityId, params, postedObj);
|
return Params.valueOf(entityId, params, postedObj, req);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Fall through to unsupported.
|
//Fall through to unsupported.
|
||||||
|
@@ -86,7 +86,7 @@ public class ResourceWebScriptPut extends AbstractResourceWebScript implements P
|
|||||||
{
|
{
|
||||||
|
|
||||||
Object putEnt = ResourceWebScriptHelper.extractJsonContent(req, jsonHelper, resourceMeta.getObjectType(operation));
|
Object putEnt = ResourceWebScriptHelper.extractJsonContent(req, jsonHelper, resourceMeta.getObjectType(operation));
|
||||||
return Params.valueOf(entityId,params,putEnt);
|
return Params.valueOf(entityId,params,putEnt, req);
|
||||||
}
|
}
|
||||||
case RELATIONSHIP:
|
case RELATIONSHIP:
|
||||||
if (StringUtils.isBlank(relationshipId))
|
if (StringUtils.isBlank(relationshipId))
|
||||||
@@ -96,7 +96,7 @@ public class ResourceWebScriptPut extends AbstractResourceWebScript implements P
|
|||||||
{
|
{
|
||||||
Object putRel = ResourceWebScriptHelper.extractJsonContent(req, jsonHelper, resourceMeta.getObjectType(operation));
|
Object putRel = ResourceWebScriptHelper.extractJsonContent(req, jsonHelper, resourceMeta.getObjectType(operation));
|
||||||
ResourceWebScriptHelper.setUniqueId(putRel,relationshipId);
|
ResourceWebScriptHelper.setUniqueId(putRel,relationshipId);
|
||||||
return Params.valueOf(entityId, params, putRel);
|
return Params.valueOf(entityId, params, putRel, req);
|
||||||
}
|
}
|
||||||
case PROPERTY:
|
case PROPERTY:
|
||||||
final String resourceName = req.getServiceMatch().getTemplateVars().get(ResourceLocator.RELATIONSHIP_RESOURCE);
|
final String resourceName = req.getServiceMatch().getTemplateVars().get(ResourceLocator.RELATIONSHIP_RESOURCE);
|
||||||
@@ -106,11 +106,11 @@ public class ResourceWebScriptPut extends AbstractResourceWebScript implements P
|
|||||||
{
|
{
|
||||||
if (StringUtils.isNotBlank(propertyName))
|
if (StringUtils.isNotBlank(propertyName))
|
||||||
{
|
{
|
||||||
return Params.valueOf(entityId, relationshipId, null, getStream(req), propertyName, params, getContentInfo(req));
|
return Params.valueOf(entityId, relationshipId, null, getStream(req), propertyName, params, getContentInfo(req), req);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return Params.valueOf(entityId, null, null, getStream(req), resourceName, params, getContentInfo(req));
|
return Params.valueOf(entityId, null, null, getStream(req), resourceName, params, getContentInfo(req), req);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -22,6 +22,7 @@ import org.mockito.invocation.InvocationOnMock;
|
|||||||
import org.mockito.stubbing.Answer;
|
import org.mockito.stubbing.Answer;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
@@ -46,7 +47,7 @@ public abstract class AbstractContextTest
|
|||||||
@Autowired
|
@Autowired
|
||||||
JacksonHelper jsonHelper;
|
JacksonHelper jsonHelper;
|
||||||
|
|
||||||
static Params NOT_USED = Params.valueOf("notUsed", null);
|
static Params NOT_USED = Params.valueOf("notUsed", null, mock(WebScriptRequest.class));
|
||||||
static final Params.RecognizedParams NULL_PARAMS = new Params.RecognizedParams(null, null, null, null, null, null, null, false);
|
static final Params.RecognizedParams NULL_PARAMS = new Params.RecognizedParams(null, null, null, null, null, null, null, false);
|
||||||
static Api api = Api.valueOf("alfrescomock", "private", "1");
|
static Api api = Api.valueOf("alfrescomock", "private", "1");
|
||||||
|
|
||||||
|
@@ -3,6 +3,7 @@ package org.alfresco.rest.framework.tests.core;
|
|||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
import org.alfresco.rest.framework.Api;
|
import org.alfresco.rest.framework.Api;
|
||||||
import org.alfresco.rest.framework.core.ResourceLookupDictionary;
|
import org.alfresco.rest.framework.core.ResourceLookupDictionary;
|
||||||
@@ -19,6 +20,7 @@ import org.junit.Test;
|
|||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpMethod;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
@@ -39,7 +41,7 @@ public class ExecutionTests extends AbstractContextTest
|
|||||||
{
|
{
|
||||||
ResourceWithMetadata entityResource = locator.locateEntityResource(api,"sheep", HttpMethod.GET);
|
ResourceWithMetadata entityResource = locator.locateEntityResource(api,"sheep", HttpMethod.GET);
|
||||||
AbstractResourceWebScript executor = (AbstractResourceWebScript) applicationContext.getBean("executorOfGets");
|
AbstractResourceWebScript executor = (AbstractResourceWebScript) applicationContext.getBean("executorOfGets");
|
||||||
executor.execute(entityResource, Params.valueOf((String)null, null), new ActionExecutor.ExecutionCallback<CollectionWithPagingInfo>(){
|
executor.execute(entityResource, Params.valueOf((String)null, null, mock(WebScriptRequest.class)), new ActionExecutor.ExecutionCallback<CollectionWithPagingInfo>(){
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(CollectionWithPagingInfo result, ContentInfo contentInfo, int statusCode)
|
public void onSuccess(CollectionWithPagingInfo result, ContentInfo contentInfo, int statusCode)
|
||||||
{
|
{
|
||||||
@@ -48,14 +50,14 @@ public class ExecutionTests extends AbstractContextTest
|
|||||||
|
|
||||||
ResourceWithMetadata baa = locator.locateRelationResource(api,"sheep", "baaahh", HttpMethod.GET);
|
ResourceWithMetadata baa = locator.locateRelationResource(api,"sheep", "baaahh", HttpMethod.GET);
|
||||||
executor = (AbstractResourceWebScript) applicationContext.getBean("executorOfGets");
|
executor = (AbstractResourceWebScript) applicationContext.getBean("executorOfGets");
|
||||||
executor.execute(baa, Params.valueOf("4", null), new ActionExecutor.ExecutionCallback<CollectionWithPagingInfo>(){
|
executor.execute(baa, Params.valueOf("4", null, mock(WebScriptRequest.class)), new ActionExecutor.ExecutionCallback<CollectionWithPagingInfo>(){
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(CollectionWithPagingInfo result, ContentInfo contentInfo, int statusCode )
|
public void onSuccess(CollectionWithPagingInfo result, ContentInfo contentInfo, int statusCode )
|
||||||
{
|
{
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
}});
|
}});
|
||||||
|
|
||||||
executor.execute(baa, Params.valueOf("4", "45"), new ActionExecutor.ExecutionCallback<ExecutionResult>(){
|
executor.execute(baa, Params.valueOf("4", "45", mock(WebScriptRequest.class)), new ActionExecutor.ExecutionCallback<ExecutionResult>(){
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(ExecutionResult result, ContentInfo contentInfo, int statusCode )
|
public void onSuccess(ExecutionResult result, ContentInfo contentInfo, int statusCode )
|
||||||
{
|
{
|
||||||
@@ -63,7 +65,7 @@ public class ExecutionTests extends AbstractContextTest
|
|||||||
}});
|
}});
|
||||||
|
|
||||||
ResourceWithMetadata baaPhoto = locator.locateRelationResource(api,"sheep/{entityId}/baaahh", "photo", HttpMethod.GET);
|
ResourceWithMetadata baaPhoto = locator.locateRelationResource(api,"sheep/{entityId}/baaahh", "photo", HttpMethod.GET);
|
||||||
executor.execute(baaPhoto, Params.valueOf("4", "45"), new ActionExecutor.ExecutionCallback<CollectionWithPagingInfo>(){
|
executor.execute(baaPhoto, Params.valueOf("4", "45", mock(WebScriptRequest.class)), new ActionExecutor.ExecutionCallback<CollectionWithPagingInfo>(){
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(CollectionWithPagingInfo result, ContentInfo contentInfo, int statusCode )
|
public void onSuccess(CollectionWithPagingInfo result, ContentInfo contentInfo, int statusCode )
|
||||||
{
|
{
|
||||||
@@ -79,7 +81,7 @@ public class ExecutionTests extends AbstractContextTest
|
|||||||
|
|
||||||
ResourceWithMetadata resource = locator.locateRelationResource(api, "sheep", "blacksheep", HttpMethod.POST);
|
ResourceWithMetadata resource = locator.locateRelationResource(api, "sheep", "blacksheep", HttpMethod.POST);
|
||||||
final Sheep aSheep = new Sheep("xyz");
|
final Sheep aSheep = new Sheep("xyz");
|
||||||
executor.execute(resource, Params.valueOf("654", null, NULL_PARAMS, Arrays.asList(aSheep)), new ActionExecutor.ExecutionCallback<ExecutionResult>(){
|
executor.execute(resource, Params.valueOf("654", null, NULL_PARAMS, Arrays.asList(aSheep), mock(WebScriptRequest.class)), new ActionExecutor.ExecutionCallback<ExecutionResult>(){
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(ExecutionResult result, ContentInfo contentInfo, int statusCode )
|
public void onSuccess(ExecutionResult result, ContentInfo contentInfo, int statusCode )
|
||||||
{
|
{
|
||||||
@@ -89,7 +91,7 @@ public class ExecutionTests extends AbstractContextTest
|
|||||||
|
|
||||||
ResourceWithMetadata grassResource = locator.locateEntityResource(api,"grass", HttpMethod.POST);
|
ResourceWithMetadata grassResource = locator.locateEntityResource(api,"grass", HttpMethod.POST);
|
||||||
final Grass grr = new Grass("grr");
|
final Grass grr = new Grass("grr");
|
||||||
executor.execute(grassResource, Params.valueOf("654", null, NULL_PARAMS, Arrays.asList(grr)), new ActionExecutor.ExecutionCallback<ExecutionResult>(){
|
executor.execute(grassResource, Params.valueOf("654", null, NULL_PARAMS, Arrays.asList(grr), mock(WebScriptRequest.class)), new ActionExecutor.ExecutionCallback<ExecutionResult>(){
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(ExecutionResult result, ContentInfo contentInfo, int statusCode )
|
public void onSuccess(ExecutionResult result, ContentInfo contentInfo, int statusCode )
|
||||||
{
|
{
|
||||||
@@ -97,7 +99,7 @@ public class ExecutionTests extends AbstractContextTest
|
|||||||
}});
|
}});
|
||||||
|
|
||||||
ResourceWithMetadata entityResource = locator.locateRelationResource(api,"grass", "grow", HttpMethod.POST);
|
ResourceWithMetadata entityResource = locator.locateRelationResource(api,"grass", "grow", HttpMethod.POST);
|
||||||
executor.execute(entityResource, Params.valueOf("654", null, NULL_PARAMS, grr), new ActionExecutor.ExecutionCallback<String>(){
|
executor.execute(entityResource, Params.valueOf("654", null, NULL_PARAMS, grr, mock(WebScriptRequest.class)), new ActionExecutor.ExecutionCallback<String>(){
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(String result, ContentInfo contentInfo, int statusCode )
|
public void onSuccess(String result, ContentInfo contentInfo, int statusCode )
|
||||||
{
|
{
|
||||||
@@ -111,14 +113,14 @@ public class ExecutionTests extends AbstractContextTest
|
|||||||
{
|
{
|
||||||
ResourceWithMetadata grassResource = locator.locateEntityResource(api,"grass", HttpMethod.DELETE);
|
ResourceWithMetadata grassResource = locator.locateEntityResource(api,"grass", HttpMethod.DELETE);
|
||||||
AbstractResourceWebScript executor = (AbstractResourceWebScript) applicationContext.getBean("executorOfDelete");
|
AbstractResourceWebScript executor = (AbstractResourceWebScript) applicationContext.getBean("executorOfDelete");
|
||||||
executor.execute(grassResource, Params.valueOf("4", null), new ActionExecutor.ExecutionCallback<Object>(){
|
executor.execute(grassResource, Params.valueOf("4", null, mock(WebScriptRequest.class)), new ActionExecutor.ExecutionCallback<Object>(){
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(Object result, ContentInfo contentInfo, int statusCode )
|
public void onSuccess(Object result, ContentInfo contentInfo, int statusCode )
|
||||||
{
|
{
|
||||||
assertNull(result);
|
assertNull(result);
|
||||||
}});
|
}});
|
||||||
ResourceWithMetadata resource = locator.locateRelationResource(api, "sheep", "blacksheep", HttpMethod.DELETE);
|
ResourceWithMetadata resource = locator.locateRelationResource(api, "sheep", "blacksheep", HttpMethod.DELETE);
|
||||||
executor.execute(resource, Params.valueOf("4", null), new ActionExecutor.ExecutionCallback<Object>(){
|
executor.execute(resource, Params.valueOf("4", null, mock(WebScriptRequest.class)), new ActionExecutor.ExecutionCallback<Object>(){
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(Object result, ContentInfo contentInfo, int statusCode )
|
public void onSuccess(Object result, ContentInfo contentInfo, int statusCode )
|
||||||
{
|
{
|
||||||
@@ -126,7 +128,7 @@ public class ExecutionTests extends AbstractContextTest
|
|||||||
}});
|
}});
|
||||||
|
|
||||||
ResourceWithMetadata goatDelete = locator.locateRelationResource(api3,"goat/{entityId}/herd", "content", HttpMethod.DELETE);
|
ResourceWithMetadata goatDelete = locator.locateRelationResource(api3,"goat/{entityId}/herd", "content", HttpMethod.DELETE);
|
||||||
executor.execute(goatDelete, Params.valueOf("4", "56"), new ActionExecutor.ExecutionCallback<Object>(){
|
executor.execute(goatDelete, Params.valueOf("4", "56", mock(WebScriptRequest.class)), new ActionExecutor.ExecutionCallback<Object>(){
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(Object result, ContentInfo contentInfo, int statusCode )
|
public void onSuccess(Object result, ContentInfo contentInfo, int statusCode )
|
||||||
{
|
{
|
||||||
@@ -141,7 +143,7 @@ public class ExecutionTests extends AbstractContextTest
|
|||||||
ResourceWithMetadata entityResource = locator.locateEntityResource(api,"sheep", HttpMethod.PUT);
|
ResourceWithMetadata entityResource = locator.locateEntityResource(api,"sheep", HttpMethod.PUT);
|
||||||
AbstractResourceWebScript executor = (AbstractResourceWebScript) applicationContext.getBean("executorOfPut");
|
AbstractResourceWebScript executor = (AbstractResourceWebScript) applicationContext.getBean("executorOfPut");
|
||||||
final Sheep aSheep = new Sheep("xyz");
|
final Sheep aSheep = new Sheep("xyz");
|
||||||
executor.execute(entityResource, Params.valueOf("654", null, NULL_PARAMS, aSheep), new ActionExecutor.ExecutionCallback<ExecutionResult>(){
|
executor.execute(entityResource, Params.valueOf("654", null, NULL_PARAMS, aSheep, mock(WebScriptRequest.class)), new ActionExecutor.ExecutionCallback<ExecutionResult>(){
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(ExecutionResult result, ContentInfo contentInfo, int statusCode )
|
public void onSuccess(ExecutionResult result, ContentInfo contentInfo, int statusCode )
|
||||||
{
|
{
|
||||||
@@ -150,7 +152,7 @@ public class ExecutionTests extends AbstractContextTest
|
|||||||
}});
|
}});
|
||||||
|
|
||||||
ResourceWithMetadata resource = locator.locateRelationResource(api, "sheep", "blacksheep", HttpMethod.PUT);
|
ResourceWithMetadata resource = locator.locateRelationResource(api, "sheep", "blacksheep", HttpMethod.PUT);
|
||||||
executor.execute(resource, Params.valueOf("654", null, NULL_PARAMS, aSheep), new ActionExecutor.ExecutionCallback<ExecutionResult>(){
|
executor.execute(resource, Params.valueOf("654", null, NULL_PARAMS, aSheep, mock(WebScriptRequest.class)), new ActionExecutor.ExecutionCallback<ExecutionResult>(){
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(ExecutionResult result, ContentInfo contentInfo, int statusCode )
|
public void onSuccess(ExecutionResult result, ContentInfo contentInfo, int statusCode )
|
||||||
{
|
{
|
||||||
@@ -158,7 +160,7 @@ public class ExecutionTests extends AbstractContextTest
|
|||||||
assertEquals(aSheep,result.getRoot());
|
assertEquals(aSheep,result.getRoot());
|
||||||
}});
|
}});
|
||||||
ResourceWithMetadata baaPhoto = locator.locateRelationResource(api,"sheep/{entityId}/baaahh", "photo", HttpMethod.PUT);
|
ResourceWithMetadata baaPhoto = locator.locateRelationResource(api,"sheep/{entityId}/baaahh", "photo", HttpMethod.PUT);
|
||||||
executor.execute(baaPhoto, Params.valueOf("4", "56"), new ActionExecutor.ExecutionCallback<Object>(){
|
executor.execute(baaPhoto, Params.valueOf("4", "56", mock(WebScriptRequest.class)), new ActionExecutor.ExecutionCallback<Object>(){
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(Object result, ContentInfo contentInfo, int statusCode )
|
public void onSuccess(Object result, ContentInfo contentInfo, int statusCode )
|
||||||
{
|
{
|
||||||
|
@@ -7,6 +7,7 @@ import static org.junit.Assert.assertNotNull;
|
|||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -53,6 +54,7 @@ import org.alfresco.rest.framework.tests.api.mocks3.SlimGoat;
|
|||||||
import org.alfresco.util.Pair;
|
import org.alfresco.util.Pair;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.extensions.webscripts.Status;
|
import org.springframework.extensions.webscripts.Status;
|
||||||
|
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpMethod;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -445,7 +447,7 @@ public class InspectorTests
|
|||||||
assertEquals("grow should return ACCEPTED", Status.STATUS_ACCEPTED, op.getSuccessStatus());
|
assertEquals("grow should return ACCEPTED", Status.STATUS_ACCEPTED, op.getSuccessStatus());
|
||||||
Class paramType = resourceMetadata.getObjectType(op);
|
Class paramType = resourceMetadata.getObjectType(op);
|
||||||
Object paramObj = paramType.newInstance();
|
Object paramObj = paramType.newInstance();
|
||||||
result = (String) ResourceInspectorUtil.invokeMethod(actionMethod,grassEntityResource, "xyz", paramObj, Params.valueOf("notUsed", null));
|
result = (String) ResourceInspectorUtil.invokeMethod(actionMethod,grassEntityResource, "xyz", paramObj, Params.valueOf("notUsed", null, mock(WebScriptRequest.class)));
|
||||||
assertEquals("Growing well",result);
|
assertEquals("Growing well",result);
|
||||||
break;
|
break;
|
||||||
case "/-root-/{id}/cut":
|
case "/-root-/{id}/cut":
|
||||||
@@ -454,7 +456,7 @@ public class InspectorTests
|
|||||||
op = resourceMetadata.getOperation(HttpMethod.POST);
|
op = resourceMetadata.getOperation(HttpMethod.POST);
|
||||||
assertNull(resourceMetadata.getObjectType(op));
|
assertNull(resourceMetadata.getObjectType(op));
|
||||||
assertEquals("cut should return ACCEPTED", Status.STATUS_NOT_IMPLEMENTED, op.getSuccessStatus());
|
assertEquals("cut should return ACCEPTED", Status.STATUS_NOT_IMPLEMENTED, op.getSuccessStatus());
|
||||||
result = (String) ResourceInspectorUtil.invokeMethod(actionMethod,grassEntityResource, "xyz", null, Params.valueOf("notUsed", null));
|
result = (String) ResourceInspectorUtil.invokeMethod(actionMethod,grassEntityResource, "xyz", null, Params.valueOf("notUsed", null, mock(WebScriptRequest.class)));
|
||||||
assertEquals("All done",result);
|
assertEquals("All done",result);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@@ -1,11 +1,14 @@
|
|||||||
package org.alfresco.rest.framework.tests.core;
|
package org.alfresco.rest.framework.tests.core;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.alfresco.rest.framework.jacksonextensions.BeanPropertiesFilter;
|
import org.alfresco.rest.framework.jacksonextensions.BeanPropertiesFilter;
|
||||||
import org.alfresco.rest.framework.resource.parameters.Paging;
|
import org.alfresco.rest.framework.resource.parameters.Paging;
|
||||||
import org.alfresco.rest.framework.resource.parameters.Params;
|
import org.alfresco.rest.framework.resource.parameters.Params;
|
||||||
|
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Just extends the Params class for testing purposes
|
* Just extends the Params class for testing purposes
|
||||||
@@ -17,7 +20,7 @@ public class ParamsExtender extends Params
|
|||||||
|
|
||||||
private ParamsExtender(String entityId, String relationshipId, Object passedIn, InputStream stream, String addressedProperty, RecognizedParams recognizedParams)
|
private ParamsExtender(String entityId, String relationshipId, Object passedIn, InputStream stream, String addressedProperty, RecognizedParams recognizedParams)
|
||||||
{
|
{
|
||||||
super(entityId, relationshipId, passedIn, stream, addressedProperty, recognizedParams, null);
|
super(entityId, relationshipId, passedIn, stream, addressedProperty, recognizedParams, null, mock(WebScriptRequest.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Params valueOf(Map<String, BeanPropertiesFilter> rFilter, String entityId)
|
public static Params valueOf(Map<String, BeanPropertiesFilter> rFilter, String entityId)
|
||||||
|
@@ -121,7 +121,7 @@ public class SerializeTests extends AbstractContextTest
|
|||||||
|
|
||||||
EntityResourceAction.Read<?> getAll = (Read<?>) entityResource.getResource();
|
EntityResourceAction.Read<?> getAll = (Read<?>) entityResource.getResource();
|
||||||
CollectionWithPagingInfo<?> resources = getAll.readAll(null);
|
CollectionWithPagingInfo<?> resources = getAll.readAll(null);
|
||||||
out = writeResponse(helper.processAdditionsToTheResponse(api,null, Params.valueOf("notUsed", null), resources));
|
out = writeResponse(helper.processAdditionsToTheResponse(api,null, Params.valueOf("notUsed", null, null), resources));
|
||||||
assertTrue("There must be json output as List", StringUtils.startsWith(out, "{\"list\":"));
|
assertTrue("There must be json output as List", StringUtils.startsWith(out, "{\"list\":"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,8 +155,8 @@ public class SerializeTests extends AbstractContextTest
|
|||||||
ResourceWithMetadata relationResource = locator.locateRelationResource(api,"sheep", "baaahh", HttpMethod.GET);
|
ResourceWithMetadata relationResource = locator.locateRelationResource(api,"sheep", "baaahh", HttpMethod.GET);
|
||||||
assertNotNull(relationResource);
|
assertNotNull(relationResource);
|
||||||
RelationshipResourceAction.Read<?> getter = (RelationshipResourceAction.Read<?>) relationResource.getResource();
|
RelationshipResourceAction.Read<?> getter = (RelationshipResourceAction.Read<?>) relationResource.getResource();
|
||||||
CollectionWithPagingInfo<?> resources = getter.readAll("123",Params.valueOf("", null));
|
CollectionWithPagingInfo<?> resources = getter.readAll("123",Params.valueOf("", null, null));
|
||||||
String out = writeResponse(helper.processAdditionsToTheResponse(api,null, Params.valueOf("notUsed", null), resources));
|
String out = writeResponse(helper.processAdditionsToTheResponse(api,null, Params.valueOf("notUsed", null, null), resources));
|
||||||
assertTrue("There must be json output as List", StringUtils.startsWith(out, "{\"list\":"));
|
assertTrue("There must be json output as List", StringUtils.startsWith(out, "{\"list\":"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,17 +166,17 @@ public class SerializeTests extends AbstractContextTest
|
|||||||
ResourceWithMetadata relationResource = locator.locateRelationResource(api,"sheep", "baaahh", HttpMethod.GET);
|
ResourceWithMetadata relationResource = locator.locateRelationResource(api,"sheep", "baaahh", HttpMethod.GET);
|
||||||
assertNotNull(relationResource);
|
assertNotNull(relationResource);
|
||||||
RelationshipResourceAction.Read<?> getter = (RelationshipResourceAction.Read<?>) relationResource.getResource();
|
RelationshipResourceAction.Read<?> getter = (RelationshipResourceAction.Read<?>) relationResource.getResource();
|
||||||
CollectionWithPagingInfo<?> resources = getter.readAll("123",Params.valueOf("", null));
|
CollectionWithPagingInfo<?> resources = getter.readAll("123",Params.valueOf("", null, null));
|
||||||
assertNotNull(resources);
|
assertNotNull(resources);
|
||||||
assertTrue(resources.getTotalItems().intValue() == 3);
|
assertTrue(resources.getTotalItems().intValue() == 3);
|
||||||
assertFalse(resources.hasMoreItems());
|
assertFalse(resources.hasMoreItems());
|
||||||
String out = writeResponse(helper.processAdditionsToTheResponse(api,null, Params.valueOf("notUsed", null), resources));
|
String out = writeResponse(helper.processAdditionsToTheResponse(api,null, Params.valueOf("notUsed", null, null), resources));
|
||||||
assertTrue("There must be json output as List with pagination", StringUtils.startsWith(out, "{\"list\":{\"pagination\":{\"count\":3,"));
|
assertTrue("There must be json output as List with pagination", StringUtils.startsWith(out, "{\"list\":{\"pagination\":{\"count\":3,"));
|
||||||
|
|
||||||
resources = getter.readAll("123",ParamsExtender.valueOf(Paging.valueOf(0, 1),"123"));
|
resources = getter.readAll("123",ParamsExtender.valueOf(Paging.valueOf(0, 1),"123"));
|
||||||
assertTrue(resources.getCollection().size() == 1);
|
assertTrue(resources.getCollection().size() == 1);
|
||||||
assertTrue(resources.hasMoreItems());
|
assertTrue(resources.hasMoreItems());
|
||||||
out = writeResponse(helper.processAdditionsToTheResponse(api,null, Params.valueOf("notUsed", null), resources));
|
out = writeResponse(helper.processAdditionsToTheResponse(api,null, Params.valueOf("notUsed", null, null), resources));
|
||||||
assertTrue("There must be json output as List with pagination", StringUtils.startsWith(out, "{\"list\":{\"pagination\":{\"count\":1,"));
|
assertTrue("There must be json output as List with pagination", StringUtils.startsWith(out, "{\"list\":{\"pagination\":{\"count\":1,"));
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -188,7 +188,7 @@ public class SerializeTests extends AbstractContextTest
|
|||||||
Farmer aFarmer = new Farmer("180");
|
Farmer aFarmer = new Farmer("180");
|
||||||
aFarmer.setGoatId("1111");
|
aFarmer.setGoatId("1111");
|
||||||
aFarmer.setSheepId("2222");
|
aFarmer.setSheepId("2222");
|
||||||
ExecutionResult res = (ExecutionResult) helper.processAdditionsToTheResponse(api,null,Params.valueOf("notUsed", null),aFarmer);
|
ExecutionResult res = (ExecutionResult) helper.processAdditionsToTheResponse(api,null,Params.valueOf("notUsed", null, null),aFarmer);
|
||||||
assertNotNull(res);
|
assertNotNull(res);
|
||||||
assertTrue(Farmer.class.equals(res.getRoot().getClass()));
|
assertTrue(Farmer.class.equals(res.getRoot().getClass()));
|
||||||
Map<String,Object> embeds = res.getEmbedded();
|
Map<String,Object> embeds = res.getEmbedded();
|
||||||
@@ -264,7 +264,7 @@ public class SerializeTests extends AbstractContextTest
|
|||||||
public void testSerializeExecutionResult() throws IOException
|
public void testSerializeExecutionResult() throws IOException
|
||||||
{
|
{
|
||||||
assertNotNull(helper);
|
assertNotNull(helper);
|
||||||
Object res = helper.processAdditionsToTheResponse(api,null,Params.valueOf("notUsed", null),new Farmer("180"));
|
Object res = helper.processAdditionsToTheResponse(api,null,Params.valueOf("notUsed", null, null),new Farmer("180"));
|
||||||
String out = writeResponse(res);
|
String out = writeResponse(res);
|
||||||
assertTrue("There must be json output", StringUtils.isNotBlank(out));
|
assertTrue("There must be json output", StringUtils.isNotBlank(out));
|
||||||
|
|
||||||
@@ -276,16 +276,16 @@ public class SerializeTests extends AbstractContextTest
|
|||||||
{
|
{
|
||||||
assertNotNull(helper);
|
assertNotNull(helper);
|
||||||
CollectionWithPagingInfo paged = CollectionWithPagingInfo.asPaged(null,null);
|
CollectionWithPagingInfo paged = CollectionWithPagingInfo.asPaged(null,null);
|
||||||
String out = writeResponse(helper.processAdditionsToTheResponse(api,null, Params.valueOf("notUsed", null), paged));
|
String out = writeResponse(helper.processAdditionsToTheResponse(api,null, Params.valueOf("notUsed", null, null), paged));
|
||||||
assertTrue("There must be json output as List with pagination", StringUtils.startsWith(out, "{\"list\":{\"pagination\":{\"count\":0,"));
|
assertTrue("There must be json output as List with pagination", StringUtils.startsWith(out, "{\"list\":{\"pagination\":{\"count\":0,"));
|
||||||
Paging pageRequest = Paging.valueOf(1, 2);
|
Paging pageRequest = Paging.valueOf(1, 2);
|
||||||
|
|
||||||
paged = CollectionWithPagingInfo.asPaged(pageRequest,Arrays.asList(new Goat(), new Sheep("ABCD"), new Sheep("XYZ")));
|
paged = CollectionWithPagingInfo.asPaged(pageRequest,Arrays.asList(new Goat(), new Sheep("ABCD"), new Sheep("XYZ")));
|
||||||
out = writeResponse(helper.processAdditionsToTheResponse(api,null, Params.valueOf("notUsed", null), paged));
|
out = writeResponse(helper.processAdditionsToTheResponse(api,null, Params.valueOf("notUsed", null, null), paged));
|
||||||
assertTrue("There must be json output as List with pagination", StringUtils.startsWith(out, "{\"list\":{\"pagination\":{\"count\":3,"));
|
assertTrue("There must be json output as List with pagination", StringUtils.startsWith(out, "{\"list\":{\"pagination\":{\"count\":3,"));
|
||||||
|
|
||||||
paged = CollectionWithPagingInfo.asPaged(pageRequest,Arrays.asList(new Goat(), new Sheep("ABCD"), new Sheep("XYZ")),true,5000);
|
paged = CollectionWithPagingInfo.asPaged(pageRequest,Arrays.asList(new Goat(), new Sheep("ABCD"), new Sheep("XYZ")),true,5000);
|
||||||
out = writeResponse(helper.processAdditionsToTheResponse(api,null, Params.valueOf("notUsed", null), paged));
|
out = writeResponse(helper.processAdditionsToTheResponse(api,null, Params.valueOf("notUsed", null, null), paged));
|
||||||
assertTrue("There must be json output as List with pagination", StringUtils.startsWith(out, "{\"list\":{\"pagination\":{\"count\":3,\"hasMoreItems\":true,\"totalItems\":5000"));
|
assertTrue("There must be json output as List with pagination", StringUtils.startsWith(out, "{\"list\":{\"pagination\":{\"count\":3,\"hasMoreItems\":true,\"totalItems\":5000"));
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -298,7 +298,7 @@ public class SerializeTests extends AbstractContextTest
|
|||||||
aMap.put("goatie", new Goat());
|
aMap.put("goatie", new Goat());
|
||||||
aMap.put("sheepie", new Sheep("ABCD"));
|
aMap.put("sheepie", new Sheep("ABCD"));
|
||||||
aMap.put("sheepy", new Sheep("XYZ"));
|
aMap.put("sheepy", new Sheep("XYZ"));
|
||||||
Object res = helper.processAdditionsToTheResponse(api,null,Params.valueOf("notUsed", null),aMap);
|
Object res = helper.processAdditionsToTheResponse(api,null,Params.valueOf("notUsed", null, null),aMap);
|
||||||
String out = writeResponse(res);
|
String out = writeResponse(res);
|
||||||
assertTrue("There must be json output", StringUtils.isNotBlank(out));
|
assertTrue("There must be json output", StringUtils.isNotBlank(out));
|
||||||
|
|
||||||
@@ -312,7 +312,7 @@ public class SerializeTests extends AbstractContextTest
|
|||||||
aSet.add(new Goat());
|
aSet.add(new Goat());
|
||||||
aSet.add(new Sheep("ABCD"));
|
aSet.add(new Sheep("ABCD"));
|
||||||
aSet.add(new Sheep("XYZ"));
|
aSet.add(new Sheep("XYZ"));
|
||||||
Object res = helper.processAdditionsToTheResponse(api,null,Params.valueOf("notUsed", null),aSet);
|
Object res = helper.processAdditionsToTheResponse(api,null,Params.valueOf("notUsed", null, null),aSet);
|
||||||
String out = writeResponse(res);
|
String out = writeResponse(res);
|
||||||
assertTrue("There must be json output", StringUtils.isNotBlank(out));
|
assertTrue("There must be json output", StringUtils.isNotBlank(out));
|
||||||
|
|
||||||
@@ -323,11 +323,11 @@ public class SerializeTests extends AbstractContextTest
|
|||||||
{
|
{
|
||||||
assertNotNull(helper);
|
assertNotNull(helper);
|
||||||
CollectionWithPagingInfo<String> pString = CollectionWithPagingInfo.asPaged(null,Arrays.asList("goat", "sheep", "horse"));
|
CollectionWithPagingInfo<String> pString = CollectionWithPagingInfo.asPaged(null,Arrays.asList("goat", "sheep", "horse"));
|
||||||
Object res = helper.processAdditionsToTheResponse(api,null,Params.valueOf("notUsed", null),pString);
|
Object res = helper.processAdditionsToTheResponse(api,null,Params.valueOf("notUsed", null, null),pString);
|
||||||
String out = writeResponse(res);
|
String out = writeResponse(res);
|
||||||
assertTrue("There must be json output", StringUtils.isNotBlank(out));
|
assertTrue("There must be json output", StringUtils.isNotBlank(out));
|
||||||
CollectionWithPagingInfo<Integer> pInts = CollectionWithPagingInfo.asPaged(null,Arrays.asList(234, 45, 890, 3456));
|
CollectionWithPagingInfo<Integer> pInts = CollectionWithPagingInfo.asPaged(null,Arrays.asList(234, 45, 890, 3456));
|
||||||
res = helper.processAdditionsToTheResponse(api,null,Params.valueOf("notUsed", null),pInts);
|
res = helper.processAdditionsToTheResponse(api,null,Params.valueOf("notUsed", null, null),pInts);
|
||||||
out = writeResponse(res);
|
out = writeResponse(res);
|
||||||
assertTrue("There must be json output", StringUtils.isNotBlank(out));
|
assertTrue("There must be json output", StringUtils.isNotBlank(out));
|
||||||
}
|
}
|
||||||
@@ -336,7 +336,7 @@ public class SerializeTests extends AbstractContextTest
|
|||||||
public void testSerializeList() throws IOException
|
public void testSerializeList() throws IOException
|
||||||
{
|
{
|
||||||
assertNotNull(helper);
|
assertNotNull(helper);
|
||||||
Object res = helper.processAdditionsToTheResponse(api,null,Params.valueOf("notUsed", null),Arrays.asList(new Goat(), new Sheep("ABCD"), new Sheep("XYZ")));
|
Object res = helper.processAdditionsToTheResponse(api,null,Params.valueOf("notUsed", null, null),Arrays.asList(new Goat(), new Sheep("ABCD"), new Sheep("XYZ")));
|
||||||
String out = writeResponse(res);
|
String out = writeResponse(res);
|
||||||
assertTrue("There must be json output", StringUtils.isNotBlank(out));
|
assertTrue("There must be json output", StringUtils.isNotBlank(out));
|
||||||
|
|
||||||
@@ -357,7 +357,7 @@ public class SerializeTests extends AbstractContextTest
|
|||||||
public void testSerializeUniqueId() throws IOException
|
public void testSerializeUniqueId() throws IOException
|
||||||
{
|
{
|
||||||
assertNotNull(helper);
|
assertNotNull(helper);
|
||||||
Object res = helper.processAdditionsToTheResponse(api,null,Params.valueOf("notUsed", null), new Sheep("ABCD"));
|
Object res = helper.processAdditionsToTheResponse(api,null,Params.valueOf("notUsed", null, null), new Sheep("ABCD"));
|
||||||
String out = writeResponse(res);
|
String out = writeResponse(res);
|
||||||
assertTrue("Id field must be called sheepGuid.", StringUtils.contains(out, "\"sheepGuid\":\"ABCD\""));
|
assertTrue("Id field must be called sheepGuid.", StringUtils.contains(out, "\"sheepGuid\":\"ABCD\""));
|
||||||
}
|
}
|
||||||
@@ -368,7 +368,7 @@ public class SerializeTests extends AbstractContextTest
|
|||||||
ResourceWithMetadata relationResource = locator.locateRelationResource(api,"sheep", "baaahh", HttpMethod.GET);
|
ResourceWithMetadata relationResource = locator.locateRelationResource(api,"sheep", "baaahh", HttpMethod.GET);
|
||||||
assertNotNull(relationResource);
|
assertNotNull(relationResource);
|
||||||
RelationshipResourceAction.Read<?> getter = (RelationshipResourceAction.Read<?>) relationResource.getResource();
|
RelationshipResourceAction.Read<?> getter = (RelationshipResourceAction.Read<?>) relationResource.getResource();
|
||||||
String out = writeResponse(helper.processAdditionsToTheResponse(api,null, Params.valueOf("notUsed", null), getter.readAll("1234A3", Params.valueOf("notUsed", null))));
|
String out = writeResponse(helper.processAdditionsToTheResponse(api,null, Params.valueOf("notUsed", null, null), getter.readAll("1234A3", Params.valueOf("notUsed", null, null))));
|
||||||
assertTrue("There must be json output", StringUtils.isNotBlank(out));
|
assertTrue("There must be json output", StringUtils.isNotBlank(out));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -401,7 +401,7 @@ public class SerializeTests extends AbstractContextTest
|
|||||||
Api api3 = Api.valueOf("alfrescomock", "private", "3");
|
Api api3 = Api.valueOf("alfrescomock", "private", "3");
|
||||||
ResourceWithMetadata propResource = locator.locateRelationResource(api3,"flock", "photo", HttpMethod.GET);
|
ResourceWithMetadata propResource = locator.locateRelationResource(api3,"flock", "photo", HttpMethod.GET);
|
||||||
AbstractResourceWebScript executor = (AbstractResourceWebScript) applicationContext.getBean("executorOfGets");
|
AbstractResourceWebScript executor = (AbstractResourceWebScript) applicationContext.getBean("executorOfGets");
|
||||||
executor.execute(propResource, Params.valueOf("234", null), new ExecutionCallback<BinaryResource>(){
|
executor.execute(propResource, Params.valueOf("234", null, null), new ExecutionCallback<BinaryResource>(){
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(BinaryResource result, ContentInfo contentInfo, int statusCode)
|
public void onSuccess(BinaryResource result, ContentInfo contentInfo, int statusCode)
|
||||||
{
|
{
|
||||||
|
@@ -216,7 +216,7 @@ public class ProcessesImplTest extends TestCase
|
|||||||
private CollectionWithPagingInfo<ProcessInfo> queryActiveProcessesAndAssertResult(int skipCount, int maxItems)
|
private CollectionWithPagingInfo<ProcessInfo> queryActiveProcessesAndAssertResult(int skipCount, int maxItems)
|
||||||
{
|
{
|
||||||
Query query = ResourceWebScriptHelper.getWhereClause(QUERY_STATUS_ACTIVE);
|
Query query = ResourceWebScriptHelper.getWhereClause(QUERY_STATUS_ACTIVE);
|
||||||
Parameters parameters = Params.valueOf(new RecognizedParams(null, Paging.valueOf(skipCount, maxItems), null, null, null, query, null, false), null, null);
|
Parameters parameters = Params.valueOf(new RecognizedParams(null, Paging.valueOf(skipCount, maxItems), null, null, null, query, null, false), null, null, null);
|
||||||
|
|
||||||
CollectionWithPagingInfo<ProcessInfo> result = processes.getProcesses(parameters);
|
CollectionWithPagingInfo<ProcessInfo> result = processes.getProcesses(parameters);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user