/** * Find a REST resource with a project id, application id and a set of resource parts * @param restProjectId The id of the project that the resource belongs to * @param restApplicationId The id of the application that the resource belongs to * @param otherRestResourceUriParts The set of resources that will be used to identify the REST resource * @return A REST resource that matches the search criteria. Null otherwise */ protected RestResource findRestResource(final String restProjectId, final String restApplicationId, final String[] otherRestResourceUriParts) { final List<RestResource> resources = this.resourceRepository.findWithApplicationId(restApplicationId); for(RestResource restResource : resources){ if(UrlUtility.compareUri(restResource.getUri(), otherRestResourceUriParts)){ return restResource; } } return null; }
restProjectId, restApplicationId, restResource.getUri()); restResource.setInvokeAddress(invokeAddress); final ModelAndView model = createPartialModelAndView(PAGE);
/** * 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); }
/** * 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<ReadRestResourceQueryParametersOutput> process( final ServiceTask<ReadRestResourceQueryParametersInput> serviceTask) { final ReadRestResourceQueryParametersInput input = serviceTask.getInput(); final RestResource resource = super.resourceRepository.findOne(input.getResourceId()); final Set<String> pathParameters = UrlUtility.getPathParameters(resource.getUri()); final Set<RestParameterQuery> parameterQueries = pathParameters.stream() .map(pathParameter -> { RestParameterQuery query = new RestParameterQuery(); query.setQuery(pathParameter); return query; }) .collect(Collectors.toSet()); return createServiceResult(ReadRestResourceQueryParametersOutput.builder() .queries(parameterQueries) .build()); } }
final String invokeAddress = getRestInvokeAddress(protocol, request.getServerPort(), restProjectId, restApplicationId, restResource.getUri()); restMethod.setInvokeAddress(invokeAddress);
/** * 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()); } }
UrlUtility.getPathParameters(restResource.getUri(), restResourceUriParts);
Assert.assertEquals("/mock", mockResource.getUri()); Assert.assertNull(mockResource.getId()); Assert.assertNull(mockResource.getApplicationId()); Assert.assertEquals("/mock/{mockId}", mockWithParameterResource.getUri()); Assert.assertNull(mockWithParameterResource.getId()); Assert.assertNull(mockWithParameterResource.getApplicationId());
Assert.assertEquals(resourceUri, restResource.getUri()); Assert.assertNull(restResource.getId()); Assert.assertNull(restResource.getApplicationId());