Search in sources :

Example 26 with APIProduct

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

the class APIProviderImpl method removeFromGateway.

protected void removeFromGateway(APIProduct apiProduct, String tenantDomain, Set<APIRevisionDeployment> gatewaysToRemove, Set<String> gatewaysToAdd) throws APIManagementException {
    APIGatewayManager gatewayManager = APIGatewayManager.getInstance();
    Set<API> associatedAPIs = getAssociatedAPIs(apiProduct);
    Set<String> environmentsToRemove = new HashSet<>();
    for (APIRevisionDeployment apiRevisionDeployment : gatewaysToRemove) {
        environmentsToRemove.add(apiRevisionDeployment.getDeployment());
    }
    environmentsToRemove.removeAll(gatewaysToAdd);
    gatewayManager.unDeployFromGateway(apiProduct, tenantDomain, associatedAPIs, environmentsToRemove);
}
Also used : API(org.wso2.carbon.apimgt.api.model.API) ImportExportAPI(org.wso2.carbon.apimgt.impl.importexport.ImportExportAPI) SubscribedAPI(org.wso2.carbon.apimgt.api.model.SubscribedAPI) PublisherAPI(org.wso2.carbon.apimgt.persistence.dto.PublisherAPI) APIRevisionDeployment(org.wso2.carbon.apimgt.api.model.APIRevisionDeployment) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 27 with APIProduct

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

the class APIProviderImpl method createAPIProduct.

/**
 * Create an Api Product
 *
 * @param apiProduct API Product
 * @throws APIManagementException if failed to create APIProduct
 */
protected String createAPIProduct(APIProduct apiProduct) throws APIManagementException {
    String apiProductUUID = null;
    // Validate Transports and Security
    validateAndSetTransports(apiProduct);
    validateAndSetAPISecurity(apiProduct);
    PublisherAPIProduct publisherAPIProduct = APIProductMapper.INSTANCE.toPublisherApiProduct(apiProduct);
    PublisherAPIProduct addedAPIProduct;
    try {
        publisherAPIProduct.setApiProductName(apiProduct.getId().getName());
        publisherAPIProduct.setProviderName(apiProduct.getId().getProviderName());
        publisherAPIProduct.setVersion(apiProduct.getId().getVersion());
        addedAPIProduct = apiPersistenceInstance.addAPIProduct(new Organization(CarbonContext.getThreadLocalCarbonContext().getTenantDomain()), publisherAPIProduct);
        apiProductUUID = addedAPIProduct.getId();
    } catch (APIPersistenceException e) {
        throw new APIManagementException("Error while creating API product ", e);
    }
    return apiProductUUID;
}
Also used : APIPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException) Organization(org.wso2.carbon.apimgt.persistence.dto.Organization) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) PublisherAPIProduct(org.wso2.carbon.apimgt.persistence.dto.PublisherAPIProduct)

Example 28 with APIProduct

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

the class APIGatewayManager method unDeployFromGateway.

public void unDeployFromGateway(APIProduct apiProduct, String tenantDomain, Set<API> associatedAPIs, Set<String> gatewaysToRemove) throws APIManagementException {
    String apiProductUuid = apiProduct.getUuid();
    APIProductIdentifier apiProductIdentifier = apiProduct.getId();
    try {
        if (artifactSaver != null) {
            artifactSaver.removeArtifact(apiProductUuid, apiProductIdentifier.getName(), apiProductIdentifier.getVersion(), APIConstants.API_PRODUCT_REVISION, tenantDomain);
        }
        GatewayArtifactsMgtDAO.getInstance().deleteGatewayArtifact(apiProductUuid, APIConstants.API_PRODUCT_REVISION);
        GatewayArtifactsMgtDAO.getInstance().removePublishedGatewayLabels(apiProductUuid, APIConstants.API_PRODUCT_REVISION);
    } catch (ArtifactSynchronizerException e) {
        throw new APIManagementException("API " + apiProductIdentifier + "couldn't get unDeployed", e);
    }
    if (debugEnabled) {
        log.debug("Status of " + apiProductIdentifier + " has been updated to DB");
    }
    sendUnDeploymentEvent(apiProduct, tenantDomain, gatewaysToRemove, associatedAPIs);
}
Also used : APIProductIdentifier(org.wso2.carbon.apimgt.api.model.APIProductIdentifier) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ArtifactSynchronizerException(org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.exception.ArtifactSynchronizerException)

Example 29 with APIProduct

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

the class APIProviderImpl method getAPIProductbyUUID.

public APIProduct getAPIProductbyUUID(String uuid, String organization) throws APIManagementException {
    try {
        Organization org = new Organization(organization);
        PublisherAPIProduct publisherAPIProduct = apiPersistenceInstance.getPublisherAPIProduct(org, uuid);
        if (publisherAPIProduct != null) {
            APIProduct product = APIProductMapper.INSTANCE.toApiProduct(publisherAPIProduct);
            product.setID(new APIProductIdentifier(publisherAPIProduct.getProviderName(), publisherAPIProduct.getApiProductName(), publisherAPIProduct.getVersion(), uuid));
            checkAccessControlPermission(userNameWithoutChange, product.getAccessControl(), product.getAccessControlRoles());
            populateRevisionInformation(product, uuid);
            populateAPIProductInformation(uuid, organization, product);
            populateAPIStatus(product);
            populateAPITier(product);
            return product;
        } else {
            String msg = "Failed to get API Product. API Product artifact corresponding to artifactId " + uuid + " does not exist";
            throw new APIMgtResourceNotFoundException(msg);
        }
    } catch (APIPersistenceException | OASPersistenceException | ParseException e) {
        String msg = "Failed to get API Product";
        throw new APIManagementException(msg, e);
    }
}
Also used : PublisherAPIProduct(org.wso2.carbon.apimgt.persistence.dto.PublisherAPIProduct) APIProduct(org.wso2.carbon.apimgt.api.model.APIProduct) APIProductIdentifier(org.wso2.carbon.apimgt.api.model.APIProductIdentifier) APIPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException) Organization(org.wso2.carbon.apimgt.persistence.dto.Organization) OASPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.OASPersistenceException) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) PublisherAPIProduct(org.wso2.carbon.apimgt.persistence.dto.PublisherAPIProduct) ParseException(org.json.simple.parser.ParseException) APIMgtResourceNotFoundException(org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException)

Example 30 with APIProduct

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

the class APIProviderImpl method deleteAPIProduct.

@Override
public void deleteAPIProduct(APIProductIdentifier identifier, String apiProductUUID, String organization) throws APIManagementException {
    if (StringUtils.isEmpty(apiProductUUID)) {
        if (identifier.getUUID() != null) {
            apiProductUUID = identifier.getUUID();
        } else {
            apiProductUUID = apiMgtDAO.getUUIDFromIdentifier(identifier, organization);
        }
    }
    APIProduct apiProduct = getAPIProductbyUUID(apiProductUUID, organization);
    apiProduct.setOrganization(organization);
    deleteAPIProduct(apiProduct);
}
Also used : PublisherAPIProduct(org.wso2.carbon.apimgt.persistence.dto.PublisherAPIProduct) APIProduct(org.wso2.carbon.apimgt.api.model.APIProduct)

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