Removed external artifact from repository.
Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
@@ -1,23 +0,0 @@
|
||||
/**
|
||||
* 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;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaExternalArtifactProvider;
|
||||
import org.eclipse.hawkbit.repository.model.ExternalArtifactProvider;
|
||||
import org.springframework.transaction.annotation.Isolation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* Repository for {@link ExternalArtifactProvider}.
|
||||
*
|
||||
*/
|
||||
@Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED)
|
||||
public interface ExternalArtifactProviderRepository extends BaseEntityRepository<JpaExternalArtifactProvider, Long> {
|
||||
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
/**
|
||||
* 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;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaExternalArtifact;
|
||||
import org.eclipse.hawkbit.repository.model.ExternalArtifact;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.transaction.annotation.Isolation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* {@link ExternalArtifact} repository.
|
||||
*
|
||||
*/
|
||||
@Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED)
|
||||
public interface ExternalArtifactRepository extends BaseEntityRepository<JpaExternalArtifact, Long> {
|
||||
|
||||
/**
|
||||
* Searches for external artifact for a base software module.
|
||||
*
|
||||
* @param pageReq
|
||||
* Pageable
|
||||
* @param swId
|
||||
* software module id
|
||||
*
|
||||
* @return Page<ExternalArtifact>
|
||||
*/
|
||||
Page<JpaExternalArtifact> findBySoftwareModuleId(Pageable pageReq, final Long swId);
|
||||
|
||||
}
|
||||
@@ -24,21 +24,15 @@ import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.exception.GridFSDBFileNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.exception.InvalidMD5HashException;
|
||||
import org.eclipse.hawkbit.repository.exception.InvalidSHA1HashException;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaExternalArtifact;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaExternalArtifactProvider;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaLocalArtifact;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaArtifact;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.jpa.specifications.SoftwareModuleSpecification;
|
||||
import org.eclipse.hawkbit.repository.model.ExternalArtifact;
|
||||
import org.eclipse.hawkbit.repository.model.ExternalArtifactProvider;
|
||||
import org.eclipse.hawkbit.repository.model.LocalArtifact;
|
||||
import org.eclipse.hawkbit.repository.model.Artifact;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.transaction.annotation.Isolation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -57,24 +51,18 @@ public class JpaArtifactManagement implements ArtifactManagement {
|
||||
@Autowired
|
||||
private LocalArtifactRepository localArtifactRepository;
|
||||
|
||||
@Autowired
|
||||
private ExternalArtifactRepository externalArtifactRepository;
|
||||
|
||||
@Autowired
|
||||
private SoftwareModuleRepository softwareModuleRepository;
|
||||
|
||||
@Autowired
|
||||
private ExternalArtifactProviderRepository externalArtifactProviderRepository;
|
||||
|
||||
@Autowired
|
||||
private ArtifactRepository artifactRepository;
|
||||
|
||||
private static LocalArtifact checkForExistingArtifact(final String filename, final boolean overrideExisting,
|
||||
private static Artifact checkForExistingArtifact(final String filename, final boolean overrideExisting,
|
||||
final SoftwareModule softwareModule) {
|
||||
if (softwareModule.getLocalArtifactByFilename(filename).isPresent()) {
|
||||
if (softwareModule.getArtifactByFilename(filename).isPresent()) {
|
||||
if (overrideExisting) {
|
||||
LOG.debug("overriding existing artifact with new filename {}", filename);
|
||||
return softwareModule.getLocalArtifactByFilename(filename).get();
|
||||
return softwareModule.getArtifactByFilename(filename).get();
|
||||
} else {
|
||||
throw new EntityAlreadyExistsException("File with that name already exists in the Software Module");
|
||||
}
|
||||
@@ -85,33 +73,14 @@ public class JpaArtifactManagement implements ArtifactManagement {
|
||||
@Override
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public ExternalArtifact createExternalArtifact(final ExternalArtifactProvider externalRepository,
|
||||
final String urlSuffix, final Long moduleId) {
|
||||
|
||||
final SoftwareModule module = getModuleAndThrowExceptionIfThatFails(moduleId);
|
||||
return externalArtifactRepository.save(new JpaExternalArtifact(externalRepository, urlSuffix, module));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public ExternalArtifactProvider createExternalArtifactProvider(final String name, final String description,
|
||||
final String basePath, final String defaultUrlSuffix) {
|
||||
return externalArtifactProviderRepository
|
||||
.save(new JpaExternalArtifactProvider(name, description, basePath, defaultUrlSuffix));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public LocalArtifact createLocalArtifact(final InputStream stream, final Long moduleId, final String filename,
|
||||
public Artifact createArtifact(final InputStream stream, final Long moduleId, final String filename,
|
||||
final String providedMd5Sum, final String providedSha1Sum, final boolean overrideExisting,
|
||||
final String contentType) {
|
||||
DbArtifact result = null;
|
||||
|
||||
final SoftwareModule softwareModule = getModuleAndThrowExceptionIfThatFails(moduleId);
|
||||
|
||||
final LocalArtifact existing = checkForExistingArtifact(filename, overrideExisting, softwareModule);
|
||||
final Artifact existing = checkForExistingArtifact(filename, overrideExisting, softwareModule);
|
||||
|
||||
try {
|
||||
result = artifactRepository.store(stream, filename, contentType,
|
||||
@@ -135,25 +104,10 @@ public class JpaArtifactManagement implements ArtifactManagement {
|
||||
@Override
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public void deleteExternalArtifact(final Long id) {
|
||||
final ExternalArtifact existing = externalArtifactRepository.findOne(id);
|
||||
public boolean clearArtifactBinary(final Artifact existing) {
|
||||
|
||||
if (null == existing) {
|
||||
return;
|
||||
}
|
||||
|
||||
existing.getSoftwareModule().removeArtifact(existing);
|
||||
softwareModuleRepository.save((JpaSoftwareModule) existing.getSoftwareModule());
|
||||
externalArtifactRepository.delete(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public boolean clearLocalArtifactBinary(final LocalArtifact existing) {
|
||||
|
||||
for (final LocalArtifact lArtifact : localArtifactRepository
|
||||
.findByGridFsFileName(((JpaLocalArtifact) existing).getGridFsFileName())) {
|
||||
for (final Artifact lArtifact : localArtifactRepository
|
||||
.findByGridFsFileName(((JpaArtifact) existing).getGridFsFileName())) {
|
||||
if (!lArtifact.getSoftwareModule().isDeleted()
|
||||
&& Long.compare(lArtifact.getSoftwareModule().getId(), existing.getSoftwareModule().getId()) != 0) {
|
||||
return false;
|
||||
@@ -161,8 +115,8 @@ public class JpaArtifactManagement implements ArtifactManagement {
|
||||
}
|
||||
|
||||
try {
|
||||
LOG.debug("deleting artifact from repository {}", ((JpaLocalArtifact) existing).getGridFsFileName());
|
||||
artifactRepository.deleteBySha1(((JpaLocalArtifact) existing).getGridFsFileName());
|
||||
LOG.debug("deleting artifact from repository {}", ((JpaArtifact) existing).getGridFsFileName());
|
||||
artifactRepository.deleteBySha1(((JpaArtifact) existing).getGridFsFileName());
|
||||
return true;
|
||||
} catch (final ArtifactStoreException e) {
|
||||
throw new ArtifactDeleteFailedException(e);
|
||||
@@ -172,14 +126,14 @@ public class JpaArtifactManagement implements ArtifactManagement {
|
||||
@Override
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public void deleteLocalArtifact(final Long id) {
|
||||
final JpaLocalArtifact existing = localArtifactRepository.findOne(id);
|
||||
public void deleteArtifact(final Long id) {
|
||||
final JpaArtifact existing = localArtifactRepository.findOne(id);
|
||||
|
||||
if (null == existing) {
|
||||
return;
|
||||
}
|
||||
|
||||
clearLocalArtifactBinary(existing);
|
||||
clearArtifactBinary(existing);
|
||||
|
||||
existing.getSoftwareModule().removeArtifact(existing);
|
||||
softwareModuleRepository.save((JpaSoftwareModule) existing.getSoftwareModule());
|
||||
@@ -187,74 +141,45 @@ public class JpaArtifactManagement implements ArtifactManagement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalArtifact findLocalArtifact(final Long id) {
|
||||
public Artifact findArtifact(final Long id) {
|
||||
return localArtifactRepository.findOne(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LocalArtifact> findByFilenameAndSoftwareModule(final String filename, final Long softwareModuleId) {
|
||||
public List<Artifact> findByFilenameAndSoftwareModule(final String filename, final Long softwareModuleId) {
|
||||
return localArtifactRepository.findByFilenameAndSoftwareModuleId(filename, softwareModuleId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalArtifact findFirstLocalArtifactsBySHA1(final String sha1) {
|
||||
public Artifact findFirstArtifactBySHA1(final String sha1) {
|
||||
return localArtifactRepository.findFirstByGridFsFileName(sha1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LocalArtifact> findLocalArtifactByFilename(final String filename) {
|
||||
public List<Artifact> findArtifactByFilename(final String filename) {
|
||||
return localArtifactRepository.findByFilename(filename);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<LocalArtifact> findLocalArtifactBySoftwareModule(final Pageable pageReq, final Long swId) {
|
||||
public Page<Artifact> findArtifactBySoftwareModule(final Pageable pageReq, final Long swId) {
|
||||
return localArtifactRepository.findBySoftwareModuleId(pageReq, swId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SoftwareModule findSoftwareModuleById(final Long id) {
|
||||
|
||||
final Specification<JpaSoftwareModule> spec = SoftwareModuleSpecification.byId(id);
|
||||
|
||||
return softwareModuleRepository.findOne(spec);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SoftwareModule findSoftwareModuleWithDetails(final Long id) {
|
||||
final SoftwareModule result = findSoftwareModuleById(id);
|
||||
if (result != null) {
|
||||
result.getArtifacts().size();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private SoftwareModule getModuleAndThrowExceptionIfThatFails(final Long moduleId) {
|
||||
final SoftwareModule softwareModule = findSoftwareModuleWithDetails(moduleId);
|
||||
|
||||
if (softwareModule == null) {
|
||||
LOG.debug("no software module with ID {} exists", moduleId);
|
||||
throw new EntityNotFoundException("Software Module: " + moduleId);
|
||||
}
|
||||
return softwareModule;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DbArtifact loadLocalArtifactBinary(final LocalArtifact artifact) {
|
||||
final DbArtifact result = artifactRepository
|
||||
.getArtifactBySha1(((JpaLocalArtifact) artifact).getGridFsFileName());
|
||||
public DbArtifact loadArtifactBinary(final Artifact artifact) {
|
||||
final DbArtifact result = artifactRepository.getArtifactBySha1(((JpaArtifact) artifact).getGridFsFileName());
|
||||
if (result == null) {
|
||||
throw new GridFSDBFileNotFoundException(((JpaLocalArtifact) artifact).getGridFsFileName());
|
||||
throw new GridFSDBFileNotFoundException(((JpaArtifact) artifact).getGridFsFileName());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private LocalArtifact storeArtifactMetadata(final SoftwareModule softwareModule, final String providedFilename,
|
||||
final DbArtifact result, final LocalArtifact existing) {
|
||||
JpaLocalArtifact artifact = (JpaLocalArtifact) existing;
|
||||
private Artifact storeArtifactMetadata(final SoftwareModule softwareModule, final String providedFilename,
|
||||
final DbArtifact result, final Artifact existing) {
|
||||
JpaArtifact artifact = (JpaArtifact) existing;
|
||||
if (existing == null) {
|
||||
artifact = new JpaLocalArtifact(result.getHashes().getSha1(), providedFilename, softwareModule);
|
||||
artifact = new JpaArtifact(result.getHashes().getSha1(), providedFilename, softwareModule);
|
||||
}
|
||||
artifact.setMd5Hash(result.getHashes().getMd5());
|
||||
artifact.setSha1Hash(result.getHashes().getSha1());
|
||||
@@ -267,26 +192,32 @@ public class JpaArtifactManagement implements ArtifactManagement {
|
||||
@Override
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public LocalArtifact createLocalArtifact(final InputStream inputStream, final Long moduleId, final String filename,
|
||||
public Artifact createArtifact(final InputStream inputStream, final Long moduleId, final String filename,
|
||||
final boolean overrideExisting) {
|
||||
return createLocalArtifact(inputStream, moduleId, filename, null, null, overrideExisting, null);
|
||||
return createArtifact(inputStream, moduleId, filename, null, null, overrideExisting, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public LocalArtifact createLocalArtifact(final InputStream inputStream, final Long moduleId, final String filename,
|
||||
public Artifact createArtifact(final InputStream inputStream, final Long moduleId, final String filename,
|
||||
final boolean overrideExisting, final String contentType) {
|
||||
return createLocalArtifact(inputStream, moduleId, filename, null, null, overrideExisting, contentType);
|
||||
return createArtifact(inputStream, moduleId, filename, null, null, overrideExisting, contentType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long countLocalArtifactsAll() {
|
||||
public Long countArtifactsAll() {
|
||||
return localArtifactRepository.count();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long countExternalArtifactsAll() {
|
||||
return externalArtifactRepository.count();
|
||||
private SoftwareModule getModuleAndThrowExceptionIfThatFails(final Long moduleId) {
|
||||
final SoftwareModule softwareModule = softwareModuleRepository.findOne(moduleId);
|
||||
|
||||
if (softwareModule == null) {
|
||||
LOG.debug("no software module with ID {} exists", moduleId);
|
||||
throw new EntityNotFoundException("Software Module: " + moduleId);
|
||||
}
|
||||
return softwareModule;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -41,8 +41,8 @@ import org.eclipse.hawkbit.repository.jpa.specifications.ActionSpecifications;
|
||||
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.Artifact;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.LocalArtifact;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetInfo;
|
||||
@@ -150,7 +150,7 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTargetArtifactAssigned(final String controllerId, final LocalArtifact localArtifact) {
|
||||
public boolean hasTargetArtifactAssigned(final String controllerId, final Artifact localArtifact) {
|
||||
final Target target = targetRepository.findByControllerId(controllerId);
|
||||
if (target == null) {
|
||||
return false;
|
||||
@@ -159,7 +159,7 @@ public class JpaControllerManagement implements ControllerManagement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTargetArtifactAssigned(final Long targetId, final LocalArtifact localArtifact) {
|
||||
public boolean hasTargetArtifactAssigned(final Long targetId, final Artifact localArtifact) {
|
||||
final Target target = targetRepository.findOne(targetId);
|
||||
if (target == null) {
|
||||
return false;
|
||||
|
||||
@@ -14,11 +14,11 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaArtifact;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetMetadata;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetTag;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaLocalArtifact;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaRollout;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
|
||||
@@ -30,11 +30,11 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag;
|
||||
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.Artifact;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetMetadata;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.model.LocalArtifact;
|
||||
import org.eclipse.hawkbit.repository.model.Rollout;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroup;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
@@ -135,12 +135,13 @@ public class JpaEntityFactory implements EntityFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TargetFilterQuery generateTargetFilterQuery(String name, String query) {
|
||||
public TargetFilterQuery generateTargetFilterQuery(final String name, final String query) {
|
||||
return new JpaTargetFilterQuery(name, query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TargetFilterQuery generateTargetFilterQuery(String name, String query, DistributionSet autoAssignDS) {
|
||||
public TargetFilterQuery generateTargetFilterQuery(final String name, final String query,
|
||||
final DistributionSet autoAssignDS) {
|
||||
return new JpaTargetFilterQuery(name, query, (JpaDistributionSet) autoAssignDS);
|
||||
}
|
||||
|
||||
@@ -220,8 +221,8 @@ public class JpaEntityFactory implements EntityFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalArtifact generateLocalArtifact() {
|
||||
return new JpaLocalArtifact();
|
||||
public Artifact generateArtifact() {
|
||||
return new JpaArtifact();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -45,15 +45,15 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.SwMetadataCompositeKey;
|
||||
import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility;
|
||||
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
|
||||
import org.eclipse.hawkbit.repository.jpa.specifications.SoftwareModuleSpecification;
|
||||
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.LocalArtifact;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
||||
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.AuditorAware;
|
||||
import org.springframework.data.domain.Page;
|
||||
@@ -178,11 +178,11 @@ public class JpaSoftwareManagement implements SoftwareManagement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Slice<SoftwareModule> findSoftwareModulesByType(final Pageable pageable, final SoftwareModuleType type) {
|
||||
public Slice<SoftwareModule> findSoftwareModulesByType(final Pageable pageable, final Long typeId) {
|
||||
|
||||
final List<Specification<JpaSoftwareModule>> specList = new LinkedList<>();
|
||||
|
||||
Specification<JpaSoftwareModule> spec = SoftwareModuleSpecification.equalType((JpaSoftwareModuleType) type);
|
||||
Specification<JpaSoftwareModule> spec = SoftwareModuleSpecification.equalType(typeId);
|
||||
specList.add(spec);
|
||||
|
||||
spec = SoftwareModuleSpecification.isDeletedFalse();
|
||||
@@ -205,23 +205,11 @@ public class JpaSoftwareManagement implements SoftwareManagement {
|
||||
return new PageImpl<>(Collections.unmodifiableList(findAll.getContent()), pageable, findAll.getTotalElements());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long countSoftwareModulesByType(final SoftwareModuleType type) {
|
||||
|
||||
final List<Specification<JpaSoftwareModule>> specList = new ArrayList<>(2);
|
||||
|
||||
Specification<JpaSoftwareModule> spec = SoftwareModuleSpecification.equalType((JpaSoftwareModuleType) type);
|
||||
specList.add(spec);
|
||||
|
||||
spec = SoftwareModuleSpecification.isDeletedFalse();
|
||||
specList.add(spec);
|
||||
|
||||
return countSwModuleByCriteriaAPI(specList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SoftwareModule findSoftwareModuleById(final Long id) {
|
||||
return artifactManagement.findSoftwareModuleById(id);
|
||||
final Specification<JpaSoftwareModule> spec = SoftwareModuleSpecification.byId(id);
|
||||
|
||||
return softwareModuleRepository.findOne(spec);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -246,8 +234,8 @@ public class JpaSoftwareManagement implements SoftwareManagement {
|
||||
}
|
||||
|
||||
private void deleteGridFsArtifacts(final JpaSoftwareModule swModule) {
|
||||
for (final LocalArtifact localArtifact : swModule.getLocalArtifacts()) {
|
||||
artifactManagement.clearLocalArtifactBinary(localArtifact);
|
||||
for (final Artifact localArtifact : swModule.getArtifacts()) {
|
||||
artifactManagement.clearArtifactBinary(localArtifact);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -311,7 +299,12 @@ public class JpaSoftwareManagement implements SoftwareManagement {
|
||||
|
||||
@Override
|
||||
public SoftwareModule findSoftwareModuleWithDetails(final Long id) {
|
||||
return artifactManagement.findSoftwareModuleWithDetails(id);
|
||||
final SoftwareModule result = findSoftwareModuleById(id);
|
||||
if (result != null) {
|
||||
result.getArtifacts().size();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -344,7 +337,7 @@ public class JpaSoftwareManagement implements SoftwareManagement {
|
||||
|
||||
@Override
|
||||
public Slice<SoftwareModule> findSoftwareModuleByFilters(final Pageable pageable, final String searchText,
|
||||
final SoftwareModuleType type) {
|
||||
final Long typeId) {
|
||||
|
||||
final List<Specification<JpaSoftwareModule>> specList = new ArrayList<>(4);
|
||||
|
||||
@@ -356,8 +349,8 @@ public class JpaSoftwareManagement implements SoftwareManagement {
|
||||
specList.add(spec);
|
||||
}
|
||||
|
||||
if (null != type) {
|
||||
spec = SoftwareModuleSpecification.equalType((JpaSoftwareModuleType) type);
|
||||
if (null != typeId) {
|
||||
spec = SoftwareModuleSpecification.equalType(typeId);
|
||||
specList.add(spec);
|
||||
}
|
||||
|
||||
@@ -375,9 +368,7 @@ public class JpaSoftwareManagement implements SoftwareManagement {
|
||||
|
||||
@Override
|
||||
public Slice<AssignedSoftwareModule> findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(
|
||||
final Pageable pageable, final Long orderByDistributionId, final String searchText,
|
||||
final SoftwareModuleType ty) {
|
||||
final JpaSoftwareModuleType type = (JpaSoftwareModuleType) ty;
|
||||
final Pageable pageable, final Long orderByDistributionId, final String searchText, final Long typeId) {
|
||||
|
||||
final List<AssignedSoftwareModule> resultList = new ArrayList<>();
|
||||
final int pageSize = pageable.getPageSize();
|
||||
@@ -391,7 +382,7 @@ public class JpaSoftwareManagement implements SoftwareManagement {
|
||||
.join(JpaSoftwareModule_.assignedTo);
|
||||
// build the specifications and then to predicates necessary by the
|
||||
// given filters
|
||||
final Predicate[] specPredicate = specificationsToPredicate(buildSpecificationList(searchText, type),
|
||||
final Predicate[] specPredicate = specificationsToPredicate(buildSpecificationList(searchText, typeId),
|
||||
assignedRoot, assignedQuery, cb,
|
||||
cb.equal(assignedDsJoin.get(JpaDistributionSet_.id), orderByDistributionId));
|
||||
// if we have some predicates then add it to the where clause of the
|
||||
@@ -422,11 +413,11 @@ public class JpaSoftwareManagement implements SoftwareManagement {
|
||||
|
||||
Predicate[] unassignedSpec;
|
||||
if (!assignedSoftwareModules.isEmpty()) {
|
||||
unassignedSpec = specificationsToPredicate(buildSpecificationList(searchText, type), unassignedRoot,
|
||||
unassignedSpec = specificationsToPredicate(buildSpecificationList(searchText, typeId), unassignedRoot,
|
||||
unassignedQuery, cb, cb.not(unassignedRoot.get(JpaSoftwareModule_.id)
|
||||
.in(assignedSoftwareModules.stream().map(sw -> sw.getId()).collect(Collectors.toList()))));
|
||||
} else {
|
||||
unassignedSpec = specificationsToPredicate(buildSpecificationList(searchText, type), unassignedRoot,
|
||||
unassignedSpec = specificationsToPredicate(buildSpecificationList(searchText, typeId), unassignedRoot,
|
||||
unassignedQuery, cb);
|
||||
}
|
||||
|
||||
@@ -443,13 +434,13 @@ public class JpaSoftwareManagement implements SoftwareManagement {
|
||||
}
|
||||
|
||||
private static List<Specification<JpaSoftwareModule>> buildSpecificationList(final String searchText,
|
||||
final JpaSoftwareModuleType type) {
|
||||
final Long typeId) {
|
||||
final List<Specification<JpaSoftwareModule>> specList = new ArrayList<>(3);
|
||||
if (!Strings.isNullOrEmpty(searchText)) {
|
||||
specList.add(SoftwareModuleSpecification.likeNameOrVersion(searchText));
|
||||
}
|
||||
if (type != null) {
|
||||
specList.add(SoftwareModuleSpecification.equalType(type));
|
||||
if (typeId != null) {
|
||||
specList.add(SoftwareModuleSpecification.equalType(typeId));
|
||||
}
|
||||
specList.add(SoftwareModuleSpecification.isDeletedFalse());
|
||||
return specList;
|
||||
@@ -464,7 +455,7 @@ public class JpaSoftwareManagement implements SoftwareManagement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long countSoftwareModuleByFilters(final String searchText, final SoftwareModuleType type) {
|
||||
public Long countSoftwareModuleByFilters(final String searchText, final Long typeId) {
|
||||
|
||||
final List<Specification<JpaSoftwareModule>> specList = new ArrayList<>(3);
|
||||
|
||||
@@ -476,8 +467,8 @@ public class JpaSoftwareManagement implements SoftwareManagement {
|
||||
specList.add(spec);
|
||||
}
|
||||
|
||||
if (null != type) {
|
||||
spec = SoftwareModuleSpecification.equalType((JpaSoftwareModuleType) type);
|
||||
if (null != typeId) {
|
||||
spec = SoftwareModuleSpecification.equalType(typeId);
|
||||
specList.add(spec);
|
||||
}
|
||||
|
||||
@@ -541,13 +532,6 @@ public class JpaSoftwareManagement implements SoftwareManagement {
|
||||
return softwareModuleRepository.findByAssignedTo(pageable, (JpaDistributionSet) set);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<SoftwareModule> findSoftwareModuleByAssignedToAndType(final Pageable pageable,
|
||||
final DistributionSet set, final SoftwareModuleType type) {
|
||||
return softwareModuleRepository.findByAssignedToAndType(pageable, (JpaDistributionSet) set,
|
||||
(JpaSoftwareModuleType) type);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
@Modifying
|
||||
@@ -597,8 +581,8 @@ public class JpaSoftwareManagement implements SoftwareManagement {
|
||||
@Override
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
@Modifying
|
||||
public void deleteSoftwareModuleMetadata(final SoftwareModule softwareModule, final String key) {
|
||||
softwareModuleMetadataRepository.delete(new SwMetadataCompositeKey(softwareModule, key));
|
||||
public void deleteSoftwareModuleMetadata(final Long moduleId, final String key) {
|
||||
softwareModuleMetadataRepository.delete(new SwMetadataCompositeKey(moduleId, key));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -635,8 +619,8 @@ public class JpaSoftwareManagement implements SoftwareManagement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public SoftwareModuleMetadata findSoftwareModuleMetadata(final SoftwareModule softwareModule, final String key) {
|
||||
return findSoftwareModuleMetadata(new SwMetadataCompositeKey(softwareModule, key));
|
||||
public SoftwareModuleMetadata findSoftwareModuleMetadata(final Long moduleId, final String key) {
|
||||
return findSoftwareModuleMetadata(new SwMetadataCompositeKey(moduleId, key));
|
||||
}
|
||||
|
||||
private SoftwareModuleMetadata findSoftwareModuleMetadata(final SwMetadataCompositeKey id) {
|
||||
@@ -661,8 +645,8 @@ public class JpaSoftwareManagement implements SoftwareManagement {
|
||||
@Override
|
||||
@Modifying
|
||||
@Transactional(isolation = Isolation.READ_UNCOMMITTED)
|
||||
public void deleteSoftwareModule(final SoftwareModule bsm) {
|
||||
deleteSoftwareModules(Sets.newHashSet(bsm.getId()));
|
||||
public void deleteSoftwareModule(final Long moduleId) {
|
||||
deleteSoftwareModules(Sets.newHashSet(moduleId));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -83,15 +83,9 @@ public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, Syst
|
||||
@Autowired
|
||||
private DistributionSetTagRepository distributionSetTagRepository;
|
||||
|
||||
@Autowired
|
||||
private ExternalArtifactRepository externalArtifactRepository;
|
||||
|
||||
@Autowired
|
||||
private LocalArtifactRepository artifactRepository;
|
||||
|
||||
@Autowired
|
||||
private ExternalArtifactProviderRepository externalArtifactProviderRepository;
|
||||
|
||||
@Autowired
|
||||
private TenantConfigurationRepository tenantConfigurationRepository;
|
||||
|
||||
@@ -229,8 +223,6 @@ public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, Syst
|
||||
rolloutGroupRepository.deleteByTenantIgnoreCase(tenant);
|
||||
rolloutRepository.deleteByTenantIgnoreCase(tenant);
|
||||
artifactRepository.deleteByTenantIgnoreCase(tenant);
|
||||
externalArtifactRepository.deleteByTenantIgnoreCase(tenant);
|
||||
externalArtifactProviderRepository.deleteByTenantIgnoreCase(tenant);
|
||||
targetTagRepository.deleteByTenantIgnoreCase(tenant);
|
||||
distributionSetTagRepository.deleteByTenantIgnoreCase(tenant);
|
||||
distributionSetRepository.deleteByTenantIgnoreCase(tenant);
|
||||
|
||||
@@ -11,8 +11,8 @@ package org.eclipse.hawkbit.repository.jpa;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaLocalArtifact;
|
||||
import org.eclipse.hawkbit.repository.model.LocalArtifact;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaArtifact;
|
||||
import org.eclipse.hawkbit.repository.model.Artifact;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
@@ -20,11 +20,11 @@ import org.springframework.transaction.annotation.Isolation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* {@link LocalArtifact} repository.
|
||||
* {@link Artifact} repository.
|
||||
*
|
||||
*/
|
||||
@Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED)
|
||||
public interface LocalArtifactRepository extends BaseEntityRepository<JpaLocalArtifact, Long> {
|
||||
public interface LocalArtifactRepository extends BaseEntityRepository<JpaArtifact, Long> {
|
||||
|
||||
/**
|
||||
* Counts artifacts size where the related software module is not
|
||||
@@ -32,7 +32,7 @@ public interface LocalArtifactRepository extends BaseEntityRepository<JpaLocalAr
|
||||
*
|
||||
* @return sum of artifacts size in bytes
|
||||
*/
|
||||
@Query("SELECT SUM(la.size) FROM JpaLocalArtifact la WHERE la.softwareModule.deleted = 0")
|
||||
@Query("SELECT SUM(la.size) FROM JpaArtifact la WHERE la.softwareModule.deleted = 0")
|
||||
Optional<Long> getSumOfUndeletedArtifactSize();
|
||||
|
||||
/**
|
||||
@@ -46,32 +46,31 @@ public interface LocalArtifactRepository extends BaseEntityRepository<JpaLocalAr
|
||||
Long countBySoftwareModuleDeleted(boolean deleted);
|
||||
|
||||
/**
|
||||
* Searches for a {@link LocalArtifact} based on given gridFsFileName.
|
||||
* Searches for a {@link Artifact} based on given gridFsFileName.
|
||||
*
|
||||
* @param gridFsFileName
|
||||
* to search
|
||||
* @return list of {@link LocalArtifact}s.
|
||||
* @return list of {@link Artifact}s.
|
||||
*/
|
||||
List<LocalArtifact> findByGridFsFileName(String gridFsFileName);
|
||||
List<Artifact> findByGridFsFileName(String gridFsFileName);
|
||||
|
||||
/**
|
||||
* Searches for a {@link LocalArtifact} based on given gridFsFileName.
|
||||
* Searches for a {@link Artifact} based on given gridFsFileName.
|
||||
*
|
||||
* @param gridFsFileName
|
||||
* to search
|
||||
* @return {@link LocalArtifact} the first in the result list
|
||||
* @return {@link Artifact} the first in the result list
|
||||
*/
|
||||
JpaLocalArtifact findFirstByGridFsFileName(String gridFsFileName);
|
||||
JpaArtifact findFirstByGridFsFileName(String gridFsFileName);
|
||||
|
||||
/**
|
||||
* Searches for a {@link LocalArtifact} based user provided filename at
|
||||
* upload.
|
||||
* Searches for a {@link Artifact} based user provided filename at upload.
|
||||
*
|
||||
* @param filename
|
||||
* to search
|
||||
* @return list of {@link LocalArtifact}.
|
||||
* @return list of {@link Artifact}.
|
||||
*/
|
||||
List<LocalArtifact> findByFilename(String filename);
|
||||
List<Artifact> findByFilename(String filename);
|
||||
|
||||
/**
|
||||
* Searches for local artifact for a base software module.
|
||||
@@ -81,20 +80,20 @@ public interface LocalArtifactRepository extends BaseEntityRepository<JpaLocalAr
|
||||
* @param swId
|
||||
* software module id
|
||||
*
|
||||
* @return Page<LocalArtifact>
|
||||
* @return Page<Artifact>
|
||||
*/
|
||||
Page<LocalArtifact> findBySoftwareModuleId(Pageable pageReq, final Long swId);
|
||||
Page<Artifact> findBySoftwareModuleId(Pageable pageReq, final Long swId);
|
||||
|
||||
/**
|
||||
* Searches for a {@link LocalArtifact} based user provided filename at
|
||||
* upload and selected software module id.
|
||||
* Searches for a {@link Artifact} based user provided filename at upload
|
||||
* and selected software module id.
|
||||
*
|
||||
* @param filename
|
||||
* to search
|
||||
* @param softwareModuleId
|
||||
* selected software module id
|
||||
* @return list of {@link LocalArtifact}.
|
||||
* @return list of {@link Artifact}.
|
||||
*/
|
||||
List<LocalArtifact> findByFilenameAndSoftwareModuleId(final String filename, final Long softwareModuleId);
|
||||
List<Artifact> findByFilenameAndSoftwareModuleId(final String filename, final Long softwareModuleId);
|
||||
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ public interface SoftwareModuleRepository
|
||||
* @return all {@link SoftwareModule}s that are assigned to given
|
||||
* {@link DistributionSet} filtered by {@link SoftwareModuleType}.
|
||||
*/
|
||||
Page<SoftwareModule> findByAssignedToAndType(Pageable pageable, JpaDistributionSet set, JpaSoftwareModuleType type);
|
||||
Page<SoftwareModule> findByAssignedToAndType(Pageable pageable, JpaDistributionSet set, SoftwareModuleType type);
|
||||
|
||||
/**
|
||||
* retrieves all software modules with a given {@link SoftwareModuleType}
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
/**
|
||||
* 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.model;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.Artifact;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
|
||||
/**
|
||||
* Tenant specific locally stored artifact representation that is used by
|
||||
* {@link SoftwareModule}.
|
||||
*/
|
||||
@MappedSuperclass
|
||||
// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for
|
||||
// sub entities
|
||||
@SuppressWarnings("squid:S2160")
|
||||
public abstract class AbstractJpaArtifact extends AbstractJpaTenantAwareBaseEntity implements Artifact {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Column(name = "sha1_hash", length = 40, nullable = true)
|
||||
private String sha1Hash;
|
||||
|
||||
@Column(name = "md5_hash", length = 32, nullable = true)
|
||||
private String md5Hash;
|
||||
|
||||
@Column(name = "file_size")
|
||||
private long size;
|
||||
|
||||
@Override
|
||||
public abstract SoftwareModule getSoftwareModule();
|
||||
|
||||
@Override
|
||||
public String getMd5Hash() {
|
||||
return md5Hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSha1Hash() {
|
||||
return sha1Hash;
|
||||
}
|
||||
|
||||
public void setMd5Hash(final String md5Hash) {
|
||||
this.md5Hash = md5Hash;
|
||||
}
|
||||
|
||||
public void setSha1Hash(final String sha1Hash) {
|
||||
this.sha1Hash = sha1Hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public void setSize(final long size) {
|
||||
this.size = size;
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ import javax.persistence.Table;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.LocalArtifact;
|
||||
import org.eclipse.hawkbit.repository.model.Artifact;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
|
||||
import com.mongodb.gridfs.GridFS;
|
||||
@@ -36,7 +36,7 @@ import com.mongodb.gridfs.GridFSFile;
|
||||
// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for
|
||||
// sub entities
|
||||
@SuppressWarnings("squid:S2160")
|
||||
public class JpaLocalArtifact extends AbstractJpaArtifact implements LocalArtifact {
|
||||
public class JpaArtifact extends AbstractJpaTenantAwareBaseEntity implements Artifact {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@NotNull
|
||||
@@ -53,10 +53,19 @@ public class JpaLocalArtifact extends AbstractJpaArtifact implements LocalArtifa
|
||||
@JoinColumn(name = "software_module", nullable = false, updatable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_assigned_sm"))
|
||||
private JpaSoftwareModule softwareModule;
|
||||
|
||||
@Column(name = "sha1_hash", length = 40, nullable = true)
|
||||
private String sha1Hash;
|
||||
|
||||
@Column(name = "md5_hash", length = 32, nullable = true)
|
||||
private String md5Hash;
|
||||
|
||||
@Column(name = "file_size")
|
||||
private long size;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
public JpaLocalArtifact() {
|
||||
public JpaArtifact() {
|
||||
super();
|
||||
}
|
||||
|
||||
@@ -70,7 +79,7 @@ public class JpaLocalArtifact extends AbstractJpaArtifact implements LocalArtifa
|
||||
* @param softwareModule
|
||||
* of this artifact
|
||||
*/
|
||||
public JpaLocalArtifact(@NotNull final String gridFsFileName, @NotNull final String filename,
|
||||
public JpaArtifact(@NotNull final String gridFsFileName, @NotNull final String filename,
|
||||
final SoftwareModule softwareModule) {
|
||||
setSoftwareModule(softwareModule);
|
||||
this.gridFsFileName = gridFsFileName;
|
||||
@@ -78,23 +87,30 @@ public class JpaLocalArtifact extends AbstractJpaArtifact implements LocalArtifa
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() { // NOSONAR - as this is generated
|
||||
final int prime = 31;
|
||||
int result = super.hashCode();
|
||||
result = prime * result + this.getClass().getName().hashCode();
|
||||
return result;
|
||||
public String getMd5Hash() {
|
||||
return md5Hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) { // NOSONAR - as this is generated
|
||||
if (!super.equals(obj)) {
|
||||
return false;
|
||||
}
|
||||
if (!(obj instanceof LocalArtifact)) {
|
||||
return false;
|
||||
}
|
||||
public String getSha1Hash() {
|
||||
return sha1Hash;
|
||||
}
|
||||
|
||||
return true;
|
||||
public void setMd5Hash(final String md5Hash) {
|
||||
this.md5Hash = md5Hash;
|
||||
}
|
||||
|
||||
public void setSha1Hash(final String sha1Hash) {
|
||||
this.sha1Hash = sha1Hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public void setSize(final long size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1,145 +0,0 @@
|
||||
/**
|
||||
* 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.model;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.ConstraintMode;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.ForeignKey;
|
||||
import javax.persistence.Index;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.ExternalArtifact;
|
||||
import org.eclipse.hawkbit.repository.model.ExternalArtifactProvider;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
|
||||
/**
|
||||
* External artifact representation with all the necessary information to
|
||||
* generate an artifact {@link URL} at runtime.
|
||||
*
|
||||
*/
|
||||
@Table(name = "sp_external_artifact", indexes = {
|
||||
@Index(name = "sp_idx_external_artifact_prim", columnList = "id,tenant") })
|
||||
@Entity
|
||||
// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for
|
||||
// sub entities
|
||||
@SuppressWarnings("squid:S2160")
|
||||
public class JpaExternalArtifact extends AbstractJpaArtifact implements ExternalArtifact {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "provider", nullable = false, updatable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_art_to_ext_provider"))
|
||||
private JpaExternalArtifactProvider externalArtifactProvider;
|
||||
|
||||
@Column(name = "url_suffix", length = 512)
|
||||
@Size(max = 512)
|
||||
private String urlSuffix;
|
||||
|
||||
// CascadeType.PERSIST as we register ourself at the BSM
|
||||
@ManyToOne(optional = false, cascade = { CascadeType.PERSIST })
|
||||
@JoinColumn(name = "software_module", nullable = false, updatable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_external_assigned_sm"))
|
||||
private JpaSoftwareModule softwareModule;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
public JpaExternalArtifact() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs {@link ExternalArtifact}.
|
||||
*
|
||||
* @param externalArtifactProvider
|
||||
* of the artifact
|
||||
* @param urlSuffix
|
||||
* of the artifact
|
||||
* @param softwareModule
|
||||
* of the artifact
|
||||
*/
|
||||
public JpaExternalArtifact(@NotNull final ExternalArtifactProvider externalArtifactProvider, final String urlSuffix,
|
||||
final SoftwareModule softwareModule) {
|
||||
setSoftwareModule(softwareModule);
|
||||
this.externalArtifactProvider = (JpaExternalArtifactProvider) externalArtifactProvider;
|
||||
|
||||
if (urlSuffix != null) {
|
||||
this.urlSuffix = urlSuffix;
|
||||
} else {
|
||||
this.urlSuffix = externalArtifactProvider.getDefaultSuffix();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the softwareModule
|
||||
*/
|
||||
@Override
|
||||
public SoftwareModule getSoftwareModule() {
|
||||
return softwareModule;
|
||||
}
|
||||
|
||||
public final void setSoftwareModule(final SoftwareModule softwareModule) {
|
||||
this.softwareModule = (JpaSoftwareModule) softwareModule;
|
||||
this.softwareModule.addArtifact(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExternalArtifactProvider getExternalArtifactProvider() {
|
||||
return externalArtifactProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUrl() {
|
||||
return new StringBuilder().append(externalArtifactProvider.getBasePath()).append(urlSuffix).toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUrlSuffix() {
|
||||
return urlSuffix;
|
||||
}
|
||||
|
||||
public void setExternalArtifactProvider(final JpaExternalArtifactProvider externalArtifactProvider) {
|
||||
this.externalArtifactProvider = externalArtifactProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param urlSuffix
|
||||
* the urlSuffix to set
|
||||
*/
|
||||
@Override
|
||||
public void setUrlSuffix(final String urlSuffix) {
|
||||
this.urlSuffix = urlSuffix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() { // NOSONAR - as this is generated
|
||||
final int prime = 31;
|
||||
int result = super.hashCode();
|
||||
result = prime * result + this.getClass().getName().hashCode();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) { // NOSONAR - as this is generated
|
||||
if (!super.equals(obj)) {
|
||||
return false;
|
||||
}
|
||||
if (!(obj instanceof JpaExternalArtifact)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
/**
|
||||
* 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.model;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Index;
|
||||
import javax.persistence.Table;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.ExternalArtifact;
|
||||
import org.eclipse.hawkbit.repository.model.ExternalArtifactProvider;
|
||||
|
||||
/**
|
||||
* JPA implementation of {@link ExternalArtifactProvider}.
|
||||
*
|
||||
*/
|
||||
@Table(name = "sp_external_provider", indexes = {
|
||||
@Index(name = "sp_idx_external_provider_prim", columnList = "tenant,id") })
|
||||
@Entity
|
||||
// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for
|
||||
// sub entities
|
||||
@SuppressWarnings("squid:S2160")
|
||||
public class JpaExternalArtifactProvider extends AbstractJpaNamedEntity implements ExternalArtifactProvider {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Column(name = "base_url", length = 512, nullable = false)
|
||||
@Size(max = 512)
|
||||
private String basePath;
|
||||
|
||||
@Column(name = "default_url_suffix", length = 512, nullable = true)
|
||||
@Size(max = 512)
|
||||
private String defaultSuffix;
|
||||
|
||||
/**
|
||||
* Constructs {@link ExternalArtifactProvider} based on given properties.
|
||||
*
|
||||
* @param name
|
||||
* of the provided
|
||||
* @param description
|
||||
* which is optional
|
||||
* @param baseURL
|
||||
* of all {@link ExternalArtifact}s of the provider
|
||||
* @param defaultUrlSuffix
|
||||
* that is used if {@link ExternalArtifact#getUrlSuffix()} is
|
||||
* empty.
|
||||
*/
|
||||
public JpaExternalArtifactProvider(final String name, final String description, final String baseURL,
|
||||
final String defaultUrlSuffix) {
|
||||
super(name, description);
|
||||
basePath = baseURL;
|
||||
defaultSuffix = defaultUrlSuffix;
|
||||
}
|
||||
|
||||
JpaExternalArtifactProvider() {
|
||||
super();
|
||||
defaultSuffix = "";
|
||||
basePath = "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBasePath() {
|
||||
return basePath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDefaultSuffix() {
|
||||
return defaultSuffix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBasePath(final String basePath) {
|
||||
this.basePath = basePath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDefaultSuffix(final String defaultSuffix) {
|
||||
this.defaultSuffix = defaultSuffix;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,9 +10,7 @@ package org.eclipse.hawkbit.repository.jpa.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
@@ -34,15 +32,11 @@ import javax.validation.constraints.Size;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.Artifact;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.ExternalArtifact;
|
||||
import org.eclipse.hawkbit.repository.model.LocalArtifact;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
||||
import org.eclipse.persistence.annotations.CascadeOnDelete;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
/**
|
||||
* Base Software Module that is supported by OS level provisioning mechanism on
|
||||
* the edge controller, e.g. OS, JVM, AgentHub.
|
||||
@@ -77,12 +71,8 @@ public class JpaSoftwareModule extends AbstractJpaNamedVersionedEntity implement
|
||||
private String vendor;
|
||||
|
||||
@CascadeOnDelete
|
||||
@OneToMany(mappedBy = "softwareModule", cascade = { CascadeType.ALL }, targetEntity = JpaLocalArtifact.class)
|
||||
private List<LocalArtifact> artifacts;
|
||||
|
||||
@CascadeOnDelete
|
||||
@OneToMany(mappedBy = "softwareModule", cascade = { CascadeType.ALL }, targetEntity = JpaExternalArtifact.class)
|
||||
private List<ExternalArtifact> externalArtifacts;
|
||||
@OneToMany(mappedBy = "softwareModule", cascade = { CascadeType.ALL }, targetEntity = JpaArtifact.class)
|
||||
private List<Artifact> artifacts;
|
||||
|
||||
@CascadeOnDelete
|
||||
@OneToMany(fetch = FetchType.LAZY, cascade = { CascadeType.REMOVE }, targetEntity = JpaSoftwareModuleMetadata.class)
|
||||
@@ -122,7 +112,7 @@ public class JpaSoftwareModule extends AbstractJpaNamedVersionedEntity implement
|
||||
* is added to the assigned {@link Artifact}s.
|
||||
*/
|
||||
@Override
|
||||
public void addArtifact(final LocalArtifact artifact) {
|
||||
public void addArtifact(final Artifact artifact) {
|
||||
if (null == artifacts) {
|
||||
artifacts = new ArrayList<>(4);
|
||||
artifacts.add(artifact);
|
||||
@@ -134,72 +124,16 @@ public class JpaSoftwareModule extends AbstractJpaNamedVersionedEntity implement
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param artifact
|
||||
* is added to the assigned {@link Artifact}s.
|
||||
*/
|
||||
@Override
|
||||
public void addArtifact(final ExternalArtifact artifact) {
|
||||
if (null == externalArtifacts) {
|
||||
externalArtifacts = new LinkedList<>();
|
||||
externalArtifacts.add(artifact);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!externalArtifacts.contains(artifact)) {
|
||||
externalArtifacts.add(artifact);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<LocalArtifact> getLocalArtifact(final Long artifactId) {
|
||||
if (artifacts == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
return artifacts.stream().filter(artifact -> artifact.getId().equals(artifactId)).findFirst();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<LocalArtifact> getLocalArtifactByFilename(final String fileName) {
|
||||
if (artifacts == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
return artifacts.stream().filter(artifact -> artifact.getFilename().equalsIgnoreCase(fileName.trim()))
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the artifacts
|
||||
*/
|
||||
@Override
|
||||
public List<Artifact> getArtifacts() {
|
||||
if (artifacts == null && externalArtifacts == null) {
|
||||
return Collections.emptyList();
|
||||
} else if (artifacts == null) {
|
||||
return Collections.unmodifiableList(externalArtifacts);
|
||||
} else if (externalArtifacts == null) {
|
||||
return Collections.unmodifiableList(artifacts);
|
||||
}
|
||||
|
||||
final List<Artifact> result = Lists.newLinkedList(artifacts);
|
||||
result.addAll(externalArtifacts);
|
||||
|
||||
return Collections.unmodifiableList(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return local artifacts only
|
||||
*/
|
||||
@Override
|
||||
public List<LocalArtifact> getLocalArtifacts() {
|
||||
if (artifacts == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return artifacts;
|
||||
return Collections.unmodifiableList(artifacts);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -212,23 +146,12 @@ public class JpaSoftwareModule extends AbstractJpaNamedVersionedEntity implement
|
||||
* is removed from the assigned {@link LocalArtifact}s.
|
||||
*/
|
||||
@Override
|
||||
public void removeArtifact(final LocalArtifact artifact) {
|
||||
public void removeArtifact(final Artifact artifact) {
|
||||
if (artifacts != null) {
|
||||
artifacts.remove(artifact);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param artifact
|
||||
* is removed from the assigned {@link ExternalArtifact}s.
|
||||
*/
|
||||
@Override
|
||||
public void removeArtifact(final ExternalArtifact artifact) {
|
||||
if (externalArtifacts != null) {
|
||||
externalArtifacts.remove(artifact);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVendor(final String vendor) {
|
||||
this.vendor = vendor;
|
||||
|
||||
@@ -46,7 +46,7 @@ public class JpaSoftwareModuleMetadata extends AbstractJpaMetaData implements So
|
||||
}
|
||||
|
||||
public SwMetadataCompositeKey getId() {
|
||||
return new SwMetadataCompositeKey(softwareModule, getKey());
|
||||
return new SwMetadataCompositeKey(softwareModule.getId(), getKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -10,8 +10,6 @@ package org.eclipse.hawkbit.repository.jpa.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
|
||||
/**
|
||||
* The Software Module meta data composite key which contains the meta data key
|
||||
* and the ID of the software module itself.
|
||||
@@ -31,13 +29,13 @@ public final class SwMetadataCompositeKey implements Serializable {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param softwareModule
|
||||
* @param moduleId
|
||||
* the software module for this meta data
|
||||
* @param key
|
||||
* the key of the meta data
|
||||
*/
|
||||
public SwMetadataCompositeKey(final SoftwareModule softwareModule, final String key) {
|
||||
this.softwareModule = softwareModule.getId();
|
||||
public SwMetadataCompositeKey(final Long moduleId, final String key) {
|
||||
this.softwareModule = moduleId;
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,14 +14,14 @@ import javax.persistence.criteria.SetJoin;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaAction_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaArtifact;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaArtifact_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaLocalArtifact;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaLocalArtifact_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule_;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.LocalArtifact;
|
||||
import org.eclipse.hawkbit.repository.model.Artifact;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
|
||||
@@ -50,14 +50,14 @@ public final class ActionSpecifications {
|
||||
* @return a specification to use with spring JPA
|
||||
*/
|
||||
public static Specification<JpaAction> hasTargetAssignedArtifact(final Target target,
|
||||
final LocalArtifact localArtifact) {
|
||||
final Artifact localArtifact) {
|
||||
return (actionRoot, query, criteriaBuilder) -> {
|
||||
final Join<JpaAction, JpaDistributionSet> dsJoin = actionRoot.join(JpaAction_.distributionSet);
|
||||
final SetJoin<JpaDistributionSet, JpaSoftwareModule> modulesJoin = dsJoin.join(JpaDistributionSet_.modules);
|
||||
final ListJoin<JpaSoftwareModule, JpaLocalArtifact> artifactsJoin = modulesJoin
|
||||
final ListJoin<JpaSoftwareModule, JpaArtifact> artifactsJoin = modulesJoin
|
||||
.join(JpaSoftwareModule_.artifacts);
|
||||
return criteriaBuilder.and(
|
||||
criteriaBuilder.equal(artifactsJoin.get(JpaLocalArtifact_.filename), localArtifact.getFilename()),
|
||||
criteriaBuilder.equal(artifactsJoin.get(JpaArtifact_.filename), localArtifact.getFilename()),
|
||||
criteriaBuilder.equal(actionRoot.get(JpaAction_.target), target));
|
||||
};
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import javax.persistence.criteria.Predicate;
|
||||
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType_;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule_;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
@@ -39,7 +40,7 @@ public final class SoftwareModuleSpecification {
|
||||
return (targetRoot, query, cb) -> {
|
||||
final Predicate predicate = cb.equal(targetRoot.<Long> get(JpaSoftwareModule_.id), moduleId);
|
||||
targetRoot.fetch(JpaSoftwareModule_.type);
|
||||
targetRoot.fetch(JpaSoftwareModule_.metadata,JoinType.LEFT);
|
||||
targetRoot.fetch(JpaSoftwareModule_.metadata, JoinType.LEFT);
|
||||
query.distinct(true);
|
||||
return predicate;
|
||||
};
|
||||
@@ -77,9 +78,9 @@ public final class SoftwareModuleSpecification {
|
||||
* to be filtered on
|
||||
* @return the {@link SoftwareModule} {@link Specification}
|
||||
*/
|
||||
public static Specification<JpaSoftwareModule> equalType(final JpaSoftwareModuleType type) {
|
||||
return (targetRoot, query, cb) -> cb.equal(targetRoot.<JpaSoftwareModuleType> get(JpaSoftwareModule_.type),
|
||||
type);
|
||||
public static Specification<JpaSoftwareModule> equalType(final Long type) {
|
||||
return (targetRoot, query, cb) -> cb.equal(
|
||||
targetRoot.<JpaSoftwareModuleType> get(JpaSoftwareModule_.type).get(JpaSoftwareModuleType_.id), type);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
DROP TABLE sp_external_provider;
|
||||
DROP TABLE sp_external_artifact;
|
||||
@@ -0,0 +1,2 @@
|
||||
DROP TABLE sp_external_provider;
|
||||
DROP TABLE sp_external_artifact;
|
||||
Reference in New Issue
Block a user