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.
Difference between revisions of "Stardust/Knowledge Base/Java API/Attaching Documents"
m (Added instructions and code) |
m |
||
Line 1: | Line 1: | ||
− | == Attaching documents to IPP Process without using Context Portal == | + | == '''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:<br>• User may like to attach the document while filling in the information from the same activity screen.<br>• One may need to attach reports, which they download from some http location. | + | There may be requirements where one needs to attach documents from the activity screen instead of launching Context portal:<br>• User may like to attach the document while filling in the information from the same activity screen.<br>• One may need to attach reports, which they download from some http location. |
− | ==== <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: ==== |
− | <br>1. Edit the xhtml file and add following entry<br><trh:rowLayout><br><tr:inputFile label="Attach Document :" value="#{SwitchDetailsDataEntryBean.file}" /><br></trh:rowLayout><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. | + | <br>'''1.''' Edit the xhtml file and add following entry<br><trh:rowLayout><br><tr:inputFile label="Attach Document :" value="#{SwitchDetailsDataEntryBean.file}" /><br></trh:rowLayout><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. |
− | <br>2. In your backing bean class add the following code:<br> | + | <br>'''2.''' In your backing bean class add the following code:<br> |
<pre>package com.sungard.iworks.web.jsf.beans.iworkscompass.switchrequest; | <pre>package com.sungard.iworks.web.jsf.beans.iworkscompass.switchrequest; | ||
import java.io.ByteArrayOutputStream; | import java.io.ByteArrayOutputStream; | ||
Line 42: | Line 42: | ||
public List complete(){ | public List complete(){ | ||
System.out.println("Complete method Started"); | System.out.println("Complete method Started"); | ||
− | if(file != null){ | + | if(file != null){ |
try{ | try{ | ||
SessionContext sessionContext = SessionContext.findSessionContext(); | SessionContext sessionContext = SessionContext.findSessionContext(); | ||
Line 51: | Line 51: | ||
// documentInfo.setProperties((Map) | // documentInfo.setProperties((Map) | ||
// this.documentPropertiesWrapper.getComplexType()); | // this.documentPropertiesWrapper.getComplexType()); | ||
− | System.out.println("File Type : " + file.getContentType()); | + | System.out.println("File Type : " + file.getContentType()); |
documentInfo.setContentType(file.getContentType()); | documentInfo.setContentType(file.getContentType()); | ||
ByteArrayOutputStream out = new ByteArrayOutputStream(); | ByteArrayOutputStream out = new ByteArrayOutputStream(); | ||
Line 57: | Line 57: | ||
InputStream in = this.getFile().getInputStream(); | InputStream in = this.getFile().getInputStream(); | ||
int b; | int b; | ||
− | while ((b = in.read()) != -1){ | + | while ((b = in.read()) != -1){ |
out.write(b); | out.write(b); | ||
} | } | ||
Line 83: | Line 83: | ||
</pre> | </pre> | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | '''3.''' Add ‘Process Attachments’ as an OUT Data to that particular activity in the model. |
Revision as of 03:35, 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.