Search in sources :

Example 1 with EventTypeEnum

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();
}
Also used : ArrayList(java.util.ArrayList) MonitorException(nl.nn.adapterframework.monitoring.MonitorException) MonitorManager(nl.nn.adapterframework.monitoring.MonitorManager) Monitor(nl.nn.adapterframework.monitoring.Monitor) EventTypeEnum(nl.nn.adapterframework.monitoring.EventTypeEnum) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Aggregations

ArrayList (java.util.ArrayList)1 RolesAllowed (javax.annotation.security.RolesAllowed)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 EventTypeEnum (nl.nn.adapterframework.monitoring.EventTypeEnum)1 Monitor (nl.nn.adapterframework.monitoring.Monitor)1 MonitorException (nl.nn.adapterframework.monitoring.MonitorException)1 MonitorManager (nl.nn.adapterframework.monitoring.MonitorManager)1