Search in sources :

Example 1 with NoteCoordinate

use of org.openntf.domino.big.NoteCoordinate in project org.openntf.domino by OpenNTF.

the class DElementIterable method containsAll.

@Override
public boolean containsAll(final Collection<?> c) {
    List<NoteCoordinate> nclist = new ArrayList<NoteCoordinate>();
    for (Object raw : c) {
        if (raw instanceof Element) {
            Element e = (Element) raw;
            Object rawid = e.getId();
            if (rawid instanceof NoteCoordinate) {
                nclist.add((NoteCoordinate) rawid);
            }
        }
    }
    return index_.containsAll(nclist);
}
Also used : NoteCoordinate(org.openntf.domino.big.NoteCoordinate) Element(com.tinkerpop.blueprints.Element) ArrayList(java.util.ArrayList)

Example 2 with NoteCoordinate

use of org.openntf.domino.big.NoteCoordinate in project org.openntf.domino by OpenNTF.

the class DElementIterable method toArray.

@Override
public Object[] toArray() {
    int size = index_.size();
    Object[] result = new Object[size];
    for (int i = 0; i < size; i++) {
        NoteCoordinate e = index_.get(i);
        result[i] = store_.getElement(e);
    }
    return result;
}
Also used : NoteCoordinate(org.openntf.domino.big.NoteCoordinate)

Example 3 with NoteCoordinate

use of org.openntf.domino.big.NoteCoordinate in project org.openntf.domino by OpenNTF.

the class DElementStore method getVertexIds.

// @Override
// public Set<Vertex> getCachedVertices() {
// FastSet<Vertex> result = new FastSet<Vertex>();
// for (Element elem : getElementCache().values()) {
// if (elem instanceof Vertex) {
// result.add((Vertex) elem);
// }
// }
// return result.unmodifiable();
// }
protected List<NoteCoordinate> getVertexIds() {
    FastTable<NoteCoordinate> result = new FastTable<NoteCoordinate>();
    Object raw = getStoreDelegate();
    if (raw instanceof Database) {
        Database db = (Database) raw;
        NoteCollection nc = db.createNoteCollection(false);
        nc.setSelectDocuments(true);
        nc.setSelectionFormula(org.openntf.domino.graph2.DVertex.FORMULA_FILTER);
        nc.buildCollection();
        for (String noteid : nc) {
            result.add(NoteCoordinate.Utils.getNoteCoordinate(nc, noteid));
        }
    } else {
        // TODO NTF implement alternative
        throw new IllegalStateException("Non-Domino implementations not yet available");
    }
    return result;
}
Also used : NoteCoordinate(org.openntf.domino.big.NoteCoordinate) NoteCollection(org.openntf.domino.NoteCollection) FastTable(javolution.util.FastTable) Database(org.openntf.domino.Database)

Example 4 with NoteCoordinate

use of org.openntf.domino.big.NoteCoordinate in project org.openntf.domino by OpenNTF.

the class DElementStore method findElementDelegate.

// @Override
@Override
public Object findElementDelegate(final Object delegateKey) throws IllegalStateException, IllegalArgumentException {
    Object result = null;
    Object del = null;
    del = getStoreDelegate();
    if (isProxied()) {
        // System.out.println("TEMP DEBUG Retrieving from proxied store for key " + String.valueOf(delegateKey));
        NoteCoordinate nc = null;
        if (delegateKey instanceof NoteCoordinate) {
            nc = (NoteCoordinate) delegateKey;
        } else if (delegateKey instanceof CharSequence) {
            nc = NoteCoordinate.Utils.getNoteCoordinate((CharSequence) delegateKey);
        }
        if (nc != null) {
            long dbkey = nc.getReplicaLong();
            if (getProxyStoreKey().equals(dbkey)) {
                del = getProxyStoreDelegate();
            }
        }
    }
    if (del instanceof Database) {
        Database db = (Database) del;
        boolean isDeletedDoc;
        db.getAncestorSession().setFixEnable(Fixes.MIME_BLOCK_ITEM_INTERFACE, false);
        if (delegateKey instanceof Serializable) {
            if (delegateKey instanceof ViewEntryCoordinate) {
                result = ((ViewEntryCoordinate) delegateKey).getViewEntry();
            } else if (delegateKey instanceof NoteCoordinate) {
                String unid = ((NoteCoordinate) delegateKey).getUNID();
                try {
                    result = db.getDocumentWithKey(unid, false);
                } catch (UserAccessException uae) {
                // this is normal and acceptable. Don't report.
                } catch (RuntimeException re) {
                    throw re;
                }
                if (result != null) {
                    if (((Document) result).isDeleted()) {
                        isDeletedDoc = true;
                        result = null;
                    }
                }
            // System.out.println("Retrieved result using NoteCoordinate with unid " + unid);
            } else if (delegateKey instanceof CharSequence) {
                String skey = ((CharSequence) delegateKey).toString();
                if (skey.length() > 50) {
                    String prefix = skey.subSequence(0, 2).toString();
                    String mid = skey.subSequence(2, 50).toString();
                    if ((prefix.equals("EC") || prefix.equals("ED") || prefix.equals("ET") || prefix.equals("EU")) && DominoUtils.isMetaversalId(mid)) {
                        ViewEntryCoordinate vec = ViewEntryCoordinate.Utils.getViewEntryCoordinate(skey);
                        result = vec.getViewEntry();
                    } else if ((prefix.equals("VC") || prefix.equals("VD") || prefix.equals("VT") || prefix.equals("VU")) && DominoUtils.isMetaversalId(mid)) {
                        ViewEntryCoordinate vec = ViewEntryCoordinate.Utils.getViewEntryCoordinate(skey);
                        result = vec.getViewEntry();
                    }
                }
            }
            if (result == null) {
                result = db.getDocumentWithKey((Serializable) delegateKey, false);
                if (result != null) {
                    if (((Document) result).isDeleted()) {
                        isDeletedDoc = true;
                        result = null;
                    }
                }
            }
            if (result != null) {
                // }
                if (isProxied()) {
                    // System.out.println("TEMP DEBUG from findElementDelegate: ElementStore "
                    // + ((Database) getStoreDelegate()).getApiPath() + "is proxied. Setting up proxy on delegate...");
                    result = setupProxy(result, (Serializable) delegateKey);
                } else {
                // System.out.println("TEMP DEBUG ElementStore " + ((Database) getStoreDelegate()).getApiPath() + " is not proxied.");
                }
            }
        } else {
            if (delegateKey != null) {
                System.out.println("WARNING: Unknown delegatekey of type " + delegateKey.getClass().getName() + ". Creating a brand new delegate.");
            }
            // null is a perfectly valid key, since it means we want to let the system assign it.
            result = db.createDocument();
        // throw new IllegalArgumentException("Cannot find a delegate with a key of type "
        // + (delegateKey == null ? "null" : delegateKey.getClass().getName()));
        }
    } else {
        throw new IllegalStateException("ElementStore delegate is not a Database; it's a " + (del == null ? "null" : del.getClass().getName()) + ". We don't handle this case yet.");
    // TODO NTF alternative strategies...
    }
    // }
    return result;
}
Also used : NoteCoordinate(org.openntf.domino.big.NoteCoordinate) Serializable(java.io.Serializable) Document(org.openntf.domino.Document) UserAccessException(org.openntf.domino.exceptions.UserAccessException) ViewEntryCoordinate(org.openntf.domino.big.ViewEntryCoordinate) Database(org.openntf.domino.Database)

