Search in sources :

Example 6 with SubscriptionDataStore

use of org.wso2.carbon.apimgt.keymgt.model.SubscriptionDataStore in project carbon-apimgt by wso2.

the class GatewayUtils method convertToApplicationDto.

private static ApplicationInfoDTO convertToApplicationDto(int applicationId, SubscriptionDataStore subscriptionDataStore) {
    ApplicationInfoDTO applicationInfoDTO = new ApplicationInfoDTO();
    Application application = subscriptionDataStore.getApplicationById(applicationId);
    if (application != null) {
        applicationInfoDTO.setId(application.getId());
        applicationInfoDTO.setName(application.getName());
        applicationInfoDTO.setPolicy(application.getPolicy());
        applicationInfoDTO.setAttributes(application.getAttributes());
        applicationInfoDTO.setSubName(application.getSubName());
        applicationInfoDTO.setUuid(application.getUUID());
        applicationInfoDTO.setTokenType(application.getTokenType());
        applicationInfoDTO.setKeys(convertToApplicationKeyMapping(applicationId, subscriptionDataStore));
    }
    return applicationInfoDTO;
}
Also used : ApplicationInfoDTO(org.wso2.carbon.apimgt.rest.api.gateway.dto.ApplicationInfoDTO) Application(org.wso2.carbon.apimgt.keymgt.model.entity.Application)

Example 7 with SubscriptionDataStore

use of org.wso2.carbon.apimgt.keymgt.model.SubscriptionDataStore in project carbon-apimgt by wso2.

the class KeyManagerDataServiceImpl method removeApplication.

@Override
public void removeApplication(ApplicationEvent event) {
    if (log.isDebugEnabled()) {
        log.debug("Remove Application in datastore in tenant " + event.getTenantDomain());
    }
    SubscriptionDataStore store = SubscriptionDataHolder.getInstance().getTenantSubscriptionStore(event.getTenantDomain());
    if (store == null) {
        if (log.isDebugEnabled()) {
            log.debug("Ignoring the Event due to tenant " + event.getTenantDomain() + " not loaded");
        }
        return;
    }
    store.removeApplication(getApplicationFromApplicationEvent(event));
}
Also used : SubscriptionDataStore(org.wso2.carbon.apimgt.keymgt.model.SubscriptionDataStore)

Example 8 with SubscriptionDataStore

use of org.wso2.carbon.apimgt.keymgt.model.SubscriptionDataStore in project carbon-apimgt by wso2.

the class KeyManagerDataServiceImpl method removeApplicationKeyMapping.

@Override
public void removeApplicationKeyMapping(ApplicationRegistrationEvent event) {
    if (log.isDebugEnabled()) {
        log.debug("Remove ApplicationKey Mapping in datastore in tenant " + event.getTenantDomain());
    }
    SubscriptionDataStore store = SubscriptionDataHolder.getInstance().getTenantSubscriptionStore(event.getTenantDomain());
    if (store == null) {
        if (log.isDebugEnabled()) {
            log.debug("Ignoring the Event due to tenant " + event.getTenantDomain() + " not loaded");
        }
        return;
    }
    store.removeApplicationKeyMapping(getApplicationKeyMappingFromApplicationRegistrationEvent(event));
}
Also used : SubscriptionDataStore(org.wso2.carbon.apimgt.keymgt.model.SubscriptionDataStore)

Example 9 with SubscriptionDataStore

use of org.wso2.carbon.apimgt.keymgt.model.SubscriptionDataStore in project carbon-apimgt by wso2.

the class KeyManagerDataServiceImpl method addOrUpdateSubscription.

@Override
public void addOrUpdateSubscription(SubscriptionEvent event) {
    if (log.isDebugEnabled()) {
        log.debug("Add or Update Subscription in datastore in tenant " + event.getTenantDomain());
    }
    SubscriptionDataStore store = SubscriptionDataHolder.getInstance().getTenantSubscriptionStore(event.getTenantDomain());
    if (store == null) {
        if (log.isDebugEnabled()) {
            log.debug("Ignoring the Event due to tenant " + event.getTenantDomain() + " not loaded");
        }
        return;
    }
    store.addOrUpdateSubscription(getSubscriptionFromSubscriptionEvent(event));
}
Also used : SubscriptionDataStore(org.wso2.carbon.apimgt.keymgt.model.SubscriptionDataStore)

