Additional checkup

This commit is contained in:
George Kalampokis 2020-04-06 18:31:12 +03:00
parent 7b5588bcbe
commit 06df52334c
1 changed files with 14 additions and 4 deletions

View File

@ -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 {
@ -1538,7 +1541,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();
@ -1587,10 +1597,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) {