Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Stardust/Knowledge Base/Java API/Attaching Documents

Attaching documents to IPP Process without using Context Portal

 

 There may be requirements where one needs to attach documents from the activity screen instead of launching Context portal:
• User may like to attach the document while filling in the information from the same activity screen.
• One may need to attach reports, which they download from some http location.


Attaching a document from an interactive application activity, e.g. JSF activity:


1. Edit the xhtml file and add following entry
<trh:rowLayout>
<tr:inputFile label="Attach Document :" value="#{SwitchDetailsDataEntryBean.file}" />
</trh:rowLayout>
This entry in xhtml will create a control with “Attach Document” as label, an edit control next to this that will display the path of the browsed file and a ‘Browse’ button, that opens up Open Windows Dialog box.


2. In your backing bean class add the following code:

package com.sungard.iworks.web.jsf.beans.iworkscompass.switchrequest;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.myfaces.trinidad.context.RequestContext;
import org.apache.myfaces.trinidad.model.UploadedFile;
import ag.carnot.web.jsf.common.ManagedBeanUtils;
import ag.carnot.web.jsf.common.beans.SessionContext;
import ag.carnot.web.jsf.common.structureddata.ComplexTypeWrapper;
import ag.carnot.web.jsf.processportal.beans.ActivityInstanceDialogBean;
import ag.carnot.workflow.runtime.DmsUtils;
import ag.carnot.workflow.runtime.Document;
import ag.carnot.workflow.runtime.DocumentInfo;
import ag.carnot.workflow.runtime.DocumentManagementService;
import ag.carnot.workflow.runtime.Folder;
import ag.carnot.workflow.runtime.ProcessInstance;
public class SwitchDetailsDataEntryBean {

private UploadedFile file; public UploadedFile getFile() { return file; } public void setFile(UploadedFile file) { this.file = file; } public SwitchDetailsDataEntryBean(){ super(); RequestContext requestContext = RequestContext.getCurrentInstance(); requestContext.getPageFlowScope().put("carnotActivityUsesUpload", new Boolean(true)); } public List complete(){ System.out.println("Complete method Started"); if(file != null){ try{ SessionContext sessionContext = SessionContext.findSessionContext(); DocumentManagementService documentManagementService = sessionContext.getServiceFactory(). getDocumentManagementService(); String fileName = this.getFile().getFilename(); DocumentInfo documentInfo = DmsUtils.createDocumentInfo(fileName); // documentInfo.setProperties((Map) // this.documentPropertiesWrapper.getComplexType()); System.out.println("File Type : " + file.getContentType()); documentInfo.setContentType(file.getContentType()); ByteArrayOutputStream out = new ByteArrayOutputStream(); try { InputStream in = this.getFile().getInputStream(); int b; while ((b = in.read()) != -1){ out.write(b); } out.close(); in.close(); } catch (Exception e) { e.printStackTrace(); } byte[] documentContent = out.toByteArray(); System.out.println("File length: " + documentContent.length); Document scannedSwitchDocument = documentManagementService.createDocument("/", documentInfo, documentContent, null); attachments.add(scannedSwitchDocument); System.out.println("Document created."); return attachments; } catch(Exception e){ System.out.println("in catch"); e.printStackTrace();} } return null; } }



3. Add ‘Process Attachments’ as an OUT Data to that particular activity in the model.

Back to the top