/** * Find a REST resource with a specific name for a REST application * @param name The name of the REST resource * @return A REST resource that matches the search criteria. Null otherwise. */ public RestResource findRestResource(List<RestResource> restResources, String name){ for(RestResource restResource : restResources){ if(restResource.getName().equals(name)){ return restResource; } } return null; }
/** * The method will add a new {@link RestResource} and update an already existing {@link RestResource}. * @param newRestResource The new {@link RestResource} that might be added to the final list of {@link RestResource} (resultRestApplication). * @param existingRestResources A list of existing {@link RestResource} * @param resultRestResources A list of the result of {@link RestResource}. These will be the new {@link RestResource}. * @since 1.10 */ private void updateRestResource(final RestResource newRestResource, final List<RestResource> existingRestResources, final List<RestResource> resultRestResources){ // Check if the new REST resource already exists final RestResource existingRestResource = findRestResource(existingRestResources, newRestResource.getName()); // It doesn't exists. Simply add it to the existing application if (existingRestResource == null) { resultRestResources.add(newRestResource); return; } // Update resource existingRestResource.setUri(newRestResource.getUri()); final List<RestMethod> existingRestMethods = this.methodRepository.findWithResourceId(existingRestResource.getId()); final List<RestMethod> resultRestMethods = new ArrayList<RestMethod>(); for(RestMethod newRestMethod : newRestResource.getMethods()){ updateRestMethod(newRestMethod, existingRestMethods, resultRestMethods); } resultRestResources.add(existingRestResource); newRestResource.setMethods(resultRestMethods); }
final String projectId = this.applicationRepository.getProjectId(resource.getApplicationId()); final SearchResult searchResult = new SearchResult(); searchResult.setTitle(resource.getName()); searchResult.setLink(REST + SLASH + PROJECT + SLASH + projectId + SLASH + APPLICATION + SLASH + resource.getApplicationId()
/** * The process message is responsible for processing an incoming serviceTask and generate * a response based on the incoming serviceTask input * @param serviceTask The serviceTask that will be processed by the service * @return A result based on the processed incoming serviceTask * @see ServiceTask * @see ServiceResult */ @Override public ServiceResult<UpdateRestResourceOutput> process(final ServiceTask<UpdateRestResourceInput> serviceTask) { final UpdateRestResourceInput input = serviceTask.getInput(); final RestResource existing = this.resourceRepository.findOne(input.getRestResourceId()); final RestResource updatedRestResource = input.getRestResource(); existing.setName(updatedRestResource.getName()); existing.setUri(updatedRestResource.getUri()); this.resourceRepository.update(input.getRestResourceId(), existing); return createServiceResult(UpdateRestResourceOutput.builder() .updatedRestResource(updatedRestResource) .build()); } }
.filter(resource -> resource.getName().equals("/mock")) .findFirst() .get(); Assert.assertEquals("/mock", mockResource.getName()); Assert.assertEquals("/mock", mockResource.getUri()); Assert.assertNull(mockResource.getId()); .filter(resource -> resource.getName().equals("/mock/{mockId}")) .findFirst() .get(); Assert.assertEquals("/mock/{mockId}", mockWithParameterResource.getName()); Assert.assertEquals("/mock/{mockId}", mockWithParameterResource.getUri()); Assert.assertNull(mockWithParameterResource.getId());
RestResource restResource = restApplication.getResources().get(0); Assert.assertEquals(resourceName, restResource.getName()); Assert.assertEquals(resourceUri, restResource.getUri()); Assert.assertNull(restResource.getId());