Search in sources :

Example 1 with NotesSession

use of com.ibm.designer.domino.napi.NotesSession in project org.openntf.xsp.jakartaee by OpenNTF.

the class NSFCDIProvider method getCDI.

@SuppressWarnings("unchecked")
@Override
public synchronized CDI<Object> getCDI() {
    CDI<Object> result = null;
    CDIContainerUtility util = LibraryUtil.findRequiredExtension(CDIContainerUtility.class);
    String databasePath = util.getThreadContextDatabasePath();
    if (StringUtil.isNotEmpty(databasePath)) {
        try {
            NotesSession session = new NotesSession();
            try {
                NotesDatabase database = session.getDatabase(databasePath);
                if (database != null) {
                    database.open();
                    try {
                        result = (CDI<Object>) util.getContainer(database);
                    } finally {
                        database.recycle();
                    }
                }
            } finally {
                session.recycle();
            }
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }
    if (result != null) {
        return result;
    }
    ApplicationEx application = ApplicationEx.getInstance();
    if (application != null) {
        result = (CDI<Object>) util.getContainer(application);
    }
    if (result != null) {
        return result;
    }
    try {
        NotesDatabase database = ContextInfo.getServerDatabase();
        if (database != null) {
            result = (CDI<Object>) util.getContainer(database);
        }
    } catch (Throwable t) {
        t.printStackTrace();
    }
    if (result != null) {
        return result;
    }
    // Check in any available locator extensions
    List<CDIContainerLocator> locators = LibraryUtil.findExtensions(CDIContainerLocator.class);
    NotesSession session = new NotesSession();
    try {
        for (CDIContainerLocator locator : locators) {
            String nsfPath = locator.getNsfPath();
            if (StringUtil.isNotEmpty(nsfPath)) {
                try {
                    NotesDatabase database = session.getDatabaseByPath(nsfPath);
                    try {
                        database.open();
                        result = (CDI<Object>) util.getContainer(database);
                        if (result != null) {
                            return result;
                        }
                    } finally {
                        if (database != null) {
                            database.recycle();
                        }
                    }
                } catch (NotesAPIException | IOException e) {
                    // Log and move on
                    e.printStackTrace();
                }
            }
            String bundleId = locator.getBundleId();
            if (StringUtil.isNotEmpty(bundleId)) {
                Optional<Bundle> bundle = LibraryUtil.getBundle(bundleId);
                if (bundle.isPresent()) {
                    return (CDI<Object>) util.getContainer(bundle.get());
                }
            }
        }
    } finally {
        try {
            session.recycle();
        } catch (NotesAPIException e) {
        // Ignore
        }
    }
    return null;
}
Also used : CDIContainerUtility(org.openntf.xsp.cdi.ext.CDIContainerUtility) CDIContainerLocator(org.openntf.xsp.cdi.ext.CDIContainerLocator) Bundle(org.osgi.framework.Bundle) CDI(jakarta.enterprise.inject.spi.CDI) IOException(java.io.IOException) NotesDatabase(com.ibm.designer.domino.napi.NotesDatabase) NotesSession(com.ibm.designer.domino.napi.NotesSession) ApplicationEx(com.ibm.xsp.application.ApplicationEx) NotesAPIException(com.ibm.designer.domino.napi.NotesAPIException)

Example 2 with NotesSession

use of com.ibm.designer.domino.napi.NotesSession in project org.openntf.nsfodp by OpenNTF.

the class DarwinoNCompositeData method writeJavaScriptLibraryData.

@Override
public void writeJavaScriptLibraryData(OutputStream os) throws IOException {
    try {
        // TODO figure out why the Darwino implementation chops data
        // https://github.com/OpenNTF/org.openntf.nsfodp/issues/271
        // this.data.writeJavaScriptLibraryData(os);
        long dbHandle = this.note.getParent().getHandle();
        NotesSession notesSession = new NotesSession();
        try {
            NotesDatabase notesDatabase = notesSession.getDatabase((int) dbHandle);
            NotesNote notesNote = notesDatabase.openNote(this.note.getNoteID(), 0);
            FileAccess.readFileContent(notesNote, os);
        } finally {
            notesSession.recycle();
        }
    } catch (NotesAPIException e) {
        throw new NDominoException(e.getNativeErrorCode(), e);
    } catch (DominoException e) {
        throw new NDominoException(e.getStatus(), e);
    }
}
Also used : NDominoException(org.openntf.nsfodp.commons.odp.notesapi.NDominoException) NotesNote(com.ibm.designer.domino.napi.NotesNote) NotesDatabase(com.ibm.designer.domino.napi.NotesDatabase) NotesSession(com.ibm.designer.domino.napi.NotesSession) NotesAPIException(com.ibm.designer.domino.napi.NotesAPIException) DominoException(com.darwino.domino.napi.DominoException) NDominoException(org.openntf.nsfodp.commons.odp.notesapi.NDominoException)

Aggregations

NotesAPIException (com.ibm.designer.domino.napi.NotesAPIException)2 NotesDatabase (com.ibm.designer.domino.napi.NotesDatabase)2 NotesSession (com.ibm.designer.domino.napi.NotesSession)2 DominoException (com.darwino.domino.napi.DominoException)1 NotesNote (com.ibm.designer.domino.napi.NotesNote)1 ApplicationEx (com.ibm.xsp.application.ApplicationEx)1 CDI (jakarta.enterprise.inject.spi.CDI)1 IOException (java.io.IOException)1 NDominoException (org.openntf.nsfodp.commons.odp.notesapi.NDominoException)1 CDIContainerLocator (org.openntf.xsp.cdi.ext.CDIContainerLocator)1 CDIContainerUtility (org.openntf.xsp.cdi.ext.CDIContainerUtility)1 Bundle (org.osgi.framework.Bundle)1