Search in sources :

Example 21 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 22 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 23 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)

Example 24 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 25 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)

Aggregations

Transactional (org.springframework.transaction.annotation.Transactional)4561 Test (org.junit.Test)1387 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)724 DAOException (com.tomasio.projects.trainning.exception.DAOException)385 CoreException (com.tomasio.projects.trainning.exeption.CoreException)372 ArrayList (java.util.ArrayList)324 Date (java.util.Date)252 Query (javax.persistence.Query)218 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)213 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)211 WithMockUser (org.springframework.security.test.context.support.WithMockUser)204 HashMap (java.util.HashMap)187 List (java.util.List)163 User (io.github.jhipster.sample.domain.User)150 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)135 HashSet (java.util.HashSet)135 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)132 UUID (java.util.UUID)131 Rollback (org.springframework.test.annotation.Rollback)109 ParseException (java.text.ParseException)108