}
}
if (existingPi != null && hasText(rule.getRepositoryAtomUrl())) {
logger.fine("Uploading CMIS documents, process ID: " + existingPi.getInternalId());
CmisAtomSessionFacade sessionFacade = new CmisAtomSessionFacade(rule.getRepositoryUser(),
rule.getRepositoryPassword(),
rule.getRepositoryAtomUrl(),
rule.getRepositoryId());
String folderId = null;
for (ProcessInstanceAttribute at : existingPi.getProcessAttributes()) {
if (at instanceof ProcessInstanceSimpleAttribute) {
ProcessInstanceSimpleAttribute pisa = (ProcessInstanceSimpleAttribute) at;
if (pisa.getKey().equals(rule.getFolderAttributeName())) {
folderId = pisa.getValue();
break;
}
}
}
org.apache.chemistry.opencmis.client.api.Folder mainFolder;
if (folderId == null) {
mainFolder = sessionFacade.createFolderIfNecessary(nvl(rule.getNewFolderPrefix(), "") +
existingPi.getInternalId(), rule.getRootFolderPath());
if (StringUtil.hasText(rule.getSubFolder()))
mainFolder = sessionFacade.createFolderIfNecessary(rule.getSubFolder(), mainFolder.getPath());
folderId = mainFolder.getId();
ProcessInstanceSimpleAttribute attr;
attr = new ProcessInstanceSimpleAttribute();
attr.setKey("emailSender");
attr.setValue(sender);
existingPi.addAttribute(attr);
attr = new ProcessInstanceSimpleAttribute();
attr.setKey("emailSubject");
attr.setValue(subject);
existingPi.addAttribute(attr);
attr = new ProcessInstanceSimpleAttribute();
attr.setKey(nvl(rule.getFolderAttributeName(), "emailFolderId"));
attr.setValue(folderId);
existingPi.addAttribute(attr);
context.getProcessInstanceDAO().saveProcessInstance(existingPi);
} else {
mainFolder = sessionFacade.getFolderById(folderId);
}
if (msg.getContent() instanceof Multipart) {
Multipart multipart = (Multipart) msg.getContent();
for (int i = 0; i < multipart.getCount(); ++i) {
BodyPart part = multipart.getBodyPart(i);
if (rule.isOmitTextAttachments() &&
(part.getContentType() == null || part.getContentType().startsWith("text/"))) {
logger.info("Skipping multipart attachment #" + i);
continue;
}
sessionFacade.uploadDocument(hasText(part.getFileName()) ? part.getFileName() : "part_" + i,
mainFolder,
toByteArray(part.getInputStream()),
part.getContentType(), null);
}
} else {
if (!rule.isOmitTextAttachments())
sessionFacade.uploadDocument("message",
mainFolder,
toByteArray(msg.getInputStream()),
msg.getContentType(), null);
}