Feature target type entity (#1162)

* Added Target Type model

Signed-off-by: Anand kumar <anand.kumar@bosch-si.com>

* Added Target Type JPA model

Signed-off-by: Anand kumar <anand.kumar@bosch-si.com>

* Added Target Type repository model classes

Signed-off-by: Anand kumar <anand.kumar@bosch-si.com>

* Removed the name entity from Target Type

Signed-off-by: Anand kumar <anand.kumar@bosch-si.com>

* Refactored the Target Type models

Signed-off-by: Anand kumar <anand.kumar@bosch-si.com>

* Added the DB migration script and updated the Target Type models

Signed-off-by: Anand kumar <anand.kumar@bosch-si.com>

* Added target type in target Mapper

Signed-off-by: Anand kumar <anand.kumar@bosch-si.com>

* Changed the target type ID to Long

Signed-off-by: Anand kumar <anand.kumar@bosch-si.com>

* Added MYSQL DB migration script and removed the deleted column for target type

Signed-off-by: Anand kumar <anand.kumar@bosch-si.com>

* Updated the DB migration script for target table

Signed-off-by: Anand kumar <anand.kumar@bosch-si.com>

* Added manyToMany reltation between target type and Ds type

Signed-off-by: Anand kumar <anand.kumar@bosch-si.com>

* Added POSTGRESQL DB migration script

Signed-off-by: Anand kumar <anand.kumar@bosch-si.com>

* Added MSSQL SERVER DB migration script

Signed-off-by: Anand kumar <anand.kumar@bosch-si.com>

* Added DB2 DB migration script

Signed-off-by: Anand kumar <anand.kumar@bosch-si.com>

* Added missing license header and java docs

Signed-off-by: Anand kumar <anand.kumar@bosch-si.com>

* Added on delete cascade in DB migration script

Signed-off-by: Anand kumar <anand.kumar@bosch-si.com>

* Added Target Type specification

Signed-off-by: Anand kumar <anand.kumar@bosch-si.com>

* Removed the delete cascade and Added type API
Signed-off-by: Anand kumar <anand.kumar@bosch-si.com>

* fixed API doc build

Signed-off-by: Anand kumar <anand.kumar@bosch-si.com>

* Added target type management test

Signed-off-by: Anand kumar <anand.kumar@bosch-si.com>

* Added target type events test

Signed-off-by: Anand kumar <anand.kumar@bosch-si.com>

* Added target type update and unassign to target

Signed-off-by: Anand kumar <anand.kumar@bosch-si.com>

* Added API tests for assigning target type to target

Signed-off-by: Anand kumar <anand.kumar@bosch-si.com>

* Added missing license header

Signed-off-by: Anand kumar <anand.kumar@bosch-si.com>

* Added missing docs

Signed-off-by: Anand kumar <anand.kumar@bosch-si.com>

* Fixed sonar issues

Signed-off-by: Anand kumar <anand.kumar@bosch-si.com>

* Fixed license header build issue

Signed-off-by: Anand kumar <anand.kumar@bosch-si.com>

* Updated the attribute name to target type

Signed-off-by: Anand kumar <anand.kumar@bosch-si.com>

* Fixed the review comments

Signed-off-by: Anand kumar <anand.kumar@bosch-si.com>

* Removed unused error status variable

Signed-off-by: Anand kumar <anand.kumar@bosch-si.com>

* Added target API to assign target type

Signed-off-by: Anand kumar <anand.kumar@bosch-si.com>

* Added the tests for assigning target type to target

Signed-off-by: Anand kumar <anand.kumar@bosch-si.com>

* Fixed the review comments for null check

Signed-off-by: Anand kumar <anand.kumar@bosch-si.com>
This commit is contained in:
Anand Kumar
2021-08-25 12:13:27 +02:00
committed by GitHub
parent 2574581b2c
commit 3fa1dd1be4
76 changed files with 4915 additions and 41 deletions

View File

@@ -0,0 +1,20 @@
/**
* 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.json.model.distributionsettype;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.eclipse.hawkbit.mgmt.json.model.MgmtId;
/**
* Request Body of DistributionSetType for assignment operations (ID only).
*
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class MgmtDistributionSetTypeAssignment extends MgmtId {
}

View File

@@ -49,6 +49,24 @@ public class MgmtTarget extends MgmtNamedEntity {
@JsonProperty
private boolean requestAttributes;
@JsonProperty
private Long targetType;
/**
* @return Target type ID
*/
public Long getTargetType() {
return targetType;
}
/**
* @param targetType
* Target type ID
*/
public void setTargetType(Long targetType) {
this.targetType = targetType;
}
/**
* @return the controllerId
*/
@@ -150,6 +168,9 @@ public class MgmtTarget extends MgmtNamedEntity {
return securityToken;
}
/**
* @return Address
*/
public String getAddress() {
return address;
}
@@ -171,6 +192,9 @@ public class MgmtTarget extends MgmtNamedEntity {
this.securityToken = securityToken;
}
/**
* @return boolean true or false
*/
public boolean isRequestAttributes() {
return requestAttributes;
}

View File

@@ -27,10 +27,34 @@ public class MgmtTargetRequestBody {
@JsonProperty
private Boolean requestAttributes;
@JsonProperty
private Long targetType;
/**
* @return Target type ID
*/
public Long getTargetType() {
return targetType;
}
/**
* @param targetType
* Target type ID
*/
public void setTargetType(Long targetType) {
this.targetType = targetType;
}
/**
* @return token
*/
public String getSecurityToken() {
return securityToken;
}
/**
* @param securityToken Token
*/
public void setSecurityToken(final String securityToken) {
this.securityToken = securityToken;
}
@@ -83,18 +107,32 @@ public class MgmtTargetRequestBody {
return this;
}
/**
* @return address
*/
public String getAddress() {
return address;
}
/**
* @param address
* Address
*/
public void setAddress(final String address) {
this.address = address;
}
/**
* @return boolean true or false
*/
public Boolean isRequestAttributes() {
return requestAttributes;
}
/**
* @param requestAttributes
* Attributes
*/
public void setRequestAttributes(final Boolean requestAttributes) {
this.requestAttributes = requestAttributes;
}

View File

@@ -0,0 +1,61 @@
/**
* 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.json.model.targettype;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.eclipse.hawkbit.mgmt.json.model.MgmtNamedEntity;
/**
* A json annotated rest model for TargetType to RESTful API
* representation.
*
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class MgmtTargetType extends MgmtNamedEntity {
@JsonProperty(value = "id", required = true)
private Long typeId;
@JsonProperty
private String colour;
/**
* @return target type ID
*/
public Long getTypeId() {
return typeId;
}
/**
* @param typeId
* Target type ID
*/
public void setTypeId(final Long typeId) {
this.typeId = typeId;
}
/**
*
* @return the color in format #000000
*/
public String getColour() {
return colour;
}
/**
* @param colour
* in format #000000
*/
public void setColour(String colour) {
this.colour = colour;
}
}

View File

@@ -0,0 +1,69 @@
/**
* 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.json.model.targettype;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonProperty;
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.softwaremoduletype.MgmtSoftwareModuleTypeAssigment;
/**
* Request Body for TargetType POST.
*
*/
public class MgmtTargetTypeRequestBodyPost extends MgmtTargetTypeRequestBodyPut{
@JsonProperty
private List<MgmtDistributionSetTypeAssignment> compatibledistributionsettypes;
/**
* @param name
* the name to set
* @return post request body
*/
@Override
public MgmtTargetTypeRequestBodyPost setName(final String name) {
super.setName(name);
return this;
}
@Override
public MgmtTargetTypeRequestBodyPost setDescription(final String description) {
super.setDescription(description);
return this;
}
@Override
public MgmtTargetTypeRequestBodyPost setColour(final String colour) {
super.setColour(colour);
return this;
}
/**
* @return the compatible ds types
*/
public List<MgmtDistributionSetTypeAssignment> getCompatibleDsTypes() {
return compatibledistributionsettypes;
}
/**
* @param compatibleDsTypes
* the compatible ds types to set
*
* @return updated body
*/
public MgmtTargetTypeRequestBodyPost setCompatibleDsTypes(
final List<MgmtDistributionSetTypeAssignment> compatibleDsTypes) {
this.compatibledistributionsettypes = compatibleDsTypes;
return this;
}
}

View File

@@ -0,0 +1,79 @@
/**
* 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.json.model.targettype;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* Request Body for TargetType PUT.
*
*/
public class MgmtTargetTypeRequestBodyPut {
@JsonProperty(required = true)
private String name;
@JsonProperty
private String description;
@JsonProperty
private String colour;
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name
* the name to set
*
* @return updated body
*/
public MgmtTargetTypeRequestBodyPut setName(final String name) {
this.name = name;
return this;
}
/**
* @return description
*/
public String getDescription() {
return description;
}
/**
* @param description
* Description
* @return Updated body
*/
public MgmtTargetTypeRequestBodyPut setDescription(final String description) {
this.description = description;
return this;
}
/**
* @return Colour
*/
public String getColour() {
return colour;
}
/**
* @param colour
* Colour
* @return Updated body
*/
public MgmtTargetTypeRequestBodyPut setColour(final String colour) {
this.colour = colour;
return this;
}
}

View File

@@ -60,6 +60,11 @@ public final class MgmtRestConstants {
public static final String SYSTEM_V1_REQUEST_MAPPING = BASE_V1_REQUEST_MAPPING + BASE_SYSTEM_MAPPING;
/**
* The target URL mapping, href link for assigned target type.
*/
public static final String TARGET_V1_ASSIGNED_TARGET_TYPE= "targetType";
/**
* The target URL mapping, href link for assigned distribution set.
*/
@@ -99,6 +104,21 @@ public final class MgmtRestConstants {
*/
public static final String TARGET_TAG_V1_REQUEST_MAPPING = BASE_V1_REQUEST_MAPPING + "/targettags";
/**
* The target URL mapping rest resource.
*/
public static final String TARGET_TARGET_TYPE_V1_REQUEST_MAPPING = "/{targetId}/targettype";
/**
* The target type URL mapping rest resource.
*/
public static final String TARGETTYPE_V1_REQUEST_MAPPING = BASE_V1_REQUEST_MAPPING + "/targettypes";
/**
* The target type URL mapping rest resource.
*/
public static final String TARGETTYPE_V1_DS_TYPES = "compatibledistributionsettypes";
/**
* The tag URL mapping rest resource.
*

View File

@@ -10,6 +10,7 @@ package org.eclipse.hawkbit.mgmt.rest.api;
import java.util.List;
import org.eclipse.hawkbit.mgmt.json.model.MgmtId;
import org.eclipse.hawkbit.mgmt.json.model.MgmtMetadata;
import org.eclipse.hawkbit.mgmt.json.model.MgmtMetadataBodyPut;
import org.eclipse.hawkbit.mgmt.json.model.PagedList;
@@ -123,6 +124,31 @@ public interface MgmtTargetRestApi {
@DeleteMapping(value = "/{targetId}")
ResponseEntity<Void> deleteTarget(@PathVariable("targetId") String targetId);
/**
* Handles the DELETE (unassign) request of a target type.
*
* @param targetId
* the ID of the target
* @return If the given targetId could exists and could be unassign Http OK.
* In any failure the JsonResponseExceptionHandler is handling the
* response.
*/
@DeleteMapping(value = MgmtRestConstants.TARGET_TARGET_TYPE_V1_REQUEST_MAPPING)
ResponseEntity<Void> unassignTargetType(@PathVariable("targetId") String targetId);
/**
* Handles the POST (assign) request of a target type.
*
* @param targetId
* the ID of the target
* @return If the given targetId could exists and could be assign Http OK.
* In any failure the JsonResponseExceptionHandler is handling the
* response.
*/
@PostMapping(value = MgmtRestConstants.TARGET_TARGET_TYPE_V1_REQUEST_MAPPING, consumes = { MediaTypes.HAL_JSON_VALUE,
MediaType.APPLICATION_JSON_VALUE })
ResponseEntity<Void> assignTargetType(@PathVariable("targetId") String targetId, MgmtId targetTypeId);
/**
* Handles the GET request of retrieving the attributes of a specific
* target.

View File

@@ -0,0 +1,159 @@
/**
* 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.rest.api;
import java.util.List;
import org.eclipse.hawkbit.mgmt.json.model.PagedList;
import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionSetType;
import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionSetTypeAssignment;
import org.eclipse.hawkbit.mgmt.json.model.targettype.MgmtTargetType;
import org.eclipse.hawkbit.mgmt.json.model.targettype.MgmtTargetTypeRequestBodyPost;
import org.eclipse.hawkbit.mgmt.json.model.targettype.MgmtTargetTypeRequestBodyPut;
import org.springframework.hateoas.MediaTypes;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
/**
* REST Resource handling for TargetType CRUD operations.
*
*/
@RequestMapping(MgmtRestConstants.TARGETTYPE_V1_REQUEST_MAPPING)
public interface MgmtTargetTypeRestApi {
/**
* Handles the GET request of retrieving all TargetTypes.
*
* @param pagingOffsetParam
* the offset of list of target types for pagination, might not be
* present in the rest request then default value will be applied
* @param pagingLimitParam
* the limit of the paged request, might not be present in the rest
* request then default value will be applied
* @param sortParam
* the sorting parameter in the request URL, syntax
* {@code field:direction, field:direction}
* @param rsqlParam
* the search parameter in the request URL, syntax
* {@code q=name==abc}
*
* @return a list of all TargetTypes for a defined or default page request with
* status OK. The response is always paged. In any failure the
* JsonResponseExceptionHandler is handling the response.
*/
@GetMapping(produces = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE })
ResponseEntity<PagedList<MgmtTargetType>> getTargetTypes(
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) int pagingOffsetParam,
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) int pagingLimitParam,
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SORTING, required = false) String sortParam,
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SEARCH, required = false) String rsqlParam);
/**
* Handles the GET request of retrieving a single TargetType.
*
* @param targetTypeId
* the ID of the target type to retrieve
*
* @return a single target type with status OK.
*/
@GetMapping(value = "/{targetTypeId}", produces = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE })
ResponseEntity<MgmtTargetType> getTargetType(@PathVariable("targetTypeId") Long targetTypeId);
/**
* Handles the DELETE request for a single Target Type.
*
* @param targetTypeId
* the ID of the target type to retrieve
* @return status OK if delete is successful.
*
*/
@DeleteMapping(value = "/{targetTypeId}")
ResponseEntity<Void> deleteTargetType(@PathVariable("targetTypeId") Long targetTypeId);
/**
* Handles the PUT request of updating a Target Type.
*
* @param targetTypeId
* the ID of the target type in the URL
* @param restTargetType
* the target type to be updated.
* @return status OK if update is successful
*/
@PutMapping(value = "/{targetTypeId}", consumes = { MediaTypes.HAL_JSON_VALUE,
MediaType.APPLICATION_JSON_VALUE }, produces = { MediaTypes.HAL_JSON_VALUE,
MediaType.APPLICATION_JSON_VALUE })
ResponseEntity<MgmtTargetType> updateTargetType(@PathVariable("targetTypeId") Long targetTypeId,
MgmtTargetTypeRequestBodyPut restTargetType);
/**
* Handles the POST request of creating new Target Types. The request body must
* always be a list of types.
*
* @param targetTypes
* the target types to be created.
* @return In case all target types could be successfully created the
* ResponseEntity with status code 201 - Created but without
* ResponseBody. In any failure the JsonResponseExceptionHandler is
* handling the response.
*/
@PostMapping(consumes = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }, produces = {
MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE })
ResponseEntity<List<MgmtTargetType>> createTargetTypes(List<MgmtTargetTypeRequestBodyPost> targetTypes);
/**
* Handles the GET request of retrieving the list of compatible distribution set
* types in that target type.
*
* @param targetTypeId
* of the TargetType.
* @return Unpaged list of distribution set types and OK in case of success.
*/
@GetMapping(value = "/{targetTypeId}/" + MgmtRestConstants.TARGETTYPE_V1_DS_TYPES, produces = {
MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE })
ResponseEntity<List<MgmtDistributionSetType>> getCompatibleDistributionSets(
@PathVariable("targetTypeId") Long targetTypeId);
/**
* Handles DELETE request for removing the compatibility of a distribution set
* type from the target type.
*
* @param targetTypeId
* of the TargetType.
* @param distributionSetTypeId
* of the DistributionSetType.
*
* @return OK if the request was successful
*/
@DeleteMapping(value = "/{targetTypeId}/" + MgmtRestConstants.TARGETTYPE_V1_DS_TYPES + "/{distributionSetTypeId}")
ResponseEntity<Void> removeCompatibleDistributionSet(@PathVariable("targetTypeId") Long targetTypeId,
@PathVariable("distributionSetTypeId") Long distributionSetTypeId);
/**
* Handles the POST request for adding the compatibility of a distribution set
* type to a target type.
*
* @param targetTypeId
* of the TargetType.
* @param distributionSetTypeIds
* of the DistributionSetTypes as a List.
*
* @return OK if the request was successful
*/
@PostMapping(value = "/{targetTypeId}/" + MgmtRestConstants.TARGETTYPE_V1_DS_TYPES, consumes = {
MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE })
ResponseEntity<Void> addCompatibleDistributionSets(@PathVariable("targetTypeId") final Long targetTypeId,
final List<MgmtDistributionSetTypeAssignment> distributionSetTypeIds);
}