Skip to content

Commit

Permalink
- fix sonar issues
Browse files Browse the repository at this point in the history
  • Loading branch information
rathnapandi committed Oct 22, 2024
1 parent b37436c commit ed8642f
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.axway.apim.adapter.APIManagerAdapter;
import com.axway.apim.adapter.apis.OrgFilter;
import com.axway.apim.adapter.jackson.CustomYamlFactory;
import com.axway.apim.api.export.ExportAPI;
import com.axway.apim.api.export.jackson.serializer.APIExportSerializerModifier;
import com.axway.apim.api.export.lib.params.APIExportParams;
Expand Down Expand Up @@ -44,7 +43,7 @@ public ExportHelper(APIExportParams params) {
this.params = params;
}

public void saveAPILocally(ExportAPI exportAPI, APIResultHandler apiResultHandler) throws AppException {
public void saveAPILocally(ObjectMapper mapper, ExportAPI exportAPI, String configFile) throws AppException {

String apiPath = getAPIExportFolder(exportAPI.getPath());
File localFolder = new File(params.getTarget() + File.separator + getVHost(exportAPI) + apiPath);
Expand All @@ -61,7 +60,6 @@ public void saveAPILocally(ExportAPI exportAPI, APIResultHandler apiResultHandle
return;
}
String targetFile = null;
String configFile;
try {
String fileName = Utils.replaceSpecialChars(exportAPI.getName()) + apiDef.getAPIDefinitionType().getFileExtension();
targetFile = localFolder.getCanonicalPath() + "/" + fileName;
Expand All @@ -72,14 +70,6 @@ public void saveAPILocally(ExportAPI exportAPI, APIResultHandler apiResultHandle
} catch (IOException e) {
throw new AppException("Can't save API-Definition locally to file: " + targetFile, ErrorCode.UNXPECTED_ERROR, e);
}
ObjectMapper mapper;
if (apiResultHandler instanceof YamlAPIExporter) {
mapper = new ObjectMapper(CustomYamlFactory.createYamlFactory());
configFile = "/api-config.yaml";
} else {
mapper = new ObjectMapper();
configFile = "/api-config.json";
}
Image image = exportAPI.getAPIImage();
if (image != null && (!EnvironmentProperties.PRINT_CONFIG_CONSOLE)) {
writeBytesToFile(image.getImageContent(), localFolder + File.separator + image.getBaseFilename());
Expand Down Expand Up @@ -147,7 +137,7 @@ private void storePrivateCerts(File localFolder, List<AuthenticationProfile> aut
Map<String, Object> parameters = profile.getParameters();
String pfx = (String) parameters.get("pfx");
String content = pfx.replaceFirst("data:.+,", "");
byte[] data = Base64.getMimeDecoder().decode(content.replace("\\r\\n","\n"));
byte[] data = Base64.getMimeDecoder().decode(content.replace("\\r\\n", "\n"));
String fileName = "backend_cert.pfx";
writeBytesToFile(data, localFolder + "/" + fileName);
parameters.remove("pfx");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.axway.apim.api.export.ExportAPI;
import com.axway.apim.api.export.lib.params.APIExportParams;
import com.axway.apim.lib.error.AppException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -29,7 +30,7 @@ public void execute(List<API> apis) throws AppException {
LOG.info("Exporting API and configuration as JSON format");
for (API api : apis) {
ExportAPI exportAPI = new ExportAPI(api);
exportHelper.saveAPILocally(exportAPI, this);
exportHelper.saveAPILocally(new ObjectMapper(), exportAPI, "/api-config.json");
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package com.axway.apim.api.export.impl;

import com.axway.apim.adapter.jackson.CustomYamlFactory;
import com.axway.apim.api.API;
import com.axway.apim.api.export.ExportAPI;
import com.axway.apim.api.export.lib.params.APIExportParams;
import com.axway.apim.lib.error.AppException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

public class YamlAPIExporter extends JsonAPIExporter{
public class YamlAPIExporter extends JsonAPIExporter {

private static final Logger LOG = LoggerFactory.getLogger(YamlAPIExporter.class);

Expand All @@ -22,7 +24,7 @@ public void execute(List<API> apis) throws AppException {
LOG.info("Export API and configuration as Yaml format");
for (API api : apis) {
ExportAPI exportAPI = new ExportAPI(api);
exportHelper.saveAPILocally(exportAPI, this);
exportHelper.saveAPILocally(new ObjectMapper(CustomYamlFactory.createYamlFactory()), exportAPI, "/api-config.yaml");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.axway.apim.adapter.APIManagerAdapter;
import com.axway.apim.adapter.apis.RemoteHostFilter;
import com.axway.apim.adapter.jackson.CustomYamlFactory;
import com.axway.apim.adapter.jackson.PolicySerializerModifier;
import com.axway.apim.adapter.jackson.UserSerializerModifier;
import com.axway.apim.api.model.Config;
Expand Down Expand Up @@ -38,14 +37,12 @@ public RemoteHostFilter getRemoteHostFilter() {

@Override
public void export(APIManagerConfig apimanagerConfig) throws AppException {
exportToFile(apimanagerConfig, this);
exportToFile(new ObjectMapper(), apimanagerConfig, "/apimanager-config.json");
}


public void exportToFile(APIManagerConfig apimanagerConfig, APIManagerSetupResultHandler apiManagerSetupResultHandler) throws AppException {
public void exportToFile(ObjectMapper mapper, APIManagerConfig apimanagerConfig, String configFile) throws AppException {
File localFolder = null;
ObjectMapper mapper;
String configFile;
if (!EnvironmentProperties.PRINT_CONFIG_CONSOLE) {
String folderName = getExportFolder(apimanagerConfig.getConfig());
String targetFolder = params.getTarget();
Expand All @@ -64,14 +61,6 @@ public void exportToFile(APIManagerConfig apimanagerConfig, APIManagerSetupResul
throw new AppException("Cannot create export folder: " + localFolder, ErrorCode.UNXPECTED_ERROR);
}
}

if (apiManagerSetupResultHandler instanceof YamlAPIManagerSetupExporter) {
mapper = new ObjectMapper(CustomYamlFactory.createYamlFactory());
configFile = "/apimanager-config.yaml";
} else {
mapper = new ObjectMapper();
configFile = "/apimanager-config.json";
}
try {
mapper.enable(SerializationFeature.INDENT_OUTPUT);
mapper.registerModule(new SimpleModule().setSerializerModifier(new PolicySerializerModifier(true)));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.axway.apim.setup.impl;

import com.axway.apim.adapter.jackson.CustomYamlFactory;
import com.axway.apim.lib.ExportResult;
import com.axway.apim.lib.error.AppException;
import com.axway.apim.setup.lib.APIManagerSetupExportParams;
import com.axway.apim.setup.model.APIManagerConfig;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class YamlAPIManagerSetupExporter extends JsonAPIManagerSetupExporter{
public class YamlAPIManagerSetupExporter extends JsonAPIManagerSetupExporter {
private static final Logger LOG = LoggerFactory.getLogger(YamlAPIManagerSetupExporter.class);

public YamlAPIManagerSetupExporter(APIManagerSetupExportParams params, ExportResult result) {
Expand All @@ -17,6 +19,6 @@ public YamlAPIManagerSetupExporter(APIManagerSetupExportParams params, ExportRes
@Override
public void export(APIManagerConfig apimanagerConfig) throws AppException {
LOG.info("Exporting API Manager Configuration in yaml");
exportToFile(apimanagerConfig, this);
exportToFile(new ObjectMapper(CustomYamlFactory.createYamlFactory()), apimanagerConfig, "/apimanager-config.yaml");
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.axway.apim.users.impl;

import com.axway.apim.adapter.jackson.CustomYamlFactory;
import com.axway.apim.adapter.jackson.ImageSerializer;
import com.axway.apim.adapter.user.UserFilter;
import com.axway.apim.api.model.Image;
Expand Down Expand Up @@ -37,14 +36,12 @@ public JsonUserExporter(UserExportParams params, ExportResult result) {
@Override
public void export(List<User> users) throws AppException {
for (User user : users) {
saveUserLocally(new ExportUser(user), this);
saveUserLocally(new ObjectMapper(), new ExportUser(user), "/user-config.json");
}
}

public void saveUserLocally(ExportUser user, UserResultHandler userResultHandler) throws AppException {
public void saveUserLocally(ObjectMapper mapper, ExportUser user, String configFile) throws AppException {
File localFolder = null;
ObjectMapper mapper;
String configFile;
if (!EnvironmentProperties.PRINT_CONFIG_CONSOLE) {
String folderName = getExportFolder(user);
String targetFolder = params.getTarget();
Expand All @@ -63,13 +60,6 @@ public void saveUserLocally(ExportUser user, UserResultHandler userResultHandler
throw new AppException("Cannot create export folder: " + localFolder, ErrorCode.UNXPECTED_ERROR);
}
}
if (userResultHandler instanceof YamlUserExporter) {
mapper = new ObjectMapper(CustomYamlFactory.createYamlFactory());
configFile = "/user-config.yaml";
} else {
mapper = new ObjectMapper();
configFile = "/user-config.json";
}
mapper.registerModule(new SimpleModule().addSerializer(Image.class, new ImageSerializer()));
FilterProvider filters = new SimpleFilterProvider()
.addFilter("UserFilter",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
package com.axway.apim.users.impl;

import com.axway.apim.adapter.jackson.CustomYamlFactory;
import com.axway.apim.api.model.User;
import com.axway.apim.lib.ExportResult;
import com.axway.apim.lib.error.AppException;
import com.axway.apim.users.lib.ExportUser;
import com.axway.apim.users.lib.params.UserExportParams;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

public class YamlUserExporter extends JsonUserExporter{
public class YamlUserExporter extends JsonUserExporter {

private static final Logger LOG = LoggerFactory.getLogger(YamlUserExporter.class);

public YamlUserExporter(UserExportParams params, ExportResult result) {
super(params, result);
}

@Override
public void export(List<User> users) throws AppException {
LOG.info("Exporting User in Yaml format");
for(User user : users) {
saveUserLocally(new ExportUser(user), this);
for (User user : users) {
saveUserLocally(new ObjectMapper(CustomYamlFactory.createYamlFactory()), new ExportUser(user), "/user-config.yaml");
}
}
}

0 comments on commit ed8642f

Please sign in to comment.