Search in sources :

Example 31 with Database

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

the class OpenntfNABNamePickerData method getSessionAddressBooks.

/**
 * Gets the address books for the current Session
 *
 * @param session
 *            Session
 * @return NABDb[] Array of address books
 * @throws NotesException
 */
private static NABDb[] getSessionAddressBooks(final Session session) throws NotesException {
    if (session != null) {
        // Unit tests
        ArrayList<NABDb> nabs = new ArrayList<NABDb>();
        Vector<?> vc = session.getAddressBooks();
        if (vc != null) {
            for (int i = 0; i < vc.size(); i++) {
                Database db = (Database) vc.get(i);
                try {
                    db.open();
                    try {
                        NABDb nab = new NABDb(db);
                        nabs.add(nab);
                    } finally {
                        db.recycle();
                    }
                } catch (NotesException ex) {
                // Opening the database can fail if the user doesn't sufficient
                // rights. In this vase, we simply ignore this NAB and continue
                // with the next one.
                }
            }
        }
        return nabs.toArray(new NABDb[nabs.size()]);
    }
    return null;
}
Also used : NotesException(lotus.domino.NotesException) ArrayList(java.util.ArrayList) Database(lotus.domino.Database)

Example 32 with Database

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

the class ReplaceDesignTaskTest method run.

@Override
public IStatus run(IProgressMonitor monitor) {
    try {
        Session session = NotesFactory.createSession();
        try {
            Database sourceDb = getDatabase(session, sourcePath);
            Database targetDb = getDatabase(session, targetPath);
            // Delete elements from the target database
            // Ignore elements having "prohibit design..." property or Master Template defined
            NoteCollection targetNoteColl = targetDb.createNoteCollection(true);
            targetNoteColl.selectAllAdminNotes(false);
            targetNoteColl.selectAllDataNotes(false);
            targetNoteColl.setSelectIcon(false);
            targetNoteColl.setSelectHelpAbout(false);
            targetNoteColl.setSelectHelpIndex(false);
            targetNoteColl.setSelectHelpUsing(false);
            // Select notes without "prohibit design" or master templates
            // $NON-NLS-1$
            targetNoteColl.setSelectionFormula(" !(@IsAvailable($Class) | @Contains($Flags; 'P')) ");
            // Remove selected notes
            targetNoteColl.buildCollection();
            String noteId = targetNoteColl.getFirstNoteID();
            while (StringUtil.isNotEmpty(noteId)) {
                Document note = targetDb.getDocumentByID(noteId);
                // System.out.println(Messages.getString("ReplaceDesignTaskTest.consoleRemoving", noteId, note.getItemValueString("$TITLE"))); //$NON-NLS-1$ //$NON-NLS-2$
                note.remove(true);
                noteId = targetNoteColl.getNextNoteID(noteId);
            }
            // Check for Help About and Help Using
            boolean isHelpAbout = false, isHelpUsing = false;
            targetNoteColl.selectAllNotes(false);
            targetNoteColl.clearCollection();
            targetNoteColl.setSelectHelpAbout(true);
            targetNoteColl.buildCollection();
            if (targetNoteColl.getCount() > 0) {
                noteId = targetNoteColl.getFirstNoteID();
                Document helpAbout = targetDb.getDocumentByID(noteId);
                if (helpAbout.getItemValueString("$Flags").contains("R")) {
                    // $NON-NLS-1$ //$NON-NLS-2$
                    // System.out.println(Messages.getString("ReplaceDesignTaskTest.consoleRemovingHelpAbout")); //$NON-NLS-1$
                    helpAbout.remove(true);
                    isHelpAbout = true;
                }
            }
            targetNoteColl.selectAllNotes(false);
            targetNoteColl.clearCollection();
            targetNoteColl.setSelectHelpUsing(true);
            targetNoteColl.buildCollection();
            if (targetNoteColl.getCount() > 0) {
                noteId = targetNoteColl.getFirstNoteID();
                Document helpUsing = targetDb.getDocumentByID(noteId);
                if (helpUsing.getItemValueString("$Flags").contains("R")) {
                    // $NON-NLS-1$ //$NON-NLS-2$
                    // System.out.println(Messages.getString("ReplaceDesignTaskTest.consoleRemovingHelpUsing")); //$NON-NLS-1$
                    helpUsing.remove(true);
                    isHelpUsing = true;
                }
            }
            // Set "More Fields" option
            targetDb.setOption(Database.DBOPT_MOREFIELDS, true);
            // Copy all design elements from source DB to target DB except Help About and Help Using
            NoteCollection sourceNoteColl = sourceDb.createNoteCollection(true);
            sourceNoteColl.selectAllAdminNotes(false);
            sourceNoteColl.selectAllDataNotes(false);
            sourceNoteColl.setSelectIcon(false);
            sourceNoteColl.setSelectHelpAbout(isHelpAbout);
            sourceNoteColl.setSelectHelpUsing(isHelpUsing);
            return Status.OK_STATUS;
        } finally {
            session.recycle();
        }
    } catch (Exception e) {
        return new Status(IStatus.ERROR, Messages.ReplaceDesignTaskTest_errorReplacingDesign, e.toString(), e);
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) NoteCollection(lotus.domino.NoteCollection) Database(lotus.domino.Database) Document(lotus.domino.Document) NotesException(lotus.domino.NotesException) Session(lotus.domino.Session)

Aggregations

Database (lotus.domino.Database)32 Session (lotus.domino.Session)18 Document (lotus.domino.Document)16 NotesException (lotus.domino.NotesException)13 DocumentCollection (lotus.domino.DocumentCollection)5 NoteCollection (lotus.domino.NoteCollection)5 View (lotus.domino.View)4 IOException (java.io.IOException)3 Vector (java.util.Vector)3 DateTime (lotus.domino.DateTime)3 DominoQuery (lotus.domino.DominoQuery)3 Item (lotus.domino.Item)3 ViewEntry (lotus.domino.ViewEntry)3 DominoDocument (com.ibm.xsp.model.domino.wrapped.DominoDocument)2 Document (jakarta.nosql.document.Document)2 URI (java.net.URI)2 Path (java.nio.file.Path)2 Date (java.util.Date)2 ExecutionException (java.util.concurrent.ExecutionException)2 ACL (lotus.domino.ACL)2