Additional checkup
This commit is contained in:
parent
b97f08d0f4
commit
330ead8f39
|
@ -25,6 +25,7 @@ import eu.eudat.elastic.entities.Organization;
|
||||||
import eu.eudat.elastic.entities.Tag;
|
import eu.eudat.elastic.entities.Tag;
|
||||||
import eu.eudat.exceptions.datamanagementplan.DMPNewVersionException;
|
import eu.eudat.exceptions.datamanagementplan.DMPNewVersionException;
|
||||||
import eu.eudat.exceptions.datamanagementplan.DMPWithDatasetsDeleteException;
|
import eu.eudat.exceptions.datamanagementplan.DMPWithDatasetsDeleteException;
|
||||||
|
import eu.eudat.exceptions.security.NonValidTokenException;
|
||||||
import eu.eudat.exceptions.security.UnauthorisedException;
|
import eu.eudat.exceptions.security.UnauthorisedException;
|
||||||
import eu.eudat.logic.builders.entity.UserInfoBuilder;
|
import eu.eudat.logic.builders.entity.UserInfoBuilder;
|
||||||
import eu.eudat.logic.mapper.elastic.DmpMapper;
|
import eu.eudat.logic.mapper.elastic.DmpMapper;
|
||||||
|
@ -111,15 +112,17 @@ public class DataManagementPlanManager {
|
||||||
private DatabaseRepository databaseRepository;
|
private DatabaseRepository databaseRepository;
|
||||||
private Environment environment;
|
private Environment environment;
|
||||||
private RDAManager rdaManager;
|
private RDAManager rdaManager;
|
||||||
|
private UserManager userManager;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public DataManagementPlanManager(ApiContext apiContext, DatasetManager datasetManager, Environment environment, RDAManager rdaManager) {
|
public DataManagementPlanManager(ApiContext apiContext, DatasetManager datasetManager, Environment environment, RDAManager rdaManager, UserManager userManager) {
|
||||||
this.apiContext = apiContext;
|
this.apiContext = apiContext;
|
||||||
this.datasetManager = datasetManager;
|
this.datasetManager = datasetManager;
|
||||||
this.utilitiesService = apiContext.getUtilitiesService();
|
this.utilitiesService = apiContext.getUtilitiesService();
|
||||||
this.databaseRepository = apiContext.getOperationsContext().getDatabaseRepository();
|
this.databaseRepository = apiContext.getOperationsContext().getDatabaseRepository();
|
||||||
this.environment = environment;
|
this.environment = environment;
|
||||||
this.rdaManager = rdaManager;
|
this.rdaManager = rdaManager;
|
||||||
|
this.userManager = userManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DataTableData<DataManagementPlanListingModel> getPaged(DataManagementPlanTableRequest dataManagementPlanTableRequest, Principal principal, String fieldsGroup) throws Exception {
|
public DataTableData<DataManagementPlanListingModel> getPaged(DataManagementPlanTableRequest dataManagementPlanTableRequest, Principal principal, String fieldsGroup) throws Exception {
|
||||||
|
@ -1599,7 +1602,14 @@ public class DataManagementPlanManager {
|
||||||
if (dmp.getDoi() != null)
|
if (dmp.getDoi() != null)
|
||||||
throw new Exception("DMP already has a DOI");
|
throw new Exception("DMP already has a DOI");
|
||||||
|
|
||||||
String zenodoToken = principal.getZenodoToken() != null && !principal.getZenodoToken().isEmpty() ? principal.getZenodoToken() : this.environment.getProperty("zenodo.access_token");
|
String zenodoToken = "";
|
||||||
|
try {
|
||||||
|
if (this.userManager.isDOITokenValid(principal)) {
|
||||||
|
zenodoToken = principal.getZenodoToken();
|
||||||
|
}
|
||||||
|
} catch (NonValidTokenException e) {
|
||||||
|
zenodoToken = this.environment.getProperty("zenodo.access_token");
|
||||||
|
}
|
||||||
// First step, post call to Zenodo, to create the entry.
|
// First step, post call to Zenodo, to create the entry.
|
||||||
RestTemplate restTemplate = new RestTemplate();
|
RestTemplate restTemplate = new RestTemplate();
|
||||||
HttpHeaders headers = new HttpHeaders();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
@ -1648,10 +1658,10 @@ public class DataManagementPlanManager {
|
||||||
String updateUrl = links.get("self") + "?access_token=" + zenodoToken;
|
String updateUrl = links.get("self") + "?access_token=" + zenodoToken;
|
||||||
restTemplate.put(updateUrl, request);
|
restTemplate.put(updateUrl, request);
|
||||||
//And finally remove pre-existing files from it
|
//And finally remove pre-existing files from it
|
||||||
String fileListUrl = links.get("self") + "/files" + "?access_token=" + zenodoToken;
|
String fileListUrl = links.get("self") + "/files" + "?access_token=" + this.environment.getProperty("zenodo.access_token");
|
||||||
ResponseEntity<Map[]> fileListResponse = restTemplate.getForEntity(fileListUrl, Map[].class);
|
ResponseEntity<Map[]> fileListResponse = restTemplate.getForEntity(fileListUrl, Map[].class);
|
||||||
for (Map file : fileListResponse.getBody()) {
|
for (Map file : fileListResponse.getBody()) {
|
||||||
String fileDeleteUrl = links.get("self") + "/files/" + file.get("id") + "?access_token=" + zenodoToken;
|
String fileDeleteUrl = links.get("self") + "/files/" + file.get("id") + "?access_token=" + this.environment.getProperty("zenodo.access_token");
|
||||||
restTemplate.delete(fileDeleteUrl);
|
restTemplate.delete(fileDeleteUrl);
|
||||||
}
|
}
|
||||||
}catch (Exception e) {
|
}catch (Exception e) {
|
||||||
|
|
Loading…
Reference in New Issue