Fine grained repository permissions (#2562)
1. Introduce @PrreAuthorize check based on hasPermission - allowing custom processing (compared with non-modifiable hasAuthority/Role processing) 2. Dedicated permissions could be implemented on management api level. Check is made by plugged in PermissionEvaluator 3. Thus common XXX_REPOSITORY permissions could differ for extending services 4. Change create/update entity builder pattern - not via EntityFactory but via clean static lombok based builders (with fine fluent api). 5. Implement abstract repository management jpa class that handles the boilerplate code from extending classes in single place consistently -> AbsreactJpaRepositoryManagement 6. Register management api-s as **Sevice**-s instead of **Bean**-s in order to make easier maintainable and get away from heavy argument forwading 7. Simplify custom hawkbit repository registration + adding proxy to handle exception mapping at lower level - thus not depending on Aspects for converting exceptions 8. Implemented general purpose 'copy' utility (ObjectCopyUtil) that using getter/setter patterns is able to copy (e.g. Create/Update) objects to other objects (e.g. JPA entity objects)
This commit is contained in:
@@ -51,7 +51,6 @@ import org.eclipse.hawkbit.repository.DeploymentManagement;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetInvalidationManagement;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetManagement;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetTypeManagement;
|
||||
import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.SoftwareModuleManagement;
|
||||
import org.eclipse.hawkbit.repository.SystemManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetFilterQueryManagement;
|
||||
@@ -82,49 +81,50 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@RestController
|
||||
public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
|
||||
|
||||
private final SoftwareModuleManagement softwareModuleManagement;
|
||||
private final SoftwareModuleManagement<? extends SoftwareModule> softwareModuleManagement;
|
||||
private final DistributionSetManagement<? extends DistributionSet> distributionSetManagement;
|
||||
private final DistributionSetTypeManagement<? extends DistributionSetType> distributionSetTypeManagement;
|
||||
private final DistributionSetInvalidationManagement distributionSetInvalidationManagement;
|
||||
private final TargetManagement targetManagement;
|
||||
private final TargetFilterQueryManagement targetFilterQueryManagement;
|
||||
private final DeploymentManagement deployManagement;
|
||||
private final SystemManagement systemManagement;
|
||||
private final EntityFactory entityFactory;
|
||||
private final DistributionSetManagement distributionSetManagement;
|
||||
private final DistributionSetTypeManagement distributionSetTypeManagement;
|
||||
private final MgmtDistributionSetMapper mgmtDistributionSetMapper;
|
||||
private final SystemSecurityContext systemSecurityContext;
|
||||
private final DistributionSetInvalidationManagement distributionSetInvalidationManagement;
|
||||
private final TenantConfigHelper tenantConfigHelper;
|
||||
|
||||
@SuppressWarnings("java:S107")
|
||||
MgmtDistributionSetResource(
|
||||
final SoftwareModuleManagement softwareModuleManagement,
|
||||
final TargetManagement targetManagement, final TargetFilterQueryManagement targetFilterQueryManagement,
|
||||
final DeploymentManagement deployManagement, final SystemManagement systemManagement,
|
||||
final EntityFactory entityFactory, final DistributionSetManagement distributionSetManagement,
|
||||
final DistributionSetTypeManagement distributionSetTypeManagement, final SystemSecurityContext systemSecurityContext,
|
||||
final SoftwareModuleManagement<? extends SoftwareModule> softwareModuleManagement,
|
||||
final DistributionSetManagement<? extends DistributionSet> distributionSetManagement,
|
||||
final DistributionSetTypeManagement<? extends DistributionSetType> distributionSetTypeManagement,
|
||||
final DistributionSetInvalidationManagement distributionSetInvalidationManagement,
|
||||
final TenantConfigurationManagement tenantConfigurationManagement) {
|
||||
final TargetManagement targetManagement, final TargetFilterQueryManagement targetFilterQueryManagement,
|
||||
final DeploymentManagement deployManagement, final TenantConfigurationManagement tenantConfigurationManagement,
|
||||
final MgmtDistributionSetMapper mgmtDistributionSetMapper,
|
||||
final SystemManagement systemManagement, final SystemSecurityContext systemSecurityContext) {
|
||||
this.softwareModuleManagement = softwareModuleManagement;
|
||||
this.distributionSetManagement = distributionSetManagement;
|
||||
this.distributionSetTypeManagement = distributionSetTypeManagement;
|
||||
this.distributionSetInvalidationManagement = distributionSetInvalidationManagement;
|
||||
this.targetManagement = targetManagement;
|
||||
this.targetFilterQueryManagement = targetFilterQueryManagement;
|
||||
this.deployManagement = deployManagement;
|
||||
this.systemManagement = systemManagement;
|
||||
this.entityFactory = entityFactory;
|
||||
this.distributionSetManagement = distributionSetManagement;
|
||||
this.distributionSetTypeManagement = distributionSetTypeManagement;
|
||||
this.systemSecurityContext = systemSecurityContext;
|
||||
this.distributionSetInvalidationManagement = distributionSetInvalidationManagement;
|
||||
this.tenantConfigHelper = TenantConfigHelper.usingContext(systemSecurityContext, tenantConfigurationManagement);
|
||||
this.mgmtDistributionSetMapper = mgmtDistributionSetMapper;
|
||||
this.systemManagement = systemManagement;
|
||||
this.systemSecurityContext = systemSecurityContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<PagedList<MgmtDistributionSet>> getDistributionSets(
|
||||
final String rsqlParam, final int pagingOffsetParam, final int pagingLimitParam, final String sortParam) {
|
||||
final Pageable pageable = PagingUtility.toPageable(pagingOffsetParam, pagingLimitParam, sanitizeDistributionSetSortParam(sortParam));
|
||||
final Slice<DistributionSet> findDsPage;
|
||||
final Slice<? extends DistributionSet> findDsPage;
|
||||
final long countModulesAll;
|
||||
if (rsqlParam != null) {
|
||||
findDsPage = distributionSetManagement.findByRsql(rsqlParam, pageable);
|
||||
countModulesAll = ((Page<DistributionSet>) findDsPage).getTotalElements();
|
||||
countModulesAll = ((Page<? extends DistributionSet>) findDsPage).getTotalElements();
|
||||
} else {
|
||||
findDsPage = distributionSetManagement.findAll(pageable);
|
||||
countModulesAll = distributionSetManagement.count();
|
||||
@@ -152,8 +152,8 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
|
||||
sets.stream().filter(ds -> ds.getType() == null).forEach(ds -> ds.setType(defaultDsKey));
|
||||
|
||||
//check if there is already deleted DS Type
|
||||
for (MgmtDistributionSetRequestBodyPost ds : sets) {
|
||||
final Optional<DistributionSetType> opt = distributionSetTypeManagement.findByKey(ds.getType());
|
||||
for (final MgmtDistributionSetRequestBodyPost ds : sets) {
|
||||
final Optional<? extends DistributionSetType> opt = distributionSetTypeManagement.findByKey(ds.getType());
|
||||
opt.ifPresent(dsType -> {
|
||||
if (dsType.isDeleted()) {
|
||||
final String text = "Cannot create Distribution Set from type with key {0}. Distribution Set Type already deleted!";
|
||||
@@ -163,8 +163,8 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
|
||||
});
|
||||
}
|
||||
|
||||
final Collection<DistributionSet> createdDSets = distributionSetManagement
|
||||
.create(MgmtDistributionSetMapper.dsFromRequest(sets, entityFactory));
|
||||
final Collection<? extends DistributionSet> createdDSets = distributionSetManagement
|
||||
.create(mgmtDistributionSetMapper.fromRequest(sets));
|
||||
|
||||
log.debug("{} distribution sets created, return status {}", sets.size(), HttpStatus.CREATED);
|
||||
return new ResponseEntity<>(MgmtDistributionSetMapper.toResponseDistributionSets(createdDSets), HttpStatus.CREATED);
|
||||
@@ -182,10 +182,11 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
|
||||
public ResponseEntity<MgmtDistributionSet> updateDistributionSet(
|
||||
final Long distributionSetId,
|
||||
final MgmtDistributionSetRequestBodyPut toUpdate) {
|
||||
final DistributionSet updated = distributionSetManagement.update(entityFactory.distributionSet()
|
||||
.update(distributionSetId).name(toUpdate.getName()).description(toUpdate.getDescription())
|
||||
final DistributionSet updated = distributionSetManagement.update(DistributionSetManagement.Update.builder()
|
||||
.id(distributionSetId).name(toUpdate.getName()).description(toUpdate.getDescription())
|
||||
.version(toUpdate.getVersion()).locked(toUpdate.getLocked())
|
||||
.requiredMigrationStep(toUpdate.getRequiredMigrationStep()));
|
||||
.requiredMigrationStep(toUpdate.getRequiredMigrationStep())
|
||||
.build());
|
||||
|
||||
final MgmtDistributionSet response = MgmtDistributionSetMapper.toResponse(updated);
|
||||
MgmtDistributionSetMapper.addLinks(updated, response);
|
||||
@@ -247,7 +248,7 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
|
||||
final List<Entry<String, Long>> offlineAssignments = assignments.stream()
|
||||
.map(assignment -> new SimpleEntry<>(assignment.getId(), distributionSetId))
|
||||
.collect(Collectors.toList());
|
||||
return ResponseEntity.ok(MgmtDistributionSetMapper
|
||||
return ResponseEntity.ok(mgmtDistributionSetMapper
|
||||
.toResponse(deployManagement.offlineAssignedDistributionSets(offlineAssignments)));
|
||||
}
|
||||
|
||||
@@ -260,7 +261,7 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
|
||||
}).toList();
|
||||
|
||||
final List<DistributionSetAssignmentResult> assignmentResults = deployManagement.assignDistributionSets(deploymentRequests);
|
||||
return ResponseEntity.ok(MgmtDistributionSetMapper.toResponse(assignmentResults));
|
||||
return ResponseEntity.ok(mgmtDistributionSetMapper.toResponse(assignmentResults));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -316,9 +317,8 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
|
||||
final Long distributionSetId,
|
||||
final int pagingOffsetParam, final int pagingLimitParam, final String sortParam) {
|
||||
final Pageable pageable = PagingUtility.toPageable(pagingOffsetParam, pagingLimitParam, sanitizeDistributionSetSortParam(sortParam));
|
||||
final Page<SoftwareModule> softwareModules = softwareModuleManagement.findByAssignedTo(distributionSetId, pageable);
|
||||
return ResponseEntity.ok(new PagedList<>(MgmtSoftwareModuleMapper.toResponse(
|
||||
softwareModules.getContent()), softwareModules.getTotalElements()));
|
||||
final Page<? extends SoftwareModule> softwareModules = softwareModuleManagement.findByAssignedTo(distributionSetId, pageable);
|
||||
return ResponseEntity.ok(new PagedList<>(MgmtSoftwareModuleMapper.toResponse(softwareModules.getContent()), softwareModules.getTotalElements()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -25,7 +25,6 @@ import org.eclipse.hawkbit.mgmt.rest.resource.mapper.MgmtTagMapper;
|
||||
import org.eclipse.hawkbit.mgmt.rest.resource.util.PagingUtility;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetManagement;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetTagManagement;
|
||||
import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
|
||||
@@ -41,31 +40,29 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRestApi {
|
||||
class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRestApi {
|
||||
|
||||
private final DistributionSetTagManagement distributionSetTagManagement;
|
||||
private final DistributionSetManagement distributionSetManagement;
|
||||
private final EntityFactory entityFactory;
|
||||
private final DistributionSetManagement<? extends DistributionSet> distributionSetManagement;
|
||||
private final DistributionSetTagManagement<? extends DistributionSetTag> distributionSetTagManagement;
|
||||
|
||||
MgmtDistributionSetTagResource(
|
||||
final DistributionSetTagManagement distributionSetTagManagement,
|
||||
final DistributionSetManagement distributionSetManagement, final EntityFactory entityFactory) {
|
||||
final DistributionSetManagement<? extends DistributionSet> distributionSetManagement,
|
||||
final DistributionSetTagManagement<? extends DistributionSetTag> distributionSetTagManagement) {
|
||||
this.distributionSetTagManagement = distributionSetTagManagement;
|
||||
this.distributionSetManagement = distributionSetManagement;
|
||||
this.entityFactory = entityFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<PagedList<MgmtTag>> getDistributionSetTags(
|
||||
final String rsqlParam, final int pagingOffsetParam, final int pagingLimitParam, final String sortParam) {
|
||||
final Pageable pageable = PagingUtility.toPageable(pagingOffsetParam, pagingLimitParam, sanitizeTagSortParam(sortParam));
|
||||
final Slice<DistributionSetTag> distributionSetTags;
|
||||
final Slice<? extends DistributionSetTag> distributionSetTags;
|
||||
final long count;
|
||||
if (rsqlParam == null) {
|
||||
distributionSetTags = distributionSetTagManagement.findAll(pageable);
|
||||
count = distributionSetTagManagement.count();
|
||||
} else {
|
||||
final Page<DistributionSetTag> page = distributionSetTagManagement.findByRsql(rsqlParam, pageable);
|
||||
final Page<? extends DistributionSetTag> page = distributionSetTagManagement.findByRsql(rsqlParam, pageable);
|
||||
distributionSetTags = page;
|
||||
count = page.getTotalElements();
|
||||
}
|
||||
@@ -88,7 +85,7 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes
|
||||
public ResponseEntity<List<MgmtTag>> createDistributionSetTags(final List<MgmtTagRequestBodyPut> tags) {
|
||||
log.debug("creating {} ds tags", tags.size());
|
||||
|
||||
final List<DistributionSetTag> createdTags = distributionSetTagManagement.create(MgmtTagMapper.mapTagFromRequest(entityFactory, tags));
|
||||
final List<? extends DistributionSetTag> createdTags = distributionSetTagManagement.create(MgmtDistributionSetMapper.mapTagFromRequest(tags));
|
||||
return new ResponseEntity<>(MgmtTagMapper.toResponseDistributionSetTag(createdTags), HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@@ -97,8 +94,8 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes
|
||||
public ResponseEntity<MgmtTag> updateDistributionSetTag(final Long distributionSetTagId, final MgmtTagRequestBodyPut restDSTagRest) {
|
||||
|
||||
final DistributionSetTag distributionSetTag = distributionSetTagManagement
|
||||
.update(entityFactory.tag().update(distributionSetTagId).name(restDSTagRest.getName())
|
||||
.description(restDSTagRest.getDescription()).colour(restDSTagRest.getColour()));
|
||||
.update(DistributionSetTagManagement.Update.builder().id(distributionSetTagId).name(restDSTagRest.getName())
|
||||
.description(restDSTagRest.getDescription()).colour(restDSTagRest.getColour()).build());
|
||||
|
||||
final MgmtTag response = MgmtTagMapper.toResponse(distributionSetTag);
|
||||
MgmtTagMapper.addLinks(distributionSetTag, response);
|
||||
@@ -122,7 +119,7 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes
|
||||
final Long distributionSetTagId, final String rsqlParam,
|
||||
final int pagingOffsetParam, final int pagingLimitParam, final String sortParam) {
|
||||
final Pageable pageable = PagingUtility.toPageable(pagingOffsetParam, pagingLimitParam, sanitizeTagSortParam(sortParam));
|
||||
final Page<DistributionSet> distributionSets;
|
||||
final Page<? extends DistributionSet> distributionSets;
|
||||
if (rsqlParam == null) {
|
||||
distributionSets = distributionSetManagement.findByTag(distributionSetTagId, pageable);
|
||||
} else {
|
||||
@@ -143,7 +140,7 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes
|
||||
@Override
|
||||
public ResponseEntity<Void> assignDistributionSets(final Long distributionSetTagId, final List<Long> distributionSetIds) {
|
||||
log.debug("Assign DistributionSet {} for ds tag {}", distributionSetIds.size(), distributionSetTagId);
|
||||
final List<DistributionSet> assignedDs = this.distributionSetManagement.assignTag(distributionSetIds, distributionSetTagId);
|
||||
final List<? extends DistributionSet> assignedDs = this.distributionSetManagement.assignTag(distributionSetIds, distributionSetTagId);
|
||||
log.debug("Assigned DistributionSet {}", assignedDs.size());
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
@@ -160,7 +157,7 @@ public class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRes
|
||||
@AuditLog(entity = "DistributionSetTag", type = AuditLog.Type.UPDATE, description = "Unassign Distribution Sets From Tag")
|
||||
public ResponseEntity<Void> unassignDistributionSets(final Long distributionsetTagId, final List<Long> distributionsetIds) {
|
||||
log.debug("Unassign DistributionSet {} for ds tag {}", distributionsetIds.size(), distributionsetTagId);
|
||||
final List<DistributionSet> assignedDs = this.distributionSetManagement.unassignTag(distributionsetIds, distributionsetTagId);
|
||||
final List<? extends DistributionSet> assignedDs = this.distributionSetManagement.unassignTag(distributionsetIds, distributionsetTagId);
|
||||
log.debug("Unassigned DistributionSet {}", assignedDs.size());
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ import org.eclipse.hawkbit.mgmt.rest.resource.mapper.MgmtDistributionSetTypeMapp
|
||||
import org.eclipse.hawkbit.mgmt.rest.resource.mapper.MgmtSoftwareModuleTypeMapper;
|
||||
import org.eclipse.hawkbit.mgmt.rest.resource.util.PagingUtility;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetTypeManagement;
|
||||
import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.SoftwareModuleTypeManagement;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.exception.SoftwareModuleTypeNotInDistributionSetTypeException;
|
||||
@@ -45,33 +44,34 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@RestController
|
||||
public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeRestApi {
|
||||
|
||||
private final SoftwareModuleTypeManagement softwareModuleTypeManagement;
|
||||
private final DistributionSetTypeManagement distributionSetTypeManagement;
|
||||
private final EntityFactory entityFactory;
|
||||
private final SoftwareModuleTypeManagement<? extends SoftwareModuleType> softwareModuleTypeManagement;
|
||||
private final DistributionSetTypeManagement<? extends DistributionSetType> distributionSetTypeManagement;
|
||||
private final MgmtDistributionSetTypeMapper mgmtDistributionSetTypeMapper;
|
||||
|
||||
MgmtDistributionSetTypeResource(
|
||||
final SoftwareModuleTypeManagement softwareModuleTypeManagement,
|
||||
final DistributionSetTypeManagement distributionSetTypeManagement, final EntityFactory entityFactory) {
|
||||
final SoftwareModuleTypeManagement<? extends SoftwareModuleType> softwareModuleTypeManagement,
|
||||
final DistributionSetTypeManagement<? extends DistributionSetType> distributionSetTypeManagement,
|
||||
final MgmtDistributionSetTypeMapper mgmtDistributionSetTypeMapper) {
|
||||
this.softwareModuleTypeManagement = softwareModuleTypeManagement;
|
||||
this.distributionSetTypeManagement = distributionSetTypeManagement;
|
||||
this.entityFactory = entityFactory;
|
||||
this.mgmtDistributionSetTypeMapper = mgmtDistributionSetTypeMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<PagedList<MgmtDistributionSetType>> getDistributionSetTypes(
|
||||
final String rsqlParam, final int pagingOffsetParam, final int pagingLimitParam, final String sortParam) {
|
||||
final Pageable pageable = PagingUtility.toPageable(pagingOffsetParam, pagingLimitParam, sanitizeDistributionSetTypeSortParam(sortParam));
|
||||
final Slice<DistributionSetType> findModuleTypessAll;
|
||||
final Slice<? extends DistributionSetType> findModuleTypesAll;
|
||||
long countModulesAll;
|
||||
if (rsqlParam != null) {
|
||||
findModuleTypessAll = distributionSetTypeManagement.findByRsql(rsqlParam, pageable);
|
||||
countModulesAll = ((Page<DistributionSetType>) findModuleTypessAll).getTotalElements();
|
||||
findModuleTypesAll = distributionSetTypeManagement.findByRsql(rsqlParam, pageable);
|
||||
countModulesAll = ((Page<?>) findModuleTypesAll).getTotalElements();
|
||||
} else {
|
||||
findModuleTypessAll = distributionSetTypeManagement.findAll(pageable);
|
||||
findModuleTypesAll = distributionSetTypeManagement.findAll(pageable);
|
||||
countModulesAll = distributionSetTypeManagement.count();
|
||||
}
|
||||
|
||||
final List<MgmtDistributionSetType> rest = MgmtDistributionSetTypeMapper.toListResponse(findModuleTypessAll.getContent());
|
||||
final List<MgmtDistributionSetType> rest = MgmtDistributionSetTypeMapper.toListResponse(findModuleTypesAll.getContent());
|
||||
return ResponseEntity.ok(new PagedList<>(rest, countModulesAll));
|
||||
}
|
||||
|
||||
@@ -97,9 +97,10 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
|
||||
@AuditLog(entity = "DistributionSetType", type = AuditLog.Type.UPDATE, description = "Update Distribution Set Type")
|
||||
public ResponseEntity<MgmtDistributionSetType> updateDistributionSetType(
|
||||
final Long distributionSetTypeId, final MgmtDistributionSetTypeRequestBodyPut restDistributionSetType) {
|
||||
final DistributionSetType updated = distributionSetTypeManagement.update(entityFactory.distributionSetType()
|
||||
.update(distributionSetTypeId).description(restDistributionSetType.getDescription())
|
||||
.colour(restDistributionSetType.getColour()));
|
||||
final DistributionSetType updated = distributionSetTypeManagement.update(DistributionSetTypeManagement.Update.builder()
|
||||
.id(distributionSetTypeId).description(restDistributionSetType.getDescription())
|
||||
.colour(restDistributionSetType.getColour()).
|
||||
build());
|
||||
|
||||
final MgmtDistributionSetType response = MgmtDistributionSetTypeMapper.toResponse(updated);
|
||||
MgmtDistributionSetTypeMapper.addLinks(response);
|
||||
@@ -110,11 +111,10 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
|
||||
@Override
|
||||
public ResponseEntity<List<MgmtDistributionSetType>> createDistributionSetTypes(
|
||||
final List<MgmtDistributionSetTypeRequestBodyPost> distributionSetTypes) {
|
||||
final List<DistributionSetType> createdSoftwareModules = distributionSetTypeManagement
|
||||
.create(MgmtDistributionSetTypeMapper.smFromRequest(entityFactory, distributionSetTypes));
|
||||
final List<? extends DistributionSetType> createdSoftwareModules = distributionSetTypeManagement
|
||||
.create(mgmtDistributionSetTypeMapper.smFromRequest(distributionSetTypes));
|
||||
|
||||
return ResponseEntity.status(HttpStatus.CREATED)
|
||||
.body(MgmtDistributionSetTypeMapper.toListResponse(createdSoftwareModules));
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(MgmtDistributionSetTypeMapper.toListResponse(createdSoftwareModules));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -36,10 +36,10 @@ import org.springframework.web.context.WebApplicationContext;
|
||||
@Scope(value = WebApplicationContext.SCOPE_REQUEST)
|
||||
public class MgmtDownloadArtifactResource implements MgmtDownloadArtifactRestApi {
|
||||
|
||||
private final SoftwareModuleManagement softwareModuleManagement;
|
||||
private final SoftwareModuleManagement<? extends SoftwareModule> softwareModuleManagement;
|
||||
private final ArtifactManagement artifactManagement;
|
||||
|
||||
public MgmtDownloadArtifactResource(final SoftwareModuleManagement softwareModuleManagement, final ArtifactManagement artifactManagement) {
|
||||
public MgmtDownloadArtifactResource(final SoftwareModuleManagement<? extends SoftwareModule> softwareModuleManagement, final ArtifactManagement artifactManagement) {
|
||||
this.softwareModuleManagement = softwareModuleManagement;
|
||||
this.artifactManagement = artifactManagement;
|
||||
}
|
||||
|
||||
@@ -62,21 +62,25 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
|
||||
|
||||
private final ArtifactManagement artifactManagement;
|
||||
private final SoftwareModuleManagement softwareModuleManagement;
|
||||
private final SoftwareModuleTypeManagement softwareModuleTypeManagement;
|
||||
private final SoftwareModuleManagement<? extends SoftwareModule> softwareModuleManagement;
|
||||
private final SoftwareModuleTypeManagement<? extends SoftwareModuleType> softwareModuleTypeManagement;
|
||||
private final ArtifactUrlHandler artifactUrlHandler;
|
||||
private final MgmtSoftwareModuleMapper mgmtSoftwareModuleMapper;
|
||||
private final SystemManagement systemManagement;
|
||||
private final EntityFactory entityFactory;
|
||||
|
||||
MgmtSoftwareModuleResource(
|
||||
final ArtifactManagement artifactManagement, final SoftwareModuleManagement softwareModuleManagement,
|
||||
final SoftwareModuleTypeManagement softwareModuleTypeManagement,
|
||||
final ArtifactUrlHandler artifactUrlHandler, final SystemManagement systemManagement,
|
||||
final EntityFactory entityFactory) {
|
||||
final ArtifactManagement artifactManagement,
|
||||
final SoftwareModuleManagement<? extends SoftwareModule> softwareModuleManagement,
|
||||
final SoftwareModuleTypeManagement<? extends SoftwareModuleType> softwareModuleTypeManagement,
|
||||
final ArtifactUrlHandler artifactUrlHandler,
|
||||
final MgmtSoftwareModuleMapper mgmtSoftwareModuleMapper,
|
||||
final SystemManagement systemManagement, final EntityFactory entityFactory) {
|
||||
this.artifactManagement = artifactManagement;
|
||||
this.softwareModuleManagement = softwareModuleManagement;
|
||||
this.softwareModuleTypeManagement = softwareModuleTypeManagement;
|
||||
this.artifactUrlHandler = artifactUrlHandler;
|
||||
this.mgmtSoftwareModuleMapper = mgmtSoftwareModuleMapper;
|
||||
this.systemManagement = systemManagement;
|
||||
this.entityFactory = entityFactory;
|
||||
}
|
||||
@@ -159,11 +163,11 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
|
||||
public ResponseEntity<PagedList<MgmtSoftwareModule>> getSoftwareModules(
|
||||
final String rsqlParam, final int pagingOffsetParam, final int pagingLimitParam, final String sortParam) {
|
||||
final Pageable pageable = PagingUtility.toPageable(pagingOffsetParam, pagingLimitParam, sanitizeSoftwareModuleSortParam(sortParam));
|
||||
final Slice<SoftwareModule> findModulesAll;
|
||||
final Slice<? extends SoftwareModule> findModulesAll;
|
||||
final long countModulesAll;
|
||||
if (rsqlParam != null) {
|
||||
findModulesAll = softwareModuleManagement.findByRsql(rsqlParam, pageable);
|
||||
countModulesAll = ((Page<SoftwareModule>) findModulesAll).getTotalElements();
|
||||
countModulesAll = ((Page<?>) findModulesAll).getTotalElements();
|
||||
} else {
|
||||
findModulesAll = softwareModuleManagement.findAll(pageable);
|
||||
countModulesAll = softwareModuleManagement.count();
|
||||
@@ -188,7 +192,7 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
|
||||
log.debug("creating {} softwareModules", softwareModules.size());
|
||||
|
||||
for (final MgmtSoftwareModuleRequestBodyPost sm : softwareModules) {
|
||||
final Optional<SoftwareModuleType> opt = softwareModuleTypeManagement.findByKey(sm.getType());
|
||||
final Optional<? extends SoftwareModuleType> opt = softwareModuleTypeManagement.findByKey(sm.getType());
|
||||
opt.ifPresent(smType -> {
|
||||
if (smType.isDeleted()) {
|
||||
final String text = "Cannot create Software Module from type with key {0}. Software Module Type already deleted!";
|
||||
@@ -197,8 +201,8 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
|
||||
}
|
||||
});
|
||||
}
|
||||
final Collection<SoftwareModule> createdSoftwareModules = softwareModuleManagement
|
||||
.create(MgmtSoftwareModuleMapper.smFromRequest(entityFactory, softwareModules));
|
||||
final Collection<? extends SoftwareModule> createdSoftwareModules = softwareModuleManagement
|
||||
.create(mgmtSoftwareModuleMapper.smFromRequest(softwareModules));
|
||||
log.debug("{} softwareModules created, return status {}", softwareModules.size(), HttpStatus.CREATED);
|
||||
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(MgmtSoftwareModuleMapper.toResponse(createdSoftwareModules));
|
||||
@@ -208,10 +212,12 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
|
||||
public ResponseEntity<MgmtSoftwareModule> updateSoftwareModule(
|
||||
final Long softwareModuleId, final MgmtSoftwareModuleRequestBodyPut restSoftwareModule) {
|
||||
final SoftwareModule module = softwareModuleManagement
|
||||
.update(entityFactory.softwareModule().update(softwareModuleId)
|
||||
.update(SoftwareModuleManagement.Update.builder()
|
||||
.id(softwareModuleId)
|
||||
.description(restSoftwareModule.getDescription())
|
||||
.vendor(restSoftwareModule.getVendor())
|
||||
.locked(restSoftwareModule.getLocked()));
|
||||
.locked(restSoftwareModule.getLocked())
|
||||
.build());
|
||||
|
||||
final MgmtSoftwareModule response = MgmtSoftwareModuleMapper.toResponse(module);
|
||||
MgmtSoftwareModuleMapper.addLinks(module, response);
|
||||
|
||||
@@ -38,23 +38,21 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@RestController
|
||||
public class MgmtSoftwareModuleTypeResource implements MgmtSoftwareModuleTypeRestApi {
|
||||
|
||||
private final SoftwareModuleTypeManagement softwareModuleTypeManagement;
|
||||
private final EntityFactory entityFactory;
|
||||
private final SoftwareModuleTypeManagement<? extends SoftwareModuleType> softwareModuleTypeManagement;
|
||||
|
||||
MgmtSoftwareModuleTypeResource(final SoftwareModuleTypeManagement softwareModuleTypeManagement, final EntityFactory entityFactory) {
|
||||
MgmtSoftwareModuleTypeResource(final SoftwareModuleTypeManagement<? extends SoftwareModuleType> softwareModuleTypeManagement) {
|
||||
this.softwareModuleTypeManagement = softwareModuleTypeManagement;
|
||||
this.entityFactory = entityFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<PagedList<MgmtSoftwareModuleType>> getTypes(
|
||||
final String rsqlParam, final int pagingOffsetParam, final int pagingLimitParam, final String sortParam) {
|
||||
final Pageable pageable = PagingUtility.toPageable(pagingOffsetParam, pagingLimitParam, sanitizeSoftwareModuleTypeSortParam(sortParam));
|
||||
final Slice<SoftwareModuleType> findModuleTypessAll;
|
||||
final Slice<? extends SoftwareModuleType> findModuleTypessAll;
|
||||
final long countModulesAll;
|
||||
if (rsqlParam != null) {
|
||||
findModuleTypessAll = softwareModuleTypeManagement.findByRsql(rsqlParam, pageable);
|
||||
countModulesAll = ((Page<SoftwareModuleType>) findModuleTypessAll).getTotalElements();
|
||||
countModulesAll = ((Page<?>) findModuleTypessAll).getTotalElements();
|
||||
} else {
|
||||
findModuleTypessAll = softwareModuleTypeManagement.findAll(pageable);
|
||||
countModulesAll = softwareModuleTypeManagement.count();
|
||||
@@ -80,9 +78,11 @@ public class MgmtSoftwareModuleTypeResource implements MgmtSoftwareModuleTypeRes
|
||||
@Override
|
||||
public ResponseEntity<MgmtSoftwareModuleType> updateSoftwareModuleType(
|
||||
final Long softwareModuleTypeId, final MgmtSoftwareModuleTypeRequestBodyPut restSoftwareModuleType) {
|
||||
final SoftwareModuleType updatedSoftwareModuleType = softwareModuleTypeManagement.update(entityFactory
|
||||
.softwareModuleType().update(softwareModuleTypeId).description(restSoftwareModuleType.getDescription())
|
||||
.colour(restSoftwareModuleType.getColour()));
|
||||
final SoftwareModuleType updatedSoftwareModuleType = softwareModuleTypeManagement.update(
|
||||
SoftwareModuleTypeManagement.Update.builder().id(softwareModuleTypeId)
|
||||
.description(restSoftwareModuleType.getDescription())
|
||||
.colour(restSoftwareModuleType.getColour())
|
||||
.build());
|
||||
|
||||
return ResponseEntity.ok(MgmtSoftwareModuleTypeMapper.toResponse(updatedSoftwareModuleType));
|
||||
}
|
||||
@@ -90,8 +90,8 @@ public class MgmtSoftwareModuleTypeResource implements MgmtSoftwareModuleTypeRes
|
||||
@Override
|
||||
public ResponseEntity<List<MgmtSoftwareModuleType>> createSoftwareModuleTypes(
|
||||
final List<MgmtSoftwareModuleTypeRequestBodyPost> softwareModuleTypes) {
|
||||
final List<SoftwareModuleType> createdSoftwareModules = softwareModuleTypeManagement
|
||||
.create(MgmtSoftwareModuleTypeMapper.smFromRequest(entityFactory, softwareModuleTypes));
|
||||
final List<? extends SoftwareModuleType> createdSoftwareModules = softwareModuleTypeManagement
|
||||
.create(MgmtSoftwareModuleTypeMapper.smFromRequest(softwareModuleTypes));
|
||||
|
||||
return new ResponseEntity<>(MgmtSoftwareModuleTypeMapper.toTypesResponse(createdSoftwareModules), HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@@ -86,17 +86,21 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
|
||||
private final TargetManagement targetManagement;
|
||||
private final ConfirmationManagement confirmationManagement;
|
||||
private final DeploymentManagement deploymentManagement;
|
||||
private final MgmtDistributionSetMapper mgmtDistributionSetMapper;
|
||||
private final EntityFactory entityFactory;
|
||||
private final TenantConfigHelper tenantConfigHelper;
|
||||
|
||||
MgmtTargetResource(
|
||||
final TargetManagement targetManagement, final DeploymentManagement deploymentManagement,
|
||||
final ConfirmationManagement confirmationManagement, final EntityFactory entityFactory,
|
||||
final ConfirmationManagement confirmationManagement,
|
||||
final MgmtDistributionSetMapper mgmtDistributionSetMapper,
|
||||
final EntityFactory entityFactory,
|
||||
final SystemSecurityContext systemSecurityContext,
|
||||
final TenantConfigurationManagement tenantConfigurationManagement) {
|
||||
this.targetManagement = targetManagement;
|
||||
this.deploymentManagement = deploymentManagement;
|
||||
this.confirmationManagement = confirmationManagement;
|
||||
this.mgmtDistributionSetMapper = mgmtDistributionSetMapper;
|
||||
this.entityFactory = entityFactory;
|
||||
this.tenantConfigHelper = TenantConfigHelper.usingContext(systemSecurityContext, tenantConfigurationManagement);
|
||||
}
|
||||
@@ -290,7 +294,7 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
|
||||
log.debug("updateActionConfirmation with data [targetId={}, actionId={}]: {}", targetId, actionId, actionConfirmation);
|
||||
|
||||
return getValidatedAction(targetId, actionId)
|
||||
.map(action -> {
|
||||
.<ResponseEntity<Void>>map(action -> {
|
||||
try {
|
||||
switch (actionConfirmation.getConfirmation()) {
|
||||
case CONFIRMED:
|
||||
@@ -305,18 +309,18 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
|
||||
confirmationManagement.denyAction(actionId, actionConfirmation.getCode(), actionConfirmation.getDetails());
|
||||
break;
|
||||
}
|
||||
return new ResponseEntity<Void>(HttpStatus.OK);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
} catch (final InvalidConfirmationFeedbackException e) {
|
||||
if (e.getReason() == InvalidConfirmationFeedbackException.Reason.ACTION_CLOSED) {
|
||||
log.warn("Updating action {} with confirmation {} not possible since action not active anymore.",
|
||||
action.getId(), actionConfirmation.getConfirmation(), e);
|
||||
return new ResponseEntity<Void>(HttpStatus.GONE);
|
||||
return new ResponseEntity<>(HttpStatus.GONE);
|
||||
} else if (e.getReason() == InvalidConfirmationFeedbackException.Reason.NOT_AWAITING_CONFIRMATION) {
|
||||
log.debug("Action is not waiting for confirmation, deny request.", e);
|
||||
return new ResponseEntity<Void>(HttpStatus.NOT_FOUND);
|
||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
} else {
|
||||
log.debug("Action confirmation failed with unknown reason.", e);
|
||||
return new ResponseEntity<Void>(HttpStatus.BAD_REQUEST);
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -371,7 +375,7 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
|
||||
final List<Entry<String, Long>> offlineAssignments = dsAssignments.stream()
|
||||
.map(dsAssignment -> new SimpleEntry<>(targetId, dsAssignment.getId()))
|
||||
.collect(Collectors.toList());
|
||||
return ResponseEntity.ok(MgmtDistributionSetMapper
|
||||
return ResponseEntity.ok(mgmtDistributionSetMapper
|
||||
.toResponse(deploymentManagement.offlineAssignedDistributionSets(offlineAssignments)));
|
||||
}
|
||||
findTargetWithExceptionIfNotFound(targetId);
|
||||
@@ -386,7 +390,7 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
|
||||
|
||||
final List<DistributionSetAssignmentResult> assignmentResults = deploymentManagement
|
||||
.assignDistributionSets(deploymentRequests);
|
||||
return ResponseEntity.ok(MgmtDistributionSetMapper.toResponse(assignmentResults));
|
||||
return ResponseEntity.ok(mgmtDistributionSetMapper.toResponse(assignmentResults));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -92,7 +92,7 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi {
|
||||
@Override
|
||||
public ResponseEntity<List<MgmtTag>> createTargetTags(final List<MgmtTagRequestBodyPut> tags) {
|
||||
log.debug("creating {} target tags", tags.size());
|
||||
final List<TargetTag> createdTargetTags = this.tagManagement.create(MgmtTagMapper.mapTagFromRequest(entityFactory, tags));
|
||||
final List<TargetTag> createdTargetTags = tagManagement.create(MgmtTagMapper.mapTagFromRequest(entityFactory, tags));
|
||||
return new ResponseEntity<>(MgmtTagMapper.toResponse(createdTargetTags), HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,45 +12,59 @@ package org.eclipse.hawkbit.mgmt.rest.resource.mapper;
|
||||
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
|
||||
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.MgmtMetadata;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtActionId;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtDistributionSet;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtDistributionSetRequestBodyPost;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtTargetAssignmentResponseBody;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.tag.MgmtTagRequestBodyPut;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetRestApi;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetTypeRestApi;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
|
||||
import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.builder.DistributionSetCreate;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetManagement;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetTagManagement;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetTypeManagement;
|
||||
import org.eclipse.hawkbit.repository.SoftwareModuleManagement;
|
||||
import org.eclipse.hawkbit.repository.SystemManagement;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.rest.json.model.ResponseList;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
/**
|
||||
* A mapper which maps repository model to RESTful model representation and
|
||||
* back.
|
||||
* A mapper which maps repository model to RESTful model representation and back.
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public final class MgmtDistributionSetMapper {
|
||||
@Service
|
||||
public class MgmtDistributionSetMapper {
|
||||
|
||||
/**
|
||||
* {@link MgmtDistributionSetRequestBodyPost}s to {@link DistributionSet}s.
|
||||
*
|
||||
* @param sets to convert
|
||||
* @return converted list of {@link DistributionSet}s
|
||||
*/
|
||||
public static List<DistributionSetCreate> dsFromRequest(
|
||||
final Collection<MgmtDistributionSetRequestBodyPost> sets, final EntityFactory entityFactory) {
|
||||
return sets.stream().map(dsRest -> fromRequest(dsRest, entityFactory)).toList();
|
||||
private final DistributionSetTypeManagement<? extends DistributionSetType> distributionSetTypeManagement;
|
||||
private final SoftwareModuleManagement<? extends SoftwareModule> softwareModuleManagement;
|
||||
private final SystemManagement systemManagement;
|
||||
|
||||
MgmtDistributionSetMapper(
|
||||
final DistributionSetTypeManagement<? extends DistributionSetType> distributionSetTypeManagement,
|
||||
final SoftwareModuleManagement<? extends SoftwareModule> softwareModuleManagement,
|
||||
final SystemManagement systemManagement) {
|
||||
this.distributionSetTypeManagement = distributionSetTypeManagement;
|
||||
this.softwareModuleManagement = softwareModuleManagement;
|
||||
this.systemManagement = systemManagement;
|
||||
}
|
||||
|
||||
public List<DistributionSetManagement.Create> fromRequest(final Collection<MgmtDistributionSetRequestBodyPost> sets) {
|
||||
return sets.stream().map(this::fromRequest).toList();
|
||||
}
|
||||
|
||||
public static MgmtDistributionSet toResponse(final DistributionSet distributionSet) {
|
||||
@@ -70,13 +84,11 @@ public final class MgmtDistributionSetMapper {
|
||||
response.setDeleted(distributionSet.isDeleted());
|
||||
response.setValid(distributionSet.isValid());
|
||||
|
||||
distributionSet.getModules()
|
||||
.forEach(module -> response.getModules().add(MgmtSoftwareModuleMapper.toResponse(module)));
|
||||
distributionSet.getModules().forEach(module -> response.getModules().add(MgmtSoftwareModuleMapper.toResponse(module)));
|
||||
|
||||
response.setRequiredMigrationStep(distributionSet.isRequiredMigrationStep());
|
||||
|
||||
response.add(linkTo(methodOn(MgmtDistributionSetRestApi.class).getDistributionSet(response.getId()))
|
||||
.withSelfRel().expand());
|
||||
response.add(linkTo(methodOn(MgmtDistributionSetRestApi.class).getDistributionSet(response.getId())).withSelfRel().expand());
|
||||
|
||||
return response;
|
||||
}
|
||||
@@ -102,7 +114,7 @@ public final class MgmtDistributionSetMapper {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static MgmtTargetAssignmentResponseBody toResponse(final List<DistributionSetAssignmentResult> dsAssignmentResults) {
|
||||
public MgmtTargetAssignmentResponseBody toResponse(final List<DistributionSetAssignmentResult> dsAssignmentResults) {
|
||||
final MgmtTargetAssignmentResponseBody result = new MgmtTargetAssignmentResponseBody();
|
||||
final int alreadyAssigned = dsAssignmentResults.stream()
|
||||
.mapToInt(DistributionSetAssignmentResult::getAlreadyAssigned).sum();
|
||||
@@ -115,7 +127,7 @@ public final class MgmtDistributionSetMapper {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List<MgmtDistributionSet> toResponseDistributionSets(final Collection<DistributionSet> sets) {
|
||||
public static List<MgmtDistributionSet> toResponseDistributionSets(final Collection<? extends DistributionSet> sets) {
|
||||
if (sets == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@@ -123,6 +135,16 @@ public final class MgmtDistributionSetMapper {
|
||||
return new ResponseList<>(sets.stream().map(MgmtDistributionSetMapper::toResponse).toList());
|
||||
}
|
||||
|
||||
public static List<DistributionSetTagManagement.Create> mapTagFromRequest(final Collection<MgmtTagRequestBodyPut> tags) {
|
||||
return tags.stream()
|
||||
.map(tagRest -> DistributionSetTagManagement.Create.builder()
|
||||
.name(tagRest.getName())
|
||||
.description(tagRest.getDescription()).colour(tagRest.getColour())
|
||||
.build())
|
||||
.map(DistributionSetTagManagement.Create.class::cast)
|
||||
.toList();
|
||||
}
|
||||
|
||||
public static MgmtMetadata toResponseDsMetadata(final String key, String value) {
|
||||
final MgmtMetadata metadataRest = new MgmtMetadata();
|
||||
metadataRest.setKey(key);
|
||||
@@ -140,7 +162,7 @@ public final class MgmtDistributionSetMapper {
|
||||
return metadata.entrySet().stream().map(e -> toResponseDsMetadata(e.getKey(), e.getValue())).toList();
|
||||
}
|
||||
|
||||
public static List<MgmtDistributionSet> toResponseFromDsList(final List<DistributionSet> sets) {
|
||||
public static List<MgmtDistributionSet> toResponseFromDsList(final List<? extends DistributionSet> sets) {
|
||||
if (sets == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@@ -148,14 +170,8 @@ public final class MgmtDistributionSetMapper {
|
||||
return sets.stream().map(MgmtDistributionSetMapper::toResponse).toList();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link MgmtDistributionSetRequestBodyPost} to {@link DistributionSet}.
|
||||
*
|
||||
* @param dsRest to convert
|
||||
* @return converted {@link DistributionSet}
|
||||
*/
|
||||
private static DistributionSetCreate fromRequest(final MgmtDistributionSetRequestBodyPost dsRest, final EntityFactory entityFactory) {
|
||||
final List<Long> modules = new ArrayList<>();
|
||||
private DistributionSetManagement.Create fromRequest(final MgmtDistributionSetRequestBodyPost dsRest) {
|
||||
final Set<Long> modules = new HashSet<>();
|
||||
if (dsRest.getOs() != null) {
|
||||
modules.add(dsRest.getOs().getId());
|
||||
}
|
||||
@@ -168,8 +184,32 @@ public final class MgmtDistributionSetMapper {
|
||||
if (dsRest.getModules() != null) {
|
||||
dsRest.getModules().forEach(module -> modules.add(module.getId()));
|
||||
}
|
||||
return entityFactory.distributionSet().create().name(dsRest.getName()).version(dsRest.getVersion())
|
||||
.description(dsRest.getDescription()).type(dsRest.getType()).modules(modules)
|
||||
.requiredMigrationStep(dsRest.getRequiredMigrationStep());
|
||||
return DistributionSetManagement.Create.builder()
|
||||
.type(Optional.ofNullable(dsRest.getType())
|
||||
// if the type is supplied the type MUST exist
|
||||
.map(typeKey -> distributionSetTypeManagement
|
||||
.findByKey(typeKey)
|
||||
.orElseThrow(() -> new EntityNotFoundException(DistributionSetType.class, typeKey)))
|
||||
.map(DistributionSetType.class::cast)
|
||||
// if here, the type is not supplied, use the default type
|
||||
.orElseGet(() -> systemManagement.getTenantMetadata().getDefaultDsType()))
|
||||
.name(dsRest.getName()).version(dsRest.getVersion())
|
||||
.description(dsRest.getDescription())
|
||||
.modules(findSoftwareModuleWithExceptionIfNotFound(modules))
|
||||
.requiredMigrationStep(dsRest.getRequiredMigrationStep())
|
||||
.build();
|
||||
}
|
||||
|
||||
private Set<? extends SoftwareModule> findSoftwareModuleWithExceptionIfNotFound(final Set<Long> softwareModuleIds) {
|
||||
if (CollectionUtils.isEmpty(softwareModuleIds)) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
final List<? extends SoftwareModule> modules = softwareModuleManagement.get(softwareModuleIds);
|
||||
if (modules.size() < softwareModuleIds.size()) {
|
||||
throw new EntityNotFoundException(SoftwareModule.class, softwareModuleIds);
|
||||
}
|
||||
|
||||
return new HashSet<>(modules);
|
||||
}
|
||||
}
|
||||
@@ -14,36 +14,47 @@ import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionSetType;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionSetTypeRequestBodyPost;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.softwaremoduletype.MgmtSoftwareModuleTypeAssignment;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetTypeRestApi;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
|
||||
import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.builder.DistributionSetTypeCreate;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetTypeManagement;
|
||||
import org.eclipse.hawkbit.repository.SoftwareModuleTypeManagement;
|
||||
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.json.model.ResponseList;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
/**
|
||||
* A mapper which maps repository model to RESTful model representation and back.
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@Service
|
||||
public final class MgmtDistributionSetTypeMapper {
|
||||
|
||||
public static List<DistributionSetTypeCreate> smFromRequest(final EntityFactory entityFactory, final Collection<MgmtDistributionSetTypeRequestBodyPost> smTypesRest) {
|
||||
private final SoftwareModuleTypeManagement<? extends SoftwareModuleType> softwareModuleTypeManagement;
|
||||
|
||||
MgmtDistributionSetTypeMapper(final SoftwareModuleTypeManagement<? extends SoftwareModuleType> softwareModuleTypeManagement) {
|
||||
this.softwareModuleTypeManagement = softwareModuleTypeManagement;
|
||||
}
|
||||
|
||||
public List<DistributionSetTypeManagement.Create> smFromRequest(final Collection<MgmtDistributionSetTypeRequestBodyPost> smTypesRest) {
|
||||
if (smTypesRest == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return smTypesRest.stream().map(smRest -> fromRequest(entityFactory, smRest)).toList();
|
||||
return smTypesRest.stream().map(this::fromRequest).toList();
|
||||
}
|
||||
|
||||
public static List<MgmtDistributionSetType> toListResponse(final Collection<DistributionSetType> types) {
|
||||
public static List<MgmtDistributionSetType> toListResponse(final Collection<? extends DistributionSetType> types) {
|
||||
if (types == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@@ -71,22 +82,32 @@ public final class MgmtDistributionSetTypeMapper {
|
||||
.withRel(MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_OPTIONAL_MODULES).expand());
|
||||
}
|
||||
|
||||
private static DistributionSetTypeCreate fromRequest(final EntityFactory entityFactory,
|
||||
final MgmtDistributionSetTypeRequestBodyPost smsRest) {
|
||||
return entityFactory.distributionSetType().create().key(smsRest.getKey()).name(smsRest.getName())
|
||||
private DistributionSetTypeManagement.Create fromRequest(final MgmtDistributionSetTypeRequestBodyPost smsRest) {
|
||||
return DistributionSetTypeManagement.Create.builder()
|
||||
.key(smsRest.getKey()).name(smsRest.getName())
|
||||
.description(smsRest.getDescription()).colour(smsRest.getColour())
|
||||
.mandatory(getMandatoryModules(smsRest)).optional(getOptionalModules(smsRest));
|
||||
.mandatoryModuleTypes(getModules(smsRest.getMandatorymodules()))
|
||||
.optionalModuleTypes(getModules(smsRest.getOptionalmodules()))
|
||||
.build();
|
||||
}
|
||||
|
||||
private static Collection<Long> getMandatoryModules(final MgmtDistributionSetTypeRequestBodyPost smsRest) {
|
||||
return Optional.ofNullable(smsRest.getMandatorymodules())
|
||||
.map(modules -> modules.stream().map(MgmtSoftwareModuleTypeAssignment::getId).toList())
|
||||
.orElse(Collections.emptyList());
|
||||
private Set<? extends SoftwareModuleType> getModules(final List<MgmtSoftwareModuleTypeAssignment> moduleAssignments) {
|
||||
return Optional.ofNullable(moduleAssignments)
|
||||
.map(modules -> modules.stream().map(MgmtSoftwareModuleTypeAssignment::getId).collect(Collectors.toSet()))
|
||||
.map(this::findSoftwareModuleTypeWithExceptionIfNotFound)
|
||||
.orElse(Collections.emptySet());
|
||||
}
|
||||
|
||||
private static Collection<Long> getOptionalModules(final MgmtDistributionSetTypeRequestBodyPost smsRest) {
|
||||
return Optional.ofNullable(smsRest.getOptionalmodules())
|
||||
.map(modules -> modules.stream().map(MgmtSoftwareModuleTypeAssignment::getId).toList())
|
||||
.orElse(Collections.emptyList());
|
||||
private Set<? extends SoftwareModuleType> findSoftwareModuleTypeWithExceptionIfNotFound(final Collection<Long> softwareModuleTypeId) {
|
||||
if (CollectionUtils.isEmpty(softwareModuleTypeId)) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
final List<? extends SoftwareModuleType> module = softwareModuleTypeManagement.get(softwareModuleTypeId);
|
||||
if (module.size() < softwareModuleTypeId.size()) {
|
||||
throw new EntityNotFoundException(SoftwareModuleType.class, softwareModuleTypeId);
|
||||
}
|
||||
|
||||
return new HashSet<>(module);
|
||||
}
|
||||
}
|
||||
@@ -16,12 +16,8 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.eclipse.hawkbit.repository.artifact.urlhandler.ApiType;
|
||||
import org.eclipse.hawkbit.repository.artifact.urlhandler.ArtifactUrl;
|
||||
import org.eclipse.hawkbit.repository.artifact.urlhandler.ArtifactUrlHandler;
|
||||
import org.eclipse.hawkbit.repository.artifact.urlhandler.URLPlaceholder;
|
||||
import jakarta.validation.ValidationException;
|
||||
|
||||
import org.eclipse.hawkbit.mgmt.json.model.artifact.MgmtArtifact;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.artifact.MgmtArtifactHash;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.softwaremodule.MgmtSoftwareModule;
|
||||
@@ -33,22 +29,36 @@ import org.eclipse.hawkbit.mgmt.rest.api.MgmtSoftwareModuleTypeRestApi;
|
||||
import org.eclipse.hawkbit.mgmt.rest.resource.MgmtDownloadArtifactResource;
|
||||
import org.eclipse.hawkbit.mgmt.rest.resource.MgmtSoftwareModuleResource;
|
||||
import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.SoftwareModuleManagement;
|
||||
import org.eclipse.hawkbit.repository.SoftwareModuleTypeManagement;
|
||||
import org.eclipse.hawkbit.repository.SystemManagement;
|
||||
import org.eclipse.hawkbit.repository.builder.SoftwareModuleCreate;
|
||||
import org.eclipse.hawkbit.repository.artifact.urlhandler.ApiType;
|
||||
import org.eclipse.hawkbit.repository.artifact.urlhandler.ArtifactUrl;
|
||||
import org.eclipse.hawkbit.repository.artifact.urlhandler.ArtifactUrlHandler;
|
||||
import org.eclipse.hawkbit.repository.artifact.urlhandler.URLPlaceholder;
|
||||
import org.eclipse.hawkbit.repository.builder.SoftwareModuleMetadataCreate;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.model.Artifact;
|
||||
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.json.model.ResponseList;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.server.mvc.WebMvcLinkBuilder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* A mapper which maps repository model to RESTful model representation and back.
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@Service
|
||||
public final class MgmtSoftwareModuleMapper {
|
||||
|
||||
private final SoftwareModuleTypeManagement<? extends SoftwareModuleType> softwareModuleTypeManagement;
|
||||
|
||||
MgmtSoftwareModuleMapper(final SoftwareModuleTypeManagement<? extends SoftwareModuleType> softwareModuleTypeManagement) {
|
||||
this.softwareModuleTypeManagement = softwareModuleTypeManagement;
|
||||
}
|
||||
|
||||
public static List<SoftwareModuleMetadataCreate> fromRequestSwMetadata(
|
||||
final EntityFactory entityFactory, final Long softwareModuleId, final Collection<MgmtSoftwareModuleMetadata> metadata) {
|
||||
if (metadata == null) {
|
||||
@@ -62,16 +72,15 @@ public final class MgmtSoftwareModuleMapper {
|
||||
.toList();
|
||||
}
|
||||
|
||||
public static List<SoftwareModuleCreate> smFromRequest(
|
||||
final EntityFactory entityFactory, final Collection<MgmtSoftwareModuleRequestBodyPost> smsRest) {
|
||||
public List<SoftwareModuleManagement.Create> smFromRequest(final Collection<MgmtSoftwareModuleRequestBodyPost> smsRest) {
|
||||
if (smsRest == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return smsRest.stream().map(smRest -> fromRequest(entityFactory, smRest)).toList();
|
||||
return smsRest.stream().map(this::fromRequest).toList();
|
||||
}
|
||||
|
||||
public static List<MgmtSoftwareModule> toResponse(final Collection<SoftwareModule> softwareModules) {
|
||||
public static List<MgmtSoftwareModule> toResponse(final Collection<? extends SoftwareModule> softwareModules) {
|
||||
if (softwareModules == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@@ -145,7 +154,7 @@ public final class MgmtSoftwareModuleMapper {
|
||||
|
||||
public static void addLinks(final Artifact artifact, final MgmtArtifact response) {
|
||||
response.add(WebMvcLinkBuilder.linkTo(methodOn(MgmtDownloadArtifactResource.class)
|
||||
.downloadArtifact(artifact.getSoftwareModule().getId(), artifact.getId())).withRel("download")
|
||||
.downloadArtifact(artifact.getSoftwareModule().getId(), artifact.getId())).withRel("download")
|
||||
.expand());
|
||||
}
|
||||
|
||||
@@ -159,10 +168,21 @@ public final class MgmtSoftwareModuleMapper {
|
||||
urls.forEach(entry -> response.add(Link.of(entry.getRef()).withRel(entry.getRel()).expand()));
|
||||
}
|
||||
|
||||
private static SoftwareModuleCreate fromRequest(final EntityFactory entityFactory,
|
||||
private SoftwareModuleManagement.Create fromRequest(
|
||||
final MgmtSoftwareModuleRequestBodyPost smsRest) {
|
||||
return entityFactory.softwareModule().create().type(smsRest.getType()).name(smsRest.getName())
|
||||
.version(smsRest.getVersion()).description(smsRest.getDescription()).vendor(smsRest.getVendor())
|
||||
.encrypted(smsRest.isEncrypted());
|
||||
return SoftwareModuleManagement.Create.builder()
|
||||
.type(getSoftwareModuleTypeFromKeyString(smsRest.getType()))
|
||||
.name(smsRest.getName()).version(smsRest.getVersion()).description(smsRest.getDescription()).vendor(smsRest.getVendor())
|
||||
.encrypted(smsRest.isEncrypted())
|
||||
.build();
|
||||
}
|
||||
|
||||
private SoftwareModuleType getSoftwareModuleTypeFromKeyString(final String type) {
|
||||
if (type == null) {
|
||||
throw new ValidationException("type cannot be null");
|
||||
}
|
||||
|
||||
return softwareModuleTypeManagement.findByKey(type.trim())
|
||||
.orElseThrow(() -> new EntityNotFoundException(SoftwareModuleType.class, type.trim()));
|
||||
}
|
||||
}
|
||||
@@ -21,8 +21,7 @@ import lombok.NoArgsConstructor;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.softwaremoduletype.MgmtSoftwareModuleType;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.softwaremoduletype.MgmtSoftwareModuleTypeRequestBodyPost;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtSoftwareModuleTypeRestApi;
|
||||
import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.builder.SoftwareModuleTypeCreate;
|
||||
import org.eclipse.hawkbit.repository.SoftwareModuleTypeManagement;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
||||
import org.eclipse.hawkbit.rest.json.model.ResponseList;
|
||||
|
||||
@@ -32,16 +31,16 @@ import org.eclipse.hawkbit.rest.json.model.ResponseList;
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public final class MgmtSoftwareModuleTypeMapper {
|
||||
|
||||
public static List<SoftwareModuleTypeCreate> smFromRequest(final EntityFactory entityFactory,
|
||||
public static List<SoftwareModuleTypeManagement.Create> smFromRequest(
|
||||
final Collection<MgmtSoftwareModuleTypeRequestBodyPost> smTypesRest) {
|
||||
if (smTypesRest == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return smTypesRest.stream().map(smRest -> fromRequest(entityFactory, smRest)).toList();
|
||||
return smTypesRest.stream().map(MgmtSoftwareModuleTypeMapper::fromRequest).toList();
|
||||
}
|
||||
|
||||
public static List<MgmtSoftwareModuleType> toTypesResponse(final Collection<SoftwareModuleType> types) {
|
||||
public static List<MgmtSoftwareModuleType> toTypesResponse(final Collection<? extends SoftwareModuleType> types) {
|
||||
if (types == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@@ -62,10 +61,11 @@ public final class MgmtSoftwareModuleTypeMapper {
|
||||
return result;
|
||||
}
|
||||
|
||||
private static SoftwareModuleTypeCreate fromRequest(final EntityFactory entityFactory,
|
||||
final MgmtSoftwareModuleTypeRequestBodyPost smsRest) {
|
||||
return entityFactory.softwareModuleType().create().key(smsRest.getKey()).name(smsRest.getName())
|
||||
private static SoftwareModuleTypeManagement.Create fromRequest(final MgmtSoftwareModuleTypeRequestBodyPost smsRest) {
|
||||
return SoftwareModuleTypeManagement.Create.builder()
|
||||
.key(smsRest.getKey()).name(smsRest.getName())
|
||||
.description(smsRest.getDescription()).colour(smsRest.getColour())
|
||||
.maxAssignments(smsRest.getMaxAssignments());
|
||||
.maxAssignments(smsRest.getMaxAssignments())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -70,7 +70,7 @@ public final class MgmtTagMapper {
|
||||
.expand());
|
||||
}
|
||||
|
||||
public static List<MgmtTag> toResponseDistributionSetTag(final List<DistributionSetTag> distributionSetTags) {
|
||||
public static List<MgmtTag> toResponseDistributionSetTag(final Collection<? extends DistributionSetTag> distributionSetTags) {
|
||||
final List<MgmtTag> tagsRest = new ArrayList<>();
|
||||
if (distributionSetTags == null) {
|
||||
return tagsRest;
|
||||
@@ -106,7 +106,7 @@ public final class MgmtTagMapper {
|
||||
.withRel("assignedDistributionSets").expand());
|
||||
}
|
||||
|
||||
public static List<TagCreate> mapTagFromRequest(final EntityFactory entityFactory, final Collection<MgmtTagRequestBodyPut> tags) {
|
||||
public static List<TagCreate<Tag>> mapTagFromRequest(final EntityFactory entityFactory, final Collection<MgmtTagRequestBodyPut> tags) {
|
||||
return tags.stream()
|
||||
.map(tagRest -> entityFactory.tag().create().name(tagRest.getName())
|
||||
.description(tagRest.getDescription()).colour(tagRest.getColour()))
|
||||
|
||||
Reference in New Issue
Block a user