use of org.alfresco.rest.framework.core.ResourceOperation in project alfresco-remote-api by Alfresco.
the class ResourceWebScriptPut method extractParams.
@Override
public Params extractParams(ResourceMetadata resourceMeta, WebScriptRequest req) {
final String relationshipId = req.getServiceMatch().getTemplateVars().get(ResourceLocator.RELATIONSHIP_ID);
final String entityId = req.getServiceMatch().getTemplateVars().get(ResourceLocator.ENTITY_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 = req.getServiceMatch().getTemplateVars().get(ResourceLocator.RELATIONSHIP_RESOURCE);
final String propertyName = req.getServiceMatch().getTemplateVars().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.core.ResourceOperation in project alfresco-remote-api by Alfresco.
the class InspectorTests method testInspectBodyParam.
@Test
public void testInspectBodyParam() {
Method aMethod = ResourceInspector.findMethod(BinaryResourceAction.Update.class, FlockEntityResource.class);
ResourceOperation op = ResourceInspector.inspectOperation(FlockEntityResource.class, aMethod, HttpMethod.PUT);
assertNotNull(op);
List<ResourceParameter> params = op.getParameters();
assertTrue(params.size() == 2);
for (ResourceParameter param : params) {
if (ResourceParameter.KIND.HTTP_BODY_OBJECT.equals(param.getParamType())) {
assertEquals(Flock.class, param.getDataType());
}
}
aMethod = ResourceInspector.findMethod(RelationshipResourceAction.Create.class, SheepBlackSheepResource.class);
op = ResourceInspector.inspectOperation(SheepBlackSheepResource.class, aMethod, HttpMethod.POST);
assertNotNull(op);
params = op.getParameters();
assertTrue(params.size() == 2);
for (ResourceParameter param : params) {
if (ResourceParameter.KIND.HTTP_BODY_OBJECT.equals(param.getParamType())) {
assertEquals(Sheep.class, param.getDataType());
}
}
aMethod = ResourceInspector.findMethod(EntityResourceAction.Update.class, SheepEntityResourceWithDeletedMethods.class);
op = ResourceInspector.inspectOperation(SheepEntityResourceWithDeletedMethods.class, aMethod, HttpMethod.POST);
assertNotNull(op);
params = op.getParameters();
assertNotNull(params);
for (ResourceParameter param : params) {
if (ResourceParameter.KIND.HTTP_BODY_OBJECT.equals(param.getParamType())) {
assertEquals(Sheep.class, param.getDataType());
}
}
}
use of org.alfresco.rest.framework.core.ResourceOperation in project alfresco-remote-api by Alfresco.
the class InspectorTests method testInspectEntity.
@Test
public void testInspectEntity() {
List<ResourceMetadata> metainfo = ResourceInspector.inspect(SheepEntityResource.class);
assertTrue("Must be one ResourceMetadata", metainfo.size() == 1);
ResourceMetadata metaData = metainfo.get(0);
assertNotNull(metaData);
assertNotNull("SheepEntityResource supports GET", metaData.getOperation(HttpMethod.GET));
assertNotNull("SheepEntityResource supports PUT", metaData.getOperation(HttpMethod.PUT));
assertNotNull("SheepEntityResource supports DELETE", metaData.getOperation(HttpMethod.DELETE));
assertNull("SheepEntityResource does not support POST", metaData.getOperation(HttpMethod.POST));
ResourceOperation op = metaData.getOperation(HttpMethod.GET);
assertEquals("Sheep ReadALL should return ACCEPTED", Status.STATUS_ACCEPTED, op.getSuccessStatus());
op = metaData.getOperation(HttpMethod.PUT);
assertTrue("SheepEntityResource must support Sheep", Sheep.class.equals(metaData.getObjectType(op)));
metainfo = ResourceInspector.inspect(SheepNoActionEntityResource.class);
assertTrue("SheepNoActionEntityResource has no actions.", metainfo.isEmpty());
metainfo = ResourceInspector.inspect(GoatEntityResource.class);
assertTrue("Must be one ResourceMetadata", metainfo.size() == 1);
metaData = metainfo.get(0);
assertNotNull(metaData);
assertNotNull("GoatEntityResource supports GET", metaData.getOperation(HttpMethod.GET));
op = metaData.getOperation(HttpMethod.GET);
List<ResourceParameter> params = op.getParameters();
assertTrue("readById method should have 1 url param", params.size() == 1);
metainfo = ResourceInspector.inspect(FlockEntityResource.class);
assertTrue("Must be one ResourceMetadata", metainfo.size() == 1);
metaData = metainfo.get(0);
assertNotNull(metaData);
assertNotNull("FlockEntityResource supports GET", metaData.getOperation(HttpMethod.GET));
assertNotNull("FlockEntityResource supports PUT", metaData.getOperation(HttpMethod.PUT));
assertNotNull("FlockEntityResource supports DELETE", metaData.getOperation(HttpMethod.DELETE));
assertNull("FlockEntityResource does not support POST", metaData.getOperation(HttpMethod.POST));
metainfo = ResourceInspector.inspect(MultiPartTestEntityResource.class);
assertTrue("Must be one ResourceMetadata", metainfo.size() == 1);
metaData = metainfo.get(0);
assertNotNull(metaData);
assertNotNull("MultiPartTestEntityResource support POST", metaData.getOperation(HttpMethod.POST));
assertNull("MultiPartTestEntityResource does not supports GET", metaData.getOperation(HttpMethod.GET));
assertNull("MultiPartTestEntityResource does not supports PUT", metaData.getOperation(HttpMethod.PUT));
assertNull("MultiPartTestEntityResource does not supports DELETE", metaData.getOperation(HttpMethod.DELETE));
op = metaData.getOperation(HttpMethod.POST);
assertTrue("MultiPartTestEntityResource must support MultiPartTestResponse", MultiPartTestResponse.class.equals(metaData.getObjectType(op)));
assertEquals("MultiPartTestEntityResource should return ACCEPTED", Status.STATUS_ACCEPTED, op.getSuccessStatus());
}
use of org.alfresco.rest.framework.core.ResourceOperation in project alfresco-remote-api by Alfresco.
the class InspectorTests method testInspectOperations.
@Test
public void testInspectOperations() throws IllegalAccessException, InstantiationException, Throwable {
Api api = Api.valueOf("alfrescomock", "private", "1");
List<ResourceMetadata> metainfo = new ArrayList<ResourceMetadata>();
GrassEntityResource grassEntityResource = new GrassEntityResource();
ResourceInspector.inspectOperations(api, GrassEntityResource.class, "-root-", metainfo);
assertEquals(3, metainfo.size());
for (ResourceMetadata resourceMetadata : metainfo) {
assertEquals(ResourceMetadata.RESOURCE_TYPE.OPERATION, resourceMetadata.getType());
OperationResourceMetaData operationResourceMetaData = (OperationResourceMetaData) resourceMetadata;
Method actionMethod = operationResourceMetaData.getOperationMethod();
String result = null;
final WithResponse wr = new WithResponse(Status.STATUS_OK, ResponseWriter.DEFAULT_JSON_CONTENT, ResponseWriter.CACHE_NEVER);
switch(resourceMetadata.getUniqueId()) {
case "/-root-/{id}/grow":
assertNotNull("GrassEntityResource supports POST", resourceMetadata.getOperation(HttpMethod.POST));
assertNull("GrassEntityResource does not support DELETE", resourceMetadata.getOperation(HttpMethod.DELETE));
ResourceOperation op = resourceMetadata.getOperation(HttpMethod.POST);
assertEquals("grow should return ACCEPTED", Status.STATUS_ACCEPTED, op.getSuccessStatus());
Class paramType = resourceMetadata.getObjectType(op);
Object paramObj = paramType.newInstance();
result = (String) ResourceInspectorUtil.invokeMethod(actionMethod, grassEntityResource, "xyz", paramObj, Params.valueOf("notUsed", null, mock(WebScriptRequest.class)), wr);
assertEquals("Growing well", result);
assertFalse(operationResourceMetaData.isNoAuth(null));
break;
case "/-root-/{id}/cut":
assertNotNull("GrassEntityResource supports POST", resourceMetadata.getOperation(HttpMethod.POST));
assertNull("GrassEntityResource does not support GET", resourceMetadata.getOperation(HttpMethod.GET));
op = resourceMetadata.getOperation(HttpMethod.POST);
assertNull(resourceMetadata.getObjectType(op));
assertEquals("cut should return ACCEPTED", Status.STATUS_NOT_IMPLEMENTED, op.getSuccessStatus());
result = (String) ResourceInspectorUtil.invokeMethod(actionMethod, grassEntityResource, "xyz", null, Params.valueOf("notUsed", null, mock(WebScriptRequest.class)), wr);
assertEquals("All done", result);
assertFalse(operationResourceMetaData.isNoAuth(null));
break;
case "/-root-/{id}/cut-noAuth":
assertNotNull("GrassEntityResource supports POST", resourceMetadata.getOperation(HttpMethod.POST));
op = resourceMetadata.getOperation(HttpMethod.POST);
assertNull(resourceMetadata.getObjectType(op));
assertEquals("cut should return ACCEPTED", Status.STATUS_NOT_IMPLEMENTED, op.getSuccessStatus());
result = (String) ResourceInspectorUtil.invokeMethod(actionMethod, grassEntityResource, "xyz", null, Params.valueOf("notUsed", null, mock(WebScriptRequest.class)), wr);
assertEquals("All done without Auth", result);
assertTrue(operationResourceMetaData.isNoAuth(null));
break;
default:
fail("Invalid action information.");
}
}
}
use of org.alfresco.rest.framework.core.ResourceOperation in project alfresco-remote-api by Alfresco.
the class InspectorTests method testNodesCommentsRelation.
@Test
public void testNodesCommentsRelation() {
List<ResourceMetadata> metainfo = ResourceInspector.inspect(NodeCommentsRelation.class);
assertTrue("Must be one ResourceMetadata", metainfo.size() == 1);
ResourceMetadata metaData = metainfo.get(0);
assertNotNull(metaData);
ResourceOperation op = metaData.getOperation(HttpMethod.POST);
assertTrue("NodeCommentsRelation must support Comment", Comment.class.equals(metaData.getObjectType(op)));
}
Aggregations