use of org.entando.entando.aps.system.services.api.model.ApiMethodParameter in project entando-core by entando.
the class ResponseBuilder method checkParameter.
private void checkParameter(ApiMethod apiMethod, Properties parameters) throws ApiException, Throwable {
try {
List<ApiMethodParameter> apiParameters = apiMethod.getParameters();
if (null == apiParameters || apiParameters.isEmpty()) {
return;
}
List<ApiError> errors = new ArrayList<ApiError>();
for (int i = 0; i < apiParameters.size(); i++) {
ApiMethodParameter apiParam = apiParameters.get(i);
String paramName = apiParam.getKey();
Object value = parameters.get(paramName);
if (apiParam.isRequired() && (null == value || value.toString().trim().length() == 0)) {
errors.add(new ApiError(IApiErrorCodes.API_PARAMETER_REQUIRED, "Parameter '" + paramName + "' is required", Response.Status.BAD_REQUEST));
}
}
if (!errors.isEmpty()) {
throw new ApiException(errors);
}
} catch (ApiException t) {
throw t;
} catch (Throwable t) {
_logger.error("Error checking api parameters", t);
throw new ApsSystemException("Internal Error", t);
}
}
use of org.entando.entando.aps.system.services.api.model.ApiMethodParameter in project entando-core by entando.
the class ApiServiceInterface method createServiceInfo.
protected ServiceInfo createServiceInfo(ApiService service, String langCode, String defaultLangCode) {
String description = service.getDescription().getProperty(langCode);
if (null == description || description.trim().length() == 0) {
description = service.getDescription().getProperty(defaultLangCode);
}
ServiceInfo smallService = new ServiceInfo(service.getKey(), description, service.getTag());
String[] freeParameters = service.getFreeParameters();
if (null != freeParameters && freeParameters.length > 0) {
for (int i = 0; i < freeParameters.length; i++) {
String freeParameter = freeParameters[i];
ApiMethodParameter apiParameter = service.getMaster().getParameter(freeParameter);
if (null != apiParameter) {
ServiceParameterInfo spi = new ServiceParameterInfo(apiParameter);
ApsProperties serviceParameters = service.getParameters();
String defaultValue = (null != serviceParameters) ? serviceParameters.getProperty(freeParameter) : null;
if (null != defaultValue) {
spi.setDefaultValue(defaultValue);
spi.setRequired(false);
}
smallService.addParameter(spi);
}
}
}
return smallService;
}
use of org.entando.entando.aps.system.services.api.model.ApiMethodParameter in project entando-core by entando.
the class ApiServiceAction method checkParameters.
private void checkParameters() {
try {
this.setApiParameterValues(new ApsProperties());
ApiMethod masterMethod = this.getMethod(this.getNamespace(), this.getResourceName());
List<ApiMethodParameter> apiParameters = masterMethod.getParameters();
if (null == apiParameters) {
return;
}
this.extractFreeParameters(apiParameters);
this.setApiParameters(apiParameters);
for (int i = 0; i < apiParameters.size(); i++) {
ApiMethodParameter apiParameter = apiParameters.get(i);
String fieldName = apiParameter.getKey() + "_apiParam";
String value = this.getRequest().getParameter(fieldName);
if (null != value && value.trim().length() > 0) {
this.getApiParameterValues().put(apiParameter.getKey(), value);
}
boolean isFreeParameter = (null != this.getFreeParameters()) ? this.getFreeParameters().contains(apiParameter.getKey()) : false;
if (apiParameter.isRequired() && (null == value || value.trim().length() == 0) && !isFreeParameter) {
this.addFieldError(fieldName, this.getText("error.service.parameter.invalidSetting", new String[] { apiParameter.getKey(), apiParameter.getDescription() }));
}
}
} catch (Throwable t) {
_logger.error("Error checking parameters", t);
throw new RuntimeException("Error checking parameters", t);
}
}
use of org.entando.entando.aps.system.services.api.model.ApiMethodParameter in project entando-core by entando.
the class ApiServiceAction method extractFreeParameters.
private void extractFreeParameters(List<ApiMethodParameter> apiParameters) {
if (null == apiParameters) {
return;
}
for (int i = 0; i < apiParameters.size(); i++) {
ApiMethodParameter apiMethodParameter = apiParameters.get(i);
String requestParamName = "freeParameter_" + apiMethodParameter.getKey();
String value = this.getRequest().getParameter(requestParamName);
if (null != value && Boolean.parseBoolean(value)) {
this.getFreeParameters().add(apiMethodParameter.getKey());
}
}
}
Aggregations