Java Code Examples for org.springframework.util.MultiValueMap#remove()

The following examples show how to use org.springframework.util.MultiValueMap#remove() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TaskController.java    From taskana with Apache License 2.0 6 votes vote down vote up
private void updateTaskQueryWithWorkbasketKey(
    TaskQuery taskQuery, MultiValueMap<String, String> params) throws InvalidArgumentException {

  String[] domains = null;
  if (params.get(DOMAIN) != null) {
    domains = extractCommaSeparatedFields(params.get(DOMAIN));
  }
  if (domains == null || domains.length != 1) {
    throw new InvalidArgumentException(
        "workbasket-key requires excactly one domain as second parameter.");
  }
  String[] workbasketKeys = extractCommaSeparatedFields(params.get(WORKBASKET_KEY));
  KeyDomain[] keyDomains = new KeyDomain[workbasketKeys.length];
  for (int i = 0; i < workbasketKeys.length; i++) {
    keyDomains[i] = new KeyDomain(workbasketKeys[i], domains[0]);
  }
  taskQuery.workbasketKeyDomainIn(keyDomains);
  params.remove(WORKBASKET_KEY);
  params.remove(DOMAIN);
}
 
Example 2
Source File: IndexedElementsBinder.java    From spring-cloud-gray with Apache License 2.0 6 votes vote down vote up
private void bindIndexed(ConfigurationPropertySource source,
                         ConfigurationPropertyName root, AggregateElementBinder elementBinder,
                         IndexedCollectionSupplier collection, ResolvableType elementType) {
    MultiValueMap<String, ConfigurationProperty> knownIndexedChildren = getKnownIndexedChildren(
            source, root);
    for (int i = 0; i < Integer.MAX_VALUE; i++) {
        ConfigurationPropertyName name = root
                .append((i != 0) ? "[" + i + "]" : INDEX_ZERO);
        Object value = elementBinder.bind(name, Bindable.of(elementType), source);
        if (value == null) {
            break;
        }
        knownIndexedChildren.remove(name.getLastElement(Form.UNIFORM));
        collection.get().add(value);
    }
    assertNoUnboundChildren(knownIndexedChildren);
}
 
Example 3
Source File: WebExchangeDataBinderTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testFieldDefaultPreemptsFieldMarker() throws Exception {
	MultiValueMap<String, String> formData = new LinkedMultiValueMap<>();
	formData.add("!postProcessed", "on");
	formData.add("_postProcessed", "visible");
	formData.add("postProcessed", "on");
	this.binder.bind(exchange(formData)).block(Duration.ofMillis(5000));
	assertTrue(this.testBean.isPostProcessed());

	formData.remove("postProcessed");
	this.binder.bind(exchange(formData)).block(Duration.ofMillis(5000));
	assertTrue(this.testBean.isPostProcessed());

	formData.remove("!postProcessed");
	this.binder.bind(exchange(formData)).block(Duration.ofMillis(5000));
	assertFalse(this.testBean.isPostProcessed());
}
 
Example 4
Source File: WebExchangeDataBinderTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testFieldDefaultNonBoolean() throws Exception {
	MultiValueMap<String, String> formData = new LinkedMultiValueMap<>();
	formData.add("!name", "anonymous");
	formData.add("name", "Scott");
	this.binder.bind(exchange(formData)).block(Duration.ofMillis(5000));
	assertEquals("Scott", this.testBean.getName());

	formData.remove("name");
	this.binder.bind(exchange(formData)).block(Duration.ofMillis(5000));
	assertEquals("anonymous", this.testBean.getName());
}
 
Example 5
Source File: AbstractPagingController.java    From taskana with Apache License 2.0 5 votes vote down vote up
private long getPage(MultiValueMap<String, String> params) throws InvalidArgumentException {
  String param = params.getFirst(PAGING_PAGE);
  params.remove(PAGING_PAGE);
  try {
    return Long.parseLong(param != null ? param : "1");
  } catch (NumberFormatException e) {
    throw new InvalidArgumentException("page must be a integer value.", e.getCause());
  }
}
 
Example 6
Source File: AbstractPagingController.java    From taskana with Apache License 2.0 5 votes vote down vote up
private long getPageSize(MultiValueMap<String, String> params) throws InvalidArgumentException {
  String param = params.getFirst(PAGING_PAGE_SIZE);
  params.remove(PAGING_PAGE_SIZE);
  try {
    return param != null ? Long.parseLong(param) : Integer.MAX_VALUE;
  } catch (NumberFormatException e) {
    throw new InvalidArgumentException("page-size must be a integer value.", e.getCause());
  }
}
 
Example 7
Source File: WorkbasketAccessItemController.java    From taskana with Apache License 2.0 5 votes vote down vote up
private WorkbasketAccessItemQuery applySortingParams(
    WorkbasketAccessItemQuery query, MultiValueMap<String, String> params)
    throws InvalidArgumentException {
  if (LOGGER.isDebugEnabled()) {
    LOGGER.debug("Entry to applySortingParams(query= {}, params= {})", query, params);
  }

  // sorting
  String sortBy = params.getFirst(SORT_BY);
  if (sortBy != null) {
    BaseQuery.SortDirection sortDirection;
    if (params.getFirst(SORT_DIRECTION) != null
        && "desc".equals(params.getFirst(SORT_DIRECTION))) {
      sortDirection = BaseQuery.SortDirection.DESCENDING;
    } else {
      sortDirection = BaseQuery.SortDirection.ASCENDING;
    }
    switch (sortBy) {
      case (WORKBASKET_KEY):
        query = query.orderByWorkbasketKey(sortDirection);
        break;
      case (ACCESS_ID):
        query = query.orderByAccessId(sortDirection);
        break;
      default:
        throw new InvalidArgumentException("Unknown order '" + sortBy + "'");
    }
  }
  params.remove(SORT_BY);
  params.remove(SORT_DIRECTION);
  if (LOGGER.isDebugEnabled()) {
    LOGGER.debug("Exit from applySortingParams(), returning {}", query);
  }

  return query;
}
 
Example 8
Source File: WorkbasketAccessItemController.java    From taskana with Apache License 2.0 5 votes vote down vote up
private void applyFilterParams(
    WorkbasketAccessItemQuery query, MultiValueMap<String, String> params) {
  if (LOGGER.isDebugEnabled()) {
    LOGGER.debug("Entry to applyFilterParams(query= {}, params= {})", query, params);
  }

  if (params.containsKey(WORKBASKET_KEY)) {
    String[] keys = extractCommaSeparatedFields(params.get(WORKBASKET_KEY));
    query.workbasketKeyIn(keys);
    params.remove(WORKBASKET_KEY);
  }
  if (params.containsKey(WORKBASKET_KEY_LIKE)) {
    query.workbasketKeyLike(LIKE + params.get(WORKBASKET_KEY_LIKE).get(0) + LIKE);
    params.remove(WORKBASKET_KEY_LIKE);
  }
  if (params.containsKey(ACCESS_ID)) {
    String[] accessId = extractCommaSeparatedFields(params.get(ACCESS_ID));
    query.accessIdIn(accessId);
    params.remove(ACCESS_ID);
  }
  if (params.containsKey(ACCESS_ID_LIKE)) {
    query.accessIdLike(LIKE + params.get(ACCESS_ID_LIKE).get(0) + LIKE);
    params.remove(ACCESS_ID_LIKE);
  }
  if (LOGGER.isDebugEnabled()) {
    LOGGER.debug("Exit from applyFilterParams(), returning {}", query);
  }
}
 
Example 9
Source File: WorkbasketAccessItemController.java    From taskana with Apache License 2.0 5 votes vote down vote up
private void getAccessIds(WorkbasketAccessItemQuery query, MultiValueMap<String, String> params) {
  if (LOGGER.isDebugEnabled()) {
    LOGGER.debug("Entry to getAccessIds(query= {}, params= {})", query, params);
  }

  if (params.containsKey(ACCESS_IDS)) {
    String[] accessIds = extractVerticalBarSeparatedFields(params.get(ACCESS_IDS));
    query.accessIdIn(accessIds);
    params.remove(ACCESS_IDS);
  }

  if (LOGGER.isDebugEnabled()) {
    LOGGER.debug("Exit from getAccessIds(), returning {}", query);
  }
}
 
