[#1509] Sync Target type with SW and DS types (REST Layer) (#1514)

Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2023-12-13 14:33:32 +02:00
committed by GitHub
parent 4b5a7d6e7d
commit 767a7e6b11
11 changed files with 117 additions and 154 deletions

View File

@@ -1399,8 +1399,9 @@ public class TestdataFactory {
*/
public TargetType findOrCreateTargetType(final String targetTypeName) {
return targetTypeManagement.getByName(targetTypeName)
.orElseGet(() -> targetTypeManagement.create(entityFactory.targetType().create().name(targetTypeName)
.description(targetTypeName + " description").colour(DEFAULT_COLOUR)));
.orElseGet(() -> targetTypeManagement.create(entityFactory.targetType().create()
.name(targetTypeName).description(targetTypeName + " description")
.key(targetTypeName + " key").colour(DEFAULT_COLOUR)));
}
/**
@@ -1431,8 +1432,9 @@ public class TestdataFactory {
public List<TargetType> createTargetTypes(final String targetTypePrefix, final int count) {
final List<TargetTypeCreate> result = Lists.newArrayListWithExpectedSize(count);
for (int i = 0; i < count; i++) {
result.add(entityFactory.targetType().create().name(targetTypePrefix + i)
.description(targetTypePrefix + " description").colour(DEFAULT_COLOUR));
result.add(entityFactory.targetType().create()
.name(targetTypePrefix + i).description(targetTypePrefix + " description")
.key(targetTypePrefix + i + " key").colour(DEFAULT_COLOUR));
}
return targetTypeManagement.create(result);
}

View File

@@ -0,0 +1,56 @@
/**
* Copyright (c) 2023 Bosch.IO GmbH and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.hawkbit.mgmt.json.model;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
/**
* A json annotated rest model for Type to RESTful API representation.
*
*/
public abstract class MgmtTypeEntity extends MgmtNamedEntity {
@JsonProperty(required = true)
@Schema(example = "id.t23")
private String key;
@JsonProperty
@Schema(example = "brown")
private String colour;
@JsonProperty
@Schema(example = "false")
private boolean deleted;
public String getKey() {
return key;
}
public void setKey(final String key) {
this.key = key;
}
public String getColour() {
return colour;
}
public void setColour(String colour) {
this.colour = colour;
}
public boolean isDeleted() {
return deleted;
}
public void setDeleted(final boolean deleted) {
this.deleted = deleted;
}
}

View File

@@ -10,49 +10,25 @@
package org.eclipse.hawkbit.mgmt.json.model.distributionsettype;
import io.swagger.v3.oas.annotations.media.Schema;
import org.eclipse.hawkbit.mgmt.json.model.MgmtNamedEntity;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.eclipse.hawkbit.mgmt.json.model.MgmtTypeEntity;
/**
* A json annotated rest model for SoftwareModuleType to RESTful API
* representation.
*
*
*
*
*/
@JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class MgmtDistributionSetType extends MgmtNamedEntity {
public class MgmtDistributionSetType extends MgmtTypeEntity {
@JsonProperty(value = "id", required = true)
@Schema(example = "99")
private Long moduleId;
@JsonProperty(required = true)
@Schema(example = "os_app")
private String key;
@JsonProperty
@Schema(example = "false")
private boolean deleted;
@JsonProperty
@Schema(example = "black")
private String colour;
public boolean isDeleted() {
return deleted;
}
public void setDeleted(final boolean deleted) {
this.deleted = deleted;
}
/**
* @return the moduleId
*/
@@ -67,35 +43,4 @@ public class MgmtDistributionSetType extends MgmtNamedEntity {
public void setModuleId(final Long moduleId) {
this.moduleId = moduleId;
}
/**
* @return the key
*/
public String getKey() {
return key;
}
/**
* @param key
* the key to set
*/
public void setKey(final String key) {
this.key = key;
}
/**
* @return the colour
*/
public String getColour() {
return colour;
}
/**
* @param colour
* the colour to set
*/
public void setColour(String colour) {
this.colour = colour;
}
}

View File

@@ -10,50 +10,29 @@
package org.eclipse.hawkbit.mgmt.json.model.softwaremoduletype;
import io.swagger.v3.oas.annotations.media.Schema;
import org.eclipse.hawkbit.mgmt.json.model.MgmtNamedEntity;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.eclipse.hawkbit.mgmt.json.model.MgmtTypeEntity;
/**
* A json annotated rest model for SoftwareModuleType to RESTful API
* representation.
*
*/
@JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class MgmtSoftwareModuleType extends MgmtNamedEntity {
public class MgmtSoftwareModuleType extends MgmtTypeEntity {
@JsonProperty(value = "id", required = true)
@Schema(example = "83")
private Long moduleId;
@JsonProperty(required = true)
@Schema(example = "OS")
private String key;
@JsonProperty
@Schema(example = "1")
private int maxAssignments;
@JsonProperty
@Schema(example = "false")
private boolean deleted;
@JsonProperty
@Schema(example = "brown")
private String colour;
public boolean isDeleted() {
return deleted;
}
public void setDeleted(final boolean deleted) {
this.deleted = deleted;
}
public Long getModuleId() {
return moduleId;
}
@@ -62,14 +41,6 @@ public class MgmtSoftwareModuleType extends MgmtNamedEntity {
this.moduleId = moduleId;
}
public String getKey() {
return key;
}
public void setKey(final String key) {
this.key = key;
}
public int getMaxAssignments() {
return maxAssignments;
}
@@ -77,12 +48,4 @@ public class MgmtSoftwareModuleType extends MgmtNamedEntity {
public void setMaxAssignments(final int maxAssignments) {
this.maxAssignments = maxAssignments;
}
public String getColour() {
return colour;
}
public void setColour(String colour) {
this.colour = colour;
}
}

View File

@@ -13,25 +13,20 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import org.eclipse.hawkbit.mgmt.json.model.MgmtNamedEntity;
import org.eclipse.hawkbit.mgmt.json.model.MgmtTypeEntity;
/**
* A json annotated rest model for TargetType to RESTful API
* representation.
*
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class MgmtTargetType extends MgmtNamedEntity {
public class MgmtTargetType extends MgmtTypeEntity {
@JsonProperty(value = "id", required = true)
@Schema(example = "26")
private Long typeId;
@JsonProperty
@Schema(example = "rgb(255,255,255")
private String colour;
/**
* @return target type ID
*/
@@ -46,20 +41,4 @@ public class MgmtTargetType extends MgmtNamedEntity {
public void setTypeId(final Long typeId) {
this.typeId = typeId;
}
/**
*
* @return the colour
*/
public String getColour() {
return colour;
}
/**
* @param colour
* the colour to set
*/
public void setColour(String colour) {
this.colour = colour;
}
}

View File

@@ -12,6 +12,7 @@ package org.eclipse.hawkbit.mgmt.json.model.targettype;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
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;
@@ -20,7 +21,11 @@ import org.eclipse.hawkbit.mgmt.json.model.softwaremoduletype.MgmtSoftwareModule
* Request Body for TargetType POST.
*
*/
public class MgmtTargetTypeRequestBodyPost extends MgmtTargetTypeRequestBodyPut{
public class MgmtTargetTypeRequestBodyPost extends MgmtTargetTypeRequestBodyPut {
@JsonProperty
@Schema(example = "id.t23")
private String key;
@JsonProperty
private List<MgmtDistributionSetTypeAssignment> compatibledistributionsettypes;
@@ -42,6 +47,15 @@ public class MgmtTargetTypeRequestBodyPost extends MgmtTargetTypeRequestBodyPut{
return this;
}
public MgmtTargetTypeRequestBodyPost setKey(final String key) {
this.key = key;
return this;
}
public String getKey() {
return key;
}
@Override
public MgmtTargetTypeRequestBodyPost setColour(final String colour) {
super.setColour(colour);

View File

@@ -80,11 +80,8 @@ final class MgmtDistributionSetTypeMapper {
static MgmtDistributionSetType toResponse(final DistributionSetType type) {
final MgmtDistributionSetType result = new MgmtDistributionSetType();
MgmtRestModelMapper.mapNamedToNamed(result, type);
result.setKey(type.getKey());
MgmtRestModelMapper.mapTypeToType(result, type);
result.setModuleId(type.getId());
result.setDeleted(type.isDeleted());
result.setColour(type.getColour());
result.add(linkTo(methodOn(MgmtDistributionSetTypeRestApi.class).getDistributionSetType(result.getModuleId()))
.withSelfRel().expand());

View File

@@ -11,12 +11,14 @@ package org.eclipse.hawkbit.mgmt.rest.resource;
import org.eclipse.hawkbit.mgmt.json.model.MgmtBaseEntity;
import org.eclipse.hawkbit.mgmt.json.model.MgmtNamedEntity;
import org.eclipse.hawkbit.mgmt.json.model.MgmtTypeEntity;
import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtActionType;
import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtCancelationType;
import org.eclipse.hawkbit.repository.model.Action.ActionType;
import org.eclipse.hawkbit.repository.model.DistributionSetInvalidation.CancelationType;
import org.eclipse.hawkbit.repository.model.NamedEntity;
import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity;
import org.eclipse.hawkbit.repository.model.Type;
/**
* A mapper which maps repository model to RESTful model representation and
@@ -48,6 +50,14 @@ public final class MgmtRestModelMapper {
response.setDescription(base.getDescription());
}
static void mapTypeToType(final MgmtTypeEntity response, final Type base) {
mapNamedToNamed(response, base);
response.setKey(base.getKey());
response.setColour(base.getColour());
response.setDeleted(base.isDeleted());
}
/**
* Convert the given {@link MgmtActionType} into a corresponding repository
* {@link ActionType}.

View File

@@ -65,12 +65,9 @@ final class MgmtSoftwareModuleTypeMapper {
static MgmtSoftwareModuleType toResponse(final SoftwareModuleType type) {
final MgmtSoftwareModuleType result = new MgmtSoftwareModuleType();
MgmtRestModelMapper.mapNamedToNamed(result, type);
result.setKey(type.getKey());
MgmtRestModelMapper.mapTypeToType(result, type);
result.setMaxAssignments(type.getMaxAssignments());
result.setModuleId(type.getId());
result.setDeleted(type.isDeleted());
result.setColour(type.getColour());
result.add(linkTo(methodOn(MgmtSoftwareModuleTypeRestApi.class).getSoftwareModuleType(result.getModuleId()))
.withSelfRel().expand());

View File

@@ -29,9 +29,7 @@ import org.eclipse.hawkbit.repository.model.TargetType;
import org.eclipse.hawkbit.rest.data.ResponseList;
/**
* A mapper which maps repository model to RESTful model representation and
* back.
*
* A mapper which maps repository model to RESTful model representation and back.
*/
public final class MgmtTargetTypeMapper {
@@ -50,8 +48,9 @@ public final class MgmtTargetTypeMapper {
private static TargetTypeCreate fromRequest(final EntityFactory entityFactory,
final MgmtTargetTypeRequestBodyPost targetTypesRest) {
return entityFactory.targetType().create().name(targetTypesRest.getName())
.description(targetTypesRest.getDescription()).colour(targetTypesRest.getColour())
return entityFactory.targetType().create()
.name(targetTypesRest.getName()).description(targetTypesRest.getDescription())
.key(targetTypesRest.getKey()).colour(targetTypesRest.getColour())
.compatible(getDistributionSets(targetTypesRest));
}
@@ -70,9 +69,9 @@ public final class MgmtTargetTypeMapper {
static MgmtTargetType toResponse(final TargetType type) {
final MgmtTargetType result = new MgmtTargetType();
MgmtRestModelMapper.mapNamedToNamed(result, type);
MgmtRestModelMapper.mapTypeToType(result, type);
result.setTypeId(type.getId());
result.setColour(type.getColour());
result.add(
linkTo(methodOn(MgmtTargetTypeRestApi.class).getTargetType(result.getTypeId())).withSelfRel().expand());
return result;

View File

@@ -98,8 +98,8 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
.andExpect(jsonPath("$.lastModifiedBy", equalTo(TEST_USER)))
.andExpect(jsonPath("$.lastModifiedAt", equalTo(testType.getLastModifiedAt())))
.andExpect(jsonPath("$._links.self.href", equalTo("http://localhost/rest/v1/targettypes/" + typeId)))
.andExpect(jsonPath("$.deleted").doesNotExist())
.andExpect(jsonPath("$.key").doesNotExist())
.andExpect(jsonPath("$.deleted", equalTo(false)))
.andExpect(jsonPath("$.key", equalTo(typeName + " key")))
.andExpect(jsonPath("$._links.compatibledistributionsettypes.href",
equalTo("http://localhost/rest/v1/targettypes/" + typeId + "/compatibledistributionsettypes")));
}
@@ -129,8 +129,8 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
.andExpect(jsonPath("$.content.[?(@.id=='" + typeId + "')].lastModifiedBy", contains(TEST_USER)))
.andExpect(jsonPath("$.content.[?(@.id=='" + typeId + "')].lastModifiedAt",
contains(testTypes.get(index).getLastModifiedAt())))
.andExpect(jsonPath("$.content.[?(@.id=='" + typeId + "')].deleted").doesNotExist())
.andExpect(jsonPath("$.content.[?(@.id=='" + typeId + "')].key").doesNotExist())
.andExpect(jsonPath("$.content.[?(@.id=='" + typeId + "')].deleted", contains(false)))
.andExpect(jsonPath("$.content.[?(@.id=='" + typeId + "')].key", contains(typeName + index + " key")))
.andExpect(jsonPath("$.content.[?(@.id=='" + typeId + "')]._links.self.href",
contains("http://localhost/rest/v1/targettypes/" + typeId)))
.andExpect(
@@ -179,8 +179,8 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
.andExpect(jsonPath("$.content.[0].createdAt", equalTo(testTypeC.getCreatedAt())))
.andExpect(jsonPath("$.content.[0].lastModifiedBy", equalTo(TEST_USER)))
.andExpect(jsonPath("$.content.[0].lastModifiedAt", equalTo(testTypeC.getLastModifiedAt())))
.andExpect(jsonPath("$.content.[0].deleted").doesNotExist())
.andExpect(jsonPath("$.content.[0].key").doesNotExist())
.andExpect(jsonPath("$.content.[0].deleted", equalTo(false)))
.andExpect(jsonPath("$.content.[0].key", equalTo(typeNameC + " key")))
.andExpect(jsonPath("$.content.[0]._links.self.href",
equalTo("http://localhost/rest/v1/targettypes/" + testTypeC.getId())))
.andExpect(jsonPath("$.content.[0]._links.compatibledistributionsettypes.href").doesNotExist())
@@ -200,8 +200,8 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
.andExpect(jsonPath("$.content.[0].createdAt", equalTo(testTypeA.getCreatedAt())))
.andExpect(jsonPath("$.content.[0].lastModifiedBy", equalTo(TEST_USER)))
.andExpect(jsonPath("$.content.[0].lastModifiedAt", equalTo(testTypeA.getLastModifiedAt())))
.andExpect(jsonPath("$.content.[0].deleted").doesNotExist())
.andExpect(jsonPath("$.content.[0].key").doesNotExist())
.andExpect(jsonPath("$.content.[0].deleted", equalTo(false)))
.andExpect(jsonPath("$.content.[0].key", equalTo(typeNameA + " key")))
.andExpect(jsonPath("$.content.[0]._links.self.href",
equalTo("http://localhost/rest/v1/targettypes/" + testTypeA.getId())))
.andExpect(jsonPath("$.content.[0]._links.compatibledistributionsettypes.href").doesNotExist())
@@ -268,8 +268,9 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
@WithUser(principal = TEST_USER, allSpPermissions = true)
@Description("Checks the correct behaviour of /rest/v1/targettypes/{id} GET requests.")
void getUpdatedTargetType() throws Exception {
TargetType testType = createTestTargetTypeInDB("TestTypeGET");
String typeNameUpdated = "TestTypeGETupdated";
final String initialTypeName = "TestTypeGET";
TargetType testType = createTestTargetTypeInDB(initialTypeName);
final String typeNameUpdated = "TestTypeGETupdated";
testType = targetTypeManagement.update(entityFactory.targetType().update(testType.getId()).name(typeNameUpdated)
.description("Updated Description").colour("#ffffff"));
@@ -283,8 +284,8 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
.andExpect(jsonPath("$.createdAt", equalTo(testType.getCreatedAt())))
.andExpect(jsonPath("$.lastModifiedBy", equalTo(TEST_USER)))
.andExpect(jsonPath("$.lastModifiedAt", equalTo(testType.getLastModifiedAt())))
.andExpect(jsonPath("$.deleted").doesNotExist())
.andExpect(jsonPath("$.key").doesNotExist());
.andExpect(jsonPath("$.deleted", equalTo(false)))
.andExpect(jsonPath("$.key", equalTo(initialTypeName + " key")));
}
@Test
@@ -437,7 +438,7 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
put(TARGETTYPE_SINGLE_ENDPOINT, testType.getId()).content(body).contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(jsonPath("$.id", equalTo(testType.getId().intValue())))
.andExpect(jsonPath("$.deleted").doesNotExist());
.andExpect(jsonPath("$.deleted", equalTo(false))); // don't delete with update
}
@Test
@@ -623,8 +624,8 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
.andExpect(jsonPath("$[" + index + "].createdAt").exists())
.andExpect(jsonPath("$[" + index + "].lastModifiedBy", equalTo(TEST_USER)))
.andExpect(jsonPath("$[" + index + "].lastModifiedAt").exists())
.andExpect(jsonPath("$[" + index + "].key").doesNotExist())
.andExpect(jsonPath("$[" + index + "].deleted").doesNotExist())
.andExpect(jsonPath("$[" + index + "].deleted", equalTo(false)))
.andExpect(jsonPath("$[" + index + "].key", startsWith("TestTypePOST")))
.andExpect(jsonPath("$[" + index + "]._links.self.href",
startsWith("http://localhost/rest/v1/targettypes/")))
.andExpect(