}
public AlertRest alertToDomain(Alert al, UriInfo uriInfo, boolean slim) {
AlertRest ret = new AlertRest();
ret.setId(al.getId());
AlertDefinition alertDefinition = al.getAlertDefinition();
ret.setName(alertDefinition.getName());
AlertDefinitionRest alertDefinitionRest;
if (slim) {
alertDefinitionRest = new AlertDefinitionRest(alertDefinition.getId());
} else {
AlertDefinitionHandlerBean adhb = new AlertDefinitionHandlerBean();
alertDefinitionRest = adhb.definitionToDomain(alertDefinition, false, uriInfo);
}
ret.setAlertDefinition(alertDefinitionRest);
ret.setDefinitionEnabled(alertDefinition.getEnabled());
if (al.getAcknowledgingSubject()!=null) {
ret.setAckBy(al.getAcknowledgingSubject());
ret.setAckTime(al.getAcknowledgeTime());
}
ret.setAlertTime(al.getCtime());
ret.setDescription(alertManager.prettyPrintAlertConditions(al,false));
ret.setRecoveryTime(al.getRecoveryTime());
Resource r = fetchResource(alertDefinition.getResource().getId());
ResourceWithType rwt;
if (slim) {
rwt = new ResourceWithType(r.getName(),r.getId());
} else {
rwt = fillRWT(r,uriInfo);
}
ret.setResource(rwt);
// add some links
UriBuilder builder = uriInfo.getBaseUriBuilder();
builder.path("/alert/{id}/conditions");
URI uri = builder.build(al.getId());
Link link = new Link("conditions",uri.toString());
ret.addLink(link);
builder = uriInfo.getBaseUriBuilder();
builder.path("/alert/{id}/notifications");
uri = builder.build(al.getId());
link = new Link("notification",uri.toString());
ret.addLink(link);
builder = uriInfo.getBaseUriBuilder();
builder.path("/alert/{id}/definition");
uri = builder.build(al.getId());
link = new Link("definition",uri.toString());
ret.addLink(link);
int resourceId = alertDefinition.getResource().getId();
ret.addLink(createUILink(uriInfo,UILinkTemplate.RESOURCE_ALERT,resourceId,al.getId()));
return ret;
}