Software AG Products 10.5 | CentraSite for Developers | Customizing CentraSite | Implementation of Computed Attributes and Profiles | Implementing Computed Profiles for CentraSite Business UI
 
Implementing Computed Profiles for CentraSite Business UI
In the following sections, we demonstrate a custom profile named SampleProfile that illustrates how to write a computed profile. The sample extends the profile selection list for an asset type and presents a screen that prompts for the profile archive to be uploaded. After confirming the archive, the appropriate adapter classes are called.
You may use this sample as a guideline, adapting it and renaming it to suit your individual requirements. The sample indicates where customization is required.
Definition of Java-Based Computed Profile
A Java based computed profile has the following rendering mechanism:
*WithUiRendering: This dictates the user-defined rendering of the profile's attributes.
*WithoutUiRendering: This dictates the CentraSite's default rendering of the profile’s attributes. This default rendering is based on the attribute’s data type.
The Build Environment
This section explains the build environment for generating the HTML files that are used for the GUI and for compiling the necessary Java source files. It assumes the use of Ant, the Java-based build tool.
The following file system structure under the computed profile directory is assumed:
Name of File or Folder
Description
META-INF
This folder contains the config.properties file, which is the build file for the computed profile. This properties file contains an entry of the following format:
com.softwareag.centrasite.computed.profil
e.bui.impl.class=com.softwareag.centrasite.bui.profil
e.server.SampleComputedProfileImpl
src
This folder that holds the Java source files.
lib
This folder contains the archive file with the source code examples, the plug-in's executor class and the external libraries.
html
This folder holds the html files that specify your computed profile window.
images
This folder holds the image files.
css
This folder holds the css files.
js
This folder holds the JavaScript codes.
build.xml
The Ant input file for building the destination files
The Ant file shown below, named build.xml, can be used to establish a custom computed profile.
<?xml version="1.0" encoding="utf-8"?>
<project name="SampleProfile" default="all" basedir=".">
<property file="${basedir}/build.properties" />
<property name="src.dir" value="${basedir}/src" />
<property name="classes.dir" value="${basedir}/classes" />
<property name="build.output.dir" value="${basedir}/build_output" />
<path id="project.class.path">
<fileset dir="${gwt.home}">
<include name="gwt-dev.jar" />
<include name="gwt-user.jar" />
<include name="validation-api-1.0.0.GA.jar" />
<include name="validation-api-1.0.0.GA-sources.jar" />
</fileset>
<fileset dir="${centrasite.redist.dir}">
<include name="gf.jaxr-api-osgi.jar" />
<include name="INMConfiguration.jar" />
</fileset>
<fileset dir="${centrasite.rts.dir}">
<include name="CentraSiteLogicLayer-API.jar" />
<include name="CentraSiteLogicLayer-impl.jar" />
<include name="CentraSiteUtils.jar" />
<include name="gf.jaxr-api-osgi.jar" />
<include name="CentraSiteJAXR-API.jar" />
</fileset>
<fileset dir="${others.dir}">
<include name="gson-2.2.2.jar" />
</fileset>
<pathelement location="${src.dir}" />
</path>
<target name="all"
depends="clean, compile, compile-to-javascript,create-jar,create-zip" />
<target name="clean">
<delete dir="${basedir}/gwt-unitCache" />
<delete dir="${build.output.dir}" />
<delete dir="${classes.dir}" />
<delete dir="${basedir}/html/SampleProfile" />
</target>
<target name="compile">
<mkdir dir="${classes.dir}" />
<javac srcdir="src" destdir="${classes.dir}" debug="${javac.debug}"
debuglevel="${javac.debuglevel}" optimize="${javac.optimize}"
deprecation="${javac.deprecation}" classpathref="project.class.path"
failonerror="true" memoryMaximumSize="512m" fork="true" />
</target>
<target name="compile-to-javascript" depends="compile"
description="GWT compile to JavaScript">
<mkdir dir="${build.output.dir}" />
<java failonerror="true" fork="true"
classname="com.google.gwt.dev.Compiler" classpathref="project.class.path">
<arg value="-war" />
<arg value="${build.output.dir}" />
<arg value="com.softwareag.centrasite.bui.profile.SampleProfile" />
<jvmarg value="-Xms1024m" />
</java>
</target>
<target name="create-jar" depends="compile"
description="create the jar by including the domain and server">
<jar destfile="classes/lib/SampleProfile.jar">
<fileset dir="classes"
excludes="**/client/** **/junit/** **/test/** **/lib/**" />
<manifest>
<section name="com/softwareag/centrasite/bui/profile/server">
<attribute name="Implementation-Title"
value="Rule for SampleProfile profile assertion" />
<attribute name="Implementation-Version"
value="${component.full.version}.${working.build.number}" />
<attribute name="Implementation-Vendor" value="Software AG" />
</section>
</manifest>
</jar>
</target>
<target name="create-zip" depends="compile,compile-to-javascript,create-jar"
description="Creating the computed profile zip">
<delete dir="html/SampleProfile" />
<copydir src="${build.output.dir}/SampleProfile"
dest="html/SampleProfile" />
<zip update="yes" basedir="." includes="META-INF/**"
destfile="${build.output.dir}/SampleProfile.zip" />
<zip update="yes" basedir="." includes="html/**, css/**, js/**"
destfile="${build.output.dir}/SampleProfile.zip" />
<zip update="yes" basedir="classes" includes="lib/**"
destfile="${build.output.dir}/SampleProfile.zip" />
</target>
</project>
The classpath for the build step must refer to all JAR files contained in the redist folder of the CentraSite installation. Add these JAR files to the build path of your java project also.
Implementation Guidelines for Computed Profile
This section does not explain all the details of the Java source file; its purpose is to indicate the code that must be modified to suit your environment.
src\com\softwareag\centrasite\bui\profile\server\SampleComputedProfileImpl.java
public class SampleComputedProfileImpl implements BUIProfile {
private static final String VIEW_PAGE_URL = "html/SampleProfile.html";
private static final String EDIT_PAGE_URL = "html/EditSampleProfile.html";
 
private CentraSiteRegistryObject csro;
private CentraSiteSession session;
private Locale locale;
 
@Override
public boolean canRenderUI() {
return true;
}
@Override
public Collection<ProfileAttribute> getProfileAttributes() {
return null;
}
@Override
public void init(Collection registryObjects, Locale locale) {
this.locale = locale;
if (registryObjects == null || registryObjects.isEmpty()) {
return;
}
 
Iterator iterator = registryObjects.iterator();
while (iterator.hasNext()) {
Object element = iterator.next();
if (element instanceof CentraSiteRegistryObject) {
csro = (CentraSiteRegistryObject) element;
} else if (element instanceof CentraSiteSession) {
this.session = (CentraSiteSession) element;
}
}
}
@Override
public Collection<CentraSiteRegistryObject> updateAsset() {
return null;
}
@Override
public Collection<CentraSiteRegistryObject> computeProfileData(String arg0)
throws Exception {
return null;
}
@Override
public String getProfileDataAsJson() throws Exception {
ArrayList<ComputedInfo> computedInfos = new ArrayList<ComputedInfo>(2);
computedInfos.add(new ComputedInfo("one", "One"));
computedInfos.add(new ComputedInfo("two", "Two"));

Gson gson = new Gson();
return gson.toJson(computedInfos);
}
@Override
public String getViewPageURL() {
return VIEW_PAGE_URL;
}
 
@Override
public String getEditPageURL() {
return EDIT_PAGE_URL;
}
}
The SampleComputedProfileImpl class implements the interface BUIProfile, which declares the basic rendering methods specific to the CentraSite Business UI.
Implementations
Description
boolean canRenderUI()
Determines whether the rendering is based on the UI (true) or on the triples associated with the profile (false).
Collection<ProfileAttribute> getProfileAttributes()
Returns a collection of ProfileAttribute and would be called only when canRenderUI() returns true.
void init(Collection registryObjects, Locale locale)
With CentraSiteRegistryObject as a parameter where the necessary implementation is done and updateAsset() which would return a collection of registry object serves as a save hook.

