use of com.tinkerpop.frames.VertexFrame in project org.openntf.domino by OpenNTF.
the class JsonSearchAdapter method putJsonProperty.
@Override
public void putJsonProperty(final String paramKey, Object value) {
Object frame = getFrame();
if (frame != null) {
CaseInsensitiveString key = new CaseInsensitiveString(paramKey);
Method crystal = getSetters().get(key);
if (crystal != null) {
try {
Class<?>[] types = crystal.getParameterTypes();
Class<?> type = types[0];
if (value == null) {
String propName = null;
TypedProperty tprop = crystal.getAnnotation(TypedProperty.class);
if (tprop != null) {
propName = tprop.value();
} else {
Property prop = crystal.getAnnotation(Property.class);
if (prop != null) {
propName = prop.value();
}
}
if (propName != null) {
if (frame instanceof VertexFrame) {
((VertexFrame) frame).asVertex().setProperty(propName, null);
} else if (frame instanceof EdgeFrame) {
((EdgeFrame) frame).asEdge().setProperty(propName, null);
}
} else {
System.err.println("ALERT the next operation will probably throw an exception");
Object[] nullarg = { type.cast(null) };
crystal.invoke(frame, nullarg);
}
} else if (!type.isAssignableFrom(value.getClass())) {
value = TypeUtils.convertToTarget(value, type, org.openntf.domino.utils.Factory.getSession(SessionType.CURRENT));
crystal.invoke(frame, value);
} else if (JsonJavaObject.class.equals(type)) {
// FIXME NTF this is a complete hack :(
TypedProperty prop = crystal.getAnnotation(TypedProperty.class);
String itemname = prop.value();
if (frame instanceof DVertexFrame) {
Document doc = ((DVertexFrame) frame).asDocument();
TypeUtils.writeToItem(doc, itemname, value, false);
}
} else {
crystal.invoke(frame, value);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
} else {
Method man = getGetters().get(key);
if (man == null) {
// undefined property
if (frame instanceof EdgeFrame) {
((EdgeFrame) frame).asEdge().setProperty(paramKey, value);
} else if (frame instanceof VertexFrame) {
((VertexFrame) frame).asVertex().setProperty(paramKey, value);
}
} else {
// NTF if there is a getter but no setter, this is a
// read-only property. Disregard the JSON
}
}
}
}
use of com.tinkerpop.frames.VertexFrame in project org.openntf.domino by OpenNTF.
the class JsonSearchAdapter method getJsonProperties.
@Override
public Iterator<String> getJsonProperties() {
List<String> result = new ArrayList<String>();
result.add("@id");
result.add("@type");
result.add("@editable");
if (getIncludeDebug()) {
result.add("@debug");
}
Collection<CharSequence> props = getProperties();
if (props == null) {
// NoteCoordinate nc = (NoteCoordinate)
// ((VertexFrame)frame_).asVertex().getId();
props = new ArrayList<CharSequence>();
props.addAll(getGetters().keySet());
if (props == null || props.size() < 5) {
if (frame_ instanceof DVertexFrame) {
try {
Set<String> raw = ((DVertexFrame) frame_).asVertex().getPropertyKeys();
props.addAll(CaseInsensitiveString.toCaseInsensitive(raw));
} catch (Throwable t) {
Throwable cause = t.getCause();
if (cause != null) {
System.err.println("Exception trying to process a frame of type " + DGraphUtils.findInterface(frame_) + " resulting in a " + cause.getClass().getSimpleName());
cause.printStackTrace();
try {
throw cause;
} catch (Throwable e) {
e.printStackTrace();
}
}
}
} else if (frame_ instanceof DEdgeFrame) {
// Set<CharSequence> raw = ((DEdgeFrame)
// frame_).asMap().keySet();
// props.addAll(CaseInsensitiveString.toCaseInsensitive(raw));
}
}
}
for (CharSequence cis : props) {
result.add(cis.toString());
}
Object frame = getFrame();
if (frame instanceof VertexFrame && getIncludeEdges()) {
result.add("@edges");
}
if (getIncludeActions()) {
result.add("@actions");
}
if (frame instanceof VertexFrame && getIncludeCounts()) {
for (CaseInsensitiveString key : getCounters().keySet()) {
result.add("@counts" + key.toString());
}
}
if (frame instanceof VertexFrame) {
Vertex v = ((VertexFrame) frame).asVertex();
if (v instanceof DProxyVertex) {
result.add("@proxyid");
}
}
if (frame instanceof VertexFrame && getLabels() != null) {
for (CharSequence cis : getLabels()) {
result.add("#" + cis.toString());
}
}
if (frame instanceof EdgeFrame) {
result.add("@in");
result.add("@out");
}
if (frame instanceof ViewVertex) {
result.add("@columninfo");
}
if (frame instanceof ViewVertex.Contains) {
Edge edge = ((ViewVertex.Contains) frame).asEdge();
if (edge instanceof DEdge) {
result.addAll(((DEdge) edge).getDelegate().keySet());
}
}
Collection<CharSequence> hideProps = getHideProperties();
if (hideProps != null && !hideProps.isEmpty()) {
for (CharSequence cis : hideProps) {
result.remove(cis.toString());
}
}
return result.iterator();
}
use of com.tinkerpop.frames.VertexFrame in project org.openntf.domino by OpenNTF.
the class JsonGraphWriter method outObject.
@Override
public void outObject(Object paramObject) throws IOException, JsonException {
// + (paramObject == null ? "NULL" : paramObject.getClass().getName()));
try {
if (paramObject != null) {
Class<?> objClass = paramObject.getClass();
IJsonWriterAdapter adapter = factory_.getJsonWriterAdapter(objClass);
if (adapter != null) {
paramObject = adapter.toJson(paramObject);
}
}
if (paramObject == null) {
super.outNull();
// } else if (paramObject instanceof Term) {
// JsonSearchAdapter adapter = new JsonSearchAdapter(graph_, (Term) paramObject, parameters_,
// isCollectionRoute_);
// super.outObject(adapter);
// } else if (paramObject instanceof Value) {
// JsonSearchAdapter adapter = new JsonSearchAdapter(graph_, (Value) paramObject, parameters_,
// isCollectionRoute_);
// super.outObject(adapter);
// } else if (paramObject instanceof RichTextReference) {
// JsonSearchAdapter adapter = new JsonSearchAdapter(graph_, (RichTextReference) paramObject, parameters_,
// isCollectionRoute_);
// super.outObject(adapter);
} else if (paramObject instanceof EdgeFrame) {
JsonFrameAdapter adapter = new JsonFrameAdapter(graph_, (EdgeFrame) paramObject, parameters_, isCollectionRoute_);
super.outObject(adapter);
} else if (paramObject instanceof VertexFrame) {
JsonFrameAdapter adapter = new JsonFrameAdapter(graph_, (VertexFrame) paramObject, parameters_, isCollectionRoute_);
super.outObject(adapter);
} else if (paramObject instanceof Class<?>) {
String className = ((Class<?>) paramObject).getName();
super.outStringLiteral(className);
} else if (paramObject instanceof RichTextItem) {
outRichTextItem((RichTextItem) paramObject);
} else if (paramObject instanceof Enum) {
String className = ((Enum<?>) paramObject).getClass().getName();
String enumName = ((Enum<?>) paramObject).name();
} else if (paramObject instanceof NoteCoordinate) {
String nc = ((NoteCoordinate) paramObject).toString();
super.outStringLiteral(nc);
} else if (paramObject instanceof org.openntf.domino.impl.View.DominoColumnInfo) {
String itemName = ((org.openntf.domino.impl.View.DominoColumnInfo) paramObject).getItemName();
super.outStringLiteral(itemName);
} else if (paramObject instanceof Set) {
// System.out.println("TEMP DEBUG outObject received a Set");
outArrayLiteral(((Set) paramObject).toArray());
} else if (paramObject instanceof DateTime) {
outDateLiteral((DateTime) paramObject);
} else if (paramObject instanceof DateRange) {
outDateRangeLiteral((DateRange) paramObject);
} else if (paramObject instanceof NoteCoordinate) {
outNoteCoordinate((NoteCoordinate) paramObject);
} else if (paramObject instanceof Throwable) {
outException((Throwable) paramObject);
} else {
// Class<?> clazz = paramObject.getClass();
// String name = clazz.getName();
super.outObject(paramObject);
}
} catch (UserAccessException uae) {
throw uae;
} catch (RuntimeException re) {
throw re;
} catch (Throwable t) {
t.printStackTrace();
}
}
use of com.tinkerpop.frames.VertexFrame in project org.openntf.domino by OpenNTF.
the class AbstractIncidenceHandler method processVertexIncidence.
@SuppressWarnings({ "rawtypes", "unchecked" })
public Object processVertexIncidence(final Annotation annotation, final Method method, final Object[] arguments, final FramedGraph framedGraph, final Vertex vertex) {
Direction dir = Direction.BOTH;
String label = "";
boolean unique = false;
if (annotation instanceof Adjacency) {
dir = ((Adjacency) annotation).direction();
label = ((Adjacency) annotation).label();
} else if (annotation instanceof AdjacencyUnique) {
dir = ((AdjacencyUnique) annotation).direction();
label = ((AdjacencyUnique) annotation).label();
unique = true;
} else if (annotation instanceof Incidence) {
dir = ((Incidence) annotation).direction();
label = ((Incidence) annotation).label();
} else if (annotation instanceof IncidenceUnique) {
dir = ((IncidenceUnique) annotation).direction();
label = ((IncidenceUnique) annotation).label();
unique = true;
}
if (ClassUtilities.isGetMethod(method)) {
Class<?> returnType = method.getReturnType();
if (Iterable.class.isAssignableFrom(returnType)) {
DEdgeList edgeList = (DEdgeList) vertex.getEdges(dir, label);
edgeList.setUnique(unique);
return new FramedEdgeList(framedGraph, vertex, edgeList, ClassUtilities.getGenericClass(method));
} else if (Edge.class.isAssignableFrom(returnType)) {
Iterator<Edge> it = vertex.getEdges(dir, label).iterator();
if (it.hasNext()) {
return it.next();
} else {
return null;
}
} else {
Iterator<Edge> it = vertex.getEdges(dir, label).iterator();
if (it.hasNext()) {
Edge e = it.next();
return framedGraph.frame(e, returnType);
} else {
return null;
}
}
} else if (AnnotationUtilities.isFindMethod(method)) {
Vertex newVertex;
Edge resultEdge = null;
newVertex = ((VertexFrame) arguments[0]).asVertex();
resultEdge = findEdge(annotation, framedGraph, vertex, newVertex);
if (resultEdge != null) {
return framedGraph.frame(resultEdge, method.getReturnType());
}
} else if (AnnotationUtilities.isCountMethod(method)) {
return countEdges(annotation, vertex);
} else if (ClassUtilities.isAddMethod(method)) {
Vertex newVertex;
Edge resultEdge = null;
newVertex = ((VertexFrame) arguments[0]).asVertex();
if (unique) {
resultEdge = findEdge(annotation, framedGraph, vertex, newVertex);
}
if (resultEdge == null) {
String replicaid = null;
if (framedGraph instanceof DFramedTransactionalGraph) {
DElementStore store = ((DFramedTransactionalGraph) framedGraph).getElementStore(method.getReturnType());
long rawkey = store.getStoreKey();
replicaid = NoteCoordinate.Utils.getReplidFromLong(rawkey);
}
resultEdge = addEdge(annotation, framedGraph, vertex, newVertex, replicaid);
}
return framedGraph.frame(resultEdge, method.getReturnType());
} else if (ClassUtilities.isRemoveMethod(method)) {
framedGraph.removeEdge(((EdgeFrame) arguments[0]).asEdge());
return null;
}
return null;
}
use of com.tinkerpop.frames.VertexFrame in project org.openntf.domino by OpenNTF.
the class FramedVertexList method applyFilter.
public FramedVertexList<T> applyFilter(final String key, final Object value) {
DVertexList vertList = new DVertexList((DVertex) sourceVertex_);
if (this.size() > 0) {
for (VertexFrame vertex : this) {
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();
}
}
}
FramedVertexList result = new FramedVertexList(getGraph(), sourceVertex_, vertList, this.kind);
return result;
}
Aggregations