Search in sources :

Example 51 with Transactional

use of org.springframework.transaction.annotation.Transactional in project opennms by OpenNMS.

the class GraphRestService method getGraphResourcesForNode.

@GET
@Path("fornode/{nodeCriteria}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML })
@Transactional(readOnly = true)
public GraphResourceDTO getGraphResourcesForNode(@PathParam("nodeCriteria") final String nodeCriteria, @DefaultValue("-1") @QueryParam("depth") final int depth) {
    OnmsNode node = m_nodeDao.get(nodeCriteria);
    if (node == null) {
        throw getException(Status.NOT_FOUND, "No node found with criteria '{}'.", nodeCriteria);
    }
    OnmsResource resource = m_resourceDao.getResourceForNode(node);
    if (resource == null) {
        throw getException(Status.NOT_FOUND, "No resource found for node with id {}.", "" + node.getId());
    }
    final ResourceVisitor visitor = new ResourceVisitor(this);
    final ResourceDTO resourceDTO = ResourceDTO.fromResource(resource, depth);
    visitor.visit(resourceDTO);
    return new GraphResourceDTO(resourceDTO, visitor.getGraphs());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsResource(org.opennms.netmgt.model.OnmsResource) ResourceDTO(org.opennms.netmgt.model.resource.ResourceDTO) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Transactional(org.springframework.transaction.annotation.Transactional)

Example 52 with Transactional

use of org.springframework.transaction.annotation.Transactional in project opennms by OpenNMS.

the class GraphRestService method getGraphNames.

@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML })
@Transactional(readOnly = true)
public GraphNameCollection getGraphNames() {
    List<String> graphNames = Lists.newLinkedList();
    for (PrefabGraph prefabGraph : m_graphDao.getAllPrefabGraphs()) {
        graphNames.add(prefabGraph.getName());
    }
    Collections.sort(graphNames);
    return new GraphNameCollection(graphNames);
}
Also used : PrefabGraph(org.opennms.netmgt.model.PrefabGraph) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Transactional(org.springframework.transaction.annotation.Transactional)

Example 53 with Transactional

use of org.springframework.transaction.annotation.Transactional in project opennms by OpenNMS.

the class MonitoringLocationsRestService method updateMonitoringLocation.

@PUT
@Path("{monitoringLocation}")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Transactional
public Response updateMonitoringLocation(@PathParam("monitoringLocation") String monitoringLocation, MultivaluedMapImpl params) {
    writeLock();
    try {
        OnmsMonitoringLocation def = m_monitoringLocationDao.get(monitoringLocation);
        LOG.debug("updateMonitoringLocation: updating monitoring location {}", monitoringLocation);
        if (params.isEmpty())
            return Response.notModified().build();
        boolean modified = false;
        final BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(def);
        wrapper.registerCustomEditor(Duration.class, new StringIntervalPropertyEditor());
        for (final String key : params.keySet()) {
            if (wrapper.isWritableProperty(key)) {
                Object value = null;
                String stringValue = params.getFirst(key);
                value = wrapper.convertIfNecessary(stringValue, (Class<?>) wrapper.getPropertyType(key));
                wrapper.setPropertyValue(key, value);
                modified = true;
            }
        }
        if (modified) {
            LOG.debug("updateMonitoringLocation: monitoring location {} updated", monitoringLocation);
            m_monitoringLocationDao.save(def);
            return Response.noContent().build();
        }
        return Response.notModified().build();
    } finally {
        writeUnlock();
    }
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) StringIntervalPropertyEditor(org.opennms.netmgt.provision.persist.StringIntervalPropertyEditor) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT) Transactional(org.springframework.transaction.annotation.Transactional)

Example 54 with Transactional

use of org.springframework.transaction.annotation.Transactional in project opennms by OpenNMS.

the class EnLinkdElementFactory method convertFromModel.

