Search in sources :

Example 6 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 7 with ObjectRetrievalFailureException

use of org.springframework.orm.ObjectRetrievalFailureException in project opennms by OpenNMS.

the class NCSComponentServiceImpl method addSubcomponent.

@Override
@Transactional
public NCSComponent addSubcomponent(final String type, final String foreignSource, final String foreignId, final NCSComponent subComponent, final boolean deleteOrphans) {
    final ComponentIdentifier subComponentId = getIdentifier(subComponent);
    LOG.debug("addSubcomponent({}, {}, {}, {}, {})", type, foreignSource, foreignId, subComponentId, Boolean.valueOf(deleteOrphans));
    final NCSComponent component = getComponent(type, foreignSource, foreignId);
    final ComponentIdentifier id = getIdentifier(component);
    final ComponentEventQueue ceq = new ComponentEventQueue();
    if (component == null) {
        throw new ObjectRetrievalFailureException(NCSComponent.class, "Unable to locate component with type=" + type + ", foreignSource=" + foreignSource + ", foreignId=" + foreignId);
    }
    final NCSComponent updatedSubComponent = addOrUpdateComponents(subComponentId, subComponent, ceq, deleteOrphans);
    component.addSubcomponent(updatedSubComponent);
    m_componentDao.update(component);
    ceq.componentUpdated(id);
    try {
        ceq.sendAll(m_eventProxy);
    } catch (final EventProxyException e) {
        LOG.warn("Component {} added to {}, but an error occured while sending add/delete/update events.", subComponentId, id, e);
    }
    return getComponent(id);
}
Also used : NCSComponent(org.opennms.netmgt.model.ncs.NCSComponent) EventProxyException(org.opennms.netmgt.events.api.EventProxyException) ObjectRetrievalFailureException(org.springframework.orm.ObjectRetrievalFailureException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with ObjectRetrievalFailureException

use of org.springframework.orm.ObjectRetrievalFailureException in project opennms by OpenNMS.

the class WmiResourceType method instantiateStorageStrategy.

private void instantiateStorageStrategy(String className) {
    Class<?> cinst;
    try {
        cinst = Class.forName(className);
    } catch (ClassNotFoundException e) {
        throw new ObjectRetrievalFailureException(StorageStrategy.class, className, "Could not load class", e);
    }
    try {
        m_storageStrategy = (StorageStrategy) cinst.newInstance();
    } catch (InstantiationException e) {
        throw new ObjectRetrievalFailureException(StorageStrategy.class, className, "Could not instantiate", e);
    } catch (IllegalAccessException e) {
        throw new ObjectRetrievalFailureException(StorageStrategy.class, className, "Could not instantiate", e);
    }
    m_storageStrategy.setResourceTypeName(m_resourceType);
}
Also used : StorageStrategy(org.opennms.netmgt.collection.api.StorageStrategy) ObjectRetrievalFailureException(org.springframework.orm.ObjectRetrievalFailureException)

Example 9 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 10 with ObjectRetrievalFailureException

use of org.springframework.orm.ObjectRetrievalFailureException in project opennms by OpenNMS.

the class InterfaceSnmpResourceType method getChildByName.

/** {@inheritDoc} */
@Override
public OnmsResource getChildByName(final OnmsResource parent, final String name) {
    if (DomainResourceType.isDomain(parent)) {
        // This is not efficient, but resources of this type should be sparse.
        for (final OnmsResource resource : getResourcesForParent(parent)) {
            if (resource.getName().equals(name)) {
                return resource;
            }
        }
        throw new ObjectRetrievalFailureException(OnmsResource.class, "No child with name '" + name + "' found on '" + parent + "'");
    }
    // Grab the node entity
    final OnmsNode node = ResourceTypeUtils.getNodeFromResource(parent);
    // Verify that the requested resource exists
    final ResourcePath resourcePath = new ResourcePath(parent.getPath(), name);
    if (!m_resourceStorageDao.exists(resourcePath, 0)) {
        throw new ObjectRetrievalFailureException(OnmsResource.class, "No resource with name '" + name + "' found.");
    }
    // Leverage the existing function for retrieving the resource list
    final List<OnmsResource> resources = getNodeResources(parent.getPath(), Sets.newHashSet(name), node);
    if (resources.size() != 1) {
        throw new ObjectRetrievalFailureException(OnmsResource.class, "No resource with name '" + name + "' found.");
    }
    final OnmsResource resource = resources.get(0);
    resource.setParent(parent);
    return resource;
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) OnmsNode(org.opennms.netmgt.model.OnmsNode) ResourcePath(org.opennms.netmgt.model.ResourcePath) ObjectRetrievalFailureException(org.springframework.orm.ObjectRetrievalFailureException)

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 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 StringWriter (java.io.StringWriter)1