Standard MO Log Table

The com.splwg.base.api.maintenanceObject.MaintenanceLogCHandlerHelper can be used for the Standard MO Log Table Change Handler validations.

The following standard validations are provided by this helper class:

  • Log entry cannot be deleted if of type:Created, Exception, Status Transition, Status Transition Error, System, User Details
  • Validates the characteristic value possibly stored on the log entry
  • Long description or message are required, but not both
  • User details must provide long description

The following default methods for Add are provided by this helper class:

  • Log dateTime to system date time
  • User to current system user
  • Log sequence to next highest number
  • Status to the parent entity's status (will warn if specified input differs from parent status)

To use the validations, create an instance of the helper class in the MO Change Handler and get the validation rules from the Helper. First you must create a new Characteristic Entity in the Characteristic Entity Lookup for your object. This entity can be selected on any Characteristic Type to indicate that that characteristic type can be used in the log messages for this log. Sample code follows.

Change Handler Sample Code


public class OutboundCrossReferenceMessageLog_CHandler extends AbstractChangeHandler<OutboundCrossReferenceMessageLog>
{
private final MaintenanceLogCHandlerHelper helper = new MaintenanceLogCHandlerHelper<OutboundCrossReferenceMessageLog,
OutboundCrossReferenceMessage>(new MaintenanceObject_Id("O2-OXREFMSG"), OutboundCrossReferenceMessageLog.properties,
OutboundCrossReferenceMessageLog.properties.lookOnParentOutboundCrossReferenceMessage(),
CharacteristicEntityLookup.constants.OUTBOUND_CROSS_REFERENCE_MESSAGE_LOG);
public void prepareToAdd(DataTransferObject<OutboundCrossReferenceMessageLog> newDTO)
{
helper.prepareToAdd(newDTO);     
}
public void prepareToChange(OutboundCrossReferenceMessageLog unchangedEntity, 
DataTransferObject<OutboundCrossReferenceMessageLog> newDTO) 
{
helper.prepareToChange(unchangedEntity, newDTO);     
}
public ValidationRule[] getValidationRules() 
{
return helper.getValidationRules();
}
} 

Change Handler Junit Test Code


public void testLongDescRequiredIfLogTypeIsUserDetails()
{
startChanges();
OutboundCrossReferenceMessage_DTO dto = (OutboundCrossReferenceMessage_DTO) createDTO(OutboundCrossReferenceMessage.class);
dto.setBusinessObjectId(new BusinessObject_Id("ZZ-OXREFBO"));
outXrefMsgTest.setDtoData(dto);
OutboundCrossReferenceMessage outboundCrossReferenceMessage = dto.newEntity();
OutboundCrossReferenceMessageLog_DTO outboundCrossReferenceMessageLogDto1 = (OutboundCrossReferenceMessageLog_DTO)
createDTO(OutboundCrossReferenceMessageLog.class);
outboundCrossReferenceMessageLogDto1.setLogEntryType(LogEntryTypeLookup.constants.USER_DETAILS);
try 
{
outboundCrossReferenceMessage.getLogs().add(outboundCrossReferenceMessageLogDto1, null);
saveChanges();
fail("An error should have been thrown");
}
catch (ApplicationError e)
{
verifyViolatedRule(MaintenanceLogCHandlerHelper
.longDescriptionIsRequiredIfLogTypeIsUserDetails
(OutboundCrossReferenceMessageLog.properties), e);         
}
}