站長留言

  • ✅ 本站維護及更新歷史紀錄,詳情請參考公告
  • ✅ 有任何意見、想法,歡迎留言給Spicy知道喔
  • ✅ 固定於每周一至周五更新Blogger文章,周末不定期
程式AlfrescoBonita BPM

【Bonita BPM】Documents 複數檔案上傳到Alfresco

tags: Bonita BPM Alfresco

Common 先期知識

Code 程式碼

Connectors 的 Scripts

  1. serialDocumentReference的設定:將檔案設定成 Multiple
  2. Document 請參考:
  3. Local variables:equipmentId
  4. Parameters:alfrescoHost, alfrescoUsername, alfrescoPassword, alfrescoFolderPath
  5. documentNum:另外取得 “keepDocumentReference” 的 size()
List<String> fileNameList = new ArrayList<String>()
List<String> mimeTypeList = new ArrayList<String>()
List<Byte[]> fileContentList = new ArrayList<Byte[]>()
List<Long> equipmentIdList = new ArrayList<Long>()

List<Document> documentList = apiAccessor.getProcessAPI().getDocumentList(processInstanceId, "keepDocumentReference", 0, documentNum)

for(int i=0; i<documentNum; i++){
    String contentFilename = documentList.get(i).getContentFileName() //取得完整檔名(包含副檔名e.g. test.jpg)
    String contentStorageId = documentList.get(i).getContentStorageId()
    //equipmentId,請自行加入

    fileNameList.add(contentFilename.substring(contentFilename.lastIndexOf("."))) //取得副檔名
    mimeTypeList.add(documentList.get(i).getContentMimeType())
    fileContentList.add(apiAccessor.getProcessAPI().getDocumentContent(contentStorageId))
    equipmentIdList.add(equipmentId)
}

UploadToAlfresco.uploadFile(fileContentList,fileNameList,mimeTypeList,equipmentIdList,alfrescoHost,alfrescoUsername,alfrescoPassword,alfrescoFolderPath)

Groovy Scripts

  • 複數檔案上傳功能
static void uploadFile(List<Byte[]> fileContentList, List<String> fileNameList, List<String> fileMimeTypeList, List<Long> equipmentIdList, String alfrescoHost, String alfrescoUsername, String alfrescoPassword, String alfrescoFolderPath){
String alfrescoHostName = alfrescoHost;
String username = alfrescoUsername; //Alfresco使用者帳密
String password = alfrescoPassword;

//======== connection alfresco by openCMIS ========
Map<String, String> sessionParameters = new HashMap<String, String>();
sessionParameters.put(SessionParameter.USER, username);
sessionParameters.put(SessionParameter.PASSWORD, password);
sessionParameters.put(SessionParameter.ATOMPUB_URL, alfrescoHostName + "alfresco/api/-default-/public/cmis/versions/1.1/atom");
sessionParameters.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
SessionFactory sessionFactory = SessionFactoryImpl.newInstance();
Session lSession = sessionFactory.getRepositories(sessionParameters).get(0).createSession();

//使用者根目錄(My files)
Folder root = (Folder) lSession.getObjectByPath(alfrescoFolderPath);

for(int i=0; i<fileNameList.size(); i++){
    //== InputStream Get ==
    InputStream stream = new ByteArrayInputStream(fileContentList.get(i));

    //== properities ==
    String extension = fileNameList.get(i).substring(fileNameList.get(i).lastIndexOf("."))
    Map<String, Object> lProperties = new HashMap<String, Object>();
    StringBuilder nameSB = new StringBuilder();
    nameSB.append("equipment");
    nameSB.append(equipmentIdList.get(i));
    nameSB.append("_0");
    nameSB.append(extension)
    String name = nameSB.toString();
    String mimeType = fileMimeTypeList.get(i);
    lProperties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
    lProperties.put(PropertyIds.NAME, name);

    ContentStream contentStream = new ContentStreamImpl(name, new BigInteger("" + fileContentList.get(i).length), mimeType, stream);
    Document upFile =  root.createDocument(lProperties, contentStream, null);
}
	
    //下載code加入的位置
}

沒有留言:

張貼留言

本網站建議使用電腦或平板瀏覽