Search in sources :

Example 1 with ResourceMetaDataWriter

use of org.alfresco.rest.framework.metadata.ResourceMetaDataWriter in project alfresco-remote-api by Alfresco.

the class WebScriptOptionsMetaData method execute.

@Override
public void execute(final Api api, WebScriptRequest req, WebScriptResponse res) throws IOException {
    final Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
    ResourceDictionary resourceDic = lookupDictionary.getDictionary();
    Map<String, ResourceWithMetadata> apiResources = resourceDic.getAllResources().get(api);
    if (apiResources == null) {
        throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_INVALID_API);
    }
    String collectionName = templateVars.get(ResourceLocator.COLLECTION_RESOURCE);
    String resourceName = templateVars.get(ResourceLocator.RELATIONSHIP_RESOURCE);
    String resourceKey = ResourceDictionary.resourceKey(collectionName, resourceName);
    if (logger.isDebugEnabled()) {
        logger.debug("Locating resource :" + resourceKey);
    }
    ResourceWithMetadata resource = apiResources.get(resourceKey);
    if (resource == null) {
        // Get entity resource and check if we are referencing a property on it.
        resourceKey = ResourceDictionary.propertyResourceKey(collectionName, resourceName);
        resource = apiResources.get(resourceKey);
    }
    ResourceMetaDataWriter writer = chooseWriter(req);
    writer.writeMetaData(res.getOutputStream(), resource, apiResources);
}
Also used : InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) ResourceDictionary(org.alfresco.rest.framework.core.ResourceDictionary) ResourceWithMetadata(org.alfresco.rest.framework.core.ResourceWithMetadata) ResourceMetaDataWriter(org.alfresco.rest.framework.metadata.ResourceMetaDataWriter)

Aggregations

ResourceDictionary (org.alfresco.rest.framework.core.ResourceDictionary)1 ResourceWithMetadata (org.alfresco.rest.framework.core.ResourceWithMetadata)1 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)1 ResourceMetaDataWriter (org.alfresco.rest.framework.metadata.ResourceMetaDataWriter)1