@Test public void testAddComponents() throws Exception { sendPost("/NCS", m_serviceXML); m_eventAnticipator.reset(); anticipateEvent(EventConstants.COMPONENT_UPDATED_UEI, new String[] { "ServiceElement", "PE2,ge-3/1/4", "NA-ServiceElement", "9876,4321" }); anticipateEvent(EventConstants.COMPONENT_ADDED_UEI, new String[] { "ServiceElementComponent", "Monkey (1)", "NA-SvcElemComp", "monkey1" }); anticipateEvent(EventConstants.COMPONENT_ADDED_UEI, new String[] { "PhysicalInterface", "Shoe (2)", "NA-PhysIfs", "shoe2" }); setupLogging("DEBUG"); String url = "/NCS/ServiceElement/NA-ServiceElement:9876,4321"; sendPost(url, m_extraXML); String xml = sendRequest(GET, url, 200); assertTrue(xml.contains("monkey1")); }
@POST @Consumes(MediaType.APPLICATION_XML) public Response addComponents(@QueryParam("deleteOrphans") final boolean deleteOrphans, final NCSComponent component) { afterPropertiesSet(); writeLock(); try { LogUtils.debugf(this, "addComponents: Adding component %s (deleteOrphans=%s)", component, Boolean.valueOf(deleteOrphans)); if (m_componentService == null) { throw new IllegalStateException("component service is null"); } try { m_componentService.addOrUpdateComponents(component, deleteOrphans); } catch (final DataAccessException e) { throw new WebApplicationException(e, Status.BAD_REQUEST); } return Response.ok(component).build(); } finally { writeUnlock(); } }
NCSRestService { @POST @Consumes(MediaType.APPLICATION_XML) public Response addComponents(@QueryParam("deleteOrphans") final boolean deleteOrphans, final NCSComponent component) { afterPropertiesSet(); writeLock(); try { LogUtils.debugf(this, "addComponents: Adding component %s (deleteOrphans=%s)", component, Boolean.valueOf(deleteOrphans)); if (m_componentService == null) { throw new IllegalStateException("component service is null"); } try { m_componentService.addOrUpdateComponents(component, deleteOrphans); } catch (final DataAccessException e) { throw new WebApplicationException(e, Status.BAD_REQUEST); } return Response.ok(component).build(); } finally { writeUnlock(); } } }
NCSRestService { @POST @Consumes(MediaType.APPLICATION_XML) public Response addComponents(@QueryParam("deleteOrphans") final boolean deleteOrphans, final NCSComponent component) { afterPropertiesSet(); writeLock(); try { LogUtils.debugf(this, "addComponents: Adding component %s (deleteOrphans=%s)", component, Boolean.valueOf(deleteOrphans)); if (m_componentService == null) { throw new IllegalStateException("component service is null"); } try { m_componentService.addOrUpdateComponents(component, deleteOrphans); } catch (final DataAccessException e) { throw new WebApplicationException(e, Status.BAD_REQUEST); } return Response.ok(component).build(); } finally { writeUnlock(); } }  }
NCSRestService { @POST @Consumes(MediaType.APPLICATION_XML) public Response addComponents(@QueryParam("deleteOrphans") final boolean deleteOrphans, final NCSComponent component) { afterPropertiesSet(); writeLock(); try { LogUtils.debugf(this, "addComponents: Adding component %s (deleteOrphans=%s)", component, Boolean.valueOf(deleteOrphans)); if (m_componentService == null) { throw new IllegalStateException("component service is null"); } try { m_componentService.addOrUpdateComponents(component, deleteOrphans); } catch (final DataAccessException e) { throw new WebApplicationException(e, Status.BAD_REQUEST); } return Response.ok(component).build(); } finally { writeUnlock(); } }  void afterPropertiesSet(); @GET @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Path("{type}/{foreignSource}:{foreignId}") NCSComponent getComponent(@PathParam("type") final String type, @PathParam("foreignSource") final String foreignSource, @PathParam("foreignId") final String foreignId); @GET @Path("attributes") ComponentList getComponentsByAttributes(); @POST @Consumes(MediaType.APPLICATION_XML) Response addComponents(@QueryParam("deleteOrphans") final boolean deleteOrphans, final NCSComponent component); @POST @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Path("{type}/{foreignSource}:{foreignId}") NCSComponent addComponent(@QueryParam("deleteOrphans") final boolean deleteOrphans, @PathParam("type") String type, @PathParam("foreignSource") String foreignSource, @PathParam("foreignId") String foreignId, NCSComponent subComponent); @DELETE @Path("{type}/{foreignSource}:{foreignId}") Response deleteComponent(@QueryParam("deleteOrphans") final boolean deleteOrphans, @PathParam("type") String type, @PathParam("foreignSource") String foreignSource, @PathParam("foreignId") String foreignId); }
NCSRestService { @POST @Consumes(MediaType.APPLICATION_XML) public Response addComponents(@QueryParam("deleteOrphans") final boolean deleteOrphans, final NCSComponent component) { afterPropertiesSet(); writeLock(); try { LogUtils.debugf(this, "addComponents: Adding component %s (deleteOrphans=%s)", component, Boolean.valueOf(deleteOrphans)); if (m_componentService == null) { throw new IllegalStateException("component service is null"); } try { m_componentService.addOrUpdateComponents(component, deleteOrphans); } catch (final DataAccessException e) { throw new WebApplicationException(e, Status.BAD_REQUEST); } return Response.ok(component).build(); } finally { writeUnlock(); } }  void afterPropertiesSet(); @GET @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Path("{type}/{foreignSource}:{foreignId}") NCSComponent getComponent(@PathParam("type") final String type, @PathParam("foreignSource") final String foreignSource, @PathParam("foreignId") final String foreignId); @GET @Path("attributes") ComponentList getComponentsByAttributes(); @POST @Consumes(MediaType.APPLICATION_XML) Response addComponents(@QueryParam("deleteOrphans") final boolean deleteOrphans, final NCSComponent component); @POST @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Path("{type}/{foreignSource}:{foreignId}") NCSComponent addComponent(@QueryParam("deleteOrphans") final boolean deleteOrphans, @PathParam("type") String type, @PathParam("foreignSource") String foreignSource, @PathParam("foreignId") String foreignId, NCSComponent subComponent); @DELETE @Path("{type}/{foreignSource}:{foreignId}") Response deleteComponent(@QueryParam("deleteOrphans") final boolean deleteOrphans, @PathParam("type") String type, @PathParam("foreignSource") String foreignSource, @PathParam("foreignId") String foreignId);  }