Added tests for DS management. Removed boilerplate.
This commit is contained in:
@@ -188,11 +188,12 @@ public class DistributionSetManagement {
|
||||
toBeChangedDSs.add(set);
|
||||
}
|
||||
}
|
||||
result = new DistributionSetTagAssignmentResult(dsIds.size() - toBeChangedDSs.size(), 0, toBeChangedDSs.size(),
|
||||
Collections.emptyList(), distributionSetRepository.save(toBeChangedDSs), myTag);
|
||||
result = new DistributionSetTagAssignmentResult(dsIds.size() - toBeChangedDSs.size(), 0,
|
||||
toBeChangedDSs.size(), Collections.emptyList(), distributionSetRepository.save(toBeChangedDSs),
|
||||
myTag);
|
||||
} else {
|
||||
result = new DistributionSetTagAssignmentResult(dsIds.size() - toBeChangedDSs.size(), toBeChangedDSs.size(), 0,
|
||||
distributionSetRepository.save(toBeChangedDSs), Collections.emptyList(), myTag);
|
||||
result = new DistributionSetTagAssignmentResult(dsIds.size() - toBeChangedDSs.size(), toBeChangedDSs.size(),
|
||||
0, distributionSetRepository.save(toBeChangedDSs), Collections.emptyList(), myTag);
|
||||
}
|
||||
|
||||
final DistributionSetTagAssignmentResult resultAssignment = result;
|
||||
@@ -348,6 +349,9 @@ public class DistributionSetManagement {
|
||||
public List<DistributionSet> createDistributionSets(@NotNull final Iterable<DistributionSet> distributionSets) {
|
||||
for (final DistributionSet ds : distributionSets) {
|
||||
prepareDsSave(ds);
|
||||
if (ds.getType() == null) {
|
||||
ds.setType(systemManagement.getTenantMetadata().getDefaultDsType());
|
||||
}
|
||||
}
|
||||
return distributionSetRepository.save(distributionSets);
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ public class TenantConfigurationManagement implements EnvironmentAware {
|
||||
* @param configurationKey
|
||||
* the key of the configuration
|
||||
* @return the converted configuration value either from the tenant specific
|
||||
* configuration stored or from the fallback default values or
|
||||
* configuration stored or from the fall back default values or
|
||||
* {@code null} in case key has not been configured and not default
|
||||
* value exists
|
||||
* @throws TenantConfigurationValidatorException
|
||||
|
||||
@@ -67,14 +67,14 @@ public class DistributionSet extends NamedVersionedEntity {
|
||||
|
||||
@ManyToMany(targetEntity = SoftwareModule.class, fetch = FetchType.LAZY)
|
||||
@JoinTable(name = "sp_ds_module", joinColumns = {
|
||||
@JoinColumn(name = "ds_id", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_module_ds") ) }, inverseJoinColumns = {
|
||||
@JoinColumn(name = "module_id", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_module_module") ) })
|
||||
@JoinColumn(name = "ds_id", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_module_ds")) }, inverseJoinColumns = {
|
||||
@JoinColumn(name = "module_id", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_module_module")) })
|
||||
private final Set<SoftwareModule> modules = new HashSet<>();
|
||||
|
||||
@ManyToMany(targetEntity = DistributionSetTag.class)
|
||||
@JoinTable(name = "sp_ds_dstag", joinColumns = {
|
||||
@JoinColumn(name = "ds", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_dstag_ds") ) }, inverseJoinColumns = {
|
||||
@JoinColumn(name = "TAG", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_dstag_tag") ) })
|
||||
@JoinColumn(name = "ds", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_dstag_ds")) }, inverseJoinColumns = {
|
||||
@JoinColumn(name = "TAG", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_dstag_tag")) })
|
||||
private Set<DistributionSetTag> tags = new HashSet<>();
|
||||
|
||||
@Column(name = "deleted")
|
||||
@@ -95,7 +95,7 @@ public class DistributionSet extends NamedVersionedEntity {
|
||||
private final List<DistributionSetMetadata> metadata = new ArrayList<>();
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "ds_id", nullable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_dstype_ds") )
|
||||
@JoinColumn(name = "ds_id", nullable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_dstype_ds"))
|
||||
private DistributionSetType type;
|
||||
|
||||
@Column(name = "complete")
|
||||
@@ -130,7 +130,9 @@ public class DistributionSet extends NamedVersionedEntity {
|
||||
if (moduleList != null) {
|
||||
moduleList.forEach(this::addModule);
|
||||
}
|
||||
complete = type.checkComplete(this);
|
||||
if (this.type != null) {
|
||||
complete = this.type.checkComplete(this);
|
||||
}
|
||||
}
|
||||
|
||||
public Set<DistributionSetTag> getTags() {
|
||||
|
||||
@@ -27,9 +27,6 @@ import javax.persistence.UniqueConstraint;
|
||||
* A distribution set type defines which software module types can or have to be
|
||||
* {@link DistributionSet}.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "sp_distribution_set_type", indexes = {
|
||||
@@ -55,7 +52,7 @@ public class DistributionSetType extends NamedEntity {
|
||||
private boolean deleted = false;
|
||||
|
||||
public DistributionSetType() {
|
||||
// default public constructor
|
||||
// default public constructor for JPA
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -307,7 +304,7 @@ public class DistributionSetType extends NamedEntity {
|
||||
if (!super.equals(obj)) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
if (!(obj instanceof DistributionSetType)) {
|
||||
return false;
|
||||
}
|
||||
final DistributionSetType other = (DistributionSetType) obj;
|
||||
@@ -337,4 +334,5 @@ public class DistributionSetType extends NamedEntity {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,17 +25,10 @@ import javax.persistence.Table;
|
||||
* Relation element between a {@link DistributionSetType} and its
|
||||
* {@link SoftwareModuleType} elements.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "sp_ds_type_element")
|
||||
public class DistributionSetTypeElement implements Serializable {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@EmbeddedId
|
||||
@@ -46,18 +39,16 @@ public class DistributionSetTypeElement implements Serializable {
|
||||
|
||||
@MapsId("dsType")
|
||||
@ManyToOne(optional = false, fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "distribution_set_type", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_type_element_dstype") )
|
||||
@JoinColumn(name = "distribution_set_type", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_type_element_dstype"))
|
||||
private DistributionSetType dsType;
|
||||
|
||||
@MapsId("smType")
|
||||
@ManyToOne(optional = false, fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "software_module_type", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_type_element_smtype") )
|
||||
@JoinColumn(name = "software_module_type", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_ds_type_element_smtype"))
|
||||
private SoftwareModuleType smType;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
public DistributionSetTypeElement() {
|
||||
// Default constructor for JPA
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,4 +99,38 @@ public class DistributionSetTypeElement implements Serializable {
|
||||
return key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((key == null) ? 0 : key.hashCode());
|
||||
result = prime * result + (mandatory ? 1231 : 1237);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (!(obj instanceof DistributionSetTypeElement)) {
|
||||
return false;
|
||||
}
|
||||
final DistributionSetTypeElement other = (DistributionSetTypeElement) obj;
|
||||
if (key == null) {
|
||||
if (other.key != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!key.equals(other.key)) {
|
||||
return false;
|
||||
}
|
||||
if (mandatory != other.mandatory) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,17 +15,9 @@ import javax.persistence.Embeddable;
|
||||
|
||||
/**
|
||||
* Composite key for {@link DistributionSetTypeElement}.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
@Embeddable
|
||||
public class DistributionSetTypeElementCompositeKey implements Serializable {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Column(name = "distribution_set_type", nullable = false)
|
||||
@@ -54,34 +46,58 @@ public class DistributionSetTypeElementCompositeKey implements Serializable {
|
||||
this.smType = smType.getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dsType
|
||||
*/
|
||||
public Long getDsType() {
|
||||
return dsType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dsType
|
||||
* the dsType to set
|
||||
*/
|
||||
public void setDsType(final Long dsType) {
|
||||
this.dsType = dsType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the smType
|
||||
*/
|
||||
public Long getSmType() {
|
||||
return smType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param smType
|
||||
* the smType to set
|
||||
*/
|
||||
public void setSmType(final Long smType) {
|
||||
this.smType = smType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((dsType == null) ? 0 : dsType.hashCode());
|
||||
result = prime * result + ((smType == null) ? 0 : smType.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (!(obj instanceof DistributionSetTypeElementCompositeKey)) {
|
||||
return false;
|
||||
}
|
||||
final DistributionSetTypeElementCompositeKey other = (DistributionSetTypeElementCompositeKey) obj;
|
||||
if (dsType == null) {
|
||||
if (other.dsType != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!dsType.equals(other.dsType)) {
|
||||
return false;
|
||||
}
|
||||
if (smType == null) {
|
||||
if (other.smType != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!smType.equals(other.smType)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user