@Test public void testNode() throws Exception { createNode(); String url = "/nodes"; String xml = sendRequest(GET, url, 200); assertTrue(xml.contains("Darwin TestMachine 9.4.0 Darwin Kernel Version 9.4.0")); OnmsNodeList list = JaxbUtils.unmarshal(OnmsNodeList.class, xml); assertEquals(1, list.getNodes().size()); assertEquals(xml, "TestMachine0", list.getNodes().get(0).getLabel()); xml = sendRequest(GET, url, parseParamData("orderBy=sysObjectId"), 200); list = JaxbUtils.unmarshal(OnmsNodeList.class, xml); assertEquals(1, list.getNodes().size()); assertEquals("TestMachine0", list.getNodes().get(0).getLabel()); for (m_nodeCounter = 1; m_nodeCounter < 5; m_nodeCounter++) { createNode(); } xml = sendRequest(GET, url, parseParamData("limit=3&offset=0&orderBy=label"), 200); list = JaxbUtils.unmarshal(OnmsNodeList.class, xml); assertEquals(3, list.getNodes().size()); assertEquals(3, list.getCount()); assertEquals(5, list.getTotalCount()); assertEquals("TestMachine0", list.getNodes().get(0).getLabel()); assertEquals("TestMachine1", list.getNodes().get(1).getLabel()); assertEquals("TestMachine2", list.getNodes().get(2).getLabel()); xml = sendRequest(GET, url, parseParamData("comparator=like&label=%25Test%25"), 200); LogUtils.infof(this, xml); list = JaxbUtils.unmarshal(OnmsNodeList.class, xml); assertEquals(5, list.getCount()); assertEquals(5, list.getTotalCount()); xml = sendRequest(GET, url, parseParamData("comparator=like&label=%25DOES_NOT_MATCH%25"), 200); LogUtils.infof(this, xml); list = JaxbUtils.unmarshal(OnmsNodeList.class, xml); assertEquals(0, list.getCount()); assertEquals(0, list.getTotalCount()); url += "/1"; sendPut(url, "sysContact=OpenNMS&assetRecord.manufacturer=Apple&assetRecord.operatingSystem=MacOSX Leopard", 303, "/nodes/1"); xml = sendRequest(GET, url, 200); assertTrue(xml.contains("<sysContact>OpenNMS</sysContact>")); assertTrue(xml.contains("<operatingSystem>MacOSX Leopard</operatingSystem>")); sendRequest(DELETE, url, 200); sendRequest(GET, url, 204); }
@GET @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML}) public OnmsNodeList getNodes() { readLock(); try { final CriteriaBuilder builder = new CriteriaBuilder(OnmsNode.class); builder.alias("snmpInterfaces", "snmpInterface", JoinType.LEFT_JOIN); builder.alias("ipInterfaces", "ipInterface", JoinType.LEFT_JOIN); builder.alias("categories", "category", JoinType.LEFT_JOIN); final MultivaluedMap<String, String> params = m_uriInfo.getQueryParameters(); final String type = params.getFirst("type"); applyQueryFilters(params, builder); builder.orderBy("label").asc(); final Criteria crit = builder.toCriteria(); if (type == null) { final List<Restriction> restrictions = new ArrayList<Restriction>(crit.getRestrictions()); restrictions.add(Restrictions.ne("type", "D")); crit.setRestrictions(restrictions); } final OnmsNodeList coll = new OnmsNodeList(m_nodeDao.findMatching(crit)); crit.setLimit(null); crit.setOffset(null); crit.setOrders(new ArrayList<Order>()); coll.setTotalCount(m_nodeDao.countMatching(crit)); return coll; } finally { readUnlock(); } }
NodeRestService extends OnmsRestService { @GET @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML}) public OnmsNodeList getNodes() { readLock(); try { final CriteriaBuilder builder = new CriteriaBuilder(OnmsNode.class); builder.alias("snmpInterfaces", "snmpInterface", JoinType.LEFT_JOIN); builder.alias("ipInterfaces", "ipInterface", JoinType.LEFT_JOIN); builder.alias("categories", "category", JoinType.LEFT_JOIN); final MultivaluedMap<String, String> params = m_uriInfo.getQueryParameters(); final String type = params.getFirst("type"); applyQueryFilters(params, builder); builder.orderBy("label").asc(); final Criteria crit = builder.toCriteria(); if (type == null) { final List<Restriction> restrictions = new ArrayList<Restriction>(crit.getRestrictions()); restrictions.add(Restrictions.ne("type", "D")); crit.setRestrictions(restrictions); } final OnmsNodeList coll = new OnmsNodeList(m_nodeDao.findMatching(crit)); crit.setLimit(null); crit.setOffset(null); crit.setOrders(new ArrayList<Order>()); coll.setTotalCount(m_nodeDao.countMatching(crit)); return coll; } finally { readUnlock(); } } }
NodeRestService extends OnmsRestService { @GET @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML}) public OnmsNodeList getNodes() { readLock(); try { final CriteriaBuilder builder = new CriteriaBuilder(OnmsNode.class); builder.alias("snmpInterfaces", "snmpInterface", JoinType.LEFT_JOIN); builder.alias("ipInterfaces", "ipInterface", JoinType.LEFT_JOIN); builder.alias("categories", "category", JoinType.LEFT_JOIN); final MultivaluedMap<String, String> params = m_uriInfo.getQueryParameters(); final String type = params.getFirst("type"); applyQueryFilters(params, builder); builder.orderBy("label").asc(); final Criteria crit = builder.toCriteria(); if (type == null) { final List<Restriction> restrictions = new ArrayList<Restriction>(crit.getRestrictions()); restrictions.add(Restrictions.ne("type", "D")); crit.setRestrictions(restrictions); } final OnmsNodeList coll = new OnmsNodeList(m_nodeDao.findMatching(crit)); crit.setLimit(null); crit.setOffset(null); crit.setOrders(new ArrayList<Order>()); coll.setTotalCount(m_nodeDao.countMatching(crit)); return coll; } finally { readUnlock(); } }  }
NodeRestService extends OnmsRestService { @GET @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML}) public OnmsNodeList getNodes() { readLock(); try { final CriteriaBuilder builder = new CriteriaBuilder(OnmsNode.class); builder.alias("snmpInterfaces", "snmpInterface", JoinType.LEFT_JOIN); builder.alias("ipInterfaces", "ipInterface", JoinType.LEFT_JOIN); builder.alias("categories", "category", JoinType.LEFT_JOIN); final MultivaluedMap<String, String> params = m_uriInfo.getQueryParameters(); final String type = params.getFirst("type"); applyQueryFilters(params, builder); builder.orderBy("label").asc(); final Criteria crit = builder.toCriteria(); if (type == null) { final List<Restriction> restrictions = new ArrayList<Restriction>(crit.getRestrictions()); restrictions.add(Restrictions.ne("type", "D")); crit.setRestrictions(restrictions); } final OnmsNodeList coll = new OnmsNodeList(m_nodeDao.findMatching(crit)); crit.setLimit(null); crit.setOffset(null); crit.setOrders(new ArrayList<Order>()); coll.setTotalCount(m_nodeDao.countMatching(crit)); return coll; } finally { readUnlock(); } }  @GET @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML}) OnmsNodeList getNodes(); @GET @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML}) @Path("{nodeCriteria}") OnmsNode getNode(@PathParam("nodeCriteria") final String nodeCriteria); @POST @Consumes(MediaType.APPLICATION_XML) Response addNode(final OnmsNode node); @PUT @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Path("{nodeCriteria}") Response updateNode(@PathParam("nodeCriteria") final String nodeCriteria, final MultivaluedMapImpl params); @DELETE @Path("{nodeCriteria}") Response deleteNode(@PathParam("nodeCriteria") final String nodeCriteria); @Path("{nodeCriteria}/ipinterfaces") OnmsIpInterfaceResource getIpInterfaceResource(); @Path("{nodeCriteria}/snmpinterfaces") OnmsSnmpInterfaceResource getSnmpInterfaceResource(); @Path("{nodeCriteria}/categories") OnmsCategoryResource getCategoryResource(); @Path("{nodeCriteria}/assetRecord") AssetRecordResource getAssetRecordResource(); }
NodeRestService extends OnmsRestService { @GET @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML}) public OnmsNodeList getNodes() { readLock(); try { final CriteriaBuilder builder = new CriteriaBuilder(OnmsNode.class); builder.alias("snmpInterfaces", "snmpInterface", JoinType.LEFT_JOIN); builder.alias("ipInterfaces", "ipInterface", JoinType.LEFT_JOIN); builder.alias("categories", "category", JoinType.LEFT_JOIN); final MultivaluedMap<String, String> params = m_uriInfo.getQueryParameters(); final String type = params.getFirst("type"); applyQueryFilters(params, builder); builder.orderBy("label").asc(); final Criteria crit = builder.toCriteria(); if (type == null) { final List<Restriction> restrictions = new ArrayList<Restriction>(crit.getRestrictions()); restrictions.add(Restrictions.ne("type", "D")); crit.setRestrictions(restrictions); } final OnmsNodeList coll = new OnmsNodeList(m_nodeDao.findMatching(crit)); crit.setLimit(null); crit.setOffset(null); crit.setOrders(new ArrayList<Order>()); coll.setTotalCount(m_nodeDao.countMatching(crit)); return coll; } finally { readUnlock(); } }  @GET @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML}) OnmsNodeList getNodes(); @GET @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML}) @Path("{nodeCriteria}") OnmsNode getNode(@PathParam("nodeCriteria") final String nodeCriteria); @POST @Consumes(MediaType.APPLICATION_XML) Response addNode(final OnmsNode node); @PUT @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Path("{nodeCriteria}") Response updateNode(@PathParam("nodeCriteria") final String nodeCriteria, final MultivaluedMapImpl params); @DELETE @Path("{nodeCriteria}") Response deleteNode(@PathParam("nodeCriteria") final String nodeCriteria); @Path("{nodeCriteria}/ipinterfaces") OnmsIpInterfaceResource getIpInterfaceResource(); @Path("{nodeCriteria}/snmpinterfaces") OnmsSnmpInterfaceResource getSnmpInterfaceResource(); @Path("{nodeCriteria}/categories") OnmsCategoryResource getCategoryResource(); @Path("{nodeCriteria}/assetRecord") AssetRecordResource getAssetRecordResource();  }