Java Code Examples for org.wso2.carbon.apimgt.impl.utils.APIUtil#getAPIPath()

The following examples show how to use org.wso2.carbon.apimgt.impl.utils.APIUtil#getAPIPath() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractAPIManager.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
public API getAPI(APIIdentifier identifier, APIIdentifier oldIdentifier, String oldContext) throws
        APIManagementException {
    String apiPath = APIUtil.getAPIPath(identifier);
    try {
        GenericArtifactManager artifactManager = getAPIGenericArtifactManagerFromUtil(registry,
                APIConstants.API_KEY);
        Resource apiResource = registry.get(apiPath);
        String artifactId = apiResource.getUUID();
        if (artifactId == null) {
            throw new APIManagementException("artifact id is null for : " + apiPath);
        }
        GenericArtifact apiArtifact = artifactManager.getGenericArtifact(artifactId);
        return APIUtil.getAPI(apiArtifact, registry, oldIdentifier, oldContext);

    } catch (RegistryException e) {
        String msg = "Failed to get API from : " + apiPath;
        throw new APIManagementException(msg, e);
    }
}
 
Example 2
Source File: APIKeyMgtUtil.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
/**
 * This returns API object for given APIIdentifier. Reads from registry entry for given APIIdentifier
 * creates API object
 *
 * @param identifier APIIdentifier object for the API
 * @return API object for given identifier
 * @throws APIManagementException on error in getting API artifact
 */
public static API getAPI(APIIdentifier identifier) throws APIManagementException {
    String apiPath = APIUtil.getAPIPath(identifier);

    try {
        Registry registry = APIKeyMgtDataHolder.getRegistryService().getGovernanceSystemRegistry();
        GenericArtifactManager artifactManager = APIUtil.getArtifactManager(registry,
                APIConstants.API_KEY);
        if (artifactManager == null) {
            String errorMessage = "Artifact manager is null when retrieving API " + identifier.getApiName();
            log.error(errorMessage);
            throw new APIManagementException(errorMessage);
        }
        Resource apiResource = registry.get(apiPath);
        String artifactId = apiResource.getUUID();
        if (artifactId == null) {
            throw new APIManagementException("artifact id is null for : " + apiPath);
        }
        GenericArtifact apiArtifact = artifactManager.getGenericArtifact(artifactId);
        return APIUtil.getAPI(apiArtifact, registry);

    } catch (RegistryException e) {
        return null;
    }
}
 
Example 3
Source File: AbstractAPIManager.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
public List<Documentation> getAllDocumentation(Identifier id) throws APIManagementException {
    List<Documentation> documentationList = new ArrayList<Documentation>();
    String resourcePath = StringUtils.EMPTY;
    String docArtifactKeyType = StringUtils.EMPTY;
    if (id instanceof APIIdentifier) {
        resourcePath = APIUtil.getAPIPath((APIIdentifier) id);
    } else if (id instanceof APIProductIdentifier) {
        resourcePath = APIUtil.getAPIProductPath((APIProductIdentifier) id);
    }
    docArtifactKeyType = APIConstants.DOCUMENTATION_KEY;

    try {
        Association[] docAssociations = registry.getAssociations(resourcePath,
                APIConstants.DOCUMENTATION_ASSOCIATION);
        if (docAssociations == null) {
            return documentationList;
        }
        for (Association association : docAssociations) {
            String docPath = association.getDestinationPath();

            Resource docResource = registry.get(docPath);
            GenericArtifactManager artifactManager = getAPIGenericArtifactManager(registry,
                    docArtifactKeyType);
            GenericArtifact docArtifact = artifactManager.getGenericArtifact(docResource.getUUID());
            Documentation doc = APIUtil.getDocumentation(docArtifact);
            Date contentLastModifiedDate;
            Date docLastModifiedDate = docResource.getLastModified();
            if (Documentation.DocumentSourceType.INLINE.equals(doc.getSourceType()) || Documentation.DocumentSourceType.MARKDOWN.equals(doc.getSourceType())) {
                String contentPath = StringUtils.EMPTY;
                if (id instanceof APIIdentifier) {
                    contentPath = APIUtil.getAPIDocContentPath((APIIdentifier) id, doc.getName());
                } else if (id instanceof APIProductIdentifier) {
                    contentPath = APIUtil.getProductDocContentPath((APIProductIdentifier) id, doc.getName());
                }

                contentLastModifiedDate = registry.get(contentPath).getLastModified();
                doc.setLastUpdated((contentLastModifiedDate.after(docLastModifiedDate) ?
                        contentLastModifiedDate : docLastModifiedDate));
            } else {
                doc.setLastUpdated(docLastModifiedDate);
            }
            documentationList.add(doc);
        }

    } catch (RegistryException e) {
        String msg = "Failed to get documentations for api/product " + id.getName();
        throw new APIManagementException(msg, e);
    }
    return documentationList;
}
 
Example 4
Source File: AbstractAPIManager.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
public Set<API> getSubscriberAPIs(Subscriber subscriber) throws APIManagementException {
    SortedSet<API> apiSortedSet = new TreeSet<API>(new APINameComparator());
    Set<SubscribedAPI> subscribedAPIs = apiMgtDAO.getSubscribedAPIs(subscriber, null);
    for (SubscribedAPI subscribedApi : subscribedAPIs) {
        Application application = subscribedApi.getApplication();
        if (application != null) {
            int applicationId = application.getId();
            Set<APIKey> keys = getApplicationKeys(applicationId);
            for (APIKey key : keys) {
                application.addKey(key);
            }
        }
    }
    boolean isTenantFlowStarted = false;
    try {
        if (tenantDomain != null && !MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
            isTenantFlowStarted = true;
            startTenantFlow(tenantDomain);
        }
        for (SubscribedAPI subscribedAPI : subscribedAPIs) {
            String apiPath = APIUtil.getAPIPath(subscribedAPI.getApiId());
            Resource resource;
            try {
                resource = registry.get(apiPath);
                GenericArtifactManager artifactManager = getAPIGenericArtifactManager(registry,
                        APIConstants.API_KEY);
                GenericArtifact artifact = artifactManager.getGenericArtifact(
                        resource.getUUID());
                API api = getAPI(artifact);
                if (api != null) {
                    apiSortedSet.add(api);
                }
            } catch (RegistryException e) {
                String msg = "Failed to get APIs for subscriber: " + subscriber.getName();
                throw  new APIManagementException(msg, e);
            }
        }
    } finally {
        if (isTenantFlowStarted) {
            endTenantFlow();
        }
    }
    return apiSortedSet;
}