use of org.alfresco.rest.framework.resource.RelationshipResource in project alfresco-remote-api by Alfresco.
the class ResourceInspector method inspectRelationship.
/**
* Inspects the relationship resource and returns meta data about it
*
* @param annot RelationshipResource
* @param resource Class<?>
*/
private static List<ResourceMetadata> inspectRelationship(RelationshipResource annot, Class<?> resource) {
Map<String, Object> annotAttribs = AnnotationUtils.getAnnotationAttributes(annot);
String urlPath = String.valueOf(annotAttribs.get("name"));
String entityPath;
Class<?> entityResource = (Class) annotAttribs.get("entityResource");
RelationshipResource relAnnot = AnnotationUtils.findAnnotation(entityResource, RelationshipResource.class);
if (relAnnot != null) {
Map<String, Object> relAnnotAttribs = AnnotationUtils.getAnnotationAttributes(relAnnot);
String relUrlPath = String.valueOf(relAnnotAttribs.get("name"));
urlPath = ResourceDictionary.resourceKey(relUrlPath, urlPath);
entityPath = findEntityNameByAnnotationAttributes(relAnnotAttribs);
} else {
entityPath = findEntityNameByAnnotationAttributes(annotAttribs);
}
String relationshipKey = ResourceDictionary.resourceKey(entityPath, urlPath);
Api api = inspectApi(resource);
List<ResourceMetadata> metainfo = new ArrayList<ResourceMetadata>();
MetaHelper helper = new MetaHelper(resource);
findOperation(RelationshipResourceAction.Create.class, HttpMethod.POST, helper);
findOperation(RelationshipResourceAction.Read.class, HttpMethod.GET, helper);
findOperation(RelationshipResourceAction.ReadById.class, HttpMethod.GET, helper);
findOperation(RelationshipResourceAction.Update.class, HttpMethod.PUT, helper);
findOperation(RelationshipResourceAction.Delete.class, HttpMethod.DELETE, helper);
findOperation(RelationshipResourceAction.DeleteSet.class, HttpMethod.DELETE, helper);
findOperation(RelationshipResourceAction.CreateWithResponse.class, HttpMethod.POST, helper);
findOperation(RelationshipResourceAction.ReadWithResponse.class, HttpMethod.GET, helper);
findOperation(RelationshipResourceAction.ReadByIdWithResponse.class, HttpMethod.GET, helper);
findOperation(RelationshipResourceAction.UpdateWithResponse.class, HttpMethod.PUT, helper);
findOperation(RelationshipResourceAction.DeleteWithResponse.class, HttpMethod.DELETE, helper);
findOperation(RelationshipResourceAction.DeleteSetWithResponse.class, HttpMethod.DELETE, helper);
findOperation(MultiPartRelationshipResourceAction.Create.class, HttpMethod.POST, helper);
boolean noAuth = resource.isAnnotationPresent(WebApiNoAuth.class);
if (noAuth) {
throw new IllegalArgumentException("@WebApiNoAuth should not be on all (relationship resource class) - only on methods: " + urlPath);
}
Set<Class<? extends ResourceAction>> apiNoAuth = helper.apiNoAuth;
if (resource.isAnnotationPresent(WebApiDeleted.class)) {
metainfo.add(new ResourceMetadata(relationshipKey, RESOURCE_TYPE.RELATIONSHIP, null, inspectApi(resource), ALL_RELATIONSHIP_RESOURCE_INTERFACES, apiNoAuth, entityPath));
} else {
metainfo.add(new ResourceMetadata(relationshipKey, RESOURCE_TYPE.RELATIONSHIP, helper.operations, inspectApi(resource), helper.apiDeleted, apiNoAuth, entityPath));
}
inspectAddressedProperties(api, resource, relationshipKey, metainfo);
inspectOperations(api, resource, relationshipKey, metainfo);
return metainfo;
}
use of org.alfresco.rest.framework.resource.RelationshipResource in project alfresco-remote-api by Alfresco.
the class ResourceInspector method inspect.
/**
* Inspects the annotated resource to understand its capabilities
*
* @param resource Class
*/
@SuppressWarnings("rawtypes")
public static List<ResourceMetadata> inspect(Class resource) {
EntityResource annot = AnnotationUtils.findAnnotation(resource, EntityResource.class);
if (annot != null) {
return inspectEntity(annot, resource);
}
RelationshipResource relAnnot = AnnotationUtils.findAnnotation(resource, RelationshipResource.class);
if (relAnnot != null) {
return inspectRelationship(relAnnot, resource);
}
throw new UnsupportedOperationException("Unable to inspect " + resource.getName());
}
Aggregations