From 08d855815aa7806ae1092406ac8104969e1a583a Mon Sep 17 00:00:00 2001 From: Anand kumar Date: Mon, 13 Sep 2021 23:36:58 +0200 Subject: [PATCH] Updated target builder with type and Added target type client and builder Signed-off-by: Anand kumar --- .../MgmtTargetTypeClientResource.java | 19 +++ .../resource/builder/TargetBuilder.java | 12 ++ .../resource/builder/TargetTypeBuilder.java | 117 ++++++++++++++++++ 3 files changed, 148 insertions(+) create mode 100644 hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtTargetTypeClientResource.java create mode 100644 hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/TargetTypeBuilder.java diff --git a/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtTargetTypeClientResource.java b/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtTargetTypeClientResource.java new file mode 100644 index 0000000..d8399b6 --- /dev/null +++ b/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtTargetTypeClientResource.java @@ -0,0 +1,19 @@ +/** + * Copyright (c) 2021 Bosch.IO GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.mgmt.client.resource; + +import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetTypeRestApi; +import org.springframework.cloud.openfeign.FeignClient; + +/** + * Client binding for the TargetType resource of the management API. + */ +@FeignClient(name = "MgmtTargetTypeClient", url = "${hawkbit.url:localhost:8080}") +public interface MgmtTargetTypeClientResource extends MgmtTargetTypeRestApi { +} diff --git a/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/TargetBuilder.java b/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/TargetBuilder.java index cab2072..13ccfe9 100644 --- a/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/TargetBuilder.java +++ b/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/TargetBuilder.java @@ -29,6 +29,7 @@ public class TargetBuilder { private String description; private String address; private Boolean requestAttributes; + private Long targetType; /** * @param controllerId @@ -40,6 +41,16 @@ public TargetBuilder controllerId(final String controllerId) { return this; } + /** + * @param targetType + * the ID of the target type + * @return the builder itself + */ + public TargetBuilder targetType(final long targetType) { + this.targetType = targetType; + return this; + } + /** * @param name * the name of the target @@ -134,6 +145,7 @@ private MgmtTargetRequestBody doBuild(final String suffix) { body.setDescription(description); body.setAddress(address); body.setRequestAttributes(requestAttributes); + body.setTargetType(targetType); return body; } diff --git a/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/TargetTypeBuilder.java b/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/TargetTypeBuilder.java new file mode 100644 index 0000000..c0e9813 --- /dev/null +++ b/hawkbit-example-mgmt-feign-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/builder/TargetTypeBuilder.java @@ -0,0 +1,117 @@ +/** + * Copyright (c) 2021 Bosch.IO GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.mgmt.client.resource.builder; + +import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionSetTypeAssignment; +import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionSetTypeRequestBodyPost; +import org.eclipse.hawkbit.mgmt.json.model.targettype.MgmtTargetTypeRequestBodyPost; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * + * Builder pattern for building {@link MgmtTargetTypeRequestBodyPost}. + * + */ +public class TargetTypeBuilder { + + private String name; + private String description; + private String color; + private final List compatibledistributionsettypes = new ArrayList<>(); + + /** + * @param name + * the name of the target type + * @return the builder itself + */ + public TargetTypeBuilder name(final String name) { + this.name = name; + return this; + } + + /** + * @param color + * the color of the target type + * @return the builder itself + */ + public TargetTypeBuilder color(final String color) { + this.color = color; + return this; + } + + /** + * @param description + * the description + * @return the builder itself + */ + public TargetTypeBuilder description(final String description) { + this.description = description; + return this; + } + + /** + * @param distributionSetTypeIds + * the IDs of the distribution set types which should be compatible + * for the target type + * @return the builder itself + */ + public TargetTypeBuilder compatibleDsSetTypes(final Long... distributionSetTypeIds) { + for (final Long id : distributionSetTypeIds) { + final MgmtDistributionSetTypeAssignment distributionSetTypeAssignment = new MgmtDistributionSetTypeAssignment(); + distributionSetTypeAssignment.setId(id); + this.compatibledistributionsettypes.add(distributionSetTypeAssignment); + } + return this; + } + + /** + * Builds a list with a single entry of + * {@link MgmtTargetTypeRequestBodyPost} which can directly be used + * in the RESTful-API. + * + * @return a single entry list of + * {@link MgmtDistributionSetTypeRequestBodyPost} + */ + public List build() { + return Collections.singletonList(doBuild("")); + } + + /** + * Builds a list of multiple {@link MgmtTargetTypeRequestBodyPost} + * to create multiple target types at once. An increasing number + * will be added to the name of the target type. The + * compatible dsSet types will remain the same. + * + * @param count + * the amount of target type body which should be + * created + * @return a list of {@link MgmtTargetTypeRequestBodyPost} + */ + public List buildAsList(final int count) { + final List bodyList = new ArrayList<>(); + for (int index = 0; index < count; index++) { + bodyList.add(doBuild(String.valueOf(index))); + } + return bodyList; + + } + + private MgmtTargetTypeRequestBodyPost doBuild(final String suffix) { + final MgmtTargetTypeRequestBodyPost body = new MgmtTargetTypeRequestBodyPost(); + body.setName(name + suffix); + body.setColour(color); + body.setDescription(description); + body.setCompatibleDsTypes(compatibledistributionsettypes); + return body; + } + +}