use of io.micronaut.data.annotation.AutoPopulated in project micronaut-data by micronaut-projects.
the class SourceParameterExpressionImpl method bind.
@Override
public QueryParameterBinding bind(BindingContext bindingContext) {
String bindName;
if (bindingContext.getName() == null) {
bindName = String.valueOf(bindingContext.getIndex());
} else {
bindName = bindingContext.getName();
}
PersistentPropertyPath incomingMethodParameterProperty = bindingContext.getIncomingMethodParameterProperty();
PersistentPropertyPath outgoingQueryParameterProperty = bindingContext.getOutgoingQueryParameterProperty();
PersistentPropertyPath propertyPath = outgoingQueryParameterProperty == null ? incomingMethodParameterProperty : outgoingQueryParameterProperty;
if (propertyPath == null) {
Objects.requireNonNull(parameterElement);
int index = Arrays.asList(parameters).indexOf(parameterElement);
DataType dataType = getDataType(null, parameterElement);
String converter = parameterElement.stringValue(TypeDef.class, "converter").orElse(null);
boolean isExpandable = isExpandable(bindingContext, dataType);
return new QueryParameterBinding() {
@Override
public String getKey() {
return bindName;
}
@Override
public int getParameterIndex() {
return index;
}
@Override
public DataType getDataType() {
return dataType;
}
@Override
public String getConverterClassName() {
return converter;
}
@Override
public boolean isExpandable() {
return isExpandable;
}
};
}
if (outgoingQueryParameterProperty == null) {
throw new IllegalStateException("Outgoing query parameter property is required!");
}
boolean autopopulated = propertyPath.getProperty().findAnnotation(AutoPopulated.class).map(ap -> ap.getRequiredValue(AutoPopulated.UPDATEABLE, Boolean.class)).orElse(false);
DataType dataType = getDataType(propertyPath, parameterElement);
String converterClassName = ((SourcePersistentProperty) propertyPath.getProperty()).getConverterClassName();
int index = parameterElement == null || isEntityParameter ? -1 : Arrays.asList(parameters).indexOf(parameterElement);
String[] path = asStringPath(outgoingQueryParameterProperty.getAssociations(), outgoingQueryParameterProperty.getProperty());
String[] parameterBindingPath = index != -1 ? getBindingPath(incomingMethodParameterProperty, outgoingQueryParameterProperty) : null;
boolean requiresPrevValue = index == -1 && autopopulated && !isUpdate;
boolean isExpandable = isExpandable(bindingContext, dataType);
return new QueryParameterBinding() {
@Override
public String getKey() {
return bindName;
}
@Override
public DataType getDataType() {
return dataType;
}
@Override
public String getConverterClassName() {
return converterClassName;
}
@Override
public int getParameterIndex() {
return index;
}
@Override
public String[] getParameterBindingPath() {
return parameterBindingPath;
}
@Override
public String[] getPropertyPath() {
return path;
}
@Override
public boolean isAutoPopulated() {
return autopopulated;
}
@Override
public boolean isRequiresPreviousPopulatedValue() {
return requiresPrevValue;
}
@Override
public boolean isExpandable() {
return isExpandable;
}
};
}
Aggregations