Search in sources :

Example 11 with ObjectRetrievalFailureException

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;
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) ObjectRetrievalFailureException(org.springframework.orm.ObjectRetrievalFailureException) AggregateStatus(org.opennms.web.svclayer.model.AggregateStatus) AggregateStatusView(org.opennms.netmgt.model.AggregateStatusView)

Example 12 with ObjectRetrievalFailureException

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.");
        }
    }
}
Also used : LocationMonitorIdCommand(org.opennms.web.svclayer.model.LocationMonitorIdCommand) ObjectRetrievalFailureException(org.springframework.orm.ObjectRetrievalFailureException) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) DataAccessException(org.springframework.dao.DataAccessException)

Example 13 with ObjectRetrievalFailureException

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);
}
Also used : PrefabGraph(org.opennms.netmgt.model.PrefabGraph) ObjectRetrievalFailureException(org.springframework.orm.ObjectRetrievalFailureException)

Example 14 with ObjectRetrievalFailureException

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;
}
Also used : Entry(java.util.Map.Entry) Resource(org.springframework.core.io.Resource) ObjectRetrievalFailureException(org.springframework.orm.ObjectRetrievalFailureException) LinkedHashMap(java.util.LinkedHashMap)

Example 15 with ObjectRetrievalFailureException

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();
}
Also used : ObjectRetrievalFailureException(org.springframework.orm.ObjectRetrievalFailureException) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)

Aggregations

ObjectRetrievalFailureException (org.springframework.orm.ObjectRetrievalFailureException)22 OnmsResource (org.opennms.netmgt.model.OnmsResource)7 PrefabGraph (org.opennms.netmgt.model.PrefabGraph)7 StorageStrategy (org.opennms.netmgt.collection.api.StorageStrategy)4 Test (org.junit.Test)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Graph (org.opennms.netmgt.config.kscReports.Graph)2 OnmsCategory (org.opennms.netmgt.model.OnmsCategory)2 OnmsLocationMonitor (org.opennms.netmgt.model.OnmsLocationMonitor)2 OnmsNode (org.opennms.netmgt.model.OnmsNode)2 OnmsResourceType (org.opennms.netmgt.model.OnmsResourceType)2 ResourcePath (org.opennms.netmgt.model.ResourcePath)2 Resource (org.springframework.core.io.Resource)2 ModelAndView (org.springframework.web.servlet.ModelAndView)2 FileOutputStream (java.io.FileOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1