Fixed entity content validation.

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
kaizimmerm
2016-09-05 14:56:28 +02:00
parent 2f415c4839
commit b317823e86
31 changed files with 234 additions and 27 deletions

View File

@@ -23,6 +23,7 @@ import org.eclipse.hawkbit.repository.SoftwareManagement;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.model.DistributionSetType;
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
import org.springframework.util.CollectionUtils;
/**
* A mapper which maps repository model to RESTful model representation and
@@ -54,26 +55,30 @@ final class MgmtDistributionSetTypeMapper {
smsRest.getName(), smsRest.getDescription());
// Add mandatory
smsRest.getMandatorymodules().stream().map(mand -> {
final SoftwareModuleType smType = softwareManagement.findSoftwareModuleTypeById(mand.getId());
if (!CollectionUtils.isEmpty(smsRest.getMandatorymodules())) {
smsRest.getMandatorymodules().stream().map(mand -> {
final SoftwareModuleType smType = softwareManagement.findSoftwareModuleTypeById(mand.getId());
if (smType == null) {
throw new EntityNotFoundException("SoftwareModuleType with ID " + mand.getId() + " not found");
}
if (smType == null) {
throw new EntityNotFoundException("SoftwareModuleType with ID " + mand.getId() + " not found");
}
return smType;
}).forEach(result::addMandatoryModuleType);
return smType;
}).forEach(result::addMandatoryModuleType);
}
// Add optional
smsRest.getOptionalmodules().stream().map(opt -> {
final SoftwareModuleType smType = softwareManagement.findSoftwareModuleTypeById(opt.getId());
if (!CollectionUtils.isEmpty(smsRest.getOptionalmodules())) {
smsRest.getOptionalmodules().stream().map(opt -> {
final SoftwareModuleType smType = softwareManagement.findSoftwareModuleTypeById(opt.getId());
if (smType == null) {
throw new EntityNotFoundException("SoftwareModuleType with ID " + opt.getId() + " not found");
}
if (smType == null) {
throw new EntityNotFoundException("SoftwareModuleType with ID " + opt.getId() + " not found");
}
return smType;
}).forEach(result::addOptionalModuleType);
return smType;
}).forEach(result::addOptionalModuleType);
}
return result;
}

View File

@@ -27,6 +27,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.apache.commons.lang3.RandomStringUtils;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.model.Action.Status;
@@ -633,6 +634,19 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
final DistributionSet missingName = testdataFactory.generateDistributionSet("missingName");
missingName.setName(null);
mvc.perform(
post("/rest/v1/distributionsets").content(JsonBuilder.distributionSets(Lists.newArrayList(missingName)))
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest());
final DistributionSet toLongName = testdataFactory.generateDistributionSet(RandomStringUtils.randomAscii(80));
mvc.perform(
post("/rest/v1/distributionsets").content(JsonBuilder.distributionSets(Lists.newArrayList(toLongName)))
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest());
// unsupported media type
mvc.perform(post("/rest/v1/distributionsets").content(JsonBuilder.distributionSets(sets))
.contentType(MediaType.APPLICATION_OCTET_STREAM)).andDo(MockMvcResultPrinter.print())

View File

@@ -24,6 +24,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.RandomStringUtils;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.repository.model.DistributionSetType;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
@@ -553,6 +554,19 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
final DistributionSetType missingName = entityFactory.generateDistributionSetType("test123", null, "Desc123");
mvc.perform(post("/rest/v1/distributionsettypes")
.content(JsonBuilder.distributionSetTypes(Lists.newArrayList(missingName)))
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
final DistributionSetType toLongName = entityFactory.generateDistributionSetType("test123",
RandomStringUtils.randomAscii(80), "Desc123");
mvc.perform(post("/rest/v1/distributionsettypes")
.content(JsonBuilder.distributionSetTypes(Lists.newArrayList(toLongName)))
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
// not allowed methods
mvc.perform(put("/rest/v1/distributionsettypes")).andDo(MockMvcResultPrinter.print())
.andExpect(status().isMethodNotAllowed());

View File

@@ -58,6 +58,7 @@ import org.springframework.mock.web.MockMultipartFile;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.web.bind.annotation.RestController;
import com.google.common.collect.Lists;
import com.jayway.jsonpath.JsonPath;
import ru.yandex.qatools.allure.annotations.Description;
@@ -456,6 +457,19 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
final SoftwareModule missingName = entityFactory.generateSoftwareModule(osType, null, "version 1", null, null);
mvc.perform(
post("/rest/v1/softwaremodules").content(JsonBuilder.softwareModules(Lists.newArrayList(missingName)))
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest());
final SoftwareModule toLongName = entityFactory.generateSoftwareModule(osType,
RandomStringUtils.randomAscii(80), "version 1", null, null);
mvc.perform(
post("/rest/v1/softwaremodules").content(JsonBuilder.softwareModules(Lists.newArrayList(toLongName)))
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest());
// unsupported media type
mvc.perform(post("/rest/v1/softwaremodules").content(JsonBuilder.softwareModules(modules))
.contentType(MediaType.APPLICATION_OCTET_STREAM)).andDo(MockMvcResultPrinter.print())

View File

@@ -24,6 +24,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.RandomStringUtils;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
@@ -37,6 +38,7 @@ import org.junit.Test;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MvcResult;
import com.google.common.collect.Lists;
import com.jayway.jsonpath.JsonPath;
import ru.yandex.qatools.allure.annotations.Description;
@@ -335,6 +337,19 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
final SoftwareModuleType missingName = entityFactory.generateSoftwareModuleType("test123", null, "Desc123", 5);
mvc.perform(post("/rest/v1/softwaremoduletypes")
.content(JsonBuilder.softwareModuleTypes(Lists.newArrayList(missingName)))
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
final SoftwareModuleType toLongName = entityFactory.generateSoftwareModuleType("test123",
RandomStringUtils.randomAscii(80), "Desc123", 5);
mvc.perform(post("/rest/v1/softwaremoduletypes")
.content(JsonBuilder.softwareModuleTypes(Lists.newArrayList(toLongName)))
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
// unsupported media type
mvc.perform(post("/rest/v1/softwaremoduletypes").content(JsonBuilder.softwareModuleTypes(types))
.contentType(MediaType.APPLICATION_OCTET_STREAM)).andDo(MockMvcResultPrinter.print())

View File

@@ -32,10 +32,12 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.apache.commons.lang3.RandomStringUtils;
import org.eclipse.hawkbit.exception.SpServerError;
import org.eclipse.hawkbit.im.authentication.SpPermission;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.repository.ActionFields;
import org.eclipse.hawkbit.repository.exception.ConstraintViolationException;
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo;
@@ -669,6 +671,48 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest {
assertThat(exceptionInfo.getErrorCode()).isEqualTo(SpServerError.SP_REST_BODY_NOT_READABLE.getKey());
}
@Test
@Description("Verfies that a mandatory properteis of new targets are validated as not null.")
public void createTargetWithMissingMandatoryPropertyBadRequest() throws Exception {
final Target test1 = entityFactory.generateTarget("id1", "token");
test1.setName(null);
final MvcResult mvcResult = mvc
.perform(post(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING)
.content(JsonBuilder.targets(Lists.newArrayList(test1), true))
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest()).andReturn();
assertThat(targetManagement.countTargetsAll()).isEqualTo(0);
// verify response json exception message
final ExceptionInfo exceptionInfo = ResourceUtility
.convertException(mvcResult.getResponse().getContentAsString());
assertThat(exceptionInfo.getExceptionClass()).isEqualTo(ConstraintViolationException.class.getName());
assertThat(exceptionInfo.getErrorCode()).isEqualTo(SpServerError.SP_REPO_CONSTRAINT_VIOLATION.getKey());
}
@Test
@Description("Verfies that a properties of new targets are validated as in allowed size range.")
public void createTargetWithInvalidPropertyBadRequest() throws Exception {
final Target test1 = entityFactory.generateTarget("id1", "token");
test1.setName(RandomStringUtils.randomAscii(80));
final MvcResult mvcResult = mvc
.perform(post(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING)
.content(JsonBuilder.targets(Lists.newArrayList(test1), true))
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest()).andReturn();
assertThat(targetManagement.countTargetsAll()).isEqualTo(0);
// verify response json exception message
final ExceptionInfo exceptionInfo = ResourceUtility
.convertException(mvcResult.getResponse().getContentAsString());
assertThat(exceptionInfo.getExceptionClass()).isEqualTo(ConstraintViolationException.class.getName());
assertThat(exceptionInfo.getErrorCode()).isEqualTo(SpServerError.SP_REPO_CONSTRAINT_VIOLATION.getKey());
}
@Test
public void createTargetsListReturnsSuccessful() throws Exception {
final Target test1 = entityFactory.generateTarget("id1", "token");

View File

@@ -131,7 +131,7 @@ public interface SoftwareManagement {
* @return created {@link Entity}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY)
List<SoftwareModuleType> createSoftwareModuleType(@NotNull final Collection<SoftwareModuleType> types);
List<SoftwareModuleType> createSoftwareModuleType(@NotNull Collection<SoftwareModuleType> types);
/**
* Creates new {@link SoftwareModuleType}.
@@ -483,21 +483,20 @@ public interface SoftwareManagement {
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
SoftwareModuleType updateSoftwareModuleType(@NotNull SoftwareModuleType sm);
/**
* Finds all meta data by the given software module id.
*
* @param softwareModuleId
* the software module id to retrieve the meta data from
*
*
* @throws RSQLParameterUnsupportedFieldException
* if a field in the RSQL string is used but not provided by the
* given {@code fieldNameProvider}
* @throws RSQLParameterSyntaxException
* if the RSQL syntax is wrong
* @return result of all meta data entries for a given software
* module id.
* @return result of all meta data entries for a given software module id.
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
List<SoftwareModuleMetadata> findSoftwareModuleMetadataBySoftwareModuleId(Long softwareModuleId);

View File

@@ -12,6 +12,8 @@ import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.eclipse.hawkbit.repository.model.MetaData;
@@ -25,9 +27,12 @@ public abstract class AbstractJpaMetaData implements MetaData {
@Id
@Column(name = "meta_key", length = 128)
@Size(min = 1, max = 128)
@NotNull
private String key;
@Column(name = "meta_value", length = 4000)
@Size(max = 4000)
@Basic
private String value;

View File

@@ -10,6 +10,8 @@ package org.eclipse.hawkbit.repository.jpa.model;
import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.eclipse.hawkbit.repository.model.NamedEntity;
import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity;
@@ -26,9 +28,12 @@ public abstract class AbstractJpaNamedEntity extends AbstractJpaTenantAwareBaseE
private static final long serialVersionUID = 1L;
@Column(name = "name", nullable = false, length = 64)
@Size(max = 64)
@NotNull
private String name;
@Column(name = "description", nullable = true, length = 512)
@Size(max = 512)
private String description;
/**

View File

@@ -10,6 +10,8 @@ package org.eclipse.hawkbit.repository.jpa.model;
import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.eclipse.hawkbit.repository.model.NamedEntity;
import org.eclipse.hawkbit.repository.model.NamedVersionedEntity;
@@ -26,6 +28,8 @@ public abstract class AbstractJpaNamedVersionedEntity extends AbstractJpaNamedEn
private static final long serialVersionUID = 1L;
@Column(name = "version", nullable = false, length = 64)
@Size(max = 64)
@NotNull
private String version;
/**

View File

@@ -10,6 +10,7 @@ package org.eclipse.hawkbit.repository.jpa.model;
import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.validation.constraints.Size;
import org.eclipse.hawkbit.repository.model.Tag;
@@ -26,6 +27,7 @@ public abstract class AbstractJpaTag extends AbstractJpaNamedEntity implements T
private static final long serialVersionUID = 1L;
@Column(name = "colour", nullable = true, length = 16)
@Size(max = 16)
private String colour;
protected AbstractJpaTag() {

View File

@@ -11,6 +11,7 @@ package org.eclipse.hawkbit.repository.jpa.model;
import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.persistence.PrePersist;
import javax.validation.constraints.Size;
import org.eclipse.hawkbit.repository.exception.TenantNotExistException;
import org.eclipse.hawkbit.repository.jpa.model.helper.SystemManagementHolder;
@@ -31,6 +32,7 @@ public abstract class AbstractJpaTenantAwareBaseEntity extends AbstractJpaBaseEn
private static final long serialVersionUID = 1L;
@Column(name = "tenant", nullable = false, insertable = false, updatable = false, length = 40)
@Size(max = 40)
private String tenant;
/**

View File

@@ -27,6 +27,7 @@ import javax.persistence.NamedEntityGraphs;
import javax.persistence.NamedSubgraph;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import org.eclipse.hawkbit.repository.eventbus.event.ActionCreatedEvent;
import org.eclipse.hawkbit.repository.eventbus.event.ActionPropertyChangeEvent;
@@ -63,13 +64,15 @@ public class JpaAction extends AbstractJpaTenantAwareBaseEntity implements Actio
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "target", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_action_target"))
@NotNull
private JpaTarget target;
@Column(name = "active")
private boolean active;
@Column(name = "action_type", nullable = false)
@Column(name = "action_type", nullable = false, length = 16)
@Enumerated(EnumType.STRING)
@NotNull
private ActionType actionType;
@Column(name = "forced_time")

View File

@@ -25,6 +25,7 @@ import javax.persistence.NamedAttributeNode;
import javax.persistence.NamedEntityGraph;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;
import org.eclipse.hawkbit.repository.jpa.cache.CacheField;
import org.eclipse.hawkbit.repository.jpa.cache.CacheKeys;
@@ -54,9 +55,11 @@ public class JpaActionStatus extends AbstractJpaTenantAwareBaseEntity implements
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "action", nullable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_act_stat_action"))
@NotNull
private JpaAction action;
@Column(name = "status")
@NotNull
private Status status;
@CascadeOnDelete

View File

@@ -33,6 +33,7 @@ import javax.persistence.NamedEntityGraph;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.validation.constraints.NotNull;
import org.eclipse.hawkbit.repository.eventbus.event.AbstractPropertyChangeEvent.PropertyChange;
import org.eclipse.hawkbit.repository.eventbus.event.DistributionCreatedEvent;
@@ -111,6 +112,7 @@ public class JpaDistributionSet extends AbstractJpaNamedVersionedEntity implemen
@ManyToOne(fetch = FetchType.LAZY, targetEntity = JpaDistributionSetType.class)
@JoinColumn(name = "ds_id", nullable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_dstype_ds"))
@NotNull
private DistributionSetType type;
@Column(name = "complete")

View File

@@ -22,6 +22,7 @@ import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.validation.constraints.Size;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetType;
@@ -50,9 +51,11 @@ public class JpaDistributionSetType extends AbstractJpaNamedEntity implements Di
private final Set<DistributionSetTypeElement> elements = new HashSet<>();
@Column(name = "type_key", nullable = false, length = 64)
@Size(max = 64)
private String key;
@Column(name = "colour", nullable = true, length = 16)
@Size(max = 16)
private String colour;
@Column(name = "deleted")

View File

@@ -20,6 +20,7 @@ import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.eclipse.hawkbit.repository.model.ExternalArtifact;
import org.eclipse.hawkbit.repository.model.ExternalArtifactProvider;
@@ -44,6 +45,7 @@ public class JpaExternalArtifact extends AbstractJpaArtifact implements External
private JpaExternalArtifactProvider externalArtifactProvider;
@Column(name = "url_suffix", length = 512)
@Size(max = 512)
private String urlSuffix;
// CascadeType.PERSIST as we register ourself at the BSM

View File

@@ -12,6 +12,7 @@ import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Index;
import javax.persistence.Table;
import javax.validation.constraints.Size;
import org.eclipse.hawkbit.repository.model.ExternalArtifact;
import org.eclipse.hawkbit.repository.model.ExternalArtifactProvider;
@@ -30,9 +31,11 @@ public class JpaExternalArtifactProvider extends AbstractJpaNamedEntity implemen
private static final long serialVersionUID = 1L;
@Column(name = "base_url", length = 512, nullable = false)
@Size(max = 512)
private String basePath;
@Column(name = "default_url_suffix", length = 512, nullable = true)
@Size(max = 512)
private String defaultSuffix;
/**

View File

@@ -18,6 +18,7 @@ import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.eclipse.hawkbit.repository.model.LocalArtifact;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
@@ -40,10 +41,12 @@ public class JpaLocalArtifact extends AbstractJpaArtifact implements LocalArtifa
@NotNull
@Column(name = "gridfs_file_name", length = 40)
@Size(max = 40)
private String gridFsFileName;
@NotNull
@Column(name = "provided_file_name", length = 256)
@Size(max = 256)
private String filename;
@ManyToOne(optional = false, cascade = { CascadeType.PERSIST })

View File

@@ -24,6 +24,8 @@ import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.eclipse.hawkbit.repository.eventbus.event.RolloutPropertyChangeEvent;
import org.eclipse.hawkbit.repository.jpa.cache.CacheField;
@@ -57,10 +59,13 @@ public class JpaRollout extends AbstractJpaNamedEntity implements Rollout, Event
private List<RolloutGroup> rolloutGroups;
@Column(name = "target_filter", length = 1024, nullable = false)
@Size(max = 1024)
@NotNull
private String targetFilterQuery;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "distribution_set", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_rolltout_ds"))
@NotNull
private JpaDistributionSet distributionSet;
@Column(name = "status")
@@ -69,8 +74,9 @@ public class JpaRollout extends AbstractJpaNamedEntity implements Rollout, Event
@Column(name = "last_check")
private long lastCheck;
@Column(name = "action_type", nullable = false)
@Column(name = "action_type", nullable = false, length = 16)
@Enumerated(EnumType.STRING)
@NotNull
private ActionType actionType = ActionType.FORCED;
@Column(name = "forced_time")

View File

@@ -24,6 +24,7 @@ import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;
import javax.validation.constraints.Size;
import org.eclipse.hawkbit.repository.eventbus.event.RolloutGroupPropertyChangeEvent;
import org.eclipse.hawkbit.repository.jpa.model.helper.EntityPropertyChangeHelper;
@@ -66,24 +67,28 @@ public class JpaRolloutGroup extends AbstractJpaNamedEntity implements RolloutGr
private RolloutGroupSuccessCondition successCondition = RolloutGroupSuccessCondition.THRESHOLD;
@Column(name = "success_condition_exp", length = 512, nullable = false)
@Size(max = 512)
private String successConditionExp;
@Column(name = "success_action", nullable = false)
private RolloutGroupSuccessAction successAction = RolloutGroupSuccessAction.NEXTGROUP;
@Column(name = "success_action_exp", length = 512, nullable = false)
@Size(max = 512)
private String successActionExp;
@Column(name = "error_condition")
private RolloutGroupErrorCondition errorCondition;
@Column(name = "error_condition_exp", length = 512)
@Size(max = 512)
private String errorConditionExp;
@Column(name = "error_action")
private RolloutGroupErrorAction errorAction;
@Column(name = "error_action_exp", length = 512)
@Size(max = 512)
private String errorActionExp;
@Column(name = "total_targets")

View File

@@ -28,6 +28,8 @@ import javax.persistence.NamedEntityGraph;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.eclipse.hawkbit.repository.model.Artifact;
import org.eclipse.hawkbit.repository.model.DistributionSet;
@@ -58,6 +60,7 @@ public class JpaSoftwareModule extends AbstractJpaNamedVersionedEntity implement
@ManyToOne
@JoinColumn(name = "module_type", nullable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_module_type"))
@NotNull
private JpaSoftwareModuleType type;
@ManyToMany(mappedBy = "modules", targetEntity = JpaDistributionSet.class, fetch = FetchType.LAZY)
@@ -67,6 +70,7 @@ public class JpaSoftwareModule extends AbstractJpaNamedVersionedEntity implement
private boolean deleted;
@Column(name = "vendor", nullable = true, length = 256)
@Size(max = 256)
private String vendor;
@OneToMany(mappedBy = "softwareModule", cascade = { CascadeType.ALL }, targetEntity = JpaLocalArtifact.class)

View File

@@ -14,6 +14,8 @@ import javax.persistence.Index;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
@@ -34,6 +36,8 @@ public class JpaSoftwareModuleType extends AbstractJpaNamedEntity implements Sof
private static final long serialVersionUID = 1L;
@Column(name = "type_key", nullable = false, length = 64)
@Size(max = 64)
@NotNull
private String key;
@Column(name = "max_ds_assignments", nullable = false)
@@ -41,6 +45,7 @@ public class JpaSoftwareModuleType extends AbstractJpaNamedEntity implements Sof
private int maxAssignments;
@Column(name = "colour", nullable = true, length = 16)
@Size(max = 16)
private String colour;
@Column(name = "deleted")

View File

@@ -74,7 +74,7 @@ public class JpaTarget extends AbstractJpaNamedEntity implements Persistable<Lon
private static final long serialVersionUID = 1L;
@Column(name = "controller_id", length = 64)
@Size(min = 1)
@Size(min = 1, max = 64)
@NotNull
private String controllerId;
@@ -107,6 +107,8 @@ public class JpaTarget extends AbstractJpaNamedEntity implements Persistable<Lon
* with this security token.
*/
@Column(name = "sec_token", insertable = true, updatable = true, nullable = false, length = 128)
@Size(max = 64)
@NotNull
private String securityToken;
@CascadeOnDelete

