Search in sources :

Example 1 with UserAccessException

use of org.openntf.domino.exceptions.UserAccessException in project org.openntf.domino by OpenNTF.

the class Database method resurrect.

@Override
public void resurrect() {
    // should only happen if the delegate has been destroyed somehow.
    // clear metaData
    shadowedMetaData_ = null;
    lotus.domino.Session rawSession = toLotus(parent);
    try {
        lotus.domino.Database d = rawSession.getDatabase(server_, path_);
        setDelegate(d, true);
    /* No special logging, since by now Database is a BaseThreadSafe */
    } catch (NotesException e) {
        if (e.id == NotesError.NOTES_ERR_DBNOACCESS) {
            throw new UserAccessException("User " + parent.getEffectiveUserName() + " cannot open database " + path_ + " on server " + server_, e);
        } else {
            DominoUtils.handleException(e, this);
        }
    }
}
Also used : OpenNTFNotesException(org.openntf.domino.exceptions.OpenNTFNotesException) NotesException(lotus.domino.NotesException) UserAccessException(org.openntf.domino.exceptions.UserAccessException)

Example 2 with UserAccessException

use of org.openntf.domino.exceptions.UserAccessException in project org.openntf.domino by OpenNTF.

the class Database method getDocumentWithKey.

@Override
public Document getDocumentWithKey(final Serializable key, final boolean createOnFail) {
    try {
        if (key != null) {
            if (key instanceof String && ((String) key).length() == 32) {
                if ("000000000000000000000000000000000000".equals(key)) {
                    // $NON-NLS-1$
                    Document result = getIconNote();
                    if (result == null) {
                        result = getACLNote();
                    }
                    return result;
                }
            }
            String checksum = DominoUtils.toUnid(key);
            Document doc = this.getDocumentByUNID(checksum);
            if (doc == null && createOnFail) {
                doc = this.createDocument();
                if (checksum != null) {
                    doc.setUniversalID(checksum, true);
                }
                // $NON-NLS-1$
                doc.replaceItemValue("$$Key", key);
                // $NON-NLS-1$
                doc.replaceItemValue("$Created", new Date());
            }
            return doc;
        } else if (createOnFail) {
            // log_.log(java.util.logging.Level.FINE,
            // "Document by key requested with null key. This is probably not what you meant to do...");
            // NTF No, its exactly what we meant to do in the case of graph elements
            Document doc = this.createDocument();
            // $NON-NLS-1$
            doc.replaceItemValue("$Created", new Date());
            // doc.replaceItemValue("$$Key", "");
            return doc;
        }
    } catch (UserAccessException uae) {
        throw uae;
    } catch (Exception e) {
        DominoUtils.handleException(e, this);
    }
    return null;
}
Also used : Document(org.openntf.domino.Document) UserAccessException(org.openntf.domino.exceptions.UserAccessException) Date(java.util.Date) OpenNTFNotesException(org.openntf.domino.exceptions.OpenNTFNotesException) FileNotFoundException(java.io.FileNotFoundException) TransactionAlreadySetException(org.openntf.domino.exceptions.TransactionAlreadySetException) UserAccessException(org.openntf.domino.exceptions.UserAccessException) InvalidClassException(java.io.InvalidClassException) NotesException(lotus.domino.NotesException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 3 with UserAccessException

use of org.openntf.domino.exceptions.UserAccessException in project org.openntf.domino by OpenNTF.

the class Session method getDatabase.

/*
	 * (non-Javadoc)
	 *
	 * @see org.openntf.domino.Session#getDatabase(java.lang.String, java.lang.String, boolean)
	 */
@Override
public org.openntf.domino.Database getDatabase(final String server, final String db, final boolean createOnFail) {
    // Handle quickly the case of .getDatabase("", "")
    if ((server == null || server.isEmpty()) && (db == null || db.isEmpty())) {
        try {
            synchronized (getDB_lock) {
                return fromLotus(getDelegate().getDatabase("", ""), Database.SCHEMA, this);
            }
        } catch (NotesException e) {
            DominoUtils.handleException(e, this);
            return null;
        }
    }
    if (db == null || db.isEmpty()) {
        throw new IllegalArgumentException("Filepath argument cannot be null or empty string unless the server is also empty.");
    }
    // try {
    lotus.domino.Database database = null;
    org.openntf.domino.Database result = null;
    if (result == null) {
        try {
            boolean isDbRepId = DominoUtils.isReplicaId(db);
            if (isDbRepId) {
                lotus.domino.Database nullDb;
                synchronized (getDB_lock) {
                    nullDb = getDelegate().getDatabase(null, null);
                }
                boolean opened = nullDb.openByReplicaID(server, db);
                if (opened) {
                    result = fromLotus(nullDb, Database.SCHEMA, this);
                } else {
                    s_recycle(nullDb);
                    result = null;
                }
            } else {
                synchronized (getDB_lock) {
                    database = getDelegate().getDatabase(server, db, createOnFail);
                }
                result = fromLotus(database, Database.SCHEMA, this);
            }
        // if (isDbCached_ && result != null) {
        // databases_.put(key, result);
        // if (isDbRepId) {
        // databases_.put(result.getApiPath(), result);
        // } else {
        // databases_.put(result.getMetaReplicaID(), result);
        // }
        // }
        } catch (NotesException e) {
            if (e.id == NotesError.NOTES_ERR_DBNOACCESS) {
                throw new UserAccessException("User " + getEffectiveUserName() + " cannot open database " + db + " on server " + server, e);
            } else {
                DominoUtils.handleException(e, this);
                return null;
            }
        }
    }
    return result;
// } catch (Exception e) {
// DominoUtils.handleException(e);
// return null;
// }
}
Also used : OpenNTFNotesException(org.openntf.domino.exceptions.OpenNTFNotesException) NotesException(lotus.domino.NotesException) UserAccessException(org.openntf.domino.exceptions.UserAccessException) Database(org.openntf.domino.Database)

Example 4 with UserAccessException

use of org.openntf.domino.exceptions.UserAccessException 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 UserAccessException

use of org.openntf.domino.exceptions.UserAccessException in project org.openntf.domino by OpenNTF.

the class DElementStore method getElement.

@Override
public Element getElement(final Object id) throws IllegalStateException {
    try {
        // if (isProxied()) {
        // System.out.println("Getting a proxied element for id: " + String.valueOf(id));
        // }
        NoteCoordinate nc = normalizeId((Serializable) id);
        Element result = null;
        // if (nc.getReplicaId().equalsIgnoreCase("852582F7007073B5")) {
        // System.out.println("Getting a demo document " + nc + " from the element cache");
        // result = getElementCache().get(nc);
        // if (result != null) {
        // System.out.println(
        // "Result was loaded from cache with id " + nc + " and cache now has " + getElementCache().size() + " elements");
        // 
        // }
        // } else {
        result = getElementCache().get(nc);
        // + System.identityHashCode(result));
        return result;
    } catch (InvalidCacheLoadException icle) {
        // "TEMP DEBUG invalidCacheLoad for id " + String.valueOf(id) + " from element store " + System.identityHashCode(this));
        return null;
    } catch (UncheckedExecutionException uee) {
        Throwable cause = uee.getCause();
        if (cause != null && cause instanceof UserAccessException) {
            throw new UserAccessException(cause.getMessage(), cause);
        } else {
            throw uee;
        }
    } catch (UserAccessException uae) {
        throw uae;
    } catch (Throwable t) {
        throw new IllegalStateException("Unable to retrieve id " + String.valueOf(id), t);
    }
}
Also used : NoteCoordinate(org.openntf.domino.big.NoteCoordinate) InvalidCacheLoadException(com.google.common.cache.CacheLoader.InvalidCacheLoadException) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) Element(com.tinkerpop.blueprints.Element) UserAccessException(org.openntf.domino.exceptions.UserAccessException)

Aggregations

UserAccessException (org.openntf.domino.exceptions.UserAccessException)16 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)7 Date (java.util.Date)7 List (java.util.List)7 JsonException (com.ibm.commons.util.io.json.JsonException)6 ParamMap (org.openntf.domino.rest.service.Parameters.ParamMap)6 JsonJavaObject (com.ibm.commons.util.io.json.JsonJavaObject)5 StringWriter (java.io.StringWriter)5 LinkedHashMap (java.util.LinkedHashMap)5 WebApplicationException (javax.ws.rs.WebApplicationException)5 Response (javax.ws.rs.core.Response)5 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)5 Database (org.openntf.domino.Database)5 Document (org.openntf.domino.Document)5 JsonGraphWriter (org.openntf.domino.rest.json.JsonGraphWriter)5 CaseInsensitiveString (org.openntf.domino.types.CaseInsensitiveString)5 EdgeFrame (com.tinkerpop.frames.EdgeFrame)4 VertexFrame (com.tinkerpop.frames.VertexFrame)4 Map (java.util.Map)4