Search in sources :

Example 26 with Tier

use of org.wso2.carbon.apimgt.api.model.Tier in project carbon-apimgt by wso2.

the class RegistryPersistenceUtil method getAPIProduct.

/**
 * Retrieves api product artifact from registry
 *
 * @param artifact
 * @param registry
 * @return APIProduct
 * @throws org.wso2.carbon.apimgt.api.APIManagementException
 */
public static APIProduct getAPIProduct(GovernanceArtifact artifact, Registry registry) throws APIManagementException {
    APIProduct apiProduct;
    try {
        String artifactPath = GovernanceUtils.getArtifactPath(registry, artifact.getId());
        String providerName = artifact.getAttribute(APIConstants.API_OVERVIEW_PROVIDER);
        String productName = artifact.getAttribute(APIConstants.API_OVERVIEW_NAME);
        String productVersion = artifact.getAttribute(APIConstants.API_OVERVIEW_VERSION);
        APIProductIdentifier apiProductIdentifier = new APIProductIdentifier(providerName, productName, productVersion);
        apiProduct = new APIProduct(apiProductIdentifier);
        setResourceProperties(apiProduct, registry, artifactPath);
        // set uuid
        apiProduct.setUuid(artifact.getId());
        apiProduct.setContext(artifact.getAttribute(APIConstants.API_OVERVIEW_CONTEXT));
        apiProduct.setDescription(artifact.getAttribute(APIConstants.API_OVERVIEW_DESCRIPTION));
        apiProduct.setState(getLcStateFromArtifact(artifact));
        apiProduct.setThumbnailUrl(artifact.getAttribute(APIConstants.API_OVERVIEW_THUMBNAIL_URL));
        apiProduct.setVisibility(artifact.getAttribute(APIConstants.API_OVERVIEW_VISIBILITY));
        apiProduct.setVisibleRoles(artifact.getAttribute(APIConstants.API_OVERVIEW_VISIBLE_ROLES));
        apiProduct.setVisibleTenants(artifact.getAttribute(APIConstants.API_OVERVIEW_VISIBLE_TENANTS));
        apiProduct.setBusinessOwner(artifact.getAttribute(APIConstants.API_OVERVIEW_BUSS_OWNER));
        apiProduct.setBusinessOwnerEmail(artifact.getAttribute(APIConstants.API_OVERVIEW_BUSS_OWNER_EMAIL));
        apiProduct.setTechnicalOwner(artifact.getAttribute(APIConstants.API_OVERVIEW_TEC_OWNER));
        apiProduct.setTechnicalOwnerEmail(artifact.getAttribute(APIConstants.API_OVERVIEW_TEC_OWNER_EMAIL));
        apiProduct.setSubscriptionAvailability(artifact.getAttribute(APIConstants.API_OVERVIEW_SUBSCRIPTION_AVAILABILITY));
        apiProduct.setSubscriptionAvailableTenants(artifact.getAttribute(APIConstants.API_OVERVIEW_SUBSCRIPTION_AVAILABLE_TENANTS));
        apiProduct.setEnvironments(getEnvironments(artifact.getAttribute(APIConstants.API_OVERVIEW_ENVIRONMENTS)));
        apiProduct.setTransports(artifact.getAttribute(APIConstants.API_OVERVIEW_TRANSPORTS));
        apiProduct.setApiSecurity(artifact.getAttribute(APIConstants.API_OVERVIEW_API_SECURITY));
        apiProduct.setAuthorizationHeader(artifact.getAttribute(APIConstants.API_OVERVIEW_AUTHORIZATION_HEADER));
        apiProduct.setCorsConfiguration(getCorsConfigurationFromArtifact(artifact));
        apiProduct.setCreatedTime(registry.get(artifactPath).getCreatedTime());
        apiProduct.setLastUpdated(registry.get(artifactPath).getLastModified());
        apiProduct.setType(artifact.getAttribute(APIConstants.API_OVERVIEW_TYPE));
        apiProduct.setGatewayVendor(artifact.getAttribute(APIConstants.API_GATEWAY_VENDOR));
        String tenantDomainName = MultitenantUtils.getTenantDomain(replaceEmailDomainBack(providerName));
        apiProduct.setTenantDomain(tenantDomainName);
        int tenantId = ServiceReferenceHolder.getInstance().getRealmService().getTenantManager().getTenantId(tenantDomainName);
        String tiers = artifact.getAttribute(APIConstants.API_OVERVIEW_TIER);
        Set<Tier> availableTiers = new HashSet<Tier>();
        if (tiers != null) {
            String[] tiersArray = tiers.split("\\|\\|");
            for (String tierName : tiersArray) {
                availableTiers.add(new Tier(tierName));
            }
        }
        apiProduct.setAvailableTiers(availableTiers);
        // We set the context template here
        apiProduct.setContextTemplate(artifact.getAttribute(APIConstants.API_OVERVIEW_CONTEXT_TEMPLATE));
        apiProduct.setEnableSchemaValidation(Boolean.parseBoolean(artifact.getAttribute(APIConstants.API_OVERVIEW_ENABLE_JSON_SCHEMA)));
        apiProduct.setEnableStore(Boolean.parseBoolean(artifact.getAttribute(APIConstants.API_OVERVIEW_ENABLE_STORE)));
        apiProduct.setTestKey(artifact.getAttribute(APIConstants.API_OVERVIEW_TESTKEY));
        apiProduct.setResponseCache(artifact.getAttribute(APIConstants.API_OVERVIEW_RESPONSE_CACHING));
        int cacheTimeout = APIConstants.API_RESPONSE_CACHE_TIMEOUT;
        try {
            cacheTimeout = Integer.parseInt(artifact.getAttribute(APIConstants.API_OVERVIEW_CACHE_TIMEOUT));
        } catch (NumberFormatException e) {
            if (log.isDebugEnabled()) {
                log.debug("Error in converting cache time out due to " + e.getMessage());
            }
        }
        apiProduct.setCacheTimeout(cacheTimeout);
        Set<String> tags = new HashSet<String>();
        Tag[] tag = registry.getTags(artifactPath);
        for (Tag tag1 : tag) {
            tags.add(tag1.getTagName());
        }
        apiProduct.addTags(tags);
        /*
            

            */
        // set data and status related to monetization
        apiProduct.setMonetizationStatus(Boolean.parseBoolean(artifact.getAttribute(APIConstants.Monetization.API_MONETIZATION_STATUS)));
        String monetizationInfo = artifact.getAttribute(APIConstants.Monetization.API_MONETIZATION_PROPERTIES);
        if (StringUtils.isNotBlank(monetizationInfo)) {
            JSONParser parser = new JSONParser();
            JSONObject jsonObj = (JSONObject) parser.parse(monetizationInfo);
            apiProduct.setMonetizationProperties(jsonObj);
        }
        apiProduct.setApiCategories(getAPICategoriesFromAPIGovernanceArtifact(artifact, tenantId));
    } catch (GovernanceException e) {
        String msg = "Failed to get API Product for artifact ";
        throw new APIManagementException(msg, e);
    } catch (RegistryException e) {
        String msg = "Failed to get LastAccess time or Rating";
        throw new APIManagementException(msg, e);
    } catch (UserStoreException e) {
        String msg = "Failed to get User Realm of API Product Provider";
        throw new APIManagementException(msg, e);
    } catch (ParseException e) {
        String msg = "Failed to get parse monetization information.";
        throw new APIManagementException(msg, e);
    }
    return apiProduct;
}
Also used : Tier(org.wso2.carbon.apimgt.api.model.Tier) GovernanceException(org.wso2.carbon.governance.api.exception.GovernanceException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) APIProduct(org.wso2.carbon.apimgt.api.model.APIProduct) APIProductIdentifier(org.wso2.carbon.apimgt.api.model.APIProductIdentifier) JSONObject(org.json.simple.JSONObject) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) UserStoreException(org.wso2.carbon.user.api.UserStoreException) JSONParser(org.json.simple.parser.JSONParser) Tag(org.wso2.carbon.registry.core.Tag) ParseException(org.json.simple.parser.ParseException) HashSet(java.util.HashSet)

Example 27 with Tier

use of org.wso2.carbon.apimgt.api.model.Tier in project carbon-apimgt by wso2.

the class SubscriptionValidationDAO method populateSubscriptionsList.

private void populateSubscriptionsList(List<Subscription> subscriptions, ResultSet resultSet) throws SQLException {
    if (resultSet != null && subscriptions != null) {
        while (resultSet.next()) {
            Subscription subscription = new Subscription();
            subscription.setSubscriptionUUID(resultSet.getString("SUBSCRIPTION_UUID"));
            subscription.setSubscriptionId(resultSet.getInt("SUB_ID"));
            subscription.setPolicyId(resultSet.getString("TIER"));
            subscription.setApiId(resultSet.getInt("API_ID"));
            subscription.setAppId(resultSet.getInt("APP_ID"));
            subscription.setApiUUID(resultSet.getString("API_UUID"));
            subscription.setApplicationUUID(resultSet.getString("APPLICATION_UUID"));
            subscription.setSubscriptionState(resultSet.getString("STATUS"));
            subscriptions.add(subscription);
        }
    }
}
Also used : Subscription(org.wso2.carbon.apimgt.api.model.subscription.Subscription)

Example 28 with Tier

use of org.wso2.carbon.apimgt.api.model.Tier in project carbon-apimgt by wso2.

the class RegistryPersistenceUtilTestCase method testcreateAPIArtifactContent.

@Test
public void testcreateAPIArtifactContent() throws APIPersistenceException, APIManagementException, RegistryException {
    API api = new API(new APIIdentifier("pubuser", "TestAPI", "1.0"));
    Set<Tier> availableTiers = new HashSet<Tier>();
    availableTiers.add(new Tier("Unlimited"));
    availableTiers.add(new Tier("Gold"));
    api.setAvailableTiers(availableTiers);
    Set<URITemplate> uriTemplates = new HashSet<URITemplate>();
    URITemplate template = new URITemplate();
    template.setHTTPVerb("GET");
    template.setUriTemplate("/test");
    template.setAuthType("None");
    uriTemplates.add(template);
    api.setUriTemplates(uriTemplates);
    List<APICategory> categories = new ArrayList<APICategory>();
    APICategory category = new APICategory();
    category.setName("testcategory");
    categories.add(category);
    api.setApiCategories(categories);
    List<Label> gatewayLabels = new ArrayList<Label>();
    Label label = new Label();
    label.setName("TestLabel");
    gatewayLabels.add(label);
    GenericArtifact genericArtifact = new GenericArtifactImpl(new QName("", "TestAPI", ""), "application/vnd.wso2-api+xml");
    genericArtifact.setAttribute("URITemplate", "/test");
    GenericArtifact retArtifact = RegistryPersistenceUtil.createAPIArtifactContent(genericArtifact, api);
    Assert.assertEquals("API name does not match", api.getId().getApiName(), retArtifact.getAttribute("overview_name"));
    Assert.assertEquals("API version does not match", api.getId().getVersion(), retArtifact.getAttribute("overview_version"));
    Assert.assertEquals("API provider does not match", api.getId().getProviderName(), retArtifact.getAttribute("overview_provider"));
}
Also used : GenericArtifact(org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact) Tier(org.wso2.carbon.apimgt.api.model.Tier) QName(javax.xml.namespace.QName) URITemplate(org.wso2.carbon.apimgt.api.model.URITemplate) ArrayList(java.util.ArrayList) Label(org.wso2.carbon.apimgt.api.model.Label) GenericArtifactImpl(org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifactImpl) PublisherAPI(org.wso2.carbon.apimgt.persistence.dto.PublisherAPI) API(org.wso2.carbon.apimgt.api.model.API) DevPortalAPI(org.wso2.carbon.apimgt.persistence.dto.DevPortalAPI) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) APICategory(org.wso2.carbon.apimgt.api.model.APICategory) HashSet(java.util.HashSet) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 29 with Tier

use of org.wso2.carbon.apimgt.api.model.Tier in project carbon-apimgt by wso2.

the class RegistryPersistenceUtilTestCase method testcreateAPIProductArtifactContent.

@Test
public void testcreateAPIProductArtifactContent() throws APIPersistenceException, APIManagementException, RegistryException {
    APIProduct product = new APIProduct(new APIProductIdentifier("pubuser", "TestAPIProd", "1.0.0"));
    GenericArtifact genericArtifact = new GenericArtifactImpl(new QName("", "TestAPIProd", ""), "application/vnd.wso2-api+xml");
    List<APICategory> categories = new ArrayList<APICategory>();
    APICategory category = new APICategory();
    category.setName("testcategory");
    categories.add(category);
    product.setApiCategories(categories);
    Set<Tier> availableTiers = new HashSet<Tier>();
    availableTiers.add(new Tier("Unlimited"));
    availableTiers.add(new Tier("Gold"));
    product.setAvailableTiers(availableTiers);
    GenericArtifact retArtifact = RegistryPersistenceUtil.createAPIProductArtifactContent(genericArtifact, product);
    Assert.assertEquals("API name does not match", product.getId().getName(), retArtifact.getAttribute("overview_name"));
    Assert.assertEquals("API version does not match", product.getId().getVersion(), retArtifact.getAttribute("overview_version"));
    Assert.assertEquals("API provider does not match", product.getId().getProviderName(), retArtifact.getAttribute("overview_provider"));
}
Also used : APIProduct(org.wso2.carbon.apimgt.api.model.APIProduct) APIProductIdentifier(org.wso2.carbon.apimgt.api.model.APIProductIdentifier) GenericArtifact(org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact) Tier(org.wso2.carbon.apimgt.api.model.Tier) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) APICategory(org.wso2.carbon.apimgt.api.model.APICategory) GenericArtifactImpl(org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifactImpl) HashSet(java.util.HashSet) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 30 with Tier

use of org.wso2.carbon.apimgt.api.model.Tier in project carbon-apimgt by wso2.

the class ApiMgtDAO method initSubscribedAPIDetailed.

private void initSubscribedAPIDetailed(Connection connection, SubscribedAPI subscribedAPI, Subscriber subscriber, ResultSet result) throws SQLException, APIManagementException {
    subscribedAPI.setSubscriptionId(result.getInt("SUBS_ID"));
    subscribedAPI.setSubStatus(result.getString("SUB_STATUS"));
    subscribedAPI.setSubCreatedStatus(result.getString("SUBS_CREATE_STATE"));
    String tierName = result.getString(APIConstants.SUBSCRIPTION_FIELD_TIER_ID);
    String requestedTierName = result.getString(APIConstants.SUBSCRIPTION_FIELD_TIER_ID_PENDING);
    subscribedAPI.setTier(new Tier(tierName));
    subscribedAPI.setRequestedTier(new Tier(requestedTierName));
    subscribedAPI.setUUID(result.getString("SUB_UUID"));
    // setting NULL for subscriber. If needed, Subscriber object should be constructed &
    // passed in
    int applicationId = result.getInt("APP_ID");
    Application application = new Application(result.getString("APP_NAME"), subscriber);
    application.setId(result.getInt("APP_ID"));
    application.setTokenType(result.getString("APP_TOKEN_TYPE"));
    application.setCallbackUrl(result.getString("CALLBACK_URL"));
    application.setUUID(result.getString("APP_UUID"));
    if (multiGroupAppSharingEnabled) {
        application.setGroupId(getGroupId(connection, application.getId()));
        application.setOwner(result.getString("OWNER"));
    }
    subscribedAPI.setApplication(application);
}
Also used : Tier(org.wso2.carbon.apimgt.api.model.Tier) Application(org.wso2.carbon.apimgt.api.model.Application)

Aggregations

Tier (org.wso2.carbon.apimgt.api.model.Tier)108 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)53 ArrayList (java.util.ArrayList)42 Test (org.junit.Test)40 HashSet (java.util.HashSet)39 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)37 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)37 API (org.wso2.carbon.apimgt.api.model.API)33 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)32 HashMap (java.util.HashMap)28 Application (org.wso2.carbon.apimgt.api.model.Application)26 Test (org.testng.annotations.Test)22 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)22 Application (org.wso2.carbon.apimgt.core.models.Application)22 LinkedHashSet (java.util.LinkedHashSet)21 JSONObject (org.json.simple.JSONObject)20 URITemplate (org.wso2.carbon.apimgt.api.model.URITemplate)20 ApplicationDAO (org.wso2.carbon.apimgt.core.dao.ApplicationDAO)20 Policy (org.wso2.carbon.apimgt.core.models.policy.Policy)20 BeforeTest (org.testng.annotations.BeforeTest)19