Initiating a review with supporting documents using the Java API

You can use the Review, Commenting, and Approval building block Java APIs to initiate a review. You can also add supporting documents at the time you initiate the review.
package customsolution; 
 
import java.io.File; 
import java.io.IOException; 
import java.io.StringWriter; 
import java.util.ArrayList; 
import java.util.List; 
import java.util.Properties; 
 
import javax.xml.parsers.DocumentBuilder; 
import javax.xml.parsers.DocumentBuilderFactory; 
import javax.xml.parsers.ParserConfigurationException; 
import javax.xml.transform.TransformerConfigurationException; 
import javax.xml.transform.TransformerException; 
import javax.xml.transform.TransformerFactory; 
import javax.xml.transform.TransformerFactoryConfigurationError; 
import javax.xml.transform.dom.DOMSource; 
import javax.xml.transform.stream.StreamResult; 
 
import org.w3c.dom.Element; 
import org.xml.sax.SAXException; 
 
import com.adobe.idp.Document; 
import com.adobe.idp.dsc.clientsdk.ServiceClientFactory; 
import com.adobe.idp.dsc.clientsdk.ServiceClientFactoryProperties; 
import com.adobe.livecycle.rca.client.ReviewCommentingAndApprovalServiceClient; 
import com.adobe.livecycle.rca.common.beans.RCADocument; 
import com.adobe.livecycle.rca.common.exception.RCAException; 
 
public class InitiateReviewWithSuppDoc { 
     
    public String initiateReview() throws RCAException { 
        ServiceClientFactory serviceClientFactory = getServiceClientFactory(); 
        ReviewCommentingAndApprovalServiceClient rcaClient = new ReviewCommentingAndApprovalServiceClient(serviceClientFactory); 
         
         
        //Step 1 Get review template (Assumption "CustomSolutionTemplate" already exists) 
        String templateName = "CustomSolutionTemplate"; 
        Document reviewTemplate = rcaClient.getReviewTemplate(templateName); 
         
        //Step 2 Parse the template to add initiator to it, review title 
        Document reviewContext = null; 
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 
        try { 
            DocumentBuilder db = dbf.newDocumentBuilder(); 
            org.w3c.dom.Document reviewTemplateW3CDoc = db.parse(reviewTemplate.getInputStream()); 
            reviewTemplateW3CDoc.getDocumentElement().normalize(); 
            Element initiatorNode = (Element) reviewTemplateW3CDoc.getElementsByTagName("initiator").item(0); 
            initiatorNode.setAttribute("domain", "DefaultDom"); 
            initiatorNode.setAttribute("canonical_name", "apink"); 
             
            Element titleNode = (Element) reviewTemplateW3CDoc.getElementsByTagName("title").item(0); 
            titleNode.setTextContent("Sample Initiate Review"); 
 
            DOMSource source = new DOMSource(reviewTemplateW3CDoc); 
            StringWriter xmlAsWriter = new StringWriter(); 
            StreamResult result = new StreamResult(xmlAsWriter); 
            TransformerFactory.newInstance().newTransformer().transform(source, result); 
            reviewContext = new Document(xmlAsWriter.toString().getBytes()); 
             
        } catch (ParserConfigurationException e) { 
            e.printStackTrace(); 
        } catch (SAXException e) { 
            e.printStackTrace(); 
        } catch (IOException e) { 
            e.printStackTrace(); 
        } catch (TransformerConfigurationException e) { 
            e.printStackTrace(); 
        } catch (TransformerException e) { 
            e.printStackTrace(); 
        } catch (TransformerFactoryConfigurationError e) { 
            e.printStackTrace(); 
        } 
         
        //Step 3 Initiate Review. 
        Document reviewDocument = new Document(new File("/home/Documents/RCATest.pdf"), false); 
         
        //Create supporting doc list 
        List<RCADocument> supportingDocList = new ArrayList<RCADocument>(); 
         
        //REF Type 
        RCADocument supportingDocument1 = new RCADocument(); 
        supportingDocument1.setType(RCADocument.Type.REF); 
        supportingDocument1.setUri("www.adobe.com"); 
        supportingDocument1.setDescription("Sample reference type supporting document"); 
        supportingDocList.add(supportingDocument1); 
         
        RCADocument supportingDocument2 = new RCADocument(); 
        supportingDocument2.setType(RCADocument.Type.DOCUMENT); 
        supportingDocument2.setName("Supporting Doc Sample"); 
        supportingDocument2.setDocument(new Document(new File("/home/Documents/Page1.pdf"), false)); 
        supportingDocument1.setDescription("Sample document type supporting document"); 
        supportingDocList.add(supportingDocument2); 
         
        String reviewId = rcaClient.initiateReview(reviewContext, reviewDocument, supportingDocList); 
         
         
        return reviewId; 
    } 
     
    private ServiceClientFactory getServiceClientFactory(){ 
        Properties connectionProps = new Properties(); 
        connectionProps.setProperty(ServiceClientFactoryProperties.DSC_DEFAULT_SOAP_ENDPOINT, "http://localhost:8080"); 
        connectionProps.setProperty(ServiceClientFactoryProperties.DSC_TRANSPORT_PROTOCOL,ServiceClientFactoryProperties.DSC_SOAP_PROTOCOL);          
        connectionProps.setProperty(ServiceClientFactoryProperties.DSC_SERVER_TYPE, ServiceClientFactoryProperties.DSC_JBOSS_SERVER_TYPE); 
        connectionProps.setProperty(ServiceClientFactoryProperties.DSC_CREDENTIAL_USERNAME, "administrator"); 
        connectionProps.setProperty(ServiceClientFactoryProperties.DSC_CREDENTIAL_PASSWORD, "password"); 
 
        ServiceClientFactory serviceClientFactory =         ServiceClientFactory.createInstance(connectionProps); 
 
return serviceClientFactory; 
    } 
     
    public static void main(String args[]) { 
        try { 
            String reviewId = new InitiateReviewWithSuppDoc().initiateReview(); 
            System.out.println(reviewId); 
        } catch (RCAException e) { 
            // TODO Auto-generated catch block 
            e.printStackTrace(); 
        } 
    } 
 
}

// Ethnio survey code removed