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);
}
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();
}
}
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;
}
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;
}
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");
}
}
Aggregations