Common 先期知識
Code 程式碼
Connectors 的 Scripts
- serialDocumentReference的設定:將檔案設定成 Multiple
- Document 請參考:
- Local variables:equipmentId
- Parameters:alfrescoHost, alfrescoUsername, alfrescoPassword, alfrescoFolderPath
- 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()
String contentStorageId = documentList.get(i).getContentStorageId()
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;
String password = alfrescoPassword;
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();
Folder root = (Folder) lSession.getObjectByPath(alfrescoFolderPath);
for(int i=0; i<fileNameList.size(); i++){
InputStream stream = new ByteArrayInputStream(fileContentList.get(i));
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);
}
}
沒有留言:
張貼留言