Search in sources :

Example 1 with HttpMethod

use of org.entando.entando.aps.system.services.api.model.ApiMethod.HttpMethod 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)

Aggregations

Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 ApiMethod (org.entando.entando.aps.system.services.api.model.ApiMethod)1 HttpMethod (org.entando.entando.aps.system.services.api.model.ApiMethod.HttpMethod)1 ApiResource (org.entando.entando.aps.system.services.api.model.ApiResource)1