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;
|
||||
Reference in New Issue
Block a user