use of org.wso2.carbon.apimgt.api.APIAdmin in project carbon-apimgt by wso2.
the class DefaultMonetizationImpl method publishMonetizationUsageRecords.
/**
* Update info about monetization usage publish job
*
* @param monetizationUsagePublishInfo
* @return boolean always return true if there is no exception
* @throws MonetizationException
*/
@Override
public boolean publishMonetizationUsageRecords(MonetizationUsagePublishInfo monetizationUsagePublishInfo) throws MonetizationException {
APIAdmin apiAdmin = new APIAdminImpl();
monetizationUsagePublishInfo.setState(APIConstants.Monetization.COMPLETED);
monetizationUsagePublishInfo.setStatus(APIConstants.Monetization.SUCCESSFULL);
DateFormat df = new SimpleDateFormat(APIConstants.Monetization.USAGE_PUBLISH_TIME_FORMAT);
Date dateobj = new Date();
// get the time in UTC format
df.setTimeZone(TimeZone.getTimeZone(APIConstants.Monetization.USAGE_PUBLISH_TIME_ZONE));
String currentDate = df.format(dateobj);
long currentTimestamp = apiAdmin.getTimestamp(currentDate);
monetizationUsagePublishInfo.setLastPublishTime(currentTimestamp);
try {
apiAdmin.updateMonetizationUsagePublishInfo(monetizationUsagePublishInfo);
} catch (APIManagementException e) {
throw new MonetizationException("Failed to update the monetization usage publish info", e);
}
return true;
}
use of org.wso2.carbon.apimgt.api.APIAdmin in project carbon-apimgt by wso2.
the class MonetizationUsagePublishAgent method run.
@Override
public void run() {
Monetization monetizationImpl = null;
APIAdmin apiAdmin = null;
try {
apiAdmin = new APIAdminImpl();
monetizationImpl = apiAdmin.getMonetizationImplClass();
monetizationUsagePublishInfo.setState(APIConstants.Monetization.RUNNING);
monetizationUsagePublishInfo.setStatus(APIConstants.Monetization.INPROGRESS);
DateFormat df = new SimpleDateFormat(APIConstants.Monetization.USAGE_PUBLISH_TIME_FORMAT);
Date dateobj = new Date();
df.setTimeZone(TimeZone.getTimeZone(APIConstants.Monetization.USAGE_PUBLISH_TIME_ZONE));
String currentDate = df.format(dateobj);
long currentTimestamp = apiAdmin.getTimestamp(currentDate);
// set the current time as starting time of the job
monetizationUsagePublishInfo.setStartedTime(currentTimestamp);
apiAdmin.updateMonetizationUsagePublishInfo(monetizationUsagePublishInfo);
monetizationImpl.publishMonetizationUsageRecords(monetizationUsagePublishInfo);
} catch (Exception e) {
try {
// update the state and status of the job incase of any execptions
monetizationUsagePublishInfo.setState(APIConstants.Monetization.COMPLETED);
monetizationUsagePublishInfo.setStatus(APIConstants.Monetization.FAILED);
apiAdmin.updateMonetizationUsagePublishInfo(monetizationUsagePublishInfo);
} catch (APIManagementException ex) {
String errorMsg = "Failed to update the state of monetization ussge publisher";
log.error(errorMsg, ex);
}
String errorMsg = "Failed to publish monetization usage to billing Engine";
log.error(errorMsg, e);
}
}
use of org.wso2.carbon.apimgt.api.APIAdmin in project carbon-apimgt by wso2.
the class KeymanagersApiServiceImpl method keymanagersGet.
public Response keymanagersGet(String xWSO2Tenant, MessageContext messageContext) {
xWSO2Tenant = SubscriptionValidationDataUtil.validateTenantDomain(xWSO2Tenant, messageContext);
try {
APIAdmin apiAdmin = new APIAdminImpl();
List<KeyManagerConfigurationDTO> keyManagerConfigurations = apiAdmin.getKeyManagerConfigurationsByOrganization(xWSO2Tenant);
List<KeyManagerDTO> keyManagerDTOList = new ArrayList<>();
for (KeyManagerConfigurationDTO keyManagerConfiguration : keyManagerConfigurations) {
keyManagerDTOList.add(toKeyManagerDTO(xWSO2Tenant, keyManagerConfiguration));
}
return Response.ok(keyManagerDTOList).build();
} catch (APIManagementException e) {
RestApiUtil.handleInternalServerError("Error while retrieving key manager configurations", e, log);
}
return null;
}
use of org.wso2.carbon.apimgt.api.APIAdmin in project carbon-apimgt by wso2.
the class AlertSubscriptionsApiServiceImpl method unsubscribeFromBotDetectionAlerts.
/**
* Unsubscribe from bot detection alerts
*
* @param uuid uuid of the subscription
* @param messageContext CXF Message Context
* @return 200 OK response if the subscription is deleted successfully
* @throws APIManagementException if an error occurs when un-subscribing from bot detection alerts
*/
@Override
public Response unsubscribeFromBotDetectionAlerts(String uuid, MessageContext messageContext) throws APIManagementException {
APIAdmin apiAdmin = new APIAdminImpl();
BotDetectionData alertSubscription = apiAdmin.getBotDetectionAlertSubscription("uuid", uuid);
if (alertSubscription == null) {
RestApiUtil.handleResourceNotFoundError("Bot detection alert subscription with uuid: " + uuid + " does not exist.", log);
}
apiAdmin.deleteBotDetectionAlertSubscription(uuid);
return Response.ok().build();
}
use of org.wso2.carbon.apimgt.api.APIAdmin in project carbon-apimgt by wso2.
the class ApiCategoriesApiServiceImpl method apiCategoriesGet.
@Override
public Response apiCategoriesGet(MessageContext messageContext) {
try {
APIAdmin apiAdmin = new APIAdminImpl();
String organization = RestApiUtil.getOrganization(messageContext);
List<APICategory> categoryList = apiAdmin.getAPICategoriesOfOrganization(organization);
APICategoryListDTO categoryListDTO = APICategoryMappingUtil.fromCategoryListToCategoryListDTO(categoryList);
return Response.ok().entity(categoryListDTO).build();
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving API categories";
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
return null;
}
Aggregations