Example

This default groovy script calculates the risk:

import com..dal.model.*
import com..survey.asset.*
import com..common.*
public class DefaultRiskUpdater implements EntityScriptUpdater{
public void updateEntity(Asset asset) throws ALException {
if (asset==null) return;
// calculate the risk
if (asset.getLikelihood()!=null && asset.getImpact()!=null) {
float risk = (float) (asset.getLikelihood() * asset.getImpact());
asset.setRisk(risk);
}
}
}

This custom groovy script illustrates a more comprehensive example:

package com..risk
import com..dal.dao.*
import com..dal.model.*
import com..survey.asset.*
import com..common.*
public class DefaultRiskUpdater implements EntityScriptUpdater{
public void updateEntity(Asset asset) throws ALException {
if (asset==null) return;
// calculate the risk
if (asset.getLikelihood()!=null && asset.getImpact()!=null) {
float risk = (float) (asset.getLikelihood() * asset.getImpact());
asset.setRisk(risk);
}
if(asset.getIncident() != null &&
asset.getCustomAttributes() != null &&
asset.getCustomAttributes.getString1() != null) {
Incident incident = asset.getIncident();
if (incident.getCustomAttributes()==null) {
CustomAttributes attr = new CustomAttributes();
new CustomAttributesDAO().save(attr);
incident.setCustomAttributes(attr);
}
asset.getIncident().getCustomAttributes()
.setString1(asset.getCustomAttributes().getString1());
}
}
}