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