-
Notifications
You must be signed in to change notification settings - Fork 99
Open
Description
I need to customize the rest api for my instances by building what I need however I am constrained by the strange technical choice made on the interfaces “EntityResourceAction” and “RelationshipResourceAction”, to get around the issue I created my own “XXXEntityResourceAction”, but I find myself in the thorny situation that the “ResourceInspector” class initializes everything in static methods and at boot.
Would i like to avoid doing an override of an important alfresco bean is it possible to add a global properties to be able to register my annotation classes to generate the rest api ?
The solution i need is something like use the intiliazing bean for register my own class:
/**
* Looks at resources to see what they can do
*
* @author Gethin James
* @author janv
*/
@Component // SET THE CLASS AS CONFIGURABLE BEAN
public class ResourceInspector implements InitializingBean
{
// START SOLUTION
@Value("alfresco.additional.resourceEntityNew")
private Map<String,String> resourceEntityNew;
// END SOLUTION
...
static {
ALL_ENTITY_RESOURCE_INTERFACES.add(EntityResourceAction.Create.class);
ALL_ENTITY_RESOURCE_INTERFACES.add(EntityResourceAction.Read.class);
ALL_ENTITY_RESOURCE_INTERFACES.add(EntityResourceAction.ReadById.class);
ALL_ENTITY_RESOURCE_INTERFACES.add(EntityResourceAction.Update.class);
ALL_ENTITY_RESOURCE_INTERFACES.add(EntityResourceAction.Delete.class);
ALL_ENTITY_RESOURCE_INTERFACES.add(EntityResourceAction.DeleteSet.class);
ALL_ENTITY_RESOURCE_INTERFACES.add(BinaryResourceAction.Read.class);
ALL_ENTITY_RESOURCE_INTERFACES.add(EntityResourceAction.CreateWithResponse.class);
ALL_ENTITY_RESOURCE_INTERFACES.add(EntityResourceAction.ReadWithResponse.class);
ALL_ENTITY_RESOURCE_INTERFACES.add(EntityResourceAction.ReadByIdWithResponse.class);
ALL_ENTITY_RESOURCE_INTERFACES.add(EntityResourceAction.UpdateWithResponse.class);
ALL_ENTITY_RESOURCE_INTERFACES.add(EntityResourceAction.DeleteWithResponse.class);
ALL_ENTITY_RESOURCE_INTERFACES.add(EntityResourceAction.DeleteSetWithResponse.class);
ALL_ENTITY_RESOURCE_INTERFACES.add(BinaryResourceAction.ReadWithResponse.class);
ALL_ENTITY_RESOURCE_INTERFACES.add(MultiPartResourceAction.Create.class);
ALL_RELATIONSHIP_RESOURCE_INTERFACES.add(RelationshipResourceAction.Create.class);
ALL_RELATIONSHIP_RESOURCE_INTERFACES.add(RelationshipResourceAction.Read.class);
ALL_RELATIONSHIP_RESOURCE_INTERFACES.add(RelationshipResourceAction.ReadById.class);
ALL_RELATIONSHIP_RESOURCE_INTERFACES.add(RelationshipResourceAction.Update.class);
ALL_RELATIONSHIP_RESOURCE_INTERFACES.add(RelationshipResourceAction.Delete.class);
ALL_RELATIONSHIP_RESOURCE_INTERFACES.add(RelationshipResourceAction.DeleteSet.class);
ALL_RELATIONSHIP_RESOURCE_INTERFACES.add(RelationshipResourceAction.CreateWithResponse.class);
ALL_RELATIONSHIP_RESOURCE_INTERFACES.add(RelationshipResourceAction.ReadWithResponse.class);
ALL_RELATIONSHIP_RESOURCE_INTERFACES.add(RelationshipResourceAction.ReadByIdWithResponse.class);
ALL_RELATIONSHIP_RESOURCE_INTERFACES.add(RelationshipResourceAction.UpdateWithResponse.class);
ALL_RELATIONSHIP_RESOURCE_INTERFACES.add(RelationshipResourceAction.DeleteWithResponse.class);
ALL_RELATIONSHIP_RESOURCE_INTERFACES.add(RelationshipResourceAction.DeleteSetWithResponse.class);
ALL_RELATIONSHIP_RESOURCE_INTERFACES.add(MultiPartRelationshipResourceAction.Create.class);
ALL_PROPERTY_RESOURCE_INTERFACES.add(BinaryResourceAction.Read.class);
ALL_PROPERTY_RESOURCE_INTERFACES.add(BinaryResourceAction.Delete.class);
ALL_PROPERTY_RESOURCE_INTERFACES.add(BinaryResourceAction.Update.class);
ALL_PROPERTY_RESOURCE_INTERFACES.add(BinaryResourceAction.ReadWithResponse.class);
ALL_PROPERTY_RESOURCE_INTERFACES.add(BinaryResourceAction.DeleteWithResponse.class);
ALL_PROPERTY_RESOURCE_INTERFACES.add(BinaryResourceAction.UpdateWithResponse.class);
}
// START SOLUTION
Map<String,org.springframework.http.HttpMethod> ALL_PROPERTY_RESOURCE_INTERFACES_NEW =
new HashMap<Class,org.springframework.http.HttpMethod>();
@Override
public void afterPropertiesSet() throws Exception {
// Read a global properties
if(resourceEntityNew != null) {
for(Map.Entry<String,String> entry : resourceEntityNew.entrySet()) {
Class clazz = Class.forName(entry.getKey);
org.springframework.http.HttpMethod httpMethod = org.springframework.http.HttpMethod.resolve(entry.getValue());
ALL_PROPERTY_RESOURCE_INTERFACES_NEW.put(clazz, httpMethod);
}
ALL_PROPERTY_RESOURCE_INTERFACES.addAll(ALL_PROPERTY_RESOURCE_INTERFACES_NEW.keySet());
}
}
// END SOLUTION
/**
* Inspects the entity resource and returns meta data about it
*
* @param annot EntityResource
* @param resource Class<?>
*/
private static List<ResourceMetadata> inspectEntity(EntityResource annot, Class<?> resource)
{
String urlPath = findEntityName(annot);
logger.debug("Found EntityResource: "+urlPath);
List<ResourceMetadata> metainfo = new ArrayList<ResourceMetadata>();
Api api = inspectApi(resource);
MetaHelper helper = new MetaHelper(resource);
findOperation(EntityResourceAction.Create.class, POST, helper);
findOperation(EntityResourceAction.Read.class, GET, helper);
findOperation(EntityResourceAction.ReadById.class, GET, helper);
findOperation(EntityResourceAction.Update.class, PUT, helper);
findOperation(EntityResourceAction.Delete.class, DELETE, helper);
findOperation(EntityResourceAction.DeleteSet.class, DELETE, helper);
findOperation(EntityResourceAction.CreateWithResponse.class, POST, helper);
findOperation(EntityResourceAction.ReadWithResponse.class, GET, helper);
findOperation(EntityResourceAction.ReadByIdWithResponse.class, GET, helper);
findOperation(EntityResourceAction.UpdateWithResponse.class, PUT, helper);
findOperation(EntityResourceAction.DeleteWithResponse.class, DELETE, helper);
findOperation(EntityResourceAction.DeleteSetWithResponse.class, DELETE, helper);
findOperation(MultiPartResourceAction.Create.class, POST, helper);
// START SOLUTION
for(Map.Entry<Class,org.springframework.http.HttpMethod> entry : ALL_PROPERTY_RESOURCE_INTERFACES_NEW.entrySet()) {
findOperation(entry.getKey(), entry.getValue(), helper);
}
// END SOLUTION
boolean noAuth = resource.isAnnotationPresent(WebApiNoAuth.class);
if (noAuth)
{
throw new IllegalArgumentException("@WebApiNoAuth should not be on all (entity resource class) - only on individual methods: "+urlPath);
}
Set<Class<? extends ResourceAction>> apiNoAuth = helper.apiNoAuth;
if (resource.isAnnotationPresent(WebApiDeleted.class))
{
metainfo.add(new ResourceMetadata(ResourceDictionary.resourceKey(urlPath,null), RESOURCE_TYPE.ENTITY,
null, api, ALL_ENTITY_RESOURCE_INTERFACES, apiNoAuth, null));
}
else
{
if (!helper.apiDeleted.isEmpty() || !helper.operations.isEmpty())
{
metainfo.add(new ResourceMetadata(ResourceDictionary.resourceKey(urlPath,null), RESOURCE_TYPE.ENTITY,
helper.operations, api, helper.apiDeleted, apiNoAuth, null));
}
}
inspectAddressedProperties(api, resource, urlPath, metainfo);
inspectOperations(api, resource, urlPath, metainfo);
return metainfo;
}
...
}
Metadata
Metadata
Assignees
Labels
No labels