Example usage for org.springframework.orm ObjectRetrievalFailureException ObjectRetrievalFailureException

List of usage examples for org.springframework.orm ObjectRetrievalFailureException ObjectRetrievalFailureException

Introduction

In this page you can find the example usage for org.springframework.orm ObjectRetrievalFailureException ObjectRetrievalFailureException.

Prototype

public ObjectRetrievalFailureException(String persistentClassName, Object identifier, String msg,
        @Nullable Throwable cause) 

Source Link

Document

Create a new ObjectRetrievalFailureException for the given object, with the given explicit message and exception.

Usage

From source file:org.opennms.ng.dao.support.ResponseTimeResourceType.java

/** {@inheritDoc} */
@Override/*from  w  w  w . j a  v  a  2  s  .c o  m*/
public List<OnmsResource> getResourcesForNode(final int nodeId) {
    final LinkedList<OnmsResource> resources = new LinkedList<OnmsResource>();

    final OnmsNode node = m_nodeDao.get(nodeId);
    if (node == null) {
        throw new ObjectRetrievalFailureException(OnmsNode.class, nodeId,
                "Could not find node for node Id " + nodeId, null);
    }

    for (final OnmsIpInterface i : node.getIpInterfaces()) {
        String ipAddr = InetAddressUtils.str(i.getIpAddress());

        final File iface = getInterfaceDirectory(ipAddr, false);

        if (iface.isDirectory()) {
            resources.add(createResource(i));
        }
    }

    return resources;
}

From source file:org.opennms.ng.dao.support.InterfaceSnmpResourceType.java

/** {@inheritDoc} */
@Override// w w w.  ja  va  2  s .com
public List<OnmsResource> getResourcesForNode(int nodeId) {
    OnmsNode node = m_nodeDao.get(nodeId);
    if (node == null) {
        throw new ObjectRetrievalFailureException(OnmsNode.class, Integer.toString(nodeId),
                "Could not find node with node ID " + nodeId, null);
    }

    File parent = getParentResourceDirectory(Integer.toString(nodeId), true);
    return OnmsResource.sortIntoResourceList(populateResourceList(parent, null, node, false));

}

From source file:org.opennms.ng.dao.support.DefaultResourceDao.java

private Map<String, GenericIndexResourceType> getGenericIndexResourceTypes() {
    Map<String, GenericIndexResourceType> resourceTypes;
    resourceTypes = new LinkedHashMap<String, GenericIndexResourceType>();

    Map<String, ResourceType> configuredResourceTypes = m_dataCollectionConfigDao.getConfiguredResourceTypes();
    List<ResourceType> resourceTypeList = new LinkedList<ResourceType>(configuredResourceTypes.values());
    Collections.sort(resourceTypeList, new Comparator<ResourceType>() {
        @Override//w  w  w .j  a v  a  2 s  .co m
        public int compare(ResourceType r0, ResourceType r1) {
            return r0.getLabel().compareTo(r1.getLabel());
        }
    });
    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(this,
                resourceType.getName(), resourceType.getLabel(), resourceType.getResourceLabel(),
                storageStrategy);
        resourceTypes.put(genericIndexResourceType.getName(), genericIndexResourceType);
    }
    return resourceTypes;
}

From source file:org.opennms.ng.dao.support.DefaultResourceDao.java

/**
 * Fetch a specific list of resources by string ID.
 * @return Resources or null if resources cannot be found.
 * @throws IllegalArgumentException When the resource ID string does not match the expected regex pattern
 * @throws org.springframework.orm.ObjectRetrievalFailureException If any exceptions are thrown while searching for the resource
 *//*  ww w.j  av a2 s.co  m*/
@Override
public List<OnmsResource> getResourceListById(String id)
        throws IllegalArgumentException, ObjectRetrievalFailureException {
    OnmsResource topLevelResource = null;

    Pattern p = Pattern.compile("([^\\[]+)\\[([^\\]]*)\\](?:\\.|$)");
    Matcher m = p.matcher(id);
    StringBuffer sb = new StringBuffer();

    while (m.find()) {
        String resourceTypeName = DefaultResourceDao.decode(m.group(1));
        String resourceName = DefaultResourceDao.decode(m.group(2));

        try {
            if (topLevelResource == null) {
                topLevelResource = getTopLevelResource(resourceTypeName, resourceName);
            } else {
                return getChildResourceList(topLevelResource);
            }
        } catch (Throwable e) {
            throw new ObjectRetrievalFailureException(OnmsResource.class, id,
                    "Could not get resource for resource ID '" + id + "'", e);
        }

        m.appendReplacement(sb, "");
    }

    m.appendTail(sb);

    if (sb.length() > 0) {
        throw new IllegalArgumentException(
                "resource ID '" + id + "' does not match pattern '" + p.toString() + "' at '" + sb + "'");
    }
    return null;
}

From source file:org.opennms.ng.dao.support.InterfaceSnmpResourceType.java

/** {@inheritDoc} */
@Override//from  w  ww  . ja  v  a 2s  .  c o m
public List<OnmsResource> getResourcesForNodeSource(String nodeSource, int nodeId) {
    String[] ident = nodeSource.split(":");
    OnmsNode node = m_nodeDao.findByForeignId(ident[0], ident[1]);
    if (node == null) {
        throw new ObjectRetrievalFailureException(OnmsNode.class, nodeSource,
                "Could not find node with nodeSource " + nodeSource, null);
    }
    File relPath = new File(DefaultResourceDao.FOREIGN_SOURCE_DIRECTORY, ident[0] + File.separator + ident[1]);
    File parent = getParentResourceDirectory(relPath.toString(), true);
    return OnmsResource.sortIntoResourceList(populateResourceList(parent, relPath, node, true));
}

From source file:org.opennms.ng.dao.support.DefaultResourceDao.java

/**
 * <p>getChildResource</p>//from  w ww  . ja  va2 s  . com
 *
 * @param parentResource a {@link org.opennms.netmgt.model.OnmsResource} object.
 * @param resourceType a {@link String} object.
 * @param resource a {@link String} object.
 * @return a {@link org.opennms.netmgt.model.OnmsResource} object.
 */
protected OnmsResource getChildResource(OnmsResource parentResource, String resourceType, String resource) {
    for (OnmsResource r : parentResource.getChildResources()) {
        if (resourceType.equals(r.getResourceType().getName()) && resource.equals(r.getName())) {
            LOG.debug("getChildResource: returning resource {}", r);
            return r;
        }
    }

    throw new ObjectRetrievalFailureException(OnmsResource.class, resourceType + "/" + resource,
            "Could not find child resource '" + resource + "' with resource type '" + resourceType
                    + "' on resource '" + resource + "'",
            null);
}

From source file:org.opennms.ng.dao.support.DefaultResourceDao.java

/**
 * <p>getNodeEntityResource</p>
 *
 * @param resource a {@link String} object.
 * @return a {@link org.opennms.netmgt.model.OnmsResource} object.
 *//*ww w.  j a  v  a  2 s.c o  m*/
protected OnmsResource getNodeEntityResource(String resource) {
    int nodeId;
    try {
        nodeId = Integer.parseInt(resource);
    } catch (NumberFormatException e) {
        throw new ObjectRetrievalFailureException(OnmsNode.class, resource,
                "Top-level resource of resource type node is not numeric: " + resource, null);
    }

    OnmsNode node = m_nodeDao.get(nodeId);
    if (node == null) {
        throw new ObjectRetrievalFailureException(OnmsNode.class, resource,
                "Top-level resource of resource type node could not be found: " + resource, null);
    }

    OnmsResource onmsResource = getResourceForNode(node);

    return onmsResource;
}

From source file:org.opennms.ng.dao.support.DefaultResourceDao.java

/**
 * <p>getForeignSourceNodeEntityResource</p>
 *
 * @param resource a {@link String} object.
 * @return a {@link org.opennms.netmgt.model.OnmsResource} object.
 *//*  ww  w  .  ja v a  2 s.  c o  m*/
protected OnmsResource getForeignSourceNodeEntityResource(String resource) {

    File idDir = new File(getRrdDirectory(), SNMP_DIRECTORY + File.separator
            + ResourceTypeUtils.getRelativeNodeSourceDirectory(resource).toString());
    if (idDir.isDirectory() && RrdFileConstants.NODESOURCE_DIRECTORY_FILTER.accept(idDir)) {
        return m_nodeSourceResourceType.createChildResource(resource);
    } else {
        LOG.debug("resource {} not found by foreign source/foreignId. Trying as a node resource instead...",
                resource);
        String[] ident = resource.split(":");
        OnmsNode node = m_nodeDao.findByForeignId(ident[0], ident[1]);
        if (node == null) {
            throw new ObjectRetrievalFailureException(OnmsNode.class, resource,
                    "Top-level resource of resource type node could not be found: " + resource, null);
        }

        OnmsResource onmsResource = getResourceForNode(node);

        return onmsResource;
    }
}

From source file:org.opennms.ng.dao.support.DefaultResourceDao.java

/**
 * <p>getDomainEntityResource</p>
 *
 * @param domain a {@link String} object.
 * @return a {@link org.opennms.netmgt.model.OnmsResource} object.
 *///from  w ww  .j  a v  a2  s  . com
protected OnmsResource getDomainEntityResource(String domain) {

    File directory = new File(getRrdDirectory(), SNMP_DIRECTORY);
    File domainDir = new File(directory, domain);
    if (!domainDir.isDirectory()) {
        throw new ObjectRetrievalFailureException(OnmsResource.class, domain,
                "Domain not found due to domain RRD directory not existing or not a directory: "
                        + domainDir.getAbsolutePath(),
                null);
    }

    if (!RrdFileConstants.DOMAIN_DIRECTORY_FILTER.accept(domainDir)) {
        throw new ObjectRetrievalFailureException(OnmsResource.class, domain,
                "Domain not found due to domain RRD directory not matching the domain directory filter: "
                        + domainDir.getAbsolutePath(),
                null);
    }

    return m_domainResourceType.createChildResource(domain);
}

From source file:org.opennms.ng.dao.support.PropertiesGraphDao.java

/** {@inheritDoc} */
@Override/* w w  w.j a  v  a 2 s.c  om*/
public PrefabGraph getPrefabGraph(String name) {
    for (FileReloadContainer<PrefabGraphTypeDao> container : m_types.values()) {
        PrefabGraphTypeDao type = container.getObject();
        this.rescanIncludeDirectory(type);
        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);
}