Merged FILE-FOLDER-API (5.2.0) to HEAD (5.2)

122240 gjames: RA-833: Initial framework changes


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@126461 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jamal Kaabi-Mofrad
2016-05-10 11:03:39 +00:00
parent e35223c712
commit 05757c9773
13 changed files with 228 additions and 17 deletions

View File

@@ -42,11 +42,12 @@ public class ResourceDictionary
}
/*
* Return a key by combining the entity and property ids
* Return a key by combining the rootEntity and property ids
*/
public static String propertyResourceKey(String entity, String property)
{
return "/"+entity+"/"+property;
String rootEntity = entity.startsWith("/")?entity:"/"+entity;
return rootEntity+"/{id}/"+property;
}
/**

View File

@@ -195,6 +195,9 @@ public class ResourceInspector
Map<String, Object> annotAttribs = AnnotationUtils.getAnnotationAttributes(annot);
String urlPath = String.valueOf(annotAttribs.get("name"));
String 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);
@@ -214,13 +217,16 @@ public class ResourceInspector
if (resource.isAnnotationPresent(WebApiDeleted.class))
{
return Arrays.asList(new ResourceMetadata(ResourceDictionary.resourceKey(entityPath,urlPath), RESOURCE_TYPE.RELATIONSHIP, null, inspectApi(resource), ALL_RELATIONSHIP_RESOURCE_INTERFACES, apiNoAuth, entityPath));
metainfo.add(new ResourceMetadata(relationshipKey, RESOURCE_TYPE.RELATIONSHIP, null, inspectApi(resource), ALL_RELATIONSHIP_RESOURCE_INTERFACES, apiNoAuth, entityPath));
}
else
{
return Arrays.asList(new ResourceMetadata(ResourceDictionary.resourceKey(entityPath,urlPath), RESOURCE_TYPE.RELATIONSHIP, helper.operations, inspectApi(resource), helper.apiDeleted, apiNoAuth, entityPath));
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;
}
/**
@@ -599,7 +605,7 @@ public class ResourceInspector
{
Map<String, Object> annotAttribs = AnnotationUtils.getAnnotationAttributes(annot);
String actionName = String.valueOf(annotAttribs.get("value"));
String actionPath = ResourceDictionary.resourceKey(entityPath,actionName);
String actionPath = ResourceDictionary.propertyResourceKey(entityPath,actionName);
ResourceOperation ro = inspectOperation(anyClass, annotatedMethod, HttpMethod.POST);
embeds.put(actionPath, new Pair<ResourceOperation,Method>(ro,annotatedMethod));
}

View File

@@ -20,6 +20,7 @@ public interface ResourceLocator
public static final String ENTITY_ID = "entityId";
public static final String RELATIONSHIP_RESOURCE = "relationResource";
public static final String RELATIONSHIP_ID = "relationshipId";
public static final String PROPERTY = "property";
/**
* Finds an Entity Resource and returns it in ResourceWithMetadata wrapper.
@@ -32,6 +33,19 @@ public interface ResourceLocator
*/
ResourceWithMetadata locateEntityResource(Api api, String resourceName, HttpMethod httpMethod) throws InvalidArgumentException, UnsupportedResourceOperationException;
/**
* Finds a property or action on a Relationship Resource and returns it in ResourceWithMetadata wrapper.
* @param api - The API being used.
* @param resourceName - The entity resource name - this is the "entityResourceName" property on the @RelationshipResource annotation.
* @param relationName - The relationship resource name - this is the "name" property on the @RelationshipResource annotation.
* @param property - The property resource name - can be either an action or a @BinaryProperty
* @param httpMethod - A permitted HttpMethod
* @return ResourceWithMetadata - The resource and its metadata.
* @throws InvalidArgumentException - thrown if either the api or resourceName's are invalid. ie. A resource doesn't exist.
* @throws UnsupportedResourceOperationException - throw if the resource does not support the specified HttpMethod.
*/
ResourceWithMetadata locateRelationPropertyResource(Api api, String entityResource, String relationResource, String property, HttpMethod httpMethod) throws InvalidArgumentException,UnsupportedResourceOperationException;
/**
* Finds an Relationship Resource and returns it in ResourceWithMetadata wrapper.
* @param api - The API being used.

View File

@@ -33,6 +33,29 @@ public class ResourceLookupDictionary implements ResourceLocator
return locateRelationResource(api, entityResource, (String)null, httpMethod);
}
@Override
public ResourceWithMetadata locateRelationPropertyResource(Api api, String entityResource, String relationResource, String property, HttpMethod httpMethod) throws InvalidArgumentException,UnsupportedResourceOperationException
{
String resourceKey = ResourceDictionary.resourceKey(entityResource, relationResource);
String propertyResourceKey = ResourceDictionary.propertyResourceKey(resourceKey, property);
Map<String, ResourceWithMetadata> apiResources = dictionary.getAllResources().get(api);
if (apiResources == null)
{
throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_INVALID_API);
}
ResourceWithMetadata resource = apiResources.get(propertyResourceKey);
if (resource != null)
{
if (!resource.getMetaData().supports(httpMethod)) { throw new UnsupportedResourceOperationException(); }
return resource;
}
logger.warn("Unable to locate resource resource for :"+entityResource+" "+relationResource==null?"":relationResource+" "+property==null?"":property);
throw new InvalidArgumentException("Unable to locate resource resource for :"+entityResource+" "+(relationResource==null?"":relationResource+" "+property==null?"":property));
}
@Override
public ResourceWithMetadata locateRelationResource(Api api, String entityResource, String relationResource, HttpMethod httpMethod) throws InvalidArgumentException,UnsupportedResourceOperationException
{
@@ -83,7 +106,12 @@ public class ResourceLookupDictionary implements ResourceLocator
String collectionName = templateVars.get(COLLECTION_RESOURCE);
String entityId = templateVars.get(ENTITY_ID);
String resourceName = templateVars.get(RELATIONSHIP_RESOURCE);
String property = templateVars.get(PROPERTY);
if (StringUtils.isNotBlank(property))
{
return locateRelationPropertyResource(api,collectionName ,resourceName, property,httpMethod);
}
if (StringUtils.isNotBlank(resourceName))
{
return locateRelationResource(api,collectionName ,resourceName,httpMethod);