Java Code Examples for org.wso2.carbon.apimgt.api.model.API#getUUID()

The following examples show how to use org.wso2.carbon.apimgt.api.model.API#getUUID() . 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: APIAdminImpl.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
public boolean isAttachedLabel(String user, String labelId) throws APIManagementException {

        APIProviderImpl apiProvider = new APIProviderImpl(user);
        List<API> apiList = apiProvider.getAllAPIs();
        List<Label> allLabelsWithID = getAllLabels(MultitenantUtils.getTenantDomain(user));
        String labelName = null;
        for (Label label : allLabelsWithID) {
            if (labelId.equalsIgnoreCase(label.getLabelId())) {
                labelName = label.getName();
                break;
            }
        }
        if (labelName != null && !StringUtils.isEmpty(labelName)) {
            UserAwareAPIProvider userAwareAPIProvider = new UserAwareAPIProvider(user);
            for (API api : apiList) {
                String uuid = api.getUUID();
                API lightweightAPIByUUID = userAwareAPIProvider.getLightweightAPIByUUID(uuid, apiProvider.
                        tenantDomain);
                List<Label> attachedLabelsWithoutID = lightweightAPIByUUID.getGatewayLabels();
                for (Label labelWithoutId : attachedLabelsWithoutID) {
                    if (labelName.equalsIgnoreCase(labelWithoutId.getName())) {
                        return true;
                    }
                }
            }
        }
        return false;
    }
 
Example 2
Source File: APIGatewayManager.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
public Map<String, String> removeDefaultAPIFromGateway(API api, String tenantDomain) {

        Map<String, String> failedEnvironmentsMap = new HashMap<String, String>(0);
        LocalEntryAdminClient localEntryAdminClient;
        String localEntryUUId = api.getUUID();
        if (api.getEnvironments() != null) {
            for (String environmentName : api.getEnvironments()) {
                try {
                    Environment environment = environments.get(environmentName);
                    APIGatewayAdminClient client = new APIGatewayAdminClient(environment);
                    APIIdentifier id = api.getId();
                    if (client.getDefaultApi(tenantDomain, id) != null) {
                        if (debugEnabled) {
                            log.debug("Removing Default API " + api.getId().getApiName() + " From environment " +
                                    environment.getName());
                        }
                        client.deleteDefaultApi(tenantDomain, api.getId());
                    }
                    if (APIConstants.APITransportType.GRAPHQL.toString().equals(api.getType())) {
                        localEntryUUId = localEntryUUId + APIConstants.GRAPHQL_LOCAL_ENTRY_EXTENSION;
                    }
                    localEntryAdminClient = new LocalEntryAdminClient(environment, tenantDomain);
                    localEntryAdminClient.deleteEntry(localEntryUUId);
                } catch (AxisFault axisFault) {
                    /*
                didn't throw this exception to handle multiple gateway publishing
                if gateway is unreachable we collect that environments into map with issue and show on popup in ui
                therefore this didn't break the gateway unpublisihing if one gateway unreachable
                 */
                    log.error("Error occurred when removing default api from gateway " + environmentName, axisFault);
                    failedEnvironmentsMap.put(environmentName, axisFault.getMessage());
                }
            }
        }
        return failedEnvironmentsMap;
    }
 
Example 3
Source File: APIGatewayManager.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
/**
 * Create a DTO object required to remove the API from a given gateway environment
 *
 * @param api                   - The API to be published
 * @param tenantDomain          - Tenant Domain of the publisher
 * @param environment           - Gateway environment
 * @return DTO object with API artifacts
 */
public GatewayAPIDTO createGatewayAPIDTOtoRemoveAPI(API api, String tenantDomain, Environment environment)
        throws CertificateManagementException {

    GatewayAPIDTO gatewayAPIDTO = new GatewayAPIDTO();
    gatewayAPIDTO.setName(api.getId().getName());
    gatewayAPIDTO.setVersion(api.getId().getVersion());
    gatewayAPIDTO.setProvider(api.getId().getProviderName());
    gatewayAPIDTO.setTenantDomain(tenantDomain);
    gatewayAPIDTO.setOverride(true);
    gatewayAPIDTO.setApiId(api.getUUID());

    setClientCertificatesToBeRemoved(api, tenantDomain, gatewayAPIDTO);
    setEndpointsToBeRemoved(api, gatewayAPIDTO);
    if (!APIConstants.APITransportType.WS.toString().equals(api.getType())) {
        if (debugEnabled) {
            log.debug("Removing API " + api.getId().getApiName() + " From environment " +
                    environment.getName());
        }
        setCustomSequencesToBeRemoved(api, gatewayAPIDTO);
        setCustomSequencesToBeRemoved(api, gatewayAPIDTO);
    } else {
        String fileName = api.getContext().replace('/', '-');
        String[] fileNames = new String[2];
        fileNames[0] = ENDPOINT_PRODUCTION + fileName;
        fileNames[1] = ENDPOINT_SANDBOX + fileName;
        gatewayAPIDTO.setSequencesToBeRemove(addStringToList(fileNames[0],
                gatewayAPIDTO.getSequencesToBeRemove()));
        gatewayAPIDTO.setSequencesToBeRemove(addStringToList(fileNames[1],
                gatewayAPIDTO.getSequencesToBeRemove()));
    }

    String localEntryUUId = api.getUUID();
    if (localEntryUUId != null && !localEntryUUId.isEmpty()) {
        if (APIConstants.APITransportType.GRAPHQL.toString().equals(api.getType())) {
            localEntryUUId = localEntryUUId + APIConstants.GRAPHQL_LOCAL_ENTRY_EXTENSION;
        }
        gatewayAPIDTO.setLocalEntriesToBeRemove(addStringToList(localEntryUUId,
                gatewayAPIDTO.getLocalEntriesToBeRemove()));
    }
    return gatewayAPIDTO;
}