Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -306,7 +306,10 @@ public enum SpServerError {
|
||||
SP_TARGET_TYPE_INCOMPATIBLE("hawkbit.server.error.target.type.incompatible",
|
||||
"Target type of target is not compatible with distribution set."),
|
||||
|
||||
SP_STOP_ROLLOUT_FAILED("hawkbit.server.error.stopRolloutFailed", "Stopping the rollout failed");
|
||||
SP_TARGET_TYPE_KEY_OR_NAME_REQUIRED("hawkbit.server.error.target.type.keyOrNameRequired",
|
||||
"Target type key or name is required."),
|
||||
|
||||
SP_STOP_ROLLOUT_FAILED("hawkbit.server.error.stopRolloutFailed", "Stopping the rollout failed.");
|
||||
|
||||
private final String key;
|
||||
private final String message;
|
||||
|
||||
@@ -13,6 +13,7 @@ import org.eclipse.hawkbit.repository.model.BaseEntity;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.model.NamedEntity;
|
||||
import org.eclipse.hawkbit.repository.model.TargetType;
|
||||
import org.eclipse.hawkbit.repository.model.Type;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
@@ -42,12 +43,19 @@ public interface TargetTypeCreate {
|
||||
*/
|
||||
TargetTypeCreate description(@Size(max = NamedEntity.DESCRIPTION_MAX_SIZE) String description);
|
||||
|
||||
/**
|
||||
* @param key
|
||||
* for {@link TargetType#getName()}
|
||||
* @return updated builder instance
|
||||
*/
|
||||
TargetTypeCreate key(@Size(min = 1, max = Type.KEY_MAX_SIZE) @NotEmpty String key);
|
||||
|
||||
/**
|
||||
* @param colour
|
||||
* for {@link TargetType#getColour()}
|
||||
* @return updated builder instance
|
||||
*/
|
||||
TargetTypeCreate colour(@Size(max = TargetType.COLOUR_MAX_SIZE) String colour);
|
||||
TargetTypeCreate colour(@Size(max = Type.COLOUR_MAX_SIZE) String colour);
|
||||
|
||||
/**
|
||||
* @param compatible
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* 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.repository.exception;
|
||||
|
||||
import org.eclipse.hawkbit.exception.AbstractServerRtException;
|
||||
import org.eclipse.hawkbit.exception.SpServerError;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* Thrown if tried creation of type with no key nor name.
|
||||
*/
|
||||
public class TargetTypeKeyOrNameRequiredException extends AbstractServerRtException {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final SpServerError THIS_ERROR = SpServerError.SP_TARGET_TYPE_KEY_OR_NAME_REQUIRED;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
public TargetTypeKeyOrNameRequiredException(final String message) {
|
||||
super(message, THIS_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.hawkbit.repository.ValidString;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -22,11 +21,7 @@ import org.springframework.util.StringUtils;
|
||||
* @param <T>
|
||||
* update or create builder interface
|
||||
*/
|
||||
public abstract class AbstractDistributionSetTypeUpdateCreate<T> extends AbstractNamedEntityBuilder<T> {
|
||||
@ValidString
|
||||
protected String colour;
|
||||
@ValidString
|
||||
protected String key;
|
||||
public abstract class AbstractDistributionSetTypeUpdateCreate<T> extends AbstractTypeUpdateCreate<T> {
|
||||
|
||||
protected Collection<Long> mandatory;
|
||||
protected Collection<Long> optional;
|
||||
@@ -48,23 +43,4 @@ public abstract class AbstractDistributionSetTypeUpdateCreate<T> extends Abstrac
|
||||
public Optional<Collection<Long>> getOptional() {
|
||||
return Optional.ofNullable(optional);
|
||||
}
|
||||
|
||||
public T colour(final String colour) {
|
||||
this.colour = StringUtils.trimWhitespace(colour);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public Optional<String> getColour() {
|
||||
return Optional.ofNullable(colour);
|
||||
}
|
||||
|
||||
public T key(final String key) {
|
||||
this.key = StringUtils.trimWhitespace(key);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public Optional<String> getKey() {
|
||||
return Optional.ofNullable(key);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,22 +9,13 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.builder;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.hawkbit.repository.ValidString;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Create and update builder DTO.
|
||||
*
|
||||
* @param <T>
|
||||
* update or create builder interface
|
||||
*/
|
||||
public abstract class AbstractSoftwareModuleTypeUpdateCreate<T> extends AbstractNamedEntityBuilder<T> {
|
||||
@ValidString
|
||||
protected String colour;
|
||||
@ValidString
|
||||
protected String key;
|
||||
public abstract class AbstractSoftwareModuleTypeUpdateCreate<T> extends AbstractTypeUpdateCreate<T> {
|
||||
|
||||
protected int maxAssignments = 1;
|
||||
|
||||
@@ -36,23 +27,4 @@ public abstract class AbstractSoftwareModuleTypeUpdateCreate<T> extends Abstract
|
||||
public int getMaxAssignments() {
|
||||
return maxAssignments;
|
||||
}
|
||||
|
||||
public T colour(final String colour) {
|
||||
this.colour = StringUtils.trimWhitespace(colour);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public Optional<String> getColour() {
|
||||
return Optional.ofNullable(colour);
|
||||
}
|
||||
|
||||
public T key(final String key) {
|
||||
this.key = StringUtils.trimWhitespace(key);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public Optional<String> getKey() {
|
||||
return Optional.ofNullable(key);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,9 +21,7 @@ import java.util.Optional;
|
||||
* @param <T>
|
||||
* update or create builder interface
|
||||
*/
|
||||
public abstract class AbstractTargetTypeUpdateCreate<T> extends AbstractNamedEntityBuilder<T> {
|
||||
@ValidString
|
||||
protected String colour;
|
||||
public abstract class AbstractTargetTypeUpdateCreate<T> extends AbstractTypeUpdateCreate<T> {
|
||||
|
||||
protected Collection<Long> compatible;
|
||||
|
||||
@@ -43,22 +41,4 @@ public abstract class AbstractTargetTypeUpdateCreate<T> extends AbstractNamedEnt
|
||||
public Optional<Collection<Long>> getCompatible() {
|
||||
return Optional.ofNullable(compatible);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param colour
|
||||
* Colour value
|
||||
* @return generic type
|
||||
*/
|
||||
public T colour(final String colour) {
|
||||
this.colour = StringUtils.trimWhitespace(colour);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return colour
|
||||
*/
|
||||
public Optional<String> getColour() {
|
||||
return Optional.ofNullable(colour);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* 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.repository.builder;
|
||||
|
||||
import org.eclipse.hawkbit.repository.ValidString;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Create and update builder DTO.
|
||||
*
|
||||
* @param <T>
|
||||
* update or create builder interface
|
||||
*/
|
||||
public abstract class AbstractTypeUpdateCreate<T> extends AbstractNamedEntityBuilder<T> {
|
||||
|
||||
@ValidString
|
||||
protected String colour;
|
||||
@ValidString
|
||||
protected String key;
|
||||
|
||||
public T colour(final String colour) {
|
||||
this.colour = StringUtils.trimWhitespace(colour);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public Optional<String> getColour() {
|
||||
return Optional.ofNullable(colour);
|
||||
}
|
||||
|
||||
public T key(final String key) {
|
||||
this.key = StringUtils.trimWhitespace(key);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public Optional<String> getKey() {
|
||||
return Optional.ofNullable(key);
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import org.eclipse.hawkbit.repository.DistributionSetTypeManagement;
|
||||
import org.eclipse.hawkbit.repository.builder.AbstractTargetTypeUpdateCreate;
|
||||
import org.eclipse.hawkbit.repository.builder.TargetTypeCreate;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.exception.TargetTypeKeyOrNameRequiredException;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetType;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
||||
@@ -42,10 +43,12 @@ public class JpaTargetTypeCreate extends AbstractTargetTypeUpdateCreate<TargetTy
|
||||
|
||||
@Override
|
||||
public JpaTargetType build() {
|
||||
final JpaTargetType result = new JpaTargetType(name, description, colour);
|
||||
if (key == null && name == null) {
|
||||
throw new TargetTypeKeyOrNameRequiredException("Key or name of the target type shall be specified!");
|
||||
}
|
||||
|
||||
final JpaTargetType result = new JpaTargetType(key == null ? name : key, name == null ? key : name, description, colour);
|
||||
findDistributionSetTypeWithExceptionIfNotFound(compatible).forEach(result::addCompatibleDistributionSetType);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -62,5 +65,4 @@ public class JpaTargetTypeCreate extends AbstractTargetTypeUpdateCreate<TargetTy
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -67,7 +67,7 @@ public class JpaTargetType extends AbstractJpaTypeEntity implements TargetType,
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* Constructor, legacy support where <code>key</code> is set to passed <code>name</code>.
|
||||
*
|
||||
* @param name
|
||||
* of the type
|
||||
@@ -76,6 +76,7 @@ public class JpaTargetType extends AbstractJpaTypeEntity implements TargetType,
|
||||
* @param colour
|
||||
* of the type
|
||||
*/
|
||||
@Deprecated
|
||||
public JpaTargetType(final String name, final String description, final String colour) {
|
||||
this(name, name, description, colour);
|
||||
}
|
||||
|
||||
@@ -92,6 +92,7 @@ public class ResponseExceptionHandler {
|
||||
ERROR_TO_HTTP_STATUS.put(SpServerError.SP_NO_WEIGHT_PROVIDED_IN_MULTIASSIGNMENT_MODE, HttpStatus.BAD_REQUEST);
|
||||
ERROR_TO_HTTP_STATUS.put(SpServerError.SP_TARGET_TYPE_IN_USE, HttpStatus.CONFLICT);
|
||||
ERROR_TO_HTTP_STATUS.put(SpServerError.SP_TARGET_TYPE_INCOMPATIBLE, HttpStatus.BAD_REQUEST);
|
||||
ERROR_TO_HTTP_STATUS.put(SpServerError.SP_TARGET_TYPE_KEY_OR_NAME_REQUIRED, HttpStatus.BAD_REQUEST);
|
||||
ERROR_TO_HTTP_STATUS.put(SpServerError.SP_DS_INVALID, HttpStatus.BAD_REQUEST);
|
||||
ERROR_TO_HTTP_STATUS.put(SpServerError.SP_DS_INCOMPLETE, HttpStatus.BAD_REQUEST);
|
||||
ERROR_TO_HTTP_STATUS.put(SpServerError.SP_STOP_ROLLOUT_FAILED, HttpStatus.LOCKED);
|
||||
|
||||
Reference in New Issue
Block a user