/** * Find a REST application with a specific name for a rest project * @param name The name of the REST application * @return A REST application that matches the search criteria. Null otherwise. */ public RestApplication findRestApplication(List<RestApplication> restApplications, String name){ for(RestApplication restApplication : restApplications){ if(restApplication.getName().equals(name)){ return restApplication; } } return null; }
/** * The method will add a new {@link RestApplication} and update an already existing {@link RestApplication}. * @param newRestApplication The new {@link RestApplication} that might be added to the final list of {@link RestApplication} (resultRestApplication). * @param existingRestApplications A list of existing {@link RestApplication} * @param resultRestApplication A list of the result of {@link RestApplication}. These will be the new {@link RestApplication}. * @since 1.10 */ private void updateRestApplication(final RestApplication newRestApplication, final List<RestApplication> existingRestApplications, final List<RestApplication> resultRestApplication){ final RestApplication existingRestApplication = findRestApplication(existingRestApplications, newRestApplication.getName()); if(existingRestApplication == null){ resultRestApplication.add(newRestApplication); return; } final List<RestResource> existingRestResources = this.resourceRepository.findWithApplicationId(existingRestApplication.getId()); final List<RestResource> resultRestResources = new ArrayList<RestResource>(); for(RestResource newRestResource : newRestApplication.getResources()) { updateRestResource(newRestResource, existingRestResources, resultRestResources); } resultRestApplication.add(existingRestApplication); newRestApplication.setResources(resultRestResources); // Remove the existing REST application from the list of existing REST application // This is done so that we can add the REST applications which have not been // either updated or re-added from the import. existingRestApplications.remove(existingRestApplication); }
searchResult.setTitle(application.getName()); searchResult.setLink(REST + SLASH + PROJECT + SLASH + application.getProjectId() + SLASH + APPLICATION + SLASH + application.getId());
/** * 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<UpdateRestApplicationOutput> process(final ServiceTask<UpdateRestApplicationInput> serviceTask) { final UpdateRestApplicationInput input = serviceTask.getInput(); final RestApplication updated = input.getRestApplication(); final RestApplication existing = this.applicationRepository.findOne(input.getRestApplicationId()); existing.setName(updated.getName()); final RestApplication updatedRestApplication = this.applicationRepository.update(input.getRestApplicationId(), existing); return createServiceResult(UpdateRestApplicationOutput.builder() .updatedRestApplication(updatedRestApplication) .build()); } }
Assert.assertEquals("Castle Mock Swagger", restApplication.getName()); Assert.assertNull(restApplication.getId()); Assert.assertNull(restApplication.getProjectId());
final HttpMethod httpMethod, final boolean generatedResponse){ Assert.assertEquals(applicationName, restApplication.getName()); Assert.assertNull(restApplication.getId()); Assert.assertNull(restApplication.getProjectId());