-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial Database interface agent for #40
- Loading branch information
1 parent
5a80568
commit 1dab7aa
Showing
2 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
...an.Portal_Agents/agentProperties/agentbuild/CustomBookmarkScripts/DatabaseRead.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# target location overwritten by properties in build.gradle | ||
$$nsfServer= | ||
$$nsfFile= | ||
|
||
## Primary Configuration | ||
# The name of the agent. An alias can be specifed with: FullName|alias | ||
agent_name=DatabaseRead | ||
# The main class that should be run for this agent. This must include the package. The maximum length is 65 characters - additional characters will be cut off. | ||
javaproject_class=CustomBookmarkAgents/DatabaseRead.class | ||
# The JAR to use for this agent. All agents will use the combined JAR | ||
$$jarSourceFile=./build/libs/Super.Human.Portal_Agents.jar | ||
# Comma-separated list of Script Libraries required for this agent | ||
$$scriptLibrary=Moonshine-Domino-CRUD | ||
|
||
## Additional options | ||
# Whether the agent should run as the web users with permissions. true or false | ||
agent_runaswebuser=false | ||
# If true, enables you to access the agent without having to wait for it to complete. If you set this attribute to true and the agent references any front-end classes, a run-time error is generated | ||
agent_clientbackgroundthread=false | ||
# If true, permits remote debugging of the LotusScript in an agent script and permits you to monitor the execution of agents written in Java | ||
agent_allowremotedebugging=false | ||
# If true, highlights the text in the retrieved documents that matches the search query. Default is false. | ||
agent_storehighlights=false | ||
# The access level the agent needs: (restricted | unrestricted | fulladminunrestricted) | ||
agent_restrictions=restricted | ||
# Space separated list of hide restrictions. Allowed Values: (web | notes | v3) | ||
agent_hide=v3 notes | ||
# Do not change | ||
agent_publicaccess=false | ||
# The method to use for triggering the agent. Options: (actionsmenu | agentlist | beforenewmail | afternewmail | docupdate | docpaste | scheduled | serverstart ) | ||
trigger_type=actionsmenu | ||
# The runtime behavior of the agent: (modified | unreadinview | allinview | selected | runonce | all) | ||
documentset_type=runonce | ||
# Name of a built-in event or a user-defined LotusScript function. | ||
code_event=action | ||
# Do not change | ||
javaproject_codepath=. | ||
# true or false. Determines whether this agent is compiled with debugging information. True is recommended to see line numbers in stack traces | ||
javaproject_compiledebug=true | ||
# Do not change this | ||
javaproject_imported=true |
94 changes: 94 additions & 0 deletions
94
Super.Human.Portal_Agents/src/main/java/CustomBookmarkAgents/DatabaseRead.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package CustomBookmarkAgents; | ||
|
||
import java.util.Random; | ||
|
||
import org.json.JSONArray; | ||
import org.json.JSONObject; | ||
|
||
import com.moonshine.domino.crud.CRUDAgentBase; | ||
import com.moonshine.domino.security.AllowAllSecurity; | ||
import com.moonshine.domino.security.SecurityInterface; | ||
import com.moonshine.domino.util.DominoUtils; | ||
|
||
import lotus.domino.Database; | ||
import lotus.domino.DbDirectory; | ||
import lotus.domino.NotesException; | ||
|
||
/** | ||
* Return a list of the databases on the server | ||
*/ | ||
public class DatabaseRead extends CRUDAgentBase | ||
{ | ||
|
||
@Override | ||
protected void runAction() { | ||
DbDirectory directory = null; | ||
JSONArray json = null; | ||
try { | ||
directory = session.getDbDirectory(""); | ||
json = new JSONArray(); | ||
|
||
Database curDatabase = directory.getFirstDatabase(DbDirectory.TEMPLATE_CANDIDATE); // include templates for now | ||
while (null != curDatabase) { | ||
String identifier = "UNKNOWN"; | ||
try { | ||
identifier = curDatabase.getFilePath(); | ||
json.put(getDatabaseJSON(curDatabase)); | ||
} | ||
catch (Exception ex) { | ||
getLog().err("Could not process database '" + identifier + "': ", ex); | ||
} | ||
finally { | ||
Database prevDatabase = curDatabase; | ||
curDatabase = directory.getNextDatabase(); | ||
DominoUtils.recycle(session, prevDatabase); | ||
} | ||
} | ||
} | ||
catch (NotesException ex) { | ||
getLog().err("Error when reading database directory: ", ex); | ||
} | ||
finally { | ||
DominoUtils.recycle(session, directory); | ||
jsonRoot.put("databases", json); | ||
} | ||
} | ||
|
||
protected JSONObject getDatabaseJSON(Database db) throws NotesException, Exception { | ||
JSONObject json = new JSONObject(); | ||
|
||
// this JSON is intended to be compatible with the database link logic | ||
json.put("name", db.getTitle()); | ||
json.put("type", "database"); | ||
json.put("server", db.getServer()); | ||
json.put("database", db.getFilePath()); | ||
json.put("view", ""); // no specific view by default | ||
|
||
// TODO: generate the access URLs based on LinkProcessor logic | ||
json.put("url", "TODO"); | ||
json.put("nomadURL", "TODO"); | ||
|
||
// additional values | ||
// Replica is not needed for initial logic, but it may be useful later | ||
json.put("replicaID", db.getReplicaID()); | ||
|
||
// properties to track existing values: | ||
// TODO: compute these instead of using placeholders | ||
json.put("hasBookmarks", false); // new Random().nextBoolean()); | ||
json.put("bookmarkCount", 0); | ||
json.put("bookmarks", new JSONArray()); | ||
|
||
return json; | ||
} | ||
|
||
@Override | ||
protected SecurityInterface createSecurityInterface() { | ||
return new AllowAllSecurity(session); | ||
} | ||
|
||
@Override | ||
protected boolean useJSON() { | ||
// only support JSON for now | ||
return true; | ||
} | ||
} |