Skip to content

Commit

Permalink
- Fix error code mapping for org, user and settings import
Browse files Browse the repository at this point in the history
  • Loading branch information
rathnapandi committed Oct 30, 2024
1 parent a5fd9b4 commit b2e7e02
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ public String getGroupDescription() {
@CLIServiceMethod(name = "get", description = "Get Organizations from API-Manager in different formats")
public static int exportOrgs(String[] args) {
OrgExportParams params;
ErrorCodeMapper errorCodeMapper = new ErrorCodeMapper();
try {
params = (OrgExportParams) OrgExportCLIOptions.create(args).getParams();
errorCodeMapper.setMapConfiguration(params.getReturnCodeMapping());
} catch (AppException e) {
LOG.error("Error {}", e.getMessage());
return e.getError().getCode();
return errorCodeMapper.getMapedErrorCode(e.getError()).getCode();
}
return exportOrgs(params).getRc();
return errorCodeMapper.getMapedErrorCode(exportOrgs(params).getErrorCode()).getCode();
}

public static ExportResult exportOrgs(OrgExportParams params) {
Expand All @@ -72,7 +74,7 @@ public static ExportResult exportOrgs(OrgExportParams params) {
}
} catch (AppException e) {
e.logException(LOG);
result.setError(new ErrorCodeMapper().getMapedErrorCode(e.getError()));
result.setError(e.getError());
return result;
} catch (Exception e) {
LOG.error(e.getMessage(), e);
Expand Down Expand Up @@ -117,6 +119,7 @@ public static int importOrganization(String[] args) {
ErrorCodeMapper errorCodeMapper = new ErrorCodeMapper();
try {
params = (OrgImportParams) OrgImportCLIOptions.create(args).getParams();
errorCodeMapper.setMapConfiguration(params.getReturnCodeMapping());
} catch (AppException e) {
LOG.error("Error importing org {}", e.getMessage());
return errorCodeMapper.getMapedErrorCode(e.getError()).getCode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,16 @@ public static int exportConfig(String[] args) {
@CLIServiceMethod(name = "import", description = "Import configuration into API-Manager")
public static int importConfig(String[] args) {
StandardImportParams params;
ErrorCodeMapper errorCodeMapper = new ErrorCodeMapper();
try {
params = (StandardImportParams) APIManagerSetupImportCLIOptions.create(args).getParams();
errorCodeMapper.setMapConfiguration(params.getReturnCodeMapping());
} catch (AppException e) {
LOG.error("Error {}", e.getMessage());
return e.getError().getCode();
return errorCodeMapper.getMapedErrorCode(e.getError()).getCode();
}
APIManagerSettingsApp managerConfigApp = new APIManagerSettingsApp();
return managerConfigApp.importConfig(params).getRc();
return errorCodeMapper.getMapedErrorCode(managerConfigApp.importConfig(params).getErrorCode()).getCode();
}

public ExportResult runExport(APIManagerSetupExportParams params) {
Expand Down
6 changes: 4 additions & 2 deletions modules/users/src/main/java/com/axway/apim/users/UserApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,15 @@ private ExportResult runExport(UserExportParams params, ResultHandler exportImpl

@CLIServiceMethod(name = "import", description = "Import user(s) into the API-Manager")
public static int importUsers(String[] args) {
ErrorCodeMapper errorCodeMapper = new ErrorCodeMapper();
try {
UserImportParams params = (UserImportParams) UserImportCLIOptions.create(args).getParams();
UserApp app = new UserApp();
return app.importUsers(params).getRc();
errorCodeMapper.setMapConfiguration(params.getReturnCodeMapping());
return errorCodeMapper.getMapedErrorCode(app.importUsers(params).getErrorCode()).getCode();
} catch (AppException e) {
LOG.error("Error importing user(s): ", e);
return e.getError().getCode();
return errorCodeMapper.getMapedErrorCode(e.getError()).getCode();
}
}

Expand Down

0 comments on commit b2e7e02

Please sign in to comment.