Search in sources :

Example 16 with APIProductIdentifier

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

the class AbstractAPIManagerTestCase method testIsAPIProductAvailable.

@Test
public void testIsAPIProductAvailable() throws APIManagementException {
    APIProductIdentifier apiProductIdentifier = getAPIProductIdentifier(SAMPLE_API_NAME, API_PROVIDER, SAMPLE_API_VERSION);
    String organization = "carbon.super";
    String path = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + apiProductIdentifier.getProviderName() + RegistryConstants.PATH_SEPARATOR + apiProductIdentifier.getName() + RegistryConstants.PATH_SEPARATOR + apiProductIdentifier.getVersion();
    AbstractAPIManager abstractAPIManager = new AbstractAPIManagerWrapper(apiMgtDAO);
    Mockito.when(apiMgtDAO.getUUIDFromIdentifier(apiProductIdentifier, organization)).thenReturn("xxxxx");
    Assert.assertTrue(abstractAPIManager.isAPIProductAvailable(apiProductIdentifier, organization));
}
Also used : APIProductIdentifier(org.wso2.carbon.apimgt.api.model.APIProductIdentifier) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 17 with APIProductIdentifier

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

the class APIProviderImpl method deleteAPIProduct.

public void deleteAPIProduct(APIProduct apiProduct) throws APIManagementException {
    APIProductIdentifier identifier = apiProduct.getId();
    try {
        // int apiId = apiMgtDAO.getAPIID(identifier, null);
        long subsCount = apiMgtDAO.getAPISubscriptionCountByAPI(identifier);
        if (subsCount > 0) {
            // Logging as a WARN since this isn't an error scenario.
            String message = "Cannot remove the API Product as active subscriptions exist.";
            log.warn(message);
            throw new APIManagementException(message);
        }
        // gatewayType check is required when API Management is deployed on
        // other servers to avoid synapse
        deleteAPIProductRevisions(apiProduct.getUuid(), apiProduct.getOrganization());
        apiPersistenceInstance.deleteAPIProduct(new Organization(apiProduct.getOrganization()), apiProduct.getUuid());
        apiMgtDAO.deleteAPIProduct(identifier);
        cleanUpPendingAPIStateChangeTask(apiProduct.getProductId(), true);
        if (log.isDebugEnabled()) {
            String logMessage = "API Product Name: " + identifier.getName() + ", API Product Version " + identifier.getVersion() + " successfully removed from the database.";
            log.debug(logMessage);
        }
        JSONObject apiLogObject = new JSONObject();
        apiLogObject.put(APIConstants.AuditLogConstants.NAME, identifier.getName());
        apiLogObject.put(APIConstants.AuditLogConstants.VERSION, identifier.getVersion());
        apiLogObject.put(APIConstants.AuditLogConstants.PROVIDER, identifier.getProviderName());
        APIUtil.logAuditMessage(APIConstants.AuditLogConstants.API_PRODUCT, apiLogObject.toString(), APIConstants.AuditLogConstants.DELETED, this.username);
        GatewayArtifactsMgtDAO.getInstance().deleteGatewayArtifacts(apiProduct.getUuid());
    } catch (APIPersistenceException e) {
        handleException("Failed to remove the API product", e);
    } catch (WorkflowException e) {
        handleException("Error while removing the pending workflows of API Product", e);
    }
}
Also used : APIProductIdentifier(org.wso2.carbon.apimgt.api.model.APIProductIdentifier) APIPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException) Organization(org.wso2.carbon.apimgt.persistence.dto.Organization) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) JSONObject(org.json.simple.JSONObject) WorkflowException(org.wso2.carbon.apimgt.impl.workflow.WorkflowException)

Example 18 with APIProductIdentifier

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

the class APIProviderImpl method updateAPIProductDisplayOnDevportal.

@Override
public void updateAPIProductDisplayOnDevportal(String apiProductId, String apiRevisionId, APIRevisionDeployment apiRevisionDeployment) throws APIManagementException {
    APIProductIdentifier apiProductIdentifier = APIUtil.getAPIProductIdentifierFromUUID(apiProductId);
    if (apiProductIdentifier == null) {
        throw new APIMgtResourceNotFoundException("Couldn't retrieve existing API Product with ID: " + apiProductId, ExceptionCodes.from(ExceptionCodes.API_NOT_FOUND, apiProductId));
    }
    APIRevision apiRevision = apiMgtDAO.getRevisionByRevisionUUID(apiRevisionId);
    if (apiRevision == null) {
        throw new APIMgtResourceNotFoundException("Couldn't retrieve existing API Revision with Revision UUID: " + apiRevisionId, ExceptionCodes.from(ExceptionCodes.API_REVISION_NOT_FOUND, apiRevisionId));
    }
    List<APIRevisionDeployment> currentApiRevisionDeploymentList = apiMgtDAO.getAPIRevisionDeploymentsByApiUUID(apiProductId);
    Set<APIRevisionDeployment> environmentsToUpdate = new HashSet<>();
    for (APIRevisionDeployment currentapiRevisionDeployment : currentApiRevisionDeploymentList) {
        if (StringUtils.equalsIgnoreCase(currentapiRevisionDeployment.getDeployment(), apiRevisionDeployment.getDeployment())) {
            environmentsToUpdate.add(apiRevisionDeployment);
        }
    }
    if (environmentsToUpdate.size() > 0) {
        apiMgtDAO.updateAPIRevisionDeployment(apiProductId, environmentsToUpdate);
    } else {
        throw new APIMgtResourceNotFoundException("deployment with " + apiRevisionDeployment.getDeployment() + " not found", ExceptionCodes.from(ExceptionCodes.EXISTING_DEPLOYMENT_NOT_FOUND, apiRevisionDeployment.getDeployment()));
    }
}
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) APIRevisionDeployment(org.wso2.carbon.apimgt.api.model.APIRevisionDeployment) APIMgtResourceNotFoundException(org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 19 with APIProductIdentifier

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

the class APIProviderImpl method searchPaginatedContent.

@Override
public Map<String, Object> searchPaginatedContent(String searchQuery, String organization, int start, int end) throws APIManagementException {
    ArrayList<Object> compoundResult = new ArrayList<Object>();
    Map<Documentation, API> docMap = new HashMap<Documentation, API>();
    Map<Documentation, APIProduct> productDocMap = new HashMap<Documentation, APIProduct>();
    Map<String, Object> result = new HashMap<String, Object>();
    SortedSet<API> apiSet = new TreeSet<API>(new APINameComparator());
    SortedSet<APIProduct> apiProductSet = new TreeSet<APIProduct>(new APIProductNameComparator());
    String userame = userNameWithoutChange;
    Organization org = new Organization(organization);
    Map<String, Object> properties = APIUtil.getUserProperties(userame);
    String[] roles = APIUtil.getFilteredUserRoles(userame);
    UserContext ctx = new UserContext(userame, org, properties, roles);
    try {
        PublisherContentSearchResult results = apiPersistenceInstance.searchContentForPublisher(org, searchQuery, start, end, ctx);
        if (results != null) {
            List<SearchContent> resultList = results.getResults();
            for (SearchContent item : resultList) {
                if ("API".equals(item.getType())) {
                    PublisherSearchContent publiserAPI = (PublisherSearchContent) item;
                    API api = new API(new APIIdentifier(publiserAPI.getProvider(), publiserAPI.getName(), publiserAPI.getVersion()));
                    api.setUuid(publiserAPI.getId());
                    api.setContext(publiserAPI.getContext());
                    api.setContextTemplate(publiserAPI.getContext());
                    api.setStatus(publiserAPI.getStatus());
                    apiSet.add(api);
                } else if ("APIProduct".equals(item.getType())) {
                    PublisherSearchContent publiserAPI = (PublisherSearchContent) item;
                    APIProduct api = new APIProduct(new APIProductIdentifier(publiserAPI.getProvider(), publiserAPI.getName(), publiserAPI.getVersion()));
                    api.setUuid(publiserAPI.getId());
                    api.setContextTemplate(publiserAPI.getContext());
                    api.setState(publiserAPI.getStatus());
                    apiProductSet.add(api);
                } else if (item instanceof DocumentSearchContent) {
                    // doc item
                    DocumentSearchContent docItem = (DocumentSearchContent) item;
                    Documentation doc = new Documentation(DocumentationType.valueOf(docItem.getDocType().toString()), docItem.getName());
                    doc.setSourceType(DocumentSourceType.valueOf(docItem.getSourceType().toString()));
                    doc.setVisibility(DocumentVisibility.valueOf(docItem.getVisibility().toString()));
                    doc.setId(docItem.getId());
                    if ("API".equals(docItem.getAssociatedType())) {
                        API api = new API(new APIIdentifier(docItem.getApiProvider(), docItem.getApiName(), docItem.getApiVersion()));
                        api.setUuid(docItem.getApiUUID());
                        docMap.put(doc, api);
                    } else if ("APIProduct".equals(docItem.getAssociatedType())) {
                        APIProduct api = new APIProduct(new APIProductIdentifier(docItem.getApiProvider(), docItem.getApiName(), docItem.getApiVersion()));
                        api.setUuid(docItem.getApiUUID());
                        productDocMap.put(doc, api);
                    }
                }
            }
            compoundResult.addAll(apiSet);
            compoundResult.addAll(apiProductSet);
            compoundResult.addAll(docMap.entrySet());
            compoundResult.addAll(productDocMap.entrySet());
            compoundResult.sort(new ContentSearchResultNameComparator());
            result.put("length", results.getTotalCount());
        } else {
            result.put("length", compoundResult.size());
        }
    } catch (APIPersistenceException e) {
        throw new APIManagementException("Error while searching content ", e);
    }
    result.put("apis", compoundResult);
    return result;
}
Also used : Organization(org.wso2.carbon.apimgt.persistence.dto.Organization) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) APINameComparator(org.wso2.carbon.apimgt.impl.utils.APINameComparator) PublisherAPIProduct(org.wso2.carbon.apimgt.persistence.dto.PublisherAPIProduct) APIProduct(org.wso2.carbon.apimgt.api.model.APIProduct) APIProductIdentifier(org.wso2.carbon.apimgt.api.model.APIProductIdentifier) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) TreeSet(java.util.TreeSet) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) SearchContent(org.wso2.carbon.apimgt.persistence.dto.SearchContent) DocumentSearchContent(org.wso2.carbon.apimgt.persistence.dto.DocumentSearchContent) PublisherSearchContent(org.wso2.carbon.apimgt.persistence.dto.PublisherSearchContent) APIPersistenceException(org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException) PublisherSearchContent(org.wso2.carbon.apimgt.persistence.dto.PublisherSearchContent) DocumentSearchContent(org.wso2.carbon.apimgt.persistence.dto.DocumentSearchContent) UserContext(org.wso2.carbon.apimgt.persistence.dto.UserContext) Documentation(org.wso2.carbon.apimgt.api.model.Documentation) PublisherContentSearchResult(org.wso2.carbon.apimgt.persistence.dto.PublisherContentSearchResult) JSONObject(org.json.simple.JSONObject) 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) ContentSearchResultNameComparator(org.wso2.carbon.apimgt.impl.utils.ContentSearchResultNameComparator) APIProductNameComparator(org.wso2.carbon.apimgt.impl.utils.APIProductNameComparator)

Example 20 with APIProductIdentifier

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

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