use of org.wso2.carbon.identity.template.mgt.exception.TemplateManagementException in project product-is by wso2.
the class TemplateManagementServiceClient method addTemplate.
public Template addTemplate(TemplateRequestDTO templateRequestDTO) throws TemplateManagementException {
handleLoggedInUserAuthorization(TemplateMgtConstants.PERMISSION_TEMPLATE_MGT_ADD);
Template template = new Template(templateRequestDTO.getTenantId(), templateRequestDTO.getTemplateName(), templateRequestDTO.getDescription(), templateRequestDTO.getTemplateScript());
return getTemplateManager().addTemplateUsingTemplateMgtDAO(template);
}
use of org.wso2.carbon.identity.template.mgt.exception.TemplateManagementException in project identity-api-server by wso2.
the class ServerIdpManagementService method deleteIDPTemplate.
/**
* Delete a IDP template identified by resource Id.
*
* @param templateId Id of the IDP template
*/
public void deleteIDPTemplate(String templateId) {
try {
TemplateManager templateManager = IdentityProviderServiceHolder.getTemplateManager();
templateManager.deleteTemplateById(templateId);
} catch (TemplateManagementException e) {
throw handleTemplateMgtException(e, Constants.ErrorMessage.ERROR_CODE_ERROR_DELETING_IDP_TEMPLATE, templateId);
}
}
use of org.wso2.carbon.identity.template.mgt.exception.TemplateManagementException in project identity-api-server by wso2.
the class ServerIdpManagementService method createIDPTemplate.
/**
* Create a new IDP template.
*
* @param identityProviderTemplate identityProviderTemplatePOSTRequest
* @return IdentityProviderTemplateResponse
*/
public String createIDPTemplate(IdentityProviderTemplate identityProviderTemplate) {
try {
TemplateManager templateManager = IdentityProviderServiceHolder.getTemplateManager();
Template idpTemplate = generateIDPTemplate(identityProviderTemplate);
return templateManager.addTemplate(idpTemplate);
} catch (TemplateManagementException e) {
throw handleTemplateMgtException(e, Constants.ErrorMessage.ERROR_CODE_ERROR_ADDING_IDP_TEMPLATE, null);
} catch (JsonProcessingException e) {
throw handleException(Response.Status.BAD_REQUEST, Constants.ErrorMessage.ERROR_CODE_ERROR_ADDING_IDP_TEMPLATE, null);
}
}
use of org.wso2.carbon.identity.template.mgt.exception.TemplateManagementException in project identity-api-server by wso2.
the class ServerIdpManagementService method handleTemplateMgtException.
/**
* Handle template management exceptions and return related API errors.
*
* @param e {@link TemplateManagementException}.
* @param errorEnum Error message with error code and description.
* @param data Additional information.
* @return API error.
*/
private APIError handleTemplateMgtException(TemplateManagementException e, Constants.ErrorMessage errorEnum, String data) {
ErrorResponse errorResponse;
Response.Status status;
if (e instanceof TemplateManagementClientException) {
if (e.getErrorCode() != null) {
String errorCode = e.getErrorCode();
errorResponse = getErrorBuilder(errorCode, e.getMessage(), data).build(log, e.getMessage());
errorCode = errorCode.contains(TEMPLATE_MGT_ERROR_CODE_DELIMITER) ? errorCode : Constants.IDP_MANAGEMENT_PREFIX + errorCode;
errorResponse.setCode(errorCode);
} else {
errorResponse = getErrorBuilder(errorEnum, data).build(log, e.getMessage());
}
errorResponse.setDescription(e.getMessage());
status = Response.Status.BAD_REQUEST;
} else if (e instanceof TemplateManagementServerException) {
if (e.getErrorCode() != null) {
String errorCode = e.getErrorCode();
errorResponse = getErrorBuilder(errorCode, e.getMessage(), data).build(log, e, includeData(e.getMessage(), data));
errorCode = errorCode.contains(TEMPLATE_MGT_ERROR_CODE_DELIMITER) ? errorCode : Constants.IDP_MANAGEMENT_PREFIX + errorCode;
errorResponse.setCode(errorCode);
} else {
errorResponse = getErrorBuilder(errorEnum, data).build(log, e, includeData(e.getMessage(), data));
}
errorResponse.setDescription(e.getMessage());
status = Response.Status.INTERNAL_SERVER_ERROR;
} else {
if (e.getErrorCode() != null) {
errorResponse = getErrorBuilder(e.getErrorCode(), e.getMessage(), data).build(log, e, includeData(e.getMessage(), data));
} else {
errorResponse = getErrorBuilder(errorEnum, data).build(log, e, includeData(e.getMessage(), data));
}
status = Response.Status.INTERNAL_SERVER_ERROR;
}
return new APIError(status, errorResponse);
}
use of org.wso2.carbon.identity.template.mgt.exception.TemplateManagementException in project carbon-identity-framework by wso2.
the class TemplateManagerImpl method listTemplates.
@Override
public List<Template> listTemplates(String templateType, Integer limit, Integer offset, Condition searchCondition) throws TemplateManagementException {
if (!isValidTemplateType(templateType)) {
throw handleClientException(TemplateMgtConstants.ErrorMessages.ERROR_CODE_INVALID_TEMPLATE_TYPE, templateType);
}
if (limit != null || offset != null) {
throw handleClientException(TemplateMgtConstants.ErrorMessages.ERROR_CODE_PAGINATION_NOT_SUPPORTED, null);
}
List<Template> templates = new ArrayList<>();
List<ReadOnlyTemplateHandler> readOnlyTemplateHandlers = TemplateManagerDataHolder.getInstance().getReadOnlyTemplateHandlers();
for (ReadOnlyTemplateHandler readOnlyTemplateHandler : readOnlyTemplateHandlers) {
templates.addAll(readOnlyTemplateHandler.listTemplates(templateType, limit, offset, searchCondition));
}
templates.addAll(configStoreBasedTemplateHandler.listTemplates(templateType, limit, offset, searchCondition));
return templates;
}
Aggregations