Thursday, April 14, 2011

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 + "
");
}
%>

Friday, December 17, 2010

Creating a New Site Area using the IBM WCM API

<%@ page import="com.ibm.workplace.wcm.api.*"%>
<%@ page import="java.util.*"%>
<% // retrieve repository Repository repository = WCM_API.getRepository(); // get workspace for current user Workspace workspace = repository.getWorkspace(request.getUserPrincipal()); // Set library workspace.setCurrentDocumentLibrary(workspace.getDocumentLibrary("WebContent")); DocumentId documentId = null; Site parentSite = null; String parentSiteName = "Site"; DocumentId siblingId = null; // find parent site DocumentIdIterator siteIterator = workspace.findByName(DocumentTypes.Site,parentSiteName); if (siteIterator.hasNext()){ documentId = siteIterator.nextId(); parentSite = (Site) workspace.getById(documentId); // create new sitearea SiteArea newSiteArea = workspace.createSiteArea((DocumentId)parentSite.getId(),siblingId,ChildPosition.END); newSiteArea.setName("NewSiteArea"); newSiteArea.setTitle("NewSiteArea"); newSiteArea.setDescription("New Sitearea Created using WCM API String[] saveMessage = workspace.save((Document)newSiteArea); if (saveMessage.length==0) { out.println ("
Created new Sitearea under " + parentSiteName );
}
} else {
out.println ("
Could not find parent Site " + parentSiteName + ". Could not create a
new Sitearea." );
}
%>

New Site Creation

Create a new Website using the IBM WCM API

<%@ page import="com.ibm.workplace.wcm.api.*"%>
<%@ page import="java.util.*"%>
<% // retrieve repository Repository repository = WCM_API.getRepository(); // get workspace for current user Workspace workspace = repository.getWorkspace(request.getUserPrincipal()); // Set library workspace.setCurrentDocumentLibrary(workspace.getDocumentLibrary("WebContent")); // create new site Site newSite = workspace.createSite(); newSite.setName("Jerome"); newSite.setTitle("JeromeSlinger"); newSite.setDescription("New Site Created using WCM API"); String[] saveMessage = workspace.save((Document)newSite); if (saveMessage.length==0){ out.println("Could not create new Site..
");
}else{
out.println("New Site created successfully.");
}
%>

Thursday, December 2, 2010

Creating a Default Portal Search Service Collection and Content Source

Step One - Log in to Portal / WCM Design



Now navigate to Administration



1.Click on Search Administration > Manage Search
2.Click on Search Collections



3.Click on New Collection
4.Add Search Collection detail and click OK



N.B.The red areas are where you enter your own Collection details

5.Check that the Search Collection was created successfully
6.Click on Log Out



OK, we are not done yet!So now.....

Create the Portal Search Content Source

1. Log into IBM WCM
2. You will now go to the Web Content and NOT the admin console
3. Select the library you wish to add to your collection
4. Select Site Areas>By SITE>Click Edit

N.B.You need to select the tick box next to the site on the right hand-side and click edit.

5.Select Search>Tick Searchable
6.From the Drop-down select your Search Service
7.Select your Search collection
8.Set User ID and Password and Click on Save

OK, Now we are making progress....but we are not done YET!

Ok Here we go....

1. Click Launch (Top left Corner)
2. Select Administration from the Drop-down
3. Select Manage Search
4. Click on Search Collections
5. Click on the collection you want to add the Content Source too
6 Click on Edit Content Source of the Content Source that was created

Now this part is extremely important!

1. Change General Parameters
> Stop collecting after (min) to Unlimited
General Parameters > Stop fetching a document after (sec) to Unlimited

2. Change Schedulers > Define Schedule > At to 22 00
Change Schedulers > Define Schedule > Update every to 1 day(s) and click Create
Select Scheduled Updates > Schedule that was created by default and click Delete
> CLICK SAVE!
>Check that the Content source was created without errors
>The crawler will run with the next run date and time

