Data Management Capabilities > Managing Change > Change Management Administration > Converting Simple Text Attribute to Rich Text Attribute > Customizing the Simple Text to Rich Text Conversion Utility > Sample Code
  
Sample Code
In the given example, CustomChangeOrder is a modeled subtype of WTChangeOrder2. CustomChangeOrder is modified to include a rich text attribute longDescription. Additionally, a simple text attribute myAttribute and the corresponding rich text attribute myLongAttribute are added in the modeled subtype. To convert the simple text description attributes, such as description and myAttribute, to rich text description attribute, such as longDescription and myLongAttribute, the CustomChangeOrderDelegate delegate is created as given:
package com.myCompany;
public class CustomChangeOrderDelegate extends ChangeItemRichTextConverterDelegate
{
private static final Logger classLogger = LogR.getLogger(ChangeSimpleToRichTextUtility.class.getName());

/**
* This method returns a concrete class, that is a model class, which implements wt.change2.ChangeItem or wt.maturity.PromotionNotice.
*
* @return class for which the delegate is implemented.
*/
@Override
public Class getTargetClass()
{
return CustomChangeOrder.class;
}

/**
* This method returns an unmodifiable map. Each entry in the map contains key as the source attribute, which is the
* simple text, and value as the target attribute, which is the rich text. The map should not be blank.
*
* @return collection of source and destination attributes for conversion
*/
@Override
public Map<String, String> getAttributesForConversion()
{
Map<String, String> srcAndDestAttributesMap = new HashMap<>(2);
srcAndDestAttributesMap.put(CustomChangeOrder.DESCRIPTION, CustomChangeOrder.LONG_DESCRIPTION);
srcAndDestAttributesMap.put(CustomChangeOrder.myAttribute, CustomChangeOrder.LONG_myAttribute);
return Collections.unmodifiableMap(srcAndDestAttributesMap);
}

/**
* This method copies or moves the attributes. The method prevents conversion
* if source attribute value is blank. If cleanSource flag is true, source attribute is set to null.
*
* @param persistable
* @param cleanSource
* @throws WTPropertyVetoException
* @return true if conversion was successful or false if conversion was not performed or was unsuccessful.
*/
@Override
public boolean convert(Persistable persistable, boolean cleanSource) throws WTPropertyVetoException {
boolean isConversionSucessful = false, areSourceAttributesNull = true;
if (persistable instanceof CustomChangeOrder) {
CustomChangeOrder changeNotice = (CustomChangeOrder) persistable;
String description = changeNotice.getDescription();
if (StringUtils.isNotBlank(description)) {
changeNotice.setLongDescription(getRichText(description));
if (cleanSource) {
changeNotice.setDescription(null);
}
isConversionSucessful = true;
areSourceAttributesNull = false;
}

String myAttribute = changeNotice.getMyAttribute();
if (StringUtils.isNotBlank(myAttribute)) {
changeNotice.setLongMyAttribute(getRichText(myAttribute));
if (cleanSource) {
changeNotice.setMyAttribute(null);
}
isConversionSucessful = true;
areSourceAttributesNull = false;
}
if (areSourceAttributesNull && classLogger.isDebugEnabled()) {
classLogger.debug("The source attributes, description and myAttribute, are blank for customChangeOrder:"
+ changeNotice.getNumber() + " " + changeNotice.getName()
+ ". Simple to rich text conversion was not performed for this object.");
}
}
else if (classLogger.isDebugEnabled()) {
classLogger
.debug("The persistable class is not an instance of CustomChangeOrder. The persistable class is:"
+ persistable.getClass().getName()
+ ". Simple to rich text conversion was not performed for this object.");
}
return isConversionSucessful;
}
}
The CustomChangeOrderDelegate class is registered as given:
<service context="default" name="wt.change2.converter.richtext.ChangeRichTextConverterDelegate">
<Option serviceClass="com.myCompany.CustomChangeOrderDelegate"
requestor="wt.change2.ChangeItem"
selector="customChangeOrder"
cardinality="singleton"/>
</Service>