Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -10,12 +10,15 @@
|
||||
package org.eclipse.hawkbit.repository.builder;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Null;
|
||||
import jakarta.validation.constraints.Size;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.NamedEntity;
|
||||
import org.eclipse.hawkbit.repository.model.NamedVersionedEntity;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Builder to update an existing {@link DistributionSet} entry. Defines all
|
||||
* fields that can be updated.
|
||||
@@ -23,30 +26,32 @@ import org.eclipse.hawkbit.repository.model.NamedVersionedEntity;
|
||||
*/
|
||||
public interface DistributionSetUpdate {
|
||||
/**
|
||||
* @param name
|
||||
* for {@link DistributionSet#getName()}
|
||||
* @param name for {@link DistributionSet#getName()}
|
||||
* @return updated builder instance
|
||||
*/
|
||||
DistributionSetUpdate name(@Size(min = 1, max = NamedEntity.NAME_MAX_SIZE) @NotNull String name);
|
||||
|
||||
/**
|
||||
* @param version
|
||||
* for {@link DistributionSet#getVersion()}
|
||||
* @param version for {@link DistributionSet#getVersion()}
|
||||
* @return updated builder instance
|
||||
*/
|
||||
DistributionSetUpdate version(@Size(min = 1, max = NamedVersionedEntity.VERSION_MAX_SIZE) @NotNull String version);
|
||||
|
||||
/**
|
||||
* @param description
|
||||
* for {@link DistributionSet#getDescription()}
|
||||
* @param description for {@link DistributionSet#getDescription()}
|
||||
* @return updated builder instance
|
||||
*/
|
||||
DistributionSetUpdate description(@Size(max = NamedEntity.DESCRIPTION_MAX_SIZE) String description);
|
||||
|
||||
/**
|
||||
* @param requiredMigrationStep
|
||||
* for {@link DistributionSet#isRequiredMigrationStep()}
|
||||
* @param locked update request if any. If not empty shall be <code>true</code>
|
||||
* @return updated builder instance
|
||||
*/
|
||||
DistributionSetUpdate locked(@Null Boolean locked);
|
||||
|
||||
/**
|
||||
* @param requiredMigrationStep for {@link DistributionSet#isRequiredMigrationStep()}
|
||||
* @return updated builder instance
|
||||
*/
|
||||
DistributionSetUpdate requiredMigrationStep(Boolean requiredMigrationStep);
|
||||
}
|
||||
}
|
||||
@@ -28,4 +28,4 @@ public interface SoftwareModuleBuilder {
|
||||
* @return builder instance
|
||||
*/
|
||||
SoftwareModuleCreate create();
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,8 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.builder;
|
||||
|
||||
import jakarta.annotation.Nullable;
|
||||
import jakarta.validation.constraints.Null;
|
||||
import jakarta.validation.constraints.Size;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.NamedEntity;
|
||||
@@ -34,4 +36,10 @@ public interface SoftwareModuleUpdate {
|
||||
* @return updated builder instance
|
||||
*/
|
||||
SoftwareModuleUpdate vendor(@Size(max = SoftwareModule.VENDOR_MAX_SIZE) String vendor);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param locked update request if any. If not empty shall be <code>true</code>
|
||||
* @return updated builder instance
|
||||
*/
|
||||
SoftwareModuleUpdate locked(@Null Boolean locked);
|
||||
}
|
||||
@@ -18,15 +18,13 @@ import org.springframework.util.StringUtils;
|
||||
/**
|
||||
* Create and update builder DTO.
|
||||
*
|
||||
* @param <T>
|
||||
* update or create builder interface
|
||||
* @param <T> update or create builder interface
|
||||
*/
|
||||
public abstract class AbstractDistributionSetUpdateCreate<T> extends AbstractNamedEntityBuilder<T> {
|
||||
|
||||
@ValidString
|
||||
protected String version;
|
||||
protected Boolean requiredMigrationStep;
|
||||
|
||||
|
||||
protected Collection<Long> modules;
|
||||
|
||||
public T modules(final Collection<Long> modules) {
|
||||
@@ -55,5 +53,4 @@ public abstract class AbstractDistributionSetUpdateCreate<T> extends AbstractNam
|
||||
public Optional<String> getVersion() {
|
||||
return Optional.ofNullable(version);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,8 @@ package org.eclipse.hawkbit.repository.builder;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import jakarta.annotation.Nullable;
|
||||
import jakarta.validation.constraints.Null;
|
||||
import org.eclipse.hawkbit.repository.ValidString;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -39,5 +41,4 @@ public abstract class AbstractNamedEntityBuilder<T> extends AbstractBaseEntityBu
|
||||
public Optional<String> getDescription() {
|
||||
return Optional.ofNullable(description);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -9,14 +9,33 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.builder;
|
||||
|
||||
import jakarta.annotation.Nullable;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Update implementation.
|
||||
*/
|
||||
public class GenericDistributionSetUpdate extends AbstractDistributionSetUpdateCreate<DistributionSetUpdate>
|
||||
implements DistributionSetUpdate {
|
||||
|
||||
@Nullable
|
||||
protected Boolean locked;
|
||||
|
||||
public GenericDistributionSetUpdate(final Long id) {
|
||||
super.id = id;
|
||||
}
|
||||
|
||||
}
|
||||
public DistributionSetUpdate locked(@Nullable final Boolean locked) {
|
||||
if (Boolean.FALSE.equals(locked)) {
|
||||
this.locked = null;
|
||||
} else {
|
||||
this.locked = locked;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public Boolean getLocked() {
|
||||
return locked;
|
||||
}
|
||||
}
|
||||
@@ -9,14 +9,33 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.builder;
|
||||
|
||||
import jakarta.annotation.Nullable;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Update implementation.
|
||||
*/
|
||||
public class GenericSoftwareModuleUpdate extends AbstractSoftwareModuleUpdateCreate<SoftwareModuleUpdate>
|
||||
implements SoftwareModuleUpdate {
|
||||
|
||||
@Nullable
|
||||
protected Boolean locked;
|
||||
|
||||
public GenericSoftwareModuleUpdate(final Long id) {
|
||||
super.id = id;
|
||||
}
|
||||
|
||||
}
|
||||
public SoftwareModuleUpdate locked(@Nullable final Boolean locked) {
|
||||
if (Boolean.FALSE.equals(locked)) {
|
||||
this.locked = null;
|
||||
} else {
|
||||
this.locked = locked;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public Boolean getLocked() {
|
||||
return locked;
|
||||
}
|
||||
}
|
||||
@@ -285,6 +285,10 @@ public class JpaDistributionSetManagement implements DistributionSetManagement {
|
||||
update.getDescription().ifPresent(set::setDescription);
|
||||
update.getVersion().ifPresent(set::setVersion);
|
||||
|
||||
if (Boolean.TRUE.equals(update.getLocked()) && !set.isLocked()) {
|
||||
set.lock();
|
||||
}
|
||||
|
||||
if (update.isRequiredMigrationStep() != null
|
||||
&& !update.isRequiredMigrationStep().equals(set.isRequiredMigrationStep())) {
|
||||
assertDistributionSetIsNotAssignedToTargets(update.getId());
|
||||
|
||||
@@ -142,6 +142,9 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
|
||||
|
||||
update.getDescription().ifPresent(module::setDescription);
|
||||
update.getVendor().ifPresent(module::setVendor);
|
||||
if (Boolean.TRUE.equals(update.getLocked()) && !module.isLocked()) {
|
||||
module.lock();
|
||||
}
|
||||
|
||||
return softwareModuleRepository.save(module);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user