@Test public void testAddGraph() throws Exception { final Map<String, String> params = new HashMap<String, String>(); params.put("title", "foo"); params.put("reportName", "bar"); params.put("resourceId", "baz"); sendRequest(PUT, "/ksc/0", params, 303, "/ksc/0"); final String xml = slurp(m_configFile); assertTrue(xml.contains("title=\"foo\"")); }
@PUT @Path("{kscReportId}") @Transactional public Response addGraph(@PathParam("kscReportId") final Integer kscReportId, @QueryParam("title") final String title, @QueryParam("reportName") final String reportName, @QueryParam("resourceId") final String resourceId, @QueryParam("timespan") String timespan) { writeLock(); try { if (kscReportId == null || reportName == null || reportName == "" || resourceId == null || resourceId == "") { throw getException(Status.BAD_REQUEST, "Invalid request: reportName and resourceId cannot be empty!"); } final Report report = m_kscReportFactory.getReportByIndex(kscReportId); final Graph graph = new Graph(); if (title != null) { graph.setTitle(title); } boolean found = false; for (final String valid : KSC_PerformanceReportFactory.TIMESPAN_OPTIONS) { if (valid.equals(timespan)) { found = true; break; } } if (!found) { LogUtils.debugf(this, "invalid timespan ('%s'), setting to '7_day' instead.", timespan); timespan = "7_day"; } graph.setGraphtype(reportName); graph.setResourceId(resourceId); graph.setTimespan(timespan); report.addGraph(graph); m_kscReportFactory.setReport(kscReportId, report); try { m_kscReportFactory.saveCurrent(); } catch (final Exception e) { throw getException(Status.BAD_REQUEST, e.getMessage()); } return Response.seeOther(getRedirectUri(m_uriInfo)).build(); } finally { writeUnlock(); } }
KscRestService extends OnmsRestService { @PUT @Path("{kscReportId}") @Transactional public Response addGraph(@PathParam("kscReportId") final Integer kscReportId, @QueryParam("title") final String title, @QueryParam("reportName") final String reportName, @QueryParam("resourceId") final String resourceId, @QueryParam("timespan") String timespan) { writeLock(); try { if (kscReportId == null || reportName == null || reportName == "" || resourceId == null || resourceId == "") { throw getException(Status.BAD_REQUEST, "Invalid request: reportName and resourceId cannot be empty!"); } final Report report = m_kscReportFactory.getReportByIndex(kscReportId); final Graph graph = new Graph(); if (title != null) { graph.setTitle(title); } boolean found = false; for (final String valid : KSC_PerformanceReportFactory.TIMESPAN_OPTIONS) { if (valid.equals(timespan)) { found = true; break; } } if (!found) { LogUtils.debugf(this, "invalid timespan ('%s'), setting to '7_day' instead.", timespan); timespan = "7_day"; } graph.setGraphtype(reportName); graph.setResourceId(resourceId); graph.setTimespan(timespan); report.addGraph(graph); m_kscReportFactory.setReport(kscReportId, report); try { m_kscReportFactory.saveCurrent(); } catch (final Exception e) { throw getException(Status.BAD_REQUEST, e.getMessage()); } return Response.seeOther(getRedirectUri(m_uriInfo)).build(); } finally { writeUnlock(); } } }
KscRestService extends OnmsRestService { @PUT @Path("{kscReportId}") @Transactional public Response addGraph(@PathParam("kscReportId") final Integer kscReportId, @QueryParam("title") final String title, @QueryParam("reportName") final String reportName, @QueryParam("resourceId") final String resourceId, @QueryParam("timespan") String timespan) { writeLock(); try { if (kscReportId == null || reportName == null || reportName == "" || resourceId == null || resourceId == "") { throw getException(Status.BAD_REQUEST, "Invalid request: reportName and resourceId cannot be empty!"); } final Report report = m_kscReportFactory.getReportByIndex(kscReportId); final Graph graph = new Graph(); if (title != null) { graph.setTitle(title); } boolean found = false; for (final String valid : KSC_PerformanceReportFactory.TIMESPAN_OPTIONS) { if (valid.equals(timespan)) { found = true; break; } } if (!found) { LogUtils.debugf(this, "invalid timespan ('%s'), setting to '7_day' instead.", timespan); timespan = "7_day"; } graph.setGraphtype(reportName); graph.setResourceId(resourceId); graph.setTimespan(timespan); report.addGraph(graph); m_kscReportFactory.setReport(kscReportId, report); try { m_kscReportFactory.saveCurrent(); } catch (final Exception e) { throw getException(Status.BAD_REQUEST, e.getMessage()); } return Response.seeOther(getRedirectUri(m_uriInfo)).build(); } finally { writeUnlock(); } }  }
KscRestService extends OnmsRestService { @PUT @Path("{kscReportId}") @Transactional public Response addGraph(@PathParam("kscReportId") final Integer kscReportId, @QueryParam("title") final String title, @QueryParam("reportName") final String reportName, @QueryParam("resourceId") final String resourceId, @QueryParam("timespan") String timespan) { writeLock(); try { if (kscReportId == null || reportName == null || reportName == "" || resourceId == null || resourceId == "") { throw getException(Status.BAD_REQUEST, "Invalid request: reportName and resourceId cannot be empty!"); } final Report report = m_kscReportFactory.getReportByIndex(kscReportId); final Graph graph = new Graph(); if (title != null) { graph.setTitle(title); } boolean found = false; for (final String valid : KSC_PerformanceReportFactory.TIMESPAN_OPTIONS) { if (valid.equals(timespan)) { found = true; break; } } if (!found) { LogUtils.debugf(this, "invalid timespan ('%s'), setting to '7_day' instead.", timespan); timespan = "7_day"; } graph.setGraphtype(reportName); graph.setResourceId(resourceId); graph.setTimespan(timespan); report.addGraph(graph); m_kscReportFactory.setReport(kscReportId, report); try { m_kscReportFactory.saveCurrent(); } catch (final Exception e) { throw getException(Status.BAD_REQUEST, e.getMessage()); } return Response.seeOther(getRedirectUri(m_uriInfo)).build(); } finally { writeUnlock(); } }  @GET @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML}) @Transactional KscReportCollection getReports(); @GET @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML}) @Path("{reportId}") @Transactional KscReport getReport(@PathParam("reportId") final Integer reportId); @GET @Produces(MediaType.TEXT_PLAIN) @Path("count") @Transactional String getCount(); @PUT @Path("{kscReportId}") @Transactional Response addGraph(@PathParam("kscReportId") final Integer kscReportId, @QueryParam("title") final String title, @QueryParam("reportName") final String reportName, @QueryParam("resourceId") final String resourceId, @QueryParam("timespan") String timespan); }
KscRestService extends OnmsRestService { @PUT @Path("{kscReportId}") @Transactional public Response addGraph(@PathParam("kscReportId") final Integer kscReportId, @QueryParam("title") final String title, @QueryParam("reportName") final String reportName, @QueryParam("resourceId") final String resourceId, @QueryParam("timespan") String timespan) { writeLock(); try { if (kscReportId == null || reportName == null || reportName == "" || resourceId == null || resourceId == "") { throw getException(Status.BAD_REQUEST, "Invalid request: reportName and resourceId cannot be empty!"); } final Report report = m_kscReportFactory.getReportByIndex(kscReportId); final Graph graph = new Graph(); if (title != null) { graph.setTitle(title); } boolean found = false; for (final String valid : KSC_PerformanceReportFactory.TIMESPAN_OPTIONS) { if (valid.equals(timespan)) { found = true; break; } } if (!found) { LogUtils.debugf(this, "invalid timespan ('%s'), setting to '7_day' instead.", timespan); timespan = "7_day"; } graph.setGraphtype(reportName); graph.setResourceId(resourceId); graph.setTimespan(timespan); report.addGraph(graph); m_kscReportFactory.setReport(kscReportId, report); try { m_kscReportFactory.saveCurrent(); } catch (final Exception e) { throw getException(Status.BAD_REQUEST, e.getMessage()); } return Response.seeOther(getRedirectUri(m_uriInfo)).build(); } finally { writeUnlock(); } }  @GET @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML}) @Transactional KscReportCollection getReports(); @GET @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML}) @Path("{reportId}") @Transactional KscReport getReport(@PathParam("reportId") final Integer reportId); @GET @Produces(MediaType.TEXT_PLAIN) @Path("count") @Transactional String getCount(); @PUT @Path("{kscReportId}") @Transactional Response addGraph(@PathParam("kscReportId") final Integer kscReportId, @QueryParam("title") final String title, @QueryParam("reportName") final String reportName, @QueryParam("resourceId") final String resourceId, @QueryParam("timespan") String timespan);  }