Example 10 with SubscriptionDataStore

use of org.wso2.carbon.apimgt.keymgt.model.SubscriptionDataStore in project carbon-apimgt by wso2.

the class GatewayUtilsTestCase method testGetAPIasNull.

@Test
public void testGetAPIasNull() {
    MessageContext messageContext = Mockito.mock(MessageContext.class);
    SubscriptionDataHolder subscriptionDataHolder = Mockito.mock(SubscriptionDataHolder.class);
    Mockito.when(SubscriptionDataHolder.getInstance()).thenReturn(subscriptionDataHolder);
    SubscriptionDataStore subscriptionDataStore = Mockito.mock(SubscriptionDataStore.class);
    Mockito.when(subscriptionDataHolder.getTenantSubscriptionStore("carbon.super")).thenReturn(subscriptionDataStore);
    Mockito.when(messageContext.getProperty(RESTConstants.REST_API_CONTEXT)).thenReturn("/abc1");
    Mockito.when(messageContext.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION)).thenReturn("1.0.0");
    Assert.assertNull(GatewayUtils.getAPI(messageContext));
    Assert.assertNull(GatewayUtils.getAPINameFromContextAndVersion(messageContext));
    Assert.assertNull(GatewayUtils.getApiProviderFromContextAndVersion(messageContext));
    Mockito.verify(messageContext, Mockito.times(0)).setProperty(Mockito.anyString(), Mockito.any());
    Mockito.verify(messageContext, Mockito.times(6)).getProperty(APIMgtGatewayConstants.API_OBJECT);
    Mockito.verify(messageContext, Mockito.times(3)).getProperty(RESTConstants.REST_API_CONTEXT);
    Mockito.verify(messageContext, Mockito.times(3)).getProperty(RESTConstants.SYNAPSE_REST_API_VERSION);
    Mockito.verify(subscriptionDataStore, Mockito.times(3)).getApiByContextAndVersion("/abc1", "1.0.0");
}
Also used : MessageContext(org.apache.synapse.MessageContext) SubscriptionDataStore(org.wso2.carbon.apimgt.keymgt.model.SubscriptionDataStore) SubscriptionDataHolder(org.wso2.carbon.apimgt.keymgt.SubscriptionDataHolder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

SubscriptionDataStore (org.wso2.carbon.apimgt.keymgt.model.SubscriptionDataStore)43 API (org.wso2.carbon.apimgt.keymgt.model.entity.API)14 SubscriptionDataHolder (org.wso2.carbon.apimgt.keymgt.SubscriptionDataHolder)9 Test (org.junit.Test)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 ArrayList (java.util.ArrayList)7 Application (org.wso2.carbon.apimgt.keymgt.model.entity.Application)6 Subscription (org.wso2.carbon.apimgt.keymgt.model.entity.Subscription)5 SubscriptionDataLoaderImpl (org.wso2.carbon.apimgt.keymgt.model.impl.SubscriptionDataLoaderImpl)5 MessageContext (org.apache.synapse.MessageContext)4 DataLoadingException (org.wso2.carbon.apimgt.keymgt.model.exception.DataLoadingException)4 ErrorDTO (org.wso2.carbon.apimgt.rest.api.gateway.dto.ErrorDTO)4 ApiPolicy (org.wso2.carbon.apimgt.keymgt.model.entity.ApiPolicy)3 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)2 URLMapping (org.wso2.carbon.apimgt.api.model.subscription.URLMapping)2 API (org.wso2.carbon.apimgt.common.analytics.publishers.dto.API)2 DeployAPIInGatewayEvent (org.wso2.carbon.apimgt.impl.notifier.events.DeployAPIInGatewayEvent)2 ApplicationPolicy (org.wso2.carbon.apimgt.keymgt.model.entity.ApplicationPolicy)2 Scope (org.wso2.carbon.apimgt.keymgt.model.entity.Scope)2 SubscriptionPolicy (org.wso2.carbon.apimgt.keymgt.model.entity.SubscriptionPolicy)2