Collection<CentraSiteRegistry
Object> updateAsset()
Returns a collection of CentraSiteRegistryObject.
String getEditPageURL()
Returns URL of the edit page of computed profile and would be called only when canRenderUI() returns true.
String getViewPageURL()
Returns URL of the view page of computed profile and would be called only when canRenderUI() returns true.
String getProfileDataAsJson()
Returns a collection of profile data as JSON-formatted string.
Collection computeProfileData(String userInputsAsJSON)
Sets a collection of profile data as JSON-formatted string.
The following diagram describes the main methods on each of the two Java source files SampleComputedProfileImpl.java and computed.js and describes the type of functions that they serve.
#
Description
The getProfileDataAsJson method returns a collection of profile data as JSON-formatted string and would be called only when canRenderUI() returns true.
This method internally invokes the setJson function when trying to view or edit the computed profile asset.
The setJson method sets the JSON-formatted data representing the computed profile and would be called only when canRenderUI() returns true.
This method is invoked when trying to view or edit the computed profile asset.
The getJson method retrieves the JSON-formatted data representing the computed profile using a HTTP GET request and would be called only when canRenderUI() returns true.
This method is invoked when trying to save the updated asset.
The computedInfos method stores a collection of profile data as JSON-formatted string and would be called only when canRenderUI() returns true.
This method is internally invoked by the getJson function when trying to save the updated asset.
Here is the frame of the computed profile implementations:
\js\computed.js
/**
Function to resize the current profile frame
**/
var resize = function() {
parent.resizeFrame(profileId);
}
/**
Function to validate the given input
**/
var validate = function() {
return true;
}
/**
Main function which is triggered from the computed profile
infrastructure. Implementaion should be called from the function.
**/
var setJson = function(profileId, json, isView) {
window.jsonData = json;
window.sampleProfileId = profileId;
 
console.log("isView = " + isView)
 
try {
if (isView) {
renderSampleProfile();
} else {
editSampleProfile();
}
} catch(err) {
}
}
/**
Function to to indicate whether the current profile is modified or not
Custom implementation can be possible here
**/
var isModified = function() {
return false;
}
As mentioned above, in order to present a user-defined computed profile in the asset details page, HTML files (viewSampleProfile.html and editSampleProfile.html) that describe the GUI (in view or edit mode) must be located in the html directory.
\html\SampleProfile.html
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!-- -->
<!-- Consider inlining CSS to reduce the number of requested files -->
<!-- -->
<!--<link type="text/css" rel="stylesheet" href="SampleProfile.css">-->
<script type="text/javascript" language="javascript"
src="SampleProfile/SampleProfile.nocache.js">
</script>
<script src="../js/computed.js"></script>
</head>
The HTML file specifies the Java source files that are user-defined to render the asset details page in the appropriate view or edit mode.
\html\EditSampleProfile.html
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!-- -->
<!-- Consider inlining CSS to reduce the number of requested files -->
<!-- -->
<!--<link type="text/css" rel="stylesheet" href="SampleProfile.css">-->
<script type="text/javascript" language="javascript"
src="SampleProfile/SampleProfile.nocache.js"></script>
<script src="../js/computed.js"></script>
</head>
Assuming that you have set up all the Java files correctly in the directories, you should be able to build with the command:
ant -f build.xml jar all
This creates the profile specific JAR file in the subdirectory lib and archives the necessary profile files into the file SampleProfile.zip.
Structure of Archive File
The archive file must contain the following folders and files:
Sample Code
Your CentraSite installation contains a sample computed profile, SampleProfile (in the demos folder) that you can use to create an archive file for the computed profile specific to the CentraSite Business UI.
Load a Computed Profile into an Asset Type Definition
After you have created an archive file that contains the profile definition, you need to load the archive file into the asset type definition. You do this by starting the Edit Asset Type wizard for the appropriate asset type and specifying in the wizard that you are defining a new computed profile.
For details about how to load the archive file of a computed profile into an asset type definition, see CentraSite User’s Guide.
When you have loaded the archive file, the new profile is displayed in the detail page of all assets of the asset type.