use of org.alfresco.rest.framework.core.ResourceDictionary 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);
}
use of org.alfresco.rest.framework.core.ResourceDictionary in project alfresco-remote-api by Alfresco.
the class InfoWebScriptGet method execute.
@Override
public void execute(final Api api, WebScriptRequest req, WebScriptResponse res) throws IOException {
ResourceDictionary resourceDic = lookupDictionary.getDictionary();
final Map<String, ResourceWithMetadata> apiResources = resourceDic.getAllResources().get(api);
if (apiResources == null) {
throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_INVALID_API);
}
assistant.getJsonHelper().withWriter(res.getOutputStream(), new Writer() {
@Override
public void writeContents(JsonGenerator generator, ObjectMapper objectMapper) throws JsonGenerationException, JsonMappingException, IOException {
List<ExecutionResult> entities = new ArrayList<ExecutionResult>();
for (ResourceWithMetadata resource : apiResources.values()) {
entities.add(new ExecutionResult(resource.getMetaData(), null));
}
Collections.sort(entities, new Comparator<ExecutionResult>() {
public int compare(ExecutionResult r1, ExecutionResult r2) {
return ((ResourceMetadata) r1.getRoot()).getUniqueId().compareTo(((ResourceMetadata) r2.getRoot()).getUniqueId());
}
});
objectMapper.writeValue(generator, CollectionWithPagingInfo.asPaged(Paging.DEFAULT, entities));
}
});
}
use of org.alfresco.rest.framework.core.ResourceDictionary in project alfresco-remote-api by Alfresco.
the class WriterTests method testWriters.
@Test
public void testWriters() throws IOException {
ResourceDictionary resourceDic = locator.getDictionary();
Map<String, ResourceWithMetadata> apiResources = resourceDic.getAllResources().get(api);
String writtenOut = testWriter(defaultMetaWriter, apiResources.get("/sheep"), apiResources);
assertTrue(writtenOut.startsWith("{\"list\":{\"pagination\":{\"count\":5"));
// ResourceMetaDataWriter wadlWriter = new WebScriptOptionsMetaData();
// writtenOut = testWriter(wadlWriter, apiResources.get("/sheep"), apiResources);
// assertTrue(writtenOut.startsWith("{\"list\":{\"pagination\":{\"count\":4"));
}
Aggregations