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 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);
}
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);
}
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 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;
}
Aggregations