From a04b7f051e427c2042ab3d5a9101950d25132b49 Mon Sep 17 00:00:00 2001 From: Neale Upstone Date: Wed, 7 Mar 2018 16:04:28 +0000 Subject: [PATCH 1/5] Switch to Spring Boot 2.0.0 --- pom.xml | 6 +++--- weblab-cross-context/pom.xml | 2 +- weblab-forms/pom.xml | 2 +- weblab-json-schema/pom.xml | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index 9f3e209..7b6870f 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ ucles.weblab weblab-api-schema pom - 0.5-SNAPSHOT + 2.0.0-SNAPSHOT weblab-cross-context @@ -17,8 +17,8 @@ - 0.5-SNAPSHOT - 1.5.3.RELEASE + 2.0.0-SNAPSHOT + 2.0.0.RELEASE 1.8 UTF-8 UTF-8 diff --git a/weblab-cross-context/pom.xml b/weblab-cross-context/pom.xml index 3d59077..b6e16a9 100644 --- a/weblab-cross-context/pom.xml +++ b/weblab-cross-context/pom.xml @@ -5,7 +5,7 @@ weblab-api-schema ucles.weblab - 0.5-SNAPSHOT + 2.0.0-SNAPSHOT 4.0.0 diff --git a/weblab-forms/pom.xml b/weblab-forms/pom.xml index 6b73b3a..c70063c 100644 --- a/weblab-forms/pom.xml +++ b/weblab-forms/pom.xml @@ -5,7 +5,7 @@ weblab-api-schema ucles.weblab - 0.5-SNAPSHOT + 2.0.0-SNAPSHOT 4.0.0 diff --git a/weblab-json-schema/pom.xml b/weblab-json-schema/pom.xml index ce1b01e..c484921 100644 --- a/weblab-json-schema/pom.xml +++ b/weblab-json-schema/pom.xml @@ -5,7 +5,7 @@ weblab-api-schema ucles.weblab - 0.5-SNAPSHOT + 2.0.0-SNAPSHOT 4.0.0 From 18781df8a27c2c93a744753e933b9f7dfd067a44 Mon Sep 17 00:00:00 2001 From: Neale Upstone Date: Wed, 7 Mar 2018 18:43:22 +0000 Subject: [PATCH 2/5] Spring 5 and Spring Boot 2 package change fixes --- .../service/ControllerIntrospectingCrossContextConverter.java | 3 ++- .../ucles/weblab/common/forms/webapi/FormController_IT.java | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/weblab-cross-context/src/main/java/ucles/weblab/common/xc/service/ControllerIntrospectingCrossContextConverter.java b/weblab-cross-context/src/main/java/ucles/weblab/common/xc/service/ControllerIntrospectingCrossContextConverter.java index 12d4d4c..f7142af 100644 --- a/weblab-cross-context/src/main/java/ucles/weblab/common/xc/service/ControllerIntrospectingCrossContextConverter.java +++ b/weblab-cross-context/src/main/java/ucles/weblab/common/xc/service/ControllerIntrospectingCrossContextConverter.java @@ -110,7 +110,8 @@ public URI toUrn(URI url) { @Override public URI toUrl(URI urn) { return Optional.ofNullable(urnToHandlerMethodInvocation(urn)) - .map(m -> MvcUriComponentsBuilder.fromMethod(m.getHandlerMethod().getMethod(), m.getArgs()) + .map(m -> MvcUriComponentsBuilder.fromMethod( + m.getHandlerMethod().getMethod().getDeclaringClass(), m.getHandlerMethod().getMethod(), m.getArgs()) .build().toUri()) .orElse(null); } diff --git a/weblab-forms/src/test/java/ucles/weblab/common/forms/webapi/FormController_IT.java b/weblab-forms/src/test/java/ucles/weblab/common/forms/webapi/FormController_IT.java index 994fd9f..55f08e7 100644 --- a/weblab-forms/src/test/java/ucles/weblab/common/forms/webapi/FormController_IT.java +++ b/weblab-forms/src/test/java/ucles/weblab/common/forms/webapi/FormController_IT.java @@ -12,11 +12,11 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration; import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration; -import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration; +import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.MessageSource; From 4dcca884dae2885b95a63ef26e59bb0738d296d7 Mon Sep 17 00:00:00 2001 From: Neale Upstone Date: Thu, 8 Mar 2018 13:43:04 +0000 Subject: [PATCH 3/5] deleteById() cannot return int when using with CrudRepository ... when using Spring Data 2+ Alternative here would be to not use CrudRepository, but this is probably a sane move made to work better across more data store engines --- .../ucles/weblab/common/forms/domain/FormRepository.java | 4 +++- .../java/ucles/weblab/common/forms/webapi/FormDelegate.java | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/weblab-forms/src/main/java/ucles/weblab/common/forms/domain/FormRepository.java b/weblab-forms/src/main/java/ucles/weblab/common/forms/domain/FormRepository.java index d95df68..b537971 100644 --- a/weblab-forms/src/main/java/ucles/weblab/common/forms/domain/FormRepository.java +++ b/weblab-forms/src/main/java/ucles/weblab/common/forms/domain/FormRepository.java @@ -14,7 +14,9 @@ public interface FormRepository { S findOne(String id); - int deleteById(String id); + boolean existsById(String id); + + void deleteById(String id); List findByBusinessStreamsContainingAndApplicationName(String businessStream, String applicationName); } diff --git a/weblab-forms/src/main/java/ucles/weblab/common/forms/webapi/FormDelegate.java b/weblab-forms/src/main/java/ucles/weblab/common/forms/webapi/FormDelegate.java index 9e3620d..a7adaa8 100644 --- a/weblab-forms/src/main/java/ucles/weblab/common/forms/webapi/FormDelegate.java +++ b/weblab-forms/src/main/java/ucles/weblab/common/forms/webapi/FormDelegate.java @@ -84,9 +84,10 @@ public FormResource get(String id) { } public void delete(String id) { - if (formRepository.deleteById(id) == 0) { - throw new ResourceNotFoundException(id); + if (formRepository.existsById(id)) { + formRepository.deleteById(id); } + throw new ResourceNotFoundException(id); } public List list(String businessStream, String applicationName) { From b624729d0ef6261662237fa5a8bc5cfe0a4b7339 Mon Sep 17 00:00:00 2001 From: Neale Upstone Date: Fri, 9 Mar 2018 09:32:37 +0000 Subject: [PATCH 4/5] Migrate findOne() to Spring Data 2's findById() which returns Optional --- .../common/forms/domain/FormRepository.java | 3 +- .../domain/mongo/FormRepositoryMongo.java | 4 +-- .../common/forms/webapi/FormDelegate.java | 31 ++++++++----------- 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/weblab-forms/src/main/java/ucles/weblab/common/forms/domain/FormRepository.java b/weblab-forms/src/main/java/ucles/weblab/common/forms/domain/FormRepository.java index b537971..4f6329a 100644 --- a/weblab-forms/src/main/java/ucles/weblab/common/forms/domain/FormRepository.java +++ b/weblab-forms/src/main/java/ucles/weblab/common/forms/domain/FormRepository.java @@ -1,6 +1,7 @@ package ucles.weblab.common.forms.domain; import java.util.List; +import java.util.Optional; /** * @@ -12,7 +13,7 @@ public interface FormRepository { List findAllByOrderByNameAsc(); - S findOne(String id); + Optional findById(String id); boolean existsById(String id); diff --git a/weblab-forms/src/main/java/ucles/weblab/common/forms/domain/mongo/FormRepositoryMongo.java b/weblab-forms/src/main/java/ucles/weblab/common/forms/domain/mongo/FormRepositoryMongo.java index bac7aba..59d5828 100644 --- a/weblab-forms/src/main/java/ucles/weblab/common/forms/domain/mongo/FormRepositoryMongo.java +++ b/weblab-forms/src/main/java/ucles/weblab/common/forms/domain/mongo/FormRepositoryMongo.java @@ -8,7 +8,5 @@ * @author Sukhraj */ public interface FormRepositoryMongo extends FormRepository, MongoRepository { - - @Override - FormEntityMongo findOne(String id); + } diff --git a/weblab-forms/src/main/java/ucles/weblab/common/forms/webapi/FormDelegate.java b/weblab-forms/src/main/java/ucles/weblab/common/forms/webapi/FormDelegate.java index a7adaa8..82782a1 100644 --- a/weblab-forms/src/main/java/ucles/weblab/common/forms/webapi/FormDelegate.java +++ b/weblab-forms/src/main/java/ucles/weblab/common/forms/webapi/FormDelegate.java @@ -74,10 +74,7 @@ public FormResource create(FormResource resource) { public FormResource get(String id) { - FormEntity formEntity = formRepository.findOne(id); - if (formEntity == null) { - throw new ResourceNotFoundException(id); - } + FormEntity formEntity = formRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException(id)); FormResource resource = toResource(formEntity); return resource; @@ -98,11 +95,9 @@ public List list(String businessStream, String applicationName) { } public FormResource update(FormResource resource) { - FormEntity exisitingFormEntity = formRepository.findOne(resource.getFormId()); - if (exisitingFormEntity == null) { - throw new ResourceNotFoundException(resource.getFormId()); - } - String stringValue = null; + FormEntity existingEntity = formRepository.findById(resource.getFormId()) + .orElseThrow(() -> new ResourceNotFoundException(resource.getFormId())); + String stringValue; try { stringValue = objectMapper.writeValueAsString(resource.getFormDefinition()); } catch (JsonProcessingException ex) { @@ -110,16 +105,16 @@ public FormResource update(FormResource resource) { throw new BadDataException(CONVERSION_ERROR, null, ex); } - exisitingFormEntity.setDescription(resource.getDescription()); - exisitingFormEntity.setName(resource.getName()); - exisitingFormEntity.setApplicationName(resource.getApplicationName()); - exisitingFormEntity.setBusinessStreams(resource.getBusinessStreams()); - exisitingFormEntity.setDescription(resource.getDescription()); - exisitingFormEntity.setSchema(stringValue); - exisitingFormEntity.setValidFrom(resource.getValidFrom()); - exisitingFormEntity.setValidTo(resource.getValidTo()); + existingEntity.setDescription(resource.getDescription()); + existingEntity.setName(resource.getName()); + existingEntity.setApplicationName(resource.getApplicationName()); + existingEntity.setBusinessStreams(resource.getBusinessStreams()); + existingEntity.setDescription(resource.getDescription()); + existingEntity.setSchema(stringValue); + existingEntity.setValidFrom(resource.getValidFrom()); + existingEntity.setValidTo(resource.getValidTo()); - FormEntity saved = formRepository.save(exisitingFormEntity); + FormEntity saved = formRepository.save(existingEntity); FormResource savedResource = toResource(saved); return savedResource; From 7dc00802c8438b2b735c5fd717c6752b449b510d Mon Sep 17 00:00:00 2001 From: Neale Upstone Date: Sun, 11 Mar 2018 19:26:08 +0000 Subject: [PATCH 5/5] Also deploy release-2.0.x branch --- shippable.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/shippable.yml b/shippable.yml index 42a0b8e..4ea85a2 100644 --- a/shippable.yml +++ b/shippable.yml @@ -15,11 +15,9 @@ build: ci: - mkdir -p shippable/testresults - mvn --batch-mode clean - # Only deploy master - - if [[ $BRANCH == "master" ]] && [[ $IS_PULL_REQUEST != true ]]; then mvn --batch-mode --update-snapshots -Pshippable deploy; fi - # Otherwise verify all other configs - - if [[ $BRANCH == "master" ]] && [[ $IS_PULL_REQUEST == true ]]; then mvn --batch-mode --update-snapshots -Pshippable verify; fi - - if [[ $BRANCH != "master" ]]; then mvn --batch-mode --update-snapshots -Pshippable verify; fi + # Only deploy for master & release-2.0.x, otherwise just verify for branches and PRs + - if [[ $BRANCH == "master" || $BRANCH == "release-2.0.x" ]] && [[ $IS_PULL_REQUEST != true ]]; then mvn --batch-mode --update-snapshots -Pshippable deploy; fi + - if [[ $BRANCH != "master" && $BRANCH != "release-2.0.x" ]] || [[ $IS_PULL_REQUEST != true ]]; then mvn --batch-mode --update-snapshots -Pshippable verify; fi integrations: notifications: