Package pl.net.bluesoft.rnd.pt.utils.cmis

Examples of pl.net.bluesoft.rnd.pt.utils.cmis.CmisAtomSessionFacade


                }

            }
            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);
                }
View Full Code Here


                    }
                }

            }
            if (existingPi != null && hasText(rule.getRepositoryAtomUrl())) {
                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();
                } else {
                    mainFolder = sessionFacade.getFolderById(folderId);
                }
                for (int i = 0; i < dir.list().length; ++i) {
                    String fileName = dir.list()[i];
                    if (!fileName.equals(".finish")) {
                        File file = new File(dir.getAbsolutePath() + "/" + fileName);
                        String mimeType = new MimetypesFileTypeMap().getContentType(file);
                        InputStream is = new FileInputStream(file);
                        try {
              long length = file.length();
              if (length > Integer.MAX_VALUE) {
                throw new IOException("Could not completely read file " + file.getName());
              }
              byte[] bytes = new byte[(int) length];
              int offset = 0;
              int numRead = 0;
              while (offset < bytes.length
                  && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) {
                offset += numRead;
              }
              if (offset < bytes.length) {
                throw new IOException("Could not completely read file " + file.getName());
              }
              sessionFacade.uploadDocument(file.getName(), mainFolder, bytes, mimeType, null);
            }
            finally {
                          is.close();
              file.delete();
            }
View Full Code Here

    // setSimpleAttribute(folderAttributeName, folderId, processInstance);
  }

  @Override
  public void loadData(BpmTask task) {
    sessionFacade = new CmisAtomSessionFacade(repositoryUser, repositoryPassword, repositoryAtomUrl, repositoryId);
    mainFolder = sessionFacade.createFolderIfNecessary(newFolderPrefix + task.getProcessInstance().getInternalId(),
        rootFolderPath);
    if (StringUtil.hasText(subFolder))
      mainFolder = sessionFacade.createFolderIfNecessary(subFolder, mainFolder.getPath());
    folderId = mainFolder.getId();
View Full Code Here

    ClassLoader previousLoader = t.getContextClassLoader();
    try {
      ClassLoader newClassLoader = ProcessToolContext.Util.getThreadProcessToolContext()
          .getRegistry().getModelAwareClassLoader(getClass().getClassLoader());
      t.setContextClassLoader(newClassLoader);
      sessionFacade = new CmisAtomSessionFacade(repositoryUser, repositoryPassword, repositoryAtomUrl,
                                                repositoryId);
      mainFolder = sessionFacade.createFolderIfNecessary(newFolderPrefix + processInstance.getInternalId(),
                                                         rootFolderPath);
      if (StringUtil.hasText(subFolder))
        mainFolder = sessionFacade.createFolderIfNecessary(subFolder, mainFolder.getPath());
View Full Code Here

TOP

Related Classes of pl.net.bluesoft.rnd.pt.utils.cmis.CmisAtomSessionFacade

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.