use of org.entando.entando.aps.system.services.api.model.ApiService in project entando-core by entando.
the class ApiServiceInterface method getService.
public Object getService(Properties properties) throws ApiException {
Object response = null;
String key = (String) properties.get("key");
try {
ApiService service = this.getApiCatalogManager().getApiService(key);
if (null == service) {
throw new ApiException(IApiErrorCodes.API_SERVICE_INVALID, "Service '" + key + "' does not exist");
}
if (!service.isActive()) {
throw new ApiException(IApiErrorCodes.API_SERVICE_ACTIVE_FALSE, "Service '" + key + "' is not active");
}
this.checkServiceAuthorization(service, properties, true);
Properties serviceParameters = new Properties();
serviceParameters.putAll(service.getParameters());
Iterator<Object> paramIter = properties.keySet().iterator();
List<String> reservedParameters = Arrays.asList(SystemConstants.API_RESERVED_PARAMETERS);
while (paramIter.hasNext()) {
Object paramName = paramIter.next();
String paramNameString = paramName.toString();
if (reservedParameters.contains(paramNameString) || service.isFreeParameter(paramNameString)) {
serviceParameters.put(paramNameString, properties.get(paramName));
}
}
response = this.getResponseBuilder().createResponse(service.getMaster(), serviceParameters);
} catch (ApiException e) {
throw e;
} catch (Throwable t) {
_logger.error("Error invocating service - key '{}'", key, t);
throw new ApiException(IApiErrorCodes.SERVER_ERROR, "Internal error");
}
return response;
}
use of org.entando.entando.aps.system.services.api.model.ApiService in project entando-core by entando.
the class ApiServiceAction method save.
/**
* Save an api service.
*
* @return The result code.
*/
public String save() {
try {
String key = this.getServiceKey().trim();
ApiMethod masterMethod = this.getMethod(this.getNamespace(), this.getResourceName());
String[] freeParams = null;
if (null != this.getFreeParameters()) {
freeParams = new String[this.getFreeParameters().size()];
for (int i = 0; i < this.getFreeParameters().size(); i++) {
freeParams[i] = this.getFreeParameters().get(i);
}
}
ApiService service = new ApiService(key, this.getDescriptions(), masterMethod, this.getApiParameterValues(), freeParams, this.getTag(), !this.isHiddenService(), this.isActiveService());
service.setRequiredAuth(this.getRequiredAuth());
if (null != this.getRequiredGroup() && this.getRequiredGroup().trim().length() > 0) {
service.setRequiredGroup(this.getRequiredGroup());
}
if (null != this.getRequiredPermission() && this.getRequiredPermission().trim().length() > 0) {
service.setRequiredPermission(this.getRequiredPermission());
}
this.getApiCatalogManager().saveService(service);
} catch (Throwable t) {
_logger.error("error in save", t);
return FAILURE;
}
return SUCCESS;
}
use of org.entando.entando.aps.system.services.api.model.ApiService in project entando-core by entando.
the class ApiServiceAction method edit.
/**
* Edit an exist api service.
*
* @return The result code.
*/
public String edit() {
try {
String check = this.checkService();
if (null != check) {
return check;
}
ApiService apiService = this.getApiService(this.getServiceKey());
this.setApiParameters(apiService.getMaster().getParameters());
this.setResourceName(apiService.getMaster().getResourceName());
this.setNamespace(apiService.getMaster().getNamespace());
this.setApiParameterValues(apiService.getParameters());
this.setDescriptions(apiService.getDescription());
this.setHiddenService(apiService.isHidden());
this.setActiveService(apiService.isActive());
// this.setMyEntandoService(apiService.isMyEntando());
this.setServiceKey(apiService.getKey());
if (null != apiService.getFreeParameters()) {
List<String> freeParams = Arrays.asList(apiService.getFreeParameters());
this.setFreeParameters(freeParams);
}
this.setTag(apiService.getTag());
this.setRequiredAuth(apiService.getRequiredAuth());
this.setRequiredGroup(apiService.getRequiredGroup());
this.setRequiredPermission(apiService.getRequiredPermission());
this.setStrutsAction(ApsAdminSystemConstants.EDIT);
} catch (Throwable t) {
_logger.error("error in edit", t);
return FAILURE;
}
return SUCCESS;
}
use of org.entando.entando.aps.system.services.api.model.ApiService in project entando-core by entando.
the class ApiServiceAction method generateResponseBodySchema.
public String generateResponseBodySchema() {
try {
String result = this.checkService();
if (null != result) {
return result;
}
ApiService apiService = this.getApiService(this.getServiceKey());
return super.generateResponseBodySchema(apiService.getMaster());
} catch (Throwable t) {
_logger.error("Error extracting response body Schema", t);
return FAILURE;
}
}
use of org.entando.entando.aps.system.services.api.model.ApiService in project entando-core by entando.
the class ApiServiceFinderAction method buildServiceGroups.
private void buildServiceGroups(Map<String, List<ApiSelectItem>> groups) throws Throwable {
try {
Map<String, ApiService> serviceMap = this.getApiCatalogManager().getServices();
if (null == serviceMap || serviceMap.isEmpty())
return;
Iterator<ApiService> services = serviceMap.values().iterator();
while (services.hasNext()) {
ApiService apiService = services.next();
if (this.includeServiceIntoMapping(apiService)) {
ApiMethod masterMethod = apiService.getMaster();
String pluginCode = masterMethod.getPluginCode();
if (null != pluginCode && pluginCode.trim().length() > 0) {
this.addService(pluginCode, apiService, groups);
} else if (masterMethod.getSource().equals("core")) {
this.addService(masterMethod.getSource(), apiService, groups);
} else {
this.addService("custom", apiService, groups);
}
}
}
} catch (Throwable t) {
_logger.error("error in buildServiceGroups", t);
// ApsSystemUtils.logThrowable(t, this, "buildServiceGroups");
throw t;
}
}
Aggregations