Search in sources :

Example 1 with NotesAPIException

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

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

the class NSFJsfServlet method doInit.

public void doInit(HttpServletRequest req, ServletConfig config) throws ServletException {
    try {
        CDI<Object> cdi = ContainerUtil.getContainer(NotesContext.getCurrent().getNotesDatabase());
        ServletContext context = config.getServletContext();
        // $NON-NLS-1$
        context.setAttribute("jakarta.enterprise.inject.spi.BeanManager", ContainerUtil.getBeanManager(cdi));
        // TODO investigate why partial state saving doesn't work with a basic form
        // $NON-NLS-1$ //$NON-NLS-2$
        context.setInitParameter("jakarta.faces.PARTIAL_STATE_SAVING", "false");
        Properties props = LibraryUtil.getXspProperties(module);
        // $NON-NLS-1$
        String projectStage = props.getProperty(ProjectStage.PROJECT_STAGE_PARAM_NAME, "");
        context.setInitParameter(ProjectStage.PROJECT_STAGE_PARAM_NAME, projectStage);
        Bundle b = FrameworkUtil.getBundle(FacesServlet.class);
        {
            ServletContainerInitializer initializer = new MyFacesContainerInitializer();
            Set<Class<?>> classes = null;
            HandlesTypes types = initializer.getClass().getAnnotation(HandlesTypes.class);
            if (types != null) {
                classes = buildMatchingClasses(types, b);
            }
            initializer.onStartup(classes, getServletContext());
        }
        {
            // Re-wrap the ServletContext to provide the context path
            javax.servlet.ServletContext oldCtx = ServletUtil.newToOld(getServletContext());
            ServletContext ctx = ServletUtil.oldToNew(req.getContextPath(), oldCtx, 5, 0);
            ctx.addListener(StartupServletContextListener.class);
            ServletUtil.getListeners(ctx, ServletContextListener.class).forEach(l -> l.contextInitialized(new ServletContextEvent(ctx)));
        }
        this.delegate = new FacesServlet();
        delegate.init(config);
    } catch (NotesAPIException e) {
        throw new ServletException(e);
    }
}
Also used : StartupServletContextListener(org.apache.myfaces.webapp.StartupServletContextListener) ProjectStage(jakarta.faces.application.ProjectStage) ComponentModule(com.ibm.designer.runtime.domino.adapter.ComponentModule) CDI(jakarta.enterprise.inject.spi.CDI) XSPErrorPage(com.ibm.designer.runtime.domino.adapter.util.XSPErrorPage) ServletConfig(jakarta.servlet.ServletConfig) HttpServletRequest(jakarta.servlet.http.HttpServletRequest) URL(java.net.URL) FacesServlet(jakarta.faces.webapp.FacesServlet) DelegatingClassLoader(org.openntf.xsp.jakartaee.DelegatingClassLoader) FacesContext(jakarta.faces.context.FacesContext) ServletException(jakarta.servlet.ServletException) ServletContainerInitializer(jakarta.servlet.ServletContainerInitializer) HttpSessionListener(jakarta.servlet.http.HttpSessionListener) HashSet(java.util.HashSet) NotesAPIException(com.ibm.designer.domino.napi.NotesAPIException) HttpSession(jakarta.servlet.http.HttpSession) MyFacesContainerInitializer(org.apache.myfaces.webapp.MyFacesContainerInitializer) ServletUtil(org.openntf.xsp.jakartaee.servlet.ServletUtil) ModuleUtil(org.openntf.xsp.jakartaee.util.ModuleUtil) ServletRequestListener(jakarta.servlet.ServletRequestListener) Bundle(org.osgi.framework.Bundle) BundleException(org.osgi.framework.BundleException) LibraryUtil(org.openntf.xsp.jakartaee.util.LibraryUtil) HandlesTypes(jakarta.servlet.annotation.HandlesTypes) PrintWriter(java.io.PrintWriter) Properties(java.util.Properties) AbstractProxyingContext(org.openntf.xsp.cdi.context.AbstractProxyingContext) Set(java.util.Set) IOException(java.io.IOException) NSFComponentModule(com.ibm.domino.xsp.module.nsf.NSFComponentModule) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) HttpServlet(jakarta.servlet.http.HttpServlet) List(java.util.List) HttpSessionEvent(jakarta.servlet.http.HttpSessionEvent) StringUtil(com.ibm.commons.util.StringUtil) ServletContextEvent(jakarta.servlet.ServletContextEvent) Annotation(java.lang.annotation.Annotation) NotesContext(com.ibm.domino.xsp.module.nsf.NotesContext) DiscoveryUtil(org.openntf.xsp.cdi.util.DiscoveryUtil) ServletContext(jakarta.servlet.ServletContext) HttpServletResponse(jakarta.servlet.http.HttpServletResponse) AccessController(java.security.AccessController) ServletRequestEvent(jakarta.servlet.ServletRequestEvent) Collections(java.util.Collections) FrameworkUtil(org.osgi.framework.FrameworkUtil) ContainerUtil(org.openntf.xsp.cdi.util.ContainerUtil) ServletContextListener(jakarta.servlet.ServletContextListener) HashSet(java.util.HashSet) Set(java.util.Set) Bundle(org.osgi.framework.Bundle) FacesServlet(jakarta.faces.webapp.FacesServlet) Properties(java.util.Properties) MyFacesContainerInitializer(org.apache.myfaces.webapp.MyFacesContainerInitializer) ServletContainerInitializer(jakarta.servlet.ServletContainerInitializer) ServletException(jakarta.servlet.ServletException) ServletContext(jakarta.servlet.ServletContext) NotesAPIException(com.ibm.designer.domino.napi.NotesAPIException) HandlesTypes(jakarta.servlet.annotation.HandlesTypes) ServletContextEvent(jakarta.servlet.ServletContextEvent) StartupServletContextListener(org.apache.myfaces.webapp.StartupServletContextListener)

