JpaSoftwareModule#metadata made map (#2412)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -26,6 +26,7 @@ import org.eclipse.hawkbit.mgmt.json.model.softwaremodule.MgmtSoftwareModuleRequ
|
||||
import org.eclipse.hawkbit.mgmt.json.model.softwaremodule.MgmtSoftwareModuleRequestBodyPut;
|
||||
import org.eclipse.hawkbit.rest.json.model.ExceptionInfo;
|
||||
import org.springframework.hateoas.MediaTypes;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
@@ -37,6 +38,7 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RequestPart;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
@@ -55,7 +57,7 @@ public interface MgmtSoftwareModuleRestApi {
|
||||
* @param optionalFileName to override {@link MultipartFile#getOriginalFilename()}
|
||||
* @param md5Sum checksum for uploaded content check
|
||||
* @param sha1Sum checksum for uploaded content check
|
||||
* @param sha256sum checksum for uploaded content check
|
||||
* @param sha256Sum checksum for uploaded content check
|
||||
* @return In case all sets could successful be created the ResponseEntity with status code 201 - Created but without ResponseBody. In any
|
||||
* failure the JsonResponseExceptionHandler is handling the response.
|
||||
*/
|
||||
@@ -387,16 +389,49 @@ public interface MgmtSoftwareModuleRestApi {
|
||||
@DeleteMapping(value = MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING + "/{softwareModuleId}")
|
||||
ResponseEntity<Void> deleteSoftwareModule(@PathVariable("softwareModuleId") Long softwareModuleId);
|
||||
|
||||
/**
|
||||
* Creates a list of metadata for a specific software module.
|
||||
*
|
||||
* @param softwareModuleId the ID of the distribution set to create metadata for
|
||||
* @param metadataRest the list of metadata entries to create
|
||||
* @return status created if post request is successful with the value of the created metadata
|
||||
*/
|
||||
@Operation(summary = "Creates a list of metadata for a specific Software Module", description = "Create a list of metadata entries Required Permission: UPDATE_REPOSITORY")
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(responseCode = "201", description = "Successfully created"),
|
||||
@ApiResponse(responseCode = "400", description = "Bad Request - e.g. invalid parameters",
|
||||
content = @Content(mediaType = "application/json", schema = @Schema(implementation = ExceptionInfo.class))),
|
||||
@ApiResponse(responseCode = "401", description = "The request requires user authentication.",
|
||||
content = @Content(mediaType = "application/json", schema = @Schema(hidden = true))),
|
||||
@ApiResponse(responseCode = "403",
|
||||
description = "Insufficient permissions, entity is not allowed to be changed (i.e. read-only) or " +
|
||||
"data volume restriction applies.",
|
||||
content = @Content(mediaType = "application/json", schema = @Schema(hidden = true))),
|
||||
@ApiResponse(responseCode = "404", description = "Software Module not found", content = @Content(mediaType = "application/json", schema = @Schema(hidden = true))),
|
||||
@ApiResponse(responseCode = "405", description = "The http request method is not allowed on the resource.",
|
||||
content = @Content(mediaType = "application/json", schema = @Schema(hidden = true))),
|
||||
@ApiResponse(responseCode = "406", description = "In case accept header is specified and not application/json.",
|
||||
content = @Content(mediaType = "application/json", schema = @Schema(hidden = true))),
|
||||
@ApiResponse(responseCode = "409", description = "E.g. in case an entity is created or modified by another " +
|
||||
"user in another request at the same time. You may retry your modification request.",
|
||||
content = @Content(mediaType = "application/json", schema = @Schema(hidden = true))),
|
||||
@ApiResponse(responseCode = "415", description = "The request was attempt with a media-type which is not " +
|
||||
"supported by the server for this resource.",
|
||||
content = @Content(mediaType = "application/json", schema = @Schema(hidden = true))),
|
||||
@ApiResponse(responseCode = "429", description = "Too many requests. The server will refuse further attempts " +
|
||||
"and the client has to wait another second.",
|
||||
content = @Content(mediaType = "application/json", schema = @Schema(hidden = true)))
|
||||
})
|
||||
@PostMapping(value = MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING + "/{softwareModuleId}/metadata",
|
||||
consumes = { MediaType.APPLICATION_JSON_VALUE, MediaTypes.HAL_JSON_VALUE })
|
||||
@ResponseStatus(HttpStatus.CREATED)
|
||||
void createMetadata(@PathVariable("softwareModuleId") Long softwareModuleId, @RequestBody List<MgmtSoftwareModuleMetadata> metadataRest);
|
||||
|
||||
/**
|
||||
* Gets a paged list of metadata for a software module.
|
||||
*
|
||||
* @param softwareModuleId the ID of the software module for the metadata
|
||||
* @param pagingOffsetParam the offset of list of metadata for pagination, might not be present in the rest request then default value will
|
||||
* be applied
|
||||
* @param pagingLimitParam the limit of the paged request, might not be present in the rest request then default value will be applied
|
||||
* @param sortParam the sorting parameter in the request URL, syntax {@code field:direction, field:direction}
|
||||
* @param rsqlParam the search parameter in the request URL, syntax {@code q=key==abc}
|
||||
* @return status OK if get request is successful with the paged list of metadata
|
||||
* @return status OK with the paged list of metadata, if the request is successful
|
||||
*/
|
||||
@Operation(summary = "Return metadata for a Software Module", description = "Get a paged list of metadata for a software module. Required Permission: READ_REPOSITORY")
|
||||
@ApiResponses(value = {
|
||||
@@ -421,30 +456,7 @@ public interface MgmtSoftwareModuleRestApi {
|
||||
})
|
||||
@GetMapping(value = MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING + "/{softwareModuleId}/metadata",
|
||||
produces = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE })
|
||||
ResponseEntity<PagedList<MgmtSoftwareModuleMetadata>> getMetadata(
|
||||
@PathVariable("softwareModuleId") Long softwareModuleId,
|
||||
@RequestParam(
|
||||
value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET,
|
||||
defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET)
|
||||
@Schema(description = "The paging offset (default is 0)")
|
||||
int pagingOffsetParam,
|
||||
@RequestParam(
|
||||
value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT,
|
||||
defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT)
|
||||
@Schema(description = "The maximum number of entries in a page (default is 50)")
|
||||
int pagingLimitParam,
|
||||
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SORTING, required = false)
|
||||
@Schema(description = """
|
||||
The query parameter sort allows to define the sort order for the result of a query. A sort criteria
|
||||
consists of the name of a field and the sort direction (ASC for ascending and DESC descending).
|
||||
The sequence of the sort criteria (multiple can be used) defines the sort order of the entities
|
||||
in the result.""")
|
||||
String sortParam,
|
||||
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SEARCH, required = false)
|
||||
@Schema(description = """
|
||||
Query fields based on the Feed Item Query Language (FIQL). See Entity Definitions for
|
||||
available fields.""")
|
||||
String rsqlParam);
|
||||
ResponseEntity<PagedList<MgmtSoftwareModuleMetadata>> getMetadata(@PathVariable("softwareModuleId") Long softwareModuleId);
|
||||
|
||||
/**
|
||||
* Gets a single metadata value for a specific key of a software module.
|
||||
@@ -486,7 +498,6 @@ public interface MgmtSoftwareModuleRestApi {
|
||||
* @param softwareModuleId the ID of the software module to update the metadata entry
|
||||
* @param metadataKey the key of the metadata to update the value
|
||||
* @param metadata body to update
|
||||
* @return status OK if the update request is successful and the updated metadata result
|
||||
*/
|
||||
@Operation(summary = "Update a single metadata value of a Software Module", description = "Update a single metadata value for speficic key. Required Permission: UPDATE_REPOSITORY")
|
||||
@ApiResponses(value = {
|
||||
@@ -508,9 +519,9 @@ public interface MgmtSoftwareModuleRestApi {
|
||||
"and the client has to wait another second.",
|
||||
content = @Content(mediaType = "application/json", schema = @Schema(hidden = true)))
|
||||
})
|
||||
@PutMapping(value = MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING + "/{softwareModuleId}/metadata/{metadataKey}",
|
||||
produces = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE })
|
||||
ResponseEntity<MgmtSoftwareModuleMetadata> updateMetadata(
|
||||
@PutMapping(value = MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING + "/{softwareModuleId}/metadata/{metadataKey}")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
void updateMetadata(
|
||||
@PathVariable("softwareModuleId") Long softwareModuleId,
|
||||
@PathVariable("metadataKey") String metadataKey,
|
||||
@RequestBody MgmtSoftwareModuleMetadataBodyPut metadata);
|
||||
@@ -520,7 +531,6 @@ public interface MgmtSoftwareModuleRestApi {
|
||||
*
|
||||
* @param softwareModuleId the ID of the software module to delete the metadata entry
|
||||
* @param metadataKey the key of the metadata to delete
|
||||
* @return status OK if the delete request is successful
|
||||
*/
|
||||
@Operation(summary = "Delete single metadata entry from the software module", description = "Delete a single metadata. Required Permission: UPDATE_REPOSITORY")
|
||||
@ApiResponses(value = {
|
||||
@@ -543,47 +553,6 @@ public interface MgmtSoftwareModuleRestApi {
|
||||
content = @Content(mediaType = "application/json", schema = @Schema(hidden = true)))
|
||||
})
|
||||
@DeleteMapping(value = MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING + "/{softwareModuleId}/metadata/{metadataKey}")
|
||||
ResponseEntity<Void> deleteMetadata(
|
||||
@PathVariable("softwareModuleId") Long softwareModuleId,
|
||||
@PathVariable("metadataKey") String metadataKey);
|
||||
|
||||
/**
|
||||
* Creates a list of metadata for a specific software module.
|
||||
*
|
||||
* @param softwareModuleId the ID of the distribution set to create metadata for
|
||||
* @param metadataRest the list of metadata entries to create
|
||||
* @return status created if post request is successful with the value of the created metadata
|
||||
*/
|
||||
@Operation(summary = "Creates a list of metadata for a specific Software Module", description = "Create a list of metadata entries Required Permission: UPDATE_REPOSITORY")
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(responseCode = "201", description = "Successfully created"),
|
||||
@ApiResponse(responseCode = "400", description = "Bad Request - e.g. invalid parameters",
|
||||
content = @Content(mediaType = "application/json", schema = @Schema(implementation = ExceptionInfo.class))),
|
||||
@ApiResponse(responseCode = "401", description = "The request requires user authentication.",
|
||||
content = @Content(mediaType = "application/json", schema = @Schema(hidden = true))),
|
||||
@ApiResponse(responseCode = "403",
|
||||
description = "Insufficient permissions, entity is not allowed to be changed (i.e. read-only) or " +
|
||||
"data volume restriction applies.",
|
||||
content = @Content(mediaType = "application/json", schema = @Schema(hidden = true))),
|
||||
@ApiResponse(responseCode = "404", description = "Software Module not found", content = @Content(mediaType = "application/json", schema = @Schema(hidden = true))),
|
||||
@ApiResponse(responseCode = "405", description = "The http request method is not allowed on the resource.",
|
||||
content = @Content(mediaType = "application/json", schema = @Schema(hidden = true))),
|
||||
@ApiResponse(responseCode = "406", description = "In case accept header is specified and not application/json.",
|
||||
content = @Content(mediaType = "application/json", schema = @Schema(hidden = true))),
|
||||
@ApiResponse(responseCode = "409", description = "E.g. in case an entity is created or modified by another " +
|
||||
"user in another request at the same time. You may retry your modification request.",
|
||||
content = @Content(mediaType = "application/json", schema = @Schema(hidden = true))),
|
||||
@ApiResponse(responseCode = "415", description = "The request was attempt with a media-type which is not " +
|
||||
"supported by the server for this resource.",
|
||||
content = @Content(mediaType = "application/json", schema = @Schema(hidden = true))),
|
||||
@ApiResponse(responseCode = "429", description = "Too many requests. The server will refuse further attempts " +
|
||||
"and the client has to wait another second.",
|
||||
content = @Content(mediaType = "application/json", schema = @Schema(hidden = true)))
|
||||
})
|
||||
@PostMapping(value = MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING + "/{softwareModuleId}/metadata",
|
||||
consumes = { MediaType.APPLICATION_JSON_VALUE, MediaTypes.HAL_JSON_VALUE },
|
||||
produces = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE })
|
||||
ResponseEntity<List<MgmtSoftwareModuleMetadata>> createMetadata(
|
||||
@PathVariable("softwareModuleId") Long softwareModuleId,
|
||||
@RequestBody List<MgmtSoftwareModuleMetadata> metadataRest);
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
void deleteMetadata(@PathVariable("softwareModuleId") Long softwareModuleId, @PathVariable("metadataKey") String metadataKey);
|
||||
}
|
||||
@@ -33,7 +33,6 @@ import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.builder.DistributionSetCreate;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult;
|
||||
import org.eclipse.hawkbit.repository.model.MetaData;
|
||||
import org.eclipse.hawkbit.rest.json.model.ResponseList;
|
||||
|
||||
/**
|
||||
|
||||
@@ -117,15 +117,10 @@ public final class MgmtSoftwareModuleMapper {
|
||||
static void addLinks(final SoftwareModule softwareModule, final MgmtSoftwareModule response) {
|
||||
response.add(linkTo(methodOn(MgmtSoftwareModuleRestApi.class).getArtifacts(response.getId(), null, null))
|
||||
.withRel(MgmtRestConstants.SOFTWAREMODULE_V1_ARTIFACT).expand());
|
||||
|
||||
response.add(linkTo(
|
||||
methodOn(MgmtSoftwareModuleTypeRestApi.class).getSoftwareModuleType(softwareModule.getType().getId()))
|
||||
response.add(linkTo(methodOn(MgmtSoftwareModuleTypeRestApi.class).getSoftwareModuleType(softwareModule.getType().getId()))
|
||||
.withRel(MgmtRestConstants.SOFTWAREMODULE_V1_TYPE).expand());
|
||||
|
||||
response.add(linkTo(methodOn(MgmtSoftwareModuleResource.class).getMetadata(response.getId(),
|
||||
MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET_VALUE,
|
||||
MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE, null, null)).withRel("metadata")
|
||||
.expand().expand());
|
||||
response.add(linkTo(methodOn(MgmtSoftwareModuleResource.class).getMetadata(response.getId()))
|
||||
.withRel("metadata").expand());
|
||||
}
|
||||
|
||||
static MgmtArtifact toResponse(final Artifact artifact) {
|
||||
|
||||
@@ -14,6 +14,7 @@ import java.io.InputStream;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import jakarta.validation.ValidationException;
|
||||
@@ -234,62 +235,42 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<PagedList<MgmtSoftwareModuleMetadata>> getMetadata(
|
||||
final Long softwareModuleId,
|
||||
final int pagingOffsetParam, final int pagingLimitParam, final String sortParam, final String rsqlParam) {
|
||||
public void createMetadata(final Long softwareModuleId, final List<MgmtSoftwareModuleMetadata> metadataRest) {
|
||||
softwareModuleManagement.createMetadata(MgmtSoftwareModuleMapper.fromRequestSwMetadata(entityFactory, softwareModuleId, metadataRest));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<PagedList<MgmtSoftwareModuleMetadata>> getMetadata(final Long softwareModuleId) {
|
||||
// check if software module exists otherwise throw exception immediately
|
||||
findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null);
|
||||
|
||||
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
|
||||
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
|
||||
final Sort sorting = PagingUtility.sanitizeSoftwareModuleMetadataSortParam(sortParam);
|
||||
|
||||
final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
|
||||
final Page<SoftwareModuleMetadata> metaDataPage;
|
||||
|
||||
if (rsqlParam != null) {
|
||||
metaDataPage = softwareModuleManagement.findMetaDataByRsql(softwareModuleId, rsqlParam, pageable);
|
||||
} else {
|
||||
metaDataPage = softwareModuleManagement.findMetaDataBySoftwareModuleId(pageable, softwareModuleId);
|
||||
}
|
||||
|
||||
return ResponseEntity
|
||||
.ok(new PagedList<>(MgmtSoftwareModuleMapper.toResponseSwMetadata(metaDataPage.getContent()), metaDataPage.getTotalElements()));
|
||||
final List<SoftwareModuleMetadata> metadata = softwareModuleManagement.getMetadata(softwareModuleId);
|
||||
return ResponseEntity.ok(new PagedList<>(MgmtSoftwareModuleMapper.toResponseSwMetadata(metadata), metadata.size()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<MgmtSoftwareModuleMetadata> getMetadataValue(final Long softwareModuleId, final String metadataKey) {
|
||||
final SoftwareModuleMetadata findOne = softwareModuleManagement
|
||||
.findMetaDataBySoftwareModuleId(softwareModuleId, metadataKey).orElseThrow(
|
||||
() -> new EntityNotFoundException(SoftwareModuleMetadata.class, softwareModuleId, metadataKey));
|
||||
final SoftwareModuleMetadata findOne = softwareModuleManagement.getMetadata(softwareModuleId).stream()
|
||||
.filter(entry -> entry.getKey().equals(metadataKey))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new EntityNotFoundException("SoftwareModule metadata", softwareModuleId + ":" + metadataKey));
|
||||
|
||||
return ResponseEntity.ok(MgmtSoftwareModuleMapper.toResponseSwMetadata(findOne));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<MgmtSoftwareModuleMetadata> updateMetadata(
|
||||
final Long softwareModuleId, final String metadataKey, final MgmtSoftwareModuleMetadataBodyPut metadata) {
|
||||
final SoftwareModuleMetadata updated = softwareModuleManagement
|
||||
.updateMetaData(entityFactory.softwareModuleMetadata().update(softwareModuleId, metadataKey)
|
||||
.value(metadata.getValue()).targetVisible(metadata.getTargetVisible()));
|
||||
|
||||
return ResponseEntity.ok(MgmtSoftwareModuleMapper.toResponseSwMetadata(updated));
|
||||
public void updateMetadata(final Long softwareModuleId, final String metadataKey, final MgmtSoftwareModuleMetadataBodyPut metadata) {
|
||||
softwareModuleManagement.updateMetadata(
|
||||
entityFactory.softwareModuleMetadata()
|
||||
.update(softwareModuleId, metadataKey)
|
||||
.value(metadata.getValue())
|
||||
.targetVisible(metadata.getTargetVisible()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@AuditLog(entity = "SoftwareModule", type = AuditLog.Type.DELETE, description = "Delete Software Module Metadata")
|
||||
public ResponseEntity<Void> deleteMetadata(final Long softwareModuleId, final String metadataKey) {
|
||||
softwareModuleManagement.deleteMetaData(softwareModuleId, metadataKey);
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<List<MgmtSoftwareModuleMetadata>> createMetadata(
|
||||
final Long softwareModuleId, final List<MgmtSoftwareModuleMetadata> metadataRest) {
|
||||
final List<SoftwareModuleMetadata> created = softwareModuleManagement.putMetaData(
|
||||
MgmtSoftwareModuleMapper.fromRequestSwMetadata(entityFactory, softwareModuleId, metadataRest));
|
||||
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(MgmtSoftwareModuleMapper.toResponseSwMetadata(created));
|
||||
public void deleteMetadata(final Long softwareModuleId, final String metadataKey) {
|
||||
softwareModuleManagement.deleteMetadata(softwareModuleId, metadataKey);
|
||||
}
|
||||
|
||||
private static MgmtRepresentationMode parseRepresentationMode(final String representationModeParam) {
|
||||
|
||||
@@ -19,7 +19,6 @@ import org.eclipse.hawkbit.repository.DistributionSetTypeFields;
|
||||
import org.eclipse.hawkbit.repository.RolloutFields;
|
||||
import org.eclipse.hawkbit.repository.RolloutGroupFields;
|
||||
import org.eclipse.hawkbit.repository.SoftwareModuleFields;
|
||||
import org.eclipse.hawkbit.repository.SoftwareModuleMetadataFields;
|
||||
import org.eclipse.hawkbit.repository.SoftwareModuleTypeFields;
|
||||
import org.eclipse.hawkbit.repository.TagFields;
|
||||
import org.eclipse.hawkbit.repository.TargetFields;
|
||||
@@ -132,22 +131,6 @@ public final class PagingUtility {
|
||||
return Sort.by(SortUtility.parse(ActionStatusFields.class, sortParam));
|
||||
}
|
||||
|
||||
public static Sort sanitizeMetadataSortParam(final String sortParam) {
|
||||
if (sortParam == null) {
|
||||
// default
|
||||
return Sort.by(Direction.ASC, SoftwareModuleMetadataFields.KEY.getJpaEntityFieldName());
|
||||
}
|
||||
return Sort.by(SortUtility.parse(SoftwareModuleMetadataFields.class, sortParam));
|
||||
}
|
||||
|
||||
public static Sort sanitizeSoftwareModuleMetadataSortParam(final String sortParam) {
|
||||
if (sortParam == null) {
|
||||
// default
|
||||
return Sort.by(Direction.ASC, SoftwareModuleMetadataFields.KEY.getJpaEntityFieldName());
|
||||
}
|
||||
return Sort.by(SortUtility.parse(SoftwareModuleMetadataFields.class, sortParam));
|
||||
}
|
||||
|
||||
public static Sort sanitizeRolloutSortParam(final String sortParam) {
|
||||
if (sortParam == null) {
|
||||
// default
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
package org.eclipse.hawkbit.mgmt.rest.resource;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.not;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
@@ -74,7 +75,6 @@ import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.hateoas.MediaTypes;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.mock.web.MockMultipartFile;
|
||||
@@ -162,7 +162,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
|
||||
final SoftwareModule module = testdataFactory.createDistributionSet("one").findFirstModuleByType(osType).get();
|
||||
|
||||
for (int index = 0; index < totalMetadata; index++) {
|
||||
softwareModuleManagement.updateMetaData(entityFactory.softwareModuleMetadata().create(module.getId())
|
||||
softwareModuleManagement.updateMetadata(entityFactory.softwareModuleMetadata().create(module.getId())
|
||||
.key(knownKeyPrefix + index).value(knownValuePrefix + index));
|
||||
}
|
||||
|
||||
@@ -182,7 +182,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
|
||||
final SoftwareModule module = testdataFactory.createDistributionSet("one").findFirstModuleByType(osType).get();
|
||||
|
||||
for (int index = 0; index < totalMetadata; index++) {
|
||||
softwareModuleManagement.updateMetaData(entityFactory.softwareModuleMetadata().create(module.getId())
|
||||
softwareModuleManagement.updateMetadata(entityFactory.softwareModuleMetadata().create(module.getId())
|
||||
.key(knownKeyPrefix + index).value(knownValuePrefix + index));
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
|
||||
final String knownKey = "knownKey";
|
||||
final String knownValue = "knownValue";
|
||||
final SoftwareModule module = testdataFactory.createDistributionSet("one").findFirstModuleByType(osType).get();
|
||||
softwareModuleManagement.updateMetaData(
|
||||
softwareModuleManagement.updateMetadata(
|
||||
entityFactory.softwareModuleMetadata().create(module.getId()).key(knownKey).value(knownValue));
|
||||
|
||||
mvc.perform(get(MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING + "/{softwareModuleId}/metadata/{metadataKey}",
|
||||
@@ -1202,8 +1202,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
|
||||
.andExpect(jsonPath("$.createdBy", equalTo("uploadTester")))
|
||||
.andExpect(jsonPath("$.createdAt", equalTo(os.getCreatedAt())))
|
||||
.andExpect(jsonPath("$._links.metadata.href",
|
||||
equalTo("http://localhost/rest/v1/softwaremodules/" + os.getId()
|
||||
+ "/metadata?offset=0&limit=50")))
|
||||
equalTo("http://localhost/rest/v1/softwaremodules/" + os.getId() + "/metadata")))
|
||||
.andExpect(jsonPath("$._links.type.href",
|
||||
equalTo("http://localhost/rest/v1/softwaremoduletypes/" + osType.getId())))
|
||||
.andExpect(jsonPath("$._links.artifacts.href",
|
||||
@@ -1346,7 +1345,6 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
|
||||
@Test
|
||||
@Description("Verifies the successful creation of metadata and the enforcement of the meta data quota.")
|
||||
void createMetadata() throws Exception {
|
||||
|
||||
final String knownKey1 = "knownKey1";
|
||||
final String knownValue1 = "knownValue1";
|
||||
final String knownKey2 = "knownKey2";
|
||||
@@ -1361,19 +1359,12 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
|
||||
mvc.perform(post("/rest/v1/softwaremodules/{swId}/metadata", sm.getId()).accept(MediaType.APPLICATION_JSON)
|
||||
.contentType(MediaType.APPLICATION_JSON).content(metaData1.toString()))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isCreated())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
|
||||
.andExpect(jsonPath("[0].key", equalTo(knownKey1)))
|
||||
.andExpect(jsonPath("[0].value", equalTo(knownValue1)))
|
||||
.andExpect(jsonPath("[0].targetVisible", equalTo(false)))
|
||||
.andExpect(jsonPath("[1].key", equalTo(knownKey2)))
|
||||
.andExpect(jsonPath("[1].value", equalTo(knownValue2)))
|
||||
.andExpect(jsonPath("[1].targetVisible", equalTo(true)));
|
||||
.andExpect(status().isCreated());
|
||||
|
||||
assertThat(softwareModuleManagement.findMetaDataBySoftwareModuleId(sm.getId(), knownKey1))
|
||||
.as("Metadata key is wrong").get().extracting(SoftwareModuleMetadata::getValue).isEqualTo(knownValue1);
|
||||
assertThat(softwareModuleManagement.findMetaDataBySoftwareModuleId(sm.getId(), knownKey2))
|
||||
.as("Metadata key is wrong").get().extracting(SoftwareModuleMetadata::getValue).isEqualTo(knownValue2);
|
||||
assertThat(softwareModuleManagement.getMetadata(sm.getId(), knownKey1))
|
||||
.as("Metadata key is wrong").extracting(SoftwareModuleMetadata::getValue).isEqualTo(knownValue1);
|
||||
assertThat(softwareModuleManagement.getMetadata(sm.getId(), knownKey2))
|
||||
.as("Metadata key is wrong").extracting(SoftwareModuleMetadata::getValue).isEqualTo(knownValue2);
|
||||
|
||||
// verify quota enforcement
|
||||
final int maxMetaData = quotaManagement.getMaxMetaDataEntriesPerSoftwareModule();
|
||||
@@ -1388,11 +1379,8 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isForbidden());
|
||||
|
||||
// verify that the number of meta data entries has not changed
|
||||
// (we cannot use the PAGE constant here as it tries to sort by ID)
|
||||
assertThat(softwareModuleManagement
|
||||
.findMetaDataBySoftwareModuleId(PageRequest.of(0, Integer.MAX_VALUE), sm.getId()).getTotalElements())
|
||||
.isEqualTo(metaData1.length());
|
||||
// verify that the number of meta data entries has not changed (we cannot use the PAGE constant here as it tries to sort by ID)
|
||||
assertThat(softwareModuleManagement.getMetadata(sm.getId()).size()).isEqualTo(metaData1.length());
|
||||
|
||||
}
|
||||
|
||||
@@ -1405,7 +1393,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
|
||||
final String updateValue = "valueForUpdate";
|
||||
|
||||
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
|
||||
softwareModuleManagement.updateMetaData(
|
||||
softwareModuleManagement.updateMetadata(
|
||||
entityFactory.softwareModuleMetadata().create(sm.getId()).key(knownKey).value(knownValue));
|
||||
|
||||
final JSONObject jsonObject = new JSONObject().put("key", knownKey)
|
||||
@@ -1415,13 +1403,9 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
|
||||
mvc.perform(put("/rest/v1/softwaremodules/{swId}/metadata/{key}", sm.getId(), knownKey).accept(
|
||||
MediaType.APPLICATION_JSON).contentType(MediaType.APPLICATION_JSON).content(jsonObject.toString()))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
|
||||
.andExpect(jsonPath("key", equalTo(knownKey)))
|
||||
.andExpect(jsonPath("value", equalTo(updateValue)));
|
||||
.andExpect(status().isOk());
|
||||
|
||||
final SoftwareModuleMetadata assertDS = softwareModuleManagement.findMetaDataBySoftwareModuleId(sm.getId(),
|
||||
knownKey).get();
|
||||
final SoftwareModuleMetadata assertDS = softwareModuleManagement.getMetadata(sm.getId(), knownKey);
|
||||
assertThat(assertDS.getValue()).as("Metadata is wrong").isEqualTo(updateValue);
|
||||
assertThat(assertDS.isTargetVisible()).as("target visible is wrong").isTrue();
|
||||
}
|
||||
@@ -1433,15 +1417,16 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
|
||||
final String knownKey = "knownKey";
|
||||
final String knownValue = "knownValue";
|
||||
|
||||
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
|
||||
softwareModuleManagement.updateMetaData(
|
||||
entityFactory.softwareModuleMetadata().create(sm.getId()).key(knownKey).value(knownValue));
|
||||
final long smId = testdataFactory.createSoftwareModuleOs().getId();
|
||||
softwareModuleManagement.updateMetadata(
|
||||
entityFactory.softwareModuleMetadata().create(smId).key(knownKey).value(knownValue));
|
||||
|
||||
mvc.perform(delete("/rest/v1/softwaremodules/{swId}/metadata/{key}", sm.getId(), knownKey))
|
||||
mvc.perform(delete("/rest/v1/softwaremodules/{swId}/metadata/{key}", smId, knownKey))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk());
|
||||
|
||||
assertThat(softwareModuleManagement.findMetaDataBySoftwareModuleId(sm.getId(), knownKey)).isNotPresent();
|
||||
assertThatExceptionOfType(EntityNotFoundException.class)
|
||||
.isThrownBy(() -> softwareModuleManagement.getMetadata(smId, knownKey));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1451,11 +1436,11 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
|
||||
final String knownKey = "knownKey";
|
||||
final String knownValue = "knownValue";
|
||||
|
||||
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
|
||||
softwareModuleManagement.updateMetaData(
|
||||
entityFactory.softwareModuleMetadata().create(sm.getId()).key(knownKey).value(knownValue));
|
||||
final long smId = testdataFactory.createSoftwareModuleOs().getId();
|
||||
softwareModuleManagement.updateMetadata(
|
||||
entityFactory.softwareModuleMetadata().create(smId).key(knownKey).value(knownValue));
|
||||
|
||||
mvc.perform(delete("/rest/v1/softwaremodules/{swId}/metadata/XXX", sm.getId(), knownKey))
|
||||
mvc.perform(delete("/rest/v1/softwaremodules/{swId}/metadata/XXX", smId, knownKey))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isNotFound());
|
||||
|
||||
@@ -1463,7 +1448,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isNotFound());
|
||||
|
||||
assertThat(softwareModuleManagement.findMetaDataBySoftwareModuleId(sm.getId(), knownKey)).isPresent();
|
||||
assertThat(softwareModuleManagement.getMetadata(smId, knownKey)).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1474,32 +1459,6 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
|
||||
.andExpect(status().isNotFound());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verifies the successful search of a metadata entry based on value.")
|
||||
void searchSoftwareModuleMetadataRsql() throws Exception {
|
||||
final int totalMetadata = 10;
|
||||
final String knownKeyPrefix = "knownKey";
|
||||
final String knownValuePrefix = "knownValue";
|
||||
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
|
||||
|
||||
for (int index = 0; index < totalMetadata; index++) {
|
||||
softwareModuleManagement.updateMetaData(entityFactory.softwareModuleMetadata()
|
||||
.create(sm.getId())
|
||||
.key(knownKeyPrefix + index)
|
||||
.value(knownValuePrefix + index));
|
||||
}
|
||||
|
||||
final String rsqlSearchValue1 = "value==knownValue1";
|
||||
|
||||
mvc.perform(get("/rest/v1/softwaremodules/{swId}/metadata?q=" + rsqlSearchValue1, sm.getId()))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("size", equalTo(1)))
|
||||
.andExpect(jsonPath("total", equalTo(1)))
|
||||
.andExpect(jsonPath("content[0].key", equalTo("knownKey1")))
|
||||
.andExpect(jsonPath("content[0].value", equalTo("knownValue1")));
|
||||
}
|
||||
|
||||
private void assertArtifact(final SoftwareModule sm, final byte[] random) throws IOException {
|
||||
// check result in db...
|
||||
// repo
|
||||
|
||||
Reference in New Issue
Block a user