io.yawp.repository.actions.ActionParameters Maven / Gradle / Ivy
package io.yawp.repository.actions;
import io.yawp.commons.utils.JsonUtils;
import io.yawp.commons.utils.ReflectionUtils;
import io.yawp.repository.IdRef;
import io.yawp.repository.models.ObjectModel;
import io.yawp.repository.Repository;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.WildcardType;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ActionParameters {
private enum ParameterType {
ID, PARENT_ID, JSON, PARAMS
}
private Method method;
private Class> endpointClazz;
private List order = new ArrayList<>();
private Map count = new HashMap<>();
private Class> jsonClazz;
private Type jsonGenericType;
public ActionParameters(Method method) throws InvalidActionMethodException {
this.method = method;
setEndpointClazz(method);
init();
if (!isValid()) {
throw new InvalidActionMethodException();
}
}
private void setEndpointClazz(Method method) {
this.endpointClazz = ReflectionUtils.getFeatureEndpointClazz(method.getDeclaringClass());
}
public int size() {
return order.size();
}
public boolean isValid() {
return isRootCollection() || isSingleObject() || isParentCollection();
}
public boolean isOverCollection() {
if (size() == 0) {
return true;
}
if (size() == 1) {
return count(ParameterType.PARENT_ID) == 1 || count(ParameterType.JSON) == 1 || count(ParameterType.PARAMS) == 1;
}
if (size() == 2) {
if (count(ParameterType.PARENT_ID) == 1) {
return count(ParameterType.JSON) == 1 || count(ParameterType.PARAMS) == 1;
}
if (count(ParameterType.JSON) == 1) {
return count(ParameterType.PARENT_ID) == 1 || count(ParameterType.PARAMS) == 1;
}
if (count(ParameterType.PARAMS) == 1) {
return count(ParameterType.PARENT_ID) == 1 || count(ParameterType.JSON) == 1;
}
}
if (size() == 3) {
return count(ParameterType.PARENT_ID) == 1 && count(ParameterType.PARAMS) == 1 && count(ParameterType.JSON) == 1;
}
return false;
}
public Object[] createArguments(Repository r, IdRef> id, String json, Map params) {
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy