Skip to content

Commit

Permalink
Merge pull request #484 from dsulochana/2.4.4-release
Browse files Browse the repository at this point in the history
HUBDEV-2314 : [Location API] : Error when changing the order of query param
  • Loading branch information
jaadds authored Nov 6, 2018
2 parents 7bfa42e + 7bae790 commit 10de4eb
Showing 1 changed file with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ public class ValidateLocation implements IServiceValidate {

static Logger logger = Logger.getLogger(ValidateLocation.class);

private List<String> addresses = new ArrayList<String>();
private double requestAccuracy = 0.0;

/* (non-Javadoc)
* @see com.wso2telco.oneapivalidation.service.IServiceValidate#validate(java.lang.String[])
*/
public void validate(String[] params) throws CustomException {
List<String> addresses = new ArrayList<String>();
double requestAccuracy = 0.0;
boolean foundAddressParam = false;

if (params == null || params.length == 0) {
Expand All @@ -56,13 +57,13 @@ public void validate(String[] params) throws CustomException {
String[] pair = param.split("=");
if (pair.length > 1 && pair[0].equalsIgnoreCase("address")) {
foundAddressParam = true;
addresses.add(pair[1]);
this.addresses.add(pair[1]);
if (logger.isDebugEnabled()) {
logger.debug("Adding MSISDN number to request : " + pair[1]);
}
} else if (pair.length > 1 && pair[0].equalsIgnoreCase("requestedAccuracy")) {
try {
requestAccuracy = Double.parseDouble(pair[1]);
this.requestAccuracy = Double.parseDouble(pair[1]);
if (logger.isDebugEnabled()) {
logger.debug("Adding requestAccuracy to request : " + pair[1]);
}
Expand All @@ -76,7 +77,7 @@ public void validate(String[] params) throws CustomException {
// to address list.
// Future this need a validation logic to identify whether this is a valid MSISDN
if (param != null && !param.isEmpty()) {
addresses.add(param);
this.addresses.add(param);
if (logger.isDebugEnabled()) {
logger.debug("Adding MSISDN number to request : " + param);
}
Expand All @@ -85,19 +86,19 @@ public void validate(String[] params) throws CustomException {
}
}

if (addresses.size() == 0 && requestAccuracy == 0.0) {
if (this.addresses.size() == 0 && this.requestAccuracy == 0.0) {
throw new CustomException("SVC0002", new String[] { "Missing mandatory parameters address and requestedAccuracy" });
} else if (!foundAddressParam || addresses.size() == 0) {
} else if (!foundAddressParam || this.addresses.size() == 0) {
throw new CustomException("SVC0002", new String[] { "Missing mandatory parameter address" });
} else if (requestAccuracy == 0.0) {
} else if (this.requestAccuracy == 0.0) {
throw new CustomException("SVC0002", new String[] { "Missing mandatory parameter requestedAccuracy" });
}

ValidationRule[] rules = {
new ValidationRule(ValidationRule.VALIDATION_TYPE_MANDATORY_TEL, "address",
addresses.toArray(new String[addresses.size()])),
this.addresses.toArray(new String[addresses.size()])),
new ValidationRule(ValidationRule.VALIDATION_TYPE_MANDATORY_LOC_ACCURACY, "requestedAccuracy",
requestAccuracy) };
this.requestAccuracy) };

Validation.checkRequestParams(rules);

Expand Down Expand Up @@ -128,4 +129,15 @@ public void validateUrl(String pathInfo) throws CustomException {

UrlValidator.validateRequest(requestParts, validationRules);
}

/**
* Returns array of MSISDNs
*/
public String[] getMsisdns() {
return this.addresses.toArray(new String[addresses.size()]);
}

public double getRequestAccuracy() {
return requestAccuracy;
}
}

0 comments on commit 10de4eb

Please sign in to comment.