Wednesday, November 23, 2011

IBM WCM 6 to 7 Migration - Commands - Unix


Hi Y'all

Please find attached the commands I used during migration form version 6.0.1.X  to 7.0.0.1


  • ./ConfigEngine.sh validate-database-connection -DTransferDomainList=jcr -DWasPassword=XXXXXX -DPortalAdminPwd=XXXXXX
  • ./ConfigEngine.sh connect-database-jcr-migration
  • ./ConfigEngine.sh create-wcm-persistence-tables
    • This is not part of the IBM listed steps...you will thank me later :-)
  • ./ConfigEngine.sh upgrade-jcr-datastore-601x-to-6100-jcr
  • ./ConfigEngine.sh configure-wcm-migration
  • ./ConfigEngine.sh configure-wcm-remote-admin
  • ./ConfigEngine.sh action-create-schema-applyMIG7000-wp.migration.jcr.db -DPreviousPortalVersion=XXX -DCurrentPortalVersion=7.0.0.x -DWasPassword=Password -DPortalAdminPwd=Password
    • Please add your Portal versions where the xx's are.
  • ./ConfigEngine.sh wcm-post-migration-data-update -DPortalAdminPwd=Password-DWasPassword=Password-DPreviousPortalVersion=6.1.0.x -DtransferDomainList=jcr
    • This step fails - Build Failed
The attached error can be found in your migration log.

Error: 
MigrationSQLExecutor: ERROR ->DB2 SQL error: SQLCODE: -204, SQLSTATE: 42704, 
SQLERRMC: JCR.ICMSTJCRNODELOCKSX

Migration Log :

/WebSphere/WP_PROFILE/ConfigEngine/log/Migration.log

The Fix:

You can resolve the issue by binding the JCRDB, executing the following commands from a DB2 command line window:
==db2 terminate 
==db2 connect to jcrDB (this is the newly copied database from 6.0.x to 7.0)
==db2 bind PATH\db2schema.bnd blocking all grant public sqlerror continue db2 terminate 

Substitute "PATH" with the install path for your DB2, and make sure you find the db2schema.bnd in the path before running the command.

Also, verify that all the Datasource passwords are correct before running the next task. You can verify this in the security.xml at cell scope:
\config\cells\\security.xml:

Find this entry for the JCR datasource and make sure the encrypted password is the same as the other datasources; if not, set it to the clear text password, and it will be encrypted at the next restart:

authDataEntries xmi:id="JAASAuthData_1296387511109"
alias="jcrdbDSJAASAuth" userId="db2admin" password="setPasswordHere”
description="JAAS Alias for DataSource jcrdbDS"



Happy Trails and Yours in WebSphere


Jerome Slinger








IBM WCM 7 : Migrating from WCM 6.0 to 7 - Release Not Found


Error received during migration: Release not found

Error Example String:
/WebSphere/PortalServer/base/wp.db.impl/config/templates/updatedb/6.0.1.6-7.0.0.1/db2/release
 not found.

Solution:
The issue is caused by missing files for migration from 6.1.0.6 to  7.0.0.1. This happened, because fixpack 6.1.0.6 is newer and so not  known by current 7.0.0.1. An APAR is requested.

As there are no database changes in the affected area between 6.1.0.5  and 6.1.0.6, you could duplicate the files in
/base/wp.db.impl/config/templates/updatedb/6.1.0.5-7.0.0.1
to the new directory
/base/wp.db.impl/config/templates/updatedb/6.1.0.6-7.0.0.1
as a workaround.

This is obviously not ideal but will resolve your problem.

...so how does one end up with this problem.IBM recommends that clients/customers need to be at the most recent fix pack level and as 6.0.1.7 is the most latest users are running into problems.

I hope that this has helped.

Yours in WebSphere
Jerome Slinger

Thursday, October 6, 2011

Migration version 6.0 to & - Checking your Versions

Hello Everyone

I am currently busy with a migration from version 6.0 to 7.

Prior to your migration it is important to ensure that you are on the most recent Fixpacks for both your 6 and 7 environment.

Finding your current Portal Version:

On Windows : run %WPS_HOME%\bin\WPVersionInfo.bat (e.g) c:\WebSphere\PortalServer\bin\WPVersionInfo.bat

On Unix : run $WPS_HOME/bin/versionInfo.sh (e.g) /opt/WebSphere/PortalServer/bin/WPVersionInfo.sh

What your report looks like:

--------------------------------------------------------------------------------
IBM WebSphere Portal Product Installation Status Report
--------------------------------------------------------------------------------

Report at date and time 2011-10-06T10:55:59+02:00

Installation
--------------------------------------------------------------------------------
Product Directory /WebSphere/PortalServer
Version Directory /WebSphere/PortalServer/version
DTD Directory /WebSphere/PortalServer/version/dtd
Log Directory /WebSphere/PortalServer/version/log
Backup Directory /WebSphere/PortalServer/version/backup
TMP Directory /tmp

Installation Platform
--------------------------------------------------------------------------------
Name IBM WebSphere Portal
Version 6.0

Technology List
--------------------------------------------------------------------------------
MP installed
PDM installed
WCM installed
PZN installed

Installed Product
--------------------------------------------------------------------------------
Name IBM WebSphere Portal MultiPlatform
Version 6.0.1.5
ID MP
Build Level wp6015_008_02
Build Date 11/08/2008

Installed Product
--------------------------------------------------------------------------------
Name IBM WebSphere Portal Document Manager
Version 6.0.1.5
ID PDM
Build Level wp6015_008_02
Build Date 11/08/2008

Installed Product
--------------------------------------------------------------------------------
Name IBM WebSphere Portal Personalization
Version 6.0.1.5
ID PZN
Build Level wp6015_008_02
Build Date 11/08/2008

Installed Product
--------------------------------------------------------------------------------
Name IBM WebSphere WebSphere Portal Web Content Manager
Version 6.0.1.5
ID WCM
Build Level wp6015_008_02
Build Date 11/08/2008

--------------------------------------------------------------------------------
End Installation Status Report
--------------------------------------------------------------------------------

You will notice that my current fix pack level is 6.0.1.5 so it's installing more fixpacks for me :-)

Will add that process as well.

Yours in WebSphere
Jerome Slinger

Tuesday, October 4, 2011

Preparing to migrate - 6.0.x to 7

Before starting the migration, go through this checklist:

Apply the latest cumulative fixpack on the 7.0 server. Refer to the IBM Support document, “Recommended Updates for WebSphere Portal and Web Content Management V7.0,” for more details.

Both the 6.x and 7.x servers should be using IBM DB2®. We tested these steps using DB2, but you can try the same with other relational databases (CloudScape is not supported).

Back up the JavaTM Content Repository (JCR) database on the 6.x server, and back up all the databases on the 7.0 server. So, in case there is a problem, you can restore the 7.0 databases to their previous working state and start over.

Verify that database-related properties in the Wkplc properties files on the 7.0 server have the correct information on all current databases being used besides the JCR database (JCRDB).

Delete the subscriber and syndicator pairs from the 6.x server before attempting the migration.

Check for any duplicate entries in the JCRSTLINKS table using following query:

select WSID , SIID , TNSID , TNAME , TIX, count(*)
from .ICMSTJCRLINKS
group by WSID , SIID , TNSID , TNAME , TIX having count(*) > 1

If you get any results from the above query, find the content with the name in TNAME column and delete it from the Authoring UI before backing up the 6.x database.

Original Article

Wednesday, May 11, 2011

System event logging: WebSphere Portal 7

The system event logging facility of IBM® WebSphere® Portal enables the recording of information about the operation of WebSphere Portal.

Event logs provide administrators with information on important or abnormal events, especially errors that occur during the operation of the product. In addition, event logs gather debugging information that helps IBM support to resolve problems.

WebSphere Portal provides two types of logging: logging of messages and logging of debugging messages called traces.

For information about how to use log files and a list of trace logger strings refer to the topic about WebSphere Portal logs.

This topic has the following sections:

Message logging
WebSphere Portal provides the logging of messages that report errors and status information.

The following types of messages are provided:

Informational


A condition worth noting but does not require the user to perform an action.

Warning

An abnormal condition has been detected. The user may have to take action. However, WebSphere Portal code is able to handle the condition without failing.

Error


A serious failure in the execution of the application that requires further action.

Messages for WebSphere Portal are logged in the following files:

SystemOut.log

Contains information that is useful for monitor the health of the WebSphere Portal server and all running processes.

System.err

Contains exception stack trace information that is useful when performing problem analysis.

Locating the log files: Log files for WebSphere Portal, including SystemOut.log and System.err are located in the following directory: wp_profile_root/logs/WebSphere_Portal

Trace logging

WebSphere Portal provides the logging of debugging messages called traces. These traces are useful for fixing problems. However, to save system resources, they are switched off by default.

Traces can be set for different durations:

Temporary

Traces can be set for a temporary period by using the administration portlet Enable Tracing or the IBM WebSphere Application Server administrative console. To set traces by using the portlet, proceed by the following steps:
Log in as the administrator.
Click Administration -> Portal Analysis -> Enable Tracing. The Enable Tracing portlet appears.
Type the required trace string into the field Append these trace settings:. For example, this can be com.ibm.wps.command.credentialvault.*=finest
Click the Add icon. Enable Tracing updates the field Current trace settings:
Note: Restarting WebSphere Portal will remove traces that were set by using the Enable Tracing Administration portlet.

To disable tracing, do either of the following:
Select the current trace settings under Current trace settings: and click the Remove icon. By the example given above, the current setting can be com.ibm.wps.command.credentialvault.*=finest.
Type the trace string *=info into the field Append these trace settings: and click the Add icon. This trace string overwrites all settings listed under Current trace settings: and resets it to the default.

Extended

To enable trace settings for a longer period of time, that is, for more than one session, switch them on in the WebSphere Application Server configuration. Proceed by the following steps:
Access the WebSphere Application Server Administrative Console by using this URL: http://hostname:port_number/ibm/console
Click Servers -> Server Types -> WebSphere application servers.
Select the application server.
Click Troubleshooting -> Change Log Detail Levels.
Specify the required trace settings. For example, this can be com.ibm.wps.command.credentialvault.*=finest
Save your updates.
Restart WebSphere Portal.
To disable tracing, specify tracestring: *=info and restart WebSphere Portal.

Changing the log file name and location
You can change the locations of the log files by configuring them in the WebSphere Application Server administrative console. Select Troubleshooting -> Logs and Trace -> server_name and select the logger type that you want to change. In the configuration dialog change the path for the log file as required. For a description of the available types of log files refer to the WebSphere Application Server information center.

Changing the language used in the log file
By default, information in the log file is written in the language that was used for the WebSphere Portal installation. However, because WebSphere Portal supports a number of languages, you can choose to have the log file information written in a language other than that used during installation.

To change the language used for the log file, edit the file log.properties. This file is located in the following WebSphere Portal directory:

UNIX: wp_profile_root/PortalServer/config/config
i: wp_profile_root/PortalServer/config/config
Windows: wp_profile_root\\PortalServer\\config\\config

Add the following line:

locale=xx

where xxis the two-letter abbreviation for the locale. For a list of the locale abbreviations used with WebSphere Portal, refer to Directories for languages. For example, to have log information generated in English, you would add the following line:

locale=en

Reference: Log file format

If the logs are written to the log file of WebSphere Portal and not redirected to the logging facility WebSphere Application Server, the log file consists of a sequence log records that are separated by blank lines.

The log records have the following format:

timestamp classification classname method threadID

messagecode: logmessage



Where:

timestamp is the time (to the millisecond) when the log record was created.
classification is one of the following letters:
E for error messages
W for warning messages
I for informational messages
l for traces (low details)
m for traces (medium details)
h for traces (high details)
classname is the Java class containing the code that triggered the log event.
method is the name of the Java method containing the code that triggered the log event.
messagecode is a unique identifier for this message, to uniquely identify the specific message and refer to it when consulting documentation or support. The message code is only available for error, warning, or informational messages, and not for traces. It consists of:
a four-character identifier for the component that defines the message.
a four-digit number identifying the message in the component.
a one-letter classification code, which can be E, W or I , as defined above.
logmessage is the actual log message describing the logged event. Error, warning, and informational messages are translated into the system locale. Trace messages are not translated.
threadID is the identification of the thread that triggered the log event.

Note:

Traces are written only if the specific tracing facility is enabled; all other messages are written unconditionally.
The system locale is part of the general internationalization features of WebSphere Portal and can be configured via LocalizerService. For more information refer to the topics about Setting service configuration properties and about the Portal configuration services.

The following is an example of a log record:

2003.05.16 13:36:14.449 W com.ibm.wps.services.datastore.DataStoreServiceImpl init 0000003a

DSTO0063W: The transaction isolation level is not set to READ_COMMITTED.
The current value is TRANSACTION_REPEATABLE_READ.


Source: http://www-10.lotus.com/ldd/portalwiki.nsf/dx/System_event_logging_wp7

Tuesday, May 10, 2011

Portal Add a New Language

If the date does not display correctly in Portal the locale might not be fully supported by Portal. To rectify this add the Language en_ZA. You access the XML configuration interface using a command line tool. This command line client is a small separate program that connects to the server using an HTTP connection or a secure HTTPS connection with SSL. It is therefore possible to configure the portal remotely.

Full syntax: /WebSphere/PortalServer/bin/xmlaccess.sh -url localhost:10038/wps/config -in CreatLanguage.xml -out /tmp/result.xml

Should run with: ./xmlaccess.sh -in /tmp/CreateLanguage.xml
respond to user/passwd prompts
must have admin rights to import the new lang.

Here is the CreateLanguage.xml file to add the lang/locale en_ZA:











English - South Africa





Thursday, April 14, 2011

Configuring and Integrating the Standalone Tivoli Directory Server with Websphere Portal : wp7

Step 1: Configuring the Tivoli Directory Server

a). Adding Suffixes
Go to Tivoli Web Admin Console --> ServerAdministration --> Manage Server Properties--> Suffixes --> Enter the Base DN name for the suffix (Like dc=yourcompany,dc=com)--> click add
Stop and Start the LDAP server from LDAP admin console
b). Importing the portaluser.ldif
copy the portalusers.ldif file , and change the dc=yourcompany,dc=com with your sepecific details.
stop the ldap server , go to LDAP admin console-->manage-->LDIF Tasks-->import LDIF data-->browse for the portalusers.ldif



LDAP suffix="dc=yourco,dc=com"
user prefix="uid"
user suffix="cn=users"
group prefix="cn"
group suffix="cn=groups"
Portal administrator DN ="uid=wpsadmin,cn=users, dc=yourco,dc=com"
Portal administrator group ="cn=wpsadmins,cn=groups, dc=yourco,dc=com"


Step 2: Integrating the Tivoli Directory Server with Portal (replacing the default filebasedrepository to TDS)

a). Update C:\IBM\WebSphere\wp_profile\ConfigEngine\config\helpers\wp_security_ids.properties file with corresponding values like below (Instead of modifying the wkplc.properties file, you can update this properties file)

standalone.ldap.id=localtds
standalone.ldap.host=sivavaka.com
standalone.ldap.port=389
standalone.ldap.bindDN=cn=root
standalone.ldap.bindPassword=ldappwd
standalone.ldap.ldapServerType=IDS
standalone.ldap.userIdMap=*:uid
standalone.ldap.groupIdMap=*:cn
standalone.ldap.groupMemberIdMap=
standalone.ldap.userFilter=(&(uid=%v)(objectclass=inetOrgPerson))
standalone.ldap.groupFilter=(&(cn=%v)(objectclass=groupOfUniqueNames))
standalone.ldap.serverId=uid=root,cn=users,dc=sivavaka,dc=com
standalone.ldap.serverPassword=Passw0rd

standalone.ldap.realm=sivavaka_portal
standalone.ldap.primaryAdminId=uid=wpsadmin,cn=users,dc=sivavaka,dc=com
standalone.ldap.primaryAdminPassword=wpsadminpwd
standalone.ldap.primaryPortalAdminId=uid=wpsadmin,cn=users,dc=sivavaka,dc=com
standalone.ldap.primaryPortalAdminPassword=wpsadminpwd
standalone.ldap.primaryPortalAdminGroup=cn=wpsadmins,cn=groups,dc=sivavaka,dc=com
standalone.ldap.baseDN=dc=sivavaka,dc=com

standalone.ldap.et.group.searchFilter=
standalone.ldap.et.group.objectClasses=groupOfUniqueNames
standalone.ldap.et.group.objectClassesForCreate=
standalone.ldap.et.group.searchBases=
standalone.ldap.et.personaccount.searchFilter=
standalone.ldap.et.personaccount.objectClasses=inetOrgPerson
standalone.ldap.et.personaccount.objectClassesForCreate=
standalone.ldap.et.personaccount.searchBases=

standalone.ldap.gm.groupMemberName=uniqueMember
standalone.ldap.gm.objectClass=groupOfUniqueNames
standalone.ldap.gm.scope=direct
standalone.ldap.gm.dummyMember=uid=dummy


standalone.ldap.personAccountParent=cn=users,dc=sivavaka,dc=com
standalone.ldap.groupParent=cn=groups,dc=sivavaka,dc=com
standalone.ldap.personAccountRdnProperties=uid
standalone.ldap.groupRdnProperties=cn

standalone.ldap.gc.name=
standalone.ldap.gc.updateGroupMembership=
standalone.ldap.gc.scope=direct
standalone.ldap.derefAliases=always
standalone.ldap.authentication=simple

standalone.ldap.referral=ignore
standalone.ldap.delimiter=/
standalone.ldap.ignoreCase=true

standalone.ldap.sslEnabled=false
standalone.ldap.sslConfiguration=
standalone.ldap.certificateMapMode=EXACT_DN
standalone.ldap.certificateFilter=
standalone.ldap.reuseConnection=true
standalone.ldap.searchTimeLimit=120000
standalone.ldap.connectionPool=false
standalone.ldap.supportSorting=false
standalone.ldap.supportPaging=false
standalone.ldap.supportTransactions=false
standalone.ldap.isExtIdUnique=true
standalone.ldap.supportExternalName=false
standalone.ldap.translateRDN=false
standalone.ldap.searchCountLimit=500
standalone.ldap.searchPageSize=
standalone.ldap.returnToPrimaryServer=
standalone.ldap.primaryServerQueryTimeInterval=
standalone.ldap.loginProperties=uid
standalone.ldap.cp.maxPoolSize=20

b). Execute the following commands to validate and update

#Validates the updated properties
ConfigEngine.bat validate-standalone-ldap -DWasPassword=wpsadmin -DparentProperties=C:\IBM\WebSphere\wp_profile\ConfigEngine\config\helpers\wp_security_ids.properties

#Below command will change the portal filebased repository toTDS
ConfigEngine.bat wp-modify-ldap-security -DWasPassword=wpsadmin -DparentProperties=C:\IBM\WebSphere\wp_profile\ConfigEngine\config\helpers\wp_security_ids.properties

Note: If any problems while executing the above commands,
a) make sure above properties proper (like LDAP admin ID(bindDN), PWD).
b) check the C:\IBM\WebSphere\wp_profile\ConfigEngine\properties\wkplc.properties and file and make sure Stand alone LDAP properties are valid and same as entered above

Once the above commands executed successfully, restart the portal and application server if its already started.

Resolving the "myportal" and "portal" issues



Following are the steps to handle the "myportal" and "portal" in WCM generated links using tags like above

1. Go to \wp_profile\PortalServer\config
2. Open ConfigService.properties using text editing tool.
3. Uncomment this property :uri.home.substitution and set it to true (initially it is commented.)
uri.home.substitution = true
4. Open CMD goto \wp_profile\ConfigEngine
5. Type ConfigEngine.bat update-properties
6. Restart your portal server for your changes to effect.

This property automatically handles this portal myportal issue. i.e if user is logged it will be myportal, if logged out then portal.

Check out this link for more information on this:
http://publib.boulder.ibm.com/infocenter/wpdoc/v6r1m0/index.jsp?topic=/com.ibm.wp.ent.doc_v6101/admin/srvcfgref.html

Yours in WebSphere

Jerome Slinger

Wednesday, April 13, 2011

Steps for migrating WCM data from 6.0 to 6.1

With Migration fever continuing I thought I would also add a 6.0 to 6.1 Migration comment.

Let me know if this seems unclear.


To migrate from IBM WebSphere Portal V6.0 or later, you must connect to a copy of the earlier portal's JCR database domain before running the migration tasks.

Important: If the new portal installation uses the same DBMS as the earlier portal, you must use the same database driver to connect to the copy of the earlier portal's JCR database domain. For example, if you configured the new portal's release domain to use DB2 with a DB2 Type 4 driver, and the earlier portal's JCR database domain also uses DB2, you must use a DB2 Type 4 driver to connect to the copy of the earlier portal's JCR database domain. If the new portal uses Oracle for the release domain and the earlier portal's JCR database domain uses a different DBMS such as DB2, you do not need to use the same database driver to connect to the copy of the earlier portal's JCR domain.

Follow these steps for migrating data

Create a separate copy of the earlier WebSphere Portal JCR domain.

On the new portal, locate and update the properties files listed below to reflect a connection to the JCR domain copy that you created in the previous step:
* wp_profile_root/ConfigEngine/properties/wkplc.properties
* wp_profile_root/ConfigEngine/properties/wkplc_comp.properties
* wp_profile_root/ConfigEngine/properties/wkplc_dbtype.properties
Note: The value of the parameter jcr.DbSchema in the wkplc_comp.properties file must be specified in uppercase (for example, jcr.DbSchema=JCR).

Change to the wp_profile_root/ConfigEngine directory, and then enter the following commands to validate the configuration properties:

ConfigEngine.bat validate-database-driver -DTransferDomainList=jcr
ConfigEngine.bat validate-database-connection -DTransferDomainList=jcr

Stop the WebSphere_Portal server.

Connect WebSphere Portal Version 6.1 to the copy of the earlier JCR domain:
ConfigEngine.bat connect-database-jcr-migration
Note: The portal-post-upgrade task uses database catalog functions during execution. These catalog functions need to be correctly bound to the database for the portal-post-upgrade task to work. Refer to the documentation for your DBMS to determine how to do this.

If you used IBM Lotus Web Content Management in the earlier portal, delete any V6.0.1.x syndicators or subscribers that were copied with the JCR database domain. See Setting up a syndication relationship.

If you are migrating Web Content Management you must also run the following task:
ConfigEngine.bat create-wcm-persistence-tables

Verify that the new portal server starts.

Sunday, February 13, 2011

Content Creation with the IBM WCM API - works for version 6, 6.1,7

<%@ page import="com.ibm.workplace.wcm.api.*"%>
<%@ page import="java.util.*"%>

<% // retrieve repository Repository repository = WCM_API.getRepository(); //Creating a workspace Workspace workspace = repository.getWorkspace("username","password"); // Set library workspace.setCurrentDocumentLibrary(workspace.getDocumentLibrary("LibraryName")); // define authoring template String authoringTemplateName = new String("Authoring Template"); // define parent sitearea String parentSiteAreaName = new String("SiteArea Name"); // define workflow String workflowName = new String("Workflow Name"); DocumentId authoringTemplateId = null; DocumentId parentSiteAreaId = null; DocumentId siblingId = null; DocumentId workflowId = null; // find authoring template by name DocumentIdIterator authoringTemplateIterator = workspace.findByName(DocumentTypes.AuthoringTemplate,authoringTemplateName); if (authoringTemplateIterator.hasNext()){ authoringTemplateId = authoringTemplateIterator.nextId(); System.out.println("Authoring Template found : " + authoringTemplateName + "
");
}else {
out.println("Could not find Authoring Template: " + authoringTemplateName + "
");
}

// find sitearea by name
DocumentIdIterator siteAreaIterator = workspace.findByName(DocumentTypes.SiteArea,parentSiteAreaName );
if (siteAreaIterator.hasNext()){
parentSiteAreaId = siteAreaIterator.nextId();
out.println("Sitearea Found : " + parentSiteAreaName + "
");
}else {
out.println("Could not find Sitearea : " + parentSiteAreaName + "
");
}

// find workflow by name
DocumentIdIterator workflowIterator = workspace.findByName(DocumentTypes.Workflow,workflowName);
if (workflowIterator.hasNext()){
workflowId = workflowIterator.nextId();
out.println("Workflow found : " + workflowName + "
");
}else {
out.println("Could not find Workflow: " + workflowName + "
");
}
if((authoringTemplateId!=null) && (parentSiteAreaId!=null) && (workflowId!=null)){
// create new content
Content newContent = workspace.createContent(authoringTemplateId,parentSiteAreaId,siblingId,ChildPosition.END);
newContent.setName("NewContent");
newContent.setTitle("NewContent");
newContent.setDescription("New Content created using WCM API"); newContent.setWorkflowId(workflowId);

workspace.save(newContent);

DocumentIdIterator contentIterator = workspace.findByName(DocumentTypes.Content,"Almost there");
DocumentId contentId = null;
if(contentIterator.hasNext()) {
contentId = contentIterator.nextId();
}

//Get the content using getById
Content content = (Content)workspace.getById(contentId);

//Approving the Content
newContent.nextWorkflowStage();

System.out.println("Content page '" + parentSiteAreaName + newContent + "' moved to the approved state
");
String[] saveMessage = workspace.save((Document)newContent);

workspace.save(content);


if (saveMessage.length==0) {
out.println ("
Created new Content under " + parentSiteAreaName );
}

}else {
out.println ("Could not create new content");
}

%>

Thursday, February 10, 2011

LWCM Utility

Attached is a utility for creating a full website.The attached code creates the site, site areas,content ,sets the security permissions and adds the workflow to the content.

I have set this up as it is extremely useful.Consider this,if you add a controller plus an online form you now have a website creator :-)

I will continue posting some great LWCM work but will spice it up with some Portal.

Yours in Websphere
T.J.S.

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
import javax.servlet.http.HttpServletRequest;
import com.ibm.workplace.wcm.api.ChildPosition;
import com.ibm.workplace.wcm.api.Content;
import com.ibm.workplace.wcm.api.DocumentId;
import com.ibm.workplace.wcm.api.DocumentIdIterator;
import com.ibm.workplace.wcm.api.DocumentLibrary;
import com.ibm.workplace.wcm.api.DocumentType;
import com.ibm.workplace.wcm.api.DocumentTypes;
import com.ibm.workplace.wcm.api.LibraryComponent;
import com.ibm.workplace.wcm.api.LibraryImageComponent;
import com.ibm.workplace.wcm.api.ReferenceComponent;
import com.ibm.workplace.wcm.api.RichTextComponent;
import com.ibm.workplace.wcm.api.Site;
import com.ibm.workplace.wcm.api.SiteArea;
import com.ibm.workplace.wcm.api.SiteFrameworkContainer;
import com.ibm.workplace.wcm.api.TextComponent;
import com.ibm.workplace.wcm.api.WCM_API;
import com.ibm.workplace.wcm.api.Workspace;
import com.ibm.workplace.wcm.api.exceptions.ComponentNotFoundException;
import com.ibm.workplace.wcm.api.exceptions.OperationFailedException;
import com.ibm.workplace.wcm.api.exceptions.ServiceNotAvailableException;

private Workspace workspace;
private final String libraryName;
private final Map contentFieldsForSiteArea = new HashMap();

public WcmApiUtilBean(String libraryName) throws Exception {
super();

this.libraryName = libraryName;
this.initWorkspace();
}

private void initWorkspace() throws Exception {
ResourceBundle resource = ResourceBundle.getBundle("xxxxxxxxxx");
String wcmUserName = resource.getString("xxxxxxxx").trim();
String wcmUserPassword = resource.getString("xxxxxxxx").trim();
this.workspace = WCM_API.getRepository().getWorkspace(wcmUserName, wcmUserPassword);

DocumentLibrary docLib = this.workspace.getDocumentLibrary(this.libraryName);
this.workspace.setCurrentDocumentLibrary(docLib);
}

public void closeWorkspace() {
WCM_API.getRepository().endWorkspace();
this.workspace = null;
}

private DocumentId[] getWCMDocumentsByName(String wcmName, DocumentType documentTypes) {
List documentIds = new ArrayList();
DocumentIdIterator docIdIter = workspace.findByName(documentTypes, wcmName);
if (docIdIter.hasNext()) {
DocumentId wcmDocumentId = docIdIter.nextId();
documentIds.add(wcmDocumentId);
}
return (DocumentId[]) documentIds.toArray(new DocumentId[documentIds.size()]);
}

private DocumentId[] getWCMDocumentsByPath(String wcmPath, int workFlowStatus) {
List documentIds = new ArrayList();

DocumentIdIterator docIdIter = workspace.findByPath(wcmPath, workFlowStatus);
if (docIdIter != null && docIdIter.hasNext()) {
DocumentId wcmDocumentId = docIdIter.nextId();
documentIds.add(wcmDocumentId);
}
return (DocumentId[]) documentIds.toArray(new DocumentId[documentIds.size()]);
}

private SiteFrameworkContainer setTemplateMapping(SiteFrameworkContainer aWCMObject, String presTemp, String authoringTemp) throws Exception {

DocumentId[] authIds = null;
DocumentId[] presIds = null;

authIds = getWCMDocumentsByName(authoringTemp, DocumentTypes.AuthoringTemplate);

presIds = getWCMDocumentsByName(presTemp, DocumentTypes.PresentationTemplate);

if ((authIds.length == 1) && (presIds.length == 1)) {

if (!aWCMObject.hasTemplateMapping(authIds[0])) {
aWCMObject.addTemplateMapping(authIds[0], presIds[0]);
} else {

DocumentIdIterator docIt = aWCMObject.getAuthoringTemplateIds();
if (docIt.hasNext()) {
} else {
aWCMObject.addTemplateMapping(authIds[0], presIds[0]);
}
System.out.println("TemplateMapping authName = " + authoringTemp + " and presName = " + presTemp + " added to object " + aWCMObject.getName());
workspace.save(aWCMObject);
}
} else {
throw new Exception("Expected to find only one Authoring Template with Name:" + authoringTemp + " and Presentation Template with Name:" + presTemp);
}
return aWCMObject;
}

private SiteFrameworkContainer setSecuritySettings(SiteFrameworkContainer aWCMObject) throws Exception {

String accessType = "addReadAccessMembers";

String[] accessnl = new String[] { "[all authenticated portal users]", "anonymous portal user" };
for (int y = 0; y < accessnl.length; y++) { String access = accessnl[y]; if (accessType.equals("addReadAccessMembers")) { aWCMObject.addReadAccessMembers(new String[] { access }); System.out.println("addReadAccessMembers for Object = " + aWCMObject.getName() + " members = " + access); } else if (accessType.equals("addEditAccessMembers")) { aWCMObject.addEditAccessMembers(new String[] { access }); System.out.println("addEditAccessMembers for Object = " + aWCMObject.getName() + " members = " + access); } else if (accessType.equals("addDeleteAccessMembers")) { aWCMObject.addDeleteAccessMembers(new String[] { access }); System.out.println("addDeleteAccessMembers for Object = " + aWCMObject.getName() + " members = " + access); } } workspace.save(aWCMObject); return aWCMObject; } private SiteFrameworkContainer setTemplates(SiteFrameworkContainer aWCMObject, String presTemp, String authoringTemp) throws Exception { aWCMObject = setTemplateMapping(aWCMObject, presTemp, authoringTemp); aWCMObject = setSecuritySettings(aWCMObject); return aWCMObject; } private Content addTextComponent(Content aContent, String aTextField, String aValue) throws Exception { TextComponent txtComp = (TextComponent) aContent.getComponent(aTextField); txtComp.setText(aValue); aContent.setComponent(aTextField, txtComp); return aContent; } private Content addComponentReference(Content aContent, String fieldName, String value) throws Exception { DocumentId[] documentIds = this.getWCMDocumentsByName(value,DocumentTypes.LibraryImageComponent); ReferenceComponent refComp = (ReferenceComponent) aContent.getComponent(fieldName); LibraryComponent libComp = (LibraryComponent)workspace.getById(documentIds[0]); refComp.setComponentRef(libComp); aContent.setComponent(fieldName,refComp); return aContent; } private Content addRichTextComponent(Content aContent, String aTextField, String aValue) throws Exception { RichTextComponent txtComp = (RichTextComponent) aContent.getComponent(aTextField); txtComp.setRichText(aValue); aContent.setComponent(aTextField, txtComp); return aContent; } private Content setTextComponentForContent(Content aContent, String name, String value) throws Exception { String textField = name; String text = value; aContent = addTextComponent(aContent, textField, text); if (aContent != null) { System.out.println("adding textField = " + textField + " to content " + aContent.getName()); } if (aContent == null) { return null; } else { return aContent; } } private Content setComponentReferenceForContent(Content aContent, String name, String value) throws Exception { aContent = addComponentReference(aContent, name, value); if (aContent != null) { System.out.println("adding Component Reference = " + name + " to content " + aContent.getName()); } if (aContent == null) { return null; } else { return aContent; } } private Content setRichTextComponentForContent(Content aContent,String name,String value) throws Exception { aContent = addRichTextComponent(aContent, name, value); return aContent; } private SiteArea addDefaultContentToSiteArea(SiteArea aSiteArea, String authoringTempName, String contentTitleValue,String contentBodyValue) throws Exception { String contentName = aSiteArea.getParent().getName() + "_" + aSiteArea.getName() + "_c"; DocumentId[] defaultAuthIds = getWCMDocumentsByName(authoringTempName, DocumentTypes.AuthoringTemplate); if (defaultAuthIds.length > 0) {
if (defaultAuthIds.length == 1) {
System.out.println("defaultAuthId = " + defaultAuthIds[0]);
Content content = null;
DocumentId[] defaultContentIds = getWCMDocumentsByName(contentName, DocumentTypes.Content);
DocumentId defaultContentId;
if (defaultContentIds.length > 0) {
if (defaultContentIds.length == 1) {
content = (Content) workspace.getById(defaultContentIds[0]);
} else {
throw new Exception("Found more than on Content Item with the Same name:" + contentName);
}
defaultContentId = defaultContentIds[0];
} else {
content = workspace.createContent(defaultAuthIds[0], aSiteArea.getId(), null, ChildPosition.START);
defaultContentId = content.getId();
content.setName(contentName);
content.setTitle(contentName);
}

content = setTextComponentForContent(content, "Title", contentTitleValue);
content = setRichTextComponentForContent(content,"Body",contentBodyValue);


String workflowName = new String("xxxxxx");

DocumentIdIterator workflowIterator = workspace.findByName(DocumentTypes.Workflow, workflowName);
if (workflowIterator.hasNext()) {
DocumentId workflowId = workflowIterator.nextId();
System.out.println("Workflow found : " + workflowName + "
");

if (!content.isPublished()) {
content.setWorkflowId(workflowId);
workspace.save(content);
content.nextWorkflowStage();
System.out.println("Moved to next workflowstage");
}

} else {
System.out.println("Could not find Workflow: " + workflowName + "
");
}

aSiteArea.setDefaultContent(defaultContentId);
return aSiteArea;

} else {
throw new Exception("Found more than one Authoring Template with the same name:" + authoringTempName);
}
} else {
throw new Exception("Did not find more than one Authoring Template with the same name:" + authoringTempName);
}

}

private boolean saveToWorkspace(com.ibm.workplace.wcm.api.Document wcmDocument) throws Exception {

String[] errors = workspace.save(wcmDocument);

for (int i = 0; i < errors.length; i++) { System.out.println("Error while saving " + wcmDocument.getName() + " : " + errors[i]); } if (errors.length > 0) {
return false;
}
return true;
}

protected void finalize() throws Throwable {
this.closeWorkspace();
super.finalize();
}

public Site obtainSite(String siteName, String presTemp, String authoringTemp) throws Exception {
Site site = null;
DocumentId[] siteIds = getWCMDocumentsByName(siteName, DocumentTypes.Site);
if (siteIds.length > 0) {
if (siteIds.length == 1) {
site = (Site) workspace.getById(siteIds[0]);
} else {
throw new Exception("More then one Site found with the Same name:" + siteName);
}
} else {
site = workspace.createSite();
site.setName(siteName);
site.setTitle(siteName);
String[] messages = workspace.save(site);

for (int i = 0; i < messages.length; i++) { System.out.println("Message = " + messages[i]); } site = (Site) setTemplates(site, presTemp, authoringTemp); } return site; } public SiteArea obtainSiteArea(String siteAreaName, String presTemp, String authoringTemp, DocumentId parentId, String siteContentTitleValue,String siteContentBodyValue) throws Exception { SiteArea sa = null; String parentPath = workspace.getPathById(parentId, true, true); String siteAreaPath = parentPath + "/" + siteAreaName; DocumentId[] siteAreaIds = getWCMDocumentsByPath(siteAreaPath, Workspace.WORKFLOWSTATUS_ALL); if (siteAreaIds.length > 0) {
// if (siteAreaIds.length == 1) {
// sa = (SiteArea) workspace.getById(siteAreaIds[0]);
// } else {
throw new Exception("Found more than one Sitearea with the same name:" + siteAreaName);
// }
} else {
sa = workspace.createSiteArea(parentId, null, 1);
sa.setTitle(siteAreaName);
sa.setName(siteAreaName);
workspace.save(sa);
}

sa = (SiteArea) setTemplates(sa, presTemp, authoringTemp);

boolean saved = saveToWorkspace(sa);

sa = addDefaultContentToSiteArea(sa, authoringTemp, siteContentTitleValue,siteContentBodyValue);

saved = saveToWorkspace(sa);
System.out.println("site area = " + sa.getName());

return sa;
}

}

Friday, January 7, 2011

Find an item by name

So you want to find an item using the WCM API ha?No problem....


<%@ page import="com.ibm.workplace.wcm.api.*"%>
<%@ page import="java.util.*"%>
<% // retrieve repository Repository repository = WCM_API.getRepository(); // get the workspace for current user Workspace workspace = repository.getWorkspace(request.getUserPrincipal()); // set the library workspace.setCurrentDocumentLibrary(workspace.getDocumentLibrary("WebContent")); // **************************** Find Site example *************************** // define site name String siteName = new String("Site"); // find site by name DocumentIdIterator siteIterator = workspace.findByName(DocumentTypes.Site,siteName); if (siteIterator.hasNext()){ out.println("Site found : " + siteName + "
");
}else {
out.println("Could not find site : " + siteName + "
");
}

// ************************* Find Sitearea example **************************
// define sitearea name
String siteArea = new String("SiteArea");
// find sitearea by name
DocumentIdIterator siteAreaIterator = workspace.findByName(DocumentTypes.SiteArea,siteArea);
if (siteAreaIterator.hasNext()){
out.println("Sitearea found : " + siteArea + "
");
}else {
out.println("Could not find Sitearea : " + siteArea + "
");
}

// ************************* Find Content example ***************************

// define content name
String contentName = new String("Content");
// find content by name
DocumentIdIterator contentIterator = workspace.findByName(DocumentTypes.Content,contentName);
if (contentIterator.hasNext()){
out.println("Content found : " + contentName + "
");
}else {
out.println("Could not find Content : " + contentName + "
");
}

// *********************** Find Authoring Template example *******************

// define authoring template name
String authoringTemplateName = new String("AuthoringTemplate");

// find authoring template by name
DocumentIdIterator authoringTemplateIterator = workspace.findByName(DocumentTypes.AuthoringTemplate,authoringTemplateName);
if (authoringTemplateIterator.hasNext()){
out.println("Authoring template found : " + authoringTemplateName + "
");
}else {
out.println("Could not find Authoring template: " + authoringTemplateName + "
");
}

// *********************** Find Presentation Template example *****************

// define presentation template name
String presentationTemplateName = new String("PresentationTemplate");
// find presentation template by name
DocumentIdIterator presentationTemplateIterator = workspace.findByName(DocumentTypes.PresentationTemplate,presentationTemplateName);
if (presentationTemplateIterator.hasNext()){
out.println("Presentation template found : " + presentationTemplateName + "
");
}else {
out.println("Could not find Presentation template: " + presentationTemplateName + "
");
}

// *********************** Find Library Component example *******************

// define library component name
String libraryComponentName = new String("LibraryComponent");
// find library component by name
DocumentIdIterator libraryComponentIterator = workspace.findByName(DocumentTypes.LibraryComponent,libraryComponentName);
if (libraryComponentIterator.hasNext()){
out.println("Library component found : " + libraryComponentName + "
");
}else {
out.println("Could not find Library component: " + libraryComponentName + "
");
}

// *************************** Find Workflow example ***********************

// define workflow name
String workflowName = new String("Workflow");

// find workflow by name
DocumentIdIterator workflowIterator = workspace.findByName(DocumentTypes.Workflow,workflowName);
if (workflowIterator.hasNext()){
out.println("Workflow found : " + workflowName + "
");
}else {
out.println("Could not find Workflow: " + workflowName + "
");
}

// ************************* Find Workflow Stage example ********************

// define workflow stage name
String workflowStageName = new String("WorkflowStageName");
// find workflow stage by name
DocumentIdIterator workflowStageIterator = workspace.findByName(DocumentTypes.WorkflowStage,workflowStageName);
if (workflowStageIterator.hasNext()){
out.println("Workflow Stage found : " + workflowStageName + "
");
}else {
out.println("Could not find Workflow Stage: " + workflowStageName + "
");
}

// ************************** Find Taxonomy example ************************

// define taxonomy name
String taxonomyName = new String("Taxonomy");
// find taxonomy by name
DocumentIdIterator taxonomyIterator = workspace.findByName(DocumentTypes.Taxonomy,taxonomyName);
if (taxonomyIterator.hasNext()){
out.println("Taxonomy found : " + taxonomyName + "
");
}else {
out.println("Could not find Taxonomy: " + taxonomyName + "
");
}

// ************************** Find Category example *************************

// define category name
String categoryName = new String("Category");
// find category by name
DocumentIdIterator categoryIterator = workspace.findByName(DocumentTypes.Category,categoryName);
if (categoryIterator.hasNext()){
out.println("Category Found : " + categoryName + "
");
}else {
out.println("Could not find Category : " + categoryName + "
");
}
%>

Generate reports from Opportunities using a Visualforce Page in Salesforce

  Step 1: Create a Visualforce Page Go to the Setup menu in Salesforce. Search for "Visualforce Pages" in the Quick Find box and c...