diff --git a/examples/hawkbit-example-mgmt-simulator/.gitignore b/examples/hawkbit-example-mgmt-simulator/.gitignore index 4b9b73073..b5c3eb864 100644 --- a/examples/hawkbit-example-mgmt-simulator/.gitignore +++ b/examples/hawkbit-example-mgmt-simulator/.gitignore @@ -1,3 +1,4 @@ /target/ /bin/ /.apt_generated/ +/.springBeans diff --git a/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/json/model/softwaremodule/MgmtSoftwareModule.java b/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/json/model/softwaremodule/MgmtSoftwareModule.java index ec4a48e89..08b723198 100644 --- a/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/json/model/softwaremodule/MgmtSoftwareModule.java +++ b/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/json/model/softwaremodule/MgmtSoftwareModule.java @@ -23,19 +23,6 @@ import com.fasterxml.jackson.annotation.JsonProperty; @JsonInclude(Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) public class MgmtSoftwareModule extends MgmtNamedEntity { - /** - * API definition for Software module type#RUNTIME. - */ - public static final String SM_RUNTIME = "runtime"; - /** - * API definition for for Software module type#OS. - */ - public static final String SM_OS = "os"; - /** - * API definition for for Software module type#APPLICATION. - */ - public static final String SM_APPLICATION = "application"; - @JsonProperty(value = "id", required = true) private Long moduleId; diff --git a/hawkbit-repository/.gitignore b/hawkbit-repository/.gitignore new file mode 100644 index 000000000..6a3b2b405 --- /dev/null +++ b/hawkbit-repository/.gitignore @@ -0,0 +1 @@ +/.springBeans diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/Constants.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/Constants.java new file mode 100644 index 000000000..6ccb4bc82 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/Constants.java @@ -0,0 +1,58 @@ +/** + * Copyright (c) 2011-2016 Bosch Software Innovations GmbH, Germany. All rights reserved. + */ +package org.eclipse.hawkbit.repository; + +import org.eclipse.hawkbit.repository.model.DistributionSetType; +import org.eclipse.hawkbit.repository.model.SoftwareModuleType; + +/** + * Repository API constants. + * + */ +public final class Constants { + /** + * Default {@link SoftwareModuleType} generated by repository for every new + * account for Firmware/Operating System. + */ + public static final String SMT_DEFAULT_OS_KEY = "os"; + /** + * Default {@link SoftwareModuleType} generated by repository for every new + * account for applications. + */ + public static final String SMT_DEFAULT_APP_KEY = "application"; + + /** + * {@link DistributionSetType#getKey()} of a {@link DistributionSetType} + * generated by repository for every new account that includes + * {@link #SMT_DEFAULT_OS_KEY} as mandatory module and optional + * {@link #SMT_DEFAULT_APP_KEY}s. + */ + public static final String DST_DEFAULT_OS_WITH_APPS_KEY = "os_app"; + + /** + * {@link DistributionSetType#getName()} of a {@link DistributionSetType} + * generated by repository for every new account that includes + * {@link #SMT_DEFAULT_OS_KEY} as mandatory module and optional + * {@link #SMT_DEFAULT_APP_KEY}s. + */ + public static final String DST_DEFAULT_OS_WITH_APPS_NAME = "OS with app(s)"; + + /** + * {@link DistributionSetType#getKey()} of a {@link DistributionSetType} + * generated by repository for every new account that includes only + * {@link #SMT_DEFAULT_OS_KEY} as mandatory module. + */ + public static final String DST_DEFAULT_OS_ONLY_KEY = "os"; + + /** + * {@link DistributionSetType#getName()} of a {@link DistributionSetType} + * generated by repository for every new account that includes only + * {@link #SMT_DEFAULT_OS_KEY} as mandatory module. + */ + public static final String DST_DEFAULT_OS_ONLY_NAME = "OS only"; + + private Constants() { + // Utility class. + } +} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java index ab5fc1b41..a2865c4b0 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSystemManagement.java @@ -16,6 +16,7 @@ import java.util.stream.Collectors; import javax.persistence.EntityManager; import org.eclipse.hawkbit.cache.TenancyCacheManager; +import org.eclipse.hawkbit.repository.Constants; import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.repository.TenantStatsManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; @@ -283,16 +284,19 @@ public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, Syst } private DistributionSetType createStandardSoftwareDataSetup() { - final SoftwareModuleType app = softwareModuleTypeRepository - .save(new JpaSoftwareModuleType("application", "Application", "Application Addons", Integer.MAX_VALUE)); - final SoftwareModuleType os = softwareModuleTypeRepository - .save(new JpaSoftwareModuleType("os", "Firmware", "Core firmware or operationg system", 1)); + final SoftwareModuleType app = softwareModuleTypeRepository.save(new JpaSoftwareModuleType( + Constants.SMT_DEFAULT_APP_KEY, "Application", "Application Addons", Integer.MAX_VALUE)); + final SoftwareModuleType os = softwareModuleTypeRepository.save(new JpaSoftwareModuleType( + Constants.SMT_DEFAULT_OS_KEY, "Firmware", "Core firmware or operationg system", 1)); - distributionSetTypeRepository.save((JpaDistributionSetType) new JpaDistributionSetType("os", "OS only", - "Default type with Firmware/OS only.").addMandatoryModuleType(os)); + distributionSetTypeRepository + .save((JpaDistributionSetType) new JpaDistributionSetType(Constants.DST_DEFAULT_OS_ONLY_KEY, + Constants.DST_DEFAULT_OS_ONLY_NAME, "Default type with Firmware/OS only.") + .addMandatoryModuleType(os)); - return distributionSetTypeRepository.save((JpaDistributionSetType) new JpaDistributionSetType("os_app", - "OS with app(s)", "Default type with Firmware/OS and optional app(s).").addMandatoryModuleType(os) - .addOptionalModuleType(app)); + return distributionSetTypeRepository + .save((JpaDistributionSetType) new JpaDistributionSetType(Constants.DST_DEFAULT_OS_WITH_APPS_KEY, + Constants.DST_DEFAULT_OS_WITH_APPS_NAME, "Default type with Firmware/OS and optional app(s).") + .addMandatoryModuleType(os).addOptionalModuleType(app)); } } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleFieldTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleFieldTest.java index d55de383f..47732dac2 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleFieldTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLSoftwareModuleFieldTest.java @@ -16,6 +16,7 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleMetadata; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata; +import org.eclipse.hawkbit.repository.util.TestdataFactory; import org.junit.Before; import org.junit.Test; import org.springframework.data.domain.Page; @@ -84,10 +85,10 @@ public class RSQLSoftwareModuleFieldTest extends AbstractJpaIntegrationTest { @Test @Description("Test filter software module by type") public void testFilterByType() { - assertRSQLQuery(SoftwareModuleFields.TYPE.name() + "==application", 2); + assertRSQLQuery(SoftwareModuleFields.TYPE.name() + "==" + TestdataFactory.SM_TYPE_APP, 2); assertRSQLQuery(SoftwareModuleFields.TYPE.name() + "==noExist*", 0); - assertRSQLQuery(SoftwareModuleFields.TYPE.name() + "=in=(application)", 2); - assertRSQLQuery(SoftwareModuleFields.TYPE.name() + "=out=(application)", 2); + assertRSQLQuery(SoftwareModuleFields.TYPE.name() + "=in=(" + TestdataFactory.SM_TYPE_APP + ")", 2); + assertRSQLQuery(SoftwareModuleFields.TYPE.name() + "=out=(" + TestdataFactory.SM_TYPE_APP + ")", 2); } @Test