tags: Bonita BPM
COMMON 基本需求
- 使用方法:OpenCMIS
- CMIS:Content Management Interoperability Services, Java 類庫、框架和工具
- 下載需要的Jar檔
- 先到官方網站:http://chemistry.apache.org/java/download.html
- 選擇CMIS FOR JAVA >> Downloads
- 下載:OpenCMIS Client with dependencies
- include自己需要的Jar檔
- 程式碼分為2部分
-
Groovy Scripts
-
Connectors 的 Scripts
-
程式碼
Connectors 的 Scripts
- serialDocumentReference的設定
- Document 請參考:
- Local variables:equipmentId
- Parameters:alfrescoHost, alfrescoUsername, alfrescoPassword, alfrescoFolderPath
Document document = apiAccessor.getProcessAPI().getDocumentAtProcessInstantiation(processInstanceId, "serialDocumentReference")
String contentFilename = document.getContentFileName() //取得完整檔名(包含副檔名e.g. test.jpg)
String filename = contentFilename.substring(contentFilename.lastIndexOf(".")) //取得副檔名
String contentStorageId = document.getContentStorageId()
byte[] file = apiAccessor.getProcessAPI().getDocumentContent(contentStorageId)
UploadToAlfresco.uploadFile(file,equipmentId,filename,alfrescoHost,alfrescoUsername,alfrescoPassword,alfrescoFolderPath)
Groovy Scripts
1. OpenCMIS提供可以使用Path的方法取得指定的檔案
Path | 根目錄 |
---|---|
/ | alfresco根目錄 |
/Shared | 分享資料夾的根目錄 |
/User Homes/使用者名稱 | 各別使用者的根目錄 |
/Sites/網站名稱/documentLibrary | 各別網站儲存庫根目錄 |
2. 上傳功能
- mimeType 參考:MIME types
static void uploadFile(byte[] file, String equipmentId, String filename, 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);
//== InputStream Get ==
InputStream stream = new ByteArrayInputStream(file);
//== properities ==
Map<String, Object> lProperties = new HashMap<String, Object>();
StringBuilder nameSB = new StringBuilder(); //拼出完整檔名
nameSB.append("test");
nameSB.append(equipmentId); //用id創造唯一檔名
nameSB.append(".");
nameSB.append(filename) //副檔名
String name = nameSB.toString();
String mimeType = "image/png, image/jpeg";
lProperties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
lProperties.put(PropertyIds.NAME, name);
ContentStream contentStream = new ContentStreamImpl(name, new BigInteger("" + file.length), mimeType, stream);
Document upFile = root.createDocument(lProperties, contentStream, null);
//下載code加入的位置
}
3. 取得URL:直接加在上傳的code
- 回傳值型態:void要改成String
- 要寫return
//回傳URL,void要改成String
StringBuilder sb = new StringBuilder()
sb.append(alfrescoHost)
sb.append("share/page/document-details?nodeRef=workspace://SpacesStore/")
sb.append(upFile.getId())
return sb.toString()
沒有留言:
張貼留言