Search in sources :

Example 1 with ServiceInfo

use of org.entando.entando.aps.system.services.api.model.ServiceInfo 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;
}
Also used : ServiceInfo(org.entando.entando.aps.system.services.api.model.ServiceInfo) ApiMethodParameter(org.entando.entando.aps.system.services.api.model.ApiMethodParameter) ServiceParameterInfo(org.entando.entando.aps.system.services.api.model.ServiceParameterInfo) ApsProperties(com.agiletec.aps.util.ApsProperties)

Example 2 with ServiceInfo

use of org.entando.entando.aps.system.services.api.model.ServiceInfo in project entando-core by entando.

the class ServicesResponseResult method getResult.

@XmlElement(name = "services", required = false)
public ListResponse getResult() {
    if (this.getMainResult() instanceof Collection) {
        List<ServiceInfo> services = new ArrayList<ServiceInfo>();
        services.addAll((Collection<ServiceInfo>) this.getMainResult());
        ListResponse listResponse = new ListResponse(services) {
        };
        return listResponse;
    }
    return null;
}
Also used : ServiceInfo(org.entando.entando.aps.system.services.api.model.ServiceInfo) ListResponse(org.entando.entando.aps.system.services.api.model.ListResponse) ArrayList(java.util.ArrayList) Collection(java.util.Collection) XmlElement(javax.xml.bind.annotation.XmlElement)

Example 3 with ServiceInfo

use of org.entando.entando.aps.system.services.api.model.ServiceInfo in project entando-core by entando.

the class ApiServiceInterface method getServices.

public ArrayList<ServiceInfo> getServices(Properties properties) throws ApiException {
    ArrayList<ServiceInfo> services = new ArrayList<ServiceInfo>();
    try {
        String defaultLangCode = this.getLangManager().getDefaultLang().getCode();
        String langCode = properties.getProperty(SystemConstants.API_LANG_CODE_PARAMETER);
        String tagParamValue = properties.getProperty("tag");
        // String myentandoParamValue = properties.getProperty("myentando");
        // Boolean myentando = (null != myentandoParamValue && myentandoParamValue.trim().length() > 0) ? Boolean.valueOf(myentandoParamValue) : null;
        langCode = (null != langCode && null != this.getLangManager().getLang(langCode)) ? langCode : defaultLangCode;
        Map<String, ApiService> masterServices = this.getApiCatalogManager().getServices(tagParamValue);
        Iterator<ApiService> iter = masterServices.values().iterator();
        while (iter.hasNext()) {
            ApiService service = (ApiService) iter.next();
            if (service.isActive() && !service.isHidden() && this.checkServiceAuthorization(service, properties, false)) {
                ServiceInfo smallService = this.createServiceInfo(service, langCode, defaultLangCode);
                services.add(smallService);
            }
        }
        BeanComparator comparator = new BeanComparator("description");
        Collections.sort(services, comparator);
    } catch (Throwable t) {
        _logger.error("Error extracting services", t);
        throw new ApiException(IApiErrorCodes.SERVER_ERROR, "Internal error");
    }
    return services;
}
Also used : ServiceInfo(org.entando.entando.aps.system.services.api.model.ServiceInfo) ApiService(org.entando.entando.aps.system.services.api.model.ApiService) ArrayList(java.util.ArrayList) BeanComparator(org.apache.commons.beanutils.BeanComparator) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Aggregations

ServiceInfo (org.entando.entando.aps.system.services.api.model.ServiceInfo)3 ArrayList (java.util.ArrayList)2 ApsProperties (com.agiletec.aps.util.ApsProperties)1 Collection (java.util.Collection)1 XmlElement (javax.xml.bind.annotation.XmlElement)1 BeanComparator (org.apache.commons.beanutils.BeanComparator)1 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)1 ApiMethodParameter (org.entando.entando.aps.system.services.api.model.ApiMethodParameter)1 ApiService (org.entando.entando.aps.system.services.api.model.ApiService)1 ListResponse (org.entando.entando.aps.system.services.api.model.ListResponse)1 ServiceParameterInfo (org.entando.entando.aps.system.services.api.model.ServiceParameterInfo)1