use of org.wso2.carbon.identity.configuration.mgt.core.exception.ConfigurationManagementException in project carbon-identity-framework by wso2.
the class CORSConfigurationDAOImpl method setCORSConfigurationByTenantDomain.
/**
* {@inheritDoc}
*/
@Override
public void setCORSConfigurationByTenantDomain(CORSConfiguration corsConfiguration, String tenantDomain) throws CORSManagementServiceServerException {
try {
FrameworkUtils.startTenantFlow(tenantDomain);
ResourceAdd resourceAdd = new CORSConfigurationToResourceAdd().apply(corsConfiguration);
getConfigurationManager().replaceResource(CORS_CONFIGURATION_RESOURCE_TYPE_NAME, resourceAdd);
} catch (ConfigurationManagementException e) {
throw handleServerException(ERROR_CODE_CORS_CONFIG_SET, e, tenantDomain);
} finally {
FrameworkUtils.endTenantFlow();
}
}
use of org.wso2.carbon.identity.configuration.mgt.core.exception.ConfigurationManagementException in project carbon-identity-framework by wso2.
the class ConfigStoreBasedTemplateHandler method listTemplates.
@Override
public List<Template> listTemplates(String templateType, Integer limit, Integer offset, Condition searchCondition) throws TemplateManagementException {
ConfigurationManager configManager = TemplateManagerDataHolder.getInstance().getConfigurationManager();
try {
Resources resourcesList;
if (searchCondition == null) {
resourcesList = configManager.getResourcesByType(templateType);
} else {
resourcesList = configManager.getTenantResources(searchCondition);
}
return resourcesList.getResources().stream().map(resource -> {
resource.setResourceType(templateType);
return new ResourceToTemplate().apply(resource);
}).collect(Collectors.toList());
} catch (ConfigurationManagementException e) {
if (ConfigurationConstants.ErrorMessages.ERROR_CODE_RESOURCE_TYPE_DOES_NOT_EXISTS.getCode().equals(e.getErrorCode())) {
if (log.isDebugEnabled()) {
log.debug("Template type : '" + templateType + "' has not been created in the database.", e);
}
return Collections.emptyList();
} else if (ConfigurationConstants.ErrorMessages.ERROR_CODE_RESOURCES_DOES_NOT_EXISTS.getCode().equals(e.getErrorCode())) {
if (log.isDebugEnabled()) {
String message = "Templates do not exist for template type: " + templateType;
if (searchCondition != null) {
message = message + ", and search criteria:" + searchCondition.toString();
}
log.debug(message, e);
}
return Collections.emptyList();
}
throw handleServerException(TemplateMgtConstants.ErrorMessages.ERROR_CODE_LIST_TEMPLATES, e, templateType, getTenantDomainFromCarbonContext());
}
}
use of org.wso2.carbon.identity.configuration.mgt.core.exception.ConfigurationManagementException in project carbon-identity-framework by wso2.
the class ConfigStoreBasedTemplateHandler method addTemplateToConfigStore.
private String addTemplateToConfigStore(Template template) throws TemplateManagementException {
if (!isValidTemplateType(template.getTemplateType().toString())) {
throw handleClientException(TemplateMgtConstants.ErrorMessages.ERROR_CODE_INVALID_TEMPLATE_TYPE, template.getTemplateType().toString());
}
ConfigurationManager configManager = TemplateManagerDataHolder.getInstance().getConfigurationManager();
try {
Resource resource = configManager.addResource(template.getTemplateType().toString(), new TemplateToResourceAdd().apply(template));
configManager.addFile(template.getTemplateType().toString(), template.getTemplateName(), template.getTemplateName() + "_template_object", IOUtils.toInputStream(template.getTemplateScript()));
return resource.getResourceId();
} catch (ConfigurationManagementException e) {
if (ConfigurationConstants.ErrorMessages.ERROR_CODE_RESOURCE_ALREADY_EXISTS.getCode().equals(e.getErrorCode())) {
throw handleClientException(TemplateMgtConstants.ErrorMessages.ERROR_CODE_TEMPLATE_ALREADY_EXIST, e, template.getTemplateName());
} else if (ConfigurationConstants.ErrorMessages.ERROR_CODE_RESOURCE_TYPE_DOES_NOT_EXISTS.getCode().equals(e.getErrorCode())) {
// in the database, create the resource-type and retry the template creation.
try {
createResourceType(template.getTemplateType().toString());
return addTemplateToConfigStore(template);
} catch (ConfigurationManagementException e1) {
throw handleServerException(TemplateMgtConstants.ErrorMessages.ERROR_CODE_INSERT_TEMPLATE, e, template.getTemplateName());
}
} else {
throw handleServerException(TemplateMgtConstants.ErrorMessages.ERROR_CODE_INSERT_TEMPLATE, e, template.getTemplateName());
}
}
}
use of org.wso2.carbon.identity.configuration.mgt.core.exception.ConfigurationManagementException in project carbon-identity-framework by wso2.
the class ConfigStoreBasedTemplateHandler method createResourceType.
private void createResourceType(String templateType) throws ConfigurationManagementException {
ConfigurationManager configManager = TemplateManagerDataHolder.getInstance().getConfigurationManager();
ResourceTypeAdd resourceType = new ResourceTypeAdd();
resourceType.setName(templateType);
resourceType.setDescription("This is the resource type for " + templateType);
configManager.addResourceType(resourceType);
}
use of org.wso2.carbon.identity.configuration.mgt.core.exception.ConfigurationManagementException in project carbon-identity-framework by wso2.
the class ConfigurationDAOImpl method getAttributeByKey.
/**
* {@inheritDoc}
*/
@Override
public Attribute getAttributeByKey(String resourceId, String attributeKey) throws ConfigurationManagementException {
JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
try {
return jdbcTemplate.fetchSingleRecord(SQLConstants.GET_ATTRIBUTE_SQL, (resultSet, rowNumber) -> new Attribute(resultSet.getString(DB_SCHEMA_COLUMN_NAME_ATTRIBUTE_KEY), resultSet.getString(DB_SCHEMA_COLUMN_NAME_ATTRIBUTE_VALUE), resultSet.getString(DB_SCHEMA_COLUMN_NAME_ID)), preparedStatement -> {
int initialParameterIndex = 1;
preparedStatement.setString(initialParameterIndex, attributeKey);
preparedStatement.setString(++initialParameterIndex, resourceId);
});
} catch (DataAccessException e) {
throw handleServerException(ERROR_CODE_GET_ATTRIBUTE, attributeKey, e);
}
}
Aggregations