Search in sources :

Example 16 with Session

use of lotus.domino.Session 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 17 with Session

use of lotus.domino.Session in project openliberty-domino by OpenNTF.

the class AdminNSFAppDeploymentProvider method deployApp.

@Override
public void deployApp(String serverName, String appName, String contextPath, String fileName, Boolean includeInReverseProxy, InputStream appData) {
    if (StringUtil.isEmpty(serverName)) {
        throw new IllegalArgumentException("serverName cannot be empty");
    }
    if (StringUtil.isEmpty(appName)) {
        throw new IllegalArgumentException("appName cannot be empty");
    }
    try {
        Session session = NotesFactory.createSession();
        try {
            Database database = AdminNSFUtil.getAdminDatabase(session);
            View serversAndApps = database.getView(VIEW_SERVERSANDAPPS);
            serversAndApps.setAutoUpdate(false);
            ViewEntry serverEntry = serversAndApps.getEntryByKey(serverName, true);
            if (serverEntry == null) {
                throw new IllegalArgumentException(MessageFormat.format("Unable to locate server \"{0}\"", serverName));
            }
            ViewNavigator nav = serversAndApps.createViewNavFromChildren(serverEntry);
            ViewEntry appEntry = nav.getFirst();
            while (appEntry != null) {
                Vector<?> columnValues = appEntry.getColumnValues();
                String entryAppName = (String) columnValues.get(0);
                if (appName.equalsIgnoreCase(entryAppName)) {
                    break;
                }
                appEntry.recycle(columnValues);
                ViewEntry tempEntry = appEntry;
                appEntry = nav.getNextSibling(appEntry);
                tempEntry.recycle();
            }
            Document appDoc;
            if (appEntry == null) {
                appDoc = database.createDocument();
                // $NON-NLS-1$
                appDoc.replaceItemValue("Form", FORM_APP);
                appDoc.makeResponse(serverEntry.getDocument());
                appDoc.replaceItemValue(ITEM_APPNAME, appName);
            } else {
                appDoc = appEntry.getDocument();
            }
            String path = contextPath;
            if (StringUtil.isEmpty(path)) {
                // Determine whether to change an existing value
                String existing = appDoc.getItemValueString(ITEM_CONTEXTPATH);
                if (StringUtil.isEmpty(existing)) {
                    // $NON-NLS-1$
                    path = "/" + appName;
                    appDoc.replaceItemValue(ITEM_CONTEXTPATH, path);
                }
            } else {
                appDoc.replaceItemValue(ITEM_CONTEXTPATH, path);
            }
            // $NON-NLS-1$ //$NON-NLS-2$
            appDoc.replaceItemValue(ITEM_REVERSEPROXY, includeInReverseProxy != null && includeInReverseProxy ? "Y" : "N");
            if (appDoc.hasItem(ITEM_FILE)) {
                appDoc.removeItem(ITEM_FILE);
            }
            RichTextItem fileItem = appDoc.createRichTextItem(ITEM_FILE);
            Path tempDir = Files.createTempDirectory(OpenLibertyUtil.getTempDirectory(), getClass().getName());
            try {
                String fname = fileName;
                if (StringUtil.isEmpty(fname)) {
                    // TODO consider a non-WAR default
                    // $NON-NLS-1$
                    fname = appName + ".war";
                }
                Path file = tempDir.resolve(fname);
                Files.copy(appData, file, StandardCopyOption.REPLACE_EXISTING);
                // $NON-NLS-1$
                fileItem.embedObject(EmbeddedObject.EMBED_ATTACHMENT, "", file.toString(), null);
            } finally {
                OpenLibertyUtil.deltree(tempDir);
            }
            appDoc.save();
        } finally {
            session.recycle();
        }
    } catch (NotesException | IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : Path(java.nio.file.Path) ViewNavigator(lotus.domino.ViewNavigator) IOException(java.io.IOException) Document(lotus.domino.Document) View(lotus.domino.View) NotesException(lotus.domino.NotesException) ViewEntry(lotus.domino.ViewEntry) RichTextItem(lotus.domino.RichTextItem) Database(lotus.domino.Database) Session(lotus.domino.Session)

Example 18 with Session

use of lotus.domino.Session in project openliberty-domino by OpenNTF.

the class IdentityServlet method getUserDisplayName.

private String getUserDisplayName(String userSecurityName) throws NotesException {
    Session session = NotesFactory.createSession();
    try {
        // $NON-NLS-1$ //$NON-NLS-2$
        Database names = session.getDatabase("", "names.nsf");
        Document tempDoc = names.createDocument();
        // $NON-NLS-1$
        tempDoc.replaceItemValue("Username", userSecurityName);
        // $NON-NLS-1$
        List<?> result = session.evaluate(" @Trim(@NameLookup([NoCache]:[Exhaustive]; Username; 'FullName')) ", tempDoc);
        if (!result.isEmpty()) {
            Name name = session.createName((String) result.get(0));
            return name.getCommon();
        } else {
            // $NON-NLS-1$
            return "";
        }
    } finally {
        session.recycle();
    }
}
Also used : Database(lotus.domino.Database) Document(lotus.domino.Document) Session(lotus.domino.Session) Name(lotus.domino.Name)

Example 19 with Session

use of lotus.domino.Session in project openliberty-domino by OpenNTF.

the class IdentityServlet method getGroups.

@SuppressWarnings("unchecked")
public String getGroups(String pattern, int limit) throws NotesException {
    Session session = NotesFactory.createSession();
    try {
        // $NON-NLS-1$ //$NON-NLS-2$
        Database names = session.getDatabase("", "names.nsf");
        Document tempDoc = names.createDocument();
        // $NON-NLS-1$
        List<String> groups = session.evaluate(" @Trim(@Sort(@Unique(@NameLookup([NoCache]:[Exhaustive]; ''; 'ListName')))) ", tempDoc);
        // $NON-NLS-1$
        return String.join("\n", groups);
    } finally {
        session.recycle();
    }
}
Also used : Database(lotus.domino.Database) Document(lotus.domino.Document) Session(lotus.domino.Session)

Example 20 with Session

use of lotus.domino.Session in project openliberty-domino by OpenNTF.

the class IdentityServlet method getUsers.

@SuppressWarnings("unchecked")
private String getUsers(String pattern, int limit) throws NotesException {
    Session session = NotesFactory.createSession();
    try {
        // TODO change API to avoid 64k trouble
        // $NON-NLS-1$ //$NON-NLS-2$
        Database names = session.getDatabase("", "names.nsf");
        Document tempDoc = names.createDocument();
        // $NON-NLS-1$
        List<String> users = session.evaluate(" @Trim(@Sort(@Unique(@NameLookup([NoCache]:[Exhaustive]; ''; 'FullName')))) ", tempDoc);
        // $NON-NLS-1$
        return String.join("\n", users);
    } finally {
        session.recycle();
    }
}
Also used : Database(lotus.domino.Database) Document(lotus.domino.Document) Session(lotus.domino.Session)

Aggregations

Session (lotus.domino.Session)24 Database (lotus.domino.Database)18 Document (lotus.domino.Document)12 NotesException (lotus.domino.NotesException)8 View (lotus.domino.View)4 ViewEntry (lotus.domino.ViewEntry)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Vector (java.util.Vector)2 ExecutionException (java.util.concurrent.ExecutionException)2 DateTime (lotus.domino.DateTime)2 DocumentCollection (lotus.domino.DocumentCollection)2 Name (lotus.domino.Name)2 NoteCollection (lotus.domino.NoteCollection)2 ViewNavigator (lotus.domino.ViewNavigator)2 NotesAPIException (com.ibm.designer.domino.napi.NotesAPIException)1 NotesSession (com.ibm.designer.domino.napi.NotesSession)1 HttpService (com.ibm.designer.runtime.domino.adapter.HttpService)1 ModuleClassLoader (com.ibm.domino.xsp.module.nsf.ModuleClassLoader)1 Sort (jakarta.nosql.Sort)1