public static RestApplication generateRestApplication(){ final RestApplication restApplication = new RestApplication(); restApplication.setId("REST APPLICATION"); restApplication.setName("Rest application name"); restApplication.setResources(new ArrayList<RestResource>()); return restApplication; }
/** * 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); }
public static RestProject generateFullRestProject(){ final RestProject project = new RestProject(); project.setId("REST PROJECT"); project.setName("Project name"); project.setDescription("Project description"); project.setCreated(new Date()); project.setUpdated(new Date()); project.setApplications(new ArrayList<RestApplication>()); for(int applicationIndex = 0; applicationIndex < 3; applicationIndex++){ final RestApplication restApplication = RestApplicationGenerator.generateRestApplication(); restApplication.setResources(new ArrayList<RestResource>()); project.getApplications().add(restApplication); for(int resourceIndex = 0; resourceIndex < 3; resourceIndex++){ final RestResource restResource = RestResourceGenerator.generateRestResource(); restResource.setMethods(new ArrayList<RestMethod>()); restApplication.getResources().add(restResource); for(int methodIndex = 0; methodIndex < 3; methodIndex++){ final RestMethod restMethod = RestMethodGenerator.generateRestMethod(); restMethod.setMockResponses(new ArrayList<RestMockResponse>()); restResource.getMethods().add(restMethod); for(int responseIndex = 0; responseIndex < 3; responseIndex++){ final RestMockResponse restMockResponse = RestMockResponseGenerator.generateRestMockResponse(); restMethod.getMockResponses().add(restMockResponse); } } } } return project; }
/** * The convert method provides the functionality to convert the provided {@link File} into * a list of {@link RestApplication}. * @param ramlModelResult The RAML model result * @param generateResponse Will generate a default response if true. No response will be generated if false. * @return A list of {@link RestApplication} based on the provided file. * @throws IllegalStateException In case the {@link RamlModelResult} is not parsable. */ private List<RestApplication> convert(final RamlModelResult ramlModelResult, final boolean generateResponse){ if(!ramlModelResult.getValidationResults().isEmpty()){ throw new IllegalStateException("Unable to parse the RAML file"); } String title = null; List<RestResource> restResources = new ArrayList<>(); if(ramlModelResult.getApiV08() != null){ org.raml.v2.api.model.v08.api.Api api = ramlModelResult.getApiV08(); title = api.title(); new RAML08Parser().getResources(api.resources(), restResources, "", generateResponse); } else if(ramlModelResult.getApiV10() != null){ org.raml.v2.api.model.v10.api.Api api = ramlModelResult.getApiV10(); title = api.title().value(); new RAML10Parser().getResources(api.resources(), restResources, "", generateResponse); } RestApplication restApplication = new RestApplication(); restApplication.setName(title); restApplication.setResources(restResources); return Arrays.asList(restApplication); }
/** * 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<ReadRestApplicationOutput> process(final ServiceTask<ReadRestApplicationInput> serviceTask) { final ReadRestApplicationInput input = serviceTask.getInput(); final RestApplication application = this.applicationRepository.findOne(input.getRestApplicationId()); final List<RestResource> resources = this.resourceRepository.findWithApplicationId(application.getId()); for(RestResource restResource : resources){ Map<RestMethodStatus, Integer> restMethodStatusCount = getRestMethodStatusCount(restResource); restResource.setStatusCount(restMethodStatusCount); } application.setResources(resources); return createServiceResult(ReadRestApplicationOutput.builder() .restApplication(application) .build()); } }