diff --git a/.circleci/config.yml b/.circleci/config.yml index d4464fea..ab783903 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: @@ -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: diff --git a/build.gradle b/build.gradle index 476a9b7a..79e81f4f 100644 --- a/build.gradle +++ b/build.gradle @@ -53,3 +53,18 @@ allprojects { propertiesFile file: project.rootProject.file('versions.props') } } + +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: 'org.inferred.processors' + + sourceCompatibility = 1.8 + + tasks.withType(JavaCompile) { + options.compilerArgs += ['-XepDisableWarningsInGeneratedCode', '-Werror'] + } +} diff --git a/example-api/src/main/conjure/example-api.yml b/example-api/src/main/conjure/example-api.yml index 770cd4f9..b3e43254 100644 --- a/example-api/src/main/conjure/example-api.yml +++ b/example-api/src/main/conjure/example-api.yml @@ -1,24 +1,29 @@ types: definitions: - default-package: com.palantir.conjure.examples + default-package: com.palantir.conjure.examples.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: name: RecipeName @@ -34,25 +39,35 @@ types: services: RecipeBookService: name: Recipe Book - package: com.palantir.comnjure.examples.api + package: com.palantir.conjure.examples.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. + returns: set + + deleteRecipe: + http: DELETE /recipes/{name} + args: + name: RecipeName diff --git a/example-server/build.gradle b/example-server/build.gradle index 1bd722f0..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' @@ -33,6 +20,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 80% 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 index 93a5d147..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,23 +17,25 @@ package com.palantir.conjure.examples; import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.common.collect.ImmutableList; +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 defbfef2..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,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 java.util.List; -import java.util.Optional; +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; public final class RecipeBookResource implements RecipeBookService { - private final List recipes; + private final Map recipes; - public RecipeBookResource(List recipes) { - this.recipes = ImmutableList.copyOf(recipes); + public RecipeBookResource(Set recipes) { + this.recipes = recipes.stream() + .collect(Collectors.toConcurrentMap(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 Set getAllRecipes() { + return new HashSet<>(recipes.values()); } @Override - public List getRecipes() { - return recipes; + public void deleteRecipe(RecipeName name) { + recipes.remove(name); } } 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..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,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.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; @@ -28,7 +30,7 @@ import feign.jackson.JacksonEncoder; import feign.jaxrs.JAXRSContract; import io.dropwizard.testing.junit.DropwizardAppRule; -import java.util.List; +import java.util.Set; import org.junit.BeforeClass; import org.junit.ClassRule; import org.junit.Test; @@ -63,11 +65,11 @@ 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(); + Set recipes = client.getAllRecipes(); assertEquals(RULE.getConfiguration().getRecipes(), recipes); } }