@Override public ResponseEntity<List<MgmtTag>> createDistributionSetTags( @RequestBody final List<MgmtTagRequestBodyPut> tags) { LOG.debug("creating {} ds tags", tags.size()); final List<DistributionSetTag> createdTags = distributionSetTagManagement .create(MgmtTagMapper.mapTagFromRequest(entityFactory, tags)); return new ResponseEntity<>(MgmtTagMapper.toResponseDistributionSetTag(createdTags), HttpStatus.CREATED); }
@Override public ResponseEntity<PagedList<MgmtTag>> getDistributionSetTags( @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.sanitizeTagSortParam(sortParam); final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting); final Slice<DistributionSetTag> distributionSetTags; final long count; if (rsqlParam == null) { distributionSetTags = distributionSetTagManagement.findAll(pageable); count = distributionSetTagManagement.count(); } else { final Page<DistributionSetTag> page = distributionSetTagManagement.findByRsql(pageable, rsqlParam); distributionSetTags = page; count = page.getTotalElements(); } final List<MgmtTag> rest = MgmtTagMapper.toResponseDistributionSetTag(distributionSetTags.getContent()); return ResponseEntity.ok(new PagedList<>(rest, count)); }
@Override public ResponseEntity<Void> deleteDistributionSetTag( @PathVariable("distributionsetTagId") final Long distributionsetTagId) { LOG.debug("Delete {} distribution set tag", distributionsetTagId); final DistributionSetTag tag = findDistributionTagById(distributionsetTagId); distributionSetTagManagement.delete(tag.getName()); return ResponseEntity.ok().build(); }
private DistributionSetTag createDistributionSetTag() { final DistributionSetTag updateTag = distributionSetTagManagement .create(entityFactory.tag().create().name("DsTag")); return distributionSetTagManagement.update(entityFactory.tag().update(updateTag.getId()) .description("My name is " + updateTag.getName()).colour("default")); }
@Override protected void deleteEntity(final String entityToDelete) { final Optional<DistributionSetTag> tagToDelete = distributionSetTagManagement.getByName(entityToDelete); tagToDelete.ifPresent(tag -> { if (managementUIState.getDistributionTableFilters().getDistSetTags().contains(entityToDelete)) { uiNotification.displayValidationError(getI18n().getMessage("message.tag.delete", entityToDelete)); removeUpdateAndDeleteColumn(); } else { distributionSetTagManagement.delete(entityToDelete); getEventBus().publish(this, new DistributionSetTagTableEvent(BaseEntityEventType.REMOVE_ENTITY, tag)); uiNotification.displaySuccess(getI18n().getMessage("message.delete.success", entityToDelete)); } }); } }
@Override public ResponseEntity<MgmtTag> updateDistributionSetTag( @PathVariable("distributionsetTagId") final Long distributionsetTagId, @RequestBody final MgmtTagRequestBodyPut restDSTagRest) { final DistributionSetTag distributionSetTag = distributionSetTagManagement .update(entityFactory.tag().update(distributionsetTagId).name(restDSTagRest.getName()) .description(restDSTagRest.getDescription()).colour(restDSTagRest.getColour())); final MgmtTag response = MgmtTagMapper.toResponse(distributionSetTag); MgmtTagMapper.addLinks(distributionSetTag, response); return ResponseEntity.ok(response); }
@Override protected Optional<DistributionSetTag> findEntityByName() { return distributionSetTagManagement.getByName(getTagName().getValue()); }
private DistributionSetTag findDistributionTagById(final Long distributionsetTagId) { return distributionSetTagManagement.get(distributionsetTagId) .orElseThrow(() -> new EntityNotFoundException(DistributionSetTag.class, distributionsetTagId)); }
@Override protected void populateContainer() { container.removeAllItems(); tagDetails.clear(); distributionSetTagManagement.findAll(new PageRequest(0, MAX_TAG_QUERY)).getContent().stream() .forEach(tag -> setContainerPropertValues(tag.getId(), tag.getName(), tag.getColour())); }
@Override public int size() { long size = getTagManagement().count(); if (size > Integer.MAX_VALUE) { size = Integer.MAX_VALUE; } return (int) size; }
@Override protected void deleteEntity(final String entityToDelete) { final Optional<DistributionSetTag> tagToDelete = distributionSetTagManagement.getByName(entityToDelete); tagToDelete.ifPresent(tag -> { if (managementUIState.getDistributionTableFilters().getDistSetTags().contains(entityToDelete)) { uiNotification.displayValidationError(getI18n().getMessage("message.tag.delete", entityToDelete)); removeUpdateAndDeleteColumn(); } else { distributionSetTagManagement.delete(entityToDelete); getEventBus().publish(this, new DistributionSetTagTableEvent(BaseEntityEventType.REMOVE_ENTITY, tag)); uiNotification.displaySuccess(getI18n().getMessage("message.delete.success", entityToDelete)); } }); } }
private void updateExistingTag(final Tag targetObj) { final TagUpdate update = getEntityFactory().tag().update(targetObj.getId()).name(getTagName().getValue()) .description(getTagDesc().getValue()) .colour(ColorPickerHelper.getColorPickedString(getColorPickerLayout().getSelPreview())); getDistributionSetTagManagement().update(update); getEventBus().publish(this, new DistributionSetTagTableEvent(BaseEntityEventType.UPDATED_ENTITY, (DistributionSetTag) targetObj)); getUiNotification().displaySuccess(getI18n().getMessage("message.update.success", targetObj.getName())); }
@Override protected Optional<DistributionSetTag> findEntityByName() { return distributionSetTagManagement.getByName(getTagName().getValue()); }
@Override @Transactional @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) public List<DistributionSet> assignTag(final Collection<Long> dsIds, final long dsTagId) { final List<JpaDistributionSet> allDs = findDistributionSetListWithDetails(dsIds); if (allDs.size() < dsIds.size()) { throw new EntityNotFoundException(DistributionSet.class, dsIds, allDs.stream().map(DistributionSet::getId).collect(Collectors.toList())); } final DistributionSetTag distributionSetTag = distributionSetTagManagement.get(dsTagId) .orElseThrow(() -> new EntityNotFoundException(DistributionSetTag.class, dsTagId)); allDs.forEach(ds -> ds.addTag(distributionSetTag)); final List<DistributionSet> result = Collections .unmodifiableList(allDs.stream().map(distributionSetRepository::save).collect(Collectors.toList())); // No reason to save the tag entityManager.detach(distributionSetTag); return result; }
@Override protected void populateContainer() { container.removeAllItems(); tagDetails.clear(); distributionSetTagManagement.findAll(PageRequest.of(0, MAX_TAG_QUERY)).getContent().stream() .forEach(tag -> setContainerPropertValues(tag.getId(), tag.getName(), tag.getColour())); }
@Override public int size() { long size = getTagManagement().count(); if (size > Integer.MAX_VALUE) { size = Integer.MAX_VALUE; } return (int) size; }
/** * Creates {@link DistributionSetTag}s in repository. * * @param number * of {@link DistributionSetTag}s * * @return the persisted {@link DistributionSetTag}s */ public List<DistributionSetTag> createDistributionSetTags(final int number) { final List<TagCreate> result = Lists.newArrayListWithExpectedSize(number); for (int i = 0; i < number; i++) { result.add( entityFactory.tag().create().name("tag" + i).description("tagdesc" + i).colour(String.valueOf(i))); } return distributionSetTagManagement.create(result); }
private void updateExistingTag(final Tag targetObj) { final TagUpdate update = getEntityFactory().tag().update(targetObj.getId()).name(getTagName().getValue()) .description(getTagDesc().getValue()) .colour(ColorPickerHelper.getColorPickedString(getColorPickerLayout().getSelPreview())); getDistributionSetTagManagement().update(update); getEventBus().publish(this, new DistributionSetTagTableEvent(BaseEntityEventType.UPDATED_ENTITY, (DistributionSetTag) targetObj)); getUiNotification().displaySuccess(getI18n().getMessage("message.update.success", targetObj.getName())); }
final DistributionSetTag myTag = distributionSetTagManagement.getByName(tagName) .orElseThrow(() -> new EntityNotFoundException(DistributionSetTag.class, tagName));
@Override @Transactional @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) public List<DistributionSet> assignTag(final Collection<Long> dsIds, final long dsTagId) { final List<JpaDistributionSet> allDs = findDistributionSetListWithDetails(dsIds); if (allDs.size() < dsIds.size()) { throw new EntityNotFoundException(DistributionSet.class, dsIds, allDs.stream().map(DistributionSet::getId).collect(Collectors.toList())); } final DistributionSetTag distributionSetTag = distributionSetTagManagement.get(dsTagId) .orElseThrow(() -> new EntityNotFoundException(DistributionSetTag.class, dsTagId)); allDs.forEach(ds -> ds.addTag(distributionSetTag)); final List<DistributionSet> result = Collections .unmodifiableList(allDs.stream().map(distributionSetRepository::save).collect(Collectors.toList())); // No reason to save the tag entityManager.detach(distributionSetTag); return result; }