First version of project - /validate POST method gets param 'guidelines' (name of selected guidelines to validate with) and a string as body (xml) to be validated
This commit is contained in:
parent
e3407abf4d
commit
85494a6dac
|
@ -0,0 +1,3 @@
|
||||||
|
.idea/
|
||||||
|
make.sh
|
||||||
|
target/
|
|
@ -0,0 +1,51 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>org.example</groupId>
|
||||||
|
<artifactId>validator-api</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<name>uoa-validator-api</name>
|
||||||
|
<packaging>war</packaging>
|
||||||
|
<parent>
|
||||||
|
<groupId>eu.dnetlib</groupId>
|
||||||
|
<artifactId>uoa-spring-boot-parent</artifactId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
|
<java.version>1.8</java.version>
|
||||||
|
<timestamp>${maven.build.timestamp}</timestamp>
|
||||||
|
<maven.build.timestamp.format>E MMM dd HH:mm:ss z yyyy</maven.build.timestamp.format>
|
||||||
|
</properties>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>eu.dnetlib</groupId>
|
||||||
|
<artifactId>uoa-validator-engine2</artifactId>
|
||||||
|
<version>0.9.0</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-war-plugin</artifactId>
|
||||||
|
<version>2.6</version>
|
||||||
|
<configuration>
|
||||||
|
<failOnMissingWebXml>false</failOnMissingWebXml>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
<finalName>uoa-validator-api</finalName>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</build>
|
||||||
|
</project>
|
|
@ -0,0 +1,13 @@
|
||||||
|
package eu.dnetlib.validatorapi;
|
||||||
|
|
||||||
|
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||||
|
import org.springframework.boot.web.support.SpringBootServletInitializer;
|
||||||
|
|
||||||
|
public class ServletInitializer extends SpringBootServletInitializer {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
||||||
|
return application.sources(ValidatorApiApplication.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package eu.dnetlib.validatorapi;
|
||||||
|
|
||||||
|
import eu.dnetlib.validatorapi.configuration.GlobalVars;
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.PropertySource;
|
||||||
|
import org.springframework.context.annotation.PropertySources;
|
||||||
|
|
||||||
|
@SpringBootApplication(scanBasePackages = {"eu.dnetlib.validatorapi"})
|
||||||
|
@PropertySources({
|
||||||
|
@PropertySource("classpath:validatorapi.properties"),
|
||||||
|
@PropertySource(value = "classpath:dnet-override.properties", ignoreResourceNotFound = true)
|
||||||
|
})
|
||||||
|
@EnableConfigurationProperties({GlobalVars.class})
|
||||||
|
public class ValidatorApiApplication {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(ValidatorApiApplication.class, args);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package eu.dnetlib.validatorapi;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class ValidatorApiConfiguration extends WebMvcConfigurerAdapter {
|
||||||
|
private final Logger log = LogManager.getLogger(this.getClass());
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
|
||||||
|
return new PropertySourcesPlaceholderConfigurer();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
package eu.dnetlib.validatorapi.configuration;
|
||||||
|
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@ConfigurationProperties("validatorapi.globalVars")
|
||||||
|
public class GlobalVars {
|
||||||
|
public static Date date = new Date();
|
||||||
|
private Date buildDate;
|
||||||
|
private String version;
|
||||||
|
|
||||||
|
public String getBuildDate() {
|
||||||
|
if(buildDate == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return buildDate.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBuildDate(Date buildDate) {
|
||||||
|
this.buildDate = buildDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getVersion() {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVersion(String version) {
|
||||||
|
this.version = version;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,46 @@
|
||||||
|
package eu.dnetlib.validatorapi.controllers;
|
||||||
|
|
||||||
|
import eu.dnetlib.validatorapi.configuration.GlobalVars;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@CrossOrigin(origins = "*")
|
||||||
|
public class ValidatorApiCheckDeployController {
|
||||||
|
private static final Logger log = LogManager.getLogger(ValidatorApiCheckDeployController.class);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private GlobalVars globalVars;
|
||||||
|
|
||||||
|
@RequestMapping(value = {"", "/health_check"}, method = RequestMethod.GET)
|
||||||
|
public String hello() {
|
||||||
|
log.debug("Hello from validator-api!");
|
||||||
|
return "Hello from validator-api!";
|
||||||
|
}
|
||||||
|
|
||||||
|
// @PreAuthorize("hasAnyAuthority(@AuthorizationService.PORTAL_ADMIN)")
|
||||||
|
@RequestMapping(value = "/health_check/advanced", method = RequestMethod.GET)
|
||||||
|
public Map<String, String> checkEverything() {
|
||||||
|
Map<String, String> response = new HashMap<>();
|
||||||
|
|
||||||
|
if(globalVars.date != null) {
|
||||||
|
response.put("Date of deploy", globalVars.date.toString());
|
||||||
|
}
|
||||||
|
if(globalVars.getBuildDate() != null) {
|
||||||
|
response.put("Date of build", globalVars.getBuildDate());
|
||||||
|
}
|
||||||
|
if(globalVars.getVersion() != null) {
|
||||||
|
response.put("Version", globalVars.getVersion());
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,79 @@
|
||||||
|
package eu.dnetlib.validatorapi.controllers;
|
||||||
|
|
||||||
|
import eu.dnetlib.validator2.validation.XMLApplicationProfile;
|
||||||
|
import eu.dnetlib.validator2.validation.guideline.Guideline;
|
||||||
|
import eu.dnetlib.validator2.validation.guideline.openaire.AbstractOpenAireProfile;
|
||||||
|
import eu.dnetlib.validator2.validation.guideline.openaire.DataArchiveGuidelinesV2Profile;
|
||||||
|
import eu.dnetlib.validator2.validation.guideline.openaire.LiteratureGuidelinesV3Profile;
|
||||||
|
import eu.dnetlib.validator2.validation.guideline.openaire.LiteratureGuidelinesV4Profile;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.xml.sax.InputSource;
|
||||||
|
|
||||||
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
import java.io.StringReader;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@CrossOrigin(origins = "*")
|
||||||
|
public class ValidatorController {
|
||||||
|
private final Logger log = LogManager.getLogger(this.getClass());
|
||||||
|
|
||||||
|
@RequestMapping(value = {"/validate"}, method = RequestMethod.POST)
|
||||||
|
public List<String> validate(@RequestParam(name = "guidelines") String guidelinesProfileName, @RequestBody String xml) {
|
||||||
|
log.debug(xml);
|
||||||
|
List<String> resultMessages = new ArrayList<>();
|
||||||
|
|
||||||
|
AbstractOpenAireProfile profile = null;
|
||||||
|
if(guidelinesProfileName.equals("dataArchiveGuidelinesV2Profile")) {
|
||||||
|
profile = new DataArchiveGuidelinesV2Profile();
|
||||||
|
} else if(guidelinesProfileName.equals("literatureGuidelinesV3Profile")) {
|
||||||
|
profile = new LiteratureGuidelinesV3Profile();
|
||||||
|
} else if(guidelinesProfileName.equals("literatureGuidelinesV4Profile")) {
|
||||||
|
profile = new LiteratureGuidelinesV4Profile();
|
||||||
|
}
|
||||||
|
if(profile == null) {
|
||||||
|
new Exception("No valid guidelines");
|
||||||
|
}
|
||||||
|
log.debug("Max score: " + profile.maxScore());
|
||||||
|
Map<String, Double> scorePerDoc = new LinkedHashMap<>();
|
||||||
|
// String file = "/home/konstantina/projects/validator-api/src/main/resources/Record_21811.xml";
|
||||||
|
XMLApplicationProfile.ValidationResult result = null;
|
||||||
|
try {
|
||||||
|
// log.debug("Processing " + file);
|
||||||
|
// Document doc = DOMBuilder.parse(new FileReader(file), false, true, true);
|
||||||
|
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||||
|
DocumentBuilder db = dbf.newDocumentBuilder();
|
||||||
|
Document doc = db.parse(new InputSource(new StringReader(xml)));
|
||||||
|
result = profile.validate("id", doc);
|
||||||
|
Date date = new Date();
|
||||||
|
scorePerDoc.put("input-"+date.toString(), result.score());
|
||||||
|
Map<String, Guideline.Result> results = result.results();
|
||||||
|
log.debug("\n\nPrinting results...");
|
||||||
|
for (Map.Entry entry : results.entrySet()) {
|
||||||
|
log.debug(entry.getKey() + " = " + entry.getValue());
|
||||||
|
resultMessages.add(entry.getKey() + " = " + entry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e) {
|
||||||
|
log.debug(e.getMessage());
|
||||||
|
log.debug(e);
|
||||||
|
e.printStackTrace();
|
||||||
|
resultMessages.add("Error processing input");
|
||||||
|
}
|
||||||
|
String printout = scorePerDoc.entrySet().stream().
|
||||||
|
map(entry -> {
|
||||||
|
resultMessages.add("score: " + entry.getValue());
|
||||||
|
return entry.getValue() + ": " + entry.getKey();
|
||||||
|
}).collect(Collectors.joining("\n"));
|
||||||
|
log.debug("\n\nPrinting scorePerDoc...");
|
||||||
|
log.debug(printout);
|
||||||
|
|
||||||
|
return resultMessages;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
<record>
|
||||||
|
<header>
|
||||||
|
<identifier>oai:dlib.tuc.gr:21811</identifier>
|
||||||
|
<datestamp>2012-10-10T00:00:00Z</datestamp>
|
||||||
|
<setSpec>28</setSpec>
|
||||||
|
</header>
|
||||||
|
<metadata>
|
||||||
|
<oai_dc:dc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||||
|
xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/"
|
||||||
|
xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd">
|
||||||
|
<dc:type>info:eu-repo/semantics/article</dc:type>
|
||||||
|
<dc:title xml:lang="en">Mainstream traffic flow control on freeways using variable speed limits</dc:title>
|
||||||
|
<dc:creator xml:lang="en">Carlson Rodrigo Castelan ()</dc:creator>
|
||||||
|
<dc:creator xml:lang="el">Παπαμιχαηλ Ιωαννης(http://users.isc.tuc.gr/~ipapa)</dc:creator>
|
||||||
|
<dc:creator xml:lang="en">Papamichail Ioannis(http://users.isc.tuc.gr/~ipapa)</dc:creator>
|
||||||
|
<dc:creator xml:lang="el">Παπαγεωργιου Μαρκος(http://users.isc.tuc.gr/~mpapageorgiou)</dc:creator>
|
||||||
|
<dc:creator xml:lang="en">Papageorgiou Markos(http://users.isc.tuc.gr/~mpapageorgiou)</dc:creator>
|
||||||
|
<dc:subject xml:lang="en">Traffic incident management,traffic congestion management,traffic incident
|
||||||
|
management
|
||||||
|
</dc:subject>
|
||||||
|
<dc:identifier>http://purl.tuc.gr/dl/dias/CF2DBEC9-EA4E-4D15-931D-C8D5D903D718</dc:identifier>
|
||||||
|
<dc:identifier>10.4237/transportes.v21i3.694</dc:identifier>
|
||||||
|
<dc:date>Published at: 2014-09-25</dc:date>
|
||||||
|
<dc:language>en</dc:language>
|
||||||
|
<dc:rights>info:eu-repo/semantics/openAccess</dc:rights>
|
||||||
|
<dc:rights xml:lang="en">License: http://creativecommons.org/licenses/by-nc-nd/4.0/</dc:rights>
|
||||||
|
<dc:format>application/pdf</dc:format>
|
||||||
|
<dc:date>Issued on: 2013</dc:date>
|
||||||
|
<dc:description xml:lang="en">Summarization: Mainstream Traffic Flow Control (MTFC), enabled via variable
|
||||||
|
speed limits, is a control concept for real-time freeway traffic management. The benefits of MTFC for
|
||||||
|
efficient freeway traffic flow have been demonstrated recently using an optimal control approach and a
|
||||||
|
feedback control approach. In this paper, both control approaches are reviewed and applied to a freeway
|
||||||
|
network in a simulation environment. The validated network model used reflects an actual freeway (a
|
||||||
|
ring-road), fed with actual (measured) demands. The optimal and feedback control results are discussed,
|
||||||
|
compared and demonstrated to improve significantly the system performance. In particular, the feedback
|
||||||
|
control scheme is deemed suitable for immediate practical application as it takes into account operational
|
||||||
|
requirements and constraints, while its results are shown to be satisfactory. In addition, the control
|
||||||
|
system performance was not very sensitive to variations of the parameters of the feedback controller. This
|
||||||
|
result indicates that the burden associated with fine tuning of the controller may be reduced in the field.
|
||||||
|
</dc:description>
|
||||||
|
<dc:publisher xml:lang="en">ANPET - Associação Nacional de Pesquisa e Ensino em Transportes</dc:publisher>
|
||||||
|
<dc:description xml:lang="en">Presented on: Transportes</dc:description>
|
||||||
|
<dc:type>peer-reviewed</dc:type>
|
||||||
|
<dc:identifier xml:lang="en">Bibliographic citation: R.C. Carlson, I. Papamichail, M. Papageorgiou,
|
||||||
|
"Mainstream traffic flow control on freeways using variable speed limits," Transportes, vol. 21, no. 3, pp.
|
||||||
|
56-65, 2013.
|
||||||
|
doi:10.4237/transportes.v21i3.694
|
||||||
|
</dc:identifier>
|
||||||
|
<dc:relation>info:eu-repo/grantAgreement/EC/FP7/246686</dc:relation>
|
||||||
|
</oai_dc:dc>
|
||||||
|
</metadata>
|
||||||
|
</record>
|
|
@ -0,0 +1,39 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Configuration status="WARN" monitorInterval="30">
|
||||||
|
<Properties>
|
||||||
|
<Property name="LOG_PATTERN">
|
||||||
|
%d %p %t [%c] - %m%n
|
||||||
|
</Property>
|
||||||
|
</Properties>
|
||||||
|
<Appenders>
|
||||||
|
<!-- Rolling File Appender -->
|
||||||
|
<RollingFile name="R" fileName="/var/log/dnet/uoa-validator-api/uoa-validator-api.log"
|
||||||
|
filePattern="/var/log/dnet/uoa-validator-api/uoa-validator-api-%d{yyyy-MM-dd}-%i.log">
|
||||||
|
<PatternLayout>
|
||||||
|
<Pattern>${LOG_PATTERN}</Pattern>
|
||||||
|
</PatternLayout>
|
||||||
|
<Policies>
|
||||||
|
<SizeBasedTriggeringPolicy size="10MB" />
|
||||||
|
</Policies>
|
||||||
|
<DefaultRolloverStrategy max="10"/>
|
||||||
|
</RollingFile>
|
||||||
|
<RollingFile name="S" fileName="/var/log/dnet/uoa-validator-api/uoa-validator-api-spring.log"
|
||||||
|
filePattern="/var/log/dnet/uoa-validator-api/uoa-validator-api-spring-%d{yyyy-MM-dd}-%i.log">
|
||||||
|
<PatternLayout>
|
||||||
|
<Pattern>${LOG_PATTERN}</Pattern>
|
||||||
|
</PatternLayout>
|
||||||
|
<Policies>
|
||||||
|
<SizeBasedTriggeringPolicy size="10MB" />
|
||||||
|
</Policies>
|
||||||
|
<DefaultRolloverStrategy max="10"/>
|
||||||
|
</RollingFile>
|
||||||
|
</Appenders>
|
||||||
|
<Loggers>
|
||||||
|
<Logger name="org.springframework" level="debug" additivity="false">
|
||||||
|
<AppenderRef ref="S"/>
|
||||||
|
</Logger>
|
||||||
|
<Root level="debug">
|
||||||
|
<AppenderRef ref="R"/>
|
||||||
|
</Root>
|
||||||
|
</Loggers>
|
||||||
|
</Configuration>
|
|
@ -0,0 +1,2 @@
|
||||||
|
validatorapi.globalVars.buildDate=@timestamp@
|
||||||
|
validatorapi.globalVars.version=@version@
|
Loading…
Reference in New Issue