diff --git a/src/main/java/com/smartharvester/controller/SmartHarvesterMappingController.java b/src/main/java/com/smartharvester/controller/SmartHarvesterMappingController.java index 939b55cebca166df1885aa9c895c7ce8ebf92fed..01265fbf5c0fa70cb4935b7a1d6779c35c937682 100644 --- a/src/main/java/com/smartharvester/controller/SmartHarvesterMappingController.java +++ b/src/main/java/com/smartharvester/controller/SmartHarvesterMappingController.java @@ -1,5 +1,6 @@ package com.smartharvester.controller; +import java.net.URI; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -74,22 +75,29 @@ public class SmartHarvesterMappingController { properties = this.mappingService.getValues(url, paths); String dataset = this.mappingService.getDatasetString(catalogId, properties.get(0), fdpUrl); + String locationDataset = null; try { responseEntity = this.mappingService.asyncPostToFdp("/dataset", fdpUrl, dataset, fdpToken); - String location = responseEntity.getHeaders().getLocation().toString(); - datasetId = location.substring(location.indexOf("dataset/") + 8); + locationDataset = responseEntity.getHeaders().getLocation().toString(); + datasetId = locationDataset.substring(locationDataset.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); + ResponseEntity<String> distributionResponse = this.mappingService.asyncPostToFdp("/distribution", fdpUrl, distribution, fdpToken); + String locationDistribution = distributionResponse.getHeaders().getLocation().toString(); + if(distributionResponse.getStatusCode().value() == 201) { + this.mappingService.draftToPublished(fdpToken, locationDistribution); + } } catch (HttpStatusCodeException e) { LOGGER.warn(e.getMessage()); } } if (statusCode.value() == 201) { publishedUrl.add(url); + this.mappingService.draftToPublished(fdpToken, locationDataset); } else { notPublishedUrl.add(url); } diff --git a/src/main/java/com/smartharvester/model/mapping/request/PublishedRequest.java b/src/main/java/com/smartharvester/model/mapping/request/PublishedRequest.java new file mode 100644 index 0000000000000000000000000000000000000000..e204afc5a148241c3000a4ed5b15ce20c09eb734 --- /dev/null +++ b/src/main/java/com/smartharvester/model/mapping/request/PublishedRequest.java @@ -0,0 +1,27 @@ +package com.smartharvester.model.mapping.request; + +public class PublishedRequest { + + private String current; + + /** + * @return the current + */ + public String getCurrent() { + return current; + } + + /** + * @param current the current to set + */ + public void setCurrent(String current) { + this.current = current; + } + + public PublishedRequest(String current) { + this.current = current; + } + + + +} diff --git a/src/main/java/com/smartharvester/service/MappingService.java b/src/main/java/com/smartharvester/service/MappingService.java index 5a39a676e377c9fbc3502b2fea25b609c62d5f1a..36f3eb34950041aeae81636e409e2de61e0a6328 100644 --- a/src/main/java/com/smartharvester/service/MappingService.java +++ b/src/main/java/com/smartharvester/service/MappingService.java @@ -24,6 +24,7 @@ import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; @@ -31,6 +32,7 @@ import org.springframework.web.client.HttpClientErrorException.BadRequest; import org.springframework.web.client.RequestCallback; import org.springframework.web.client.RestTemplate; import com.smartharvester.model.mapping.Path; +import com.smartharvester.model.mapping.request.PublishedRequest; @Service public class MappingService { @@ -143,7 +145,7 @@ public class MappingService { .filter(e -> e.getProperty().equals("dct:publisher")).collect(Collectors.toList()).size() == 0) { datasetProperties += "dct:publisher [ a foaf:Agent; foaf:name \"undefined\"];\n"; } - distributionProperties += "dct:hasVersion \"null\";\ndct:publisher [ a foaf:Agent; foaf:name \\\"undefined\\\"];\\n"; + distributionProperties += "dct:hasVersion \"null\";\ndct:publisher [ a foaf:Agent; foaf:name \"undefined\"];\n"; for (Path path : paths) { try { String[] array = path.getPath().split(" : "); @@ -309,5 +311,16 @@ public class MappingService { return this.restTemplate.exchange(fdpUrl + path, HttpMethod.POST, entity, String.class); } + + public void draftToPublished(String fdpToken, String url) { + HttpHeaders headers = new HttpHeaders(); + + headers.setBearerAuth(fdpToken); + headers.setContentType(MediaType.APPLICATION_JSON); + + HttpEntity<PublishedRequest> entity = new HttpEntity<PublishedRequest>(new PublishedRequest("PUBLISHED"), headers); + + this.restTemplate.exchange(url + "/meta/state", HttpMethod.PUT, entity, Void.class); + } }