Search in sources :

Example 1 with Database

use of lotus.domino.Database in project org.openntf.xsp.jakartaee by OpenNTF.

the class AbstractOpenAPIResource method buildOpenAPI.

protected OpenAPI buildOpenAPI() throws IOException, NotesException {
    Set<Class<?>> classes = new HashSet<>();
    classes.addAll(application.getClasses());
    classes.add(application.getClass());
    Index index = Index.of(classes);
    Config mpConfig = CDI.current().select(Config.class).get();
    OpenApiConfig config = OpenApiConfigImpl.fromConfig(mpConfig);
    ClassLoader cl = new DelegatingClassLoader(OpenApiProcessor.class.getClassLoader(), Thread.currentThread().getContextClassLoader());
    OpenAPI openapi;
    synchronized (OpenApiProcessor.class) {
        // OpenApiProcessor appears to be not thread-safe
        openapi = OpenApiProcessor.bootstrap(config, index, cl);
    }
    NotesContext notesContext = NotesContext.getCurrent();
    Database database = notesContext.getCurrentDatabase();
    Info info = openapi.getInfo();
    String existingTitle = config.getInfoTitle();
    if (existingTitle == null || existingTitle.isEmpty()) {
        info.setTitle(database.getTitle());
    } else {
        info.setTitle(existingTitle);
    }
    String existingVersion = config.getInfoVersion();
    if (existingVersion == null || existingVersion.isEmpty()) {
        String templateBuild = getVersionNumber(database);
        if (templateBuild != null && !templateBuild.isEmpty()) {
            info.setVersion(templateBuild);
        } else {
            info.setVersion(existingVersion);
        }
    } else {
        info.setVersion(existingVersion);
    }
    // Build a URI to the base of JAX-RS
    Set<String> servers = config.servers();
    if (servers == null || servers.isEmpty()) {
        Server server = new ServerImpl();
        URI uri = URI.create(req.getRequestURL().toString());
        String jaxrsRoot = JAXRSServletFactory.getServletPath(notesContext.getModule());
        uri = uri.resolve(PathUtil.concat(req.getContextPath(), jaxrsRoot, '/'));
        String uriString = uri.toString();
        if (uriString.endsWith("/")) {
            // $NON-NLS-1$
            uriString = uriString.substring(0, uriString.length() - 1);
        }
        server.setUrl(uriString);
        openapi.addServer(server);
    }
    return openapi;
}
Also used : Server(org.eclipse.microprofile.openapi.models.servers.Server) Config(org.eclipse.microprofile.config.Config) OpenApiConfig(io.smallrye.openapi.api.OpenApiConfig) NotesContext(com.ibm.domino.xsp.module.nsf.NotesContext) Index(org.jboss.jandex.Index) OpenApiProcessor(io.smallrye.openapi.runtime.OpenApiProcessor) Info(org.eclipse.microprofile.openapi.models.info.Info) DelegatingClassLoader(org.openntf.xsp.jakartaee.DelegatingClassLoader) URI(java.net.URI) ServerImpl(io.smallrye.openapi.api.models.servers.ServerImpl) OpenApiConfig(io.smallrye.openapi.api.OpenApiConfig) Database(lotus.domino.Database) DelegatingClassLoader(org.openntf.xsp.jakartaee.DelegatingClassLoader) OpenAPI(org.eclipse.microprofile.openapi.models.OpenAPI) HashSet(java.util.HashSet)

Example 2 with Database

use of lotus.domino.Database in project org.openntf.xsp.jakartaee by OpenNTF.

the class DefaultDominoDocumentCollectionManager method update.

@Override
public DocumentEntity update(DocumentEntity entity) {
    try {
        Database database = supplier.get();
        Document id = entity.find(EntityConverter.ID_FIELD).orElseThrow(() -> new IllegalArgumentException(MessageFormat.format("Unable to find {0} in entity", EntityConverter.ID_FIELD)));
        lotus.domino.Document target = database.getDocumentByUNID((String) id.get());
        EntityConverter.convert(entity, target);
        target.save();
        return entity;
    } catch (NotesException e) {
        throw new RuntimeException(e);
    }
}
Also used : NotesException(lotus.domino.NotesException) Database(lotus.domino.Database) Document(jakarta.nosql.document.Document)

Example 3 with Database

use of lotus.domino.Database in project org.openntf.xsp.jakartaee by OpenNTF.

the class PassingHealthCheck method call.

@Override
public HealthCheckResponse call() {
    HealthCheckResponseBuilder response = HealthCheckResponse.named("I am the liveliness check");
    try {
        Database database = NotesContext.getCurrent().getCurrentDatabase();
        NoteCollection notes = database.createNoteCollection(true);
        notes.buildCollection();
        return response.status(true).withData("noteCount", notes.getCount()).build();
    } catch (NotesException e) {
        return response.status(false).withData("exception", e.text).build();
    }
}
Also used : NotesException(lotus.domino.NotesException) HealthCheckResponseBuilder(org.eclipse.microprofile.health.HealthCheckResponseBuilder) NoteCollection(lotus.domino.NoteCollection) Database(lotus.domino.Database)

