You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@manifoldcf.apache.org by kw...@apache.org on 2011/07/12 19:13:05 UTC
svn commit: r1145683 -
/incubator/lcf/branches/CONNECTORS-221/connectors/cmis/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/cmis/CmisRepositoryConnector.java
Author: kwright
Date: Tue Jul 12 17:13:05 2011
New Revision: 1145683
URL: http://svn.apache.org/viewvc?rev=1145683&view=rev
Log:
Apply java-2 patch.
Modified:
incubator/lcf/branches/CONNECTORS-221/connectors/cmis/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/cmis/CmisRepositoryConnector.java
Modified: incubator/lcf/branches/CONNECTORS-221/connectors/cmis/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/cmis/CmisRepositoryConnector.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-221/connectors/cmis/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/cmis/CmisRepositoryConnector.java?rev=1145683&r1=1145682&r2=1145683&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-221/connectors/cmis/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/cmis/CmisRepositoryConnector.java (original)
+++ incubator/lcf/branches/CONNECTORS-221/connectors/cmis/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/cmis/CmisRepositoryConnector.java Tue Jul 12 17:13:05 2011
@@ -24,7 +24,6 @@ import java.math.BigInteger;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.text.SimpleDateFormat;
-import java.util.ArrayList;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Iterator;
@@ -44,11 +43,7 @@ import org.apache.chemistry.opencmis.cli
import org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl;
import org.apache.chemistry.opencmis.commons.PropertyIds;
import org.apache.chemistry.opencmis.commons.SessionParameter;
-import org.apache.chemistry.opencmis.commons.data.Ace;
-import org.apache.chemistry.opencmis.commons.data.Acl;
-import org.apache.chemistry.opencmis.commons.data.AclCapabilities;
import org.apache.chemistry.opencmis.commons.enums.BindingType;
-import org.apache.chemistry.opencmis.commons.enums.CapabilityAcl;
import org.apache.chemistry.opencmis.commons.enums.PropertyType;
import org.apache.chemistry.opencmis.commons.impl.Constants;
import org.apache.commons.lang.StringUtils;
@@ -56,10 +51,8 @@ import org.apache.manifoldcf.agents.inte
import org.apache.manifoldcf.agents.interfaces.ServiceInterruption;
import org.apache.manifoldcf.core.interfaces.ConfigParams;
import org.apache.manifoldcf.core.interfaces.IHTTPOutput;
-import org.apache.manifoldcf.core.interfaces.IKeystoreManager;
import org.apache.manifoldcf.core.interfaces.IPostParameters;
import org.apache.manifoldcf.core.interfaces.IThreadContext;
-import org.apache.manifoldcf.core.interfaces.KeystoreManagerFactory;
import org.apache.manifoldcf.core.interfaces.ManifoldCFException;
import org.apache.manifoldcf.core.interfaces.SpecificationNode;
import org.apache.manifoldcf.crawler.connectors.BaseRepositoryConnector;
@@ -80,7 +73,6 @@ public class CmisRepositoryConnector ext
public static final String CONFIG_PARAM_ENDPOINT = "endpoint";
public static final String CONFIG_PARAM_REPOSITORY_ID = "repositoryId";
public static final String CONFIG_PARAM_CMIS_QUERY = "cmisQuery";
- public static final String CONFIG_PARAM_ACL_FETCH = "enableAclFetch";
private static final String JOB_STARTPOINT_NODE_TYPE = "startpoint";
private static final String TAB_LABEL_CMIS_QUERY = "CMIS Query";
@@ -91,16 +83,13 @@ public class CmisRepositoryConnector ext
private static final String CMIS_FOLDER_BASE_TYPE = "Folder";
private static final SimpleDateFormat ISO8601_DATE_FORMATTER = new SimpleDateFormat(
"yyyy-MM-dd'T'HH:mm:ssZ");
-
- private static final String CMIS_PERMISSION_FIELD = "cmis:permission";
- private static final String CMIS_PRINCIPAL_PERMISSION_SEP = ",";
/**
* CMIS Session handle
*/
Session session = null;
- OperationContext operationContextAclFetchEnabled = null;
+ OperationContext oc = null;
protected String username = null;
protected String password = null;
@@ -165,10 +154,8 @@ public class CmisRepositoryConnector ext
session = factory.createSession(parameters);
}
- //special CMIS operation contexts used only if there are some
- //specific settings configured in the job (ACL Fetch, etc...)
- operationContextAclFetchEnabled = session.createOperationContext();
- operationContextAclFetchEnabled.setIncludeAcls(true);
+ oc = session.createOperationContext();
+ oc.setIncludeAcls(true);
} catch (Throwable e) {
this.exception = e;
@@ -212,7 +199,7 @@ public class CmisRepositoryConnector ext
public void run() {
try {
- session.clear();
+ session = null;
} catch (Throwable e) {
this.exception = e;
}
@@ -254,7 +241,7 @@ public class CmisRepositoryConnector ext
lastSessionFetch = -1L;
// Treat this as a transient problem
Logging.connectors.warn(
- "Cmis: Transient remote exception closing session: "
+ "CMIS: Transient remote exception closing session: "
+ e.getMessage(), e);
}
@@ -303,13 +290,13 @@ public class CmisRepositoryConnector ext
+ " required but not set");
if (Logging.connectors.isDebugEnabled())
- Logging.connectors.debug("Cmis: Username = '" + username + "'");
+ Logging.connectors.debug("CMIS: Username = '" + username + "'");
if (StringUtils.isEmpty(password))
throw new ManifoldCFException("Parameter " + CONFIG_PARAM_PASSWORD
+ " required but not set");
- Logging.connectors.debug("Cmis: Password exists");
+ Logging.connectors.debug("CMIS: Password exists");
if (StringUtils.isEmpty(endpoint))
throw new ManifoldCFException("Parameter " + CONFIG_PARAM_ENDPOINT
@@ -340,7 +327,7 @@ public class CmisRepositoryConnector ext
} catch (NotBoundException e) {
// Transient problem: Server not available at the moment.
Logging.connectors.warn(
- "Cmis: CMIS server not up at the moment: " + e.getMessage(), e);
+ "CMIS: Server not up at the moment: " + e.getMessage(), e);
currentTime = System.currentTimeMillis();
throw new ServiceInterruption(e.getMessage(), currentTime + 60000L);
} catch (RemoteException e) {
@@ -351,7 +338,7 @@ public class CmisRepositoryConnector ext
ManifoldCFException.INTERRUPTED);
// Treat this as a transient problem
Logging.connectors.warn(
- "Cmis: Transient remote exception creating session: "
+ "CMIS: Transient remote exception creating session: "
+ e.getMessage(), e);
currentTime = System.currentTimeMillis();
throw new ServiceInterruption(e.getMessage(), currentTime + 60000L);
@@ -398,7 +385,7 @@ public class CmisRepositoryConnector ext
lastSessionFetch = -1L;
// Treat this as a transient problem
Logging.connectors.warn(
- "Cmis: Transient remote exception closing session: "
+ "CMIS: Transient remote exception closing session: "
+ e.getMessage(), e);
}
@@ -480,7 +467,7 @@ public class CmisRepositoryConnector ext
lastSessionFetch = -1L;
// Treat this as a transient problem
Logging.connectors.warn(
- "Cmis: Transient remote exception closing session: "
+ "CMIS: Transient remote exception closing session: "
+ e.getMessage(), e);
}
@@ -506,7 +493,7 @@ public class CmisRepositoryConnector ext
}
if (StringUtils.isEmpty(cmisQuery)) {
- // get root Documents from the Cmis Repository
+ // get root Documents from the CMIS Repository
ItemIterable<CmisObject> cmisObjects = session.getRootFolder()
.getChildren();
for (CmisObject cmisObject : cmisObjects) {
@@ -569,14 +556,6 @@ public class CmisRepositoryConnector ext
out.print(" <nobr>"
+ org.apache.manifoldcf.ui.util.Encoder.bodyEscape(param)
+ "=********</nobr><br/>\n");
- } else if (param.length() >= "keystore".length()
- && param.substring(param.length() - "keystore".length())
- .equalsIgnoreCase("keystore")) {
- IKeystoreManager kmanager = KeystoreManagerFactory.make("", value);
- out.print(" <nobr>"
- + org.apache.manifoldcf.ui.util.Encoder.bodyEscape(param) + "=<"
- + Integer.toString(kmanager.getContents().length)
- + " certificate(s)></nobr><br/>\n");
} else {
out.print(" <nobr>"
+ org.apache.manifoldcf.ui.util.Encoder.bodyEscape(param) + "="
@@ -584,7 +563,7 @@ public class CmisRepositoryConnector ext
+ "</nobr><br/>\n");
}
}
- out.print(" </td>\n" + " </tr>\n" + "</table>\n");
+ out.print("</td>\n" + " </tr>\n" + "</table>\n");
}
/**
@@ -608,7 +587,6 @@ public class CmisRepositoryConnector ext
public void outputConfigurationHeader(IThreadContext threadContext,
IHTTPOutput out, ConfigParams parameters, List<String> tabsArray)
throws ManifoldCFException, IOException {
-
out.print("<script type=\"text/javascript\">\n" + "<!--\n"
+ "function checkConfig()\n" + "{\n"
+ " if (editconnection.username.value == \"\")\n" + " {\n"
@@ -620,7 +598,7 @@ public class CmisRepositoryConnector ext
+ " }\n" + " if (editconnection.endpoint.value == \"\")\n" + " {\n"
+ " alert(\"The endpoint must be not null\");\n"
+ " editconnection.endpoint.focus();\n" + " return false;\n"
- + " }\n" + "\n" + " return true;\n" + "}\n" + " \n"
+ + " }\n" + "\n" + " return true;\n" + "}\n" + " \n"
+ "function checkConfigForSave()\n" + "{\n"
+ " if (editconnection.username.value == \"\")\n" + " {\n"
+ " alert(\"The username must be not null\");\n"
@@ -657,18 +635,18 @@ public class CmisRepositoryConnector ext
out.print("<table class=\"displaytable\">\n"
+ " <tr><td class=\"separator\" colspan=\"2\"><hr/></td></tr>\n");
out.print(
- "<tr><td class=\"description\">Username:</td>\n"
+ "<tr><td class=\"description\"><nobr>Username:</nobr></td>\n"
+"<td class=\"value\"><input type=\"text\" name=\""
+ CONFIG_PARAM_USERNAME + "\" value=\""+username+"\"/></td></tr>\n");
- out.print("<tr><td class=\"description\">Password:</td>" +
+ out.print("<tr><td class=\"description\"><nobr>Password:</nobr></td>" +
"<td class=\"value\"><input type=\"password\" name=\""
+ CONFIG_PARAM_PASSWORD + "\" value=\""+password+"\"/></td></tr>\n");
- out.print("<tr><td class=\"description\">Endpoint:</td>" +
+ out.print("<tr><td class=\"description\"><nobr>Endpoint:</nobr></td>" +
"<td class=\"value\"><input type=\"text\" name=\""
- + CONFIG_PARAM_ENDPOINT + "\" value=\""+endpoint+"\" size=\"60\"/></td></tr>\n");
- out.print("<tr><td class=\"description\">Repository ID:</td>" +
+ + CONFIG_PARAM_ENDPOINT + "\" value=\""+endpoint+"\" size=\"50\"/></td></tr>\n");
+ out.print("<tr><td class=\"description\"><nobr>Repository ID:</nobr></td>" +
"<td class=\"value\"><input type=\"text\" name=\""
- + CONFIG_PARAM_REPOSITORY_ID + "\" value=\""+repositoryId+"\"/></td></tr>\n");
+ + CONFIG_PARAM_REPOSITORY_ID + "\" value=\""+repositoryId+"\"/><nobr>(optional)</nobr></td></tr>\n");
out.print("</table>\n");
}
@@ -746,13 +724,6 @@ public class CmisRepositoryConnector ext
+ org.apache.manifoldcf.ui.util.Encoder.bodyEscape(sn
.getAttributeValue(CONFIG_PARAM_CMIS_QUERY)));
out.print(" </td>\n" + " </tr>\n");
- out.print(" <tr>\n"
- + " <td class=\"description\">ACL Fetch:</td>\n"
- + " <td class=\"value\">\n"
- + org.apache.manifoldcf.ui.util.Encoder.bodyEscape(sn
- .getAttributeValue(CONFIG_PARAM_ACL_FETCH)));
- out.print(" </td>\n" + " </tr>\n");
-
}
i++;
}
@@ -783,7 +754,6 @@ public class CmisRepositoryConnector ext
public String processSpecificationPost(IPostParameters variableContext,
DocumentSpecification ds) throws ManifoldCFException {
String cmisQuery = variableContext.getParameter(CONFIG_PARAM_CMIS_QUERY);
- String enableAclFetch = variableContext.getParameter(CONFIG_PARAM_ACL_FETCH);
if (StringUtils.isNotEmpty(cmisQuery)) {
int i = 0;
while (i < ds.getChildCount()) {
@@ -796,9 +766,7 @@ public class CmisRepositoryConnector ext
}
SpecificationNode node = new SpecificationNode(JOB_STARTPOINT_NODE_TYPE);
node.setAttribute(CONFIG_PARAM_CMIS_QUERY, cmisQuery);
- node.setAttribute(CONFIG_PARAM_ACL_FETCH, enableAclFetch);
variableContext.setParameter(CONFIG_PARAM_CMIS_QUERY, cmisQuery);
- variableContext.setParameter(CONFIG_PARAM_ACL_FETCH, enableAclFetch);
ds.addChild(ds.getChildCount(), node);
} else {
int i = 0;
@@ -807,8 +775,6 @@ public class CmisRepositoryConnector ext
if (oldNode.getType().equals(JOB_STARTPOINT_NODE_TYPE)) {
variableContext.setParameter(CONFIG_PARAM_CMIS_QUERY,
oldNode.getAttributeValue(CONFIG_PARAM_CMIS_QUERY));
- variableContext.setParameter(CONFIG_PARAM_ACL_FETCH,
- oldNode.getAttributeValue(CONFIG_PARAM_ACL_FETCH));
}
i++;
}
@@ -838,43 +804,27 @@ public class CmisRepositoryConnector ext
IOException {
if (tabName.equals(TAB_LABEL_CMIS_QUERY)) {
String cmisQuery = StringUtils.EMPTY;
- Boolean enableAclFetch = false;
int i = 0;
while (i < ds.getChildCount()) {
SpecificationNode n = ds.getChild(i);
if (n.getType().equals(JOB_STARTPOINT_NODE_TYPE)) {
cmisQuery = n.getAttributeValue(CONFIG_PARAM_CMIS_QUERY);
- enableAclFetch = new Boolean(n.getAttributeValue(CONFIG_PARAM_ACL_FETCH));
break;
}
i++;
}
out.print("<table class=\"displaytable\">\n"
- + " <tr><td class=\"separator\" colspan=\"3\"><hr/></td></tr>\n");
- out.print(" <tr class=\"formrow\">\n"
- + " <td class=\"formcolumncell\">CMIS Query: </td>"
- + " <td class=\"formcolumncell\">\n"
+ + " <tr><td class=\"separator\" colspan=\"3\"><hr/></td></tr>\n"
+ + " <tr>\n"
+ + " <td class=\"description\"><nobr>CMIS Query:</nobr></td>"
+ + " <td class=\"value\">\n"
+ " <nobr>\n"
- + " <input type=\"text\" size=\"120\" name=\"cmisQuery\" value=\""
- + cmisQuery
- + "\"/>\n"
+ + " <input type=\"text\" size=\"120\" name=\"cmisQuery\" value=\""+cmisQuery+"\"/>\n"
+ " </nobr>\n"
+ " </td>\n"
+ " </tr>\n"
- + " <tr><td class=\"separator\" colspan=\"3\"><hr/></td></tr>\n"
- + " <tr class=\"formrow\">\n"
- + " <td class=\"formcolumncell\">ACL Fetch: </td>");
-
- if(enableAclFetch){
- out.print(" <td class=\"formcolumncell\"><nobr>Enabled <input type=\"radio\" name=\"enableAclFetch\" value=\"true\" checked/>"
- + " Disabled <input type=\"radio\" name=\"enableAclFetch\" value=\"false\"/></nobr></td>");
- } else {
- out.print(" <td class=\"formcolumncell\"><nobr>Enabled <input type=\"radio\" name=\"enableAclFetch\" value=\"true\"/>"
- + " Disabled <input type=\"radio\" name=\"enableAclFetch\" value=\"false\" checked/></nobr></td>");
- }
-
- out.print("</tr>"
+ + " </tr>"
+ "</table>\n");
}
}
@@ -914,7 +864,7 @@ public class CmisRepositoryConnector ext
boolean[] scanOnly) throws ManifoldCFException, ServiceInterruption {
getSession();
- Logging.connectors.debug("Cmis: Inside processDocuments");
+ Logging.connectors.debug("CMIS: Inside processDocuments");
int i = 0;
while (i < documentIdentifiers.length) {
@@ -922,7 +872,7 @@ public class CmisRepositoryConnector ext
String nodeId = documentIdentifiers[i];
if (Logging.connectors.isDebugEnabled())
- Logging.connectors.debug("Cmis: Processing document identifier '"
+ Logging.connectors.debug("CMIS: Processing document identifier '"
+ nodeId + "'");
CmisObject cmisObject = session.getObject(nodeId);
@@ -1005,62 +955,11 @@ public class CmisRepositoryConnector ext
}
}
}
-
- //get ACL settings from the job configuration
- Boolean enabledAclFetch = false;
- int j = 0;
- while (j < spec.getChildCount()) {
- SpecificationNode sn = spec.getChild(i);
- if (sn.getType().equals(JOB_STARTPOINT_NODE_TYPE)) {
- enabledAclFetch = new Boolean(sn.getAttributeValue(CONFIG_PARAM_ACL_FETCH));
- break;
- }
- j++;
- }
-
- if(enabledAclFetch){
- // ACL Fetch enabled
-
- //check if the CMIS repository supports fetching for ACL
- AclCapabilities aclCapabilities = session.getRepositoryInfo().getAclCapabilities();
- if(!CapabilityAcl.NONE.equals(aclCapabilities)){
-
- //ACL metadata is indexed using a cmis:permission multivalue property as the following example:
- //cmis:permission='johndoe,cmis:write'
- //cmis:permission='guest,cmis:read'
- //cmis:permission='admin,cmis:all'
- // on Apache Solr you can configure the following field for permissions in the schema.xml:
- //<field name="permissions" type="string" indexed="true" stored="true" multiValued="true"/>
- //Then inside the job configuration form you can set the following field mapping:
- //cmis:permission -> permissions
-
- document = (Document) session.getObject(document.getId(), operationContextAclFetchEnabled);
- Acl aclCmis = document.getAcl();
- List<Ace> aces = aclCmis.getAces();
- String principalId = StringUtils.EMPTY;
- String permissionData = StringUtils.EMPTY;
- String[] fieldData = null;
- List<String> fieldDataList = new ArrayList<String>();
- fieldDataList.toArray();
- for (Ace ace : aces) {
- principalId = ace.getPrincipalId();
- List<String> permissions = ace.getPermissions();
- for (String permission : permissions) {
- permissionData = principalId + CMIS_PRINCIPAL_PERMISSION_SEP + permission;
- fieldDataList.add(permissionData);
- }
- }
-
- //converting List to String[]
- fieldData = new String[fieldDataList.size()];
- fieldDataList.toArray(fieldData);
- rd.addField(CMIS_PERMISSION_FIELD, fieldData);
- }
- }
//ingestion
String version = document.getVersionLabel();
- activities.ingestDocument(id, version, id, rd);
+ String documentURI = endpoint+"/"+id+"/"+version;
+ activities.ingestDocument(id, version, documentURI, rd);
} finally {
try {
@@ -1074,7 +973,7 @@ public class CmisRepositoryConnector ext
errorCode = "IO ERROR";
errorDesc = e.getMessage();
Logging.connectors.warn(
- "Cmis: IOException closing file input stream: "
+ "CMIS: IOException closing file input stream: "
+ e.getMessage(), e);
}
@@ -1085,4 +984,39 @@ public class CmisRepositoryConnector ext
i++;
}
}
+
+ /** The short version of getDocumentVersions.
+ * Get document versions given an array of document identifiers.
+ * This method is called for EVERY document that is considered. It is
+ * therefore important to perform as little work as possible here.
+ *@param documentIdentifiers is the array of local document identifiers, as understood by this connector.
+ *@param spec is the current document specification for the current job. If there is a dependency on this
+ * specification, then the version string should include the pertinent data, so that reingestion will occur
+ * when the specification changes. This is primarily useful for metadata.
+ *@return the corresponding version strings, with null in the places where the document no longer exists.
+ * Empty version strings indicate that there is no versioning ability for the corresponding document, and the document
+ * will always be processed.
+ */
+ @Override
+ public String[] getDocumentVersions(String[] documentIdentifiers,
+ DocumentSpecification spec) throws ManifoldCFException,
+ ServiceInterruption {
+
+ getSession();
+
+ String[] rval = new String[documentIdentifiers.length];
+ int i = 0;
+ while (i < rval.length){
+ CmisObject cmisObject = session.getObject(documentIdentifiers[i]);
+ if (!cmisObject.getBaseType().getDisplayName().equals(CMIS_FOLDER_BASE_TYPE)) {
+ Document document = (Document) cmisObject;
+ rval[i] = document.getVersionLabel();
+ } else {
+ //a CMIS folder will always be processed
+ rval[i] = StringUtils.EMPTY;
+ }
+ i++;
+ }
+ return rval;
+ }
}
\ No newline at end of file