Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Stardust/Knowledge Base/Java API/Attaching Documents"

m
m
Line 7: Line 7:
 
==== <br>Attaching a document from an interactive application activity, e.g. JSF activity:  ====
 
==== <br>Attaching a document from an interactive application activity, e.g. JSF activity:  ====
  
'''1.''' Edit the xhtml file and add following entry<br>&lt;trh:rowLayout&gt;<br>&lt;tr:inputFile label="Attach Document&nbsp;:" value="#{SwitchDetailsDataEntryBean.file}" /&gt;<br>&lt;/trh:rowLayout&gt;<br>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.  
+
'''1.''' Edit the xhtml file and add following entry
 +
<pre>
 +
&lt;trh:rowLayout&gt;
 +
&lt;tr:inputFile label="Attach Document&nbsp;:" value="#{SwitchDetailsDataEntryBean.file}" /&gt;
 +
&lt;/trh:rowLayout&gt;</pre>
 +
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.  
  
 
<br>'''2.''' In your backing bean class add the following code:<br>
 
<br>'''2.''' In your backing bean class add the following code:<br>
Line 85: Line 90:
 
<br>
 
<br>
  
'''3.''' Add ‘Process Attachments’ as an OUT Data to that particular activity in the model.  
+
'''3.''' Add ‘Process Attachments’ as an OUT Data to that particular activity in the model.
 
+
 
+
  
 
==== Attaching a document available at some http location:  ====
 
==== Attaching a document available at some http location:  ====

Revision as of 03:46, 6 December 2011

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.

Attaching a document available at some http location:

1. Have an Application activity in your model, whose service method should look like as below:

package com.sungard.iworks.web.jsf.beans.iworkscompass.switchrequest; 
import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List; 
import ag.carnot.web.jsf.common.beans.SessionContext;
import ag.carnot.workflow.runtime.DmsUtils;
import ag.carnot.workflow.runtime.Document;
import ag.carnot.workflow.runtime.DocumentInfo;
import ag.carnot.workflow.runtime.DocumentManagementService;
public class AttachReportToProcess{ 

public List attachReport(String repFileName, List documents) { InputStream is = null; ByteArrayOutputStream out = new ByteArrayOutputStream(); try{ SessionContext sessionContext = SessionContext.findSessionContext(); DocumentManagementService documentManagementService = sessionContext.getServiceFactory(). getDocumentManagementService(); DocumentInfo documentInfo = DmsUtils.createDocumentInfo(repFileName); System.out.println("Downloaded Started."); String fileURL ="http://iwks-nat-frmsvr:7778/reportspdf/" + repFileName; URL fileUrl = new URL(fileURL); documentInfo.setContentType("application/pdf"); //os = new BufferedOutputStream(new FileOutputStream("c:\\src\\A00004056238.pdf"));

// openConnection method on a URL. URLConnection URLConn = fileUrl.openConnection(); is = URLConn.getInputStream(); //InputStream in = this.getFile().getInputStream(); int b; while ((b = is.read()) != -1){ out.write(b); } out.close(); is.close(); byte[] documentContent = out.toByteArray(); System.out.println("File length: " + documentContent.length); Document scannedSwitchDocument = documentManagementService.createDocument("/", documentInfo, documentContent, null); List attachments = new ArrayList(); List paths = new ArrayList (); paths.add("/"); System.out.println("documents : "+documents); //ArrayList existingAttachments = new ArrayList (documentManagementService.getDocuments(paths)); attachments.addAll(documents); attachments.add(scannedSwitchDocument); return attachments;

} catch (Exception e) { e.printStackTrace(); } return null; }

}

2. Make sure to have the existing attachments passed in as an IN parameter to this method and also use that to add all existing attachments to the process attachment that you are going to return from this service method. Otherwise this code will attach the current doc (the report only) and deletes all existing attachments.

3. Have PROCESS_ATTACHMENTS passed as IN and OUT data to this application activity in the model.

Back to the top