From 4ff66f74ff4bd3c41af4171205ec14ad60062f18 Mon Sep 17 00:00:00 2001 From: forozco Date: Fri, 20 Jul 2018 10:13:59 +0100 Subject: [PATCH 1/5] expand api --- build.gradle | 21 ++++++++++ example-api/src/main/conjure/example-api.yml | 30 +++++++++++---- example-server/build.gradle | 1 + .../examples}/RecipeBookApplication.java | 0 .../examples}/RecipeBookConfiguration.java | 0 .../resources/RecipeBookResource.java | 38 ++++++++++++------- 6 files changed, 70 insertions(+), 20 deletions(-) rename example-server/src/main/java/com/palantir/{conjure.examples => conjure/examples}/RecipeBookApplication.java (100%) rename example-server/src/main/java/com/palantir/{conjure.examples => conjure/examples}/RecipeBookConfiguration.java (100%) diff --git a/build.gradle b/build.gradle index 476a9b7a..d5cd0b5e 100644 --- a/build.gradle +++ b/build.gradle @@ -53,3 +53,24 @@ allprojects { propertiesFile file: project.rootProject.file('versions.props') } } + +configure(subprojects - project(':example-api')) { + apply plugin: 'com.palantir.baseline-checkstyle' + apply plugin: 'com.palantir.baseline-eclipse' + apply plugin: 'com.palantir.baseline-error-prone' + apply plugin: 'com.palantir.baseline-idea' + apply plugin: 'java-library' + apply plugin: 'org.inferred.processors' + + sourceCompatibility = 1.8 + + tasks.withType(JavaCompile) { + options.compilerArgs += ['-XepDisableWarningsInGeneratedCode', '-Werror'] + } + + // Run `./gradlew test -Drecreate=true` to recreate all the expected + // generated code that we have checked into the repo. + tasks.withType(Test) { + systemProperty 'recreate', System.getProperty('recreate', 'false') + } +} diff --git a/example-api/src/main/conjure/example-api.yml b/example-api/src/main/conjure/example-api.yml index 770cd4f9..0ba40662 100644 --- a/example-api/src/main/conjure/example-api.yml +++ b/example-api/src/main/conjure/example-api.yml @@ -1,26 +1,32 @@ types: definitions: - default-package: com.palantir.conjure.examples + default-package: com.palantir.conjure.recipes.api objects: Temperature: fields: degree: double unit: string + Ingredient: alias: string + RecipeName: alias: string + BakeStep: fields: temperature: Temperature durationInSeconds: integer + RecipeStep: union: mix: set chop: Ingredient bake: BakeStep + Recipe: fields: + recipeId: uuid name: RecipeName steps: list @@ -34,25 +40,35 @@ types: services: RecipeBookService: name: Recipe Book - package: com.palantir.comnjure.examples.api + package: com.palantir.conjure.recipes.api base-path: / docs: | APIs for retrieving recipes endpoints: + createRecipe: + http: POST /recipes + args: + createRecipeRequest: + param-type: body + type: Recipe + getRecipe: http: GET /recipes/{name} args: - name: - type: RecipeName + name: RecipeName returns: Recipe docs: | Retrieves a recipe for the given name. @param name The name of the recipe - getRecipes: + + getAllRecipes: http: GET /recipes returns: list - docs: | - Returns a list of avaiable recipes in the book. + + deleteRecipe: + http: DELETE /recipes/{name} + args: + name: RecipeName diff --git a/example-server/build.gradle b/example-server/build.gradle index 1bd722f0..e1ab3d59 100644 --- a/example-server/build.gradle +++ b/example-server/build.gradle @@ -33,6 +33,7 @@ dependencies { } mainClassName = 'com.palantir.conjure.examples.RecipeBookApplication' + run { args 'server', 'var/conf/recipes.yml' } diff --git a/example-server/src/main/java/com/palantir/conjure.examples/RecipeBookApplication.java b/example-server/src/main/java/com/palantir/conjure/examples/RecipeBookApplication.java similarity index 100% rename from example-server/src/main/java/com/palantir/conjure.examples/RecipeBookApplication.java rename to example-server/src/main/java/com/palantir/conjure/examples/RecipeBookApplication.java diff --git a/example-server/src/main/java/com/palantir/conjure.examples/RecipeBookConfiguration.java b/example-server/src/main/java/com/palantir/conjure/examples/RecipeBookConfiguration.java similarity index 100% rename from example-server/src/main/java/com/palantir/conjure.examples/RecipeBookConfiguration.java rename to example-server/src/main/java/com/palantir/conjure/examples/RecipeBookConfiguration.java diff --git a/example-server/src/main/java/com/palantir/conjure/examples/resources/RecipeBookResource.java b/example-server/src/main/java/com/palantir/conjure/examples/resources/RecipeBookResource.java index defbfef2..b21c41ac 100644 --- a/example-server/src/main/java/com/palantir/conjure/examples/resources/RecipeBookResource.java +++ b/example-server/src/main/java/com/palantir/conjure/examples/resources/RecipeBookResource.java @@ -17,35 +17,47 @@ package com.palantir.conjure.examples.resources; import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableList; -import com.palantir.comnjure.examples.api.RecipeBookService; -import com.palantir.conjure.examples.Recipe; -import com.palantir.conjure.examples.RecipeErrors; -import com.palantir.conjure.examples.RecipeName; +import com.palantir.conjure.recipes.api.Recipe; +import com.palantir.conjure.recipes.api.RecipeBookService; +import com.palantir.conjure.recipes.api.RecipeErrors; +import com.palantir.conjure.recipes.api.RecipeName; +import java.util.ArrayList; import java.util.List; -import java.util.Optional; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; public final class RecipeBookResource implements RecipeBookService { - private final List recipes; + private final Map recipes; public RecipeBookResource(List recipes) { - this.recipes = ImmutableList.copyOf(recipes); + this.recipes = recipes.stream() + .collect(Collectors.toMap(Recipe::getName, Function.identity())); } @Override public Recipe getRecipe(RecipeName name) { Preconditions.checkNotNull(name, "Recipe name must be provided."); - Optional maybeRecipe = this.recipes.stream().filter(r -> r.getName().equals(name)).findAny(); - if (!maybeRecipe.isPresent()) { + Recipe maybeRecipe = this.recipes.get(name); + if (maybeRecipe == null) { throw RecipeErrors.recipeNotFound(name); } + return maybeRecipe; + } - return maybeRecipe.get(); + @Override + public void createRecipe(Recipe createRecipeRequest) { + recipes.put(createRecipeRequest.getName(), createRecipeRequest); + } + + @Override + public List getAllRecipes() { + return new ArrayList<>(recipes.values()); } @Override - public List getRecipes() { - return recipes; + public void deleteRecipe(RecipeName name) { + recipes.remove(name); } } From 85ebd7459162615ee60f57127dff7b1dbf8e3f75 Mon Sep 17 00:00:00 2001 From: forozco Date: Fri, 20 Jul 2018 10:36:53 +0100 Subject: [PATCH 2/5] fix tests --- example-api/src/main/conjure/example-api.yml | 1 - .../conjure/examples/RecipeBookConfiguration.java | 1 + .../conjure/examples/RecipeBookApplicationTest.java | 11 +++++------ 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/example-api/src/main/conjure/example-api.yml b/example-api/src/main/conjure/example-api.yml index 0ba40662..5e36c23c 100644 --- a/example-api/src/main/conjure/example-api.yml +++ b/example-api/src/main/conjure/example-api.yml @@ -26,7 +26,6 @@ types: Recipe: fields: - recipeId: uuid name: RecipeName steps: list diff --git a/example-server/src/main/java/com/palantir/conjure/examples/RecipeBookConfiguration.java b/example-server/src/main/java/com/palantir/conjure/examples/RecipeBookConfiguration.java index 93a5d147..4f281896 100644 --- a/example-server/src/main/java/com/palantir/conjure/examples/RecipeBookConfiguration.java +++ b/example-server/src/main/java/com/palantir/conjure/examples/RecipeBookConfiguration.java @@ -18,6 +18,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.google.common.collect.ImmutableList; +import com.palantir.conjure.recipes.api.Recipe; import io.dropwizard.Configuration; import java.util.List; import org.hibernate.validator.constraints.NotEmpty; diff --git a/example-server/src/test/java/com/palantir/conjure/examples/RecipeBookApplicationTest.java b/example-server/src/test/java/com/palantir/conjure/examples/RecipeBookApplicationTest.java index 84cc0866..fce2d3a0 100644 --- a/example-server/src/test/java/com/palantir/conjure/examples/RecipeBookApplicationTest.java +++ b/example-server/src/test/java/com/palantir/conjure/examples/RecipeBookApplicationTest.java @@ -20,7 +20,9 @@ import static org.junit.Assert.assertEquals; import com.google.common.io.Resources; -import com.palantir.comnjure.examples.api.RecipeBookService; +import com.palantir.conjure.recipes.api.Recipe; +import com.palantir.conjure.recipes.api.RecipeBookService; +import com.palantir.conjure.recipes.api.RecipeName; import feign.Client; import feign.Feign; import feign.FeignException; @@ -63,11 +65,8 @@ public void getRecipeUsingInvalidName() { public void getRecipe() { RecipeName recipeName = RecipeName.of("roasted broccoli with garlic"); Recipe recipe = client.getRecipe(recipeName); - Recipe expectedRecipe = RULE.getConfiguration().getRecipes().stream().filter( - r -> r.getName().equals(recipeName)).findFirst().get(); + Recipe expectedRecipe = RULE.getConfiguration().getRecipes().stream() + .filter(r -> r.getName().equals(recipeName)).findFirst().get(); assertEquals(expectedRecipe, recipe); - - List recipes = client.getRecipes(); - assertEquals(RULE.getConfiguration().getRecipes(), recipes); } } From 185ee94593e58628296a3d454980233de38e57bb Mon Sep 17 00:00:00 2001 From: forozco Date: Fri, 20 Jul 2018 10:54:42 +0100 Subject: [PATCH 3/5] new image --- .circleci/config.yml | 2 +- .../palantir/conjure/examples/RecipeBookApplicationTest.java | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index d4464fea..8b0f7fc1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,7 +2,7 @@ version: 2 jobs: build: docker: - - image: circleci/openjdk:10.0.1-jdk-node-browsers + - image: circleci/openjdk:8u171-jdk-node-browsers environment: GRADLE_OPTS: -Dorg.gradle.console=plain -Dorg.gradle.internal.launcher.welcomeMessageEnabled=false steps: diff --git a/example-server/src/test/java/com/palantir/conjure/examples/RecipeBookApplicationTest.java b/example-server/src/test/java/com/palantir/conjure/examples/RecipeBookApplicationTest.java index fce2d3a0..9d8a517d 100644 --- a/example-server/src/test/java/com/palantir/conjure/examples/RecipeBookApplicationTest.java +++ b/example-server/src/test/java/com/palantir/conjure/examples/RecipeBookApplicationTest.java @@ -30,7 +30,6 @@ import feign.jackson.JacksonEncoder; import feign.jaxrs.JAXRSContract; import io.dropwizard.testing.junit.DropwizardAppRule; -import java.util.List; import org.junit.BeforeClass; import org.junit.ClassRule; import org.junit.Test; From 9e8f4fd98347742117bfda6f1d2d4aa11e266f10 Mon Sep 17 00:00:00 2001 From: forozco Date: Fri, 20 Jul 2018 10:56:06 +0100 Subject: [PATCH 4/5] no maven publish --- .circleci/config.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 8b0f7fc1..ab783903 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -37,10 +37,6 @@ jobs: command: | if [[ "${CIRCLE_BRANCH}" == "develop" || "${CIRCLE_TAG}" =~ [0-9]+(\.[0-9]+)+(-[a-zA-Z]+[0-9]*)* ]]; then ./gradlew --stacktrace --continue publish - else - ./gradlew --parallel --continue publishToMavenLocal - mkdir -p ~/poms - find . -name 'pom-default.xml' -exec cp --parents {} ~/poms \; fi - store_artifacts: From 7fb8ae57e9fe52ac77473d4acdddcadde8913112 Mon Sep 17 00:00:00 2001 From: Qinfeng Chen Date: Fri, 20 Jul 2018 12:33:07 +0100 Subject: [PATCH 5/5] tweak things around --- build.gradle | 8 +------- example-api/src/main/conjure/example-api.yml | 6 +++--- example-server/build.gradle | 13 ------------ .../examples/RecipeBookConfiguration.java | 11 +++++----- .../resources/RecipeBookResource.java | 20 +++++++++---------- .../examples/RecipeBookApplicationTest.java | 10 +++++++--- 6 files changed, 27 insertions(+), 41 deletions(-) diff --git a/build.gradle b/build.gradle index d5cd0b5e..79e81f4f 100644 --- a/build.gradle +++ b/build.gradle @@ -55,11 +55,11 @@ allprojects { } configure(subprojects - project(':example-api')) { + apply plugin: 'java' apply plugin: 'com.palantir.baseline-checkstyle' apply plugin: 'com.palantir.baseline-eclipse' apply plugin: 'com.palantir.baseline-error-prone' apply plugin: 'com.palantir.baseline-idea' - apply plugin: 'java-library' apply plugin: 'org.inferred.processors' sourceCompatibility = 1.8 @@ -67,10 +67,4 @@ configure(subprojects - project(':example-api')) { tasks.withType(JavaCompile) { options.compilerArgs += ['-XepDisableWarningsInGeneratedCode', '-Werror'] } - - // Run `./gradlew test -Drecreate=true` to recreate all the expected - // generated code that we have checked into the repo. - tasks.withType(Test) { - systemProperty 'recreate', System.getProperty('recreate', 'false') - } } diff --git a/example-api/src/main/conjure/example-api.yml b/example-api/src/main/conjure/example-api.yml index 5e36c23c..b3e43254 100644 --- a/example-api/src/main/conjure/example-api.yml +++ b/example-api/src/main/conjure/example-api.yml @@ -1,6 +1,6 @@ types: definitions: - default-package: com.palantir.conjure.recipes.api + default-package: com.palantir.conjure.examples.recipes.api objects: Temperature: fields: @@ -39,7 +39,7 @@ types: services: RecipeBookService: name: Recipe Book - package: com.palantir.conjure.recipes.api + package: com.palantir.conjure.examples.recipes.api base-path: / docs: | APIs for retrieving recipes @@ -65,7 +65,7 @@ services: getAllRecipes: http: GET /recipes - returns: list + returns: set deleteRecipe: http: DELETE /recipes/{name} diff --git a/example-server/build.gradle b/example-server/build.gradle index e1ab3d59..d796e290 100644 --- a/example-server/build.gradle +++ b/example-server/build.gradle @@ -1,17 +1,4 @@ -apply plugin: 'java' apply plugin: 'application' -apply plugin: 'com.palantir.baseline-checkstyle' -apply plugin: 'com.palantir.baseline-eclipse' -apply plugin: 'com.palantir.baseline-error-prone' -apply plugin: 'com.palantir.baseline-idea' -apply plugin: 'com.palantir.launch-config' -apply plugin: 'org.inferred.processors' - -tasks.withType(JavaCompile) { - options.compilerArgs += ['-XepDisableWarningsInGeneratedCode', '-Werror'] -} - -sourceCompatibility = '1.8' dependencies { processor 'org.immutables:value' diff --git a/example-server/src/main/java/com/palantir/conjure/examples/RecipeBookConfiguration.java b/example-server/src/main/java/com/palantir/conjure/examples/RecipeBookConfiguration.java index 4f281896..d5914763 100644 --- a/example-server/src/main/java/com/palantir/conjure/examples/RecipeBookConfiguration.java +++ b/example-server/src/main/java/com/palantir/conjure/examples/RecipeBookConfiguration.java @@ -17,24 +17,25 @@ package com.palantir.conjure.examples; import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.common.collect.ImmutableList; -import com.palantir.conjure.recipes.api.Recipe; +import com.google.common.collect.ImmutableSet; +import com.palantir.conjure.examples.recipes.api.Recipe; import io.dropwizard.Configuration; import java.util.List; +import java.util.Set; import org.hibernate.validator.constraints.NotEmpty; public final class RecipeBookConfiguration extends Configuration { @NotEmpty - private List recipes; + private Set recipes; @JsonProperty - public List getRecipes() { + public Set getRecipes() { return recipes; } @JsonProperty public void setRecipes(List recipes) { - this.recipes = ImmutableList.copyOf(recipes); + this.recipes = ImmutableSet.copyOf(recipes); } } diff --git a/example-server/src/main/java/com/palantir/conjure/examples/resources/RecipeBookResource.java b/example-server/src/main/java/com/palantir/conjure/examples/resources/RecipeBookResource.java index b21c41ac..5c9676ce 100644 --- a/example-server/src/main/java/com/palantir/conjure/examples/resources/RecipeBookResource.java +++ b/example-server/src/main/java/com/palantir/conjure/examples/resources/RecipeBookResource.java @@ -17,13 +17,13 @@ package com.palantir.conjure.examples.resources; import com.google.common.base.Preconditions; -import com.palantir.conjure.recipes.api.Recipe; -import com.palantir.conjure.recipes.api.RecipeBookService; -import com.palantir.conjure.recipes.api.RecipeErrors; -import com.palantir.conjure.recipes.api.RecipeName; -import java.util.ArrayList; -import java.util.List; +import com.palantir.conjure.examples.recipes.api.Recipe; +import com.palantir.conjure.examples.recipes.api.RecipeBookService; +import com.palantir.conjure.examples.recipes.api.RecipeErrors; +import com.palantir.conjure.examples.recipes.api.RecipeName; +import java.util.HashSet; import java.util.Map; +import java.util.Set; import java.util.function.Function; import java.util.stream.Collectors; @@ -31,9 +31,9 @@ public final class RecipeBookResource implements RecipeBookService { private final Map recipes; - public RecipeBookResource(List recipes) { + public RecipeBookResource(Set recipes) { this.recipes = recipes.stream() - .collect(Collectors.toMap(Recipe::getName, Function.identity())); + .collect(Collectors.toConcurrentMap(Recipe::getName, Function.identity())); } @Override @@ -52,8 +52,8 @@ public void createRecipe(Recipe createRecipeRequest) { } @Override - public List getAllRecipes() { - return new ArrayList<>(recipes.values()); + public Set getAllRecipes() { + return new HashSet<>(recipes.values()); } @Override diff --git a/example-server/src/test/java/com/palantir/conjure/examples/RecipeBookApplicationTest.java b/example-server/src/test/java/com/palantir/conjure/examples/RecipeBookApplicationTest.java index 9d8a517d..edf001ee 100644 --- a/example-server/src/test/java/com/palantir/conjure/examples/RecipeBookApplicationTest.java +++ b/example-server/src/test/java/com/palantir/conjure/examples/RecipeBookApplicationTest.java @@ -20,9 +20,9 @@ import static org.junit.Assert.assertEquals; import com.google.common.io.Resources; -import com.palantir.conjure.recipes.api.Recipe; -import com.palantir.conjure.recipes.api.RecipeBookService; -import com.palantir.conjure.recipes.api.RecipeName; +import com.palantir.conjure.examples.recipes.api.Recipe; +import com.palantir.conjure.examples.recipes.api.RecipeBookService; +import com.palantir.conjure.examples.recipes.api.RecipeName; import feign.Client; import feign.Feign; import feign.FeignException; @@ -30,6 +30,7 @@ import feign.jackson.JacksonEncoder; import feign.jaxrs.JAXRSContract; import io.dropwizard.testing.junit.DropwizardAppRule; +import java.util.Set; import org.junit.BeforeClass; import org.junit.ClassRule; import org.junit.Test; @@ -67,5 +68,8 @@ public void getRecipe() { Recipe expectedRecipe = RULE.getConfiguration().getRecipes().stream() .filter(r -> r.getName().equals(recipeName)).findFirst().get(); assertEquals(expectedRecipe, recipe); + + Set recipes = client.getAllRecipes(); + assertEquals(RULE.getConfiguration().getRecipes(), recipes); } }