com.mocean.modules.AbstractClient Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of moceanapisdk Show documentation
Show all versions of moceanapisdk Show documentation
This is an Mocean SDK written in java. To use it you will need a mocean account. Signup for free at
https://moceanapi.com
package com.mocean.modules;
import com.mocean.exception.RequiredFieldException;
import com.mocean.system.auth.AuthInterface;
import com.mocean.utils.Utils;
import java.util.HashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class AbstractClient {
protected HashMap params;
protected String[] requiredFields;
private AuthInterface objAuth;
protected Transmitter transmitter;
public AbstractClient(AuthInterface objAuth, Transmitter transmitter) {
this.objAuth = objAuth;
this.transmitter = transmitter;
this.params = objAuth.getParams();
this.requiredFields = new String[0];
}
protected void isRequiredFieldsSet() throws RequiredFieldException {
for (String value : this.requiredFields) {
if (Utils.isNullOrEmpty(this.params.get(value))) {
throw new RequiredFieldException(value + " is mandatory field, can't be empty.");
}
}
}
protected void createFinalParams() {
HashMap newParams = new HashMap();
Pattern prefixRegex = Pattern.compile("mocean-");
for (String key : this.params.keySet()) {
if (this.params.get(key) != null) {
Matcher prefix = prefixRegex.matcher(key);
if (!prefix.find()) {
newParams.put("mocean-" + key, this.params.get(key));
} else {
newParams.put(key, this.params.get(key));
}
}
}
this.params = newParams;
}
protected AbstractClient create(HashMap params) {
this.params.putAll(params);
return this;
}
protected void reset() {
this.params = this.objAuth.getParams();
}
public HashMap getParams() {
return this.params;
}
}