use of lotus.domino.Database in project org.openntf.xsp.jakartaee by OpenNTF.
the class DefaultDominoDocumentCollectionManager method getQrpDatabase.
private Database getQrpDatabase(Session session, Database database) throws NotesException {
String server = database.getServer();
String filePath = database.getFilePath();
try {
// $NON-NLS-1$
String fileName = md5(server + filePath) + ".nsf";
Path tempDir = getTempDirectory();
Path dest = tempDir.resolve(getClass().getPackage().getName());
Files.createDirectories(dest);
Path dbPath = dest.resolve(fileName);
// $NON-NLS-1$
Database qrp = session.getDatabase("", dbPath.toString());
if (!qrp.isOpen()) {
qrp.recycle();
DbDirectory dbDir = session.getDbDirectory(null);
// TODO encrypt when the API allows
qrp = dbDir.createDatabase(dbPath.toString(), true);
ACL acl = qrp.getACL();
ACLEntry entry = acl.createACLEntry(session.getEffectiveUserName(), ACL.LEVEL_MANAGER);
entry.setCanDeleteDocuments(true);
acl.save();
}
return qrp;
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
use of lotus.domino.Database 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);
}
}
use of lotus.domino.Database in project org.openntf.xsp.jakartaee by OpenNTF.
the class DefaultDominoDocumentCollectionManager method insert.
@Override
public DocumentEntity insert(DocumentEntity entity) {
try {
Database database = supplier.get();
lotus.domino.Document target = database.createDocument();
Optional<Document> maybeId = entity.find(EntityConverter.ID_FIELD);
if (maybeId.isPresent()) {
target.setUniversalID(maybeId.get().get().toString());
} else {
// Write the generated UNID into the entity
entity.add(Document.of(EntityConverter.ID_FIELD, target.getUniversalID()));
}
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 DefaultDominoDocumentCollectionManager method count.
@Override
public long count(String documentCollection) {
try {
Database database = supplier.get();
DominoQuery dominoQuery = database.createDominoQuery();
DQLTerm dql = DQL.item(EntityConverter.NAME_FIELD).isEqualTo(documentCollection);
DocumentCollection result = dominoQuery.execute(dql.toString());
return result.getCount();
} catch (NotesException e) {
throw new RuntimeException(e);
}
}
use of lotus.domino.Database 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);
}
}
Aggregations