Search in sources :

Example 6 with SubscriptionValidationData

use of org.wso2.carbon.apimgt.core.models.SubscriptionValidationData in project carbon-apimgt by wso2.

the class APIMgtAdminServiceImplTestCase method testGetAPISubscriptionsOfApi.

@Test(description = "Get api subscriptions of API")
public void testGetAPISubscriptionsOfApi() throws APIManagementException {
    APISubscriptionDAO apiSubscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
    APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(apiSubscriptionDAO);
    Mockito.when(apiSubscriptionDAO.getAPISubscriptionsOfAPIForValidation(API_CONTEXT, API_VERSION)).thenReturn(new ArrayList<SubscriptionValidationData>());
    adminService.getAPISubscriptionsOfApi(API_CONTEXT, API_VERSION);
    Mockito.verify(apiSubscriptionDAO, Mockito.times(1)).getAPISubscriptionsOfAPIForValidation(API_CONTEXT, API_VERSION);
}
Also used : APISubscriptionDAO(org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO) SubscriptionValidationData(org.wso2.carbon.apimgt.core.models.SubscriptionValidationData) Test(org.testng.annotations.Test)

Example 7 with SubscriptionValidationData

use of org.wso2.carbon.apimgt.core.models.SubscriptionValidationData in project carbon-apimgt by wso2.

the class SubscriptionsApiServiceImpl method subscriptionsGet.

/**
 * Retrieve subscriptions
 *
 * @param apiContext Context of the API
 * @param apiVersion API version
 * @param limit      Limit value
 * @return Subscriptions of the API
 * @throws NotFoundException If failed to retrieve subscriptions
 */
@Override
public Response subscriptionsGet(String apiContext, String apiVersion, Integer limit, String accept, Request request) throws NotFoundException {
    try {
        APIMgtAdminService apiMgtAdminService = APIManagerFactory.getInstance().getAPIMgtAdminService();
        List<SubscriptionValidationData> subscriptionsOfApi;
        if (StringUtils.isEmpty(apiContext) || StringUtils.isEmpty(apiVersion)) {
            APIUtils.logDebug("API Context or version is null or empty. Retrieving subscriptions of all APIs", log);
            subscriptionsOfApi = apiMgtAdminService.getAPISubscriptions(limit);
        } else {
            subscriptionsOfApi = apiMgtAdminService.getAPISubscriptionsOfApi(apiContext, apiVersion);
        }
        SubscriptionListDTO subscriptionsList = new SubscriptionListDTO();
        subscriptionsList.setList(MappingUtil.convertToSubscriptionListDto(subscriptionsOfApi));
        return Response.ok(subscriptionsList).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error while retrieving subscriptions.";
        HashMap<String, String> paramList = new HashMap<String, String>();
        if (!StringUtils.isEmpty(apiContext)) {
            paramList.put(APIMgtConstants.ExceptionsConstants.API_CONTEXT, apiContext);
        }
        if (!StringUtils.isEmpty(apiVersion)) {
            paramList.put(APIMgtConstants.ExceptionsConstants.API_VERSION, apiVersion);
        }
        ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
        log.error(errorMessage, e);
        return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
    }
}
Also used : APIMgtAdminService(org.wso2.carbon.apimgt.core.api.APIMgtAdminService) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) HashMap(java.util.HashMap) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) SubscriptionValidationData(org.wso2.carbon.apimgt.core.models.SubscriptionValidationData) SubscriptionListDTO(org.wso2.carbon.apimgt.rest.api.core.dto.SubscriptionListDTO)

Example 8 with SubscriptionValidationData

use of org.wso2.carbon.apimgt.core.models.SubscriptionValidationData in project carbon-apimgt by wso2.

the class MappingUtil method convertToSubscriptionListDto.

/**
 * This method converts List of SubscriptionValidationData into SubscriptionDTO list.
 *
 * @param subscriptionValidationData List of Subscription Validation Data
 * @return SubscriptionDTO list
 */
public static List<SubscriptionDTO> convertToSubscriptionListDto(List<SubscriptionValidationData> subscriptionValidationData) {
    List<SubscriptionDTO> subscriptionDTOList = new ArrayList<>();
    for (SubscriptionValidationData subscriptionData : subscriptionValidationData) {
        SubscriptionDTO subscriptionDTO = new SubscriptionDTO();
        subscriptionDTO.setApiName(subscriptionData.getApiName());
        subscriptionDTO.setApiContext(subscriptionData.getApiContext());
        subscriptionDTO.setApiVersion(subscriptionData.getApiVersion());
        subscriptionDTO.setApiProvider(subscriptionData.getApiProvider());
        subscriptionDTO.setConsumerKey(subscriptionData.getConsumerKey());
        subscriptionDTO.setSubscriptionPolicy(subscriptionData.getSubscriptionPolicy());
        subscriptionDTO.setKeyEnvType(subscriptionData.getKeyEnvType());
        subscriptionDTO.setApplicationId(subscriptionData.getApplicationId());
        subscriptionDTO.setStatus(subscriptionData.getStatus());
        subscriptionDTOList.add(subscriptionDTO);
    }
    return subscriptionDTOList;
}
Also used : ArrayList(java.util.ArrayList) SubscriptionValidationData(org.wso2.carbon.apimgt.core.models.SubscriptionValidationData) SubscriptionDTO(org.wso2.carbon.apimgt.rest.api.core.dto.SubscriptionDTO)

