diff --git a/hawkbit-artifact/hawkbit-artifact-api/src/main/java/org/eclipse/hawkbit/repository/artifact/AbstractArtifactRepository.java b/hawkbit-artifact/hawkbit-artifact-api/src/main/java/org/eclipse/hawkbit/repository/artifact/AbstractArtifactRepository.java
index 5f4ad8653..966b88df2 100644
--- a/hawkbit-artifact/hawkbit-artifact-api/src/main/java/org/eclipse/hawkbit/repository/artifact/AbstractArtifactRepository.java
+++ b/hawkbit-artifact/hawkbit-artifact-api/src/main/java/org/eclipse/hawkbit/repository/artifact/AbstractArtifactRepository.java
@@ -67,8 +67,9 @@ public abstract class AbstractArtifactRepository implements ArtifactRepository {
checkHashes(providedHashes, sha1Hash16, md5Hash16, sha256Hash16);
// Check if file with same sha1 hash exists and if so return it
- if (existsByTenantAndSha1(tenant, sha1Hash16)) {
- return addMissingHashes(getArtifactBySha1(tenant, sha1Hash16), sha1Hash16, md5Hash16, sha256Hash16);
+ if (existsBySha1(tenant, sha1Hash16)) {
+ // TODO - shall check if the file is really the same as bytes or just sha1 hash is the same
+ return addMissingHashes(getBySha1(tenant, sha1Hash16), sha1Hash16, md5Hash16, sha256Hash16);
}
return store(sanitizeTenant(tenant), new DbArtifactHash(sha1Hash16, md5Hash16, sha256Hash16), contentType, tempFile);
diff --git a/hawkbit-artifact/hawkbit-artifact-api/src/main/java/org/eclipse/hawkbit/repository/artifact/ArtifactRepository.java b/hawkbit-artifact/hawkbit-artifact-api/src/main/java/org/eclipse/hawkbit/repository/artifact/ArtifactRepository.java
index b7d829425..b322cb465 100644
--- a/hawkbit-artifact/hawkbit-artifact-api/src/main/java/org/eclipse/hawkbit/repository/artifact/ArtifactRepository.java
+++ b/hawkbit-artifact/hawkbit-artifact-api/src/main/java/org/eclipse/hawkbit/repository/artifact/ArtifactRepository.java
@@ -41,6 +41,26 @@ public interface ArtifactRepository {
@NotEmpty String tenant, @NotNull InputStream content, @NotEmpty String filename,
String contentType, DbArtifactHash hash);
+ /**
+ * Retrieves a {@link AbstractDbArtifact} from the store by its SHA1 hash. Throws {@link org.eclipse.hawkbit.repository.artifact.exception.ArtifactBinaryNotFoundException} if not found.
+ *
+ * @param tenant the tenant to store the artifact
+ * @param sha1Hash the sha1-hash of the file to lookup.
+ * @return The artifact file object or {@code null} if no file exists.
+ * @throws UnsupportedOperationException if implementation does not support the operation
+ */
+ AbstractDbArtifact getBySha1(@NotEmpty String tenant, @NotEmpty String sha1Hash);
+
+
+ /**
+ * Checks if an artifact exists for a given tenant by its sha1 hash
+ *
+ * @param tenant the tenant
+ * @param sha1Hash the sha1-hash of the file to lookup.
+ * @return the boolean whether the artifact exists or not
+ */
+ boolean existsBySha1(@NotEmpty String tenant, @NotEmpty String sha1Hash);
+
/**
* Deletes an artifact by its SHA1 hash.
*
@@ -50,29 +70,10 @@ public interface ArtifactRepository {
*/
void deleteBySha1(@NotEmpty String tenant, @NotEmpty String sha1Hash);
- /**
- * Retrieves a {@link AbstractDbArtifact} from the store by its SHA1 hash.
- *
- * @param tenant the tenant to store the artifact
- * @param sha1Hash the sha1-hash of the file to lookup.
- * @return The artifact file object or {@code null} if no file exists.
- * @throws UnsupportedOperationException if implementation does not support the operation
- */
- AbstractDbArtifact getArtifactBySha1(@NotEmpty String tenant, @NotEmpty String sha1Hash);
-
/**
* Deletes all artifacts of given tenant.
*
* @param tenant to erase
*/
void deleteByTenant(@NotEmpty String tenant);
-
- /**
- * Checks if an artifact exists for a given tenant by its sha1 hash
- *
- * @param tenant the tenant
- * @param sha1Hash the sha1-hash of the file to lookup.
- * @return the boolean whether the artifact exists or not
- */
- boolean existsByTenantAndSha1(@NotEmpty String tenant, @NotEmpty String sha1Hash);
}
\ No newline at end of file
diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/ArtifactBinaryNoLongerExistsException.java b/hawkbit-artifact/hawkbit-artifact-api/src/main/java/org/eclipse/hawkbit/repository/artifact/exception/ArtifactBinaryNoLongerExistsException.java
similarity index 88%
rename from hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/ArtifactBinaryNoLongerExistsException.java
rename to hawkbit-artifact/hawkbit-artifact-api/src/main/java/org/eclipse/hawkbit/repository/artifact/exception/ArtifactBinaryNoLongerExistsException.java
index 6c88392a7..e85e6f577 100644
--- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/ArtifactBinaryNoLongerExistsException.java
+++ b/hawkbit-artifact/hawkbit-artifact-api/src/main/java/org/eclipse/hawkbit/repository/artifact/exception/ArtifactBinaryNoLongerExistsException.java
@@ -7,7 +7,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
-package org.eclipse.hawkbit.repository.exception;
+package org.eclipse.hawkbit.repository.artifact.exception;
import java.io.Serial;
@@ -15,11 +15,9 @@ import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.eclipse.hawkbit.exception.AbstractServerRtException;
import org.eclipse.hawkbit.exception.SpServerError;
-import org.eclipse.hawkbit.repository.model.SoftwareModule;
/**
- * Exception indicating that an artifact's binary does not exist anymore. This
- * might be caused due to the soft deletion of a {@link SoftwareModule}.
+ * Exception indicating that an artifact's binary does not exist anymore. This might be caused due to the soft deletion of a software module.
*/
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/ArtifactBinaryNotFoundException.java b/hawkbit-artifact/hawkbit-artifact-api/src/main/java/org/eclipse/hawkbit/repository/artifact/exception/ArtifactBinaryNotFoundException.java
similarity index 95%
rename from hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/ArtifactBinaryNotFoundException.java
rename to hawkbit-artifact/hawkbit-artifact-api/src/main/java/org/eclipse/hawkbit/repository/artifact/exception/ArtifactBinaryNotFoundException.java
index 1d267b2df..5179a8e54 100644
--- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/ArtifactBinaryNotFoundException.java
+++ b/hawkbit-artifact/hawkbit-artifact-api/src/main/java/org/eclipse/hawkbit/repository/artifact/exception/ArtifactBinaryNotFoundException.java
@@ -7,7 +7,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
-package org.eclipse.hawkbit.repository.exception;
+package org.eclipse.hawkbit.repository.artifact.exception;
import java.io.Serial;
diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/ArtifactDeleteFailedException.java b/hawkbit-artifact/hawkbit-artifact-api/src/main/java/org/eclipse/hawkbit/repository/artifact/exception/ArtifactDeleteFailedException.java
similarity index 95%
rename from hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/ArtifactDeleteFailedException.java
rename to hawkbit-artifact/hawkbit-artifact-api/src/main/java/org/eclipse/hawkbit/repository/artifact/exception/ArtifactDeleteFailedException.java
index cc151d477..0f7e05418 100644
--- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/ArtifactDeleteFailedException.java
+++ b/hawkbit-artifact/hawkbit-artifact-api/src/main/java/org/eclipse/hawkbit/repository/artifact/exception/ArtifactDeleteFailedException.java
@@ -7,7 +7,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
-package org.eclipse.hawkbit.repository.exception;
+package org.eclipse.hawkbit.repository.artifact.exception;
import java.io.Serial;
diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/ArtifactUploadFailedException.java b/hawkbit-artifact/hawkbit-artifact-api/src/main/java/org/eclipse/hawkbit/repository/artifact/exception/ArtifactUploadFailedException.java
similarity index 96%
rename from hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/ArtifactUploadFailedException.java
rename to hawkbit-artifact/hawkbit-artifact-api/src/main/java/org/eclipse/hawkbit/repository/artifact/exception/ArtifactUploadFailedException.java
index f9e310f7e..4647b210f 100644
--- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/exception/ArtifactUploadFailedException.java
+++ b/hawkbit-artifact/hawkbit-artifact-api/src/main/java/org/eclipse/hawkbit/repository/artifact/exception/ArtifactUploadFailedException.java
@@ -7,7 +7,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
-package org.eclipse.hawkbit.repository.exception;
+package org.eclipse.hawkbit.repository.artifact.exception;
import java.io.Serial;
diff --git a/hawkbit-artifact/hawkbit-artifact-repository-filesystem/src/main/java/org/eclipse/hawkbit/repository/artifact/ArtifactFilesystemRepository.java b/hawkbit-artifact/hawkbit-artifact-repository-filesystem/src/main/java/org/eclipse/hawkbit/repository/artifact/ArtifactFilesystemRepository.java
index db015d004..175817791 100644
--- a/hawkbit-artifact/hawkbit-artifact-repository-filesystem/src/main/java/org/eclipse/hawkbit/repository/artifact/ArtifactFilesystemRepository.java
+++ b/hawkbit-artifact/hawkbit-artifact-repository-filesystem/src/main/java/org/eclipse/hawkbit/repository/artifact/ArtifactFilesystemRepository.java
@@ -14,8 +14,10 @@ import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
+import java.util.Optional;
import org.apache.commons.io.FileUtils;
+import org.eclipse.hawkbit.repository.artifact.exception.ArtifactBinaryNotFoundException;
import org.eclipse.hawkbit.repository.artifact.model.AbstractDbArtifact;
import org.eclipse.hawkbit.repository.artifact.model.DbArtifactHash;
import org.springframework.validation.annotation.Validated;
@@ -52,10 +54,10 @@ public class ArtifactFilesystemRepository extends AbstractArtifactRepository {
}
@Override
- public ArtifactFilesystem getArtifactBySha1(final String tenant, final String sha1) {
+ public AbstractDbArtifact getBySha1(final String tenant, final String sha1) {
final File file = getFile(tenant, sha1);
if (!file.exists()) {
- return null;
+ throw new ArtifactBinaryNotFoundException(sha1);
}
return new ArtifactFilesystem(file, sha1, new DbArtifactHash(sha1, null, null), file.length(), null);
@@ -67,7 +69,7 @@ public class ArtifactFilesystemRepository extends AbstractArtifactRepository {
}
@Override
- public boolean existsByTenantAndSha1(final String tenant, final String sha1) {
+ public boolean existsBySha1(final String tenant, final String sha1) {
return getFile(tenant, sha1).exists();
}
diff --git a/hawkbit-artifact/hawkbit-artifact-repository-filesystem/src/test/java/org/eclipse/hawkbit/repository/artifact/ArtifactFilesystemRepositoryTest.java b/hawkbit-artifact/hawkbit-artifact-repository-filesystem/src/test/java/org/eclipse/hawkbit/repository/artifact/ArtifactFilesystemRepositoryTest.java
index a23894020..282d4cc79 100644
--- a/hawkbit-artifact/hawkbit-artifact-repository-filesystem/src/test/java/org/eclipse/hawkbit/repository/artifact/ArtifactFilesystemRepositoryTest.java
+++ b/hawkbit-artifact/hawkbit-artifact-repository-filesystem/src/test/java/org/eclipse/hawkbit/repository/artifact/ArtifactFilesystemRepositoryTest.java
@@ -10,6 +10,7 @@
package org.eclipse.hawkbit.repository.artifact;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import java.io.ByteArrayInputStream;
import java.io.File;
@@ -20,16 +21,17 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.assertj.core.api.Assertions;
+import org.eclipse.hawkbit.repository.artifact.exception.ArtifactBinaryNotFoundException;
import org.eclipse.hawkbit.repository.artifact.model.AbstractDbArtifact;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
-@Slf4j
/**
* Feature: Unit Tests - Artifact File System Repository
* Story: Test storing artifact binaries in the file-system
*/
+@Slf4j
class ArtifactFilesystemRepositoryTest {
private static final String TENANT = "test_tenant";
@@ -77,7 +79,7 @@ class ArtifactFilesystemRepositoryTest {
final byte[] fileContent = randomBytes();
final AbstractDbArtifact artifact = storeRandomArtifact(fileContent);
- assertThat(artifactFilesystemRepository.getArtifactBySha1(TENANT, artifact.getHashes().getSha1())).isNotNull();
+ assertThat(artifactFilesystemRepository.getBySha1(TENANT, artifact.getHashes().getSha1())).isNotNull();
}
/**
@@ -88,7 +90,9 @@ class ArtifactFilesystemRepositoryTest {
final AbstractDbArtifact artifact = storeRandomArtifact(randomBytes());
artifactFilesystemRepository.deleteBySha1(TENANT, artifact.getHashes().getSha1());
- assertThat(artifactFilesystemRepository.getArtifactBySha1(TENANT, artifact.getHashes().getSha1())).isNull();
+ final String sha1Hash = artifact.getHashes().getSha1();
+ assertThatExceptionOfType(ArtifactBinaryNotFoundException.class)
+ .isThrownBy(() -> artifactFilesystemRepository.getBySha1(TENANT, sha1Hash));
}
/**
@@ -99,7 +103,9 @@ class ArtifactFilesystemRepositoryTest {
final AbstractDbArtifact artifact = storeRandomArtifact(randomBytes());
artifactFilesystemRepository.deleteByTenant(TENANT);
- assertThat(artifactFilesystemRepository.getArtifactBySha1(TENANT, artifact.getHashes().getSha1())).isNull();
+ final String sha1Hash = artifact.getHashes().getSha1();
+ assertThatExceptionOfType(ArtifactBinaryNotFoundException.class)
+ .isThrownBy(() -> artifactFilesystemRepository.getBySha1(TENANT, sha1Hash));
}
/**
diff --git a/hawkbit-ddi/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java b/hawkbit-ddi/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java
index f1af927e7..45690f43d 100644
--- a/hawkbit-ddi/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java
+++ b/hawkbit-ddi/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java
@@ -53,7 +53,6 @@ import org.eclipse.hawkbit.repository.UpdateMode;
import org.eclipse.hawkbit.repository.artifact.model.DbArtifact;
import org.eclipse.hawkbit.repository.artifact.urlhandler.ArtifactUrlHandler;
import org.eclipse.hawkbit.repository.event.remote.DownloadProgressEvent;
-import org.eclipse.hawkbit.repository.exception.ArtifactBinaryNotFoundException;
import org.eclipse.hawkbit.repository.exception.CancelActionNotAllowedException;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.exception.InvalidConfirmationFeedbackException;
@@ -180,9 +179,7 @@ public class DdiRootController implements DdiRootControllerRestApi {
} else {
// Artifact presence is ensured in 'checkModule'
final Artifact artifact = module.getArtifactByFilename(fileName).orElseThrow(NoSuchElementException::new);
- final DbArtifact file = artifactManagement
- .loadArtifactBinary(artifact.getSha1Hash(), module.getId(), module.isEncrypted())
- .orElseThrow(() -> new ArtifactBinaryNotFoundException(artifact.getSha1Hash()));
+ final DbArtifact file = artifactManagement.loadArtifactBinary(artifact.getSha1Hash(), module.getId(), module.isEncrypted());
final String ifMatch = RequestResponseContextHolder.getHttpServletRequest().getHeader(HttpHeaders.IF_MATCH);
if (ifMatch != null && !HttpUtil.matchesHttpHeader(ifMatch, artifact.getSha1Hash())) {
@@ -694,7 +691,7 @@ public class DdiRootController implements DdiRootControllerRestApi {
}
private Target findTarget(final String controllerId) {
- return controllerManagement.getByControllerId(controllerId)
+ return controllerManagement.findByControllerId(controllerId)
.orElseThrow(() -> new EntityNotFoundException(Target.class, controllerId));
}
diff --git a/hawkbit-ddi/hawkbit-ddi-security/src/main/java/org/eclipse/hawkbit/security/controller/SecurityTokenAuthenticator.java b/hawkbit-ddi/hawkbit-ddi-security/src/main/java/org/eclipse/hawkbit/security/controller/SecurityTokenAuthenticator.java
index 4791ffd0d..d4162f3d6 100644
--- a/hawkbit-ddi/hawkbit-ddi-security/src/main/java/org/eclipse/hawkbit/security/controller/SecurityTokenAuthenticator.java
+++ b/hawkbit-ddi/hawkbit-ddi-security/src/main/java/org/eclipse/hawkbit/security/controller/SecurityTokenAuthenticator.java
@@ -60,8 +60,8 @@ public class SecurityTokenAuthenticator extends Authenticator.AbstractAuthentica
final String presentedToken = authHeader.substring(OFFSET_TARGET_TOKEN);
return systemSecurityContext.runAsSystemAsTenant(() -> controllerSecurityToken.getTargetId() != null
- ? controllerManagement.get(controllerSecurityToken.getTargetId())
- : controllerManagement.getByControllerId(controllerSecurityToken.getControllerId()),
+ ? controllerManagement.find(controllerSecurityToken.getTargetId())
+ : controllerManagement.findByControllerId(controllerSecurityToken.getControllerId()),
controllerSecurityToken.getTenant())
// validate if the presented token is the same as the one set for the target
.filter(target -> presentedToken.equals(
diff --git a/hawkbit-ddi/hawkbit-ddi-security/src/test/java/org/eclipse/hawkbit/security/controller/SecurityTokenAuthenticatorTest.java b/hawkbit-ddi/hawkbit-ddi-security/src/test/java/org/eclipse/hawkbit/security/controller/SecurityTokenAuthenticatorTest.java
index f782f5963..008438c0d 100644
--- a/hawkbit-ddi/hawkbit-ddi-security/src/test/java/org/eclipse/hawkbit/security/controller/SecurityTokenAuthenticatorTest.java
+++ b/hawkbit-ddi/hawkbit-ddi-security/src/test/java/org/eclipse/hawkbit/security/controller/SecurityTokenAuthenticatorTest.java
@@ -78,7 +78,7 @@ class SecurityTokenAuthenticatorTest {
final Target target = Mockito.mock(Target.class);
when(target.getControllerId()).thenReturn(CONTROLLER_ID);
when(target.getSecurityToken()).thenReturn(SECURITY_TOKEN);
- when(controllerManagementMock.getByControllerId(CONTROLLER_ID)).thenReturn(Optional.of(target));
+ when(controllerManagementMock.findByControllerId(CONTROLLER_ID)).thenReturn(Optional.of(target));
assertThat(authenticator.authenticate(securityToken))
.isNotNull()
diff --git a/hawkbit-dmf/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java b/hawkbit-dmf/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java
index 193bbff16..fd8657ee7 100644
--- a/hawkbit-dmf/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java
+++ b/hawkbit-dmf/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java
@@ -413,7 +413,7 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
private void sendUpdateMessageToTargets(
final Long dsId, final Map actionsPropsByTargetId, final List targets) {
- distributionSetManagement.get(dsId).ifPresent(ds -> {
+ distributionSetManagement.find(dsId).ifPresent(ds -> {
final Map> softwareModules = getSoftwareModulesWithMetadata(ds);
sendUpdateMessageToTargets(actionsPropsByTargetId, targets, softwareModules);
});
diff --git a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java
index e7bd50957..b4e0fe306 100644
--- a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java
+++ b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java
@@ -24,7 +24,6 @@ import java.util.Optional;
import java.util.UUID;
import org.eclipse.hawkbit.repository.RepositoryProperties;
-import org.eclipse.hawkbit.repository.TargetManagement;
import org.eclipse.hawkbit.repository.TargetManagement.Create;
import org.eclipse.hawkbit.repository.artifact.ArtifactFilesystem;
import org.eclipse.hawkbit.repository.artifact.model.AbstractDbArtifact;
@@ -184,8 +183,8 @@ class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTest {
receivedList.add(new ArtifactFilesystem(new File("./test"), artifact.getSha1Hash(),
new DbArtifactHash(artifact.getSha1Hash(), null, null), artifact.getSize(), null));
}
- module = softwareModuleManagement.get(module.getId()).get();
- dsA = distributionSetManagement.get(dsA.getId()).get();
+ module = softwareModuleManagement.find(module.getId()).get();
+ dsA = distributionSetManagement.find(dsA.getId()).get();
final Action action = createAction(dsA);
diff --git a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AbstractAmqpServiceIntegrationTest.java b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AbstractAmqpServiceIntegrationTest.java
index 0832b5dff..10f06a1e7 100644
--- a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AbstractAmqpServiceIntegrationTest.java
+++ b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AbstractAmqpServiceIntegrationTest.java
@@ -279,7 +279,7 @@ abstract class AbstractAmqpServiceIntegrationTest extends AbstractAmqpIntegratio
protected void registerSameTargetAndAssertBasedOnVersion(final String controllerId, final String name,
final int existingTargetsAfterCreation, final TargetUpdateStatus expectedTargetStatus,
final Map attributes) {
- final int version = controllerManagement.getByControllerId(controllerId).get().getOptLockRevision();
+ final int version = controllerManagement.findByControllerId(controllerId).get().getOptLockRevision();
registerAndAssertTargetWithExistingTenant(controllerId, name, existingTargetsAfterCreation,
expectedTargetStatus, CREATED_BY, attributes, () -> findTargetBasedOnNewVersion(controllerId, version));
}
@@ -364,7 +364,7 @@ abstract class AbstractAmqpServiceIntegrationTest extends AbstractAmqpIntegratio
}
protected void assertUpdateAttributes(final String controllerId, final Map attributes) {
- waitUntilIsPresent(() -> controllerManagement.getByControllerId(controllerId));
+ waitUntilIsPresent(() -> controllerManagement.findByControllerId(controllerId));
await().untilAsserted(() -> {
try {
final Map controllerAttributes = SecurityContextSwitch.callAsPrivileged(
@@ -443,7 +443,7 @@ abstract class AbstractAmqpServiceIntegrationTest extends AbstractAmqpIntegratio
}
private Optional findTargetBasedOnNewVersion(final String controllerId, final int version) {
- final Optional target2 = controllerManagement.getByControllerId(controllerId);
+ final Optional target2 = controllerManagement.findByControllerId(controllerId);
if (version < target2.get().getOptLockRevision()) {
return target2;
}
diff --git a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpMessageDispatcherServiceIntegrationTest.java b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpMessageDispatcherServiceIntegrationTest.java
index e3f25990b..af7873206 100644
--- a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpMessageDispatcherServiceIntegrationTest.java
+++ b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpMessageDispatcherServiceIntegrationTest.java
@@ -601,7 +601,7 @@ class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpServiceInt
.containsEntry("type", EVENT.toString())
.containsEntry("topic", DOWNLOAD.toString());
- final Optional target = controllerManagement.getByControllerId(controllerId);
+ final Optional target = controllerManagement.findByControllerId(controllerId);
assertThat(target).isPresent();
// verify the DS was assigned to the Target
@@ -631,7 +631,7 @@ class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpServiceInt
assertSoftwareModules(softwareModules, request.getSoftwareModules());
final List tokens = controllerIds.stream().map(controllerId -> {
- final Optional target = controllerManagement.getByControllerId(controllerId);
+ final Optional target = controllerManagement.findByControllerId(controllerId);
assertThat(target).isPresent();
return target.get().getSecurityToken();
}).toList();
diff --git a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpMessageHandlerServiceIntegrationTest.java b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpMessageHandlerServiceIntegrationTest.java
index c2dc83c5e..2a727f2ec 100644
--- a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpMessageHandlerServiceIntegrationTest.java
+++ b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AmqpMessageHandlerServiceIntegrationTest.java
@@ -1192,7 +1192,7 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
}
private void verifyAssignedDsAndInstalledDs(final Long assignedDsId, final Long installedDsId) {
- final Optional target = controllerManagement.getByControllerId(DMF_REGISTER_TEST_CONTROLLER_ID);
+ final Optional target = controllerManagement.findByControllerId(DMF_REGISTER_TEST_CONTROLLER_ID);
assertThat(target).isPresent();
// verify the DS was assigned to the Target
diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java b/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java
index 79c364c51..40fefefbf 100644
--- a/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java
+++ b/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java
@@ -132,7 +132,7 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
@Override
public ResponseEntity getDistributionSet(final Long distributionSetId) {
- final DistributionSet foundDs = distributionSetManagement.getOrElseThrowException(distributionSetId);
+ final DistributionSet foundDs = distributionSetManagement.get(distributionSetId);
final MgmtDistributionSet response = MgmtDistributionSetMapper.toResponse(foundDs);
MgmtDistributionSetMapper.addLinks(foundDs, response);
@@ -211,7 +211,7 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
final Long distributionSetId, final String rsqlParam,
final int pagingOffsetParam, final int pagingLimitParam, final String sortParam) {
// check if distribution set exists otherwise throw exception immediately
- distributionSetManagement.getOrElseThrowException(distributionSetId);
+ distributionSetManagement.get(distributionSetId);
final Pageable pageable = PagingUtility.toPageable(pagingOffsetParam, pagingLimitParam, sanitizeDistributionSetSortParam(sortParam));
final Page targetsInstalledDS;
if (rsqlParam != null) {
diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResource.java b/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResource.java
index 04c800aaf..5bb495b8f 100644
--- a/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResource.java
+++ b/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResource.java
@@ -160,7 +160,7 @@ class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRestApi {
}
private DistributionSetTag findDistributionTagById(final Long distributionsetTagId) {
- return distributionSetTagManagement.get(distributionsetTagId)
+ return distributionSetTagManagement.find(distributionsetTagId)
.orElseThrow(() -> new EntityNotFoundException(DistributionSetTag.class, distributionsetTagId));
}
}
\ No newline at end of file
diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResource.java b/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResource.java
index d263a243e..75922721c 100644
--- a/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResource.java
+++ b/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResource.java
@@ -180,12 +180,12 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
}
private DistributionSetType findDistributionSetTypeWithExceptionIfNotFound(final Long distributionSetTypeId) {
- return distributionSetTypeManagement.get(distributionSetTypeId)
+ return distributionSetTypeManagement.find(distributionSetTypeId)
.orElseThrow(() -> new EntityNotFoundException(DistributionSetType.class, distributionSetTypeId));
}
private SoftwareModuleType findSoftwareModuleTypeWithExceptionIfNotFound(final Long softwareModuleTypeId) {
- return softwareModuleTypeManagement.get(softwareModuleTypeId)
+ return softwareModuleTypeManagement.find(softwareModuleTypeId)
.orElseThrow(() -> new EntityNotFoundException(SoftwareModuleType.class, softwareModuleTypeId));
}
}
\ No newline at end of file
diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDownloadArtifactResource.java b/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDownloadArtifactResource.java
index f89573f7e..177d76699 100644
--- a/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDownloadArtifactResource.java
+++ b/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDownloadArtifactResource.java
@@ -13,12 +13,11 @@ import java.io.InputStream;
import jakarta.servlet.http.HttpServletRequest;
+import org.eclipse.hawkbit.repository.artifact.exception.ArtifactBinaryNoLongerExistsException;
import org.eclipse.hawkbit.repository.artifact.model.DbArtifact;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtDownloadArtifactRestApi;
import org.eclipse.hawkbit.repository.ArtifactManagement;
import org.eclipse.hawkbit.repository.SoftwareModuleManagement;
-import org.eclipse.hawkbit.repository.exception.ArtifactBinaryNoLongerExistsException;
-import org.eclipse.hawkbit.repository.exception.ArtifactBinaryNotFoundException;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.model.Artifact;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
@@ -53,7 +52,7 @@ public class MgmtDownloadArtifactResource implements MgmtDownloadArtifactRestApi
*/
@Override
public ResponseEntity downloadArtifact(final Long softwareModuleId, final Long artifactId) {
- final SoftwareModule module = softwareModuleManagement.get(softwareModuleId)
+ final SoftwareModule module = softwareModuleManagement.find(softwareModuleId)
.orElseThrow(() -> new EntityNotFoundException(SoftwareModule.class, softwareModuleId));
if (module.isDeleted()) {
throw new ArtifactBinaryNoLongerExistsException();
@@ -61,9 +60,7 @@ public class MgmtDownloadArtifactResource implements MgmtDownloadArtifactRestApi
final Artifact artifact = module.getArtifact(artifactId)
.orElseThrow(() -> new EntityNotFoundException(Artifact.class, artifactId));
- final DbArtifact file = artifactManagement
- .loadArtifactBinary(artifact.getSha1Hash(), module.getId(), module.isEncrypted())
- .orElseThrow(() -> new ArtifactBinaryNotFoundException(artifact.getSha1Hash()));
+ final DbArtifact file = artifactManagement.loadArtifactBinary(artifact.getSha1Hash(), module.getId(), module.isEncrypted());
final HttpServletRequest request = RequestResponseContextHolder.getHttpServletRequest();
final String ifMatch = request.getHeader(HttpHeaders.IF_MATCH);
if (ifMatch != null && !HttpUtil.matchesHttpHeader(ifMatch, artifact.getSha1Hash())) {
diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResource.java b/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResource.java
index fe7329efe..073edd3f9 100644
--- a/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResource.java
+++ b/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResource.java
@@ -273,7 +273,7 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi {
@Override
public ResponseEntity retryRollout(final Long rolloutId) {
- final Rollout rolloutForRetry = rolloutManagement.get(rolloutId)
+ final Rollout rolloutForRetry = rolloutManagement.find(rolloutId)
.orElseThrow(() -> new EntityNotFoundException(Rollout.class, rolloutId));
if (rolloutForRetry.isDeleted()) {
throw new EntityNotFoundException(Rollout.class, rolloutId);
diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java b/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java
index 340b0ffa1..14446f206 100644
--- a/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java
+++ b/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java
@@ -278,7 +278,7 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
}
private SoftwareModule findSoftwareModuleWithExceptionIfNotFound(final Long softwareModuleId, final Long artifactId) {
- final SoftwareModule module = softwareModuleManagement.get(softwareModuleId)
+ final SoftwareModule module = softwareModuleManagement.find(softwareModuleId)
.orElseThrow(() -> new EntityNotFoundException(SoftwareModule.class, softwareModuleId));
if (artifactId != null && module.getArtifact(artifactId).isEmpty()) {
diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResource.java b/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResource.java
index dc4f28a94..7f2d953a4 100644
--- a/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResource.java
+++ b/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResource.java
@@ -96,7 +96,7 @@ public class MgmtSoftwareModuleTypeResource implements MgmtSoftwareModuleTypeRes
}
private SoftwareModuleType findSoftwareModuleTypeWithExceptionIfNotFound(final Long softwareModuleTypeId) {
- return softwareModuleTypeManagement.get(softwareModuleTypeId)
+ return softwareModuleTypeManagement.find(softwareModuleTypeId)
.orElseThrow(() -> new EntityNotFoundException(SoftwareModuleType.class, softwareModuleTypeId));
}
}
\ No newline at end of file
diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetFilterQueryResource.java b/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetFilterQueryResource.java
index ccca241cf..209b06ca9 100644
--- a/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetFilterQueryResource.java
+++ b/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetFilterQueryResource.java
@@ -172,7 +172,7 @@ public class MgmtTargetFilterQueryResource implements MgmtTargetFilterQueryRestA
}
private TargetFilterQuery findFilterWithExceptionIfNotFound(final Long filterId) {
- return filterManagement.get(filterId)
+ return filterManagement.find(filterId)
.orElseThrow(() -> new EntityNotFoundException(TargetFilterQuery.class, filterId));
}
}
\ No newline at end of file
diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResource.java b/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResource.java
index 09d061103..198e2e91a 100644
--- a/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResource.java
+++ b/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResource.java
@@ -154,7 +154,7 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
targetManagement.unassignType(targetId);
return null;
} else {
- return targetTypeManagement.get(targetRest.getTargetType())
+ return targetTypeManagement.find(targetRest.getTargetType())
.orElseThrow(() -> new EntityNotFoundException(TargetType.class, targetRest.getTargetType()));
}
})
diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResource.java b/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResource.java
index 985e2783a..7c54f3cd6 100644
--- a/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResource.java
+++ b/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResource.java
@@ -193,6 +193,6 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi {
}
private TargetTag findTargetTagById(final Long targetTagId) {
- return tagManagement.get(targetTagId).orElseThrow(() -> new EntityNotFoundException(TargetTag.class, targetTagId));
+ return tagManagement.find(targetTagId).orElseThrow(() -> new EntityNotFoundException(TargetTag.class, targetTagId));
}
}
\ No newline at end of file
diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTypeResource.java b/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTypeResource.java
index b1b010834..edb2c70e6 100644
--- a/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTypeResource.java
+++ b/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTypeResource.java
@@ -122,7 +122,7 @@ public class MgmtTargetTypeResource implements MgmtTargetTypeRestApi {
}
private TargetType findTargetTypeWithExceptionIfNotFound(final Long targetTypeId) {
- return targetTypeManagement.get(targetTypeId)
+ return targetTypeManagement.find(targetTypeId)
.orElseThrow(() -> new EntityNotFoundException(TargetType.class, targetTypeId));
}
}
\ No newline at end of file
diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/mapper/MgmtTargetMapper.java b/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/mapper/MgmtTargetMapper.java
index 52abef2aa..889417825 100644
--- a/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/mapper/MgmtTargetMapper.java
+++ b/hawkbit-mgmt/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/mapper/MgmtTargetMapper.java
@@ -345,7 +345,7 @@ public final class MgmtTargetMapper {
.description(targetRest.getDescription()).securityToken(targetRest.getSecurityToken())
.address(targetRest.getAddress())
.targetType(Optional.ofNullable(targetRest.getTargetType())
- .map(targetTypeId -> targetTypeManagement.get(targetTypeId)
+ .map(targetTypeId -> targetTypeManagement.find(targetTypeId)
.orElseThrow(() -> new EntityNotFoundException(TargetType.class, targetTypeId)))
.map(TargetType.class::cast)
.orElse(null))
diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java
index acb90b245..05a3162f3 100644
--- a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java
+++ b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java
@@ -50,7 +50,6 @@ import org.eclipse.hawkbit.repository.TargetManagement;
import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.jpa.repository.ActionRepository;
-import org.eclipse.hawkbit.repository.jpa.specifications.ActionSpecifications;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.Action.Status;
import org.eclipse.hawkbit.repository.model.DistributionSet;
@@ -1067,7 +1066,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
.andExpect(jsonPath("$.locked", equalTo(false)))
.andExpect(jsonPath("$.deleted", equalTo(false)));
- final DistributionSet setupdated = distributionSetManagement.get(set.getId()).get();
+ final DistributionSet setupdated = distributionSetManagement.find(set.getId()).get();
assertThat(setupdated.isRequiredMigrationStep()).isTrue();
assertThat(setupdated.getVersion()).isEqualTo("anotherVersion");
@@ -1079,8 +1078,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
* Ensures that DS property update on requiredMigrationStep fails if DS is assigned to a target.
*/
@Test
- void updateRequiredMigrationStepFailsIfDistributionSetisInUse() throws Exception {
-
+ void updateRequiredMigrationStepFailsIfDistributionSetIsInUse() throws Exception {
// prepare test data
assertThat(distributionSetManagement.findAll(PAGE)).isEmpty();
@@ -1095,7 +1093,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isForbidden());
- final DistributionSet setupdated = distributionSetManagement.get(set.getId()).get();
+ final DistributionSet setupdated = distributionSetManagement.find(set.getId()).get();
assertThat(setupdated.isRequiredMigrationStep()).isFalse();
assertThat(setupdated.getVersion()).isEqualTo(set.getVersion());
@@ -1702,16 +1700,16 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
.content(jsonObject.toString()).contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk());
- assertThat(targetFilterQueryManagement.get(targetFilterQuery.getId()).get().getAutoAssignDistributionSet())
+ assertThat(targetFilterQueryManagement.find(targetFilterQuery.getId()).get().getAutoAssignDistributionSet())
.isNull();
- assertThat(rolloutManagement.get(rollout.getId()).get().getStatus()).isIn(RolloutStatus.STOPPING,
+ assertThat(rolloutManagement.find(rollout.getId()).get().getStatus()).isIn(RolloutStatus.STOPPING,
RolloutStatus.STOPPED);
//then enforce executor to stop the rollout and check
rolloutHandler.handleAll();
- assertThat(rolloutManagement.get(rollout.getId()).get().getStatus()).isIn(RolloutStatus.STOPPED);
+ assertThat(rolloutManagement.find(rollout.getId()).get().getStatus()).isIn(RolloutStatus.STOPPED);
for (final Target target : targets) {
- assertThat(targetManagement.get(target.getId()).get().getUpdateStatus())
+ assertThat(targetManagement.find(target.getId()).get().getUpdateStatus())
.isEqualTo(TargetUpdateStatus.PENDING);
assertThat(deploymentManagement.findActionsByTarget(target.getControllerId(), PageRequest.of(0, 100))
.getNumberOfElements()).isEqualTo(1);
@@ -1737,17 +1735,17 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
.content(jsonObject.toString()).contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk());
- assertThat(targetFilterQueryManagement.get(targetFilterQuery.getId()).get().getAutoAssignDistributionSet())
+ assertThat(targetFilterQueryManagement.find(targetFilterQuery.getId()).get().getAutoAssignDistributionSet())
.isNull();
- assertThat(rolloutManagement.get(rollout.getId()).get().getStatus()).isIn(RolloutStatus.DELETING,
+ assertThat(rolloutManagement.find(rollout.getId()).get().getStatus()).isIn(RolloutStatus.DELETING,
RolloutStatus.DELETED);
//then enforce executor to stop the rollout and check
rolloutHandler.handleAll();
// assert rollout is deleted
- assertThat(rolloutManagement.get(rollout.getId())).isEmpty();
+ assertThat(rolloutManagement.find(rollout.getId())).isEmpty();
for (final Target target : targets) {
- assertThat(targetManagement.get(target.getId()).get().getUpdateStatus())
+ assertThat(targetManagement.find(target.getId()).get().getUpdateStatus())
.isEqualTo(TargetUpdateStatus.IN_SYNC);
assertThat(deploymentManagement.findActionsByTarget(target.getControllerId(), PageRequest.of(0, 100))
.getNumberOfElements()).isEqualTo(1);
@@ -1771,10 +1769,10 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
.content(jsonObject.toString()).contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk());
- assertThat(rolloutManagement.get(rollout.getId()).get().getStatus()).isIn(RolloutStatus.RUNNING);
+ assertThat(rolloutManagement.find(rollout.getId()).get().getStatus()).isIn(RolloutStatus.RUNNING);
for (final Target target : targets) {
- assertThat(targetManagement.get(target.getId()).get().getUpdateStatus())
+ assertThat(targetManagement.find(target.getId()).get().getUpdateStatus())
.isEqualTo(TargetUpdateStatus.PENDING);
assertThat(deploymentManagement.findActionsByTarget(target.getControllerId(), PageRequest.of(0, 100))
.getNumberOfElements()).isEqualTo(1);
@@ -1803,7 +1801,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
.andExpect(status().isOk())
.andExpect(jsonPath("$.locked", equalTo(true)));
- final DistributionSet updatedSet = distributionSetManagement.get(set.getId()).get();
+ final DistributionSet updatedSet = distributionSetManagement.find(set.getId()).get();
assertThat(updatedSet.isLocked()).isTrue();
}
@@ -1818,7 +1816,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
final DistributionSet set = testdataFactory.createDistributionSet("one");
assertThat(distributionSetManagement.count()).isEqualTo(1);
distributionSetManagement.lock(set);
- assertThat(distributionSetManagement.get(set.getId())
+ assertThat(distributionSetManagement.find(set.getId())
.orElseThrow(() -> new EntityNotFoundException(SoftwareModule.class, set.getId())).isLocked())
.as("Distribution set should be locked")
.isTrue();
@@ -1831,7 +1829,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
.andExpect(status().isOk())
.andExpect(jsonPath("$.locked", equalTo(false)));
- final DistributionSet updatedSet = distributionSetManagement.get(set.getId()).get();
+ final DistributionSet updatedSet = distributionSetManagement.find(set.getId()).get();
assertThat(updatedSet.isLocked()).isFalse();
}
diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResourceTest.java b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResourceTest.java
index 1a53acded..0bd9fe5d8 100644
--- a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResourceTest.java
+++ b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResourceTest.java
@@ -261,7 +261,7 @@ class MgmtDistributionSetTagResourceTest extends AbstractManagementApiIntegratio
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
- assertThat(distributionSetTagManagement.get(original.getId())).isNotPresent();
+ assertThat(distributionSetTagManagement.find(original.getId())).isNotPresent();
}
/**
diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResourceTest.java b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResourceTest.java
index 60627f5b2..9886be140 100644
--- a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResourceTest.java
+++ b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResourceTest.java
@@ -181,7 +181,7 @@ class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIntegrati
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
- testType = distributionSetTypeManagement.get(testType.getId()).get();
+ testType = distributionSetTypeManagement.find(testType.getId()).get();
assertThat(testType.getLastModifiedBy()).isEqualTo("uploadTester");
assertThat(testType.getMandatoryModuleTypes()).containsExactly(osType);
assertThat(testType.getOptionalModuleTypes()).isEmpty();
@@ -207,7 +207,7 @@ class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIntegrati
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
- testType = distributionSetTypeManagement.get(testType.getId()).get();
+ testType = distributionSetTypeManagement.find(testType.getId()).get();
assertThat(testType.getLastModifiedBy()).isEqualTo("uploadTester");
assertThat(testType.getOptionalModuleTypes()).containsExactly(osType);
assertThat(testType.getMandatoryModuleTypes()).isEmpty();
@@ -366,7 +366,7 @@ class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIntegrati
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
- testType = distributionSetTypeManagement.get(testType.getId()).get();
+ testType = distributionSetTypeManagement.find(testType.getId()).get();
assertThat(testType.getLastModifiedBy()).isEqualTo("uploadTester");
assertThat(testType.getOptionalModuleTypes()).containsExactly(appType);
assertThat(testType.getMandatoryModuleTypes()).isEmpty();
@@ -385,7 +385,7 @@ class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIntegrati
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
- testType = distributionSetTypeManagement.get(testType.getId()).get();
+ testType = distributionSetTypeManagement.find(testType.getId()).get();
assertThat(testType.getLastModifiedBy()).isEqualTo("uploadTester");
assertThat(testType.getOptionalModuleTypes()).isEmpty();
assertThat(testType.getMandatoryModuleTypes()).containsExactly(osType);
diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResourceTest.java b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResourceTest.java
index 782c07671..e487b05c4 100644
--- a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResourceTest.java
+++ b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResourceTest.java
@@ -1946,7 +1946,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
private void awaitRunningState(final Long rolloutId) {
awaitRollout().until(() -> SecurityContextSwitch
- .callAsPrivileged(() -> rolloutManagement.get(rolloutId).orElseThrow(NoSuchElementException::new))
+ .callAsPrivileged(() -> rolloutManagement.find(rolloutId).orElseThrow(NoSuchElementException::new))
.getStatus().equals(RolloutStatus.RUNNING));
}
@@ -1966,7 +1966,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
}
private void assertStatusIs(final Rollout rollout, final RolloutStatus expected) {
- final Optional updatedRollout = rolloutManagement.get(rollout.getId());
+ final Optional updatedRollout = rolloutManagement.find(rollout.getId());
assertThat(updatedRollout).get().extracting(Rollout::getStatus).isEqualTo(expected);
}
@@ -2039,7 +2039,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
// Run here, because Scheduler is disabled during tests
rolloutHandler.handleAll();
- return rolloutManagement.get(rollout.getId()).orElseThrow(NoSuchElementException::new);
+ return rolloutManagement.find(rollout.getId()).orElseThrow(NoSuchElementException::new);
}
private void triggerNextGroupAndExpect(final Rollout rollout, final ResultMatcher expect) throws Exception {
diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java
index 6b2c02ca0..272009329 100644
--- a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java
+++ b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java
@@ -47,6 +47,9 @@ import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.mgmt.rest.resource.util.ResourceUtility;
import org.eclipse.hawkbit.repository.Constants;
import org.eclipse.hawkbit.repository.SoftwareModuleManagement;
+import org.eclipse.hawkbit.repository.artifact.exception.ArtifactBinaryNotFoundException;
+import org.eclipse.hawkbit.repository.artifact.model.DbArtifact;
+import org.eclipse.hawkbit.repository.artifact.model.DbArtifactHash;
import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.exception.FileSizeQuotaExceededException;
@@ -258,7 +261,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
.andExpect(jsonPath("$.locked", equalTo(false)))
.andReturn();
- final SoftwareModule updatedSm = softwareModuleManagement.get(sm.getId()).get();
+ final SoftwareModule updatedSm = softwareModuleManagement.find(sm.getId()).get();
assertThat(updatedSm.getName()).isEqualTo(knownSWName);
assertThat(updatedSm.getVendor()).isEqualTo(updateVendor);
assertThat(updatedSm.getLastModifiedBy()).isEqualTo("smUpdateTester");
@@ -294,7 +297,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
.andExpect(jsonPath("$.lastModifiedAt", equalTo(sm.getLastModifiedAt())))
.andExpect(jsonPath("$.deleted", equalTo(false)));
- softwareModuleManagement.get(sm.getId());
+ softwareModuleManagement.find(sm.getId());
assertThat(sm.getLastModifiedBy()).isEqualTo("smUpdateTester");
assertThat(sm.getLastModifiedAt()).isEqualTo(sm.getLastModifiedAt());
assertThat(sm.isDeleted()).isFalse();
@@ -319,7 +322,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
mvc.perform(put("/rest/v1/softwaremodules/{smId}", sm.getId()).content(body)
.contentType(MediaType.APPLICATION_JSON));
- final SoftwareModule updatedSm = softwareModuleManagement.get(sm.getId()).get();
+ final SoftwareModule updatedSm = softwareModuleManagement.find(sm.getId()).get();
assertThat(updatedSm.getLastModifiedBy()).isEqualTo("smUpdateTester");
assertThat(updatedSm.isLocked()).isTrue();
@@ -341,7 +344,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
final SoftwareModule sm = softwareModuleManagement.create(
SoftwareModuleManagement.Create.builder().type(osType).name("name1").version("version1").build());
softwareModuleManagement.lock(sm);
- assertThat(softwareModuleManagement.get(sm.getId())
+ assertThat(softwareModuleManagement.find(sm.getId())
.orElseThrow(() -> new EntityNotFoundException(SoftwareModule.class, sm.getId())).isLocked())
.as("Software module is locked")
.isTrue();
@@ -354,7 +357,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
mvc.perform(put("/rest/v1/softwaremodules/{smId}", sm.getId()).content(body)
.contentType(MediaType.APPLICATION_JSON));
- final SoftwareModule updatedSm = softwareModuleManagement.get(sm.getId()).get();
+ final SoftwareModule updatedSm = softwareModuleManagement.find(sm.getId()).get();
assertThat(updatedSm.getLastModifiedBy()).isEqualTo("smUpdateTester");
assertThat(updatedSm.isLocked()).isFalse(); // not unlocked
@@ -397,7 +400,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
// check rest of response compared to DB
final MgmtArtifact artResult = ResourceUtility.convertArtifactResponse(
mvcResult.getResponse().getContentAsString());
- final Long artId = softwareModuleManagement.get(sm.getId()).get().getArtifacts().get(0).getId();
+ final Long artId = softwareModuleManagement.find(sm.getId()).get().getArtifacts().get(0).getId();
assertThat(artResult.getId()).as("Wrong artifact id").isEqualTo(artId);
assertThat((Object) JsonPath.compile("$._links.self.href").read(mvcResult.getResponse().getContentAsString()))
.as("Link contains no self url")
@@ -455,14 +458,10 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
@Test
void emptyUploadArtifact() throws Exception {
assertThat(softwareModuleManagement.findAll(PAGE)).isEmpty();
- assertThat(artifactManagement.count()).isZero();
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
-
final MockMultipartFile file = new MockMultipartFile("file", "orig", null, new byte[0]);
-
- mvc.perform(multipart("/rest/v1/softwaremodules/{smId}/artifacts", sm.getId()).file(file)
- .accept(MediaType.APPLICATION_JSON))
+ mvc.perform(multipart("/rest/v1/softwaremodules/{smId}/artifacts", sm.getId()).file(file).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
}
@@ -502,7 +501,6 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
@Test
void uploadArtifactWithCustomName() throws Exception {
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
- assertThat(artifactManagement.count()).isZero();
// create test file
final byte[] random = randomBytes(5 * 1024);
@@ -515,14 +513,11 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
.andExpect(status().isCreated())
.andExpect(content().contentType(MediaTypes.HAL_JSON))
.andExpect(jsonPath("$.providedFilename", equalTo("customFilename")))
- .andExpect(status().isCreated());
-
- // check result in db...
- // repo
- assertThat(artifactManagement.count()).isEqualTo(1);
-
- // hashes
- assertThat(artifactManagement.getByFilename("customFilename")).as("Local artifact is wrong").isPresent();
+ .andExpect(status().isCreated())
+ .andDo(result -> {
+ final MgmtArtifact mgmtArtifact = OBJECT_MAPPER.readerFor(MgmtArtifact.class).readValue(result.getResponse().getContentAsString());
+ assertThat(artifactManagement.loadArtifactBinary(mgmtArtifact.getHashes().getSha1(), sm.getId(), sm.isEncrypted())).isNotNull();
+ });
}
/**
@@ -531,7 +526,6 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
@Test
void uploadArtifactWithHashCheck() throws Exception {
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
- assertThat(artifactManagement.count()).isZero();
// create test file
final byte[] random = randomBytes(5 * 1024);
@@ -586,7 +580,6 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
.andExpect(status().isCreated());
assertArtifact(sm, random);
-
}
/**
@@ -700,9 +693,6 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
downloadAndVerify(sm, random, artifact);
downloadAndVerify(sm, random, artifact2);
-
- assertThat(softwareModuleManagement.findAll(PAGE)).as("Softwaremodule size is wrong").hasSize(1);
- assertThat(artifactManagement.count()).isEqualTo(2);
}
/**
@@ -783,7 +773,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
SoftwareModule sm = testdataFactory.createSoftwareModuleOs("softDeleted");
final Artifact artifact = testdataFactory.createArtifacts(sm.getId()).get(0);
// the sm is changed by artifact creation, necessary to get the latest version for Hibernate
- sm = softwareModuleManagement.get(sm.getId()).orElseThrow();
+ sm = softwareModuleManagement.find(sm.getId()).orElseThrow();
testdataFactory.createDistributionSet(List.of(sm));
softwareModuleManagement.delete(sm.getId());
@@ -904,7 +894,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
SoftwareModule smSoftDeleted = testdataFactory.createSoftwareModuleOs("softDeleted");
final Artifact artifactSoftDeleted = testdataFactory.createArtifacts(smSoftDeleted.getId()).get(0);
// the smSoftDeleted is changed by artifact creation, necessary to get the latest version for Hibernate
- smSoftDeleted = softwareModuleManagement.get(smSoftDeleted.getId()).orElseThrow();
+ smSoftDeleted = softwareModuleManagement.find(smSoftDeleted.getId()).orElseThrow();
testdataFactory.createDistributionSet(List.of(smSoftDeleted));
softwareModuleManagement.delete(smSoftDeleted.getId());
@@ -959,31 +949,34 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
final int artifactSize = 5 * 1024;
- final byte[] random = randomBytes(artifactSize);
// Create 2 artifacts
+ final long moduleId = sm.getId();
+ final byte[] random = randomBytes(artifactSize);
final Artifact artifact = artifactManagement.create(
- new ArtifactUpload(new ByteArrayInputStream(random), sm.getId(), "file1", false, artifactSize));
+ new ArtifactUpload(new ByteArrayInputStream(random), moduleId, "file1", false, artifactSize));
+ final byte[] random2 = randomBytes(artifactSize);
artifactManagement.create(
- new ArtifactUpload(new ByteArrayInputStream(random), sm.getId(), "file2", false, artifactSize));
+ new ArtifactUpload(new ByteArrayInputStream(random2), moduleId, "file2", false, artifactSize));
// check repo before delete
assertThat(softwareModuleManagement.findAll(PAGE)).hasSize(1);
- assertThat(softwareModuleManagement.get(sm.getId()).get().getArtifacts()).hasSize(2);
- assertThat(artifactManagement.count()).isEqualTo(2);
+ assertThat(softwareModuleManagement.find(moduleId).get().getArtifacts()).hasSize(2);
// delete
- mvc.perform(delete("/rest/v1/softwaremodules/{smId}/artifacts/{artId}", sm.getId(), artifact.getId()))
+ mvc.perform(delete("/rest/v1/softwaremodules/{smId}/artifacts/{artId}", moduleId, artifact.getId()))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
// check that only one artifact is still alive and still assigned
assertThat(softwareModuleManagement.findAll(PAGE)).as("After the sm should be marked as deleted").hasSize(1);
- assertThat(artifactManagement.count()).isEqualTo(1);
- assertThat(softwareModuleManagement.get(sm.getId()).get().getArtifacts())
+ final boolean encrypted = sm.isEncrypted();
+ final String sha1Hash = artifact.getSha1Hash();
+ assertThatExceptionOfType(ArtifactBinaryNotFoundException.class)
+ .isThrownBy(() -> artifactManagement.loadArtifactBinary(sha1Hash, moduleId, encrypted));
+ assertThat(softwareModuleManagement.find(moduleId).get().getArtifacts())
.as("After delete artifact should available for marked as deleted sm's").hasSize(1);
-
}
/**
@@ -1332,8 +1325,8 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
.isEqualTo("http://localhost/rest/v1/softwaremodules/" + appCreatedId);
assertThat(softwareModuleManagement.findAll(PAGE)).as("Wrong softwaremodule size").hasSize(2);
- final SoftwareModule osCreated = softwareModuleManagement.get(osCreatedId).orElseThrow();
- final SoftwareModule appCreated = softwareModuleManagement.get(appCreatedId).orElseThrow();
+ final SoftwareModule osCreated = softwareModuleManagement.find(osCreatedId).orElseThrow();
+ final SoftwareModule appCreated = softwareModuleManagement.find(appCreatedId).orElseThrow();
assertThat(osCreated.getName()).as("Softwaremoudle name is wrong").isEqualTo(os.getName());
assertThat(osCreated.getCreatedBy()).as("Softwaremoudle created by is wrong").isEqualTo("uploadTester");
assertThat(osCreated.getCreatedAt()).as("Softwaremoudle created at is wrong").isGreaterThanOrEqualTo(current);
@@ -1345,29 +1338,32 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
*/
@Test
void deleteUnassignedSoftwareModule() throws Exception {
-
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
final int artifactSize = 5 * 1024;
final byte[] random = randomBytes(artifactSize);
- artifactManagement.create(
+ final Artifact artifact = artifactManagement.create(
new ArtifactUpload(new ByteArrayInputStream(random), sm.getId(), "file1", false, artifactSize));
assertThat(softwareModuleManagement.findAll(PAGE)).as("Softwaremoudle size is wrong").hasSize(1);
- assertThat(artifactManagement.count()).isEqualTo(1);
+
+ final Long smId = sm.getId();
+ final String sha1Hash = artifact.getSha1Hash();
+ final boolean encrypted = sm.isEncrypted();
+ assertThat(artifactManagement.loadArtifactBinary(sha1Hash, smId, encrypted)).isNotNull();
mvc.perform(delete("/rest/v1/softwaremodules/{smId}", sm.getId()))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
- assertThat(softwareModuleManagement.findAll(PAGE)).as("After delete no softwarmodule should be available")
- .isEmpty();
- assertThat(artifactManagement.count()).isZero();
+ assertThat(softwareModuleManagement.findAll(PAGE)).as("After delete no softwarmodule should be available").isEmpty();
+ assertThatExceptionOfType(EntityNotFoundException.class) // sm doesn't exists
+ .isThrownBy(() -> artifactManagement.loadArtifactBinary(sha1Hash, smId, encrypted));
}
/**
- * Verifies successfull deletion of a software module that is in use, i.e. assigned to a DS which should result in movinf the module to the archive.
+ * Verifies successful deletion of a software module that is in use, i.e. assigned to a DS which should result in movinf the module to the archive.
*/
@Test
void deleteAssignedSoftwareModule() throws Exception {
@@ -1376,13 +1372,16 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
final int artifactSize = 5 * 1024;
final byte[] random = randomBytes(artifactSize);
- final Long appTypeSmId = findFirstModuleByType(ds1, appType).get().getId();
+ final SoftwareModule appTypeSm = findFirstModuleByType(ds1, appType).get();
+ final Long appTypeSmId = appTypeSm.getId();
- artifactManagement.create(
+ final Artifact artifact = artifactManagement.create(
new ArtifactUpload(new ByteArrayInputStream(random), appTypeSmId, "file1", false, artifactSize));
assertThat(softwareModuleManagement.count()).isEqualTo(3);
- assertThat(artifactManagement.count()).isEqualTo(1);
+ final String sha1Hash = artifact.getSha1Hash();
+ final boolean encrypted = appTypeSm.isEncrypted();
+ assertThat(artifactManagement.loadArtifactBinary(sha1Hash, appTypeSmId, encrypted)).isNotNull();
mvc.perform(get("/rest/v1/softwaremodules/{smId}", appTypeSmId))
.andDo(MockMvcResultPrinter.print())
@@ -1399,7 +1398,8 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
.andExpect(jsonPath("$.deleted", equalTo(true)));
assertThat(softwareModuleManagement.count()).isEqualTo(2);
- assertThat(artifactManagement.count()).isEqualTo(1);
+ assertThatExceptionOfType(ArtifactBinaryNotFoundException.class)
+ .isThrownBy(() -> artifactManagement.loadArtifactBinary(sha1Hash, appTypeSmId, encrypted));
}
/**
@@ -1526,31 +1526,25 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
}
private void assertArtifact(final SoftwareModule sm, final byte[] random) throws IOException {
- // check result in db...
- // repo
- assertThat(artifactManagement.count()).as("Wrong artifact size").isEqualTo(1);
-
+ final DbArtifact artifact = artifactManagement
+ .loadArtifactBinary(
+ softwareModuleManagement.find(
+ sm.getId()).orElseThrow().getArtifacts().get(0).getSha1Hash(), sm.getId(), sm.isEncrypted());
// binary
- try (final InputStream fileInputStream = artifactManagement
- .loadArtifactBinary(softwareModuleManagement.get(sm.getId()).orElseThrow().getArtifacts().get(0).getSha1Hash(),
- sm.getId(), sm.isEncrypted())
- .get().getFileInputStream()) {
+ try (final InputStream fileInputStream = artifact.getFileInputStream()) {
assertTrue(IOUtils.contentEquals(new ByteArrayInputStream(random), fileInputStream),
"Wrong artifact content");
}
// hashes
- assertThat(artifactManagement.getByFilename("origFilename").orElseThrow().getSha1Hash()).as("Wrong sha1 hash")
- .isEqualTo(HashGeneratorUtils.generateSHA1(random));
-
- assertThat(artifactManagement.getByFilename("origFilename").orElseThrow().getMd5Hash()).as("Wrong md5 hash")
- .isEqualTo(HashGeneratorUtils.generateMD5(random));
-
- assertThat(artifactManagement.getByFilename("origFilename").orElseThrow().getSha256Hash()).as("Wrong sha256 hash")
- .isEqualTo(HashGeneratorUtils.generateSHA256(random));
+ final DbArtifactHash hash = artifact.getHashes();
+ assertThat(hash.getSha1()).as("Wrong sha1 hash").isEqualTo(HashGeneratorUtils.generateSHA1(random));
+ // sha1 hashes are not used via loaded artifact
+// assertThat(hash.getMd5()).as("Wrong md5 hash").isEqualTo(HashGeneratorUtils.generateMD5(random));
+// assertThat(hash.getSha256()).as("Wrong sha256 hash").isEqualTo(HashGeneratorUtils.generateSHA256(random));
// metadata
- assertThat(softwareModuleManagement.get(sm.getId()).orElseThrow().getArtifacts().get(0).getFilename())
+ assertThat(softwareModuleManagement.find(sm.getId()).orElseThrow().getArtifacts().get(0).getFilename())
.as("wrong metadata of the filename").isEqualTo("origFilename");
}
diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResourceTest.java b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResourceTest.java
index c29326607..40ec0a3b0 100644
--- a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResourceTest.java
+++ b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResourceTest.java
@@ -349,7 +349,7 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt
.andExpect(jsonPath("$.lastModifiedAt", equalTo(testType.getLastModifiedAt())))
.andExpect(jsonPath("$.deleted", equalTo(false)));
- testType = softwareModuleTypeManagement.get(testType.getId()).get();
+ testType = softwareModuleTypeManagement.find(testType.getId()).get();
assertThat(testType.getLastModifiedAt()).isEqualTo(testType.getLastModifiedAt());
assertThat(testType.isDeleted()).isFalse();
}
diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetFilterQueryResourceTest.java b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetFilterQueryResourceTest.java
index 9190d2daa..10d32efde 100644
--- a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetFilterQueryResourceTest.java
+++ b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetFilterQueryResourceTest.java
@@ -144,7 +144,7 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte
mvc.perform(delete(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "/" + filterQuery.getId()))
.andExpect(status().isOk());
- assertThat(targetFilterQueryManagement.get(filterQuery.getId())).isNotPresent();
+ assertThat(targetFilterQueryManagement.find(filterQuery.getId())).isNotPresent();
}
/**
@@ -192,7 +192,7 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte
.andExpect(jsonPath(JSON_PATH_NAME, equalTo(filterName)))
.andExpect(jsonPath(JSON_PATH_CONFIRMATION_REQUIRED).doesNotExist());
- final TargetFilterQuery tfqCheck = targetFilterQueryManagement.get(tfq.getId()).get();
+ final TargetFilterQuery tfqCheck = targetFilterQueryManagement.find(tfq.getId()).get();
assertThat(tfqCheck.getQuery()).isEqualTo(filterQuery2);
assertThat(tfqCheck.getName()).isEqualTo(filterName);
}
@@ -219,7 +219,7 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte
.andExpect(jsonPath(JSON_PATH_NAME, equalTo(filterName2)))
.andExpect(jsonPath(JSON_PATH_CONFIRMATION_REQUIRED).doesNotExist());
- final TargetFilterQuery tfqCheck = targetFilterQueryManagement.get(tfq.getId()).get();
+ final TargetFilterQuery tfqCheck = targetFilterQueryManagement.find(tfq.getId()).get();
assertThat(tfqCheck.getQuery()).isEqualTo(filterQuery);
assertThat(tfqCheck.getName()).isEqualTo(filterName2);
}
@@ -493,7 +493,7 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte
.andExpect(status().isOk());
implicitLock(set);
- final TargetFilterQuery updatedFilterQuery = targetFilterQueryManagement.get(filterQuery.getId()).get();
+ final TargetFilterQuery updatedFilterQuery = targetFilterQueryManagement.find(filterQuery.getId()).get();
assertThat(updatedFilterQuery.getAutoAssignDistributionSet()).isEqualTo(set);
assertThat(updatedFilterQuery.getAutoAssignActionType()).isEqualTo(ActionType.FORCED);
@@ -603,7 +603,7 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte
targetFilterQueryManagement.updateAutoAssignDS(new AutoAssignDistributionSetUpdate(tfq.getId()).ds(set.getId()));
implicitLock(set);
- final TargetFilterQuery updatedFilterQuery = targetFilterQueryManagement.get(tfq.getId()).orElseThrow();
+ final TargetFilterQuery updatedFilterQuery = targetFilterQueryManagement.find(tfq.getId()).orElseThrow();
assertThat(updatedFilterQuery.getAutoAssignDistributionSet()).isEqualTo(set);
assertThat(updatedFilterQuery.getAutoAssignActionType()).isEqualTo(ActionType.FORCED);
@@ -615,7 +615,7 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte
mvc.perform(delete(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "/" + tfq.getId() + "/autoAssignDS"))
.andExpect(status().isNoContent());
- final TargetFilterQuery filterQueryWithDeletedDs = targetFilterQueryManagement.get(tfq.getId()).get();
+ final TargetFilterQuery filterQueryWithDeletedDs = targetFilterQueryManagement.find(tfq.getId()).get();
assertThat(filterQueryWithDeletedDs.getAutoAssignDistributionSet()).isNull();
assertThat(filterQueryWithDeletedDs.getAutoAssignActionType()).isNull();
@@ -676,7 +676,7 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte
// do not provide something about the confirmation
verifyAutoAssignmentByActionType(tfq, set, null, null);
- assertThat(targetFilterQueryManagement.get(tfq.getId())).hasValueSatisfying(filter ->
+ assertThat(targetFilterQueryManagement.find(tfq.getId())).hasValueSatisfying(filter ->
assertThat(filter.isConfirmationRequired()).isEqualTo(confirmationFlowActive));
}
@@ -720,7 +720,7 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte
.andExpect(status().isOk());
implicitLock(set);
- final TargetFilterQuery updatedFilterQuery = targetFilterQueryManagement.get(tfq.getId()).get();
+ final TargetFilterQuery updatedFilterQuery = targetFilterQueryManagement.find(tfq.getId()).get();
final MgmtActionType expectedActionType = actionType != null ? actionType : MgmtActionType.FORCED;
assertThat(updatedFilterQuery.getAutoAssignDistributionSet()).isEqualTo(set);
diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java
index 75c84fb71..eae80ef15 100644
--- a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java
+++ b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java
@@ -2576,7 +2576,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
final long unknownTargetTypeId = 999;
final String errorMsg = String.format("TargetType with given identifier {%s} does not exist.", unknownTargetTypeId);
- final Optional extends TargetType> targetType = targetTypeManagement.get(unknownTargetTypeId);
+ final Optional extends TargetType> targetType = targetTypeManagement.find(unknownTargetTypeId);
assertThat(targetType).isNotPresent();
final String controllerId = "targetcontroller";
diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResourceTest.java b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResourceTest.java
index 3e5313cec..01ccb03f0 100644
--- a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResourceTest.java
+++ b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResourceTest.java
@@ -227,7 +227,7 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
- assertThat(targetTagManagement.get(original.getId())).isNotPresent();
+ assertThat(targetTagManagement.find(original.getId())).isNotPresent();
}
/**
diff --git a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTypeResourceTest.java b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTypeResourceTest.java
index 9d21f7265..af47fcafc 100644
--- a/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTypeResourceTest.java
+++ b/hawkbit-mgmt/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTypeResourceTest.java
@@ -349,7 +349,7 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
- testType = targetTypeManagement.get(testType.getId()).get();
+ testType = targetTypeManagement.find(testType.getId()).get();
assertThat(testType.getLastModifiedBy()).isEqualTo(TEST_USER);
assertThat(testType.getOptLockRevision()).isEqualTo(2);
assertThat(testType.getDistributionSetTypes()).containsExactly(standardDsType);
@@ -405,7 +405,7 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
- testType = targetTypeManagement.get(testType.getId()).get();
+ testType = targetTypeManagement.find(testType.getId()).get();
assertThat(testType.getLastModifiedBy()).isEqualTo(TEST_USER);
assertThat(testType.getOptLockRevision()).isEqualTo(2);
assertThat(testType.getDistributionSetTypes()).isEmpty();
@@ -425,7 +425,7 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
- testType = targetTypeManagement.get(testType.getId()).get();
+ testType = targetTypeManagement.find(testType.getId()).get();
assertThat(testType.getLastModifiedBy()).isEqualTo(TEST_USER);
assertThat(testType.getOptLockRevision()).isEqualTo(2);
assertThat(testType.getDistributionSetTypes()).isEmpty();
diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ArtifactManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ArtifactManagement.java
index d06bbb24c..6069b91d1 100644
--- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ArtifactManagement.java
+++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ArtifactManagement.java
@@ -9,8 +9,6 @@
*/
package org.eclipse.hawkbit.repository;
-import java.util.Optional;
-
import jakarta.validation.ConstraintViolationException;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
@@ -19,8 +17,6 @@ import jakarta.validation.constraints.NotNull;
import org.eclipse.hawkbit.im.authentication.SpPermission;
import org.eclipse.hawkbit.repository.artifact.model.DbArtifact;
import org.eclipse.hawkbit.im.authentication.SpringEvalExpressions;
-import org.eclipse.hawkbit.repository.exception.ArtifactDeleteFailedException;
-import org.eclipse.hawkbit.repository.exception.ArtifactUploadFailedException;
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.exception.InvalidMD5HashException;
@@ -28,8 +24,6 @@ import org.eclipse.hawkbit.repository.exception.InvalidSHA1HashException;
import org.eclipse.hawkbit.repository.model.Artifact;
import org.eclipse.hawkbit.repository.model.ArtifactUpload;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.Pageable;
import org.springframework.security.access.prepost.PreAuthorize;
/**
@@ -42,12 +36,6 @@ public interface ArtifactManagement extends PermissionSupport {
return SpPermission.SOFTWARE_MODULE;
}
- /**
- * @return the total amount of local artifacts stored in the artifact management
- */
- @PreAuthorize(SpringEvalExpressions.HAS_READ_REPOSITORY)
- long count();
-
/**
* Persists artifact binary as provided by given InputStream. assign the
* artifact in addition to given {@link SoftwareModule}.
@@ -56,7 +44,7 @@ public interface ArtifactManagement extends PermissionSupport {
* @return uploaded {@link Artifact}
* @throws EntityNotFoundException if given software module does not exist
* @throws EntityAlreadyExistsException if File with that name already exists in the Software Module
- * @throws ArtifactUploadFailedException if upload fails with internal server errors
+ * @throws org.eclipse.hawkbit.repository.artifact.exception.ArtifactUploadFailedException if upload fails with internal server errors
* @throws InvalidMD5HashException if check against provided MD5 checksum failed
* @throws InvalidSHA1HashException if check against provided SHA1 checksum failed
* @throws ConstraintViolationException if {@link ArtifactUpload} contains invalid values
@@ -64,75 +52,6 @@ public interface ArtifactManagement extends PermissionSupport {
@PreAuthorize(SpringEvalExpressions.HAS_CREATE_REPOSITORY)
Artifact create(@NotNull @Valid ArtifactUpload artifactUpload);
- /**
- * Deletes {@link Artifact} based on given id.
- *
- * @param id of the {@link Artifact} that has to be deleted.
- * @throws ArtifactDeleteFailedException if deletion failed (MongoDB is not available)
- * @throws EntityNotFoundException if artifact with given ID does not exist
- */
- @PreAuthorize(SpringEvalExpressions.HAS_DELETE_REPOSITORY)
- void delete(long id);
-
- /**
- * Searches for {@link Artifact} with given {@link Identifiable}.
- *
- * @param id to search for
- * @return found {@link Artifact}
- */
- @PreAuthorize(SpringEvalExpressions.HAS_READ_REPOSITORY + " or " + SpringEvalExpressions.IS_CONTROLLER)
- Optional get(long id);
-
- /**
- * Find by artifact by software module id and filename.
- *
- * @param filename file name
- * @param softwareModuleId software module id.
- * @return found {@link Artifact}
- * @throws EntityNotFoundException if software module with given ID does not exist
- */
- @PreAuthorize(SpringEvalExpressions.HAS_READ_REPOSITORY + " or " + SpringEvalExpressions.IS_CONTROLLER)
- Optional getByFilenameAndSoftwareModule(@NotNull String filename, long softwareModuleId);
-
- /**
- * Find all local artifact by sha1 and return the first artifact.
- *
- * @param sha1 the sha1
- * @return the first local artifact
- */
- @PreAuthorize(SpringEvalExpressions.HAS_READ_REPOSITORY + " or " + SpringEvalExpressions.IS_CONTROLLER)
- Optional findFirstBySHA1(@NotNull String sha1);
-
- /**
- * Searches for {@link Artifact} with given file name.
- *
- * @param filename to search for
- * @return found List of {@link Artifact}s.
- */
- @PreAuthorize(SpringEvalExpressions.HAS_READ_REPOSITORY + " or " + SpringEvalExpressions.IS_CONTROLLER)
- Optional getByFilename(@NotNull String filename);
-
- /**
- * Get local artifact for a base software module.
- *
- * @param softwareModuleId software module id
- * @param pageable Pageable parameter
- * @return Page
- * @throws EntityNotFoundException if software module with given ID does not exist
- */
- @PreAuthorize(SpringEvalExpressions.HAS_READ_REPOSITORY)
- Page findBySoftwareModule(long softwareModuleId, @NotNull Pageable pageable);
-
- /**
- * Count local artifacts for a base software module.
- *
- * @param softwareModuleId software module id
- * @return count by software module
- * @throws EntityNotFoundException if software module with given ID does not exist
- */
- @PreAuthorize(SpringEvalExpressions.HAS_READ_REPOSITORY)
- long countBySoftwareModule(long softwareModuleId);
-
/**
* Loads {@link DbArtifact} from store for given {@link Artifact}.
*
@@ -142,6 +61,14 @@ public interface ArtifactManagement extends PermissionSupport {
* @return loaded {@link DbArtifact}
*/
@PreAuthorize("hasAuthority('" + SpPermission.DOWNLOAD_REPOSITORY_ARTIFACT + "')" + " or " + SpringEvalExpressions.IS_CONTROLLER)
- Optional loadArtifactBinary(@NotEmpty String sha1Hash, long softwareModuleId,
- final boolean isEncrypted);
+ DbArtifact loadArtifactBinary(@NotEmpty String sha1Hash, long softwareModuleId, final boolean isEncrypted);
+
+ /**
+ * Deletes {@link Artifact} based on given id.
+ *
+ * @param id of the {@link Artifact} that has to be deleted.
+ * @throws EntityNotFoundException if artifact with given ID does not exist
+ */
+ @PreAuthorize(SpringEvalExpressions.HAS_DELETE_REPOSITORY)
+ void delete(long id);
}
\ No newline at end of file
diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java
index a3770e42d..6cd574306 100644
--- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java
+++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java
@@ -268,7 +268,7 @@ public interface ControllerManagement {
* @see Target#getControllerId()
*/
@PreAuthorize(SpringEvalExpressions.IS_CONTROLLER + " or " + SpringEvalExpressions.IS_SYSTEM_CODE)
- Optional getByControllerId(@NotEmpty String controllerId);
+ Optional findByControllerId(@NotEmpty String controllerId);
/**
* Finds {@link Target} based on given ID returns found Target without details, i.e.
@@ -280,7 +280,7 @@ public interface ControllerManagement {
* @see Target#getId()
*/
@PreAuthorize(SpringEvalExpressions.IS_CONTROLLER + " or " + SpringEvalExpressions.IS_SYSTEM_CODE)
- Optional get(long targetId);
+ Optional find(long targetId);
/**
* Retrieves the specified number of messages from action history of the given {@link Action} based on messageCount. Regardless of the
diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java
index 838a00dbc..83aa21f05 100644
--- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java
+++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java
@@ -37,7 +37,6 @@ import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException;
import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException;
import org.eclipse.hawkbit.repository.exception.UnsupportedSoftwareModuleForThisDistributionSetException;
import org.eclipse.hawkbit.repository.model.DistributionSet;
-import org.eclipse.hawkbit.repository.model.DistributionSetFilter;
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
import org.eclipse.hawkbit.repository.model.DistributionSetType;
import org.eclipse.hawkbit.repository.model.NamedEntity;
@@ -46,7 +45,6 @@ import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.Statistic;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
-import org.springframework.data.domain.Slice;
import org.springframework.security.access.prepost.PreAuthorize;
/**
@@ -62,7 +60,7 @@ public interface DistributionSetManagement
/**
* Find {@link DistributionSet} based on given ID including (lazy loaded) details, e.g. {@link DistributionSet#getModules()}.
- * For performance reasons it is recommended to use {@link #get(long)} if the details are not required.
+ * For performance reasons it is recommended to use {@link #find(long)} if the details are not required.
*
* @param id to look for.
* @return {@link DistributionSet}
@@ -70,16 +68,6 @@ public interface DistributionSetManagement
@PreAuthorize(HAS_READ_REPOSITORY)
Optional getWithDetails(long id);
- /**
- * Find distribution set by id and throw an exception if it is (soft) deleted.
- *
- * @param id id of {@link DistributionSet}
- * @return the found valid {@link DistributionSet}
- * @throws EntityNotFoundException if distribution set with given ID does not exist
- */
- @PreAuthorize(HAS_READ_REPOSITORY)
- T getOrElseThrowException(long id);
-
@PreAuthorize(HAS_READ_REPOSITORY)
boolean shouldLockImplicitly(final DistributionSet distributionSet);
diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RepositoryManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RepositoryManagement.java
index cde60f010..0b2156ea3 100644
--- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RepositoryManagement.java
+++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RepositoryManagement.java
@@ -11,6 +11,7 @@ package org.eclipse.hawkbit.repository;
import java.util.Collection;
import java.util.List;
+import java.util.Map;
import java.util.Optional;
import jakarta.validation.ConstraintViolationException;
@@ -26,7 +27,6 @@ import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldExc
import org.eclipse.hawkbit.repository.model.BaseEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
-import org.springframework.data.domain.Slice;
import org.springframework.security.access.prepost.PreAuthorize;
/**
@@ -58,6 +58,16 @@ public interface RepositoryManagement create(@NotNull @Valid Collection create);
+ /**
+ * Retrieve {@link BaseEntity} and throws exception if not found.
+ *
+ * @param id to search for
+ * @return {@link BaseEntity} in the repository with given {@link BaseEntity#getId()}
+ * @throws EntityNotFoundException if no entity with given ID exists
+ */
+ @PreAuthorize(SpringEvalExpressions.HAS_READ_REPOSITORY)
+ T get(long id);
+
/**
* Retrieve {@link BaseEntity}
*
@@ -65,16 +75,26 @@ public interface RepositoryManagement get(long id);
+ Optional find(long id);
/**
- * Retrieves all {@link BaseEntity}s without details.
+ * Retrieves {@link BaseEntity}s by id and throws exception if any of the requested entities are not found.
+ *
+ * @param ids the ids to for
+ * @return the found {@link BaseEntity}s
+ * @throws EntityNotFoundException if at least one of the given ids does not exist
+ */
+ @PreAuthorize(SpringEvalExpressions.HAS_READ_REPOSITORY)
+ List get(@NotEmpty Collection ids);
+
+ /**
+ * Retrieves {@link BaseEntity}s by id and skips not found.
*
* @param ids the ids to for
* @return the found {@link BaseEntity}s
*/
@PreAuthorize(SpringEvalExpressions.HAS_READ_REPOSITORY)
- List get(@NotEmpty Collection ids);
+ List find(@NotEmpty Collection ids);
/**
* Retrieves {@link Page} of all {@link BaseEntity} of given type.
@@ -134,6 +154,18 @@ public interface RepositoryManagement key is the ID of the entity, value is the updated entity
+ * @throws EntityReadOnlyException if the {@link BaseEntity} cannot be updated (e.g. is already in use)
+ * @throws EntityNotFoundException in case the {@link BaseEntity} does not exist and cannot be updated
+ * @throws ConstraintViolationException if fields are not filled as specified. Check {@link BaseEntity} for field constraints.
+ */
+ @PreAuthorize(SpringEvalExpressions.HAS_UPDATE_REPOSITORY)
+ Map update(@NotNull @Valid Collection update);
+
/**
* Deletes or marks as delete in case the {@link BaseEntity} is in use.
*
diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java
index f60b62a29..739932af3 100644
--- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java
+++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java
@@ -235,18 +235,16 @@ public interface RolloutManagement extends PermissionSupport {
* Retrieves a specific rollout by its ID.
*
* @param rolloutId the ID of the rollout to retrieve
- * @return the founded rollout or {@code null} if rollout with given ID does
- * not exists
+ * @return the found rollout or empty if rollout with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_READ_REPOSITORY)
- Optional get(long rolloutId);
+ Optional find(long rolloutId);
/**
* Retrieves a specific rollout by its name.
*
* @param rolloutName the name of the rollout to retrieve
- * @return the founded rollout or {@code null} if rollout with given name
- * does not exists
+ * @return the found rollout or empty if rollout with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_READ_REPOSITORY)
Optional getByName(@NotEmpty String rolloutName);
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutHandler.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutHandler.java
index 4d378cc1e..6c19f11aa 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutHandler.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutHandler.java
@@ -16,7 +16,6 @@ import java.util.concurrent.locks.Lock;
import io.micrometer.core.instrument.MeterRegistry;
import lombok.extern.slf4j.Slf4j;
-import org.eclipse.hawkbit.ContextAware;
import org.eclipse.hawkbit.repository.RolloutExecutor;
import org.eclipse.hawkbit.repository.RolloutHandler;
import org.eclipse.hawkbit.repository.RolloutManagement;
@@ -108,7 +107,7 @@ public class JpaRolloutHandler implements RolloutHandler {
final long startNano = System.nanoTime();
DeploymentHelper.runInNewTransaction(txManager, handlerId + "-" + rolloutId, status -> {
- rolloutManagement.get(rolloutId).ifPresentOrElse(
+ rolloutManagement.find(rolloutId).ifPresentOrElse(
rolloutExecutor::execute,
() -> log.error("Could not retrieve rollout with id {}. Will not continue with execution.", rolloutId));
return 0L;
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/AbstractJpaRepositoryManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/AbstractJpaRepositoryManagement.java
index a2dea5bf3..f3ab09819 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/AbstractJpaRepositoryManagement.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/AbstractJpaRepositoryManagement.java
@@ -15,12 +15,16 @@ import static org.eclipse.hawkbit.repository.jpa.configuration.Constants.TX_RT_M
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
+import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -31,11 +35,13 @@ import jakarta.persistence.criteria.CriteriaUpdate;
import jakarta.persistence.criteria.Root;
import jakarta.validation.constraints.NotNull;
+import lombok.extern.slf4j.Slf4j;
import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.Identifiable;
import org.eclipse.hawkbit.repository.RepositoryManagement;
import org.eclipse.hawkbit.repository.RsqlQueryField;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
+import org.eclipse.hawkbit.repository.exception.InvalidDistributionSetException;
import org.eclipse.hawkbit.repository.jpa.Jpa;
import org.eclipse.hawkbit.repository.jpa.JpaManagementHelper;
import org.eclipse.hawkbit.repository.jpa.JpaRepositoryConfiguration;
@@ -48,7 +54,6 @@ import org.eclipse.hawkbit.utils.ObjectCopyUtil;
import org.springframework.dao.ConcurrencyFailureException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
-import org.springframework.data.domain.Slice;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Retryable;
@@ -73,6 +78,7 @@ import org.springframework.validation.annotation.Validated;
@HandleAuthorizationDenied(handlerClass = JpaRepositoryConfiguration.ManagementExceptionThrowingMethodAuthorizationDeniedHandler.class)
@Transactional(readOnly = true)
@Validated
+@Slf4j
abstract class AbstractJpaRepositoryManagement, R extends BaseEntityRepository, A extends Enum & RsqlQueryField>
implements RepositoryManagement {
@@ -81,6 +87,7 @@ abstract class AbstractJpaRepositoryManagement jpaEntityCreator;
+ private final Function isValid;
protected AbstractJpaRepositoryManagement(final R jpaRepository, final EntityManager entityManager) {
this.jpaRepository = jpaRepository;
@@ -100,6 +107,25 @@ abstract class AbstractJpaRepositoryManagement {
+ if (isValidMethodF == null) {
+ return true; // if there is no isValid method, then it is always valid
+ } else {
+ try {
+ return (Boolean) isValidMethodF.invoke(jpaEntity);
+ } catch (final IllegalAccessException | InvocationTargetException e) {
+ log.error(e.getMessage(), e);
+ return false; // if it fails, then it is not valid
+ }
+ }
+ };
}
@Override
@@ -117,13 +143,23 @@ abstract class AbstractJpaRepositoryManagement get(final long id) {
+ public T get(final long id) {
+ return jpaRepository.getById(id);
+ }
+
+ @Override
+ public Optional find(final long id) {
return jpaRepository.findById(id);
}
@Override
public List get(final Collection ids) {
- return findAllById(ids);
+ return findAllById(ids, true);
+ }
+
+ @Override
+ public List find(final Collection ids) {
+ return findAllById(ids, false);
}
@Override
@@ -157,13 +193,8 @@ abstract class AbstractJpaRepositoryManagement new EntityNotFoundException(managementClass(), update.getId()));
- return update(update, entity);
- }
-
- protected T update(final Identifiable update, final T entity) {
+ final T entity = getValid(update.getId());
+ checkUpdate(update, entity);
// update getId has no setter in target JPA entity but shall have getter and the value shall be the same
// otherwise the Utils will throw an exception that there is no counterpart setter for getId
if (ObjectCopyUtil.copy(update, entity, false, this::attach)) {
@@ -173,6 +204,43 @@ abstract class AbstractJpaRepositoryManagement update(final Collection update) {
+ final Map toUpdate = findAllById(update.stream().map(Identifiable::getId).toList(), true)
+ .stream()
+ .filter(entity -> {
+ if (Boolean.FALSE.equals(isValid.apply(entity))) {
+ throw new InvalidDistributionSetException(
+ jpaRepository.getManagementClass().getSimpleName() + " " + entity.getId() + " is invalid");
+ }
+ return true;
+ })
+ .collect(Collectors.toMap(Identifiable::getId, Function.identity()));
+ final List toSave = new ArrayList<>(toUpdate.values());
+ for (final U u : update) {
+ final T entity = toUpdate.get(u.getId());
+ checkUpdate(u, entity);
+ // update getId has no setter in target JPA entity but shall have getter and the value shall be the same
+ // otherwise the Utils will throw an exception that there is no counterpart setter for getId
+ if (ObjectCopyUtil.copy(u, entity, false, this::attach)) {
+ toSave.add(entity);
+ }
+ }
+ if (toSave.isEmpty()) {
+ return toUpdate;
+ } else {
+ final List savedEntities = jpaRepository.saveAll(toSave);
+ final Map result = new HashMap<>(toUpdate);
+ for (final T savedEntity : savedEntities) {
+ result.put(savedEntity.getId(), savedEntity);
+ }
+ return result;
+ }
+ }
+
@Override
@Transactional
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = TX_RT_MAX, backoff = @Backoff(delay = TX_RT_DELAY))
@@ -194,18 +262,28 @@ abstract class AbstractJpaRepositoryManagement List.of(RsqlUtility.getInstance().buildRsqlSpecification(rsql, fieldsClass())));
}
+ protected void checkUpdate(final U update, final T distributionSet) {}
+
// return which are for soft deletion
@SuppressWarnings("java:S1172") // java:S1172 - it is intended to be used by subclasses
protected Collection softDelete(final Collection toDelete) {
return Collections.emptyList();
}
+ protected T getValid(final Long id) {
+ final T jpaEntity = jpaRepository.getById(id);
+ if (Boolean.FALSE.equals(isValid.apply(jpaEntity))) {
+ throw new InvalidDistributionSetException(jpaRepository.getManagementClass().getSimpleName() + " " + id + " is invalid");
+ }
+ return jpaEntity;
+ }
+
protected void delete0(final Collection ids) {
if (ObjectUtils.isEmpty(ids)) {
return;
}
- final List toDelete = findAllById(ids); // throws EntityNotFoundException if any of these does not exist
+ final List toDelete = findAllById(ids, true); // throws EntityNotFoundException if any of these does not exist
jpaRepository.getAccessController().ifPresent(ac -> {
for (final T entity : toDelete) {
ac.assertOperationAllowed(AccessController.Operation.DELETE, entity);
@@ -240,9 +318,9 @@ abstract class AbstractJpaRepositoryManagement findAllById(final Collection ids) {
+ private List findAllById(final Collection ids, final boolean throwIfNotFound) {
final List foundDs = jpaRepository.findAllById(ids);
- if (foundDs.size() != ids.size()) {
+ if (throwIfNotFound && foundDs.size() != ids.size()) {
throw new EntityNotFoundException(managementClass(), ids, foundDs.stream().map(T::getId).toList());
}
return foundDs;
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/AbstractJpaRepositoryWithMetadataManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/AbstractJpaRepositoryWithMetadataManagement.java
index 97ac16f18..752b84364 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/AbstractJpaRepositoryWithMetadataManagement.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/AbstractJpaRepositoryWithMetadataManagement.java
@@ -121,14 +121,8 @@ abstract class AbstractJpaRepositoryWithMetadataManagement getMetadata(final Long id) {
- return jpaRepository
- .findById(id)
- .map(T::getMetadata)
- .map(metadata -> metadata.entrySet().stream()
- .collect(Collectors.toMap(
- Map.Entry::getKey,
- e -> (MV) e.getValue())))
- .orElseThrow(() -> new EntityNotFoundException(jpaRepository.getManagementClass(), id));
+ final T entity = jpaRepository.getById(id);
+ return entity.getMetadata().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}
@Override
@@ -146,16 +140,6 @@ abstract class AbstractJpaRepositoryWithMetadataManagement new EntityNotFoundException(jpaRepository.getManagementClass(), id));
- if (!jpaEntity.isValid()) {
- throw new InvalidDistributionSetException(jpaRepository.getManagementClass().getSimpleName() + " " + id + " is invalid");
- }
- return jpaEntity;
- }
-
@SuppressWarnings("unchecked")
private boolean setMetadataValue(final String key, final MV newValue, final MVI existingValue, final Map metadataValueMap) {
if (useCopy) {
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaActionManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaActionManagement.java
index e04be2053..ff35ef061 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaActionManagement.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaActionManagement.java
@@ -21,7 +21,6 @@ import java.util.stream.Stream;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.hawkbit.repository.QuotaManagement;
import org.eclipse.hawkbit.repository.RepositoryProperties;
-import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.jpa.model.AbstractJpaBaseEntity_;
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus;
@@ -80,7 +79,7 @@ public class JpaActionManagement {
protected Action addActionStatus(final ActionStatusCreate create) {
final Long actionId = create.getActionId();
- final JpaAction action = getActionAndThrowExceptionIfNotFound(actionId);
+ final JpaAction action = actionRepository.getById(actionId);
if (isUpdatingActionStatusAllowed(action, create)) {
return handleAddUpdateActionStatus(create, action);
@@ -92,10 +91,6 @@ public class JpaActionManagement {
return action;
}
- protected JpaAction getActionAndThrowExceptionIfNotFound(final Long actionId) {
- return actionRepository.findById(actionId).orElseThrow(() -> new EntityNotFoundException(Action.class, actionId));
- }
-
protected void onActionStatusUpdate(final JpaActionStatus newActionStatus, final JpaAction action) {
// can be overwritten to intercept the persistence of the action status
}
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaArtifactManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaArtifactManagement.java
index 24e72ea09..32a09c705 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaArtifactManagement.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaArtifactManagement.java
@@ -13,24 +13,22 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.Optional;
-import jakarta.annotation.Nullable;
import jakarta.persistence.EntityManager;
import lombok.extern.slf4j.Slf4j;
+import org.eclipse.hawkbit.repository.ArtifactManagement;
+import org.eclipse.hawkbit.repository.QuotaManagement;
import org.eclipse.hawkbit.repository.artifact.ArtifactRepository;
+import org.eclipse.hawkbit.repository.artifact.encryption.ArtifactEncryptionService;
+import org.eclipse.hawkbit.repository.artifact.exception.ArtifactBinaryNotFoundException;
+import org.eclipse.hawkbit.repository.artifact.exception.ArtifactDeleteFailedException;
import org.eclipse.hawkbit.repository.artifact.exception.ArtifactStoreException;
+import org.eclipse.hawkbit.repository.artifact.exception.ArtifactUploadFailedException;
import org.eclipse.hawkbit.repository.artifact.exception.HashNotMatchException;
import org.eclipse.hawkbit.repository.artifact.model.AbstractDbArtifact;
import org.eclipse.hawkbit.repository.artifact.model.DbArtifact;
import org.eclipse.hawkbit.repository.artifact.model.DbArtifactHash;
-import org.eclipse.hawkbit.repository.artifact.encryption.ArtifactEncryptionService;
-import org.eclipse.hawkbit.repository.ArtifactManagement;
-import org.eclipse.hawkbit.repository.QuotaManagement;
-import org.eclipse.hawkbit.repository.exception.ArtifactDeleteFailedException;
-import org.eclipse.hawkbit.repository.exception.ArtifactUploadFailedException;
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
-import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
-import org.eclipse.hawkbit.repository.exception.InsufficientPermissionException;
import org.eclipse.hawkbit.repository.exception.InvalidMD5HashException;
import org.eclipse.hawkbit.repository.exception.InvalidSHA1HashException;
import org.eclipse.hawkbit.repository.exception.InvalidSHA256HashException;
@@ -53,8 +51,6 @@ import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.tenancy.TenantAware;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBooleanProperty;
import org.springframework.dao.ConcurrencyFailureException;
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.Pageable;
import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;
@@ -72,49 +68,49 @@ import org.springframework.validation.annotation.Validated;
@ConditionalOnBooleanProperty(prefix = "hawkbit.jpa", name = { "enabled", "artifact-management" }, matchIfMissing = true)
public class JpaArtifactManagement implements ArtifactManagement {
+ private final LocalArtifactRepository localArtifactRepository;
+ private final ArtifactRepository artifactRepository;
+ private final SoftwareModuleRepository softwareModuleRepository;
private final EntityManager entityManager;
private final PlatformTransactionManager txManager;
- private final LocalArtifactRepository localArtifactRepository;
- private final SoftwareModuleRepository softwareModuleRepository;
- @Nullable
- private final ArtifactRepository artifactRepository;
private final TenantAware tenantAware;
private final QuotaManagement quotaManagement;
protected JpaArtifactManagement(
+ final LocalArtifactRepository localArtifactRepository,
+ final Optional artifactRepository,
+ final SoftwareModuleRepository softwareModuleRepository,
final EntityManager entityManager,
final PlatformTransactionManager txManager,
- final LocalArtifactRepository localArtifactRepository,
- final SoftwareModuleRepository softwareModuleRepository, @Nullable final ArtifactRepository artifactRepository,
final QuotaManagement quotaManagement,
final TenantAware tenantAware) {
+ this.localArtifactRepository = localArtifactRepository;
+ this.artifactRepository = artifactRepository.orElse(null);
+ this.softwareModuleRepository = softwareModuleRepository;
this.entityManager = entityManager;
this.txManager = txManager;
- this.localArtifactRepository = localArtifactRepository;
- this.softwareModuleRepository = softwareModuleRepository;
- this.artifactRepository = artifactRepository;
this.quotaManagement = quotaManagement;
this.tenantAware = tenantAware;
}
- @Override
- public long count() {
- return localArtifactRepository.count();
- }
-
@Override
@Transactional
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Artifact create(final ArtifactUpload artifactUpload) {
- assertArtifactRepositoryAvailable();
+ if (artifactRepository == null) {
+ throw new UnsupportedOperationException();
+ }
final long moduleId = artifactUpload.getModuleId();
- assertArtifactQuota(moduleId, 1);
- final JpaSoftwareModule softwareModule =
- softwareModuleRepository
- .findById(moduleId)
- .orElseThrow(() -> new EntityNotFoundException(SoftwareModule.class, moduleId));
+ QuotaHelper.assertAssignmentQuota(
+ moduleId, 1, quotaManagement.getMaxArtifactsPerSoftwareModule(),
+ Artifact.class, SoftwareModule.class,
+ // get all artifacts without user context
+ softwareModuleId -> localArtifactRepository
+ .count(null, ArtifactSpecifications.bySoftwareModuleId(softwareModuleId)));
+
+ final JpaSoftwareModule softwareModule = softwareModuleRepository.getById(moduleId);
final String filename = artifactUpload.getFilename();
final Artifact existing = softwareModule.getArtifactByFilename(filename).orElse(null);
@@ -139,12 +135,34 @@ public class JpaArtifactManagement implements ArtifactManagement {
}
}
+ @SuppressWarnings("java:S2201") // java:S2201 - the idea is to just check if the artifact exists
+ @Override
+ public DbArtifact loadArtifactBinary(final String sha1Hash, final long softwareModuleId, final boolean isEncrypted) {
+ if (artifactRepository == null) {
+ throw new UnsupportedOperationException();
+ }
+
+ final String tenant = tenantAware.getCurrentTenant();
+ // check access to the software module and if artifact belongs to it
+ for (final Artifact artifact : softwareModuleRepository.getById(softwareModuleId).getArtifacts()) {
+ if (artifact.getSha1Hash().equals(sha1Hash)) {
+ final DbArtifact dbArtifact = artifactRepository.getBySha1(tenant, sha1Hash);
+ return isEncrypted ? wrapInEncryptionAwareDbArtifact(softwareModuleId, dbArtifact) : dbArtifact;
+ }
+ }
+ throw new ArtifactBinaryNotFoundException(sha1Hash);
+ }
+
@Override
@Transactional
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void delete(final long id) {
- final JpaArtifact toDelete = (JpaArtifact) get(id).orElseThrow(() -> new EntityNotFoundException(Artifact.class, id));
+ if (artifactRepository == null) {
+ throw new UnsupportedOperationException();
+ }
+
+ final JpaArtifact toDelete = localArtifactRepository.getById(id);
final JpaSoftwareModule softwareModule = toDelete.getSoftwareModule();
// clearArtifactBinary checks (unconditionally) software module UPDATE access
@@ -159,66 +177,6 @@ public class JpaArtifactManagement implements ArtifactManagement {
AfterTransactionCommitExecutorHolder.getInstance().getAfterCommit().afterCommit(() -> clearArtifactBinary(sha1Hash));
}
- @Override
- public Optional get(final long id) {
- return localArtifactRepository.findById(id).map(Artifact.class::cast);
- }
-
- @Override
- public Optional getByFilenameAndSoftwareModule(final String filename, final long softwareModuleId) {
- assertSoftwareModuleExists(softwareModuleId);
-
- return localArtifactRepository.findFirstByFilenameAndSoftwareModuleId(filename, softwareModuleId);
- }
-
- @Override
- public Optional findFirstBySHA1(final String sha1Hash) {
- return localArtifactRepository.findFirstBySha1Hash(sha1Hash);
- }
-
- @Override
- public Optional getByFilename(final String filename) {
- return localArtifactRepository.findFirstByFilename(filename);
- }
-
- @Override
- public Page findBySoftwareModule(final long softwareModuleId, final Pageable pageable) {
- assertSoftwareModuleExists(softwareModuleId);
-
- return localArtifactRepository
- .findAll(ArtifactSpecifications.bySoftwareModuleId(softwareModuleId), pageable)
- .map(Artifact.class::cast);
- }
-
- @Override
- public long countBySoftwareModule(final long softwareModuleId) {
- assertSoftwareModuleExists(softwareModuleId);
-
- return localArtifactRepository.count(ArtifactSpecifications.bySoftwareModuleId(softwareModuleId));
- }
-
- @SuppressWarnings("java:S2201") // java:S2201 - the idea is to just check if the artifact exists
- @Override
- public Optional loadArtifactBinary(final String sha1Hash, final long softwareModuleId, final boolean isEncrypted) {
- assertArtifactRepositoryAvailable();
-
- assertSoftwareModuleExists(softwareModuleId);
-
- final String tenant = tenantAware.getCurrentTenant();
- if (artifactRepository.existsByTenantAndSha1(tenant, sha1Hash)) {
- // assert artifact exists and belongs to the software module
- findFirstBySHA1(sha1Hash)
- // if not found no assertOperationAllowed shall fail
- .orElseThrow(InsufficientPermissionException::new);
-
- final DbArtifact dbArtifact = artifactRepository.getArtifactBySha1(tenant, sha1Hash);
- return Optional.ofNullable(
- isEncrypted ? wrapInEncryptionAwareDbArtifact(softwareModuleId, dbArtifact) : dbArtifact);
- }
-
- return Optional.empty();
- }
-
/**
* Garbage collects artifact binaries if only referenced by given {@link SoftwareModule#getId()} or {@link SoftwareModule}'s that are
* marked as deleted.
@@ -231,11 +189,10 @@ public class JpaArtifactManagement implements ArtifactManagement {
* @param sha1Hash no longer needed
*/
void clearArtifactBinary(final String sha1Hash) {
- assertArtifactRepositoryAvailable();
-
DeploymentHelper.runInNewTransaction(txManager, "clearArtifactBinary", status -> {
// countBySha1HashAndTenantAndSoftwareModuleDeletedIsFalse will skip ACM checks and will return total count as it should be
- if (localArtifactRepository.countBySha1HashAndTenantAndSoftwareModuleDeletedIsFalse(sha1Hash, tenantAware.getCurrentTenant()) <= 0) { // 1 artifact is the one being deleted!
+ if (localArtifactRepository.countBySha1HashAndTenantAndSoftwareModuleDeletedIsFalse(sha1Hash,
+ tenantAware.getCurrentTenant()) <= 0) { // 1 artifact is the one being deleted!
// removes the real artifact ONLY AFTER the delete of artifact or software module
// in local history has passed successfully (caller has permission and no errors)
AfterTransactionCommitExecutorHolder.getInstance().getAfterCommit().afterCommit(() -> {
@@ -252,19 +209,17 @@ public class JpaArtifactManagement implements ArtifactManagement {
}
private AbstractDbArtifact storeArtifact(final ArtifactUpload artifactUpload, final boolean isSmEncrypted) {
- final String tenant = tenantAware.getCurrentTenant();
- final long smId = artifactUpload.getModuleId();
final InputStream stream = artifactUpload.getInputStream();
- final String fileName = artifactUpload.getFilename();
- final String contentType = artifactUpload.getContentType();
- final String providedSha1 = artifactUpload.getProvidedSha1Sum();
- final String providedMd5 = artifactUpload.getProvidedMd5Sum();
- final String providedSha256 = artifactUpload.getProvidedSha256Sum();
-
try (final InputStream wrappedStream = wrapInQuotaStream(
- isSmEncrypted ? wrapInEncryptionStream(smId, stream) : stream)) {
- return artifactRepository.store(tenant, wrappedStream, fileName, contentType,
- new DbArtifactHash(providedSha1, providedMd5, providedSha256));
+ isSmEncrypted
+ ? wrapInEncryptionStream(artifactUpload.getModuleId(), stream)
+ : stream)) {
+ return artifactRepository.store(
+ tenantAware.getCurrentTenant(), wrappedStream, artifactUpload.getFilename(), artifactUpload.getContentType(),
+ new DbArtifactHash(
+ artifactUpload.getProvidedSha1Sum(),
+ artifactUpload.getProvidedMd5Sum(),
+ artifactUpload.getProvidedSha256Sum()));
} catch (final ArtifactStoreException | IOException e) {
throw new ArtifactUploadFailedException(e);
} catch (final HashNotMatchException e) {
@@ -282,15 +237,6 @@ public class JpaArtifactManagement implements ArtifactManagement {
return ArtifactEncryptionService.getInstance().encryptArtifact(smId, stream);
}
- private void assertArtifactQuota(final long moduleId, final int requested) {
- QuotaHelper.assertAssignmentQuota(
- moduleId, requested, quotaManagement.getMaxArtifactsPerSoftwareModule(),
- Artifact.class, SoftwareModule.class,
- // get all artifacts without user context
- softwareModuleId -> localArtifactRepository
- .count(null, ArtifactSpecifications.bySoftwareModuleId(softwareModuleId)));
- }
-
private InputStream wrapInQuotaStream(final InputStream in) {
final long maxArtifactSize = quotaManagement.getMaxArtifactSize();
@@ -311,8 +257,9 @@ public class JpaArtifactManagement implements ArtifactManagement {
encryptionService.encryptionSizeOverhead());
}
- private Artifact storeArtifactMetadata(final SoftwareModule softwareModule, final String providedFilename,
- final AbstractDbArtifact result, final Artifact existing) {
+ private Artifact storeArtifactMetadata(
+ final SoftwareModule softwareModule, final String providedFilename, final AbstractDbArtifact result,
+ final Artifact existing) {
final JpaArtifact artifact;
if (existing == null) {
artifact = new JpaArtifact(result.getHashes().getSha1(), providedFilename, softwareModule);
@@ -327,16 +274,4 @@ public class JpaArtifactManagement implements ArtifactManagement {
log.debug("storing new artifact into repository {}", artifact);
return localArtifactRepository.save(AccessController.Operation.CREATE, artifact);
}
-
- private void assertSoftwareModuleExists(final long softwareModuleId) {
- if (!softwareModuleRepository.existsById(softwareModuleId)) {
- throw new EntityNotFoundException(SoftwareModule.class, softwareModuleId);
- }
- }
-
- private void assertArtifactRepositoryAvailable() {
- if (artifactRepository == null) {
- throw new UnsupportedOperationException("ArtifactRepository is unavailable");
- }
- }
}
\ No newline at end of file
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaConfirmationManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaConfirmationManagement.java
index 3141774a0..8c6ce33ab 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaConfirmationManagement.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaConfirmationManagement.java
@@ -108,7 +108,7 @@ public class JpaConfirmationManagement extends JpaActionManagement implements Co
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Action confirmAction(final long actionId, final Integer code, final Collection deviceMessages) {
log.trace("Action with id {} confirm request is triggered.", actionId);
- final Action action = getActionAndThrowExceptionIfNotFound(actionId);
+ final Action action = actionRepository.getById(actionId);
assertActionCanAcceptFeedback(action);
final List messages = new ArrayList<>();
if (deviceMessages != null) {
@@ -124,7 +124,7 @@ public class JpaConfirmationManagement extends JpaActionManagement implements Co
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Action denyAction(final long actionId, final Integer code, final Collection deviceMessages) {
log.trace("Action with id {} deny request is triggered.", actionId);
- final Action action = getActionAndThrowExceptionIfNotFound(actionId);
+ final Action action = actionRepository.getById(actionId);
assertActionCanAcceptFeedback(action);
final List messages = new ArrayList<>();
if (deviceMessages != null) {
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaControllerManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaControllerManagement.java
index 38e8c06f8..713044d97 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaControllerManagement.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaControllerManagement.java
@@ -223,7 +223,7 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont
}
case DOWNLOADED: {
handleDownloadedActionStatus(action).ifPresent(controllerId ->
- requestControllerAttributes(getByControllerId(controllerId)
+ requestControllerAttributes(findByControllerId(controllerId)
.map(JpaTarget.class::cast)
.orElseThrow(() -> new EntityNotFoundException(Target.class, controllerId))));
break;
@@ -239,7 +239,7 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Action addCancelActionStatus(final ActionStatusCreate create) {
- final JpaAction action = getActionAndThrowExceptionIfNotFound(create.getActionId());
+ final JpaAction action = actionRepository.getById(create.getActionId());
if (!action.isCancelingOrCanceled()) {
throw new CancelActionNotAllowedException("The action is not in canceling state.");
}
@@ -284,7 +284,7 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public ActionStatus addInformationalActionStatus(final ActionStatusCreate create) {
- final JpaAction action = getActionAndThrowExceptionIfNotFound(create.getActionId());
+ final JpaAction action = actionRepository.getById(create.getActionId());
assertActionStatusQuota(create, action);
final JpaActionStatus actionStatus = buildJpaActionStatus(create);
@@ -476,13 +476,13 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont
}
@Override
- public Optional getByControllerId(final String controllerId) {
- return targetRepository.findByControllerId(controllerId).map(Target.class::cast);
+ public Optional find(final long targetId) {
+ return targetRepository.findById(targetId).map(Target.class::cast);
}
@Override
- public Optional get(final long targetId) {
- return targetRepository.findById(targetId).map(Target.class::cast);
+ public Optional findByControllerId(final String controllerId) {
+ return targetRepository.findByControllerId(controllerId).map(Target.class::cast);
}
@Override
@@ -538,10 +538,7 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont
targetRepository.getAccessController().ifPresent(
accessController -> accessController.assertOperationAllowed(
AccessController.Operation.UPDATE,
- actionRepository
- .findById(actionId)
- .orElseThrow(() -> new EntityNotFoundException(Action.class, actionId))
- .getTarget()));
+ actionRepository.getById(actionId).getTarget()));
actionRepository.updateExternalRef(actionId, externalRef);
}
@@ -579,13 +576,14 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont
public boolean updateOfflineAssignedVersion(@NotEmpty final String controllerId, final String distributionName, final String version) {
List distributionSetAssignmentResults =
systemSecurityContext.runAsSystem(() ->
- distributionSetManagement.findByNameAndVersion(distributionName, version).map(
- distributionSet -> deploymentManagement.offlineAssignedDistributionSets(
- controllerId, List.of(Map.entry(controllerId, distributionSet.getId()))))
+ distributionSetManagement.findByNameAndVersion(distributionName, version)
+ .map(distributionSet -> deploymentManagement.offlineAssignedDistributionSets(
+ controllerId, List.of(Map.entry(controllerId, distributionSet.getId()))))
.orElseThrow(() ->
new EntityNotFoundException(DistributionSet.class, Map.entry(distributionName, version))));
- return distributionSetAssignmentResults.stream().findFirst()
+ return distributionSetAssignmentResults.stream()
+ .findFirst()
.map(result -> result.getAlreadyAssigned() == 0)
.orElseThrow();
}
@@ -901,7 +899,7 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont
* {@link Status#RETRIEVED}
*/
private Action handleRegisterRetrieved(final Long actionId, final String message) {
- final JpaAction action = getActionAndThrowExceptionIfNotFound(actionId);
+ final JpaAction action = actionRepository.getById(actionId);
// do a manual query with CriteriaBuilder to avoid unnecessary field queries and an extra
// count query made by spring-data when using pageable requests, we don't need an extra count
// query, we just want to check if the last action status is a retrieved or not.
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaDeploymentManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaDeploymentManagement.java
index 6a23e18c7..deb943197 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaDeploymentManagement.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaDeploymentManagement.java
@@ -222,7 +222,7 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
private Action cancelAction0(final long actionId) {
log.debug("cancelAction({})", actionId);
- final JpaAction action = actionRepository.findById(actionId).orElseThrow(() -> new EntityNotFoundException(Action.class, actionId));
+ final JpaAction action = actionRepository.getById(actionId);
if (action.isCancelingOrCanceled()) {
throw new CancelActionNotAllowedException("Actions in canceling or canceled state cannot be canceled");
@@ -378,7 +378,7 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
}
private Action forceQuitAction0(final long actionId) {
- final JpaAction action = actionRepository.findById(actionId).orElseThrow(() -> new EntityNotFoundException(Action.class, actionId));
+ final JpaAction action = actionRepository.getById(actionId);
if (!action.isCancelingOrCanceled()) {
throw new ForceQuitActionNotAllowedException(action.getId() + " is not canceled yet and cannot be force quit");
@@ -406,7 +406,8 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
@Retryable(retryFor = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Action forceTargetAction(final long actionId) {
- final JpaAction action = actionRepository.findById(actionId).map(this::assertTargetUpdateAllowed)
+ final JpaAction action = actionRepository.findById(actionId)
+ .map(this::assertTargetUpdateAllowed)
.orElseThrow(() -> new EntityNotFoundException(Action.class, actionId));
if (!action.isForcedOrTimeForced()) {
@@ -997,9 +998,4 @@ public class JpaDeploymentManagement extends JpaActionManagement implements Depl
throw new EntityNotFoundException(Action.class, actionId);
}
}
-
- private Page findActiveActionsForRollout(long rolloutId, Pageable pageable) {
- return actionRepository
- .findAll(ActionSpecifications.byRolloutIdAndActive(rolloutId), pageable);
- }
}
\ No newline at end of file
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaDistributionSetInvalidationManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaDistributionSetInvalidationManagement.java
index 45a95fa38..18cb80f1b 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaDistributionSetInvalidationManagement.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaDistributionSetInvalidationManagement.java
@@ -9,7 +9,6 @@
*/
package org.eclipse.hawkbit.repository.jpa.management;
-import java.util.Collection;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
@@ -22,13 +21,10 @@ import org.eclipse.hawkbit.repository.RolloutManagement;
import org.eclipse.hawkbit.repository.TargetFilterQueryManagement;
import org.eclipse.hawkbit.repository.exception.IncompleteDistributionSetException;
import org.eclipse.hawkbit.repository.exception.StopRolloutException;
-import org.eclipse.hawkbit.repository.jpa.repository.ActionRepository;
import org.eclipse.hawkbit.repository.jpa.utils.DeploymentHelper;
-import org.eclipse.hawkbit.repository.model.Action.Status;
import org.eclipse.hawkbit.repository.model.ActionCancellationType;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetInvalidation;
-import org.eclipse.hawkbit.repository.model.DistributionSetInvalidationCount;
import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
import org.eclipse.hawkbit.security.SystemSecurityContext;
import org.eclipse.hawkbit.tenancy.TenantAware;
@@ -115,7 +111,7 @@ public class JpaDistributionSetInvalidationManagement implements DistributionSet
}
private void invalidateDistributionSet(final long setId, final ActionCancellationType cancelationType) {
- final DistributionSet distributionSet = distributionSetManagement.getOrElseThrowException(setId);
+ final DistributionSet distributionSet = distributionSetManagement.get(setId);
if (!distributionSet.isComplete()) {
throw new IncompleteDistributionSetException(
"Distribution set of type " + distributionSet.getType().getKey() + " is incomplete: " + distributionSet.getId());
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaDistributionSetManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaDistributionSetManagement.java
index e37f60d56..b7b7813f0 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaDistributionSetManagement.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaDistributionSetManagement.java
@@ -105,28 +105,32 @@ public class JpaDistributionSetManagement
this.repositoryProperties = repositoryProperties;
}
- @SuppressWarnings("java:S1066") // java:S1066 better readable without merging the if statements
@Override
public JpaDistributionSet update(final Update update) {
- final JpaDistributionSet distributionSet = getValid0(update.getId());
-
- // lock/unlock ONLY if locked flag is present!
+ final JpaDistributionSet updated = super.update(update);
if (Boolean.TRUE.equals(update.getLocked())) {
- if (!distributionSet.isLocked()) {
- lockSoftwareModules(distributionSet);
- distributionSet.setLocked(true);
- }
- } else if (Boolean.FALSE.equals(update.getLocked())) {
- if (distributionSet.isLocked()) {
- distributionSet.setLocked(false);
+ lockSoftwareModules(updated);
+ }
+ return updated;
+ }
+
+ @Override
+ public Map update(final Collection updates) {
+ final Map updated = super.update(updates);
+ for (final Update update : updates) {
+ final JpaDistributionSet updatedSet = updated.get(update.getId());
+ if (Boolean.TRUE.equals(update.getLocked())) {
+ lockSoftwareModules(updatedSet);
}
}
+ return updated;
+ }
+ @Override
+ protected void checkUpdate(final Update update, final JpaDistributionSet distributionSet) {
if (update.getRequiredMigrationStep() != null && !update.getRequiredMigrationStep().equals(distributionSet.isRequiredMigrationStep())) {
assertDistributionSetIsNotAssignedToTargets(update.getId());
}
-
- return super.update(update, distributionSet);
}
@Override
@@ -154,11 +158,6 @@ public class JpaDistributionSetManagement
return jpaRepository.findOne(jpaRepository.byIdSpec(id), JpaDistributionSet_.GRAPH_DISTRIBUTION_SET_DETAIL);
}
- @Override
- public JpaDistributionSet getOrElseThrowException(final long id) {
- return getById(id);
- }
-
// implicitly lock a distribution set if not already locked and implicit lock is enabled and not to skip
@Override
@Transactional
@@ -256,7 +255,7 @@ public class JpaDistributionSetManagement
final JpaDistributionSet set = getValid0(id);
assertDistributionSetIsNotAssignedToTargets(id);
- final JpaSoftwareModule module = findSoftwareModuleAndThrowExceptionIfNotFound(moduleId);
+ final JpaSoftwareModule module = softwareModuleRepository.getById(moduleId);
set.removeModule(module);
return jpaRepository.save(set);
@@ -364,7 +363,7 @@ public class JpaDistributionSetManagement
}
private JpaDistributionSet getValid0(final long id) {
- final JpaDistributionSet distributionSet = getById(id);
+ final JpaDistributionSet distributionSet = jpaRepository.getById(id);
if (!distributionSet.isValid()) {
throw new InvalidDistributionSetException(
"Distribution set of type " + distributionSet.getType().getKey() + " is invalid: " + distributionSet.getId());
@@ -375,8 +374,7 @@ public class JpaDistributionSetManagement
private List updateTag(
final Collection dsIds, final long dsTagId,
final BiFunction updater) {
- final DistributionSetTag tag = distributionSetTagManagement.get(dsTagId)
- .orElseThrow(() -> new EntityNotFoundException(DistributionSetTag.class, dsTagId));
+ final DistributionSetTag tag = distributionSetTagManagement.get(dsTagId);
final List allDs = dsIds.size() == 1 ?
jpaRepository.findById(dsIds.iterator().next())
.map(List::of)
@@ -395,11 +393,6 @@ public class JpaDistributionSetManagement
}
}
- private JpaSoftwareModule findSoftwareModuleAndThrowExceptionIfNotFound(final Long softwareModuleId) {
- return softwareModuleRepository.findById(softwareModuleId)
- .orElseThrow(() -> new EntityNotFoundException(SoftwareModule.class, softwareModuleId));
- }
-
private void assertSoftwareModuleQuota(final Long id, final int requested) {
QuotaHelper.assertAssignmentQuota(id, requested, quotaManagement.getMaxSoftwareModulesPerDistributionSet(),
SoftwareModule.class, DistributionSet.class, softwareModuleRepository::countByAssignedToId);
@@ -422,17 +415,11 @@ public class JpaDistributionSetManagement
});
}
- private JpaDistributionSet getById(final long id) {
- return jpaRepository
- .findById(id)
- .orElseThrow(() -> new EntityNotFoundException(DistributionSet.class, id));
- }
-
private JpaDistributionSet toJpaDistributionSet(final DistributionSet distributionSet) {
if (distributionSet instanceof JpaDistributionSet jpaDistributionSet) {
return jpaDistributionSet;
} else {
- return getById(distributionSet.getId());
+ return jpaRepository.getById(distributionSet.getId());
}
}
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaDistributionSetTypeManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaDistributionSetTypeManagement.java
index 890ce43ef..338eab2b3 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaDistributionSetTypeManagement.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaDistributionSetTypeManagement.java
@@ -71,8 +71,7 @@ public class JpaDistributionSetTypeManagement
@Transactional
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = TX_RT_MAX, backoff = @Backoff(delay = TX_RT_DELAY))
public void delete(final long id) {
- final JpaDistributionSetType toDelete = jpaRepository.findById(id)
- .orElseThrow(() -> new EntityNotFoundException(DistributionSetType.class, id));
+ final JpaDistributionSetType toDelete = jpaRepository.getById(id);
unassignDsTypeFromTargetTypes(id);
@@ -118,7 +117,7 @@ public class JpaDistributionSetTypeManagement
@Transactional
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = TX_RT_MAX, backoff = @Backoff(delay = TX_RT_DELAY))
public JpaDistributionSetType unassignSoftwareModuleType(final long id, final long softwareModuleTypeId) {
- final JpaDistributionSetType type = findDistributionSetTypeAndThrowExceptionIfNotFound(id);
+ final JpaDistributionSetType type = jpaRepository.getById(id);
checkDistributionSetTypeNotAssigned(id);
type.removeModuleType(softwareModuleTypeRepository.getById(softwareModuleTypeId));
return jpaRepository.save(type);
@@ -132,7 +131,7 @@ public class JpaDistributionSetTypeManagement
SoftwareModuleType.class, softwareModulesTypeIds, foundModules.stream().map(SoftwareModuleType::getId).toList());
}
- final JpaDistributionSetType type = findDistributionSetTypeAndThrowExceptionIfNotFound(dsTypeId);
+ final JpaDistributionSetType type = jpaRepository.getById(dsTypeId);
checkDistributionSetTypeNotAssigned(dsTypeId);
assertSoftwareModuleTypeQuota(dsTypeId, softwareModulesTypeIds.size());
@@ -164,10 +163,6 @@ public class JpaDistributionSetTypeManagement
});
}
- private JpaDistributionSetType findDistributionSetTypeAndThrowExceptionIfNotFound(final Long id) {
- return jpaRepository.findById(id).orElseThrow(() -> new EntityNotFoundException(DistributionSetType.class, id));
- }
-
private void checkDistributionSetTypeNotAssigned(final Long id) {
if (distributionSetRepository.countByTypeId(id) > 0) {
throw new EntityReadOnlyException(String.format(
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaRolloutGroupManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaRolloutGroupManagement.java
index 8a0d2a05e..b0d945b9c 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaRolloutGroupManagement.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaRolloutGroupManagement.java
@@ -162,8 +162,7 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
@Override
public Page findTargetsOfRolloutGroup(final long rolloutGroupId, final Pageable page) {
- final JpaRolloutGroup rolloutGroup = rolloutGroupRepository.findById(rolloutGroupId)
- .orElseThrow(() -> new EntityNotFoundException(RolloutGroup.class, rolloutGroupId));
+ final JpaRolloutGroup rolloutGroup = rolloutGroupRepository.getById(rolloutGroupId);
if (isRolloutStatusReady(rolloutGroup)) {
// in case of status ready the action has not been created yet and
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaRolloutManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaRolloutManagement.java
index 7feef08af..f45a48955 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaRolloutManagement.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaRolloutManagement.java
@@ -305,7 +305,7 @@ public class JpaRolloutManagement implements RolloutManagement {
}
@Override
- public Optional get(final long rolloutId) {
+ public Optional find(final long rolloutId) {
return rolloutRepository.findById(rolloutId).map(Rollout.class::cast);
}
@@ -316,7 +316,7 @@ public class JpaRolloutManagement implements RolloutManagement {
@Override
public Optional getWithDetailedStatus(final long rolloutId) {
- final Optional rollout = get(rolloutId);
+ final Optional rollout = find(rolloutId);
if (rollout.isEmpty()) {
return rollout;
}
@@ -344,7 +344,7 @@ public class JpaRolloutManagement implements RolloutManagement {
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void pauseRollout(final long rolloutId) {
- final JpaRollout rollout = getRolloutOrThrowExceptionIfNotFound(rolloutId);
+ final JpaRollout rollout = rolloutRepository.getById(rolloutId);
if (RolloutStatus.RUNNING != rollout.getStatus()) {
throw new RolloutIllegalStateException("Rollout can only be paused in state running but current state is " +
rollout.getStatus().name().toLowerCase());
@@ -361,7 +361,7 @@ public class JpaRolloutManagement implements RolloutManagement {
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void resumeRollout(final long rolloutId) {
- final JpaRollout rollout = getRolloutOrThrowExceptionIfNotFound(rolloutId);
+ final JpaRollout rollout = rolloutRepository.getById(rolloutId);
if (RolloutStatus.PAUSED != rollout.getStatus()) {
throw new RolloutIllegalStateException("Rollout can only be resumed in state paused but current state is " +
rollout.getStatus().name().toLowerCase());
@@ -388,7 +388,7 @@ public class JpaRolloutManagement implements RolloutManagement {
private Rollout approveOrDeny0(final long rolloutId, final Rollout.ApprovalDecision decision, final String remark) {
log.debug("approveOrDeny rollout called for rollout {} with decision {}", rolloutId, decision);
- final JpaRollout rollout = getRolloutOrThrowExceptionIfNotFound(rolloutId);
+ final JpaRollout rollout = rolloutRepository.getById(rolloutId);
RolloutHelper.verifyRolloutInStatus(rollout, RolloutStatus.WAITING_FOR_APPROVAL);
switch (decision) {
case APPROVED: {
@@ -417,7 +417,7 @@ public class JpaRolloutManagement implements RolloutManagement {
public Rollout start(final long rolloutId) {
log.debug("startRollout called for rollout {}", rolloutId);
- final JpaRollout rollout = getRolloutOrThrowExceptionIfNotFound(rolloutId);
+ final JpaRollout rollout = rolloutRepository.getById(rolloutId);
RolloutHelper.checkIfRolloutCanStarted(rollout, rollout);
rollout.setStatus(RolloutStatus.STARTING);
rollout.setLastCheck(0);
@@ -429,7 +429,7 @@ public class JpaRolloutManagement implements RolloutManagement {
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Rollout update(final Update update) {
- final JpaRollout rollout = getRolloutOrThrowExceptionIfNotFound(update.getId());
+ final JpaRollout rollout = rolloutRepository.getById(update.getId());
checkIfDeleted(update.getId(), rollout.getStatus());
ObjectCopyUtil.copy(update, rollout, false, UnaryOperator.identity());
@@ -441,8 +441,7 @@ public class JpaRolloutManagement implements RolloutManagement {
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Rollout stop(long rolloutId) {
- final JpaRollout jpaRollout = rolloutRepository.findById(rolloutId)
- .orElseThrow(() -> new EntityNotFoundException(Rollout.class, rolloutId));
+ final JpaRollout jpaRollout = rolloutRepository.getById(rolloutId);
if (!ROLLOUT_STATUS_STOPPABLE.contains(jpaRollout.getStatus())) {
log.debug("Failed to stop rollout {} because it is in {} status.", rolloutId, jpaRollout.getStatus());
@@ -459,9 +458,7 @@ public class JpaRolloutManagement implements RolloutManagement {
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void delete(final long rolloutId) {
- final JpaRollout jpaRollout = rolloutRepository.findById(rolloutId)
- .orElseThrow(() -> new EntityNotFoundException(Rollout.class, rolloutId));
- this.delete0(jpaRollout);
+ this.delete0(rolloutRepository.getById(rolloutId));
}
@Override
@@ -490,7 +487,7 @@ public class JpaRolloutManagement implements RolloutManagement {
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void triggerNextGroup(final long rolloutId) {
- final JpaRollout rollout = getRolloutOrThrowExceptionIfNotFound(rolloutId);
+ final JpaRollout rollout = rolloutRepository.getById(rolloutId);
if (RolloutStatus.RUNNING != rollout.getStatus()) {
throw new RolloutIllegalStateException("Rollout is not in running state");
}
@@ -891,11 +888,6 @@ public class JpaRolloutManagement implements RolloutManagement {
group.setErrorActionExp(errorActionExp);
}
- private JpaRollout getRolloutOrThrowExceptionIfNotFound(final Long rolloutId) {
- return rolloutRepository.findById(rolloutId)
- .orElseThrow(() -> new EntityNotFoundException(Rollout.class, rolloutId));
- }
-
private @NotNull Map> getStatusCountItemForRollout(final List rollouts) {
if (rollouts.isEmpty()) {
return Collections.emptyMap();
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaSoftwareModuleManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaSoftwareModuleManagement.java
index 8b1846ae4..57a68ccc1 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaSoftwareModuleManagement.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaSoftwareModuleManagement.java
@@ -101,21 +101,6 @@ public class JpaSoftwareModuleManagement
return createdModule;
}
- @Override
- public JpaSoftwareModule update(final Update update) {
- final JpaSoftwareModule module = jpaRepository.findById(update.getId())
- .orElseThrow(() -> new EntityNotFoundException(SoftwareModule.class, update.getId()));
-
- // lock/unlock ONLY if locked flag is present!
- if (Boolean.TRUE.equals(update.getLocked())) {
- module.lock();
- } else if (Boolean.FALSE.equals(update.getLocked())) {
- module.unlock();
- }
-
- return super.update(update, module);
- }
-
@Override
protected List softDelete(final Collection toDelete) {
return toDelete.stream()
@@ -213,16 +198,10 @@ public class JpaSoftwareModuleManagement
if (softwareModule instanceof JpaSoftwareModule jpaSoftwareModule) {
return jpaSoftwareModule;
} else {
- return getById(softwareModule.getId());
+ return jpaRepository.getById(softwareModule.getId());
}
}
- private JpaSoftwareModule getById(final long id) {
- return jpaRepository
- .findById(id)
- .orElseThrow(() -> new EntityNotFoundException(SoftwareModule.class, id));
- }
-
private void deleteGridFsArtifacts(final JpaSoftwareModule swModule) {
jpaRepository.getAccessController().ifPresent(accessController ->
accessController.assertOperationAllowed(AccessController.Operation.DELETE, swModule));
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaSystemManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaSystemManagement.java
index f3106ccdd..7ba07ac44 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaSystemManagement.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaSystemManagement.java
@@ -267,15 +267,13 @@ public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, Syst
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public TenantMetaData updateTenantMetadata(final long defaultDsType) {
final JpaTenantMetaData data = (JpaTenantMetaData) getTenantMetadataWithoutDetails();
- data.setDefaultDsType(distributionSetTypeRepository.findById(defaultDsType)
- .orElseThrow(() -> new EntityNotFoundException(DistributionSetType.class, defaultDsType)));
+ data.setDefaultDsType(distributionSetTypeRepository.getById(defaultDsType));
return tenantMetaDataRepository.save(data);
}
@Override
public TenantMetaData getTenantMetadata(final long tenantId) {
- return tenantMetaDataRepository.findById(tenantId)
- .orElseThrow(() -> new EntityNotFoundException(TenantMetaData.class, tenantId));
+ return tenantMetaDataRepository.findById(tenantId).orElseThrow(() -> new EntityNotFoundException(TenantMetaData.class, tenantId));
}
private static boolean isPostgreSql(final JpaProperties properties) {
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaTargetFilterQueryManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaTargetFilterQueryManagement.java
index 4a2ae9922..a8c9e8ef1 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaTargetFilterQueryManagement.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaTargetFilterQueryManagement.java
@@ -27,7 +27,6 @@ import org.eclipse.hawkbit.repository.TargetFilterQueryFields;
import org.eclipse.hawkbit.repository.TargetFilterQueryManagement;
import org.eclipse.hawkbit.repository.TargetManagement;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
-import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.exception.IncompleteDistributionSetException;
import org.eclipse.hawkbit.repository.exception.InvalidAutoAssignActionTypeException;
import org.eclipse.hawkbit.repository.exception.InvalidDistributionSetException;
@@ -132,7 +131,7 @@ class JpaTargetFilterQueryManagement
@Override
public Page findByAutoAssignDSAndRsql(final long setId, final String rsql, final Pageable pageable) {
- final DistributionSet distributionSet = distributionSetManagement.getOrElseThrowException(setId);
+ final DistributionSet distributionSet = distributionSetManagement.get(setId);
final List> specList = new ArrayList<>(2);
specList.add(TargetFilterQuerySpecification.byAutoAssignDS(distributionSet));
@@ -152,7 +151,7 @@ class JpaTargetFilterQueryManagement
@Override
@Transactional
public TargetFilterQuery updateAutoAssignDS(final AutoAssignDistributionSetUpdate update) {
- final JpaTargetFilterQuery targetFilterQuery = findTargetFilterQueryOrThrowExceptionIfNotFound(update.targetFilterId());
+ final JpaTargetFilterQuery targetFilterQuery = jpaRepository.getById(update.targetFilterId());
if (update.dsId() == null) {
targetFilterQuery.setAccessControlContext(null);
targetFilterQuery.setAutoAssignDistributionSet(null);
@@ -201,12 +200,7 @@ class JpaTargetFilterQueryManagement
}
private boolean isConfirmationFlowEnabled() {
- return TenantConfigHelper.usingContext(systemSecurityContext, tenantConfigurationManagement)
- .isConfirmationFlowEnabled();
- }
-
- private JpaTargetFilterQuery findTargetFilterQueryOrThrowExceptionIfNotFound(final Long queryId) {
- return jpaRepository.findById(queryId).orElseThrow(() -> new EntityNotFoundException(TargetFilterQuery.class, queryId));
+ return TenantConfigHelper.usingContext(systemSecurityContext, tenantConfigurationManagement).isConfirmationFlowEnabled();
}
private void assertMaxTargetsQuota(final String query, final String filterName, final long dsId) {
@@ -245,7 +239,7 @@ class JpaTargetFilterQueryManagement
}
private void validate(final Update update) {
- final JpaTargetFilterQuery targetFilterQuery = findTargetFilterQueryOrThrowExceptionIfNotFound(update.getId());
+ final JpaTargetFilterQuery targetFilterQuery = jpaRepository.getById(update.getId());
Optional.ofNullable(update.getQuery()).ifPresent(query -> {
// validate the RSQL query syntax
RsqlUtility.getInstance().validateRsqlFor(query, TargetFields.class, JpaTarget.class);
diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaTargetManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaTargetManagement.java
index d51ae5f33..5f323145b 100644
--- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaTargetManagement.java
+++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaTargetManagement.java
@@ -113,8 +113,7 @@ public class JpaTargetManagement
public boolean isTargetMatchingQueryAndDSNotAssignedAndCompatibleAndUpdatable(
final String controllerId, final long distributionSetId, final String targetFilterQuery) {
RsqlUtility.getInstance().validateRsqlFor(targetFilterQuery, TargetFields.class, JpaTarget.class);
- final DistributionSet ds = distributionSetManagement.get(distributionSetId)
- .orElseThrow(() -> new EntityNotFoundException(DistributionSet.class, distributionSetId));
+ final DistributionSet ds = distributionSetManagement.get(distributionSetId);
final Long distSetTypeId = ds.getType().getId();
final List> specList = List.of(
RsqlUtility.getInstance().buildRsqlSpecification(targetFilterQuery, TargetFields.class),
@@ -130,7 +129,7 @@ public class JpaTargetManagement
@Override
public Slice findByTargetFilterQueryAndNonDSAndCompatibleAndUpdatable(
final long distributionSetId, final String rsql, final Pageable pageable) {
- final DistributionSet jpaDistributionSet = distributionSetManagement.getOrElseThrowException(distributionSetId);
+ final DistributionSet jpaDistributionSet = distributionSetManagement.get(distributionSetId);
final Long distSetTypeId = jpaDistributionSet.getType().getId();
return jpaRepository
@@ -205,7 +204,7 @@ public class JpaTargetManagement
@Override
public Page findByAssignedDistributionSet(final long distributionSetId, final Pageable pageable) {
- final DistributionSet validDistSet = distributionSetManagement.getOrElseThrowException(distributionSetId);
+ final DistributionSet validDistSet = distributionSetManagement.get(distributionSetId);
return JpaManagementHelper.findAllWithCountBySpec(
jpaRepository,
@@ -214,7 +213,7 @@ public class JpaTargetManagement
@Override
public Page findByAssignedDistributionSetAndRsql(final long distributionSetId, final String rsql, final Pageable pageable) {
- final DistributionSet validDistSet = distributionSetManagement.getOrElseThrowException(distributionSetId);
+ final DistributionSet validDistSet = distributionSetManagement.get(distributionSetId);
final List> specList = List.of(
RsqlUtility.getInstance().buildRsqlSpecification(rsql, TargetFields.class),
@@ -225,7 +224,7 @@ public class JpaTargetManagement
@Override
public Page findByInstalledDistributionSet(final long distributionSetId, final Pageable pageReq) {
- final DistributionSet validDistSet = distributionSetManagement.getOrElseThrowException(distributionSetId);
+ final DistributionSet validDistSet = distributionSetManagement.get(distributionSetId);
return JpaManagementHelper.findAllWithCountBySpec(
jpaRepository, List.of(TargetSpecifications.hasInstalledDistributionSet(validDistSet.getId())), pageReq);
@@ -233,7 +232,7 @@ public class JpaTargetManagement
@Override
public Page findByInstalledDistributionSetAndRsql(final long distributionSetId, final String rsql, final Pageable pageable) {
- final DistributionSet validDistSet = distributionSetManagement.getOrElseThrowException(distributionSetId);
+ final DistributionSet validDistSet = distributionSetManagement.get(distributionSetId);
final List> specList = List.of(
RsqlUtility.getInstance().buildRsqlSpecification(rsql, TargetFields.class),
@@ -275,7 +274,7 @@ public class JpaTargetManagement
@Override
public long countByRsqlAndNonDsAndCompatibleAndUpdatable(final long distributionSetId, final String rsql) {
- final DistributionSet jpaDistributionSet = distributionSetManagement.getOrElseThrowException(distributionSetId);
+ final DistributionSet jpaDistributionSet = distributionSetManagement.get(distributionSetId);
final Long distSetTypeId = jpaDistributionSet.getType().getId();
return jpaRepository.count(
@@ -314,7 +313,7 @@ public class JpaTargetManagement
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void deleteByControllerId(final String controllerId) {
- jpaRepository.delete(getByControllerIdAndThrowIfNotFound(controllerId));
+ jpaRepository.delete(jpaRepository.getByControllerId(controllerId));
}
@Override
@@ -386,12 +385,12 @@ public class JpaTargetManagement
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Target assignType(final String controllerId, final Long targetTypeId) {
- final JpaTarget target = getByControllerIdAndThrowIfNotFound(controllerId);
+ final JpaTarget target = jpaRepository.getByControllerId(controllerId);
jpaRepository.getAccessController().ifPresent(acm ->
acm.assertOperationAllowed(AccessController.Operation.UPDATE, target));
- final JpaTargetType targetType = getTargetTypeByIdAndThrowIfNotFound(targetTypeId);
+ final JpaTargetType targetType = targetTypeRepository.getById(targetTypeId);
target.setTargetType(targetType);
return jpaRepository.save(target);
}
@@ -401,7 +400,7 @@ public class JpaTargetManagement
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Target unassignType(final String controllerId) {
- final JpaTarget target = getByControllerIdAndThrowIfNotFound(controllerId);
+ final JpaTarget target = jpaRepository.getByControllerId(controllerId);
target.setTargetType(null);
return jpaRepository.save(target);
}
@@ -460,7 +459,7 @@ public class JpaTargetManagement
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void createMetadata(final String controllerId, final String key, final String value) {
- final JpaTarget target = getByControllerIdAndThrowIfNotFound(controllerId);
+ final JpaTarget target = jpaRepository.getByControllerId(controllerId);
// get the modifiable metadata map
final Map metadata = target.getMetadata();
@@ -477,7 +476,7 @@ public class JpaTargetManagement
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void createMetadata(final String controllerId, final Map md) {
- final JpaTarget target = getByControllerIdAndThrowIfNotFound(controllerId);
+ final JpaTarget target = jpaRepository.getByControllerId(controllerId);
// get the modifiable metadata map
final Map metadata = target.getMetadata();
@@ -507,7 +506,7 @@ public class JpaTargetManagement
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public void deleteMetadata(final String controllerId, final String key) {
- final JpaTarget target = getByControllerIdAndThrowIfNotFound(controllerId);
+ final JpaTarget target = jpaRepository.getByControllerId(controllerId);
// get the modifiable metadata map
final Map metadata = target.getMetadata();
@@ -519,7 +518,7 @@ public class JpaTargetManagement
}
private Map getMap(final String controllerId, final MapAttribute mapAttribute) {
- getByControllerIdAndThrowIfNotFound(controllerId);
+ jpaRepository.getByControllerId(controllerId);
final CriteriaBuilder cb = entityManager.getCriteriaBuilder();
final CriteriaQuery