Search in sources :

Example 1 with ApiResource

use of org.entando.entando.aps.system.services.api.model.ApiResource 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 2 with ApiResource

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

the class ApiCatalogManager method getResources.

@Override
public Map<String, ApiResource> getResources() throws ApsSystemException {
    Map<String, ApiResource> clonedApiResources = new HashMap<String, ApiResource>();
    try {
        Map<String, ApiResource> resources = this.getResourceCacheWrapper().getMasterResources();
        Iterator<String> iterator = resources.keySet().iterator();
        while (iterator.hasNext()) {
            String resourceFullCode = iterator.next();
            ApiResource resource = resources.get(resourceFullCode);
            clonedApiResources.put(resourceFullCode, resource.clone());
        }
    } catch (Throwable t) {
        logger.error("Error extracting resources", t);
        throw new ApsSystemException("Error extracting resources", t);
    }
    return clonedApiResources;
}
Also used : ApiResource(org.entando.entando.aps.system.services.api.model.ApiResource) HashMap(java.util.HashMap) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 3 with ApiResource

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

the class ApiCatalogManager method getMasterMethod.

protected ApiMethod getMasterMethod(ApiMethod.HttpMethod httpMethod, String namespace, String resourceName) throws ApsSystemException {
    try {
        String resourceCode = ApiResource.getCode(namespace, resourceName);
        ApiResource resource = this.getResourceCacheWrapper().getMasterResource(resourceCode);
        if (null != resource) {
            return resource.getMethod(httpMethod);
        }
    } catch (Throwable t) {
        logger.error("Error extracting methods", t);
        throw new ApsSystemException("Error extracting methods", t);
    }
    return null;
}
Also used : ApiResource(org.entando.entando.aps.system.services.api.model.ApiResource) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 4 with ApiResource

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

the class ApiCatalogManager method getResource.

@Override
public ApiResource getResource(String namespace, String resourceName) throws ApsSystemException {
    try {
        String resourceCode = ApiResource.getCode(namespace, resourceName);
        ApiResource apiResource = this.getResourceCacheWrapper().getMasterResource(resourceCode);
        if (null != apiResource) {
            return apiResource.clone();
        }
    } catch (Throwable t) {
        logger.error("Error extracting resource by name '{}'", resourceName, t);
        throw new ApsSystemException("Error extracting resource", t);
    }
    return null;
}
Also used : ApiResource(org.entando.entando.aps.system.services.api.model.ApiResource) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 5 with ApiResource

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

the class ApiResourcesDefDOM method getResources.

public Map<String, ApiResource> getResources() {
    Map<String, ApiResource> apiResources = new HashMap<String, ApiResource>();
    try {
        List<Element> methodElements = this._doc.getRootElement().getChildren(METHOD_ELEMENT_NAME);
        if (null != methodElements) {
            for (int i = 0; i < methodElements.size(); i++) {
                Element methodElement = methodElements.get(i);
                ApiMethod apiMethod = new ApiMethod(methodElement);
                ApiResource resource = new ApiResource();
                resource.setResourceName(apiMethod.getResourceName());
                resource.setNamespace(apiMethod.getNamespace());
                resource.setDescription(apiMethod.getDescription());
                resource.setPluginCode(apiMethod.getPluginCode());
                resource.setSource(apiMethod.getSource());
                resource.setMethod(apiMethod);
                this.checkResource(resource, apiResources);
            }
        }
        List<Element> resourceElements = this._doc.getRootElement().getChildren(RESOURCE_ELEMENT_NAME);
        if (null != resourceElements) {
            for (int j = 0; j < resourceElements.size(); j++) {
                Element resourceElement = resourceElements.get(j);
                String resourceName = resourceElement.getAttributeValue(RESOURCE_ATTRIBUTE_NAME);
                String namespace = resourceElement.getAttributeValue(RESOURCE_ATTRIBUTE_NAMESPACE);
                Element descriptionElement = resourceElement.getChild(RESOURCE_DESCRIPTION_ELEMENT_NAME);
                String resourceDescription = (null != descriptionElement) ? descriptionElement.getText() : null;
                Element sourceElement = resourceElement.getChild(ApiResourcesDefDOM.SOURCE_ELEMENT_NAME);
                String source = null;
                String pluginCode = null;
                if (null != sourceElement) {
                    source = sourceElement.getText();
                    pluginCode = sourceElement.getAttributeValue(PLUGIN_CODE_ATTRIBUTE_NAME);
                }
                ApiResource resource = new ApiResource();
                resource.setResourceName(resourceName);
                resource.setNamespace(namespace);
                resource.setDescription(resourceDescription);
                resource.setPluginCode(pluginCode);
                resource.setSource(source);
                List<Element> resourceMethodElements = resourceElement.getChildren(METHOD_ELEMENT_NAME);
                for (int k = 0; k < resourceMethodElements.size(); k++) {
                    Element methodElement = resourceMethodElements.get(k);
                    ApiMethod apiMethod = new ApiMethod(resourceName, namespace, source, pluginCode, methodElement);
                    this.checkMethod(apiMethod, resource);
                }
                this.checkResource(resource, apiResources);
            }
        }
    } catch (Throwable t) {
        _logger.error("Error building api resources", t);
    }
    return apiResources;
}
Also used : ApiResource(org.entando.entando.aps.system.services.api.model.ApiResource) HashMap(java.util.HashMap) Element(org.jdom.Element) ApiMethod(org.entando.entando.aps.system.services.api.model.ApiMethod)

Aggregations

ApiResource (org.entando.entando.aps.system.services.api.model.ApiResource)17 ApiMethod (org.entando.entando.aps.system.services.api.model.ApiMethod)8 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)4 Properties (java.util.Properties)4 InputStream (java.io.InputStream)3 HashMap (java.util.HashMap)3 ApsProperties (com.agiletec.aps.util.ApsProperties)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ArrayList (java.util.ArrayList)2 StringApiResponse (org.entando.entando.aps.system.services.api.model.StringApiResponse)2 JAXBI18nLabel (org.entando.entando.aps.system.services.i18n.model.JAXBI18nLabel)2 JAXBContent (org.entando.entando.plugins.jacms.aps.system.services.api.model.JAXBContent)2 EntitySearchFilter (com.agiletec.aps.system.common.entity.model.EntitySearchFilter)1 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)1 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 Date (java.util.Date)1 List (java.util.List)1