use of org.springframework.orm.ObjectRetrievalFailureException in project opennms by OpenNMS.
the class CustomViewController method handleRequestInternal.
/** {@inheritDoc} */
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
String[] requiredParameters = new String[] { "report", "type" };
// Get Form Variable
int reportId = -1;
String reportType = WebSecurityUtils.sanitizeString(request.getParameter(Parameters.type.toString()));
String reportIdString = WebSecurityUtils.sanitizeString(request.getParameter(Parameters.report.toString()));
if (reportType == null) {
throw new MissingParameterException(Parameters.type.toString(), requiredParameters);
}
if (reportIdString == null) {
throw new MissingParameterException(Parameters.report.toString(), requiredParameters);
}
if (reportType.equals("node") || reportType.equals("custom")) {
reportId = WebSecurityUtils.safeParseInt(reportIdString);
}
String overrideTimespan = WebSecurityUtils.sanitizeString(request.getParameter(Parameters.timespan.toString()));
if ("null".equals(overrideTimespan) || "none".equals(overrideTimespan)) {
overrideTimespan = null;
}
String overrideGraphType = WebSecurityUtils.sanitizeString(request.getParameter(Parameters.graphtype.toString()));
if ("null".equals(overrideGraphType) || "none".equals(overrideGraphType)) {
overrideGraphType = null;
}
// Load report to view
Report report = null;
if ("node".equals(reportType)) {
LOG.debug("handleRequestInternal: buildNodeReport(reportId) {}", reportId);
report = getKscReportService().buildNodeReport(reportId);
} else if ("nodeSource".equals(reportType)) {
LOG.debug("handleRequestInternal: buildNodeSourceReport(nodeSource) {}", reportIdString);
report = getKscReportService().buildNodeSourceReport(reportIdString);
} else if ("domain".equals(reportType)) {
LOG.debug("handleRequestInternal: buildDomainReport(reportIdString) {}", reportIdString);
report = getKscReportService().buildDomainReport(reportIdString);
} else if ("custom".equals(reportType)) {
LOG.debug("handleRequestInternal: getReportByIndex(reportId) {}", reportId);
report = m_kscReportFactory.getReportByIndex(reportId);
if (report == null) {
throw new ServletException("Report could not be found in config file for index '" + reportId + "'");
}
} else {
throw new IllegalArgumentException("value to 'type' parameter of '" + reportType + "' is not supported. Must be one of: node, nodeSource, domain, or custom");
}
// Get the list of available prefabricated graph options
Map<String, OnmsResource> resourceMap = new HashMap<String, OnmsResource>();
Set<PrefabGraph> prefabGraphs = new TreeSet<PrefabGraph>();
if (removeBrokenGraphsFromReport(report) && reportId > -1) {
m_kscReportFactory.setReport(reportId, report);
m_kscReportFactory.saveCurrent();
EventBuilder eb = new EventBuilder(EventConstants.KSC_REPORT_UPDATED_UEI, "Web UI");
eb.addParam(EventConstants.PARAM_REPORT_TITLE, report.getTitle() == null ? "Report #" + report.getId() : report.getTitle());
eb.addParam(EventConstants.PARAM_REPORT_GRAPH_COUNT, report.getGraphs().size());
try {
Util.createEventProxy().send(eb.getEvent());
} catch (Throwable e) {
LOG.error("Can't send event " + eb.getEvent(), e);
}
}
List<Graph> graphCollection = report.getGraphs();
if (!graphCollection.isEmpty()) {
for (Graph graph : graphCollection) {
final OnmsResource resource = getKscReportService().getResourceFromGraph(graph);
resourceMap.put(graph.toString(), resource);
if (resource == null) {
LOG.debug("Could not get resource for graph {} in report {}", graph, report.getTitle());
} else {
prefabGraphs.addAll(Arrays.asList(getResourceService().findPrefabGraphsForResource(resource)));
}
}
}
List<KscResultSet> resultSets = new ArrayList<KscResultSet>(report.getGraphs().size());
for (Graph graph : graphCollection) {
OnmsResource resource = resourceMap.get(graph.toString());
if (resource != null) {
promoteResourceAttributesIfNecessary(resource);
}
String displayGraphType;
if (overrideGraphType == null) {
displayGraphType = graph.getGraphtype();
} else {
displayGraphType = overrideGraphType;
}
PrefabGraph displayGraph;
try {
displayGraph = getResourceService().getPrefabGraph(displayGraphType);
} catch (ObjectRetrievalFailureException e) {
LOG.debug("The prefabricated graph '{}' does not exist: {}", displayGraphType, e, e);
displayGraph = null;
}
boolean foundGraph = false;
if (resource != null) {
for (PrefabGraph availableGraph : getResourceService().findPrefabGraphsForResource(resource)) {
if (availableGraph.equals(displayGraph)) {
foundGraph = true;
break;
}
}
}
if (!foundGraph) {
displayGraph = null;
}
// gather start/stop time information
String displayTimespan = null;
if (overrideTimespan == null) {
displayTimespan = graph.getTimespan();
} else {
displayTimespan = overrideTimespan;
}
Calendar beginTime = Calendar.getInstance();
Calendar endTime = Calendar.getInstance();
KSC_PerformanceReportFactory.getBeginEndTime(displayTimespan, beginTime, endTime);
KscResultSet resultSet = new KscResultSet(graph.getTitle(), beginTime.getTime(), endTime.getTime(), resource, displayGraph);
resultSets.add(resultSet);
}
ModelAndView modelAndView = new ModelAndView("KSC/customView");
modelAndView.addObject("loggedIn", request.getRemoteUser() != null);
modelAndView.addObject("reportType", reportType);
if (report != null) {
modelAndView.addObject("report", reportIdString);
}
modelAndView.addObject("title", report.getTitle());
modelAndView.addObject("resultSets", resultSets);
if (report.getShowTimespanButton().orElse(false)) {
if (overrideTimespan == null || !getKscReportService().getTimeSpans(true).containsKey(overrideTimespan)) {
modelAndView.addObject("timeSpan", "none");
} else {
modelAndView.addObject("timeSpan", overrideTimespan);
}
modelAndView.addObject("timeSpans", getKscReportService().getTimeSpans(true));
} else {
// Make sure it's null so the pulldown list isn't shown
modelAndView.addObject("timeSpan", null);
}
if (report.getShowGraphtypeButton().orElse(false)) {
LinkedHashMap<String, String> graphTypes = new LinkedHashMap<String, String>();
graphTypes.put("none", "none");
for (PrefabGraph graphOption : prefabGraphs) {
graphTypes.put(graphOption.getName(), graphOption.getName());
}
if (overrideGraphType == null || !graphTypes.containsKey(overrideGraphType)) {
modelAndView.addObject("graphType", "none");
} else {
modelAndView.addObject("graphType", overrideGraphType);
}
modelAndView.addObject("graphTypes", graphTypes);
} else {
// Make sure it's null so the pulldown list isn't shown
modelAndView.addObject("graphType", null);
}
modelAndView.addObject("showCustomizeButton", (request.isUserInRole(Authentication.ROLE_ADMIN) || !request.isUserInRole(Authentication.ROLE_READONLY)) && (request.getRemoteUser() != null));
if (report.getGraphsPerLine() != null && report.getGraphsPerLine().get() > 0) {
modelAndView.addObject("graphsPerLine", report.getGraphsPerLine());
} else {
modelAndView.addObject("graphsPerLine", getDefaultGraphsPerLine());
}
return modelAndView;
}
use of org.springframework.orm.ObjectRetrievalFailureException in project opennms by OpenNMS.
the class CustomViewController method removeBrokenGraphsFromReport.
// Returns true if the report was modified due to invalid resource IDs.
private boolean removeBrokenGraphsFromReport(Report report) {
for (Iterator<Graph> itr = report.getGraphs().iterator(); itr.hasNext(); ) {
Graph graph = itr.next();
try {
OnmsResource r = getKscReportService().getResourceFromGraph(graph);
if (r == null) {
LOG.error("Removing graph '{}' in KSC report '{}' because the resource it refers to could not be found. Perhaps resource '{}' (or its ancestor) referenced by this graph no longer exists?", graph.getTitle(), report.getTitle(), graph.getResourceId());
itr.remove();
return true;
}
} catch (ObjectRetrievalFailureException orfe) {
LOG.error("Removing graph '{}' in KSC report '{}' because the resource it refers to could not be found. Perhaps resource '{}' (or its ancestor) referenced by this graph no longer exists?", graph.getTitle(), report.getTitle(), graph.getResourceId());
itr.remove();
return true;
} catch (Throwable e) {
LOG.error("Unexpected error while scanning through graphs in report: {}", e.getMessage(), e);
itr.remove();
return true;
}
}
return false;
}
use of org.springframework.orm.ObjectRetrievalFailureException in project opennms by OpenNMS.
the class GenericIndexResourceType method createTypes.
protected static Map<String, GenericIndexResourceType> createTypes(Map<String, ResourceType> configuredResourceTypes, ResourceStorageDao resourceStorageDao) {
Map<String, GenericIndexResourceType> resourceTypes = Maps.newLinkedHashMap();
List<ResourceType> resourceTypeList = new LinkedList<ResourceType>(configuredResourceTypes.values());
Collections.sort(resourceTypeList, new Comparator<ResourceType>() {
@Override
public int compare(ResourceType r0, ResourceType r1) {
// Sort by resource label, allowing the resource label to be null
final Comparator<? super String> comparator = (a, b) -> a.compareTo(b);
return Objects.compare(r0.getLabel(), r1.getLabel(), Comparator.nullsLast(comparator));
}
});
for (ResourceType resourceType : resourceTypeList) {
String className = resourceType.getStorageStrategy().getClazz();
Class<?> cinst;
try {
cinst = Class.forName(className);
} catch (ClassNotFoundException e) {
throw new ObjectRetrievalFailureException(StorageStrategy.class, className, "Could not load class '" + className + "' for resource type '" + resourceType.getName() + "'", e);
}
StorageStrategy storageStrategy;
try {
storageStrategy = (StorageStrategy) cinst.newInstance();
} catch (InstantiationException e) {
throw new ObjectRetrievalFailureException(StorageStrategy.class, className, "Could not instantiate class '" + className + "' for resource type '" + resourceType.getName() + "'", e);
} catch (IllegalAccessException e) {
throw new ObjectRetrievalFailureException(StorageStrategy.class, className, "Could not instantiate class '" + className + "' for resource type '" + resourceType.getName() + "'", e);
}
storageStrategy.setResourceTypeName(resourceType.getName());
GenericIndexResourceType genericIndexResourceType = new GenericIndexResourceType(resourceStorageDao, resourceType.getName(), resourceType.getLabel(), resourceType.getResourceLabel(), storageStrategy);
resourceTypes.put(genericIndexResourceType.getName(), genericIndexResourceType);
}
return resourceTypes;
}
use of org.springframework.orm.ObjectRetrievalFailureException in project opennms by OpenNMS.
the class DefaultSurveillanceService method createNodePageUrl.
/*
* This creates a relative url to the node list page and sets the category
* parameters to show the categories for this cell.
* FIXME: this code should move to the jsp after the status table is
* enhanced to support this requirement.
*/
private String createNodePageUrl(final SurveillanceView view, final int colIndex, final int rowIndex) {
Set<OnmsCategory> columns = Collections.emptySet();
Set<OnmsCategory> rows = Collections.emptySet();
try {
columns = view.getCategoriesForColumn(colIndex);
} catch (final ObjectRetrievalFailureException e) {
LOG.warn("An error occurred while getting categories for view {}, column {}", view, colIndex);
}
try {
rows = view.getCategoriesForRow(rowIndex);
} catch (final ObjectRetrievalFailureException e) {
LOG.warn("An error occurred while getting categories for view {}, row {}", view, rowIndex);
}
final List<String> params = new ArrayList<String>(columns.size() + rows.size());
for (final OnmsCategory category : columns) {
params.add("category1=" + Util.encode(category.getName()));
}
for (final OnmsCategory category : rows) {
params.add("category2=" + Util.encode(category.getName()));
}
params.add("nodesWithDownAggregateStatus=true");
return "element/nodeList.htm?" + StringUtils.collectionToDelimitedString(params, "&");
}
use of org.springframework.orm.ObjectRetrievalFailureException in project opennms by OpenNMS.
the class DefaultSiteStatusViewService method getCategoriesForRowDef.
private Set<OnmsCategory> getCategoriesForRowDef(RowDef rowDef) {
Set<OnmsCategory> categories = new LinkedHashSet<OnmsCategory>();
//Loop over the defined categories and create model categories (OnmsCategory)
List<Category> cats = rowDef.getCategories();
for (Category cat : cats) {
OnmsCategory category = m_categoryDao.findByName(cat.getName());
if (category == null) {
throw new ObjectRetrievalFailureException(OnmsCategory.class, cat.getName(), "Unable to locate OnmsCategory named: " + cat.getName() + " as specified in the site status view configuration file", null);
}
categories.add(category);
}
return categories;
}
Aggregations