TaxonomyService extends BaseService { @GET @Path("{taxonomyName}/terms/{rootTerm}/{remainder:.*}") @Produces(Servlets.JSON_MEDIA_TYPE) public Response getSubTerms(@Context HttpHeaders headers, @Context UriInfo ui, @PathParam("taxonomyName") String taxonomyName, @PathParam("rootTerm") String rootTerm, @PathParam("remainder") String remainder) throws CatalogException { AtlasPerfTracer perf = null; try { if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) { perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "TaxonomyService.getSubTerms(" + taxonomyName + ", " + rootTerm + ", " + remainder + ")"); } Result result; String termName = String.format("%s%s", rootTerm, remainder.replaceAll("/?terms/?([.]*)", "$1.")); String queryString = decode(getQueryString(ui)); TermPath termPath = new TermPath(taxonomyName, termName); Map<String, Object> properties = new HashMap<>(); properties.put("termPath", termPath); List<PathSegment> pathSegments = ui.getPathSegments(); int lastIndex = pathSegments.size() - 1; String lastSegment = pathSegments.get(lastIndex).getPath(); if (lastSegment.equals("terms") || (lastSegment.isEmpty() && pathSegments.get(lastIndex - 1).getPath().equals("terms"))) { result = getResources(termResourceProvider, new CollectionRequest(properties, queryString)); } else { result = getResource(termResourceProvider, new InstanceRequest(properties)); } return Response.status(Response.Status.OK).entity(getSerializer().serialize(result, ui)).build(); } finally { AtlasPerfTracer.log(perf); } }  @Inject void setMetadataService(MetadataService metadataService, AtlasTypeDefStore typeDefStore); @GET @Path("{taxonomyName}") @Produces(Servlets.JSON_MEDIA_TYPE) Response getTaxonomy(@Context HttpHeaders headers,
                                @Context UriInfo ui,
                                @PathParam("taxonomyName") String taxonomyName); @GET @Produces(Servlets.JSON_MEDIA_TYPE) Response getTaxonomies(@Context HttpHeaders headers, @Context UriInfo ui); @POST @Path("{taxonomyName}") @Produces(Servlets.JSON_MEDIA_TYPE) Response createTaxonomy(String body,
                                   @Context HttpHeaders headers,
                                   @Context UriInfo ui,
                                   @PathParam("taxonomyName") String taxonomyName); @PUT @Path("{taxonomyName}") @Produces(Servlets.JSON_MEDIA_TYPE) Response updateTaxonomy(String body,
                                   @Context HttpHeaders headers,
                                   @Context UriInfo ui,
                                   @PathParam("taxonomyName") String taxonomyName); @DELETE @Path("{taxonomyName}") @Produces(Servlets.JSON_MEDIA_TYPE) Response deleteTaxonomy(@Context HttpHeaders headers,
                                   @Context UriInfo ui,
                                   @PathParam("taxonomyName") String taxonomyName); @GET @Path("{taxonomyName}/terms/{termName}") @Produces(Servlets.JSON_MEDIA_TYPE) Response getTaxonomyTerm(@Context HttpHeaders headers,
                                    @Context UriInfo ui,
                                    @PathParam("taxonomyName") String taxonomyName,
                                    @PathParam("termName") String termName); @GET @Path("{taxonomyName}/terms") @Produces(Servlets.JSON_MEDIA_TYPE) Response getTaxonomyTerms(@Context HttpHeaders headers,
                                     @Context UriInfo ui,
                                     @PathParam("taxonomyName") String taxonomyName); @GET @Path("{taxonomyName}/terms/{rootTerm}/{remainder:.*}") @Produces(Servlets.JSON_MEDIA_TYPE) Response getSubTerms(@Context HttpHeaders headers,
                            @Context UriInfo ui,
                            @PathParam("taxonomyName") String taxonomyName,
                            @PathParam("rootTerm") String rootTerm,
                            @PathParam("remainder") String remainder); @POST @Path("{taxonomyName}/terms/{termName}") @Produces(Servlets.JSON_MEDIA_TYPE) Response createTerm(String body,
                               @Context HttpHeaders headers,
                               @Context UriInfo ui,
                               @PathParam("taxonomyName") String taxonomyName,
                               @PathParam("termName") String termName); @POST @Path("{taxonomyName}/terms/{termName}/{remainder:.*}") @Produces(Servlets.JSON_MEDIA_TYPE) Response createSubTerm(String body,
                                  @Context HttpHeaders headers,
                                  @Context UriInfo ui,
                                  @PathParam("taxonomyName") String taxonomyName,
                                  @PathParam("termName") String termName,
                                  @PathParam("remainder") String remainder); @PUT @Path("{taxonomyName}/terms/{termName}") @Produces(Servlets.JSON_MEDIA_TYPE) Response updateTerm(String body,
                               @Context HttpHeaders headers,
                               @Context UriInfo ui,
                               @PathParam("taxonomyName") String taxonomyName,
                               @PathParam("termName") String termName); @PUT @Path("{taxonomyName}/terms/{termName}/{remainder:.*}") @Produces(Servlets.JSON_MEDIA_TYPE) Response updateSubTerm(String body,
                                  @Context HttpHeaders headers,
                                  @Context UriInfo ui,
                                  @PathParam("taxonomyName") String taxonomyName,
                                  @PathParam("termName") String termName,
                                  @PathParam("remainder") String remainder); @DELETE @Path("{taxonomyName}/terms/{termName}") @Produces(Servlets.JSON_MEDIA_TYPE) Response deleteTerm(@Context HttpHeaders headers,
                               @Context UriInfo ui,
                               @PathParam("taxonomyName") String taxonomyName,
                               @PathParam("termName") String termName); @DELETE @Path("{taxonomyName}/terms/{termName}/{remainder:.*}") @Produces(Servlets.JSON_MEDIA_TYPE) Response deleteSubTerm(@Context HttpHeaders headers,
                                  @Context UriInfo ui,
                                  @PathParam("taxonomyName") String taxonomyName,
                                  @PathParam("termName") String termName,
                                  @PathParam("remainder") String remainder);  }
