Search in sources :

Example 1 with View

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

the class AdminNSFProxyConfigProvider method createConfiguration.

@SuppressWarnings("unchecked")
@Override
public ReverseProxyConfig createConfiguration() {
    ReverseProxyConfig result = new ReverseProxyConfig();
    RuntimeConfigurationProvider runtimeConfig = OpenLibertyUtil.findRequiredExtension(RuntimeConfigurationProvider.class);
    result.dominoHostName = runtimeConfig.getDominoHostName();
    result.dominoHttpPort = runtimeConfig.getDominoPort();
    result.dominoHttps = runtimeConfig.isDominoHttps();
    try {
        DominoThreadFactory.getExecutor().submit(() -> {
            try {
                Session session = NotesFactory.createSession();
                try {
                    Database adminNsf = AdminNSFUtil.getAdminDatabase(session);
                    Document config = AdminNSFUtil.getConfigurationDocument(adminNsf);
                    // Load the main config
                    boolean connectorHeaders = runtimeConfig.isUseDominoConnectorHeaders();
                    readConfigurationDocument(result, config, connectorHeaders);
                    if (!result.isGlobalEnabled()) {
                        return;
                    }
                    Collection<String> namesList = AdminNSFUtil.getCurrentServerNamesList();
                    // Look for proxy-enabled webapps
                    View targetsView = adminNsf.getView(VIEW_REVERSEPROXYTARGETS);
                    targetsView.setAutoUpdate(false);
                    targetsView.refresh();
                    ViewNavigator nav = targetsView.createViewNav();
                    nav.setEntryOptions(ViewNavigator.VN_ENTRYOPT_NOCOUNTDATA);
                    ViewEntry entry = nav.getFirst();
                    while (entry != null) {
                        Vector<?> columnValues = entry.getColumnValues();
                        List<String> dominoServers;
                        Object dominoServersObj = columnValues.get(4);
                        if (dominoServersObj instanceof String) {
                            dominoServers = Arrays.asList((String) dominoServersObj);
                        } else {
                            dominoServers = (List<String>) dominoServersObj;
                        }
                        boolean shouldRun = AdminNSFUtil.isNamesListMatch(namesList, dominoServers);
                        if (shouldRun) {
                            // Format: http://localhost:80
                            String baseUri = (String) columnValues.get(1);
                            // $NON-NLS-1$
                            boolean useXForwardedFor = "Y".equals(columnValues.get(2));
                            // $NON-NLS-1$
                            boolean useWsHeaders = "Y".equals(columnValues.get(3));
                            // Now read the children to build targets
                            ViewEntry childEntry = nav.getChild(entry);
                            while (childEntry != null) {
                                Vector<?> childValues = childEntry.getColumnValues();
                                // Format: foo
                                String contextPath = (String) childValues.get(0);
                                // $NON-NLS-1$
                                URI uri = URI.create(baseUri + "/" + contextPath);
                                ReverseProxyTarget target = new ReverseProxyTarget(uri, useXForwardedFor, useWsHeaders);
                                result.addTarget(contextPath, target);
                                childEntry.recycle(childValues);
                                ViewEntry tempChild = childEntry;
                                childEntry = nav.getNextSibling(childEntry);
                                tempChild.recycle();
                            }
                        }
                        entry.recycle(columnValues);
                        ViewEntry tempEntry = entry;
                        entry = nav.getNextSibling(entry);
                        tempEntry.recycle();
                    }
                } finally {
                    session.recycle();
                }
                return;
            } catch (Throwable e) {
                e.printStackTrace(OpenLibertyLog.instance.out);
                throw new RuntimeException(e);
            }
        }).get();
        if (result.isGlobalEnabled()) {
            // Determine the local server port from the server doc
            DominoThreadFactory.getExecutor().submit(() -> {
                try {
                    Session session = NotesFactory.createSession();
                    try {
                        String serverName = session.getUserName();
                        // $NON-NLS-1$ //$NON-NLS-2$
                        Database names = session.getDatabase("", "names.nsf");
                        // $NON-NLS-1$
                        View servers = names.getView("$Servers");
                        Document serverDoc = servers.getDocumentByKey(serverName);
                        // Mirror Domino's maximum entity size
                        // $NON-NLS-1$
                        long maxEntitySize = serverDoc.getItemValueInteger("HTTP_MaxContentLength");
                        if (maxEntitySize == 0) {
                            maxEntitySize = Long.MAX_VALUE;
                        }
                        result.maxEntitySize = maxEntitySize;
                    } finally {
                        session.recycle();
                    }
                } catch (Exception e) {
                    e.printStackTrace(OpenLibertyLog.instance.out);
                    throw new RuntimeException(e);
                }
            }).get();
        }
    } catch (InterruptedException | ExecutionException e) {
        e.printStackTrace(OpenLibertyLog.instance.out);
        throw new RuntimeException(e);
    }
    return result;
}
Also used : ReverseProxyTarget(org.openntf.openliberty.domino.reverseproxy.ReverseProxyTarget) ViewNavigator(lotus.domino.ViewNavigator) RuntimeConfigurationProvider(org.openntf.openliberty.domino.config.RuntimeConfigurationProvider) Document(lotus.domino.Document) View(lotus.domino.View) URI(java.net.URI) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) KeyStoreException(java.security.KeyStoreException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) NotesException(lotus.domino.NotesException) IOException(java.io.IOException) KeyManagementException(java.security.KeyManagementException) CertificateException(java.security.cert.CertificateException) ExecutionException(java.util.concurrent.ExecutionException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) ReverseProxyConfig(org.openntf.openliberty.domino.reverseproxy.ReverseProxyConfig) ViewEntry(lotus.domino.ViewEntry) Database(lotus.domino.Database) Collection(java.util.Collection) List(java.util.List) ExecutionException(java.util.concurrent.ExecutionException) Vector(java.util.Vector) Session(lotus.domino.Session)

