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

Wednesday, August 6, 2014

UCM: Delete a folder and all the contents inside it using RIDC

To delete a folder and all the contents inside it, using COLLECTION_DELETE_LOT service.
DataBinder serviceBinder = idcClient.createBinder();
serviceBinder.putLocal("IdcService", "COLLECTION_DELETE_LOT");
serviceBinder.putLocal("collectionselect0", "true");
serviceBinder.putLocal("fromCollectionisLink0", "0");
serviceBinder.putLocal("fromhasCollectionID0", "1");
serviceBinder.putLocal("fromdCollectionID0", "814720879757000011");//folder to delete
ServiceResponse response = idcClient.sendRequest(userContext, serviceBinder);
DataBinder responseBinder = response.getResponseAsBinder();

To delete a particular content:
DataBinder serviceBinder = idcClient.createBinder();
serviceBinder.putLocal("IdcService", "COLLECTION_DELETE_LOT");
serviceBinder.putLocal("contentselect0", "true");
serviceBinder.putLocal("fromContentisLink0", "0");
serviceBinder.putLocal("fromdDocName0", "UCM_SERVER21-012455");//dDocName to delete
ServiceResponse response = idcClient.sendRequest(userContext, serviceBinder);
DataBinder responseBinder = response.getResponseAsBinder();

Friday, July 18, 2014

GUAVA: Copy or move a file

Normally this is the code in order to copy a file in Java:
import java.io.*;

public class CopyFileExample {
    public static void main(String[] args) {

        File original = new File("src/main/resources/sampleTextFileOne.txt");
        File copy = new File("src/main/resources/copy.txt");
        byte[] buffer = new byte[1024];
        FileInputStream is = null;
        FileOutputStream os = null;
        int numberRead;
        try {
            is = new FileInputStream(original);
            os = new FileOutputStream(copy, false);
            while((numberRead = is.read(buffer))!= -1){
                os.write(buffer,0,numberRead);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try{
                is.close();
                os.close();
            }catch (IOException e){
                e.printStackTrace();
            }
        }
    }
}

Using Guava API, it's so simple:
import com.google.common.io.Files;

import java.io.File;
import java.io.IOException;

public class CopyFileExample {

    public static void main(String[] args) {
        File original = new File("src/main/resources/sampleTextFileOne.txt");
        File copy = new File("src/main/resources/copy.txt");

        try {
            Files.copy(original, copy);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Similarly to move a file using Files.move method.
import com.google.common.io.Files;

import java.io.File;
import java.io.IOException;

public class CopyFileExample {

    public static void main(String[] args) {
        File original = new File("src/main/resources/sampleTextFileOne.txt");
        File newFile = new File("src/main/resources/copy.txt");

        try {
            Files.move(original, newFile);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Monday, February 10, 2014

UCM: Unable to initialize the system provider "SystemDatabase". Cannot find parameter "JdbcConnectionString"


CAUSE: The applets are not running in the WLS container and can not use the connection to the DB.

SOLUTION:
1. Open SystemProperties: Intradocdir\bin\SystemProperties.exe

2. Go to the "Database" tab.

3. Select Oracle Thin JDBC Driver. Enter the details as below and click OK:


4. Thats it. Make sure that you know the password of the sysadmin user. If not, you can change it in User Admin applet.

Monday, January 20, 2014

Java program to find IP Address of localhost


import java.net.UnknownHostException;

/**
 * Simple Java program to find IP Address of localhost. This program uses
 * InetAddress from java.net package to find IP address. 
 *
 * @author Javin Paul
 */
public class IPTest {
  
    public static void main(String args[]) throws UnknownHostException {
        InetAddress addr = InetAddress.getLocalHost();
        String ipAddress = addr.getHostAddress();
        System.out.println("IP address of localhost: " + ipAddress);
        String hostname = addr.getHostName();
        System.out.println("Name of hostname : " + hostname);
    }
}

Output:
IP address of localhost from Java Program: 190.12.209.123
Name of hostname : PCLOND3433

Source: http://javarevisited.blogspot.in/2012/09/java-program-to-find-ip-address-of.html

Tuesday, January 7, 2014

Webcenter Sites: Asset, Asset Type, Asset definition

An asset represents a piece of content, such as an article or an image, that is managed in WebCenter Sites. It consists of a set of properties that helps distinguish it from other assets of the same type.

An asset type is a schema for distinguishing content types from one another. It is made up of a set of attributes, which can also be described as a set of fields on an asset creation form.

An asset type is a set of attribute names, while an asset is a set of attribute values.
An asset is an instance of an asset type.

When you create a new asset type for your CM site, a table in the database is also created, named for the asset type, that will store its instances (the assets). The columns in the database table correspond to the attribute names, while the rows correspond to its asset instances.

Asset definition controls the asset creation form. In particular, one can determine what attribute fields appear on the form and what order they appear in, as well as which attribute fields are mandatory versus optional.


Core asset types ship with WebCenter Sites by default. These are asset types that are typically used to support the structure of your CM site and website. Core asset types can be categorized as follows:
1. Container Assets: They "contain" lists of assets. Collection, Recommendation
2. Developer Assets: Query, Template, CSElement, Site Entry, Attribute Editor

Core "content" asset types does not ship with WebCenter Sites, such as articles, images, and media types.

All assets can be divided into two loosely defined categories: 
1. Content assets are items that visitors read and examine on your site. 
2. Design assets are items that organize and format the content assets. 

The assets available to a site depend on the content applications and sample sites that are installed. As a general rule, the applications deliver design assets, and the sample sites deliver content assets.

WebCenter Sites: Product Architecture


WebCenter Sites The base application for web experience and content management
WebCenter Sites: Community Management of user-generated content, such as comments, ratings, and polling
WebCenter Sites: Gadgets Management of gadgets for use on websites such as iGoogle
WebCenter Sites: Engage Management of segments and strategic marketing tools
Content Connectors For integration with other source repository systems, such as WebCenter Content, Documentum, Sharepoint, or file systems
WebCenter Sites: Analytics Reporting of website content usage
Remote Satellite Server Edge caching application for larger-scale deployments