Example 10
Source File: WechatOAuth2Template.java    From spring-social-wechat with Apache License 2.0 5 votes vote down vote up
@Override
protected AccessGrant postForAccessGrant(String accessTokenUrl, MultiValueMap<String, String> parameters) {
	if ("authorization_code".equals(parameters.getFirst("grant_type"))) {
		parameters.set("appid", parameters.getFirst("client_id"));
		parameters.remove("client_id");
		parameters.set("secret", parameters.getFirst("client_secret"));
		parameters.remove("client_secret");
	}
	return super.postForAccessGrant(accessTokenUrl, parameters);
}
 
Example 11
Source File: WebExchangeDataBinderTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testFieldPrefixCausesFieldResetWithIgnoreUnknownFields() throws Exception {
	this.binder.setIgnoreUnknownFields(false);

	MultiValueMap<String, String> formData = new LinkedMultiValueMap<>();
	formData.add("_postProcessed", "visible");
	formData.add("postProcessed", "on");
	this.binder.bind(exchange(formData)).block(Duration.ofMillis(5000));
	assertTrue(this.testBean.isPostProcessed());

	formData.remove("postProcessed");
	this.binder.bind(exchange(formData)).block(Duration.ofMillis(5000));
	assertFalse(this.testBean.isPostProcessed());
}
 
Example 12
Source File: WebExchangeDataBinderTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testFieldPrefixCausesFieldReset() throws Exception {
	MultiValueMap<String, String> formData = new LinkedMultiValueMap<>();
	formData.add("_postProcessed", "visible");
	formData.add("postProcessed", "on");
	this.binder.bind(exchange(formData)).block(Duration.ofMillis(5000));
	assertTrue(this.testBean.isPostProcessed());

	formData.remove("postProcessed");
	this.binder.bind(exchange(formData)).block(Duration.ofMillis(5000));
	assertFalse(this.testBean.isPostProcessed());
}
 
Example 13
Source File: RemoveRequestParameterGatewayFilterFactory.java    From spring-cloud-gateway with Apache License 2.0 5 votes vote down vote up
@Override
public GatewayFilter apply(NameConfig config) {
	return new GatewayFilter() {
		@Override
		public Mono<Void> filter(ServerWebExchange exchange,
				GatewayFilterChain chain) {
			ServerHttpRequest request = exchange.getRequest();
			MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<>(
					request.getQueryParams());
			queryParams.remove(config.getName());

			URI newUri = UriComponentsBuilder.fromUri(request.getURI())
					.replaceQueryParams(unmodifiableMultiValueMap(queryParams))
					.build().toUri();

			ServerHttpRequest updatedRequest = exchange.getRequest().mutate()
					.uri(newUri).build();

			return chain.filter(exchange.mutate().request(updatedRequest).build());
		}

		@Override
		public String toString() {
			return filterToStringCreator(
					RemoveRequestParameterGatewayFilterFactory.this)
							.append("name", config.getName()).toString();
		}
	};
}
 
Example 14
Source File: TaskController.java    From taskana with Apache License 2.0 5 votes vote down vote up
private void updateTaskQueryWithIndefiniteTimeInterval(
    TaskQuery taskQuery,
    MultiValueMap<String, String> params,
    String param,
    TimeInterval timeInterval) {

  if (param.equals(PLANNED_FROM) || param.equals(PLANNED_UNTIL)) {
    taskQuery.plannedWithin(timeInterval);

  } else {
    taskQuery.dueWithin(timeInterval);
  }
  params.remove(param);
}
 
Example 15
Source File: WebExchangeDataBinderTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testFieldDefault() throws Exception {
	MultiValueMap<String, String> formData = new LinkedMultiValueMap<>();
	formData.add("!postProcessed", "off");
	formData.add("postProcessed", "on");
	this.binder.bind(exchange(formData)).block(Duration.ofMillis(5000));
	assertTrue(this.testBean.isPostProcessed());

	formData.remove("postProcessed");
	this.binder.bind(exchange(formData)).block(Duration.ofMillis(5000));
	assertFalse(this.testBean.isPostProcessed());
}
 
