}
AlertDefinitionRest definitionToDomain(AlertDefinition def, boolean full, UriInfo uriInfo) {
AlertDefinitionRest adr = new AlertDefinitionRest(def.getId());
adr.setName(def.getName());
adr.setEnabled(def.getEnabled());
adr.setPriority(def.getPriority().getName());
adr.setConditionMode(def.getConditionExpression().toString());
adr.setRecoveryId(def.getRecoveryId());
if (full) {
Set<AlertCondition> conditions = def.getConditions();
if (conditions.size() > 0) {
List<AlertConditionRest> conditionRestList = new ArrayList<AlertConditionRest>(conditions.size());
for (AlertCondition condition : conditions) {
AlertConditionRest acr = conditionToConditionRest(condition);
conditionRestList.add(acr);
}
adr.setConditions(conditionRestList);
}
List<AlertNotification> notifications = def.getAlertNotifications();
if (notifications.size() > 0) {
List<AlertNotificationRest> notificationRestList = new ArrayList<AlertNotificationRest>(notifications.size());
for (AlertNotification notification : notifications) {
AlertNotificationRest anr = notificationToNotificationRest(notification);
notificationRestList.add(anr);
}
adr.setNotifications(notificationRestList);
}
}
AlertDampening dampening = def.getAlertDampening();
adr.setDampeningCategory(dampening.getCategory().name());
if (dampening.getCategory()== AlertDampening.Category.NONE && def.getWillRecover()) {
adr.setDampeningCategory(AlertDampening.Category.ONCE.name());
}
AlertDampening.TimeUnits units = dampening.getValueUnits();
String s = units != null ? " " + units.name() : "";
adr.setDampeningCount(dampening.getValue());
units = dampening.getPeriodUnits();
s = units != null ? " " + units.name() : "";
adr.setDampeningPeriod(dampening.getPeriod());
if (dampening.getPeriodUnits()!=null) {
adr.setDampeningUnit(dampening.getPeriodUnits().name());
}
List<Link> links = adr.getLinks();
if (def.getResource()!=null) {
links.add(createUILink(uriInfo, UILinkTemplate.RESOURCE_ALERT_DEF, def.getResource().getId(), adr.getId()));
links.add(getLinkToResource(def.getResource(), uriInfo, "resource"));
} else if (def.getGroup() != null) {
links.add(
createUILink(uriInfo, UILinkTemplate.GROUP_ALERT_DEF, def.getGroup().getId(), adr.getId()));
links.add(getLinkToGroup(def.getGroup(), uriInfo, "group"));
} else {
links.add(
createUILink(uriInfo, UILinkTemplate.TEMPLATE_ALERT_DEF, def.getResourceType().getId(), adr.getId()));
links.add(getLinkToResourceType(def.getResourceType(),uriInfo,"resourceType"));
}
return adr;
}