use of org.openntf.domino.graph2.annotations.MixedFramedVertexList in project org.openntf.domino by OpenNTF.
the class TermsResource method getTermsObject.
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getTermsObject(@Context final UriInfo uriInfo, @PathParam(Routes.NAMESPACE) final String namespace, @Context final Request request) throws JsonException, IOException {
DFramedTransactionalGraph graph = this.getGraph(namespace);
ParamMap pm = Parameters.toParamMap(uriInfo);
StringWriter sw = new StringWriter();
JsonGraphWriter writer = new JsonGraphWriter(sw, graph, pm, false, true, true);
try {
List<CharSequence> types = new ArrayList<CharSequence>();
types.add("org.openntf.domino.graph2.builtin.search.Term");
List<CharSequence> filterkeys = pm.getFilterKeys();
List<CharSequence> filtervalues = pm.getFilterValues();
List<CharSequence> partialkeys = pm.getPartialKeys();
List<CharSequence> partialvalues = pm.getPartialValues();
List<CharSequence> startskeys = pm.getStartsKeys();
List<CharSequence> startsvalues = pm.getStartsValues();
if (types.size() == 0) {
writer.outNull();
} else if (types.size() == 1) {
CharSequence typename = types.get(0);
Iterable<?> elements = null;
if (filterkeys != null) {
elements = graph.getFilteredElements(typename.toString(), filterkeys, filtervalues);
} else if (partialkeys != null) {
elements = graph.getFilteredElementsPartial(typename.toString(), partialkeys, partialvalues);
} else if (startskeys != null) {
elements = graph.getFilteredElementsStarts(typename.toString(), startskeys, startsvalues);
} else {
elements = graph.getElements(typename.toString());
}
if (elements instanceof FramedEdgeList) {
List<?> result = sortAndLimitList((List<?>) elements, pm);
writer.outArrayLiteral(result);
} else if (elements instanceof FramedVertexList) {
List<?> result = sortAndLimitList((List<?>) elements, pm);
writer.outArrayLiteral(result);
} else {
List<Object> maps = new ArrayList<Object>();
for (Object element : elements) {
maps.add(element);
}
writer.outArrayLiteral(maps);
}
} else {
MixedFramedVertexList vresult = null;
FramedEdgeList eresult = null;
for (CharSequence typename : types) {
Iterable<?> elements = null;
if (filterkeys != null) {
elements = graph.getFilteredElements(typename.toString(), filterkeys, filtervalues);
} else if (partialkeys != null) {
elements = graph.getFilteredElementsPartial(typename.toString(), partialkeys, partialvalues);
} else if (startskeys != null) {
elements = graph.getFilteredElementsStarts(typename.toString(), startskeys, startsvalues);
} else {
elements = graph.getElements(typename.toString());
}
if (elements instanceof FramedVertexList) {
if (vresult == null) {
vresult = new MixedFramedVertexList(graph, null, (FramedVertexList) elements);
} else {
vresult.addAll((List<?>) elements);
}
} else if (elements instanceof FramedEdgeList) {
if (eresult == null) {
eresult = (FramedEdgeList) elements;
} else {
eresult.addAll((FramedEdgeList) elements);
}
}
}
if (vresult != null) {
List<?> result = sortAndLimitList(vresult, pm);
writer.outArrayLiteral(result);
}
if (eresult != null) {
List<?> result = sortAndLimitList(eresult, pm);
writer.outArrayLiteral(result);
}
}
} catch (UserAccessException uae) {
throw new WebApplicationException(ErrorHelper.createErrorResponse(uae, Response.Status.UNAUTHORIZED));
} catch (Exception e) {
throw new WebApplicationException(ErrorHelper.createErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
}
String jsonEntity = sw.toString();
ResponseBuilder berg = getBuilder(jsonEntity, new Date(), true, request);
Response response = berg.build();
return response;
}
use of org.openntf.domino.graph2.annotations.MixedFramedVertexList in project org.openntf.domino by OpenNTF.
the class FramedCollectionResource method getFramedObject.
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getFramedObject(@Context final UriInfo uriInfo, @PathParam(Routes.NAMESPACE) final String namespace, @Context final Request request) throws JsonException, IOException {
DFramedTransactionalGraph graph = this.getGraph(namespace);
ParamMap pm = Parameters.toParamMap(uriInfo);
StringWriter sw = new StringWriter();
JsonGraphWriter writer = new JsonGraphWriter(sw, graph, pm, false, true, true);
try {
if (pm.getTypes() != null) {
List<CharSequence> types = pm.getTypes();
List<CharSequence> filterkeys = pm.getFilterKeys();
List<CharSequence> filtervalues = pm.getFilterValues();
List<CharSequence> partialkeys = pm.getPartialKeys();
List<CharSequence> partialvalues = pm.getPartialValues();
List<CharSequence> startskeys = pm.getStartsKeys();
List<CharSequence> startsvalues = pm.getStartsValues();
if (types.size() == 0) {
writer.outNull();
} else if (types.size() == 1) {
long startTime = new Date().getTime();
CharSequence typename = types.get(0);
Iterable<?> elements = null;
if (filterkeys != null) {
elements = graph.getFilteredElements(typename.toString(), filterkeys, filtervalues);
} else if (partialkeys != null) {
elements = graph.getFilteredElementsPartial(typename.toString(), partialkeys, partialvalues);
} else if (startskeys != null) {
elements = graph.getFilteredElementsStarts(typename.toString(), startskeys, startsvalues);
} else {
elements = graph.getElements(typename.toString());
}
if (elements instanceof FramedEdgeList) {
List<?> result = sortAndLimitList((List<?>) elements, pm);
writer.outArrayLiteral(result);
} else if (elements instanceof FramedVertexList) {
List<?> result = sortAndLimitList((List<?>) elements, pm);
writer.outArrayLiteral(result);
} else {
List<Object> maps = new ArrayList<Object>();
for (Object element : elements) {
maps.add(element);
}
writer.outArrayLiteral(maps);
}
long endTime = new Date().getTime();
System.out.println("TEMP DEBUG Output for " + typename + " took " + (endTime - startTime) + "ms");
} else {
MixedFramedVertexList vresult = null;
FramedEdgeList eresult = null;
for (CharSequence typename : types) {
Iterable<?> elements = null;
if (filterkeys != null) {
elements = graph.getFilteredElements(typename.toString(), filterkeys, filtervalues);
} else if (partialkeys != null) {
elements = graph.getFilteredElementsPartial(typename.toString(), partialkeys, partialvalues);
} else if (startskeys != null) {
elements = graph.getFilteredElementsStarts(typename.toString(), startskeys, startsvalues);
} else {
elements = graph.getElements(typename.toString());
}
/*
* if (elements != null) { System.out.
* println("TEMP DEBUG found elements for type " +
* typename.toString()); } else {
* System.out.println("TEMP DEBUG NO elements for type "
* + typename.toString()); }
*/
if (elements instanceof FramedVertexList) {
if (vresult == null) {
vresult = new MixedFramedVertexList(graph, null, (FramedVertexList) elements);
} else {
vresult.addAll((List<?>) elements);
}
} else if (elements instanceof FramedEdgeList) {
if (eresult == null) {
eresult = (FramedEdgeList) elements;
} else {
eresult.addAll((FramedEdgeList) elements);
}
}
}
if (vresult != null) {
List<?> result = sortAndLimitList(vresult, pm);
writer.outArrayLiteral(result);
}
if (eresult != null) {
List<?> result = sortAndLimitList(eresult, pm);
writer.outArrayLiteral(result);
}
}
} else {
// System.out.println("TEMP DEBUG: ID was null therefore we
// can't report...");
Map<String, Object> jsonMap = new LinkedHashMap<String, Object>();
jsonMap.put("namespace", namespace);
jsonMap.put("status", "active");
writer.outObject(jsonMap);
}
} catch (UserAccessException uae) {
throw new WebApplicationException(ErrorHelper.createErrorResponse(uae, Response.Status.UNAUTHORIZED));
} catch (Exception e) {
throw new WebApplicationException(ErrorHelper.createErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
}
String jsonEntity = sw.toString();
ResponseBuilder berg = getBuilder(jsonEntity, new Date(), true, request);
Response response = berg.build();
return response;
}
use of org.openntf.domino.graph2.annotations.MixedFramedVertexList in project org.openntf.domino by OpenNTF.
the class MixedFramedVertexList method applyFilter.
public MixedFramedVertexList applyFilter(final String key, final Object value) {
DVertexList vertList = new DVertexList((DVertex) sourceVertex_);
if (this.size() > 0) {
for (Object raw : this) {
VertexFrame vertex = (VertexFrame) raw;
try {
if ("@type".equals(key)) {
if (DGraphUtils.isType(vertex, TypeUtils.toString(value))) {
vertList.add((DVertex) vertex.asVertex());
}
} else {
Object vertexVal = DGraphUtils.getFramedProperty(getGraph(), vertex, key);
if (vertexVal instanceof Collection) {
for (Object rawVal : (Collection) vertexVal) {
if (value.equals(TypeUtils.toString(rawVal))) {
vertList.add((DVertex) vertex.asVertex());
}
}
} else {
if (value.equals(TypeUtils.toString(vertexVal))) {
vertList.add((DVertex) vertex.asVertex());
}
}
}
} catch (Throwable t) {
t.printStackTrace();
}
}
}
MixedFramedVertexList result = new MixedFramedVertexList(getGraph(), sourceVertex_, vertList);
return result;
}
Aggregations