Search in sources :

Example 56 with Transactional

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

the class EnLinkdElementFactory method convertFromModel.

@Transactional
@SuppressWarnings("deprecation")
private IsisLinkNode convertFromModel(int nodeid, IsIsLink link) {
    IsisLinkNode linknode = new IsisLinkNode();
    linknode.setIsisCircIfIndex(link.getIsisCircIfIndex());
    linknode.setIsisCircAdminState(IsisAdminState.getTypeString(link.getIsisCircAdminState().getValue()));
    IsIsElement isiselement = m_isisElementDao.findByIsIsSysId(link.getIsisISAdjNeighSysID());
    if (isiselement != null) {
        linknode.setIsisISAdjNeighSysID(getAdjSysIDString(link.getIsisISAdjNeighSysID(), isiselement.getNode().getLabel()));
        linknode.setIsisISAdjUrl(getNodeUrl(isiselement.getNode().getId()));
    } else {
        linknode.setIsisISAdjNeighSysID(link.getIsisISAdjNeighSysID());
    }
    linknode.setIsisISAdjNeighSysType(IsisISAdjNeighSysType.getTypeString(link.getIsisISAdjNeighSysType().getValue()));
    linknode.setIsisISAdjNeighSNPAAddress(link.getIsisISAdjNeighSNPAAddress());
    linknode.setIsisISAdjState(IsisISAdjState.get(link.getIsisISAdjState().getValue()).toString());
    linknode.setIsisISAdjNbrExtendedCircID(link.getIsisISAdjNbrExtendedCircID());
    OnmsSnmpInterface remiface = null;
    if (isiselement != null) {
        IsIsLink adjLink = m_isisLinkDao.get(isiselement.getNode().getId(), link.getIsisISAdjIndex(), link.getIsisCircIndex());
        if (adjLink != null) {
            remiface = m_snmpInterfaceDao.findByNodeIdAndIfIndex(isiselement.getNode().getId(), adjLink.getIsisCircIfIndex());
        }
    }
    if (remiface == null) {
        remiface = getFromPhysAddress(link.getIsisISAdjNeighSNPAAddress());
    }
    if (remiface != null) {
        linknode.setIsisISAdjNeighPort(getPortString(remiface.getIfIndex(), remiface.getIfName(), remiface.getIfAlias()));
        linknode.setIsisISAdjUrl(getSnmpInterfaceUrl(remiface.getNode().getId(), remiface.getIfIndex()));
    } else {
        linknode.setIsisISAdjNeighPort("(Isis IS Adj Index: " + link.getIsisISAdjIndex() + ")");
    }
    linknode.setIsisLinkCreateTime(Util.formatDateToUIString(link.getIsisLinkCreateTime()));
    linknode.setIsisLinkLastPollTime(Util.formatDateToUIString(link.getIsisLinkLastPollTime()));
    return linknode;
}
Also used : IsIsLink(org.opennms.netmgt.model.IsIsLink) IsIsElement(org.opennms.netmgt.model.IsIsElement) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) Transactional(org.springframework.transaction.annotation.Transactional)

Example 57 with Transactional

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

the class EnLinkdElementFactory method convertFromModel.

@Transactional
@SuppressWarnings("deprecation")
private LldpLinkNode convertFromModel(int nodeid, LldpLink link) {
    LldpLinkNode linknode = new LldpLinkNode();
    linknode.setLldpPortString(getPortString(link.getLldpPortId(), link.getLldpPortIdSubType()));
    linknode.setLldpPortDescr(link.getLldpPortDescr());
    linknode.setLldpPortUrl(getSnmpInterfaceUrl(Integer.valueOf(nodeid), link.getLldpPortIfindex()));
    linknode.setLldpRemSysName(link.getLldpRemSysname());
    linknode.setLldpRemPortString(getPortString(link.getLldpRemPortId(), link.getLldpRemPortIdSubType()));
    linknode.setLldpRemPortDescr(link.getLldpRemPortDescr());
    linknode.setLldpCreateTime(Util.formatDateToUIString(link.getLldpLinkCreateTime()));
    linknode.setLldpLastPollTime(Util.formatDateToUIString(link.getLldpLinkLastPollTime()));
    OnmsNode remNode = null;
    List<LldpElement> lldpremelements = m_lldpElementDao.findByChassisId(link.getLldpRemChassisId(), link.getLldpRemChassisIdSubType());
    if (lldpremelements.size() == 1) {
        remNode = lldpremelements.get(0).getNode();
    } else if (lldpremelements.size() > 1) {
        linknode.setLldpRemChassisIdString(getChassisIdString("Found " + lldpremelements.size() + " nodes for", link.getLldpRemChassisId(), link.getLldpRemChassisIdSubType()));
        return linknode;
    } else {
        final Criteria criteria = new Criteria(OnmsNode.class).addRestriction(new EqRestriction("sysName", link.getLldpRemSysname()));
        List<OnmsNode> nodes = m_nodeDao.findMatching(criteria);
        if (nodes.size() == 1)
            remNode = nodes.get(0);
    }
    if (remNode != null) {
        linknode.setLldpRemChassisIdString(getChassisIdString(remNode.getLabel(), link.getLldpRemChassisId(), link.getLldpRemChassisIdSubType()));
        linknode.setLldpRemChassisIdUrl(getNodeUrl(remNode.getId()));
        if (link.getLldpRemPortIdSubType() == LldpPortIdSubType.LLDP_PORTID_SUBTYPE_LOCAL) {
            try {
                Integer remIfIndex = Integer.getInteger(link.getLldpRemPortId());
                linknode.setLldpRemPortUrl(getSnmpInterfaceUrl(Integer.valueOf(remNode.getId()), remIfIndex));
            } catch (Exception e) {
            }
        }
    } else {
        linknode.setLldpRemChassisIdString(getChassisIdString(link.getLldpRemChassisId(), link.getLldpRemChassisIdSubType()));
    }
    return linknode;
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) EqRestriction(org.opennms.core.criteria.restrictions.EqRestriction) List(java.util.List) ArrayList(java.util.ArrayList) LldpElement(org.opennms.netmgt.model.LldpElement) Criteria(org.opennms.core.criteria.Criteria) Transactional(org.springframework.transaction.annotation.Transactional)

