Search in sources :

Example 1 with ExportResult

use of com.axway.apim.lib.ExportResult in project apim-cli by Axway-API-Management-Plus.

the class APIExportApp method upgradeAccess.

@CLIServiceMethod(name = "upgrade-access", description = "Upgrades access for one or more APIs based on a given 'old/reference' API.")
public static int upgradeAccess(String[] args) {
    try {
        deleteInstances();
        APIUpgradeAccessParams params = (APIUpgradeAccessParams) CLIAPIUpgradeAccessOptions.create(args).getParams();
        APIExportApp app = new APIExportApp();
        ExportResult result = app.uprgradeAPI(params, APIListImpl.API_UPGRADE_ACCESS_HANDLE);
        return result.getRc();
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
        return ErrorCode.UNXPECTED_ERROR.getCode();
    }
}
Also used : APIUpgradeAccessParams(com.axway.apim.api.export.lib.params.APIUpgradeAccessParams) AppException(com.axway.apim.lib.errorHandling.AppException) ExportResult(com.axway.apim.lib.ExportResult) CLIServiceMethod(com.axway.apim.cli.CLIServiceMethod)

Example 2 with ExportResult

use of com.axway.apim.lib.ExportResult in project apim-cli by Axway-API-Management-Plus.

the class APIExportApp method uprgradeAPI.

public ExportResult uprgradeAPI(APIUpgradeAccessParams params, APIListImpl resultHandlerImpl) {
    ExportResult result = new ExportResult();
    try {
        params.validateRequiredParameters();
        // We need to clean some Singleton-Instances, as tests are running in the same JVM
        APIManagerAdapter.deleteInstance();
        APIMHttpClient.deleteInstances();
        APIManagerAdapter apimanagerAdapter = APIManagerAdapter.getInstance();
        if (!APIManagerAdapter.hasAdminAccount()) {
            LOG.error("Upgrading API-Access needs admin access.");
            result.setError(ErrorCode.NO_ADMIN_ROLE_USER);
            return result;
        }
        // Get the reference API from API-Manager
        API referenceAPI = apimanagerAdapter.apiAdapter.getAPI(params.getReferenceAPIFilter(), true);
        if (referenceAPI == null) {
            LOG.info("Published reference API for upgrade access not found using filter: " + params.getReferenceAPIFilter());
            return result;
        }
        params.setReferenceAPI(referenceAPI);
        // Get all APIs to be upgraded
        APIResultHandler resultHandler = APIResultHandler.create(resultHandlerImpl, params);
        APIFilter filter = resultHandler.getFilter();
        List<API> apis = apimanagerAdapter.apiAdapter.getAPIs(filter, true);
        if (apis.size() == 0) {
            LOG.info("No published APIs found using filter: " + filter);
        } else {
            LOG.info(apis.size() + " API(s) selected.");
            resultHandler.execute(apis);
            if (resultHandler.hasError()) {
                LOG.info("");
                LOG.error("Please check the log. At least one error was recorded.");
            } else {
                LOG.debug("Successfully selected " + apis.size() + " API(s).");
            }
        }
        return result;
    } catch (AppException ap) {
        ap.logException(LOG);
        result.setError(errorCodeMapper.getMapedErrorCode(ap.getError()));
        return result;
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
        result.setError(ErrorCode.UNXPECTED_ERROR);
        return result;
    }
}
Also used : APIFilter(com.axway.apim.adapter.apis.APIFilter) AppException(com.axway.apim.lib.errorHandling.AppException) API(com.axway.apim.api.API) APIManagerAdapter(com.axway.apim.adapter.APIManagerAdapter) APIResultHandler(com.axway.apim.api.export.impl.APIResultHandler) AppException(com.axway.apim.lib.errorHandling.AppException) ExportResult(com.axway.apim.lib.ExportResult)

Example 3 with ExportResult

use of com.axway.apim.lib.ExportResult in project apim-cli by Axway-API-Management-Plus.

the class APIExportApp method grantAccessToAPI.

