From 0332d3114645c5766e4b259fb35d3cc391977601 Mon Sep 17 00:00:00 2001 From: kaizimmerm Date: Thu, 20 Oct 2016 12:03:17 +0200 Subject: [PATCH 1/5] Removed external artifact from repository. Signed-off-by: kaizimmerm --- .../rest/resource/DataConversionHelper.java | 10 +- .../resource/DdiArtifactStoreController.java | 12 +- .../ddi/rest/resource/DdiRootController.java | 10 +- .../resource/DdiArtifactDownloadTest.java | 21 +- .../rest/resource/DdiDeploymentBaseTest.java | 16 +- .../AmqpAuthenticationMessageHandler.java | 22 +- .../amqp/AmqpMessageDispatcherService.java | 9 +- .../AmqpControllerAuthenticationTest.java | 12 +- .../AmqpMessageDispatcherServiceTest.java | 8 +- .../amqp/AmqpMessageHandlerServiceTest.java | 12 +- .../MgmtDownloadArtifactResource.java | 12 +- .../resource/MgmtSoftwareModuleMapper.java | 9 +- .../resource/MgmtSoftwareModuleResource.java | 18 +- .../resource/MgmtDownloadResourceTest.java | 2 +- .../MgmtSoftwareModuleResourceTest.java | 95 +++++---- ...MRessourceMisingMongoDbConnectionTest.java | 7 +- .../hawkbit-repository-api/pom.xml | 4 - .../repository/ArtifactManagement.java | 135 +++--------- .../repository/ControllerManagement.java | 6 +- .../hawkbit/repository/EntityFactory.java | 8 +- .../repository/SoftwareManagement.java | 60 ++---- .../hawkbit/repository/model/Artifact.java | 4 + .../repository/model/ExternalArtifact.java | 41 ---- .../repository/model/LocalArtifact.java | 28 --- .../repository/model/SoftwareModule.java | 40 ++-- .../ExternalArtifactProviderRepository.java | 23 --- .../jpa/ExternalArtifactRepository.java | 37 ---- .../repository/jpa/JpaArtifactManagement.java | 151 ++++---------- .../jpa/JpaControllerManagement.java | 6 +- .../repository/jpa/JpaEntityFactory.java | 13 +- .../repository/jpa/JpaSoftwareManagement.java | 84 +++----- .../repository/jpa/JpaSystemManagement.java | 8 - .../jpa/LocalArtifactRepository.java | 41 ++-- .../jpa/SoftwareModuleRepository.java | 2 +- .../jpa/model/AbstractJpaArtifact.java | 66 ------ ...JpaLocalArtifact.java => JpaArtifact.java} | 52 +++-- .../jpa/model/JpaExternalArtifact.java | 145 ------------- .../model/JpaExternalArtifactProvider.java | 87 -------- .../jpa/model/JpaSoftwareModule.java | 87 +------- .../jpa/model/JpaSoftwareModuleMetadata.java | 2 +- .../jpa/model/SwMetadataCompositeKey.java | 8 +- .../specifications/ActionSpecifications.java | 12 +- .../SoftwareModuleSpecification.java | 9 +- .../V1_8_2__remove_external_artifact___H2.sql | 2 + ..._8_2__remove_external_artifact___MYSQL.sql | 2 + .../jpa/AbstractJpaIntegrationTest.java | 3 - ...AbstractJpaIntegrationTestWithMongoDB.java | 3 - .../ArtifactManagementFailedMongoDBTest.java | 9 +- .../jpa/ArtifactManagementTest.java | 195 ++++++------------ .../jpa/SoftwareManagementTest.java | 107 +++++----- .../repository/jpa/SystemManagementTest.java | 6 +- .../repository/test/util/TestdataFactory.java | 13 +- .../util/RestResourceConversionHelper.java | 12 +- .../artifacts/details/ArtifactBeanQuery.java | 26 +-- .../details/ArtifactDetailsLayout.java | 2 +- .../smtable/BaseSwModuleBeanQuery.java | 6 +- .../upload/UploadConfirmationWindow.java | 15 +- .../smtable/SwMetadataPopupLayout.java | 4 +- .../smtable/SwModuleBeanQuery.java | 4 +- 59 files changed, 531 insertions(+), 1312 deletions(-) delete mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifact.java delete mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/LocalArtifact.java delete mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/ExternalArtifactProviderRepository.java delete mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/ExternalArtifactRepository.java delete mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaArtifact.java rename hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/{JpaLocalArtifact.java => JpaArtifact.java} (75%) delete mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaExternalArtifact.java delete mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaExternalArtifactProvider.java create mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/main/resources/db/migration/H2/V1_8_2__remove_external_artifact___H2.sql create mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/main/resources/db/migration/MYSQL/V1_8_2__remove_external_artifact___MYSQL.sql diff --git a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DataConversionHelper.java b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DataConversionHelper.java index a091557392..55da0792a6 100644 --- a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DataConversionHelper.java +++ b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DataConversionHelper.java @@ -32,7 +32,7 @@ import org.eclipse.hawkbit.ddi.rest.api.DdiRestConstants; import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.repository.model.Action; -import org.eclipse.hawkbit.repository.model.LocalArtifact; +import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.tenancy.TenantAware; import org.springframework.hateoas.Link; @@ -85,13 +85,13 @@ public static List createArtifacts(final Target target, final org.eclipse.hawkbit.repository.model.SoftwareModule module, final ArtifactUrlHandler artifactUrlHandler, final SystemManagement systemManagement) { - return module.getLocalArtifacts().stream() + return module.getArtifacts().stream() .map(artifact -> createArtifact(target, artifactUrlHandler, artifact, systemManagement)) .collect(Collectors.toList()); } private static DdiArtifact createArtifact(final Target target, final ArtifactUrlHandler artifactUrlHandler, - final LocalArtifact artifact, final SystemManagement systemManagement) { + final Artifact artifact, final SystemManagement systemManagement) { final DdiArtifact file = new DdiArtifact(); file.setHashes(new DdiArtifactHash(artifact.getSha1Hash(), artifact.getMd5Hash())); file.setFilename(artifact.getFilename()); @@ -157,8 +157,8 @@ private static int calculateEtag(final Action action) { return result; } - static void writeMD5FileResponse(final String fileName, final HttpServletResponse response, - final LocalArtifact artifact) throws IOException { + static void writeMD5FileResponse(final String fileName, final HttpServletResponse response, final Artifact artifact) + throws IOException { final StringBuilder builder = new StringBuilder(); builder.append(artifact.getMd5Hash()); builder.append(" "); diff --git a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java index d3f57a7f73..39eeca2931 100644 --- a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java +++ b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactStoreController.java @@ -23,7 +23,7 @@ import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; -import org.eclipse.hawkbit.repository.model.LocalArtifact; +import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.rest.util.RequestResponseContextHolder; import org.eclipse.hawkbit.rest.util.RestResourceConversionHelper; @@ -71,7 +71,7 @@ public class DdiArtifactStoreController implements DdiDlArtifactStoreControllerR @Override public ResponseEntity downloadArtifactByFilename(@PathVariable("tenant") final String tenant, @PathVariable("fileName") final String fileName, @AuthenticationPrincipal final String targetid) { - final List foundArtifacts = artifactManagement.findLocalArtifactByFilename(fileName); + final List foundArtifacts = artifactManagement.findArtifactByFilename(fileName); if (foundArtifacts.isEmpty()) { LOG.warn("Software artifact with name {} could not be found.", fileName); @@ -82,13 +82,13 @@ public ResponseEntity downloadArtifactByFilename(@PathVariable("ten LOG.warn("Software artifact name {} is not unique. We will use the first entry.", fileName); } ResponseEntity result; - final LocalArtifact artifact = foundArtifacts.get(0); + final Artifact artifact = foundArtifacts.get(0); final String ifMatch = requestResponseContextHolder.getHttpServletRequest().getHeader("If-Match"); if (ifMatch != null && !RestResourceConversionHelper.matchesHttpHeader(ifMatch, artifact.getSha1Hash())) { result = new ResponseEntity<>(HttpStatus.PRECONDITION_FAILED); } else { - final DbArtifact file = artifactManagement.loadLocalArtifactBinary(artifact); + final DbArtifact file = artifactManagement.loadArtifactBinary(artifact); // we set a download status only if we are aware of the // targetid, i.e. authenticated and not anonymous @@ -112,7 +112,7 @@ public ResponseEntity downloadArtifactByFilename(@PathVariable("ten @Override public ResponseEntity downloadArtifactMD5ByFilename(@PathVariable("tenant") final String tenant, @PathVariable("fileName") final String fileName) { - final List foundArtifacts = artifactManagement.findLocalArtifactByFilename(fileName); + final List foundArtifacts = artifactManagement.findArtifactByFilename(fileName); if (foundArtifacts.isEmpty()) { LOG.warn("Softeare artifact with name {} could not be found.", fileName); @@ -133,7 +133,7 @@ public ResponseEntity downloadArtifactMD5ByFilename(@PathVariable("tenant" } private ActionStatus checkAndReportDownloadByTarget(final HttpServletRequest request, final String targetid, - final LocalArtifact artifact) { + final Artifact artifact) { final Target target = controllerManagement.updateLastTargetQuery(targetid, IpUtil.getClientIpFromRequest(request, securityProperties)); diff --git a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java index 6d3856fd51..b654c382b8 100644 --- a/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java +++ b/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootController.java @@ -38,7 +38,7 @@ import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; -import org.eclipse.hawkbit.repository.model.LocalArtifact; +import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.rest.util.RequestResponseContextHolder; @@ -154,9 +154,9 @@ public ResponseEntity downloadArtifact(@PathVariable("tenant") fina // Exception squid:S3655 - Optional access is checked in checkModule // subroutine @SuppressWarnings("squid:S3655") - final LocalArtifact artifact = module.getLocalArtifactByFilename(fileName).get(); + final Artifact artifact = module.getArtifactByFilename(fileName).get(); - final DbArtifact file = artifactManagement.loadLocalArtifactBinary(artifact); + final DbArtifact file = artifactManagement.loadArtifactBinary(artifact); final String ifMatch = requestResponseContextHolder.getHttpServletRequest().getHeader("If-Match"); if (ifMatch != null && !RestResourceConversionHelper.matchesHttpHeader(ifMatch, artifact.getSha1Hash())) { @@ -196,7 +196,7 @@ private ActionStatus checkAndLogDownload(final HttpServletRequest request, final } private static boolean checkModule(final String fileName, final SoftwareModule module) { - return null == module || !module.getLocalArtifactByFilename(fileName).isPresent(); + return null == module || !module.getArtifactByFilename(fileName).isPresent(); } @Override @@ -219,7 +219,7 @@ public ResponseEntity downloadArtifactMd5(@PathVariable("tenant") final St try { DataConversionHelper.writeMD5FileResponse(fileName, requestResponseContextHolder.getHttpServletResponse(), - module.getLocalArtifactByFilename(fileName).get()); + module.getArtifactByFilename(fileName).get()); } catch (final IOException e) { LOG.error("Failed to stream MD5 File", e); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java index c0958c947a..a1b7e6de46 100644 --- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java +++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java @@ -35,7 +35,6 @@ import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.DistributionSet; -import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.test.util.WithUser; import org.eclipse.hawkbit.rest.AbstractRestIntegrationTestWithMongoDB; @@ -99,7 +98,7 @@ public void invalidRequestsOnArtifactResource() throws Exception { // create artifact final byte random[] = RandomUtils.nextBytes(5 * 1024); - final LocalArtifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), + final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random), ds.findFirstModuleByType(osType).getId(), "file1", false); // no artifact available @@ -193,7 +192,7 @@ public void invalidRequestsOnArtifactResourceByName() throws Exception { .andExpect(status().isNotFound()); // test now consistent data to test allowed methods - final Artifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), + final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random), ds.findFirstModuleByType(osType).getId(), "file1", false); mvc.perform( @@ -268,7 +267,7 @@ public void downloadArtifactThroughFileName() throws Exception { // create artifact final byte random[] = RandomUtils.nextBytes(ARTIFACT_SIZE); - final LocalArtifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), + final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random), ds.findFirstModuleByType(osType).getId(), "file1", false); // download fails as artifact is not yet assigned @@ -309,7 +308,7 @@ public void downloadMd5sumThroughControllerApi() throws Exception { // create artifact final byte random[] = RandomUtils.nextBytes(5 * 1024); - final LocalArtifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), + final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random), ds.findFirstModuleByType(osType).getId(), "file1", false); // download @@ -349,8 +348,8 @@ public void downloadArtifactByNameFailsIfNotAuthenticated() throws Exception { // create artifact final byte random[] = RandomUtils.nextBytes(ARTIFACT_SIZE); - artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), - ds.findFirstModuleByType(osType).getId(), "file1.tar.bz2", false); + artifactManagement.createArtifact(new ByteArrayInputStream(random), ds.findFirstModuleByType(osType).getId(), + "file1.tar.bz2", false); // download fails as artifact is not yet assigned to target deploymentManagement.assignDistributionSet(ds, targets); @@ -383,7 +382,7 @@ public void downloadArtifactByNameByNamedController() throws Exception { // create artifact final byte random[] = RandomUtils.nextBytes(ARTIFACT_SIZE); - final Artifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), + final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random), ds.findFirstModuleByType(osType).getId(), "file1", false); // download fails as artifact is not yet assigned to target @@ -435,7 +434,7 @@ public void rangeDownloadArtifactByName() throws Exception { // create artifact final byte random[] = RandomUtils.nextBytes(resultLength); - final Artifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), + final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random), ds.findFirstModuleByType(osType).getId(), "file1", false); assertThat(random.length).isEqualTo(resultLength); @@ -539,7 +538,7 @@ public void faildDownloadArtifactByNameIfAuthenticationMissing() throws Exceptio // create artifact final byte random[] = RandomUtils.nextBytes(5 * 1024); - final Artifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), + final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random), ds.findFirstModuleByType(osType).getId(), "file1.tar.bz2", false); // download fails as artifact is not yet assigned to target @@ -559,7 +558,7 @@ public void downloadMd5sumFileByName() throws Exception { // create artifact final byte random[] = RandomUtils.nextBytes(5 * 1024); - final Artifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), + final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random), ds.findFirstModuleByType(osType).getId(), "file1.tar.bz2", false); // download diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java index f3821a6867..8b0248a39a 100644 --- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java +++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java @@ -32,8 +32,8 @@ import org.eclipse.hawkbit.repository.model.Action.ActionType; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; +import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.DistributionSet; -import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.RepositoryModelConstants; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; @@ -87,7 +87,7 @@ public void artifactsExists() throws Exception { tenantAware.getCurrentTenant(), target.getName(), softwareModuleId)).andDo(MockMvcResultPrinter.print()) .andExpect(status().isOk()).andExpect(jsonPath("$", hasSize(0))); - testdataFactory.createLocalArtifacts(softwareModuleId); + testdataFactory.createArtifacts(softwareModuleId); mvc.perform(get("/{tenant}/controller/v1/{targetNotExist}/softwaremodules/{softwareModuleId}/artifacts", tenantAware.getCurrentTenant(), target.getName(), softwareModuleId)).andDo(MockMvcResultPrinter.print()) @@ -107,9 +107,9 @@ public void deplomentForceAction() throws Exception { final DistributionSet ds2 = testdataFactory.createDistributionSet("2", true); final byte random[] = RandomUtils.nextBytes(5 * 1024); - final LocalArtifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), + final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random), ds.findFirstModuleByType(osType).getId(), "test1", false); - final LocalArtifact artifactSignature = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), + final Artifact artifactSignature = artifactManagement.createArtifact(new ByteArrayInputStream(random), ds.findFirstModuleByType(osType).getId(), "test1.signature", false); final Target savedTarget = targetManagement.createTarget(target); @@ -270,9 +270,9 @@ public void deplomentAttemptAction() throws Exception { final DistributionSet ds2 = testdataFactory.createDistributionSet("2", true); final byte random[] = RandomUtils.nextBytes(5 * 1024); - final LocalArtifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), + final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random), ds.findFirstModuleByType(osType).getId(), "test1", false); - final LocalArtifact artifactSignature = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), + final Artifact artifactSignature = artifactManagement.createArtifact(new ByteArrayInputStream(random), ds.findFirstModuleByType(osType).getId(), "test1.signature", false); final Target savedTarget = targetManagement.createTarget(target); @@ -394,9 +394,9 @@ public void deplomentAutoForceAction() throws Exception { final DistributionSet ds2 = testdataFactory.createDistributionSet("2", true); final byte random[] = RandomUtils.nextBytes(5 * 1024); - final LocalArtifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), + final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random), ds.findFirstModuleByType(osType).getId(), "test1", false); - final LocalArtifact artifactSignature = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), + final Artifact artifactSignature = artifactManagement.createArtifact(new ByteArrayInputStream(random), ds.findFirstModuleByType(osType).getId(), "test1.signature", false); final Target savedTarget = targetManagement.createTarget(target); diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpAuthenticationMessageHandler.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpAuthenticationMessageHandler.java index fc73116f7a..7200f3204b 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpAuthenticationMessageHandler.java +++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpAuthenticationMessageHandler.java @@ -24,7 +24,6 @@ import org.eclipse.hawkbit.repository.ArtifactManagement; import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; -import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.amqp.AmqpRejectAndDontRequeueException; @@ -122,7 +121,7 @@ public Message onAuthenticationRequest(final Message message) { * download this artifact */ private void checkIfArtifactIsAssignedToTarget(final TenantSecurityToken secruityToken, - final LocalArtifact localArtifact) { + final org.eclipse.hawkbit.repository.model.Artifact localArtifact) { if (secruityToken.getControllerId() != null) { checkByControllerId(localArtifact, secruityToken.getControllerId()); @@ -135,7 +134,8 @@ private void checkIfArtifactIsAssignedToTarget(final TenantSecurityToken secruit } - private void checkByTargetId(final LocalArtifact localArtifact, final Long targetId) { + private void checkByTargetId(final org.eclipse.hawkbit.repository.model.Artifact localArtifact, + final Long targetId) { LOG.debug("no anonymous download request, doing authentication check for target {} and artifact {}", targetId, localArtifact); if (!controllerManagement.hasTargetArtifactAssigned(targetId, localArtifact)) { @@ -146,7 +146,8 @@ private void checkByTargetId(final LocalArtifact localArtifact, final Long targe LOG.info("download security check for target {} and artifact {} granted", targetId, localArtifact); } - private void checkByControllerId(final LocalArtifact localArtifact, final String controllerId) { + private void checkByControllerId(final org.eclipse.hawkbit.repository.model.Artifact localArtifact, + final String controllerId) { LOG.debug("no anonymous download request, doing authentication check for target {} and artifact {}", controllerId, localArtifact); if (!controllerManagement.hasTargetArtifactAssigned(controllerId, localArtifact)) { @@ -157,14 +158,14 @@ private void checkByControllerId(final LocalArtifact localArtifact, final String LOG.info("download security check for target {} and artifact {} granted", controllerId, localArtifact); } - private LocalArtifact findLocalArtifactByFileResource(final FileResource fileResource) { + private org.eclipse.hawkbit.repository.model.Artifact findArtifactByFileResource(final FileResource fileResource) { if (fileResource.getSha1() != null) { - return artifactManagement.findFirstLocalArtifactsBySHA1(fileResource.getSha1()); + return artifactManagement.findFirstArtifactBySHA1(fileResource.getSha1()); } else if (fileResource.getFilename() != null) { - return artifactManagement.findLocalArtifactByFilename(fileResource.getFilename()).stream().findFirst() + return artifactManagement.findArtifactByFilename(fileResource.getFilename()).stream().findFirst() .orElse(null); } else if (fileResource.getArtifactId() != null) { - return artifactManagement.findLocalArtifact(fileResource.getArtifactId()); + return artifactManagement.findArtifact(fileResource.getArtifactId()); } else if (fileResource.getSoftwareModuleFilenameResource() != null) { return artifactManagement .findByFilenameAndSoftwareModule(fileResource.getSoftwareModuleFilenameResource().getFilename(), @@ -191,7 +192,8 @@ private Message handleAuthenticationMessage(final Message message) { try { SecurityContextHolder.getContext().setAuthentication(authenticationManager.doAuthenticate(secruityToken)); - final LocalArtifact localArtifact = findLocalArtifactByFileResource(fileResource); + final org.eclipse.hawkbit.repository.model.Artifact localArtifact = findArtifactByFileResource( + fileResource); if (localArtifact == null) { LOG.info("target {} requested file resource {} which does not exists to download", @@ -201,7 +203,7 @@ private Message handleAuthenticationMessage(final Message message) { checkIfArtifactIsAssignedToTarget(secruityToken, localArtifact); - final Artifact artifact = convertDbArtifact(artifactManagement.loadLocalArtifactBinary(localArtifact)); + final Artifact artifact = convertDbArtifact(artifactManagement.loadArtifactBinary(localArtifact)); if (artifact == null) { throw new EntityNotFoundException(); } diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java index 2d4b5c52ab..8356548432 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java +++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java @@ -29,7 +29,6 @@ import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.repository.eventbus.event.CancelTargetAssignmentEvent; import org.eclipse.hawkbit.repository.eventbus.event.TargetAssignDistributionSetEvent; -import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.security.SystemSecurityContext; import org.eclipse.hawkbit.util.IpUtil; @@ -159,12 +158,13 @@ private SoftwareModule convertToAmqpSoftwareModule(final Target target, amqpSoftwareModule.setModuleType(softwareModule.getType().getKey()); amqpSoftwareModule.setModuleVersion(softwareModule.getVersion()); - final List artifacts = convertArtifacts(target, softwareModule.getLocalArtifacts()); + final List artifacts = convertArtifacts(target, softwareModule.getArtifacts()); amqpSoftwareModule.setArtifacts(artifacts); return amqpSoftwareModule; } - private List convertArtifacts(final Target target, final List localArtifacts) { + private List convertArtifacts(final Target target, + final List localArtifacts) { if (localArtifacts.isEmpty()) { return Collections.emptyList(); } @@ -173,7 +173,8 @@ private List convertArtifacts(final Target target, final List receivedList = new ArrayList<>(); - for (final Artifact artifact : testdataFactory.createLocalArtifacts(module.getId())) { - module.addArtifact((LocalArtifact) artifact); + for (final Artifact artifact : testdataFactory.createArtifacts(module.getId())) { + module.addArtifact(artifact); receivedList.add(new DbArtifact()); } @@ -186,8 +185,7 @@ public void testSendDownloadRequest() { module.getArtifacts().forEach(dbArtifact -> { final Optional found = softwareModule.getArtifacts() - .stream().filter(dmfartifact -> dmfartifact.getFilename() - .equals(((LocalArtifact) dbArtifact).getFilename())) + .stream().filter(dmfartifact -> dmfartifact.getFilename().equals(dbArtifact.getFilename())) .findFirst(); assertTrue("The artifact should exist in message", found.isPresent()); diff --git a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java index e4c309412f..991b19fc77 100644 --- a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java +++ b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java @@ -49,7 +49,7 @@ import org.eclipse.hawkbit.repository.jpa.model.helper.SecurityTokenGeneratorHolder; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; -import org.eclipse.hawkbit.repository.model.LocalArtifact; +import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.TargetInfo; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; @@ -300,8 +300,8 @@ public void authenticationRequestDeniedForArtifactWhichIsNotAssignedToTarget() { final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(securityToken, messageProperties); - final LocalArtifact localArtifactMock = mock(LocalArtifact.class); - when(artifactManagementMock.findFirstLocalArtifactsBySHA1(anyString())).thenReturn(localArtifactMock); + final Artifact localArtifactMock = mock(Artifact.class); + when(artifactManagementMock.findFirstArtifactBySHA1(anyString())).thenReturn(localArtifactMock); when(controllerManagementMock.getActionForDownloadByTargetAndSoftwareModule(anyObject(), anyObject())) .thenThrow(EntityNotFoundException.class); @@ -325,12 +325,12 @@ public void authenticationRequestAllowedForArtifactWhichExistsAndAssignedToTarge messageProperties); // mock - final LocalArtifact localArtifactMock = mock(LocalArtifact.class); + final Artifact localArtifactMock = mock(Artifact.class); final DbArtifact dbArtifactMock = mock(DbArtifact.class); - when(artifactManagementMock.findFirstLocalArtifactsBySHA1(anyString())).thenReturn(localArtifactMock); + when(artifactManagementMock.findFirstArtifactBySHA1(anyString())).thenReturn(localArtifactMock); when(controllerManagementMock.hasTargetArtifactAssigned(securityToken.getControllerId(), localArtifactMock)) .thenReturn(true); - when(artifactManagementMock.loadLocalArtifactBinary(localArtifactMock)).thenReturn(dbArtifactMock); + when(artifactManagementMock.loadArtifactBinary(localArtifactMock)).thenReturn(dbArtifactMock); when(dbArtifactMock.getArtifactId()).thenReturn("artifactId"); when(dbArtifactMock.getSize()).thenReturn(1L); when(dbArtifactMock.getHashes()).thenReturn(new DbArtifactHash("sha1", "md5")); diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDownloadArtifactResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDownloadArtifactResource.java index dad43bf009..a187e6769c 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDownloadArtifactResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDownloadArtifactResource.java @@ -17,7 +17,7 @@ import org.eclipse.hawkbit.repository.ArtifactManagement; import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; -import org.eclipse.hawkbit.repository.model.LocalArtifact; +import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.rest.util.RequestResponseContextHolder; import org.eclipse.hawkbit.rest.util.RestResourceConversionHelper; @@ -52,7 +52,7 @@ public class MgmtDownloadArtifactResource implements MgmtDownloadArtifactRestApi * @param softwareModuleId * of the parent SoftwareModule * @param artifactId - * of the related LocalArtifact + * of the related Artifact * * @return responseEntity with status ok if successful */ @@ -62,12 +62,12 @@ public ResponseEntity downloadArtifact(@PathVariable("softwareModul @PathVariable("artifactId") final Long artifactId) { final SoftwareModule module = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, artifactId); - if (null == module || !module.getLocalArtifact(artifactId).isPresent()) { + if (null == module || !module.getArtifact(artifactId).isPresent()) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } - final LocalArtifact artifact = module.getLocalArtifact(artifactId).get(); - final DbArtifact file = artifactManagement.loadLocalArtifactBinary(artifact); + final Artifact artifact = module.getArtifact(artifactId).get(); + final DbArtifact file = artifactManagement.loadArtifactBinary(artifact); final HttpServletRequest request = requestResponseContextHolder.getHttpServletRequest(); final String ifMatch = request.getHeader("If-Match"); if (ifMatch != null && !RestResourceConversionHelper.matchesHttpHeader(ifMatch, artifact.getSha1Hash())) { @@ -84,7 +84,7 @@ private SoftwareModule findSoftwareModuleWithExceptionIfNotFound(final Long soft final SoftwareModule module = softwareManagement.findSoftwareModuleById(softwareModuleId); if (module == null) { throw new EntityNotFoundException("SoftwareModule with Id {" + softwareModuleId + "} does not exist"); - } else if (artifactId != null && !module.getLocalArtifact(artifactId).isPresent()) { + } else if (artifactId != null && !module.getArtifact(artifactId).isPresent()) { throw new EntityNotFoundException("Artifact with Id {" + artifactId + "} does not exist"); } return module; diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleMapper.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleMapper.java index 2166a7e434..eb0728cf84 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleMapper.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleMapper.java @@ -29,7 +29,6 @@ import org.eclipse.hawkbit.repository.exception.ConstraintViolationException; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.model.Artifact; -import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; @@ -156,7 +155,7 @@ public static MgmtSoftwareModule toResponse(final SoftwareModule baseSofwareModu * @return */ static MgmtArtifact toResponse(final Artifact artifact) { - final MgmtArtifact.ArtifactType type = artifact instanceof LocalArtifact ? MgmtArtifact.ArtifactType.LOCAL + final MgmtArtifact.ArtifactType type = artifact instanceof Artifact ? MgmtArtifact.ArtifactType.LOCAL : MgmtArtifact.ArtifactType.EXTERNAL; final MgmtArtifact artifactRest = new MgmtArtifact(); @@ -165,16 +164,14 @@ static MgmtArtifact toResponse(final Artifact artifact) { artifactRest.setSize(artifact.getSize()); artifactRest.setHashes(new MgmtArtifactHash(artifact.getSha1Hash(), artifact.getMd5Hash())); - if (artifact instanceof LocalArtifact) { - artifactRest.setProvidedFilename(((LocalArtifact) artifact).getFilename()); - } + artifactRest.setProvidedFilename(artifact.getFilename()); MgmtRestModelMapper.mapBaseToBase(artifactRest, artifact); artifactRest.add(linkTo(methodOn(MgmtSoftwareModuleRestApi.class) .getArtifact(artifact.getSoftwareModule().getId(), artifact.getId())).withRel("self")); - if (artifact instanceof LocalArtifact) { + if (artifact instanceof Artifact) { artifactRest.add(linkTo(methodOn(MgmtDownloadArtifactResource.class) .downloadArtifact(artifact.getSoftwareModule().getId(), artifact.getId())).withRel("download")); } diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java index 1706a80309..972fd4863a 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java @@ -86,9 +86,9 @@ public ResponseEntity uploadArtifact(@PathVariable("softwareModule } try { - final Artifact result = artifactManagement.createLocalArtifact(file.getInputStream(), softwareModuleId, - fileName, md5Sum == null ? null : md5Sum.toLowerCase(), - sha1Sum == null ? null : sha1Sum.toLowerCase(), false, file.getContentType()); + final Artifact result = artifactManagement.createArtifact(file.getInputStream(), softwareModuleId, fileName, + md5Sum == null ? null : md5Sum.toLowerCase(), sha1Sum == null ? null : sha1Sum.toLowerCase(), false, + file.getContentType()); return ResponseEntity.status(CREATED).body(toResponse(result)); } catch (final IOException e) { LOG.error("Failed to store artifact", e); @@ -116,7 +116,7 @@ public ResponseEntity getArtifact(@PathVariable("softwareModuleId" final SoftwareModule module = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, artifactId); - return ResponseEntity.ok(toResponse(module.getLocalArtifact(artifactId).get())); + return ResponseEntity.ok(toResponse(module.getArtifact(artifactId).get())); } @Override @@ -125,7 +125,7 @@ public ResponseEntity deleteArtifact(@PathVariable("softwareModuleId") fin @PathVariable("artifactId") final Long artifactId) { findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, artifactId); - artifactManagement.deleteLocalArtifact(artifactId); + artifactManagement.deleteArtifact(artifactId); return ResponseEntity.ok().build(); } @@ -200,7 +200,7 @@ public ResponseEntity updateSoftwareModule( public ResponseEntity deleteSoftwareModule(@PathVariable("softwareModuleId") final Long softwareModuleId) { final SoftwareModule module = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null); - softwareManagement.deleteSoftwareModule(module); + softwareManagement.deleteSoftwareModule(module.getId()); return ResponseEntity.ok().build(); } @@ -239,7 +239,7 @@ public ResponseEntity getMetadataValue(@PathVariable("softwareModu @PathVariable("metadataKey") final String metadataKey) { final SoftwareModule sw = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null); - final SoftwareModuleMetadata findOne = softwareManagement.findSoftwareModuleMetadata(sw, metadataKey); + final SoftwareModuleMetadata findOne = softwareManagement.findSoftwareModuleMetadata(sw.getId(), metadataKey); return ResponseEntity.ok(toResponseSwMetadata(findOne)); } @@ -260,7 +260,7 @@ public ResponseEntity deleteMetadata(@PathVariable("softwareModuleId") fin @PathVariable("metadataKey") final String metadataKey) { final SoftwareModule sw = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null); - softwareManagement.deleteSoftwareModuleMetadata(sw, metadataKey); + softwareManagement.deleteSoftwareModuleMetadata(sw.getId(), metadataKey); return ResponseEntity.ok().build(); } @@ -284,7 +284,7 @@ private SoftwareModule findSoftwareModuleWithExceptionIfNotFound(final Long soft if (module == null) { throw new EntityNotFoundException("SoftwareModule with Id {" + softwareModuleId + "} does not exist"); } - if (artifactId != null && !module.getLocalArtifact(artifactId).isPresent()) { + if (artifactId != null && !module.getArtifact(artifactId).isPresent()) { throw new EntityNotFoundException("Artifact with Id {" + artifactId + "} does not exist"); } diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDownloadResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDownloadResourceTest.java index 16cc82e750..b15ff7983c 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDownloadResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDownloadResourceTest.java @@ -47,7 +47,7 @@ public void setupCache() { final DistributionSet distributionSet = testdataFactory.createDistributionSet("Test"); final SoftwareModule softwareModule = distributionSet.getModules().stream().findFirst().get(); - final Artifact artifact = testdataFactory.createLocalArtifacts(softwareModule.getId()).stream().findFirst().get(); + final Artifact artifact = testdataFactory.createArtifacts(softwareModule.getId()).stream().findFirst().get(); downloadIdCache.put(downloadIdSha1, new DownloadArtifactCache(DownloadType.BY_SHA1, artifact.getSha1Hash())); } diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java index 4f3e12b16f..60ce8e7352 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java @@ -39,7 +39,6 @@ import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.DistributionSet; -import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata; import org.eclipse.hawkbit.repository.test.util.HashGeneratorUtils; @@ -148,8 +147,7 @@ public void uploadArtifact() throws Exception { // check rest of response compared to DB final MgmtArtifact artResult = ResourceUtility .convertArtifactResponse(mvcResult.getResponse().getContentAsString()); - final Long artId = ((LocalArtifact) softwareManagement.findSoftwareModuleWithDetails(sm.getId()).getArtifacts() - .get(0)).getId(); + final Long artId = softwareManagement.findSoftwareModuleWithDetails(sm.getId()).getArtifacts().get(0).getId(); assertThat(artResult.getArtifactId()).as("Wrong artifact id").isEqualTo(artId); assertThat(JsonPath.compile("$._links.self.href").read(mvcResult.getResponse().getContentAsString()).toString()) .as("Link contains no self url") @@ -164,33 +162,32 @@ public void uploadArtifact() throws Exception { private void assertArtifact(final SoftwareModule sm, final byte[] random) throws IOException { // check result in db... // repo - assertThat(artifactManagement.countLocalArtifactsAll()).as("Wrong artifact size").isEqualTo(1); + assertThat(artifactManagement.countArtifactsAll()).as("Wrong artifact size").isEqualTo(1); // binary assertTrue("Wrong artifact content", IOUtils.contentEquals(new ByteArrayInputStream(random), - artifactManagement - .loadLocalArtifactBinary((LocalArtifact) softwareManagement - .findSoftwareModuleWithDetails(sm.getId()).getArtifacts().get(0)) + artifactManagement.loadArtifactBinary( + softwareManagement.findSoftwareModuleWithDetails(sm.getId()).getArtifacts().get(0)) .getFileInputStream())); // hashes - assertThat(artifactManagement.findLocalArtifactByFilename("origFilename").get(0).getSha1Hash()) - .as("Wrong sha1 hash").isEqualTo(HashGeneratorUtils.generateSHA1(random)); + assertThat(artifactManagement.findArtifactByFilename("origFilename").get(0).getSha1Hash()).as("Wrong sha1 hash") + .isEqualTo(HashGeneratorUtils.generateSHA1(random)); - assertThat(artifactManagement.findLocalArtifactByFilename("origFilename").get(0).getMd5Hash()) - .as("Wrong md5 hash").isEqualTo(HashGeneratorUtils.generateMD5(random)); + assertThat(artifactManagement.findArtifactByFilename("origFilename").get(0).getMd5Hash()).as("Wrong md5 hash") + .isEqualTo(HashGeneratorUtils.generateMD5(random)); // metadata - assertThat(((LocalArtifact) softwareManagement.findSoftwareModuleWithDetails(sm.getId()).getArtifacts().get(0)) - .getFilename()).as("wrong metadata of the filename").isEqualTo("origFilename"); + assertThat(softwareManagement.findSoftwareModuleWithDetails(sm.getId()).getArtifacts().get(0).getFilename()) + .as("wrong metadata of the filename").isEqualTo("origFilename"); } @Test @Description("Verfies that the system does not accept empty artifact uploads. Expected response: BAD REQUEST") public void emptyUploadArtifact() throws Exception { assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0); - assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(0); + assertThat(artifactManagement.countArtifactsAll()).isEqualTo(0); SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null); sm = softwareManagement.createSoftwareModule(sm); @@ -229,7 +226,7 @@ public void duplicateUploadArtifact() throws Exception { public void uploadArtifactWithCustomName() throws Exception { SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null); sm = softwareManagement.createSoftwareModule(sm); - assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(0); + assertThat(artifactManagement.countArtifactsAll()).isEqualTo(0); // create test file final byte random[] = RandomStringUtils.random(5 * 1024).getBytes(); @@ -244,10 +241,10 @@ public void uploadArtifactWithCustomName() throws Exception { // check result in db... // repo - assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(1); + assertThat(artifactManagement.countArtifactsAll()).isEqualTo(1); // hashes - assertThat(artifactManagement.findLocalArtifactByFilename("customFilename")).as("Local artifact is wrong") + assertThat(artifactManagement.findArtifactByFilename("customFilename")).as("Local artifact is wrong") .hasSize(1); } @@ -256,7 +253,7 @@ public void uploadArtifactWithCustomName() throws Exception { public void uploadArtifactWithHashCheck() throws Exception { SoftwareModule sm = entityFactory.generateSoftwareModule(osType, "name 1", "version 1", null, null); sm = softwareManagement.createSoftwareModule(sm); - assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(0); + assertThat(artifactManagement.countArtifactsAll()).isEqualTo(0); // create test file final byte random[] = RandomStringUtils.random(5 * 1024).getBytes(); @@ -303,9 +300,9 @@ public void downloadArtifact() throws Exception { final byte random[] = RandomStringUtils.random(5 * 1024).getBytes(); - final Artifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(), + final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", false); - final Artifact artifact2 = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(), + final Artifact artifact2 = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), "file2", false); final MvcResult result = mvc @@ -326,7 +323,7 @@ public void downloadArtifact() throws Exception { Arrays.equals(result2.getResponse().getContentAsByteArray(), random)); assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).as("Softwaremodule size is wrong").hasSize(1); - assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(2); + assertThat(artifactManagement.countArtifactsAll()).isEqualTo(2); } @Test @@ -337,7 +334,7 @@ public void getArtifact() throws Exception { sm = softwareManagement.createSoftwareModule(sm); final byte random[] = RandomStringUtils.random(5 * 1024).getBytes(); - final Artifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(), + final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", false); // perform test @@ -364,9 +361,9 @@ public void getArtifacts() throws Exception { final byte random[] = RandomStringUtils.random(5 * 1024).getBytes(); - final Artifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(), + final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", false); - final Artifact artifact2 = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(), + final Artifact artifact2 = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), "file2", false); mvc.perform(get("/rest/v1/softwaremodules/{smId}/artifacts", sm.getId()).accept(MediaType.APPLICATION_JSON)) @@ -413,7 +410,7 @@ public void invalidRequestsOnArtifactResource() throws Exception { .andDo(MockMvcResultPrinter.print()).andExpect(status().isNotFound()); // SM does not exist - artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", false); + artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", false); mvc.perform(get("/rest/v1/softwaremodules/1234567890/artifacts")).andDo(MockMvcResultPrinter.print()) .andExpect(status().isNotFound()); @@ -834,15 +831,15 @@ public void createSoftwareModules() throws JSONException, Exception { .isEqualTo("http://localhost/rest/v1/softwaremodules/" + ahCreated.getId() + "/artifacts"); assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).as("Wrong softwaremodule size").hasSize(3); - assertThat(softwareManagement.findSoftwareModulesByType(pageReq, osType).getContent().get(0).getName()) + assertThat(softwareManagement.findSoftwareModulesByType(pageReq, osType.getId()).getContent().get(0).getName()) .as("Softwaremoudle name is wrong").isEqualTo(os.getName()); - assertThat(softwareManagement.findSoftwareModulesByType(pageReq, osType).getContent().get(0).getCreatedBy()) - .as("Softwaremoudle created by is wrong").isEqualTo("uploadTester"); - assertThat(softwareManagement.findSoftwareModulesByType(pageReq, osType).getContent().get(0).getCreatedAt()) - .as("Softwaremoudle created at is wrong").isGreaterThanOrEqualTo(current); - assertThat(softwareManagement.findSoftwareModulesByType(pageReq, runtimeType).getContent().get(0).getName()) - .as("Softwaremoudle name is wrong").isEqualTo(jvm.getName()); - assertThat(softwareManagement.findSoftwareModulesByType(pageReq, appType).getContent().get(0).getName()) + assertThat(softwareManagement.findSoftwareModulesByType(pageReq, osType.getId()).getContent().get(0) + .getCreatedBy()).as("Softwaremoudle created by is wrong").isEqualTo("uploadTester"); + assertThat(softwareManagement.findSoftwareModulesByType(pageReq, osType.getId()).getContent().get(0) + .getCreatedAt()).as("Softwaremoudle created at is wrong").isGreaterThanOrEqualTo(current); + assertThat(softwareManagement.findSoftwareModulesByType(pageReq, runtimeType.getId()).getContent().get(0) + .getName()).as("Softwaremoudle name is wrong").isEqualTo(jvm.getName()); + assertThat(softwareManagement.findSoftwareModulesByType(pageReq, appType.getId()).getContent().get(0).getName()) .as("Softwaremoudle name is wrong").isEqualTo(ah.getName()); } @@ -855,17 +852,17 @@ public void deleteUnassignedSoftwareModule() throws Exception { final byte random[] = RandomStringUtils.random(5 * 1024).getBytes(); - artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", false); + artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", false); assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).as("Softwaremoudle size is wrong").hasSize(1); - assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(1); + assertThat(artifactManagement.countArtifactsAll()).isEqualTo(1); mvc.perform(delete("/rest/v1/softwaremodules/{smId}", sm.getId())).andDo(MockMvcResultPrinter.print()) .andExpect(status().isOk()); assertThat(softwareManagement.findSoftwareModulesAll(pageReq)) .as("After delete no softwarmodule should be available").isEmpty(); - assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(0); + assertThat(artifactManagement.countArtifactsAll()).isEqualTo(0); } @Test @@ -875,11 +872,11 @@ public void deleteAssignedSoftwareModule() throws Exception { final byte random[] = RandomStringUtils.random(5 * 1024).getBytes(); - artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), - ds1.findFirstModuleByType(appType).getId(), "file1", false); + artifactManagement.createArtifact(new ByteArrayInputStream(random), ds1.findFirstModuleByType(appType).getId(), + "file1", false); assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(3); - assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(1); + assertThat(artifactManagement.countArtifactsAll()).isEqualTo(1); mvc.perform(delete("/rest/v1/softwaremodules/{smId}", ds1.findFirstModuleByType(appType).getId())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); @@ -891,7 +888,7 @@ public void deleteAssignedSoftwareModule() throws Exception { // all 3 are now marked as deleted assertThat(softwareManagement.findSoftwareModulesAll(pageReq).getNumber()) .as("After delete no softwarmodule should be available").isEqualTo(0); - assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(1); + assertThat(artifactManagement.countArtifactsAll()).isEqualTo(1); } @Test @@ -904,15 +901,15 @@ public void deleteArtifact() throws Exception { final byte random[] = RandomStringUtils.random(5 * 1024).getBytes(); // Create 2 artifacts - final LocalArtifact artifact = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), - sm.getId(), "file1", false); - artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(), "file2", false); + final Artifact artifact = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), + "file1", false); + artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), "file2", false); // check repo before delete assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(1); assertThat(softwareManagement.findSoftwareModuleWithDetails(sm.getId()).getArtifacts()).hasSize(2); - assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(2); + assertThat(artifactManagement.countArtifactsAll()).isEqualTo(2); // delete mvc.perform(delete("/rest/v1/softwaremodules/{smId}/artifacts/{artId}", sm.getId(), artifact.getId())) @@ -921,7 +918,7 @@ public void deleteArtifact() throws Exception { // check that only one artifact is still alive and still assigned assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).as("After the sm should be marked as deleted") .hasSize(1); - assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(1); + assertThat(artifactManagement.countArtifactsAll()).isEqualTo(1); assertThat(softwareManagement.findSoftwareModuleWithDetails(sm.getId()).getArtifacts()) .as("After delete artifact should available for marked as deleted sm's").hasSize(1); @@ -950,8 +947,8 @@ public void createMetadata() throws Exception { .andExpect(jsonPath("[1]key", equalTo(knownKey2))) .andExpect(jsonPath("[1]value", equalTo(knownValue2))); - final SoftwareModuleMetadata metaKey1 = softwareManagement.findSoftwareModuleMetadata(sm, knownKey1); - final SoftwareModuleMetadata metaKey2 = softwareManagement.findSoftwareModuleMetadata(sm, knownKey2); + final SoftwareModuleMetadata metaKey1 = softwareManagement.findSoftwareModuleMetadata(sm.getId(), knownKey1); + final SoftwareModuleMetadata metaKey2 = softwareManagement.findSoftwareModuleMetadata(sm.getId(), knownKey2); assertThat(metaKey1.getValue()).as("Metadata key is wrong").isEqualTo(knownValue1); assertThat(metaKey2.getValue()).as("Metadata key is wrong").isEqualTo(knownValue2); @@ -978,7 +975,7 @@ public void updateMetadata() throws Exception { .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("key", equalTo(knownKey))).andExpect(jsonPath("value", equalTo(updateValue))); - final SoftwareModuleMetadata assertDS = softwareManagement.findSoftwareModuleMetadata(sm, knownKey); + final SoftwareModuleMetadata assertDS = softwareManagement.findSoftwareModuleMetadata(sm.getId(), knownKey); assertThat(assertDS.getValue()).as("Metadata is wrong").isEqualTo(updateValue); } @@ -998,7 +995,7 @@ public void deleteMetadata() throws Exception { .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); try { - softwareManagement.findSoftwareModuleMetadata(sm, knownKey); + softwareManagement.findSoftwareModuleMetadata(sm.getId(), knownKey); fail("expected EntityNotFoundException but didn't throw"); } catch (final EntityNotFoundException e) { // ok as expected diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/SMRessourceMisingMongoDbConnectionTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/SMRessourceMisingMongoDbConnectionTest.java index 737bf50d57..0c815831df 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/SMRessourceMisingMongoDbConnectionTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/SMRessourceMisingMongoDbConnectionTest.java @@ -42,11 +42,11 @@ public void missingMongoDbConnectionResultsInErrorAtUpload() throws Exception { mongodExecutable.stop(); assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0); - assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(0); + assertThat(artifactManagement.countArtifactsAll()).isEqualTo(0); SoftwareModule sm = entityFactory.generateSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1", "version 1", null, null); sm = softwareManagement.createSoftwareModule(sm); - assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(0); + assertThat(artifactManagement.countArtifactsAll()).isEqualTo(0); // create test file final byte random[] = RandomStringUtils.random(5 * 1024).getBytes(); @@ -64,10 +64,11 @@ public void missingMongoDbConnectionResultsInErrorAtUpload() throws Exception { assertThat(exceptionInfo.getMessage()).isEqualTo(SpServerError.SP_ARTIFACT_UPLOAD_FAILED.getMessage()); // ensure that the JPA transaction was rolled back - assertThat(artifactManagement.countLocalArtifactsAll()).isEqualTo(0); + assertThat(artifactManagement.countArtifactsAll()).isEqualTo(0); } + @Override @After public void cleanCurrentCollection() { // not needed, mongodb is stopped already diff --git a/hawkbit-repository/hawkbit-repository-api/pom.xml b/hawkbit-repository/hawkbit-repository-api/pom.xml index e809ce29d1..4311485925 100644 --- a/hawkbit-repository/hawkbit-repository-api/pom.xml +++ b/hawkbit-repository/hawkbit-repository-api/pom.xml @@ -32,10 +32,6 @@ org.hibernate hibernate-validator - - cz.jirutka.rsql - rsql-parser - org.springframework.hateoas spring-hateoas 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 cbe9f827eb..93ac1a7d65 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 @@ -23,9 +23,6 @@ import org.eclipse.hawkbit.repository.exception.InvalidMD5HashException; import org.eclipse.hawkbit.repository.exception.InvalidSHA1HashException; import org.eclipse.hawkbit.repository.model.Artifact; -import org.eclipse.hawkbit.repository.model.ExternalArtifact; -import org.eclipse.hawkbit.repository.model.ExternalArtifactProvider; -import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.hibernate.validator.constraints.NotEmpty; import org.springframework.data.domain.Page; @@ -38,59 +35,12 @@ * */ public interface ArtifactManagement { - - /** - * Creates {@link ExternalArtifact} based on given provider. - * - * @param externalRepository - * the artifact is located in - * @param urlSuffix - * of the artifact - * {@link ExternalArtifactProvider#getDefaultSuffix()} is used if - * empty. - * @param moduleId - * to assign the artifact to - * - * @return created {@link ExternalArtifact} - * - * @throws EntityNotFoundException - * if {@link SoftwareModule} with given ID does not exist - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) - ExternalArtifact createExternalArtifact(@NotNull ExternalArtifactProvider externalRepository, String urlSuffix, - @NotNull Long moduleId); - /** * @return the total amount of local artifacts stored in the artifact * management */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Long countLocalArtifactsAll(); - - /** - * @return the total amount of external artifacts stored in the artifact - * management - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Long countExternalArtifactsAll(); - - /** - * Persists {@link ExternalArtifactProvider} based on given properties. - * - * @param name - * of the provided - * @param description - * which is optional - * @param basePath - * of all {@link ExternalArtifact}s of the provider - * @param defaultUrlSuffix - * that is used if {@link ExternalArtifact#getUrlSuffix()} is - * empty. - * @return created {@link ExternalArtifactProvider} - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) - ExternalArtifactProvider createExternalArtifactProvider(@NotEmpty String name, String description, - @NotNull String basePath, String defaultUrlSuffix); + Long countArtifactsAll(); /** * Persists artifact binary as provided by given InputStream. assign the @@ -106,12 +56,12 @@ ExternalArtifactProvider createExternalArtifactProvider(@NotEmpty String name, S * to true if the artifact binary can be overridden * if it already exists * - * @return uploaded {@link LocalArtifact} + * @return uploaded {@link Artifact} * * @throw ArtifactUploadFailedException if upload fails */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - LocalArtifact createLocalArtifact(@NotNull InputStream inputStream, @NotNull Long moduleId, final String filename, + Artifact createArtifact(@NotNull InputStream inputStream, @NotNull Long moduleId, final String filename, final boolean overrideExisting); /** @@ -130,13 +80,13 @@ LocalArtifact createLocalArtifact(@NotNull InputStream inputStream, @NotNull Lon * @param contentType * the contentType of the file * - * @return uploaded {@link LocalArtifact} + * @return uploaded {@link Artifact} * * @throw ArtifactUploadFailedException if upload fails */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - LocalArtifact createLocalArtifact(@NotNull InputStream inputStream, @NotNull Long moduleId, - @NotNull String filename, final boolean overrideExisting, @NotNull String contentType); + Artifact createArtifact(@NotNull InputStream inputStream, @NotNull Long moduleId, @NotNull String filename, + final boolean overrideExisting, @NotNull String contentType); /** * Persists artifact binary as provided by given InputStream. assign the @@ -157,7 +107,7 @@ LocalArtifact createLocalArtifact(@NotNull InputStream inputStream, @NotNull Lon * if it already exists * @param contentType * the contentType of the file - * @return uploaded {@link LocalArtifact} + * @return uploaded {@link Artifact} * * @throws EntityNotFoundException * if given software module does not exist @@ -171,24 +121,12 @@ LocalArtifact createLocalArtifact(@NotNull InputStream inputStream, @NotNull Lon * if check against provided SHA1 checksum failed */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) - LocalArtifact createLocalArtifact(@NotNull InputStream stream, @NotNull Long moduleId, @NotEmpty String filename, + Artifact createArtifact(@NotNull InputStream stream, @NotNull Long moduleId, @NotEmpty String filename, String providedMd5Sum, String providedSha1Sum, boolean overrideExisting, String contentType); - /** - * 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) - * - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY) - void deleteExternalArtifact(@NotNull Long id); - /** * Garbage collects local artifact binary file if only referenced by given - * {@link LocalArtifact} metadata object. + * {@link Artifact} metadata object. * * @param onlyByThisReferenced * the related local artifact @@ -196,7 +134,7 @@ LocalArtifact createLocalArtifact(@NotNull InputStream stream, @NotNull Long mod * @return true if an binary was actually garbage collected */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY) - boolean clearLocalArtifactBinary(@NotNull LocalArtifact onlyByThisReferenced); + boolean clearArtifactBinary(@NotNull Artifact onlyByThisReferenced); /** * Deletes {@link Artifact} based on given id. @@ -208,19 +146,19 @@ LocalArtifact createLocalArtifact(@NotNull InputStream stream, @NotNull Long mod * */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY) - void deleteLocalArtifact(@NotNull Long id); + void deleteArtifact(@NotNull Long id); /** - * Searches for {@link LocalArtifact} with given {@link Identifiable}. + * Searches for {@link Artifact} with given {@link Identifiable}. * * @param id * to search for - * @return found {@link LocalArtifact} or null is it could not - * be found. + * @return found {@link Artifact} or null is it could not be + * found. */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY + SpringEvalExpressions.HAS_AUTH_OR + SpringEvalExpressions.IS_CONTROLLER) - LocalArtifact findLocalArtifact(@NotNull Long id); + Artifact findArtifact(@NotNull Long id); /** * Find by artifact by software module id and filename. @@ -229,11 +167,11 @@ LocalArtifact createLocalArtifact(@NotNull InputStream stream, @NotNull Long mod * file name * @param softwareModuleId * software module id. - * @return LocalArtifact if artifact present + * @return Artifact if artifact present */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY + SpringEvalExpressions.HAS_AUTH_OR + SpringEvalExpressions.IS_CONTROLLER) - List findByFilenameAndSoftwareModule(@NotNull String filename, @NotNull Long softwareModuleId); + List findByFilenameAndSoftwareModule(@NotNull String filename, @NotNull Long softwareModuleId); /** * Find all local artifact by sha1 and return the first artifact. @@ -244,18 +182,18 @@ LocalArtifact createLocalArtifact(@NotNull InputStream stream, @NotNull Long mod */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY + SpringEvalExpressions.HAS_AUTH_OR + SpringEvalExpressions.IS_CONTROLLER) - LocalArtifact findFirstLocalArtifactsBySHA1(@NotNull String sha1); + Artifact findFirstArtifactBySHA1(@NotNull String sha1); /** * Searches for {@link Artifact} with given file name. * * @param filename * to search for - * @return found List of {@link LocalArtifact}s. + * @return found List of {@link Artifact}s. */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY + SpringEvalExpressions.HAS_AUTH_OR + SpringEvalExpressions.IS_CONTROLLER) - List findLocalArtifactByFilename(@NotNull String filename); + List findArtifactByFilename(@NotNull String filename); /** * Get local artifact for a base software module. @@ -264,38 +202,13 @@ LocalArtifact createLocalArtifact(@NotNull InputStream stream, @NotNull Long mod * Pageable * @param swId * software module id - * @return Page - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Page findLocalArtifactBySoftwareModule(@NotNull Pageable pageReq, @NotNull Long swId); - - /** - * Finds {@link SoftwareModule} by given id. - * - * @param id - * to search for - * @return the found {@link SoftwareModule}s or null if not - * found. - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY + SpringEvalExpressions.HAS_AUTH_OR - + SpringEvalExpressions.IS_CONTROLLER) - SoftwareModule findSoftwareModuleById(@NotNull Long id); - - /** - * Retrieves software module including details ( - * {@link SoftwareModule#getArtifacts()}). - * - * @param id - * parameter - * @param isDeleted - * parameter - * @return the found {@link SoftwareModule}s + * @return Page */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - SoftwareModule findSoftwareModuleWithDetails(@NotNull Long id); + Page findArtifactBySoftwareModule(@NotNull Pageable pageReq, @NotNull Long swId); /** - * Loads {@link DbArtifact} from store for given {@link LocalArtifact}. + * Loads {@link DbArtifact} from store for given {@link Artifact}. * * @param artifact * to search for @@ -306,6 +219,6 @@ LocalArtifact createLocalArtifact(@NotNull InputStream stream, @NotNull Long mod */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DOWNLOAD_ARTIFACT + SpringEvalExpressions.HAS_AUTH_OR + SpringEvalExpressions.HAS_CONTROLLER_DOWNLOAD) - DbArtifact loadLocalArtifactBinary(@NotNull LocalArtifact artifact); + DbArtifact loadArtifactBinary(@NotNull Artifact artifact); } 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 659781460b..ac1d7e201e 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 @@ -24,8 +24,8 @@ import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; +import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.DistributionSet; -import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetInfo; @@ -200,7 +200,7 @@ public interface ControllerManagement { * otherwise {@code false} */ @PreAuthorize(SpringEvalExpressions.IS_CONTROLLER) - boolean hasTargetArtifactAssigned(@NotNull String controllerId, @NotNull LocalArtifact localArtifact); + boolean hasTargetArtifactAssigned(@NotNull String controllerId, @NotNull Artifact localArtifact); /** * Checks if a given target has currently or has even been assigned to the @@ -219,7 +219,7 @@ public interface ControllerManagement { * otherwise {@code false} */ @PreAuthorize(SpringEvalExpressions.IS_CONTROLLER) - boolean hasTargetArtifactAssigned(@NotNull Long targetId, @NotNull LocalArtifact localArtifact); + boolean hasTargetArtifactAssigned(@NotNull Long targetId, @NotNull Artifact localArtifact); /** * Registers retrieved status for given {@link Target} and {@link Action} if diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/EntityFactory.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/EntityFactory.java index c54f00cc63..0bbdcbcee7 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/EntityFactory.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/EntityFactory.java @@ -16,12 +16,12 @@ import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; +import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.BaseEntity; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetMetadata; import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.DistributionSetType; -import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.RolloutGroup; import org.eclipse.hawkbit.repository.model.SoftwareModule; @@ -376,10 +376,10 @@ SoftwareModuleType generateSoftwareModuleType(@NotNull String key, @NotNull Stri TargetTag generateTargetTag(@NotNull String name, String description, String colour); /** - * Generates an empty {@link LocalArtifact} without persisting it. + * Generates an empty {@link Artifact} without persisting it. * - * @return {@link LocalArtifact} object + * @return {@link Artifact} object */ - LocalArtifact generateLocalArtifact(); + Artifact generateArtifact(); } diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java index 2746686a72..6e6b9b87ef 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java @@ -42,12 +42,12 @@ public interface SoftwareManagement { * * @param searchText * to search for in name and version - * @param type - * to filter the result + * @param typeId + * to filter the result by type * @return number of found {@link SoftwareModule}s */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Long countSoftwareModuleByFilters(String searchText, SoftwareModuleType type); + Long countSoftwareModuleByFilters(String searchText, Long typeId); /** * Count all {@link SoftwareModule}s in the repository that are not marked @@ -58,16 +58,6 @@ public interface SoftwareManagement { @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) Long countSoftwareModulesAll(); - /** - * Counts {@link SoftwareModule}s with given {@link SoftwareModuleType}. - * - * @param type - * to count - * @return number of found {@link SoftwareModule}s - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Long countSoftwareModulesByType(@NotNull SoftwareModuleType type); - /** * @return number of {@link SoftwareModuleType}s in the repository. */ @@ -146,31 +136,31 @@ public interface SoftwareManagement { /** * Deletes the given {@link SoftwareModule} {@link Entity}. * - * @param bsm + * @param moduleId * is the {@link SoftwareModule} to be deleted */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY) - void deleteSoftwareModule(@NotNull SoftwareModule bsm); + void deleteSoftwareModule(@NotNull Long moduleId); /** * deletes a software module meta data entry. * - * @param softwareModule + * @param moduleId * where meta data has to be deleted * @param key * of the metda data element */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) - void deleteSoftwareModuleMetadata(@NotNull SoftwareModule softwareModule, @NotEmpty String key); + void deleteSoftwareModuleMetadata(@NotNull Long moduleId, @NotEmpty String key); /** * Deletes {@link SoftwareModule}s which is any if the given ids. * - * @param ids + * @param moduleIds * of the Software Modules to be deleted */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY) - void deleteSoftwareModules(@NotNull Collection ids); + void deleteSoftwareModules(@NotNull Collection moduleIds); /** * Deletes or marks as delete in case the type is in use. @@ -192,20 +182,6 @@ public interface SoftwareManagement { @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) Page findSoftwareModuleByAssignedTo(@NotNull Pageable pageable, @NotNull DistributionSet set); - /** - * @param pageable - * the page request to page the result set - * @param set - * to search for - * @param type - * to filter - * @return all {@link SoftwareModule}s that are assigned to given - * {@link DistributionSet} filtered by {@link SoftwareModuleType}. - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Page findSoftwareModuleByAssignedToAndType(@NotNull Pageable pageable, @NotNull DistributionSet set, - @NotNull SoftwareModuleType type); - /** * Filter {@link SoftwareModule}s with given * {@link SoftwareModule#getName()} or {@link SoftwareModule#getVersion()} @@ -215,13 +191,12 @@ Page findSoftwareModuleByAssignedToAndType(@NotNull Pageable pag * page parameter * @param searchText * to be filtered as "like" on {@link SoftwareModule#getName()} - * @param type + * @param typeId * to be filtered as "like" on {@link SoftwareModule#getType()} * @return the page of found {@link SoftwareModule} */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Slice findSoftwareModuleByFilters(@NotNull Pageable pageable, String searchText, - SoftwareModuleType type); + Slice findSoftwareModuleByFilters(@NotNull Pageable pageable, String searchText, Long typeId); /** * Finds {@link SoftwareModule} by given id. @@ -253,7 +228,7 @@ SoftwareModule findSoftwareModuleByNameAndVersion(@NotEmpty String name, @NotEmp /** * finds a single software module meta data by its id. * - * @param softwareModule + * @param moduleId * where meta data has to be found * @param key * of the meta data element @@ -262,7 +237,7 @@ SoftwareModule findSoftwareModuleByNameAndVersion(@NotEmpty String name, @NotEmp * in case the meta data does not exists for the given key */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - SoftwareModuleMetadata findSoftwareModuleMetadata(@NotNull SoftwareModule softwareModule, @NotEmpty String key); + SoftwareModuleMetadata findSoftwareModuleMetadata(@NotNull Long moduleId, @NotEmpty String key); /** * finds all meta data by the given software module id. @@ -316,14 +291,13 @@ Page findSoftwareModuleMetadataBySoftwareModuleId(@NotNu * the ID of distribution set to be ordered on top * @param searchText * filtered as "like" on {@link SoftwareModule#getName()} - * @param type + * @param typeId * filtered as "equal" on {@link SoftwareModule#getType()} * @return the page of found {@link SoftwareModule} */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) Slice findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc( - @NotNull Pageable pageable, @NotNull Long orderByDistributionId, String searchText, - SoftwareModuleType type); + @NotNull Pageable pageable, @NotNull Long orderByDistributionId, String searchText, Long typeId); /** * Retrieves all software modules. Deleted ones are filtered. @@ -370,12 +344,12 @@ Slice findSoftwareModuleOrderBySetAssignmentAndModuleNam * * @param pageable * page parameters - * @param type + * @param typeId * to be filtered on * @return the found {@link SoftwareModule}s */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Slice findSoftwareModulesByType(@NotNull Pageable pageable, @NotNull SoftwareModuleType type); + Slice findSoftwareModulesByType(@NotNull Pageable pageable, @NotNull Long typeId); /** * diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Artifact.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Artifact.java index e0a142b434..c83f7c1ee5 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Artifact.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/Artifact.java @@ -17,6 +17,10 @@ * */ public interface Artifact extends TenantAwareBaseEntity { + /** + * @return the filename that was provided during upload. + */ + String getFilename(); /** * @return {@link SoftwareModule} this {@link Artifact} belongs to. diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifact.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifact.java deleted file mode 100644 index 7e1a965e77..0000000000 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/ExternalArtifact.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.model; - -import java.net.URL; - -/** - * External artifact representation with all the necessary information to - * generate an artifact {@link URL} at runtime. - * - */ -public interface ExternalArtifact extends Artifact { - - /** - * @return {@link ExternalArtifactProvider} of this {@link Artifact}. - */ - ExternalArtifactProvider getExternalArtifactProvider(); - - /** - * @return generated download {@link URL}. - */ - String getUrl(); - - /** - * @return suffix for {@link URL} generation. - */ - String getUrlSuffix(); - - /** - * @param urlSuffix - * the urlSuffix to set - */ - void setUrlSuffix(String urlSuffix); - -} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/LocalArtifact.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/LocalArtifact.java deleted file mode 100644 index 9aeb791c4e..0000000000 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/LocalArtifact.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.model; - -import org.eclipse.hawkbit.artifact.repository.ArtifactRepository; - -/** - * Tenant specific locally stored artifact representation that is used by - * {@link SoftwareModule}s . It contains all information that is provided by the - * user while all update server generated information related to the artifact - * (hash, length) is stored directly with the binary itself in the - * {@link ArtifactRepository}. - * - */ -public interface LocalArtifact extends Artifact { - - /** - * @return the filename that was provided during upload. - */ - String getFilename(); - -} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModule.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModule.java index e3bf1468f1..002adf4939 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModule.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModule.java @@ -21,38 +21,40 @@ public interface SoftwareModule extends NamedVersionedEntity { * @param artifact * is added to the assigned {@link Artifact}s. */ - void addArtifact(LocalArtifact artifact); - - /** - * @param artifact - * is added to the assigned {@link Artifact}s. - */ - void addArtifact(ExternalArtifact artifact); + void addArtifact(Artifact artifact); /** * @param artifactId * to look for * @return found {@link Artifact} */ - Optional getLocalArtifact(Long artifactId); + default Optional getArtifact(final Long artifactId) { + if (getArtifacts().isEmpty()) { + return Optional.empty(); + } + + return getArtifacts().stream().filter(artifact -> artifact.getId().equals(artifactId)).findFirst(); + } /** * @param fileName * to look for * @return found {@link Artifact} */ - Optional getLocalArtifactByFilename(String fileName); + default Optional getArtifactByFilename(final String fileName) { + if (getArtifacts().isEmpty()) { + return Optional.empty(); + } + + return getArtifacts().stream().filter(artifact -> artifact.getFilename().equalsIgnoreCase(fileName.trim())) + .findFirst(); + } /** * @return immutable list of all artifacts */ List getArtifacts(); - /** - * @return immutable list of local artifacts only - */ - List getLocalArtifacts(); - /** * @return the vendor of this software module */ @@ -66,15 +68,9 @@ public interface SoftwareModule extends NamedVersionedEntity { /** * @param artifact - * is removed from the assigned {@link LocalArtifact}s. - */ - void removeArtifact(LocalArtifact artifact); - - /** - * @param artifact - * is removed from the assigned {@link ExternalArtifact}s. + * is removed from the assigned {@link Artifact}s. */ - void removeArtifact(ExternalArtifact artifact); + void removeArtifact(Artifact artifact); /** * @return the type of the software module diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/ExternalArtifactProviderRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/ExternalArtifactProviderRepository.java deleted file mode 100644 index 039c4917e4..0000000000 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/ExternalArtifactProviderRepository.java +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.jpa; - -import org.eclipse.hawkbit.repository.jpa.model.JpaExternalArtifactProvider; -import org.eclipse.hawkbit.repository.model.ExternalArtifactProvider; -import org.springframework.transaction.annotation.Isolation; -import org.springframework.transaction.annotation.Transactional; - -/** - * Repository for {@link ExternalArtifactProvider}. - * - */ -@Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) -public interface ExternalArtifactProviderRepository extends BaseEntityRepository { - -} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/ExternalArtifactRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/ExternalArtifactRepository.java deleted file mode 100644 index 5845afbee0..0000000000 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/ExternalArtifactRepository.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.jpa; - -import org.eclipse.hawkbit.repository.jpa.model.JpaExternalArtifact; -import org.eclipse.hawkbit.repository.model.ExternalArtifact; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; -import org.springframework.transaction.annotation.Isolation; -import org.springframework.transaction.annotation.Transactional; - -/** - * {@link ExternalArtifact} repository. - * - */ -@Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) -public interface ExternalArtifactRepository extends BaseEntityRepository { - - /** - * Searches for external artifact for a base software module. - * - * @param pageReq - * Pageable - * @param swId - * software module id - * - * @return Page - */ - Page findBySoftwareModuleId(Pageable pageReq, final Long swId); - -} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaArtifactManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaArtifactManagement.java index 9414470476..92623fb7bf 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaArtifactManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaArtifactManagement.java @@ -24,21 +24,15 @@ import org.eclipse.hawkbit.repository.exception.GridFSDBFileNotFoundException; import org.eclipse.hawkbit.repository.exception.InvalidMD5HashException; import org.eclipse.hawkbit.repository.exception.InvalidSHA1HashException; -import org.eclipse.hawkbit.repository.jpa.model.JpaExternalArtifact; -import org.eclipse.hawkbit.repository.jpa.model.JpaExternalArtifactProvider; -import org.eclipse.hawkbit.repository.jpa.model.JpaLocalArtifact; +import org.eclipse.hawkbit.repository.jpa.model.JpaArtifact; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; -import org.eclipse.hawkbit.repository.jpa.specifications.SoftwareModuleSpecification; -import org.eclipse.hawkbit.repository.model.ExternalArtifact; -import org.eclipse.hawkbit.repository.model.ExternalArtifactProvider; -import org.eclipse.hawkbit.repository.model.LocalArtifact; +import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; -import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.repository.Modifying; import org.springframework.transaction.annotation.Isolation; import org.springframework.transaction.annotation.Transactional; @@ -57,24 +51,18 @@ public class JpaArtifactManagement implements ArtifactManagement { @Autowired private LocalArtifactRepository localArtifactRepository; - @Autowired - private ExternalArtifactRepository externalArtifactRepository; - @Autowired private SoftwareModuleRepository softwareModuleRepository; - @Autowired - private ExternalArtifactProviderRepository externalArtifactProviderRepository; - @Autowired private ArtifactRepository artifactRepository; - private static LocalArtifact checkForExistingArtifact(final String filename, final boolean overrideExisting, + private static Artifact checkForExistingArtifact(final String filename, final boolean overrideExisting, final SoftwareModule softwareModule) { - if (softwareModule.getLocalArtifactByFilename(filename).isPresent()) { + if (softwareModule.getArtifactByFilename(filename).isPresent()) { if (overrideExisting) { LOG.debug("overriding existing artifact with new filename {}", filename); - return softwareModule.getLocalArtifactByFilename(filename).get(); + return softwareModule.getArtifactByFilename(filename).get(); } else { throw new EntityAlreadyExistsException("File with that name already exists in the Software Module"); } @@ -85,33 +73,14 @@ private static LocalArtifact checkForExistingArtifact(final String filename, fin @Override @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) - public ExternalArtifact createExternalArtifact(final ExternalArtifactProvider externalRepository, - final String urlSuffix, final Long moduleId) { - - final SoftwareModule module = getModuleAndThrowExceptionIfThatFails(moduleId); - return externalArtifactRepository.save(new JpaExternalArtifact(externalRepository, urlSuffix, module)); - } - - @Override - @Modifying - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - public ExternalArtifactProvider createExternalArtifactProvider(final String name, final String description, - final String basePath, final String defaultUrlSuffix) { - return externalArtifactProviderRepository - .save(new JpaExternalArtifactProvider(name, description, basePath, defaultUrlSuffix)); - } - - @Override - @Modifying - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - public LocalArtifact createLocalArtifact(final InputStream stream, final Long moduleId, final String filename, + public Artifact createArtifact(final InputStream stream, final Long moduleId, final String filename, final String providedMd5Sum, final String providedSha1Sum, final boolean overrideExisting, final String contentType) { DbArtifact result = null; final SoftwareModule softwareModule = getModuleAndThrowExceptionIfThatFails(moduleId); - final LocalArtifact existing = checkForExistingArtifact(filename, overrideExisting, softwareModule); + final Artifact existing = checkForExistingArtifact(filename, overrideExisting, softwareModule); try { result = artifactRepository.store(stream, filename, contentType, @@ -135,25 +104,10 @@ public LocalArtifact createLocalArtifact(final InputStream stream, final Long mo @Override @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) - public void deleteExternalArtifact(final Long id) { - final ExternalArtifact existing = externalArtifactRepository.findOne(id); - - if (null == existing) { - return; - } - - existing.getSoftwareModule().removeArtifact(existing); - softwareModuleRepository.save((JpaSoftwareModule) existing.getSoftwareModule()); - externalArtifactRepository.delete(id); - } - - @Override - @Modifying - @Transactional(isolation = Isolation.READ_UNCOMMITTED) - public boolean clearLocalArtifactBinary(final LocalArtifact existing) { + public boolean clearArtifactBinary(final Artifact existing) { - for (final LocalArtifact lArtifact : localArtifactRepository - .findByGridFsFileName(((JpaLocalArtifact) existing).getGridFsFileName())) { + for (final Artifact lArtifact : localArtifactRepository + .findByGridFsFileName(((JpaArtifact) existing).getGridFsFileName())) { if (!lArtifact.getSoftwareModule().isDeleted() && Long.compare(lArtifact.getSoftwareModule().getId(), existing.getSoftwareModule().getId()) != 0) { return false; @@ -161,8 +115,8 @@ public boolean clearLocalArtifactBinary(final LocalArtifact existing) { } try { - LOG.debug("deleting artifact from repository {}", ((JpaLocalArtifact) existing).getGridFsFileName()); - artifactRepository.deleteBySha1(((JpaLocalArtifact) existing).getGridFsFileName()); + LOG.debug("deleting artifact from repository {}", ((JpaArtifact) existing).getGridFsFileName()); + artifactRepository.deleteBySha1(((JpaArtifact) existing).getGridFsFileName()); return true; } catch (final ArtifactStoreException e) { throw new ArtifactDeleteFailedException(e); @@ -172,14 +126,14 @@ public boolean clearLocalArtifactBinary(final LocalArtifact existing) { @Override @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) - public void deleteLocalArtifact(final Long id) { - final JpaLocalArtifact existing = localArtifactRepository.findOne(id); + public void deleteArtifact(final Long id) { + final JpaArtifact existing = localArtifactRepository.findOne(id); if (null == existing) { return; } - clearLocalArtifactBinary(existing); + clearArtifactBinary(existing); existing.getSoftwareModule().removeArtifact(existing); softwareModuleRepository.save((JpaSoftwareModule) existing.getSoftwareModule()); @@ -187,74 +141,45 @@ public void deleteLocalArtifact(final Long id) { } @Override - public LocalArtifact findLocalArtifact(final Long id) { + public Artifact findArtifact(final Long id) { return localArtifactRepository.findOne(id); } @Override - public List findByFilenameAndSoftwareModule(final String filename, final Long softwareModuleId) { + public List findByFilenameAndSoftwareModule(final String filename, final Long softwareModuleId) { return localArtifactRepository.findByFilenameAndSoftwareModuleId(filename, softwareModuleId); } @Override - public LocalArtifact findFirstLocalArtifactsBySHA1(final String sha1) { + public Artifact findFirstArtifactBySHA1(final String sha1) { return localArtifactRepository.findFirstByGridFsFileName(sha1); } @Override - public List findLocalArtifactByFilename(final String filename) { + public List findArtifactByFilename(final String filename) { return localArtifactRepository.findByFilename(filename); } @Override - public Page findLocalArtifactBySoftwareModule(final Pageable pageReq, final Long swId) { + public Page findArtifactBySoftwareModule(final Pageable pageReq, final Long swId) { return localArtifactRepository.findBySoftwareModuleId(pageReq, swId); } @Override - public SoftwareModule findSoftwareModuleById(final Long id) { - - final Specification spec = SoftwareModuleSpecification.byId(id); - - return softwareModuleRepository.findOne(spec); - } - - @Override - public SoftwareModule findSoftwareModuleWithDetails(final Long id) { - final SoftwareModule result = findSoftwareModuleById(id); - if (result != null) { - result.getArtifacts().size(); - } - - return result; - } - - private SoftwareModule getModuleAndThrowExceptionIfThatFails(final Long moduleId) { - final SoftwareModule softwareModule = findSoftwareModuleWithDetails(moduleId); - - if (softwareModule == null) { - LOG.debug("no software module with ID {} exists", moduleId); - throw new EntityNotFoundException("Software Module: " + moduleId); - } - return softwareModule; - } - - @Override - public DbArtifact loadLocalArtifactBinary(final LocalArtifact artifact) { - final DbArtifact result = artifactRepository - .getArtifactBySha1(((JpaLocalArtifact) artifact).getGridFsFileName()); + public DbArtifact loadArtifactBinary(final Artifact artifact) { + final DbArtifact result = artifactRepository.getArtifactBySha1(((JpaArtifact) artifact).getGridFsFileName()); if (result == null) { - throw new GridFSDBFileNotFoundException(((JpaLocalArtifact) artifact).getGridFsFileName()); + throw new GridFSDBFileNotFoundException(((JpaArtifact) artifact).getGridFsFileName()); } return result; } - private LocalArtifact storeArtifactMetadata(final SoftwareModule softwareModule, final String providedFilename, - final DbArtifact result, final LocalArtifact existing) { - JpaLocalArtifact artifact = (JpaLocalArtifact) existing; + private Artifact storeArtifactMetadata(final SoftwareModule softwareModule, final String providedFilename, + final DbArtifact result, final Artifact existing) { + JpaArtifact artifact = (JpaArtifact) existing; if (existing == null) { - artifact = new JpaLocalArtifact(result.getHashes().getSha1(), providedFilename, softwareModule); + artifact = new JpaArtifact(result.getHashes().getSha1(), providedFilename, softwareModule); } artifact.setMd5Hash(result.getHashes().getMd5()); artifact.setSha1Hash(result.getHashes().getSha1()); @@ -267,26 +192,32 @@ private LocalArtifact storeArtifactMetadata(final SoftwareModule softwareModule, @Override @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) - public LocalArtifact createLocalArtifact(final InputStream inputStream, final Long moduleId, final String filename, + public Artifact createArtifact(final InputStream inputStream, final Long moduleId, final String filename, final boolean overrideExisting) { - return createLocalArtifact(inputStream, moduleId, filename, null, null, overrideExisting, null); + return createArtifact(inputStream, moduleId, filename, null, null, overrideExisting, null); } @Override @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) - public LocalArtifact createLocalArtifact(final InputStream inputStream, final Long moduleId, final String filename, + public Artifact createArtifact(final InputStream inputStream, final Long moduleId, final String filename, final boolean overrideExisting, final String contentType) { - return createLocalArtifact(inputStream, moduleId, filename, null, null, overrideExisting, contentType); + return createArtifact(inputStream, moduleId, filename, null, null, overrideExisting, contentType); } @Override - public Long countLocalArtifactsAll() { + public Long countArtifactsAll() { return localArtifactRepository.count(); } - @Override - public Long countExternalArtifactsAll() { - return externalArtifactRepository.count(); + private SoftwareModule getModuleAndThrowExceptionIfThatFails(final Long moduleId) { + final SoftwareModule softwareModule = softwareModuleRepository.findOne(moduleId); + + if (softwareModule == null) { + LOG.debug("no software module with ID {} exists", moduleId); + throw new EntityNotFoundException("Software Module: " + moduleId); + } + return softwareModule; } + } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java index 5d7dbdc0bc..8d539e0d84 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java @@ -41,8 +41,8 @@ import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; +import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.DistributionSet; -import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetInfo; @@ -150,7 +150,7 @@ public Action getActionForDownloadByTargetAndSoftwareModule(final String control } @Override - public boolean hasTargetArtifactAssigned(final String controllerId, final LocalArtifact localArtifact) { + public boolean hasTargetArtifactAssigned(final String controllerId, final Artifact localArtifact) { final Target target = targetRepository.findByControllerId(controllerId); if (target == null) { return false; @@ -159,7 +159,7 @@ public boolean hasTargetArtifactAssigned(final String controllerId, final LocalA } @Override - public boolean hasTargetArtifactAssigned(final Long targetId, final LocalArtifact localArtifact) { + public boolean hasTargetArtifactAssigned(final Long targetId, final Artifact localArtifact) { final Target target = targetRepository.findOne(targetId); if (target == null) { return false; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaEntityFactory.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaEntityFactory.java index d09606df2d..d2d66d4840 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaEntityFactory.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaEntityFactory.java @@ -14,11 +14,11 @@ import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.jpa.model.JpaAction; import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus; +import org.eclipse.hawkbit.repository.jpa.model.JpaArtifact; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetMetadata; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType; -import org.eclipse.hawkbit.repository.jpa.model.JpaLocalArtifact; import org.eclipse.hawkbit.repository.jpa.model.JpaRollout; import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; @@ -30,11 +30,11 @@ import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; +import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetMetadata; import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.DistributionSetType; -import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.RolloutGroup; import org.eclipse.hawkbit.repository.model.SoftwareModule; @@ -135,12 +135,13 @@ public TargetFilterQuery generateTargetFilterQuery() { } @Override - public TargetFilterQuery generateTargetFilterQuery(String name, String query) { + public TargetFilterQuery generateTargetFilterQuery(final String name, final String query) { return new JpaTargetFilterQuery(name, query); } @Override - public TargetFilterQuery generateTargetFilterQuery(String name, String query, DistributionSet autoAssignDS) { + public TargetFilterQuery generateTargetFilterQuery(final String name, final String query, + final DistributionSet autoAssignDS) { return new JpaTargetFilterQuery(name, query, (JpaDistributionSet) autoAssignDS); } @@ -220,8 +221,8 @@ public ActionStatus generateActionStatus(final Action action, final Status statu } @Override - public LocalArtifact generateLocalArtifact() { - return new JpaLocalArtifact(); + public Artifact generateArtifact() { + return new JpaArtifact(); } } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java index a20e17f1de..69b068b6ac 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java @@ -45,15 +45,15 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule_; import org.eclipse.hawkbit.repository.jpa.model.SwMetadataCompositeKey; import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility; -import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer; import org.eclipse.hawkbit.repository.jpa.specifications.SoftwareModuleSpecification; import org.eclipse.hawkbit.repository.jpa.specifications.SpecificationsBuilder; +import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.AssignedSoftwareModule; import org.eclipse.hawkbit.repository.model.DistributionSet; -import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; +import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.AuditorAware; import org.springframework.data.domain.Page; @@ -178,11 +178,11 @@ public List createSoftwareModule(final Collection findSoftwareModulesByType(final Pageable pageable, final SoftwareModuleType type) { + public Slice findSoftwareModulesByType(final Pageable pageable, final Long typeId) { final List> specList = new LinkedList<>(); - Specification spec = SoftwareModuleSpecification.equalType((JpaSoftwareModuleType) type); + Specification spec = SoftwareModuleSpecification.equalType(typeId); specList.add(spec); spec = SoftwareModuleSpecification.isDeletedFalse(); @@ -205,23 +205,11 @@ private static Page convertSmMdPage(final Page(Collections.unmodifiableList(findAll.getContent()), pageable, findAll.getTotalElements()); } - @Override - public Long countSoftwareModulesByType(final SoftwareModuleType type) { - - final List> specList = new ArrayList<>(2); - - Specification spec = SoftwareModuleSpecification.equalType((JpaSoftwareModuleType) type); - specList.add(spec); - - spec = SoftwareModuleSpecification.isDeletedFalse(); - specList.add(spec); - - return countSwModuleByCriteriaAPI(specList); - } - @Override public SoftwareModule findSoftwareModuleById(final Long id) { - return artifactManagement.findSoftwareModuleById(id); + final Specification spec = SoftwareModuleSpecification.byId(id); + + return softwareModuleRepository.findOne(spec); } @Override @@ -246,8 +234,8 @@ private Long countSwModuleByCriteriaAPI(final List findSoftwareModulesById(final Collection ids) @Override public Slice findSoftwareModuleByFilters(final Pageable pageable, final String searchText, - final SoftwareModuleType type) { + final Long typeId) { final List> specList = new ArrayList<>(4); @@ -356,8 +349,8 @@ public Slice findSoftwareModuleByFilters(final Pageable pageable specList.add(spec); } - if (null != type) { - spec = SoftwareModuleSpecification.equalType((JpaSoftwareModuleType) type); + if (null != typeId) { + spec = SoftwareModuleSpecification.equalType(typeId); specList.add(spec); } @@ -375,9 +368,7 @@ public Slice findSoftwareModuleByFilters(final Pageable pageable @Override public Slice findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc( - final Pageable pageable, final Long orderByDistributionId, final String searchText, - final SoftwareModuleType ty) { - final JpaSoftwareModuleType type = (JpaSoftwareModuleType) ty; + final Pageable pageable, final Long orderByDistributionId, final String searchText, final Long typeId) { final List resultList = new ArrayList<>(); final int pageSize = pageable.getPageSize(); @@ -391,7 +382,7 @@ public Slice findSoftwareModuleOrderBySetAssignmentAndMo .join(JpaSoftwareModule_.assignedTo); // build the specifications and then to predicates necessary by the // given filters - final Predicate[] specPredicate = specificationsToPredicate(buildSpecificationList(searchText, type), + final Predicate[] specPredicate = specificationsToPredicate(buildSpecificationList(searchText, typeId), assignedRoot, assignedQuery, cb, cb.equal(assignedDsJoin.get(JpaDistributionSet_.id), orderByDistributionId)); // if we have some predicates then add it to the where clause of the @@ -422,11 +413,11 @@ public Slice findSoftwareModuleOrderBySetAssignmentAndMo Predicate[] unassignedSpec; if (!assignedSoftwareModules.isEmpty()) { - unassignedSpec = specificationsToPredicate(buildSpecificationList(searchText, type), unassignedRoot, + unassignedSpec = specificationsToPredicate(buildSpecificationList(searchText, typeId), unassignedRoot, unassignedQuery, cb, cb.not(unassignedRoot.get(JpaSoftwareModule_.id) .in(assignedSoftwareModules.stream().map(sw -> sw.getId()).collect(Collectors.toList())))); } else { - unassignedSpec = specificationsToPredicate(buildSpecificationList(searchText, type), unassignedRoot, + unassignedSpec = specificationsToPredicate(buildSpecificationList(searchText, typeId), unassignedRoot, unassignedQuery, cb); } @@ -443,13 +434,13 @@ public Slice findSoftwareModuleOrderBySetAssignmentAndMo } private static List> buildSpecificationList(final String searchText, - final JpaSoftwareModuleType type) { + final Long typeId) { final List> specList = new ArrayList<>(3); if (!Strings.isNullOrEmpty(searchText)) { specList.add(SoftwareModuleSpecification.likeNameOrVersion(searchText)); } - if (type != null) { - specList.add(SoftwareModuleSpecification.equalType(type)); + if (typeId != null) { + specList.add(SoftwareModuleSpecification.equalType(typeId)); } specList.add(SoftwareModuleSpecification.isDeletedFalse()); return specList; @@ -464,7 +455,7 @@ private Predicate[] specificationsToPredicate(final List> specList = new ArrayList<>(3); @@ -476,8 +467,8 @@ public Long countSoftwareModuleByFilters(final String searchText, final Software specList.add(spec); } - if (null != type) { - spec = SoftwareModuleSpecification.equalType((JpaSoftwareModuleType) type); + if (null != typeId) { + spec = SoftwareModuleSpecification.equalType(typeId); specList.add(spec); } @@ -541,13 +532,6 @@ public Page findSoftwareModuleByAssignedTo(final Pageable pageab return softwareModuleRepository.findByAssignedTo(pageable, (JpaDistributionSet) set); } - @Override - public Page findSoftwareModuleByAssignedToAndType(final Pageable pageable, - final DistributionSet set, final SoftwareModuleType type) { - return softwareModuleRepository.findByAssignedToAndType(pageable, (JpaDistributionSet) set, - (JpaSoftwareModuleType) type); - } - @Override @Transactional(isolation = Isolation.READ_UNCOMMITTED) @Modifying @@ -597,8 +581,8 @@ public SoftwareModuleMetadata updateSoftwareModuleMetadata(final SoftwareModuleM @Override @Transactional(isolation = Isolation.READ_UNCOMMITTED) @Modifying - public void deleteSoftwareModuleMetadata(final SoftwareModule softwareModule, final String key) { - softwareModuleMetadataRepository.delete(new SwMetadataCompositeKey(softwareModule, key)); + public void deleteSoftwareModuleMetadata(final Long moduleId, final String key) { + softwareModuleMetadataRepository.delete(new SwMetadataCompositeKey(moduleId, key)); } @Override @@ -635,8 +619,8 @@ public List findSoftwareModuleMetadataBySoftwareModuleId } @Override - public SoftwareModuleMetadata findSoftwareModuleMetadata(final SoftwareModule softwareModule, final String key) { - return findSoftwareModuleMetadata(new SwMetadataCompositeKey(softwareModule, key)); + public SoftwareModuleMetadata findSoftwareModuleMetadata(final Long moduleId, final String key) { + return findSoftwareModuleMetadata(new SwMetadataCompositeKey(moduleId, key)); } private SoftwareModuleMetadata findSoftwareModuleMetadata(final SwMetadataCompositeKey id) { @@ -661,8 +645,8 @@ private static void throwMetadataKeyAlreadyExists(final String metadataKey) { @Override @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) - public void deleteSoftwareModule(final SoftwareModule bsm) { - deleteSoftwareModules(Sets.newHashSet(bsm.getId())); + public void deleteSoftwareModule(final Long moduleId) { + deleteSoftwareModules(Sets.newHashSet(moduleId)); } @Override diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java index a8c3f18601..34afd0c8f5 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java @@ -83,15 +83,9 @@ public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, Syst @Autowired private DistributionSetTagRepository distributionSetTagRepository; - @Autowired - private ExternalArtifactRepository externalArtifactRepository; - @Autowired private LocalArtifactRepository artifactRepository; - @Autowired - private ExternalArtifactProviderRepository externalArtifactProviderRepository; - @Autowired private TenantConfigurationRepository tenantConfigurationRepository; @@ -229,8 +223,6 @@ public void deleteTenant(final String tenant) { rolloutGroupRepository.deleteByTenantIgnoreCase(tenant); rolloutRepository.deleteByTenantIgnoreCase(tenant); artifactRepository.deleteByTenantIgnoreCase(tenant); - externalArtifactRepository.deleteByTenantIgnoreCase(tenant); - externalArtifactProviderRepository.deleteByTenantIgnoreCase(tenant); targetTagRepository.deleteByTenantIgnoreCase(tenant); distributionSetTagRepository.deleteByTenantIgnoreCase(tenant); distributionSetRepository.deleteByTenantIgnoreCase(tenant); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/LocalArtifactRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/LocalArtifactRepository.java index e6eb62a271..53720e79d3 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/LocalArtifactRepository.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/LocalArtifactRepository.java @@ -11,8 +11,8 @@ import java.util.List; import java.util.Optional; -import org.eclipse.hawkbit.repository.jpa.model.JpaLocalArtifact; -import org.eclipse.hawkbit.repository.model.LocalArtifact; +import org.eclipse.hawkbit.repository.jpa.model.JpaArtifact; +import org.eclipse.hawkbit.repository.model.Artifact; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.Query; @@ -20,11 +20,11 @@ import org.springframework.transaction.annotation.Transactional; /** - * {@link LocalArtifact} repository. + * {@link Artifact} repository. * */ @Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) -public interface LocalArtifactRepository extends BaseEntityRepository { +public interface LocalArtifactRepository extends BaseEntityRepository { /** * Counts artifacts size where the related software module is not @@ -32,7 +32,7 @@ public interface LocalArtifactRepository extends BaseEntityRepository getSumOfUndeletedArtifactSize(); /** @@ -46,32 +46,31 @@ public interface LocalArtifactRepository extends BaseEntityRepository findByGridFsFileName(String gridFsFileName); + List findByGridFsFileName(String gridFsFileName); /** - * Searches for a {@link LocalArtifact} based on given gridFsFileName. + * Searches for a {@link Artifact} based on given gridFsFileName. * * @param gridFsFileName * to search - * @return {@link LocalArtifact} the first in the result list + * @return {@link Artifact} the first in the result list */ - JpaLocalArtifact findFirstByGridFsFileName(String gridFsFileName); + JpaArtifact findFirstByGridFsFileName(String gridFsFileName); /** - * Searches for a {@link LocalArtifact} based user provided filename at - * upload. + * Searches for a {@link Artifact} based user provided filename at upload. * * @param filename * to search - * @return list of {@link LocalArtifact}. + * @return list of {@link Artifact}. */ - List findByFilename(String filename); + List findByFilename(String filename); /** * Searches for local artifact for a base software module. @@ -81,20 +80,20 @@ public interface LocalArtifactRepository extends BaseEntityRepository + * @return Page */ - Page findBySoftwareModuleId(Pageable pageReq, final Long swId); + Page findBySoftwareModuleId(Pageable pageReq, final Long swId); /** - * Searches for a {@link LocalArtifact} based user provided filename at - * upload and selected software module id. + * Searches for a {@link Artifact} based user provided filename at upload + * and selected software module id. * * @param filename * to search * @param softwareModuleId * selected software module id - * @return list of {@link LocalArtifact}. + * @return list of {@link Artifact}. */ - List findByFilenameAndSoftwareModuleId(final String filename, final Long softwareModuleId); + List findByFilenameAndSoftwareModuleId(final String filename, final Long softwareModuleId); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleRepository.java index 08c84b349c..de6e437a31 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleRepository.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleRepository.java @@ -107,7 +107,7 @@ void deleteSoftwareModule(@Param("lastModifiedAt") Long modifiedAt, @Param("last * @return all {@link SoftwareModule}s that are assigned to given * {@link DistributionSet} filtered by {@link SoftwareModuleType}. */ - Page findByAssignedToAndType(Pageable pageable, JpaDistributionSet set, JpaSoftwareModuleType type); + Page findByAssignedToAndType(Pageable pageable, JpaDistributionSet set, SoftwareModuleType type); /** * retrieves all software modules with a given {@link SoftwareModuleType} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaArtifact.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaArtifact.java deleted file mode 100644 index 1cf6921a4a..0000000000 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaArtifact.java +++ /dev/null @@ -1,66 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.jpa.model; - -import javax.persistence.Column; -import javax.persistence.MappedSuperclass; - -import org.eclipse.hawkbit.repository.model.Artifact; -import org.eclipse.hawkbit.repository.model.SoftwareModule; - -/** - * Tenant specific locally stored artifact representation that is used by - * {@link SoftwareModule}. - */ -@MappedSuperclass -// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for -// sub entities -@SuppressWarnings("squid:S2160") -public abstract class AbstractJpaArtifact extends AbstractJpaTenantAwareBaseEntity implements Artifact { - private static final long serialVersionUID = 1L; - - @Column(name = "sha1_hash", length = 40, nullable = true) - private String sha1Hash; - - @Column(name = "md5_hash", length = 32, nullable = true) - private String md5Hash; - - @Column(name = "file_size") - private long size; - - @Override - public abstract SoftwareModule getSoftwareModule(); - - @Override - public String getMd5Hash() { - return md5Hash; - } - - @Override - public String getSha1Hash() { - return sha1Hash; - } - - public void setMd5Hash(final String md5Hash) { - this.md5Hash = md5Hash; - } - - public void setSha1Hash(final String sha1Hash) { - this.sha1Hash = sha1Hash; - } - - @Override - public long getSize() { - return size; - } - - public void setSize(final long size) { - this.size = size; - } -} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaLocalArtifact.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaArtifact.java similarity index 75% rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaLocalArtifact.java rename to hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaArtifact.java index 46482715df..13be80d710 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaLocalArtifact.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaArtifact.java @@ -20,7 +20,7 @@ import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; -import org.eclipse.hawkbit.repository.model.LocalArtifact; +import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; import com.mongodb.gridfs.GridFS; @@ -36,7 +36,7 @@ // exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for // sub entities @SuppressWarnings("squid:S2160") -public class JpaLocalArtifact extends AbstractJpaArtifact implements LocalArtifact { +public class JpaArtifact extends AbstractJpaTenantAwareBaseEntity implements Artifact { private static final long serialVersionUID = 1L; @NotNull @@ -53,10 +53,19 @@ public class JpaLocalArtifact extends AbstractJpaArtifact implements LocalArtifa @JoinColumn(name = "software_module", nullable = false, updatable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_assigned_sm")) private JpaSoftwareModule softwareModule; + @Column(name = "sha1_hash", length = 40, nullable = true) + private String sha1Hash; + + @Column(name = "md5_hash", length = 32, nullable = true) + private String md5Hash; + + @Column(name = "file_size") + private long size; + /** * Default constructor. */ - public JpaLocalArtifact() { + public JpaArtifact() { super(); } @@ -70,7 +79,7 @@ public JpaLocalArtifact() { * @param softwareModule * of this artifact */ - public JpaLocalArtifact(@NotNull final String gridFsFileName, @NotNull final String filename, + public JpaArtifact(@NotNull final String gridFsFileName, @NotNull final String filename, final SoftwareModule softwareModule) { setSoftwareModule(softwareModule); this.gridFsFileName = gridFsFileName; @@ -78,23 +87,30 @@ public JpaLocalArtifact(@NotNull final String gridFsFileName, @NotNull final Str } @Override - public int hashCode() { // NOSONAR - as this is generated - final int prime = 31; - int result = super.hashCode(); - result = prime * result + this.getClass().getName().hashCode(); - return result; + public String getMd5Hash() { + return md5Hash; + } + + @Override + public String getSha1Hash() { + return sha1Hash; + } + + public void setMd5Hash(final String md5Hash) { + this.md5Hash = md5Hash; + } + + public void setSha1Hash(final String sha1Hash) { + this.sha1Hash = sha1Hash; } @Override - public boolean equals(final Object obj) { // NOSONAR - as this is generated - if (!super.equals(obj)) { - return false; - } - if (!(obj instanceof LocalArtifact)) { - return false; - } - - return true; + public long getSize() { + return size; + } + + public void setSize(final long size) { + this.size = size; } @Override diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaExternalArtifact.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaExternalArtifact.java deleted file mode 100644 index 86cd11a261..0000000000 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaExternalArtifact.java +++ /dev/null @@ -1,145 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.jpa.model; - -import java.net.URL; - -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.ConstraintMode; -import javax.persistence.Entity; -import javax.persistence.ForeignKey; -import javax.persistence.Index; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.Table; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; - -import org.eclipse.hawkbit.repository.model.ExternalArtifact; -import org.eclipse.hawkbit.repository.model.ExternalArtifactProvider; -import org.eclipse.hawkbit.repository.model.SoftwareModule; - -/** - * External artifact representation with all the necessary information to - * generate an artifact {@link URL} at runtime. - * - */ -@Table(name = "sp_external_artifact", indexes = { - @Index(name = "sp_idx_external_artifact_prim", columnList = "id,tenant") }) -@Entity -// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for -// sub entities -@SuppressWarnings("squid:S2160") -public class JpaExternalArtifact extends AbstractJpaArtifact implements ExternalArtifact { - private static final long serialVersionUID = 1L; - - @ManyToOne - @JoinColumn(name = "provider", nullable = false, updatable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_art_to_ext_provider")) - private JpaExternalArtifactProvider externalArtifactProvider; - - @Column(name = "url_suffix", length = 512) - @Size(max = 512) - private String urlSuffix; - - // CascadeType.PERSIST as we register ourself at the BSM - @ManyToOne(optional = false, cascade = { CascadeType.PERSIST }) - @JoinColumn(name = "software_module", nullable = false, updatable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_external_assigned_sm")) - private JpaSoftwareModule softwareModule; - - /** - * Default constructor. - */ - public JpaExternalArtifact() { - super(); - } - - /** - * Constructs {@link ExternalArtifact}. - * - * @param externalArtifactProvider - * of the artifact - * @param urlSuffix - * of the artifact - * @param softwareModule - * of the artifact - */ - public JpaExternalArtifact(@NotNull final ExternalArtifactProvider externalArtifactProvider, final String urlSuffix, - final SoftwareModule softwareModule) { - setSoftwareModule(softwareModule); - this.externalArtifactProvider = (JpaExternalArtifactProvider) externalArtifactProvider; - - if (urlSuffix != null) { - this.urlSuffix = urlSuffix; - } else { - this.urlSuffix = externalArtifactProvider.getDefaultSuffix(); - } - } - - /** - * @return the softwareModule - */ - @Override - public SoftwareModule getSoftwareModule() { - return softwareModule; - } - - public final void setSoftwareModule(final SoftwareModule softwareModule) { - this.softwareModule = (JpaSoftwareModule) softwareModule; - this.softwareModule.addArtifact(this); - } - - @Override - public ExternalArtifactProvider getExternalArtifactProvider() { - return externalArtifactProvider; - } - - @Override - public String getUrl() { - return new StringBuilder().append(externalArtifactProvider.getBasePath()).append(urlSuffix).toString(); - } - - @Override - public String getUrlSuffix() { - return urlSuffix; - } - - public void setExternalArtifactProvider(final JpaExternalArtifactProvider externalArtifactProvider) { - this.externalArtifactProvider = externalArtifactProvider; - } - - /** - * @param urlSuffix - * the urlSuffix to set - */ - @Override - public void setUrlSuffix(final String urlSuffix) { - this.urlSuffix = urlSuffix; - } - - @Override - public int hashCode() { // NOSONAR - as this is generated - final int prime = 31; - int result = super.hashCode(); - result = prime * result + this.getClass().getName().hashCode(); - return result; - } - - @Override - public boolean equals(final Object obj) { // NOSONAR - as this is generated - if (!super.equals(obj)) { - return false; - } - if (!(obj instanceof JpaExternalArtifact)) { - return false; - } - - return true; - } -} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaExternalArtifactProvider.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaExternalArtifactProvider.java deleted file mode 100644 index cb07f723ab..0000000000 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaExternalArtifactProvider.java +++ /dev/null @@ -1,87 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.jpa.model; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Index; -import javax.persistence.Table; -import javax.validation.constraints.Size; - -import org.eclipse.hawkbit.repository.model.ExternalArtifact; -import org.eclipse.hawkbit.repository.model.ExternalArtifactProvider; - -/** - * JPA implementation of {@link ExternalArtifactProvider}. - * - */ -@Table(name = "sp_external_provider", indexes = { - @Index(name = "sp_idx_external_provider_prim", columnList = "tenant,id") }) -@Entity -// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for -// sub entities -@SuppressWarnings("squid:S2160") -public class JpaExternalArtifactProvider extends AbstractJpaNamedEntity implements ExternalArtifactProvider { - private static final long serialVersionUID = 1L; - - @Column(name = "base_url", length = 512, nullable = false) - @Size(max = 512) - private String basePath; - - @Column(name = "default_url_suffix", length = 512, nullable = true) - @Size(max = 512) - private String defaultSuffix; - - /** - * Constructs {@link ExternalArtifactProvider} based on given properties. - * - * @param name - * of the provided - * @param description - * which is optional - * @param baseURL - * of all {@link ExternalArtifact}s of the provider - * @param defaultUrlSuffix - * that is used if {@link ExternalArtifact#getUrlSuffix()} is - * empty. - */ - public JpaExternalArtifactProvider(final String name, final String description, final String baseURL, - final String defaultUrlSuffix) { - super(name, description); - basePath = baseURL; - defaultSuffix = defaultUrlSuffix; - } - - JpaExternalArtifactProvider() { - super(); - defaultSuffix = ""; - basePath = ""; - } - - @Override - public String getBasePath() { - return basePath; - } - - @Override - public String getDefaultSuffix() { - return defaultSuffix; - } - - @Override - public void setBasePath(final String basePath) { - this.basePath = basePath; - } - - @Override - public void setDefaultSuffix(final String defaultSuffix) { - this.defaultSuffix = defaultSuffix; - } - -} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModule.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModule.java index e827be8b10..ba2eb193df 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModule.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModule.java @@ -10,9 +10,7 @@ import java.util.ArrayList; import java.util.Collections; -import java.util.LinkedList; import java.util.List; -import java.util.Optional; import javax.persistence.CascadeType; import javax.persistence.Column; @@ -34,15 +32,11 @@ import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.DistributionSet; -import org.eclipse.hawkbit.repository.model.ExternalArtifact; -import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.persistence.annotations.CascadeOnDelete; -import com.google.common.collect.Lists; - /** * Base Software Module that is supported by OS level provisioning mechanism on * the edge controller, e.g. OS, JVM, AgentHub. @@ -77,12 +71,8 @@ public class JpaSoftwareModule extends AbstractJpaNamedVersionedEntity implement private String vendor; @CascadeOnDelete - @OneToMany(mappedBy = "softwareModule", cascade = { CascadeType.ALL }, targetEntity = JpaLocalArtifact.class) - private List artifacts; - - @CascadeOnDelete - @OneToMany(mappedBy = "softwareModule", cascade = { CascadeType.ALL }, targetEntity = JpaExternalArtifact.class) - private List externalArtifacts; + @OneToMany(mappedBy = "softwareModule", cascade = { CascadeType.ALL }, targetEntity = JpaArtifact.class) + private List artifacts; @CascadeOnDelete @OneToMany(fetch = FetchType.LAZY, cascade = { CascadeType.REMOVE }, targetEntity = JpaSoftwareModuleMetadata.class) @@ -122,7 +112,7 @@ public JpaSoftwareModule(final SoftwareModuleType type, final String name, final * is added to the assigned {@link Artifact}s. */ @Override - public void addArtifact(final LocalArtifact artifact) { + public void addArtifact(final Artifact artifact) { if (null == artifacts) { artifacts = new ArrayList<>(4); artifacts.add(artifact); @@ -134,72 +124,16 @@ public void addArtifact(final LocalArtifact artifact) { } } - /** - * @param artifact - * is added to the assigned {@link Artifact}s. - */ - @Override - public void addArtifact(final ExternalArtifact artifact) { - if (null == externalArtifacts) { - externalArtifacts = new LinkedList<>(); - externalArtifacts.add(artifact); - return; - } - - if (!externalArtifacts.contains(artifact)) { - externalArtifacts.add(artifact); - } - - } - - @Override - public Optional getLocalArtifact(final Long artifactId) { - if (artifacts == null) { - return Optional.empty(); - } - - return artifacts.stream().filter(artifact -> artifact.getId().equals(artifactId)).findFirst(); - } - - @Override - public Optional getLocalArtifactByFilename(final String fileName) { - if (artifacts == null) { - return Optional.empty(); - } - - return artifacts.stream().filter(artifact -> artifact.getFilename().equalsIgnoreCase(fileName.trim())) - .findFirst(); - } - /** * @return the artifacts */ @Override public List getArtifacts() { - if (artifacts == null && externalArtifacts == null) { - return Collections.emptyList(); - } else if (artifacts == null) { - return Collections.unmodifiableList(externalArtifacts); - } else if (externalArtifacts == null) { - return Collections.unmodifiableList(artifacts); - } - - final List result = Lists.newLinkedList(artifacts); - result.addAll(externalArtifacts); - - return Collections.unmodifiableList(result); - } - - /** - * @return local artifacts only - */ - @Override - public List getLocalArtifacts() { if (artifacts == null) { return Collections.emptyList(); } - return artifacts; + return Collections.unmodifiableList(artifacts); } @Override @@ -212,23 +146,12 @@ public String getVendor() { * is removed from the assigned {@link LocalArtifact}s. */ @Override - public void removeArtifact(final LocalArtifact artifact) { + public void removeArtifact(final Artifact artifact) { if (artifacts != null) { artifacts.remove(artifact); } } - /** - * @param artifact - * is removed from the assigned {@link ExternalArtifact}s. - */ - @Override - public void removeArtifact(final ExternalArtifact artifact) { - if (externalArtifacts != null) { - externalArtifacts.remove(artifact); - } - } - @Override public void setVendor(final String vendor) { this.vendor = vendor; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModuleMetadata.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModuleMetadata.java index e8972eb97a..8b085c2ce1 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModuleMetadata.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModuleMetadata.java @@ -46,7 +46,7 @@ public JpaSoftwareModuleMetadata(final String key, final SoftwareModule software } public SwMetadataCompositeKey getId() { - return new SwMetadataCompositeKey(softwareModule, getKey()); + return new SwMetadataCompositeKey(softwareModule.getId(), getKey()); } @Override diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/SwMetadataCompositeKey.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/SwMetadataCompositeKey.java index e9c63b511d..90637245f4 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/SwMetadataCompositeKey.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/SwMetadataCompositeKey.java @@ -10,8 +10,6 @@ import java.io.Serializable; -import org.eclipse.hawkbit.repository.model.SoftwareModule; - /** * The Software Module meta data composite key which contains the meta data key * and the ID of the software module itself. @@ -31,13 +29,13 @@ public SwMetadataCompositeKey() { } /** - * @param softwareModule + * @param moduleId * the software module for this meta data * @param key * the key of the meta data */ - public SwMetadataCompositeKey(final SoftwareModule softwareModule, final String key) { - this.softwareModule = softwareModule.getId(); + public SwMetadataCompositeKey(final Long moduleId, final String key) { + this.softwareModule = moduleId; this.key = key; } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/ActionSpecifications.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/ActionSpecifications.java index 54d529d6c6..6cabc4bd2a 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/ActionSpecifications.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/ActionSpecifications.java @@ -14,14 +14,14 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaAction; import org.eclipse.hawkbit.repository.jpa.model.JpaAction_; +import org.eclipse.hawkbit.repository.jpa.model.JpaArtifact; +import org.eclipse.hawkbit.repository.jpa.model.JpaArtifact_; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet_; -import org.eclipse.hawkbit.repository.jpa.model.JpaLocalArtifact; -import org.eclipse.hawkbit.repository.jpa.model.JpaLocalArtifact_; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule_; import org.eclipse.hawkbit.repository.model.Action; -import org.eclipse.hawkbit.repository.model.LocalArtifact; +import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.Target; import org.springframework.data.jpa.domain.Specification; @@ -50,14 +50,14 @@ private ActionSpecifications() { * @return a specification to use with spring JPA */ public static Specification hasTargetAssignedArtifact(final Target target, - final LocalArtifact localArtifact) { + final Artifact localArtifact) { return (actionRoot, query, criteriaBuilder) -> { final Join dsJoin = actionRoot.join(JpaAction_.distributionSet); final SetJoin modulesJoin = dsJoin.join(JpaDistributionSet_.modules); - final ListJoin artifactsJoin = modulesJoin + final ListJoin artifactsJoin = modulesJoin .join(JpaSoftwareModule_.artifacts); return criteriaBuilder.and( - criteriaBuilder.equal(artifactsJoin.get(JpaLocalArtifact_.filename), localArtifact.getFilename()), + criteriaBuilder.equal(artifactsJoin.get(JpaArtifact_.filename), localArtifact.getFilename()), criteriaBuilder.equal(actionRoot.get(JpaAction_.target), target)); }; } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/SoftwareModuleSpecification.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/SoftwareModuleSpecification.java index 044383d490..6b303607ca 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/SoftwareModuleSpecification.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/SoftwareModuleSpecification.java @@ -13,6 +13,7 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType; +import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType_; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule_; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.springframework.data.jpa.domain.Specification; @@ -39,7 +40,7 @@ public static Specification byId(final Long moduleId) { return (targetRoot, query, cb) -> { final Predicate predicate = cb.equal(targetRoot. get(JpaSoftwareModule_.id), moduleId); targetRoot.fetch(JpaSoftwareModule_.type); - targetRoot.fetch(JpaSoftwareModule_.metadata,JoinType.LEFT); + targetRoot.fetch(JpaSoftwareModule_.metadata, JoinType.LEFT); query.distinct(true); return predicate; }; @@ -77,9 +78,9 @@ public static Specification likeNameOrVersion(final String su * to be filtered on * @return the {@link SoftwareModule} {@link Specification} */ - public static Specification equalType(final JpaSoftwareModuleType type) { - return (targetRoot, query, cb) -> cb.equal(targetRoot. get(JpaSoftwareModule_.type), - type); + public static Specification equalType(final Long type) { + return (targetRoot, query, cb) -> cb.equal( + targetRoot. get(JpaSoftwareModule_.type).get(JpaSoftwareModuleType_.id), type); } } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/resources/db/migration/H2/V1_8_2__remove_external_artifact___H2.sql b/hawkbit-repository/hawkbit-repository-jpa/src/main/resources/db/migration/H2/V1_8_2__remove_external_artifact___H2.sql new file mode 100644 index 0000000000..ac35f9c370 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/resources/db/migration/H2/V1_8_2__remove_external_artifact___H2.sql @@ -0,0 +1,2 @@ +DROP TABLE sp_external_provider; +DROP TABLE sp_external_artifact; \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/resources/db/migration/MYSQL/V1_8_2__remove_external_artifact___MYSQL.sql b/hawkbit-repository/hawkbit-repository-jpa/src/main/resources/db/migration/MYSQL/V1_8_2__remove_external_artifact___MYSQL.sql new file mode 100644 index 0000000000..ac35f9c370 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/resources/db/migration/MYSQL/V1_8_2__remove_external_artifact___MYSQL.sql @@ -0,0 +1,2 @@ +DROP TABLE sp_external_provider; +DROP TABLE sp_external_artifact; \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTest.java index 45831d08fe..a4b929eb00 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTest.java @@ -56,9 +56,6 @@ public abstract class AbstractJpaIntegrationTest extends AbstractIntegrationTest @Autowired protected ActionStatusRepository actionStatusRepository; - @Autowired - protected ExternalArtifactRepository externalArtifactRepository; - @Autowired protected LocalArtifactRepository artifactRepository; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTestWithMongoDB.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTestWithMongoDB.java index d2c2a7cfac..d71accc460 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTestWithMongoDB.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/AbstractJpaIntegrationTestWithMongoDB.java @@ -55,9 +55,6 @@ public abstract class AbstractJpaIntegrationTestWithMongoDB extends AbstractInte @Autowired protected ActionStatusRepository actionStatusRepository; - @Autowired - protected ExternalArtifactRepository externalArtifactRepository; - @Autowired protected LocalArtifactRepository artifactRepository; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementFailedMongoDBTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementFailedMongoDBTest.java index 98af08494a..e28d1776a6 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementFailedMongoDBTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementFailedMongoDBTest.java @@ -40,22 +40,21 @@ public void deleteArtifactsWithNoMongoDb() throws UnknownHostException, IOExcept "version 1", null, null); sm = softwareModuleRepository.save(sm); - final Artifact result = artifactManagement.createLocalArtifact(new RandomGeneratedInputStream(5 * 1024), - sm.getId(), "file1", false); + final Artifact result = artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024), sm.getId(), + "file1", false); assertThat(artifactRepository.findAll()).hasSize(1); mongodExecutable.stop(); try { - artifactManagement.deleteLocalArtifact(result.getId()); + artifactManagement.deleteArtifact(result.getId()); fail("deletion should have failed"); } catch (final ArtifactDeleteFailedException e) { } try { - artifactManagement.createLocalArtifact(new RandomGeneratedInputStream(5 * 1024), sm.getId(), "file2", - false); + artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024), sm.getId(), "file2", false); fail("Should not have worked with MongoDb down."); } catch (final ArtifactUploadFailedException e) { diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementTest.java index cb117ad7a8..62304c5318 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementTest.java @@ -9,7 +9,6 @@ package org.eclipse.hawkbit.repository.jpa; import static org.fest.assertions.api.Assertions.assertThat; -import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -22,13 +21,9 @@ import org.eclipse.hawkbit.im.authentication.SpPermission; import org.eclipse.hawkbit.repository.ArtifactManagement; import org.eclipse.hawkbit.repository.exception.InsufficientPermissionException; -import org.eclipse.hawkbit.repository.jpa.model.JpaExternalArtifact; -import org.eclipse.hawkbit.repository.jpa.model.JpaExternalArtifactProvider; -import org.eclipse.hawkbit.repository.jpa.model.JpaLocalArtifact; +import org.eclipse.hawkbit.repository.jpa.model.JpaArtifact; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; import org.eclipse.hawkbit.repository.model.Artifact; -import org.eclipse.hawkbit.repository.model.ExternalArtifactProvider; -import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.test.util.HashGeneratorUtils; import org.eclipse.hawkbit.repository.test.util.WithUser; @@ -57,7 +52,7 @@ public ArtifactManagementTest() { /** * Test method for - * {@link org.eclipse.hawkbit.repository.ArtifactManagement#createLocalArtifact(java.io.InputStream)} + * {@link org.eclipse.hawkbit.repository.ArtifactManagement#createArtifact(java.io.InputStream)} * . * * @throws IOException @@ -65,7 +60,7 @@ public ArtifactManagementTest() { */ @Test @Description("Test if a local artifact can be created by API including metadata.") - public void createLocalArtifact() throws NoSuchAlgorithmException, IOException { + public void createArtifact() throws NoSuchAlgorithmException, IOException { // checkbaseline assertThat(softwareModuleRepository.findAll()).hasSize(0); assertThat(artifactRepository.findAll()).hasSize(0); @@ -84,27 +79,26 @@ public void createLocalArtifact() throws NoSuchAlgorithmException, IOException { final byte random[] = RandomStringUtils.random(5 * 1024).getBytes(); - final Artifact result = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(), - "file1", false); - final Artifact result11 = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(), + final Artifact result = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", + false); + final Artifact result11 = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), "file11", false); - final Artifact result12 = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(), + final Artifact result12 = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), "file12", false); - final Artifact result2 = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm2.getId(), + final Artifact result2 = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm2.getId(), "file2", false); - assertThat(result).isInstanceOf(LocalArtifact.class); + assertThat(result).isInstanceOf(Artifact.class); assertThat(result.getSoftwareModule().getId()).isEqualTo(sm.getId()); assertThat(result2.getSoftwareModule().getId()).isEqualTo(sm2.getId()); - assertThat(((JpaLocalArtifact) result).getFilename()).isEqualTo("file1"); - assertThat(((JpaLocalArtifact) result).getGridFsFileName()).isNotNull(); + assertThat(((JpaArtifact) result).getFilename()).isEqualTo("file1"); + assertThat(((JpaArtifact) result).getGridFsFileName()).isNotNull(); assertThat(result).isNotEqualTo(result2); - assertThat(((JpaLocalArtifact) result).getGridFsFileName()) - .isEqualTo(((JpaLocalArtifact) result2).getGridFsFileName()); + assertThat(((JpaArtifact) result).getGridFsFileName()).isEqualTo(((JpaArtifact) result2).getGridFsFileName()); - assertThat(artifactManagement.findLocalArtifactByFilename("file1").get(0).getSha1Hash()) + assertThat(artifactManagement.findArtifactByFilename("file1").get(0).getSha1Hash()) .isEqualTo(HashGeneratorUtils.generateSHA1(random)); - assertThat(artifactManagement.findLocalArtifactByFilename("file1").get(0).getMd5Hash()) + assertThat(artifactManagement.findArtifactByFilename("file1").get(0).getMd5Hash()) .isEqualTo(HashGeneratorUtils.generateMD5(random)); assertThat(artifactRepository.findAll()).hasSize(4); @@ -122,7 +116,7 @@ public void hardDeleteSoftwareModule() throws NoSuchAlgorithmException, IOExcept final byte random[] = RandomStringUtils.random(5 * 1024).getBytes(); - artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", false); + artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", false); assertThat(artifactRepository.findAll()).hasSize(1); softwareModuleRepository.deleteAll(); @@ -131,63 +125,7 @@ public void hardDeleteSoftwareModule() throws NoSuchAlgorithmException, IOExcept /** * Test method for - * {@link org.eclipse.hawkbit.repository.ArtifactManagement#createExternalArtifact(org.eclipse.hawkbit.repository.model.ExternalArtifactProvider, java.lang.String)} - * . - */ - @Test - @Description("Tests the creation of an external artifact metadata element.") - public void createExternalArtifact() { - JpaSoftwareModule sm = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1", - "version 1", null, null); - sm = softwareModuleRepository.save(sm); - - JpaSoftwareModule sm2 = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 2", - "version 2", null, null); - sm2 = softwareModuleRepository.save(sm2); - - final ExternalArtifactProvider provider = artifactManagement.createExternalArtifactProvider("provider X", null, - "https://fhghdfjgh", "/{version}/"); - - JpaExternalArtifact result = (JpaExternalArtifact) artifactManagement.createExternalArtifact(provider, null, - sm.getId()); - - assertNotNull("The result of an external artifact should not be null", result); - assertThat(externalArtifactRepository.findAll()).contains(result).hasSize(1); - assertThat(result.getSoftwareModule().getId()).isEqualTo(sm.getId()); - assertThat(result.getUrl()).isEqualTo("https://fhghdfjgh/{version}/"); - assertThat(result.getExternalArtifactProvider()).isEqualTo(provider); - - result = (JpaExternalArtifact) artifactManagement.createExternalArtifact(provider, "/test", sm2.getId()); - assertNotNull("The newly created external artifact should not be null", result); - assertThat(externalArtifactRepository.findAll()).contains(result).hasSize(2); - assertThat(result.getUrl()).isEqualTo("https://fhghdfjgh/test"); - assertThat(result.getExternalArtifactProvider()).isEqualTo(provider); - } - - @Test - @Description("Tests deletio of an external artifact metadata element.") - public void deleteExternalArtifact() { - assertThat(artifactRepository.findAll()).isEmpty(); - - JpaSoftwareModule sm = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1", - "version 1", null, null); - sm = softwareModuleRepository.save(sm); - - final JpaExternalArtifactProvider provider = (JpaExternalArtifactProvider) artifactManagement - .createExternalArtifactProvider("provider X", null, "https://fhghdfjgh", "/{version}/"); - - final JpaExternalArtifact result = (JpaExternalArtifact) artifactManagement.createExternalArtifact(provider, - null, sm.getId()); - assertNotNull("The newly created external artifact should not be null", result); - assertThat(externalArtifactRepository.findAll()).contains(result).hasSize(1); - - artifactManagement.deleteExternalArtifact(result.getId()); - assertThat(externalArtifactRepository.findAll()).isEmpty(); - } - - /** - * Test method for - * {@link org.eclipse.hawkbit.repository.ArtifactManagement#deleteLocalArtifact(java.lang.Long)} + * {@link org.eclipse.hawkbit.repository.ArtifactManagement#deleteArtifact(java.lang.Long)} * . * * @throws IOException @@ -195,7 +133,7 @@ public void deleteExternalArtifact() { */ @Test @Description("Tests the deletion of a local artifact including metadata.") - public void deleteLocalArtifact() throws NoSuchAlgorithmException, IOException { + public void deleteArtifact() throws NoSuchAlgorithmException, IOException { JpaSoftwareModule sm = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1", "version 1", null, null); sm = softwareModuleRepository.save(sm); @@ -206,34 +144,35 @@ public void deleteLocalArtifact() throws NoSuchAlgorithmException, IOException { assertThat(artifactRepository.findAll()).isEmpty(); - final Artifact result = artifactManagement.createLocalArtifact(new RandomGeneratedInputStream(5 * 1024), - sm.getId(), "file1", false); - final Artifact result2 = artifactManagement.createLocalArtifact(new RandomGeneratedInputStream(5 * 1024), + final Artifact result = artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024), sm.getId(), + "file1", false); + final Artifact result2 = artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024), sm2.getId(), "file2", false); assertThat(artifactRepository.findAll()).hasSize(2); assertThat(result.getId()).isNotNull(); assertThat(result2.getId()).isNotNull(); - assertThat(((JpaLocalArtifact) result).getGridFsFileName()) - .isNotEqualTo(((JpaLocalArtifact) result2).getGridFsFileName()); - assertThat(operations.findOne(new Query() - .addCriteria(Criteria.where("filename").is(((JpaLocalArtifact) result).getGridFsFileName())))) + assertThat(((JpaArtifact) result).getGridFsFileName()) + .isNotEqualTo(((JpaArtifact) result2).getGridFsFileName()); + assertThat(operations.findOne( + new Query().addCriteria(Criteria.where("filename").is(((JpaArtifact) result).getGridFsFileName())))) .isNotNull(); - assertThat(operations.findOne(new Query() - .addCriteria(Criteria.where("filename").is(((JpaLocalArtifact) result2).getGridFsFileName())))) + assertThat(operations.findOne( + new Query().addCriteria(Criteria.where("filename").is(((JpaArtifact) result2).getGridFsFileName())))) .isNotNull(); - artifactManagement.deleteLocalArtifact(result.getId()); - assertThat(operations.findOne(new Query() - .addCriteria(Criteria.where("filename").is(((JpaLocalArtifact) result).getGridFsFileName())))).isNull(); - assertThat(operations.findOne(new Query() - .addCriteria(Criteria.where("filename").is(((JpaLocalArtifact) result2).getGridFsFileName())))) + artifactManagement.deleteArtifact(result.getId()); + assertThat(operations.findOne( + new Query().addCriteria(Criteria.where("filename").is(((JpaArtifact) result).getGridFsFileName())))) + .isNull(); + assertThat(operations.findOne( + new Query().addCriteria(Criteria.where("filename").is(((JpaArtifact) result2).getGridFsFileName())))) .isNotNull(); - artifactManagement.deleteLocalArtifact(result2.getId()); - assertThat(operations.findOne(new Query() - .addCriteria(Criteria.where("filename").is(((JpaLocalArtifact) result2).getGridFsFileName())))) + artifactManagement.deleteArtifact(result2.getId()); + assertThat(operations.findOne( + new Query().addCriteria(Criteria.where("filename").is(((JpaArtifact) result2).getGridFsFileName())))) .isNull(); assertThat(artifactRepository.findAll()).hasSize(0); @@ -253,33 +192,33 @@ public void deleteDuplicateArtifacts() throws NoSuchAlgorithmException, IOExcept final byte random[] = RandomStringUtils.random(5 * 1024).getBytes(); - final Artifact result = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(), - "file1", false); - final Artifact result2 = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm2.getId(), + final Artifact result = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", + false); + final Artifact result2 = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm2.getId(), "file2", false); assertThat(artifactRepository.findAll()).hasSize(2); assertThat(result.getId()).isNotNull(); assertThat(result2.getId()).isNotNull(); - assertThat(((JpaLocalArtifact) result).getGridFsFileName()) - .isEqualTo(((JpaLocalArtifact) result2).getGridFsFileName()); + assertThat(((JpaArtifact) result).getGridFsFileName()).isEqualTo(((JpaArtifact) result2).getGridFsFileName()); - assertThat(operations.findOne(new Query() - .addCriteria(Criteria.where("filename").is(((JpaLocalArtifact) result).getGridFsFileName())))) + assertThat(operations.findOne( + new Query().addCriteria(Criteria.where("filename").is(((JpaArtifact) result).getGridFsFileName())))) .isNotNull(); - artifactManagement.deleteLocalArtifact(result.getId()); - assertThat(operations.findOne(new Query() - .addCriteria(Criteria.where("filename").is(((JpaLocalArtifact) result).getGridFsFileName())))) + artifactManagement.deleteArtifact(result.getId()); + assertThat(operations.findOne( + new Query().addCriteria(Criteria.where("filename").is(((JpaArtifact) result).getGridFsFileName())))) .isNotNull(); - artifactManagement.deleteLocalArtifact(result2.getId()); - assertThat(operations.findOne(new Query() - .addCriteria(Criteria.where("filename").is(((JpaLocalArtifact) result).getGridFsFileName())))).isNull(); + artifactManagement.deleteArtifact(result2.getId()); + assertThat(operations.findOne( + new Query().addCriteria(Criteria.where("filename").is(((JpaArtifact) result).getGridFsFileName())))) + .isNull(); } /** * Test method for - * {@link org.eclipse.hawkbit.repository.ArtifactManagement#findLocalArtifact(java.lang.Long)} + * {@link org.eclipse.hawkbit.repository.ArtifactManagement#findArtifact(java.lang.Long)} * . * * @throws IOException @@ -287,20 +226,20 @@ public void deleteDuplicateArtifacts() throws NoSuchAlgorithmException, IOExcept */ @Test @Description("Loads an local artifact based on given ID.") - public void findLocalArtifact() throws NoSuchAlgorithmException, IOException { + public void findArtifact() throws NoSuchAlgorithmException, IOException { SoftwareModule sm = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1", "version 1", null, null); sm = softwareManagement.createSoftwareModule(sm); - final LocalArtifact result = artifactManagement.createLocalArtifact(new RandomGeneratedInputStream(5 * 1024), - sm.getId(), "file1", false); + final Artifact result = artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024), sm.getId(), + "file1", false); - assertThat(artifactManagement.findLocalArtifact(result.getId())).isEqualTo(result); + assertThat(artifactManagement.findArtifact(result.getId())).isEqualTo(result); } /** * Test method for - * {@link org.eclipse.hawkbit.repository.ArtifactManagement#loadLocalArtifactBinary(java.lang.Long)} + * {@link org.eclipse.hawkbit.repository.ArtifactManagement#loadArtifactBinary(java.lang.Long)} * . * * @throws IOException @@ -308,26 +247,26 @@ public void findLocalArtifact() throws NoSuchAlgorithmException, IOException { */ @Test @Description("Loads an artifact binary based on given ID.") - public void loadStreamOfLocalArtifact() throws NoSuchAlgorithmException, IOException { + public void loadStreamOfArtifact() throws NoSuchAlgorithmException, IOException { SoftwareModule sm = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1", "version 1", null, null); sm = softwareManagement.createSoftwareModule(sm); final byte random[] = RandomStringUtils.random(5 * 1024).getBytes(); - final LocalArtifact result = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), - sm.getId(), "file1", false); + final Artifact result = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", + false); assertTrue("The stored binary matches the given binary", IOUtils.contentEquals(new ByteArrayInputStream(random), - artifactManagement.loadLocalArtifactBinary(result).getFileInputStream())); + artifactManagement.loadArtifactBinary(result).getFileInputStream())); } @Test @WithUser(allSpPermissions = true, removeFromAllPermission = { SpPermission.DOWNLOAD_REPOSITORY_ARTIFACT }) @Description("Trys and fails to load an artifact without required permission. Checks if expected InsufficientPermissionException is thrown.") - public void loadLocalArtifactBinaryWithoutDownloadArtifactThrowsPermissionDenied() { + public void loadArtifactBinaryWithoutDownloadArtifactThrowsPermissionDenied() { try { - artifactManagement.loadLocalArtifactBinary(new JpaLocalArtifact()); + artifactManagement.loadArtifactBinary(new JpaArtifact()); fail("Should not have worked with missing permission."); } catch (final InsufficientPermissionException e) { @@ -336,19 +275,19 @@ public void loadLocalArtifactBinaryWithoutDownloadArtifactThrowsPermissionDenied @Test @Description("Searches an artifact through the relations of a software module.") - public void findLocalArtifactBySoftwareModule() { + public void findArtifactBySoftwareModule() { SoftwareModule sm = new JpaSoftwareModule(osType, "name 1", "version 1", null, null); sm = softwareManagement.createSoftwareModule(sm); SoftwareModule sm2 = new JpaSoftwareModule(osType, "name 2", "version 2", null, null); sm2 = softwareManagement.createSoftwareModule(sm2); - assertThat(artifactManagement.findLocalArtifactBySoftwareModule(pageReq, sm.getId())).isEmpty(); + assertThat(artifactManagement.findArtifactBySoftwareModule(pageReq, sm.getId())).isEmpty(); - final Artifact result = artifactManagement.createLocalArtifact(new RandomGeneratedInputStream(5 * 1024), - sm.getId(), "file1", false); + final Artifact result = artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024), sm.getId(), + "file1", false); - assertThat(artifactManagement.findLocalArtifactBySoftwareModule(pageReq, sm.getId())).hasSize(1); + assertThat(artifactManagement.findArtifactBySoftwareModule(pageReq, sm.getId())).hasSize(1); } @Test @@ -359,8 +298,8 @@ public void findByFilenameAndSoftwareModule() { assertThat(artifactManagement.findByFilenameAndSoftwareModule("file1", sm.getId())).isEmpty(); - artifactManagement.createLocalArtifact(new RandomGeneratedInputStream(5 * 1024), sm.getId(), "file1", false); - artifactManagement.createLocalArtifact(new RandomGeneratedInputStream(5 * 1024), sm.getId(), "file2", false); + artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024), sm.getId(), "file1", false); + artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024), sm.getId(), "file2", false); assertThat(artifactManagement.findByFilenameAndSoftwareModule("file1", sm.getId())).hasSize(1); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SoftwareManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SoftwareManagementTest.java index 4f44d260c1..c5cad9a62c 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SoftwareManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SoftwareManagementTest.java @@ -24,9 +24,9 @@ import org.apache.commons.lang3.RandomUtils; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; +import org.eclipse.hawkbit.repository.jpa.model.JpaArtifact; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType; -import org.eclipse.hawkbit.repository.jpa.model.JpaLocalArtifact; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleMetadata; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType; @@ -237,24 +237,29 @@ public void findSoftwareModuleByFilters() { ds = (JpaDistributionSet) assignSet(target, ds).getDistributionSet(); // standard searches - assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "poky", osType).getContent()).hasSize(1); - assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "poky", osType).getContent().get(0)) + assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "poky", osType.getId()).getContent()) + .hasSize(1); + assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "poky", osType.getId()).getContent().get(0)) .isEqualTo(os); - assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "oracle%", runtimeType).getContent()) + assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "oracle%", runtimeType.getId()).getContent()) .hasSize(1); - assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "oracle%", runtimeType).getContent().get(0)) - .isEqualTo(jvm); - assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "1.0.1", appType).getContent()).hasSize(1); - assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "1.0.1", appType).getContent().get(0)) - .isEqualTo(ah); - assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "1.0%", appType).getContent()).hasSize(2); + assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "oracle%", runtimeType.getId()).getContent() + .get(0)).isEqualTo(jvm); + assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "1.0.1", appType.getId()).getContent()) + .hasSize(1); + assertThat( + softwareManagement.findSoftwareModuleByFilters(pageReq, "1.0.1", appType.getId()).getContent().get(0)) + .isEqualTo(ah); + assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "1.0%", appType.getId()).getContent()) + .hasSize(2); // no we search with on entity marked as deleted softwareManagement.deleteSoftwareModule( - softwareManagement.findSoftwareModuleByAssignedToAndType(pageReq, ds, appType).getContent().get(0)); + softwareModuleRepository.findByAssignedToAndType(pageReq, ds, appType).getContent().get(0).getId()); - assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "1.0%", appType).getContent()).hasSize(1); - assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "1.0%", appType).getContent().get(0)) + assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "1.0%", appType.getId()).getContent()) + .hasSize(1); + assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "1.0%", appType.getId()).getContent().get(0)) .isEqualTo(ah); } @@ -294,11 +299,11 @@ public void findSoftwareModulesByType() { final SoftwareModule two = softwareManagement .createSoftwareModule(new JpaSoftwareModule(osType, "two", "two", null, "")); // ignored - softwareManagement.deleteSoftwareModule( - softwareManagement.createSoftwareModule(new JpaSoftwareModule(osType, "deleted", "deleted", null, ""))); + softwareManagement.deleteSoftwareModule(softwareManagement + .createSoftwareModule(new JpaSoftwareModule(osType, "deleted", "deleted", null, "")).getId()); softwareManagement.createSoftwareModule(new JpaSoftwareModule(appType, "three", "3.0.2", null, "")); - assertThat(softwareManagement.findSoftwareModulesByType(pageReq, osType).getContent()) + assertThat(softwareManagement.findSoftwareModulesByType(pageReq, osType.getId()).getContent()) .as("Expected to find the following number of modules:").hasSize(2).as("with the following elements") .contains(two, one); } @@ -310,29 +315,13 @@ public void countSoftwareModulesAll() { softwareManagement.createSoftwareModule(new JpaSoftwareModule(osType, "one", "one", null, "")); softwareManagement.createSoftwareModule(new JpaSoftwareModule(appType, "two", "two", null, "")); // ignored - softwareManagement.deleteSoftwareModule( - softwareManagement.createSoftwareModule(new JpaSoftwareModule(osType, "deleted", "deleted", null, ""))); + softwareManagement.deleteSoftwareModule(softwareManagement + .createSoftwareModule(new JpaSoftwareModule(osType, "deleted", "deleted", null, "")).getId()); assertThat(softwareManagement.countSoftwareModulesAll()).as("Expected to find the following number of modules:") .isEqualTo(2); } - @Test - @Description("Counts for software modules by type.") - public void countSoftwareModulesByType() { - // found in test - softwareManagement.createSoftwareModule(new JpaSoftwareModule(osType, "one", "one", null, "")); - softwareManagement.createSoftwareModule(new JpaSoftwareModule(osType, "two", "two", null, "")); - - // ignored - softwareManagement.deleteSoftwareModule( - softwareManagement.createSoftwareModule(new JpaSoftwareModule(osType, "deleted", "deleted", null, ""))); - softwareManagement.createSoftwareModule(new JpaSoftwareModule(appType, "three", "3.0.2", null, "")); - - assertThat(softwareManagement.countSoftwareModulesByType(osType)) - .as("Expected to find the following number of modules:").isEqualTo(2); - } - @Test @Description("Tests the successfull deletion of software module types. Both unused (hard delete) and used ones (soft delete).") public void deleteAssignedAndUnassignedSoftwareModuleTypes() { @@ -382,7 +371,7 @@ public void hardDeleteOfNotAssignedArtifact() { final Artifact artifact2 = artifactsIt.next(); // [STEP2]: Delete unassigned SoftwareModule - softwareManagement.deleteSoftwareModule(unassignedModule); + softwareManagement.deleteSoftwareModule(unassignedModule.getId()); // [VERIFY EXPECTED RESULT]: // verify: SoftwareModule is deleted @@ -412,7 +401,7 @@ public void softDeleteOfAssignedArtifact() { distributionSetManagement.assignSoftwareModules(disSet, Sets.newHashSet(assignedModule)); // [STEP3]: Delete the assigned SoftwareModule - softwareManagement.deleteSoftwareModule(assignedModule); + softwareManagement.deleteSoftwareModule(assignedModule.getId()); // [VERIFY EXPECTED RESULT]: // verify: assignedModule is marked as deleted @@ -454,7 +443,7 @@ public void softDeleteOfHistoricalAssignedArtifact() { distributionSetManagement.deleteDistributionSet(disSet); // [STEP5]: Delete the assigned SoftwareModule - softwareManagement.deleteSoftwareModule(assignedModule); + softwareManagement.deleteSoftwareModule(assignedModule.getId()); // [VERIFY EXPECTED RESULT]: // verify: assignedModule is marked as deleted @@ -488,7 +477,7 @@ public void deleteSoftwareModulesWithSharedArtifact() throws IOException { SoftwareModule moduleX = createSoftwareModuleWithArtifacts(osType, "modulex", "v1.0", 0); // [STEP2]: Create newArtifactX and add it to SoftwareModuleX - artifactManagement.createLocalArtifact(new ByteArrayInputStream(source), moduleX.getId(), "artifactx", false); + artifactManagement.createArtifact(new ByteArrayInputStream(source), moduleX.getId(), "artifactx", false); moduleX = softwareManagement.findSoftwareModuleWithDetails(moduleX.getId()); final Artifact artifactX = moduleX.getArtifacts().iterator().next(); @@ -496,7 +485,7 @@ public void deleteSoftwareModulesWithSharedArtifact() throws IOException { SoftwareModule moduleY = createSoftwareModuleWithArtifacts(osType, "moduley", "v1.0", 0); // [STEP4]: Assign the same ArtifactX to SoftwareModuleY - artifactManagement.createLocalArtifact(new ByteArrayInputStream(source), moduleY.getId(), "artifactx", false); + artifactManagement.createArtifact(new ByteArrayInputStream(source), moduleY.getId(), "artifactx", false); moduleY = softwareManagement.findSoftwareModuleWithDetails(moduleY.getId()); final Artifact artifactY = moduleY.getArtifacts().iterator().next(); @@ -504,7 +493,7 @@ public void deleteSoftwareModulesWithSharedArtifact() throws IOException { assertThat(operations.find(new Query())).hasSize(1); // [STEP5]: Delete SoftwareModuleX - softwareManagement.deleteSoftwareModule(moduleX); + softwareManagement.deleteSoftwareModule(moduleX.getId()); // [VERIFY EXPECTED RESULT]: // verify: SoftwareModuleX is deleted, and ModuelY still exists @@ -540,14 +529,14 @@ public void deleteMultipleSoftwareModulesWhichShareAnArtifact() throws IOExcepti // [STEP1]: Create SoftwareModuleX and add a new ArtifactX SoftwareModule moduleX = createSoftwareModuleWithArtifacts(osType, "modulex", "v1.0", 0); - artifactManagement.createLocalArtifact(new ByteArrayInputStream(source), moduleX.getId(), "artifactx", false); + artifactManagement.createArtifact(new ByteArrayInputStream(source), moduleX.getId(), "artifactx", false); moduleX = softwareManagement.findSoftwareModuleWithDetails(moduleX.getId()); final Artifact artifactX = moduleX.getArtifacts().iterator().next(); // [STEP2]: Create SoftwareModuleY and add the same ArtifactX SoftwareModule moduleY = createSoftwareModuleWithArtifacts(osType, "moduley", "v1.0", 0); - artifactManagement.createLocalArtifact(new ByteArrayInputStream(source), moduleY.getId(), "artifactx", false); + artifactManagement.createArtifact(new ByteArrayInputStream(source), moduleY.getId(), "artifactx", false); moduleY = softwareManagement.findSoftwareModuleWithDetails(moduleY.getId()); final Artifact artifactY = moduleY.getArtifacts().iterator().next(); @@ -563,10 +552,10 @@ public void deleteMultipleSoftwareModulesWhichShareAnArtifact() throws IOExcepti deploymentManagement.assignDistributionSet(disSetY, Lists.newArrayList(target)); // [STEP5]: Delete SoftwareModuleX - softwareManagement.deleteSoftwareModule(moduleX); + softwareManagement.deleteSoftwareModule(moduleX.getId()); // [STEP6]: Delete SoftwareModuleY - softwareManagement.deleteSoftwareModule(moduleY); + softwareManagement.deleteSoftwareModule(moduleY.getId()); // [VERIFY EXPECTED RESULT]: moduleX = softwareManagement.findSoftwareModuleById(moduleX.getId()); @@ -597,7 +586,7 @@ private SoftwareModule createSoftwareModuleWithArtifacts(final SoftwareModuleTyp new JpaSoftwareModule(type, name, version, "description of artifact " + name, "")); for (int i = 0; i < numberArtifacts; i++) { - artifactManagement.createLocalArtifact(new RandomGeneratedInputStream(5 * 1024), softwareModule.getId(), + artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024), softwareModule.getId(), "file" + (i + 1), false); } @@ -622,16 +611,16 @@ private void assertArtfiactNotNull(final Artifact... results) { assertThat(artifactRepository.findAll()).hasSize(results.length); for (final Artifact result : results) { assertThat(result.getId()).isNotNull(); - assertThat(operations.findOne(new Query() - .addCriteria(Criteria.where("filename").is(((JpaLocalArtifact) result).getGridFsFileName())))) + assertThat(operations.findOne( + new Query().addCriteria(Criteria.where("filename").is(((JpaArtifact) result).getGridFsFileName())))) .isNotNull(); } } private void assertArtfiactNull(final Artifact... results) { for (final Artifact result : results) { - assertThat(operations.findOne(new Query() - .addCriteria(Criteria.where("filename").is(((JpaLocalArtifact) result).getGridFsFileName())))) + assertThat(operations.findOne( + new Query().addCriteria(Criteria.where("filename").is(((JpaArtifact) result).getGridFsFileName())))) .isNull(); } } @@ -664,18 +653,18 @@ public void findSoftwareModuleOrderByDistributionModuleNameAscModuleVersionAsc() final DistributionSet set = distributionSetManagement.createDistributionSet(new JpaDistributionSet("set", "1", "desc", testDsType, Lists.newArrayList(one, two, deleted, four, differentName))); - softwareManagement.deleteSoftwareModule(deleted); + softwareManagement.deleteSoftwareModule(deleted.getId()); // with filter on name, version and module type assertThat(softwareManagement.findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(pageReq, - set.getId(), "found", testType).getContent()) + set.getId(), "found", testType.getId()).getContent()) .as("Found modules with given name, given module type and the assigned ones first") .containsExactly(new AssignedSoftwareModule(one, true), new AssignedSoftwareModule(two, true), new AssignedSoftwareModule(unassigned, false)); // with filter on module type only assertThat(softwareManagement.findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(pageReq, - set.getId(), null, testType).getContent()) + set.getId(), null, testType.getId()).getContent()) .as("Found modules with given module type and the assigned ones first").containsExactly( new AssignedSoftwareModule(differentName, true), new AssignedSoftwareModule(one, true), new AssignedSoftwareModule(two, true), new AssignedSoftwareModule(unassigned, false)); @@ -715,12 +704,12 @@ public void countSoftwareModuleByFilters() { .createSoftwareModule(new JpaSoftwareModule(testType, "deleted", "deleted", null, "")); distributionSetManagement.createDistributionSet(new JpaDistributionSet("set", "1", "desc", testDsType, Lists.newArrayList(one, two, deleted, four, differentName))); - softwareManagement.deleteSoftwareModule(deleted); + softwareManagement.deleteSoftwareModule(deleted.getId()); // test - assertThat(softwareManagement.countSoftwareModuleByFilters("found", testType)) + assertThat(softwareManagement.countSoftwareModuleByFilters("found", testType.getId())) .as("Number of modules with given name or version and type").isEqualTo(3); - assertThat(softwareManagement.countSoftwareModuleByFilters(null, testType)) + assertThat(softwareManagement.countSoftwareModuleByFilters(null, testType.getId())) .as("Number of modules with given type").isEqualTo(4); assertThat(softwareManagement.countSoftwareModuleByFilters(null, null)).as("Number of modules overall") .isEqualTo(5); @@ -742,7 +731,7 @@ public void countSoftwareModuleTypesAll() { .createSoftwareModule(new JpaSoftwareModule(testType, "deleted", "deleted", null, "")); distributionSetManagement.createDistributionSet( new JpaDistributionSet("set", "1", "desc", testDsType, Lists.newArrayList(deleted, four))); - softwareManagement.deleteSoftwareModule(deleted); + softwareManagement.deleteSoftwareModule(deleted.getId()); assertThat(softwareManagement.countSoftwareModulesAll()).as("Number of undeleted modules").isEqualTo(1); assertThat(softwareModuleRepository.count()).as("Number of all modules").isEqualTo(2); @@ -829,7 +818,7 @@ public void findSoftwareModuleByAssignedTo() { .createSoftwareModule(new JpaSoftwareModule(testType, "deleted", "deleted", null, "")); final DistributionSet set = distributionSetManagement.createDistributionSet( new JpaDistributionSet("set", "1", "desc", testDsType, Lists.newArrayList(one, deleted))); - softwareManagement.deleteSoftwareModule(deleted); + softwareManagement.deleteSoftwareModule(deleted.getId()); assertThat(softwareManagement.findSoftwareModuleByAssignedTo(pageReq, set).getContent()) .as("Found this number of modules").hasSize(2); @@ -950,7 +939,7 @@ public void deleteSoftwareModuleMetadata() { .as("Contains the created metadata element") .containsExactly(new JpaSoftwareModuleMetadata(knownKey1, ah, knownValue1)); - softwareManagement.deleteSoftwareModuleMetadata(ah, knownKey1); + softwareManagement.deleteSoftwareModuleMetadata(ah.getId(), knownKey1); assertThat(softwareManagement.findSoftwareModuleById(ah.getId()).getMetadata()).as("Metadata elemenets are") .isEmpty(); } @@ -968,7 +957,7 @@ public void findSoftwareModuleMetadataFailsIfEntryDoesNotExist() { .getSoftwareModule(); try { - softwareManagement.findSoftwareModuleMetadata(ah, "doesnotexist"); + softwareManagement.findSoftwareModuleMetadata(ah.getId(), "doesnotexist"); fail("should not have worked as module metadata with that key does not exist"); } catch (final EntityNotFoundException e) { diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SystemManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SystemManagementTest.java index ac2b30d232..9cb937eea6 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SystemManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SystemManagementTest.java @@ -136,14 +136,14 @@ private void createTestArtifact(final byte[] random) { "version 1", null, null); sm = softwareModuleRepository.save(sm); - artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", false); + artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", false); } private void createDeletedTestArtifact(final byte[] random) { final DistributionSet ds = testdataFactory.createDistributionSet("deleted garbage", true); ds.getModules().stream().forEach(module -> { - artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), module.getId(), "file1", false); - softwareManagement.deleteSoftwareModule(module); + artifactManagement.createArtifact(new ByteArrayInputStream(random), module.getId(), "file1", false); + softwareManagement.deleteSoftwareModule(module.getId()); }); } diff --git a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/TestdataFactory.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/TestdataFactory.java index 9360626c45..22110bb67d 100644 --- a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/TestdataFactory.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/TestdataFactory.java @@ -33,7 +33,6 @@ import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.DistributionSetType; -import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.repository.model.NamedEntity; import org.eclipse.hawkbit.repository.model.NamedVersionedEntity; import org.eclipse.hawkbit.repository.model.SoftwareModule; @@ -306,19 +305,19 @@ public DistributionSet createDistributionSetWithNoSoftwareModules(final String n } /** - * Creates {@link LocalArtifact}s for given {@link SoftwareModule} with a - * small text payload. + * Creates {@link Artifact}s for given {@link SoftwareModule} with a small + * text payload. * * @param moduleId * the {@link Artifact}s belong to. * - * @return {@link LocalArtifact} entity. + * @return {@link Artifact} entity. */ - public List createLocalArtifacts(final Long moduleId) { - final List artifacts = new ArrayList<>(); + public List createArtifacts(final Long moduleId) { + final List artifacts = new ArrayList<>(); for (int i = 0; i < 3; i++) { final InputStream stubInputStream = IOUtils.toInputStream("some test data" + i, Charset.forName("UTF-8")); - artifacts.add(artifactManagement.createLocalArtifact(stubInputStream, moduleId, "filename" + i, false)); + artifacts.add(artifactManagement.createArtifact(stubInputStream, moduleId, "filename" + i, false)); } diff --git a/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/util/RestResourceConversionHelper.java b/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/util/RestResourceConversionHelper.java index 7e2fbed7cc..5fc3c53a88 100644 --- a/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/util/RestResourceConversionHelper.java +++ b/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/util/RestResourceConversionHelper.java @@ -37,7 +37,7 @@ import org.eclipse.hawkbit.artifact.repository.model.DbArtifact; import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.model.ActionStatus; -import org.eclipse.hawkbit.repository.model.LocalArtifact; +import org.eclipse.hawkbit.repository.model.Artifact; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.ResponseEntity; @@ -71,7 +71,7 @@ private RestResourceConversionHelper() { * * @return http code */ - public static ResponseEntity writeFileResponse(final LocalArtifact artifact, + public static ResponseEntity writeFileResponse(final Artifact artifact, final HttpServletResponse servletResponse, final HttpServletRequest request, final DbArtifact file) { return writeFileResponse(artifact, servletResponse, request, file, null, null); } @@ -104,7 +104,7 @@ public static ResponseEntity writeFileResponse(final LocalArtifact * @see https://tools.ietf.org * /html/rfc7233 */ - public static ResponseEntity writeFileResponse(final LocalArtifact artifact, + public static ResponseEntity writeFileResponse(final Artifact artifact, final HttpServletResponse response, final HttpServletRequest request, final DbArtifact file, final ControllerManagement controllerManagement, final Long statusId) { @@ -173,7 +173,7 @@ else if (ranges.size() == 1) { return result; } - private static void handleFullFileRequest(final LocalArtifact artifact, final HttpServletResponse response, + private static void handleFullFileRequest(final Artifact artifact, final HttpServletResponse response, final DbArtifact file, final ControllerManagement controllerManagement, final Long statusId, final ByteRange full) { final ByteRange r = full; @@ -240,7 +240,7 @@ private static void checkForShortcut(final HttpServletRequest request, final Str } } - private static void handleMultipartRangeRequest(final LocalArtifact artifact, final HttpServletResponse response, + private static void handleMultipartRangeRequest(final Artifact artifact, final HttpServletResponse response, final DbArtifact file, final ControllerManagement controllerManagement, final Long statusId, final List ranges) { response.setContentType("multipart/byteranges; boundary=" + MULTIPART_BOUNDARY); @@ -268,7 +268,7 @@ private static void handleMultipartRangeRequest(final LocalArtifact artifact, fi } } - private static void handleStandardRangeRequest(final LocalArtifact artifact, final HttpServletResponse response, + private static void handleStandardRangeRequest(final Artifact artifact, final HttpServletResponse response, final DbArtifact file, final ControllerManagement controllerManagement, final Long statusId, final List ranges) { final ByteRange r = ranges.get(0); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/details/ArtifactBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/details/ArtifactBeanQuery.java index d08474a5ae..8f2094263f 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/details/ArtifactBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/details/ArtifactBeanQuery.java @@ -19,7 +19,7 @@ import org.eclipse.hawkbit.repository.ArtifactManagement; import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; -import org.eclipse.hawkbit.repository.model.LocalArtifact; +import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SpringContextHelper; import org.springframework.data.domain.Page; @@ -33,12 +33,12 @@ * Simple implementation of generics bean query which dynamically loads artifact * beans. */ -public class ArtifactBeanQuery extends AbstractBeanQuery { +public class ArtifactBeanQuery extends AbstractBeanQuery { private static final long serialVersionUID = -333786310371208962L; private Sort sort = new Sort(Direction.DESC, "filename"); private transient ArtifactManagement artifactManagement = null; private transient EntityFactory entityFactory; - private transient Page firstPagetArtifacts = null; + private transient Page firstPagetArtifacts = null; private Long baseSwModuleId = null; /** @@ -72,26 +72,26 @@ public ArtifactBeanQuery(final QueryDefinition definition, final Map loadBeans(final int startIndex, final int count) { - Page artifactBeans; + protected List loadBeans(final int startIndex, final int count) { + Page artifactBeans; if (startIndex == 0 && firstPagetArtifacts != null) { artifactBeans = firstPagetArtifacts; } else { - artifactBeans = getArtifactManagement().findLocalArtifactBySoftwareModule( - new OffsetBasedPageRequest(startIndex, count, sort), baseSwModuleId); + artifactBeans = getArtifactManagement() + .findArtifactBySoftwareModule(new OffsetBasedPageRequest(startIndex, count, sort), baseSwModuleId); } return artifactBeans.getContent(); } @Override - protected void saveBeans(final List addedTargets, final List modifiedTargets, - final List removedTargets) { + protected void saveBeans(final List addedTargets, final List modifiedTargets, + final List removedTargets) { // CRUD operations on Target will be done through repository methods } @@ -99,8 +99,8 @@ protected void saveBeans(final List addedTargets, final List Integer.MAX_VALUE) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/details/ArtifactDetailsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/details/ArtifactDetailsLayout.java index 7549db040b..f9713ef2ec 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/details/ArtifactDetailsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/details/ArtifactDetailsLayout.java @@ -278,7 +278,7 @@ private void confirmAndDeleteArtifact(final Long id, final String fileName) { if (ok) { final ArtifactManagement artifactManagement = SpringContextHelper .getBean(ArtifactManagement.class); - artifactManagement.deleteLocalArtifact(id); + artifactManagement.deleteArtifact(id); uINotification.displaySuccess(i18n.get("message.artifact.deleted", fileName)); if (artifactUploadState.getSelectedBaseSwModuleId().isPresent()) { populateArtifactDetails(artifactUploadState.getSelectedBaseSwModuleId().get(), diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/BaseSwModuleBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/BaseSwModuleBeanQuery.java index 103481f89f..6b5178e893 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/BaseSwModuleBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/BaseSwModuleBeanQuery.java @@ -80,8 +80,8 @@ protected List loadBeans(final int startIndex, fina .findSoftwareModulesAll(new OffsetBasedPageRequest(startIndex, count, sort)); } else { - swModuleBeans = getSoftwareManagementService() - .findSoftwareModuleByFilters(new OffsetBasedPageRequest(startIndex, count, sort), searchText, type); + swModuleBeans = getSoftwareManagementService().findSoftwareModuleByFilters( + new OffsetBasedPageRequest(startIndex, count, sort), searchText, type.getId()); } for (final SoftwareModule swModule : swModuleBeans) { @@ -113,7 +113,7 @@ public int size() { if (type == null && Strings.isNullOrEmpty(searchText)) { size = getSoftwareManagementService().countSoftwareModulesAll(); } else { - size = getSoftwareManagementService().countSoftwareModuleByFilters(searchText, type); + size = getSoftwareManagementService().countSoftwareModuleByFilters(searchText, type.getId()); } if (size > Integer.MAX_VALUE) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadConfirmationWindow.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadConfirmationWindow.java index c71a58367f..6f5735b0a1 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadConfirmationWindow.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadConfirmationWindow.java @@ -22,7 +22,7 @@ import org.eclipse.hawkbit.repository.exception.ArtifactUploadFailedException; import org.eclipse.hawkbit.repository.exception.InvalidMD5HashException; import org.eclipse.hawkbit.repository.exception.InvalidSHA1HashException; -import org.eclipse.hawkbit.repository.model.LocalArtifact; +import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState; import org.eclipse.hawkbit.ui.artifacts.state.CustomFile; @@ -191,8 +191,7 @@ private void setWarningIcon(final Label warningIconLabel, final String fileName, final ArtifactManagement artifactManagement = SpringContextHelper.getBean(ArtifactManagement.class); if (HawkbitCommonUtil.trimAndNullIfEmpty(fileName) != null) { final Long baseSwId = (Long) item.getItemProperty(BASE_SOFTWARE_ID).getValue(); - final List artifactList = artifactManagement.findByFilenameAndSoftwareModule(fileName, - baseSwId); + final List artifactList = artifactManagement.findByFilenameAndSoftwareModule(fileName, baseSwId); if (!artifactList.isEmpty()) { warningIconLabel.setVisible(true); if (isErrorIcon(warningIconLabel)) { @@ -434,7 +433,7 @@ private void hideErrorIcon(final Label warningLabel, final int errorLabelCount, final Label errorLabel, final String oldFileName, final Long currentSwId) { if (warningLabel == null && (errorLabelCount > 1 || (duplicateCount == 1 && errorLabelCount == 1))) { final ArtifactManagement artifactManagement = SpringContextHelper.getBean(ArtifactManagement.class); - final List artifactList = artifactManagement.findByFilenameAndSoftwareModule(oldFileName, + final List artifactList = artifactManagement.findByFilenameAndSoftwareModule(oldFileName, currentSwId); errorLabel.removeStyleName(SPUIStyleDefinitions.ERROR_LABEL); errorLabel.setDescription(i18n.get(ALREADY_EXISTS_MSG)); @@ -591,7 +590,7 @@ private void processArtifactUpload() { customFile.getBaseSoftwareModuleName(), customFile.getBaseSoftwareModuleVersion()); if (customFile.getFileName().equals(fileName) && baseSwModuleNameVersion.equals(baseSoftwareModuleNameVersion)) { - createLocalArtifact(itemId, customFile.getFilePath(), artifactManagement, bSoftwareModule); + createArtifact(itemId, customFile.getFilePath(), artifactManagement, bSoftwareModule); } } refreshArtifactDetailsLayout = checkIfArtifactDetailsDispalyed(bSoftwareModule.getId()); @@ -619,8 +618,8 @@ private void onResultDetailsPopupClose() { currentUploadResultWindow = null; } - private void createLocalArtifact(final String itemId, final String filePath, - final ArtifactManagement artifactManagement, final SoftwareModule baseSw) { + private void createArtifact(final String itemId, final String filePath, final ArtifactManagement artifactManagement, + final SoftwareModule baseSw) { final File newFile = new File(filePath); final Item item = tabelContainer.getItem(itemId); @@ -633,7 +632,7 @@ private void createLocalArtifact(final String itemId, final String filePath, try (FileInputStream fis = new FileInputStream(newFile)) { - artifactManagement.createLocalArtifact(fis, baseSw.getId(), providedFileName, + artifactManagement.createArtifact(fis, baseSw.getId(), providedFileName, HawkbitCommonUtil.trimAndNullIfEmpty(md5Checksum), HawkbitCommonUtil.trimAndNullIfEmpty(sha1Checksum), true, customFile.getMimeType()); saveUploadStatus(providedFileName, swModuleNameVersion, SUCCESS, ""); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwMetadataPopupLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwMetadataPopupLayout.java index 3ff0dd4766..e271661dda 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwMetadataPopupLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwMetadataPopupLayout.java @@ -43,7 +43,7 @@ public class SwMetadataPopupLayout extends AbstractMetadataPopupLayout getMetadataList() { @Override protected void deleteMetadata(final SoftwareModule entity, final String key, final String value) { final SoftwareModuleMetadata swMetadata = entityFactory.generateSoftwareModuleMetadata(entity, key, value); - softwareManagement.deleteSoftwareModuleMetadata(entity, key); + softwareManagement.deleteSoftwareModuleMetadata(entity.getId(), key); eventBus.publish(this, new MetadataEvent(MetadataUIEvent.DELETE_SOFTWARE_MODULE_METADATA, swMetadata)); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleBeanQuery.java index 7222b10124..ba40372cb2 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleBeanQuery.java @@ -79,7 +79,7 @@ protected List loadBeans(final int startIndex, final int final List proxyBeans = new ArrayList<>(); swModuleBeans = getSoftwareManagement().findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc( - new OffsetBasedPageRequest(startIndex, count), orderByDistId, searchText, type); + new OffsetBasedPageRequest(startIndex, count), orderByDistId, searchText, type.getId()); for (final AssignedSoftwareModule swModule : swModuleBeans) { proxyBeans.add(getProxyBean(swModule)); @@ -114,7 +114,7 @@ public int size() { if (type == null && Strings.isNullOrEmpty(searchText)) { size = getSoftwareManagement().countSoftwareModulesAll(); } else { - size = getSoftwareManagement().countSoftwareModuleByFilters(searchText, type); + size = getSoftwareManagement().countSoftwareModuleByFilters(searchText, type.getId()); } if (size > Integer.MAX_VALUE) { From e2281ac67bb035a88e9a9c09294e3316b0757c18 Mon Sep 17 00:00:00 2001 From: kaizimmerm Date: Thu, 20 Oct 2016 14:57:07 +0200 Subject: [PATCH 2/5] Removed further unnedded repo methods. Signed-off-by: kaizimmerm --- .../AmqpMessageDispatcherServiceTest.java | 3 +- .../json/model/artifact/MgmtArtifact.java | 41 ------------------- .../resource/MgmtSoftwareModuleMapper.java | 10 +---- .../MgmtSoftwareModuleResourceTest.java | 21 +++++----- .../repository/SoftwareManagement.java | 29 ++++--------- .../repository/model/SoftwareModule.java | 23 +---------- .../repository/jpa/JpaArtifactManagement.java | 2 +- .../repository/jpa/JpaSoftwareManagement.java | 14 +------ .../jpa/model/JpaSoftwareModule.java | 17 ++++---- .../V1_8_2__remove_external_artifact___H2.sql | 2 +- ..._8_2__remove_external_artifact___MYSQL.sql | 2 +- .../jpa/ArtifactManagementTest.java | 2 +- .../jpa/SoftwareManagementTest.java | 16 ++++---- .../resources/application-test.properties | 5 +++ .../src/test/resources/logback-spring.xml | 2 + .../smtable/BaseSwModuleBeanQuery.java | 23 +++++------ .../smtable/SoftwareModuleDetails.java | 2 +- .../smtable/SoftwareModuleTable.java | 2 +- .../smtable/SwMetadataPopupLayout.java | 2 +- .../smtable/SwModuleBeanQuery.java | 30 ++++++-------- .../smtable/SwModuleDetails.java | 4 +- .../distributions/smtable/SwModuleTable.java | 6 +-- 22 files changed, 82 insertions(+), 176 deletions(-) diff --git a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java index 6ec21af9b0..c001e4fe3f 100644 --- a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java +++ b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java @@ -19,6 +19,7 @@ import java.net.URI; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Optional; @@ -112,7 +113,7 @@ public void before() throws Exception { @Description("Verfies that download and install event with no software modul works") public void testSendDownloadRequesWithEmptySoftwareModules() { final TargetAssignDistributionSetEvent targetAssignDistributionSetEvent = new TargetAssignDistributionSetEvent( - 1L, TENANT, testTarget, 1L, new ArrayList()); + 1L, TENANT, testTarget, 1L, Collections.emptyList()); amqpMessageDispatcherService.targetAssignDistributionSet(targetAssignDistributionSetEvent); final Message sendMessage = createArgumentCapture( targetAssignDistributionSetEvent.getTarget().getTargetInfo().getAddress()); diff --git a/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/json/model/artifact/MgmtArtifact.java b/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/json/model/artifact/MgmtArtifact.java index afb2d204ac..c0bf8998b5 100644 --- a/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/json/model/artifact/MgmtArtifact.java +++ b/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/json/model/artifact/MgmtArtifact.java @@ -15,7 +15,6 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonValue; /** * A json annotated rest model for Artifact to RESTful API representation. @@ -24,9 +23,6 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class MgmtArtifact extends MgmtBaseEntity { - @JsonProperty(required = true) - private ArtifactType type; - @JsonProperty("id") private Long artifactId; @@ -40,18 +36,9 @@ public class MgmtArtifact extends MgmtBaseEntity { private Long size; public MgmtArtifact() { - super(); // need for json encoder } - /** - * @param type - * the type to set - */ - public void setType(final ArtifactType type) { - this.type = type; - } - /** * @param hashes * the hashes to set @@ -70,13 +57,6 @@ public void setArtifactId(final Long artifactId) { this.artifactId = artifactId; } - /** - * @return the type - */ - public ArtifactType getType() { - return type; - } - /** * @return the artifactId */ @@ -107,27 +87,6 @@ public void setProvidedFilename(final String providedFilename) { this.providedFilename = providedFilename; } - /** - * Type maps to either local artifact} or external artifact. - */ - public enum ArtifactType { - LOCAL("local"), EXTERNAL("external"); - - private final String name; - - private ArtifactType(final String name) { - this.name = name; - } - - /** - * @return the name - */ - @JsonValue - public String getName() { - return name; - } - } - /** * @return the size */ diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleMapper.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleMapper.java index eb0728cf84..d7f23a0191 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleMapper.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleMapper.java @@ -155,11 +155,7 @@ public static MgmtSoftwareModule toResponse(final SoftwareModule baseSofwareModu * @return */ static MgmtArtifact toResponse(final Artifact artifact) { - final MgmtArtifact.ArtifactType type = artifact instanceof Artifact ? MgmtArtifact.ArtifactType.LOCAL - : MgmtArtifact.ArtifactType.EXTERNAL; - final MgmtArtifact artifactRest = new MgmtArtifact(); - artifactRest.setType(type); artifactRest.setArtifactId(artifact.getId()); artifactRest.setSize(artifact.getSize()); artifactRest.setHashes(new MgmtArtifactHash(artifact.getSha1Hash(), artifact.getMd5Hash())); @@ -171,10 +167,8 @@ static MgmtArtifact toResponse(final Artifact artifact) { artifactRest.add(linkTo(methodOn(MgmtSoftwareModuleRestApi.class) .getArtifact(artifact.getSoftwareModule().getId(), artifact.getId())).withRel("self")); - if (artifact instanceof Artifact) { - artifactRest.add(linkTo(methodOn(MgmtDownloadArtifactResource.class) - .downloadArtifact(artifact.getSoftwareModule().getId(), artifact.getId())).withRel("download")); - } + artifactRest.add(linkTo(methodOn(MgmtDownloadArtifactResource.class) + .downloadArtifact(artifact.getSoftwareModule().getId(), artifact.getId())).withRel("download")); return artifactRest; } diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java index 60ce8e7352..a875807961 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java @@ -139,7 +139,7 @@ public void uploadArtifact() throws Exception { .accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$.type", equalTo("local"))).andExpect(jsonPath("$.hashes.md5", equalTo(md5sum))) + .andExpect(jsonPath("$.hashes.md5", equalTo(md5sum))) .andExpect(jsonPath("$.hashes.sha1", equalTo(sha1sum))) .andExpect(jsonPath("$.size", equalTo(random.length))) .andExpect(jsonPath("$.providedFilename", equalTo("origFilename"))).andReturn(); @@ -147,7 +147,7 @@ public void uploadArtifact() throws Exception { // check rest of response compared to DB final MgmtArtifact artResult = ResourceUtility .convertArtifactResponse(mvcResult.getResponse().getContentAsString()); - final Long artId = softwareManagement.findSoftwareModuleWithDetails(sm.getId()).getArtifacts().get(0).getId(); + final Long artId = softwareManagement.findSoftwareModuleById(sm.getId()).getArtifacts().get(0).getId(); assertThat(artResult.getArtifactId()).as("Wrong artifact id").isEqualTo(artId); assertThat(JsonPath.compile("$._links.self.href").read(mvcResult.getResponse().getContentAsString()).toString()) .as("Link contains no self url") @@ -167,8 +167,9 @@ private void assertArtifact(final SoftwareModule sm, final byte[] random) throws // binary assertTrue("Wrong artifact content", IOUtils.contentEquals(new ByteArrayInputStream(random), - artifactManagement.loadArtifactBinary( - softwareManagement.findSoftwareModuleWithDetails(sm.getId()).getArtifacts().get(0)) + artifactManagement + .loadArtifactBinary( + softwareManagement.findSoftwareModuleById(sm.getId()).getArtifacts().get(0)) .getFileInputStream())); // hashes @@ -179,7 +180,7 @@ private void assertArtifact(final SoftwareModule sm, final byte[] random) throws .isEqualTo(HashGeneratorUtils.generateMD5(random)); // metadata - assertThat(softwareManagement.findSoftwareModuleWithDetails(sm.getId()).getArtifacts().get(0).getFilename()) + assertThat(softwareManagement.findSoftwareModuleById(sm.getId()).getArtifacts().get(0).getFilename()) .as("wrong metadata of the filename").isEqualTo("origFilename"); } @@ -213,7 +214,7 @@ public void duplicateUploadArtifact() throws Exception { mvc.perform(fileUpload("/rest/v1/softwaremodules/{smId}/artifacts", sm.getId()).file(file) .accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$.type", equalTo("local"))).andExpect(jsonPath("$.hashes.md5", equalTo(md5sum))) + .andExpect(jsonPath("$.hashes.md5", equalTo(md5sum))) .andExpect(jsonPath("$.hashes.sha1", equalTo(sha1sum))) .andExpect(jsonPath("$.providedFilename", equalTo("orig"))).andExpect(status().isCreated()); @@ -342,7 +343,7 @@ public void getArtifact() throws Exception { .accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.id", equalTo(artifact.getId().intValue()))) - .andExpect(jsonPath("$.type", equalTo("local"))).andExpect(jsonPath("$.size", equalTo(random.length))) + .andExpect(jsonPath("$.size", equalTo(random.length))) .andExpect(jsonPath("$.hashes.md5", equalTo(artifact.getMd5Hash()))) .andExpect(jsonPath("$.hashes.sha1", equalTo(artifact.getSha1Hash()))) .andExpect(jsonPath("$.providedFilename", equalTo("file1"))) @@ -370,7 +371,6 @@ public void getArtifacts() throws Exception { .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.[0].id", equalTo(artifact.getId().intValue()))) - .andExpect(jsonPath("$.[0].type", equalTo("local"))) .andExpect(jsonPath("$.[0].size", equalTo(random.length))) .andExpect(jsonPath("$.[0].hashes.md5", equalTo(artifact.getMd5Hash()))) .andExpect(jsonPath("$.[0].hashes.sha1", equalTo(artifact.getSha1Hash()))) @@ -382,7 +382,6 @@ public void getArtifacts() throws Exception { equalTo("http://localhost/rest/v1/softwaremodules/" + sm.getId() + "/artifacts/" + artifact.getId()))) .andExpect(jsonPath("$.[1].id", equalTo(artifact2.getId().intValue()))) - .andExpect(jsonPath("$.[1].type", equalTo("local"))) .andExpect(jsonPath("$.[1].hashes.md5", equalTo(artifact2.getMd5Hash()))) .andExpect(jsonPath("$.[1].hashes.sha1", equalTo(artifact2.getSha1Hash()))) .andExpect(jsonPath("$.[1].providedFilename", equalTo("file2"))) @@ -908,7 +907,7 @@ public void deleteArtifact() throws Exception { // check repo before delete assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(1); - assertThat(softwareManagement.findSoftwareModuleWithDetails(sm.getId()).getArtifacts()).hasSize(2); + assertThat(softwareManagement.findSoftwareModuleById(sm.getId()).getArtifacts()).hasSize(2); assertThat(artifactManagement.countArtifactsAll()).isEqualTo(2); // delete @@ -919,7 +918,7 @@ public void deleteArtifact() throws Exception { assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).as("After the sm should be marked as deleted") .hasSize(1); assertThat(artifactManagement.countArtifactsAll()).isEqualTo(1); - assertThat(softwareManagement.findSoftwareModuleWithDetails(sm.getId()).getArtifacts()) + assertThat(softwareManagement.findSoftwareModuleById(sm.getId()).getArtifacts()) .as("After delete artifact should available for marked as deleted sm's").hasSize(1); } diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java index 6e6b9b87ef..d65411a59a 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/SoftwareManagement.java @@ -118,7 +118,7 @@ public interface SoftwareManagement { * * @param types * to create - * @return created {@link Entity} + * @return created Entity */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) List createSoftwareModuleType(@NotNull Collection types); @@ -128,13 +128,13 @@ public interface SoftwareManagement { * * @param type * to create - * @return created {@link Entity} + * @return created Entity */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) SoftwareModuleType createSoftwareModuleType(@NotNull SoftwareModuleType type); /** - * Deletes the given {@link SoftwareModule} {@link Entity}. + * Deletes the given {@link SoftwareModule} Entity. * * @param moduleId * is the {@link SoftwareModule} to be deleted @@ -256,7 +256,7 @@ Page findSoftwareModuleMetadataBySoftwareModuleId(@NotNu /** * finds all meta data by the given software module id. * - * @param softwareModuleId + * @param moduleId * the software module id to retrieve the meta data from * @param rsqlParam * filter definition in RSQL syntax @@ -272,7 +272,7 @@ Page findSoftwareModuleMetadataBySoftwareModuleId(@NotNu * if the RSQL syntax is wrong */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - Page findSoftwareModuleMetadataBySoftwareModuleId(@NotNull Long softwareModuleId, + Page findSoftwareModuleMetadataBySoftwareModuleId(@NotNull Long moduleId, @NotNull String rsqlParam, @NotNull Pageable pageable); /** @@ -407,19 +407,6 @@ Slice findSoftwareModuleOrderBySetAssignmentAndModuleNam @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) Page findSoftwareModuleTypesAll(@NotNull String rsqlParam, @NotNull Pageable pageable); - /** - * Retrieves software module including details ( - * {@link SoftwareModule#getArtifacts()}). - * - * @param id - * parameter - * @param isDeleted - * parameter - * @return the found {@link SoftwareModule}s - */ - @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - SoftwareModule findSoftwareModuleWithDetails(@NotNull Long id); - /** * Updates existing {@link SoftwareModule}. Update-able values are * {@link SoftwareModule#getDescription()} @@ -428,7 +415,7 @@ Slice findSoftwareModuleOrderBySetAssignmentAndModuleNam * @param sm * to update * - * @return the saved {@link Entity}. + * @return the saved Entity. * * @throws NullPointerException * of {@link SoftwareModule#getId()} is null @@ -456,7 +443,7 @@ Slice findSoftwareModuleOrderBySetAssignmentAndModuleNam * * @param sm * to update - * @return updated {@link Entity} + * @return updated Entity */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY) SoftwareModuleType updateSoftwareModuleType(@NotNull SoftwareModuleType sm); @@ -476,6 +463,6 @@ Slice findSoftwareModuleOrderBySetAssignmentAndModuleNam * @return result of all meta data entries for a given software module id. */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY) - List findSoftwareModuleMetadataBySoftwareModuleId(Long softwareModuleId); + List findSoftwareModuleMetadataBySoftwareModuleId(@NotNull Long moduleId); } diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModule.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModule.java index 002adf4939..66a1fa3ff9 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModule.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/SoftwareModule.java @@ -16,13 +16,12 @@ * */ public interface SoftwareModule extends NamedVersionedEntity { - /** * @param artifact * is added to the assigned {@link Artifact}s. */ void addArtifact(Artifact artifact); - + /** * @param artifactId * to look for @@ -66,12 +65,6 @@ default Optional getArtifactByFilename(final String fileName) { */ void setVendor(String vendor); - /** - * @param artifact - * is removed from the assigned {@link Artifact}s. - */ - void removeArtifact(Artifact artifact); - /** * @return the type of the software module */ @@ -83,26 +76,12 @@ default Optional getArtifactByFilename(final String fileName) { */ boolean isDeleted(); - /** - * Marks or un-marks this software module as deleted. - * - * @param deleted - * {@code true} if the software module should be marked as - * deleted otherwise {@code false} - */ - void setDeleted(boolean deleted); - /** * @param type * the module type for this software module */ void setType(SoftwareModuleType type); - /** - * @return immutable list of meta data elements. - */ - List getMetadata(); - /** * @return immutable list of {@link DistributionSet}s the module is assigned * to diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaArtifactManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaArtifactManagement.java index 92623fb7bf..c8bfc53c4a 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaArtifactManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaArtifactManagement.java @@ -135,7 +135,7 @@ public void deleteArtifact(final Long id) { clearArtifactBinary(existing); - existing.getSoftwareModule().removeArtifact(existing); + ((JpaSoftwareModule) existing.getSoftwareModule()).removeArtifact(existing); softwareModuleRepository.save((JpaSoftwareModule) existing.getSoftwareModule()); localArtifactRepository.delete(id); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java index 69b068b6ac..7308fb1d03 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java @@ -207,9 +207,7 @@ private static Page convertSmMdPage(final Page spec = SoftwareModuleSpecification.byId(id); - - return softwareModuleRepository.findOne(spec); + return softwareModuleRepository.findOne(id); } @Override @@ -297,16 +295,6 @@ public Long countSoftwareModulesAll() { return countSwModuleByCriteriaAPI(Lists.newArrayList(spec)); } - @Override - public SoftwareModule findSoftwareModuleWithDetails(final Long id) { - final SoftwareModule result = findSoftwareModuleById(id); - if (result != null) { - result.getArtifacts().size(); - } - - return result; - } - @Override public Page findSoftwareModulesByPredicate(final String rsqlParam, final Pageable pageable) { final Specification spec = RSQLUtility.parse(rsqlParam, SoftwareModuleFields.class, diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModule.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModule.java index ba2eb193df..096d0460f4 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModule.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaSoftwareModule.java @@ -71,7 +71,8 @@ public class JpaSoftwareModule extends AbstractJpaNamedVersionedEntity implement private String vendor; @CascadeOnDelete - @OneToMany(mappedBy = "softwareModule", cascade = { CascadeType.ALL }, targetEntity = JpaArtifact.class) + @OneToMany(fetch = FetchType.LAZY, mappedBy = "softwareModule", cascade = { + CascadeType.ALL }, targetEntity = JpaArtifact.class) private List artifacts; @CascadeOnDelete @@ -107,10 +108,6 @@ public JpaSoftwareModule(final SoftwareModuleType type, final String name, final this.type = (JpaSoftwareModuleType) type; } - /** - * @param artifact - * is added to the assigned {@link Artifact}s. - */ @Override public void addArtifact(final Artifact artifact) { if (null == artifacts) { @@ -145,7 +142,6 @@ public String getVendor() { * @param artifact * is removed from the assigned {@link LocalArtifact}s. */ - @Override public void removeArtifact(final Artifact artifact) { if (artifacts != null) { artifacts.remove(artifact); @@ -167,7 +163,13 @@ public boolean isDeleted() { return deleted; } - @Override + /** + * Marks or un-marks this software module as deleted. + * + * @param deleted + * {@code true} if the software module should be marked as + * deleted otherwise {@code false} + */ public void setDeleted(final boolean deleted) { this.deleted = deleted; } @@ -177,7 +179,6 @@ public void setType(final SoftwareModuleType type) { this.type = (JpaSoftwareModuleType) type; } - @Override public List getMetadata() { if (metadata == null) { return Collections.emptyList(); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/resources/db/migration/H2/V1_8_2__remove_external_artifact___H2.sql b/hawkbit-repository/hawkbit-repository-jpa/src/main/resources/db/migration/H2/V1_8_2__remove_external_artifact___H2.sql index ac35f9c370..f806edd8dc 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/resources/db/migration/H2/V1_8_2__remove_external_artifact___H2.sql +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/resources/db/migration/H2/V1_8_2__remove_external_artifact___H2.sql @@ -1,2 +1,2 @@ +DROP TABLE sp_external_artifact; DROP TABLE sp_external_provider; -DROP TABLE sp_external_artifact; \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/resources/db/migration/MYSQL/V1_8_2__remove_external_artifact___MYSQL.sql b/hawkbit-repository/hawkbit-repository-jpa/src/main/resources/db/migration/MYSQL/V1_8_2__remove_external_artifact___MYSQL.sql index ac35f9c370..f806edd8dc 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/resources/db/migration/MYSQL/V1_8_2__remove_external_artifact___MYSQL.sql +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/resources/db/migration/MYSQL/V1_8_2__remove_external_artifact___MYSQL.sql @@ -1,2 +1,2 @@ +DROP TABLE sp_external_artifact; DROP TABLE sp_external_provider; -DROP TABLE sp_external_artifact; \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementTest.java index 62304c5318..a8bdd5fa78 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ArtifactManagementTest.java @@ -104,7 +104,7 @@ public void createArtifact() throws NoSuchAlgorithmException, IOException { assertThat(artifactRepository.findAll()).hasSize(4); assertThat(softwareModuleRepository.findAll()).hasSize(3); - assertThat(softwareManagement.findSoftwareModuleWithDetails(sm.getId()).getArtifacts()).hasSize(3); + assertThat(softwareManagement.findSoftwareModuleById(sm.getId()).getArtifacts()).hasSize(3); } @Test diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SoftwareManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SoftwareManagementTest.java index c5cad9a62c..895210da4b 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SoftwareManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/SoftwareManagementTest.java @@ -478,7 +478,7 @@ public void deleteSoftwareModulesWithSharedArtifact() throws IOException { // [STEP2]: Create newArtifactX and add it to SoftwareModuleX artifactManagement.createArtifact(new ByteArrayInputStream(source), moduleX.getId(), "artifactx", false); - moduleX = softwareManagement.findSoftwareModuleWithDetails(moduleX.getId()); + moduleX = softwareManagement.findSoftwareModuleById(moduleX.getId()); final Artifact artifactX = moduleX.getArtifacts().iterator().next(); // [STEP3]: Create SoftwareModuleY and add the same ArtifactX @@ -486,7 +486,7 @@ public void deleteSoftwareModulesWithSharedArtifact() throws IOException { // [STEP4]: Assign the same ArtifactX to SoftwareModuleY artifactManagement.createArtifact(new ByteArrayInputStream(source), moduleY.getId(), "artifactx", false); - moduleY = softwareManagement.findSoftwareModuleWithDetails(moduleY.getId()); + moduleY = softwareManagement.findSoftwareModuleById(moduleY.getId()); final Artifact artifactY = moduleY.getArtifacts().iterator().next(); // verify: that only one entry was created in mongoDB @@ -530,14 +530,14 @@ public void deleteMultipleSoftwareModulesWhichShareAnArtifact() throws IOExcepti SoftwareModule moduleX = createSoftwareModuleWithArtifacts(osType, "modulex", "v1.0", 0); artifactManagement.createArtifact(new ByteArrayInputStream(source), moduleX.getId(), "artifactx", false); - moduleX = softwareManagement.findSoftwareModuleWithDetails(moduleX.getId()); + moduleX = softwareManagement.findSoftwareModuleById(moduleX.getId()); final Artifact artifactX = moduleX.getArtifacts().iterator().next(); // [STEP2]: Create SoftwareModuleY and add the same ArtifactX SoftwareModule moduleY = createSoftwareModuleWithArtifacts(osType, "moduley", "v1.0", 0); artifactManagement.createArtifact(new ByteArrayInputStream(source), moduleY.getId(), "artifactx", false); - moduleY = softwareManagement.findSoftwareModuleWithDetails(moduleY.getId()); + moduleY = softwareManagement.findSoftwareModuleById(moduleY.getId()); final Artifact artifactY = moduleY.getArtifacts().iterator().next(); // verify: that only one entry was created in mongoDB @@ -591,7 +591,7 @@ private SoftwareModule createSoftwareModuleWithArtifacts(final SoftwareModuleTyp } // Verify correct Creation of SoftwareModule and corresponding artifacts - softwareModule = softwareManagement.findSoftwareModuleWithDetails(softwareModule.getId()); + softwareModule = softwareManagement.findSoftwareModuleById(softwareModule.getId()); assertThat(softwareModuleRepository.findAll()).hasSize((int) countSoftwareModule + 1); final List artifacts = softwareModule.getArtifacts(); @@ -935,13 +935,13 @@ public void deleteSoftwareModuleMetadata() { ah = softwareManagement.createSoftwareModuleMetadata(new JpaSoftwareModuleMetadata(knownKey1, ah, knownValue1)) .getSoftwareModule(); - assertThat(softwareManagement.findSoftwareModuleById(ah.getId()).getMetadata()) + assertThat(softwareManagement.findSoftwareModuleMetadataBySoftwareModuleId(ah.getId())) .as("Contains the created metadata element") .containsExactly(new JpaSoftwareModuleMetadata(knownKey1, ah, knownValue1)); softwareManagement.deleteSoftwareModuleMetadata(ah.getId(), knownKey1); - assertThat(softwareManagement.findSoftwareModuleById(ah.getId()).getMetadata()).as("Metadata elemenets are") - .isEmpty(); + assertThat(softwareManagement.findSoftwareModuleMetadataBySoftwareModuleId(ah.getId())) + .as("Metadata elemenets are").isEmpty(); } @Test diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/resources/application-test.properties b/hawkbit-repository/hawkbit-repository-jpa/src/test/resources/application-test.properties index 0882d901c9..ed93684d24 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/resources/application-test.properties +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/resources/application-test.properties @@ -25,6 +25,11 @@ spring.datasource.driverClassName=org.h2.Driver spring.datasource.username=sa spring.datasource.password=sa +spring.datasource.eclipselink.logging.logger=JavaLogger +spring.jpa.properties.eclipselink.logging.level=FINE +spring.jpa.properties.eclipselink.logging.level.sql=FINE +spring.jpa.properties.eclipselink.logging.parameters=true + flyway.enabled=true flyway.sqlMigrationSuffix=${spring.jpa.database}.sql #spring.jpa.show-sql=true diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/resources/logback-spring.xml b/hawkbit-repository/hawkbit-repository-jpa/src/test/resources/logback-spring.xml index 4a77556093..2079a6964a 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/resources/logback-spring.xml +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/resources/logback-spring.xml @@ -11,6 +11,8 @@ --> + + diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/BaseSwModuleBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/BaseSwModuleBeanQuery.java index 6b5178e893..8591517390 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/BaseSwModuleBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/BaseSwModuleBeanQuery.java @@ -8,9 +8,10 @@ */ package org.eclipse.hawkbit.ui.artifacts.smtable; -import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Optional; +import java.util.stream.Collectors; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.SoftwareManagement; @@ -37,8 +38,8 @@ public class BaseSwModuleBeanQuery extends AbstractBeanQuery { private static final long serialVersionUID = 4362142538539335466L; private transient SoftwareManagement softwareManagementService; - private SoftwareModuleType type; - private String searchText = null; + private Long type; + private String searchText; private final Sort sort = new Sort(Direction.ASC, "name", "version"); /** @@ -57,7 +58,8 @@ public BaseSwModuleBeanQuery(final QueryDefinition definition, final Map type.getId()).orElse(null); searchText = (String) queryConfig.get(SPUIDefinitions.FILTER_BY_TEXT); if (!Strings.isNullOrEmpty(searchText)) { searchText = String.format("%%%s%%", searchText); @@ -73,22 +75,17 @@ protected ProxyBaseSoftwareModuleItem constructBean() { @Override protected List loadBeans(final int startIndex, final int count) { final Slice swModuleBeans; - final List proxyBeans = new ArrayList<>(); if (type == null && Strings.isNullOrEmpty(searchText)) { swModuleBeans = getSoftwareManagementService() .findSoftwareModulesAll(new OffsetBasedPageRequest(startIndex, count, sort)); } else { - swModuleBeans = getSoftwareManagementService().findSoftwareModuleByFilters( - new OffsetBasedPageRequest(startIndex, count, sort), searchText, type.getId()); - } - - for (final SoftwareModule swModule : swModuleBeans) { - proxyBeans.add(getProxyBean(swModule)); + swModuleBeans = getSoftwareManagementService() + .findSoftwareModuleByFilters(new OffsetBasedPageRequest(startIndex, count, sort), searchText, type); } - return proxyBeans; + return swModuleBeans.getContent().stream().map(this::getProxyBean).collect(Collectors.toList()); } private ProxyBaseSoftwareModuleItem getProxyBean(final SoftwareModule bean) { @@ -113,7 +110,7 @@ public int size() { if (type == null && Strings.isNullOrEmpty(searchText)) { size = getSoftwareManagementService().countSoftwareModulesAll(); } else { - size = getSoftwareManagementService().countSoftwareModuleByFilters(searchText, type.getId()); + size = getSoftwareManagementService().countSoftwareModuleByFilters(searchText, type); } if (size > Integer.MAX_VALUE) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleDetails.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleDetails.java index 0e6b276904..2b0a74b13c 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleDetails.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleDetails.java @@ -209,7 +209,7 @@ protected Boolean isMetadataIconToBeDisplayed() { @Override protected void showMetadata(final ClickEvent event) { - final SoftwareModule swmodule = softwareManagement.findSoftwareModuleWithDetails(getSelectedBaseEntityId()); + final SoftwareModule swmodule = softwareManagement.findSoftwareModuleById(getSelectedBaseEntityId()); /* display the window */ UI.getCurrent().addWindow(swMetadataPopupLayout.getWindow(swmodule, null)); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java index 0168ad3d9a..13f3addf58 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/SoftwareModuleTable.java @@ -245,7 +245,7 @@ private String getNameAndVerion(final Object itemId) { } private void showMetadataDetails(final Long itemId) { - final SoftwareModule swmodule = softwareManagement.findSoftwareModuleWithDetails(itemId); + final SoftwareModule swmodule = softwareManagement.findSoftwareModuleById(itemId); /* display the window */ UI.getCurrent().addWindow(swMetadataPopupLayout.getWindow(swmodule, null)); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwMetadataPopupLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwMetadataPopupLayout.java index e271661dda..b98f72bb7f 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwMetadataPopupLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwMetadataPopupLayout.java @@ -71,7 +71,7 @@ protected SoftwareModuleMetadata updateMetadata(final SoftwareModule entity, fin @Override protected List getMetadataList() { - return getSelectedEntity().getMetadata(); + return softwareManagement.findSoftwareModuleMetadataBySoftwareModuleId(getSelectedEntity().getId()); } /** diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleBeanQuery.java index ba40372cb2..018ffed3f9 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleBeanQuery.java @@ -8,9 +8,10 @@ */ package org.eclipse.hawkbit.ui.distributions.smtable; -import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Optional; +import java.util.stream.Collectors; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.SoftwareManagement; @@ -22,7 +23,6 @@ import org.eclipse.hawkbit.ui.utils.SPDateTimeUtil; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SpringContextHelper; -import org.springframework.data.domain.Slice; import org.vaadin.addons.lazyquerycontainer.AbstractBeanQuery; import org.vaadin.addons.lazyquerycontainer.QueryDefinition; @@ -36,9 +36,9 @@ public class SwModuleBeanQuery extends AbstractBeanQuery { private static final long serialVersionUID = 4362142538539335466L; private transient SoftwareManagement softwareManagementService; - private SoftwareModuleType type; - private String searchText = null; - private Long orderByDistId = 0L; + private Long type; + private String searchText; + private Long orderByDistId; /** * Parametric Constructor. @@ -56,7 +56,8 @@ public SwModuleBeanQuery(final QueryDefinition definition, final Map type.getId()).orElse(null); searchText = (String) queryConfig.get(SPUIDefinitions.FILTER_BY_TEXT); if (!Strings.isNullOrEmpty(searchText)) { searchText = String.format("%%%s%%", searchText); @@ -75,17 +76,10 @@ protected ProxyBaseSwModuleItem constructBean() { @Override protected List loadBeans(final int startIndex, final int count) { - final Slice swModuleBeans; - final List proxyBeans = new ArrayList<>(); - - swModuleBeans = getSoftwareManagement().findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc( - new OffsetBasedPageRequest(startIndex, count), orderByDistId, searchText, type.getId()); - - for (final AssignedSoftwareModule swModule : swModuleBeans) { - proxyBeans.add(getProxyBean(swModule)); - } - - return proxyBeans; + return getSoftwareManagement() + .findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc( + new OffsetBasedPageRequest(startIndex, count), orderByDistId, searchText, type) + .getContent().stream().map(this::getProxyBean).collect(Collectors.toList()); } private ProxyBaseSwModuleItem getProxyBean(final AssignedSoftwareModule customSoftwareModule) { @@ -114,7 +108,7 @@ public int size() { if (type == null && Strings.isNullOrEmpty(searchText)) { size = getSoftwareManagement().countSoftwareModulesAll(); } else { - size = getSoftwareManagement().countSoftwareModuleByFilters(searchText, type.getId()); + size = getSoftwareManagement().countSoftwareModuleByFilters(searchText, type); } if (size > Integer.MAX_VALUE) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleDetails.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleDetails.java index 160abc438c..046de5e5e1 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleDetails.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleDetails.java @@ -153,7 +153,7 @@ private void populateDetails() { if (getSelectedBaseEntity().getType().getMaxAssignments() == 1) { maxAssign = getI18n().get("label.singleAssign.type"); } else { - maxAssign = getI18n().get("label.multiAssign.type"); + maxAssign = getI18n().get("label.multiAssign.type"); } updateSwModuleDetailsLayout(getSelectedBaseEntity().getType().getName(), getSelectedBaseEntity().getVendor(), maxAssign); @@ -217,7 +217,7 @@ protected Boolean isMetadataIconToBeDisplayed() { @Override protected void showMetadata(final ClickEvent event) { - final SoftwareModule swmodule = softwareManagement.findSoftwareModuleWithDetails(getSelectedBaseEntityId()); + final SoftwareModule swmodule = softwareManagement.findSoftwareModuleById(getSelectedBaseEntityId()); UI.getCurrent().addWindow(swMetadataPopupLayout.getWindow(swmodule, null)); } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTable.java index dd684009fb..e8504e7a46 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleTable.java @@ -27,11 +27,11 @@ import org.eclipse.hawkbit.ui.distributions.event.SaveActionWindowEvent; import org.eclipse.hawkbit.ui.distributions.state.ManageDistUIState; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; -import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions; import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions; import org.eclipse.hawkbit.ui.utils.TableColumn; +import org.eclipse.hawkbit.ui.utils.UIComponentIdProvider; import org.springframework.beans.factory.annotation.Autowired; import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory; import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer; @@ -118,7 +118,7 @@ void onEvent(final DistributionsUIEvent event) { @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final SaveActionWindowEvent event) { if (event == SaveActionWindowEvent.DELETE_ALL_SOFWARE) { - UI.getCurrent().access(() -> refreshFilter()); + UI.getCurrent().access(this::refreshFilter); } } @@ -400,7 +400,7 @@ protected void setDataAvailable(final boolean available) { } private void showMetadataDetails(final Long itemId) { - final SoftwareModule swmodule = softwareManagement.findSoftwareModuleWithDetails(itemId); + final SoftwareModule swmodule = softwareManagement.findSoftwareModuleById(itemId); UI.getCurrent().addWindow(swMetadataPopupLayout.getWindow(swmodule, null)); } From 5d9436d31225ce0b472d103033a3f9fb36818ee1 Mon Sep 17 00:00:00 2001 From: kaizimmerm Date: Thu, 20 Oct 2016 15:26:06 +0200 Subject: [PATCH 3/5] Fix sonar issues Signed-off-by: kaizimmerm --- .../hawkbit/ui/artifacts/smtable/BaseSwModuleBeanQuery.java | 2 +- .../hawkbit/ui/distributions/smtable/SwModuleBeanQuery.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/BaseSwModuleBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/BaseSwModuleBeanQuery.java index 8591517390..7bf4f8bfe8 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/BaseSwModuleBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/BaseSwModuleBeanQuery.java @@ -59,7 +59,7 @@ public BaseSwModuleBeanQuery(final QueryDefinition definition, final Map type.getId()).orElse(null); + .map(t -> t.getId()).orElse(null); searchText = (String) queryConfig.get(SPUIDefinitions.FILTER_BY_TEXT); if (!Strings.isNullOrEmpty(searchText)) { searchText = String.format("%%%s%%", searchText); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleBeanQuery.java index 018ffed3f9..df4dfb0588 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleBeanQuery.java @@ -57,7 +57,7 @@ public SwModuleBeanQuery(final QueryDefinition definition, final Map type.getId()).orElse(null); + .map(t -> t.getId()).orElse(null); searchText = (String) queryConfig.get(SPUIDefinitions.FILTER_BY_TEXT); if (!Strings.isNullOrEmpty(searchText)) { searchText = String.format("%%%s%%", searchText); From 14f07c1f82120643afe2d95f149499880936deb5 Mon Sep 17 00:00:00 2001 From: kaizimmerm Date: Sat, 22 Oct 2016 07:12:19 +0200 Subject: [PATCH 4/5] Fixed potential orderByDistId null problem Signed-off-by: kaizimmerm --- .../smtable/SwModuleBeanQuery.java | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleBeanQuery.java index df4dfb0588..e3e6e2de90 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/smtable/SwModuleBeanQuery.java @@ -36,9 +36,9 @@ public class SwModuleBeanQuery extends AbstractBeanQuery { private static final long serialVersionUID = 4362142538539335466L; private transient SoftwareManagement softwareManagementService; - private Long type; - private String searchText; - private Long orderByDistId; + private final Long type; + private final String searchText; + private final Long orderByDistId; /** * Parametric Constructor. @@ -58,15 +58,20 @@ public SwModuleBeanQuery(final QueryDefinition definition, final Map t.getId()).orElse(null); - searchText = (String) queryConfig.get(SPUIDefinitions.FILTER_BY_TEXT); - if (!Strings.isNullOrEmpty(searchText)) { - searchText = String.format("%%%s%%", searchText); - } - orderByDistId = (Long) queryConfig.get(SPUIDefinitions.ORDER_BY_DISTRIBUTION); - if (orderByDistId == null) { - orderByDistId = 0L; + final String text = (String) queryConfig.get(SPUIDefinitions.FILTER_BY_TEXT); + if (!Strings.isNullOrEmpty(text)) { + searchText = String.format("%%%s%%", text); + } else { + searchText = null; } + orderByDistId = Optional.ofNullable((Long) queryConfig.get(SPUIDefinitions.ORDER_BY_DISTRIBUTION)) + .orElse(0L); + return; } + + orderByDistId = 0L; + type = null; + searchText = null; } @Override @@ -79,10 +84,10 @@ protected List loadBeans(final int startIndex, final int return getSoftwareManagement() .findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc( new OffsetBasedPageRequest(startIndex, count), orderByDistId, searchText, type) - .getContent().stream().map(this::getProxyBean).collect(Collectors.toList()); + .getContent().stream().map(SwModuleBeanQuery::getProxyBean).collect(Collectors.toList()); } - private ProxyBaseSwModuleItem getProxyBean(final AssignedSoftwareModule customSoftwareModule) { + private static ProxyBaseSwModuleItem getProxyBean(final AssignedSoftwareModule customSoftwareModule) { final SoftwareModule bean = customSoftwareModule.getSoftwareModule(); final ProxyBaseSwModuleItem proxyItem = new ProxyBaseSwModuleItem(); proxyItem.setSwId(bean.getId()); From 1d0028ce9ef3df88e678d418f7938114b9852d0c Mon Sep 17 00:00:00 2001 From: kaizimmerm Date: Tue, 25 Oct 2016 19:47:13 +0200 Subject: [PATCH 5/5] Fixed paramter name. Signed-off-by: kaizimmerm --- .../amqp/AmqpAuthenticationMessageHandler.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpAuthenticationMessageHandler.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpAuthenticationMessageHandler.java index 7200f3204b..d60f4e233b 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpAuthenticationMessageHandler.java +++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpAuthenticationMessageHandler.java @@ -116,19 +116,19 @@ public Message onAuthenticationRequest(final Message message) { * * @param secruityToken * the security token which holds the target ID to check on - * @param localArtifact - * the local artifact to verify if the given target is allowed to - * download this artifact + * @param artifact + * the artifact to verify if the given target is allowed to + * download it */ private void checkIfArtifactIsAssignedToTarget(final TenantSecurityToken secruityToken, - final org.eclipse.hawkbit.repository.model.Artifact localArtifact) { + final org.eclipse.hawkbit.repository.model.Artifact artifact) { if (secruityToken.getControllerId() != null) { - checkByControllerId(localArtifact, secruityToken.getControllerId()); + checkByControllerId(artifact, secruityToken.getControllerId()); } else if (secruityToken.getTargetId() != null) { - checkByTargetId(localArtifact, secruityToken.getTargetId()); + checkByTargetId(artifact, secruityToken.getTargetId()); } else { - LOG.info("anonymous download no authentication check for artifact {}", localArtifact); + LOG.info("anonymous download no authentication check for artifact {}", artifact); return; }