@Transactional
@SuppressWarnings("deprecation")
private NodeLinkBridge convertFromModel(String mac, SharedSegment segment, String port) {
    final NodeLinkBridge linknode = new NodeLinkBridge();
    linknode.setNodeLocalPort(port);
    for (BridgePort link : segment.getBridgePortsOnSegment()) {
        final BridgeLinkRemoteNode remlinknode = new BridgeLinkRemoteNode();
        final Integer rempnodeId = link.getNode().getId();
        final Integer rembridgePortIfIndex = link.getBridgePortIfIndex();
        remlinknode.setBridgeRemoteNode(link.getNode().getLabel());
        remlinknode.setBridgeRemoteUrl(getNodeUrl(rempnodeId));
        final OnmsSnmpInterface remiface = rembridgePortIfIndex == null ? null : m_snmpInterfaceDao.findByNodeIdAndIfIndex(rempnodeId, rembridgePortIfIndex);
        if (remiface != null) {
            remlinknode.setBridgeRemotePort(getPortString(rembridgePortIfIndex, remiface.getIfName(), remiface.getIfAlias()));
        } else {
            remlinknode.setBridgeRemotePort(getPortString(rembridgePortIfIndex, null, null));
        }
        remlinknode.setBridgeRemotePortUrl(getSnmpInterfaceUrl(rempnodeId, rembridgePortIfIndex));
        remlinknode.setBridgeRemoteVlan(link.getVlan());
        linknode.getBridgeLinkRemoteNodes().add(remlinknode);
    }
    for (BridgeMacLink link : segment.getBridgeMacLinks()) {
        if (link.getMacAddress().equals(mac)) {
            linknode.setBridgeLinkCreateTime(Util.formatDateToUIString(link.getBridgeMacLinkCreateTime()));
            linknode.setBridgeLinkLastPollTime(Util.formatDateToUIString(link.getBridgeMacLinkLastPollTime()));
            break;
        }
    }
    Map<String, List<IpNetToMedia>> sharedmacs = new HashMap<String, List<IpNetToMedia>>();
    for (String shredmac : segment.getMacsOnSegment()) {
        if (shredmac.equals(mac))
            continue;
        sharedmacs.put(shredmac, new ArrayList<IpNetToMedia>());
        sharedmacs.get(shredmac).addAll(m_ipNetToMediaDao.findByPhysAddress(shredmac));
    }
    Map<String, List<OnmsIpInterface>> sharedhosts = new HashMap<String, List<OnmsIpInterface>>();
    for (String shredmac : sharedmacs.keySet()) {
        if (sharedmacs.get(shredmac).isEmpty()) {
            BridgeLinkSharedHost remlinknode = new BridgeLinkSharedHost();
            OnmsSnmpInterface snmp = getFromPhysAddress(shredmac);
            if (snmp == null) {
                remlinknode.setSharedHost(shredmac + " No ip address found");
            } else {
                remlinknode.setSharedHost(snmp.getNode().getLabel());
                remlinknode.setSharedHostUrl(getNodeUrl(snmp.getNode().getId()));
                remlinknode.setSharedHostPort(getPortString(snmp.getIfIndex(), snmp.getIfName(), snmp.getIfAlias()));
                remlinknode.setSharedHostPortUrl(getSnmpInterfaceUrl(snmp.getNode().getId(), snmp.getIfIndex()));
            }
            linknode.getBridgeLinkSharedHost().add(remlinknode);
            continue;
        }
        sharedhosts.put(shredmac, new ArrayList<OnmsIpInterface>());
        for (IpNetToMedia ipnettomedia : sharedmacs.get(shredmac)) sharedhosts.get(shredmac).addAll(m_ipInterfaceDao.findByIpAddress(ipnettomedia.getNetAddress().getHostAddress()));
    }
    for (String shredmac : sharedhosts.keySet()) {
        BridgeLinkSharedHost remlinknode = new BridgeLinkSharedHost();
        Set<InetAddress> ips = new HashSet<InetAddress>();
        if (sharedhosts.get(shredmac).isEmpty()) {
            for (IpNetToMedia ipnettomedia : sharedmacs.get(shredmac)) {
                ips.add(ipnettomedia.getNetAddress());
            }
            remlinknode.setSharedHost(getNodePortString(ips, shredmac) + " No node found");
            linknode.getBridgeLinkSharedHost().add(remlinknode);
            continue;
        }
        OnmsIpInterface first = null;
        boolean multiplenodeids = false;
        for (OnmsIpInterface ip : sharedhosts.get(shredmac)) {
            if (first == null)
                first = ip;
            if (first.getNode().getId().intValue() != ip.getNode().getId().intValue())
                multiplenodeids = true;
            ips.add(ip.getIpAddress());
        }
        if (multiplenodeids) {
            remlinknode.setSharedHost(getNodePortString(ips, shredmac) + " duplicated ip multiple node associated in db");
        } else {
            remlinknode.setSharedHost(first.getNode().getLabel());
            remlinknode.setSharedHostUrl(getNodeUrl(first.getNode().getId()));
        }
        remlinknode.setSharedHostPort(getNodePortString(ips, shredmac));
        if (ips.size() == 1) {
            remlinknode.setSharedHostPortUrl(getIpInterfaceUrl(first));
        }
        linknode.getBridgeLinkSharedHost().add(remlinknode);
    }
    return linknode;
}
Also used : BridgePort(org.opennms.netmgt.model.topology.BridgePort) HashMap(java.util.HashMap) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) IpNetToMedia(org.opennms.netmgt.model.IpNetToMedia) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) List(java.util.List) ArrayList(java.util.ArrayList) BridgeMacLink(org.opennms.netmgt.model.BridgeMacLink) InetAddress(java.net.InetAddress) HashSet(java.util.HashSet) Transactional(org.springframework.transaction.annotation.Transactional)