Example 9 with SubscriptionValidationData

use of org.wso2.carbon.apimgt.core.models.SubscriptionValidationData in project carbon-apimgt by wso2.

the class APIStoreImpl method mapApplicationKeys.

@Override
public OAuthApplicationInfo mapApplicationKeys(String applicationId, String keyType, String clientId, String clientSecret) throws APIManagementException {
    if (log.isDebugEnabled()) {
        log.debug("Semi-manual client registering for App: " + applicationId + " and Client ID: " + clientId);
    }
    if (StringUtils.isEmpty(applicationId) || StringUtils.isEmpty(clientId) || StringUtils.isEmpty(clientSecret)) {
        String msg = "One of input values is null or empty. Application Id: " + applicationId + " Client Id: " + clientId + (StringUtils.isEmpty(clientSecret) ? " Client Secret: " + clientSecret : "");
        log.error(msg);
        throw new APIManagementException(msg, ExceptionCodes.OAUTH2_APP_MAP_FAILED);
    }
    // Checking whether given consumer key and secret match with an existing OAuth app.
    // If they does not match, throw an exception.
    OAuthApplicationInfo oAuthApp = getKeyManager().retrieveApplication(clientId);
    if (oAuthApp == null || !clientSecret.equals(oAuthApp.getClientSecret())) {
        String msg = "Unable to find OAuth app. The provided Client Id is invalid. Client Id: " + clientId;
        throw new APIManagementException(msg, ExceptionCodes.OAUTH2_APP_MAP_FAILED);
    }
    try {
        getApplicationDAO().addApplicationKeys(applicationId, keyType, clientId);
    } catch (APIMgtDAOException e) {
        String errorMsg = "Error occurred while saving key data.";
        log.error(errorMsg, e);
        throw new APIManagementException(errorMsg, e, e.getErrorHandler());
    }
    log.debug("Application keys are successfully saved in the database");
    List<SubscriptionValidationData> subscriptionValidationData = getApiSubscriptionDAO().getAPISubscriptionsOfAppForValidation(applicationId, keyType);
    if (subscriptionValidationData != null && !subscriptionValidationData.isEmpty()) {
        getApiGateway().addAPISubscription(subscriptionValidationData);
    }
    if (log.isDebugEnabled()) {
        log.debug("Semi-manual client registration was successful for application: " + applicationId + " and Client ID: " + clientId);
    }
    return oAuthApp;
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) OAuthApplicationInfo(org.wso2.carbon.apimgt.core.models.OAuthApplicationInfo) SubscriptionValidationData(org.wso2.carbon.apimgt.core.models.SubscriptionValidationData)

Example 10 with SubscriptionValidationData

use of org.wso2.carbon.apimgt.core.models.SubscriptionValidationData in project carbon-apimgt by wso2.

the class APIGatewayPublisherImpl method updateAPISubscriptionStatus.

@Override
public void updateAPISubscriptionStatus(List<SubscriptionValidationData> subscriptionValidationDataList) throws GatewayException {
    SubscriptionEvent subscriptionBlockEvent = new SubscriptionEvent(APIMgtConstants.GatewayEventTypes.SUBSCRIPTION_STATUS_CHANGE);
    subscriptionBlockEvent.setSubscriptionsList(subscriptionValidationDataList);
    publishToStoreTopic(subscriptionBlockEvent);
    if (log.isDebugEnabled()) {
        log.debug("Subscription updated event has been successfully published to broker");
    }
}
Also used : SubscriptionEvent(org.wso2.carbon.apimgt.core.models.events.SubscriptionEvent)

Aggregations

SubscriptionValidationData (org.wso2.carbon.apimgt.core.models.SubscriptionValidationData)16 Test (org.testng.annotations.Test)6 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)6 APISubscriptionDAO (org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO)5 API (org.wso2.carbon.apimgt.core.models.API)5 Application (org.wso2.carbon.apimgt.core.models.Application)5 ArrayList (java.util.ArrayList)4 ApplicationDAO (org.wso2.carbon.apimgt.core.dao.ApplicationDAO)4 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)4 SQLException (java.sql.SQLException)3 SubscriptionEvent (org.wso2.carbon.apimgt.core.models.events.SubscriptionEvent)3 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)2 OAuthApplicationInfo (org.wso2.carbon.apimgt.core.models.OAuthApplicationInfo)2 SubscriptionDTO (org.wso2.carbon.apimgt.rest.api.core.dto.SubscriptionDTO)2 HashMap (java.util.HashMap)1 APIMgtAdminService (org.wso2.carbon.apimgt.core.api.APIMgtAdminService)1 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)1