private DistributionSet findDistributionSetAndThrowExceptionIfNotFound(final Long setId) { return distributionSetManagement.get(setId) .orElseThrow(() -> new EntityNotFoundException(DistributionSet.class, setId)); } }
protected List<DistributionSetMetadata> createDistributionSetMetadata(final long dsId, final List<MetaData> md) { return distributionSetManagement.createMetaData(dsId, md); }
@Override public ResponseEntity<List<MgmtDistributionSet>> createDistributionSets( @RequestBody final List<MgmtDistributionSetRequestBodyPost> sets) { LOG.debug("creating {} distribution sets", sets.size()); // set default Ds type if ds type is null final String defaultDsKey = systemSecurityContext .runAsSystem(systemManagement.getTenantMetadata().getDefaultDsType()::getKey); sets.stream().filter(ds -> ds.getType() == null).forEach(ds -> ds.setType(defaultDsKey)); final Collection<DistributionSet> createdDSets = distributionSetManagement .create(MgmtDistributionSetMapper.dsFromRequest(sets, entityFactory)); LOG.debug("{} distribution sets created, return status {}", sets.size(), HttpStatus.CREATED); return new ResponseEntity<>(MgmtDistributionSetMapper.toResponseDistributionSets(createdDSets), HttpStatus.CREATED); }
/** * Creates {@link DistributionSet} in repository including three * {@link SoftwareModule}s of types {@link #SM_TYPE_OS}, {@link #SM_TYPE_RT} * , {@link #SM_TYPE_APP}. * * @param prefix * for {@link SoftwareModule}s and {@link DistributionSet}s name, * vendor and description. * @param version * {@link DistributionSet#getVersion()} and * {@link SoftwareModule#getVersion()} extended by a random * number.updat * @param tags * {@link DistributionSet#getTags()} * * @return {@link DistributionSet} entity. */ public DistributionSet createDistributionSet(final String prefix, final String version, final Collection<DistributionSetTag> tags) { final DistributionSet set = createDistributionSet(prefix, version, false); tags.forEach(tag -> distributionSetManagement.toggleTagAssignment(Arrays.asList(set.getId()), tag.getName())); return distributionSetManagement.get(set.getId()).get(); }
/** * Creates {@link DistributionSet}s in repository including three * {@link SoftwareModule}s of types {@link #SM_TYPE_OS}, {@link #SM_TYPE_RT} * , {@link #SM_TYPE_APP} with {@link #DEFAULT_VERSION} followed by an * iterative number and {@link DistributionSet#isRequiredMigrationStep()} * <code>false</code>. * * In addition it updates the created {@link DistributionSet}s and * {@link SoftwareModule}s to ensure that * {@link BaseEntity#getLastModifiedAt()} and * {@link BaseEntity#getLastModifiedBy()} is filled. * * @return persisted {@link DistributionSet}. */ public DistributionSet createUpdatedDistributionSet() { DistributionSet set = createDistributionSet(""); set = distributionSetManagement.update( entityFactory.distributionSet().update(set.getId()).description("Updated " + DEFAULT_DESCRIPTION)); set.getModules().forEach(module -> softwareModuleManagement.update( entityFactory.softwareModule().update(module.getId()).description("Updated " + DEFAULT_DESCRIPTION))); // load also lazy stuff return distributionSetManagement.getWithDetails(set.getId()).get(); }
@Override protected Optional<DistributionSet> findEntityByTableValue(final Long entityTableId) { return distributionSetManagement.getWithDetails(entityTableId); }
@Override public ResponseEntity<MgmtDistributionSet> updateDistributionSet( @PathVariable("distributionSetId") final Long distributionSetId, @RequestBody final MgmtDistributionSetRequestBodyPut toUpdate) { final DistributionSet updated = distributionSetManagement.update(entityFactory.distributionSet() .update(distributionSetId).name(toUpdate.getName()).description(toUpdate.getDescription()) .version(toUpdate.getVersion()).requiredMigrationStep(toUpdate.isRequiredMigrationStep())); final MgmtDistributionSet response = MgmtDistributionSetMapper.toResponse(updated); MgmtDistributionSetMapper.addLinks(updated, response); return ResponseEntity.ok(response); }
private DistributionSetTagAssignmentResult toggleAssignment(final String tagNameSelected) { final DistributionSetTagAssignmentResult result = distributionSetManagement .toggleTagAssignment(Sets.newHashSet(selectedEntity.getId()), tagNameSelected); processTargetTagAssigmentResult(result); uinotification.displaySuccess(HawkbitCommonUtil.createAssignmentMessage(tagNameSelected, result, i18n)); return result; }
@Override public ResponseEntity<Void> deleteDistributionSet(@PathVariable("distributionSetId") final Long distributionSetId) { distributionSetManagement.delete(distributionSetId); return ResponseEntity.ok().build(); }
@Override public ResponseEntity<Void> assignSoftwareModules(@PathVariable("distributionSetId") final Long distributionSetId, @RequestBody final List<MgmtSoftwareModuleAssigment> softwareModuleIDs) { distributionSetManagement.assignSoftwareModules(distributionSetId, softwareModuleIDs.stream().map(MgmtSoftwareModuleAssigment::getId).collect(Collectors.toList())); return ResponseEntity.ok().build(); }
@Override protected void deleteMetadata(final DistributionSet entity, final String key) { distributionSetManagement.deleteMetaData(entity.getId(), key); }
@Override public ResponseEntity<List<MgmtDistributionSet>> assignDistributionSets( @PathVariable("distributionsetTagId") final Long distributionsetTagId, @RequestBody final List<MgmtAssignedDistributionSetRequestBody> assignedDSRequestBodies) { LOG.debug("Assign DistributionSet {} for ds tag {}", assignedDSRequestBodies.size(), distributionsetTagId); final List<DistributionSet> assignedDs = this.distributionSetManagement .assignTag(findDistributionSetIds(assignedDSRequestBodies), distributionsetTagId); LOG.debug("Assignd DistributionSet {}", assignedDs.size()); return ResponseEntity.ok(MgmtDistributionSetMapper.toResponseDistributionSets(assignedDs)); }
/** * Creates {@link DistributionSet} in repository including three * {@link SoftwareModule}s of types {@link #SM_TYPE_OS}, {@link #SM_TYPE_RT} * , {@link #SM_TYPE_APP}. * * @param prefix * for {@link SoftwareModule}s and {@link DistributionSet}s name, * vendor and description. * @param version * {@link DistributionSet#getVersion()} and * {@link SoftwareModule#getVersion()} extended by a random * number.updat * @param tags * {@link DistributionSet#getTags()} * * @return {@link DistributionSet} entity. */ public DistributionSet createDistributionSet(final String prefix, final String version, final Collection<DistributionSetTag> tags) { final DistributionSet set = createDistributionSet(prefix, version, false); tags.forEach(tag -> distributionSetManagement.toggleTagAssignment(Arrays.asList(set.getId()), tag.getName())); return distributionSetManagement.get(set.getId()).get(); }
/** * Creates {@link DistributionSet}s in repository including three * {@link SoftwareModule}s of types {@link #SM_TYPE_OS}, {@link #SM_TYPE_RT} * , {@link #SM_TYPE_APP} with {@link #DEFAULT_VERSION} followed by an * iterative number and {@link DistributionSet#isRequiredMigrationStep()} * <code>false</code>. * * In addition it updates the created {@link DistributionSet}s and * {@link SoftwareModule}s to ensure that * {@link BaseEntity#getLastModifiedAt()} and * {@link BaseEntity#getLastModifiedBy()} is filled. * * @return persisted {@link DistributionSet}. */ public DistributionSet createUpdatedDistributionSet() { DistributionSet set = createDistributionSet(""); set = distributionSetManagement.update( entityFactory.distributionSet().update(set.getId()).description("Updated " + DEFAULT_DESCRIPTION)); set.getModules().forEach(module -> softwareModuleManagement.update( entityFactory.softwareModule().update(module.getId()).description("Updated " + DEFAULT_DESCRIPTION))); // load also lazy stuff return distributionSetManagement.getWithDetails(set.getId()).get(); }
@Override protected Optional<DistributionSet> findEntityByTableValue(final Long lastSelectedId) { return distributionSetManagement.getWithDetails(lastSelectedId); }
protected DistributionSet createDistributionSet() { DistributionSet distributionSet = testdataFactory.createDistributionSet(""); distributionSet = distributionSetManagement.update(entityFactory.distributionSet() .update(distributionSet.getId()).description("The descption of the distribution set.")); distributionSet.getModules().forEach(module -> { final byte[] random = RandomStringUtils.random(5).getBytes(); artifactManagement .create(new ArtifactUpload(new ByteArrayInputStream(random), module.getId(), "file1", false, 0)); softwareModuleManagement.update(entityFactory.softwareModule().update(module.getId()) .description("Description of the software module")); }); return distributionSet; }
private DistributionSetTagAssignmentResult toggleAssignment(final String tagNameSelected) { final DistributionSetTagAssignmentResult result = distributionSetManagement .toggleTagAssignment(Sets.newHashSet(selectedEntity.getId()), tagNameSelected); processTargetTagAssigmentResult(result); uinotification.displaySuccess(HawkbitCommonUtil.createAssignmentMessage(tagNameSelected, result, i18n)); return result; }
@Override protected void handleOkDelete(final List<Long> entitiesToDelete) { distributionSetManagement.delete(entitiesToDelete); getEventBus().publish(this, new DistributionTableEvent(BaseEntityEventType.REMOVE_ENTITY, entitiesToDelete)); getNotification().displaySuccess(getI18n().getMessage("message.delete.success", entitiesToDelete.size() + " " + getI18n().getMessage("distribution.details.header") + "(s)")); managementUIState.getTargetTableFilters().getPinnedDistId() .ifPresent(distId -> unPinDeletedDS(entitiesToDelete, distId)); managementUIState.getSelectedDsIdName().clear(); }
private void saveAllAssignments() { manageDistUIState.getAssignedList().forEach((distIdName, softIdNameSet) -> { final List<Long> softIds = softIdNameSet.stream().map(SoftwareModuleIdName::getId) .collect(Collectors.toList()); distributionSetManagement.assignSoftwareModules(distIdName.getId(), softIds); }); int count = 0; for (final Entry<DistributionSetIdName, Set<SoftwareModuleIdName>> entry : manageDistUIState .getAssignedList().entrySet()) { count += entry.getValue().size(); } getNotification().displaySuccess(getI18n().getMessage("message.software.assignment", count)); resetState(); getEventBus().publish(this, SaveActionWindowEvent.SAVED_ASSIGNMENTS); }
@Override public ResponseEntity<Void> deleteMetadata(@PathVariable("distributionSetId") final Long distributionSetId, @PathVariable("metadataKey") final String metadataKey) { // check if distribution set exists otherwise throw exception // immediately distributionSetManagement.deleteMetaData(distributionSetId, metadataKey); return ResponseEntity.ok().build(); }