Search in sources :

Example 46 with Transactional

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

the class EnhancedLinkdServiceImpl method store.

@Override
@Transactional
public void store(int nodeId, LldpElement element) {
    if (element == null)
        return;
    final OnmsNode node = m_nodeDao.get(nodeId);
    if (node == null)
        return;
    LldpElement dbelement = node.getLldpElement();
    if (dbelement != null) {
        dbelement.merge(element);
        node.setLldpElement(dbelement);
    } else {
        element.setNode(node);
        element.setLldpNodeLastPollTime(element.getLldpNodeCreateTime());
        node.setLldpElement(element);
    }
    m_nodeDao.saveOrUpdate(node);
    m_nodeDao.flush();
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) LldpElement(org.opennms.netmgt.model.LldpElement) Transactional(org.springframework.transaction.annotation.Transactional)

Example 47 with Transactional

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

the class AccessPointDaoTest method testFindByPhysAddr.

@Test
@Transactional
public void testFindByPhysAddr() {
    addNewAccessPoint("ap1", AP1_MAC, "default-package");
    addNewAccessPoint("ap2", AP2_MAC, "not-default-package");
    OnmsAccessPoint ap1 = m_accessPointDao.get(AP1_MAC);
    assertEquals("default-package", ap1.getPollingPackage());
    OnmsAccessPoint ap2 = m_accessPointDao.get(AP2_MAC);
    assertEquals("not-default-package", ap2.getPollingPackage());
}
Also used : OnmsAccessPoint(org.opennms.netmgt.model.OnmsAccessPoint) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 48 with Transactional

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

the class AccessPointMonitordTest method addNewAccessPoint.

@Transactional(propagation = Propagation.MANDATORY)
public void addNewAccessPoint(String name, String mac, String pkg) {
    NetworkBuilder nb = new NetworkBuilder();
    nb.addNode(name).setForeignSource("apmd").setForeignId(name);
    nb.addInterface("169.254.0.1");
    m_nodeDao.save(nb.getCurrentNode());
    final OnmsAccessPoint ap1 = new OnmsAccessPoint(mac, nb.getCurrentNode().getId(), pkg);
    ap1.setStatus(AccessPointStatus.UNKNOWN);
    m_accessPointDao.save(ap1);
    m_nodeDao.flush();
    m_accessPointDao.flush();
}
Also used : NetworkBuilder(org.opennms.netmgt.model.NetworkBuilder) OnmsAccessPoint(org.opennms.netmgt.model.OnmsAccessPoint) Transactional(org.springframework.transaction.annotation.Transactional)

Example 49 with Transactional

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

the class KscRestService method addGraph.

@PUT
@Path("{kscReportId}")
@Transactional
public Response addGraph(@PathParam("kscReportId") final Integer kscReportId, @QueryParam("title") final String title, @QueryParam("reportName") final String reportName, @QueryParam("resourceId") final String resourceId, @QueryParam("timespan") String timespan) {
    writeLock();
    try {
        if (kscReportId == null || reportName == null || reportName == "" || resourceId == null || resourceId == "") {
            throw getException(Status.BAD_REQUEST, "Invalid request: reportName and resourceId cannot be empty!");
        }
        final Report report = m_kscReportFactory.getReportByIndex(kscReportId);
        if (report == null) {
            throw getException(Status.NOT_FOUND, "Invalid request: No KSC report found with ID: {}.", Integer.toString(kscReportId));
        }
        final Graph graph = new Graph();
        if (title != null) {
            graph.setTitle(title);
        }
        boolean found = false;
        for (final String valid : KSC_PerformanceReportFactory.TIMESPAN_OPTIONS) {
            if (valid.equals(timespan)) {
                found = true;
                break;
            }
        }
        if (!found) {
            LOG.debug("invalid timespan ('{}'), setting to '7_day' instead.", timespan);
            timespan = "7_day";
        }
        graph.setGraphtype(reportName);
        graph.setResourceId(resourceId);
        graph.setTimespan(timespan);
        report.addGraph(graph);
        m_kscReportFactory.setReport(kscReportId, report);
        try {
            m_kscReportFactory.saveCurrent();
        } catch (final Exception e) {
            throw getException(Status.INTERNAL_SERVER_ERROR, "Cannot save report with Id {} : {} ", kscReportId.toString(), e.getMessage());
        }
        return Response.noContent().build();
    } finally {
        writeUnlock();
    }
}
Also used : Graph(org.opennms.netmgt.config.kscReports.Graph) Report(org.opennms.netmgt.config.kscReports.Report) ParseException(java.text.ParseException) Path(javax.ws.rs.Path) PUT(javax.ws.rs.PUT) Transactional(org.springframework.transaction.annotation.Transactional)

Example 50 with Transactional

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

the class MinionRestService method getMinions.

@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML })
@Transactional
public OnmsMinionCollection getMinions(@Context final UriInfo uriInfo) throws ParseException {
    final CriteriaBuilder builder = getCriteriaBuilder(uriInfo.getQueryParameters());
    final OnmsMinionCollection coll = new OnmsMinionCollection(m_minionDao.findMatching(builder.toCriteria()));
    coll.setTotalCount(m_minionDao.countMatching(builder.clearOrder().toCriteria()));
    return coll;
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsMinionCollection(org.opennms.netmgt.model.OnmsMinionCollection) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) 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