add example mgmt-api-client powered by feign and spring-cloud.

Signed-off-by: Michael Hirsch <michael.hirsch@bosch-si.com>
This commit is contained in:
Michael Hirsch
2016-02-09 17:49:24 +01:00
parent 81bf2df2d8
commit 17d815e1b6
58 changed files with 3865 additions and 2646 deletions

View File

@@ -22,6 +22,8 @@ import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetMetadata;
import org.eclipse.hawkbit.repository.model.DistributionSetType;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.rest.resource.api.DistributionSetRestApi;
import org.eclipse.hawkbit.rest.resource.api.DistributionSetTypeRestApi;
import org.eclipse.hawkbit.rest.resource.model.MetadataRest;
import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetRequestBodyPost;
import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetRest;
@@ -169,13 +171,13 @@ public final class DistributionSetMapper {
response.setRequiredMigrationStep(distributionSet.isRequiredMigrationStep());
response.add(
linkTo(methodOn(DistributionSetResource.class).getDistributionSet(response.getDsId())).withRel("self"));
linkTo(methodOn(DistributionSetRestApi.class).getDistributionSet(response.getDsId())).withRel("self"));
response.add(linkTo(
methodOn(DistributionSetTypeResource.class).getDistributionSetType(distributionSet.getType().getId()))
methodOn(DistributionSetTypeRestApi.class).getDistributionSetType(distributionSet.getType().getId()))
.withRel("type"));
response.add(linkTo(methodOn(DistributionSetResource.class).getMetadata(response.getDsId(),
response.add(linkTo(methodOn(DistributionSetRestApi.class).getMetadata(response.getDsId(),
Integer.parseInt(RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET),
Integer.parseInt(RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT), null, null))
.withRel("metadata"));

View File

@@ -30,6 +30,7 @@ import org.eclipse.hawkbit.repository.model.DsMetadataCompositeKey;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.rsql.RSQLUtility;
import org.eclipse.hawkbit.rest.resource.api.DistributionSetRestApi;
import org.eclipse.hawkbit.rest.resource.helper.RestResourceConversionHelper;
import org.eclipse.hawkbit.rest.resource.model.MetadataRest;
import org.eclipse.hawkbit.rest.resource.model.MetadataRestPageList;
@@ -51,25 +52,14 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* REST Resource handling for {@link DistributionSet} CRUD operations.
*
*
*
*
*/
@RestController
@RequestMapping(RestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING)
public class DistributionSetResource {
public class DistributionSetResource implements DistributionSetRestApi {
private static final Logger LOG = LoggerFactory.getLogger(DistributionSetResource.class);
@Autowired
@@ -90,32 +80,9 @@ public class DistributionSetResource {
@Autowired
private DistributionSetManagement distributionSetManagement;
/**
* Handles the GET request of retrieving all {@link DistributionSet}s within
* SP.
*
* @param pagingOffsetParam
* the offset of list of sets 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=name==abc}
* @return a list of all set for a defined or default page request with
* status OK. The response is always paged. In any failure the
* JsonResponseExceptionHandler is handling the response.
*/
@RequestMapping(method = RequestMethod.GET, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<DistributionSetPagedList> getDistributionSets(
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) {
@Override
public ResponseEntity<DistributionSetPagedList> getDistributionSets(final int pagingOffsetParam,
final int pagingLimitParam, final String sortParam, final String rsqlParam) {
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
@@ -124,99 +91,51 @@ public class DistributionSetResource {
final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
final Page<DistributionSet> findDsPage;
if (rsqlParam != null) {
findDsPage = distributionSetManagement.findDistributionSetsAll(
findDsPage = this.distributionSetManagement.findDistributionSetsAll(
RSQLUtility.parse(rsqlParam, DistributionSetFields.class), pageable, false);
} else {
findDsPage = distributionSetManagement.findDistributionSetsAll(pageable, false, null);
findDsPage = this.distributionSetManagement.findDistributionSetsAll(pageable, false, null);
}
final List<DistributionSetRest> rest = DistributionSetMapper.toResponseFromDsList(findDsPage.getContent());
return new ResponseEntity<>(new DistributionSetPagedList(rest, findDsPage.getTotalElements()), HttpStatus.OK);
}
/**
* Handles the GET request of retrieving a single {@link DistributionSet}
* within SP.
*
* @param distributionSetId
* the ID of the set to retrieve
*
* @return a single {@link DistributionSet} with status OK.
*
* @throws EntityNotFoundException
* in case no {@link DistributionSet} with the given ID exists.
*/
@RequestMapping(method = RequestMethod.GET, value = "/{distributionSetId}", produces = { "application/hal+json",
MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<DistributionSetRest> getDistributionSet(@PathVariable final Long distributionSetId) {
@Override
public ResponseEntity<DistributionSetRest> getDistributionSet(final Long distributionSetId) {
final DistributionSet foundDs = findDistributionSetWithExceptionIfNotFound(distributionSetId);
return new ResponseEntity<>(DistributionSetMapper.toResponse(foundDs), HttpStatus.OK);
}
/**
* Handles the POST request of creating new distribution sets within SP. The
* request body must always be a list of sets. The requests is delegating to
* the {@link SoftwareManagement#createDistributionSet(DistributionSet))}.
*
* @param sets
* the {@link DistributionSet}s to be created.
* @return In case all sets could successful created the ResponseEntity with
* status code 201 - Created but without ResponseBody. In any
* failure the JsonResponseExceptionHandler is handling the
* response.
*/
@RequestMapping(method = RequestMethod.POST, consumes = { MediaType.APPLICATION_JSON_VALUE,
"application/hal+json" }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
@Override
public ResponseEntity<DistributionSetsRest> createDistributionSets(
@RequestBody final List<DistributionSetRequestBodyPost> sets) {
final List<DistributionSetRequestBodyPost> sets) {
LOG.debug("creating {} distribution sets", sets.size());
// set default Ds type if ds type is null
sets.stream().filter(ds -> ds.getType() == null).forEach(ds -> ds.setType(
systemManagement.getTenantMetadata(currentTenant.getCurrentTenant()).getDefaultDsType().getKey()));
sets.stream().filter(ds -> ds.getType() == null).forEach(ds -> ds.setType(this.systemManagement
.getTenantMetadata(this.currentTenant.getCurrentTenant()).getDefaultDsType().getKey()));
final Iterable<DistributionSet> createdDSets = distributionSetManagement.createDistributionSets(
DistributionSetMapper.dsFromRequest(sets, softwareManagement, distributionSetManagement));
final Iterable<DistributionSet> createdDSets = this.distributionSetManagement.createDistributionSets(
DistributionSetMapper.dsFromRequest(sets, this.softwareManagement, this.distributionSetManagement));
LOG.debug("{} distribution sets created, return status {}", sets.size(), HttpStatus.CREATED);
return new ResponseEntity<>(DistributionSetMapper.toResponseDistributionSets(createdDSets), HttpStatus.CREATED);
}
/**
* Handles the DELETE request for a single {@link DistributionSet} within
* SP.
*
* @param distributionSetId
* the ID of the {@link DistributionSet} to delete
* @return status OK if delete as successful.
*
*/
@RequestMapping(method = RequestMethod.DELETE, value = "/{distributionSetId}")
public ResponseEntity<Void> deleteDistributionSet(@PathVariable final Long distributionSetId) {
@Override
public ResponseEntity<Void> deleteDistributionSet(final Long distributionSetId) {
final DistributionSet set = findDistributionSetWithExceptionIfNotFound(distributionSetId);
distributionSetManagement.deleteDistributionSet(set);
this.distributionSetManagement.deleteDistributionSet(set);
return new ResponseEntity<>(HttpStatus.OK);
}
/**
* Handles the UPDATE request for a single {@link DistributionSet} within
* SP.
*
* @param distributionSetId
* the ID of the {@link DistributionSet} to delete
* @param toUpdate
* with the data that needs updating
*
* @return status OK if update as successful with updated content.
*
*/
@RequestMapping(method = RequestMethod.PUT, value = "/{distributionSetId}", consumes = { "application/hal+json",
MediaType.APPLICATION_JSON_VALUE }, produces = { MediaType.APPLICATION_JSON_VALUE, "application/hal+json" })
public ResponseEntity<DistributionSetRest> updateDistributionSet(@PathVariable final Long distributionSetId,
@RequestBody final DistributionSetRequestBodyPut toUpdate) {
@Override
public ResponseEntity<DistributionSetRest> updateDistributionSet(final Long distributionSetId,
final DistributionSetRequestBodyPut toUpdate) {
final DistributionSet set = findDistributionSetWithExceptionIfNotFound(distributionSetId);
if (toUpdate.getDescription() != null) {
@@ -231,38 +150,13 @@ public class DistributionSetResource {
set.setVersion(toUpdate.getVersion());
}
return new ResponseEntity<>(
DistributionSetMapper.toResponse(distributionSetManagement.updateDistributionSet(set)), HttpStatus.OK);
DistributionSetMapper.toResponse(this.distributionSetManagement.updateDistributionSet(set)),
HttpStatus.OK);
}
/**
* Handles the GET request of retrieving assigned targets to a specific
* distribution set.
*
* @param distributionSetId
* the ID of the distribution set to retrieve the assigned
* targets
* @param pagingOffsetParam
* the offset of list of targets 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=name==abc}
* @return status OK if get request is successful with the paged list of
* targets
*/
@RequestMapping(method = RequestMethod.GET, value = "/{distributionSetId}/assignedTargets", produces = {
MediaType.APPLICATION_JSON_VALUE, "application/hal+json" })
public ResponseEntity<TargetPagedList> getAssignedTargets(@PathVariable final Long distributionSetId,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) {
@Override
public ResponseEntity<TargetPagedList> getAssignedTargets(final Long distributionSetId, final int pagingOffsetParam,
final int pagingLimitParam, final String sortParam, final String rsqlParam) {
// check if distribution set exists otherwise throw exception
// immediately
@@ -275,45 +169,19 @@ public class DistributionSetResource {
final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
final Page<Target> targetsAssignedDS;
if (rsqlParam != null) {
targetsAssignedDS = targetManagement.findTargetByAssignedDistributionSet(distributionSetId,
targetsAssignedDS = this.targetManagement.findTargetByAssignedDistributionSet(distributionSetId,
RSQLUtility.parse(rsqlParam, TargetFields.class), pageable);
} else {
targetsAssignedDS = targetManagement.findTargetByAssignedDistributionSet(distributionSetId, pageable);
targetsAssignedDS = this.targetManagement.findTargetByAssignedDistributionSet(distributionSetId, pageable);
}
return new ResponseEntity<>(new TargetPagedList(TargetMapper.toResponse(targetsAssignedDS.getContent()),
targetsAssignedDS.getTotalElements()), HttpStatus.OK);
}
/**
* Handles the GET request of retrieving installed targets to a specific
* distribution set.
*
* @param distributionSetId
* the ID of the distribution set to retrieve the assigned
* targets
* @param pagingOffsetParam
* the offset of list of targets 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=name==abc}
* @return status OK if get request is successful with the paged list of
* targets
*/
@RequestMapping(method = RequestMethod.GET, value = "/{distributionSetId}/installedTargets", produces = {
MediaType.APPLICATION_JSON_VALUE, "application/hal+json" })
public ResponseEntity<TargetPagedList> getInstalledTargets(@PathVariable final Long distributionSetId,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) {
@Override
public ResponseEntity<TargetPagedList> getInstalledTargets(final Long distributionSetId,
final int pagingOffsetParam, final int pagingLimitParam, final String sortParam, final String rsqlParam) {
// check if distribution set exists otherwise throw exception
// immediately
findDistributionSetWithExceptionIfNotFound(distributionSetId);
@@ -325,36 +193,22 @@ public class DistributionSetResource {
final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
final Page<Target> targetsInstalledDS;
if (rsqlParam != null) {
targetsInstalledDS = targetManagement.findTargetByInstalledDistributionSet(distributionSetId,
targetsInstalledDS = this.targetManagement.findTargetByInstalledDistributionSet(distributionSetId,
RSQLUtility.parse(rsqlParam, TargetFields.class), pageable);
} else {
targetsInstalledDS = targetManagement.findTargetByInstalledDistributionSet(distributionSetId, pageable);
targetsInstalledDS = this.targetManagement.findTargetByInstalledDistributionSet(distributionSetId,
pageable);
}
return new ResponseEntity<>(new TargetPagedList(TargetMapper.toResponse(targetsInstalledDS.getContent()),
targetsInstalledDS.getTotalElements()), HttpStatus.OK);
}
/**
* Handles the POST request of assigning multiple targets to a single
* distribution set.
*
* @param distributionSetId
* the ID of the distribution set within the URL path parameter
* @param targetIds
* the IDs of the target which should get assigned to the
* distribution set given in the response body
* @return status OK if the assignment of the targets was successful and a
* complex return body which contains information about the assigned
* targets and the already assigned targets counters
*/
@RequestMapping(method = RequestMethod.POST, value = "/{distributionSetId}/assignedTargets", consumes = {
"application/hal+json",
MediaType.APPLICATION_JSON_VALUE }, produces = { MediaType.APPLICATION_JSON_VALUE, "application/hal+json" })
public ResponseEntity<TargetAssignmentResponseBody> createAssignedTarget(@PathVariable final Long distributionSetId,
@RequestBody final List<TargetAssignmentRequestBody> targetIds) {
@Override
public ResponseEntity<TargetAssignmentResponseBody> createAssignedTarget(final Long distributionSetId,
final List<TargetAssignmentRequestBody> targetIds) {
final DistributionSetAssignmentResult assignDistributionSet = deployManagament.assignDistributionSet(
final DistributionSetAssignmentResult assignDistributionSet = this.deployManagament.assignDistributionSet(
distributionSetId,
targetIds.stream()
.map(t -> new TargetWithActionType(t.getId(),
@@ -364,33 +218,9 @@ public class DistributionSetResource {
return new ResponseEntity<>(DistributionSetMapper.toResponse(assignDistributionSet), HttpStatus.OK);
}
/**
* Gets a paged list of meta data for a distribution set.
*
* @param distributionSetId
* the ID of the distribution set for the meta data
* @param pagingOffsetParam
* the offset of list of targets 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
* meta data
*/
@RequestMapping(method = RequestMethod.GET, value = "/{distributionSetId}/metadata", produces = {
MediaType.APPLICATION_JSON_VALUE, "application/hal+json" })
public ResponseEntity<MetadataRestPageList> getMetadata(@PathVariable final Long distributionSetId,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) {
@Override
public ResponseEntity<MetadataRestPageList> getMetadata(final Long distributionSetId, final int pagingOffsetParam,
final int pagingLimitParam, final String sortParam, final String rsqlParam) {
// check if distribution set exists otherwise throw exception
// immediately
@@ -404,11 +234,11 @@ public class DistributionSetResource {
final Page<DistributionSetMetadata> metaDataPage;
if (rsqlParam != null) {
metaDataPage = distributionSetManagement.findDistributionSetMetadataByDistributionSetId(distributionSetId,
RSQLUtility.parse(rsqlParam, DistributionSetMetadataFields.class), pageable);
metaDataPage = this.distributionSetManagement.findDistributionSetMetadataByDistributionSetId(
distributionSetId, RSQLUtility.parse(rsqlParam, DistributionSetMetadataFields.class), pageable);
} else {
metaDataPage = distributionSetManagement.findDistributionSetMetadataByDistributionSetId(distributionSetId,
pageable);
metaDataPage = this.distributionSetManagement
.findDistributionSetMetadataByDistributionSetId(distributionSetId, pageable);
}
return new ResponseEntity<>(
@@ -418,119 +248,59 @@ public class DistributionSetResource {
}
/**
* Gets a single meta data value for a specific key of a distribution set.
*
* @param distributionSetId
* the ID of the distribution set to get the meta data from
* @param metadataKey
* the key of the meta data entry to retrieve the value from
* @return status OK if get request is successful with the value of the meta
* data
*/
@RequestMapping(method = RequestMethod.GET, value = "/{distributionSetId}/metadata/{metadataKey}", produces = {
MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<MetadataRest> getMetadataValue(@PathVariable final Long distributionSetId,
@PathVariable final String metadataKey) {
@Override
public ResponseEntity<MetadataRest> getMetadataValue(final Long distributionSetId, final String metadataKey) {
// check if distribution set exists otherwise throw exception
// immediately
final DistributionSet ds = findDistributionSetWithExceptionIfNotFound(distributionSetId);
final DistributionSetMetadata findOne = distributionSetManagement
final DistributionSetMetadata findOne = this.distributionSetManagement
.findOne(new DsMetadataCompositeKey(ds, metadataKey));
return ResponseEntity.<MetadataRest> ok(DistributionSetMapper.toResponseDsMetadata(findOne));
}
/**
* Updates a single meta data value of a distribution set.
*
* @param distributionSetId
* the ID of the distribution set to update the meta data entry
* @param metadataKey
* the key of the meta data to update the value
* @return status OK if the update request is successful and the updated
* meta data result
*/
@RequestMapping(method = RequestMethod.PUT, value = "/{distributionSetId}/metadata/{metadataKey}", produces = {
MediaType.APPLICATION_JSON_VALUE, "application/hal+json" })
public ResponseEntity<MetadataRest> updateMetadata(@PathVariable final Long distributionSetId,
@PathVariable final String metadataKey, @RequestBody final MetadataRest metadata) {
@Override
public ResponseEntity<MetadataRest> updateMetadata(final Long distributionSetId, final String metadataKey,
final MetadataRest metadata) {
// check if distribution set exists otherwise throw exception
// immediately
final DistributionSet ds = findDistributionSetWithExceptionIfNotFound(distributionSetId);
final DistributionSetMetadata updated = distributionSetManagement
final DistributionSetMetadata updated = this.distributionSetManagement
.updateDistributionSetMetadata(new DistributionSetMetadata(metadataKey, ds, metadata.getValue()));
return ResponseEntity.ok(DistributionSetMapper.toResponseDsMetadata(updated));
}
/**
* Deletes a single meta data entry from the distribution set.
*
* @param distributionSetId
* the ID of the distribution set to delete the meta data entry
* @param metadataKey
* the key of the meta data to delete
* @return status OK if the delete request is successful
*/
@RequestMapping(method = RequestMethod.DELETE, value = "/{distributionSetId}/metadata/{metadataKey}")
public ResponseEntity<Void> deleteMetadata(@PathVariable final Long distributionSetId,
@PathVariable final String metadataKey) {
@Override
public ResponseEntity<Void> deleteMetadata(final Long distributionSetId, final String metadataKey) {
// check if distribution set exists otherwise throw exception
// immediately
final DistributionSet ds = findDistributionSetWithExceptionIfNotFound(distributionSetId);
distributionSetManagement.deleteDistributionSetMetadata(new DsMetadataCompositeKey(ds, metadataKey));
this.distributionSetManagement.deleteDistributionSetMetadata(new DsMetadataCompositeKey(ds, metadataKey));
return ResponseEntity.ok().build();
}
/**
* Creates a list of meta data for a specific distribution set.
*
* @param distributionSetId
* the ID of the distribution set to create meta data for
* @param metadataRest
* the list of meta data entries to create
* @return status created if post request is successful with the value of
* the created meta data
*/
@RequestMapping(method = RequestMethod.POST, value = "/{distributionSetId}/metadata", consumes = {
MediaType.APPLICATION_JSON_VALUE,
"application/hal+json" }, produces = { MediaType.APPLICATION_JSON_VALUE, "application/hal+json" })
public ResponseEntity<List<MetadataRest>> createMetadata(@PathVariable final Long distributionSetId,
@RequestBody final List<MetadataRest> metadataRest) {
@Override
public ResponseEntity<List<MetadataRest>> createMetadata(final Long distributionSetId,
final List<MetadataRest> metadataRest) {
// check if distribution set exists otherwise throw exception
// immediately
final DistributionSet ds = findDistributionSetWithExceptionIfNotFound(distributionSetId);
final List<DistributionSetMetadata> created = distributionSetManagement
final List<DistributionSetMetadata> created = this.distributionSetManagement
.createDistributionSetMetadata(DistributionSetMapper.fromRequestDsMetadata(ds, metadataRest));
return new ResponseEntity<>(DistributionSetMapper.toResponseDsMetadata(created), HttpStatus.CREATED);
}
/**
* Assigns a list of software modules to a distribution set.
*
* @param distributionSetId
* the ID of the distribution set to assign software modules for
* @param softwareModuleIDs
* the list of software modules ids to assign
* @return {@link HttpStatus#OK}
*
* @throws EntityNotFoundException
* in case no distribution set with the given
* {@code distributionSetId} exists.
*/
@RequestMapping(method = RequestMethod.POST, value = "/{distributionSetId}/assignedSM", consumes = {
MediaType.APPLICATION_JSON_VALUE,
"application/hal+json" }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<Void> assignSoftwareModules(@PathVariable final Long distributionSetId,
@RequestBody final List<SoftwareModuleAssigmentRest> softwareModuleIDs) {
@Override
public ResponseEntity<Void> assignSoftwareModules(final Long distributionSetId,
final List<SoftwareModuleAssigmentRest> softwareModuleIDs) {
// check if distribution set exists otherwise throw exception
// immediately
final DistributionSet ds = findDistributionSetWithExceptionIfNotFound(distributionSetId);
final Set<SoftwareModule> softwareModuleToBeAssigned = new HashSet<>();
for (final SoftwareModuleAssigmentRest sm : softwareModuleIDs) {
final SoftwareModule softwareModule = softwareManagement.findSoftwareModuleById(sm.getId());
final SoftwareModule softwareModule = this.softwareManagement.findSoftwareModuleById(sm.getId());
if (softwareModule != null) {
softwareModuleToBeAssigned.add(softwareModule);
} else {
@@ -538,63 +308,23 @@ public class DistributionSetResource {
}
}
// Add Softwaremodules to DisSet only if all of them were found
distributionSetManagement.assignSoftwareModules(ds, softwareModuleToBeAssigned);
this.distributionSetManagement.assignSoftwareModules(ds, softwareModuleToBeAssigned);
return new ResponseEntity<>(HttpStatus.OK);
}
/**
* Deletes the assignment of the software module form the distribution set.
*
* @param distributionSetId
* the ID of the distribution set to reject the software module
* for
* @param softwareModuleId
* the software module id to get rejected form the distribution
* set
* @return status OK if rejection was successful.
* @throws EntityNotFoundException
* in case no distribution set with the given
* {@code distributionSetId} exists.
*/
@RequestMapping(method = RequestMethod.DELETE, value = "/{distributionSetId}/assignedSM/{softwareModuleId}")
public ResponseEntity<Void> deleteAssignSoftwareModules(@PathVariable final Long distributionSetId,
@PathVariable final Long softwareModuleId) {
@Override
public ResponseEntity<Void> deleteAssignSoftwareModules(final Long distributionSetId, final Long softwareModuleId) {
// check if distribution set and software module exist otherwise throw
// exception immediately
final DistributionSet ds = findDistributionSetWithExceptionIfNotFound(distributionSetId);
final SoftwareModule sm = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId);
distributionSetManagement.unassignSoftwareModule(ds, sm);
this.distributionSetManagement.unassignSoftwareModule(ds, sm);
return ResponseEntity.ok().build();
}
/**
* Handles the GET request for retrieving the assigned software modules of a
* specific distribution set.
*
* @param distributionSetId
* the ID of the distribution to retrieve
* @param pagingOffsetParam
* the offset of list of sets 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}
* @return a list of the assigned software modules of a distribution set
* with status OK, if none is assigned than {@code null}
* @throws EntityNotFoundException
* in case no distribution set with the given
* {@code distributionSetId} exists.
*/
@RequestMapping(method = RequestMethod.GET, value = "/{distributionSetId}/assignedSM", produces = {
"application/hal+json", MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<SoftwareModulePagedList> getAssignedSoftwareModules(
@PathVariable final Long distributionSetId,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam) {
@Override
public ResponseEntity<SoftwareModulePagedList> getAssignedSoftwareModules(final Long distributionSetId,
final int pagingOffsetParam, final int pagingLimitParam, final String sortParam) {
// check if distribution set exists otherwise throw exception
// immediately
final DistributionSet foundDs = findDistributionSetWithExceptionIfNotFound(distributionSetId);
@@ -602,7 +332,7 @@ public class DistributionSetResource {
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
final Sort sorting = PagingUtility.sanitizeSoftwareModuleSortParam(sortParam);
final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
final Page<SoftwareModule> softwaremodules = softwareManagement.findSoftwareModuleByAssignedTo(pageable,
final Page<SoftwareModule> softwaremodules = this.softwareManagement.findSoftwareModuleByAssignedTo(pageable,
foundDs);
return new ResponseEntity<>(
new SoftwareModulePagedList(SoftwareModuleMapper.toResponse(softwaremodules.getContent()),
@@ -611,7 +341,7 @@ public class DistributionSetResource {
}
private DistributionSet findDistributionSetWithExceptionIfNotFound(final Long distributionSetId) {
final DistributionSet set = distributionSetManagement.findDistributionSetById(distributionSetId);
final DistributionSet set = this.distributionSetManagement.findDistributionSetById(distributionSetId);
if (set == null) {
throw new EntityNotFoundException("DistributionSet with Id {" + distributionSetId + "} does not exist");
}
@@ -620,7 +350,7 @@ public class DistributionSetResource {
}
private SoftwareModule findSoftwareModuleWithExceptionIfNotFound(final Long softwareModuleId) {
final SoftwareModule sm = softwareManagement.findSoftwareModuleById(softwareModuleId);
final SoftwareModule sm = this.softwareManagement.findSoftwareModuleById(softwareModuleId);
if (sm == null) {
throw new EntityNotFoundException("SoftwareModule with Id {" + softwareModuleId + "} does not exist");
}

View File

@@ -19,6 +19,7 @@ import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
import org.eclipse.hawkbit.repository.model.DistributionSetTagAssigmentResult;
import org.eclipse.hawkbit.repository.rsql.RSQLUtility;
import org.eclipse.hawkbit.rest.resource.api.DistributionSetTagRestApi;
import org.eclipse.hawkbit.rest.resource.model.distributionset.DistributionSetsRest;
import org.eclipse.hawkbit.rest.resource.model.tag.AssignedDistributionSetRequestBody;
import org.eclipse.hawkbit.rest.resource.model.tag.DistributionSetTagAssigmentResultRest;
@@ -34,13 +35,7 @@ import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.domain.Sort;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
@@ -48,8 +43,7 @@ import org.springframework.web.bind.annotation.RestController;
*
*/
@RestController
@RequestMapping(RestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING)
public class DistributionSetTagResource {
public class DistributionSetTagResource implements DistributionSetTagRestApi {
private static final Logger LOG = LoggerFactory.getLogger(DistributionSetTagResource.class);
@Autowired
@@ -58,32 +52,9 @@ public class DistributionSetTagResource {
@Autowired
private DistributionSetManagement distributionSetManagement;
/**
* Handles the GET request of retrieving all DistributionSet tags.
*
* @param pagingOffsetParam
* the offset of list of DistributionSet tags 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=name==abc}
* @return a list of all target tags for a defined or default page request
* with status OK. The response is always paged. In any failure the
* JsonResponseExceptionHandler is handling the response.
*/
@RequestMapping(method = RequestMethod.GET, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<TagPagedList> getDistributionSetTags(
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) {
@Override
public ResponseEntity<TagPagedList> getDistributionSetTags(final int pagingOffsetParam, final int pagingLimitParam,
final String sortParam, final String rsqlParam) {
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
@@ -93,11 +64,11 @@ public class DistributionSetTagResource {
final Slice<DistributionSetTag> findTargetsAll;
final Long countTargetsAll;
if (rsqlParam == null) {
findTargetsAll = tagManagement.findAllDistributionSetTags(pageable);
countTargetsAll = tagManagement.countTargetTags();
findTargetsAll = this.tagManagement.findAllDistributionSetTags(pageable);
countTargetsAll = this.tagManagement.countTargetTags();
} else {
final Page<DistributionSetTag> findTargetPage = tagManagement
final Page<DistributionSetTag> findTargetPage = this.tagManagement
.findAllDistributionSetTags(RSQLUtility.parse(rsqlParam, TagFields.class), pageable);
countTargetsAll = findTargetPage.getTotalElements();
findTargetsAll = findTargetPage;
@@ -108,141 +79,63 @@ public class DistributionSetTagResource {
return new ResponseEntity<>(new TagPagedList(rest, countTargetsAll), HttpStatus.OK);
}
/**
* Handles the GET request of retrieving a single distribution set tag.
*
* @param distributionsetTagId
* the ID of the distribution set tag to retrieve
*
* @return a single distribution set tag with status OK.
* @throws EntityNotFoundException
* in case the given {@code distributionsetTagId} doesn't
* exists.
*/
@RequestMapping(method = RequestMethod.GET, value = "/{distributionsetTagId}", produces = { "application/hal+json",
MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<TagRest> getDistributionSetTag(@PathVariable final Long distributionsetTagId) {
@Override
public ResponseEntity<TagRest> getDistributionSetTag(final Long distributionsetTagId) {
final DistributionSetTag tag = findDistributionTagById(distributionsetTagId);
return new ResponseEntity<>(TagMapper.toResponse(tag), HttpStatus.OK);
}
/**
* Handles the POST request of creating new distribution set tag. The
* request body must always be a list of tags.
*
* @param tags
* the distribution set tags to be created.
* @return In case all modules could successful created the ResponseEntity
* with status code 201 - Created. The Response Body are the created
* distribution set tags but without ResponseBody.
*/
@RequestMapping(method = RequestMethod.POST, consumes = { "application/hal+json",
MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<TagsRest> createDistributionSetTags(@RequestBody final List<TagRequestBodyPut> tags) {
@Override
public ResponseEntity<TagsRest> createDistributionSetTags(final List<TagRequestBodyPut> tags) {
LOG.debug("creating {} ds tags", tags.size());
final List<DistributionSetTag> createdTags = tagManagement
final List<DistributionSetTag> createdTags = this.tagManagement
.createDistributionSetTags(TagMapper.mapDistributionSetTagFromRequest(tags));
return new ResponseEntity<>(TagMapper.toResponseDistributionSetTag(createdTags), HttpStatus.CREATED);
}
/**
*
* Handles the PUT request of updating a single distribution set tag.
*
* @param distributionsetTagId
* the ID of the distribution set tag
* @param restDSTagRest
* the the request body to be updated
* @return status OK if update is successful and the updated distribution
* set tag.
* @throws EntityNotFoundException
* in case the given {@code distributionsetTagId} doesn't
* exists.
*/
@RequestMapping(method = RequestMethod.PUT, value = "/{distributionsetTagId}", consumes = { "application/hal+json",
MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<TagRest> updateDistributionSetTag(@PathVariable final Long distributionsetTagId,
@RequestBody final TagRequestBodyPut restDSTagRest) {
@Override
public ResponseEntity<TagRest> updateDistributionSetTag(final Long distributionsetTagId,
final TagRequestBodyPut restDSTagRest) {
LOG.debug("update {} ds tag", restDSTagRest);
final DistributionSetTag distributionSetTag = findDistributionTagById(distributionsetTagId);
TagMapper.updateTag(restDSTagRest, distributionSetTag);
final DistributionSetTag updateDistributionSetTag = tagManagement.updateDistributionSetTag(distributionSetTag);
final DistributionSetTag updateDistributionSetTag = this.tagManagement
.updateDistributionSetTag(distributionSetTag);
LOG.debug("ds tag updated");
return new ResponseEntity<>(TagMapper.toResponse(updateDistributionSetTag), HttpStatus.OK);
}
/**
* Handles the DELETE request for a single distribution set tag.
*
* @param distributionsetTagId
* the ID of the distribution set tag
* @return status OK if delete as successfully.
* @throws EntityNotFoundException
* in case the given {@code distributionsetTagId} doesn't
* exists.
*
*/
@RequestMapping(method = RequestMethod.DELETE, value = "/{distributionsetTagId}")
public ResponseEntity<Void> deleteDistributionSetTag(@PathVariable final Long distributionsetTagId) {
@Override
public ResponseEntity<Void> deleteDistributionSetTag(final Long distributionsetTagId) {
LOG.debug("Delete {} distribution set tag", distributionsetTagId);
final DistributionSetTag tag = findDistributionTagById(distributionsetTagId);
tagManagement.deleteDistributionSetTag(tag.getName());
this.tagManagement.deleteDistributionSetTag(tag.getName());
return new ResponseEntity<>(HttpStatus.OK);
}
/**
* Handles the GET request of retrieving all assigned distribution sets by
* the given tag id.
*
* @param distributionsetTagId
* the ID of the distribution set tag
*
* @return the list of assigned distribution sets.
* @throws EntityNotFoundException
* in case the given {@code distributionsetTagId} doesn't
* exists.
*/
@RequestMapping(method = RequestMethod.GET, value = RestConstants.DISTRIBUTIONSET_REQUEST_MAPPING)
public ResponseEntity<DistributionSetsRest> getAssignedDistributionSets(
@PathVariable final Long distributionsetTagId) {
@Override
public ResponseEntity<DistributionSetsRest> getAssignedDistributionSets(final Long distributionsetTagId) {
final DistributionSetTag tag = findDistributionTagById(distributionsetTagId);
return new ResponseEntity<>(
DistributionSetMapper.toResponseDistributionSets(tag.getAssignedToDistributionSet()), HttpStatus.OK);
}
/**
* Handles the POST request to toggle the assignment of distribution sets by
* the given tag id.
*
* @param distributionsetTagIds
* the ID of the distribution set tag to retrieve
* @param assignedDSRequestBodies
* list of distribution set ids to be toggled
*
* @return the list of assigned distribution sets and unassigned
* distribution sets.
* @throws EntityNotFoundException
* in case the given {@code distributionsetTagId} doesn't
* exists.
*/
@RequestMapping(method = RequestMethod.POST, value = RestConstants.DISTRIBUTIONSET_REQUEST_MAPPING
+ "/toggleTagAssignment")
public ResponseEntity<DistributionSetTagAssigmentResultRest> toggleTagAssignment(
@PathVariable final Long distributionsetTagId,
@RequestBody final List<AssignedDistributionSetRequestBody> assignedDSRequestBodies) {
@Override
public ResponseEntity<DistributionSetTagAssigmentResultRest> toggleTagAssignment(final Long distributionsetTagId,
final List<AssignedDistributionSetRequestBody> assignedDSRequestBodies) {
LOG.debug("Toggle distribution set assignment {} for ds tag {}", assignedDSRequestBodies.size(),
distributionsetTagId);
final DistributionSetTag tag = findDistributionTagById(distributionsetTagId);
final DistributionSetTagAssigmentResult assigmentResult = distributionSetManagement
final DistributionSetTagAssigmentResult assigmentResult = this.distributionSetManagement
.toggleTagAssignment(findDistributionSetIds(assignedDSRequestBodies), tag.getName());
final DistributionSetTagAssigmentResultRest tagAssigmentResultRest = new DistributionSetTagAssigmentResultRest();
@@ -257,44 +150,20 @@ public class DistributionSetTagResource {
return new ResponseEntity<>(tagAssigmentResultRest, HttpStatus.OK);
}
/**
* Handles the POST request to assign distribution sets to the given tag id.
*
* @param distributionsetTagId
* the ID of the distribution set tag to retrieve
* @param assignedDSRequestBodies
* list of distribution sets ids to be assigned
*
* @return the list of assigned distribution set.
* @throws EntityNotFoundException
* in case the given {@code distributionsetTagId} doesn't
* exists.
*/
@RequestMapping(method = RequestMethod.POST, value = RestConstants.DISTRIBUTIONSET_REQUEST_MAPPING)
public ResponseEntity<DistributionSetsRest> assignDistributionSets(@PathVariable final Long distributionsetTagId,
@RequestBody final List<AssignedDistributionSetRequestBody> assignedDSRequestBodies) {
@Override
public ResponseEntity<DistributionSetsRest> assignDistributionSets(final Long distributionsetTagId,
final List<AssignedDistributionSetRequestBody> assignedDSRequestBodies) {
LOG.debug("Assign DistributionSet {} for ds tag {}", assignedDSRequestBodies.size(), distributionsetTagId);
final DistributionSetTag tag = findDistributionTagById(distributionsetTagId);
final List<DistributionSet> assignedDs = distributionSetManagement
final List<DistributionSet> assignedDs = this.distributionSetManagement
.assignTag(findDistributionSetIds(assignedDSRequestBodies), tag);
LOG.debug("Assignd DistributionSet {}", assignedDs.size());
return new ResponseEntity<>(DistributionSetMapper.toResponseDistributionSets(assignedDs), HttpStatus.OK);
}
/**
* Handles the DELETE request to unassign all distribution set from the
* given tag id.
*
* @param distributionsetTagId
* the ID of the distribution set tag to retrieve
* @return http status code
* @throws EntityNotFoundException
* in case the given {@code distributionsetTagId} doesn't
* exists.
*/
@RequestMapping(method = RequestMethod.DELETE, value = RestConstants.DISTRIBUTIONSET_REQUEST_MAPPING)
public ResponseEntity<Void> unassignDistributionSets(@PathVariable final Long distributionsetTagId) {
@Override
public ResponseEntity<Void> unassignDistributionSets(final Long distributionsetTagId) {
LOG.debug("Unassign all DS for ds tag {}", distributionsetTagId);
final DistributionSetTag tag = findDistributionTagById(distributionsetTagId);
if (tag.getAssignedToDistributionSet() == null) {
@@ -302,36 +171,22 @@ public class DistributionSetTagResource {
return new ResponseEntity<>(HttpStatus.OK);
}
final List<DistributionSet> distributionSets = distributionSetManagement.unAssignAllDistributionSetsByTag(tag);
final List<DistributionSet> distributionSets = this.distributionSetManagement
.unAssignAllDistributionSetsByTag(tag);
LOG.debug("Unassigned ds {}", distributionSets.size());
return new ResponseEntity<>(HttpStatus.OK);
}
/**
* Handles the DELETE request to unassign one distribution set from the
* given tag id.
*
* @param distributionsetTagId
* the ID of the distribution set tag
* @param distributionsetId
* the ID of the distribution set to unassign
* @return http status code
* @throws EntityNotFoundException
* in case the given {@code distributionsetTagId} doesn't
* exists.
*/
@RequestMapping(method = RequestMethod.DELETE, value = RestConstants.DISTRIBUTIONSET_REQUEST_MAPPING
+ "/{distributionsetId}")
public ResponseEntity<Void> unassignDistributionSet(@PathVariable final Long distributionsetTagId,
@PathVariable final Long distributionsetId) {
@Override
public ResponseEntity<Void> unassignDistributionSet(final Long distributionsetTagId, final Long distributionsetId) {
LOG.debug("Unassign ds {} for ds tag {}", distributionsetId, distributionsetTagId);
final DistributionSetTag tag = findDistributionTagById(distributionsetTagId);
distributionSetManagement.unAssignTag(distributionsetId, tag);
this.distributionSetManagement.unAssignTag(distributionsetId, tag);
return new ResponseEntity<>(HttpStatus.OK);
}
private DistributionSetTag findDistributionTagById(final Long distributionsetTagId) {
final DistributionSetTag tag = tagManagement.findDistributionSetTagById(distributionsetTagId);
final DistributionSetTag tag = this.tagManagement.findDistributionSetTagById(distributionsetTagId);
if (tag == null) {
throw new EntityNotFoundException("Distribution Tag with Id {" + distributionsetTagId + "} does not exist");
}

View File

@@ -18,6 +18,7 @@ import org.eclipse.hawkbit.repository.SoftwareManagement;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.model.DistributionSetType;
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
import org.eclipse.hawkbit.rest.resource.api.DistributionSetTypeRestApi;
import org.eclipse.hawkbit.rest.resource.model.distributionsettype.DistributionSetTypeRequestBodyPost;
import org.eclipse.hawkbit.rest.resource.model.distributionsettype.DistributionSetTypeRest;
import org.eclipse.hawkbit.rest.resource.model.distributionsettype.DistributionSetTypesRest;
@@ -101,13 +102,13 @@ final class DistributionSetTypeMapper {
result.setKey(type.getKey());
result.setModuleId(type.getId());
result.add(linkTo(methodOn(DistributionSetTypeResource.class).getDistributionSetType(result.getModuleId()))
result.add(linkTo(methodOn(DistributionSetTypeRestApi.class).getDistributionSetType(result.getModuleId()))
.withRel("self"));
result.add(linkTo(methodOn(DistributionSetTypeResource.class).getMandatoryModules(result.getModuleId()))
result.add(linkTo(methodOn(DistributionSetTypeRestApi.class).getMandatoryModules(result.getModuleId()))
.withRel(RestConstants.DISTRIBUTIONSETTYPE_V1_MANDATORY_MODULES));
result.add(linkTo(methodOn(DistributionSetTypeResource.class).getOptionalModules(result.getModuleId()))
result.add(linkTo(methodOn(DistributionSetTypeRestApi.class).getOptionalModules(result.getModuleId()))
.withRel(RestConstants.DISTRIBUTIONSETTYPE_V1_OPTIONAL_MODULES));
return result;

View File

@@ -19,6 +19,7 @@ import org.eclipse.hawkbit.repository.model.DistributionSetType;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
import org.eclipse.hawkbit.repository.rsql.RSQLUtility;
import org.eclipse.hawkbit.rest.resource.api.DistributionSetTypeRestApi;
import org.eclipse.hawkbit.rest.resource.model.IdRest;
import org.eclipse.hawkbit.rest.resource.model.distributionsettype.DistributionSetTypePagedList;
import org.eclipse.hawkbit.rest.resource.model.distributionsettype.DistributionSetTypeRequestBodyPost;
@@ -33,12 +34,9 @@ import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.domain.Sort;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@@ -47,12 +45,9 @@ import org.springframework.web.bind.annotation.RestController;
* {@link Artifact} CRUD operations.
*
*
*
*
*/
@RestController
@RequestMapping(RestConstants.DISTRIBUTIONSETTYPE_V1_REQUEST_MAPPING)
public class DistributionSetTypeResource {
public class DistributionSetTypeResource implements DistributionSetTypeRestApi {
@Autowired
private SoftwareManagement softwareManagement;
@@ -60,30 +55,7 @@ public class DistributionSetTypeResource {
@Autowired
private DistributionSetManagement distributionSetManagement;
/**
* Handles the GET request of retrieving all {@link DistributionSetType}s
* within SP.
*
* @param pagingOffsetParam
* the offset of list of modules 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=name==abc}
*
* @return a list of all {@link DistributionSetType} for a defined or
* default page request with status OK. The response is always
* paged. In any failure the JsonResponseExceptionHandler is
* handling the response.
*/
@RequestMapping(method = RequestMethod.GET, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
@Override
public ResponseEntity<DistributionSetTypePagedList> getDistributionSetTypes(
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam,
@@ -112,19 +84,7 @@ public class DistributionSetTypeResource {
return new ResponseEntity<>(new DistributionSetTypePagedList(rest, countModulesAll), HttpStatus.OK);
}
/**
* Handles the GET request of retrieving a single
* {@link DistributionSetType} within SP.
*
* @param distributionSetTypeId
* the ID of the module type to retrieve
*
* @return a single softwareModule with status OK.
* @throws EntityNotFoundException
* in case no with the given {@code softwareModuleId} exists.
*/
@RequestMapping(method = RequestMethod.GET, value = "/{distributionSetTypeId}", produces = { "application/hal+json",
MediaType.APPLICATION_JSON_VALUE })
@Override
public ResponseEntity<DistributionSetTypeRest> getDistributionSetType(
@PathVariable final Long distributionSetTypeId) {
final DistributionSetType foundType = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId);
@@ -132,15 +92,7 @@ public class DistributionSetTypeResource {
return new ResponseEntity<>(DistributionSetTypeMapper.toResponse(foundType), HttpStatus.OK);
}
/**
* Handles the DELETE request for a single Distribution Set Type within SP.
*
* @param distributionSetTypeId
* the ID of the module to retrieve
* @return status OK if delete as sucessfull.
*
*/
@RequestMapping(method = RequestMethod.DELETE, value = "/{distributionSetTypeId}")
@Override
public ResponseEntity<Void> deleteDistributionSetType(@PathVariable final Long distributionSetTypeId) {
final DistributionSetType module = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId);
@@ -149,17 +101,7 @@ public class DistributionSetTypeResource {
return new ResponseEntity<>(HttpStatus.OK);
}
/**
* Handles the PUT request of updating a Distribution Set Type within SP.
*
* @param distributionSetTypeId
* the ID of the software module in the URL
* @param restDistributionSetType
* the module type to be updated.
* @return status OK if update is successful
*/
@RequestMapping(method = RequestMethod.PUT, value = "/{distributionSetTypeId}", consumes = { "application/hal+json",
MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
@Override
public ResponseEntity<DistributionSetTypeRest> updateDistributionSetType(
@PathVariable final Long distributionSetTypeId,
@RequestBody final DistributionSetTypeRequestBodyPut restDistributionSetType) {
@@ -176,19 +118,7 @@ public class DistributionSetTypeResource {
return new ResponseEntity<>(DistributionSetTypeMapper.toResponse(updatedDistributionSetType), HttpStatus.OK);
}
/**
* Handles the POST request of creating new {@link DistributionSetType}s
* within SP. The request body must always be a list of types.
*
* @param distributionSetTypes
* the modules to be created.
* @return In case all modules could successful created the ResponseEntity
* with status code 201 - Created but without ResponseBody. In any
* failure the JsonResponseExceptionHandler is handling the
* response.
*/
@RequestMapping(method = RequestMethod.POST, consumes = { "application/hal+json",
MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
@Override
public ResponseEntity<DistributionSetTypesRest> createDistributionSetTypes(
@RequestBody final List<DistributionSetTypeRequestBodyPost> distributionSetTypes) {
@@ -208,17 +138,7 @@ public class DistributionSetTypeResource {
return module;
}
/**
* Handles the GET request of retrieving the list of mandatory software
* module types in that distribution set type.
*
* @param distributionSetTypeId
* of the {@link DistributionSetType}.
* @return Unpaged list of module types and OK in case of success.
*/
@RequestMapping(method = RequestMethod.GET, value = "/{distributionSetTypeId}/"
+ RestConstants.DISTRIBUTIONSETTYPE_V1_MANDATORY_MODULE_TYPES, produces = { "application/hal+json",
MediaType.APPLICATION_JSON_VALUE })
@Override
public ResponseEntity<SoftwareModuleTypesRest> getMandatoryModules(@PathVariable final Long distributionSetTypeId) {
final DistributionSetType foundType = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId);
@@ -229,19 +149,7 @@ public class DistributionSetTypeResource {
return new ResponseEntity<>(rest, HttpStatus.OK);
}
/**
* Handles the GET request of retrieving the single mandatory software
* module type in that distribution set type.
*
* @param distributionSetTypeId
* of the {@link DistributionSetType}.
* @param softwareModuleTypeId
* of {@link SoftwareModuleType}.
* @return Unpaged list of module types and OK in case of success.
*/
@RequestMapping(method = RequestMethod.GET, value = "/{distributionSetTypeId}/"
+ RestConstants.DISTRIBUTIONSETTYPE_V1_MANDATORY_MODULE_TYPES
+ "/{softwareModuleTypeId}", produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
@Override
public ResponseEntity<SoftwareModuleTypeRest> getMandatoryModule(@PathVariable final Long distributionSetTypeId,
@PathVariable final Long softwareModuleTypeId) {
@@ -257,19 +165,7 @@ public class DistributionSetTypeResource {
return new ResponseEntity<>(SoftwareModuleTypeMapper.toResponse(foundSmType), HttpStatus.OK);
}
/**
* Handles the GET request of retrieving the single optional software module
* type in that distribution set type.
*
* @param distributionSetTypeId
* of the {@link DistributionSetType}.
* @param softwareModuleTypeId
* of {@link SoftwareModuleType}.
* @return Unpaged list of module types and OK in case of success.
*/
@RequestMapping(method = RequestMethod.GET, value = "/{distributionSetTypeId}/"
+ RestConstants.DISTRIBUTIONSETTYPE_V1_OPTIONAL_MODULE_TYPES
+ "/{softwareModuleTypeId}", produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
@Override
public ResponseEntity<SoftwareModuleTypeRest> getOptionalModule(@PathVariable final Long distributionSetTypeId,
@PathVariable final Long softwareModuleTypeId) {
@@ -285,17 +181,7 @@ public class DistributionSetTypeResource {
return new ResponseEntity<>(SoftwareModuleTypeMapper.toResponse(foundSmType), HttpStatus.OK);
}
/**
* Handles the GET request of retrieving the list of optional software
* module types in that distribution set type.
*
* @param distributionSetTypeId
* of the {@link DistributionSetType}.
* @return Unpaged list of module types and OK in case of success.
*/
@RequestMapping(method = RequestMethod.GET, value = "/{distributionSetTypeId}/"
+ RestConstants.DISTRIBUTIONSETTYPE_V1_OPTIONAL_MODULE_TYPES, produces = { "application/hal+json",
MediaType.APPLICATION_JSON_VALUE })
@Override
public ResponseEntity<SoftwareModuleTypesRest> getOptionalModules(@PathVariable final Long distributionSetTypeId) {
final DistributionSetType foundType = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId);
@@ -306,20 +192,7 @@ public class DistributionSetTypeResource {
return new ResponseEntity<>(rest, HttpStatus.OK);
}
/**
* Handles DELETE request for removing a mandatory module from the
* {@link DistributionSetType}.
*
* @param distributionSetTypeId
* of the {@link DistributionSetType}.
* @param softwareModuleTypeId
* of the {@link SoftwareModuleType} to remove
*
* @return OK if the request was successful
*/
@RequestMapping(method = RequestMethod.DELETE, value = "/{distributionSetTypeId}/"
+ RestConstants.DISTRIBUTIONSETTYPE_V1_MANDATORY_MODULE_TYPES
+ "/{softwareModuleTypeId}", produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
@Override
public ResponseEntity<Void> removeMandatoryModule(@PathVariable final Long distributionSetTypeId,
@PathVariable final Long softwareModuleTypeId) {
@@ -339,20 +212,7 @@ public class DistributionSetTypeResource {
return new ResponseEntity<>(HttpStatus.OK);
}
/**
* Handles DELETE request for removing an optional module from the
* {@link DistributionSetType}.
*
* @param distributionSetTypeId
* of the {@link DistributionSetType}.
* @param softwareModuleTypeId
* of the {@link SoftwareModuleType} to remove
*
* @return OK if the request was successful
*/
@RequestMapping(method = RequestMethod.DELETE, value = "/{distributionSetTypeId}/"
+ RestConstants.DISTRIBUTIONSETTYPE_V1_OPTIONAL_MODULE_TYPES
+ "/{softwareModuleTypeId}", produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
@Override
public ResponseEntity<Void> removeOptionalModule(@PathVariable final Long distributionSetTypeId,
@PathVariable final Long softwareModuleTypeId) {
final DistributionSetType foundType = findDistributionSetTypeWithExceptionIfNotFound(distributionSetTypeId);
@@ -371,21 +231,7 @@ public class DistributionSetTypeResource {
return new ResponseEntity<>(HttpStatus.OK);
}
/**
* Handles the POST request for adding a mandatory software module type to a
* distribution set type.
*
* @param distributionSetTypeId
* of the {@link DistributionSetType}.
* @param smtId
* of the {@link SoftwareModuleType} to add
*
* @return OK if the request was successful
*/
@RequestMapping(method = RequestMethod.POST, value = "/{distributionSetTypeId}/"
+ RestConstants.DISTRIBUTIONSETTYPE_V1_MANDATORY_MODULE_TYPES, consumes = { "application/hal+json",
MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json",
MediaType.APPLICATION_JSON_VALUE })
@Override
public ResponseEntity<Void> addMandatoryModule(@PathVariable final Long distributionSetTypeId,
@RequestBody final IdRest smtId) {
@@ -400,21 +246,7 @@ public class DistributionSetTypeResource {
return new ResponseEntity<>(HttpStatus.OK);
}
/**
* Handles the POST request for adding an optional software module type to a
* distribution set type.
*
* @param distributionSetTypeId
* of the {@link DistributionSetType}.
* @param smtId
* of the {@link SoftwareModuleType} to add
*
* @return OK if the request was successful
*/
@RequestMapping(method = RequestMethod.POST, value = "/{distributionSetTypeId}/"
+ RestConstants.DISTRIBUTIONSETTYPE_V1_OPTIONAL_MODULE_TYPES, consumes = { "application/hal+json",
MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json",
MediaType.APPLICATION_JSON_VALUE })
@Override
public ResponseEntity<Void> addOptionalModule(@PathVariable final Long distributionSetTypeId,
@RequestBody final IdRest smtId) {

View File

@@ -0,0 +1,92 @@
/**
* 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.rest.resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.hawkbit.artifact.repository.model.DbArtifact;
import org.eclipse.hawkbit.repository.ArtifactManagement;
import org.eclipse.hawkbit.repository.SoftwareManagement;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.model.LocalArtifact;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.rest.resource.helper.RestResourceConversionHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
/**
* @author Jonathan Knoblauch
*
*/
@RestController
@RequestMapping(RestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING)
public class DownloadArtifactResource {
@Autowired
private SoftwareManagement softwareManagement;
@Autowired
private ArtifactManagement artifactManagement;
/**
* Handles the GET request for downloading an artifact.
*
* @param softwareModuleId
* of the parent SoftwareModule
* @param artifactId
* of the related LocalArtifact
* @param servletResponse
* of the servlet
* @param request
* of the client
*
* @return responseEntity with status ok if successful
*/
@RequestMapping(method = RequestMethod.GET, value = "/{softwareModuleId}/artifacts/{artifactId}/download")
@ResponseBody
public ResponseEntity<Void> downloadArtifact(@PathVariable("softwareModuleId") final Long softwareModuleId,
@PathVariable("artifactId") final Long artifactId, final HttpServletResponse servletResponse,
final HttpServletRequest request) {
final SoftwareModule module = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, artifactId);
if (null == module || !module.getLocalArtifact(artifactId).isPresent()) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
final LocalArtifact artifact = module.getLocalArtifact(artifactId).get();
final DbArtifact file = artifactManagement.loadLocalArtifactBinary(artifact);
final String ifMatch = request.getHeader("If-Match");
if (ifMatch != null && !RestResourceConversionHelper.matchesHttpHeader(ifMatch, artifact.getSha1Hash())) {
return new ResponseEntity<>(HttpStatus.PRECONDITION_FAILED);
}
return RestResourceConversionHelper.writeFileResponse(artifact, servletResponse, request, file);
}
private SoftwareModule findSoftwareModuleWithExceptionIfNotFound(final Long softwareModuleId,
final Long artifactId) {
final SoftwareModule module = softwareManagement.findSoftwareModuleById(softwareModuleId);
if (module == null) {
throw new EntityNotFoundException("SoftwareModule with Id {" + softwareModuleId + "} does not exist");
} else if (artifactId != null && !module.getLocalArtifact(artifactId).isPresent()) {
throw new EntityNotFoundException("Artifact with Id {" + artifactId + "} does not exist");
}
return module;
}
}

View File

@@ -23,6 +23,7 @@ import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupErrorCondit
import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupSuccessAction;
import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupSuccessCondition;
import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus;
import org.eclipse.hawkbit.rest.resource.api.RolloutRestApi;
import org.eclipse.hawkbit.rest.resource.helper.RestResourceConversionHelper;
import org.eclipse.hawkbit.rest.resource.model.rollout.RolloutCondition.Condition;
import org.eclipse.hawkbit.rest.resource.model.rollout.RolloutErrorAction.ErrorAction;
@@ -70,12 +71,12 @@ final class RolloutMapper {
rollout.getTotalTargetCountStatus().getTotalTargetCountByStatus(status));
}
body.add(linkTo(methodOn(RolloutResource.class).getRollout(rollout.getId())).withRel("self"));
body.add(linkTo(methodOn(RolloutResource.class).start(rollout.getId(), false)).withRel("start"));
body.add(linkTo(methodOn(RolloutResource.class).start(rollout.getId(), true)).withRel("startAsync"));
body.add(linkTo(methodOn(RolloutResource.class).pause(rollout.getId())).withRel("pause"));
body.add(linkTo(methodOn(RolloutResource.class).resume(rollout.getId())).withRel("resume"));
body.add(linkTo(methodOn(RolloutResource.class).getRolloutGroups(rollout.getId(),
body.add(linkTo(methodOn(RolloutRestApi.class).getRollout(rollout.getId())).withRel("self"));
body.add(linkTo(methodOn(RolloutRestApi.class).start(rollout.getId(), false)).withRel("start"));
body.add(linkTo(methodOn(RolloutRestApi.class).start(rollout.getId(), true)).withRel("startAsync"));
body.add(linkTo(methodOn(RolloutRestApi.class).pause(rollout.getId())).withRel("pause"));
body.add(linkTo(methodOn(RolloutRestApi.class).resume(rollout.getId())).withRel("resume"));
body.add(linkTo(methodOn(RolloutRestApi.class).getRolloutGroups(rollout.getId(),
Integer.parseInt(RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET),
Integer.parseInt(RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT), null, null)).withRel("groups"));
return body;
@@ -115,8 +116,9 @@ final class RolloutMapper {
body.setName(rolloutGroup.getName());
body.setRolloutGroupId(rolloutGroup.getId());
body.setStatus(rolloutGroup.getStatus().toString().toLowerCase());
body.add(linkTo(methodOn(RolloutResource.class).getRolloutGroup(rolloutGroup.getRollout().getId(),
rolloutGroup.getId())).withRel("self"));
body.add(linkTo(
methodOn(RolloutRestApi.class).getRolloutGroup(rolloutGroup.getRollout().getId(), rolloutGroup.getId()))
.withRel("self"));
return body;
}

View File

@@ -27,6 +27,7 @@ import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupSuccessActi
import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupSuccessCondition;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.rsql.RSQLUtility;
import org.eclipse.hawkbit.rest.resource.api.RolloutRestApi;
import org.eclipse.hawkbit.rest.resource.model.rollout.RolloutPagedList;
import org.eclipse.hawkbit.rest.resource.model.rollout.RolloutResponseBody;
import org.eclipse.hawkbit.rest.resource.model.rollout.RolloutRestRequestBody;
@@ -40,13 +41,8 @@ import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
@@ -54,8 +50,9 @@ import org.springframework.web.bind.annotation.RestController;
*
*/
@RestController
@RequestMapping(RestConstants.ROLLOUT_V1_REQUEST_MAPPING)
public class RolloutResource {
public class RolloutResource implements RolloutRestApi {
private static final String DOES_NOT_EXIST = "} does not exist";
@Autowired
private RolloutManagement rolloutManagement;
@@ -66,31 +63,9 @@ public class RolloutResource {
@Autowired
private DistributionSetManagement distributionSetManagement;
/**
* Handles the GET request of retrieving all rollouts.
*
* @param pagingOffsetParam
* the offset of list of rollouts 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=name==abc}
* @return a list of all rollouts for a defined or default page request with
* status OK. The response is always paged. In any failure the
* JsonResponseExceptionHandler is handling the response.
*/
@RequestMapping(method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE, "application/hal+json" })
public ResponseEntity<RolloutPagedList> getRollouts(
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) {
@Override
public ResponseEntity<RolloutPagedList> getRollouts(final int pagingOffsetParam, final int pagingLimitParam,
final String sortParam, final String rsqlParam) {
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
@@ -100,50 +75,28 @@ public class RolloutResource {
final Page<Rollout> findModulesAll;
if (rsqlParam != null) {
findModulesAll = rolloutManagement
findModulesAll = this.rolloutManagement
.findAllWithDetailedStatusByPredicate(RSQLUtility.parse(rsqlParam, RolloutFields.class), pageable);
} else {
findModulesAll = rolloutManagement.findAll(pageable);
findModulesAll = this.rolloutManagement.findAll(pageable);
}
final List<RolloutResponseBody> rest = RolloutMapper.toResponseRollout(findModulesAll.getContent());
return new ResponseEntity<>(new RolloutPagedList(rest, findModulesAll.getTotalElements()), HttpStatus.OK);
}
/**
* Handles the GET request of retrieving a single rollout.
*
* @param rolloutId
* the ID of the rollout to retrieve
* @return a single rollout with status OK.
* @throws EntityNotFoundException
* in case no rollout with the given {@code rolloutId} exists.
*/
@RequestMapping(value = "/{rolloutId}", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE,
"application/hal+json" })
public ResponseEntity<RolloutResponseBody> getRollout(@PathVariable("rolloutId") final Long rolloutId) {
@Override
public ResponseEntity<RolloutResponseBody> getRollout(final Long rolloutId) {
final Rollout findRolloutById = findRolloutOrThrowException(rolloutId);
return new ResponseEntity<>(RolloutMapper.toResponseRollout(findRolloutById), HttpStatus.OK);
}
/**
* Handles the POST request for creating rollout.
*
* @param rollout
* the rollout body to be created.
* @return In case rollout could successful created the ResponseEntity with
* status code 201 with the successfully created rollout. In any
* failure the JsonResponseExceptionHandler is handling the
* response.
* @throws EntityNotFoundException
*/
@RequestMapping(method = RequestMethod.POST, consumes = { "application/hal+json",
MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
@Override
public ResponseEntity<RolloutResponseBody> create(@RequestBody final RolloutRestRequestBody rolloutRequestBody) {
// first check the given RSQL query if it's well formed, otherwise and
// exception is thrown
RSQLUtility.isValid(rolloutRequestBody.getTargetFilterQuery());
RSQLUtility.parse(rolloutRequestBody.getTargetFilterQuery(), TargetFields.class);
final DistributionSet distributionSet = findDistributionSetOrThrowException(rolloutRequestBody);
@@ -181,7 +134,7 @@ public class RolloutResource {
.successCondition(successCondition, successConditionExpr)
.successAction(successAction, successActionExpr).errorCondition(errorCondition, errorConditionExpr)
.errorAction(errorAction, errorActionExpr).build();
final Rollout rollout = rolloutManagement.createRollout(
final Rollout rollout = this.rolloutManagement.createRollout(
RolloutMapper.fromRequest(rolloutRequestBody, distributionSet,
rolloutRequestBody.getTargetFilterQuery()),
rolloutRequestBody.getAmountGroups(), rolloutGroupConditions);
@@ -189,97 +142,34 @@ public class RolloutResource {
return ResponseEntity.status(HttpStatus.CREATED).body(RolloutMapper.toResponseRollout(rollout));
}
/**
* Handles the POST request for starting a rollout.
*
* @param rolloutId
* the ID of the rollout to be started.
* @return OK response (200) if rollout could be started. In case of any
* exception the corresponding errors occur.
* @throws EntityNotFoundException
* @see RolloutManagement#startRollout(Rollout)
* @see ResponseExceptionHandler
*/
@RequestMapping(method = RequestMethod.POST, value = "/{rolloutId}/start", produces = { "application/hal+json",
MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<Void> start(@PathVariable("rolloutId") final Long rolloutId,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_ASYNC, defaultValue = "false") final boolean startAsync) {
@Override
public ResponseEntity<Void> start(final Long rolloutId, final boolean startAsync) {
final Rollout rollout = findRolloutOrThrowException(rolloutId);
if (startAsync) {
rolloutManagement.startRolloutAsync(rollout);
this.rolloutManagement.startRolloutAsync(rollout);
} else {
rolloutManagement.startRollout(rollout);
this.rolloutManagement.startRollout(rollout);
}
return ResponseEntity.ok().build();
}
/**
* Handles the POST request for pausing a rollout.
*
* @param rolloutId
* the ID of the rollout to be paused.
* @return OK response (200) if rollout could be paused. In case of any
* exception the corresponding errors occur.
* @throws EntityNotFoundException
* @see RolloutManagement#pauseRollout(Rollout)
* @see ResponseExceptionHandler
*/
@RequestMapping(method = RequestMethod.POST, value = "/{rolloutId}/pause", produces = { "application/hal+json",
MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<Void> pause(@PathVariable("rolloutId") final Long rolloutId) {
@Override
public ResponseEntity<Void> pause(final Long rolloutId) {
final Rollout rollout = findRolloutOrThrowException(rolloutId);
rolloutManagement.pauseRollout(rollout);
this.rolloutManagement.pauseRollout(rollout);
return ResponseEntity.ok().build();
}
/**
* Handles the POST request for resuming a rollout.
*
* @param rolloutId
* the ID of the rollout to be resumed.
* @return OK response (200) if rollout could be resumed. In case of any
* exception the corresponding errors occur.
* @throws EntityNotFoundException
* @see RolloutManagement#resumeRollout(Rollout)
* @see ResponseExceptionHandler
*/
@RequestMapping(method = RequestMethod.POST, value = "/{rolloutId}/resume", produces = { "application/hal+json",
MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<Void> resume(@PathVariable("rolloutId") final Long rolloutId) {
@Override
public ResponseEntity<Void> resume(final Long rolloutId) {
final Rollout rollout = findRolloutOrThrowException(rolloutId);
rolloutManagement.resumeRollout(rollout);
this.rolloutManagement.resumeRollout(rollout);
return ResponseEntity.ok().build();
}
/**
* Handles the GET request of retrieving all rollout groups referred to a
* rollout.
*
* @param pagingOffsetParam
* the offset of list of rollout groups 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=name==abc}
* @return a list of all rollout groups referred to a rollout for a defined
* or default page request with status OK. The response is always
* paged. In any failure the JsonResponseExceptionHandler is
* handling the response.
*/
@RequestMapping(method = RequestMethod.GET, value = "/{rolloutId}/deploygroups", produces = {
MediaType.APPLICATION_JSON_VALUE, "application/hal+json" })
public ResponseEntity<RolloutGroupPagedList> getRolloutGroups(@PathVariable("rolloutId") final Long rolloutId,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) {
@Override
public ResponseEntity<RolloutGroupPagedList> getRolloutGroups(final Long rolloutId, final int pagingOffsetParam,
final int pagingLimitParam, final String sortParam, final String rsqlParam) {
final Rollout rollout = findRolloutOrThrowException(rolloutId);
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
@@ -290,10 +180,10 @@ public class RolloutResource {
final Page<RolloutGroup> findRolloutGroupsAll;
if (rsqlParam != null) {
findRolloutGroupsAll = rolloutGroupManagement.findRolloutGroupsByPredicate(rollout,
findRolloutGroupsAll = this.rolloutGroupManagement.findRolloutGroupsByPredicate(rollout,
RSQLUtility.parse(rsqlParam, RolloutGroupFields.class), pageable);
} else {
findRolloutGroupsAll = rolloutGroupManagement.findRolloutGroupsByRolloutId(rolloutId, pageable);
findRolloutGroupsAll = this.rolloutGroupManagement.findRolloutGroupsByRolloutId(rolloutId, pageable);
}
final List<RolloutGroupResponseBody> rest = RolloutMapper
@@ -302,56 +192,16 @@ public class RolloutResource {
HttpStatus.OK);
}
/**
* Handles the GET request for retrieving a single rollout group.
*
* @param rolloutId
* the rolloutId to retrieve the group from
* @param groupId
* the groupId to retrieve the rollout group
* @return the OK response containing the {@link RolloutGroupResponseBody}
* @throws EntityNotFoundException
*/
@RequestMapping(method = RequestMethod.GET, value = "/{rolloutId}/deploygroups/{groupId}", produces = {
MediaType.APPLICATION_JSON_VALUE, "application/hal+json" })
public ResponseEntity<RolloutGroupResponseBody> getRolloutGroup(@PathVariable("rolloutId") final Long rolloutId,
@PathVariable("groupId") final Long groupId) {
@Override
public ResponseEntity<RolloutGroupResponseBody> getRolloutGroup(final Long rolloutId, final Long groupId) {
findRolloutOrThrowException(rolloutId);
final RolloutGroup rolloutGroup = findRolloutGroupOrThrowException(groupId);
return ResponseEntity.ok(RolloutMapper.toResponseRolloutGroup(rolloutGroup));
}
/**
* Retrieves all targets related to a specific rollout group.
*
* @param rolloutId
* the ID of the rollout
* @param groupId
* the ID of the rollout group
* @param pagingOffsetParam
* the offset of list of rollout groups 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=name==abc}
* @return a paged list of targets related to a specific rollout and rollout
* group.
*/
@RequestMapping(method = RequestMethod.GET, value = "/{rolloutId}/deploygroups/{groupId}/targets", produces = {
MediaType.APPLICATION_JSON_VALUE, "application/hal+json" })
public ResponseEntity<TargetPagedList> getRolloutGroupTargets(@PathVariable("rolloutId") final Long rolloutId,
@PathVariable("groupId") final Long groupId,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) {
@Override
public ResponseEntity<TargetPagedList> getRolloutGroupTargets(final Long rolloutId, final Long groupId,
final int pagingOffsetParam, final int pagingLimitParam, final String sortParam, final String rsqlParam) {
findRolloutOrThrowException(rolloutId);
final RolloutGroup rolloutGroup = findRolloutGroupOrThrowException(groupId);
@@ -364,10 +214,11 @@ public class RolloutResource {
final Page<Target> rolloutGroupTargets;
if (rsqlParam != null) {
final Specification<Target> rsqlSpecification = RSQLUtility.parse(rsqlParam, TargetFields.class);
rolloutGroupTargets = rolloutGroupManagement.findRolloutGroupTargets(rolloutGroup, rsqlSpecification,
rolloutGroupTargets = this.rolloutGroupManagement.findRolloutGroupTargets(rolloutGroup, rsqlSpecification,
pageable);
} else {
final Page<Target> pageTargets = rolloutGroupManagement.findRolloutGroupTargets(rolloutGroup, pageable);
final Page<Target> pageTargets = this.rolloutGroupManagement.findRolloutGroupTargets(rolloutGroup,
pageable);
rolloutGroupTargets = pageTargets;
}
final List<TargetRest> rest = TargetMapper.toResponse(rolloutGroupTargets.getContent());
@@ -375,27 +226,27 @@ public class RolloutResource {
}
private Rollout findRolloutOrThrowException(final Long rolloutId) {
final Rollout rollout = rolloutManagement.findRolloutWithDetailedStatus(rolloutId);
final Rollout rollout = this.rolloutManagement.findRolloutWithDetailedStatus(rolloutId);
if (rollout == null) {
throw new EntityNotFoundException("Rollout with Id {" + rolloutId + "} does not exist");
throw new EntityNotFoundException("Rollout with Id {" + rolloutId + DOES_NOT_EXIST);
}
return rollout;
}
private RolloutGroup findRolloutGroupOrThrowException(final Long rolloutGroupId) {
final RolloutGroup rolloutGroup = rolloutGroupManagement.findRolloutGroupById(rolloutGroupId);
final RolloutGroup rolloutGroup = this.rolloutGroupManagement.findRolloutGroupById(rolloutGroupId);
if (rolloutGroup == null) {
throw new EntityNotFoundException("Group with Id {" + rolloutGroupId + "} does not exist");
throw new EntityNotFoundException("Group with Id {" + rolloutGroupId + DOES_NOT_EXIST);
}
return rolloutGroup;
}
private DistributionSet findDistributionSetOrThrowException(final RolloutRestRequestBody rolloutRequestBody) {
final DistributionSet ds = distributionSetManagement
final DistributionSet ds = this.distributionSetManagement
.findDistributionSetById(rolloutRequestBody.getDistributionSetId());
if (ds == null) {
throw new EntityNotFoundException(
"DistributionSet with Id {" + rolloutRequestBody.getDistributionSetId() + "} does not exist");
"DistributionSet with Id {" + rolloutRequestBody.getDistributionSetId() + DOES_NOT_EXIST);
}
return ds;
}

View File

@@ -21,6 +21,8 @@ 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.rest.resource.api.SoftwareModuleRestAPI;
import org.eclipse.hawkbit.rest.resource.api.SoftwareModuleTypeRestApi;
import org.eclipse.hawkbit.rest.resource.model.MetadataRest;
import org.eclipse.hawkbit.rest.resource.model.artifact.ArtifactHash;
import org.eclipse.hawkbit.rest.resource.model.artifact.ArtifactRest;
@@ -142,13 +144,13 @@ public final class SoftwareModuleMapper {
response.setType(baseSofwareModule.getType().getKey());
response.setVendor(baseSofwareModule.getVendor());
response.add(linkTo(methodOn(SoftwareModuleResource.class).getArtifacts(response.getModuleId()))
response.add(linkTo(methodOn(SoftwareModuleRestAPI.class).getArtifacts(response.getModuleId()))
.withRel(RestConstants.SOFTWAREMODULE_V1_ARTIFACT));
response.add(linkTo(methodOn(SoftwareModuleResource.class).getSoftwareModule(response.getModuleId()))
response.add(linkTo(methodOn(SoftwareModuleRestAPI.class).getSoftwareModule(response.getModuleId()))
.withRel("self"));
response.add(linkTo(
methodOn(SoftwareModuleTypeResource.class).getSoftwareModuleType(baseSofwareModule.getType().getId()))
methodOn(SoftwareModuleTypeRestApi.class).getSoftwareModuleType(baseSofwareModule.getType().getId()))
.withRel(RestConstants.SOFTWAREMODULE_V1_TYPE));
response.add(linkTo(methodOn(SoftwareModuleResource.class).getMetadata(response.getModuleId(),
@@ -178,13 +180,13 @@ public final class SoftwareModuleMapper {
RestModelMapper.mapBaseToBase(artifactRest, artifact);
artifactRest.add(linkTo(methodOn(SoftwareModuleResource.class).getArtifact(artifact.getSoftwareModule().getId(),
artifactRest.add(linkTo(methodOn(SoftwareModuleRestAPI.class).getArtifact(artifact.getSoftwareModule().getId(),
artifact.getId())).withRel("self"));
if (artifact instanceof LocalArtifact) {
artifactRest.add(
linkTo(methodOn(SoftwareModuleResource.class).downloadArtifact(artifact.getSoftwareModule().getId(),
artifact.getId(), null, null)).withRel("download"));
artifactRest.add(linkTo(methodOn(DownloadArtifactResource.class)
.downloadArtifact(artifact.getSoftwareModule().getId(), artifact.getId(), null, null))
.withRel("download"));
}
return artifactRest;

View File

@@ -11,22 +11,17 @@ package org.eclipse.hawkbit.rest.resource;
import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.hawkbit.artifact.repository.model.DbArtifact;
import org.eclipse.hawkbit.repository.ArtifactManagement;
import org.eclipse.hawkbit.repository.SoftwareManagement;
import org.eclipse.hawkbit.repository.SoftwareModuleFields;
import org.eclipse.hawkbit.repository.SoftwareModuleMetadataFields;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.model.Artifact;
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.SwMetadataCompositeKey;
import org.eclipse.hawkbit.repository.rsql.RSQLUtility;
import org.eclipse.hawkbit.rest.resource.helper.RestResourceConversionHelper;
import org.eclipse.hawkbit.rest.resource.api.SoftwareModuleRestAPI;
import org.eclipse.hawkbit.rest.resource.model.MetadataRest;
import org.eclipse.hawkbit.rest.resource.model.MetadataRestPageList;
import org.eclipse.hawkbit.rest.resource.model.artifact.ArtifactRest;
@@ -44,14 +39,10 @@ import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.domain.Sort;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
@@ -59,13 +50,9 @@ import org.springframework.web.multipart.MultipartFile;
* REST Resource handling for {@link SoftwareModule} and related
* {@link Artifact} CRUD operations.
*
*
*
*
*/
@RestController
@RequestMapping(RestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING)
public class SoftwareModuleResource {
public class SoftwareModuleResource implements SoftwareModuleRestAPI {
private static final Logger LOG = LoggerFactory.getLogger(SoftwareModuleResource.class);
@Autowired
@@ -74,25 +61,7 @@ public class SoftwareModuleResource {
@Autowired
private SoftwareManagement softwareManagement;
/**
* Handles POST request for artifact upload.
*
* @param softwareModuleId
* of the parent {@link SoftwareModule}
* @param file
* that has to be uploaded
* @param optionalFileName
* to override {@link MultipartFile#getOriginalFilename()}
* @param md5Sum
* checksum for uploaded content check
* @param sha1Sum
* checksum for uploaded content check
*
* @return {@link ResponseEntity} if status {@link HttpStatus#CREATED} if
* successful
*/
@RequestMapping(method = RequestMethod.POST, value = "/{softwareModuleId}/artifacts", produces = {
"application/hal+json", MediaType.APPLICATION_JSON_VALUE })
@Override
public ResponseEntity<ArtifactRest> uploadArtifact(@PathVariable final Long softwareModuleId,
@RequestParam("file") final MultipartFile file,
@RequestParam(value = "filename", required = false) final String optionalFileName,
@@ -123,19 +92,7 @@ public class SoftwareModuleResource {
}
/**
* Handles the GET request of retrieving all meta data of artifacts assigned
* to a software module.
*
* @param softwareModuleId
* of the parent {@link SoftwareModule}
*
* @return {@link ResponseEntity} with status {@link HttpStatus#OK} if
* successful
*/
@RequestMapping(method = RequestMethod.GET, value = "/{softwareModuleId}/artifacts", produces = {
"application/hal+json", MediaType.APPLICATION_JSON_VALUE })
@ResponseBody
@Override
public ResponseEntity<ArtifactsRest> getArtifacts(@PathVariable final Long softwareModuleId) {
final SoftwareModule module = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null);
@@ -146,55 +103,49 @@ public class SoftwareModuleResource {
* Handles the GET request for downloading an artifact.
*
* @param softwareModuleId
* of the parent {@link SoftwareModule}
* of the parent SoftwareModule
* @param artifactId
* of the related {@link LocalArtifact}
* of the related LocalArtifact
* @param servletResponse
* of the servlet
* @param request
* of the client
*
* @return {@link ResponseEntity} with status {@link HttpStatus#OK} if
* successful
* @return responseEntity with status ok if successful
*/
@RequestMapping(method = RequestMethod.GET, value = "/{softwareModuleId}/artifacts/{artifactId}/download")
@ResponseBody
public ResponseEntity<Void> downloadArtifact(@PathVariable final Long softwareModuleId,
@PathVariable final Long artifactId, final HttpServletResponse servletResponse,
final HttpServletRequest request) {
final SoftwareModule module = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, artifactId);
// @RequestMapping(method = RequestMethod.GET, value =
// RestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING
// + "/{softwareModuleId}/artifacts/{artifactId}/download")
// @ResponseBody
// public ResponseEntity<Void> downloadArtifact(@PathVariable final Long
// softwareModuleId,
// @PathVariable final Long artifactId, final HttpServletResponse
// servletResponse,
// final HttpServletRequest request) {
// final SoftwareModule module =
// findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, artifactId);
//
// if (null == module || !module.getLocalArtifact(artifactId).isPresent()) {
// return new ResponseEntity<>(HttpStatus.NOT_FOUND);
// }
//
// final LocalArtifact artifact = module.getLocalArtifact(artifactId).get();
// final DbArtifact file =
// artifactManagement.loadLocalArtifactBinary(artifact);
//
// final String ifMatch = request.getHeader("If-Match");
// if (ifMatch != null &&
// !RestResourceConversionHelper.matchesHttpHeader(ifMatch,
// artifact.getSha1Hash())) {
// return new ResponseEntity<>(HttpStatus.PRECONDITION_FAILED);
// }
//
// return RestResourceConversionHelper.writeFileResponse(artifact,
// servletResponse, request, file);
//
// }
if (null == module || !module.getLocalArtifact(artifactId).isPresent()) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
final LocalArtifact artifact = module.getLocalArtifact(artifactId).get();
final DbArtifact file = artifactManagement.loadLocalArtifactBinary(artifact);
final String ifMatch = request.getHeader("If-Match");
if (ifMatch != null && !RestResourceConversionHelper.matchesHttpHeader(ifMatch, artifact.getSha1Hash())) {
return new ResponseEntity<>(HttpStatus.PRECONDITION_FAILED);
}
return RestResourceConversionHelper.writeFileResponse(artifact, servletResponse, request, file);
}
/**
* Handles the GET request of retrieving a single Artifact meta data
* request.
*
* @param softwareModuleId
* of the parent {@link SoftwareModule}
* @param artifactId
* of the related {@link LocalArtifact}
*
* @return {@link ResponseEntity} with status {@link HttpStatus#OK} if
* successful
*/
@RequestMapping(method = RequestMethod.GET, value = "/{softwareModuleId}/artifacts/{artifactId}", produces = {
"application/hal+json", MediaType.APPLICATION_JSON_VALUE })
@ResponseBody
@Override
public ResponseEntity<ArtifactRest> getArtifact(@PathVariable final Long softwareModuleId,
@PathVariable final Long artifactId) {
final SoftwareModule module = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, artifactId);
@@ -203,18 +154,7 @@ public class SoftwareModuleResource {
HttpStatus.OK);
}
/**
* Handles the DELETE request for a single SoftwareModule within SP.
*
* @param softwareModuleId
* the ID of the module that has the artifact
* @param artifactId
* of the artifact to be deleted
*
* @return status OK if delete as successful.
*/
@RequestMapping(method = RequestMethod.DELETE, value = "/{softwareModuleId}/artifacts/{artifactId}")
@ResponseBody
@Override
public ResponseEntity<Void> deleteArtifact(@PathVariable final Long softwareModuleId,
@PathVariable final Long artifactId) {
findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, artifactId);
@@ -225,27 +165,7 @@ public class SoftwareModuleResource {
}
/**
* Handles the GET request of retrieving all softwaremodules within SP.
*
* @param pagingOffsetParam
* the offset of list of modules 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=name==abc}
*
* @return a list of all modules for a defined or default page request with
* status OK. The response is always paged. In any failure the
* JsonResponseExceptionHandler is handling the response.
*/
@RequestMapping(method = RequestMethod.GET, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
@Override
public ResponseEntity<SoftwareModulePagedList> getSoftwareModules(
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam,
@@ -273,38 +193,14 @@ public class SoftwareModuleResource {
return new ResponseEntity<>(new SoftwareModulePagedList(rest, countModulesAll), HttpStatus.OK);
}
/**
* Handles the GET request of retrieving a single software module within SP.
*
* @param softwareModuleId
* the ID of the module to retrieve
*
* @return a single softwareModule with status OK.
* @throws EntityNotFoundException
* in case no with the given {@code softwareModuleId} exists.
*/
@RequestMapping(method = RequestMethod.GET, value = "/{softwareModuleId}", produces = { "application/hal+json",
MediaType.APPLICATION_JSON_VALUE })
@Override
public ResponseEntity<SoftwareModuleRest> getSoftwareModule(@PathVariable final Long softwareModuleId) {
final SoftwareModule findBaseSoftareModule = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null);
return new ResponseEntity<>(SoftwareModuleMapper.toResponse(findBaseSoftareModule), HttpStatus.OK);
}
/**
* Handles the POST request of creating new softwaremodules within SP. The
* request body must always be a list of modules. The requests is delgating
* to the {@link SoftwareManagement#createSoftwareModule(Iterable)}.
*
* @param softwareModules
* the modules to be created.
* @return In case all modules could successful created the ResponseEntity
* with status code 201 - Created but without ResponseBody. In any
* failure the JsonResponseExceptionHandler is handling the
* response.
*/
@RequestMapping(method = RequestMethod.POST, consumes = { "application/hal+json",
MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
@Override
public ResponseEntity<SoftwareModulesRest> createSoftwareModules(
@RequestBody final List<SoftwareModuleRequestBodyPost> softwareModules) {
LOG.debug("creating {} softwareModules", softwareModules.size());
@@ -316,18 +212,7 @@ public class SoftwareModuleResource {
HttpStatus.CREATED);
}
/**
* Handles the PUT request of updating a software module within SP.
* {@link SoftwareManagement#createSoftwareModule(Iterable)}.
*
* @param softwareModuleId
* the ID of the software module in the URL
* @param restSoftwareModule
* the modules to be updated.
* @return status OK if update is successful
*/
@RequestMapping(method = RequestMethod.PUT, value = "/{softwareModuleId}", consumes = { "application/hal+json",
MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
@Override
public ResponseEntity<SoftwareModuleRest> updateSoftwareModule(@PathVariable final Long softwareModuleId,
@RequestBody final SoftwareModuleRequestBodyPut restSoftwareModule) {
final SoftwareModule module = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null);
@@ -344,15 +229,7 @@ public class SoftwareModuleResource {
return new ResponseEntity<>(SoftwareModuleMapper.toResponse(updateSoftwareModule), HttpStatus.OK);
}
/**
* Handles the DELETE request for a single softwaremodule within SP.
*
* @param softwareModuleId
* the ID of the module to retrieve
* @return status OK if delete as sucessfull.
*
*/
@RequestMapping(method = RequestMethod.DELETE, value = "/{softwareModuleId}")
@Override
public ResponseEntity<Void> deleteSoftwareModule(@PathVariable final Long softwareModuleId) {
final SoftwareModule module = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, null);
@@ -361,28 +238,7 @@ public class SoftwareModuleResource {
return new ResponseEntity<>(HttpStatus.OK);
}
/**
* Gets a paged list of meta data for a software module.
*
* @param softwareModuleId
* the ID of the software module for the meta data
* @param pagingOffsetParam
* the offset of list of meta data 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
* meta data
*/
@RequestMapping(method = RequestMethod.GET, value = "/{softwareModuleId}/metadata", produces = {
MediaType.APPLICATION_JSON_VALUE, "application/hal+json" })
@Override
public ResponseEntity<MetadataRestPageList> getMetadata(@PathVariable final Long softwareModuleId,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam,
@@ -412,18 +268,7 @@ public class SoftwareModuleResource {
HttpStatus.OK);
}
/**
* Gets a single meta data value for a specific key of a software module.
*
* @param softwareModuleId
* the ID of the software module to get the meta data from
* @param metadataKey
* the key of the meta data entry to retrieve the value from
* @return status OK if get request is successful with the value of the meta
* data
*/
@RequestMapping(method = RequestMethod.GET, value = "/{softwareModuleId}/metadata/{metadataKey}", produces = {
MediaType.APPLICATION_JSON_VALUE })
@Override
public ResponseEntity<MetadataRest> getMetadataValue(@PathVariable final Long softwareModuleId,
@PathVariable final String metadataKey) {
// check if distribution set exists otherwise throw exception
@@ -433,18 +278,7 @@ public class SoftwareModuleResource {
return ResponseEntity.<MetadataRest> ok(SoftwareModuleMapper.toResponseSwMetadata(findOne));
}
/**
* Updates a single meta data value of a software module.
*
* @param softwareModuleId
* the ID of the software module to update the meta data entry
* @param metadataKey
* the key of the meta data to update the value
* @return status OK if the update request is successful and the updated
* meta data result
*/
@RequestMapping(method = RequestMethod.PUT, value = "/{softwareModuleId}/metadata/{metadataKey}", produces = {
MediaType.APPLICATION_JSON_VALUE, "application/hal+json" })
@Override
public ResponseEntity<MetadataRest> updateMetadata(@PathVariable final Long softwareModuleId,
@PathVariable final String metadataKey, @RequestBody final MetadataRest metadata) {
// check if software module exists otherwise throw exception immediately
@@ -454,16 +288,7 @@ public class SoftwareModuleResource {
return ResponseEntity.ok(SoftwareModuleMapper.toResponseSwMetadata(updated));
}
/**
* Deletes a single meta data entry from the software module.
*
* @param softwareModuleId
* the ID of the software module to delete the meta data entry
* @param metadataKey
* the key of the meta data to delete
* @return status OK if the delete request is successful
*/
@RequestMapping(method = RequestMethod.DELETE, value = "/{softwareModuleId}/metadata/{metadataKey}")
@Override
public ResponseEntity<Void> deleteMetadata(@PathVariable final Long softwareModuleId,
@PathVariable final String metadataKey) {
// check if software module exists otherwise throw exception immediately
@@ -472,19 +297,7 @@ public class SoftwareModuleResource {
return ResponseEntity.ok().build();
}
/**
* Creates a list of meta data for a specific software module.
*
* @param softwareModuleId
* the ID of the distribution set to create meta data for
* @param metadataRest
* the list of meta data entries to create
* @return status created if post request is successful with the value of
* the created meta data
*/
@RequestMapping(method = RequestMethod.POST, value = "/{softwareModuleId}/metadata", consumes = {
MediaType.APPLICATION_JSON_VALUE,
"application/hal+json" }, produces = { MediaType.APPLICATION_JSON_VALUE, "application/hal+json" })
@Override
public ResponseEntity<List<MetadataRest>> createMetadata(@PathVariable final Long softwareModuleId,
@RequestBody final List<MetadataRest> metadataRest) {
// check if software module exists otherwise throw exception immediately

View File

@@ -16,6 +16,7 @@ import java.util.Collection;
import java.util.List;
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
import org.eclipse.hawkbit.rest.resource.api.SoftwareModuleTypeRestApi;
import org.eclipse.hawkbit.rest.resource.model.softwaremoduletype.SoftwareModuleTypeRequestBodyPost;
import org.eclipse.hawkbit.rest.resource.model.softwaremoduletype.SoftwareModuleTypeRest;
import org.eclipse.hawkbit.rest.resource.model.softwaremoduletype.SoftwareModuleTypesRest;
@@ -73,7 +74,7 @@ final class SoftwareModuleTypeMapper {
result.setMaxAssignments(type.getMaxAssignments());
result.setModuleId(type.getId());
result.add(linkTo(methodOn(SoftwareModuleTypeResource.class).getSoftwareModuleType(result.getModuleId()))
result.add(linkTo(methodOn(SoftwareModuleTypeRestApi.class).getSoftwareModuleType(result.getModuleId()))
.withRel("self"));
return result;

View File

@@ -10,8 +10,6 @@ package org.eclipse.hawkbit.rest.resource;
import java.util.List;
import javax.persistence.EntityManager;
import org.eclipse.hawkbit.repository.SoftwareManagement;
import org.eclipse.hawkbit.repository.SoftwareModuleTypeFields;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
@@ -19,6 +17,7 @@ import org.eclipse.hawkbit.repository.model.Artifact;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
import org.eclipse.hawkbit.repository.rsql.RSQLUtility;
import org.eclipse.hawkbit.rest.resource.api.SoftwareModuleTypeRestApi;
import org.eclipse.hawkbit.rest.resource.model.softwaremoduletype.SoftwareModuleTypePagedList;
import org.eclipse.hawkbit.rest.resource.model.softwaremoduletype.SoftwareModuleTypeRequestBodyPost;
import org.eclipse.hawkbit.rest.resource.model.softwaremoduletype.SoftwareModuleTypeRequestBodyPut;
@@ -30,59 +29,22 @@ import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.domain.Sort;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* REST Resource handling for {@link SoftwareModule} and related
* {@link Artifact} CRUD operations.
*
*
*
*
*/
@RestController
@RequestMapping(RestConstants.SOFTWAREMODULETYPE_V1_REQUEST_MAPPING)
public class SoftwareModuleTypeResource {
public class SoftwareModuleTypeResource implements SoftwareModuleTypeRestApi {
@Autowired
private SoftwareManagement softwareManagement;
@Autowired
private EntityManager entityManager;
/**
* Handles the GET request of retrieving all {@link SoftwareModuleType}s
* within SP.
*
* @param pagingOffsetParam
* the offset of list of modules 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=name==abc}
*
* @return a list of all module type for a defined or default page request
* with status OK. The response is always paged. In any failure the
* JsonResponseExceptionHandler is handling the response.
*/
@RequestMapping(method = RequestMethod.GET, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<SoftwareModuleTypePagedList> getTypes(
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) {
@Override
public ResponseEntity<SoftwareModuleTypePagedList> getTypes(final int pagingOffsetParam, final int pagingLimitParam,
final String sortParam, final String rsqlParam) {
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
@@ -93,12 +55,12 @@ public class SoftwareModuleTypeResource {
final Slice<SoftwareModuleType> findModuleTypessAll;
Long countModulesAll;
if (rsqlParam != null) {
findModuleTypessAll = softwareManagement.findSoftwareModuleTypesByPredicate(
findModuleTypessAll = this.softwareManagement.findSoftwareModuleTypesByPredicate(
RSQLUtility.parse(rsqlParam, SoftwareModuleTypeFields.class), pageable);
countModulesAll = ((Page<SoftwareModuleType>) findModuleTypessAll).getTotalElements();
} else {
findModuleTypessAll = softwareManagement.findSoftwareModuleTypesAll(pageable);
countModulesAll = softwareManagement.countSoftwareModuleTypesAll();
findModuleTypessAll = this.softwareManagement.findSoftwareModuleTypesAll(pageable);
countModulesAll = this.softwareManagement.countSoftwareModuleTypesAll();
}
final List<SoftwareModuleTypeRest> rest = SoftwareModuleTypeMapper
@@ -106,56 +68,25 @@ public class SoftwareModuleTypeResource {
return new ResponseEntity<>(new SoftwareModuleTypePagedList(rest, countModulesAll), HttpStatus.OK);
}
/**
* Handles the GET request of retrieving a single software module type
* within SP.
*
* @param softwareModuleTypeId
* the ID of the module type to retrieve
*
* @return a single softwareModule with status OK.
* @throws EntityNotFoundException
* in case no with the given {@code softwareModuleId} exists.
*/
@RequestMapping(method = RequestMethod.GET, value = "/{softwareModuleTypeId}", produces = { "application/hal+json",
MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<SoftwareModuleTypeRest> getSoftwareModuleType(@PathVariable final Long softwareModuleTypeId) {
@Override
public ResponseEntity<SoftwareModuleTypeRest> getSoftwareModuleType(final Long softwareModuleTypeId) {
final SoftwareModuleType foundType = findSoftwareModuleTypeWithExceptionIfNotFound(softwareModuleTypeId);
return new ResponseEntity<>(SoftwareModuleTypeMapper.toResponse(foundType), HttpStatus.OK);
}
/**
* Handles the DELETE request for a single software module type within SP.
*
* @param softwareModuleTypeId
* the ID of the module to retrieve
* @return status OK if delete as sucessfull.
*
*/
@RequestMapping(method = RequestMethod.DELETE, value = "/{softwareModuleTypeId}")
public ResponseEntity<Void> deleteSoftwareModuleType(@PathVariable final Long softwareModuleTypeId) {
@Override
public ResponseEntity<Void> deleteSoftwareModuleType(final Long softwareModuleTypeId) {
final SoftwareModuleType module = findSoftwareModuleTypeWithExceptionIfNotFound(softwareModuleTypeId);
softwareManagement.deleteSoftwareModuleType(module);
this.softwareManagement.deleteSoftwareModuleType(module);
return new ResponseEntity<>(HttpStatus.OK);
}
/**
* Handles the PUT request of updating a software module type within SP.
*
* @param softwareModuleTypeId
* the ID of the software module in the URL
* @param restSoftwareModuleType
* the module type to be updated.
* @return status OK if update is successful
*/
@RequestMapping(method = RequestMethod.PUT, value = "/{softwareModuleTypeId}", consumes = { "application/hal+json",
MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<SoftwareModuleTypeRest> updateSoftwareModuleType(
@PathVariable final Long softwareModuleTypeId,
@RequestBody final SoftwareModuleTypeRequestBodyPut restSoftwareModuleType) {
@Override
public ResponseEntity<SoftwareModuleTypeRest> updateSoftwareModuleType(final Long softwareModuleTypeId,
final SoftwareModuleTypeRequestBodyPut restSoftwareModuleType) {
final SoftwareModuleType type = findSoftwareModuleTypeWithExceptionIfNotFound(softwareModuleTypeId);
// only description can be modified
@@ -163,27 +94,15 @@ public class SoftwareModuleTypeResource {
type.setDescription(restSoftwareModuleType.getDescription());
}
final SoftwareModuleType updatedSoftwareModuleType = softwareManagement.updateSoftwareModuleType(type);
final SoftwareModuleType updatedSoftwareModuleType = this.softwareManagement.updateSoftwareModuleType(type);
return new ResponseEntity<>(SoftwareModuleTypeMapper.toResponse(updatedSoftwareModuleType), HttpStatus.OK);
}
/**
* Handles the POST request of creating new {@link SoftwareModuleType}s
* within SP. The request body must always be a list of types.
*
* @param softwareModuleTypes
* the modules to be created.
* @return In case all modules could successful created the ResponseEntity
* with status code 201 - Created but without ResponseBody. In any
* failure the JsonResponseExceptionHandler is handling the
* response.
*/
@RequestMapping(method = RequestMethod.POST, consumes = { "application/hal+json",
MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
@Override
public ResponseEntity<SoftwareModuleTypesRest> createSoftwareModuleTypes(
@RequestBody final List<SoftwareModuleTypeRequestBodyPost> softwareModuleTypes) {
final List<SoftwareModuleTypeRequestBodyPost> softwareModuleTypes) {
final List<SoftwareModuleType> createdSoftwareModules = softwareManagement
final List<SoftwareModuleType> createdSoftwareModules = this.softwareManagement
.createSoftwareModuleTypes(SoftwareModuleTypeMapper.smFromRequest(softwareModuleTypes));
return new ResponseEntity<>(SoftwareModuleTypeMapper.toTypesResponse(createdSoftwareModules),
@@ -191,7 +110,7 @@ public class SoftwareModuleTypeResource {
}
private SoftwareModuleType findSoftwareModuleTypeWithExceptionIfNotFound(final Long softwareModuleTypeId) {
final SoftwareModuleType module = softwareManagement.findSoftwareModuleTypeById(softwareModuleTypeId);
final SoftwareModuleType module = this.softwareManagement.findSoftwareModuleTypeById(softwareModuleTypeId);
if (module == null) {
throw new EntityNotFoundException(
"SoftwareModuleType with Id {" + softwareModuleTypeId + "} does not exist");

View File

@@ -17,6 +17,8 @@ import java.util.List;
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
import org.eclipse.hawkbit.repository.model.Tag;
import org.eclipse.hawkbit.repository.model.TargetTag;
import org.eclipse.hawkbit.rest.resource.api.DistributionSetTagRestApi;
import org.eclipse.hawkbit.rest.resource.api.TargetTagRestApi;
import org.eclipse.hawkbit.rest.resource.model.tag.TagRequestBodyPut;
import org.eclipse.hawkbit.rest.resource.model.tag.TagRest;
import org.eclipse.hawkbit.rest.resource.model.tag.TagsRest;
@@ -53,9 +55,9 @@ final class TagMapper {
mapTag(response, targetTag);
response.add(linkTo(methodOn(TargetTagResource.class).getTargetTag(targetTag.getId())).withRel("self"));
response.add(linkTo(methodOn(TargetTagRestApi.class).getTargetTag(targetTag.getId())).withRel("self"));
response.add(linkTo(methodOn(TargetTagResource.class).getAssignedTargets(targetTag.getId()))
response.add(linkTo(methodOn(TargetTagRestApi.class).getAssignedTargets(targetTag.getId()))
.withRel("assignedTargets"));
return response;
@@ -83,12 +85,11 @@ final class TagMapper {
mapTag(response, distributionSetTag);
response.add(
linkTo(methodOn(DistributionSetTagResource.class).getDistributionSetTag(distributionSetTag.getId()))
.withRel("self"));
response.add(linkTo(methodOn(DistributionSetTagRestApi.class).getDistributionSetTag(distributionSetTag.getId()))
.withRel("self"));
response.add(linkTo(
methodOn(DistributionSetTagResource.class).getAssignedDistributionSets(distributionSetTag.getId()))
methodOn(DistributionSetTagRestApi.class).getAssignedDistributionSets(distributionSetTag.getId()))
.withRel("assignedDistributionSets"));
return response;

View File

@@ -23,6 +23,7 @@ import org.eclipse.hawkbit.repository.model.ActionStatus;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetInfo.PollStatus;
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
import org.eclipse.hawkbit.rest.resource.api.TargetRestApi;
import org.eclipse.hawkbit.rest.resource.model.PollStatusRest;
import org.eclipse.hawkbit.rest.resource.model.action.ActionRest;
import org.eclipse.hawkbit.rest.resource.model.action.ActionStatusRest;
@@ -45,18 +46,18 @@ final public class TargetMapper {
/**
* Add links to a target response.
*
*
* @param response
* the target response
*/
public static void addTargetLinks(final TargetRest response) {
response.add(linkTo(methodOn(TargetResource.class).getAssignedDistributionSet(response.getControllerId()))
response.add(linkTo(methodOn(TargetRestApi.class).getAssignedDistributionSet(response.getControllerId()))
.withRel(RestConstants.TARGET_V1_ASSIGNED_DISTRIBUTION_SET));
response.add(linkTo(methodOn(TargetResource.class).getInstalledDistributionSet(response.getControllerId()))
response.add(linkTo(methodOn(TargetRestApi.class).getInstalledDistributionSet(response.getControllerId()))
.withRel(RestConstants.TARGET_V1_INSTALLED_DISTRIBUTION_SET));
response.add(linkTo(methodOn(TargetResource.class).getAttributes(response.getControllerId()))
response.add(linkTo(methodOn(TargetRestApi.class).getAttributes(response.getControllerId()))
.withRel(RestConstants.TARGET_V1_ATTRIBUTES));
response.add(linkTo(methodOn(TargetResource.class).getActionHistory(response.getControllerId(), 0,
response.add(linkTo(methodOn(TargetRestApi.class).getActionHistory(response.getControllerId(), 0,
RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE,
ActionFields.ID.getFieldName() + ":" + SortDirection.DESC, null))
.withRel(RestConstants.TARGET_V1_ACTIONS));
@@ -64,7 +65,7 @@ final public class TargetMapper {
/**
* Add the pollstatus to a target response.
*
*
* @param target
* the target
* @param targetRest
@@ -85,7 +86,7 @@ final public class TargetMapper {
/**
* Create a response which includes links and pollstatus for all targets.
*
*
* @param targets
* the targets
* @return the response
@@ -105,7 +106,7 @@ final public class TargetMapper {
/**
* Create a response for targets.
*
*
* @param targets
* list of targets
* @return the response
@@ -123,7 +124,7 @@ final public class TargetMapper {
/**
* Create a response for target.
*
*
* @param target
* the target
* @return the response
@@ -163,7 +164,7 @@ final public class TargetMapper {
targetRest.setInstalledAt(installationDate);
}
targetRest.add(linkTo(methodOn(TargetResource.class).getTarget(target.getControllerId())).withRel("self"));
targetRest.add(linkTo(methodOn(TargetRestApi.class).getTarget(target.getControllerId())).withRel("self"));
return targetRest;
}
@@ -210,7 +211,7 @@ final public class TargetMapper {
RestModelMapper.mapBaseToBase(result, action);
result.add(linkTo(methodOn(TargetResource.class).getAction(targetId, action.getId())).withRel("self"));
result.add(linkTo(methodOn(TargetRestApi.class).getAction(targetId, action.getId())).withRel("self"));
return result;
}

View File

@@ -20,13 +20,14 @@ import org.eclipse.hawkbit.repository.ActionStatusFields;
import org.eclipse.hawkbit.repository.DeploymentManagement;
import org.eclipse.hawkbit.repository.TargetFields;
import org.eclipse.hawkbit.repository.TargetManagement;
import org.eclipse.hawkbit.repository.exception.CancelActionNotAllowedException;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.Action.ActionType;
import org.eclipse.hawkbit.repository.model.ActionStatus;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.rsql.RSQLUtility;
import org.eclipse.hawkbit.rest.resource.api.DistributionSetRestApi;
import org.eclipse.hawkbit.rest.resource.api.TargetRestApi;
import org.eclipse.hawkbit.rest.resource.helper.RestResourceConversionHelper;
import org.eclipse.hawkbit.rest.resource.model.action.ActionPagedList;
import org.eclipse.hawkbit.rest.resource.model.action.ActionRest;
@@ -47,25 +48,15 @@ import org.springframework.data.domain.Slice;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* REST Resource handling target CRUD operations.
*
*
*
*
*/
@RestController
@RequestMapping(RestConstants.TARGET_V1_REQUEST_MAPPING)
public class TargetResource {
public class TargetResource implements TargetRestApi {
private static final Logger LOG = LoggerFactory.getLogger(TargetResource.class);
@Autowired
@@ -74,18 +65,8 @@ public class TargetResource {
@Autowired
private DeploymentManagement deploymentManagement;
/**
* Handles the GET request of retrieving a single target within SP.
*
* @param targetId
* the ID of the target to retrieve
* @return a single target with status OK.
* @throws EntityNotFoundException
* in case no target with the given {@code targetId} exists.
*/
@RequestMapping(method = RequestMethod.GET, value = "/{targetId}", produces = { "application/hal+json",
MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<TargetRest> getTarget(@PathVariable final String targetId) {
@Override
public ResponseEntity<TargetRest> getTarget(final String targetId) {
final Target findTarget = findTargetWithExceptionIfNotFound(targetId);
// to single response include poll status
final TargetRest response = TargetMapper.toResponse(findTarget);
@@ -95,31 +76,9 @@ public class TargetResource {
return new ResponseEntity<>(response, HttpStatus.OK);
}
/**
* Handles the GET request of retrieving all targets within SP.
*
* @param pagingOffsetParam
* the offset of list of targets 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=name==abc}
* @return a list of all targets for a defined or default page request with
* status OK. The response is always paged. In any failure the
* JsonResponseExceptionHandler is handling the response.
*/
@RequestMapping(method = RequestMethod.GET, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<TargetPagedList> getTargets(
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) {
@Override
public ResponseEntity<TargetPagedList> getTargets(final int pagingOffsetParam, final int pagingLimitParam,
final String sortParam, final String rsqlParam) {
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
@@ -129,58 +88,29 @@ public class TargetResource {
final Slice<Target> findTargetsAll;
final Long countTargetsAll;
if (rsqlParam != null) {
final Page<Target> findTargetPage = targetManagement
final Page<Target> findTargetPage = this.targetManagement
.findTargetsAll(RSQLUtility.parse(rsqlParam, TargetFields.class), pageable);
countTargetsAll = findTargetPage.getTotalElements();
findTargetsAll = findTargetPage;
} else {
findTargetsAll = targetManagement.findTargetsAll(pageable);
countTargetsAll = targetManagement.countTargetsAll();
findTargetsAll = this.targetManagement.findTargetsAll(pageable);
countTargetsAll = this.targetManagement.countTargetsAll();
}
final List<TargetRest> rest = TargetMapper.toResponse(findTargetsAll.getContent());
return new ResponseEntity<>(new TargetPagedList(rest, countTargetsAll), HttpStatus.OK);
}
/**
* Handles the POST request of creating new targets within SP. The request
* body must always be a list of targets. The requests is delegating to the
* {@link TargetManagement#createTarget(Iterable)}.
*
* @param targets
* the targets to be created.
* @return In case all targets could successful created the ResponseEntity
* with status code 201 with a list of successfully created
* entities. In any failure the JsonResponseExceptionHandler is
* handling the response.
*/
@RequestMapping(method = RequestMethod.POST, consumes = { "application/hal+json",
MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<TargetsRest> createTargets(@RequestBody final List<TargetRequestBody> targets) {
@Override
public ResponseEntity<TargetsRest> createTargets(final List<TargetRequestBody> targets) {
LOG.debug("creating {} targets", targets.size());
final Iterable<Target> createdTargets = targetManagement.createTargets(TargetMapper.fromRequest(targets));
final Iterable<Target> createdTargets = this.targetManagement.createTargets(TargetMapper.fromRequest(targets));
LOG.debug("{} targets created, return status {}", targets.size(), HttpStatus.CREATED);
return new ResponseEntity<>(TargetMapper.toResponse(createdTargets), HttpStatus.CREATED);
}
/**
* Handles the PUT request of updating a target within SP. The ID is within
* the URL path of the request. A given ID in the request body is ignored.
* It's not possible to set fields to {@code null} values.
*
* @param targetId
* the path parameter which contains the ID of the target
* @param targetRest
* the request body which contains the fields which should be
* updated, fields which are not given are ignored for the
* udpate.
* @return the updated target response which contains all fields also fields
* which have not updated
*/
@RequestMapping(method = RequestMethod.PUT, value = "/{targetId}", consumes = { "application/hal+json",
MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<TargetRest> updateTarget(@PathVariable final String targetId,
@RequestBody final TargetRequestBody targetRest) {
@Override
public ResponseEntity<TargetRest> updateTarget(final String targetId, final TargetRequestBody targetRest) {
final Target existingTarget = findTargetWithExceptionIfNotFound(targetId);
LOG.debug("updating target {}", existingTarget.getId());
if (targetRest.getDescription() != null) {
@@ -189,42 +119,21 @@ public class TargetResource {
if (targetRest.getName() != null) {
existingTarget.setName(targetRest.getName());
}
final Target updateTarget = targetManagement.updateTarget(existingTarget);
final Target updateTarget = this.targetManagement.updateTarget(existingTarget);
return new ResponseEntity<>(TargetMapper.toResponse(updateTarget), HttpStatus.OK);
}
/**
* Handles the DELETE request of deleting a target within SP.
*
* @param targetId
* the ID of the target to be deleted
* @return If the given targetId could exists and could be deleted Http OK.
* In any failure the JsonResponseExceptionHandler is handling the
* response.
*/
@RequestMapping(method = RequestMethod.DELETE, value = "/{targetId}", produces = { "application/hal+json",
MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<Void> deleteTarget(@PathVariable final String targetId) {
@Override
public ResponseEntity<Void> deleteTarget(final String targetId) {
final Target target = findTargetWithExceptionIfNotFound(targetId);
targetManagement.deleteTargets(target.getId());
this.targetManagement.deleteTargets(target.getId());
LOG.debug("{} target deleted, return status {}", targetId, HttpStatus.OK);
return new ResponseEntity<>(HttpStatus.OK);
}
/**
* Handles the GET request of retrieving the attributes of a specific
* target.
*
* @param targetId
* the ID of the target to retrieve the attributes.
* @return the target attributes as map response with status OK
* @throws EntityNotFoundException
* in case no target with the given {@code targetId} exists.
*/
@RequestMapping(method = RequestMethod.GET, value = "/{targetId}/attributes", produces = { "application/hal+json",
MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<TargetAttributes> getAttributes(@PathVariable final String targetId) {
@Override
public ResponseEntity<TargetAttributes> getAttributes(final String targetId) {
final Target foundTarget = findTargetWithExceptionIfNotFound(targetId);
final Map<String, String> controllerAttributes = foundTarget.getTargetInfo().getControllerAttributes();
if (controllerAttributes.isEmpty()) {
@@ -237,36 +146,9 @@ public class TargetResource {
return new ResponseEntity<>(result, HttpStatus.OK);
}
/**
* Handles the GET request of retrieving the {@link Action}s of a specific
* target.
*
* @param targetId
* to load actions for
* @param pagingOffsetParam
* the offset of list of targets 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=status==pending}
* @return a list of all {@link Action}s for a defined or default page
* request with status OK. The response is always paged. In any
* failure the JsonResponseExceptionHandler is handling the
* response.
*/
@RequestMapping(method = RequestMethod.GET, value = "/{targetId}/actions", produces = { "application/hal+json",
MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<ActionPagedList> getActionHistory(@PathVariable final String targetId,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) {
@Override
public ResponseEntity<ActionPagedList> getActionHistory(final String targetId, final int pagingOffsetParam,
final int pagingLimitParam, final String sortParam, final String rsqlParam) {
final Target foundTarget = findTargetWithExceptionIfNotFound(targetId);
@@ -279,11 +161,11 @@ public class TargetResource {
final Long totalActionCount;
if (rsqlParam != null) {
final Specification<Action> parse = RSQLUtility.parse(rsqlParam, ActionFields.class);
activeActions = deploymentManagement.findActionsByTarget(parse, foundTarget, pageable);
totalActionCount = deploymentManagement.countActionsByTarget(parse, foundTarget);
activeActions = this.deploymentManagement.findActionsByTarget(parse, foundTarget, pageable);
totalActionCount = this.deploymentManagement.countActionsByTarget(parse, foundTarget);
} else {
activeActions = deploymentManagement.findActionsByTarget(foundTarget, pageable);
totalActionCount = deploymentManagement.countActionsByTarget(foundTarget);
activeActions = this.deploymentManagement.findActionsByTarget(foundTarget, pageable);
totalActionCount = this.deploymentManagement.countActionsByTarget(foundTarget);
}
return new ResponseEntity<>(
@@ -291,20 +173,8 @@ public class TargetResource {
HttpStatus.OK);
}
/**
* Handles the GET request of retrieving a specific {@link Action}s of a
* specific {@link Target}.
*
* @param targetId
* to load the action for
* @param actionId
* to load
* @return the action
*/
@RequestMapping(method = RequestMethod.GET, value = "/{targetId}/actions/{actionId}", produces = {
"application/hal+json", MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<ActionRest> getAction(@PathVariable final String targetId,
@PathVariable final Long actionId) {
@Override
public ResponseEntity<ActionRest> getAction(final String targetId, final Long actionId) {
final Target target = findTargetWithExceptionIfNotFound(targetId);
final Action action = findActionWithExceptionIfNotFound(actionId);
@@ -317,14 +187,14 @@ public class TargetResource {
if (!action.isCancelingOrCanceled()) {
result.add(linkTo(
methodOn(DistributionSetResource.class).getDistributionSet(action.getDistributionSet().getId()))
methodOn(DistributionSetRestApi.class).getDistributionSet(action.getDistributionSet().getId()))
.withRel("distributionset"));
} else if (action.isCancelingOrCanceled()) {
result.add(linkTo(methodOn(TargetResource.class).getAction(targetId, action.getId()))
result.add(linkTo(methodOn(TargetRestApi.class).getAction(targetId, action.getId()))
.withRel(RestConstants.TARGET_V1_CANCELED_ACTION));
}
result.add(linkTo(methodOn(TargetResource.class).getActionStatusList(targetId, action.getId(), 0,
result.add(linkTo(methodOn(TargetRestApi.class).getActionStatusList(targetId, action.getId(), 0,
RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE,
ActionStatusFields.ID.getFieldName() + ":" + SortDirection.DESC))
.withRel(RestConstants.TARGET_V1_ACTION_STATUS));
@@ -332,32 +202,16 @@ public class TargetResource {
return new ResponseEntity<>(result, HttpStatus.OK);
}
/**
* Handles the DELETE request of canceling an specific {@link Action}s of a
* specific {@link Target}.
*
* @param targetId
* the ID of the target in the URL path parameter
* @param actionId
* the ID of the action in the URL path parameter
* @param force
* optional parameter, which indicates a force cancel
* @return status no content in case cancellation was successful
* @throws CancelActionNotAllowedException
* if the given action is not active and cannot be canceled.
* @throws EntityNotFoundException
* if the target or the action is not found
*/
@RequestMapping(method = RequestMethod.DELETE, value = "/{targetId}/actions/{actionId}")
public ResponseEntity<Void> cancelAction(@PathVariable final String targetId, @PathVariable final Long actionId,
@Override
public ResponseEntity<Void> cancelAction(final String targetId, final Long actionId,
@RequestParam(required = false, defaultValue = "false") final boolean force) {
final Target target = findTargetWithExceptionIfNotFound(targetId);
final Action action = findActionWithExceptionIfNotFound(actionId);
if (force) {
deploymentManagement.forceQuitAction(action, target);
this.deploymentManagement.forceQuitAction(action, target);
} else {
deploymentManagement.cancelAction(action, target);
this.deploymentManagement.cancelAction(action, target);
}
// both functions will throw an exception, when action is in wrong
// state, which is mapped by ResponseExceptionHandler.
@@ -365,35 +219,9 @@ public class TargetResource {
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
/**
* Handles the GET request of retrieving the {@link ActionStatus}s of a
* specific target and action.
*
* @param targetId
* of the the action
* @param actionId
* of the status we are intend to load
* @param pagingOffsetParam
* the offset of list of targets 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}
* @return a list of all {@link ActionStatus}s for a defined or default page
* request with status OK. The response is always paged. In any
* failure the JsonResponseExceptionHandler is handling the
* response.
*/
@RequestMapping(method = RequestMethod.GET, value = "/{targetId}/actions/{actionId}/status", produces = {
"application/hal+json", MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<ActionStatusPagedList> getActionStatusList(@PathVariable final String targetId,
@PathVariable final Long actionId,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam) {
@Override
public ResponseEntity<ActionStatusPagedList> getActionStatusList(final String targetId, final Long actionId,
final int pagingOffsetParam, final int pagingLimitParam, final String sortParam) {
final Target target = findTargetWithExceptionIfNotFound(targetId);
@@ -407,7 +235,7 @@ public class TargetResource {
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
final Sort sorting = PagingUtility.sanitizeActionStatusSortParam(sortParam);
final Page<ActionStatus> statusList = deploymentManagement.findActionStatusMessagesByActionInDescOrder(
final Page<ActionStatus> statusList = this.deploymentManagement.findActionStatusMessagesByActionInDescOrder(
new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting), action, true);
return new ResponseEntity<>(
@@ -417,20 +245,8 @@ public class TargetResource {
}
/**
* Handles the GET request of retrieving the assigned distribution set of an
* specific target.
*
* @param targetId
* the ID of the target to retrieve the assigned distribution
* @return the assigned distribution set with status OK, if none is assigned
* than {@code null} content (e.g. "{}")
* @throws EntityNotFoundException
* in case no target with the given {@code targetId} exists.
*/
@RequestMapping(method = RequestMethod.GET, value = "/{targetId}/assignedDS", produces = { "application/hal+json",
MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<DistributionSetRest> getAssignedDistributionSet(@PathVariable final String targetId) {
@Override
public ResponseEntity<DistributionSetRest> getAssignedDistributionSet(final String targetId) {
final Target findTarget = findTargetWithExceptionIfNotFound(targetId);
final DistributionSetRest distributionSetRest = DistributionSetMapper
.toResponse(findTarget.getAssignedDistributionSet());
@@ -443,28 +259,14 @@ public class TargetResource {
return new ResponseEntity<>(distributionSetRest, retStatus);
}
/**
* Changes the assigned distribution set of a target.
*
* @param targetId
* of the target to change
* @param dsId
* of the distributionset that is to be assigned
* @return {@link HttpStatus#OK}
*
* @throws EntityNotFoundException
* in case no target with the given {@code targetId} exists.
*
*/
@RequestMapping(method = RequestMethod.POST, value = "/{targetId}/assignedDS", consumes = { "application/hal+json",
MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<Void> postAssignedDistributionSet(@PathVariable final String targetId,
@RequestBody final DistributionSetAssigmentRest dsId) {
@Override
public ResponseEntity<Void> postAssignedDistributionSet(final String targetId,
final DistributionSetAssigmentRest dsId) {
findTargetWithExceptionIfNotFound(targetId);
final ActionType type = (dsId.getType() != null)
? RestResourceConversionHelper.convertActionType(dsId.getType()) : ActionType.FORCED;
final Iterator<Target> changed = deploymentManagement
final Iterator<Target> changed = this.deploymentManagement
.assignDistributionSet(dsId.getId(), type, dsId.getForcetime(), targetId).getAssignedTargets()
.iterator();
if (changed.hasNext()) {
@@ -477,20 +279,8 @@ public class TargetResource {
}
/**
* Handles the GET request of retrieving the installed distribution set of
* an specific target.
*
* @param targetId
* the ID of the target to retrieve
* @return the assigned installed set with status OK, if none is installed
* than {@code null} content (e.g. "{}")
* @throws EntityNotFoundException
* in case no target with the given {@code targetId} exists.
*/
@RequestMapping(method = RequestMethod.GET, value = "/{targetId}/installedDS", produces = { "application/hal+json",
MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<DistributionSetRest> getInstalledDistributionSet(@PathVariable final String targetId) {
@Override
public ResponseEntity<DistributionSetRest> getInstalledDistributionSet(final String targetId) {
final Target findTarget = findTargetWithExceptionIfNotFound(targetId);
final DistributionSetRest distributionSetRest = DistributionSetMapper
.toResponse(findTarget.getTargetInfo().getInstalledDistributionSet());
@@ -504,7 +294,7 @@ public class TargetResource {
}
private Target findTargetWithExceptionIfNotFound(final String targetId) {
final Target findTarget = targetManagement.findTargetByControllerID(targetId);
final Target findTarget = this.targetManagement.findTargetByControllerID(targetId);
if (findTarget == null) {
throw new EntityNotFoundException("Target with Id {" + targetId + "} does not exist");
}
@@ -512,7 +302,7 @@ public class TargetResource {
}
private Action findActionWithExceptionIfNotFound(final Long actionId) {
final Action findAction = deploymentManagement.findAction(actionId);
final Action findAction = this.deploymentManagement.findAction(actionId);
if (findAction == null) {
throw new EntityNotFoundException("Action with Id {" + actionId + "} does not exist");
}

View File

@@ -11,8 +11,6 @@ package org.eclipse.hawkbit.rest.resource;
import java.util.List;
import java.util.stream.Collectors;
import javax.persistence.EntityManager;
import org.eclipse.hawkbit.repository.TagFields;
import org.eclipse.hawkbit.repository.TagManagement;
import org.eclipse.hawkbit.repository.TargetManagement;
@@ -21,6 +19,7 @@ import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetTag;
import org.eclipse.hawkbit.repository.model.TargetTagAssigmentResult;
import org.eclipse.hawkbit.repository.rsql.RSQLUtility;
import org.eclipse.hawkbit.rest.resource.api.TargetTagRestApi;
import org.eclipse.hawkbit.rest.resource.model.tag.AssignedTargetRequestBody;
import org.eclipse.hawkbit.rest.resource.model.tag.TagPagedList;
import org.eclipse.hawkbit.rest.resource.model.tag.TagRequestBodyPut;
@@ -36,13 +35,8 @@ import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.domain.Sort;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
@@ -50,10 +44,8 @@ import org.springframework.web.bind.annotation.RestController;
*
*/
@RestController
@RequestMapping(RestConstants.TARGET_TAG_V1_REQUEST_MAPPING)
public class TargetTagResource {
public class TargetTagResource implements TargetTagRestApi {
private static final Logger LOG = LoggerFactory.getLogger(TargetTagResource.class);
private static final String TARGET_TAG_TAGERTS_REQUEST_MAPPING = RestConstants.TARGET_TAG_TAGERTS_REQUEST_MAPPING;
@Autowired
private TagManagement tagManagement;
@@ -61,34 +53,9 @@ public class TargetTagResource {
@Autowired
private TargetManagement targetManagement;
@Autowired
private EntityManager entityManager;
/**
* Handles the GET request of retrieving all target tags.
*
* @param pagingOffsetParam
* the offset of list of target tags 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=name==abc}
* @return a list of all target tags for a defined or default page request
* with status OK. The response is always paged. In any failure the
* JsonResponseExceptionHandler is handling the response.
*/
@RequestMapping(method = RequestMethod.GET, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<TagPagedList> getTargetTags(
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = RestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam,
@RequestParam(value = RestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) {
@Override
public ResponseEntity<TagPagedList> getTargetTags(final int pagingOffsetParam, final int pagingLimitParam,
final String sortParam, final String rsqlParam) {
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
@@ -98,11 +65,11 @@ public class TargetTagResource {
final Slice<TargetTag> findTargetsAll;
final Long countTargetsAll;
if (rsqlParam == null) {
findTargetsAll = tagManagement.findAllTargetTags(pageable);
countTargetsAll = tagManagement.countTargetTags();
findTargetsAll = this.tagManagement.findAllTargetTags(pageable);
countTargetsAll = this.tagManagement.countTargetTags();
} else {
final Page<TargetTag> findTargetPage = tagManagement
final Page<TargetTag> findTargetPage = this.tagManagement
.findAllTargetTags(RSQLUtility.parse(rsqlParam, TagFields.class), pageable);
countTargetsAll = findTargetPage.getTotalElements();
findTargetsAll = findTargetPage;
@@ -113,127 +80,57 @@ public class TargetTagResource {
return new ResponseEntity<>(new TagPagedList(rest, countTargetsAll), HttpStatus.OK);
}
/**
* Handles the GET request of retrieving a single target tag.
*
* @param targetTagId
* the ID of the target tag to retrieve
*
* @return a single target tag with status OK.
* @throws EntityNotFoundException
* in case the given {@code targetTagId} doesn't exists.
*/
@RequestMapping(method = RequestMethod.GET, value = "/{targetTagId}", produces = { "application/hal+json",
MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<TagRest> getTargetTag(@PathVariable final Long targetTagId) {
@Override
public ResponseEntity<TagRest> getTargetTag(final Long targetTagId) {
final TargetTag tag = findTargetTagById(targetTagId);
return new ResponseEntity<>(TagMapper.toResponse(tag), HttpStatus.OK);
}
/**
* Handles the POST request of creating new target tag. The request body
* must always be a list of tags.
*
* @param tags
* the target tags to be created.
* @return In case all modules could successful created the ResponseEntity
* with status code 201 - Created. The Response Body are the created
* target tags but without ResponseBody.
*/
@RequestMapping(method = RequestMethod.POST, consumes = { "application/hal+json",
MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
@Override
public ResponseEntity<TagsRest> createTargetTags(@RequestBody final List<TagRequestBodyPut> tags) {
LOG.debug("creating {} target tags", tags.size());
final List<TargetTag> createdTargetTags = tagManagement
final List<TargetTag> createdTargetTags = this.tagManagement
.createTargetTags(TagMapper.mapTargeTagFromRequest(tags));
return new ResponseEntity<>(TagMapper.toResponse(createdTargetTags), HttpStatus.CREATED);
}
/**
*
* Handles the PUT request of updating a single targetr tag.
*
* @param targetTagId
* the ID of the target tag
* @param restTargetTagRest
* the the request body to be updated
* @return status OK if update is successful and the updated target tag.
* @throws EntityNotFoundException
* in case the given {@code targetTagId} doesn't exists.
*/
@RequestMapping(method = RequestMethod.PUT, value = "/{targetTagId}", consumes = { "application/hal+json",
MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<TagRest> updateTagretTag(@PathVariable final Long targetTagId,
@RequestBody final TagRequestBodyPut restTargetTagRest) {
@Override
public ResponseEntity<TagRest> updateTagretTag(final Long targetTagId, final TagRequestBodyPut restTargetTagRest) {
LOG.debug("update {} target tag", restTargetTagRest);
final TargetTag targetTag = findTargetTagById(targetTagId);
TagMapper.updateTag(restTargetTagRest, targetTag);
final TargetTag updateTargetTag = tagManagement.updateTargetTag(targetTag);
final TargetTag updateTargetTag = this.tagManagement.updateTargetTag(targetTag);
LOG.debug("target tag updated");
return new ResponseEntity<>(TagMapper.toResponse(updateTargetTag), HttpStatus.OK);
}
/**
* Handles the DELETE request for a single target tag.
*
* @param targetTagId
* the ID of the target tag
* @return status OK if delete as successfully.
* @throws EntityNotFoundException
* in case the given {@code targetTagId} doesn't exists.
*
*/
@RequestMapping(method = RequestMethod.DELETE, value = "/{targetTagId}")
public ResponseEntity<Void> deleteTargetTag(@PathVariable final Long targetTagId) {
@Override
public ResponseEntity<Void> deleteTargetTag(final Long targetTagId) {
LOG.debug("Delete {} target tag", targetTagId);
final TargetTag targetTag = findTargetTagById(targetTagId);
tagManagement.deleteTargetTag(targetTag.getName());
this.tagManagement.deleteTargetTag(targetTag.getName());
return new ResponseEntity<>(HttpStatus.OK);
}
/**
* Handles the GET request of retrieving all assigned targets by the given
* tag id.
*
* @param targetTagId
* the ID of the target tag to retrieve
*
* @return the list of assigned targets.
* @throws EntityNotFoundException
* in case the given {@code targetTagId} doesn't exists.
*/
@RequestMapping(method = RequestMethod.GET, value = TARGET_TAG_TAGERTS_REQUEST_MAPPING)
public ResponseEntity<TargetsRest> getAssignedTargets(@PathVariable final Long targetTagId) {
@Override
public ResponseEntity<TargetsRest> getAssignedTargets(final Long targetTagId) {
final TargetTag targetTag = findTargetTagById(targetTagId);
return new ResponseEntity<>(TargetMapper.toResponseWithLinksAndPollStatus(targetTag.getAssignedToTargets()),
HttpStatus.OK);
}
/**
* Handles the POST request to toggle the assignment of targets by the given
* tag id.
*
* @param targetTagId
* the ID of the target tag to retrieve
* @param assignedTargetRequestBodies
* list of target ids to be toggled
*
* @return the list of assigned targets and unassigned targets.
* @throws EntityNotFoundException
* in case the given {@code targetTagId} doesn't exists.
*/
@RequestMapping(method = RequestMethod.POST, value = TARGET_TAG_TAGERTS_REQUEST_MAPPING + "/toggleTagAssignment")
public ResponseEntity<TargetTagAssigmentResultRest> toggleTagAssignment(@PathVariable final Long targetTagId,
@RequestBody final List<AssignedTargetRequestBody> assignedTargetRequestBodies) {
@Override
public ResponseEntity<TargetTagAssigmentResultRest> toggleTagAssignment(final Long targetTagId,
final List<AssignedTargetRequestBody> assignedTargetRequestBodies) {
LOG.debug("Toggle Target assignment {} for target tag {}", assignedTargetRequestBodies.size(), targetTagId);
final TargetTag targetTag = findTargetTagById(targetTagId);
final TargetTagAssigmentResult assigmentResult = targetManagement
final TargetTagAssigmentResult assigmentResult = this.targetManagement
.toggleTagAssignment(findTargetControllerIds(assignedTargetRequestBodies), targetTag.getName());
final TargetTagAssigmentResultRest tagAssigmentResultRest = new TargetTagAssigmentResultRest();
@@ -242,71 +139,38 @@ public class TargetTagResource {
return new ResponseEntity<>(tagAssigmentResultRest, HttpStatus.OK);
}
/**
* Handles the POST request to assign targets to the given tag id.
*
* @param targetTagId
* the ID of the target tag to retrieve
* @param assignedTargetRequestBodies
* list of target ids to be assigned
*
* @return the list of assigned targets.
* @throws EntityNotFoundException
* in case the given {@code targetTagId} doesn't exists.
*/
@RequestMapping(method = RequestMethod.POST, value = TARGET_TAG_TAGERTS_REQUEST_MAPPING)
public ResponseEntity<TargetsRest> assignTargets(@PathVariable final Long targetTagId,
@RequestBody final List<AssignedTargetRequestBody> assignedTargetRequestBodies) {
@Override
public ResponseEntity<TargetsRest> assignTargets(final Long targetTagId,
final List<AssignedTargetRequestBody> assignedTargetRequestBodies) {
LOG.debug("Assign Targets {} for target tag {}", assignedTargetRequestBodies.size(), targetTagId);
final TargetTag targetTag = findTargetTagById(targetTagId);
final List<Target> assignedTarget = targetManagement
final List<Target> assignedTarget = this.targetManagement
.assignTag(findTargetControllerIds(assignedTargetRequestBodies), targetTag);
return new ResponseEntity<>(TargetMapper.toResponseWithLinksAndPollStatus(assignedTarget), HttpStatus.OK);
}
/**
* Handles the DELETE request to unassign all targets from the given tag id.
*
* @param targetTagId
* the ID of the target tag to retrieve
* @return http status code
* @throws EntityNotFoundException
* in case the given {@code targetTagId} doesn't exists.
*/
@RequestMapping(method = RequestMethod.DELETE, value = TARGET_TAG_TAGERTS_REQUEST_MAPPING)
public ResponseEntity<Void> unassignTargets(@PathVariable final Long targetTagId) {
@Override
public ResponseEntity<Void> unassignTargets(final Long targetTagId) {
LOG.debug("Unassign all Targets for target tag {}", targetTagId);
final TargetTag targetTag = findTargetTagById(targetTagId);
if (targetTag.getAssignedToTargets() == null) {
LOG.debug("No assigned targets found");
return new ResponseEntity<>(HttpStatus.OK);
}
targetManagement.unAssignAllTargetsByTag(targetTag);
this.targetManagement.unAssignAllTargetsByTag(targetTag);
return new ResponseEntity<>(HttpStatus.OK);
}
/**
* Handles the DELETE request to unassign one target from the given tag id.
*
* @param targetTagId
* the ID of the target tag
* @param controllerId
* the ID of the target to unassign
* @return http status code
* @throws EntityNotFoundException
* in case the given {@code targetTagId} doesn't exists.
*/
@RequestMapping(method = RequestMethod.DELETE, value = TARGET_TAG_TAGERTS_REQUEST_MAPPING + "/{controllerId}")
public ResponseEntity<Void> unassignTarget(@PathVariable final Long targetTagId,
@PathVariable final String controllerId) {
@Override
public ResponseEntity<Void> unassignTarget(final Long targetTagId, final String controllerId) {
LOG.debug("Unassign target {} for target tag {}", controllerId, targetTagId);
final TargetTag targetTag = findTargetTagById(targetTagId);
targetManagement.unAssignTag(controllerId, targetTag);
this.targetManagement.unAssignTag(controllerId, targetTag);
return new ResponseEntity<>(HttpStatus.OK);
}
private TargetTag findTargetTagById(final Long targetTagId) {
final TargetTag tag = tagManagement.findTargetTagById(targetTagId);
final TargetTag tag = this.tagManagement.findTargetTagById(targetTagId);
if (tag == null) {
throw new EntityNotFoundException("Target Tag with Id {" + targetTagId + "} does not exist");
}