Example 3 with NotesAPIException

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

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

the class DefaultDominoDocumentCollectionManager method select.

@Override
public Stream<DocumentEntity> select(DocumentQuery query) {
    try {
        QueryConverterResult queryResult = QueryConverter.select(query);
        long skip = queryResult.getSkip();
        long limit = queryResult.getLimit();
        List<Sort> sorts = query.getSorts();
        Stream<DocumentEntity> result;
        if (sorts != null && !sorts.isEmpty()) {
            Database database = supplier.get();
            Session sessionAsSigner = sessionSupplier.get();
            Database qrpDatabase = getQrpDatabase(sessionAsSigner, database);
            String userName = database.getParent().getEffectiveUserName();
            // $NON-NLS-1$
            String viewName = getClass().getName() + "-" + (String.valueOf(sorts) + skip + limit + userName).hashCode();
            View view = qrpDatabase.getView(viewName);
            try {
                if (view != null) {
                    // Check to see if we need to "expire" it based on the data mod time of the DB
                    DateTime created = view.getCreated();
                    try {
                        long dataMod = NotesSession.getLastDataModificationDateByName(database.getServer(), database.getFilePath());
                        if (dataMod > (created.toJavaDate().getTime() / 1000)) {
                            view.remove();
                            view.recycle();
                            view = null;
                        }
                    } catch (NotesAPIException e) {
                        throw new RuntimeException(e);
                    } finally {
                        recycle(created);
                    }
                }
                if (view != null) {
                    result = EntityConverter.convert(database, view);
                } else {
                    DominoQuery dominoQuery = database.createDominoQuery();
                    QueryResultsProcessor qrp = qrpDatabase.createQueryResultsProcessor();
                    try {
                        qrp.addDominoQuery(dominoQuery, queryResult.getStatement().toString(), null);
                        for (Sort sort : sorts) {
                            int dir = sort.getType() == SortType.DESC ? QueryResultsProcessor.SORT_DESCENDING : QueryResultsProcessor.SORT_ASCENDING;
                            qrp.addColumn(sort.getName(), null, null, dir, false, false);
                        }
                        if (skip == 0 && limit > 0 && limit <= Integer.MAX_VALUE) {
                            qrp.setMaxEntries((int) limit);
                        }
                        view = qrp.executeToView(viewName, 24);
                        try {
                            result = EntityConverter.convert(database, view);
                        } finally {
                            recycle(view);
                        }
                    } finally {
                        recycle(qrp, dominoQuery, qrpDatabase);
                    }
                }
            } finally {
                recycle(view);
            }
        } else {
            Database database = supplier.get();
            DominoQuery dominoQuery = database.createDominoQuery();
            DocumentCollection docs = dominoQuery.execute(queryResult.getStatement().toString());
            try {
                result = EntityConverter.convert(docs);
            } finally {
                recycle(docs, dominoQuery);
            }
        }
        if (skip > 0) {
            result = result.skip(skip);
        }
        if (limit > 0) {
            result = result.limit(limit);
        }
        return result;
    } catch (NotesException e) {
        throw new RuntimeException(e);
    }
}
Also used : QueryResultsProcessor(lotus.domino.QueryResultsProcessor) QueryConverterResult(org.openntf.xsp.nosql.communication.driver.QueryConverter.QueryConverterResult) DocumentCollection(lotus.domino.DocumentCollection) View(lotus.domino.View) DateTime(lotus.domino.DateTime) NotesException(lotus.domino.NotesException) DocumentEntity(jakarta.nosql.document.DocumentEntity) Database(lotus.domino.Database) Sort(jakarta.nosql.Sort) NotesAPIException(com.ibm.designer.domino.napi.NotesAPIException) DominoQuery(lotus.domino.DominoQuery) NotesSession(com.ibm.designer.domino.napi.NotesSession) Session(lotus.domino.Session)

Example 5 with NotesAPIException

use of com.ibm.designer.domino.napi.NotesAPIException 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)5 NotesDatabase (com.ibm.designer.domino.napi.NotesDatabase)3 NotesSession (com.ibm.designer.domino.napi.NotesSession)3 NotesContext (com.ibm.domino.xsp.module.nsf.NotesContext)2 ApplicationEx (com.ibm.xsp.application.ApplicationEx)2 CDI (jakarta.enterprise.inject.spi.CDI)2 IOException (java.io.IOException)2 Bundle (org.osgi.framework.Bundle)2 DominoException (com.darwino.domino.napi.DominoException)1 StringUtil (com.ibm.commons.util.StringUtil)1 NotesNote (com.ibm.designer.domino.napi.NotesNote)1 ComponentModule (com.ibm.designer.runtime.domino.adapter.ComponentModule)1 XSPErrorPage (com.ibm.designer.runtime.domino.adapter.util.XSPErrorPage)1 NSFComponentModule (com.ibm.domino.xsp.module.nsf.NSFComponentModule)1 ProjectStage (jakarta.faces.application.ProjectStage)1 FacesContext (jakarta.faces.context.FacesContext)1 FacesServlet (jakarta.faces.webapp.FacesServlet)1 Sort (jakarta.nosql.Sort)1 DocumentEntity (jakarta.nosql.document.DocumentEntity)1 ServletConfig (jakarta.servlet.ServletConfig)1