Example 2 with View

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

the class Connect17Standard method run.

@SuppressWarnings("unchecked")
@Override
public void run() {
    org.openntf.domino.Session sess = Factory.getSession(SessionType.NATIVE);
    try {
        TreeSet<String> names = new TreeSet<String>();
        Session session = TypeUtils.toLotus(sess);
        // Point to ExtLib demo, create a view called AllContactsByState
        // Copy AllContacts but adding a categorised column for State
        Database extLib = session.getDatabase(session.getServerName(), "odademo/oda_1.nsf");
        View states = extLib.getView("AllStates");
        states.setAutoUpdate(false);
        ViewEntry entState = states.getAllEntries().getFirstEntry();
        View byState = extLib.getView("AllContactsByState");
        byState.setAutoUpdate(false);
        Vector<String> key = new Vector<String>();
        Vector<String> stateVals = entState.getColumnValues();
        key.add(stateVals.get(0));
        ViewEntryCollection ec = byState.getAllEntriesByKey(key, true);
        ViewEntry ent = ec.getFirstEntry();
        while (null != ent) {
            Vector<Object> vals = ent.getColumnValues();
            names.add((String) vals.get(7));
            ViewEntry tmpEnt = ec.getNextEntry();
            ent.recycle(vals);
            ent.recycle();
            ent = tmpEnt;
        }
        System.out.println(names.toString());
    } catch (NotesException e) {
        e.printStackTrace();
    }
}
Also used : View(lotus.domino.View) NotesException(lotus.domino.NotesException) ViewEntry(lotus.domino.ViewEntry) TreeSet(java.util.TreeSet) Database(lotus.domino.Database) ViewEntryCollection(lotus.domino.ViewEntryCollection) Vector(java.util.Vector) Session(lotus.domino.Session)

Example 3 with View

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

the class OpenntfNABNamePickerData method readEntries.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.ibm.xsp.extlib.component.picker.data.AbstractDominoViewPickerData#readEntries(com.ibm.xsp.extlib.component.picker.data.IPickerOptions
	 * )
	 */
