use of org.opennms.netmgt.config.kscReports.Report in project opennms by OpenNMS.
the class KscRestService method addKscReport.
@POST
@Consumes(MediaType.APPLICATION_XML)
public Response addKscReport(@Context final UriInfo uriInfo, final KscReport kscReport) {
writeLock();
try {
LOG.debug("addKscReport: Adding KSC Report {}", kscReport);
Report report = m_kscReportFactory.getReportByIndex(kscReport.getId());
if (report != null) {
throw getException(Status.CONFLICT, "Invalid request: Existing KSC report found with ID: {}.", Integer.toString(kscReport.getId()));
}
report = new Report();
report.setId(kscReport.getId());
report.setTitle(kscReport.getLabel());
if (kscReport.getShowGraphtypeButton() != null) {
report.setShowGraphtypeButton(kscReport.getShowGraphtypeButton());
}
if (kscReport.getShowTimespanButton() != null) {
report.setShowTimespanButton(kscReport.getShowTimespanButton());
}
if (kscReport.getGraphsPerLine() != null) {
report.setGraphsPerLine(kscReport.getGraphsPerLine());
}
if (kscReport.hasGraphs()) {
for (KscGraph kscGraph : kscReport.getGraphs()) {
final Graph graph = kscGraph.buildGraph();
report.addGraph(graph);
}
}
m_kscReportFactory.addReport(report);
try {
m_kscReportFactory.saveCurrent();
} catch (final Exception e) {
throw getException(Status.BAD_REQUEST, e.getMessage());
}
return Response.created(getRedirectUri(uriInfo, kscReport.getId())).build();
} finally {
writeUnlock();
}
}
use of org.opennms.netmgt.config.kscReports.Report in project opennms by OpenNMS.
the class KscRestService method addGraph.
@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);
if (report == null) {
throw getException(Status.NOT_FOUND, "Invalid request: No KSC report found with ID: {}.", Integer.toString(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) {
LOG.debug("invalid timespan ('{}'), 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.INTERNAL_SERVER_ERROR, "Cannot save report with Id {} : {} ", kscReportId.toString(), e.getMessage());
}
return Response.noContent().build();
} finally {
writeUnlock();
}
}
use of org.opennms.netmgt.config.kscReports.Report in project opennms by OpenNMS.
the class RrdDashletConfigurationWindow method importKscReport.
/**
* Import the KSC report with the given name
*/
private void importKscReport(int reportId) {
Report report = kscPerformanceReportFactory.getReportByIndex(reportId);
int columns = report.getGraphsPerLine().orElse(1);
int rows = report.getGraphs().size() / columns;
if (rows == 0) {
rows = 1;
}
if (report.getGraphs().size() % columns > 0) {
rows++;
}
for (int y = 0; y < m_gridLayout.getRows(); y++) {
for (int x = 0; x < m_gridLayout.getColumns(); x++) {
if (x >= columns || y >= rows) {
m_gridLayout.removeComponent(x, y);
}
}
}
m_columnsSelect.setValue(columns);
m_rowsSelect.setValue(rows);
m_gridLayout.setColumns(columns);
m_gridLayout.setRows(rows);
int timeFrameValue = 1;
int timeFrameType = Calendar.HOUR;
int i = 0;
for (int y = 0; y < m_gridLayout.getRows(); y++) {
for (int x = 0; x < m_gridLayout.getColumns(); x++) {
if (m_gridLayout.getComponent(x, y) == null) {
RrdGraphEntry rrdGraphEntry = new RrdGraphEntry(m_nodeDao, m_rrdGraphHelper, x, y);
rrdGraphEntry.setPreviewTimeFrame(timeFrameType, timeFrameValue);
m_gridLayout.addComponent(rrdGraphEntry, x, y);
}
RrdGraphEntry rrdGraphEntry = (RrdGraphEntry) m_gridLayout.getComponent(x, y);
/**
* setting the values if defined in the KSC report
*/
if (i < report.getGraphs().size()) {
final int index = i;
setRrdGraphEntryFromKscReportGraph(rrdGraphEntry, report.getGraphs().get(index));
}
rrdGraphEntry.update();
i++;
}
}
}
use of org.opennms.netmgt.config.kscReports.Report in project opennms by OpenNMS.
the class KSC_PerformanceReportFactory method getReportList.
/**
* <p>getReportList</p>
*
* @return a {@link java.util.Map} object.
*/
public Map<Integer, String> getReportList() {
LinkedHashMap<Integer, String> reports = new LinkedHashMap<Integer, String>(m_config.getReports().size());
List<Report> reportList = m_config.getReports();
Collections.sort(reportList, new Comparator<Report>() {
@Override
public int compare(Report o1, Report o2) {
return o1.getTitle().compareTo(o2.getTitle());
}
});
for (Report report : reportList) {
reports.put(report.getId().get(), report.getTitle());
}
return Collections.unmodifiableMap(reports);
}
use of org.opennms.netmgt.config.kscReports.Report in project opennms by OpenNMS.
the class KSC_PerformanceReportFactory method deleteReportAndSave.
/**
* Deletes the indexed report and updates file configuration
*
* @param index a int.
* @throws java.lang.ArrayIndexOutOfBoundsException if any.
* @throws java.io.IOException if any.
* @throws java.io.FileNotFoundException if any.
*/
public void deleteReportAndSave(int index) throws ArrayIndexOutOfBoundsException, IOException, FileNotFoundException {
Report report = getReportByIndex(index);
if (report == null) {
throw new ArrayIndexOutOfBoundsException("Reports List index to be deleted is out of bounds: " + index);
}
m_config.removeReport(report);
saveCurrent();
}
Aggregations