Skip to content

Commit

Permalink
[INJICERT-657] Added csv plugin fix to prevent crash for other data p…
Browse files Browse the repository at this point in the history
…rovider plugin

Signed-off-by: Piyush7034 <[email protected]>
  • Loading branch information
Piyush7034 committed Dec 18, 2024
1 parent 9c29bb9 commit 1eb1b93
Showing 1 changed file with 29 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ public class MockCSVDataProviderPlugin implements DataProviderPlugin {
private String id;
@Autowired
private CSVReader csvReader;
@Value("${mosip.certify.mock.data-provider.csv-registry-uri}")
@Value("${mosip.certify.mock.data-provider.csv-registry-uri:}")
private String csvRegistryURI;
@Value("${mosip.certify.mock.data-provider.csv.identifier-column}")
@Value("${mosip.certify.mock.data-provider.csv.identifier-column:}")
private String identifierColumn;
@Value("#{'${mosip.certify.mock.data-provider.csv.data-columns}'.split(',')}")
@Value("#{'${mosip.certify.mock.data-provider.csv.data-columns:}'.split(',')}")
private Set<String> dataColumns;
@Autowired
private RestTemplate restTemplate;
Expand All @@ -46,32 +46,35 @@ public class MockCSVDataProviderPlugin implements DataProviderPlugin {
* @return
*/
@PostConstruct
public File initialize() throws IOException, JSONException {
File filePath;
if (csvRegistryURI.startsWith("http")) {
// download the file to a path: usecase(docker, spring cloud config)
filePath = restTemplate.execute(csvRegistryURI, HttpMethod.GET, null, resp -> {
File ret = File.createTempFile("download", "tmp");
StreamUtils.copy(resp.getBody(), new FileOutputStream(ret));
return ret;
});
} else if (csvRegistryURI.startsWith("classpath:")) {
try {
public void initialize() throws IOException, JSONException {
try {
File filePath;
if (csvRegistryURI.startsWith("http")) {
// download the file to a path: usecase(docker, spring cloud config)
filePath = restTemplate.execute(csvRegistryURI, HttpMethod.GET, null, resp -> {
File ret = File.createTempFile("download", "tmp");
StreamUtils.copy(resp.getBody(), new FileOutputStream(ret));
return ret;
});
} else if (csvRegistryURI.startsWith("classpath:")) {
try {
// usecase(local setup)
filePath = ResourceUtils.getFile(csvRegistryURI);
} catch (IOException e) {
throw new FileNotFoundException("File not found in: " + csvRegistryURI);
}
} else {
// usecase(local setup)
filePath = ResourceUtils.getFile(csvRegistryURI);
} catch (IOException e) {
throw new FileNotFoundException("File not found in: " + csvRegistryURI);
}
} else {
// usecase(local setup)
filePath = new File(csvRegistryURI);
if (!filePath.isFile()) {
// TODO: make sure it crashes the application
throw new FileNotFoundException("File not found: " + csvRegistryURI);
filePath = new File(csvRegistryURI);
if (!filePath.isFile()) {
// TODO: make sure it crashes the application
throw new FileNotFoundException("File not found: " + csvRegistryURI);
}
}
csvReader.readCSV(filePath, identifierColumn, dataColumns);
} catch (Exception e) {
log.error("Undefined CSV source. " + e.getMessage());
}
csvReader.readCSV(filePath, identifierColumn, dataColumns);
return filePath;
}

@Override
Expand Down

0 comments on commit 1eb1b93

Please sign in to comment.