From 906321218d79b99f7de87392526322000ae7aa4a Mon Sep 17 00:00:00 2001 From: SirWayne Date: Wed, 27 Apr 2016 15:25:39 +0200 Subject: [PATCH 1/2] Extend rest enitity builder Signed-off-by: SirWayne --- .../builder/DistributionSetBuilder.java | 16 +++++++-- .../builder/DistributionSetTypeBuilder.java | 27 ++++++++++---- .../resource/builder/RolloutBuilder.java | 14 +++++++- .../builder/SoftwareModuleBuilder.java | 36 +++++++++++++++---- 4 files changed, 77 insertions(+), 16 deletions(-) diff --git a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/DistributionSetBuilder.java b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/DistributionSetBuilder.java index 56c0ddbf8..d1b3fad35 100644 --- a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/DistributionSetBuilder.java +++ b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/DistributionSetBuilder.java @@ -24,6 +24,7 @@ public class DistributionSetBuilder { private String name; private String version; private String type; + private String description; private final List modules = new ArrayList<>(); /** @@ -63,10 +64,20 @@ public class DistributionSetBuilder { return this; } + /** + * @param description + * the description + * @return the builder itself + */ + public DistributionSetBuilder description(final String description) { + this.description = description; + return this; + } + /** * Builds a list with a single entry of - * {@link MgmtDistributionSetRequestBodyPost} which can directly be used to post - * on the RESTful-API. + * {@link MgmtDistributionSetRequestBodyPost} which can directly be used to + * post on the RESTful-API. * * @return a single entry list of {@link MgmtDistributionSetRequestBodyPost} */ @@ -98,6 +109,7 @@ public class DistributionSetBuilder { body.setName(prefixName); body.setVersion(version); body.setType(type); + body.setDescription(description); body.setModules(modules); return body; } diff --git a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/DistributionSetTypeBuilder.java b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/DistributionSetTypeBuilder.java index 909e08470..e08240de3 100644 --- a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/DistributionSetTypeBuilder.java +++ b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/DistributionSetTypeBuilder.java @@ -25,6 +25,7 @@ public class DistributionSetTypeBuilder { private String key; private String name; + private String description; private final List mandatorymodules = Lists.newArrayList(); private final List optionalmodules = Lists.newArrayList(); @@ -48,6 +49,16 @@ public class DistributionSetTypeBuilder { return this; } + /** + * @param description + * the description + * @return the builder itself + */ + public DistributionSetTypeBuilder description(final String description) { + this.description = description; + return this; + } + /** * @param softwareModuleTypeIds * the IDs of the software module types which should be mandatory @@ -81,20 +92,21 @@ public class DistributionSetTypeBuilder { /** * Builds a list with a single entry of - * {@link MgmtDistributionSetTypeRequestBodyPost} which can directly be used in - * the RESTful-API. + * {@link MgmtDistributionSetTypeRequestBodyPost} which can directly be used + * in the RESTful-API. * - * @return a single entry list of {@link MgmtDistributionSetTypeRequestBodyPost} + * @return a single entry list of + * {@link MgmtDistributionSetTypeRequestBodyPost} */ public List build() { return Lists.newArrayList(doBuild(name, key)); } /** - * Builds a list of multiple {@link MgmtDistributionSetTypeRequestBodyPost} to - * create multiple distribution set types at once. An increasing number will - * be added to the name and key of the distribution set type. The optional - * and mandatory software module types will remain the same. + * Builds a list of multiple {@link MgmtDistributionSetTypeRequestBodyPost} + * to create multiple distribution set types at once. An increasing number + * will be added to the name and key of the distribution set type. The + * optional and mandatory software module types will remain the same. * * @param count * the amount of distribution sets type body which should be @@ -114,6 +126,7 @@ public class DistributionSetTypeBuilder { final MgmtDistributionSetTypeRequestBodyPost body = new MgmtDistributionSetTypeRequestBodyPost(); body.setKey(prefixKey); body.setName(prefixName); + body.setDescription(description); body.setMandatorymodules(mandatorymodules); body.setOptionalmodules(optionalmodules); return body; diff --git a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/RolloutBuilder.java b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/RolloutBuilder.java index e9f8431d8..9ba378192 100644 --- a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/RolloutBuilder.java +++ b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/RolloutBuilder.java @@ -9,8 +9,8 @@ package org.eclipse.hawkbit.mgmt.client.resource.builder; import org.eclipse.hawkbit.mgmt.json.model.rollout.MgmtRolloutCondition; -import org.eclipse.hawkbit.mgmt.json.model.rollout.MgmtRolloutRestRequestBody; import org.eclipse.hawkbit.mgmt.json.model.rollout.MgmtRolloutCondition.Condition; +import org.eclipse.hawkbit.mgmt.json.model.rollout.MgmtRolloutRestRequestBody; /** * @@ -25,6 +25,7 @@ public class RolloutBuilder { private long distributionSetId; private String successThreshold; private String errorThreshold; + private String description; /** * @param name @@ -57,6 +58,16 @@ public class RolloutBuilder { return this; } + /** + * @param description + * the description + * @return the builder itself + */ + public RolloutBuilder description(final String description) { + this.description = description; + return this; + } + /** * @param distributionSetId * the ID of the distribution set to assign to the target in the @@ -105,6 +116,7 @@ public class RolloutBuilder { body.setAmountGroups(groupSize); body.setTargetFilterQuery(targetFilterQuery); body.setDistributionSetId(distributionSetId); + body.setDescription(description); body.setSuccessCondition(new MgmtRolloutCondition(Condition.THRESHOLD, successThreshold)); body.setErrorCondition(new MgmtRolloutCondition(Condition.THRESHOLD, errorThreshold)); return body; diff --git a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/SoftwareModuleBuilder.java b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/SoftwareModuleBuilder.java index d1b38b2b6..6f243d08a 100644 --- a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/SoftwareModuleBuilder.java +++ b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/SoftwareModuleBuilder.java @@ -26,6 +26,8 @@ public class SoftwareModuleBuilder { private String name; private String version; private String type; + private String vendor; + private String description; /** * @param name @@ -58,10 +60,30 @@ public class SoftwareModuleBuilder { return this; } + /** + * @param vendor + * the vendor + * @return the builder itself + */ + public SoftwareModuleBuilder vendor(final String vendor) { + this.vendor = vendor; + return this; + } + + /** + * @param description + * the description + * @return the builder itself + */ + public SoftwareModuleBuilder description(final String description) { + this.description = description; + return this; + } + /** * Builds a list with a single entry of - * {@link MgmtSoftwareModuleRequestBodyPost} which can directly be used in the - * RESTful-API. + * {@link MgmtSoftwareModuleRequestBodyPost} which can directly be used in + * the RESTful-API. * * @return a single entry list of {@link MgmtSoftwareModuleRequestBodyPost} */ @@ -70,10 +92,10 @@ public class SoftwareModuleBuilder { } /** - * Builds a list of multiple {@link MgmtSoftwareModuleRequestBodyPost} to create - * multiple software module at once. An increasing number will be added to - * the name of the software module. The version and type will remain the - * same. + * Builds a list of multiple {@link MgmtSoftwareModuleRequestBodyPost} to + * create multiple software module at once. An increasing number will be + * added to the name of the software module. The version and type will + * remain the same. * * @param count * the amount of software module body which should be created @@ -93,6 +115,8 @@ public class SoftwareModuleBuilder { body.setName(prefixName); body.setVersion(version); body.setType(type); + body.setVendor(vendor); + body.setDescription(description); return body; } From f86f615c917dc334c28dd20858f340ac594e9b10 Mon Sep 17 00:00:00 2001 From: SirWayne Date: Wed, 27 Apr 2016 17:34:07 +0200 Subject: [PATCH 2/2] Set MediaTye json for file upload Signed-off-by: SirWayne --- .../hawkbit/mgmt/rest/api/MgmtSoftwareModuleRestApi.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtSoftwareModuleRestApi.java b/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtSoftwareModuleRestApi.java index eb601487b..dab8cc594 100644 --- a/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtSoftwareModuleRestApi.java +++ b/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtSoftwareModuleRestApi.java @@ -53,7 +53,8 @@ public interface MgmtSoftwareModuleRestApi { * failure the JsonResponseExceptionHandler is handling the * response. */ - @RequestMapping(method = RequestMethod.POST, value = "/{softwareModuleId}/artifacts") + @RequestMapping(method = RequestMethod.POST, value = "/{softwareModuleId}/artifacts", produces = { + "application/hal+json", MediaType.APPLICATION_JSON_VALUE }) ResponseEntity uploadArtifact(@PathVariable("softwareModuleId") final Long softwareModuleId, @RequestParam("file") final MultipartFile file, @RequestParam(value = "filename", required = false) final String optionalFileName,