use of org.springframework.orm.ObjectRetrievalFailureException in project opennms by OpenNMS.
the class SiteStatusViewController method handleRequestInternal.
/**
* {@inheritDoc}
*/
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest req, HttpServletResponse resp) throws Exception {
ModelAndView mav = new ModelAndView("siteStatus");
String statusView = req.getParameter("statusView");
String statusSite = req.getParameter("statusSite");
String nodeId = req.getParameter("nodeid");
AggregateStatusView view = null;
try {
view = m_service.createAggregateStatusView(statusView);
} catch (ObjectRetrievalFailureException e) {
SiteStatusViewError viewError = createSiteStatusViewError((String) e.getIdentifier(), e.getMessage());
return new ModelAndView("siteStatusError", "error", viewError);
}
Collection<AggregateStatus> aggrStati;
if (nodeId != null && WebSecurityUtils.safeParseInt(nodeId) > 0) {
aggrStati = m_service.createAggregateStatusesUsingNodeId(WebSecurityUtils.safeParseInt(nodeId), statusView);
} else if (statusSite == null) {
aggrStati = m_service.createAggregateStatuses(view);
} else {
aggrStati = m_service.createAggregateStatuses(view, statusSite);
// Don't persist this, convenience for display only.
view.setColumnValue(statusSite);
}
mav.addObject("view", view);
mav.addObject("stati", aggrStati);
return mav;
}
use of org.springframework.orm.ObjectRetrievalFailureException in project opennms by OpenNMS.
the class LocationMonitorIdValidator method validate.
/**
* {@inheritDoc}
*/
@Override
public void validate(Object obj, Errors errors) {
LocationMonitorIdCommand cmd = (LocationMonitorIdCommand) obj;
if (cmd.getMonitorId() == null) {
errors.rejectValue("monitorId", "monitorId.notSpecified", new Object[] { "monitorId" }, "Value required.");
} else {
try {
String monitorId = cmd.getMonitorId();
OnmsLocationMonitor monitor = m_locationMonitorDao.get(monitorId);
if (monitor == null) {
throw new ObjectRetrievalFailureException(OnmsLocationMonitor.class, monitorId, "Could not find location monitor with id " + monitorId, null);
}
} catch (DataAccessException e) {
errors.rejectValue("monitorId", "monitorId.notFound", new Object[] { "monitorId", cmd.getMonitorId() }, "Valid location monitor ID required.");
}
}
}
use of org.springframework.orm.ObjectRetrievalFailureException in project opennms by OpenNMS.
the class PropertiesGraphDao method getPrefabGraph.
/**
* {@inheritDoc}
*/
@Override
public PrefabGraph getPrefabGraph(final String name) {
for (final FileReloadContainer<PrefabGraphTypeDao> container : m_types.values()) {
final PrefabGraphTypeDao type = container.getObject();
this.rescanIncludeDirectory(type);
final PrefabGraph graph = type.getQuery(name);
if (graph != null) {
return graph;
}
}
throw new ObjectRetrievalFailureException(PrefabGraph.class, name, "Could not find prefabricated graph report with name '" + name + "'", null);
}
use of org.springframework.orm.ObjectRetrievalFailureException in project opennms by OpenNMS.
the class Events method loadEventFilesIfModified.
public void loadEventFilesIfModified(final Resource configResource, final Map<String, Long> lastModifiedEventFiles) throws IOException {
// longer appear in the list of event files
for (Iterator<Map.Entry<String, Events>> it = m_loadedEventFiles.entrySet().iterator(); it.hasNext(); ) {
final String eventFile = it.next().getKey();
if (!m_eventFiles.contains(eventFile)) {
// The event file was previously loaded and has been removed
// from the list of event files
it.remove();
}
}
// Conditionally load or reload the event files
for (final String eventFile : m_eventFiles) {
final Resource eventResource = getRelative(configResource, eventFile);
final long lastModified = eventResource.lastModified();
// Determine whether or not the file should be loaded
boolean shouldLoadFile = true;
if (lastModifiedEventFiles.containsKey(eventFile) && lastModifiedEventFiles.get(eventFile) == lastModified) {
shouldLoadFile = false;
// be already loaded
assert (m_loadedEventFiles.containsKey(eventFile));
}
// Skip any files that don't need to be loaded
if (!shouldLoadFile) {
continue;
}
lastModifiedEventFiles.put(eventFile, lastModified);
final Events events = JaxbUtils.unmarshal(Events.class, eventResource);
if (events.getEvents().isEmpty()) {
throw new IllegalStateException("Uh oh! An event file " + eventResource.getFile() + " with no events has been laoded!");
}
if (events.getGlobal() != null) {
throw new ObjectRetrievalFailureException(Resource.class, eventResource, "The event resource " + eventResource + " included from the root event configuration file cannot have a 'global' element", null);
}
if (!events.getEventFiles().isEmpty()) {
throw new ObjectRetrievalFailureException(Resource.class, eventResource, "The event resource " + eventResource + " included from the root event configuration file cannot include other configuration files: " + StringUtils.collectionToCommaDelimitedString(events.getEventFiles()), null);
}
m_loadedEventFiles.put(eventFile, events);
}
// Re-order the loaded event files to match the order specified in the root configuration
final Map<String, Events> orderedAndLoadedEventFiles = new LinkedHashMap<>();
for (String eventFile : m_eventFiles) {
final Events loadedEvents = m_loadedEventFiles.get(eventFile);
if (loadedEvents != null) {
orderedAndLoadedEventFiles.put(eventFile, loadedEvents);
}
}
m_loadedEventFiles = orderedAndLoadedEventFiles;
}
use of org.springframework.orm.ObjectRetrievalFailureException in project opennms by OpenNMS.
the class DefaultPollerBackEnd method registerLocationMonitor.
/**
* {@inheritDoc}
*/
@Override
public String registerLocationMonitor(final String monitoringLocationId) {
final OnmsMonitoringLocation def = m_monitoringLocationDao.get(monitoringLocationId);
if (def == null) {
throw new ObjectRetrievalFailureException(OnmsMonitoringLocation.class, monitoringLocationId, "Location monitor definition with the id '" + monitoringLocationId + "' not found", null);
}
final OnmsLocationMonitor mon = new OnmsLocationMonitor();
mon.setId(UUID.randomUUID().toString());
mon.setLocation(def.getLocationName());
mon.setStatus(MonitorStatus.REGISTERED);
m_locMonDao.save(mon);
sendMonitorRegisteredEvent(mon);
return mon.getId();
}
Aggregations