Software module metadata available to targets (in DMF and DDI) (#608)
* Software module metadata can be configure as target visible. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Added metadata to DDI. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Managed by UI. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Complete DMF integration and started UI. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Add DMF tests and completed UI. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Add RSQL test. Fix sonar issues. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Add JavaDocs. foreachtenant robustness. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Review feedback included. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Updated DMF docs. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * targetVisible optional in builder. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Fix typos. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Fix checkbox ID. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * DB optimization. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com> * Fix component ID of sm metadat details tab. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
@@ -9,10 +9,12 @@
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.criteria.CriteriaBuilder;
|
||||
@@ -45,6 +47,7 @@ import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
import org.eclipse.hawkbit.repository.model.ActionStatus;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
import org.eclipse.hawkbit.security.SystemSecurityContext;
|
||||
@@ -115,6 +118,9 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
@Autowired
|
||||
private AfterTransactionCommitExecutor afterCommit;
|
||||
|
||||
@Autowired
|
||||
private SoftwareModuleMetadataRepository softwareModuleMetadataRepository;
|
||||
|
||||
@Override
|
||||
public String getPollingTime() {
|
||||
return systemSecurityContext.runAsSystem(() -> tenantConfigurationManagement
|
||||
@@ -523,4 +529,15 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
public Optional<SoftwareModule> getSoftwareModule(final Long id) {
|
||||
return Optional.ofNullable(softwareModuleRepository.findOne(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Long, List<SoftwareModuleMetadata>> findTargetVisibleMetaDataBySoftwareModuleId(
|
||||
final Collection<Long> moduleId) {
|
||||
|
||||
return softwareModuleMetadataRepository
|
||||
.findBySoftwareModuleIdInAndTargetVisible(new PageRequest(0, RepositoryConstants.MAX_META_DATA_COUNT),
|
||||
moduleId, true)
|
||||
.getContent().stream().collect(Collectors.groupingBy(o -> (Long) o[0],
|
||||
Collectors.mapping(o -> (SoftwareModuleMetadata) o[1], Collectors.toList())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import org.eclipse.hawkbit.repository.builder.DistributionSetTypeBuilder;
|
||||
import org.eclipse.hawkbit.repository.builder.RolloutBuilder;
|
||||
import org.eclipse.hawkbit.repository.builder.RolloutGroupBuilder;
|
||||
import org.eclipse.hawkbit.repository.builder.SoftwareModuleBuilder;
|
||||
import org.eclipse.hawkbit.repository.builder.SoftwareModuleMetadataBuilder;
|
||||
import org.eclipse.hawkbit.repository.builder.SoftwareModuleTypeBuilder;
|
||||
import org.eclipse.hawkbit.repository.builder.TagBuilder;
|
||||
import org.eclipse.hawkbit.repository.builder.TargetBuilder;
|
||||
@@ -24,7 +25,7 @@ import org.eclipse.hawkbit.repository.jpa.builder.JpaRolloutGroupBuilder;
|
||||
import org.eclipse.hawkbit.repository.jpa.builder.JpaSoftwareModuleTypeBuilder;
|
||||
import org.eclipse.hawkbit.repository.jpa.builder.JpaTagBuilder;
|
||||
import org.eclipse.hawkbit.repository.jpa.builder.JpaTargetBuilder;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaMetaData;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetMetadata;
|
||||
import org.eclipse.hawkbit.repository.model.MetaData;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@@ -51,9 +52,12 @@ public class JpaEntityFactory implements EntityFactory {
|
||||
@Autowired
|
||||
private TargetFilterQueryBuilder targetFilterQueryBuilder;
|
||||
|
||||
@Autowired
|
||||
private SoftwareModuleMetadataBuilder softwareModuleMetadataBuilder;
|
||||
|
||||
@Override
|
||||
public MetaData generateMetadata(final String key, final String value) {
|
||||
return new JpaMetaData(key, value);
|
||||
return new JpaDistributionSetMetadata(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -106,4 +110,9 @@ public class JpaEntityFactory implements EntityFactory {
|
||||
return new JpaRolloutGroupBuilder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SoftwareModuleMetadataBuilder softwareModuleMetadata() {
|
||||
return softwareModuleMetadataBuilder;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,15 +28,20 @@ import javax.persistence.criteria.Root;
|
||||
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions;
|
||||
import org.eclipse.hawkbit.repository.ArtifactManagement;
|
||||
import org.eclipse.hawkbit.repository.RepositoryConstants;
|
||||
import org.eclipse.hawkbit.repository.SoftwareModuleFields;
|
||||
import org.eclipse.hawkbit.repository.SoftwareModuleManagement;
|
||||
import org.eclipse.hawkbit.repository.SoftwareModuleMetadataFields;
|
||||
import org.eclipse.hawkbit.repository.builder.GenericSoftwareModuleMetadataUpdate;
|
||||
import org.eclipse.hawkbit.repository.builder.GenericSoftwareModuleUpdate;
|
||||
import org.eclipse.hawkbit.repository.builder.SoftwareModuleCreate;
|
||||
import org.eclipse.hawkbit.repository.builder.SoftwareModuleMetadataCreate;
|
||||
import org.eclipse.hawkbit.repository.builder.SoftwareModuleMetadataUpdate;
|
||||
import org.eclipse.hawkbit.repository.builder.SoftwareModuleUpdate;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.jpa.builder.JpaSoftwareModuleCreate;
|
||||
import org.eclipse.hawkbit.repository.jpa.builder.JpaSoftwareModuleMetadataCreate;
|
||||
import org.eclipse.hawkbit.repository.jpa.configuration.Constants;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet_;
|
||||
@@ -51,7 +56,6 @@ import org.eclipse.hawkbit.repository.jpa.specifications.SpecificationsBuilder;
|
||||
import org.eclipse.hawkbit.repository.model.Artifact;
|
||||
import org.eclipse.hawkbit.repository.model.AssignedSoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.MetaData;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
||||
@@ -61,6 +65,7 @@ import org.springframework.dao.ConcurrencyFailureException;
|
||||
import org.springframework.data.domain.AuditorAware;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Slice;
|
||||
import org.springframework.data.domain.SliceImpl;
|
||||
@@ -443,15 +448,17 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
|
||||
@Transactional
|
||||
@Retryable(include = {
|
||||
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
||||
public SoftwareModuleMetadata createMetaData(final Long moduleId, final MetaData md) {
|
||||
public SoftwareModuleMetadata createMetaData(final SoftwareModuleMetadataCreate c) {
|
||||
final JpaSoftwareModuleMetadataCreate create = (JpaSoftwareModuleMetadataCreate) c;
|
||||
|
||||
checkAndThrowAlreadyIfSoftwareModuleMetadataExists(moduleId, md);
|
||||
checkAndThrowAlreadyIfSoftwareModuleMetadataExists(create.getSoftwareModuleId(), create);
|
||||
touch(create.getSoftwareModuleId());
|
||||
|
||||
return softwareModuleMetadataRepository
|
||||
.save(new JpaSoftwareModuleMetadata(md.getKey(), touch(moduleId), md.getValue()));
|
||||
return softwareModuleMetadataRepository.save(create.build());
|
||||
}
|
||||
|
||||
private void checkAndThrowAlreadyIfSoftwareModuleMetadataExists(final Long moduleId, final MetaData md) {
|
||||
private void checkAndThrowAlreadyIfSoftwareModuleMetadataExists(final Long moduleId,
|
||||
final JpaSoftwareModuleMetadataCreate md) {
|
||||
if (softwareModuleMetadataRepository.exists(new SwMetadataCompositeKey(moduleId, md.getKey()))) {
|
||||
throwMetadataKeyAlreadyExists(md.getKey());
|
||||
}
|
||||
@@ -461,28 +468,26 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
|
||||
@Transactional
|
||||
@Retryable(include = {
|
||||
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
||||
public List<SoftwareModuleMetadata> createMetaData(final Long moduleId, final Collection<MetaData> md) {
|
||||
md.forEach(meta -> checkAndThrowAlreadyIfSoftwareModuleMetadataExists(moduleId, meta));
|
||||
public List<SoftwareModuleMetadata> createMetaData(final Collection<SoftwareModuleMetadataCreate> create) {
|
||||
|
||||
final JpaSoftwareModule module = touch(moduleId);
|
||||
|
||||
return Collections.unmodifiableList(md.stream()
|
||||
.map(meta -> softwareModuleMetadataRepository
|
||||
.save(new JpaSoftwareModuleMetadata(meta.getKey(), module, meta.getValue())))
|
||||
.collect(Collectors.toList()));
|
||||
return create.stream().map(this::createMetaData).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Retryable(include = {
|
||||
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
||||
public SoftwareModuleMetadata updateMetaData(final Long moduleId, final MetaData md) {
|
||||
public SoftwareModuleMetadata updateMetaData(final SoftwareModuleMetadataUpdate u) {
|
||||
final GenericSoftwareModuleMetadataUpdate update = (GenericSoftwareModuleMetadataUpdate) u;
|
||||
|
||||
// check if exists otherwise throw entity not found exception
|
||||
final JpaSoftwareModuleMetadata metadata = (JpaSoftwareModuleMetadata) getMetaDataBySoftwareModuleId(moduleId,
|
||||
md.getKey()).orElseThrow(
|
||||
() -> new EntityNotFoundException(SoftwareModuleMetadata.class, moduleId, md.getKey()));
|
||||
metadata.setValue(md.getValue());
|
||||
final JpaSoftwareModuleMetadata metadata = (JpaSoftwareModuleMetadata) getMetaDataBySoftwareModuleId(
|
||||
update.getSoftwareModuleId(), update.getKey())
|
||||
.orElseThrow(() -> new EntityNotFoundException(SoftwareModuleMetadata.class,
|
||||
update.getSoftwareModuleId(), update.getKey()));
|
||||
|
||||
update.getValue().ifPresent(metadata::setValue);
|
||||
update.isTargetVisible().ifPresent(metadata::setTargetVisible);
|
||||
|
||||
touch(metadata.getSoftwareModule());
|
||||
return softwareModuleMetadataRepository.save(metadata);
|
||||
@@ -593,4 +598,13 @@ public class JpaSoftwareModuleManagement implements SoftwareModuleManagement {
|
||||
return softwareModuleRepository.exists(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<SoftwareModuleMetadata> findMetaDataBySoftwareModuleIdAndTargetVisible(final Pageable pageable,
|
||||
final Long moduleId) {
|
||||
throwExceptionIfSoftwareModuleDoesNotExist(moduleId);
|
||||
|
||||
return convertMdPage(softwareModuleMetadataRepository.findBySoftwareModuleIdAndTargetVisible(
|
||||
new PageRequest(0, RepositoryConstants.MAX_META_DATA_COUNT), moduleId, true), pageable);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,6 +34,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.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.cache.interceptor.KeyGenerator;
|
||||
@@ -59,6 +61,8 @@ import org.springframework.validation.annotation.Validated;
|
||||
@Transactional(readOnly = true)
|
||||
@Validated
|
||||
public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, SystemManagement {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(JpaSystemManagement.class);
|
||||
|
||||
private static final int MAX_TENANTS_QUERY = 500;
|
||||
|
||||
@Autowired
|
||||
@@ -328,7 +332,12 @@ public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, Syst
|
||||
do {
|
||||
tenants = findTenants(query);
|
||||
tenants.forEach(tenant -> tenantAware.runAsTenant(tenant, () -> {
|
||||
consumer.accept(tenant);
|
||||
try {
|
||||
consumer.accept(tenant);
|
||||
} catch (final RuntimeException ex) {
|
||||
LOGGER.error("Exception on forEachTenant execution for tenant {}. Continue with next tenant.",
|
||||
tenant, ex);
|
||||
}
|
||||
return null;
|
||||
}));
|
||||
} while (tenants.hasNext() && (query = tenants.nextPageable()) != null);
|
||||
|
||||
@@ -39,6 +39,7 @@ import org.eclipse.hawkbit.repository.builder.DistributionSetBuilder;
|
||||
import org.eclipse.hawkbit.repository.builder.DistributionSetTypeBuilder;
|
||||
import org.eclipse.hawkbit.repository.builder.RolloutBuilder;
|
||||
import org.eclipse.hawkbit.repository.builder.SoftwareModuleBuilder;
|
||||
import org.eclipse.hawkbit.repository.builder.SoftwareModuleMetadataBuilder;
|
||||
import org.eclipse.hawkbit.repository.builder.TargetFilterQueryBuilder;
|
||||
import org.eclipse.hawkbit.repository.event.ApplicationEventFilter;
|
||||
import org.eclipse.hawkbit.repository.event.remote.EventEntityManager;
|
||||
@@ -51,6 +52,7 @@ import org.eclipse.hawkbit.repository.jpa.builder.JpaDistributionSetBuilder;
|
||||
import org.eclipse.hawkbit.repository.jpa.builder.JpaDistributionSetTypeBuilder;
|
||||
import org.eclipse.hawkbit.repository.jpa.builder.JpaRolloutBuilder;
|
||||
import org.eclipse.hawkbit.repository.jpa.builder.JpaSoftwareModuleBuilder;
|
||||
import org.eclipse.hawkbit.repository.jpa.builder.JpaSoftwareModuleMetadataBuilder;
|
||||
import org.eclipse.hawkbit.repository.jpa.builder.JpaTargetFilterQueryBuilder;
|
||||
import org.eclipse.hawkbit.repository.jpa.configuration.MultiTenantJpaTransactionManager;
|
||||
import org.eclipse.hawkbit.repository.jpa.event.JpaEventEntityManager;
|
||||
@@ -167,6 +169,12 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
|
||||
return new JpaDistributionSetBuilder(distributionSetTypeManagement, softwareManagement);
|
||||
}
|
||||
|
||||
@Bean
|
||||
SoftwareModuleMetadataBuilder softwareModuleMetadataBuilder(
|
||||
final SoftwareModuleManagement softwareModuleManagement) {
|
||||
return new JpaSoftwareModuleMetadataBuilder(softwareModuleManagement);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param softwareManagement
|
||||
* for loading
|
||||
|
||||
@@ -38,7 +38,7 @@ public interface RolloutGroupRepository
|
||||
* the rollout the rolloutgroups belong to
|
||||
* @return the rollout groups belonging to a rollout ordered by ID ASC.
|
||||
*/
|
||||
List<JpaRolloutGroup> findByRolloutOrderByIdAsc(final JpaRollout rollout);
|
||||
List<JpaRolloutGroup> findByRolloutOrderByIdAsc(JpaRollout rollout);
|
||||
|
||||
/**
|
||||
* Retrieves all {@link RolloutGroup} referring a specific rollout in a
|
||||
@@ -50,7 +50,7 @@ public interface RolloutGroupRepository
|
||||
* the status of the rollout groups
|
||||
* @return the rollout groups belonging to a rollout in a specific status
|
||||
*/
|
||||
List<JpaRolloutGroup> findByRolloutAndStatus(final Rollout rollout, final RolloutGroupStatus status);
|
||||
List<JpaRolloutGroup> findByRolloutAndStatus(Rollout rollout, RolloutGroupStatus status);
|
||||
|
||||
/**
|
||||
* Counts all {@link RolloutGroup} referring a specific rollout in specific
|
||||
|
||||
@@ -8,11 +8,17 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleMetadata;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.SwMetadataCompositeKey;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.PagingAndSortingRepository;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
@@ -24,4 +30,11 @@ public interface SoftwareModuleMetadataRepository
|
||||
extends PagingAndSortingRepository<JpaSoftwareModuleMetadata, SwMetadataCompositeKey>,
|
||||
JpaSpecificationExecutor<JpaSoftwareModuleMetadata> {
|
||||
|
||||
Page<JpaSoftwareModuleMetadata> findBySoftwareModuleIdAndTargetVisible(Pageable page, Long moduleId,
|
||||
boolean targetVisible);
|
||||
|
||||
@Query("SELECT smd.softwareModule.id, smd FROM JpaSoftwareModuleMetadata smd WHERE smd.softwareModule.id IN :moduleId AND smd.targetVisible = :targetVisible")
|
||||
Page<Object[]> findBySoftwareModuleIdInAndTargetVisible(Pageable page, @Param("moduleId") Collection<Long> moduleId,
|
||||
@Param("targetVisible") boolean targetVisible);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.builder;
|
||||
|
||||
import org.eclipse.hawkbit.repository.SoftwareModuleManagement;
|
||||
import org.eclipse.hawkbit.repository.builder.GenericSoftwareModuleMetadataUpdate;
|
||||
import org.eclipse.hawkbit.repository.builder.SoftwareModuleMetadataBuilder;
|
||||
import org.eclipse.hawkbit.repository.builder.SoftwareModuleMetadataCreate;
|
||||
import org.eclipse.hawkbit.repository.builder.SoftwareModuleMetadataUpdate;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata;
|
||||
|
||||
/**
|
||||
* Builder implementation for {@link SoftwareModuleMetadata}.
|
||||
*
|
||||
*/
|
||||
public class JpaSoftwareModuleMetadataBuilder implements SoftwareModuleMetadataBuilder {
|
||||
|
||||
private final SoftwareModuleManagement softwareModuleManagement;
|
||||
|
||||
public JpaSoftwareModuleMetadataBuilder(final SoftwareModuleManagement softwareModuleManagement) {
|
||||
this.softwareModuleManagement = softwareModuleManagement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SoftwareModuleMetadataUpdate update(final long softwareModuleId, final String key) {
|
||||
return new GenericSoftwareModuleMetadataUpdate(softwareModuleId, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SoftwareModuleMetadataCreate create(final long softwareModuleId) {
|
||||
return new JpaSoftwareModuleMetadataCreate(softwareModuleId, softwareModuleManagement);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.builder;
|
||||
|
||||
import org.eclipse.hawkbit.repository.SoftwareModuleManagement;
|
||||
import org.eclipse.hawkbit.repository.builder.AbstractSoftwareModuleMetadataUpdateCreate;
|
||||
import org.eclipse.hawkbit.repository.builder.SoftwareModuleMetadataCreate;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleMetadata;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
|
||||
/**
|
||||
* Create/build implementation.
|
||||
*
|
||||
*/
|
||||
public class JpaSoftwareModuleMetadataCreate
|
||||
extends AbstractSoftwareModuleMetadataUpdateCreate<SoftwareModuleMetadataCreate>
|
||||
implements SoftwareModuleMetadataCreate {
|
||||
|
||||
private final SoftwareModuleManagement softwareModuleManagement;
|
||||
|
||||
JpaSoftwareModuleMetadataCreate(final long softwareModuleId,
|
||||
final SoftwareModuleManagement softwareModuleManagement) {
|
||||
this.softwareModuleManagement = softwareModuleManagement;
|
||||
this.softwareModuleId = softwareModuleId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JpaSoftwareModuleMetadata build() {
|
||||
final SoftwareModule module = softwareModuleManagement.get(softwareModuleId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(SoftwareModule.class, softwareModuleId));
|
||||
|
||||
if (key == null) {
|
||||
new JpaSoftwareModuleMetadata(key, module, value, isTargetVisible().orElse(false));
|
||||
}
|
||||
|
||||
return new JpaSoftwareModuleMetadata(key, module, value, isTargetVisible().orElse(false));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,36 +12,36 @@ import javax.persistence.Basic;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.MetaData;
|
||||
import org.hibernate.validator.constraints.NotEmpty;
|
||||
|
||||
/**
|
||||
* Meta data for entities.
|
||||
*
|
||||
*/
|
||||
@MappedSuperclass
|
||||
public class JpaMetaData implements MetaData {
|
||||
public abstract class AbstractJpaMetaData implements MetaData {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
@Column(name = "meta_key", nullable = false, length = 128)
|
||||
@Size(min = 1, max = 128)
|
||||
@NotEmpty
|
||||
@Column(name = "meta_key", nullable = false, length = MetaData.KEY_MAX_SIZE, updatable = false)
|
||||
@Size(min = 1, max = MetaData.KEY_MAX_SIZE)
|
||||
@NotNull
|
||||
private String key;
|
||||
|
||||
@Column(name = "meta_value", length = 4000)
|
||||
@Size(max = 4000)
|
||||
@Column(name = "meta_value", length = MetaData.VALUE_MAX_SIZE)
|
||||
@Size(max = MetaData.VALUE_MAX_SIZE)
|
||||
@Basic
|
||||
private String value;
|
||||
|
||||
public JpaMetaData(final String key, final String value) {
|
||||
public AbstractJpaMetaData(final String key, final String value) {
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public JpaMetaData() {
|
||||
public AbstractJpaMetaData() {
|
||||
// Default constructor needed for JPA entities
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ public class JpaMetaData implements MetaData {
|
||||
if (!(this.getClass().isInstance(obj))) {
|
||||
return false;
|
||||
}
|
||||
final JpaMetaData other = (JpaMetaData) obj;
|
||||
final AbstractJpaMetaData other = (AbstractJpaMetaData) obj;
|
||||
if (key == null) {
|
||||
if (other.key != null) {
|
||||
return false;
|
||||
@@ -28,7 +28,7 @@ import org.eclipse.hawkbit.repository.model.DistributionSetMetadata;
|
||||
@IdClass(DsMetadataCompositeKey.class)
|
||||
@Entity
|
||||
@Table(name = "sp_ds_metadata")
|
||||
public class JpaDistributionSetMetadata extends JpaMetaData implements DistributionSetMetadata {
|
||||
public class JpaDistributionSetMetadata extends AbstractJpaMetaData implements DistributionSetMetadata {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
@@ -40,6 +40,10 @@ public class JpaDistributionSetMetadata extends JpaMetaData implements Distribut
|
||||
// default public constructor for JPA
|
||||
}
|
||||
|
||||
public JpaDistributionSetMetadata(final String key, final String value) {
|
||||
super(key, value);
|
||||
}
|
||||
|
||||
public JpaDistributionSetMetadata(final String key, final DistributionSet distributionSet, final String value) {
|
||||
super(key, value);
|
||||
this.distributionSet = (JpaDistributionSet) distributionSet;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.model;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.ConstraintMode;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
@@ -28,7 +29,7 @@ import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata;
|
||||
@IdClass(SwMetadataCompositeKey.class)
|
||||
@Entity
|
||||
@Table(name = "sp_sw_metadata")
|
||||
public class JpaSoftwareModuleMetadata extends JpaMetaData implements SoftwareModuleMetadata {
|
||||
public class JpaSoftwareModuleMetadata extends AbstractJpaMetaData implements SoftwareModuleMetadata {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
@@ -36,6 +37,9 @@ public class JpaSoftwareModuleMetadata extends JpaMetaData implements SoftwareMo
|
||||
@JoinColumn(name = "sw_id", nullable = false, updatable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_metadata_sw"))
|
||||
private JpaSoftwareModule softwareModule;
|
||||
|
||||
@Column(name = "target_visible")
|
||||
private boolean targetVisible;
|
||||
|
||||
public JpaSoftwareModuleMetadata() {
|
||||
// default public constructor for JPA
|
||||
}
|
||||
@@ -45,6 +49,18 @@ public class JpaSoftwareModuleMetadata extends JpaMetaData implements SoftwareMo
|
||||
this.softwareModule = (JpaSoftwareModule) softwareModule;
|
||||
}
|
||||
|
||||
public JpaSoftwareModuleMetadata(final String key, final SoftwareModule softwareModule, final String value,
|
||||
final boolean targetVisible) {
|
||||
super(key, value);
|
||||
this.softwareModule = (JpaSoftwareModule) softwareModule;
|
||||
this.targetVisible = targetVisible;
|
||||
}
|
||||
|
||||
public JpaSoftwareModuleMetadata(final String key, final String value, final boolean targetVisible) {
|
||||
super(key, value);
|
||||
this.targetVisible = targetVisible;
|
||||
}
|
||||
|
||||
public SwMetadataCompositeKey getId() {
|
||||
return new SwMetadataCompositeKey(softwareModule.getId(), getKey());
|
||||
}
|
||||
@@ -58,6 +74,15 @@ public class JpaSoftwareModuleMetadata extends JpaMetaData implements SoftwareMo
|
||||
this.softwareModule = softwareModule;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTargetVisible() {
|
||||
return targetVisible;
|
||||
}
|
||||
|
||||
public void setTargetVisible(final boolean targetVisible) {
|
||||
this.targetVisible = targetVisible;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
@@ -83,4 +108,5 @@ public class JpaSoftwareModuleMetadata extends JpaMetaData implements SoftwareMo
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE sp_sw_metadata ADD COLUMN target_visible boolean;
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE sp_sw_metadata ADD COLUMN target_visible bit;
|
||||
@@ -17,6 +17,7 @@ import java.io.ByteArrayInputStream;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.validation.ConstraintViolationException;
|
||||
|
||||
@@ -40,6 +41,7 @@ import org.eclipse.hawkbit.repository.model.ActionStatus;
|
||||
import org.eclipse.hawkbit.repository.model.Artifact;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
import org.eclipse.hawkbit.repository.test.matcher.Expect;
|
||||
@@ -432,6 +434,23 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
.as("register target with empty controllerId should fail");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verify that targetVisible metadata is returned from repository")
|
||||
@ExpectEvents({ @Expect(type = DistributionSetCreatedEvent.class, count = 1),
|
||||
@Expect(type = SoftwareModuleCreatedEvent.class, count = 3),
|
||||
@Expect(type = SoftwareModuleUpdatedEvent.class, count = 6) })
|
||||
public void findTargetVisibleMetaDataBySoftwareModuleId() {
|
||||
final DistributionSet set = testdataFactory.createDistributionSet();
|
||||
testdataFactory.addSoftwareModuleMetadata(set);
|
||||
|
||||
final Map<Long, List<SoftwareModuleMetadata>> result = controllerManagement
|
||||
.findTargetVisibleMetaDataBySoftwareModuleId(
|
||||
set.getModules().stream().map(SoftwareModule::getId).collect(Collectors.toList()));
|
||||
|
||||
assertThat(result).hasSize(3);
|
||||
result.entrySet().forEach(entry -> assertThat(entry.getValue()).hasSize(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verify that controller registration does not result in a TargetPollEvent if feature is disabled")
|
||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1),
|
||||
|
||||
@@ -747,19 +747,17 @@ public class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Description("Queries and loads the metadata related to a given software module.")
|
||||
public void findAllDistributionSetMetadataByDsId() {
|
||||
// create a DS
|
||||
DistributionSet ds1 = testdataFactory.createDistributionSet("testDs1");
|
||||
DistributionSet ds2 = testdataFactory.createDistributionSet("testDs2");
|
||||
final DistributionSet ds1 = testdataFactory.createDistributionSet("testDs1");
|
||||
final DistributionSet ds2 = testdataFactory.createDistributionSet("testDs2");
|
||||
|
||||
for (int index = 0; index < 10; index++) {
|
||||
|
||||
ds1 = createDistributionSetMetadata(ds1.getId(),
|
||||
new JpaDistributionSetMetadata("key" + index, ds1, "value" + index)).getDistributionSet();
|
||||
createDistributionSetMetadata(ds1.getId(),
|
||||
new JpaDistributionSetMetadata("key" + index, ds1, "value" + index));
|
||||
}
|
||||
|
||||
for (int index = 0; index < 20; index++) {
|
||||
|
||||
ds2 = createDistributionSetMetadata(ds2.getId(),
|
||||
new JpaDistributionSetMetadata("key" + index, ds2, "value" + index)).getDistributionSet();
|
||||
createDistributionSetMetadata(ds2.getId(),
|
||||
new JpaDistributionSetMetadata("key" + index, ds2, "value" + index));
|
||||
}
|
||||
|
||||
final Page<DistributionSetMetadata> metadataOfDs1 = distributionSetManagement
|
||||
|
||||
@@ -9,17 +9,18 @@
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.RandomUtils;
|
||||
import org.eclipse.hawkbit.repository.builder.SoftwareModuleMetadataCreate;
|
||||
import org.eclipse.hawkbit.repository.event.remote.entity.SoftwareModuleCreatedEvent;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
|
||||
@@ -84,10 +85,14 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
|
||||
.create(entityFactory.softwareModule().create().name("xxx").type(NOT_EXIST_ID)),
|
||||
"SoftwareModuleType");
|
||||
|
||||
verifyThrownExceptionBy(() -> softwareModuleManagement.createMetaData(NOT_EXIST_IDL,
|
||||
entityFactory.generateMetadata("xxx", "xxx")), "SoftwareModule");
|
||||
verifyThrownExceptionBy(() -> softwareModuleManagement.createMetaData(NOT_EXIST_IDL,
|
||||
Arrays.asList(entityFactory.generateMetadata("xxx", "xxx"))), "SoftwareModule");
|
||||
verifyThrownExceptionBy(
|
||||
() -> softwareModuleManagement.createMetaData(
|
||||
entityFactory.softwareModuleMetadata().create(NOT_EXIST_IDL).key("xxx").value("xxx")),
|
||||
"SoftwareModule");
|
||||
verifyThrownExceptionBy(
|
||||
() -> softwareModuleManagement.createMetaData(Arrays
|
||||
.asList(entityFactory.softwareModuleMetadata().create(NOT_EXIST_IDL).key("xxx").value("xxx"))),
|
||||
"SoftwareModule");
|
||||
|
||||
verifyThrownExceptionBy(() -> softwareModuleManagement.delete(NOT_EXIST_IDL), "SoftwareModule");
|
||||
verifyThrownExceptionBy(() -> softwareModuleManagement.delete(Arrays.asList(NOT_EXIST_IDL)), "SoftwareModule");
|
||||
@@ -95,10 +100,14 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
|
||||
verifyThrownExceptionBy(() -> softwareModuleManagement.deleteMetaData(module.getId(), NOT_EXIST_ID),
|
||||
"SoftwareModuleMetadata");
|
||||
|
||||
verifyThrownExceptionBy(() -> softwareModuleManagement.updateMetaData(NOT_EXIST_IDL,
|
||||
entityFactory.generateMetadata("xxx", "xxx")), "SoftwareModule");
|
||||
verifyThrownExceptionBy(() -> softwareModuleManagement.updateMetaData(module.getId(),
|
||||
entityFactory.generateMetadata(NOT_EXIST_ID, "xxx")), "SoftwareModuleMetadata");
|
||||
verifyThrownExceptionBy(
|
||||
() -> softwareModuleManagement.updateMetaData(
|
||||
entityFactory.softwareModuleMetadata().update(NOT_EXIST_IDL, "xxx").value("xxx")),
|
||||
"SoftwareModule");
|
||||
verifyThrownExceptionBy(
|
||||
() -> softwareModuleManagement.updateMetaData(
|
||||
entityFactory.softwareModuleMetadata().update(module.getId(), NOT_EXIST_ID).value("xxx")),
|
||||
"SoftwareModuleMetadata");
|
||||
|
||||
verifyThrownExceptionBy(() -> softwareModuleManagement.findByAssignedTo(PAGE, NOT_EXIST_IDL),
|
||||
"DistributionSet");
|
||||
@@ -624,12 +633,14 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
assertThat(ah.getOptLockRevision()).isEqualTo(1);
|
||||
|
||||
final SoftwareModuleMetadata swMetadata1 = new JpaSoftwareModuleMetadata(knownKey1, ah, knownValue1);
|
||||
final SoftwareModuleMetadataCreate swMetadata1 = entityFactory.softwareModuleMetadata().create(ah.getId())
|
||||
.key(knownKey1).value(knownValue1);
|
||||
|
||||
final SoftwareModuleMetadata swMetadata2 = new JpaSoftwareModuleMetadata(knownKey2, ah, knownValue2);
|
||||
final SoftwareModuleMetadataCreate swMetadata2 = entityFactory.softwareModuleMetadata().create(ah.getId())
|
||||
.key(knownKey2).value(knownValue2);
|
||||
|
||||
final List<SoftwareModuleMetadata> softwareModuleMetadata = softwareModuleManagement.createMetaData(ah.getId(),
|
||||
Arrays.asList(swMetadata1, swMetadata2));
|
||||
final List<SoftwareModuleMetadata> softwareModuleMetadata = softwareModuleManagement
|
||||
.createMetaData(Arrays.asList(swMetadata1, swMetadata2));
|
||||
|
||||
final SoftwareModule changedLockRevisionModule = softwareModuleManagement.get(ah.getId()).get();
|
||||
assertThat(changedLockRevisionModule.getOptLockRevision()).isEqualTo(2);
|
||||
@@ -638,7 +649,7 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(softwareModuleMetadata.get(0)).isNotNull();
|
||||
assertThat(softwareModuleMetadata.get(0).getValue()).isEqualTo(knownValue1);
|
||||
assertThat(((JpaSoftwareModuleMetadata) softwareModuleMetadata.get(0)).getId().getKey()).isEqualTo(knownKey1);
|
||||
assertThat(softwareModuleMetadata.get(0).getSoftwareModule().getId()).isEqualTo(ah.getId());
|
||||
assertThat(softwareModuleMetadata.get(0).getEntityId()).isEqualTo(ah.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -651,14 +662,23 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
final SoftwareModule ah = testdataFactory.createSoftwareModuleApp();
|
||||
|
||||
softwareModuleManagement.createMetaData(ah.getId(), entityFactory.generateMetadata(knownKey1, knownValue1));
|
||||
softwareModuleManagement.createMetaData(entityFactory.softwareModuleMetadata().create(ah.getId()).key(knownKey1)
|
||||
.value(knownValue1).targetVisible(true));
|
||||
|
||||
try {
|
||||
softwareModuleManagement.createMetaData(ah.getId(), entityFactory.generateMetadata(knownKey1, knownValue2));
|
||||
fail("should not have worked as module metadata already exists");
|
||||
} catch (final EntityAlreadyExistsException e) {
|
||||
assertThatExceptionOfType(EntityAlreadyExistsException.class)
|
||||
.isThrownBy(() -> softwareModuleManagement.createMetaData(entityFactory.softwareModuleMetadata()
|
||||
.create(ah.getId()).key(knownKey1).value(knownValue1).targetVisible(true)))
|
||||
.withMessageContaining("Metadata").withMessageContaining(knownKey1);
|
||||
|
||||
}
|
||||
final String knownKey2 = "myKnownKey2";
|
||||
|
||||
softwareModuleManagement.createMetaData(entityFactory.softwareModuleMetadata().create(ah.getId()).key(knownKey2)
|
||||
.value(knownValue1).targetVisible(false));
|
||||
|
||||
assertThatExceptionOfType(EntityAlreadyExistsException.class)
|
||||
.isThrownBy(() -> softwareModuleManagement.createMetaData(entityFactory.softwareModuleMetadata()
|
||||
.create(ah.getId()).key(knownKey2).value(knownValue1).targetVisible(true)))
|
||||
.withMessageContaining("Metadata").withMessageContaining(knownKey2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -675,9 +695,11 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(ah.getOptLockRevision()).isEqualTo(1);
|
||||
|
||||
// create an software module meta data entry
|
||||
final List<SoftwareModuleMetadata> softwareModuleMetadata = softwareModuleManagement.createMetaData(ah.getId(),
|
||||
Collections.singleton(entityFactory.generateMetadata(knownKey, knownValue)));
|
||||
assertThat(softwareModuleMetadata).hasSize(1);
|
||||
final SoftwareModuleMetadata softwareModuleMetadata = softwareModuleManagement.createMetaData(
|
||||
entityFactory.softwareModuleMetadata().create(ah.getId()).key(knownKey).value(knownValue));
|
||||
assertThat(softwareModuleMetadata.isTargetVisible()).isFalse();
|
||||
assertThat(softwareModuleMetadata.getValue()).isEqualTo(knownValue);
|
||||
|
||||
// base software module should have now the opt lock revision one
|
||||
// because we are modifying the
|
||||
// base software module
|
||||
@@ -686,8 +708,8 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
// update the software module metadata
|
||||
Thread.sleep(100);
|
||||
final SoftwareModuleMetadata updated = softwareModuleManagement.updateMetaData(ah.getId(),
|
||||
entityFactory.generateMetadata(knownKey, knownUpdateValue));
|
||||
final SoftwareModuleMetadata updated = softwareModuleManagement.updateMetaData(entityFactory
|
||||
.softwareModuleMetadata().update(ah.getId(), knownKey).value(knownUpdateValue).targetVisible(true));
|
||||
// we are updating the sw meta data so also modiying the base software
|
||||
// module so opt lock
|
||||
// revision must be two
|
||||
@@ -697,8 +719,9 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
|
||||
// verify updated meta data contains the updated value
|
||||
assertThat(updated).isNotNull();
|
||||
assertThat(updated.getValue()).isEqualTo(knownUpdateValue);
|
||||
assertThat(updated.isTargetVisible()).isTrue();
|
||||
assertThat(((JpaSoftwareModuleMetadata) updated).getId().getKey()).isEqualTo(knownKey);
|
||||
assertThat(updated.getSoftwareModule().getId()).isEqualTo(ah.getId());
|
||||
assertThat(updated.getEntityId()).isEqualTo(ah.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -709,8 +732,10 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
SoftwareModule ah = testdataFactory.createSoftwareModuleApp();
|
||||
|
||||
ah = softwareModuleManagement.createMetaData(ah.getId(), entityFactory.generateMetadata(knownKey1, knownValue1))
|
||||
.getSoftwareModule();
|
||||
softwareModuleManagement.createMetaData(
|
||||
entityFactory.softwareModuleMetadata().create(ah.getId()).key(knownKey1).value(knownValue1));
|
||||
|
||||
ah = softwareModuleManagement.get(ah.getId()).get();
|
||||
|
||||
assertThat(softwareModuleManagement.findMetaDataBySoftwareModuleId(new PageRequest(0, 10), ah.getId())
|
||||
.getContent()).as("Contains the created metadata element")
|
||||
@@ -727,10 +752,10 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
|
||||
final String knownKey1 = "myKnownKey1";
|
||||
final String knownValue1 = "myKnownValue1";
|
||||
|
||||
SoftwareModule ah = testdataFactory.createSoftwareModuleApp();
|
||||
final SoftwareModule ah = testdataFactory.createSoftwareModuleApp();
|
||||
|
||||
ah = softwareModuleManagement.createMetaData(ah.getId(), entityFactory.generateMetadata(knownKey1, knownValue1))
|
||||
.getSoftwareModule();
|
||||
softwareModuleManagement.createMetaData(
|
||||
entityFactory.softwareModuleMetadata().create(ah.getId()).key(knownKey1).value(knownValue1));
|
||||
|
||||
assertThat(softwareModuleManagement.getMetaDataBySoftwareModuleId(ah.getId(), "doesnotexist")).isNotPresent();
|
||||
}
|
||||
@@ -739,26 +764,24 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Description("Queries and loads the metadata related to a given software module.")
|
||||
public void findAllSoftwareModuleMetadataBySwId() {
|
||||
|
||||
SoftwareModule sw1 = testdataFactory.createSoftwareModuleApp();
|
||||
final SoftwareModule sw1 = testdataFactory.createSoftwareModuleApp();
|
||||
|
||||
SoftwareModule sw2 = testdataFactory.createSoftwareModuleOs();
|
||||
final SoftwareModule sw2 = testdataFactory.createSoftwareModuleOs();
|
||||
|
||||
for (int index = 0; index < 10; index++) {
|
||||
sw1 = softwareModuleManagement
|
||||
.createMetaData(sw1.getId(), entityFactory.generateMetadata("key" + index, "value" + index))
|
||||
.getSoftwareModule();
|
||||
softwareModuleManagement.createMetaData(entityFactory.softwareModuleMetadata().create(sw1.getId())
|
||||
.key("key" + index).value("value" + index).targetVisible(true));
|
||||
}
|
||||
|
||||
for (int index = 0; index < 20; index++) {
|
||||
sw2 = softwareModuleManagement
|
||||
.createMetaData(sw2.getId(), new JpaSoftwareModuleMetadata("key" + index, sw2, "value" + index))
|
||||
.getSoftwareModule();
|
||||
softwareModuleManagement.createMetaData(entityFactory.softwareModuleMetadata().create(sw2.getId())
|
||||
.key("key" + index).value("value" + index).targetVisible(false));
|
||||
}
|
||||
|
||||
final Page<SoftwareModuleMetadata> metadataOfSw1 = softwareModuleManagement
|
||||
Page<SoftwareModuleMetadata> metadataOfSw1 = softwareModuleManagement
|
||||
.findMetaDataBySoftwareModuleId(new PageRequest(0, 100), sw1.getId());
|
||||
|
||||
final Page<SoftwareModuleMetadata> metadataOfSw2 = softwareModuleManagement
|
||||
Page<SoftwareModuleMetadata> metadataOfSw2 = softwareModuleManagement
|
||||
.findMetaDataBySoftwareModuleId(new PageRequest(0, 100), sw2.getId());
|
||||
|
||||
assertThat(metadataOfSw1.getNumberOfElements()).isEqualTo(10);
|
||||
@@ -766,5 +789,17 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
assertThat(metadataOfSw2.getNumberOfElements()).isEqualTo(20);
|
||||
assertThat(metadataOfSw2.getTotalElements()).isEqualTo(20);
|
||||
|
||||
metadataOfSw1 = softwareModuleManagement.findMetaDataBySoftwareModuleIdAndTargetVisible(new PageRequest(0, 100),
|
||||
sw1.getId());
|
||||
|
||||
metadataOfSw2 = softwareModuleManagement.findMetaDataBySoftwareModuleIdAndTargetVisible(new PageRequest(0, 100),
|
||||
sw2.getId());
|
||||
|
||||
assertThat(metadataOfSw1.getNumberOfElements()).isEqualTo(10);
|
||||
assertThat(metadataOfSw1.getTotalElements()).isEqualTo(10);
|
||||
|
||||
assertThat(metadataOfSw2.getNumberOfElements()).isEqualTo(0);
|
||||
assertThat(metadataOfSw2.getTotalElements()).isEqualTo(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,9 +11,9 @@ package org.eclipse.hawkbit.repository.jpa.rsql;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.eclipse.hawkbit.repository.SoftwareModuleFields;
|
||||
import org.eclipse.hawkbit.repository.builder.SoftwareModuleMetadataCreate;
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.MetaData;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.test.util.TestdataFactory;
|
||||
import org.junit.Before;
|
||||
@@ -31,21 +31,23 @@ public class RSQLSoftwareModuleFieldTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
@Before
|
||||
public void setupBeforeTest() {
|
||||
final SoftwareModule ah = softwareModuleManagement.create(entityFactory.softwareModule().create()
|
||||
.type(appType).name("agent-hub").version("1.0.1").description("agent-hub"));
|
||||
softwareModuleManagement.create(entityFactory.softwareModule().create().type(runtimeType)
|
||||
.name("oracle-jre").version("1.7.2").description("aa"));
|
||||
final SoftwareModule ah = softwareModuleManagement.create(entityFactory.softwareModule().create().type(appType)
|
||||
.name("agent-hub").version("1.0.1").description("agent-hub"));
|
||||
softwareModuleManagement.create(entityFactory.softwareModule().create().type(runtimeType).name("oracle-jre")
|
||||
.version("1.7.2").description("aa"));
|
||||
softwareModuleManagement.create(
|
||||
entityFactory.softwareModule().create().type(osType).name("poky").version("3.0.2").description("aa"));
|
||||
|
||||
final JpaSoftwareModule ah2 = (JpaSoftwareModule) softwareModuleManagement.create(entityFactory
|
||||
.softwareModule().create().type(appType).name("agent-hub2").version("1.0.1").description("agent-hub2"));
|
||||
final JpaSoftwareModule ah2 = (JpaSoftwareModule) softwareModuleManagement.create(entityFactory.softwareModule()
|
||||
.create().type(appType).name("agent-hub2").version("1.0.1").description("agent-hub2"));
|
||||
|
||||
final MetaData softwareModuleMetadata = entityFactory.generateMetadata("metaKey", "metaValue");
|
||||
softwareModuleManagement.createMetaData(ah.getId(), softwareModuleMetadata);
|
||||
final SoftwareModuleMetadataCreate softwareModuleMetadata = entityFactory.softwareModuleMetadata()
|
||||
.create(ah.getId()).key("metaKey").value("metaValue");
|
||||
softwareModuleManagement.createMetaData(softwareModuleMetadata);
|
||||
|
||||
final MetaData softwareModuleMetadata2 = entityFactory.generateMetadata("metaKey", "value");
|
||||
softwareModuleManagement.createMetaData(ah2.getId(), softwareModuleMetadata2);
|
||||
final SoftwareModuleMetadataCreate softwareModuleMetadata2 = entityFactory.softwareModuleMetadata()
|
||||
.create(ah2.getId()).key("metaKey").value("value");
|
||||
softwareModuleManagement.createMetaData(softwareModuleMetadata2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -105,8 +107,7 @@ public class RSQLSoftwareModuleFieldTest extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
|
||||
private void assertRSQLQuery(final String rsqlParam, final long excpectedEntity) {
|
||||
final Page<SoftwareModule> find = softwareModuleManagement.findByRsql(new PageRequest(0, 100),
|
||||
rsqlParam);
|
||||
final Page<SoftwareModule> find = softwareModuleManagement.findByRsql(new PageRequest(0, 100), rsqlParam);
|
||||
final long countAll = find.getTotalElements();
|
||||
assertThat(find).isNotNull();
|
||||
assertThat(countAll).isEqualTo(excpectedEntity);
|
||||
|
||||
@@ -10,12 +10,11 @@ package org.eclipse.hawkbit.repository.jpa.rsql;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.hawkbit.repository.SoftwareModuleMetadataFields;
|
||||
import org.eclipse.hawkbit.repository.builder.SoftwareModuleMetadataCreate;
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.model.MetaData;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata;
|
||||
import org.eclipse.hawkbit.repository.test.util.TestdataFactory;
|
||||
@@ -24,6 +23,8 @@ import org.junit.Test;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import ru.yandex.qatools.allure.annotations.Description;
|
||||
import ru.yandex.qatools.allure.annotations.Features;
|
||||
import ru.yandex.qatools.allure.annotations.Stories;
|
||||
@@ -40,12 +41,16 @@ public class RSQLSoftwareModuleMetadataFieldsTest extends AbstractJpaIntegration
|
||||
|
||||
softwareModuleId = softwareModule.getId();
|
||||
|
||||
final List<MetaData> metadata = new ArrayList<>(5);
|
||||
final List<SoftwareModuleMetadataCreate> metadata = Lists.newArrayListWithExpectedSize(5);
|
||||
for (int i = 0; i < 5; i++) {
|
||||
metadata.add(entityFactory.generateMetadata("" + i, "" + i));
|
||||
metadata.add(
|
||||
entityFactory.softwareModuleMetadata().create(softwareModule.getId()).key("" + i).value("" + i));
|
||||
}
|
||||
|
||||
softwareModuleManagement.createMetaData(softwareModule.getId(), metadata);
|
||||
metadata.add(entityFactory.softwareModuleMetadata().create(softwareModule.getId()).key("targetVisible")
|
||||
.value("targetVisible").targetVisible(true));
|
||||
|
||||
softwareModuleManagement.createMetaData(metadata);
|
||||
|
||||
}
|
||||
|
||||
@@ -53,18 +58,27 @@ public class RSQLSoftwareModuleMetadataFieldsTest extends AbstractJpaIntegration
|
||||
@Description("Test filter software module metadata by key")
|
||||
public void testFilterByParameterKey() {
|
||||
assertRSQLQuery(SoftwareModuleMetadataFields.KEY.name() + "==1", 1);
|
||||
assertRSQLQuery(SoftwareModuleMetadataFields.KEY.name() + "!=1", 4);
|
||||
assertRSQLQuery(SoftwareModuleMetadataFields.KEY.name() + "!=1", 5);
|
||||
assertRSQLQuery(SoftwareModuleMetadataFields.KEY.name() + "=in=(1,2)", 2);
|
||||
assertRSQLQuery(SoftwareModuleMetadataFields.KEY.name() + "=out=(1,2)", 3);
|
||||
assertRSQLQuery(SoftwareModuleMetadataFields.KEY.name() + "=out=(1,2)", 4);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test fitler software module metadata status by value")
|
||||
@Description("Test fitler software module metadata by value")
|
||||
public void testFilterByParameterValue() {
|
||||
assertRSQLQuery(SoftwareModuleMetadataFields.VALUE.name() + "==1", 1);
|
||||
assertRSQLQuery(SoftwareModuleMetadataFields.VALUE.name() + "!=1", 4);
|
||||
assertRSQLQuery(SoftwareModuleMetadataFields.VALUE.name() + "!=1", 5);
|
||||
assertRSQLQuery(SoftwareModuleMetadataFields.VALUE.name() + "=in=(1,2)", 2);
|
||||
assertRSQLQuery(SoftwareModuleMetadataFields.VALUE.name() + "=out=(1,2)", 3);
|
||||
assertRSQLQuery(SoftwareModuleMetadataFields.VALUE.name() + "=out=(1,2)", 4);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Test fitler software module metadata by target visible")
|
||||
public void testFilterByParameterTargetVisible() {
|
||||
assertRSQLQuery(SoftwareModuleMetadataFields.TARGETVISIBLE.name() + "==true", 1);
|
||||
assertRSQLQuery(SoftwareModuleMetadataFields.TARGETVISIBLE.name() + "==false", 5);
|
||||
assertRSQLQuery(SoftwareModuleMetadataFields.TARGETVISIBLE.name() + "!=false", 1);
|
||||
assertRSQLQuery(SoftwareModuleMetadataFields.TARGETVISIBLE.name() + "!=true", 5);
|
||||
}
|
||||
|
||||
private void assertRSQLQuery(final String rsqlParam, final long expectedEntities) {
|
||||
|
||||
Reference in New Issue
Block a user