/** * 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); }
restResource.setName(resourceName); restResource.setUri(baseUri.orElse("") + resourceName); restApplication.getResources().add(restResource);
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; }
for (RestResource resource : application.getResources()) { if(this.resourceRepository.exists(resource.getId())){ throw new IllegalArgumentException("A resource with the following key already exists: " + resource.getId());
restApplication.getResources().add(restResource);
RestApplication savedApplication = this.applicationRepository.save(application); for(RestResource restResource : application.getResources()){ restResource.setApplicationId(savedApplication.getId()); RestResource savedResource = this.resourceRepository.save(restResource);
resource.setId(restResourceV1.getId()); resource.setApplicationId(application.getId()); application.getResources().add(resource);
Assert.assertEquals(1, restApplication.getResources().size()); RestResource restResource = restApplication.getResources().get(0);
Assert.assertNull(restApplication.getId()); Assert.assertNull(restApplication.getProjectId()); Assert.assertEquals(2, restApplication.getResources().size()); final RestResource mockResource = restApplication.getResources().stream() .filter(resource -> resource.getName().equals("/mock")) .findFirst() final RestResource mockWithParameterResource = restApplication.getResources().stream() .filter(resource -> resource.getName().equals("/mock/{mockId}")) .findFirst()