Skip to content
Snippets Groups Projects
Commit 3f527aea authored by Baptiste Toulemonde's avatar Baptiste Toulemonde
Browse files

Merge branch 'fix/draft_to_publsh' into 'master'

fix request to publish

See merge request !15
parents 0358e1de acc1229f
No related branches found
No related tags found
1 merge request!15fix request to publish
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);
}
......
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;
}
}
......@@ -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);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment