/** * Finds {@link DistributionSetType} in repository with given * {@link DistributionSetType#getKey()} or creates if it does not exist yet. * * @param dsTypeKey * {@link DistributionSetType#getKey()} * @param dsTypeName * {@link DistributionSetType#getName()} * @param mandatory * {@link DistributionSetType#getMandatoryModuleTypes()} * @param optional * {@link DistributionSetType#getOptionalModuleTypes()} * * @return persisted {@link DistributionSetType} */ public DistributionSetType findOrCreateDistributionSetType(final String dsTypeKey, final String dsTypeName, final Collection<SoftwareModuleType> mandatory, final Collection<SoftwareModuleType> optional) { return distributionSetTypeManagement.getByKey(dsTypeKey) .orElseGet(() -> distributionSetTypeManagement.create(entityFactory.distributionSetType().create() .key(dsTypeKey).name(dsTypeName).description(LOREM.words(10)).colour("black") .optional(optional.stream().map(SoftwareModuleType::getId).collect(Collectors.toList())) .mandatory(mandatory.stream().map(SoftwareModuleType::getId).collect(Collectors.toList())))); }
@Override public ResponseEntity<PagedList<MgmtDistributionSetType>> getDistributionSetTypes( @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam, @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam, @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam, @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) { final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam); final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam); final Sort sorting = PagingUtility.sanitizeDistributionSetTypeSortParam(sortParam); final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting); final Slice<DistributionSetType> findModuleTypessAll; long countModulesAll; if (rsqlParam != null) { findModuleTypessAll = distributionSetTypeManagement.findByRsql(pageable, rsqlParam); countModulesAll = ((Page<DistributionSetType>) findModuleTypessAll).getTotalElements(); } else { findModuleTypessAll = distributionSetTypeManagement.findAll(pageable); countModulesAll = distributionSetTypeManagement.count(); } final List<MgmtDistributionSetType> rest = MgmtDistributionSetTypeMapper .toListResponse(findModuleTypessAll.getContent()); return ResponseEntity.ok(new PagedList<>(rest, countModulesAll)); }
@Override public ResponseEntity<MgmtDistributionSetType> updateDistributionSetType( @PathVariable("distributionSetTypeId") final Long distributionSetTypeId, @RequestBody final MgmtDistributionSetTypeRequestBodyPut restDistributionSetType) { final DistributionSetType updated = distributionSetTypeManagement.update(entityFactory.distributionSetType() .update(distributionSetTypeId).description(restDistributionSetType.getDescription()) .colour(restDistributionSetType.getColour())); final MgmtDistributionSetType reponse = MgmtDistributionSetTypeMapper.toResponse(updated); MgmtDistributionSetTypeMapper.addLinks(reponse); return ResponseEntity.ok(reponse); }
@Override public ResponseEntity<List<MgmtDistributionSetType>> createDistributionSetTypes( @RequestBody final List<MgmtDistributionSetTypeRequestBodyPost> distributionSetTypes) { final List<DistributionSetType> createdSoftwareModules = distributionSetTypeManagement .create(MgmtDistributionSetTypeMapper.smFromRequest(entityFactory, distributionSetTypes)); return ResponseEntity.status(HttpStatus.CREATED) .body(MgmtDistributionSetTypeMapper.toListResponse(createdSoftwareModules)); }
private DistributionSetType findDistributionSetTypeWithExceptionIfNotFound(final String distributionSetTypekey) { return distributionSetTypeManagement.getByKey(distributionSetTypekey) .orElseThrow(() -> new EntityNotFoundException(DistributionSetType.class, distributionSetTypekey)); }
@Override public int size() { long size = getDistributionSetManagement().count(); if (size > Integer.MAX_VALUE) { size = Integer.MAX_VALUE; } return (int) size; }
private DistributionSetType findDistributionSetTypeWithExceptionIfNotFound(final Long distributionSetTypeId) { return distributionSetTypeManagement.get(distributionSetTypeId) .orElseThrow(() -> new EntityNotFoundException(DistributionSetType.class, distributionSetTypeId)); }
@Override protected void deleteEntity(final String entityToDelete) { final Optional<DistributionSetType> distTypeToDelete = distributionSetTypeManagement.getByName(entityToDelete); distTypeToDelete.ifPresent(tag -> { if (tag.equals(manageDistUIState.getManageDistFilters().getClickedDistSetType())) { uiNotification.displayValidationError(getI18n().getMessage("message.tag.delete", entityToDelete)); removeUpdateAndDeleteColumn(); } else if (isDefaultDsType(entityToDelete)) { uiNotification.displayValidationError(getI18n().getMessage("message.cannot.delete.default.dstype")); removeUpdateAndDeleteColumn(); } else { distributionSetTypeManagement.delete(distTypeToDelete.get().getId()); getEventBus().publish(this, SaveActionWindowEvent.SAVED_DELETE_DIST_SET_TYPES); uiNotification.displaySuccess(getI18n().getMessage("message.delete.success", entityToDelete)); } }); }
@Override protected List<DistributionSetType> loadBeans(final int startIndex, final int count) { return getDistributionSetManagement().findAll(new OffsetBasedPageRequest(startIndex, count, sort)).getContent(); }
@Override public ResponseEntity<Void> deleteDistributionSetType( @PathVariable("distributionSetTypeId") final Long distributionSetTypeId) { distributionSetTypeManagement.delete(distributionSetTypeId); return ResponseEntity.ok().build(); }
@SuppressWarnings("unchecked") private void createNewDistributionSetType() { final String colorPicked = ColorPickerHelper.getColorPickedString(getColorPickerLayout().getSelPreview()); final String typeNameValue = getTagName().getValue(); final String typeKeyValue = getTypeKey().getValue(); final String typeDescValue = getTagDesc().getValue(); final List<Long> itemIds = (List<Long>) getTwinTables().getSelectedTable().getItemIds(); if (typeNameValue != null && typeKeyValue != null && !CollectionUtils.isEmpty(itemIds)) { final List<Long> mandatory = itemIds.stream() .filter(itemId -> DistributionSetTypeSoftwareModuleSelectLayout .isMandatoryModuleType(getTwinTables().getSelectedTable().getItem(itemId))) .collect(Collectors.toList()); final List<Long> optional = itemIds.stream() .filter(itemId -> DistributionSetTypeSoftwareModuleSelectLayout .isOptionalModuleType(getTwinTables().getSelectedTable().getItem(itemId))) .collect(Collectors.toList()); final DistributionSetType newDistType = getDistributionSetTypeManagement() .create(getEntityFactory().distributionSetType().create().key(typeKeyValue).name(typeNameValue) .description(typeDescValue).colour(colorPicked).mandatory(mandatory).optional(optional)); getUiNotification().displaySuccess(getI18n().getMessage("message.save.success", newDistType.getName())); getEventBus().publish(this, new DistributionSetTypeEvent(DistributionSetTypeEnum.ADD_DIST_SET_TYPE, newDistType)); } else { getUiNotification().displayValidationError(getI18n().getMessage("message.error.missing.typenameorkey")); } }
private DistributionSetType findDistributionSetTypeWithExceptionIfNotFound(final String distributionSetTypekey) { return distributionSetTypeManagement.getByKey(distributionSetTypekey) .orElseThrow(() -> new EntityNotFoundException(DistributionSetType.class, distributionSetTypekey)); }
@Override public int size() { long size = getDistributionSetManagement().count(); if (size > Integer.MAX_VALUE) { size = Integer.MAX_VALUE; } return (int) size; }
@Override public void saveOrUpdate() { final String name = distNameTextField.getValue(); final String version = distVersionTextField.getValue(); final Long distSetTypeId = (Long) distsetTypeNameComboBox.getValue(); final String desc = descTextArea.getValue(); final boolean isMigStepReq = reqMigStepCheckbox.getValue(); final DistributionSetType distributionSetType = distributionSetTypeManagement.get(distSetTypeId) .orElseThrow(() -> new EntityNotFoundException(DistributionSetType.class, distSetTypeId)); final DistributionSet newDist = distributionSetManagement .create(entityFactory.distributionSet().create().name(name).version(version).description(desc) .type(distributionSetType).requiredMigrationStep(isMigStepReq)); eventBus.publish(this, new DistributionTableEvent(BaseEntityEventType.ADD_ENTITY, newDist)); notificationMessage.displaySuccess(i18n.getMessage("message.new.dist.save.success", new Object[] { newDist.getName(), newDist.getVersion() })); distributionSetTable.setValue(Sets.newHashSet(newDist.getId())); }
@Override protected void deleteEntity(final String entityToDelete) { final Optional<DistributionSetType> distTypeToDelete = distributionSetTypeManagement.getByName(entityToDelete); distTypeToDelete.ifPresent(tag -> { if (tag.equals(manageDistUIState.getManageDistFilters().getClickedDistSetType())) { uiNotification.displayValidationError(getI18n().getMessage("message.tag.delete", entityToDelete)); removeUpdateAndDeleteColumn(); } else if (isDefaultDsType(entityToDelete)) { uiNotification.displayValidationError(getI18n().getMessage("message.cannot.delete.default.dstype")); removeUpdateAndDeleteColumn(); } else { distributionSetTypeManagement.delete(distTypeToDelete.get().getId()); getEventBus().publish(this, SaveActionWindowEvent.SAVED_DELETE_DIST_SET_TYPES); uiNotification.displaySuccess(getI18n().getMessage("message.delete.success", entityToDelete)); } }); }
@Override protected List<DistributionSetType> loadBeans(final int startIndex, final int count) { return getDistributionSetManagement().findAll(new OffsetBasedPageRequest(startIndex, count, sort)).getContent(); }
/** * Finds {@link DistributionSetType} in repository with given * {@link DistributionSetType#getKey()} or creates if it does not exist yet. * * @param dsTypeKey * {@link DistributionSetType#getKey()} * @param dsTypeName * {@link DistributionSetType#getName()} * @param mandatory * {@link DistributionSetType#getMandatoryModuleTypes()} * @param optional * {@link DistributionSetType#getOptionalModuleTypes()} * * @return persisted {@link DistributionSetType} */ public DistributionSetType findOrCreateDistributionSetType(final String dsTypeKey, final String dsTypeName, final Collection<SoftwareModuleType> mandatory, final Collection<SoftwareModuleType> optional) { return distributionSetTypeManagement.getByKey(dsTypeKey) .orElseGet(() -> distributionSetTypeManagement.create(entityFactory.distributionSetType().create() .key(dsTypeKey).name(dsTypeName).description(LOREM.words(10)).colour("black") .optional(optional.stream().map(SoftwareModuleType::getId).collect(Collectors.toList())) .mandatory(mandatory.stream().map(SoftwareModuleType::getId).collect(Collectors.toList())))); }
@SuppressWarnings("unchecked") private void createNewDistributionSetType() { final String colorPicked = ColorPickerHelper.getColorPickedString(getColorPickerLayout().getSelPreview()); final String typeNameValue = getTagName().getValue(); final String typeKeyValue = getTypeKey().getValue(); final String typeDescValue = getTagDesc().getValue(); final List<Long> itemIds = (List<Long>) getTwinTables().getSelectedTable().getItemIds(); if (typeNameValue != null && typeKeyValue != null && !CollectionUtils.isEmpty(itemIds)) { final List<Long> mandatory = itemIds.stream() .filter(itemId -> DistributionSetTypeSoftwareModuleSelectLayout .isMandatoryModuleType(getTwinTables().getSelectedTable().getItem(itemId))) .collect(Collectors.toList()); final List<Long> optional = itemIds.stream() .filter(itemId -> DistributionSetTypeSoftwareModuleSelectLayout .isOptionalModuleType(getTwinTables().getSelectedTable().getItem(itemId))) .collect(Collectors.toList()); final DistributionSetType newDistType = getDistributionSetTypeManagement() .create(getEntityFactory().distributionSetType().create().key(typeKeyValue).name(typeNameValue) .description(typeDescValue).colour(colorPicked).mandatory(mandatory).optional(optional)); getUiNotification().displaySuccess(getI18n().getMessage("message.save.success", newDistType.getName())); getEventBus().publish(this, new DistributionSetTypeEvent(DistributionSetTypeEnum.ADD_DIST_SET_TYPE, newDistType)); } else { getUiNotification().displayValidationError(getI18n().getMessage("message.error.missing.typenameorkey")); } }
@SuppressWarnings("unchecked") private void updateDistributionSetType(final DistributionSetType existingType) { final List<Long> itemIds = (List<Long>) getTwinTables().getSelectedTable().getItemIds(); final DistributionSetTypeUpdate update = getEntityFactory().distributionSetType().update(existingType.getId()) .description(getTagDesc().getValue()) .colour(ColorPickerHelper.getColorPickedString(getColorPickerLayout().getSelPreview())); if (distributionSetManagement.countByTypeId(existingType.getId()) <= 0 && !CollectionUtils.isEmpty(itemIds)) { update.mandatory(itemIds.stream() .filter(itemId -> DistributionSetTypeSoftwareModuleSelectLayout .isMandatoryModuleType(getTwinTables().getSelectedTable().getItem(itemId))) .collect(Collectors.toList())) .optional(itemIds.stream() .filter(itemId -> DistributionSetTypeSoftwareModuleSelectLayout .isOptionalModuleType(getTwinTables().getSelectedTable().getItem(itemId))) .collect(Collectors.toList())); } final DistributionSetType updateDistSetType = getDistributionSetTypeManagement().update(update); getUiNotification().displaySuccess(getI18n().getMessage("message.update.success", updateDistSetType.getName())); getEventBus().publish(this, new DistributionSetTypeEvent(DistributionSetTypeEnum.UPDATE_DIST_SET_TYPE, updateDistSetType)); }
@Override protected Optional<DistributionSetType> findEntityByKey() { return distributionSetTypeManagement.getByKey(getTypeKey().getValue()); }