Skip to content

Commit

Permalink
[#1509] Sync Target type with SW and DS types (REST Layer)
Browse files Browse the repository at this point in the history
Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
  • Loading branch information
avgustinmm committed Dec 13, 2023
1 parent 4b5a7d6 commit 685f647
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1399,8 +1399,9 @@ public Rollout createSoftDeletedRollout(final String prefix) {
*/
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)));
}

/**
Expand Down Expand Up @@ -1431,8 +1432,9 @@ public TargetType createTargetType(final String targetTypeName, final List<Distr
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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -67,35 +43,4 @@ public Long getModuleId() {
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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -62,27 +41,11 @@ public void setModuleId(final Long moduleId) {
this.moduleId = moduleId;
}

public String getKey() {
return key;
}

public void setKey(final String key) {
this.key = key;
}

public int getMaxAssignments() {
return maxAssignments;
}

public void setMaxAssignments(final int maxAssignments) {
this.maxAssignments = maxAssignments;
}

public String getColour() {
return colour;
}

public void setColour(String colour) {
this.colour = colour;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,20 @@
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
*/
Expand All @@ -46,20 +41,4 @@ public Long getTypeId() {
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
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;
Expand All @@ -20,7 +21,11 @@
* 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;
Expand All @@ -42,6 +47,15 @@ public MgmtTargetTypeRequestBodyPost setDescription(final String description) {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,8 @@ static List<MgmtDistributionSetType> toListResponse(final Collection<Distributio
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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@

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
Expand Down Expand Up @@ -48,6 +50,14 @@ static void mapNamedToNamed(final MgmtNamedEntity response, final NamedEntity ba
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}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,9 @@ static List<MgmtSoftwareModuleType> toTypesResponse(final Collection<SoftwareMod
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());
Expand Down
Loading

0 comments on commit 685f647

Please sign in to comment.