Search in sources :

Example 6 with Database

use of org.openntf.domino.Database in project org.openntf.domino by OpenNTF.

the class Subform method getExplicitSubformsRecursive.

/* (non-Javadoc)
	 * @see org.openntf.domino.design.AnyFormOrSubform#getExplicitSubformsRecursive(java.util.List)
	 */
@Override
public List<String> getExplicitSubformsRecursive(final List<String> existingList) {
    Database db = getAncestorDatabase();
    DatabaseDesign dbDesign = db.getDesign();
    XMLNodeList nodes = getSubformNodes();
    ArrayList<String> subforms = new ArrayList<String>();
    for (XMLNode node : nodes) {
        // $NON-NLS-1$
        String name = node.getAttribute("name");
        if (!Strings.isBlankString(name)) {
            if (!existingList.contains(name)) {
                // $NON-NLS-1$
                existingList.add(node.getAttribute("name"));
                org.openntf.domino.design.Subform sf = dbDesign.getSubform(name);
                existingList.addAll(sf.getExplicitSubformsRecursive(subforms));
            }
        }
    }
    return existingList;
}
Also used : XMLNode(org.openntf.domino.utils.xml.XMLNode) DatabaseDesign(org.openntf.domino.design.DatabaseDesign) Database(org.openntf.domino.Database) ArrayList(java.util.ArrayList) XMLNodeList(org.openntf.domino.utils.xml.XMLNodeList)

Example 7 with Database

use of org.openntf.domino.Database 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 8 with Database

use of org.openntf.domino.Database in project org.openntf.domino by OpenNTF.

the class DocumentIterator method next.

/*
	 * (non-Javadoc)
	 * 
	 * @see java.util.Iterator#next()
	 */
@Override
public Document next() {
    Document result = null;
    if (hasNext()) {
        currentNoteid_ = Integer.toHexString(getIdArray()[getIndex()]);
        setIndex(getIndex() + 1);
        // Base.recycle(current_);
        try {
            Database db = collection_.getAncestorDatabase();
            lotus.domino.Document doc = db.getDocumentByID(currentNoteid_);
            if (doc instanceof org.openntf.domino.Document) {
                result = (org.openntf.domino.Document) doc;
            } else {
                result = wf_.fromLotus(doc, Document.SCHEMA, db);
            }
        // current_ = result;
        } catch (Throwable t) {
            DominoUtils.handleException(t);
        }
    }
    return result;
}
Also used : Database(org.openntf.domino.Database) Document(org.openntf.domino.Document)

Example 9 with Database

use of org.openntf.domino.Database in project org.openntf.domino by OpenNTF.

the class LogGeneratorOpenLog method log.

// private static boolean _xInitDone = false;
/*-------------------------------------------------------------*/
// private static void doStaticStartUp() {
// ClassLoader loader = Thread.currentThread().getContextClassLoader();
// try {
// Class<?> xotsDemonClass = Class.forName(_xotsDemonClassName, true, loader);
// Method xotsDemonToQueueMethod = xotsDemonClass.getMethod(_xotsDemonToQueueMethodName, Runnable.class);
// LogTaskletOpenLog tol = new LogTaskletOpenLog();
// _olQueue = new LinkedBlockingQueue<LogGeneratorOpenLog.OL_EntryToWrite>();
// xotsDemonToQueueMethod.invoke(null, tol);
// } catch (Exception e) {
// System.out.println("Can't make Xots-LogDB-Thread: " + e.getMessage());
// _olQueue = null;
// } finally {
// _xInitDone = true;
// }
// }
/*-------------------------------------------------------------*/
// TODO RPR: remove synchronized
synchronized void log(final Session sess, LogRecord logRec, final LogRecordAdditionalInfo lrai) {
    // if (!_xInitDone)
    // doStaticStartUp();
    OL_LogRecord ollr = new OL_LogRecord(logRec, lrai.getExceptionDetails(), lrai.getLastWrappedDocs());
    Exception localExc = null;
    try {
        ollr._serverName = sess.getServerName();
        ollr._agentName = Factory.getRunContext().name();
        Database currDB = sess.getCurrentDatabase();
        if (currDB != null) {
            ollr._dbPath = currDB.getFilePath();
            ollr._accessLevel = getAccessLevel(currDB);
        }
        ollr._userName = sess.getUserName();
        ollr._effectiveUserName = sess.getEffectiveUserName();
        // $NON-NLS-1$
        ollr._userRoles = sess.evaluate("@UserRoles");
        String clVer = sess.getNotesVersion();
        if (clVer != null) {
            // $NON-NLS-1$
            ollr._clientVersion = clVer.split("\\|");
            for (int i = 0; i < ollr._clientVersion.length; i++) {
                ollr._clientVersion[i] = ollr._clientVersion[i].trim();
            }
        }
    } catch (Exception e) {
        printException(e);
        ollr._clientVersion = new String[] { "Exception while collecting logg data!", "See next LogEntry for details." };
        localExc = e;
    }
    if (_olQueue != null) {
        _olQueue.add(new OL_EntryToWrite(this, ollr));
    } else {
        _olWriter.writeLogRecToDB(sess, ollr, _startTime);
    }
    if (localExc == null) {
        return;
    }
    logRec = new LogRecord(Level.SEVERE, "Exception in LogGenerator.log");
    logRec.setThrown(localExc);
    logRec.setMillis(System.currentTimeMillis());
    ollr = new OL_LogRecord(logRec, null, null);
    // $NON-NLS-1$
    ollr._agentName = "LogGeneratorOpenLog";
    ollr._dbPath = _logDBPath;
    if (_olQueue != null) {
        _olQueue.add(new OL_EntryToWrite(this, ollr));
    } else {
        _olWriter.writeLogRecToDB(sess, ollr, _startTime);
    }
}
Also used : LogRecord(java.util.logging.LogRecord) Database(org.openntf.domino.Database) OpenNTFNotesException(org.openntf.domino.exceptions.OpenNTFNotesException) NotesException(lotus.domino.NotesException)

Example 10 with Database

use of org.openntf.domino.Database in project org.openntf.domino by OpenNTF.

the class BaseOpenLogItem method writeToLog.

/* (non-Javadoc)
	 * @see org.openntf.domino.logging.OpenLogItem#writeToLog()
	 */
