use of nl.nn.adapterframework.monitoring.EventTypeEnum in project iaf by ibissource.
the class ShowMonitors method addMonitor.
@SuppressWarnings("unchecked")
@POST
@RolesAllowed({ "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/monitors")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response addMonitor(LinkedHashMap<String, Object> json) throws ApiException {
initBase(servletConfig);
String name = null;
EventTypeEnum type = null;
ArrayList<String> destinations = new ArrayList<String>();
for (Entry<String, Object> entry : json.entrySet()) {
String key = entry.getKey();
if (key.equalsIgnoreCase("name")) {
name = entry.getValue().toString();
}
if (key.equalsIgnoreCase("type")) {
type = EventTypeEnum.getEnum(entry.getValue().toString());
}
if (key.equalsIgnoreCase("destinations")) {
try {
destinations.addAll((ArrayList<String>) entry.getValue());
} catch (Exception e) {
throw new ApiException("Failed to parse destinations!");
}
}
}
if (name == null)
throw new ApiException("Name not set!");
if (type == null)
throw new ApiException("Type not set!");
MonitorManager mm = MonitorManager.getInstance();
Monitor monitor = new Monitor();
monitor.setName(name);
monitor.setTypeEnum(type);
// Check if destination is set, and if it actually exists...
if (destinations != null && destinations.size() > 0) {
List<String> tmp = new ArrayList<String>();
for (Iterator<String> i = destinations.iterator(); i.hasNext(); ) {
String destination = (String) i.next();
if (mm.getDestination(destination) != null) {
tmp.add(destination);
}
}
String[] result = new String[tmp.size()];
result = (String[]) tmp.toArray(result);
monitor.setDestinations(result);
}
mm.addMonitor(monitor);
return Response.status(Response.Status.CREATED).build();
}
Aggregations