Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce target type client and builder #58

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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 {
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class TargetBuilder {
private String description;
private String address;
private Boolean requestAttributes;
private Long targetType;

/**
* @param controllerId
Expand All @@ -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
Expand Down Expand Up @@ -134,6 +145,7 @@ private MgmtTargetRequestBody doBuild(final String suffix) {
body.setDescription(description);
body.setAddress(address);
body.setRequestAttributes(requestAttributes);
body.setTargetType(targetType);
return body;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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<MgmtDistributionSetTypeAssignment> 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<MgmtTargetTypeRequestBodyPost> 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<MgmtTargetTypeRequestBodyPost> buildAsList(final int count) {
final List<MgmtTargetTypeRequestBodyPost> 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;
}

}