Search in sources :

Example 11 with APIProduct

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

the class OAS3Parser method getOASDefinitionForStore.

/**
 * Update OAS definition for store
 *
 * @param product        APIProduct
 * @param oasDefinition  OAS definition
 * @param hostsWithSchemes host addresses with protocol mapping
 * @return OAS definition
 */
@Override
public String getOASDefinitionForStore(APIProduct product, String oasDefinition, Map<String, String> hostsWithSchemes) {
    OpenAPI openAPI = getOpenAPI(oasDefinition);
    updateOperations(openAPI);
    updateEndpoints(product, hostsWithSchemes, openAPI);
    return updateSwaggerSecurityDefinitionForStore(openAPI, new SwaggerData(product), hostsWithSchemes);
}
Also used : SwaggerData(org.wso2.carbon.apimgt.api.model.SwaggerData) OpenAPI(io.swagger.v3.oas.models.OpenAPI)

Example 12 with APIProduct

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

the class APIMapperTestCase method testAPIProductToPublisherAPIProductAndBack.

@Test
public void testAPIProductToPublisherAPIProductAndBack() throws GovernanceException, APIManagementException {
    PublisherAPIProduct pubAPI = APIProductMapper.INSTANCE.toPublisherApiProduct(product);
    Assert.assertEquals("API product uuid does not match", product.getUuid(), pubAPI.getId());
    Assert.assertEquals("API product type does not match", product.getType(), pubAPI.getType());
    APIProduct mappedProduct = APIProductMapper.INSTANCE.toApiProduct(pubAPI);
    Assert.assertEquals("Mapped product uuid does not match", mappedProduct.getUuid(), product.getUuid());
}
Also used : APIProduct(org.wso2.carbon.apimgt.api.model.APIProduct) PublisherAPIProduct(org.wso2.carbon.apimgt.persistence.dto.PublisherAPIProduct) PublisherAPIProduct(org.wso2.carbon.apimgt.persistence.dto.PublisherAPIProduct) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 13 with APIProduct

use of org.wso2.carbon.apimgt.api.model.APIProduct 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 14 with APIProduct

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

the class ApiMgtDAO method setAPIProductFromDB.

/**
 * Get product Id from the product name and the provider.
 *
 * @param product product identifier
 * @throws APIManagementException exception
 */
public void setAPIProductFromDB(APIProduct product) throws APIManagementException {
    APIProductIdentifier apiProductIdentifier = product.getId();
    String currentApiUuid;
    APIRevision apiRevision = ApiMgtDAO.getInstance().checkAPIUUIDIsARevisionUUID(product.getUuid());
    if (apiRevision != null && apiRevision.getApiUUID() != null) {
        currentApiUuid = apiRevision.getApiUUID();
    } else {
        currentApiUuid = product.getUuid();
    }
    try (Connection connection = APIMgtDBUtil.getConnection();
        PreparedStatement prepStmt = connection.prepareStatement(SQLConstants.GET_API_PRODUCT_SQL)) {
        prepStmt.setString(1, currentApiUuid);
        try (ResultSet rs = prepStmt.executeQuery()) {
            if (rs.next()) {
                product.setProductId(rs.getInt("API_ID"));
                product.setProductLevelPolicy(rs.getString("API_TIER"));
            } else {
                String msg = "Unable to find the API Product : " + apiProductIdentifier.getName() + "-" + APIUtil.replaceEmailDomainBack(apiProductIdentifier.getProviderName()) + "-" + apiProductIdentifier.getVersion() + " in the database";
                throw new APIMgtResourceNotFoundException(msg);
            }
        }
    } catch (SQLException e) {
        handleException("Error while locating API Product: " + apiProductIdentifier.getName() + "-" + APIUtil.replaceEmailDomainBack(apiProductIdentifier.getProviderName()) + "-" + apiProductIdentifier.getVersion() + " from the database", e);
    }
}
Also used : APIProductIdentifier(org.wso2.carbon.apimgt.api.model.APIProductIdentifier) DeployedAPIRevision(org.wso2.carbon.apimgt.api.model.DeployedAPIRevision) APIRevision(org.wso2.carbon.apimgt.api.model.APIRevision) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) APIMgtResourceNotFoundException(org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException)

Example 15 with APIProduct

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

the class APIProviderImplTest method testDeleteAPIProductWorkflowTask.

@Test
public void testDeleteAPIProductWorkflowTask() throws APIManagementException, WorkflowException {
    APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
    Mockito.when(apimgtDAO.getAPIID(apiUUID)).thenReturn(1111);
    WorkflowExecutorFactory wfe = PowerMockito.mock(WorkflowExecutorFactory.class);
    Mockito.when(WorkflowExecutorFactory.getInstance()).thenReturn(wfe);
    WorkflowExecutor productStateChangeWorkflowExecutor = Mockito.mock(WorkflowExecutor.class);
    Mockito.when(wfe.getWorkflowExecutor(WorkflowConstants.WF_TYPE_AM_API_PRODUCT_STATE)).thenReturn(productStateChangeWorkflowExecutor);
    WorkflowDTO workflowDTO = Mockito.mock(WorkflowDTO.class);
    Mockito.when(apimgtDAO.retrieveWorkflowFromInternalReference(Integer.toString(1111), WorkflowConstants.WF_TYPE_AM_API_PRODUCT_STATE)).thenReturn(workflowDTO);
    APIProductIdentifier identifier = new APIProductIdentifier("admin", "APIProduct", "1.0.0", apiUUID);
    apiProvider.deleteWorkflowTask(identifier);
    Mockito.verify(apimgtDAO, Mockito.times(1)).getAPIID(apiUUID);
}
Also used : APIProductIdentifier(org.wso2.carbon.apimgt.api.model.APIProductIdentifier) WorkflowDTO(org.wso2.carbon.apimgt.impl.dto.WorkflowDTO) WorkflowExecutorFactory(org.wso2.carbon.apimgt.impl.workflow.WorkflowExecutorFactory) APIStateChangeSimpleWorkflowExecutor(org.wso2.carbon.apimgt.impl.workflow.APIStateChangeSimpleWorkflowExecutor) WorkflowExecutor(org.wso2.carbon.apimgt.impl.workflow.WorkflowExecutor) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

APIProduct (org.wso2.carbon.apimgt.api.model.APIProduct)71 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)52 APIProductIdentifier (org.wso2.carbon.apimgt.api.model.APIProductIdentifier)51 API (org.wso2.carbon.apimgt.api.model.API)37 ArrayList (java.util.ArrayList)31 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)22 PublisherAPIProduct (org.wso2.carbon.apimgt.persistence.dto.PublisherAPIProduct)22 APIProductResource (org.wso2.carbon.apimgt.api.model.APIProductResource)21 Tier (org.wso2.carbon.apimgt.api.model.Tier)21 HashMap (java.util.HashMap)19 GenericArtifact (org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact)19 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)18 JSONObject (org.json.simple.JSONObject)17 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)17 APIPersistenceException (org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException)16 HashSet (java.util.HashSet)15 GenericArtifactManager (org.wso2.carbon.governance.api.generic.GenericArtifactManager)15 APIMgtResourceNotFoundException (org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException)14 Organization (org.wso2.carbon.apimgt.persistence.dto.Organization)14 ParseException (org.json.simple.parser.ParseException)12