Search in sources :

Example 56 with API

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

the class APIGatewayPublisherImpl method deleteCompositeAPI.

@Override
public void deleteCompositeAPI(CompositeAPI api) throws GatewayException {
    // build the message to send
    APIEvent gatewayDTO = new APIEvent(APIMgtConstants.GatewayEventTypes.API_DELETE);
    gatewayDTO.setLabels(api.getLabels());
    APISummary apiSummary = new APISummary();
    apiSummary.setName(api.getName());
    apiSummary.setVersion(api.getVersion());
    apiSummary.setContext(api.getContext());
    apiSummary.setThreatProtectionPolicies(api.getThreatProtectionPolicies());
    gatewayDTO.setApiSummary(apiSummary);
    publishToPublisherTopic(gatewayDTO);
}
Also used : APISummary(org.wso2.carbon.apimgt.core.models.APISummary) APIEvent(org.wso2.carbon.apimgt.core.models.events.APIEvent)

Example 57 with API

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

the class APIExecutor method execute.

/**
 * This method will be called when the invoke() method of the default lifecycle implementation is called.
 * Execution logic should reside in this method since the default lifecycle implementation will determine
 * the execution output by looking at the output of this method.
 *
 * @param resource     The resource in which the lifecycle state is changed.
 * @param currentState Current lifecycle state.
 * @param targetState  The target lifecycle state.
 * @throws LifecycleException If exception occurs while running the executor.
 */
@Override
public void execute(Object resource, String currentState, String targetState) throws LifecycleException {
    API api = (API) resource;
    if (!currentState.equals(targetState)) {
        // todo:This place need to write how to handle Gateway publishing
        try {
            ApiDAO apiDAO = DAOFactory.getApiDAO();
            apiDAO.changeLifeCycleStatus(api.getId(), targetState);
        } catch (APIMgtDAOException e) {
            throw new LifecycleException("Couldn't create APIPublisher from user", e);
        }
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) LifecycleException(org.wso2.carbon.lcm.core.exception.LifecycleException) API(org.wso2.carbon.apimgt.core.models.API) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO)

Example 58 with API

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

the class APIManagerFactory method newConsumer.

private APIStore newConsumer(String username) throws APIManagementException {
    // }
    try {
        APIStoreImpl userAwareAPIStore = new APIStoreImpl(username, getIdentityProvider(), getKeyManager(), DAOFactory.getApiDAO(), DAOFactory.getApplicationDAO(), DAOFactory.getAPISubscriptionDAO(), DAOFactory.getPolicyDAO(), DAOFactory.getTagDAO(), DAOFactory.getLabelDAO(), DAOFactory.getWorkflowDAO(), new GatewaySourceGeneratorImpl(), new APIGatewayPublisherImpl());
        // Register all the observers which need to observe 'Store' component
        userAwareAPIStore.registerObserver(new EventLogger());
        userAwareAPIStore.registerObserver(new FunctionTrigger(DAOFactory.getFunctionDAO(), new RestCallUtilImpl()));
        return userAwareAPIStore;
    } catch (APIMgtDAOException e) {
        log.error("Couldn't Create API Consumer", e);
        throw new APIMgtDAOException("Couldn't Create API Consumer", ExceptionCodes.APIMGT_DAO_EXCEPTION);
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)

Example 59 with API

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

the class APIManagerFactory method newProvider.

private APIPublisher newProvider(String username) throws APIManagementException {
    try {
        APIPublisherImpl apiPublisher = new APIPublisherImpl(username, getIdentityProvider(), getKeyManager(), DAOFactory.getApiDAO(), DAOFactory.getApplicationDAO(), DAOFactory.getAPISubscriptionDAO(), DAOFactory.getPolicyDAO(), geApiLifecycleManager(), DAOFactory.getLabelDAO(), DAOFactory.getWorkflowDAO(), DAOFactory.getTagDAO(), DAOFactory.getThreatProtectionDAO(), new GatewaySourceGeneratorImpl(), new APIGatewayPublisherImpl());
        // Register all the observers which need to observe 'Publisher' component
        apiPublisher.registerObserver(new EventLogger());
        apiPublisher.registerObserver(new FunctionTrigger(DAOFactory.getFunctionDAO(), new RestCallUtilImpl()));
        return apiPublisher;
    } catch (APIMgtDAOException e) {
        log.error("Couldn't Create API Provider", e);
        throw new APIMgtDAOException("Couldn't Create API Provider", ExceptionCodes.APIMGT_DAO_EXCEPTION);
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)

Example 60 with API

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

the class APIMgtAdminServiceImpl method getAPIsByGatewayLabel.

@Override
public List<API> getAPIsByGatewayLabel(List<String> gatewayLabels) throws APIManagementException {
    List<API> apiList;
    try {
        if (gatewayLabels != null) {
            apiList = apiDAO.getAPIsByGatewayLabel(gatewayLabels);
        } else {
            String msg = "Gateway labels cannot be null";
            log.error(msg);
            throw new APIManagementException(msg, ExceptionCodes.GATEWAY_LABELS_CANNOT_BE_NULL);
        }
    } catch (APIMgtDAOException e) {
        String msg = "Error occurred while getting the API list in given gateway labels";
        log.error(msg, e);
        throw new APIManagementException(msg, ExceptionCodes.APIMGT_DAO_EXCEPTION);
    }
    return apiList;
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) API(org.wso2.carbon.apimgt.core.models.API)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)582 ArrayList (java.util.ArrayList)374 API (org.wso2.carbon.apimgt.core.models.API)359 Test (org.testng.annotations.Test)350 HashMap (java.util.HashMap)318 Test (org.junit.Test)316 API (org.wso2.carbon.apimgt.api.model.API)307 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)255 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)253 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)234 SQLException (java.sql.SQLException)190 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)186 IOException (java.io.IOException)181 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)179 PreparedStatement (java.sql.PreparedStatement)169 Connection (java.sql.Connection)158 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)154 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)149 JSONObject (org.json.simple.JSONObject)142 Resource (org.wso2.carbon.registry.core.Resource)139