-
-
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
Showing
25 changed files
with
2,777 additions
and
52 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
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
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package se.alipsa.munin.model; | ||
|
||
public enum ReportType { | ||
UNMANAGED, MDR | ||
R, MDR, GROOVY, GMD | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/se/alipsa/munin/service/GroovyReportEngine.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,42 @@ | ||
package se.alipsa.munin.service; | ||
|
||
import groovy.lang.GroovyClassLoader; | ||
import org.codehaus.groovy.jsr223.GroovyScriptEngineImpl; | ||
import org.springframework.stereotype.Service; | ||
import se.alipsa.groovy.gmd.Gmd; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import javax.script.ScriptContext; | ||
import javax.script.ScriptException; | ||
|
||
@Service | ||
public class GroovyReportEngine { | ||
|
||
GroovyScriptEngineImpl engine; | ||
|
||
public GroovyReportEngine() { | ||
GroovyClassLoader classLoader = new GroovyClassLoader(); | ||
engine = new GroovyScriptEngineImpl(classLoader); | ||
} | ||
|
||
public String runGroovyReport(String definition, Map<String, Object>... params) throws ScriptException { | ||
try { | ||
if (params.length > 0) { | ||
engine.getBindings(ScriptContext.ENGINE_SCOPE).putAll(params[0]); | ||
} | ||
return String.valueOf(engine.eval(definition)); | ||
} finally { | ||
engine.getBindings(ScriptContext.ENGINE_SCOPE).clear(); | ||
} | ||
} | ||
|
||
public String runGmdReport(String definition, Map<String, Object>... params) { | ||
var gmd = new Gmd(); | ||
if (params.length == 0) { | ||
return gmd.gmdToHtml(definition); | ||
} else { | ||
return gmd.gmdToHtml(definition, params[0]); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package se.alipsa.munin.service; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
import se.alipsa.munin.model.Report; | ||
|
||
import java.util.Map; | ||
import javax.script.ScriptException; | ||
|
||
@Service | ||
public class ReportService { | ||
|
||
private final RenjinReportEngine renjinReportEngine; | ||
private final GroovyReportEngine groovyReportEngine; | ||
|
||
@Autowired | ||
public ReportService(RenjinReportEngine renjinReportEngine, GroovyReportEngine groovyReportEngine) { | ||
this.renjinReportEngine = renjinReportEngine; | ||
this.groovyReportEngine = groovyReportEngine; | ||
} | ||
public String runReport(Report report, Map<String, Object>... params) throws ScriptException, ReportDefinitionException { | ||
return switch (report.getReportType()) { | ||
case R -> renjinReportEngine.runReport(report.getDefinition(), params); | ||
case MDR -> renjinReportEngine.runMdrReport(report.getDefinition(), params); | ||
case GROOVY -> groovyReportEngine.runGroovyReport(report.getDefinition(), params); | ||
case GMD -> groovyReportEngine.runGmdReport(report.getDefinition(), params); | ||
}; | ||
} | ||
} |
Oops, something went wrong.