com.identityx.clientSDK.queryHolders.BaseSpec Maven / Gradle / Ivy
/*
* Copyright Daon.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.identityx.clientSDK.queryHolders;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public abstract class BaseSpec {
public Map buildSearchValues() {
HashMap result = new HashMap();
Method[] methods = this.getClass().getDeclaredMethods();
Object value;
for (int i = 0; i < methods.length; i++) {
try {
String methodName = methods[i].getName();
if (methodName.startsWith("get") && methodName.length() > 3) {
value = methods[i].invoke(this, null);
if (value != null) {
String fieldName = methodName.substring(3, 4).toLowerCase();
if (methodName.length() > 4) {
fieldName = fieldName + methodName.substring(4, methodName.length());
}
// Special for querying on multiple status values
// Value is array of enum, want to turn into comma-delimited string
if (fieldName.equals("statuses")) {
fieldName = "status";
List values = (List) value;
String statuses = null;
for (Object val : values) {
statuses = statuses == null ? val.toString() : statuses + "," + val.toString();
}
result.put(fieldName, statuses);
}
else {
result.put(fieldName, value.toString());
}
}
}
}
catch (IllegalAccessException e) {
} catch (IllegalArgumentException e) {
} catch (InvocationTargetException e) {
}
}
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy