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);
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations