@PreAuthorize("hasAuthority('MODIFIER') or hasAuthority('ADMIN')") @RequestMapping(value = "/{projectId}/application/{applicationId}/create/resource", method = RequestMethod.GET) public ModelAndView defaultPage(@PathVariable final String projectId, @PathVariable final String applicationId) { final RestResource restResource = new RestResource(); restResource.setUri(SLASH); final ModelAndView model = createPartialModelAndView(PAGE); model.addObject(REST_PROJECT_ID, projectId); model.addObject(REST_APPLICATION_ID, applicationId); model.addObject(REST_RESOURCE, restResource); return model; }
public static RestResource generateRestResource(){ final RestResource restResource = new RestResource(); restResource.setId("REST Resource"); restResource.setName("Rest resource name"); restResource.setMethods(new ArrayList<RestMethod>()); restResource.setUri("URI"); return restResource; }
RestResource createRestResource(String applicationId, String uri) { RestResource restResource = new RestResource(); restResource.setApplicationId(applicationId); restResource.setUri(uri); return restResource; } }
final RestResource restResource = new RestResource(); restResource.setName(resourceName); restResource.setUri(baseUri.orElse("") + resourceName); restApplication.getResources().add(restResource);
/** * 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); }
RestResource restResource = new RestResource(); restResource.setName(uri); restResource.setUri(uri); result.add(restResource);
RestResource restResource = new RestResource(); restResource.setName(resource.displayName().value()); restResource.setUri(uri); result.add(restResource);
restResource.setUri(resourceName);
@Test(expected = IllegalArgumentException.class) public void testProcessResourceNotFound(){ RestResource restResource1 = RestResourceGenerator.generateRestResource(); restResource1.setId("Resource1"); restResource1.setUri("/user"); RestMethod restMethod1 = RestMethodGenerator.generateRestMethod(); restMethod1.setHttpMethod(HttpMethod.POST); RestMethod restMethod2 = RestMethodGenerator.generateRestMethod(); restMethod2.setHttpMethod(HttpMethod.GET); RestMethod restMethod3 = RestMethodGenerator.generateRestMethod(); restMethod3.setHttpMethod(HttpMethod.PUT); restResource1.getMethods().add(restMethod1); restResource1.getMethods().add(restMethod2); restResource1.getMethods().add(restMethod3); Mockito.when(resourceRepository.findWithApplicationId("RestApplicationId")).thenReturn(Arrays.asList(restResource1)); Mockito.when(methodRepository.findWithResourceId(restResource1.getId())).thenReturn(Arrays.asList(restMethod1, restMethod2, restMethod3)); Mockito.when(mockResponseRepository.findWithMethodId(Mockito.anyString())).thenReturn(new ArrayList<>()); IdentifyRestMethodInput input1 = IdentifyRestMethodInput.builder() .restProjectId("RestProjectId") .restApplicationId("RestApplicationId") .restResourceUri("/random") .httpMethod(HttpMethod.GET) .build(); ServiceTask<IdentifyRestMethodInput> serviceTask1 = new ServiceTask<IdentifyRestMethodInput>(input1); service.process(serviceTask1); }
RestResource restResource1 = RestResourceGenerator.generateRestResource(); restResource1.setId("Resource1"); restResource1.setUri("/user"); RestMethod restMethod1 = RestMethodGenerator.generateRestMethod(); restMethod1.setHttpMethod(HttpMethod.POST); restResource2.setUri("/user/resource"); RestMethod restMethod4 = RestMethodGenerator.generateRestMethod(); restMethod4.setHttpMethod(HttpMethod.POST);
/** * 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()); } }
RestResource restResource1 = RestResourceGenerator.generateRestResource(); restResource1.setId("Resource1"); restResource1.setUri("/user/{test}"); RestMethod restMethod1 = RestMethodGenerator.generateRestMethod(); restMethod1.setHttpMethod(HttpMethod.GET); restResource2.setUri("/user/{test}/resource"); RestMethod restMethod2 = RestMethodGenerator.generateRestMethod(); restMethod2.setHttpMethod(HttpMethod.POST);
RestResource restResource1 = RestResourceGenerator.generateRestResource(); restResource1.setId("Resource1"); restResource1.setUri("/user/{variable}.json"); RestMethod restMethod1 = RestMethodGenerator.generateRestMethod(); restMethod1.setHttpMethod(HttpMethod.GET); restResource2.setUri("/user/id.{type}"); RestMethod restMethod2 = RestMethodGenerator.generateRestMethod(); restMethod2.setHttpMethod(HttpMethod.GET); restResource3.setUri("/resource/{id}...{type}"); RestMethod restMethod3 = RestMethodGenerator.generateRestMethod(); restMethod3.setHttpMethod(HttpMethod.GET);
RestResource restResource1 = RestResourceGenerator.generateRestResource(); restResource1.setId("Resource1"); restResource1.setUri("/user"); RestMethod restMethod1 = RestMethodGenerator.generateRestMethod(); restMethod1.setHttpMethod(HttpMethod.POST); restResource2.setUri("/user/resource"); RestMethod restMethod4 = RestMethodGenerator.generateRestMethod(); restMethod4.setHttpMethod(HttpMethod.POST);
resource.setUri(restResourceV1.getUri()); resource.setName(restResourceV1.getName()); resource.setId(restResourceV1.getId());