Example 58 with Transactional

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

the class DefaultSurveillanceServiceIntegrationIT method testCreateSurveillanceServiceTableUsingViewName.

@Test
@Transactional
public void testCreateSurveillanceServiceTableUsingViewName() {
    String viewName = "default";
    SimpleWebTable table = m_surveillanceService.createSurveillanceTable(viewName, new ProgressMonitor() {

        @Override
        public void beginNextPhase(String string) {
            System.err.println("PHASE: " + string);
        }

        @Override
        public void setPhaseCount(int i) {
        }
    });
    assertEquals("default", table.getTitle());
}
Also used : ProgressMonitor(org.opennms.web.svclayer.model.ProgressMonitor) SimpleWebTable(org.opennms.web.svclayer.model.SimpleWebTable) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 59 with Transactional

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

the class AlarmRestServiceIT method testAlarmUpdates.

@Test
@Transactional
@JUnitTemporaryDatabase
public void testAlarmUpdates() throws Exception {
    createAlarm(OnmsSeverity.MAJOR);
    OnmsAlarm alarm = getLastAlarm();
    alarm.setAlarmAckTime(null);
    alarm.setAlarmAckUser(null);
    getAlarmDao().saveOrUpdate(alarm);
    final Integer alarmId = alarm.getId();
    sendPut("/alarms", "ack=true&alarmId=" + alarmId, 204);
    String xml = sendRequest(GET, "/alarms/" + alarmId, 200);
    assertTrue(xml.contains("ackUser>admin<"));
    sendPut("/alarms/" + alarmId, "clear=true", 204);
    xml = sendRequest(GET, "/alarms/" + alarmId, 200);
    assertTrue(xml.contains("severity=\"CLEARED\""));
    sendPut("/alarms/" + alarmId, "escalate=true", 204);
    xml = sendRequest(GET, "/alarms/" + alarmId, 200);
    assertTrue(xml.contains("severity=\"NORMAL\""));
    sendPut("/alarms/" + alarmId, "ticketId=12345", 204);
    xml = sendRequest(GET, "/alarms/" + alarmId, 200);
    assertTrue(xml.contains("<troubleTicket>12345</troubleTicket>"));
    sendPut("/alarms/" + alarmId, "ticketState=UPDATE_PENDING", 204);
    xml = sendRequest(GET, "/alarms/" + alarmId, 200);
    sendPut("/alarms/" + alarmId, "ticketState=UPDATE_PENDING", 204);
    alarm = getLastAlarm();
    alarm.setSeverity(OnmsSeverity.MAJOR);
    alarm.setAlarmAckTime(null);
    alarm.setAlarmAckUser(null);
    getAlarmDao().saveOrUpdate(alarm);
    // Log in as a normal REST user and attempt to resolve an alarm as a different user.
    // This should fail with a 403 forbidden.
    setUser("foo", new String[] { "ROLE_REST" });
    sendPut("/alarms/" + alarmId, "ack=true&ackUser=bar", 403);
}
Also used : OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase) Transactional(org.springframework.transaction.annotation.Transactional)

Example 60 with Transactional

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

the class AlarmRepositoryIT method testCountMatchingBySeverity.

@Test
@Transactional
@JUnitTemporaryDatabase
public void testCountMatchingBySeverity() {
    int[] matchingAlarmCount = m_alarmRepo.countMatchingAlarmsBySeverity(AlarmUtil.getOnmsCriteria(new AlarmCriteria(new SeverityFilter(OnmsSeverity.NORMAL))));
    assertEquals(8, matchingAlarmCount.length);
}
Also used : SeverityFilter(org.opennms.web.alarm.filter.SeverityFilter) AlarmCriteria(org.opennms.web.alarm.filter.AlarmCriteria) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase) 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