private Document[] getAttachments(String path) throws Exception { Document[] listDoc = null; String servicePattern = DocumentService.SERVICE_NAME; String typePattern = Document.RESOURCE_NAME; String[] docsArray = browser.listChildrenOfType(path, servicePattern, typePattern); if (docsArray != null && docsArray.length > 0) { Vector<Document> docVector = new Vector<Document>(); for (int i = 0; i < docsArray.length; i++) { logIt("child #" + i + ". " + docsArray[i]); Document doc = documentService.readDocumentProperties(docsArray[i]); if (doc != null) { docVector.add(doc); } } listDoc = docVector.toArray(new Document[docVector.size()]); } return listDoc; }
@Override public void attachDocumentToForum(String path, String documentPath) throws ForumServiceException { logIt("attach document " + documentPath + " at " + path); try { // Get forum Forum forum = readForum(path); if (forum != null) { // Get the document Document doc = documentService.readDocument(documentPath); if (doc != null) { List<String> documents = new ArrayList<String>(); documents.add(doc.getId()); // Update the forum HashMap<String, String> values = forumWS.attachDocumentsToForum(forum.getId(), documents); if (values != null && !values.isEmpty()) { String code = (String) values.get("statusCode"); String msgTxt = (String) values.get("statusMessage"); logIt("Message Code:" + code + " Message: " + msgTxt); if (!code.equals(CollaborationUtils.SUCCESS_CODE)) { throw new ForumServiceException( "Error code recieved from the WS." + " Code" + code + " Message:" + msgTxt); } logIt( "Attached succesfully document " + doc.getName() + " to forum " + forum.getName()); } else { throw new ForumServiceException("No valid answer from the WS.Check logs."); } } else { throw new ForumServiceException("Cannot read document from given path " + documentPath); } } else { throw new ForumServiceException("Cannot read forum from given path " + path); } } catch (Exception e) { // ctx.setRollbackOnly(); logger.error("Unable to attach document for the forum " + path, e); throw new ForumServiceException("Unable to attach document for the forum " + path, e); } }