forked from mecdcme/is2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
mbruno
authored and
mbruno
committed
Jun 24, 2019
1 parent
ed17214
commit 4622e5b
Showing
9 changed files
with
127 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,7 +111,7 @@ | |
<version>20180130</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
src/main/java/it/istat/is2/rule/engine/EngineValidate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package it.istat.is2.rule.engine; | ||
|
||
import it.istat.is2.app.service.LogService; | ||
import it.istat.is2.workflow.domain.SxRule; | ||
import java.util.List; | ||
import org.apache.log4j.Logger; | ||
import org.rosuda.REngine.Rserve.RConnection; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class EngineValidate { | ||
|
||
public static final String INPUT = "input"; | ||
public static final String OUTPUT = "output"; | ||
public static final String SRC_VALIDATE = "validate.R"; | ||
@Value("${serverR.host}") | ||
private String serverRHost; | ||
@Value("${serverR.port}") | ||
private Integer serverRPort; | ||
@Value("${path.script.R}") | ||
private String pathR; | ||
private RConnection connection; | ||
private String[] input; | ||
|
||
@Autowired | ||
private LogService logService; | ||
|
||
public void init() throws Exception { | ||
|
||
logService.save("Connecting to R server..."); | ||
|
||
// Create a connection to Rserve instance running on default port 6311 | ||
if (serverRPort == null || serverRPort == 0) { | ||
serverRPort = 6311; | ||
} | ||
|
||
if (serverRHost == null || serverRHost.equals("") || serverRHost.equals("localhost")) { | ||
connection = new RConnection(); | ||
} else { | ||
connection = new RConnection(serverRHost, serverRPort); | ||
} | ||
|
||
logService.save("Successfully connected!"); | ||
|
||
connection.eval("setwd('" + pathR + "')"); | ||
connection.eval("source('" + SRC_VALIDATE + "')"); | ||
logService.save("Validate R script loaded"); | ||
} | ||
|
||
public void validateRules(List<SxRule> rules) throws Exception { | ||
|
||
init(); | ||
|
||
input = new String[rules.size()]; | ||
for(int i = 0; i < rules.size(); i++){ | ||
input[i] = rules.get(i).getRule().toUpperCase(); | ||
} | ||
connection.assign(INPUT, input); | ||
connection.eval(INPUT + " <- data.frame(rule=" + INPUT + ")"); | ||
connection.eval("print(" + INPUT + ")"); | ||
String[] out = connection.eval("validate(" + INPUT + ")").asStrings(); | ||
|
||
logService.save("Script output " + out[0]); | ||
|
||
destroy(); | ||
} | ||
|
||
public void destroy() { | ||
if (connection != null || !connection.isConnected()) { | ||
connection.close(); | ||
} | ||
logService.save("Connection to R server closed!"); | ||
} | ||
|
||
} |
72 changes: 0 additions & 72 deletions
72
src/main/java/it/istat/is2/rule/service/EngineValidate.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters