diff --git a/src/main/java/com/smartharvester/controller/SmartHarvesterMappingController.java b/src/main/java/com/smartharvester/controller/SmartHarvesterMappingController.java index 36dc2fef65d2815a6dc72eb4f51e422ddfc803b1..5c2681d5975f3beccd34f66ee1a0649e3e31def0 100644 --- a/src/main/java/com/smartharvester/controller/SmartHarvesterMappingController.java +++ b/src/main/java/com/smartharvester/controller/SmartHarvesterMappingController.java @@ -66,46 +66,50 @@ public class SmartHarvesterMappingController { List<String> notPublishedUrl = new ArrayList<String>(); List<Path> distributionPaths = paths.stream().filter(path -> path.getDcatClass().equals("dcat:distribution")) .collect(Collectors.toList()); - try { + for (String url : urls) { String datasetId = null; - List<String> properties = this.mappingService.getValues(url, paths); - - String dataset = this.mappingService.getDatasetString(catalogId, properties.get(0), fdpUrl); + List<String> properties = new ArrayList<String>(); try { - responseEntity = this.mappingService.asyncPostToFdp("/dataset", fdpUrl, dataset, fdpToken); - String location = responseEntity.getHeaders().getLocation().toString(); - datasetId = location.substring(location.indexOf("dataset/") + 8); - HttpStatus statusCode = responseEntity.getStatusCode(); - if (distributionPaths.size() > 0) { - String distribution = this.mappingService.getDistributionString(datasetId, properties.get(1), - fdpUrl); - try { - this.mappingService.asyncPostToFdp("/distribution", fdpUrl, distribution, fdpToken); - } catch (HttpStatusCodeException e) { - LOGGER.warn(e.getMessage()); + properties = this.mappingService.getValues(url, paths); + String dataset = this.mappingService.getDatasetString(catalogId, properties.get(0), fdpUrl); + try { + responseEntity = this.mappingService.asyncPostToFdp("/dataset", fdpUrl, dataset, fdpToken); + String location = responseEntity.getHeaders().getLocation().toString(); + datasetId = location.substring(location.indexOf("dataset/") + 8); + HttpStatus statusCode = responseEntity.getStatusCode(); + if (distributionPaths.size() > 0) { + String distribution = this.mappingService.getDistributionString(datasetId, properties.get(1), + fdpUrl); + try { + this.mappingService.asyncPostToFdp("/distribution", fdpUrl, distribution, fdpToken); + } catch (HttpStatusCodeException e) { + LOGGER.warn(e.getMessage()); + } } + if (statusCode.value() == 201) { + publishedUrl.add(url); + } else { + notPublishedUrl.add(url); + } + } catch (HttpStatusCodeException e) { + notPublishedUrl.add(url + " => " + e.getMessage()); + LOGGER.warn(e.getMessage()); } - if (statusCode.value() == 201) { - publishedUrl.add(url); - } else { - notPublishedUrl.add(url); - } - } catch (HttpStatusCodeException e) { - notPublishedUrl.add(url + " => " + e.getMessage()); - LOGGER.warn(e.getMessage()); + } catch (JSONException e1) { + + LOGGER.warn(e1.getMessage()); + notPublishedUrl.add(url); } + + } LOGGER.info("mapping closed"); return ResponseEntity.ok(new MappingResponse(publishedUrl, notPublishedUrl)); - } catch (JSONException e) { - LOGGER.warn(e.getMessage()); - LOGGER.info("mapping closed"); - return ResponseEntity.badRequest().body(e.getMessage()); - } + }