@Override
public IPickerResult readEntries(final IPickerOptions options) {
    try {
        getReturnNameFormat();
        EntryMetaData meta = createOpenntfEntryMetaData(options);
        meta.setKey(getReturnNameFormatAsKey());
        View view = meta.getView();
        view.setAutoUpdate(false);
        try {
            ArrayList<IPickerEntry> entries = new ArrayList<IPickerEntry>();
            int start = options.getStart();
            int count = options.getCount();
            String key = options.getKey();
            String _startKey = options.getStartKey();
            if (StringUtil.isNotEmpty(_startKey)) {
                key = _startKey;
            }
            String searchType = getSearchType();
            if (StringUtil.isEmpty(searchType)) {
                searchType = SEARCH_STARTFROM;
            }
            if (StringUtil.equals(searchType, SEARCH_MATCH)) {
                ViewEntryCollection vc = view.getAllEntriesByKey(key);
                ViewEntry ve = start > 0 ? vc.getNthEntry(start) : vc.getFirstEntry();
                for (int i = 0; i < count && ve != null; i++) {
                    entries.add(meta.createEntry(ve));
                    ve = vc.getNextEntry(ve);
                }
                int nEntries = vc.getCount();
                return new Result(entries, nEntries);
            }
            if (StringUtil.equals(searchType, SEARCH_FTSEARCH)) {
                applyFTSearch(options, view, key);
                ViewEntryCollection vc = view.getAllEntries();
                ViewEntry ve = start > 0 ? vc.getNthEntry(start) : vc.getFirstEntry();
                for (int i = 0; i < count && ve != null; i++) {
                    entries.add(meta.createEntry(ve));
                    ve = vc.getNextEntry(ve);
                }
                int nEntries = vc.getCount();
                return new Result(entries, nEntries);
            } else {
                ViewNavigator nav = view.createViewNav();
                try {
                    ViewEntry ve = null;
                    if (key != null) {
                        int searchOptions = DominoUtils.FIND_GREATER_THAN | DominoUtils.FIND_EQUAL | DominoUtils.FIND_PARTIAL | DominoUtils.FIND_CASE_INSENSITIVE;
                        ve = DominoUtils.getViewEntryByKeyWithOptions(Factory.getWrapperFactory().toLotus(view), key, searchOptions);
                    } else {
                        ve = nav.getCurrent();
                    }
                    if (start > 0) {
                        if (nav.skip(start) != start) {
                            // ok not all of them are skipped, stop the process
                            count = 0;
                        }
                    }
                    for (int i = 0; i < count && ve != null; i++) {
                        entries.add(meta.createEntry(ve));
                        ve = nav.getNext(ve);
                    }
                    int nEntries = -1;
                    return new Result(entries, nEntries);
                } finally {
                    nav.recycle();
                }
            }
        } finally {
        // Recycle the view?
        }
    } catch (Exception ex) {
        Platform.getInstance().log(ex);
        // Swallow the exception for the end user and return an empty picker
        return new EmptyPickerResult();
    }
}
Also used : ViewNavigator(lotus.domino.ViewNavigator) ArrayList(java.util.ArrayList) IPickerEntry(com.ibm.xsp.extlib.component.picker.data.IPickerEntry) EmptyPickerResult(com.ibm.xsp.extlib.component.picker.data.EmptyPickerResult) View(lotus.domino.View) NotesException(lotus.domino.NotesException) EmptyPickerResult(com.ibm.xsp.extlib.component.picker.data.EmptyPickerResult) IPickerResult(com.ibm.xsp.extlib.component.picker.data.IPickerResult) DominoViewEntry(com.ibm.xsp.model.domino.wrapped.DominoViewEntry) ViewEntry(lotus.domino.ViewEntry) ViewEntryCollection(lotus.domino.ViewEntryCollection)

Example 4 with View

use of lotus.domino.View 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 View

use of lotus.domino.View 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)

Aggregations

NotesException (lotus.domino.NotesException)6 View (lotus.domino.View)6 ViewEntry (lotus.domino.ViewEntry)5 Database (lotus.domino.Database)4 Session (lotus.domino.Session)4 ViewNavigator (lotus.domino.ViewNavigator)4 ViewEntryCollection (lotus.domino.ViewEntryCollection)3 EmptyPickerResult (com.ibm.xsp.extlib.component.picker.data.EmptyPickerResult)2 IPickerEntry (com.ibm.xsp.extlib.component.picker.data.IPickerEntry)2 IPickerResult (com.ibm.xsp.extlib.component.picker.data.IPickerResult)2 DominoViewEntry (com.ibm.xsp.model.domino.wrapped.DominoViewEntry)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Vector (java.util.Vector)2 Document (lotus.domino.Document)2 NotesAPIException (com.ibm.designer.domino.napi.NotesAPIException)1 NotesSession (com.ibm.designer.domino.napi.NotesSession)1 Sort (jakarta.nosql.Sort)1 DocumentEntity (jakarta.nosql.document.DocumentEntity)1 URI (java.net.URI)1