diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaSoftwareModuleManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaSoftwareModuleManagement.java index 913d3c8883..cac7e96df8 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaSoftwareModuleManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaSoftwareModuleManagement.java @@ -474,14 +474,12 @@ public SoftwareModuleMetadata updateMetaData(final SoftwareModuleMetadataUpdate // check if exists otherwise throw entity not found exception final JpaSoftwareModuleMetadata metadata = (JpaSoftwareModuleMetadata) getMetaDataBySoftwareModuleId( update.getSoftwareModuleId(), update.getKey()) - .orElseThrow(() -> new EntityNotFoundException(SoftwareModuleMetadata.class, - update.getSoftwareModuleId(), update.getKey())); + .orElseThrow(() -> new EntityNotFoundException(SoftwareModuleMetadata.class, update.getSoftwareModuleId(), update.getKey())); update.getValue().ifPresent(metadata::setValue); update.isTargetVisible().ifPresent(metadata::setTargetVisible); - JpaManagementHelper.touch(entityManager, softwareModuleRepository, - (JpaSoftwareModule) metadata.getSoftwareModule()); + JpaManagementHelper.touch(entityManager, softwareModuleRepository, metadata.getSoftwareModule()); return softwareModuleMetadataRepository.save(metadata); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaSystemManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaSystemManagement.java index b0efbf12e7..4eb40e22c9 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaSystemManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaSystemManagement.java @@ -47,10 +47,8 @@ import org.eclipse.hawkbit.repository.report.model.SystemUsageReportWithTenants; import org.eclipse.hawkbit.security.SystemSecurityContext; import org.eclipse.hawkbit.tenancy.TenantAware; -import org.eclipse.persistence.config.PersistenceUnitProperties; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties; -import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.interceptor.KeyGenerator; import org.springframework.dao.ConcurrencyFailureException; import org.springframework.data.domain.Page; @@ -140,7 +138,6 @@ public KeyGenerator currentTenantKeyGenerator() { } @Override - @Transactional @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) public void deleteTenant(final String t) { @@ -151,8 +148,7 @@ public void deleteTenant(final String t) { final String tenant = t.toUpperCase(); cacheManager.evictCaches(tenant); rolloutStatusCache.evictCaches(tenant); - tenantAware.runAsTenant(tenant, () -> { - entityManager.setProperty(PersistenceUnitProperties.MULTITENANT_PROPERTY_DEFAULT, tenant); + tenantAware.runAsTenant(tenant, () -> DeploymentHelper.runInNewTransaction(txManager, "deleteTenant", status -> { tenantMetaDataRepository.deleteByTenantIgnoreCase(tenant); tenantConfigurationRepository.deleteByTenant(tenant); targetRepository.deleteByTenant(tenant); @@ -167,7 +163,7 @@ public void deleteTenant(final String t) { artifactRepository.deleteByTenant(tenant); softwareModuleTypeRepository.deleteByTenant(tenant); return null; - }); + })); } @Override @@ -292,13 +288,16 @@ private void usageStatsPerTenant(final SystemUsageReportWithTenants report) { } private DistributionSetType createStandardSoftwareDataSetup() { - final SoftwareModuleType app = softwareModuleTypeRepository - .save(new JpaSoftwareModuleType(org.eclipse.hawkbit.repository.Constants.SMT_DEFAULT_APP_KEY, - org.eclipse.hawkbit.repository.Constants.SMT_DEFAULT_APP_NAME, "Application Addons", - Integer.MAX_VALUE)); - final SoftwareModuleType os = softwareModuleTypeRepository.save(new JpaSoftwareModuleType( - org.eclipse.hawkbit.repository.Constants.SMT_DEFAULT_OS_KEY, - org.eclipse.hawkbit.repository.Constants.SMT_DEFAULT_OS_NAME, "Core firmware or operation system", 1)); + final SoftwareModuleType app = softwareModuleTypeRepository.save( + new JpaSoftwareModuleType( + org.eclipse.hawkbit.repository.Constants.SMT_DEFAULT_APP_KEY, + org.eclipse.hawkbit.repository.Constants.SMT_DEFAULT_APP_NAME, + "Application Addons", Integer.MAX_VALUE)); + final SoftwareModuleType os = softwareModuleTypeRepository.save( + new JpaSoftwareModuleType( + org.eclipse.hawkbit.repository.Constants.SMT_DEFAULT_OS_KEY, + org.eclipse.hawkbit.repository.Constants.SMT_DEFAULT_OS_NAME, + "Core firmware or operation system", 1)); // make sure the module types get their IDs entityManager.flush(); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/LocalArtifactRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/LocalArtifactRepository.java index cea7f22660..5ab376ac8c 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/LocalArtifactRepository.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/LocalArtifactRepository.java @@ -22,12 +22,10 @@ * {@link Artifact} repository. */ @Transactional(readOnly = true) -public interface LocalArtifactRepository - extends BaseEntityRepository { +public interface LocalArtifactRepository extends BaseEntityRepository { /** - * Counts artifacts size where the related software module is not - * deleted/archived. + * Counts artifacts size where the related software module is not deleted/archived. *

* No access control applied. * @@ -47,8 +45,7 @@ public interface LocalArtifactRepository Long countBySoftwareModuleDeleted(boolean deleted); /** - * Counts current elements based on the sha1 and tenant, as well as having the - * {@link SoftwareModule} property 'deleted' with value 'false' + * Counts current elements based on the sha1 and tenant, as well as having the {@link SoftwareModule} property 'deleted' with value 'false' *

* No access control applied * @@ -56,8 +53,7 @@ public interface LocalArtifactRepository * @param tenant the current tenant\ * @return the count of the elements */ - long countBySha1HashAndTenantAndSoftwareModuleDeletedIsFalse( - @Param("sha1") String sha1, @Param("tenant") String tenant); + long countBySha1HashAndTenantAndSoftwareModuleDeletedIsFalse(@Param("sha1") String sha1, @Param("tenant") String tenant); /** * Searches for a {@link Artifact} based on given gridFsFileName. @@ -84,4 +80,4 @@ long countBySha1HashAndTenantAndSoftwareModuleDeletedIsFalse( * @return list of {@link Artifact}. */ Optional findFirstByFilenameAndSoftwareModuleId(String filename, Long softwareModuleId); -} +} \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/TenantMetaDataRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/TenantMetaDataRepository.java index 888ed0fecc..a5143f8c03 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/TenantMetaDataRepository.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/repository/TenantMetaDataRepository.java @@ -21,12 +21,10 @@ import org.springframework.transaction.annotation.Transactional; /** - * repository for operations on {@link TenantMetaData} entity. + * Repository for operations on {@link TenantMetaData} entity. */ @Transactional(readOnly = true) -public interface TenantMetaDataRepository - extends PagingAndSortingRepository, - CrudRepository { +public interface TenantMetaDataRepository extends PagingAndSortingRepository, CrudRepository { /** * Search {@link TenantMetaData} by tenant name. @@ -47,4 +45,4 @@ public interface TenantMetaDataRepository @Modifying @Query("DELETE FROM JpaTenantMetaData t WHERE UPPER(t.tenant) = UPPER(:tenant)") void deleteByTenantIgnoreCase(@Param("tenant") String tenant); -} +} \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/SystemManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/SystemManagementTest.java index 583f3c5b85..29798f70a4 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/SystemManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/management/SystemManagementTest.java @@ -33,11 +33,11 @@ @Feature("Component Tests - Repository") @Story("System Management") @ExtendWith(DisposableSqlTestDatabaseExtension.class) -public class SystemManagementTest extends AbstractJpaIntegrationTest { +class SystemManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Ensures that findTenants returns all tenants and not only restricted to the tenant which currently is logged in") - public void findTenantsReturnsAllTenantsNotOnlyWhichLoggedIn() throws Exception { + void findTenantsReturnsAllTenantsNotOnlyWhichLoggedIn() throws Exception { assertThat(systemManagement.findTenants(PAGE).getContent()).hasSize(1); createTestTenantsForSystemStatistics(2, 0, 0, 0); @@ -47,7 +47,7 @@ public void findTenantsReturnsAllTenantsNotOnlyWhichLoggedIn() throws Exception @Test @Description("Ensures that getSystemUsageStatisticsWithTenants returns the usage of all tenants and not only the first 1000 (max page size).") - public void systemUsageReportCollectsStatisticsOfManyTenants() throws Exception { + void systemUsageReportCollectsStatisticsOfManyTenants() throws Exception { // Prepare tenants createTestTenantsForSystemStatistics(1050, 0, 0, 0); @@ -57,7 +57,7 @@ public void systemUsageReportCollectsStatisticsOfManyTenants() throws Exception @Test @Description("Checks that the system report calculates correctly the artifact size of all tenants in the system. It ignores deleted software modules with their artifacts.") - public void systemUsageReportCollectsArtifactsOfAllTenants() throws Exception { + void systemUsageReportCollectsArtifactsOfAllTenants() throws Exception { // Prepare tenants createTestTenantsForSystemStatistics(2, 1234, 0, 0); @@ -81,7 +81,7 @@ public void systemUsageReportCollectsArtifactsOfAllTenants() throws Exception { @Test @Description("Checks that the system report calculates correctly the targets size of all tenants in the system") - public void systemUsageReportCollectsTargetsOfAllTenants() throws Exception { + void systemUsageReportCollectsTargetsOfAllTenants() throws Exception { // Prepare tenants createTestTenantsForSystemStatistics(2, 0, 100, 0); @@ -101,7 +101,7 @@ public void systemUsageReportCollectsTargetsOfAllTenants() throws Exception { @Test @Description("Checks that the system report calculates correctly the actions size of all tenants in the system") - public void systemUsageReportCollectsActionsOfAllTenants() throws Exception { + void systemUsageReportCollectsActionsOfAllTenants() throws Exception { // Prepare tenants createTestTenantsForSystemStatistics(2, 0, 20, 2);