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;
}
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);
}
}
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();
}
}
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];
}
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);
}
}
Aggregations