Search in sources :

Example 21 with APIAdmin

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;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) MonetizationException(org.wso2.carbon.apimgt.api.MonetizationException) APIAdminImpl(org.wso2.carbon.apimgt.impl.APIAdminImpl) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 22 with APIAdmin

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);
    }
}
Also used : Monetization(org.wso2.carbon.apimgt.api.model.Monetization) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) APIAdminImpl(org.wso2.carbon.apimgt.impl.APIAdminImpl) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException)

Example 23 with APIAdmin

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;
}
Also used : KeyManagerConfigurationDTO(org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) ArrayList(java.util.ArrayList) KeyManagerDTO(org.wso2.carbon.apimgt.internal.service.dto.KeyManagerDTO) APIAdminImpl(org.wso2.carbon.apimgt.impl.APIAdminImpl)

Example 24 with APIAdmin

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();
}
Also used : APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) BotDetectionData(org.wso2.carbon.apimgt.api.model.botDataAPI.BotDetectionData) APIAdminImpl(org.wso2.carbon.apimgt.impl.APIAdminImpl)

Example 25 with APIAdmin

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;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) APIAdminImpl(org.wso2.carbon.apimgt.impl.APIAdminImpl) APICategory(org.wso2.carbon.apimgt.api.model.APICategory) APICategoryListDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.APICategoryListDTO)

Aggregations

APIAdmin (org.wso2.carbon.apimgt.api.APIAdmin)46 APIAdminImpl (org.wso2.carbon.apimgt.impl.APIAdminImpl)39 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)31 Test (org.junit.Test)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 BeforeTest (org.testng.annotations.BeforeTest)8 KeyManagerConfigurationDTO (org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO)8 APIUtil (org.wso2.carbon.apimgt.impl.utils.APIUtil)6 ArrayList (java.util.ArrayList)5 Schema (org.everit.json.schema.Schema)5 File (java.io.File)4 URI (java.net.URI)4 URISyntaxException (java.net.URISyntaxException)4 BotDetectionData (org.wso2.carbon.apimgt.api.model.botDataAPI.BotDetectionData)4 APIPolicy (org.wso2.carbon.apimgt.api.model.policy.APIPolicy)4 ApplicationPolicy (org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy)4 GlobalPolicy (org.wso2.carbon.apimgt.api.model.policy.GlobalPolicy)4 Policy (org.wso2.carbon.apimgt.api.model.policy.Policy)4 SubscriptionPolicy (org.wso2.carbon.apimgt.api.model.policy.SubscriptionPolicy)4 Gson (com.google.gson.Gson)3