@Test public void testTranslate() throws Exception { List<Entity> learningObjectiveList = new ArrayList<Entity>(); Entity loEntity = mock(Entity.class); Map<String, Object> body = new HashMap<String, Object>(); body.put("parentLearningObjective", "456"); when(loEntity.getEntityId()).thenReturn("123"); when(loEntity.getBody()).thenReturn(body); learningObjectiveList.add(loEntity); when(repository.findAll(anyString(), any(NeutralQuery.class))).thenReturn(learningObjectiveList); String newPath = translator.getTranslator("parentLearningObjective").translate("v1/learningObjectives/123/parentLearningObjectives"); assertTrue("Should match new uri", "learningObjectives/456".equals(newPath)); }
public void translate(ContainerRequest request) { String uri = request.getPath(); List<PathSegment> segments = request.getPathSegments(); String version = PathConstants.V1; if (!segments.isEmpty()) { version = segments.get(0).getPath(); } for (Map.Entry<String, URITranslation> entry : uriTranslationMap.entrySet()) { String key = entry.getKey(); if (uri.contains(key)) { String newPath = uriTranslationMap.get(key).translate(request.getPath()); if (!newPath.equals(uri)) { request.setUris(request.getBaseUri(), request.getBaseUriBuilder().path(version).path(newPath).build()); } } } }
URITranslator { public void translate(ContainerRequest request) { String uri = request.getPath(); List<PathSegment> segments = request.getPathSegments(); String version = PathConstants.V1; if (!segments.isEmpty()) { version = segments.get(0).getPath(); } for (Map.Entry<String, URITranslation> entry : uriTranslationMap.entrySet()) { String key = entry.getKey(); if (uri.contains(key)) { String newPath = uriTranslationMap.get(key).translate(request.getPath()); if (!newPath.equals(uri)) { request.setUris(request.getBaseUri(), request.getBaseUriBuilder().path(version).path(newPath).build()); } } } } }
URITranslator { public void translate(ContainerRequest request) { String uri = request.getPath(); List<PathSegment> segments = request.getPathSegments(); String version = PathConstants.V1; if (!segments.isEmpty()) { version = segments.get(0).getPath(); } for (Map.Entry<String, URITranslation> entry : uriTranslationMap.entrySet()) { String key = entry.getKey(); if (uri.contains(key)) { String newPath = uriTranslationMap.get(key).translate(request.getPath()); if (!newPath.equals(uri)) { request.setUris(request.getBaseUri(), request.getBaseUriBuilder().path(version).path(newPath).build()); } } } } URITranslator(); }
URITranslator { public void translate(ContainerRequest request) { String uri = request.getPath(); List<PathSegment> segments = request.getPathSegments(); String version = PathConstants.V1; if (!segments.isEmpty()) { version = segments.get(0).getPath(); } for (Map.Entry<String, URITranslation> entry : uriTranslationMap.entrySet()) { String key = entry.getKey(); if (uri.contains(key)) { String newPath = uriTranslationMap.get(key).translate(request.getPath()); if (!newPath.equals(uri)) { request.setUris(request.getBaseUri(), request.getBaseUriBuilder().path(version).path(newPath).build()); } } } } URITranslator(); void setRepository(PagingRepositoryDelegate<Entity> repository); void translate(ContainerRequest request); URITranslation getTranslator(String uri); }
URITranslator { public void translate(ContainerRequest request) { String uri = request.getPath(); List<PathSegment> segments = request.getPathSegments(); String version = PathConstants.V1; if (!segments.isEmpty()) { version = segments.get(0).getPath(); } for (Map.Entry<String, URITranslation> entry : uriTranslationMap.entrySet()) { String key = entry.getKey(); if (uri.contains(key)) { String newPath = uriTranslationMap.get(key).translate(request.getPath()); if (!newPath.equals(uri)) { request.setUris(request.getBaseUri(), request.getBaseUriBuilder().path(version).path(newPath).build()); } } } } URITranslator(); void setRepository(PagingRepositoryDelegate<Entity> repository); void translate(ContainerRequest request); URITranslation getTranslator(String uri);  }