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 6ec21af9b..c001e4fe3 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 static org.mockito.Mockito.when; 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 class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTest { @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 afb2d204a..c0bf8998b 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.JsonIgnoreProperties; 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 @@ import com.fasterxml.jackson.annotation.JsonValue; @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 class MgmtArtifact extends MgmtBaseEntity { this.artifactId = artifactId; } - /** - * @return the type - */ - public ArtifactType getType() { - return type; - } - /** * @return the artifactId */ @@ -107,27 +87,6 @@ public class MgmtArtifact extends MgmtBaseEntity { 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 eb0728cf8..d7f23a019 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 final class MgmtSoftwareModuleMapper { * @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 @@ public final class MgmtSoftwareModuleMapper { 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 60ce8e735..a87580796 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 class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW .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 class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW // 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 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW // 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 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW .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 class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW 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 class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW .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 class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW .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 class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW 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 class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW // 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 class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW 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 6e6b9b87e..d65411a59 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 @@ public interface SoftwareManagement { /** * 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 @@ public interface SoftwareManagement { * 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 @@ public interface SoftwareManagement { @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 @@ public interface SoftwareManagement { * @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 @@ public interface SoftwareManagement { * * @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 @@ public interface SoftwareManagement { * @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 002adf493..66a1fa3ff 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 @@ import java.util.Optional; * */ 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 @@ public interface SoftwareModule extends NamedVersionedEntity { */ 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 @@ public interface SoftwareModule extends NamedVersionedEntity { */ 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 92623fb7b..c8bfc53c4 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 class JpaArtifactManagement implements ArtifactManagement { 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 69b068b6a..7308fb1d0 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 @@ public class JpaSoftwareManagement implements SoftwareManagement { @Override public SoftwareModule findSoftwareModuleById(final Long id) { - final Specification spec = SoftwareModuleSpecification.byId(id); - - return softwareModuleRepository.findOne(spec); + return softwareModuleRepository.findOne(id); } @Override @@ -297,16 +295,6 @@ public class JpaSoftwareManagement implements SoftwareManagement { 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 ba2eb193d..096d0460f 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 class JpaSoftwareModule extends AbstractJpaNamedVersionedEntity implement 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 class JpaSoftwareModule extends AbstractJpaNamedVersionedEntity implement * @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 class JpaSoftwareModule extends AbstractJpaNamedVersionedEntity implement 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 class JpaSoftwareModule extends AbstractJpaNamedVersionedEntity implement 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 ac35f9c37..f806edd8d 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 ac35f9c37..f806edd8d 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 62304c531..a8bdd5fa7 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 class ArtifactManagementTest extends AbstractJpaIntegrationTestWithMongoD 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 c5cad9a62..895210da4 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 class SoftwareManagementTest extends AbstractJpaIntegrationTestWithMongoD // [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 class SoftwareManagementTest extends AbstractJpaIntegrationTestWithMongoD // [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 class SoftwareManagementTest extends AbstractJpaIntegrationTestWithMongoD 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 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTestWithMongoD } // 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 class SoftwareManagementTest extends AbstractJpaIntegrationTestWithMongoD 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 0882d901c..ed93684d2 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 4a7755609..2079a6964 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 6b5178e89..859151739 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 @@ import com.google.common.base.Strings; 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 class BaseSwModuleBeanQuery extends AbstractBeanQuery 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 @@ public class BaseSwModuleBeanQuery extends AbstractBeanQuery 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()); + swModuleBeans = getSoftwareManagementService() + .findSoftwareModuleByFilters(new OffsetBasedPageRequest(startIndex, count, sort), searchText, type); } - for (final SoftwareModule swModule : swModuleBeans) { - proxyBeans.add(getProxyBean(swModule)); - } - - return proxyBeans; + return swModuleBeans.getContent().stream().map(this::getProxyBean).collect(Collectors.toList()); } private ProxyBaseSoftwareModuleItem getProxyBean(final SoftwareModule bean) { @@ -113,7 +110,7 @@ public class BaseSwModuleBeanQuery extends AbstractBeanQuery 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 0e6b27690..2b0a74b13 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 @@ public class SoftwareModuleDetails extends AbstractNamedVersionedEntityTableDeta @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 0168ad3d9..13f3addf5 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 @@ public class SoftwareModuleTable extends AbstractNamedVersionTable 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 ba40372cb..018ffed3f 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.HawkbitCommonUtil; 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 @@ import com.google.common.base.Strings; 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 class SwModuleBeanQuery extends AbstractBeanQuery final Object[] sortIds, final boolean[] sortStates) { super(definition, queryConfig, sortIds, sortStates); if (HawkbitCommonUtil.isNotNullOrEmpty(queryConfig)) { - type = (SoftwareModuleType) queryConfig.get(SPUIDefinitions.BY_SOFTWARE_MODULE_TYPE); + type = Optional.ofNullable((SoftwareModuleType) queryConfig.get(SPUIDefinitions.BY_SOFTWARE_MODULE_TYPE)) + .map(type -> 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 @@ public class SwModuleBeanQuery extends AbstractBeanQuery @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 class SwModuleBeanQuery extends AbstractBeanQuery 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 160abc438..046de5e5e 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 @@ public class SwModuleDetails extends AbstractNamedVersionedEntityTableDetailsLay 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 @@ public class SwModuleDetails extends AbstractNamedVersionedEntityTableDetailsLay @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 dd684009f..e8504e7a4 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.DistributionsViewAcceptCriteri 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 @@ public class SwModuleTable extends AbstractNamedVersionTable refreshFilter()); + UI.getCurrent().access(this::refreshFilter); } } @@ -400,7 +400,7 @@ public class SwModuleTable extends AbstractNamedVersionTable