Example 16
Source File: WebExchangeDataBinderTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testFieldPrefixCausesFieldResetWithIgnoreUnknownFields() throws Exception {
	this.binder.setIgnoreUnknownFields(false);

	MultiValueMap<String, String> formData = new LinkedMultiValueMap<>();
	formData.add("_postProcessed", "visible");
	formData.add("postProcessed", "on");
	this.binder.bind(exchange(formData)).block(Duration.ofMillis(5000));
	assertTrue(this.testBean.isPostProcessed());

	formData.remove("postProcessed");
	this.binder.bind(exchange(formData)).block(Duration.ofMillis(5000));
	assertFalse(this.testBean.isPostProcessed());
}
 
Example 17
Source File: TaskHistoryEventController.java    From taskana with Apache License 2.0 4 votes vote down vote up
private HistoryQuery applySortingParams(HistoryQuery query, MultiValueMap<String, String> params)
    throws InvalidArgumentException {
  if (LOGGER.isDebugEnabled()) {
    LOGGER.debug("Entry to applySortingParams(params= {})", params);
  }

  String sortBy = params.getFirst(SORT_BY);
  if (sortBy != null) {
    BaseQuery.SortDirection sortDirection;
    if (params.getFirst(SORT_DIRECTION) != null
        && "desc".equals(params.getFirst(SORT_DIRECTION))) {
      sortDirection = BaseQuery.SortDirection.DESCENDING;
    } else {
      sortDirection = BaseQuery.SortDirection.ASCENDING;
    }
    switch (sortBy) {
      case (BUSINESS_PROCESS_ID):
        query = query.orderByBusinessProcessId(sortDirection);
        break;
      case (PARENT_BUSINESS_PROCESS_ID):
        query = query.orderByParentBusinessProcessId(sortDirection);
        break;
      case (TASK_ID):
        query = query.orderByTaskId(sortDirection);
        break;
      case (EVENT_TYPE):
        query = query.orderByEventType(sortDirection);
        break;
      case (CREATED):
        query = query.orderByCreated(sortDirection);
        break;
      case (USER_ID):
        query = query.orderByUserId(sortDirection);
        break;
      case (DOMAIN):
        query = query.orderByDomain(sortDirection);
        break;
      case (WORKBASKET_KEY):
        query = query.orderByWorkbasketKey(sortDirection);
        break;
      case (POR_COMPANY):
        query = query.orderByPorCompany(sortDirection);
        break;
      case (POR_SYSTEM):
        query = query.orderByPorSystem(sortDirection);
        break;
      case (POR_INSTANCE):
        query = query.orderByPorInstance(sortDirection);
        break;
      case (POR_TYPE):
        query = query.orderByPorType(sortDirection);
        break;
      case (POR_VALUE):
        query = query.orderByPorValue(sortDirection);
        break;
      case (TASK_CLASSIFICATION_KEY):
        query = query.orderByTaskClassificationKey(sortDirection);
        break;
      case (TASK_CLASSIFICATION_CATEGORY):
        query = query.orderByTaskClassificationCategory(sortDirection);
        break;
      case (ATTACHMENT_CLASSIFICATION_KEY):
        query = query.orderByAttachmentClassificationKey(sortDirection);
        break;
      case (CUSTOM_1):
        query = query.orderByCustomAttribute(1, sortDirection);
        break;
      case (CUSTOM_2):
        query = query.orderByCustomAttribute(2, sortDirection);
        break;
      case (CUSTOM_3):
        query = query.orderByCustomAttribute(3, sortDirection);
        break;
      case (CUSTOM_4):
        query = query.orderByCustomAttribute(4, sortDirection);
        break;
      default:
        throw new IllegalArgumentException("Unknown order '" + sortBy + "'");
    }
  }
  params.remove(SORT_BY);
  params.remove(SORT_DIRECTION);
  if (LOGGER.isDebugEnabled()) {
    LOGGER.debug("Exit from applySortingParams(), returning {}", query);
  }

  return query;
}
 