View File

@@ -13,6 +13,8 @@ import javax.persistence.Entity;
import javax.persistence.Index;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
@@ -30,10 +32,14 @@ import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
public class JpaTargetFilterQuery extends AbstractJpaTenantAwareBaseEntity implements TargetFilterQuery {
private static final long serialVersionUID = 7493966984413479089L;
@Column(name = "name", length = 64)
@Column(name = "name", length = 64, nullable = false)
@Size(max = 64)
@NotNull
private String name;
@Column(name = "query", length = 1024)
@Column(name = "query", length = 1024, nullable = false)
@Size(max = 1024)
@NotNull
private String query;
public JpaTargetFilterQuery() {

View File

@@ -37,6 +37,8 @@ import javax.persistence.MapsId;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.eclipse.hawkbit.repository.eventbus.event.TargetInfoUpdateEvent;
import org.eclipse.hawkbit.repository.exception.InvalidTargetAddressException;
@@ -88,6 +90,7 @@ public class JpaTargetInfo implements Persistable<Long>, TargetInfo, EventAwareE
private JpaTarget target;
@Column(name = "address", length = 512)
@Size(max = 512)
private String address;
@Column(name = "last_target_query")
@@ -96,8 +99,9 @@ public class JpaTargetInfo implements Persistable<Long>, TargetInfo, EventAwareE
@Column(name = "install_date")
private Long installationDate;
@Column(name = "update_status", nullable = false, length = 255)
@Column(name = "update_status", nullable = false, length = 16)
@Enumerated(EnumType.STRING)
@NotNull
private TargetUpdateStatus updateStatus = TargetUpdateStatus.UNKNOWN;
@ManyToOne(optional = true, fetch = FetchType.LAZY)

View File

@@ -13,6 +13,8 @@ import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.eclipse.hawkbit.repository.model.TenantConfiguration;
@@ -29,11 +31,15 @@ import org.eclipse.hawkbit.repository.model.TenantConfiguration;
public class JpaTenantConfiguration extends AbstractJpaTenantAwareBaseEntity implements TenantConfiguration {
private static final long serialVersionUID = 1L;
@Column(name = "conf_key", length = 128)
@Column(name = "conf_key", length = 128, nullable = false)
@Size(max = 128)
@NotNull
private String key;
@Column(name = "conf_value", length = 512)
@Column(name = "conf_value", length = 512, nullable = false)
@Basic
@Size(max = 512)
@NotNull
private String value;
/**

View File

@@ -19,6 +19,7 @@ import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.validation.constraints.Size;
import org.eclipse.hawkbit.repository.model.DistributionSetType;
import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity;
@@ -43,6 +44,7 @@ public class JpaTenantMetaData extends AbstractJpaBaseEntity implements TenantMe
private static final long serialVersionUID = 1L;
@Column(name = "tenant", nullable = false, length = 40)
@Size(max = 40)
private String tenant;
@OneToOne(fetch = FetchType.LAZY)

View File

@@ -0,0 +1,5 @@
ALTER TABLE sp_target_info MODIFY update_status VARCHAR(16) not null;
ALTER TABLE sp_action MODIFY action_type VARCHAR(16) not null;
ALTER TABLE sp_rollout MODIFY action_type VARCHAR(16) not null;
ALTER TABLE sp_tenant_configuration MODIFY conf_key VARCHAR(128) not null;
ALTER TABLE sp_tenant_configuration MODIFY conf_value VARCHAR(512) not null;

View File

@@ -0,0 +1,5 @@
ALTER TABLE sp_target_info MODIFY update_status VARCHAR(16) not null;
ALTER TABLE sp_action MODIFY action_type VARCHAR(16) not null;
ALTER TABLE sp_rollout MODIFY action_type VARCHAR(16) not null;
ALTER TABLE sp_tenant_configuration MODIFY conf_key VARCHAR(128) not null;
ALTER TABLE sp_tenant_configuration MODIFY conf_value VARCHAR(512) not null;

View File

@@ -506,6 +506,21 @@ public class TestdataFactory {
return distributionSet;
}
/**
* builder method for generating a {@link DistributionSet}.
*
* @param name
* {@link DistributionSet#getName()}
*
* @return the generated {@link DistributionSet}
*/
public DistributionSet generateDistributionSet(final String name) {
final DistributionSet distributionSet = entityFactory.generateDistributionSet(name, DEFAULT_VERSION, null,
findOrCreateDefaultTestDsType(), null);
distributionSet.setDescription(LOREM.words(10));
return distributionSet;
}
/**
* Creates {@link DistributionSetTag}s in repository.
*