use of org.wso2.carbon.apimgt.impl.APIAdminImpl in project carbon-apimgt by wso2.
the class SystemScopesApiServiceImpl method systemScopesScopeNameGet.
public Response systemScopesScopeNameGet(String scope, String username, MessageContext messageContext) throws APIManagementException {
ScopeSettingsDTO scopeSettingsDTO = new ScopeSettingsDTO();
APIAdmin apiAdmin = new APIAdminImpl();
String decodedScope = new String(Base64.getDecoder().decode(scope));
boolean existence;
if (username == null) {
existence = apiAdmin.isScopeExists(RestApiCommonUtil.getLoggedInUsername(), decodedScope);
if (existence) {
scopeSettingsDTO.setName(decodedScope);
} else {
throw new APIManagementException("Scope Not Found. Scope : " + decodedScope, ExceptionCodes.SCOPE_NOT_FOUND);
}
} else {
existence = apiAdmin.isScopeExistsForUser(username, decodedScope);
if (existence) {
scopeSettingsDTO.setName(decodedScope);
} else {
throw new APIManagementException("User does not have scope. Username : " + username + " Scope : " + decodedScope, ExceptionCodes.SCOPE_NOT_FOUND_FOR_USER);
}
}
return Response.ok().entity(scopeSettingsDTO).build();
}
use of org.wso2.carbon.apimgt.impl.APIAdminImpl in project carbon-apimgt by wso2.
the class TenantThemeApiServiceImpl method exportTenantTheme.
/**
* Export a Tenant Theme of a particular tenant as an archive file.
*
* @param messageContext
* @return Theme export response
* @throws APIManagementException if an error occurs when importing a tenant theme
*/
@Override
public Response exportTenantTheme(MessageContext messageContext) throws APIManagementException {
String tenantDomain = RestApiCommonUtil.getLoggedInUserTenantDomain();
int tenantId = APIUtil.getTenantIdFromTenantDomain(tenantDomain);
APIAdminImpl apiAdmin = new APIAdminImpl();
if (!apiAdmin.isTenantThemeExist(tenantId)) {
RestApiUtil.handleResourceNotFoundError("Tenant Theme for tenant " + tenantDomain + " does not exist.", log);
}
InputStream tenantTheme = apiAdmin.getTenantTheme(tenantId);
String tempPath = System.getProperty(RestApiConstants.JAVA_IO_TMPDIR) + File.separator + TENANT_THEMES_EXPORT_DIR_PREFIX;
String tempFile = tenantDomain + APIConstants.ZIP_FILE_EXTENSION;
File tenantThemeArchive = new File(tempPath, tempFile);
try {
FileUtils.copyInputStreamToFile(tenantTheme, tenantThemeArchive);
return Response.ok(tenantThemeArchive, MediaType.APPLICATION_OCTET_STREAM).header(RestApiConstants.HEADER_CONTENT_DISPOSITION, "attachment; filename=\"" + tenantThemeArchive.getName() + "\"").build();
} catch (IOException e) {
throw new APIManagementException(e.getMessage(), e, ExceptionCodes.from(ExceptionCodes.TENANT_THEME_EXPORT_FAILED, tenantDomain, e.getMessage()));
}
}
use of org.wso2.carbon.apimgt.impl.APIAdminImpl in project carbon-apimgt by wso2.
the class WorkflowsApiServiceImpl method workflowsExternalWorkflowRefGet.
/**
* This is used to get the workflow pending request according to ExternalWorkflowReference
*
* @param externalWorkflowRef is the unique identifier for workflow request
* @return
*/
@Override
public Response workflowsExternalWorkflowRefGet(String externalWorkflowRef, MessageContext messageContext) throws APIManagementException {
WorkflowInfoDTO workflowinfoDTO;
try {
Workflow workflow;
String status = "CREATED";
String tenantDomain = RestApiCommonUtil.getLoggedInUserTenantDomain();
APIAdmin apiAdmin = new APIAdminImpl();
workflow = apiAdmin.getworkflowReferenceByExternalWorkflowReferenceID(externalWorkflowRef, status, tenantDomain);
workflowinfoDTO = WorkflowMappingUtil.fromWorkflowsToInfoDTO(workflow);
return Response.ok().entity(workflowinfoDTO).build();
} catch (APIManagementException e) {
RestApiUtil.handleInternalServerError("Error while retrieving workflow request by the " + "external workflow reference. ", e, log);
}
return null;
}
use of org.wso2.carbon.apimgt.impl.APIAdminImpl in project carbon-apimgt by wso2.
the class AlertSubscriptionsApiServiceImpl method getBotDetectionAlertSubscriptions.
/**
* Retrieve a list of bot detection alert subscriptions
*
* @param messageContext CXF Message Context
* @return list of bot detection alert subscriptions
* @throws APIManagementException if an error occurs when retrieving bot detection alert subscriptions
*/
@Override
public Response getBotDetectionAlertSubscriptions(MessageContext messageContext) throws APIManagementException {
APIAdmin apiAdmin = new APIAdminImpl();
List<BotDetectionData> botDetectionDataList = apiAdmin.getBotDetectionAlertSubscriptions();
BotDetectionAlertSubscriptionListDTO listDTO = BotDetectionMappingUtil.fromAlertSubscriptionListToListDTO(botDetectionDataList);
return Response.ok().entity(listDTO).build();
}
use of org.wso2.carbon.apimgt.impl.APIAdminImpl in project carbon-apimgt by wso2.
the class AlertSubscriptionsApiServiceImpl method subscribeForBotDetectionAlerts.
/**
* Subscribe for bot detection alerts
*
* @param body email to be registered for the subscription
* @param messageContext CXF Message Context
* @return alert subscription DTO containing the uuid of the subscription and the registered email
* @throws APIManagementException if an error occurs when subscribing for bot detection alerts
*/
@Override
public Response subscribeForBotDetectionAlerts(BotDetectionAlertSubscriptionDTO body, MessageContext messageContext) throws APIManagementException {
String email = body.getEmail();
if (StringUtils.isBlank(email)) {
String propertyName = AlertMgtConstants.BOT_DETECTION_EMAIL_FIELD;
throw new APIManagementException(propertyName + " property value of payload cannot be blank", ExceptionCodes.from(ExceptionCodes.BLANK_PROPERTY_VALUE, propertyName));
}
APIAdmin apiAdmin = new APIAdminImpl();
BotDetectionData alertSubscription = apiAdmin.getBotDetectionAlertSubscription(AlertMgtConstants.BOT_DETECTION_EMAIL_FIELD, email);
if (alertSubscription != null) {
RestApiUtil.handleResourceAlreadyExistsError("Email: " + email + " has already been subscribed for bot detection alerts", log);
}
apiAdmin.addBotDetectionAlertSubscription(email);
BotDetectionData newAlertSubscription = apiAdmin.getBotDetectionAlertSubscription(AlertMgtConstants.BOT_DETECTION_EMAIL_FIELD, email);
BotDetectionAlertSubscriptionDTO alertSubscriptionDTO = BotDetectionMappingUtil.fromAlertSubscriptionToDTO(newAlertSubscription);
return Response.ok(alertSubscriptionDTO).build();
}
Aggregations