All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.identityx.clientSDK.queryHolders.BaseSpec Maven / Gradle / Ivy

There is a newer version: 5.6.0.2
Show newest version
/*
* 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 or policy type 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 if (fieldName.equals("types")) {
							fieldName = "type";
							List values = (List) value;
							String types = null;
							for (Object val : values) {
								types = types == null ? val.toString() : types + "," + val.toString();
							}
							result.put(fieldName, types);
						}
						else {
							result.put(fieldName, value.toString());
						}
					}
				}
			}
			catch (IllegalAccessException e) {
			} catch (IllegalArgumentException e) {
			} catch (InvocationTargetException e) {
			}
		} 

		return result;
	}
	
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy