Search in sources :

Example 1 with NotesDatabase

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

the class OSGiServletBeanArchiveHandler method handle.

@Override
public BeanArchiveBuilder handle(String beanArchiveReference) {
    try {
        Bundle bundle = PROCESSING_BUNDLE.get();
        if (bundle == null) {
            NotesDatabase database = ContextInfo.getServerDatabase();
            if (database != null) {
                String bundleName = ContainerUtil.getApplicationCDIBundle(database);
                if (StringUtil.isNotEmpty(bundleName)) {
                    bundle = LibraryUtil.getBundle(bundleName).orElse(null);
                } else {
                    bundleName = ContainerUtil.getApplicationCDIBundleBase(database);
                    if (StringUtil.isNotEmpty(bundleName)) {
                        bundle = LibraryUtil.getBundle(bundleName).orElse(null);
                    }
                }
            }
        }
        if (bundle != null) {
            String symbolicName = bundle.getSymbolicName();
            // Slightly customize the builder to keep some extra metadata
            BeanArchiveBuilder builder = new BeanArchiveBuilder() {

                {
                    super.setBeansXml(BeansXml.EMPTY_BEANS_XML);
                    super.setId(symbolicName);
                }

                @Override
                public BeanArchiveBuilder setBeansXml(BeansXml beansXml) {
                    return this;
                }
            };
            return builder;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : NotesDatabase(com.ibm.designer.domino.napi.NotesDatabase) Bundle(org.osgi.framework.Bundle) BeansXml(org.jboss.weld.bootstrap.spi.BeansXml) BeanArchiveBuilder(org.jboss.weld.environment.deployment.discovery.BeanArchiveBuilder)

Example 2 with NotesDatabase

use of com.ibm.designer.domino.napi.NotesDatabase 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 3 with NotesDatabase

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

the class NSFCdiInjectorFactory method lookupBeanManager.

@Override
@SuppressWarnings("nls")
protected BeanManager lookupBeanManager() {
    ApplicationEx application = ApplicationEx.getInstance();
    if (application != null) {
        return ContainerUtil.getBeanManager(application);
    }
    NotesContext ctx = NotesContext.getCurrentUnchecked();
    if (ctx != null) {
        try {
            NotesDatabase database = ctx.getNotesDatabase();
            if (database != null) {
                return ContainerUtil.getBeanManager(database);
            }
        } catch (NotesAPIException e) {
            throw new RuntimeException(e);
        }
    }
    throw new IllegalStateException("Unable to locate active application!");
}
Also used : NotesDatabase(com.ibm.designer.domino.napi.NotesDatabase) ApplicationEx(com.ibm.xsp.application.ApplicationEx) NotesContext(com.ibm.domino.xsp.module.nsf.NotesContext) NotesAPIException(com.ibm.designer.domino.napi.NotesAPIException)

Example 4 with NotesDatabase

use of com.ibm.designer.domino.napi.NotesDatabase 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

NotesDatabase (com.ibm.designer.domino.napi.NotesDatabase)4 NotesAPIException (com.ibm.designer.domino.napi.NotesAPIException)3 NotesSession (com.ibm.designer.domino.napi.NotesSession)2 ApplicationEx (com.ibm.xsp.application.ApplicationEx)2 Bundle (org.osgi.framework.Bundle)2 DominoException (com.darwino.domino.napi.DominoException)1 NotesNote (com.ibm.designer.domino.napi.NotesNote)1 NotesContext (com.ibm.domino.xsp.module.nsf.NotesContext)1 CDI (jakarta.enterprise.inject.spi.CDI)1 IOException (java.io.IOException)1 BeansXml (org.jboss.weld.bootstrap.spi.BeansXml)1 BeanArchiveBuilder (org.jboss.weld.environment.deployment.discovery.BeanArchiveBuilder)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