Skip to content

Commit

Permalink
Added defaultAction for #46
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelProminic committed Nov 16, 2023
1 parent ce67dbf commit 6bfd7e7
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ protected void writeNewDocument(Document document) throws NotesException {
super.writeNewDocument(document);

// update with link logic
LinkProcessor linkProcessor = new LinkProcessor(session, getLog());
LinkProcessor linkProcessor = new LinkProcessor(session, getLog(), agentDatabase);
linkProcessor.setAllowRemoteServer(true);
JSONObject link = (JSONObject) jsonRoot.get("document");
linkProcessor.cleanupLink(link);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.moonshine.domino.util.DominoUtils;

import genesis.LinkProcessor;
import lotus.domino.Database;
import lotus.domino.NotesException;
import lotus.domino.View;
import lotus.domino.ViewEntryCollection;
Expand All @@ -21,7 +22,7 @@ public class CustomBookmarkRead extends CustomBookmarkReadBase {

@Override
protected void writeDocuments(ViewEntryCollection entries, Collection<FieldDefinition> fieldList) throws NotesException {
LinkProcessor linkProcessor = new LinkProcessor(session, getLog());
LinkProcessor linkProcessor = new LinkProcessor(session, getLog(), agentDatabase);
linkProcessor.setAllowRemoteServer(true);

super.writeDocuments(entries, fieldList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ protected void writeUpdatedDocument(Document document) throws NotesException {
}

// update with link logic
LinkProcessor linkProcessor = new LinkProcessor(session, getLog());
LinkProcessor linkProcessor = new LinkProcessor(session, getLog(), agentDatabase);
linkProcessor.setAllowRemoteServer(true);
JSONObject link = (JSONObject) jsonRoot.get("document");
linkProcessor.cleanupLink(link);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected JSONObject getDatabaseJSON(Database db) throws NotesException, Excepti
// Generate the access URLs based on LinkProcessor logic
// json.put("url", "TODO");
// json.put("nomadURL", "TODO");
LinkProcessor processor = new LinkProcessor(session, getLog());
LinkProcessor processor = new LinkProcessor(session, getLog(), agentDatabase);
// set allowRemoteServer if we add support for reading other servers later
processor.cleanupLink(json);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ else if (appID.equalsIgnoreCase("genesis-directory")) {

// build the default URL
// TODO: this is specialized for SHI Domino instances. Make this more general, or only run for SHI instances?
LinkProcessor processor = new LinkProcessor(session, getLog());
LinkProcessor processor = new LinkProcessor(session, getLog(), agentDatabase);
String url = "http://" + processor.serverCommon;
url += ":82/"; // Default for SHI Domino servers. TODO: determine this from server document?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected void runAction() {
ViewEntryCollection additionalDirectories = null;
try {
loadInstalledApps();
linkProcessor = new LinkProcessor(session, getLog());
linkProcessor = new LinkProcessor(session, getLog(), agentDatabase);

// The central directory. Use "" for the label for now.
addApplicationsFromDirectory(getDataURL(), DEFAULT_DIRECTORY_LABEL, entries, linkProcessor);
Expand Down
40 changes: 37 additions & 3 deletions Super.Human.Portal_Agents/src/main/java/genesis/LinkProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
import org.json.JSONObject;

import com.moonshine.domino.log.LogInterface;
import com.moonshine.domino.util.ConfigurationUtils;
import com.moonshine.domino.util.DominoUtils;

import lotus.domino.Database;
import lotus.domino.Name;
import lotus.domino.NotesException;
import lotus.domino.Session;
Expand All @@ -35,12 +37,16 @@ public class LinkProcessor
* This is not desired for the central Genesis Direcotry, but could be useful for custom bookmarks and custom Genesis directories. */
private boolean allowRemoteServer = false;

public LinkProcessor(Session session, LogInterface log)
/** Cache the configured default action */
protected String defaultAction = null;
public static final String DEFAULT_ACTION_NOMAD = "nomad";

public LinkProcessor(Session session, LogInterface log, Database configDatabase)
{
this.session = session;
this.log = log;

initializeInsertionParameters();
initializeInsertionParameters(configDatabase);
}

protected LogInterface getLog() {
Expand Down Expand Up @@ -163,7 +169,16 @@ public void cleanupLink(JSONObject link) {

// // This was added to test the GUI logic for views. Remove this and configure a real example
// link.put("view", "Configuration");

// specify the default action for the link/bookmark
// either "nomad" or "notes" for now.
String defaultAction = JSONUtils.getStringSafe(link, "defaultAction");
if (DominoUtils.isValueEmpty(defaultAction)) {
link.put("defaultAction", getDefaultAction());
}
// else: keep existing value for defaultAction
}
// else: no special logic for 'browser' type



Expand Down Expand Up @@ -229,7 +244,7 @@ public boolean isDatabaseName(String value) {
/**
* Initialize insertion parameters that can be applied to the Genesis application list, including the local server name.
*/
protected void initializeInsertionParameters() {
protected void initializeInsertionParameters(Database configDatabase) {
Name nameObj = null;
try {
String name = session.getServerName();
Expand All @@ -246,6 +261,21 @@ protected void initializeInsertionParameters() {
finally {
DominoUtils.recycle(session, nameObj);
}


// Load Configuration values - TODO: move this to a different method?
// defaultAction
try {
// TODO: get a configuration database from a parameter instead
defaultAction = ConfigurationUtils.getConfigAsString(session.getCurrentDatabase(), "link_default_action");
if (DominoUtils.isValueEmpty(defaultAction)) {
defaultAction = DEFAULT_ACTION_NOMAD;
}
}
catch (Exception ex) {
getLog().err("Failed to load configured default action: ", ex);
defaultAction = DEFAULT_ACTION_NOMAD;
}
}

protected String getAbbrNameSafe(String name) {
Expand Down Expand Up @@ -297,4 +327,8 @@ public void processInsertionParameters(JSONObject object, String key, Map<String
getLog().err("Failed to update key '" + key + "'");
}
}

protected String getDefaultAction() {
return defaultAction;
}
}

0 comments on commit 6bfd7e7

Please sign in to comment.