Refactors rda file parsing logic.
This commit is contained in:
parent
e81ffa2825
commit
2a6f6b3923
|
@ -7,6 +7,7 @@ import eu.eudat.exceptions.datasetprofile.DatasetProfileWithDatasetsExeption;
|
|||
import eu.eudat.logic.managers.AdminManager;
|
||||
import eu.eudat.logic.managers.DatasetProfileManager;
|
||||
import eu.eudat.logic.managers.UserManager;
|
||||
import eu.eudat.logic.proxy.config.configloaders.ConfigLoader;
|
||||
import eu.eudat.logic.security.claims.ClaimedAuthorities;
|
||||
import eu.eudat.logic.services.ApiContext;
|
||||
import eu.eudat.models.data.admin.composite.DatasetProfile;
|
||||
|
@ -38,14 +39,14 @@ public class Admin extends BaseController {
|
|||
|
||||
private DatasetProfileManager datasetProfileManager;
|
||||
private UserManager userManager;
|
||||
private Environment environment;
|
||||
private ConfigLoader configLoader;
|
||||
|
||||
@Autowired
|
||||
public Admin(ApiContext apiContext, DatasetProfileManager datasetProfileManager, UserManager userManager, Logger logger, Environment environment) {
|
||||
public Admin(ApiContext apiContext, DatasetProfileManager datasetProfileManager, UserManager userManager, Logger logger, ConfigLoader configLoader) {
|
||||
super(apiContext);
|
||||
this.datasetProfileManager = datasetProfileManager;
|
||||
this.userManager = userManager;
|
||||
this.environment = environment;
|
||||
this.configLoader = configLoader;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
|
@ -154,7 +155,6 @@ public class Admin extends BaseController {
|
|||
|
||||
@RequestMapping(method = RequestMethod.GET, value = {"/getRDACommonStandards"}, produces = "application/json")
|
||||
public ResponseEntity getRDACommonStandards(@ClaimedAuthorities(claims = {ADMIN}) Principal principal) {
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<String>>().status(ApiMessageCode.SUCCESS_MESSAGE).payload(this.datasetProfileManager.getRDACommonStandards(environment)));
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<String>>().status(ApiMessageCode.SUCCESS_MESSAGE).payload(configLoader.getRdaProperties()));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@ import eu.eudat.models.data.helpers.common.DataTableData;
|
|||
import eu.eudat.queryable.QueryableList;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
@ -45,6 +44,7 @@ public class DatasetProfileManager {
|
|||
|
||||
private ApiContext apiContext;
|
||||
private DatabaseRepository databaseRepository;
|
||||
|
||||
@Autowired
|
||||
public DatasetProfileManager(ApiContext apiContext) {
|
||||
this.apiContext = apiContext;
|
||||
|
@ -190,23 +190,4 @@ public class DatasetProfileManager {
|
|||
throw new DatasetProfileNewVersionException("Version to update not the latest.");
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getRDACommonStandards(Environment environment) {
|
||||
String filePath = environment.getProperty("configuration.rda");
|
||||
BufferedReader reader;
|
||||
List<String> rdaList = new LinkedList<>();
|
||||
try {
|
||||
reader = new BufferedReader(new FileReader(filePath));
|
||||
String line = reader.readLine();
|
||||
while (line != null) {
|
||||
rdaList.add(line);
|
||||
line = reader.readLine();
|
||||
}
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return rdaList;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,9 +2,9 @@ package eu.eudat.logic.proxy.config.configloaders;
|
|||
|
||||
import eu.eudat.logic.proxy.config.ExternalUrls;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 2/9/2018.
|
||||
*/
|
||||
import java.util.List;
|
||||
|
||||
public interface ConfigLoader {
|
||||
ExternalUrls getExternalUrls();
|
||||
List<String> getRdaProperties();
|
||||
}
|
||||
|
|
|
@ -8,15 +8,20 @@ import org.springframework.stereotype.Service;
|
|||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
@Service("configLoader")
|
||||
@Profile("devel")
|
||||
public class DevelConfigLoader implements ConfigLoader {
|
||||
|
||||
private ExternalUrls externalUrls;
|
||||
private List<String> rdaProperties;
|
||||
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
|
@ -31,7 +36,7 @@ public class DevelConfigLoader implements ConfigLoader {
|
|||
|
||||
JAXBContext jaxbContext = JAXBContext.newInstance(ExternalUrls.class);
|
||||
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
|
||||
is = new URL("file:///"+ current +"/web/src/main/resources/ExternalUrls.xml").openStream();
|
||||
is = new URL("file:///" + current + fileUrl).openStream();
|
||||
externalUrls = (ExternalUrls) jaxbUnmarshaller.unmarshal(is);
|
||||
|
||||
} catch (Exception ex) {
|
||||
|
@ -44,13 +49,36 @@ public class DevelConfigLoader implements ConfigLoader {
|
|||
System.out.println("Warning: Could not close a stream after reading from file: " + fileUrl);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void setRdaProperties() {
|
||||
String filePath = environment.getProperty("configuration.rda");
|
||||
String current = null;
|
||||
BufferedReader reader;
|
||||
List<String> rdaList = new LinkedList<>();
|
||||
try {
|
||||
current = new java.io.File(".").getCanonicalPath();
|
||||
reader = new BufferedReader(new FileReader(current + filePath));
|
||||
String line = reader.readLine();
|
||||
while (line != null) {
|
||||
rdaList.add(line);
|
||||
line = reader.readLine();
|
||||
}
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
rdaProperties = rdaList;
|
||||
}
|
||||
|
||||
public ExternalUrls getExternalUrls() {
|
||||
this.setExternalUrls();
|
||||
return externalUrls;
|
||||
}
|
||||
|
||||
public List<String> getRdaProperties() {
|
||||
this.setRdaProperties();
|
||||
return rdaProperties;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,19 +8,21 @@ import org.springframework.stereotype.Service;
|
|||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by ikalyvas on 2/9/2018.
|
||||
*/
|
||||
@Service("configLoader")
|
||||
@Profile({ "production", "staging" })
|
||||
public class ProductionConfigLoader implements ConfigLoader {
|
||||
|
||||
private ExternalUrls externalUrls;
|
||||
private List<String> rdaProperties;
|
||||
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
|
@ -48,13 +50,34 @@ public class ProductionConfigLoader implements ConfigLoader {
|
|||
System.out.println("Warning: Could not close a stream after reading from file: " + fileUrl);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void setRdaProperties() {
|
||||
String filePath = environment.getProperty("configuration.rda");
|
||||
BufferedReader reader;
|
||||
List<String> rdaList = new LinkedList<>();
|
||||
try {
|
||||
reader = new BufferedReader(new FileReader(Paths.get(filePath).toUri().toURL().toString()));
|
||||
String line = reader.readLine();
|
||||
while (line != null) {
|
||||
rdaList.add(line);
|
||||
line = reader.readLine();
|
||||
}
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
rdaProperties = rdaList;
|
||||
}
|
||||
|
||||
public ExternalUrls getExternalUrls() {
|
||||
this.setExternalUrls();
|
||||
return externalUrls;
|
||||
}
|
||||
|
||||
public List<String> getRdaProperties() {
|
||||
this.setRdaProperties();
|
||||
return rdaProperties;
|
||||
}
|
||||
}
|
|
@ -15,8 +15,8 @@ http-logger.server-address = http://localhost:31311
|
|||
pdf.converter.url=http://localhost:88/
|
||||
|
||||
####################CONFIGURATION FILES OVERRIDES CONFIGURATIONS##########
|
||||
configuration.externalUrls=/tmp/ExternalUrls.xml
|
||||
configuration.rda=C:/Users/gkolokythas/Documents/openDmp/dmp-backend/web/src/main/resources/RDACommonStandards.txt
|
||||
configuration.externalUrls=/web/src/main/resources/ExternalUrls.xml
|
||||
configuration.rda=/web/src/main/resources/RDACommonStandards.txt
|
||||
configuration.loginProviders=C:/Users/gkolokythas/Documents/openDmp/dmp-backend/web/src/main/resources/LoginProviders.xml
|
||||
configuration.h2020template=C:/Users/gkolokythas/Documents/openDmp/dmp-backend/web/src/main/resources/documents/h2020.docx
|
||||
|
||||
|
|
Loading…
Reference in New Issue