Removed external artifact from repository.
Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
@@ -32,10 +32,6 @@
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-validator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cz.jirutka.rsql</groupId>
|
||||
<artifactId>rsql-parser</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.hateoas</groupId>
|
||||
<artifactId>spring-hateoas</artifactId>
|
||||
|
||||
@@ -23,9 +23,6 @@ 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.model.Artifact;
|
||||
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.SoftwareModule;
|
||||
import org.hibernate.validator.constraints.NotEmpty;
|
||||
import org.springframework.data.domain.Page;
|
||||
@@ -38,59 +35,12 @@ import org.springframework.security.access.prepost.PreAuthorize;
|
||||
*
|
||||
*/
|
||||
public interface ArtifactManagement {
|
||||
|
||||
/**
|
||||
* Creates {@link ExternalArtifact} based on given provider.
|
||||
*
|
||||
* @param externalRepository
|
||||
* the artifact is located in
|
||||
* @param urlSuffix
|
||||
* of the artifact
|
||||
* {@link ExternalArtifactProvider#getDefaultSuffix()} is used if
|
||||
* empty.
|
||||
* @param moduleId
|
||||
* to assign the artifact to
|
||||
*
|
||||
* @return created {@link ExternalArtifact}
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* if {@link SoftwareModule} with given ID does not exist
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY)
|
||||
ExternalArtifact createExternalArtifact(@NotNull ExternalArtifactProvider externalRepository, String urlSuffix,
|
||||
@NotNull Long moduleId);
|
||||
|
||||
/**
|
||||
* @return the total amount of local artifacts stored in the artifact
|
||||
* management
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
Long countLocalArtifactsAll();
|
||||
|
||||
/**
|
||||
* @return the total amount of external artifacts stored in the artifact
|
||||
* management
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
Long countExternalArtifactsAll();
|
||||
|
||||
/**
|
||||
* Persists {@link ExternalArtifactProvider} based on given properties.
|
||||
*
|
||||
* @param name
|
||||
* of the provided
|
||||
* @param description
|
||||
* which is optional
|
||||
* @param basePath
|
||||
* of all {@link ExternalArtifact}s of the provider
|
||||
* @param defaultUrlSuffix
|
||||
* that is used if {@link ExternalArtifact#getUrlSuffix()} is
|
||||
* empty.
|
||||
* @return created {@link ExternalArtifactProvider}
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY)
|
||||
ExternalArtifactProvider createExternalArtifactProvider(@NotEmpty String name, String description,
|
||||
@NotNull String basePath, String defaultUrlSuffix);
|
||||
Long countArtifactsAll();
|
||||
|
||||
/**
|
||||
* Persists artifact binary as provided by given InputStream. assign the
|
||||
@@ -106,12 +56,12 @@ public interface ArtifactManagement {
|
||||
* to <code>true</code> if the artifact binary can be overridden
|
||||
* if it already exists
|
||||
*
|
||||
* @return uploaded {@link LocalArtifact}
|
||||
* @return uploaded {@link Artifact}
|
||||
*
|
||||
* @throw ArtifactUploadFailedException if upload fails
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
|
||||
LocalArtifact createLocalArtifact(@NotNull InputStream inputStream, @NotNull Long moduleId, final String filename,
|
||||
Artifact createArtifact(@NotNull InputStream inputStream, @NotNull Long moduleId, final String filename,
|
||||
final boolean overrideExisting);
|
||||
|
||||
/**
|
||||
@@ -130,13 +80,13 @@ public interface ArtifactManagement {
|
||||
* @param contentType
|
||||
* the contentType of the file
|
||||
*
|
||||
* @return uploaded {@link LocalArtifact}
|
||||
* @return uploaded {@link Artifact}
|
||||
*
|
||||
* @throw ArtifactUploadFailedException if upload fails
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
|
||||
LocalArtifact createLocalArtifact(@NotNull InputStream inputStream, @NotNull Long moduleId,
|
||||
@NotNull String filename, final boolean overrideExisting, @NotNull String contentType);
|
||||
Artifact createArtifact(@NotNull InputStream inputStream, @NotNull Long moduleId, @NotNull String filename,
|
||||
final boolean overrideExisting, @NotNull String contentType);
|
||||
|
||||
/**
|
||||
* Persists artifact binary as provided by given InputStream. assign the
|
||||
@@ -157,7 +107,7 @@ public interface ArtifactManagement {
|
||||
* if it already exists
|
||||
* @param contentType
|
||||
* the contentType of the file
|
||||
* @return uploaded {@link LocalArtifact}
|
||||
* @return uploaded {@link Artifact}
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
* if given software module does not exist
|
||||
@@ -171,24 +121,12 @@ public interface ArtifactManagement {
|
||||
* if check against provided SHA1 checksum failed
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY)
|
||||
LocalArtifact createLocalArtifact(@NotNull InputStream stream, @NotNull Long moduleId, @NotEmpty String filename,
|
||||
Artifact createArtifact(@NotNull InputStream stream, @NotNull Long moduleId, @NotEmpty String filename,
|
||||
String providedMd5Sum, String providedSha1Sum, boolean overrideExisting, String contentType);
|
||||
|
||||
/**
|
||||
* Deletes {@link Artifact} based on given id.
|
||||
*
|
||||
* @param id
|
||||
* of the {@link Artifact} that has to be deleted.
|
||||
* @throws ArtifactDeleteFailedException
|
||||
* if deletion failed (MongoDB is not available)
|
||||
*
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY)
|
||||
void deleteExternalArtifact(@NotNull Long id);
|
||||
|
||||
/**
|
||||
* Garbage collects local artifact binary file if only referenced by given
|
||||
* {@link LocalArtifact} metadata object.
|
||||
* {@link Artifact} metadata object.
|
||||
*
|
||||
* @param onlyByThisReferenced
|
||||
* the related local artifact
|
||||
@@ -196,7 +134,7 @@ public interface ArtifactManagement {
|
||||
* @return <code>true</code> if an binary was actually garbage collected
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY)
|
||||
boolean clearLocalArtifactBinary(@NotNull LocalArtifact onlyByThisReferenced);
|
||||
boolean clearArtifactBinary(@NotNull Artifact onlyByThisReferenced);
|
||||
|
||||
/**
|
||||
* Deletes {@link Artifact} based on given id.
|
||||
@@ -208,19 +146,19 @@ public interface ArtifactManagement {
|
||||
*
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY)
|
||||
void deleteLocalArtifact(@NotNull Long id);
|
||||
void deleteArtifact(@NotNull Long id);
|
||||
|
||||
/**
|
||||
* Searches for {@link LocalArtifact} with given {@link Identifiable}.
|
||||
* Searches for {@link Artifact} with given {@link Identifiable}.
|
||||
*
|
||||
* @param id
|
||||
* to search for
|
||||
* @return found {@link LocalArtifact} or <code>null</code> is it could not
|
||||
* be found.
|
||||
* @return found {@link Artifact} or <code>null</code> is it could not be
|
||||
* found.
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY + SpringEvalExpressions.HAS_AUTH_OR
|
||||
+ SpringEvalExpressions.IS_CONTROLLER)
|
||||
LocalArtifact findLocalArtifact(@NotNull Long id);
|
||||
Artifact findArtifact(@NotNull Long id);
|
||||
|
||||
/**
|
||||
* Find by artifact by software module id and filename.
|
||||
@@ -229,11 +167,11 @@ public interface ArtifactManagement {
|
||||
* file name
|
||||
* @param softwareModuleId
|
||||
* software module id.
|
||||
* @return LocalArtifact if artifact present
|
||||
* @return Artifact if artifact present
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY + SpringEvalExpressions.HAS_AUTH_OR
|
||||
+ SpringEvalExpressions.IS_CONTROLLER)
|
||||
List<LocalArtifact> findByFilenameAndSoftwareModule(@NotNull String filename, @NotNull Long softwareModuleId);
|
||||
List<Artifact> findByFilenameAndSoftwareModule(@NotNull String filename, @NotNull Long softwareModuleId);
|
||||
|
||||
/**
|
||||
* Find all local artifact by sha1 and return the first artifact.
|
||||
@@ -244,18 +182,18 @@ public interface ArtifactManagement {
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY + SpringEvalExpressions.HAS_AUTH_OR
|
||||
+ SpringEvalExpressions.IS_CONTROLLER)
|
||||
LocalArtifact findFirstLocalArtifactsBySHA1(@NotNull String sha1);
|
||||
Artifact findFirstArtifactBySHA1(@NotNull String sha1);
|
||||
|
||||
/**
|
||||
* Searches for {@link Artifact} with given file name.
|
||||
*
|
||||
* @param filename
|
||||
* to search for
|
||||
* @return found List of {@link LocalArtifact}s.
|
||||
* @return found List of {@link Artifact}s.
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY + SpringEvalExpressions.HAS_AUTH_OR
|
||||
+ SpringEvalExpressions.IS_CONTROLLER)
|
||||
List<LocalArtifact> findLocalArtifactByFilename(@NotNull String filename);
|
||||
List<Artifact> findArtifactByFilename(@NotNull String filename);
|
||||
|
||||
/**
|
||||
* Get local artifact for a base software module.
|
||||
@@ -264,38 +202,13 @@ public interface ArtifactManagement {
|
||||
* Pageable
|
||||
* @param swId
|
||||
* software module id
|
||||
* @return Page<LocalArtifact>
|
||||
* @return Page<Artifact>
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
Page<LocalArtifact> findLocalArtifactBySoftwareModule(@NotNull Pageable pageReq, @NotNull Long swId);
|
||||
Page<Artifact> findArtifactBySoftwareModule(@NotNull Pageable pageReq, @NotNull Long swId);
|
||||
|
||||
/**
|
||||
* Finds {@link SoftwareModule} by given id.
|
||||
*
|
||||
* @param id
|
||||
* to search for
|
||||
* @return the found {@link SoftwareModule}s or <code>null</code> if not
|
||||
* found.
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY + SpringEvalExpressions.HAS_AUTH_OR
|
||||
+ SpringEvalExpressions.IS_CONTROLLER)
|
||||
SoftwareModule findSoftwareModuleById(@NotNull Long id);
|
||||
|
||||
/**
|
||||
* Retrieves software module including details (
|
||||
* {@link SoftwareModule#getArtifacts()}).
|
||||
*
|
||||
* @param id
|
||||
* parameter
|
||||
* @param isDeleted
|
||||
* parameter
|
||||
* @return the found {@link SoftwareModule}s
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
SoftwareModule findSoftwareModuleWithDetails(@NotNull Long id);
|
||||
|
||||
/**
|
||||
* Loads {@link DbArtifact} from store for given {@link LocalArtifact}.
|
||||
* Loads {@link DbArtifact} from store for given {@link Artifact}.
|
||||
*
|
||||
* @param artifact
|
||||
* to search for
|
||||
@@ -306,6 +219,6 @@ public interface ArtifactManagement {
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DOWNLOAD_ARTIFACT + SpringEvalExpressions.HAS_AUTH_OR
|
||||
+ SpringEvalExpressions.HAS_CONTROLLER_DOWNLOAD)
|
||||
DbArtifact loadLocalArtifactBinary(@NotNull LocalArtifact artifact);
|
||||
DbArtifact loadArtifactBinary(@NotNull Artifact artifact);
|
||||
|
||||
}
|
||||
|
||||
@@ -24,8 +24,8 @@ import org.eclipse.hawkbit.repository.exception.TooManyStatusEntriesException;
|
||||
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;
|
||||
@@ -200,7 +200,7 @@ public interface ControllerManagement {
|
||||
* otherwise {@code false}
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.IS_CONTROLLER)
|
||||
boolean hasTargetArtifactAssigned(@NotNull String controllerId, @NotNull LocalArtifact localArtifact);
|
||||
boolean hasTargetArtifactAssigned(@NotNull String controllerId, @NotNull Artifact localArtifact);
|
||||
|
||||
/**
|
||||
* Checks if a given target has currently or has even been assigned to the
|
||||
@@ -219,7 +219,7 @@ public interface ControllerManagement {
|
||||
* otherwise {@code false}
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.IS_CONTROLLER)
|
||||
boolean hasTargetArtifactAssigned(@NotNull Long targetId, @NotNull LocalArtifact localArtifact);
|
||||
boolean hasTargetArtifactAssigned(@NotNull Long targetId, @NotNull Artifact localArtifact);
|
||||
|
||||
/**
|
||||
* Registers retrieved status for given {@link Target} and {@link Action} if
|
||||
|
||||
@@ -16,12 +16,12 @@ import javax.validation.constraints.NotNull;
|
||||
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.BaseEntity;
|
||||
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;
|
||||
@@ -376,10 +376,10 @@ public interface EntityFactory {
|
||||
TargetTag generateTargetTag(@NotNull String name, String description, String colour);
|
||||
|
||||
/**
|
||||
* Generates an empty {@link LocalArtifact} without persisting it.
|
||||
* Generates an empty {@link Artifact} without persisting it.
|
||||
*
|
||||
* @return {@link LocalArtifact} object
|
||||
* @return {@link Artifact} object
|
||||
*/
|
||||
LocalArtifact generateLocalArtifact();
|
||||
Artifact generateArtifact();
|
||||
|
||||
}
|
||||
|
||||
@@ -42,12 +42,12 @@ public interface SoftwareManagement {
|
||||
*
|
||||
* @param searchText
|
||||
* to search for in name and version
|
||||
* @param type
|
||||
* to filter the result
|
||||
* @param typeId
|
||||
* to filter the result by type
|
||||
* @return number of found {@link SoftwareModule}s
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
Long countSoftwareModuleByFilters(String searchText, SoftwareModuleType type);
|
||||
Long countSoftwareModuleByFilters(String searchText, Long typeId);
|
||||
|
||||
/**
|
||||
* Count all {@link SoftwareModule}s in the repository that are not marked
|
||||
@@ -58,16 +58,6 @@ public interface SoftwareManagement {
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
Long countSoftwareModulesAll();
|
||||
|
||||
/**
|
||||
* Counts {@link SoftwareModule}s with given {@link SoftwareModuleType}.
|
||||
*
|
||||
* @param type
|
||||
* to count
|
||||
* @return number of found {@link SoftwareModule}s
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
Long countSoftwareModulesByType(@NotNull SoftwareModuleType type);
|
||||
|
||||
/**
|
||||
* @return number of {@link SoftwareModuleType}s in the repository.
|
||||
*/
|
||||
@@ -146,31 +136,31 @@ public interface SoftwareManagement {
|
||||
/**
|
||||
* Deletes the given {@link SoftwareModule} {@link Entity}.
|
||||
*
|
||||
* @param bsm
|
||||
* @param moduleId
|
||||
* is the {@link SoftwareModule} to be deleted
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY)
|
||||
void deleteSoftwareModule(@NotNull SoftwareModule bsm);
|
||||
void deleteSoftwareModule(@NotNull Long moduleId);
|
||||
|
||||
/**
|
||||
* deletes a software module meta data entry.
|
||||
*
|
||||
* @param softwareModule
|
||||
* @param moduleId
|
||||
* where meta data has to be deleted
|
||||
* @param key
|
||||
* of the metda data element
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
|
||||
void deleteSoftwareModuleMetadata(@NotNull SoftwareModule softwareModule, @NotEmpty String key);
|
||||
void deleteSoftwareModuleMetadata(@NotNull Long moduleId, @NotEmpty String key);
|
||||
|
||||
/**
|
||||
* Deletes {@link SoftwareModule}s which is any if the given ids.
|
||||
*
|
||||
* @param ids
|
||||
* @param moduleIds
|
||||
* of the Software Modules to be deleted
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY)
|
||||
void deleteSoftwareModules(@NotNull Collection<Long> ids);
|
||||
void deleteSoftwareModules(@NotNull Collection<Long> moduleIds);
|
||||
|
||||
/**
|
||||
* Deletes or marks as delete in case the type is in use.
|
||||
@@ -192,20 +182,6 @@ public interface SoftwareManagement {
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
Page<SoftwareModule> findSoftwareModuleByAssignedTo(@NotNull Pageable pageable, @NotNull DistributionSet set);
|
||||
|
||||
/**
|
||||
* @param pageable
|
||||
* the page request to page the result set
|
||||
* @param set
|
||||
* to search for
|
||||
* @param type
|
||||
* to filter
|
||||
* @return all {@link SoftwareModule}s that are assigned to given
|
||||
* {@link DistributionSet} filtered by {@link SoftwareModuleType}.
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
Page<SoftwareModule> findSoftwareModuleByAssignedToAndType(@NotNull Pageable pageable, @NotNull DistributionSet set,
|
||||
@NotNull SoftwareModuleType type);
|
||||
|
||||
/**
|
||||
* Filter {@link SoftwareModule}s with given
|
||||
* {@link SoftwareModule#getName()} or {@link SoftwareModule#getVersion()}
|
||||
@@ -215,13 +191,12 @@ public interface SoftwareManagement {
|
||||
* page parameter
|
||||
* @param searchText
|
||||
* to be filtered as "like" on {@link SoftwareModule#getName()}
|
||||
* @param type
|
||||
* @param typeId
|
||||
* to be filtered as "like" on {@link SoftwareModule#getType()}
|
||||
* @return the page of found {@link SoftwareModule}
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
Slice<SoftwareModule> findSoftwareModuleByFilters(@NotNull Pageable pageable, String searchText,
|
||||
SoftwareModuleType type);
|
||||
Slice<SoftwareModule> findSoftwareModuleByFilters(@NotNull Pageable pageable, String searchText, Long typeId);
|
||||
|
||||
/**
|
||||
* Finds {@link SoftwareModule} by given id.
|
||||
@@ -253,7 +228,7 @@ public interface SoftwareManagement {
|
||||
/**
|
||||
* finds a single software module meta data by its id.
|
||||
*
|
||||
* @param softwareModule
|
||||
* @param moduleId
|
||||
* where meta data has to be found
|
||||
* @param key
|
||||
* of the meta data element
|
||||
@@ -262,7 +237,7 @@ public interface SoftwareManagement {
|
||||
* in case the meta data does not exists for the given key
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
SoftwareModuleMetadata findSoftwareModuleMetadata(@NotNull SoftwareModule softwareModule, @NotEmpty String key);
|
||||
SoftwareModuleMetadata findSoftwareModuleMetadata(@NotNull Long moduleId, @NotEmpty String key);
|
||||
|
||||
/**
|
||||
* finds all meta data by the given software module id.
|
||||
@@ -316,14 +291,13 @@ public interface SoftwareManagement {
|
||||
* the ID of distribution set to be ordered on top
|
||||
* @param searchText
|
||||
* filtered as "like" on {@link SoftwareModule#getName()}
|
||||
* @param type
|
||||
* @param typeId
|
||||
* filtered as "equal" on {@link SoftwareModule#getType()}
|
||||
* @return the page of found {@link SoftwareModule}
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
Slice<AssignedSoftwareModule> findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(
|
||||
@NotNull Pageable pageable, @NotNull Long orderByDistributionId, String searchText,
|
||||
SoftwareModuleType type);
|
||||
@NotNull Pageable pageable, @NotNull Long orderByDistributionId, String searchText, Long typeId);
|
||||
|
||||
/**
|
||||
* Retrieves all software modules. Deleted ones are filtered.
|
||||
@@ -370,12 +344,12 @@ public interface SoftwareManagement {
|
||||
*
|
||||
* @param pageable
|
||||
* page parameters
|
||||
* @param type
|
||||
* @param typeId
|
||||
* to be filtered on
|
||||
* @return the found {@link SoftwareModule}s
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
|
||||
Slice<SoftwareModule> findSoftwareModulesByType(@NotNull Pageable pageable, @NotNull SoftwareModuleType type);
|
||||
Slice<SoftwareModule> findSoftwareModulesByType(@NotNull Pageable pageable, @NotNull Long typeId);
|
||||
|
||||
/**
|
||||
*
|
||||
|
||||
@@ -17,6 +17,10 @@ import com.google.common.io.BaseEncoding;
|
||||
*
|
||||
*/
|
||||
public interface Artifact extends TenantAwareBaseEntity {
|
||||
/**
|
||||
* @return the filename that was provided during upload.
|
||||
*/
|
||||
String getFilename();
|
||||
|
||||
/**
|
||||
* @return {@link SoftwareModule} this {@link Artifact} belongs to.
|
||||
|
||||
@@ -1,41 +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.model;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* External artifact representation with all the necessary information to
|
||||
* generate an artifact {@link URL} at runtime.
|
||||
*
|
||||
*/
|
||||
public interface ExternalArtifact extends Artifact {
|
||||
|
||||
/**
|
||||
* @return {@link ExternalArtifactProvider} of this {@link Artifact}.
|
||||
*/
|
||||
ExternalArtifactProvider getExternalArtifactProvider();
|
||||
|
||||
/**
|
||||
* @return generated download {@link URL}.
|
||||
*/
|
||||
String getUrl();
|
||||
|
||||
/**
|
||||
* @return suffix for {@link URL} generation.
|
||||
*/
|
||||
String getUrlSuffix();
|
||||
|
||||
/**
|
||||
* @param urlSuffix
|
||||
* the urlSuffix to set
|
||||
*/
|
||||
void setUrlSuffix(String urlSuffix);
|
||||
|
||||
}
|
||||
@@ -1,28 +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.model;
|
||||
|
||||
import org.eclipse.hawkbit.artifact.repository.ArtifactRepository;
|
||||
|
||||
/**
|
||||
* Tenant specific locally stored artifact representation that is used by
|
||||
* {@link SoftwareModule}s . It contains all information that is provided by the
|
||||
* user while all update server generated information related to the artifact
|
||||
* (hash, length) is stored directly with the binary itself in the
|
||||
* {@link ArtifactRepository}.
|
||||
*
|
||||
*/
|
||||
public interface LocalArtifact extends Artifact {
|
||||
|
||||
/**
|
||||
* @return the filename that was provided during upload.
|
||||
*/
|
||||
String getFilename();
|
||||
|
||||
}
|
||||
@@ -21,38 +21,40 @@ public interface SoftwareModule extends NamedVersionedEntity {
|
||||
* @param artifact
|
||||
* is added to the assigned {@link Artifact}s.
|
||||
*/
|
||||
void addArtifact(LocalArtifact artifact);
|
||||
|
||||
/**
|
||||
* @param artifact
|
||||
* is added to the assigned {@link Artifact}s.
|
||||
*/
|
||||
void addArtifact(ExternalArtifact artifact);
|
||||
void addArtifact(Artifact artifact);
|
||||
|
||||
/**
|
||||
* @param artifactId
|
||||
* to look for
|
||||
* @return found {@link Artifact}
|
||||
*/
|
||||
Optional<LocalArtifact> getLocalArtifact(Long artifactId);
|
||||
default Optional<Artifact> getArtifact(final Long artifactId) {
|
||||
if (getArtifacts().isEmpty()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
return getArtifacts().stream().filter(artifact -> artifact.getId().equals(artifactId)).findFirst();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param fileName
|
||||
* to look for
|
||||
* @return found {@link Artifact}
|
||||
*/
|
||||
Optional<LocalArtifact> getLocalArtifactByFilename(String fileName);
|
||||
default Optional<Artifact> getArtifactByFilename(final String fileName) {
|
||||
if (getArtifacts().isEmpty()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
return getArtifacts().stream().filter(artifact -> artifact.getFilename().equalsIgnoreCase(fileName.trim()))
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return immutable list of all artifacts
|
||||
*/
|
||||
List<Artifact> getArtifacts();
|
||||
|
||||
/**
|
||||
* @return immutable list of local artifacts only
|
||||
*/
|
||||
List<LocalArtifact> getLocalArtifacts();
|
||||
|
||||
/**
|
||||
* @return the vendor of this software module
|
||||
*/
|
||||
@@ -66,15 +68,9 @@ public interface SoftwareModule extends NamedVersionedEntity {
|
||||
|
||||
/**
|
||||
* @param artifact
|
||||
* is removed from the assigned {@link LocalArtifact}s.
|
||||
* is removed from the assigned {@link Artifact}s.
|
||||
*/
|
||||
void removeArtifact(LocalArtifact artifact);
|
||||
|
||||
/**
|
||||
* @param artifact
|
||||
* is removed from the assigned {@link ExternalArtifact}s.
|
||||
*/
|
||||
void removeArtifact(ExternalArtifact artifact);
|
||||
void removeArtifact(Artifact artifact);
|
||||
|
||||
/**
|
||||
* @return the type of the software module
|
||||
|
||||
@@ -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;
|
||||
@@ -56,9 +56,6 @@ public abstract class AbstractJpaIntegrationTest extends AbstractIntegrationTest
|
||||
@Autowired
|
||||
protected ActionStatusRepository actionStatusRepository;
|
||||
|
||||
@Autowired
|
||||
protected ExternalArtifactRepository externalArtifactRepository;
|
||||
|
||||
@Autowired
|
||||
protected LocalArtifactRepository artifactRepository;
|
||||
|
||||
|
||||
@@ -55,9 +55,6 @@ public abstract class AbstractJpaIntegrationTestWithMongoDB extends AbstractInte
|
||||
@Autowired
|
||||
protected ActionStatusRepository actionStatusRepository;
|
||||
|
||||
@Autowired
|
||||
protected ExternalArtifactRepository externalArtifactRepository;
|
||||
|
||||
@Autowired
|
||||
protected LocalArtifactRepository artifactRepository;
|
||||
|
||||
|
||||
@@ -40,22 +40,21 @@ public class ArtifactManagementFailedMongoDBTest extends AbstractJpaIntegrationT
|
||||
"version 1", null, null);
|
||||
sm = softwareModuleRepository.save(sm);
|
||||
|
||||
final Artifact result = artifactManagement.createLocalArtifact(new RandomGeneratedInputStream(5 * 1024),
|
||||
sm.getId(), "file1", false);
|
||||
final Artifact result = artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024), sm.getId(),
|
||||
"file1", false);
|
||||
|
||||
assertThat(artifactRepository.findAll()).hasSize(1);
|
||||
|
||||
mongodExecutable.stop();
|
||||
try {
|
||||
artifactManagement.deleteLocalArtifact(result.getId());
|
||||
artifactManagement.deleteArtifact(result.getId());
|
||||
fail("deletion should have failed");
|
||||
} catch (final ArtifactDeleteFailedException e) {
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
artifactManagement.createLocalArtifact(new RandomGeneratedInputStream(5 * 1024), sm.getId(), "file2",
|
||||
false);
|
||||
artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024), sm.getId(), "file2", false);
|
||||
fail("Should not have worked with MongoDb down.");
|
||||
} catch (final ArtifactUploadFailedException e) {
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
package org.eclipse.hawkbit.repository.jpa;
|
||||
|
||||
import static org.fest.assertions.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
@@ -22,13 +21,9 @@ import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission;
|
||||
import org.eclipse.hawkbit.repository.ArtifactManagement;
|
||||
import org.eclipse.hawkbit.repository.exception.InsufficientPermissionException;
|
||||
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.model.Artifact;
|
||||
import org.eclipse.hawkbit.repository.model.ExternalArtifactProvider;
|
||||
import org.eclipse.hawkbit.repository.model.LocalArtifact;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.test.util.HashGeneratorUtils;
|
||||
import org.eclipse.hawkbit.repository.test.util.WithUser;
|
||||
@@ -57,7 +52,7 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTestWithMongoD
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.eclipse.hawkbit.repository.ArtifactManagement#createLocalArtifact(java.io.InputStream)}
|
||||
* {@link org.eclipse.hawkbit.repository.ArtifactManagement#createArtifact(java.io.InputStream)}
|
||||
* .
|
||||
*
|
||||
* @throws IOException
|
||||
@@ -65,7 +60,7 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTestWithMongoD
|
||||
*/
|
||||
@Test
|
||||
@Description("Test if a local artifact can be created by API including metadata.")
|
||||
public void createLocalArtifact() throws NoSuchAlgorithmException, IOException {
|
||||
public void createArtifact() throws NoSuchAlgorithmException, IOException {
|
||||
// checkbaseline
|
||||
assertThat(softwareModuleRepository.findAll()).hasSize(0);
|
||||
assertThat(artifactRepository.findAll()).hasSize(0);
|
||||
@@ -84,27 +79,26 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTestWithMongoD
|
||||
|
||||
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
|
||||
|
||||
final Artifact result = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(),
|
||||
"file1", false);
|
||||
final Artifact result11 = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(),
|
||||
final Artifact result = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), "file1",
|
||||
false);
|
||||
final Artifact result11 = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(),
|
||||
"file11", false);
|
||||
final Artifact result12 = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(),
|
||||
final Artifact result12 = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(),
|
||||
"file12", false);
|
||||
final Artifact result2 = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm2.getId(),
|
||||
final Artifact result2 = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm2.getId(),
|
||||
"file2", false);
|
||||
|
||||
assertThat(result).isInstanceOf(LocalArtifact.class);
|
||||
assertThat(result).isInstanceOf(Artifact.class);
|
||||
assertThat(result.getSoftwareModule().getId()).isEqualTo(sm.getId());
|
||||
assertThat(result2.getSoftwareModule().getId()).isEqualTo(sm2.getId());
|
||||
assertThat(((JpaLocalArtifact) result).getFilename()).isEqualTo("file1");
|
||||
assertThat(((JpaLocalArtifact) result).getGridFsFileName()).isNotNull();
|
||||
assertThat(((JpaArtifact) result).getFilename()).isEqualTo("file1");
|
||||
assertThat(((JpaArtifact) result).getGridFsFileName()).isNotNull();
|
||||
assertThat(result).isNotEqualTo(result2);
|
||||
assertThat(((JpaLocalArtifact) result).getGridFsFileName())
|
||||
.isEqualTo(((JpaLocalArtifact) result2).getGridFsFileName());
|
||||
assertThat(((JpaArtifact) result).getGridFsFileName()).isEqualTo(((JpaArtifact) result2).getGridFsFileName());
|
||||
|
||||
assertThat(artifactManagement.findLocalArtifactByFilename("file1").get(0).getSha1Hash())
|
||||
assertThat(artifactManagement.findArtifactByFilename("file1").get(0).getSha1Hash())
|
||||
.isEqualTo(HashGeneratorUtils.generateSHA1(random));
|
||||
assertThat(artifactManagement.findLocalArtifactByFilename("file1").get(0).getMd5Hash())
|
||||
assertThat(artifactManagement.findArtifactByFilename("file1").get(0).getMd5Hash())
|
||||
.isEqualTo(HashGeneratorUtils.generateMD5(random));
|
||||
|
||||
assertThat(artifactRepository.findAll()).hasSize(4);
|
||||
@@ -122,7 +116,7 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTestWithMongoD
|
||||
|
||||
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
|
||||
|
||||
artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", false);
|
||||
artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", false);
|
||||
assertThat(artifactRepository.findAll()).hasSize(1);
|
||||
|
||||
softwareModuleRepository.deleteAll();
|
||||
@@ -131,63 +125,7 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTestWithMongoD
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.eclipse.hawkbit.repository.ArtifactManagement#createExternalArtifact(org.eclipse.hawkbit.repository.model.ExternalArtifactProvider, java.lang.String)}
|
||||
* .
|
||||
*/
|
||||
@Test
|
||||
@Description("Tests the creation of an external artifact metadata element.")
|
||||
public void createExternalArtifact() {
|
||||
JpaSoftwareModule sm = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1",
|
||||
"version 1", null, null);
|
||||
sm = softwareModuleRepository.save(sm);
|
||||
|
||||
JpaSoftwareModule sm2 = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 2",
|
||||
"version 2", null, null);
|
||||
sm2 = softwareModuleRepository.save(sm2);
|
||||
|
||||
final ExternalArtifactProvider provider = artifactManagement.createExternalArtifactProvider("provider X", null,
|
||||
"https://fhghdfjgh", "/{version}/");
|
||||
|
||||
JpaExternalArtifact result = (JpaExternalArtifact) artifactManagement.createExternalArtifact(provider, null,
|
||||
sm.getId());
|
||||
|
||||
assertNotNull("The result of an external artifact should not be null", result);
|
||||
assertThat(externalArtifactRepository.findAll()).contains(result).hasSize(1);
|
||||
assertThat(result.getSoftwareModule().getId()).isEqualTo(sm.getId());
|
||||
assertThat(result.getUrl()).isEqualTo("https://fhghdfjgh/{version}/");
|
||||
assertThat(result.getExternalArtifactProvider()).isEqualTo(provider);
|
||||
|
||||
result = (JpaExternalArtifact) artifactManagement.createExternalArtifact(provider, "/test", sm2.getId());
|
||||
assertNotNull("The newly created external artifact should not be null", result);
|
||||
assertThat(externalArtifactRepository.findAll()).contains(result).hasSize(2);
|
||||
assertThat(result.getUrl()).isEqualTo("https://fhghdfjgh/test");
|
||||
assertThat(result.getExternalArtifactProvider()).isEqualTo(provider);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Tests deletio of an external artifact metadata element.")
|
||||
public void deleteExternalArtifact() {
|
||||
assertThat(artifactRepository.findAll()).isEmpty();
|
||||
|
||||
JpaSoftwareModule sm = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1",
|
||||
"version 1", null, null);
|
||||
sm = softwareModuleRepository.save(sm);
|
||||
|
||||
final JpaExternalArtifactProvider provider = (JpaExternalArtifactProvider) artifactManagement
|
||||
.createExternalArtifactProvider("provider X", null, "https://fhghdfjgh", "/{version}/");
|
||||
|
||||
final JpaExternalArtifact result = (JpaExternalArtifact) artifactManagement.createExternalArtifact(provider,
|
||||
null, sm.getId());
|
||||
assertNotNull("The newly created external artifact should not be null", result);
|
||||
assertThat(externalArtifactRepository.findAll()).contains(result).hasSize(1);
|
||||
|
||||
artifactManagement.deleteExternalArtifact(result.getId());
|
||||
assertThat(externalArtifactRepository.findAll()).isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.eclipse.hawkbit.repository.ArtifactManagement#deleteLocalArtifact(java.lang.Long)}
|
||||
* {@link org.eclipse.hawkbit.repository.ArtifactManagement#deleteArtifact(java.lang.Long)}
|
||||
* .
|
||||
*
|
||||
* @throws IOException
|
||||
@@ -195,7 +133,7 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTestWithMongoD
|
||||
*/
|
||||
@Test
|
||||
@Description("Tests the deletion of a local artifact including metadata.")
|
||||
public void deleteLocalArtifact() throws NoSuchAlgorithmException, IOException {
|
||||
public void deleteArtifact() throws NoSuchAlgorithmException, IOException {
|
||||
JpaSoftwareModule sm = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1",
|
||||
"version 1", null, null);
|
||||
sm = softwareModuleRepository.save(sm);
|
||||
@@ -206,34 +144,35 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTestWithMongoD
|
||||
|
||||
assertThat(artifactRepository.findAll()).isEmpty();
|
||||
|
||||
final Artifact result = artifactManagement.createLocalArtifact(new RandomGeneratedInputStream(5 * 1024),
|
||||
sm.getId(), "file1", false);
|
||||
final Artifact result2 = artifactManagement.createLocalArtifact(new RandomGeneratedInputStream(5 * 1024),
|
||||
final Artifact result = artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024), sm.getId(),
|
||||
"file1", false);
|
||||
final Artifact result2 = artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024),
|
||||
sm2.getId(), "file2", false);
|
||||
|
||||
assertThat(artifactRepository.findAll()).hasSize(2);
|
||||
|
||||
assertThat(result.getId()).isNotNull();
|
||||
assertThat(result2.getId()).isNotNull();
|
||||
assertThat(((JpaLocalArtifact) result).getGridFsFileName())
|
||||
.isNotEqualTo(((JpaLocalArtifact) result2).getGridFsFileName());
|
||||
assertThat(operations.findOne(new Query()
|
||||
.addCriteria(Criteria.where("filename").is(((JpaLocalArtifact) result).getGridFsFileName()))))
|
||||
assertThat(((JpaArtifact) result).getGridFsFileName())
|
||||
.isNotEqualTo(((JpaArtifact) result2).getGridFsFileName());
|
||||
assertThat(operations.findOne(
|
||||
new Query().addCriteria(Criteria.where("filename").is(((JpaArtifact) result).getGridFsFileName()))))
|
||||
.isNotNull();
|
||||
assertThat(operations.findOne(new Query()
|
||||
.addCriteria(Criteria.where("filename").is(((JpaLocalArtifact) result2).getGridFsFileName()))))
|
||||
assertThat(operations.findOne(
|
||||
new Query().addCriteria(Criteria.where("filename").is(((JpaArtifact) result2).getGridFsFileName()))))
|
||||
.isNotNull();
|
||||
|
||||
artifactManagement.deleteLocalArtifact(result.getId());
|
||||
assertThat(operations.findOne(new Query()
|
||||
.addCriteria(Criteria.where("filename").is(((JpaLocalArtifact) result).getGridFsFileName())))).isNull();
|
||||
assertThat(operations.findOne(new Query()
|
||||
.addCriteria(Criteria.where("filename").is(((JpaLocalArtifact) result2).getGridFsFileName()))))
|
||||
artifactManagement.deleteArtifact(result.getId());
|
||||
assertThat(operations.findOne(
|
||||
new Query().addCriteria(Criteria.where("filename").is(((JpaArtifact) result).getGridFsFileName()))))
|
||||
.isNull();
|
||||
assertThat(operations.findOne(
|
||||
new Query().addCriteria(Criteria.where("filename").is(((JpaArtifact) result2).getGridFsFileName()))))
|
||||
.isNotNull();
|
||||
|
||||
artifactManagement.deleteLocalArtifact(result2.getId());
|
||||
assertThat(operations.findOne(new Query()
|
||||
.addCriteria(Criteria.where("filename").is(((JpaLocalArtifact) result2).getGridFsFileName()))))
|
||||
artifactManagement.deleteArtifact(result2.getId());
|
||||
assertThat(operations.findOne(
|
||||
new Query().addCriteria(Criteria.where("filename").is(((JpaArtifact) result2).getGridFsFileName()))))
|
||||
.isNull();
|
||||
|
||||
assertThat(artifactRepository.findAll()).hasSize(0);
|
||||
@@ -253,33 +192,33 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTestWithMongoD
|
||||
|
||||
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
|
||||
|
||||
final Artifact result = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(),
|
||||
"file1", false);
|
||||
final Artifact result2 = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm2.getId(),
|
||||
final Artifact result = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), "file1",
|
||||
false);
|
||||
final Artifact result2 = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm2.getId(),
|
||||
"file2", false);
|
||||
|
||||
assertThat(artifactRepository.findAll()).hasSize(2);
|
||||
assertThat(result.getId()).isNotNull();
|
||||
assertThat(result2.getId()).isNotNull();
|
||||
assertThat(((JpaLocalArtifact) result).getGridFsFileName())
|
||||
.isEqualTo(((JpaLocalArtifact) result2).getGridFsFileName());
|
||||
assertThat(((JpaArtifact) result).getGridFsFileName()).isEqualTo(((JpaArtifact) result2).getGridFsFileName());
|
||||
|
||||
assertThat(operations.findOne(new Query()
|
||||
.addCriteria(Criteria.where("filename").is(((JpaLocalArtifact) result).getGridFsFileName()))))
|
||||
assertThat(operations.findOne(
|
||||
new Query().addCriteria(Criteria.where("filename").is(((JpaArtifact) result).getGridFsFileName()))))
|
||||
.isNotNull();
|
||||
artifactManagement.deleteLocalArtifact(result.getId());
|
||||
assertThat(operations.findOne(new Query()
|
||||
.addCriteria(Criteria.where("filename").is(((JpaLocalArtifact) result).getGridFsFileName()))))
|
||||
artifactManagement.deleteArtifact(result.getId());
|
||||
assertThat(operations.findOne(
|
||||
new Query().addCriteria(Criteria.where("filename").is(((JpaArtifact) result).getGridFsFileName()))))
|
||||
.isNotNull();
|
||||
|
||||
artifactManagement.deleteLocalArtifact(result2.getId());
|
||||
assertThat(operations.findOne(new Query()
|
||||
.addCriteria(Criteria.where("filename").is(((JpaLocalArtifact) result).getGridFsFileName())))).isNull();
|
||||
artifactManagement.deleteArtifact(result2.getId());
|
||||
assertThat(operations.findOne(
|
||||
new Query().addCriteria(Criteria.where("filename").is(((JpaArtifact) result).getGridFsFileName()))))
|
||||
.isNull();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.eclipse.hawkbit.repository.ArtifactManagement#findLocalArtifact(java.lang.Long)}
|
||||
* {@link org.eclipse.hawkbit.repository.ArtifactManagement#findArtifact(java.lang.Long)}
|
||||
* .
|
||||
*
|
||||
* @throws IOException
|
||||
@@ -287,20 +226,20 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTestWithMongoD
|
||||
*/
|
||||
@Test
|
||||
@Description("Loads an local artifact based on given ID.")
|
||||
public void findLocalArtifact() throws NoSuchAlgorithmException, IOException {
|
||||
public void findArtifact() throws NoSuchAlgorithmException, IOException {
|
||||
SoftwareModule sm = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1",
|
||||
"version 1", null, null);
|
||||
sm = softwareManagement.createSoftwareModule(sm);
|
||||
|
||||
final LocalArtifact result = artifactManagement.createLocalArtifact(new RandomGeneratedInputStream(5 * 1024),
|
||||
sm.getId(), "file1", false);
|
||||
final Artifact result = artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024), sm.getId(),
|
||||
"file1", false);
|
||||
|
||||
assertThat(artifactManagement.findLocalArtifact(result.getId())).isEqualTo(result);
|
||||
assertThat(artifactManagement.findArtifact(result.getId())).isEqualTo(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.eclipse.hawkbit.repository.ArtifactManagement#loadLocalArtifactBinary(java.lang.Long)}
|
||||
* {@link org.eclipse.hawkbit.repository.ArtifactManagement#loadArtifactBinary(java.lang.Long)}
|
||||
* .
|
||||
*
|
||||
* @throws IOException
|
||||
@@ -308,26 +247,26 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTestWithMongoD
|
||||
*/
|
||||
@Test
|
||||
@Description("Loads an artifact binary based on given ID.")
|
||||
public void loadStreamOfLocalArtifact() throws NoSuchAlgorithmException, IOException {
|
||||
public void loadStreamOfArtifact() throws NoSuchAlgorithmException, IOException {
|
||||
SoftwareModule sm = new JpaSoftwareModule(softwareManagement.findSoftwareModuleTypeByKey("os"), "name 1",
|
||||
"version 1", null, null);
|
||||
sm = softwareManagement.createSoftwareModule(sm);
|
||||
|
||||
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
|
||||
|
||||
final LocalArtifact result = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random),
|
||||
sm.getId(), "file1", false);
|
||||
final Artifact result = artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), "file1",
|
||||
false);
|
||||
|
||||
assertTrue("The stored binary matches the given binary", IOUtils.contentEquals(new ByteArrayInputStream(random),
|
||||
artifactManagement.loadLocalArtifactBinary(result).getFileInputStream()));
|
||||
artifactManagement.loadArtifactBinary(result).getFileInputStream()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithUser(allSpPermissions = true, removeFromAllPermission = { SpPermission.DOWNLOAD_REPOSITORY_ARTIFACT })
|
||||
@Description("Trys and fails to load an artifact without required permission. Checks if expected InsufficientPermissionException is thrown.")
|
||||
public void loadLocalArtifactBinaryWithoutDownloadArtifactThrowsPermissionDenied() {
|
||||
public void loadArtifactBinaryWithoutDownloadArtifactThrowsPermissionDenied() {
|
||||
try {
|
||||
artifactManagement.loadLocalArtifactBinary(new JpaLocalArtifact());
|
||||
artifactManagement.loadArtifactBinary(new JpaArtifact());
|
||||
fail("Should not have worked with missing permission.");
|
||||
} catch (final InsufficientPermissionException e) {
|
||||
|
||||
@@ -336,19 +275,19 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTestWithMongoD
|
||||
|
||||
@Test
|
||||
@Description("Searches an artifact through the relations of a software module.")
|
||||
public void findLocalArtifactBySoftwareModule() {
|
||||
public void findArtifactBySoftwareModule() {
|
||||
SoftwareModule sm = new JpaSoftwareModule(osType, "name 1", "version 1", null, null);
|
||||
sm = softwareManagement.createSoftwareModule(sm);
|
||||
|
||||
SoftwareModule sm2 = new JpaSoftwareModule(osType, "name 2", "version 2", null, null);
|
||||
sm2 = softwareManagement.createSoftwareModule(sm2);
|
||||
|
||||
assertThat(artifactManagement.findLocalArtifactBySoftwareModule(pageReq, sm.getId())).isEmpty();
|
||||
assertThat(artifactManagement.findArtifactBySoftwareModule(pageReq, sm.getId())).isEmpty();
|
||||
|
||||
final Artifact result = artifactManagement.createLocalArtifact(new RandomGeneratedInputStream(5 * 1024),
|
||||
sm.getId(), "file1", false);
|
||||
final Artifact result = artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024), sm.getId(),
|
||||
"file1", false);
|
||||
|
||||
assertThat(artifactManagement.findLocalArtifactBySoftwareModule(pageReq, sm.getId())).hasSize(1);
|
||||
assertThat(artifactManagement.findArtifactBySoftwareModule(pageReq, sm.getId())).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -359,8 +298,8 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTestWithMongoD
|
||||
|
||||
assertThat(artifactManagement.findByFilenameAndSoftwareModule("file1", sm.getId())).isEmpty();
|
||||
|
||||
artifactManagement.createLocalArtifact(new RandomGeneratedInputStream(5 * 1024), sm.getId(), "file1", false);
|
||||
artifactManagement.createLocalArtifact(new RandomGeneratedInputStream(5 * 1024), sm.getId(), "file2", false);
|
||||
artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024), sm.getId(), "file1", false);
|
||||
artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024), sm.getId(), "file2", false);
|
||||
|
||||
assertThat(artifactManagement.findByFilenameAndSoftwareModule("file1", sm.getId())).hasSize(1);
|
||||
|
||||
|
||||
@@ -24,9 +24,9 @@ import javax.validation.ConstraintViolationException;
|
||||
import org.apache.commons.lang3.RandomUtils;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaArtifact;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaLocalArtifact;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleMetadata;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModuleType;
|
||||
@@ -237,24 +237,29 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTestWithMongoD
|
||||
ds = (JpaDistributionSet) assignSet(target, ds).getDistributionSet();
|
||||
|
||||
// standard searches
|
||||
assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "poky", osType).getContent()).hasSize(1);
|
||||
assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "poky", osType).getContent().get(0))
|
||||
.isEqualTo(os);
|
||||
assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "oracle%", runtimeType).getContent())
|
||||
assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "poky", osType.getId()).getContent())
|
||||
.hasSize(1);
|
||||
assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "oracle%", runtimeType).getContent().get(0))
|
||||
.isEqualTo(jvm);
|
||||
assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "1.0.1", appType).getContent()).hasSize(1);
|
||||
assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "1.0.1", appType).getContent().get(0))
|
||||
.isEqualTo(ah);
|
||||
assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "1.0%", appType).getContent()).hasSize(2);
|
||||
assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "poky", osType.getId()).getContent().get(0))
|
||||
.isEqualTo(os);
|
||||
assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "oracle%", runtimeType.getId()).getContent())
|
||||
.hasSize(1);
|
||||
assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "oracle%", runtimeType.getId()).getContent()
|
||||
.get(0)).isEqualTo(jvm);
|
||||
assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "1.0.1", appType.getId()).getContent())
|
||||
.hasSize(1);
|
||||
assertThat(
|
||||
softwareManagement.findSoftwareModuleByFilters(pageReq, "1.0.1", appType.getId()).getContent().get(0))
|
||||
.isEqualTo(ah);
|
||||
assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "1.0%", appType.getId()).getContent())
|
||||
.hasSize(2);
|
||||
|
||||
// no we search with on entity marked as deleted
|
||||
softwareManagement.deleteSoftwareModule(
|
||||
softwareManagement.findSoftwareModuleByAssignedToAndType(pageReq, ds, appType).getContent().get(0));
|
||||
softwareModuleRepository.findByAssignedToAndType(pageReq, ds, appType).getContent().get(0).getId());
|
||||
|
||||
assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "1.0%", appType).getContent()).hasSize(1);
|
||||
assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "1.0%", appType).getContent().get(0))
|
||||
assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "1.0%", appType.getId()).getContent())
|
||||
.hasSize(1);
|
||||
assertThat(softwareManagement.findSoftwareModuleByFilters(pageReq, "1.0%", appType.getId()).getContent().get(0))
|
||||
.isEqualTo(ah);
|
||||
}
|
||||
|
||||
@@ -294,11 +299,11 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTestWithMongoD
|
||||
final SoftwareModule two = softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(osType, "two", "two", null, ""));
|
||||
// ignored
|
||||
softwareManagement.deleteSoftwareModule(
|
||||
softwareManagement.createSoftwareModule(new JpaSoftwareModule(osType, "deleted", "deleted", null, "")));
|
||||
softwareManagement.deleteSoftwareModule(softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(osType, "deleted", "deleted", null, "")).getId());
|
||||
softwareManagement.createSoftwareModule(new JpaSoftwareModule(appType, "three", "3.0.2", null, ""));
|
||||
|
||||
assertThat(softwareManagement.findSoftwareModulesByType(pageReq, osType).getContent())
|
||||
assertThat(softwareManagement.findSoftwareModulesByType(pageReq, osType.getId()).getContent())
|
||||
.as("Expected to find the following number of modules:").hasSize(2).as("with the following elements")
|
||||
.contains(two, one);
|
||||
}
|
||||
@@ -310,29 +315,13 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTestWithMongoD
|
||||
softwareManagement.createSoftwareModule(new JpaSoftwareModule(osType, "one", "one", null, ""));
|
||||
softwareManagement.createSoftwareModule(new JpaSoftwareModule(appType, "two", "two", null, ""));
|
||||
// ignored
|
||||
softwareManagement.deleteSoftwareModule(
|
||||
softwareManagement.createSoftwareModule(new JpaSoftwareModule(osType, "deleted", "deleted", null, "")));
|
||||
softwareManagement.deleteSoftwareModule(softwareManagement
|
||||
.createSoftwareModule(new JpaSoftwareModule(osType, "deleted", "deleted", null, "")).getId());
|
||||
|
||||
assertThat(softwareManagement.countSoftwareModulesAll()).as("Expected to find the following number of modules:")
|
||||
.isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Counts for software modules by type.")
|
||||
public void countSoftwareModulesByType() {
|
||||
// found in test
|
||||
softwareManagement.createSoftwareModule(new JpaSoftwareModule(osType, "one", "one", null, ""));
|
||||
softwareManagement.createSoftwareModule(new JpaSoftwareModule(osType, "two", "two", null, ""));
|
||||
|
||||
// ignored
|
||||
softwareManagement.deleteSoftwareModule(
|
||||
softwareManagement.createSoftwareModule(new JpaSoftwareModule(osType, "deleted", "deleted", null, "")));
|
||||
softwareManagement.createSoftwareModule(new JpaSoftwareModule(appType, "three", "3.0.2", null, ""));
|
||||
|
||||
assertThat(softwareManagement.countSoftwareModulesByType(osType))
|
||||
.as("Expected to find the following number of modules:").isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Tests the successfull deletion of software module types. Both unused (hard delete) and used ones (soft delete).")
|
||||
public void deleteAssignedAndUnassignedSoftwareModuleTypes() {
|
||||
@@ -382,7 +371,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTestWithMongoD
|
||||
final Artifact artifact2 = artifactsIt.next();
|
||||
|
||||
// [STEP2]: Delete unassigned SoftwareModule
|
||||
softwareManagement.deleteSoftwareModule(unassignedModule);
|
||||
softwareManagement.deleteSoftwareModule(unassignedModule.getId());
|
||||
|
||||
// [VERIFY EXPECTED RESULT]:
|
||||
// verify: SoftwareModule is deleted
|
||||
@@ -412,7 +401,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTestWithMongoD
|
||||
distributionSetManagement.assignSoftwareModules(disSet, Sets.newHashSet(assignedModule));
|
||||
|
||||
// [STEP3]: Delete the assigned SoftwareModule
|
||||
softwareManagement.deleteSoftwareModule(assignedModule);
|
||||
softwareManagement.deleteSoftwareModule(assignedModule.getId());
|
||||
|
||||
// [VERIFY EXPECTED RESULT]:
|
||||
// verify: assignedModule is marked as deleted
|
||||
@@ -454,7 +443,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTestWithMongoD
|
||||
distributionSetManagement.deleteDistributionSet(disSet);
|
||||
|
||||
// [STEP5]: Delete the assigned SoftwareModule
|
||||
softwareManagement.deleteSoftwareModule(assignedModule);
|
||||
softwareManagement.deleteSoftwareModule(assignedModule.getId());
|
||||
|
||||
// [VERIFY EXPECTED RESULT]:
|
||||
// verify: assignedModule is marked as deleted
|
||||
@@ -488,7 +477,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTestWithMongoD
|
||||
SoftwareModule moduleX = createSoftwareModuleWithArtifacts(osType, "modulex", "v1.0", 0);
|
||||
|
||||
// [STEP2]: Create newArtifactX and add it to SoftwareModuleX
|
||||
artifactManagement.createLocalArtifact(new ByteArrayInputStream(source), moduleX.getId(), "artifactx", false);
|
||||
artifactManagement.createArtifact(new ByteArrayInputStream(source), moduleX.getId(), "artifactx", false);
|
||||
moduleX = softwareManagement.findSoftwareModuleWithDetails(moduleX.getId());
|
||||
final Artifact artifactX = moduleX.getArtifacts().iterator().next();
|
||||
|
||||
@@ -496,7 +485,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTestWithMongoD
|
||||
SoftwareModule moduleY = createSoftwareModuleWithArtifacts(osType, "moduley", "v1.0", 0);
|
||||
|
||||
// [STEP4]: Assign the same ArtifactX to SoftwareModuleY
|
||||
artifactManagement.createLocalArtifact(new ByteArrayInputStream(source), moduleY.getId(), "artifactx", false);
|
||||
artifactManagement.createArtifact(new ByteArrayInputStream(source), moduleY.getId(), "artifactx", false);
|
||||
moduleY = softwareManagement.findSoftwareModuleWithDetails(moduleY.getId());
|
||||
final Artifact artifactY = moduleY.getArtifacts().iterator().next();
|
||||
|
||||
@@ -504,7 +493,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTestWithMongoD
|
||||
assertThat(operations.find(new Query())).hasSize(1);
|
||||
|
||||
// [STEP5]: Delete SoftwareModuleX
|
||||
softwareManagement.deleteSoftwareModule(moduleX);
|
||||
softwareManagement.deleteSoftwareModule(moduleX.getId());
|
||||
|
||||
// [VERIFY EXPECTED RESULT]:
|
||||
// verify: SoftwareModuleX is deleted, and ModuelY still exists
|
||||
@@ -540,14 +529,14 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTestWithMongoD
|
||||
// [STEP1]: Create SoftwareModuleX and add a new ArtifactX
|
||||
SoftwareModule moduleX = createSoftwareModuleWithArtifacts(osType, "modulex", "v1.0", 0);
|
||||
|
||||
artifactManagement.createLocalArtifact(new ByteArrayInputStream(source), moduleX.getId(), "artifactx", false);
|
||||
artifactManagement.createArtifact(new ByteArrayInputStream(source), moduleX.getId(), "artifactx", false);
|
||||
moduleX = softwareManagement.findSoftwareModuleWithDetails(moduleX.getId());
|
||||
final Artifact artifactX = moduleX.getArtifacts().iterator().next();
|
||||
|
||||
// [STEP2]: Create SoftwareModuleY and add the same ArtifactX
|
||||
SoftwareModule moduleY = createSoftwareModuleWithArtifacts(osType, "moduley", "v1.0", 0);
|
||||
|
||||
artifactManagement.createLocalArtifact(new ByteArrayInputStream(source), moduleY.getId(), "artifactx", false);
|
||||
artifactManagement.createArtifact(new ByteArrayInputStream(source), moduleY.getId(), "artifactx", false);
|
||||
moduleY = softwareManagement.findSoftwareModuleWithDetails(moduleY.getId());
|
||||
final Artifact artifactY = moduleY.getArtifacts().iterator().next();
|
||||
|
||||
@@ -563,10 +552,10 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTestWithMongoD
|
||||
deploymentManagement.assignDistributionSet(disSetY, Lists.newArrayList(target));
|
||||
|
||||
// [STEP5]: Delete SoftwareModuleX
|
||||
softwareManagement.deleteSoftwareModule(moduleX);
|
||||
softwareManagement.deleteSoftwareModule(moduleX.getId());
|
||||
|
||||
// [STEP6]: Delete SoftwareModuleY
|
||||
softwareManagement.deleteSoftwareModule(moduleY);
|
||||
softwareManagement.deleteSoftwareModule(moduleY.getId());
|
||||
|
||||
// [VERIFY EXPECTED RESULT]:
|
||||
moduleX = softwareManagement.findSoftwareModuleById(moduleX.getId());
|
||||
@@ -597,7 +586,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTestWithMongoD
|
||||
new JpaSoftwareModule(type, name, version, "description of artifact " + name, ""));
|
||||
|
||||
for (int i = 0; i < numberArtifacts; i++) {
|
||||
artifactManagement.createLocalArtifact(new RandomGeneratedInputStream(5 * 1024), softwareModule.getId(),
|
||||
artifactManagement.createArtifact(new RandomGeneratedInputStream(5 * 1024), softwareModule.getId(),
|
||||
"file" + (i + 1), false);
|
||||
}
|
||||
|
||||
@@ -622,16 +611,16 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTestWithMongoD
|
||||
assertThat(artifactRepository.findAll()).hasSize(results.length);
|
||||
for (final Artifact result : results) {
|
||||
assertThat(result.getId()).isNotNull();
|
||||
assertThat(operations.findOne(new Query()
|
||||
.addCriteria(Criteria.where("filename").is(((JpaLocalArtifact) result).getGridFsFileName()))))
|
||||
assertThat(operations.findOne(
|
||||
new Query().addCriteria(Criteria.where("filename").is(((JpaArtifact) result).getGridFsFileName()))))
|
||||
.isNotNull();
|
||||
}
|
||||
}
|
||||
|
||||
private void assertArtfiactNull(final Artifact... results) {
|
||||
for (final Artifact result : results) {
|
||||
assertThat(operations.findOne(new Query()
|
||||
.addCriteria(Criteria.where("filename").is(((JpaLocalArtifact) result).getGridFsFileName()))))
|
||||
assertThat(operations.findOne(
|
||||
new Query().addCriteria(Criteria.where("filename").is(((JpaArtifact) result).getGridFsFileName()))))
|
||||
.isNull();
|
||||
}
|
||||
}
|
||||
@@ -664,18 +653,18 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTestWithMongoD
|
||||
|
||||
final DistributionSet set = distributionSetManagement.createDistributionSet(new JpaDistributionSet("set", "1",
|
||||
"desc", testDsType, Lists.newArrayList(one, two, deleted, four, differentName)));
|
||||
softwareManagement.deleteSoftwareModule(deleted);
|
||||
softwareManagement.deleteSoftwareModule(deleted.getId());
|
||||
|
||||
// with filter on name, version and module type
|
||||
assertThat(softwareManagement.findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(pageReq,
|
||||
set.getId(), "found", testType).getContent())
|
||||
set.getId(), "found", testType.getId()).getContent())
|
||||
.as("Found modules with given name, given module type and the assigned ones first")
|
||||
.containsExactly(new AssignedSoftwareModule(one, true), new AssignedSoftwareModule(two, true),
|
||||
new AssignedSoftwareModule(unassigned, false));
|
||||
|
||||
// with filter on module type only
|
||||
assertThat(softwareManagement.findSoftwareModuleOrderBySetAssignmentAndModuleNameAscModuleVersionAsc(pageReq,
|
||||
set.getId(), null, testType).getContent())
|
||||
set.getId(), null, testType.getId()).getContent())
|
||||
.as("Found modules with given module type and the assigned ones first").containsExactly(
|
||||
new AssignedSoftwareModule(differentName, true), new AssignedSoftwareModule(one, true),
|
||||
new AssignedSoftwareModule(two, true), new AssignedSoftwareModule(unassigned, false));
|
||||
@@ -715,12 +704,12 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTestWithMongoD
|
||||
.createSoftwareModule(new JpaSoftwareModule(testType, "deleted", "deleted", null, ""));
|
||||
distributionSetManagement.createDistributionSet(new JpaDistributionSet("set", "1", "desc", testDsType,
|
||||
Lists.newArrayList(one, two, deleted, four, differentName)));
|
||||
softwareManagement.deleteSoftwareModule(deleted);
|
||||
softwareManagement.deleteSoftwareModule(deleted.getId());
|
||||
|
||||
// test
|
||||
assertThat(softwareManagement.countSoftwareModuleByFilters("found", testType))
|
||||
assertThat(softwareManagement.countSoftwareModuleByFilters("found", testType.getId()))
|
||||
.as("Number of modules with given name or version and type").isEqualTo(3);
|
||||
assertThat(softwareManagement.countSoftwareModuleByFilters(null, testType))
|
||||
assertThat(softwareManagement.countSoftwareModuleByFilters(null, testType.getId()))
|
||||
.as("Number of modules with given type").isEqualTo(4);
|
||||
assertThat(softwareManagement.countSoftwareModuleByFilters(null, null)).as("Number of modules overall")
|
||||
.isEqualTo(5);
|
||||
@@ -742,7 +731,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTestWithMongoD
|
||||
.createSoftwareModule(new JpaSoftwareModule(testType, "deleted", "deleted", null, ""));
|
||||
distributionSetManagement.createDistributionSet(
|
||||
new JpaDistributionSet("set", "1", "desc", testDsType, Lists.newArrayList(deleted, four)));
|
||||
softwareManagement.deleteSoftwareModule(deleted);
|
||||
softwareManagement.deleteSoftwareModule(deleted.getId());
|
||||
|
||||
assertThat(softwareManagement.countSoftwareModulesAll()).as("Number of undeleted modules").isEqualTo(1);
|
||||
assertThat(softwareModuleRepository.count()).as("Number of all modules").isEqualTo(2);
|
||||
@@ -829,7 +818,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTestWithMongoD
|
||||
.createSoftwareModule(new JpaSoftwareModule(testType, "deleted", "deleted", null, ""));
|
||||
final DistributionSet set = distributionSetManagement.createDistributionSet(
|
||||
new JpaDistributionSet("set", "1", "desc", testDsType, Lists.newArrayList(one, deleted)));
|
||||
softwareManagement.deleteSoftwareModule(deleted);
|
||||
softwareManagement.deleteSoftwareModule(deleted.getId());
|
||||
|
||||
assertThat(softwareManagement.findSoftwareModuleByAssignedTo(pageReq, set).getContent())
|
||||
.as("Found this number of modules").hasSize(2);
|
||||
@@ -950,7 +939,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTestWithMongoD
|
||||
.as("Contains the created metadata element")
|
||||
.containsExactly(new JpaSoftwareModuleMetadata(knownKey1, ah, knownValue1));
|
||||
|
||||
softwareManagement.deleteSoftwareModuleMetadata(ah, knownKey1);
|
||||
softwareManagement.deleteSoftwareModuleMetadata(ah.getId(), knownKey1);
|
||||
assertThat(softwareManagement.findSoftwareModuleById(ah.getId()).getMetadata()).as("Metadata elemenets are")
|
||||
.isEmpty();
|
||||
}
|
||||
@@ -968,7 +957,7 @@ public class SoftwareManagementTest extends AbstractJpaIntegrationTestWithMongoD
|
||||
.getSoftwareModule();
|
||||
|
||||
try {
|
||||
softwareManagement.findSoftwareModuleMetadata(ah, "doesnotexist");
|
||||
softwareManagement.findSoftwareModuleMetadata(ah.getId(), "doesnotexist");
|
||||
fail("should not have worked as module metadata with that key does not exist");
|
||||
} catch (final EntityNotFoundException e) {
|
||||
|
||||
|
||||
@@ -136,14 +136,14 @@ public class SystemManagementTest extends AbstractJpaIntegrationTestWithMongoDB
|
||||
"version 1", null, null);
|
||||
sm = softwareModuleRepository.save(sm);
|
||||
|
||||
artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", false);
|
||||
artifactManagement.createArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", false);
|
||||
}
|
||||
|
||||
private void createDeletedTestArtifact(final byte[] random) {
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet("deleted garbage", true);
|
||||
ds.getModules().stream().forEach(module -> {
|
||||
artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), module.getId(), "file1", false);
|
||||
softwareManagement.deleteSoftwareModule(module);
|
||||
artifactManagement.createArtifact(new ByteArrayInputStream(random), module.getId(), "file1", false);
|
||||
softwareManagement.deleteSoftwareModule(module.getId());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,6 @@ import org.eclipse.hawkbit.repository.model.BaseEntity;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
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.NamedEntity;
|
||||
import org.eclipse.hawkbit.repository.model.NamedVersionedEntity;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
@@ -306,19 +305,19 @@ public class TestdataFactory {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates {@link LocalArtifact}s for given {@link SoftwareModule} with a
|
||||
* small text payload.
|
||||
* Creates {@link Artifact}s for given {@link SoftwareModule} with a small
|
||||
* text payload.
|
||||
*
|
||||
* @param moduleId
|
||||
* the {@link Artifact}s belong to.
|
||||
*
|
||||
* @return {@link LocalArtifact} entity.
|
||||
* @return {@link Artifact} entity.
|
||||
*/
|
||||
public List<LocalArtifact> createLocalArtifacts(final Long moduleId) {
|
||||
final List<LocalArtifact> artifacts = new ArrayList<>();
|
||||
public List<Artifact> createArtifacts(final Long moduleId) {
|
||||
final List<Artifact> artifacts = new ArrayList<>();
|
||||
for (int i = 0; i < 3; i++) {
|
||||
final InputStream stubInputStream = IOUtils.toInputStream("some test data" + i, Charset.forName("UTF-8"));
|
||||
artifacts.add(artifactManagement.createLocalArtifact(stubInputStream, moduleId, "filename" + i, false));
|
||||
artifacts.add(artifactManagement.createArtifact(stubInputStream, moduleId, "filename" + i, false));
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user