@Test public void testGetSubTerms_instance() throws Exception { MetadataService metadataService = createStrictMock(MetadataService.class); AtlasTypeDefStore typeDefStore = createStrictMock(AtlasTypeDefStore.class); ResourceProvider taxonomyResourceProvider = createStrictMock(ResourceProvider.class); ResourceProvider termResourceProvider = createStrictMock(ResourceProvider.class); UriInfo uriInfo = createNiceMock(UriInfo.class); URI uri = new URI("http: JsonSerializer serializer = createStrictMock(JsonSerializer.class); PathSegment segment1 = createNiceMock(PathSegment.class); PathSegment segment2 = createNiceMock(PathSegment.class); PathSegment segment3 = createNiceMock(PathSegment.class); Capture<Request> requestCapture = newCapture(); Collection<Map<String, Object>> resultPropertyMaps = new ArrayList<>(); Map<String, Object> propertyMap = new HashMap<>(); propertyMap.put("name", "testTaxonomy.testTerm.testTerm2"); resultPropertyMaps.add(propertyMap); Result result = new Result(resultPropertyMaps); expect(uriInfo.getRequestUri()).andReturn(uri); expect(uriInfo.getPathSegments()).andReturn(Arrays.asList(segment1, segment2, segment3)); expect(segment3.getPath()).andReturn("testTerm2"); expect(termResourceProvider.getResourceById(capture(requestCapture))).andReturn(result); expect(serializer.serialize(result, uriInfo)).andReturn("Taxonomy Term Get Response"); expect(metadataService.getTypeDefinition(TaxonomyResourceProvider.TAXONOMY_TERM_TYPE)).andReturn(TaxonomyResourceProvider.TAXONOMY_TERM_TYPE + "-definition"); replay(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider, serializer, segment1, segment2, segment3); TestTaxonomyService service = new TestTaxonomyService( metadataService, typeDefStore, taxonomyResourceProvider, termResourceProvider, serializer); Response response = service.getSubTerms(null, uriInfo, "testTaxonomy", "testTerm", "/terms/testTerm2"); Request request = requestCapture.getValue(); assertEquals(request.getQueryProperties().size(), 1); TermPath termPath = (TermPath) request.getQueryProperties().get("termPath"); assertEquals(termPath.getFullyQualifiedName(), "testTaxonomy.testTerm.testTerm2"); assertNull(request.getQueryString()); assertEquals(response.getStatus(), 200); assertEquals(response.getEntity(), "Taxonomy Term Get Response"); verify(uriInfo, taxonomyResourceProvider, termResourceProvider, serializer, segment1, segment2, segment3); }
@Test public void testGetSubTerms_collection() throws Exception { MetadataService metadataService = createStrictMock(MetadataService.class); AtlasTypeDefStore typeDefStore = createStrictMock(AtlasTypeDefStore.class); ResourceProvider taxonomyResourceProvider = createStrictMock(ResourceProvider.class); ResourceProvider termResourceProvider = createStrictMock(ResourceProvider.class); UriInfo uriInfo = createNiceMock(UriInfo.class); URI uri = new URI("http: JsonSerializer serializer = createStrictMock(JsonSerializer.class); PathSegment segment1 = createNiceMock(PathSegment.class); PathSegment segment2 = createNiceMock(PathSegment.class); PathSegment segment3 = createNiceMock(PathSegment.class); Capture<Request> requestCapture = newCapture(); Collection<Map<String, Object>> resultPropertyMaps = new ArrayList<>(); Map<String, Object> propertyMap = new HashMap<>(); propertyMap.put("name", "testTaxonomy.testTerm.testTerm2.testTerm3"); resultPropertyMaps.add(propertyMap); Result result = new Result(resultPropertyMaps); expect(uriInfo.getRequestUri()).andReturn(uri); expect(uriInfo.getPathSegments()).andReturn(Arrays.asList(segment1, segment2, segment3)); expect(segment3.getPath()).andReturn("terms"); expect(termResourceProvider.getResources(capture(requestCapture))).andReturn(result); expect(serializer.serialize(result, uriInfo)).andReturn("Taxonomy Term Get Response"); expect(metadataService.getTypeDefinition(TaxonomyResourceProvider.TAXONOMY_TERM_TYPE)).andReturn(TaxonomyResourceProvider.TAXONOMY_TERM_TYPE + "-definition"); replay(uriInfo, metadataService, taxonomyResourceProvider, termResourceProvider, serializer, segment1, segment2, segment3); TestTaxonomyService service = new TestTaxonomyService( metadataService, typeDefStore, taxonomyResourceProvider, termResourceProvider, serializer); Response response = service.getSubTerms(null, uriInfo, "testTaxonomy", "testTerm", "/terms/testTerm2/terms"); Request request = requestCapture.getValue(); assertEquals(request.getQueryProperties().size(), 1); TermPath termPath = (TermPath) request.getQueryProperties().get("termPath"); assertEquals(termPath.getFullyQualifiedName(), "testTaxonomy.testTerm.testTerm2."); assertEquals(request.getQueryString(), "name:testTaxonomy.testTerm.testTerm2.testTerm3"); assertEquals(response.getStatus(), 200); assertEquals(response.getEntity(), "Taxonomy Term Get Response"); verify(uriInfo, taxonomyResourceProvider, termResourceProvider, serializer, segment1, segment2, segment3); }