Friday, September 19, 2014

UCM: GET_SCHEMA_VIEW_VALUES

GET_SCHEMA_VIEW_VALUES service displays values in the specified view of std_services.htm file. Here in this example, the SecurityGroups present in UCM will be displayed on the ADF page, as a select one choice option.


This is the code for the UCMCoreServices class. Some of the methods of this class can be reused.

import oracle.stellent.ridc.IdcClient;
import oracle.stellent.ridc.IdcClientException;
import oracle.stellent.ridc.IdcClientManager;
import oracle.stellent.ridc.IdcContext;
import oracle.stellent.ridc.model.DataBinder;
import oracle.stellent.ridc.protocol.ServiceResponse;


public class UCMCoreServices {
    
    IdcContext userContext = null;
    IdcClientManager manager = null;
    IdcClient idcClient = null;
    ConfigurationsExtractor ucmConfig;
    String clientURL;
    
    public UCMCoreServices() throws UCMException {
        this.manager = new IdcClientManager();
        this.ucmConfig = new ConfigurationsExtractor();
        String username = this.ucmConfig.getString("UCM_USER");
        this.userContext = new IdcContext(username);

        try {
            establishUCMConnection();
        } catch (IdcClientException e) {
            throw new UCMException("Connection could not be established");
        }
    }
    private void establishUCMConnection() throws IdcClientException {
        String ucmServer = this.ucmConfig.getString("UCM_SERVER");
        String ucmPort = this.ucmConfig.getString("UCM_PORT");
        this.clientURL = ("idc://" + ucmServer + ":" + ucmPort);
        this.idcClient = this.manager.createClient(this.clientURL);
    }

    public ServiceResponse getSecurityGroups() throws UCMException {
        try {
            DataBinder binder = idcClient.createBinder();
            binder.putLocal("IdcService", "GET_SCHEMA_VIEW_VALUES");
            binder.putLocal("schViewName", "SecurityGroups");
            return idcClient.sendRequest(userContext, binder);
        } catch (IdcClientException e) {
            throw new UCMException(e.getMessage());
        }
    }

    public ServiceResponse getDocumentTypesService() throws UCMException {
        DataBinder binder = this.idcClient.createBinder();
        binder.putLocal("IdcService", "GET_DOCTYPES");

        try {
            return this.idcClient.sendRequest(this.userContext, binder);
        } catch (IdcClientException e) {
            throw new UCMException(e.getMessage());
        }
    }
}

This is the code for the fileUpload class.

import java.io.IOException;

import java.util.ArrayList;
import java.util.List;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.model.SelectItem;

import oracle.adf.share.ADFContext;
import oracle.adf.view.rich.component.rich.input.RichInputFile;

import oracle.stellent.ridc.IdcClientException;
import oracle.stellent.ridc.model.DataBinder;
import oracle.stellent.ridc.model.DataObject;
import oracle.stellent.ridc.model.DataResultSet;
import oracle.stellent.ridc.model.TransferFile;
import oracle.stellent.ridc.protocol.ServiceResponse;

import org.apache.myfaces.trinidad.model.UploadedFile;


public class fileUpload {

    private RichInputFile file;
    private String dDocTitle;
    private List itemsForDocTypes;
    private List itemsForSecurityGroups;
    private String dDocType;
    private String dGroupName;

    public fileUpload() {
        super();
    }

    public void onFileUpload(ActionEvent actionEvent) {
        try {
            UCMCoreServices ucmConnection = new UCMCoreServices();
            UploadedFile uploadedFile = (UploadedFile)file.getValue();

            DataBinder serviceBinder = ucmConnection.idcClient.createBinder();
            serviceBinder.putLocal("IdcService", "CHECKIN_NEW");
            serviceBinder.putLocal("dDocType", dDocType);
            serviceBinder.putLocal("dDocTitle", dDocTitle);
            serviceBinder.putLocal("dDocAuthor",
                                   ADFContext.getCurrent().getSecurityContext().getUserName());
            serviceBinder.putLocal("dSecurityGroup", dGroupName);
            try {
                serviceBinder.addFile("primaryFile",
                                      new TransferFile(uploadedFile.getInputStream(),
                                                       uploadedFile.getFilename(),
                                                       uploadedFile.getLength()));
            } catch (IOException e) {
                throw new UCMException("Primary File Error: " +
                                       e.getMessage());
            }

            ServiceResponse response =
                ucmConnection.idcClient.sendRequest(ucmConnection.userContext,
                                                    serviceBinder);
            DataBinder responseBinder = response.getResponseAsBinder();

            DataObject localData = responseBinder.getLocalData();
            System.out.println(localData.get("dID"));

            if (localData.get("StatusCode").equals("0")) {
                addFacesMessage(FacesMessage.SEVERITY_INFO,
                                localData.get("StatusMessage"));
            }
        } catch (IdcClientException e) {
            throw new UCMException(e.getMessage());
        } catch (NullPointerException e) {
            throw new UCMException(e.getMessage());
        }
    }

    public static void addFacesMessage(FacesMessage.Severity severity,
                                       String message) {
        FacesMessage fm = new FacesMessage(severity, message, null);
        FacesContext.getCurrentInstance().addMessage(null, fm);
    }

    public void onInit(ActionEvent actionEvent) throws UCMException {
        UCMCoreServices ucmConnection = new UCMCoreServices();
        DataResultSet resultSetForDocTypes;
        DataResultSet resultSetForSecurityGroups;
        itemsForDocTypes = new ArrayList();
        itemsForSecurityGroups = new ArrayList();
        try {
            resultSetForDocTypes =
                    ucmConnection.getDocumentTypesService().getResponseAsBinder().getResultSet("DocTypes");
            //System.out.println(resultSetForDocTypes.getRows().size());
            for (DataObject dataObject : resultSetForDocTypes.getRows()) {
                itemsForDocTypes.add(new SelectItem(dataObject.get("dDocType")));
            }
            
            resultSetForSecurityGroups =
                    ucmConnection.getSecurityGroups().getResponseAsBinder().getResultSet("SecurityGroups");
            for (DataObject dataObject : resultSetForSecurityGroups.getRows()) {
                itemsForSecurityGroups.add(new SelectItem(dataObject.get("dGroupName")));
            }

        } catch (IdcClientException e) {
            throw new UCMException(e.getMessage());
        }
    }
}

This is the code of the relevant components in the Main.jspx page.
                <af:selectOneChoice label="dDocType" id="soc1"
                                    value="#{CSBean.DDocType}"
                                    valuePassThru="true">
                  <f:selectItems id="si1" value="#{CSBean.itemsForDocTypes}"/>
                </af:selectOneChoice>
                <af:selectOneChoice label="dGroupName" id="soc2"
                                    value="#{CSBean.DGroupName}"
                                    valuePassThru="true">
                  <f:selectItems value="#{CSBean.itemsForSecurityGroups}" id="si2"/>
                </af:selectOneChoice>
                <af:inputText label="dDocTitle" id="it2"
                              value="#{CSBean.DDocTitle}"/>
                <af:inputFile label="File" id="if1" binding="#{CSBean.file}"/>
                <af:spacer width="10" height="10" id="s1"/>
                <af:commandButton text="Upload" id="cb1"
                                  actionListener="#{CSBean.onFileUpload}"
                                  action="back"/>


Set the valuePassThru="true" for both the selectOneChoice components. I spent the entire day in finding why the values, which were populated in the option lists, were passed as NULL.

Similarly, docTypes present in UCM are also been displayed on the ADF page, but by executing GET_DOCTYPES service.

Wednesday, September 10, 2014

Webcenter Capture: Exporting and Importing the Workspace Configuration

The exportWorkspace command allows you to output an entire workspace's configuration, including its definition, profiles, jobs, and scripts, to an XML file.
The importWorkspace command allows you to import an entire workspace, including its configuration (profiles, jobs, and scripts) and data (images, documents, and metadata) from an XML file created using the exportWorkspace WLST command.

To export a workspace to an XML file:
1. Invoke the wlst script wlst.cmd located in
E:\Oracle\Middleware\Oracle_ECM1\common\bin

2. Connect to the Oracle WebLogic Server managed server (default port 16400) on which the Oracle WebCenter Capture application is deployed
connect('weblogic', 'welcome1', 'localhost:16400')

3. Identify the workspace by its ID.
listWorkspaces()

4. Use the export command to act on the specified workspace, where "1" is the workspace ID identified in step 3.
exportWorkspace(1,'C:\workspaceExpense.xml')


To import a workspace from an XML file:
To import the workspace's configuration to a different environment:
importWorkspace('C:\workspaceExpense.xml')

For more WLST commands related to Capture, please check the link below:
http://docs.oracle.com/cd/E29542_01/doc.1111/e37898/advd_functions.htm#CJACHEJA