public ExportResult grantAccessToAPI(APIGrantAccessParams params, APIListImpl resultHandlerImpl) {
    ExportResult result = new ExportResult();
    try {
        params.validateRequiredParameters();
        // We need to clean some Singleton-Instances, as tests are running in the same JVM
        APIManagerAdapter.deleteInstance();
        APIMHttpClient.deleteInstances();
        APIManagerAdapter apimanagerAdapter = APIManagerAdapter.getInstance();
        if (!APIManagerAdapter.hasAdminAccount()) {
            LOG.error("Upgrading API-Access needs admin access.");
            result.setError(ErrorCode.NO_ADMIN_ROLE_USER);
            return result;
        }
        // Get all organizations that should be granted
        List<Organization> orgs = apimanagerAdapter.orgAdapter.getOrgs(params.getOrganizationFilter());
        if (orgs == null || orgs.size() == 0) {
            LOG.info("No organization found to grant access to using filter: " + params.getOrganizationFilter());
            return result;
        }
        // Get all APIs that should be granted access
        List<API> apis = apimanagerAdapter.apiAdapter.getAPIs(params.getAPIFilter(), true);
        if (apis == null || apis.size() == 0) {
            LOG.info("No published APIs to grant access to found using filter: " + params.getAPIFilter());
            return result;
        }
        LOG.info(apis.size() + " API(s) and " + orgs.size() + " Organization(s) selected.");
        params.setOrgs(orgs);
        params.setApis(apis);
        APIResultHandler resultHandler = APIResultHandler.create(resultHandlerImpl, params);
        resultHandler.execute(apis);
        if (resultHandler.hasError()) {
            LOG.info("");
            LOG.error("Please check the log. At least one error was recorded.");
        } else {
            LOG.debug("Successfully selected " + apis.size() + " API(s).");
        }
        return result;
    } catch (AppException ap) {
        ap.logException(LOG);
        result.setError(errorCodeMapper.getMapedErrorCode(ap.getError()));
        return result;
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
        result.setError(ErrorCode.UNXPECTED_ERROR);
        return result;
    }
}
Also used : AppException(com.axway.apim.lib.errorHandling.AppException) Organization(com.axway.apim.api.model.Organization) API(com.axway.apim.api.API) APIManagerAdapter(com.axway.apim.adapter.APIManagerAdapter) APIResultHandler(com.axway.apim.api.export.impl.APIResultHandler) AppException(com.axway.apim.lib.errorHandling.AppException) ExportResult(com.axway.apim.lib.ExportResult)

Example 4 with ExportResult

use of com.axway.apim.lib.ExportResult in project apim-cli by Axway-API-Management-Plus.

the class APIExportApp method grantAccess.

@CLIServiceMethod(name = "grant-access", description = "Grant access to selected APIs to the given organization.")
public static int grantAccess(String[] args) {
    try {
        deleteInstances();
        APIGrantAccessParams params = (APIGrantAccessParams) CLIAPIGrantAccessOptions.create(args).getParams();
        APIExportApp app = new APIExportApp();
        ExportResult result = app.grantAccessToAPI(params, APIListImpl.API_GRANT_ACCESS_HANDLER);
        return result.getRc();
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
        return ErrorCode.UNXPECTED_ERROR.getCode();
    }
}
Also used : APIGrantAccessParams(com.axway.apim.api.export.lib.params.APIGrantAccessParams) AppException(com.axway.apim.lib.errorHandling.AppException) ExportResult(com.axway.apim.lib.ExportResult) CLIServiceMethod(com.axway.apim.cli.CLIServiceMethod)

Example 5 with ExportResult

use of com.axway.apim.lib.ExportResult in project apim-cli by Axway-API-Management-Plus.

the class ExportManagerConfigTestAction method runTest.

@Override
public ExportResult runTest(TestContext context) {
    APIManagerSetupExportParams params = new APIManagerSetupExportParams();
    addParameters(params, context);
    params.setRemoteHostName(getVariable(context, PARAM_NAME));
    params.setRemoteHostId(getVariable(context, PARAM_ID));
    APIManagerSettingsApp app = new APIManagerSettingsApp();
    LOG.info("Running " + app.getClass().getSimpleName() + " with params: " + params);
    ExportResult result = app.runExport(params);
    if (this.getExpectedReturnCode(context) != result.getRc()) {
        throw new ValidationException("Expected RC was: " + this.getExpectedReturnCode(context) + " but got: " + result.getRc());
    }
    return result;
}
Also used : APIManagerSetupExportParams(com.axway.apim.setup.lib.APIManagerSetupExportParams) ValidationException(com.consol.citrus.exceptions.ValidationException) APIManagerSettingsApp(com.axway.apim.setup.APIManagerSettingsApp) ExportResult(com.axway.apim.lib.ExportResult)

Aggregations

ExportResult (com.axway.apim.lib.ExportResult)8 AppException (com.axway.apim.lib.errorHandling.AppException)4 ValidationException (com.consol.citrus.exceptions.ValidationException)4 APIManagerAdapter (com.axway.apim.adapter.APIManagerAdapter)2 API (com.axway.apim.api.API)2 APIResultHandler (com.axway.apim.api.export.impl.APIResultHandler)2 CLIServiceMethod (com.axway.apim.cli.CLIServiceMethod)2 APIFilter (com.axway.apim.adapter.apis.APIFilter)1 APIGrantAccessParams (com.axway.apim.api.export.lib.params.APIGrantAccessParams)1 APIUpgradeAccessParams (com.axway.apim.api.export.lib.params.APIUpgradeAccessParams)1 Organization (com.axway.apim.api.model.Organization)1 ApplicationExportApp (com.axway.apim.appexport.ApplicationExportApp)1 AppExportParams (com.axway.apim.appexport.lib.AppExportParams)1 OrganizationApp (com.axway.apim.organization.OrganizationApp)1 OrgExportParams (com.axway.apim.organization.lib.OrgExportParams)1 APIManagerSettingsApp (com.axway.apim.setup.APIManagerSettingsApp)1 APIManagerSetupExportParams (com.axway.apim.setup.lib.APIManagerSetupExportParams)1 UserApp (com.axway.apim.users.UserApp)1 UserExportParams (com.axway.apim.users.lib.params.UserExportParams)1