use of org.alfresco.rest.framework.jacksonextensions.ExecutionResult in project alfresco-remote-api by Alfresco.
the class ResourceWebScriptHelper method processAdditionsToTheResponse.
/**
* Looks at the object passed in and recursively expands any @EmbeddedEntityResource annotations or related relationship.
* {@link org.alfresco.rest.framework.resource.EmbeddedEntityResource EmbeddedEntityResource} is expanded by calling the ReadById method for this entity.
*
* Either returns a ExecutionResult object or a CollectionWithPagingInfo containing a collection of ExecutionResult objects.
*
* @param api Api
* @param entityCollectionName String
* @param params Params
* @param objectToWrap Object
* @return Object - Either ExecutionResult or CollectionWithPagingInfo<ExecutionResult>
*/
public Object processAdditionsToTheResponse(WebScriptResponse res, Api api, String entityCollectionName, Params params, Object objectToWrap) {
PropertyCheck.mandatory(this, null, params);
if (objectToWrap == null)
return null;
if (objectToWrap instanceof CollectionWithPagingInfo<?>) {
CollectionWithPagingInfo<?> collectionToWrap = (CollectionWithPagingInfo<?>) objectToWrap;
Object sourceEntity = executeIncludedSource(api, params, entityCollectionName, collectionToWrap);
Collection<Object> resultCollection = new ArrayList(collectionToWrap.getCollection().size());
if (!collectionToWrap.getCollection().isEmpty()) {
for (Object obj : collectionToWrap.getCollection()) {
resultCollection.add(processAdditionsToTheResponse(res, api, entityCollectionName, params, obj));
}
}
return CollectionWithPagingInfo.asPaged(collectionToWrap.getPaging(), resultCollection, collectionToWrap.hasMoreItems(), collectionToWrap.getTotalItems(), sourceEntity, collectionToWrap.getContext());
} else {
if (BeanUtils.isSimpleProperty(objectToWrap.getClass()) || objectToWrap instanceof Collection) {
// Simple property or Collection that can't be embedded so just return it.
return objectToWrap;
}
final ExecutionResult execRes = new ExecutionResult(objectToWrap, params.getFilter());
Map<String, Pair<String, Method>> embeddded = ResourceInspector.findEmbeddedResources(objectToWrap.getClass());
if (embeddded != null && !embeddded.isEmpty()) {
Map<String, Object> results = executeEmbeddedResources(api, params, objectToWrap, embeddded);
execRes.addEmbedded(results);
}
if (params.getRelationsFilter() != null && !params.getRelationsFilter().isEmpty()) {
Map<String, ResourceWithMetadata> relationshipResources = locator.locateRelationResource(api, entityCollectionName, params.getRelationsFilter().keySet(), HttpMethod.GET);
String uniqueEntityId = ResourceInspector.findUniqueId(objectToWrap);
Map<String, Object> relatedResources = executeRelatedResources(api, params, relationshipResources, uniqueEntityId);
execRes.addRelated(relatedResources);
}
return execRes;
}
}
use of org.alfresco.rest.framework.jacksonextensions.ExecutionResult 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.jacksonextensions.ExecutionResult in project alfresco-remote-api by Alfresco.
the class SearchQuerySerializerTests method testSerializeContext.
@Test
public void testSerializeContext() throws IOException {
ExecutionResult exec1 = new ExecutionResult(new Farmer("180"), null);
FacetFieldContext ffc = new FacetFieldContext("theLabel", Arrays.asList(new Bucket("b1", "name:b1", 23, "displayText1"), new Bucket("b2", null, 34, "displayText2")));
SearchContext searchContext = new SearchContext(23l, null, Arrays.asList(new FacetQueryContext("f1", "creator:bob", 15), new FacetQueryContext("f2", null, 20)), Arrays.asList(ffc), new SpellCheckContext("aFlag", Arrays.asList("bish", "bash")), null);
CollectionWithPagingInfo<ExecutionResult> coll = CollectionWithPagingInfo.asPaged(null, Arrays.asList(exec1), false, 2, null, searchContext);
String out = helper.writeResponse(coll);
assertTrue("There must 'context' json output", out.contains("\"context\":{\"consistency\":{\"lastTxId\":23}"));
assertTrue("There must 'facetQueries' json output", out.contains("\"facetQueries\":"));
assertTrue("There must 'facetQueries f1' json output", out.contains("{\"label\":\"f1\",\"filterQuery\":\"creator:bob\",\"count\":15}"));
assertTrue("There must 'facetQueries f2' json output", out.contains("{\"label\":\"f2\",\"count\":20}"));
assertTrue("There must 'spellCheck' json output", out.contains("\"spellCheck\":{\"type\":\"aFlag\",\"suggestions\":[\"bish\",\"bash\"]}"));
assertTrue("There must 'facetsFields' json output", out.contains("\"facetsFields\":[{\"label\":\"theLabel\",\"buckets\""));
assertTrue("There must 'bucket1' json output", out.contains("{\"label\":\"b1\",\"filterQuery\":\"name:b1\",\"count\":23,\"display\":\"displayText1\"}"));
assertTrue("There must 'bucket2' json output", out.contains("{\"label\":\"b2\",\"count\":34,\"display\":\"displayText2\"}"));
searchContext = new SearchContext(-1, null, null, null, null, null);
coll = CollectionWithPagingInfo.asPaged(null, Arrays.asList(exec1), false, 2, null, searchContext);
out = helper.writeResponse(coll);
assertTrue("There must NOT BE a 'context' json output", out.contains("\"context\":{}"));
assertFalse("There must NOT BE a 'facetsFields' json output", out.contains("\"facetsFields\":{}"));
}
Aggregations