diff --git a/examples/hawkbit-custom-theme-example/pom.xml b/examples/hawkbit-custom-theme-example/pom.xml index 7caa99ba2..875db18e3 100644 --- a/examples/hawkbit-custom-theme-example/pom.xml +++ b/examples/hawkbit-custom-theme-example/pom.xml @@ -79,6 +79,11 @@ hawkbit-http-security ${project.version} + + org.eclipse.hawkbit + hawkbit-repository-jpa + ${project.version} + diff --git a/examples/hawkbit-custom-theme-example/src/main/java/org/eclipse/hawkbit/app/Start.java b/examples/hawkbit-custom-theme-example/src/main/java/org/eclipse/hawkbit/app/Start.java index fdad8a999..7f80eb05b 100644 --- a/examples/hawkbit-custom-theme-example/src/main/java/org/eclipse/hawkbit/app/Start.java +++ b/examples/hawkbit-custom-theme-example/src/main/java/org/eclipse/hawkbit/app/Start.java @@ -8,6 +8,7 @@ package org.eclipse.hawkbit.app; * http://www.eclipse.org/legal/epl-v10.html */ +import org.eclipse.hawkbit.EnableJpaRepository; import org.eclipse.hawkbit.autoconfigure.security.EnableHawkbitManagedSecurityConfiguration; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -21,6 +22,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; @EnableHawkbitManagedSecurityConfiguration // Exception squid:S1118 - Spring boot standard behavior @SuppressWarnings({ "squid:S1118" }) +@EnableJpaRepository public class Start { /** * Main method to start the spring-boot application. diff --git a/examples/hawkbit-example-app/pom.xml b/examples/hawkbit-example-app/pom.xml index 957ba8d6a..f501d5529 100644 --- a/examples/hawkbit-example-app/pom.xml +++ b/examples/hawkbit-example-app/pom.xml @@ -92,6 +92,11 @@ hawkbit-http-security ${project.version} + + org.eclipse.hawkbit + hawkbit-repository-jpa + ${project.version} + diff --git a/examples/hawkbit-example-app/src/main/java/org/eclipse/hawkbit/app/Start.java b/examples/hawkbit-example-app/src/main/java/org/eclipse/hawkbit/app/Start.java index d22d6f4a1..95fb39147 100644 --- a/examples/hawkbit-example-app/src/main/java/org/eclipse/hawkbit/app/Start.java +++ b/examples/hawkbit-example-app/src/main/java/org/eclipse/hawkbit/app/Start.java @@ -8,6 +8,7 @@ */ package org.eclipse.hawkbit.app; +import org.eclipse.hawkbit.EnableJpaRepository; import org.eclipse.hawkbit.autoconfigure.security.EnableHawkbitManagedSecurityConfiguration; import org.eclipse.hawkbit.ddi.EnableDdiApi; import org.eclipse.hawkbit.mgmt.EnableMgmtApi; @@ -23,6 +24,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; @EnableHawkbitManagedSecurityConfiguration @EnableMgmtApi @EnableDdiApi +@EnableJpaRepository // Exception squid:S1118 - Spring boot standard behavior @SuppressWarnings({ "squid:S1118" }) public class Start { diff --git a/hawkbit-ddi-resource/pom.xml b/hawkbit-ddi-resource/pom.xml index 35aff47f5..cb85f8c8c 100644 --- a/hawkbit-ddi-resource/pom.xml +++ b/hawkbit-ddi-resource/pom.xml @@ -38,7 +38,7 @@ org.eclipse.hawkbit - hawkbit-repository-jpa + hawkbit-repository-api ${project.version} @@ -54,6 +54,12 @@ ${project.version} test + + org.eclipse.hawkbit + hawkbit-repository-jpa + ${project.version} + test + org.eclipse.hawkbit hawkbit-rest-core 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 5bed44295..85a326f9a 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 @@ -17,10 +17,9 @@ import javax.servlet.http.HttpServletRequest; import org.eclipse.hawkbit.artifact.repository.model.DbArtifact; import org.eclipse.hawkbit.ddi.dl.rest.api.DdiDlArtifactStoreControllerRestApi; import org.eclipse.hawkbit.repository.ArtifactManagement; -import org.eclipse.hawkbit.repository.RepositoryConstants; import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.EntityFactory; -import org.eclipse.hawkbit.repository.jpa.cache.CacheWriteNotify; +import org.eclipse.hawkbit.repository.RepositoryConstants; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; @@ -60,9 +59,6 @@ public class DdiArtifactStoreController implements DdiDlArtifactStoreControllerR @Autowired private ControllerManagement controllerManagement; - @Autowired - private CacheWriteNotify cacheWriteNotify; - @Autowired private HawkbitSecurityProperties securityProperties; @@ -101,7 +97,8 @@ public class DdiArtifactStoreController implements DdiDlArtifactStoreControllerR requestResponseContextHolder.getHttpServletRequest(), targetid, artifact); result = RestResourceConversionHelper.writeFileResponse(artifact, requestResponseContextHolder.getHttpServletResponse(), - requestResponseContextHolder.getHttpServletRequest(), file, cacheWriteNotify, action.getId()); + requestResponseContextHolder.getHttpServletRequest(), file, controllerManagement, + action.getId()); } else { result = RestResourceConversionHelper.writeFileResponse(artifact, requestResponseContextHolder.getHttpServletResponse(), @@ -149,10 +146,11 @@ public class DdiArtifactStoreController implements DdiDlArtifactStoreControllerR actionStatus.setStatus(Status.DOWNLOAD); if (range != null) { - actionStatus.addMessage(RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target downloads range " + range + " of: " - + request.getRequestURI()); + actionStatus.addMessage(RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target downloads range " + range + + " of: " + request.getRequestURI()); } else { - actionStatus.addMessage(RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target downloads: " + request.getRequestURI()); + actionStatus.addMessage( + RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target downloads: " + request.getRequestURI()); } controllerManagement.addInformationalActionStatus(actionStatus); return action; 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 0c6fa4386..20d1b2e29 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 @@ -29,12 +29,11 @@ import org.eclipse.hawkbit.ddi.json.model.DdiDeploymentBase; import org.eclipse.hawkbit.ddi.json.model.DdiResult.FinalResult; import org.eclipse.hawkbit.ddi.rest.api.DdiRootControllerRestApi; import org.eclipse.hawkbit.repository.ArtifactManagement; -import org.eclipse.hawkbit.repository.RepositoryConstants; import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.EntityFactory; +import org.eclipse.hawkbit.repository.RepositoryConstants; import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; -import org.eclipse.hawkbit.repository.jpa.cache.CacheWriteNotify; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; @@ -83,9 +82,6 @@ public class DdiRootController implements DdiRootControllerRestApi { @Autowired private ArtifactManagement artifactManagement; - @Autowired - private CacheWriteNotify cacheWriteNotify; - @Autowired private HawkbitSecurityProperties securityProperties; @@ -167,7 +163,8 @@ public class DdiRootController implements DdiRootControllerRestApi { module); result = RestResourceConversionHelper.writeFileResponse(artifact, requestResponseContextHolder.getHttpServletResponse(), - requestResponseContextHolder.getHttpServletRequest(), file, cacheWriteNotify, action.getId()); + requestResponseContextHolder.getHttpServletRequest(), file, controllerManagement, + action.getId()); } } return result; @@ -185,10 +182,11 @@ public class DdiRootController implements DdiRootControllerRestApi { statusMessage.setStatus(Status.DOWNLOAD); if (range != null) { - statusMessage.addMessage(RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target downloads range " + range + " of: " - + request.getRequestURI()); + statusMessage.addMessage(RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target downloads range " + range + + " of: " + request.getRequestURI()); } else { - statusMessage.addMessage(RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target downloads " + request.getRequestURI()); + statusMessage.addMessage( + RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target downloads " + request.getRequestURI()); } controllerManagement.addInformationalActionStatus(statusMessage); return action; @@ -339,8 +337,8 @@ public class DdiRootController implements DdiRootControllerRestApi { LOG.debug("Controller reported intermediate status (actionid: {}, targetid: {}) as we got {} report.", actionid, targetid, feedback.getStatus().getExecution()); actionStatus.setStatus(Status.RUNNING); - actionStatus - .addMessage(RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target reported " + feedback.getStatus().getExecution()); + actionStatus.addMessage( + RepositoryConstants.SERVER_MESSAGE_PREFIX + "Target reported " + feedback.getStatus().getExecution()); } private static void handleClosedUpdateStatus(final DdiActionFeedback feedback, final String targetid, diff --git a/hawkbit-dmf-amqp/pom.xml b/hawkbit-dmf-amqp/pom.xml index bcebc9628..c2ed7c213 100644 --- a/hawkbit-dmf-amqp/pom.xml +++ b/hawkbit-dmf-amqp/pom.xml @@ -23,10 +23,10 @@ org.eclipse.hawkbit - hawkbit-repository-jpa + hawkbit-repository-api ${project.version} - + org.eclipse.hawkbit hawkbit-core ${project.version} @@ -41,6 +41,10 @@ hawkbit-dmf-api ${project.version} + + org.springframework.boot + spring-boot-autoconfigure + org.springframework.amqp spring-rabbit @@ -98,7 +102,7 @@ org.eclipse.hawkbit hawkbit-repository-jpa ${project.version} - tests + test ru.yandex.qatools.allure 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 480948683..5faaa74f0 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 @@ -33,11 +33,11 @@ import org.eclipse.hawkbit.dmf.amqp.api.MessageType; import org.eclipse.hawkbit.dmf.json.model.DownloadAndUpdateRequest; import org.eclipse.hawkbit.eventbus.event.CancelTargetAssignmentEvent; import org.eclipse.hawkbit.repository.eventbus.event.TargetAssignDistributionSetEvent; -import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTestWithMongoDB; 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.util.AbstractIntegrationTestWithMongoDB; import org.eclipse.hawkbit.util.IpUtil; import org.junit.Test; import org.mockito.ArgumentCaptor; @@ -47,6 +47,7 @@ import org.springframework.amqp.core.MessageProperties; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.amqp.support.converter.AbstractJavaTypeMapper; import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; +import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.test.context.ActiveProfiles; import ru.yandex.qatools.allure.annotations.Description; @@ -56,7 +57,8 @@ import ru.yandex.qatools.allure.annotations.Stories; @ActiveProfiles({ "test" }) @Features("Component Tests - Device Management Federation API") @Stories("AmqpMessage Dispatcher Service Test") -public class AmqpMessageDispatcherServiceTest extends AbstractJpaIntegrationTestWithMongoDB { +@SpringApplicationConfiguration(classes = { org.eclipse.hawkbit.RepositoryApplicationConfiguration.class }) +public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTestWithMongoDB { private static final String TENANT = "default"; diff --git a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/util/PropertyBasedArtifactUrlHandlerTest.java b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/util/PropertyBasedArtifactUrlHandlerTest.java index 8f855da68..c67d6cf47 100644 --- a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/util/PropertyBasedArtifactUrlHandlerTest.java +++ b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/util/PropertyBasedArtifactUrlHandlerTest.java @@ -11,15 +11,12 @@ package org.eclipse.hawkbit.util; import static org.junit.Assert.assertEquals; import org.eclipse.hawkbit.AmqpTestConfiguration; -import org.eclipse.hawkbit.RepositoryApplicationConfiguration; import org.eclipse.hawkbit.api.ArtifactUrlHandler; import org.eclipse.hawkbit.api.UrlProtocol; -import org.eclipse.hawkbit.repository.jpa.TestConfiguration; 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.util.AbstractIntegrationTestWithMongoDB; -import org.eclipse.hawkbit.tenancy.TenantAware; import org.junit.Before; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -34,18 +31,18 @@ import ru.yandex.qatools.allure.annotations.Stories; */ @Features("Component Tests - Artifact URL Handler") @Stories("Test to generate the artifact download URL") -@SpringApplicationConfiguration(classes = { RepositoryApplicationConfiguration.class, TestConfiguration.class, - AmqpTestConfiguration.class }) +@SpringApplicationConfiguration(classes = { AmqpTestConfiguration.class, + org.eclipse.hawkbit.RepositoryApplicationConfiguration.class }) public class PropertyBasedArtifactUrlHandlerTest extends AbstractIntegrationTestWithMongoDB { private static final String HTTPS_LOCALHOST = "https://localhost:8080/"; private static final String HTTP_LOCALHOST = "http://localhost:8080/"; + @Autowired private ArtifactUrlHandler urlHandlerProperties; - @Autowired - private TenantAware tenantAware; + private LocalArtifact localArtifact; - private final String controllerId = "Test"; + private static final String CONTROLLER_ID = "Test"; private String fileName; private Long softwareModuleId; private String sha1Hash; @@ -65,21 +62,22 @@ public class PropertyBasedArtifactUrlHandlerTest extends AbstractIntegrationTest @Description("Tests the generation of http download url.") public void testHttpUrl() { - final String url = urlHandlerProperties.getUrl(controllerId, softwareModuleId, fileName, sha1Hash, + final String url = urlHandlerProperties.getUrl(CONTROLLER_ID, softwareModuleId, fileName, sha1Hash, UrlProtocol.HTTP); assertEquals("http is build incorrect", - HTTP_LOCALHOST + tenantAware.getCurrentTenant() + "/controller/v1/" + controllerId + "/softwaremodules/" - + localArtifact.getSoftwareModule().getId() + "/artifacts/" + localArtifact.getFilename(), + HTTP_LOCALHOST + tenantAware.getCurrentTenant() + "/controller/v1/" + CONTROLLER_ID + + "/softwaremodules/" + localArtifact.getSoftwareModule().getId() + "/artifacts/" + + localArtifact.getFilename(), url); } @Test @Description("Tests the generation of https download url.") public void testHttpsUrl() { - final String url = urlHandlerProperties.getUrl(controllerId, softwareModuleId, fileName, sha1Hash, + final String url = urlHandlerProperties.getUrl(CONTROLLER_ID, softwareModuleId, fileName, sha1Hash, UrlProtocol.HTTPS); assertEquals("https is build incorrect", - HTTPS_LOCALHOST + tenantAware.getCurrentTenant() + "/controller/v1/" + controllerId + HTTPS_LOCALHOST + tenantAware.getCurrentTenant() + "/controller/v1/" + CONTROLLER_ID + "/softwaremodules/" + localArtifact.getSoftwareModule().getId() + "/artifacts/" + localArtifact.getFilename(), url); @@ -88,10 +86,10 @@ public class PropertyBasedArtifactUrlHandlerTest extends AbstractIntegrationTest @Test @Description("Tests the generation of coap download url.") public void testCoapUrl() { - final String url = urlHandlerProperties.getUrl(controllerId, softwareModuleId, fileName, sha1Hash, + final String url = urlHandlerProperties.getUrl(CONTROLLER_ID, softwareModuleId, fileName, sha1Hash, UrlProtocol.COAP); assertEquals("coap is build incorrect", "coap://127.0.0.1:5683/fw/" + tenantAware.getCurrentTenant() + "/" - + controllerId + "/sha1/" + localArtifact.getSha1Hash(), url); + + CONTROLLER_ID + "/sha1/" + localArtifact.getSha1Hash(), url); } } diff --git a/hawkbit-dmf-amqp/src/test/resources/application-test.properties b/hawkbit-dmf-amqp/src/test/resources/application-test.properties new file mode 100644 index 000000000..79b1fe78f --- /dev/null +++ b/hawkbit-dmf-amqp/src/test/resources/application-test.properties @@ -0,0 +1,38 @@ +# +# 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 +# + + + +# supported: H2, MYSQL +hawkbit.server.database=H2 + +spring.jpa.database=${hawkbit.server.database} + + +flyway.sqlMigrationSuffix=${spring.jpa.database}.sql + +# effective DB setting +spring.datasource.url=${${hawkbit.server.database}.spring.datasource.url} +spring.datasource.driverClassName=${${hawkbit.server.database}.spring.datasource.driverClassName} +spring.datasource.username=${${hawkbit.server.database}.spring.datasource.username} +spring.datasource.password=${${hawkbit.server.database}.spring.datasource.password} + +# H2 +##;AUTOCOMMIT=ON +H2.spring.datasource.url=jdbc:h2:mem:sp-db;DB_CLOSE_ON_EXIT=FALSE +#H2.spring.datasource.url=jdbc:h2:./db/sp-db;AUTO_SERVER=TRUE;DB_CLOSE_ON_EXIT=FALSE;MVCC=TRUE +H2.spring.datasource.driverClassName=org.h2.Driver +H2.spring.datasource.username=sa +H2.spring.datasource.password=sa + +# MYSQL +MYSQL.spring.datasource.url=jdbc:mysql://localhost:3306/sp_test +MYSQL.spring.datasource.driverClassName=org.mariadb.jdbc.Driver +MYSQL.spring.datasource.username=root +MYSQL.spring.datasource.password= diff --git a/hawkbit-dmf-amqp/src/test/resources/logback.xml b/hawkbit-dmf-amqp/src/test/resources/logback.xml new file mode 100644 index 000000000..30060d1c6 --- /dev/null +++ b/hawkbit-dmf-amqp/src/test/resources/logback.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/hawkbit-http-security/pom.xml b/hawkbit-http-security/pom.xml index 03a9b6678..bb77df454 100644 --- a/hawkbit-http-security/pom.xml +++ b/hawkbit-http-security/pom.xml @@ -22,7 +22,7 @@ org.eclipse.hawkbit - hawkbit-repository-jpa + hawkbit-repository-api ${project.version} diff --git a/hawkbit-mgmt-resource/pom.xml b/hawkbit-mgmt-resource/pom.xml index fb0167793..007c6789b 100644 --- a/hawkbit-mgmt-resource/pom.xml +++ b/hawkbit-mgmt-resource/pom.xml @@ -23,9 +23,9 @@ org.eclipse.hawkbit - hawkbit-repository-jpa + hawkbit-repository-api ${project.version} - + org.eclipse.hawkbit hawkbit-mgmt-api @@ -53,6 +53,12 @@ ${project.version} test + + org.eclipse.hawkbit + hawkbit-repository-jpa + ${project.version} + test + org.eclipse.hawkbit hawkbit-rest-core @@ -96,13 +102,6 @@ spring-security-config test - - org.eclipse.hawkbit - hawkbit-repository-jpa - ${project.version} - tests - test - org.eclipse.hawkbit hawkbit-http-security diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResource.java index 623241981..7144316b8 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResource.java @@ -22,9 +22,8 @@ import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.RolloutGroupManagement; import org.eclipse.hawkbit.repository.RolloutManagement; -import org.eclipse.hawkbit.repository.TargetFields; +import org.eclipse.hawkbit.repository.TargetFilterQueryManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; -import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.RolloutGroup; @@ -64,6 +63,9 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi { @Autowired private DistributionSetManagement distributionSetManagement; + @Autowired + private TargetFilterQueryManagement targetFilterQueryManagement; + @Autowired private EntityFactory entityFactory; @@ -103,7 +105,7 @@ public class MgmtRolloutResource implements MgmtRolloutRestApi { // first check the given RSQL query if it's well formed, otherwise and // exception is thrown - RSQLUtility.parse(rolloutRequestBody.getTargetFilterQuery(), TargetFields.class); + targetFilterQueryManagement.verifyTargetFilterQuerySyntax(rolloutRequestBody.getTargetFilterQuery()); final DistributionSet distributionSet = findDistributionSetOrThrowException(rolloutRequestBody); 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 a0bf416c9..e7397dd49 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 @@ -36,12 +36,12 @@ import org.eclipse.hawkbit.exception.SpServerError; import org.eclipse.hawkbit.mgmt.json.model.artifact.MgmtArtifact; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; -import org.eclipse.hawkbit.repository.jpa.HashGeneratorUtils; 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.util.HashGeneratorUtils; import org.eclipse.hawkbit.repository.util.WithUser; import org.eclipse.hawkbit.rest.AbstractRestIntegrationTestWithMongoDB; import org.eclipse.hawkbit.rest.json.model.ExceptionInfo; diff --git a/hawkbit-mgmt-resource/src/test/resources/application-test.properties b/hawkbit-mgmt-resource/src/test/resources/application-test.properties index 92506caa4..cd98bb23f 100644 --- a/hawkbit-mgmt-resource/src/test/resources/application-test.properties +++ b/hawkbit-mgmt-resource/src/test/resources/application-test.properties @@ -7,22 +7,8 @@ # http://www.eclipse.org/legal/epl-v10.html # -# used if IM profile is disabled -security.ignored=true - -# IM required for integration tests -spring.profiles.active=im,suiteembedded,artifactrepository,redis - -server.port=12222 - -spring.data.mongodb.uri=mongodb://localhost/spArtifactRepository${random.value} -spring.data.mongodb.port=28017 - - # supported: H2, MYSQL hawkbit.server.database=H2 -hawkbit.server.database.env=TEST -spring.main.show_banner=false hawkbit.server.ddi.security.authentication.header=true diff --git a/hawkbit-repository/hawkbit-repository-api/pom.xml b/hawkbit-repository/hawkbit-repository-api/pom.xml index 076ae8cd8..050a9a070 100644 --- a/hawkbit-repository/hawkbit-repository-api/pom.xml +++ b/hawkbit-repository/hawkbit-repository-api/pom.xml @@ -31,6 +31,10 @@ org.hibernate hibernate-validator + + + cz.jirutka.rsql + rsql-parser org.springframework.hateoas 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 90bb7068b..f8615bcc3 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 @@ -14,6 +14,7 @@ import java.util.Map; import javax.validation.constraints.NotNull; +import org.eclipse.hawkbit.eventbus.event.DownloadProgressEvent; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; @@ -32,6 +33,8 @@ import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; import org.hibernate.validator.constraints.NotEmpty; import org.springframework.security.access.prepost.PreAuthorize; +import com.google.common.eventbus.EventBus; + /** * Service layer for all operations of the DDI API (with access permissions only * for the controller). @@ -54,6 +57,18 @@ public interface ControllerManagement { @PreAuthorize(SpringEvalExpressions.IS_CONTROLLER) Action addCancelActionStatus(@NotNull ActionStatus actionStatus); + /** + * Sends the download progress in percentage and notifies the + * {@link EventBus} with a {@link DownloadProgressEvent}. + * + * @param statusId + * the ID of the {@link ActionStatus} + * @param progressPercent + * the progress in percentage which must be between 0-100 + */ + @PreAuthorize(SpringEvalExpressions.IS_CONTROLLER) + void downloadProgressPercent(long statusId, int progressPercent); + /** * Simple addition of a new {@link ActionStatus} entry to the {@link Action} * . No state changes. 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 85a2f5e76..7542cd2ce 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 @@ -19,6 +19,7 @@ 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; @@ -330,4 +331,11 @@ public interface EntityFactory { */ TargetTag generateTargetTag(String name, String description, String colour); + /** + * Generates an empty {@link LocalArtifact} without persisting it. + * + * @return {@link LocalArtifact} object + */ + LocalArtifact generateLocalArtifact(); + } diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagement.java index 48018b9ec..d748ed470 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetFilterQueryManagement.java @@ -11,6 +11,8 @@ package org.eclipse.hawkbit.repository; import javax.validation.constraints.NotNull; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; +import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException; +import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException; import org.eclipse.hawkbit.repository.model.TargetFilterQuery; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -40,6 +42,23 @@ public interface TargetFilterQueryManagement { @PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_TARGET) void deleteTargetFilterQuery(@NotNull Long targetFilterQueryId); + /** + * Verifies provided filter syntax. + * + * @param query + * to verify + * + * @return true if syntax is valid + * + * @throws RSQLParameterUnsupportedFieldException + * if a field in the RSQL string is used but not provided by the + * given {@code fieldNameProvider} + * @throws RSQLParameterSyntaxException + * if the RSQL syntax is wrong + */ + @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) + boolean verifyTargetFilterQuerySyntax(String query); + /** * * Retrieves all target filter query{@link TargetFilterQuery}. diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java index ee10883ec..9054127ef 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java @@ -439,7 +439,14 @@ public interface TargetManagement { * in string notation * @param pageable * pagination parameter + * * @return the found {@link Target}s, never {@code null} + * + * @throws RSQLParameterUnsupportedFieldException + * if a field in the RSQL string is used but not provided by the + * given {@code fieldNameProvider} + * @throws RSQLParameterSyntaxException + * if the RSQL syntax is wrong */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) Page findTargetsAll(@NotNull String targetFilterQuery, @NotNull Pageable pageable); @@ -455,6 +462,12 @@ public interface TargetManagement { * pagination parameter * * @return the found {@link Target}s, never {@code null} + * + * @throws RSQLParameterUnsupportedFieldException + * if a field in the RSQL string is used but not provided by the + * given {@code fieldNameProvider} + * @throws RSQLParameterSyntaxException + * if the RSQL syntax is wrong */ @PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET) Slice findTargetsAll(@NotNull TargetFilterQuery targetFilterQuery, @NotNull Pageable pageable); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/EventBusHolder.java b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/EventBusHolder.java similarity index 90% rename from hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/EventBusHolder.java rename to hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/EventBusHolder.java index 5196283d1..3829d639b 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/EventBusHolder.java +++ b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/EventBusHolder.java @@ -8,7 +8,6 @@ */ package org.eclipse.hawkbit.repository.jpa.model.helper; -import org.eclipse.hawkbit.repository.jpa.model.CacheFieldEntityListener; import org.springframework.beans.factory.annotation.Autowired; import com.google.common.eventbus.EventBus; @@ -16,7 +15,7 @@ import com.google.common.eventbus.EventBus; /** * A singleton bean which holds the {@link EventBus} to have to the cache * manager in beans not instantiated by spring e.g. JPA entities or - * {@link CacheFieldEntityListener} which cannot be autowired. + * CacheFieldEntityListener which cannot be autowired. * */ public final class EventBusHolder { diff --git a/hawkbit-repository/hawkbit-repository-jpa/pom.xml b/hawkbit-repository/hawkbit-repository-jpa/pom.xml index d234f5f57..bd56e9ca5 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/pom.xml +++ b/hawkbit-repository/hawkbit-repository-jpa/pom.xml @@ -120,27 +120,12 @@ javax.el javax.el-api test - - - org.springframework - spring-context-support - test - + ru.yandex.qatools.allure allure-junit-adaptor test - - org.springframework.security - spring-security-aspects - test - - - org.springframework - spring-test - test - org.easytesting fest-assert-core @@ -151,16 +136,6 @@ fest-assert test - - org.springframework.security - spring-security-config - test - - - org.springframework.security - spring-security-web - test - diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/EnableJpaRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/EnableJpaRepository.java index f15ec8c82..55fd4a111 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/EnableJpaRepository.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/EnableJpaRepository.java @@ -26,7 +26,6 @@ import org.springframework.stereotype.Controller; @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Configuration -@ComponentScan @Import(RepositoryApplicationConfiguration.class) public @interface EnableJpaRepository { diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java index 5f5a46c0b..50207037a 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java @@ -47,8 +47,8 @@ import org.springframework.validation.beanvalidation.MethodValidationPostProcess @EnableTransactionManagement @EnableJpaAuditing @EnableAspectJAutoProxy -@ComponentScan @Configuration +@ComponentScan @EnableAutoConfiguration public class RepositoryApplicationConfiguration extends JpaBaseConfiguration { /** 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 9fcd646b5..80de385c8 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 @@ -19,13 +19,14 @@ import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.Root; import javax.validation.constraints.NotNull; -import org.eclipse.hawkbit.repository.RepositoryConstants; import org.eclipse.hawkbit.repository.ControllerManagement; +import org.eclipse.hawkbit.repository.RepositoryConstants; import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.exception.ToManyAttributeEntriesException; import org.eclipse.hawkbit.repository.exception.ToManyStatusEntriesException; +import org.eclipse.hawkbit.repository.jpa.cache.CacheWriteNotify; import org.eclipse.hawkbit.repository.jpa.model.JpaAction; import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus; import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus_; @@ -98,6 +99,9 @@ public class JpaControllerManagement implements ControllerManagement { @Autowired private TenantConfigurationManagement tenantConfigurationManagement; + @Autowired + private CacheWriteNotify cacheWriteNotify; + @Override public String getPollingTime() { final TenantConfigurationKey configurationKey = TenantConfigurationKey.POLLING_TIME_INTERVAL; @@ -230,7 +234,8 @@ public class JpaControllerManagement implements ControllerManagement { private void handleFinishedCancelation(final ActionStatus actionStatus, final JpaAction action) { // in case of successful cancellation we also report the success at // the canceled action itself. - actionStatus.addMessage(RepositoryConstants.SERVER_MESSAGE_PREFIX + "Cancellation completion is finished sucessfully."); + actionStatus.addMessage( + RepositoryConstants.SERVER_MESSAGE_PREFIX + "Cancellation completion is finished sucessfully."); DeploymentHelper.successCancellation(action, actionRepository, targetManagement, targetInfoRepository, entityManager); } @@ -436,4 +441,9 @@ public class JpaControllerManagement implements ControllerManagement { return updateTargetStatus(target, null, System.currentTimeMillis(), address); } + @Override + public void downloadProgressPercent(final long statusId, final int progressPercent) { + cacheWriteNotify.downloadProgressPercent(statusId, progressPercent); + } + } 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 88c34ad11..afa3b4dc6 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 @@ -17,6 +17,7 @@ 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; @@ -32,6 +33,7 @@ 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; @@ -198,4 +200,9 @@ public class JpaEntityFactory implements EntityFactory { return new JpaActionStatus(action, status, occurredAt); } + @Override + public LocalArtifact generateLocalArtifact() { + return new JpaLocalArtifact(); + } + } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetFilterQueryManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetFilterQueryManagement.java index 296483bf8..f418f5f4b 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetFilterQueryManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetFilterQueryManagement.java @@ -11,9 +11,11 @@ package org.eclipse.hawkbit.repository.jpa; import java.util.ArrayList; import java.util.List; +import org.eclipse.hawkbit.repository.TargetFields; import org.eclipse.hawkbit.repository.TargetFilterQueryManagement; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.jpa.model.JpaTargetFilterQuery; +import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility; import org.eclipse.hawkbit.repository.jpa.specifications.SpecificationsBuilder; import org.eclipse.hawkbit.repository.jpa.specifications.TargetFilterQuerySpecification; import org.eclipse.hawkbit.repository.model.TargetFilterQuery; @@ -109,4 +111,10 @@ public class JpaTargetFilterQueryManagement implements TargetFilterQueryManageme return targetFilterQueryRepository.save((JpaTargetFilterQuery) targetFilterQuery); } + @Override + public boolean verifyTargetFilterQuerySyntax(final String query) { + RSQLUtility.parse(query, TargetFields.class); + return true; + } + } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaTenantAwareBaseEntity.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaTenantAwareBaseEntity.java index 880a51167..ccd4a30b1 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaTenantAwareBaseEntity.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaTenantAwareBaseEntity.java @@ -97,6 +97,8 @@ public abstract class AbstractJpaTenantAwareBaseEntity extends AbstractJpaBaseEn * @see org.eclipse.hawkbit.repository.model.BaseEntity#equals(java.lang.Object) */ @Override + // exception squid:S2259 - obj is checked for null in super + @SuppressWarnings("squid:S2259") public boolean equals(final Object obj) { if (!super.equals(obj)) { return false; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetMetadata.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetMetadata.java index 5d176b4a9..3f4323bbe 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetMetadata.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSetMetadata.java @@ -67,6 +67,8 @@ public class JpaDistributionSetMetadata extends AbstractJpaMetaData implements D } @Override + // exception squid:S2259 - obj is checked for null in super + @SuppressWarnings("squid:S2259") public boolean equals(final Object obj) { if (!super.equals(obj)) { return false; 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 ecb7f2d37..b4b451ecd 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 @@ -17,8 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.data.mongodb.gridfs.GridFsOperations; -@SpringApplicationConfiguration(classes = { org.eclipse.hawkbit.RepositoryApplicationConfiguration.class, - TestConfiguration.class }) +@SpringApplicationConfiguration(classes = { org.eclipse.hawkbit.RepositoryApplicationConfiguration.class }) public abstract class AbstractJpaIntegrationTest extends AbstractIntegrationTest { @PersistenceContext 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 6650d1e3c..d1c433cc4 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 @@ -16,8 +16,7 @@ import org.eclipse.hawkbit.repository.util.AbstractIntegrationTestWithMongoDB; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.SpringApplicationConfiguration; -@SpringApplicationConfiguration(classes = { org.eclipse.hawkbit.RepositoryApplicationConfiguration.class, - TestConfiguration.class }) +@SpringApplicationConfiguration(classes = { org.eclipse.hawkbit.RepositoryApplicationConfiguration.class }) public abstract class AbstractJpaIntegrationTestWithMongoDB extends AbstractIntegrationTestWithMongoDB { @PersistenceContext 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 ea6e8e01b..faf7649d0 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 @@ -32,6 +32,7 @@ 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.util.HashGeneratorUtils; import org.eclipse.hawkbit.repository.util.WithUser; import org.junit.Test; import org.slf4j.LoggerFactory; diff --git a/hawkbit-repository/hawkbit-repository-test/pom.xml b/hawkbit-repository/hawkbit-repository-test/pom.xml index 6b421c8ab..4a05735ac 100644 --- a/hawkbit-repository/hawkbit-repository-test/pom.xml +++ b/hawkbit-repository/hawkbit-repository-test/pom.xml @@ -33,7 +33,11 @@ org.eclipse.hawkbit hawkbit-artifact-repository-mongo ${project.version} - + + + org.springframework + spring-context-support + de.flapdoodle.embed de.flapdoodle.embed.mongo @@ -55,5 +59,17 @@ org.springframework.security spring-security-config + + org.springframework.security + spring-security-aspects + + + org.springframework + spring-test + + + org.springframework.security + spring-security-web + \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/AbstractIntegrationTest.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/AbstractIntegrationTest.java index b8690bc74..c2bd61676 100644 --- a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/AbstractIntegrationTest.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/AbstractIntegrationTest.java @@ -10,11 +10,11 @@ package org.eclipse.hawkbit.repository.util; import org.eclipse.hawkbit.ExcludePathAwareShallowETagFilter; import org.eclipse.hawkbit.repository.ArtifactManagement; -import org.eclipse.hawkbit.repository.RepositoryConstants; import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.EntityFactory; +import org.eclipse.hawkbit.repository.RepositoryConstants; import org.eclipse.hawkbit.repository.RolloutGroupManagement; import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.SoftwareManagement; @@ -39,6 +39,7 @@ import org.junit.runner.RunWith; import org.junit.runners.model.FrameworkMethod; import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.context.EnvironmentAware; import org.springframework.core.env.Environment; import org.springframework.data.auditing.AuditingHandler; @@ -58,6 +59,7 @@ import org.springframework.web.context.WebApplicationContext; @WebAppConfiguration @ActiveProfiles({ "test" }) @WithUser(principal = "bumlux", allSpPermissions = true, authorities = "ROLE_CONTROLLER") +@SpringApplicationConfiguration(classes = { TestConfiguration.class }) // destroy the context after each test class because otherwise we get problem // when context is // refreshed we e.g. get two instances of CacheManager which leads to very diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/HashGeneratorUtils.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/HashGeneratorUtils.java similarity index 74% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/HashGeneratorUtils.java rename to hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/HashGeneratorUtils.java index a94807958..e222007f1 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/HashGeneratorUtils.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/HashGeneratorUtils.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.jpa; +package org.eclipse.hawkbit.repository.util; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; @@ -14,13 +14,10 @@ import java.security.NoSuchAlgorithmException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.google.common.io.BaseEncoding; + /** - * Hash utility calls copied from - * http://www.codejava.net/coding/how-to-calculate-md5-and-sha-hash-values-in- - * java. - * - * - * + * Hash digest utility. */ public final class HashGeneratorUtils { @@ -68,18 +65,11 @@ public final class HashGeneratorUtils { try { final MessageDigest digest = MessageDigest.getInstance(algorithm); final byte[] hashedBytes = digest.digest(message); - return convertByteArrayToHexString(hashedBytes); + return BaseEncoding.base16().lowerCase().encode(hashedBytes); } catch (final NoSuchAlgorithmException e) { - LOG.error("Algorithm could not be find", e); + LOG.error("Algorithm could not be found", e); } return null; } - private static String convertByteArrayToHexString(final byte[] arrayBytes) { - final StringBuilder builder = new StringBuilder(); - for (int i = 0; i < arrayBytes.length; i++) { - builder.append(Integer.toString((arrayBytes[i] & 0xff) + 0x100, 16).substring(1)); - } - return builder.toString(); - } } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/JpaTestRepositoryManagement.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/JpaTestRepositoryManagement.java similarity index 50% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/JpaTestRepositoryManagement.java rename to hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/JpaTestRepositoryManagement.java index 5c4b0efcc..7ec5bb407 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/JpaTestRepositoryManagement.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/JpaTestRepositoryManagement.java @@ -6,77 +6,18 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.jpa; +package org.eclipse.hawkbit.repository.util; import java.util.List; -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; - import org.eclipse.hawkbit.cache.TenantAwareCacheManager; import org.eclipse.hawkbit.repository.SystemManagement; -import org.eclipse.hawkbit.repository.util.TestRepositoryManagement; import org.eclipse.hawkbit.security.SystemSecurityContext; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.mongodb.gridfs.GridFsOperations; import org.springframework.transaction.annotation.Transactional; public class JpaTestRepositoryManagement implements TestRepositoryManagement { - @PersistenceContext - private EntityManager entityManager; - - @Autowired - private TargetRepository targetRepository; - - @Autowired - private ActionRepository actionRepository; - - @Autowired - private DistributionSetRepository distributionSetRepository; - - @Autowired - private SoftwareModuleRepository softwareModuleRepository; - - @Autowired - private TenantMetaDataRepository tenantMetaDataRepository; - - @Autowired - private DistributionSetTypeRepository distributionSetTypeRepository; - - @Autowired - private SoftwareModuleTypeRepository softwareModuleTypeRepository; - - @Autowired - private TargetTagRepository targetTagRepository; - - @Autowired - private DistributionSetTagRepository distributionSetTagRepository; - - @Autowired - private SoftwareModuleMetadataRepository softwareModuleMetadataRepository; - - @Autowired - private ActionStatusRepository actionStatusRepository; - - @Autowired - private ExternalArtifactRepository externalArtifactRepository; - - @Autowired - private LocalArtifactRepository artifactRepository; - - @Autowired - private TargetInfoRepository targetInfoRepository; - - @Autowired - private GridFsOperations operations; - - @Autowired - private RolloutGroupRepository rolloutGroupRepository; - - @Autowired - private RolloutRepository rolloutRepository; - @Autowired private TenantAwareCacheManager cacheManager; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TestConfiguration.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/TestConfiguration.java similarity index 95% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TestConfiguration.java rename to hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/TestConfiguration.java index 8ea794f6a..acbaae2b4 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TestConfiguration.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/util/TestConfiguration.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.jpa; +package org.eclipse.hawkbit.repository.util; import java.util.concurrent.Executor; import java.util.concurrent.Executors; @@ -16,8 +16,6 @@ import org.eclipse.hawkbit.cache.CacheConstants; import org.eclipse.hawkbit.cache.TenancyCacheManager; import org.eclipse.hawkbit.cache.TenantAwareCacheManager; import org.eclipse.hawkbit.repository.jpa.model.helper.EventBusHolder; -import org.eclipse.hawkbit.repository.util.TestRepositoryManagement; -import org.eclipse.hawkbit.repository.util.TestdataFactory; import org.eclipse.hawkbit.security.DdiSecurityProperties; import org.eclipse.hawkbit.security.SecurityContextTenantAware; import org.eclipse.hawkbit.security.SpringSecurityAuditorAware; diff --git a/hawkbit-rest-core/pom.xml b/hawkbit-rest-core/pom.xml index 1a74f4b3e..bb511839c 100644 --- a/hawkbit-rest-core/pom.xml +++ b/hawkbit-rest-core/pom.xml @@ -21,6 +21,11 @@ + + org.eclipse.hawkbit + hawkbit-repository-api + ${project.version} + org.eclipse.hawkbit hawkbit-repository-jpa @@ -62,13 +67,7 @@ org.easytesting fest-assert test - - - org.eclipse.hawkbit - hawkbit-repository-jpa - ${project.version} - tests - + ru.yandex.qatools.allure allure-junit-adaptor 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 baa18edb2..875152e0e 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 @@ -22,7 +22,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.eclipse.hawkbit.artifact.repository.model.DbArtifact; -import org.eclipse.hawkbit.repository.jpa.cache.CacheWriteNotify; +import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -84,7 +84,7 @@ public final class RestResourceConversionHelper { * from the client * @param file * to be write to the client response - * @param cacheWriteNotify + * @param controllerManagement * to write progress updates to * @param statusId * of the UpdateActionStatus @@ -95,9 +95,9 @@ public final class RestResourceConversionHelper { */ public static ResponseEntity writeFileResponse(final LocalArtifact artifact, final HttpServletResponse response, final HttpServletRequest request, final DbArtifact file, - final CacheWriteNotify cacheWriteNotify, final Long statusId) { + final ControllerManagement controllerManagement, final Long statusId) { - ResponseEntity result = null; + ResponseEntity result; final String etag = artifact.getSha1Hash(); final Long lastModified = artifact.getLastModifiedAt() != null ? artifact.getLastModifiedAt() @@ -143,19 +143,19 @@ public final class RestResourceConversionHelper { // full request - no range if (ranges.isEmpty() || ranges.get(0).equals(full)) { LOG.debug("filename ({}) results into a full request: ", artifact.getFilename()); - fullfileRequest(artifact, response, file, cacheWriteNotify, statusId, full); + fullfileRequest(artifact, response, file, controllerManagement, statusId, full); result = new ResponseEntity<>(HttpStatus.OK); } // standard range request else if (ranges.size() == 1) { LOG.debug("filename ({}) results into a standard range request: ", artifact.getFilename()); - standardRangeRequest(artifact, response, file, cacheWriteNotify, statusId, ranges); + standardRangeRequest(artifact, response, file, controllerManagement, statusId, ranges); result = new ResponseEntity<>(HttpStatus.PARTIAL_CONTENT); } // multipart range request else { LOG.debug("filename ({}) results into a multipart range request: ", artifact.getFilename()); - multipartRangeRequest(artifact, response, file, cacheWriteNotify, statusId, ranges); + multipartRangeRequest(artifact, response, file, controllerManagement, statusId, ranges); result = new ResponseEntity<>(HttpStatus.PARTIAL_CONTENT); } @@ -164,14 +164,15 @@ public final class RestResourceConversionHelper { } private static void fullfileRequest(final LocalArtifact artifact, final HttpServletResponse response, - final DbArtifact file, final CacheWriteNotify cacheWriteNotify, final Long statusId, final ByteRange full) { + final DbArtifact file, final ControllerManagement controllerManagement, final Long statusId, + final ByteRange full) { final ByteRange r = full; response.setHeader(HttpHeaders.CONTENT_RANGE, "bytes " + r.getStart() + "-" + r.getEnd() + "/" + r.getTotal()); response.setHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(r.getLength())); try { - copyStreams(file.getFileInputStream(), response.getOutputStream(), cacheWriteNotify, statusId, r.getStart(), - r.getLength()); + copyStreams(file.getFileInputStream(), response.getOutputStream(), controllerManagement, statusId, + r.getStart(), r.getLength()); } catch (final IOException e) { LOG.error("fullfileRequest of file ({}) failed!", artifact.getFilename(), e); throw new FileSteamingFailedException(artifact.getFilename()); @@ -231,7 +232,7 @@ public final class RestResourceConversionHelper { } private static void multipartRangeRequest(final LocalArtifact artifact, final HttpServletResponse response, - final DbArtifact file, final CacheWriteNotify cacheWriteNotify, final Long statusId, + final DbArtifact file, final ControllerManagement controllerManagement, final Long statusId, final List ranges) { response.setContentType("multipart/byteranges; boundary=" + ByteRange.MULTIPART_BOUNDARY); response.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT); @@ -245,7 +246,7 @@ public final class RestResourceConversionHelper { .println("Content-Range: bytes " + r.getStart() + "-" + r.getEnd() + "/" + r.getTotal()); // Copy single part range of multi part range. - copyStreams(file.getFileInputStream(), response.getOutputStream(), cacheWriteNotify, statusId, + copyStreams(file.getFileInputStream(), response.getOutputStream(), controllerManagement, statusId, r.getStart(), r.getLength()); } @@ -259,7 +260,7 @@ public final class RestResourceConversionHelper { } private static void standardRangeRequest(final LocalArtifact artifact, final HttpServletResponse response, - final DbArtifact file, final CacheWriteNotify cacheWriteNotify, final Long statusId, + final DbArtifact file, final ControllerManagement controllerManagement, final Long statusId, final List ranges) { final ByteRange r = ranges.get(0); response.setHeader(HttpHeaders.CONTENT_RANGE, "bytes " + r.getStart() + "-" + r.getEnd() + "/" + r.getTotal()); @@ -267,8 +268,8 @@ public final class RestResourceConversionHelper { response.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT); try { - copyStreams(file.getFileInputStream(), response.getOutputStream(), cacheWriteNotify, statusId, r.getStart(), - r.getLength()); + copyStreams(file.getFileInputStream(), response.getOutputStream(), controllerManagement, statusId, + r.getStart(), r.getLength()); } catch (final IOException e) { LOG.error("standardRangeRequest of file ({}) failed!", artifact.getFilename(), e); throw new FileSteamingFailedException(artifact.getFilename()); @@ -276,7 +277,7 @@ public final class RestResourceConversionHelper { } private static long copyStreams(final InputStream from, final OutputStream to, - final CacheWriteNotify cacheWriteNotify, final Long statusId, final long start, final long length) + final ControllerManagement controllerManagement, final Long statusId, final long start, final long length) throws IOException { checkNotNull(from); checkNotNull(to); @@ -309,13 +310,13 @@ public final class RestResourceConversionHelper { toContinue = false; } - if (cacheWriteNotify != null) { + if (controllerManagement != null) { final int newPercent = DoubleMath.roundToInt(total * 100.0 / length, RoundingMode.DOWN); // every 10 percent an event if (newPercent == 100 || newPercent > progressPercent + 10) { progressPercent = newPercent; - cacheWriteNotify.downloadProgressPercent(statusId, progressPercent); + controllerManagement.downloadProgressPercent(statusId, progressPercent); } } } diff --git a/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTest.java b/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTest.java index 1b54eed3e..14ba8556e 100644 --- a/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTest.java +++ b/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTest.java @@ -8,7 +8,7 @@ */ package org.eclipse.hawkbit.rest; -import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest; +import org.eclipse.hawkbit.repository.util.AbstractIntegrationTest; import org.eclipse.hawkbit.rest.configuration.RestConfiguration; import org.eclipse.hawkbit.rest.util.FilterHttpResponse; import org.springframework.beans.factory.annotation.Autowired; @@ -18,8 +18,9 @@ import org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder; /** * Abstract Test for Rest tests. */ -@SpringApplicationConfiguration(classes = { RestConfiguration.class }) -public abstract class AbstractRestIntegrationTest extends AbstractJpaIntegrationTest { +@SpringApplicationConfiguration(classes = { RestConfiguration.class, + org.eclipse.hawkbit.RepositoryApplicationConfiguration.class }) +public abstract class AbstractRestIntegrationTest extends AbstractIntegrationTest { @Autowired private FilterHttpResponse filterHttpResponse; diff --git a/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTestWithMongoDB.java b/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTestWithMongoDB.java index 81e2c3d16..4d952434d 100644 --- a/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTestWithMongoDB.java +++ b/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTestWithMongoDB.java @@ -8,7 +8,7 @@ */ package org.eclipse.hawkbit.rest; -import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTestWithMongoDB; +import org.eclipse.hawkbit.repository.util.AbstractIntegrationTestWithMongoDB; import org.eclipse.hawkbit.rest.configuration.RestConfiguration; import org.eclipse.hawkbit.rest.util.FilterHttpResponse; import org.springframework.beans.factory.annotation.Autowired; @@ -18,8 +18,9 @@ import org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder; /** * Abstract Test for Rest tests. */ -@SpringApplicationConfiguration(classes = { RestConfiguration.class }) -public abstract class AbstractRestIntegrationTestWithMongoDB extends AbstractJpaIntegrationTestWithMongoDB { +@SpringApplicationConfiguration(classes = { RestConfiguration.class, + org.eclipse.hawkbit.RepositoryApplicationConfiguration.class }) +public abstract class AbstractRestIntegrationTestWithMongoDB extends AbstractIntegrationTestWithMongoDB { @Autowired private FilterHttpResponse filterHttpResponse; diff --git a/hawkbit-security-integration/pom.xml b/hawkbit-security-integration/pom.xml index 194a5e3cb..455e3ece1 100644 --- a/hawkbit-security-integration/pom.xml +++ b/hawkbit-security-integration/pom.xml @@ -23,7 +23,7 @@ org.eclipse.hawkbit - hawkbit-repository-jpa + hawkbit-repository-api ${project.version} @@ -37,6 +37,12 @@ + + org.eclipse.hawkbit + hawkbit-repository-jpa + ${project.version} + test + junit junit diff --git a/hawkbit-ui/pom.xml b/hawkbit-ui/pom.xml index a9cd5aca3..dadcb264a 100644 --- a/hawkbit-ui/pom.xml +++ b/hawkbit-ui/pom.xml @@ -151,7 +151,7 @@ org.eclipse.hawkbit - hawkbit-repository-jpa + hawkbit-repository-api ${project.version} @@ -229,6 +229,12 @@ + + org.eclipse.hawkbit + hawkbit-repository-jpa + ${project.version} + test + org.mockito mockito-core 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 b9bceda3a..80e8a2f4f 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 @@ -12,8 +12,8 @@ import java.util.List; import java.util.Map; import org.eclipse.hawkbit.repository.ArtifactManagement; +import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; -import org.eclipse.hawkbit.repository.jpa.model.JpaLocalArtifact; import org.eclipse.hawkbit.repository.model.LocalArtifact; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; @@ -38,6 +38,7 @@ 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 Long baseSwModuleId = null; @@ -73,7 +74,7 @@ public class ArtifactBeanQuery extends AbstractBeanQuery { @Override protected LocalArtifact constructBean() { - return new JpaLocalArtifact(); + return entityFactory.generateLocalArtifact(); } @Override @@ -116,4 +117,11 @@ public class ArtifactBeanQuery extends AbstractBeanQuery { } return artifactManagement; } + + private EntityFactory getEntityFactory() { + if (entityFactory == null) { + entityFactory = SpringContextHelper.getBean(EntityFactory.class); + } + return entityFactory; + } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/ProxyBaseSoftwareModuleItem.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/ProxyBaseSoftwareModuleItem.java index 14568c307..1559a9bec 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/ProxyBaseSoftwareModuleItem.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/smtable/ProxyBaseSoftwareModuleItem.java @@ -10,8 +10,6 @@ package org.eclipse.hawkbit.ui.artifacts.smtable; import java.security.SecureRandom; -import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; - /** * * Proxy for software module to display details in Software modules table. @@ -19,7 +17,7 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; * * */ -public class ProxyBaseSoftwareModuleItem extends JpaSoftwareModule { +public class ProxyBaseSoftwareModuleItem { private static final long serialVersionUID = -1555306616599140635L; @@ -39,6 +37,11 @@ public class ProxyBaseSoftwareModuleItem extends JpaSoftwareModule { private String modifiedByUser; + private String name; + private String version; + private String vendor; + private String description; + /** * Default constructor. */ @@ -47,6 +50,38 @@ public class ProxyBaseSoftwareModuleItem extends JpaSoftwareModule { swId = RANDOM_OBJ.nextLong(); } + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + public String getVersion() { + return version; + } + + public void setVersion(final String version) { + this.version = version; + } + + public String getVendor() { + return vendor; + } + + public void setVendor(final String vendor) { + this.vendor = vendor; + } + + public String getDescription() { + return description; + } + + public void setDescription(final String description) { + this.description = description; + } + public String getCreatedByUser() { return createdByUser; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/DistributionSetIdName.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/DistributionSetIdName.java index c499babcd..66101fbd4 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/DistributionSetIdName.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/DistributionSetIdName.java @@ -22,13 +22,18 @@ public class DistributionSetIdName implements Serializable { private final Long id; private final String name; private final String version; - + public static DistributionSetIdName generate(final DistributionSet distributionSet) { return new DistributionSetIdName(distributionSet.getId(), distributionSet.getName(), distributionSet.getVersion()); } + public static DistributionSetIdName generate(final Long id, final String name, final String version) { + return new DistributionSetIdName(id, name, version); + + } + /** * @param id * the {@link DistributionSet#getId()} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/ProxyDistribution.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/ProxyDistribution.java index a8e7fe9d1..0420f9e4b 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/ProxyDistribution.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/ProxyDistribution.java @@ -8,7 +8,6 @@ */ package org.eclipse.hawkbit.ui.components; -import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.ui.common.DistributionSetIdName; @@ -17,7 +16,7 @@ import org.eclipse.hawkbit.ui.common.DistributionSetIdName; * * */ -public class ProxyDistribution extends JpaDistributionSet { +public class ProxyDistribution { private static final long serialVersionUID = -8891449133620645310L; @@ -35,6 +34,11 @@ public class ProxyDistribution extends JpaDistributionSet { private String nameVersion; + private Long id; + private String name; + private String version; + private String description; + /** * @return the nameVersion */ @@ -43,7 +47,7 @@ public class ProxyDistribution extends JpaDistributionSet { } public DistributionSetIdName getDistributionSetIdName() { - return DistributionSetIdName.generate(this); + return DistributionSetIdName.generate(id, name, version); } /** @@ -102,4 +106,36 @@ public class ProxyDistribution extends JpaDistributionSet { this.modifiedByUser = modifiedByUser; } + public Long getId() { + return id; + } + + public void setId(final Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + public String getVersion() { + return version; + } + + public void setVersion(final String version) { + this.version = version; + } + + public String getDescription() { + return description; + } + + public void setDescription(final String description) { + this.description = description; + } + } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/ProxyTargetFilter.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/ProxyTargetFilter.java index eb3f22dce..9faf501e0 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/ProxyTargetFilter.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/components/ProxyTargetFilter.java @@ -8,14 +8,12 @@ */ package org.eclipse.hawkbit.ui.components; -import org.eclipse.hawkbit.repository.jpa.model.JpaTargetFilterQuery; - /** * * * */ -public class ProxyTargetFilter extends JpaTargetFilterQuery { +public class ProxyTargetFilter { private static final long serialVersionUID = 6622060929679084419L; @@ -23,6 +21,12 @@ public class ProxyTargetFilter extends JpaTargetFilterQuery { private String modifiedDate; + private String name; + private Long id; + private String createdBy; + private String lastModifiedBy; + private String query; + public String getCreatedDate() { return createdDate; } @@ -46,4 +50,44 @@ public class ProxyTargetFilter extends JpaTargetFilterQuery { this.modifiedDate = modifiedDate; } + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + public Long getId() { + return id; + } + + public void setId(final Long id) { + this.id = id; + } + + public String getLastModifiedBy() { + return lastModifiedBy; + } + + public void setLastModifiedBy(final String lastModifiedBy) { + this.lastModifiedBy = lastModifiedBy; + } + + public String getQuery() { + return query; + } + + public void setQuery(final String query) { + this.query = query; + } + + public String getCreatedBy() { + return createdBy; + } + + public void setCreatedBy(final String createdBy) { + this.createdBy = createdBy; + } + } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionAddUpdateWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionAddUpdateWindowLayout.java index 90b3ad597..2a4e63466 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionAddUpdateWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionAddUpdateWindowLayout.java @@ -19,7 +19,6 @@ import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; -import org.eclipse.hawkbit.repository.jpa.TenantMetaDataRepository; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.TenantMetaData; @@ -92,9 +91,6 @@ public class DistributionAddUpdateWindowLayout extends VerticalLayout { @Autowired private transient SystemManagement systemManagement; - @Autowired - private transient TenantMetaDataRepository tenantMetaDataRepository; - @Autowired private transient EntityFactory entityFactory; @@ -225,8 +221,7 @@ public class DistributionAddUpdateWindowLayout extends VerticalLayout { } private DistributionSetType getDefaultDistributionSetType() { - final TenantMetaData tenantMetaData = tenantMetaDataRepository - .findByTenantIgnoreCase(systemManagement.currentTenant()); + final TenantMetaData tenantMetaData = systemManagement.getTenantMetadata(); return tenantMetaData.getDefaultDsType(); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java index 4074edb55..88e7204aa 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/ProxyRollout.java @@ -10,8 +10,10 @@ package org.eclipse.hawkbit.ui.rollout.rollout; import java.util.Set; -import org.eclipse.hawkbit.repository.jpa.model.JpaRollout; +import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.Rollout.RolloutStatus; import org.eclipse.hawkbit.repository.model.SoftwareModule; +import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RolloutRendererData; import com.vaadin.server.FontAwesome; @@ -20,7 +22,7 @@ import com.vaadin.server.FontAwesome; * Proxy rollout with custom properties. * */ -public class ProxyRollout extends JpaRollout { +public class ProxyRollout { private static final long serialVersionUID = 4539849939617681918L; @@ -46,6 +48,17 @@ public class ProxyRollout extends JpaRollout { private Set swModules; + private Long id; + private String name; + private String version; + private String description; + private DistributionSet distributionSet; + private String createdBy; + private String lastModifiedBy; + private long forcedTime; + private RolloutStatus status; + private TotalTargetCountStatus totalTargetCountStatus; + /** * @return the isRequiredMigrationStep */ @@ -214,4 +227,83 @@ public class ProxyRollout extends JpaRollout { return FontAwesome.CIRCLE_O.getHtml(); } + public Long getId() { + return id; + } + + public void setId(final Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + public String getVersion() { + return version; + } + + public void setVersion(final String version) { + this.version = version; + } + + public String getDescription() { + return description; + } + + public void setDescription(final String description) { + this.description = description; + } + + public DistributionSet getDistributionSet() { + return distributionSet; + } + + public void setDistributionSet(final DistributionSet distributionSet) { + this.distributionSet = distributionSet; + } + + public String getCreatedBy() { + return createdBy; + } + + public void setCreatedBy(final String createdBy) { + this.createdBy = createdBy; + } + + public String getLastModifiedBy() { + return lastModifiedBy; + } + + public void setLastModifiedBy(final String lastModifiedBy) { + this.lastModifiedBy = lastModifiedBy; + } + + public long getForcedTime() { + return forcedTime; + } + + public void setForcedTime(final long forcedTime) { + this.forcedTime = forcedTime; + } + + public RolloutStatus getStatus() { + return status; + } + + public void setStatus(final RolloutStatus status) { + this.status = status; + } + + public TotalTargetCountStatus getTotalTargetCountStatus() { + return totalTargetCountStatus; + } + + public void setTotalTargetCountStatus(final TotalTargetCountStatus totalTargetCountStatus) { + this.totalTargetCountStatus = totalTargetCountStatus; + } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java index 8a9675564..0bfa349d0 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutBeanQuery.java @@ -138,8 +138,6 @@ public class RolloutBeanQuery extends AbstractBeanQuery { final TotalTargetCountStatus totalTargetCountActionStatus = rollout.getTotalTargetCountStatus(); proxyRollout.setTotalTargetCountStatus(totalTargetCountActionStatus); proxyRollout.setTotalTargetsCount(String.valueOf(rollout.getTotalTargets())); - - proxyRollout.setDescription(distributionSet.getDescription()); proxyRollout.setType(distributionSet.getType().getName()); proxyRollout.setIsRequiredMigrationStep(distributionSet.isRequiredMigrationStep()); proxyRollout.setSwModules(distributionSet.getModules()); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java index f6653d971..05a6ec410 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/ProxyRolloutGroup.java @@ -8,14 +8,19 @@ */ package org.eclipse.hawkbit.ui.rollout.rolloutgroup; -import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup; +import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupErrorAction; +import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupErrorCondition; +import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupStatus; +import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupSuccessAction; +import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupSuccessCondition; +import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; import org.eclipse.hawkbit.ui.customrenderers.client.renderers.RolloutRendererData; /** * Proxy rollout group with renderer properties. * */ -public class ProxyRolloutGroup extends JpaRolloutGroup { +public class ProxyRolloutGroup { private static final long serialVersionUID = -2745056813306692356L; @@ -41,6 +46,23 @@ public class ProxyRolloutGroup extends JpaRolloutGroup { private String totalTargetsCount; + private Long id; + private String name; + private String description; + private String createdBy; + private String lastModifiedBy; + private RolloutGroupStatus status; + private TotalTargetCountStatus totalTargetCountStatus; + + private RolloutGroupSuccessCondition successCondition; + private String successConditionExp; + private RolloutGroupSuccessAction successAction; + private String successActionExp; + private RolloutGroupErrorCondition errorCondition; + private String errorConditionExp; + private RolloutGroupErrorAction errorAction; + private String errorActionExp; + private RolloutRendererData rolloutRendererData; public RolloutRendererData getRolloutRendererData() { @@ -216,4 +238,124 @@ public class ProxyRolloutGroup extends JpaRolloutGroup { this.totalTargetsCount = totalTargetsCount; } + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + public Long getId() { + return id; + } + + public void setId(final Long id) { + this.id = id; + } + + public String getDescription() { + return description; + } + + public void setDescription(final String description) { + this.description = description; + } + + public String getCreatedBy() { + return createdBy; + } + + public void setCreatedBy(final String createdBy) { + this.createdBy = createdBy; + } + + public String getLastModifiedBy() { + return lastModifiedBy; + } + + public void setLastModifiedBy(final String lastModifiedBy) { + this.lastModifiedBy = lastModifiedBy; + } + + public RolloutGroupStatus getStatus() { + return status; + } + + public void setStatus(final RolloutGroupStatus status) { + this.status = status; + } + + public TotalTargetCountStatus getTotalTargetCountStatus() { + return totalTargetCountStatus; + } + + public void setTotalTargetCountStatus(final TotalTargetCountStatus totalTargetCountStatus) { + this.totalTargetCountStatus = totalTargetCountStatus; + } + + public RolloutGroupSuccessCondition getSuccessCondition() { + return successCondition; + } + + public void setSuccessCondition(final RolloutGroupSuccessCondition successCondition) { + this.successCondition = successCondition; + } + + public String getSuccessConditionExp() { + return successConditionExp; + } + + public void setSuccessConditionExp(final String successConditionExp) { + this.successConditionExp = successConditionExp; + } + + public RolloutGroupSuccessAction getSuccessAction() { + return successAction; + } + + public void setSuccessAction(final RolloutGroupSuccessAction successAction) { + this.successAction = successAction; + } + + public String getSuccessActionExp() { + return successActionExp; + } + + public void setSuccessActionExp(final String successActionExp) { + this.successActionExp = successActionExp; + } + + public RolloutGroupErrorCondition getErrorCondition() { + return errorCondition; + } + + public void setErrorCondition(final RolloutGroupErrorCondition errorCondition) { + this.errorCondition = errorCondition; + } + + public String getErrorConditionExp() { + return errorConditionExp; + } + + public void setErrorConditionExp(final String errorConditionExp) { + this.errorConditionExp = errorConditionExp; + } + + public RolloutGroupErrorAction getErrorAction() { + return errorAction; + } + + public void setErrorAction(final RolloutGroupErrorAction errorAction) { + this.errorAction = errorAction; + } + + public String getErrorActionExp() { + return errorActionExp; + } + + public void setErrorActionExp(final String errorActionExp) { + this.errorActionExp = errorActionExp; + } + }