Example 55 with Transactional

use of org.springframework.transaction.annotation.Transactional in project opennms by OpenNMS.

the class EnLinkdElementFactory method convertFromModel.

@Transactional
@SuppressWarnings("deprecation")
private BridgeLinkNode convertFromModel(int nodeid, SharedSegment segment) {
    final BridgeLinkNode linknode = new BridgeLinkNode();
    for (BridgePort link : segment.getBridgePortsOnSegment()) {
        final Integer rempnodeId = link.getNode().getId();
        final Integer rembridgePortIfIndex = link.getBridgePortIfIndex();
        final OnmsSnmpInterface remiface = rembridgePortIfIndex == null ? null : m_snmpInterfaceDao.findByNodeIdAndIfIndex(rempnodeId, rembridgePortIfIndex);
        if (link.getNode().getId().intValue() == nodeid) {
            if (remiface != null) {
                linknode.setNodeLocalPort(getPortString(rembridgePortIfIndex, remiface.getIfName(), remiface.getIfAlias()));
            } else {
                linknode.setNodeLocalPort(getPortString(rembridgePortIfIndex, null, null));
            }
            linknode.setBridgeLocalVlan(link.getVlan());
            continue;
        }
        final BridgeLinkRemoteNode remlinknode = new BridgeLinkRemoteNode();
        remlinknode.setBridgeRemoteNode(link.getNode().getLabel());
        remlinknode.setBridgeRemoteUrl(getNodeUrl(rempnodeId));
        if (remiface != null) {
            remlinknode.setBridgeRemotePort(getPortString(rembridgePortIfIndex, remiface.getIfName(), remiface.getIfAlias()));
        } else {
            remlinknode.setBridgeRemotePort(getPortString(rembridgePortIfIndex, null, null));
        }
        remlinknode.setBridgeRemotePortUrl(getSnmpInterfaceUrl(rempnodeId, rembridgePortIfIndex));
        remlinknode.setBridgeRemoteVlan(link.getVlan());
        linknode.getBridgeLinkRemoteNodes().add(remlinknode);
    }
    if (segment.getBridgeBridgeLinks().isEmpty()) {
        for (BridgeMacLink link : segment.getBridgeMacLinks()) {
            if (link.getNode().getId().intValue() == nodeid) {
                linknode.setBridgeLinkCreateTime(Util.formatDateToUIString(link.getBridgeMacLinkCreateTime()));
                linknode.setBridgeLinkLastPollTime(Util.formatDateToUIString(link.getBridgeMacLinkLastPollTime()));
                break;
            }
        }
    } else {
        for (BridgeBridgeLink link : segment.getBridgeBridgeLinks()) {
            if (link.getNode().getId().intValue() == nodeid || link.getDesignatedNode().getId().intValue() == nodeid) {
                linknode.setBridgeLinkCreateTime(Util.formatDateToUIString(link.getBridgeBridgeLinkCreateTime()));
                linknode.setBridgeLinkLastPollTime(Util.formatDateToUIString(link.getBridgeBridgeLinkLastPollTime()));
                break;
            }
        }
    }
    Map<String, List<IpNetToMedia>> sharedmacs = new HashMap<String, List<IpNetToMedia>>();
    for (String shredmac : segment.getMacsOnSegment()) {
        sharedmacs.put(shredmac, new ArrayList<IpNetToMedia>());
        sharedmacs.get(shredmac).addAll(m_ipNetToMediaDao.findByPhysAddress(shredmac));
    }
    Map<String, List<OnmsIpInterface>> sharedhosts = new HashMap<String, List<OnmsIpInterface>>();
    for (String shredmac : sharedmacs.keySet()) {
        if (sharedmacs.get(shredmac).isEmpty()) {
            BridgeLinkSharedHost remlinknode = new BridgeLinkSharedHost();
            OnmsSnmpInterface snmp = getFromPhysAddress(shredmac);
            if (snmp == null) {
                remlinknode.setSharedHost(shredmac + " No ip address found");
            } else {
                remlinknode.setSharedHost(snmp.getNode().getLabel());
                remlinknode.setSharedHostUrl(getNodeUrl(snmp.getNode().getId()));
                remlinknode.setSharedHostPort(getPortString(snmp.getIfIndex(), snmp.getIfName(), snmp.getIfAlias()));
                remlinknode.setSharedHostPortUrl(getSnmpInterfaceUrl(snmp.getNode().getId(), snmp.getIfIndex()));
            }
            linknode.getBridgeLinkSharedHost().add(remlinknode);
            continue;
        }
        sharedhosts.put(shredmac, new ArrayList<OnmsIpInterface>());
        for (IpNetToMedia ipnettomedia : sharedmacs.get(shredmac)) sharedhosts.get(shredmac).addAll(m_ipInterfaceDao.findByIpAddress(ipnettomedia.getNetAddress().getHostAddress()));
    }
    for (String shredmac : sharedhosts.keySet()) {
        BridgeLinkSharedHost remlinknode = new BridgeLinkSharedHost();
        Set<InetAddress> ips = new HashSet<InetAddress>();
        if (sharedhosts.get(shredmac).isEmpty()) {
            for (IpNetToMedia ipnettomedia : sharedmacs.get(shredmac)) {
                ips.add(ipnettomedia.getNetAddress());
            }
            remlinknode.setSharedHost(getNodePortString(ips, shredmac) + " No node found");
            linknode.getBridgeLinkSharedHost().add(remlinknode);
            continue;
        }
        OnmsIpInterface first = null;
        boolean multiplenodeids = false;
        for (OnmsIpInterface ip : sharedhosts.get(shredmac)) {
            if (first == null)
                first = ip;
            if (first.getNode().getId().intValue() != ip.getNode().getId().intValue())
                multiplenodeids = true;
            ips.add(ip.getIpAddress());
        }
        if (multiplenodeids) {
            remlinknode.setSharedHost(getNodePortString(ips, shredmac) + " duplicated ip multiple node associated in db");
        } else {
            remlinknode.setSharedHost(first.getNode().getLabel());
            remlinknode.setSharedHostUrl(getNodeUrl(first.getNode().getId()));
        }
        remlinknode.setSharedHostPort(getNodePortString(ips, shredmac));
        if (ips.size() == 1) {
            remlinknode.setSharedHostPortUrl(getIpInterfaceUrl(first));
        }
        linknode.getBridgeLinkSharedHost().add(remlinknode);
    }
    return linknode;
}
Also used : BridgePort(org.opennms.netmgt.model.topology.BridgePort) HashMap(java.util.HashMap) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) IpNetToMedia(org.opennms.netmgt.model.IpNetToMedia) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) BridgeBridgeLink(org.opennms.netmgt.model.BridgeBridgeLink) List(java.util.List) ArrayList(java.util.ArrayList) BridgeMacLink(org.opennms.netmgt.model.BridgeMacLink) InetAddress(java.net.InetAddress) HashSet(java.util.HashSet) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Transactional (org.springframework.transaction.annotation.Transactional)1415 Test (org.junit.Test)507 Query (javax.persistence.Query)166 Date (java.util.Date)121 ArrayList (java.util.ArrayList)99 ServiceException (com.netsteadfast.greenstep.base.exception.ServiceException)89 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)87 ServiceMethodAuthority (com.netsteadfast.greenstep.base.model.ServiceMethodAuthority)84 OnmsNode (org.opennms.netmgt.model.OnmsNode)83 TypedQuery (javax.persistence.TypedQuery)81 Rollback (org.springframework.test.annotation.Rollback)81 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)67 HashMap (java.util.HashMap)65 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)61 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)58 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)58 DBUnitTest (org.orcid.test.DBUnitTest)57 List (java.util.List)56 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)41 User (com.arnaugarcia.uplace.domain.User)39