Example 4 with Database

use of lotus.domino.Database in project org.openntf.xsp.jakartaee by OpenNTF.

the class PostInstallFactory method getServices.

@Override
public HttpService[] getServices(LCDEnvironment env) {
    System.out.println("postinstall start");
    try {
        Session session = NotesFactory.createSession();
        try {
            for (String nsfName : NSFS) {
                Database database = session.getDatabase("", nsfName);
                if (database == null || !database.isOpen()) {
                    throw new RuntimeException("Could not find " + nsfName);
                }
                ACL acl = database.getACL();
                ACLEntry anon = acl.getEntry("Anonymous");
                if (anon == null) {
                    anon = acl.createACLEntry("Anonymous", ACL.LEVEL_AUTHOR);
                } else {
                    anon.setLevel(ACL.LEVEL_AUTHOR);
                }
                ACLEntry admin = acl.createACLEntry("CN=Jakarta EE Test/O=OpenNTFTest", ACL.LEVEL_MANAGER);
                try {
                    admin.enableRole("[Admin]");
                } catch (NotesException e) {
                // Failing here is fine, in case the NSF doesn't have the role
                }
                acl.save();
                database.getView("Persons");
                session.sendConsoleCommand("", "load updall " + nsfName);
            }
            session.sendConsoleCommand("", "tell http osgi diag");
        } finally {
            session.recycle();
        }
    } catch (NotesException e) {
        e.printStackTrace();
    } finally {
        System.out.println("Done with postinstall");
    }
    return new HttpService[0];
}
Also used : NotesException(lotus.domino.NotesException) ACLEntry(lotus.domino.ACLEntry) HttpService(com.ibm.designer.runtime.domino.adapter.HttpService) Database(lotus.domino.Database) ACL(lotus.domino.ACL) Session(lotus.domino.Session)

Example 5 with Database

use of lotus.domino.Database in project org.openntf.nsfodp by OpenNTF.

the class DeployNSFTask method run.

@Override
public void run() {
    try {
        Session session = NotesFactory.createSession();
        try {
            String server, filePath;
            // $NON-NLS-1$
            int bangIndex = destPath.indexOf("!!");
            if (bangIndex > -1) {
                server = destPath.substring(0, bangIndex);
                filePath = destPath.substring(bangIndex + 2);
            } else {
                // $NON-NLS-1$
                server = "";
                filePath = destPath;
            }
            Database dest = session.getDatabase(server, filePath, true);
            if (dest.isOpen() && !replaceDesign) {
                throw new IllegalStateException(MessageFormat.format(Messages.DeployNSFTask_dbExists, destPath));
            }
            if (dest.isOpen()) {
                // Then do a replace design
                ReplaceDesignTaskLocal task = new ReplaceDesignTaskLocal(filePath, nsfFile, new NullProgressMonitor());
                DominoThreadFactory.getExecutor().submit(task).get();
            } else {
                // $NON-NLS-1$
                Database source = session.getDatabase("", nsfFile.toAbsolutePath().toString());
                dest = source.createFromTemplate(server, filePath, false);
            }
            if (this.signDatabase) {
                AdministrationProcess adminp = session.createAdministrationProcess(server);
                adminp.signDatabaseWithServerID(server, filePath);
                // $NON-NLS-1$
                session.sendConsoleCommand(server, "tell adminp p im");
            }
        } finally {
            session.recycle();
        }
    } catch (NotesException | ExecutionException | InterruptedException ne) {
        throw new RuntimeException(Messages.DeployNSFTask_exceptionDeploying, ne);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) NotesException(lotus.domino.NotesException) Database(lotus.domino.Database) AdministrationProcess(lotus.domino.AdministrationProcess) ExecutionException(java.util.concurrent.ExecutionException) Session(lotus.domino.Session)

Aggregations

Database (lotus.domino.Database)32 Session (lotus.domino.Session)18 Document (lotus.domino.Document)16 NotesException (lotus.domino.NotesException)13 DocumentCollection (lotus.domino.DocumentCollection)5 NoteCollection (lotus.domino.NoteCollection)5 View (lotus.domino.View)4 IOException (java.io.IOException)3 Vector (java.util.Vector)3 DateTime (lotus.domino.DateTime)3 DominoQuery (lotus.domino.DominoQuery)3 Item (lotus.domino.Item)3 ViewEntry (lotus.domino.ViewEntry)3 DominoDocument (com.ibm.xsp.model.domino.wrapped.DominoDocument)2 Document (jakarta.nosql.document.Document)2 URI (java.net.URI)2 Path (java.nio.file.Path)2 Date (java.util.Date)2 ExecutionException (java.util.concurrent.ExecutionException)2 ACL (lotus.domino.ACL)2