@Override
public boolean writeToLog() {
    Database currDb = Factory.getSession(SessionType.CURRENT).getCurrentDatabase();
    // Current database may be null from Xots
    if (null == currDb) {
        if (!StringUtil.equals(getCurrentDatabasePath(), "")) {
            reinitialiseSettings();
        }
    } else {
        if (!StringUtil.equals(getCurrentDatabasePath(), Factory.getSession(SessionType.CURRENT).getCurrentDatabase().getFilePath())) {
            reinitialiseSettings();
        }
    }
    // exit early if there is no database
    Database db = getLogDb();
    if (db == null) {
        return false;
    }
    boolean retval = false;
    Document logDoc = null;
    RichTextItem rtitem = null;
    Database docDb = null;
    try {
        logDoc = db.createDocument();
        logDoc.appendItemValue("Form", _logFormName);
        Throwable ee = getBase();
        if (ee != null) {
            StackTraceElement ste = ee.getStackTrace()[0];
            if (ee instanceof NotesException) {
                logDoc.replaceItemValue("LogErrorNumber", ((NotesException) ee).id);
                logDoc.replaceItemValue("LogErrorMessage", ((NotesException) ee).text);
            } else {
                // Fixed next line
                logDoc.replaceItemValue("LogErrorMessage", getMessage());
            }
            logDoc.replaceItemValue("LogErrorLine", ste.getLineNumber());
            logDoc.replaceItemValue("LogFromMethod", ste.getClassName() + "." + ste.getMethodName());
        }
        if (LogType.TYPE_EVENT.getValue().equals(getEventType())) {
            if (!getSuppressEventStack()) {
                logDoc.replaceItemValue("LogStackTrace", getStackTrace(ee));
            }
        } else {
            logDoc.replaceItemValue("LogStackTrace", getStackTrace(ee));
        }
        logDoc.replaceItemValue("LogSeverity", getSeverity().getName());
        logDoc.replaceItemValue("LogEventTime", getEventTime());
        logDoc.replaceItemValue("LogEventType", getEventType());
        logDoc.replaceItemValue("LogMessage", getMessage());
        logDoc.replaceItemValue("LogFromDatabase", getCurrentDatabasePath());
        logDoc.replaceItemValue("LogFromServer", getThisServer());
        logDoc.replaceItemValue("LogFromAgent", getThisAgent());
        // Fixed next line
        logDoc.replaceItemValue("LogAgentLanguage", "Java");
        logDoc.replaceItemValue("LogUserName", Factory.getSession(SessionType.CURRENT).getUserName());
        logDoc.replaceItemValue("LogEffectiveName", Factory.getSession(SessionType.CURRENT).getEffectiveUserName());
        logDoc.replaceItemValue("LogAccessLevel", getAccessLevel());
        logDoc.replaceItemValue("LogUserRoles", getUserRoles());
        logDoc.replaceItemValue("LogClientVersion", getClientVersion());
        logDoc.replaceItemValue("LogAgentStartTime", getStartTime());
        if (getErrDoc() != null) {
            docDb = getErrDoc().getParentDatabase();
            rtitem = logDoc.createRichTextItem("LogDocInfo");
            rtitem.appendText("The document associated with this event is:");
            rtitem.addNewLine(1);
            rtitem.appendText("Server: " + docDb.getServer());
            rtitem.addNewLine(1);
            rtitem.appendText("Database: " + docDb.getFilePath());
            rtitem.addNewLine(1);
            rtitem.appendText("UNID: " + getErrDoc().getUniversalID());
            rtitem.addNewLine(1);
            rtitem.appendText("Note ID: " + getErrDoc().getNoteID());
            rtitem.addNewLine(1);
            rtitem.appendText("DocLink: ");
            rtitem.appendDocLink(_errDoc, getErrDoc().getUniversalID());
        }
        // make sure Depositor-level users can add documents too
        logDoc.appendItemValue("$PublicAccess", "1");
        logDoc.save(true);
        retval = true;
    } catch (Exception e) {
        debugPrint(e);
        retval = false;
    } finally {
        _errDoc = null;
        _errDocUnid = null;
    }
    return retval;
}
Also used : NotesException(lotus.domino.NotesException) RichTextItem(org.openntf.domino.RichTextItem) Database(org.openntf.domino.Database) Document(org.openntf.domino.Document) NotesException(lotus.domino.NotesException)

Aggregations

Database (org.openntf.domino.Database)131 Session (org.openntf.domino.Session)73 Document (org.openntf.domino.Document)49 Test (org.junit.Test)19 View (org.openntf.domino.View)19 DbDirectory (org.openntf.domino.DbDirectory)17 NotesException (lotus.domino.NotesException)12 ArrayList (java.util.ArrayList)11 NoteCollection (org.openntf.domino.NoteCollection)11 OpenNTFNotesException (org.openntf.domino.exceptions.OpenNTFNotesException)10 DocumentCollection (org.openntf.domino.DocumentCollection)8 NoteCoordinate (org.openntf.domino.big.NoteCoordinate)8 Date (java.util.Date)6 UserAccessException (org.openntf.domino.exceptions.UserAccessException)6 IOException (java.io.IOException)5 HashMap (java.util.HashMap)5 ViewEntry (org.openntf.domino.ViewEntry)5 FastTable (javolution.util.FastTable)4 Item (org.openntf.domino.Item)4 RichTextItem (org.openntf.domino.RichTextItem)4