Example 5 with NoteCoordinate

use of org.openntf.domino.big.NoteCoordinate in project org.openntf.domino by OpenNTF.

the class DElementStore method setupProxy.

@SuppressWarnings("unchecked")
protected DProxyVertex setupProxy(final Object proxy, final Serializable originalKey) {
    // System.out.println("TEMP DEBUG Setting up proxy vertex");
    DProxyVertex result = new DProxyVertex(getConfiguration().getGraph(), (Map<String, Object>) proxy);
    Object rawpid = result.getProxiedId();
    if (rawpid != null) {
        if (result.getProxyDelegate() == null) {
            DElement elem = (DElement) getConfiguration().getGraph().getElement(rawpid);
            if (elem == null) {
                rawpid = null;
            }
        }
    }
    if (rawpid == null) {
        CustomProxyResolver resolver = getCustomProxyResolver();
        if (resolver == null) {
            System.err.println("No default resolver implemented yet");
            throw new UnimplementedException("Generics resolution of proxied vertices not yet implemented");
        } else {
            // System.out.println("Resolving using a " + resolver.getClass().getName());
            Map<String, Object> originalDelegate = resolver.getOriginalDelegate(originalKey);
            if (originalDelegate instanceof Document) {
                String pid = ((Document) originalDelegate).getMetaversalID();
                NoteCoordinate nc = NoteCoordinate.Utils.getNoteCoordinate(pid);
                // System.out.println("Setting up proxy with id " + nc.toString());
                try {
                    result.setProxiedId(nc);
                } catch (Throwable t) {
                    t.printStackTrace();
                }
            } else {
                if (originalDelegate == null) {
                // System.out.println("No original delegate found for key " + String.valueOf(originalKey));
                } else {
                // System.err.println("original delegate returned a " + originalDelegate.getClass().getName());
                }
            }
        }
    } else {
    }
    // System.out.println("Setup a proxy with an id of " + String.valueOf(result.getProxiedId()));
    return result;
}
Also used : NoteCoordinate(org.openntf.domino.big.NoteCoordinate) Document(org.openntf.domino.Document) UnimplementedException(org.openntf.domino.exceptions.UnimplementedException)

Aggregations

NoteCoordinate (org.openntf.domino.big.NoteCoordinate)31 CaseInsensitiveString (org.openntf.domino.types.CaseInsensitiveString)9 Database (org.openntf.domino.Database)8 ArrayList (java.util.ArrayList)7 LinkedHashMap (java.util.LinkedHashMap)7 UserAccessException (org.openntf.domino.exceptions.UserAccessException)7 JsonJavaObject (com.ibm.commons.util.io.json.JsonJavaObject)6 Element (com.tinkerpop.blueprints.Element)6 VertexFrame (com.tinkerpop.frames.VertexFrame)6 HashMap (java.util.HashMap)6 NoteCollection (org.openntf.domino.NoteCollection)6 JsonException (com.ibm.commons.util.io.json.JsonException)5 Edge (com.tinkerpop.blueprints.Edge)5 EdgeFrame (com.tinkerpop.frames.EdgeFrame)5 IOException (java.io.IOException)5 WebApplicationException (javax.ws.rs.WebApplicationException)5 DVertexFrame (org.openntf.domino.graph2.builtin.DVertexFrame)5 List (java.util.List)4 FastTable (javolution.util.FastTable)4 Document (org.openntf.domino.Document)4