Search in sources :

Example 11 with APIProductIdentifier

use of org.wso2.carbon.apimgt.api.model.APIProductIdentifier 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)

Example 12 with APIProductIdentifier

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

the class APIProviderImplTest method createMockAPIProduct.

private APIProduct createMockAPIProduct(String provider) {
    APIProductIdentifier productIdentifier = new APIProductIdentifier(provider, APIConstants.API_PRODUCT, APIConstants.API_PRODUCT_VERSION);
    APIProduct apiProduct = new APIProduct(productIdentifier);
    apiProduct.setContext("/test");
    apiProduct.setState(APIConstants.CREATED);
    apiProduct.setType(APIConstants.API_PRODUCT);
    apiProduct.setOrganization(APIConstants.SUPER_TENANT_DOMAIN);
    return apiProduct;
}
Also used : APIProductIdentifier(org.wso2.carbon.apimgt.api.model.APIProductIdentifier) PublisherAPIProduct(org.wso2.carbon.apimgt.persistence.dto.PublisherAPIProduct) APIProduct(org.wso2.carbon.apimgt.api.model.APIProduct)

Example 13 with APIProductIdentifier

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

the class ApiMgtDAO method updateAPIProduct.

public void updateAPIProduct(APIProduct product, String username) throws APIManagementException {
    Connection conn = null;
    PreparedStatement ps = null;
    if (log.isDebugEnabled()) {
        log.debug("updateAPIProduct() : product- " + product.toString());
    }
    try {
        conn = APIMgtDBUtil.getConnection();
        conn.setAutoCommit(false);
        String query = SQLConstants.UPDATE_PRODUCT_SQL;
        ps = conn.prepareStatement(query);
        ps.setString(1, product.getProductLevelPolicy());
        ps.setString(2, username);
        ps.setTimestamp(3, new Timestamp(System.currentTimeMillis()));
        ps.setString(4, product.getGatewayVendor());
        APIProductIdentifier identifier = product.getId();
        ps.setString(5, identifier.getName());
        ps.setString(6, APIUtil.replaceEmailDomainBack(identifier.getProviderName()));
        ps.setString(7, identifier.getVersion());
        ps.executeUpdate();
        int productId = getAPIID(product.getUuid(), conn);
        updateAPIProductResourceMappings(product, productId, conn);
        conn.commit();
    } catch (SQLException e) {
        if (conn != null) {
            try {
                conn.rollback();
            } catch (SQLException e1) {
                log.error("Error while rolling back the failed operation", e1);
            }
        }
        handleException("Error in updating API Product: " + e.getMessage(), e);
    } finally {
        APIMgtDBUtil.closeAllConnections(ps, conn, null);
    }
}
Also used : APIProductIdentifier(org.wso2.carbon.apimgt.api.model.APIProductIdentifier) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) Timestamp(java.sql.Timestamp)

Example 14 with APIProductIdentifier

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

the class ApiMgtDAO method setAssociatedAPIProductsURLMappings.

private void setAssociatedAPIProductsURLMappings(String uuid, Map<Integer, URITemplate> uriTemplates) throws SQLException {
    try (Connection conn = APIMgtDBUtil.getConnection();
        PreparedStatement ps = conn.prepareStatement(SQLConstants.GET_ASSOCIATED_API_PRODUCT_URL_TEMPLATES_SQL)) {
        ps.setString(1, uuid);
        try (ResultSet rs = ps.executeQuery()) {
            while (rs.next()) {
                String productName = rs.getString("API_NAME");
                String productVersion = rs.getString("API_VERSION");
                String productProvider = rs.getString("API_PROVIDER");
                int uriTemplateId = rs.getInt("URL_MAPPING_ID");
                URITemplate uriTemplate = uriTemplates.get(uriTemplateId);
                if (uriTemplate != null) {
                    APIProductIdentifier productIdentifier = new APIProductIdentifier(productProvider, productName, productVersion);
                    uriTemplate.addUsedByProduct(productIdentifier);
                }
            }
        }
    }
}
Also used : APIProductIdentifier(org.wso2.carbon.apimgt.api.model.APIProductIdentifier) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) URITemplate(org.wso2.carbon.apimgt.api.model.URITemplate) PreparedStatement(java.sql.PreparedStatement)

Example 15 with APIProductIdentifier

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

the class ApiMgtDAO method removeSubscription.

/**
 * Removes the subscription entry from AM_SUBSCRIPTIONS for identifier.
 *
 * @param identifier    Identifier
 * @param applicationId ID of the application which has the subscription
 * @throws APIManagementException
 */
public void removeSubscription(Identifier identifier, int applicationId) throws APIManagementException {
    Connection conn = null;
    ResultSet resultSet = null;
    PreparedStatement ps = null;
    int id = -1;
    String uuid;
    try {
        conn = APIMgtDBUtil.getConnection();
        conn.setAutoCommit(false);
        String subscriptionUUIDQuery = SQLConstants.GET_SUBSCRIPTION_UUID_SQL;
        if (identifier.getId() > 0) {
            id = identifier.getId();
        } else if (identifier instanceof APIIdentifier) {
            String apiUuid;
            if (identifier.getUUID() != null) {
                apiUuid = identifier.getUUID();
            } else {
                apiUuid = getUUIDFromIdentifier((APIIdentifier) identifier);
            }
            id = getAPIID(apiUuid, conn);
        } else if (identifier instanceof APIProductIdentifier) {
            id = ((APIProductIdentifier) identifier).getProductId();
        }
        ps = conn.prepareStatement(subscriptionUUIDQuery);
        ps.setInt(1, id);
        ps.setInt(2, applicationId);
        resultSet = ps.executeQuery();
        if (resultSet.next()) {
            uuid = resultSet.getString("UUID");
            SubscribedAPI subscribedAPI = new SubscribedAPI(uuid);
            removeSubscription(subscribedAPI, conn);
        } else {
            throw new APIManagementException("UUID does not exist for the given apiId:" + id + " and " + "application id:" + applicationId);
        }
        conn.commit();
    } catch (SQLException e) {
        if (conn != null) {
            try {
                conn.rollback();
            } catch (SQLException ex) {
                log.error("Failed to rollback the add subscription ", ex);
            }
        }
        handleException("Failed to add subscriber data ", e);
    } finally {
        APIMgtDBUtil.closeAllConnections(ps, conn, resultSet);
    }
}
Also used : APIProductIdentifier(org.wso2.carbon.apimgt.api.model.APIProductIdentifier) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) SubscribedAPI(org.wso2.carbon.apimgt.api.model.SubscribedAPI) PreparedStatement(java.sql.PreparedStatement) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier)

Aggregations

APIProductIdentifier (org.wso2.carbon.apimgt.api.model.APIProductIdentifier)91 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)48 APIProduct (org.wso2.carbon.apimgt.api.model.APIProduct)33 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)22 PreparedStatement (java.sql.PreparedStatement)19 APIProductResource (org.wso2.carbon.apimgt.api.model.APIProductResource)19 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)19 Connection (java.sql.Connection)18 ArrayList (java.util.ArrayList)18 ResultSet (java.sql.ResultSet)17 SQLException (java.sql.SQLException)17 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)17 API (org.wso2.carbon.apimgt.api.model.API)14 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)14 HashSet (java.util.HashSet)13 APIMgtResourceNotFoundException (org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException)13 URITemplate (org.wso2.carbon.apimgt.api.model.URITemplate)13 APIPersistenceException (org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException)13 Tier (org.wso2.carbon.apimgt.api.model.Tier)12 PublisherAPIProduct (org.wso2.carbon.apimgt.persistence.dto.PublisherAPIProduct)12