use of lotus.domino.ViewNavigator 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;
}
use of lotus.domino.ViewNavigator 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();
}
}
use of lotus.domino.ViewNavigator 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);
}
}
use of lotus.domino.ViewNavigator in project org.openntf.domino by OpenNTF.
the class OpenntfViewValuePickerData 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 {
EntryMetaData meta = new _EntryMetaData(options);
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;
// This is the one line that's different
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();
}
}
Aggregations