Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Jul 14, 2017
1 parent be3f2fd commit bbd4196
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 17 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,20 @@ Changelog of Generic Webhook Plugin.
## Unreleased
### No issue

**Doc**


[bc3eb085bc2543d](https://github.com/jenkinsci/generic-webhook-trigger-plugin/commit/bc3eb085bc2543d) Tomas Bjerre *2017-07-13 19:59:27*


## 1.13 (2017-07-13 19:46:13)
### No issue

**Both exact and "_0" if only one value**

* If request, or header, expression matches only one value then both an exact variable and a variable with added _0 is now contributed. Users who expect only one value will probably expect the exact variable name. Users who expects several will probably want to always use the variableName_X varaibles.

[2ed09abb65eeef5](https://github.com/jenkinsci/generic-webhook-trigger-plugin/commit/2ed09abb65eeef5) Tomas Bjerre *2017-07-13 19:37:12*
[4cc63cc9fc5be42](https://github.com/jenkinsci/generic-webhook-trigger-plugin/commit/4cc63cc9fc5be42) Tomas Bjerre *2017-07-13 19:45:19*

**doc**

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.jenkinsci.plugins.gwt;
package org.jenkinsci.plugins.gwt.resolvers;

public class FlattenerUtils {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.jenkinsci.plugins.gwt.resolvers;

import static com.google.common.collect.Maps.newHashMap;
import static org.jenkinsci.plugins.gwt.FlattenerUtils.filter;
import static org.jenkinsci.plugins.gwt.FlattenerUtils.noWhitespace;
import static org.jenkinsci.plugins.gwt.resolvers.FlattenerUtils.filter;
import static org.jenkinsci.plugins.gwt.resolvers.FlattenerUtils.noWhitespace;

import java.util.List;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import static com.google.common.base.Optional.absent;
import static com.google.common.base.Optional.of;
import static org.jenkinsci.plugins.gwt.FlattenerUtils.filter;
import static org.jenkinsci.plugins.gwt.resolvers.FlattenerUtils.filter;

import java.util.Enumeration;
import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package org.jenkinsci.plugins.gwt.resolvers;

import static com.google.common.base.Optional.absent;
import static com.google.common.base.Optional.fromNullable;
import static com.google.common.collect.Maps.newHashMap;
import static org.jenkinsci.plugins.gwt.FlattenerUtils.filter;
import static org.jenkinsci.plugins.gwt.resolvers.FlattenerUtils.filter;

import java.util.List;
import java.util.Map;
Expand All @@ -21,15 +20,14 @@ public Map<String, String> getRequestParameters(
Map<String, String> resolvedVariables = newHashMap();
if (incomingParameterMap != null) {
for (String requestParamName : incomingParameterMap.keySet()) {
Optional<String> mappedRequestParameterOpt =
findMappedRequestParameter(configuredGenericRequestVariables, requestParamName);
if (!mappedRequestParameterOpt.isPresent()) {
Optional<GenericRequestVariable> configuredVariable =
findConfiguredVariable(configuredGenericRequestVariables, requestParamName);
if (!configuredVariable.isPresent()) {
continue;
}
String regexpFilter = mappedRequestParameterOpt.get();
String[] values = incomingParameterMap.get(requestParamName);
for (int i = 0; i < values.length; i++) {
String filteredValue = filter(values[i], regexpFilter);
String filteredValue = filter(values[i], configuredVariable.get().getRegexpFilter());
resolvedVariables.put(requestParamName + "_" + i, filteredValue);
boolean firstAndOnlyValue = i == 0 && values.length == 1;
if (firstAndOnlyValue) {
Expand All @@ -42,12 +40,12 @@ public Map<String, String> getRequestParameters(
return resolvedVariables;
}

private Optional<String> findMappedRequestParameter(
private Optional<GenericRequestVariable> findConfiguredVariable(
List<GenericRequestVariable> genericRequestVariables, String requestParamName) {
if (genericRequestVariables != null) {
for (GenericRequestVariable v : genericRequestVariables) {
if (v.getKey().equals(requestParamName)) {
return fromNullable(v.getRegexpFilter());
return Optional.of(v);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.jenkinsci.plugins.gwt.resolvers;

import static com.google.common.collect.Maps.newHashMap;
import static org.jenkinsci.plugins.gwt.FlattenerUtils.filter;
import static org.jenkinsci.plugins.gwt.FlattenerUtils.noWhitespace;
import static org.jenkinsci.plugins.gwt.resolvers.FlattenerUtils.filter;
import static org.jenkinsci.plugins.gwt.resolvers.FlattenerUtils.noWhitespace;

import java.util.Map;

Expand All @@ -27,7 +27,7 @@ public Map<String, String> flatternXmlNode(GenericVariable gv, NodeList nodeList
return resolvedVariables;
}

Map<String, String> flattenXmlNode(
private Map<String, String> flattenXmlNode(
String parentKey, String regexFilter, Node node, int level, boolean fromRootLevel) {
Map<String, String> resolvedVariables = newHashMap();
if (isXmlLeafNode(node)) {
Expand Down

0 comments on commit bbd4196

Please sign in to comment.