N.B. I was using 22 00 as an example so please amend this to your own requirements.


Now I am going to share a secret with you that will save you a lot of time....come closer....this is serious....you will thank me later.

On the left hand side of your admin console do the following:

1.Click on Access > Resource Permissions > PSE Sources
2.Click on Assign Access for your collection
3.Click on Edit Role for the User role
4.Add anonymous Portal user

Well Done!!

We will make you a WebSphere guru yet!

Monday, November 22, 2010

Component Reference Errors

This week we are covering Reference errors:


Error Example


11/22/10 10:48:47:440 SAST] 000001e4 PackageProces W Could not resolve a reference from item of type com.aptrix.pluto.cmpnt.HTMLCmpnt and name xxxxxxx to an item with id {xxxxxxxxxxxxxxxxxxxxxx, com.aptrix.pluto.cmpnt.ImageResourceCmpnt}. The reference is of type com.aptrix.deployment.subscriber.SyndicationReferenceResolver$ArrayCmpntHandler$ArrayElementReference.
[11/22/10 10:48:47:693 SAST] 000001e4 PackageProces W IWKPD1029X: Could not store doc: xxxxxx, IdRef: {xxxxxxxxxxxxxxxxxxxx, com.aptrix.pluto.cmpnt.HTMLCmpnt}

So now we have seen the snippet from our System log but where to from here.

Points to take note of:

1. In our error strings we can deduce the following:
1.1. We have a reference from an HTML component which WCM can not resolve
1.2. This example error occured during syndication
1.3. The document has not been moved

Steps to take:

1.Navigate to the library containing the component
2.Search for the component (use filter as the system log gives us the name)
3. Select the component and edit.
4. Check the current links contained in the component.
5. Remember that our error is related to an item which the component is linking too.
6. Repair the link issue

....and thats it folks.

I will keep on posting various types of errors and discoveries as I go along.
Please feel free to mail me any issues and I will blog solutions.

Your in Websphere
J

Friday, May 7, 2010

Bulk PDF or file Upload with IBM WCM

Hi All

Now I know there's been a lot of request for a bulk up-loader using the API for WCM.
So you as the old saying goes ...ask and you shall receive.

String libraryName = null;
Workspace workspace = null;
DocumentId authTempId = null;
DocumentId workflowId = null;
String destinationSitearea = null;

void uploadFiles(JspWriter out) {
File baseDir = new File(destFolder);
try {
if (!baseDir.exists()) {
System.out.println("Bulk uploader: path does not exist - " + destFolder);
return;
}
File[] buDirs = baseDir.listFiles();
for (int i = 0; i <>
if (buDirs[i].isFile()) {
continue;
}
// you need to get the sitearea destination first
File textFile = new File(buDirs[i], "sitearea.txt");
if (!textFile.exists()) {
continue; // textFile contains destination sitearea
}
destinationSitearea = getDestinationSitearea(textFile);
if (destinationSitearea == null) {
continue; // nonsensical destination area retrieved
}

File[] files = buDirs[i].listFiles();
for (int m = 0; m <>
if (files[m].isDirectory()) {
// files[m].delete();
continue;
}
boolean hasUpdated = false;
if (files[m].getName().toLowerCase().endsWith(".pdf")) {
hasUpdated = updateWCMPage(files[m], out);
}
if (hasUpdated) {
out.println("File uploaded: " + files[m].getAbsolutePath() + "
");
files[m].delete();
} else {
if (files[m].getName().toLowerCase().endsWith(".pdf")) {
out.println("Failed to update file '" + files[m] + "' into wcm
");
}
}
}
}

} catch (SecurityException se) {
} catch (IOException ioe) {
}
}

boolean updateWCMPage(File file, JspWriter out) {
boolean hasUpdated = false;
try {
try {
if (workspace == null) {
workspace = WCM_API.getRepository().getWorkspace(wcmUserName, wcmUserPassword);
}
workspace.setCurrentDocumentLibrary(workspace.getDocumentLibrary(libraryName));
DocumentIdIterator contentIterator = workspace.findContentByPath(destinationSitearea + file.getName());

if (contentIterator.hasNext()) {
DocumentId contentId = (DocumentId) contentIterator.next();
Content content = (Content) workspace.getById(contentId);

TextComponent txtName = (TextComponent) content.getComponent("Name");
txtName.setText(file.getName());
FileComponent fileComponent = (FileComponent) content.getComponent("File");

FileInputStream fin = new FileInputStream(file);
byte[] fileContent = new byte[(int) file.length()];
fin.read(fileContent);

if (!workspace.isLocked(contentId)) {
fileComponent.setFile(file.getName(), fileContent);
content.setComponent("File", fileComponent);
content.setComponent("Name", txtName);

String[] errors = workspace.save(content);
for (int j = 0; j <>
out.println("Error saving page" + errors[j]);
}
if (errors.length == 0) {
hasUpdated = true;
out.println("Content page '" + destinationSitearea + file.getName() + "' has been updated
");
} else {
StringBuffer buffer = new StringBuffer();
for (int k = 0; k <>
buffer.append(errors[k]);
}
out.println("Errors updating content page '" + destinationSitearea + file.getName() + "' " + buffer.toString() + "
");
}
} else {
out.println("Contet page '" + file.getName() + "' is locked currently locked by another user.
");
}

} else { // page does not exist
DocumentIdIterator siteareaIterator = workspace.findContentByPath(destinationSitearea);
DocumentId defContentId = null;
DocumentId siteareaId = null;
boolean validPath = false;
if (siteareaIterator.hasNext()) {
defContentId = siteareaIterator.nextId();
Content defContent = (Content) workspace.getById(defContentId);
defContent.getDirectParent(); // used to get sitearea
siteareaId = defContent.getDirectParent();
validPath = true;
}

if (validPath) {
setAuthoringTemplateId(out);
setWorkflowId(out);
workspace.setCurrentDocumentLibrary(workspace.getDocumentLibrary(libraryName));
Content addedPage = workspace.createContent(authTempId, siteareaId, null, ChildPosition.END);
addedPage.setWorkflowId(workflowId);
System.out.println("trying to process '" + file.getName() + "'");
String pageName = file.getName();
pageName = pageName.replaceAll("[^a-zA-Z._-]", "");
addedPage.setName(pageName);
if (!addedPage.isPublished()) {
if (addedPage.isDraft()) {
out.println("Content page '" + destinationSitearea + pageName + "' is in the draft state
");
TextComponent txtName = (TextComponent) addedPage.getComponent("Name");
txtName.setText(file.getName());
FileComponent fileComponent = (FileComponent) addedPage.getComponent("File");

FileInputStream fin = new FileInputStream(file);
byte[] fileContent = new byte[(int) file.length()];
fin.read(fileContent);

fileComponent.setFile(file.getName(), fileContent);
addedPage.setComponent("File", fileComponent);
addedPage.setComponent("Name", txtName);
addedPage.addHistoryLogEntry("New page created: " + file.getName());

String[] errors = workspace.save(addedPage);
for (int j = 0; j <>
System.out.println(errors[j]);
}
addedPage.nextWorkflowStage();
out.println("Content page '" + destinationSitearea + pageName + "' moved to the approved state
");
addedPage.nextWorkflowStage();
out.println("Content page '" + destinationSitearea + pageName + "' moved to the published state
");
hasUpdated = true;
}
}
} else {
out.println("Error: Please ensure your sitearea '" + destinationSitearea + "' has its default content set");
}
}

} catch (OperationFailedException ofe) {
out.println("Error: Operation failed: " + ofe.getMessage() + "
");
} catch (ServiceNotAvailableException snae) {
out.println("Error: Service not available: " + snae.getMessage() + "
");
} catch (DocumentRetrievalException dre) {
out.println("Error: Unable to retrieve document: " + dre.getMessage() + "
");
} catch (AuthorizationException ae) {
out.println("Error: Authorization problem: " + ae.getMessage() + "
");
} catch (DocumentCreationException dce) {
out.println("Error: Unable to create document: " + dce.getMessage() + "
");
} catch (IllegalDocumentTypeException idte) {
out.println("Error: Wrong document type: " + idte.getMessage() + "
");
} catch (PropertyRetrievalException pre) {
out.println("Error: Unable to get document workflow stage: " + pre.getMessage() + "
");
} catch (NoMoreWorkflowStagesException nmwfse) {
out.println("Error: " + nmwfse.getMessage() + "
");
} catch (DocumentSaveException dse) {
out.println("Error: Unable to save new document: " + dse.getMessage());
} catch (DuplicateChildException dce) {
out.println("Error: Duplicate page: " + dce.getMessage());
} catch (ComponentNotFoundException cne) {
out.println("Error: Authoring template element not found: " + cne.getMessage());
} catch (IllegalTypeChangeException ile) {
out.println("Error: Illegal AT type: " + ile.getMessage());
}
} catch (IOException ioe) {
}
return hasUpdated;
}

String getDestinationSitearea(File file) {
String sitearea = null;
try {
FileInputStream fin = new FileInputStream(file);
byte[] fileContent = new byte[(int) file.length()];
fin.read(fileContent);
String content = new String(fileContent);
content = content.toLowerCase().trim();
if (!content.startsWith("/")) {
content = "/" + content;
}
if (content.endsWith("\n")) {
content = content.replaceAll("\n", "");
}
if (!content.endsWith("/")) {
content = content + "/";
}
String[] segments = content.split("/"); //obtain library name from path
libraryName = segments[1];
sitearea = content;

} catch (IOException ioe) {
}
return sitearea;
}

void setAuthoringTemplateId(JspWriter out) {
try {
try {
if (authTempId == null) {
workspace.setCurrentDocumentLibrary(workspace.getDocumentLibrary("documents"));
DocumentIdIterator docIds = workspace.findByType(DocumentTypes.AuthoringTemplate);
while (docIds.hasNext()) {
authTempId = (DocumentId) docIds.next();
AuthoringTemplate at = (AuthoringTemplate) workspace.getById(authTempId);
String name = at.getName();
if (name.equalsIgnoreCase("at-file-resource")) {
break;
}
}
}
} catch (DocumentRetrievalException dre) {
out.println("Error: Unable to retrieve document: " + dre.getMessage() + "
");
} catch (AuthorizationException ae) {
out.println("Error: Authorization problem: " + ae.getMessage() + "
");
}
} catch (IOException ioe) {
}
}

void setWorkflowId(JspWriter out) {
try {
try {
if (workflowId == null) {
workspace.setCurrentDocumentLibrary(workspace.getDocumentLibrary("documents"));
DocumentIdIterator docIds = workspace.findByType(DocumentTypes.Workflow);
while (docIds.hasNext()) {
workflowId = (DocumentId) docIds.next();
Workflow wf = (Workflow) workspace.getById(workflowId);
String name = wf.getName();
if (name.equalsIgnoreCase("wf-documents")) {
break;
}
}
}
} catch (DocumentRetrievalException dre) {
out.println("Error: Unable to retrieve document: " + dre.getMessage() + "
");
} catch (AuthorizationException ae) {
out.println("Error: Authorization problem: " + ae.getMessage() + "
");
}
} catch (IOException ioe) {
}
}

boolean isEmpty(String value) {
if (value == null || value.trim().length() == 0) {
return true;
} else {
return false;
}
}

%>



Yours in Websphere
Jerome Slinger

Wednesday, February 3, 2010

कस्तोमिसेद औथोरिंग टूल्स

Inline Editing

So now I have tested the inline editing jsp done by David De Vos.Simply brilliant!
Really offers you the ability to offer easier editing to content authors.

Attached Mr David De Vos's Code - Let me know if you have any hassles.

<%
%>
<%@page session="false" contentType="text/html" %>
<%@page import="com.ibm.workplace.wcm.api.*"%>
<%@page import="com.ibm.workplace.wcm.api.exceptions.*"%>
<%@taglib uri="/WEB-INF/tld/wcm.tld" prefix="wcm" %>

<%
// PURPOSE
// An example of a custom 'New' Authoring Tools link which allows the action to be targeted at
// a specific server as well as passing in the current site area and authoring template.
// In WCM 6.1, this JSP can be further customised to set the values of various fields, see
// the InfoCenter topic on Remote Actions for what is possible

// USAGE INSTRUCTIONS
// 1. Set the value of 's_authoringServerNameAndPort' to match the name and port of your authoring server
// NOTE: You will need to have single-sign working between the current server and the authoring otherwise the user
// will need to login
// 2. [Optional] Customise the HTML produced for the 'New' link on line 111
// 3. Add this JSP to the following locations on all authoring nodes and any rendering nodes that use Inline Editing
// \installedApps\WCM_Authoring_UI_1k9qukya.ear\1k9qukya.war\jsp\html
// \installedApps\WCM_Local_ng_Portlet_PA_dm010y1.ear\dm010y1.war\jsp\html
// \installedApps\\wcm.ear\ilwwcm.war\jsp\html (only required for servlet rendering)
// 4. Add a JSP Component that references this JSP
// 5. In your Authoring tools component, set the 'New action design' to a Component tag that references the library
// component created in step 4

// AUTHOR
// David de Vos
%>

<%!
// The name and port of your authoring server
String s_authoringServerNameAndPort = "[Auth server plus port ID]";
%>


<%
// Retrieve current users workspace
Workspace workspace = (Workspace) pageContext.getAttribute(Workspace.WCM_WORKSPACE_KEY);

// Retrieve the current Rendering Context
RenderingContext renderingContext = (RenderingContext) pageContext.getRequest().getAttribute(Workspace.WCM_RENDERINGCONTEXT_KEY);

if ((workspace != null) && (renderingContext != null))
{
// Get current authoring template
DocumentId currentAuthoringTemplateId = null;
Content currentContent = renderingContext.getContent();
if (currentContent != null)
{
currentAuthoringTemplateId = currentContent.getAuthoringTemplateID();
}

// Get current site area
DocumentId currentSiteAreaId = null;
String fullPath = renderingContext.getPath();
if (fullPath != null)
{
String siteAreaPath = java.net.URLDecoder.decode(fullPath);
// If Content name is in path, then strip it out (won't be if current URL was to a site area)
if (currentContent != null)
{
int index = siteAreaPath.lastIndexOf(currentContent.getName());
if (index > 0)
{
siteAreaPath = siteAreaPath.substring(0, index-1);
}
}
DocumentIdIterator parentSiteAreaIdIterator = workspace.findByPath(siteAreaPath, Workspace.WORKFLOWSTATUS_PUBLISHED | Workspace.WORKFLOWSTATUS_EXPIRED);
if (parentSiteAreaIdIterator.hasNext())
{
currentSiteAreaId = parentSiteAreaIdIterator.nextId();
}
}

// Build 'New' link URL
StringBuffer newLinkURL = new StringBuffer();
newLinkURL.append("http://").append(s_authoringServerNameAndPort).append("/wps/wcmAuthoring");
newLinkURL.append("?wcmAuthoringAction=new&type=com.ibm.workplace.wcm.api.WCM_Content");
if (currentAuthoringTemplateId != null)
{
// Include the current authoring template if known
newLinkURL.append("&atid=").append(currentAuthoringTemplateId);
}
if (currentSiteAreaId != null)
{
// Include the current site area if known
newLinkURL.append("&pid=").append(currentSiteAreaId);
}

// Render the Link..
%>
New
<%
}
%>


Yours in Websphere

Jerome Slinger

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...