Example 18
Source File: TaskHistoryEventController.java    From taskana with Apache License 2.0 4 votes vote down vote up
@GetMapping
@Transactional(readOnly = true, rollbackFor = Exception.class)
public ResponseEntity<TaskHistoryEventListResource> getTaskHistoryEvents(
    @RequestParam MultiValueMap<String, String> params) throws InvalidArgumentException {
  if (LOGGER.isDebugEnabled()) {
    LOGGER.debug("Entry to getTaskHistoryEvents(params= {})", params);
  }

  HistoryQuery query = simpleHistoryService.createHistoryQuery();
  query = applySortingParams(query, params);
  applyFilterParams(query, params);

  PageMetadata pageMetadata = null;
  List<HistoryEventImpl> historyEvents;
  final String page = params.getFirst(PAGING_PAGE);
  final String pageSize = params.getFirst(PAGING_PAGE_SIZE);
  params.remove(PAGING_PAGE);
  params.remove(PAGING_PAGE_SIZE);
  validateNoInvalidParameterIsLeft(params);
  if (page != null && pageSize != null) {
    long totalElements = query.count();
    pageMetadata = initPageMetadata(pageSize, page, totalElements);
    historyEvents = query.listPage((int) pageMetadata.getNumber(), (int) pageMetadata.getSize());
  } else if (page == null && pageSize == null) {
    historyEvents = query.list();
  } else {
    throw new InvalidArgumentException("Paging information is incomplete.");
  }

  TaskHistoryEventListResourceAssembler assembler = new TaskHistoryEventListResourceAssembler();
  TaskHistoryEventListResource pagedResources =
      assembler.toResources(historyEvents, pageMetadata);

  if (LOGGER.isDebugEnabled()) {
    LOGGER.debug(
        "Exit from getTaskHistoryEvents(), returning {}",
        new ResponseEntity<>(pagedResources, HttpStatus.OK));
  }

  return new ResponseEntity<>(pagedResources, HttpStatus.OK);
}
 
Example 19
Source File: WorkbasketController.java    From taskana with Apache License 2.0 4 votes vote down vote up
private WorkbasketQuery applySortingParams(
    WorkbasketQuery query, MultiValueMap<String, String> params) throws InvalidArgumentException {
  if (LOGGER.isDebugEnabled()) {
    LOGGER.debug("Entry to applySortingParams(query= {}, params={})", query, params);
  }

  // sorting
  String sortBy = params.getFirst(SORT_BY);
  if (sortBy != null) {
    SortDirection sortDirection;
    if (params.getFirst(SORT_DIRECTION) != null
        && "desc".equals(params.getFirst(SORT_DIRECTION))) {
      sortDirection = SortDirection.DESCENDING;
    } else {
      sortDirection = SortDirection.ASCENDING;
    }
    switch (sortBy) {
      case (NAME):
        query = query.orderByName(sortDirection);
        break;
      case (KEY):
        query = query.orderByKey(sortDirection);
        break;
      case (OWNER):
        query = query.orderByOwner(sortDirection);
        break;
      case (TYPE):
        query = query.orderByType(sortDirection);
        break;
      case (DESCRIPTION):
        query = query.orderByDescription(sortDirection);
        break;
      default:
        throw new InvalidArgumentException("Unknown order '" + sortBy + "'");
    }
  }
  params.remove(SORT_BY);
  params.remove(SORT_DIRECTION);
  if (LOGGER.isDebugEnabled()) {
    LOGGER.debug("Exit from applySortingParams(), returning {}", query);
  }

  return query;
}
 
Example 20
Source File: TaskController.java    From taskana with Apache License 2.0 3 votes vote down vote up
private void updateTaskQueryWithPlannedOrDueTimeIntervals(
    TaskQuery taskQuery, MultiValueMap<String, String> params, String plannedOrDue) {

  String[] instants = extractCommaSeparatedFields(params.get(plannedOrDue));

  TimeInterval[] timeIntervals = extractTimeIntervals(instants);

  taskQuery.plannedWithin(timeIntervals);

  params.remove(plannedOrDue);
}