forbid software modules / artifacts modification for locked distribution sets / software modules respectively Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -44,6 +44,7 @@ import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetCreated
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetUpdatedEvent;
|
||||
import org.eclipse.hawkbit.repository.exception.DistributionSetTypeUndefinedException;
|
||||
import org.eclipse.hawkbit.repository.exception.IncompleteDistributionSetException;
|
||||
import org.eclipse.hawkbit.repository.exception.LockedException;
|
||||
import org.eclipse.hawkbit.repository.exception.UnsupportedSoftwareModuleForThisDistributionSetException;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
@@ -185,6 +186,10 @@ public class JpaDistributionSet extends AbstractJpaNamedVersionedEntity implemen
|
||||
}
|
||||
|
||||
public boolean addModule(final SoftwareModule softwareModule) {
|
||||
if (isLocked()) {
|
||||
throw new LockedException(JpaDistributionSet.class, getId(), "ADD_SOFTWARE_MODULE");
|
||||
}
|
||||
|
||||
if (modules == null) {
|
||||
modules = new HashSet<>();
|
||||
}
|
||||
@@ -215,6 +220,10 @@ public class JpaDistributionSet extends AbstractJpaNamedVersionedEntity implemen
|
||||
}
|
||||
|
||||
public void removeModule(final SoftwareModule softwareModule) {
|
||||
if (isLocked()) {
|
||||
throw new LockedException(JpaDistributionSet.class, getId(), "REMOVE_SOFTWARE_MODULE");
|
||||
}
|
||||
|
||||
if (modules != null && modules.removeIf(m -> m.getId().equals(softwareModule.getId()))) {
|
||||
complete = type.checkComplete(this);
|
||||
}
|
||||
@@ -253,7 +262,7 @@ public class JpaDistributionSet extends AbstractJpaNamedVersionedEntity implemen
|
||||
}
|
||||
|
||||
public void lock() {
|
||||
if (!complete) {
|
||||
if (!isComplete()) {
|
||||
throw new IncompleteDistributionSetException("Could not be locked while incomplete!");
|
||||
}
|
||||
locked = true;
|
||||
|
||||
@@ -39,6 +39,7 @@ import lombok.ToString;
|
||||
import org.eclipse.hawkbit.repository.event.remote.SoftwareModuleDeletedEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.SoftwareModuleCreatedEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.SoftwareModuleUpdatedEvent;
|
||||
import org.eclipse.hawkbit.repository.exception.LockedException;
|
||||
import org.eclipse.hawkbit.repository.model.Artifact;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
@@ -140,6 +141,10 @@ public class JpaSoftwareModule extends AbstractJpaNamedVersionedEntity implement
|
||||
}
|
||||
|
||||
public void addArtifact(final Artifact artifact) {
|
||||
if (isLocked()) {
|
||||
throw new LockedException(JpaSoftwareModule.class, getId(), "ADD_ARTIFACT");
|
||||
}
|
||||
|
||||
if (artifacts == null) {
|
||||
artifacts = new ArrayList<>(4);
|
||||
artifacts.add((JpaArtifact) artifact);
|
||||
@@ -155,6 +160,10 @@ public class JpaSoftwareModule extends AbstractJpaNamedVersionedEntity implement
|
||||
* @param artifact is removed from the assigned {@link Artifact}s.
|
||||
*/
|
||||
public void removeArtifact(final Artifact artifact) {
|
||||
if (isLocked()) {
|
||||
throw new LockedException(JpaSoftwareModule.class, getId(), "REMOVE_ARTIFACT");
|
||||
}
|
||||
|
||||
if (artifacts != null) {
|
||||
artifacts.remove(artifact);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user