Search in sources :

Example 1 with ApiMethod

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

the class ApiCatalogDAO method buildService.

private void buildService(Map<String, ApiMethod> methods, Map<String, ApiService> services, List<String> invalidServices, ResultSet res) {
    String key = null;
    try {
        key = res.getString(1);
        String parentCode = res.getString(2);
        ApiMethod masterMethod = methods.get(parentCode);
        if (null != masterMethod) {
            ApsProperties description = new ApsProperties();
            description.loadFromXml(res.getString(3));
            ApsProperties parameters = new ApsProperties();
            parameters.loadFromXml(res.getString(4));
            String tag = res.getString(5);
            String[] freeParameters = null;
            String freeParamString = res.getString(6);
            if (null != freeParamString && freeParamString.trim().length() > 0) {
                ServiceExtraConfigDOM dom = new ServiceExtraConfigDOM(freeParamString);
                freeParameters = dom.extractFreeParameters();
            }
            boolean isActive = (1 == res.getInt(7)) ? true : false;
            boolean isHidden = (1 == res.getInt(8)) ? true : false;
            // boolean isMyEntando = (1 == res.getInt(9)) ? true : false;
            ApiService apiService = new ApiService(key, description, masterMethod, parameters, freeParameters, tag, !isHidden, isActive);
            boolean authRequired = (1 == res.getInt(10)) ? true : false;
            apiService.setRequiredAuth(authRequired);
            String requiredPermission = res.getString(11);
            if (null != requiredPermission && requiredPermission.trim().length() > 0) {
                apiService.setRequiredPermission(requiredPermission);
            }
            String requiredGroup = res.getString(12);
            if (null != requiredGroup && requiredGroup.trim().length() > 0) {
                apiService.setRequiredGroup(requiredGroup);
            }
            services.put(key, apiService);
        } else {
            invalidServices.add(key);
        }
    } catch (Throwable t) {
        _logger.error("Error building service - key '{}'", key, t);
    }
}
Also used : ApiService(org.entando.entando.aps.system.services.api.model.ApiService) ApiMethod(org.entando.entando.aps.system.services.api.model.ApiMethod) ApsProperties(com.agiletec.aps.util.ApsProperties)

Example 2 with ApiMethod

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

the class ApiCatalogDAO method loadApiStatus.

@Override
public void loadApiStatus(Map<String, ApiResource> resources) {
    Connection conn = null;
    PreparedStatement stat = null;
    ResultSet res = null;
    try {
        conn = this.getConnection();
        conn.setAutoCommit(false);
        stat = conn.prepareStatement(LOAD_API_STATUS);
        // resourcecode, httpmethod, isactive, authenticationrequired, authorizationrequired
        // "SELECT method, isactive FROM apicatalog_status";
        res = stat.executeQuery();
        while (res.next()) {
            String resourceCode = res.getString("resourcecode");
            String httpMethodString = res.getString("httpmethod");
            ApiMethod.HttpMethod httpMethod = Enum.valueOf(ApiMethod.HttpMethod.class, httpMethodString.toUpperCase());
            ApiMethod method = null;
            ApiResource resource = resources.get(resourceCode);
            if (null != resource) {
                method = resource.getMethod(httpMethod);
            }
            if (null == method) {
                this.resetApiStatus(resourceCode, httpMethod, conn);
                continue;
            }
            boolean active = (res.getInt("isactive") == 1);
            method.setStatus(active);
            boolean authenticationRequired = (res.getInt("authenticationrequired") == 1);
            method.setRequiredAuth(authenticationRequired);
            String requiredPermission = res.getString("authorizationrequired");
            if (null != requiredPermission && requiredPermission.trim().length() > 0) {
                method.setRequiredPermission(requiredPermission);
            } else {
                method.setRequiredPermission(null);
            }
            boolean hidden = (res.getInt("ishidden") == 1);
            method.setHidden(hidden);
        }
        conn.commit();
    } catch (Throwable t) {
        this.executeRollback(conn);
        _logger.error("Error while loading api status", t);
        throw new RuntimeException("Error while loading api status", t);
    } finally {
        closeDaoResources(res, stat, conn);
    }
}
Also used : ApiResource(org.entando.entando.aps.system.services.api.model.ApiResource) ApiMethod(org.entando.entando.aps.system.services.api.model.ApiMethod) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) HttpMethod(org.entando.entando.aps.system.services.api.model.ApiMethod.HttpMethod) PreparedStatement(java.sql.PreparedStatement)

Example 3 with ApiMethod

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

the class ApiCatalogDAO method loadServices.

@Override
public Map<String, ApiService> loadServices(List<ApiMethod> methods) {
    Map<String, ApiMethod> methodMap = new HashMap<String, ApiMethod>();
    for (int i = 0; i < methods.size(); i++) {
        ApiMethod method = methods.get(i);
        String resourceCode = ApiResource.getCode(method.getNamespace(), method.getResourceName());
        methodMap.put(resourceCode, method);
    }
    Map<String, ApiService> services = new HashMap<String, ApiService>();
    Connection conn = null;
    Statement stat = null;
    ResultSet res = null;
    List<String> invalidServices = new ArrayList<String>();
    try {
        conn = this.getConnection();
        stat = conn.createStatement();
        res = stat.executeQuery(LOAD_SERVICES);
        while (res.next()) {
            this.buildService(methodMap, services, invalidServices, res);
        }
    } catch (Throwable t) {
        _logger.error("Error while loading services", t);
        throw new RuntimeException("Error while loading services", t);
    } finally {
        closeDaoResources(res, stat, conn);
    }
    return services;
}
Also used : HashMap(java.util.HashMap) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ApiMethod(org.entando.entando.aps.system.services.api.model.ApiMethod) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) ApiService(org.entando.entando.aps.system.services.api.model.ApiService) ResultSet(java.sql.ResultSet)

Example 4 with ApiMethod

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

the class ApiServiceCacheWrapper method buildApiGetMethods.

protected List<ApiMethod> buildApiGetMethods(Map<String, ApiResource> resources) {
    List<ApiMethod> apiGETMethods = new ArrayList<>();
    List<ApiResource> resourceList = new ArrayList<>(resources.values());
    for (int i = 0; i < resourceList.size(); i++) {
        ApiResource apiResource = resourceList.get(i);
        if (null != apiResource.getGetMethod()) {
            apiGETMethods.add(apiResource.getGetMethod());
        }
    }
    return apiGETMethods;
}
Also used : ApiResource(org.entando.entando.aps.system.services.api.model.ApiResource) ApiMethod(org.entando.entando.aps.system.services.api.model.ApiMethod) ArrayList(java.util.ArrayList)

Example 5 with ApiMethod

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

the class TestApiI18nLabelInterface method testGetLabel.

protected JAXBI18nLabel testGetLabel(MediaType mediaType, String username, String key) throws Throwable {
    ApiResource contentResource = this.getApiCatalogManager().getResource("core", "i18nlabel");
    ApiMethod getMethod = contentResource.getGetMethod();
    Properties properties = super.createApiProperties(username, "en", mediaType);
    properties.put("key", key);
    Object result = this.getResponseBuilder().createResponse(getMethod, properties);
    assertNotNull(result);
    ApiI18nLabelInterface apiLabelInterface = (ApiI18nLabelInterface) this.getApplicationContext().getBean("ApiI18nLabelInterface");
    Object singleResult = apiLabelInterface.getLabel(properties);
    assertNotNull(singleResult);
    String toString = this.marshall(singleResult, mediaType);
    InputStream stream = new ByteArrayInputStream(toString.getBytes());
    JAXBI18nLabel jaxbLabel = (JAXBI18nLabel) UnmarshalUtils.unmarshal(super.getApplicationContext(), JAXBI18nLabel.class, stream, mediaType);
    assertNotNull(jaxbLabel);
    return jaxbLabel;
}
Also used : ApiResource(org.entando.entando.aps.system.services.api.model.ApiResource) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) JAXBI18nLabel(org.entando.entando.aps.system.services.i18n.model.JAXBI18nLabel) ApiMethod(org.entando.entando.aps.system.services.api.model.ApiMethod) Properties(java.util.Properties) ApsProperties(com.agiletec.aps.util.ApsProperties)

Aggregations

ApiMethod (org.entando.entando.aps.system.services.api.model.ApiMethod)40 Properties (java.util.Properties)11 ApiResource (org.entando.entando.aps.system.services.api.model.ApiResource)10 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)9 ApsProperties (com.agiletec.aps.util.ApsProperties)6 StringApiResponse (org.entando.entando.aps.system.services.api.model.StringApiResponse)6 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)5 ApiService (org.entando.entando.aps.system.services.api.model.ApiService)5 Method (java.lang.reflect.Method)4 HashMap (java.util.HashMap)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 ApiMethodRelatedWidget (org.entando.entando.aps.system.services.api.model.ApiMethodRelatedWidget)3 EntitySearchFilter (com.agiletec.aps.system.common.entity.model.EntitySearchFilter)2 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2