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();
}
}
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;
}
}
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;
}
}
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();
}
}
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;
}
Aggregations