use of org.alfresco.rest.framework.resource.parameters.Params.RecognizedParams in project alfresco-remote-api by Alfresco.
the class ResourceWebScriptGet method extractParams.
@Override
public Params extractParams(ResourceMetadata resourceMeta, WebScriptRequest req) {
final Map<String, String> resourceVars = locator.parseTemplateVars(req.getServiceMatch().getTemplateVars());
final String entityId = resourceVars.get(ResourceLocator.ENTITY_ID);
final String resourceName = resourceVars.get(ResourceLocator.RELATIONSHIP_RESOURCE);
final String relationshipId = resourceVars.get(ResourceLocator.RELATIONSHIP_ID);
final String propertyName = resourceVars.get(ResourceLocator.PROPERTY);
final String relationship2Id = resourceVars.get(ResourceLocator.RELATIONSHIP2_ID);
final RecognizedParams params = getRecognizedParams(req);
switch(resourceMeta.getType()) {
case ENTITY:
if (StringUtils.isNotBlank(entityId)) {
return Params.valueOf(params, entityId, null, req);
} else {
// collection resource (top-level of entities)
return Params.valueOf(params, null, null, req);
}
case RELATIONSHIP:
if (StringUtils.isNotBlank(propertyName)) {
if (StringUtils.isNotBlank(relationship2Id)) {
return Params.valueOf(false, entityId, relationshipId, relationship2Id, null, null, null, params, null, req);
} else {
// collection resource (second level of relationship)
return Params.valueOf(true, entityId, relationshipId, null, null, null, null, params, null, req);
}
} else if (StringUtils.isNotBlank(relationshipId)) {
return Params.valueOf(false, entityId, relationshipId, null, null, null, null, params, null, req);
} else {
// collection resource (first level of relationship)
return Params.valueOf(true, entityId, null, null, null, null, null, params, null, req);
}
case PROPERTY:
if (StringUtils.isNotBlank(entityId) && StringUtils.isNotBlank(resourceName)) {
if (StringUtils.isNotBlank(propertyName)) {
return Params.valueOf(false, entityId, relationshipId, relationship2Id, null, null, propertyName, params, null, req);
} else {
return Params.valueOf(entityId, null, null, null, resourceName, params, null, req);
}
}
// Fall through to unsupported.
default:
throw new UnsupportedResourceOperationException("GET not supported for Actions");
}
}
use of org.alfresco.rest.framework.resource.parameters.Params.RecognizedParams in project alfresco-remote-api by Alfresco.
the class ProcessesImplTest method queryActiveProcessesAndAssertResult.
private CollectionWithPagingInfo<ProcessInfo> queryActiveProcessesAndAssertResult(int skipCount, int maxItems) {
Query query = getWhereClause(QUERY_STATUS_ACTIVE);
Parameters parameters = Params.valueOf(new RecognizedParams(null, Paging.valueOf(skipCount, maxItems), null, null, null, null, query, null, false), null, null, null);
CollectionWithPagingInfo<ProcessInfo> result = processes.getProcesses(parameters);
assertNotNull(result);
assertNotNull(result.getCollection());
int remainingProcessesAmount = skipCount > ACTIVE_WORKFLOWS_INITIAL_AMOUNT ? 0 : ACTIVE_WORKFLOWS_INITIAL_AMOUNT - skipCount;
if (maxItems >= remainingProcessesAmount) {
assertEquals(remainingProcessesAmount, result.getCollection().size());
} else {
assertEquals(maxItems, result.getCollection().size());
}
return result;
}
use of org.alfresco.rest.framework.resource.parameters.Params.RecognizedParams in project alfresco-remote-api by Alfresco.
the class ResourceWebScriptPut method extractParams.
@Override
public Params extractParams(ResourceMetadata resourceMeta, WebScriptRequest req) {
final Map<String, String> resourceVars = locator.parseTemplateVars(req.getServiceMatch().getTemplateVars());
final String entityId = resourceVars.get(ResourceLocator.ENTITY_ID);
final String relationshipId = resourceVars.get(ResourceLocator.RELATIONSHIP_ID);
final RecognizedParams params = getRecognizedParams(req);
final ResourceOperation operation = resourceMeta.getOperation(HttpMethod.PUT);
switch(resourceMeta.getType()) {
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)) {
throw new UnsupportedResourceOperationException("PUT is executed against the instance URL");
} else {
Object putRel = extractJsonContent(req, assistant.getJsonHelper(), resourceMeta.getObjectType(operation));
ResourceWebScriptHelper.setUniqueId(putRel, relationshipId);
return Params.valueOf(entityId, 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)) {
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.");
}
}
use of org.alfresco.rest.framework.resource.parameters.Params.RecognizedParams in project alfresco-remote-api by Alfresco.
the class ResourceWebScriptPost method extractParams.
@Override
public Params extractParams(ResourceMetadata resourceMeta, WebScriptRequest req) {
final Map<String, String> resourceVars = locator.parseTemplateVars(req.getServiceMatch().getTemplateVars());
final String entityId = resourceVars.get(ResourceLocator.ENTITY_ID);
final String relationshipId = resourceVars.get(ResourceLocator.RELATIONSHIP_ID);
final String operationName = resourceVars.get(ResourceLocator.RELATIONSHIP_RESOURCE);
final String propertyName = resourceVars.get(ResourceLocator.PROPERTY);
final RecognizedParams params = getRecognizedParams(req);
final ResourceOperation operation = resourceMeta.getOperation(HttpMethod.POST);
switch(resourceMeta.getType()) {
case ENTITY:
if (StringUtils.isNotBlank(entityId)) {
throw new UnsupportedResourceOperationException("POST is executed against a collection URL");
} else {
Object postedObj = processRequest(resourceMeta, operation, req);
return Params.valueOf(null, params, postedObj, req);
}
case RELATIONSHIP:
if (StringUtils.isNotBlank(propertyName) && (StringUtils.isNotBlank(relationshipId))) {
// collection resource (second level of relationship)
Object postedRel = processRequest(resourceMeta, operation, req);
return Params.valueOf(true, entityId, relationshipId, null, postedRel, null, null, params, null, req);
} else if (StringUtils.isNotBlank(relationshipId)) {
throw new UnsupportedResourceOperationException("POST is executed against a collection URL");
} else {
Object postedRel = processRequest(resourceMeta, operation, req);
return Params.valueOf(entityId, params, postedRel, req);
}
case OPERATION:
if (StringUtils.isNotBlank(entityId) && StringUtils.isNotBlank(operationName)) {
Object postedObj = processRequest(resourceMeta, operation, req);
if (StringUtils.isNotBlank(propertyName)) {
return Params.valueOf(entityId, relationshipId, params, postedObj, req);
} else {
return Params.valueOf(entityId, params, postedObj, req);
}
}
// Fall through to unsupported.
default:
throw new UnsupportedResourceOperationException("POST not supported for Actions");
}
}
use of org.alfresco.rest.framework.resource.parameters.Params.RecognizedParams in project alfresco-remote-api by Alfresco.
the class ProcessesImplTest method queryMatchesProcesses.
private CollectionWithPagingInfo<ProcessInfo> queryMatchesProcesses(String matchesString) {
Query query = getWhereClause(String.format(QUERY_WORKFLOWDESCRIPTION_MATCHES, matchesString));
Parameters parameters = Params.valueOf(new RecognizedParams(null, Paging.valueOf(0, ACTIVE_WORKFLOWS_INITIAL_AMOUNT), null, null, null, null, query, null, false), null, null, null);
return processes.getProcesses(parameters);
}
Aggregations