use of org.apache.manifoldcf.core.interfaces.ManifoldCFException in project manifoldcf by apache.
the class AlfrescoRepositoryConnector method processDocuments.
/**
* Process a set of documents.
* This is the method that should cause each document to be fetched, processed, and the results either added
* to the queue of documents for the current job, and/or entered into the incremental ingestion manager.
* The document specification allows this class to filter what is done based on the job.
* The connector will be connected before this method can be called.
*@param documentIdentifiers is the set of document identifiers to process.
*@param statuses are the currently-stored document versions for each document in the set of document identifiers
* passed in above.
*@param activities is the interface this method should use to queue up new document references
* and ingest documents.
*@param jobMode is an integer describing how the job is being run, whether continuous or once-only.
*@param usesDefaultAuthority will be true only if the authority in use for these documents is the default one.
*/
@Override
public void processDocuments(String[] documentIdentifiers, IExistingVersions statuses, Specification spec, IProcessActivity activities, int jobMode, boolean usesDefaultAuthority) throws ManifoldCFException, ServiceInterruption {
for (String documentIdentifier : documentIdentifiers) {
// Prepare to access the document
String nodeReference = documentIdentifier;
String uuid = NodeUtils.getUuidFromNodeReference(nodeReference);
if (Logging.connectors.isDebugEnabled())
Logging.connectors.debug("Alfresco: Processing document identifier '" + nodeReference + "'");
Reference reference = new Reference();
reference.setStore(SearchUtils.STORE);
reference.setUuid(uuid);
Predicate predicate = new Predicate();
predicate.setStore(SearchUtils.STORE);
predicate.setNodes(new Reference[] { reference });
Node resultNode = null;
try {
resultNode = NodeUtils.get(endpoint, username, password, socketTimeout, session, predicate);
} catch (IOException e) {
Logging.connectors.warn("Alfresco: IOException getting node: " + e.getMessage(), e);
handleIOException(e);
}
NamedValue[] properties = resultNode.getProperties();
boolean isDocument;
String versionString = "";
if (properties != null)
isDocument = ContentModelUtils.isDocument(properties);
else
isDocument = false;
if (isDocument) {
boolean isVersioned = NodeUtils.isVersioned(resultNode.getAspects());
if (isVersioned) {
versionString = NodeUtils.getVersionLabel(properties);
}
}
if (versionString.length() == 0 || activities.checkDocumentNeedsReindexing(documentIdentifier, versionString)) {
// Need to (re)index
String errorCode = "OK";
String errorDesc = StringUtils.EMPTY;
Long fileLengthLong = null;
long startTime = System.currentTimeMillis();
try {
try {
boolean isFolder = ContentModelUtils.isFolder(endpoint, username, password, socketTimeout, session, reference);
// a generic node in Alfresco could have child-associations
if (isFolder) {
// queue all the children of the folder
QueryResult queryResult = SearchUtils.getChildren(endpoint, username, password, socketTimeout, session, reference);
ResultSet resultSet = queryResult.getResultSet();
ResultSetRow[] resultSetRows = resultSet.getRows();
for (ResultSetRow resultSetRow : resultSetRows) {
NamedValue[] childProperties = resultSetRow.getColumns();
String childNodeReference = PropertiesUtils.getNodeReference(childProperties);
activities.addDocumentReference(childNodeReference, nodeReference, RELATIONSHIP_CHILD);
}
}
} catch (IOException e) {
errorCode = e.getClass().getSimpleName().toUpperCase(Locale.ROOT);
errorDesc = e.getMessage();
Logging.connectors.warn("Alfresco: IOException finding children: " + e.getMessage(), e);
handleIOException(e);
}
// a generic node in Alfresco could also have binaries content
if (isDocument) {
// this is a content to ingest
InputStream is = null;
long fileLength = 0;
try {
// properties ingestion
RepositoryDocument rd = new RepositoryDocument();
List<NamedValue> contentProperties = PropertiesUtils.getContentProperties(properties);
PropertiesUtils.ingestProperties(rd, properties, contentProperties);
// binaries ingestion - in Alfresco we could have more than one binary for each node (custom content models)
for (NamedValue contentProperty : contentProperties) {
// we are ingesting all the binaries defined as d:content property in the Alfresco content model
Content binary = ContentReader.read(endpoint, username, password, socketTimeout, session, predicate, contentProperty.getName());
fileLength = binary.getLength();
is = ContentReader.getBinary(endpoint, binary, username, password, socketTimeout, session);
rd.setBinary(is, fileLength);
// id is the node reference only if the node has an unique content stream
// For a node with a single d:content property: id = node reference
String id = PropertiesUtils.getNodeReference(properties);
// The QName of a property of type d:content will be appended to the node reference
if (contentProperties.size() > 1) {
id = id + INGESTION_SEPARATOR_FOR_MULTI_BINARY + contentProperty.getName();
}
// the document uri is related to the specific d:content property available in the node
// we want to ingest each content stream that are nested in a single node
String documentURI = binary.getUrl();
activities.ingestDocumentWithException(documentIdentifier, id, versionString, documentURI, rd);
fileLengthLong = new Long(fileLength);
}
AuthenticationUtils.endSession();
} catch (ParseException e) {
errorCode = "PARSEEXCEPTION";
errorDesc = e.getMessage();
Logging.connectors.warn("Alfresco: Error during the reading process of dates: " + e.getMessage(), e);
handleParseException(e);
} catch (IOException e) {
errorCode = e.getClass().getSimpleName().toUpperCase(Locale.ROOT);
errorDesc = e.getMessage();
Logging.connectors.warn("Alfresco: IOException: " + e.getMessage(), e);
handleIOException(e);
} finally {
session = null;
try {
if (is != null) {
is.close();
}
} catch (InterruptedIOException e) {
errorCode = null;
throw new ManifoldCFException(e.getMessage(), e, ManifoldCFException.INTERRUPTED);
} catch (IOException e) {
errorCode = e.getClass().getSimpleName().toUpperCase(Locale.ROOT);
errorDesc = e.getMessage();
Logging.connectors.warn("Alfresco: IOException closing file input stream: " + e.getMessage(), e);
handleIOException(e);
}
}
}
} catch (ManifoldCFException e) {
if (e.getErrorCode() == ManifoldCFException.INTERRUPTED)
errorCode = null;
throw e;
} finally {
if (errorCode != null)
activities.recordActivity(new Long(startTime), ACTIVITY_READ, fileLengthLong, nodeReference, errorCode, errorDesc, null);
}
}
}
}
use of org.apache.manifoldcf.core.interfaces.ManifoldCFException in project manifoldcf by apache.
the class AlfrescoRepositoryConnector method checkConnection.
protected void checkConnection() throws ManifoldCFException, ServiceInterruption {
while (true) {
try {
getSession();
String ticket = AuthenticationUtils.getTicket();
if (StringUtils.isEmpty(ticket)) {
Logging.connectors.error("Alfresco: Error during checking the connection.");
throw new ManifoldCFException("Alfresco: Error during checking the connection.");
}
AuthenticationUtils.endSession();
} catch (Exception e) {
Logging.connectors.error("Alfresco: Error during checking the connection.");
throw new ManifoldCFException("Alfresco: Error during checking the connection.");
}
session = null;
return;
}
}
use of org.apache.manifoldcf.core.interfaces.ManifoldCFException in project manifoldcf by apache.
the class AlfrescoRepositoryConnector method getSession.
/**
* Set up a session
*/
protected void getSession() throws ManifoldCFException, ServiceInterruption {
if (session == null) {
if (StringUtils.isEmpty(username))
throw new ManifoldCFException("Parameter " + AlfrescoConfig.USERNAME_PARAM + " required but not set");
if (Logging.connectors.isDebugEnabled())
Logging.connectors.debug("Alfresco: Username = '" + username + "'");
if (StringUtils.isEmpty(password))
throw new ManifoldCFException("Parameter " + AlfrescoConfig.PASSWORD_PARAM + " required but not set");
Logging.connectors.debug("Alfresco: Password exists");
if (StringUtils.isEmpty(protocol))
throw new ManifoldCFException("Parameter " + AlfrescoConfig.PROTOCOL_PARAM + " required but not set");
if (StringUtils.isEmpty(server))
throw new ManifoldCFException("Parameter " + AlfrescoConfig.SERVER_PARAM + " required but not set");
if (StringUtils.isEmpty(port))
throw new ManifoldCFException("Parameter " + AlfrescoConfig.PORT_PARAM + " required but not set");
if (StringUtils.isEmpty(path))
throw new ManifoldCFException("Parameter " + AlfrescoConfig.PATH_PARAM + " required but not set");
endpoint = protocol + "://" + server + ":" + port + path;
try {
WebServiceFactory.setEndpointAddress(endpoint);
WebServiceFactory.setTimeoutMilliseconds(socketTimeout);
AuthenticationUtils.startSession(username, password);
session = AuthenticationUtils.getAuthenticationDetails();
} catch (AuthenticationFault e) {
Logging.connectors.warn("Alfresco: Error during authentication. Username: " + username + ", endpoint: " + endpoint + ". " + e.getMessage(), e);
handleIOException(e);
} catch (WebServiceException e) {
Logging.connectors.warn("Alfresco: Error during trying to authenticate the user. Username: " + username + ", endpoint: " + endpoint + ". Please check the connector parameters. " + e.getMessage(), e);
throw new ManifoldCFException("Alfresco: Error during trying to authenticate the user. Username: " + username + ", endpoint: " + endpoint + ". Please check the connector parameters. " + e.getMessage(), e);
}
lastSessionFetch = System.currentTimeMillis();
}
}
use of org.apache.manifoldcf.core.interfaces.ManifoldCFException in project manifoldcf by apache.
the class CmisOutputConnectorUtils method getDocumentURL.
public static final String getDocumentURL(final Document document, final Session session) throws ManifoldCFException {
String link = null;
try {
Method loadLink = AbstractAtomPubService.class.getDeclaredMethod(LOAD_LINK_METHOD_NAME, new Class[] { String.class, String.class, String.class, String.class });
loadLink.setAccessible(true);
link = (String) loadLink.invoke(session.getBinding().getObjectService(), session.getRepositoryInfo().getId(), document.getId(), AtomPubParser.LINK_REL_CONTENT, null);
} catch (Exception e) {
Logging.connectors.error("CMIS: Error during getting the content stream url: " + e.getMessage(), e);
throw new ManifoldCFException(e.getMessage(), e);
}
return link;
}
use of org.apache.manifoldcf.core.interfaces.ManifoldCFException in project manifoldcf by apache.
the class CmisRepositoryConnector method poll.
/**
* This method is periodically called for all connectors that are connected but not
* in active use.
*/
@Override
public void poll() throws ManifoldCFException {
if (lastSessionFetch == -1L)
return;
long currentTime = System.currentTimeMillis();
if (currentTime >= lastSessionFetch + timeToRelease) {
DestroySessionThread t = new DestroySessionThread();
try {
t.start();
t.join();
Throwable thr = t.getException();
if (thr != null) {
if (thr instanceof RemoteException)
throw (RemoteException) thr;
else
throw (Error) thr;
}
session = null;
lastSessionFetch = -1L;
} catch (InterruptedException e) {
t.interrupt();
throw new ManifoldCFException("Interrupted: " + e.getMessage(), e, ManifoldCFException.INTERRUPTED);
} catch (RemoteException e) {
Throwable e2 = e.getCause();
if (e2 instanceof InterruptedException || e2 instanceof InterruptedIOException)
throw new ManifoldCFException(e2.getMessage(), e2, ManifoldCFException.INTERRUPTED);
session = null;
lastSessionFetch = -1L;
// Treat this as a transient problem
Logging.connectors.warn("CMIS: Transient remote exception closing session: " + e.getMessage(), e);
}
}
}
Aggregations