remove redundant parameter in deposit interface
This commit is contained in:
parent
5e2639848b
commit
573aab059b
|
@ -69,7 +69,7 @@ public class DataverseDeposit implements RepositoryDeposit {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String deposit(DMPDepositModel dmpDepositModel, boolean update, String repositoryAccessToken) throws Exception {
|
public String deposit(DMPDepositModel dmpDepositModel, String repositoryAccessToken) throws Exception {
|
||||||
|
|
||||||
if(!this.isApiSet)
|
if(!this.isApiSet)
|
||||||
this.setDataverseApi();
|
this.setDataverseApi();
|
||||||
|
|
|
@ -4,7 +4,7 @@ import eu.eudat.depositinterface.models.DMPDepositModel;
|
||||||
|
|
||||||
public interface RepositoryDeposit {
|
public interface RepositoryDeposit {
|
||||||
|
|
||||||
String deposit(DMPDepositModel dmpDepositModel, boolean update, String repositoryAccessToken) throws Exception;
|
String deposit(DMPDepositModel dmpDepositModel, String repositoryAccessToken) throws Exception;
|
||||||
|
|
||||||
String authenticate(String code);
|
String authenticate(String code);
|
||||||
|
|
||||||
|
|
|
@ -2100,7 +2100,7 @@ public class DataManagementPlanManager {
|
||||||
String finalDoi = null;
|
String finalDoi = null;
|
||||||
for(RepositoryDeposit repo: this.repositoriesDeposit) { //temp
|
for(RepositoryDeposit repo: this.repositoriesDeposit) { //temp
|
||||||
if(repo.getConfiguration().getRepositoryId().equals("Zenodo")) {
|
if(repo.getConfiguration().getRepositoryId().equals("Zenodo")) {
|
||||||
finalDoi = repo.deposit(dmpDepositModel, update, zenodoToken);
|
finalDoi = repo.deposit(dmpDepositModel, zenodoToken);
|
||||||
if (finalDoi != null) {
|
if (finalDoi != null) {
|
||||||
EntityDoi doiEntity = new EntityDoi();
|
EntityDoi doiEntity = new EntityDoi();
|
||||||
doiEntity.setId(UUID.randomUUID());
|
doiEntity.setId(UUID.randomUUID());
|
||||||
|
@ -2158,7 +2158,7 @@ public class DataManagementPlanManager {
|
||||||
Optional<RepositoryDeposit> repo = this.repositoriesDeposit.stream().filter(x -> x.getConfiguration().getRepositoryId().equals(depositRequest.getRepositoryId())).findFirst();
|
Optional<RepositoryDeposit> repo = this.repositoriesDeposit.stream().filter(x -> x.getConfiguration().getRepositoryId().equals(depositRequest.getRepositoryId())).findFirst();
|
||||||
String finalDoi = repo.map(r -> {
|
String finalDoi = repo.map(r -> {
|
||||||
try {
|
try {
|
||||||
return r.deposit(dmpDepositModel, false, depositRequest.getAccessToken());
|
return r.deposit(dmpDepositModel, depositRequest.getAccessToken());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error(e.getMessage(), e);
|
logger.error(e.getMessage(), e);
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -41,7 +41,7 @@ public class ZenodoDeposit implements RepositoryDeposit {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String deposit(DMPDepositModel dmpDepositModel, boolean update, String zenodoToken) throws Exception {
|
public String deposit(DMPDepositModel dmpDepositModel, String zenodoToken) throws Exception {
|
||||||
|
|
||||||
RepositoryDepositConfiguration conf = this.getConfiguration();
|
RepositoryDepositConfiguration conf = this.getConfiguration();
|
||||||
|
|
||||||
|
@ -71,7 +71,6 @@ public class ZenodoDeposit implements RepositoryDeposit {
|
||||||
String createUrl = zenodoUrl + "deposit/depositions" + "?access_token=" + zenodoToken;
|
String createUrl = zenodoUrl + "deposit/depositions" + "?access_token=" + zenodoToken;
|
||||||
createResponse = restTemplate.postForEntity(createUrl, request, Map.class).getBody();
|
createResponse = restTemplate.postForEntity(createUrl, request, Map.class).getBody();
|
||||||
links = (LinkedHashMap<String, String>) createResponse.get("links");
|
links = (LinkedHashMap<String, String>) createResponse.get("links");
|
||||||
finalDoi = (String) createResponse.get("conceptdoi");
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
unpublishedUrl = this.getUnpublishedDOI(zenodoUrl, previousDOI, zenodoToken, dmpDepositModel.getVersion());
|
unpublishedUrl = this.getUnpublishedDOI(zenodoUrl, previousDOI, zenodoToken, dmpDepositModel.getVersion());
|
||||||
|
@ -90,7 +89,6 @@ public class ZenodoDeposit implements RepositoryDeposit {
|
||||||
String latestDraftUrl = links.get("latest_draft") + "?access_token=" + zenodoToken;
|
String latestDraftUrl = links.get("latest_draft") + "?access_token=" + zenodoToken;
|
||||||
createResponse = restTemplate.getForObject(latestDraftUrl, Map.class);
|
createResponse = restTemplate.getForObject(latestDraftUrl, Map.class);
|
||||||
links = (LinkedHashMap<String, String>) createResponse.get("links");
|
links = (LinkedHashMap<String, String>) createResponse.get("links");
|
||||||
finalDoi = (String) createResponse.get("conceptdoi");
|
|
||||||
//At this point it might fail to perform the next requests so enclose them with try catch
|
//At this point it might fail to perform the next requests so enclose them with try catch
|
||||||
try {
|
try {
|
||||||
//Forth, update the new deposit's metadata
|
//Forth, update the new deposit's metadata
|
||||||
|
@ -117,7 +115,6 @@ public class ZenodoDeposit implements RepositoryDeposit {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!update) {
|
|
||||||
if (unpublishedUrl == null) {
|
if (unpublishedUrl == null) {
|
||||||
// Second step, add the file to the entry.
|
// Second step, add the file to the entry.
|
||||||
File pdfFile = dmpDepositModel.getPdfFile();
|
File pdfFile = dmpDepositModel.getPdfFile();
|
||||||
|
@ -151,14 +148,9 @@ public class ZenodoDeposit implements RepositoryDeposit {
|
||||||
else {
|
else {
|
||||||
publishUrl = unpublishedUrl + "?access_token=" + zenodoToken;
|
publishUrl = unpublishedUrl + "?access_token=" + zenodoToken;
|
||||||
}
|
}
|
||||||
finalDoi = this.publish(publishUrl);
|
|
||||||
} else {
|
|
||||||
Map<String, Object> editResponce = restTemplate.postForObject(links.get("edit") + "?access_token=" + zenodoToken, "", Map.class);
|
|
||||||
restTemplate.put(links.get("self") + "?access_token=" + zenodoToken, request);
|
|
||||||
finalDoi = this.publish(links.get("publish") + "?access_token=" + zenodoToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
return finalDoi;
|
return this.publish(publishUrl);
|
||||||
|
|
||||||
} catch (HttpClientErrorException | HttpServerErrorException ex) {
|
} catch (HttpClientErrorException | HttpServerErrorException ex) {
|
||||||
Map<String, String> parsedException = objectMapper.readValue(ex.getResponseBodyAsString(), HashMap.class);
|
Map<String, String> parsedException = objectMapper.readValue(ex.getResponseBodyAsString(), HashMap.class);
|
||||||
throw new IOException(parsedException.get("message"), ex);
|
throw new IOException(parsedException.get("message"), ex);
|
||||||
|
@ -172,24 +164,6 @@ public class ZenodoDeposit implements RepositoryDeposit {
|
||||||
return (String) publishResponce.get("conceptdoi");
|
return (String) publishResponce.get("conceptdoi");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void publishIfNot(String zenodoUrl, String doi, String zenodoToken, DMPDepositModel dmpDepositModel){
|
|
||||||
RestTemplate restTemplate = new RestTemplate();
|
|
||||||
HttpHeaders headers = new HttpHeaders();
|
|
||||||
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
|
|
||||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
|
||||||
|
|
||||||
eu.eudat.depositinterface.zenodorepository.models.ZenodoDeposit deposit = DMPToZenodoMapper.fromDMP(dmpDepositModel, "argos", "ARGOS", "https://argos.openaire.eu/", this.configLoader.getDOIFunders());
|
|
||||||
HttpEntity<eu.eudat.depositinterface.zenodorepository.models.ZenodoDeposit> request = new HttpEntity<>(deposit, headers);
|
|
||||||
|
|
||||||
String listUrl = zenodoUrl + "deposit/depositions" + "?q=conceptdoi:\"" + doi + "\"&access_token=" + zenodoToken;
|
|
||||||
ResponseEntity<Map[]> listResponses = restTemplate.getForEntity(listUrl, Map[].class);
|
|
||||||
Map createResponse = listResponses.getBody()[0];
|
|
||||||
LinkedHashMap<String, String> links = (LinkedHashMap<String, String>) createResponse.get("links");
|
|
||||||
Map<String, Object> editResponce = restTemplate.postForObject(links.get("edit") + "?access_token=" + zenodoToken, "", Map.class);
|
|
||||||
|
|
||||||
restTemplate.put(links.get("self") + "?access_token=" + zenodoToken, request);
|
|
||||||
this.publish(links.get("publish") + "?access_token=" + zenodoToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RepositoryDepositConfiguration getConfiguration() {
|
public RepositoryDepositConfiguration getConfiguration() {
|
||||||
|
|
Loading…
Reference in New Issue