-trendylyzer algorithm to new obis db resource;
-spd algorithm to new spd-model dependency version;

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-analysis/EcologicalEngineExternalAlgorithms@97277 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Angela Italiano 2014-06-11 08:56:26 +00:00
parent 5465a7f62f
commit f6313e177e
18 changed files with 492 additions and 314 deletions

View File

@ -6,11 +6,6 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
@ -22,5 +17,10 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@ -1,4 +1,3 @@
#Tue Mar 19 10:56:09 CET 2013
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding/<project>=UTF-8
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding/<project>=UTF-8

View File

@ -1,13 +1,12 @@
#Tue Mar 19 10:56:09 CET 2013
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.6
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.7

64
pom.xml
View File

@ -9,7 +9,7 @@
</parent>
<groupId>org.gcube.dataanalysis</groupId>
<artifactId>ecological-engine-external-algorithms</artifactId>
<version>1.1.1-SNAPSHOT</version>
<version>1.1.3</version>
<name>ecological-engine-external-algorithms</name>
<description>ecological-engine-external-algorithms library</description>
<properties>
@ -19,7 +19,7 @@
<dependency>
<groupId>org.gcube.dataanalysis</groupId>
<artifactId>ecological-engine</artifactId>
<version>1.7.1-SNAPSHOT</version>
<version>[1.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>rapidminer-custom</groupId>
@ -31,6 +31,11 @@
<artifactId>postgresql</artifactId>
<version>8.4-702.jdbc4</version>
</dependency>
<dependency>
<groupId>rapidminer-custom</groupId>
<artifactId>gsay-service</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-gcore-stubs</artifactId>
@ -69,7 +74,6 @@
<groupId>org.gcube.data.spd</groupId>
<artifactId>spd-client-library</artifactId>
<version>[3.0.0-SNAPSHOT, 4.0.0-SNAPSHOT)</version>
<scope>provided</scope>
</dependency>
<!-- This dependency is needed and is need on TOP to use GWT UI BInder
without old Xerces version of gCore complaining -->
@ -79,10 +83,6 @@
<version>2.9.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.data.spd</groupId>
<artifactId>spql-parser</artifactId>
@ -93,53 +93,45 @@
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>csv4j</artifactId>
<version>[1.1.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.data.spd</groupId>
<artifactId>spd-model</artifactId>
<version>[1.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
<!-- <version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version> -->
<!-- UNCOMMENT THIS FOR RELEASE -->
<scope>provided</scope>
<version>[1.0.0-SNAPSHOT, 4.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.gcube.resources.discovery</groupId>
<artifactId>discovery-client</artifactId>
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
<scope>provided</scope>
<groupId>org.gcube.resources.discovery</groupId>
<artifactId>discovery-client</artifactId>
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-clients</artifactId>
<version>[2.0.0-SNAPSHOT,3.0.0-SNAPSHOT)</version>
<groupId>org.gcube.core</groupId>
<artifactId>common-clients</artifactId>
<version>[2.0.0-SNAPSHOT,3.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-gcore-clients</artifactId>
<version>[1.0.0-SNAPSHOT,3.0.0-SNAPSHOT)</version>
<groupId>org.gcube.core</groupId>
<artifactId>common-gcore-clients</artifactId>
<version>[1.0.0-SNAPSHOT,3.0.0-SNAPSHOT)</version>
</dependency>
<!-- <dependency> -->
<!-- <groupId>org.gcube.core</groupId> -->
<!-- <artifactId>common-fw-clients</artifactId> -->
<!-- <version>[1.0.0-SNAPSHOT,3.0.0-SNAPSHOT)</version> -->
<!-- <scope>runtime</scope> -->
<!-- </dependency> -->
<dependency>
<groupId>org.gcube.resources.discovery</groupId>
<artifactId>ic-client</artifactId>
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
<groupId>org.gcube.resources.discovery</groupId>
<artifactId>ic-client</artifactId>
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-scope-maps</artifactId>
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
<groupId>org.gcube.core</groupId>
<artifactId>common-scope-maps</artifactId>
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
</dependency>
</dependencies>
@ -155,8 +147,8 @@
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>

View File

@ -0,0 +1,19 @@
package org.gcube.dataanalysis.JobSMspd;
public class Lock{
private boolean isLocked = false;
public synchronized void lock()
throws InterruptedException{
while(isLocked){
wait();
}
isLocked = true;
}
public synchronized void unlock(){
isLocked = false;
notify();
}
}

View File

@ -186,8 +186,8 @@ public class MapDwCA {
file.write("\t");
//scientificNameAuthorship
if (taxonomyItem.getAuthor()!= null)
file.write(taxonomyItem.getAuthor());
if (taxonomyItem.getScientificNameAuthorship()!= null)
file.write(taxonomyItem.getScientificNameAuthorship());
file.write("\t");
if (taxonomyItem.getCitation()!= null)

View File

@ -2,17 +2,16 @@ package org.gcube.dataanalysis.JobSMspd;
import static org.gcube.data.spd.client.plugins.AbstractPlugin.manager;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.reflect.Field;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
@ -26,9 +25,6 @@ import org.gcube.data.spd.client.proxies.Manager;
import org.gcube.data.spd.model.Conditions;
import org.gcube.data.spd.model.PluginDescription;
import org.gcube.data.spd.model.util.Capabilities;
import org.gcube.dataanalysis.JobSMspd.TaxaProcedure.DataPenum;
import org.gcube.dataanalysis.JobSMspd.TaxaProcedure.ExtentionDPEnum;
import org.gcube.dataanalysis.JobSMspd.TaxaProcedure.UnfoldDPEnum;
import org.gcube.dataanalysis.ecoengine.configuration.AlgorithmConfiguration;
import org.gcube.dataanalysis.ecoengine.datatypes.ColumnTypesList;
import org.gcube.dataanalysis.ecoengine.datatypes.DatabaseType;
@ -56,10 +52,10 @@ public class OccurencesProcedure extends StandardLocalExternalAlgorithm {
SessionFactory dbconnection = null;
// public static boolean call=false;
String tablename;
File outputResult;
String columnnames;
List<Object> speciesList=null;
List<Object> speciesList = null;
protected String fileName;
BufferedWriter out;
String outputtablename;
String outputErrortablename;
String outputtable;
@ -77,6 +73,7 @@ public class OccurencesProcedure extends StandardLocalExternalAlgorithm {
// private String chosendataProviderUnfold="Data Provider Unfold:";
private String dataProviderUnfold = "Data Provider (Unfold Option):";
private String chosendataProviderUnfold = new String();
private Lock lock = new Lock();
@Override
public String getDescription() {
@ -86,6 +83,8 @@ public class OccurencesProcedure extends StandardLocalExternalAlgorithm {
@Override
public void init() throws Exception {
AnalysisLogger.getLogger().debug("SMFaoAlg");
AnalysisLogger.getLogger().debug("Init scope :"+ScopeProvider.instance.get());
}
@ -109,7 +108,7 @@ public class OccurencesProcedure extends StandardLocalExternalAlgorithm {
speciesList = DatabaseFactory.executeSQLQuery("select " + columnlist[0]
+ " from " + tablename, dbconnection);
fileName = super.config.getPersistencePath() + "results.csv";
out = new BufferedWriter(new FileWriter(fileName));
outputResult= new File(fileName);
}
@ -118,6 +117,11 @@ public class OccurencesProcedure extends StandardLocalExternalAlgorithm {
try {
String scope = ScopeProvider.instance.get();
AnalysisLogger.getLogger().debug("process scope :"+scope);
AnalysisLogger.getLogger().debug(
"-------Procedure config scope"
+ config.getGcubeScope());
fulfilParameters();
createTables();
int lenght = (int) (speciesList.size() / 3);
@ -152,13 +156,16 @@ public class OccurencesProcedure extends StandardLocalExternalAlgorithm {
th1.join();
th2.join();
th3.join();
write("scientific_name; author; catalogue_number; citation; collection_gode; cordinate_uncertaninty_in_meters; country;"
+ "credits; family; id; institution_code; kingdom; locality; providere; latitude; longitude; max_depth; min_depth");
out.newLine();
insertInTheTable(t1.getInfo());
insertInTheTable(t2.getInfo());
insertInTheTable(t3.getInfo());
File []files= new File[3];
if(t1.getInfo()!= null)
files[0]=t1.getInfo();
if(t1.getInfo()!= null)
files[1]=t2.getInfo();
if(t1.getInfo()!= null)
files[2]=t3.getInfo();
mergeFiles(files, outputResult);
insertInTheTableErrors(t1.getErrors());
insertInTheTableErrors(t2.getErrors());
@ -167,12 +174,12 @@ public class OccurencesProcedure extends StandardLocalExternalAlgorithm {
} catch (Exception e) {
e.printStackTrace();
AnalysisLogger.getLogger().debug(e.toString());
throw e;
} finally {
DatabaseUtils.closeDBConnection(dbconnection);
out.close();
}
}
@ -183,33 +190,33 @@ public class OccurencesProcedure extends StandardLocalExternalAlgorithm {
+ " (error character varying)", dbconnection);
}
private void insertInTheTable(ArrayList<ArrayList<String>> arrays)
throws Exception {
for (ArrayList<String> array : arrays) {
// String query = "insert into " + outputtable + st + " values (";
String writeString = new String();
int i = 0;
for (String s : array) {
if (i != 0) {
writeString = writeString + "; ";
}
writeString = writeString + " '";
if (s != null)
s = s.replace("'", "");
writeString = writeString + s;
writeString = writeString + "'";
i++;
}
write(writeString);
out.newLine();
}
}
// private void insertInTheTable(ArrayList<ArrayList<String>> arrays)
// throws Exception {
//
// for (ArrayList<String> array : arrays) {
// // String query = "insert into " + outputtable + st + " values (";
// String writeString = new String();
// int i = 0;
//
// for (String s : array) {
// if (i != 0) {
// writeString = writeString + "; ";
// }
// writeString = writeString + " '";
// if (s != null)
// s = s.replace("'", "");
// writeString = writeString + s;
//
// writeString = writeString + "'";
// i++;
//
// }
// write(writeString);
// out.newLine();
//
// }
//
// }
private void insertInTheTableErrors(ArrayList<String> arrays)
throws Exception {
@ -226,58 +233,79 @@ public class OccurencesProcedure extends StandardLocalExternalAlgorithm {
}
private void insertEnumValuesr() {
AnalysisLogger.getLogger().debug(" insertEnumValuesr");
AnalysisLogger.getLogger().debug(" second version");
if (dp == null || dpU == null || dpE == null) {
dp = new DataPenum();
dpE = new ExtentionDPEnum();
dpU = new UnfoldDPEnum();
setDynamicParameter();
try {
setDynamicParameter();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
AnalysisLogger.getLogger().debug(" call setDynamicParameter");
}
if (dp != null) {
try {
if (UnfoldDPEnumType.values().length == 0) {
AnalysisLogger.getLogger().debug("Only one provider.");
dp = new DataPenum();
dpE = new ExtentionDPEnum();
dpU = new UnfoldDPEnum();
setDynamicParameter();
}
} catch (Exception e) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
AnalysisLogger.getLogger().debug(sw.toString());
}
}
}
@Override
public void shutdown() {
AnalysisLogger.getLogger().debug("Shut down ");
}
private void setDynamicParameter() {
private void setDynamicParameter() throws InterruptedException {
AnalysisLogger.getLogger().debug("Inside setDynamicParameter");
// ScopeProvider.instance.set("/gcube/devsec");
AnalysisLogger.getLogger().debug(
"Procedure called in the scope"
"-------Procedure setParameter in the scope"
+ ScopeProvider.instance.get().toString());
Manager manager = null;
manager = manager().build();
AnalysisLogger.getLogger().debug("build Manager");
AnalysisLogger.getLogger().debug("before dei plugin");
List<PluginDescription> plugin=null;
try{
List<PluginDescription> plugin = null;
try {
plugin = manager.getPluginsDescription();
}
catch(Exception e)
{
String eTracMes= e.getMessage();
} catch (Exception e) {
String eTracMes = e.getMessage();
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
sw.toString();
AnalysisLogger.getLogger().debug(eTracMes);
AnalysisLogger.getLogger().debug(sw.toString());
}
finally
{
e.printStackTrace();
} finally {
lock.lock();
dp.addEnum(DataProvidersType.class, "ALL");
dpE.addEnum(ExtentionDPType.class, "ALL");
dpU.addEnum(UnfoldDPEnumType.class, "NO OPTION");
dpE.addEnum(ExtentionDPType.class, "NO OPTION");
lock.unlock();
}
AnalysisLogger.getLogger().debug("get plugin");
if (plugin != null) {
AnalysisLogger.getLogger().debug(
@ -297,9 +325,9 @@ public class OccurencesProcedure extends StandardLocalExternalAlgorithm {
for (Entry<Capabilities, List<Conditions>> pluginCapability : pluginCapabilities
.entrySet()) {
Capabilities capability = pluginCapability.getKey();
String capabilityName=capability.name().toString();
String capabilityName = capability.name().toString();
AnalysisLogger.getLogger().debug(capabilityName);
if (capabilityName.equals("Unfold"))
dpU.addEnum(UnfoldDPEnumType.class, pluginDescription
@ -347,11 +375,9 @@ public class OccurencesProcedure extends StandardLocalExternalAlgorithm {
ServiceParameters.RANDOMSTRING, "OutputTable", "", "occ");
ServiceType randomstringErr = new ServiceType(
ServiceParameters.RANDOMSTRING, "ErrorTable", "", "err");
insertEnumValuesr();
addEnumerateInput(DataProvidersType.values(), dataProvider,
"Choose Data Providere", "ALL");
AnalysisLogger.getLogger().debug("After DataProvidersType");
@ -361,7 +387,6 @@ public class OccurencesProcedure extends StandardLocalExternalAlgorithm {
addEnumerateInput(UnfoldDPEnumType.values(), dataProviderUnfold,
"Choose UnfoldRR Option Data Providere", "ALL");
AnalysisLogger.getLogger().debug("After UnfoldDPEnumType");
inputs.add(tinput);
inputs.add(columns);
inputs.add(randomstring);
@ -385,8 +410,7 @@ public class OccurencesProcedure extends StandardLocalExternalAlgorithm {
OutputTable outErr = new OutputTable(outtemplate, outputErrortablename,
tableError, "The output table containing all the matches");
PrimitiveType f = new PrimitiveType(File.class.getName(), new File(
fileName), PrimitiveTypes.FILE, "OccFile", "OccFile");
PrimitiveType f = new PrimitiveType(File.class.getName(), outputResult, PrimitiveTypes.FILE, "OccFile", "OccFile");
map.put("Output", f);
map.put("Errors", outErr);
PrimitiveType output = new PrimitiveType(HashMap.class.getName(), map,
@ -396,17 +420,6 @@ public class OccurencesProcedure extends StandardLocalExternalAlgorithm {
}
public void write(String writeSt) {
try {
out.write(writeSt);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
enum DataProvidersType {
}
@ -438,4 +451,57 @@ public class OccurencesProcedure extends StandardLocalExternalAlgorithm {
}
}
public static void mergeFiles(File[] files, File mergedFile) {
AnalysisLogger.getLogger().debug("Inside mergeFiles");
if (mergedFile.exists()){
mergedFile.delete();
}
FileWriter fstream = null;
BufferedWriter out = null;
try {
fstream = new FileWriter(mergedFile, true);
out = new BufferedWriter(fstream);
} catch (IOException e1) {
e1.printStackTrace();
}
String title = "institutionCode, " + "collectionCode, "
+ "catalogueNumber, " + "dataSet, " + "dataProvider, "
+ "dataSource, " + "scientificNameAuthorship,"
+ "identifiedBy," + "credits," + "recordedBy, " + "eventDate, "
+ "modified, " + "scientificName, " + "kingdom, " + "family, "
+ "locality, " + "country, " + "citation, "
+ "decimalLatitude, " + "decimalLongitude, "
+ "coordinateUncertaintyInMeters, " + "maxDepth, "
+ "minDepth, " + "basisOfRecord";
try {
out.write(title);
out.newLine();
for (File f : files) {
System.out.println("merging: " + f.getName());
FileInputStream fis;
fis = new FileInputStream(f);
BufferedReader in = new BufferedReader(new InputStreamReader(
fis));
String aLine;
while ((aLine = in.readLine()) != null) {
out.write(aLine);
out.newLine();
}
in.close();
}
} catch (IOException e) {
e.printStackTrace();
}
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@ -63,7 +63,7 @@ public class TaxaProcedure extends StandardLocalExternalAlgorithm {
// public static boolean call=false;
String tablename;
String columnnames;
List<Object> speciesList=null;
List<Object> speciesList = null;
// protected String fileName;
// BufferedWriter out;
String outputtablename;
@ -73,8 +73,8 @@ public class TaxaProcedure extends StandardLocalExternalAlgorithm {
HashMap<String, String> dpUHash = new HashMap<String, String>();
HashMap<String, String> dpEHash = new HashMap<String, String>();
String tableError;
private static DataPenum dp = null;
private static ExtentionDPEnum dpE = null;
private static DataPenum dp = null;
private static ExtentionDPEnum dpE = null;
private static UnfoldDPEnum dpU = null;
private String dataProvider = "Data Provider :";
private String chosendataProvider = new String();
@ -84,6 +84,8 @@ public class TaxaProcedure extends StandardLocalExternalAlgorithm {
private String dataProviderUnfold = "Data Provider (Unfold Option):";
private String chosendataProviderUnfold = new String();
File file;
private Lock lock = new Lock();
@Override
public String getDescription() {
@ -228,24 +230,43 @@ public class TaxaProcedure extends StandardLocalExternalAlgorithm {
}
@Override
public void shutdown() {
AnalysisLogger.getLogger().debug("Shut down ");
}
private void insertEnumValuesr() {
if (dp == null || dpU == null || dpE == null) {
dp = new DataPenum();
dpE = new ExtentionDPEnum();
dpU = new UnfoldDPEnum();
setDynamicParameter();
}
private void insertEnumValuesr() {
AnalysisLogger.getLogger().debug(" insertEnumValuesr");
// if (dp == null || dpU == null || dpE == null) {
// dp = new DataPenum();
// dpE = new ExtentionDPEnum();
// dpU = new UnfoldDPEnum();
// AnalysisLogger.getLogger().debug(" call setDynamicParameter");
//
// setDynamicParameter();
//
// }
// if (dp != null) {
try {
if (UnfoldDPEnumType.values().length == 0) {
AnalysisLogger.getLogger().debug("Only one provider.");
dp = new DataPenum();
dpE = new ExtentionDPEnum();
dpU = new UnfoldDPEnum();
setDynamicParameter();
}
} catch (Exception e) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
AnalysisLogger.getLogger().debug(sw.toString());
}
// }
}
private void setDynamicParameter() {
private void setDynamicParameter() {
AnalysisLogger.getLogger().debug("Inside setDynamicParameter");
AnalysisLogger.getLogger().debug(
"Procedure called in the scope"
@ -259,18 +280,24 @@ public class TaxaProcedure extends StandardLocalExternalAlgorithm {
try {
plugin = manager.getPluginsDescription();
} catch (Exception e) {
String eTracMes= e.getMessage();
String eTracMes = e.getMessage();
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
sw.toString();
AnalysisLogger.getLogger().debug(eTracMes);
AnalysisLogger.getLogger().debug(sw.toString());
} finally {
try {
lock.lock();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
dp.addEnum(DataProvidersType.class, "ALL");
dpE.addEnum(ExtentionDPType.class, "ALL");
dpU.addEnum(UnfoldDPEnumType.class, "NO OPTION");
dpE.addEnum(ExtentionDPType.class, "NO OPTION");
lock.unlock();
}
AnalysisLogger.getLogger().debug("get plugin");
@ -283,7 +310,6 @@ public class TaxaProcedure extends StandardLocalExternalAlgorithm {
for (int i = 0; i < plugin.size(); i++) {
PluginDescription pluginDescription = plugin.get(i);
AnalysisLogger.getLogger().debug(
"For plugin ***" + pluginDescription.getName());
@ -297,9 +323,8 @@ public class TaxaProcedure extends StandardLocalExternalAlgorithm {
.entrySet()) {
Capabilities capability = pluginCapability.getKey();
String capabilityName=capability.name().toString();
AnalysisLogger.getLogger().debug(
capabilityName);
String capabilityName = capability.name().toString();
AnalysisLogger.getLogger().debug(capabilityName);
if (capabilityName.equals("Unfold")) {
dpU.addEnum(UnfoldDPEnumType.class, pluginDescription
@ -355,13 +380,13 @@ public class TaxaProcedure extends StandardLocalExternalAlgorithm {
addEnumerateInput(DataProvidersType.values(), dataProvider,
"Choose Data Providere", "ALL");
AnalysisLogger.getLogger().debug("Dopo DataProvidersType");
AnalysisLogger.getLogger().debug("After DataProvidersType");
addEnumerateInput(ExtentionDPType.values(), dataProviderExtention,
"Choose Expand Option Data Providere", "ALL");
AnalysisLogger.getLogger().debug("Dopo ExtentionDPType");
AnalysisLogger.getLogger().debug("After ExtentionDPType");
addEnumerateInput(UnfoldDPEnumType.values(), dataProviderUnfold,
"Choose Unfold Option Data Providere", "ALL");
AnalysisLogger.getLogger().debug("Dopo UnfoldDPEnumType");
AnalysisLogger.getLogger().debug("After UnfoldDPEnumType");
inputs.add(tinput);
inputs.add(columns);

View File

@ -2,6 +2,11 @@ package org.gcube.dataanalysis.JobSMspd;
import static org.gcube.data.spd.client.plugins.AbstractPlugin.manager;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import org.gcube.common.scope.api.ScopeProvider;
@ -9,147 +14,220 @@ import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
import org.gcube.data.spd.client.proxies.Manager;
import org.gcube.data.spd.model.products.OccurrencePoint;
import org.gcube.data.spd.model.products.ResultElement;
import org.gcube.data.streams.Stream;
public class ThreadExtractionOccFromSPD implements Runnable {
private ArrayList<String> chunk;
private ArrayList<ArrayList<String>> informations;
private ArrayList<String> errors;
BufferedWriter out;
private String dataProvider;
private String dataProviderUnfold;
private String dataProviderExpand;
String scope;
private File tempFile;
public ThreadExtractionOccFromSPD(ArrayList<String> chunk, String dataProvider,String dataProviderExpand,String dataProviderUnfold,String scope ) {
public ThreadExtractionOccFromSPD(ArrayList<String> chunk,
String dataProvider, String dataProviderExpand,
String dataProviderUnfold, String scope) {
this.chunk = chunk;
for (String species : chunk) {
// AnalysisLogger.getLogger().debug(species);
}
this.dataProvider=dataProvider;
this.dataProviderExpand= dataProviderExpand;
this.dataProviderUnfold=dataProviderUnfold;
informations = new ArrayList<ArrayList<String>>();
errors= new ArrayList<String>();
this.scope=scope;
this.dataProvider = dataProvider;
this.dataProviderExpand = dataProviderExpand;
this.dataProviderUnfold = dataProviderUnfold;
errors = new ArrayList<String>();
this.scope = scope;
}
public void run() {
AnalysisLogger.getLogger().debug("SCOPE *******: "+scope);
AnalysisLogger.getLogger().debug("SCOPE " + scope);
try {
tempFile = File.createTempFile("chunk"
+ Thread.currentThread().getId(), ".csv");
out = new BufferedWriter(new FileWriter(tempFile, false));
} catch (Exception e) {
AnalysisLogger.getLogger().error(
"Error in the chunk file creation: " + e);
}
ScopeProvider.instance.set(scope);
Manager manager=null;
try{
Manager manager = null;
try {
manager = manager().build();
for (String species : chunk) {
if (species != null) {
String query = new String();
for (String species : chunk) {
if (species != null) {
String query = new String();
query = createQueryParameter(species);
AnalysisLogger.getLogger().debug("QUERY *******: " + query);
Stream<ResultElement> stream;
try {
stream = manager.search(query);
int i = 0;
while (stream.hasNext()) {
i++;
OccurrencePoint ti = (OccurrencePoint) stream
.next();
ArrayList<String> array = crateRowTable(ti);
query=createQueryParameter(species);
AnalysisLogger.getLogger().debug("QUERY *******: "+query);
Stream<ResultElement> stream;
try {
stream = manager.search(query);
int i=0;
while (stream.hasNext()) {
i++;
OccurrencePoint ti = (OccurrencePoint) stream.next();
informations.add(crateRowTable(ti));
insertInTheFile(array);
array = null;
System.gc();
}
if (i == 0) {
errors.add(species + " not found.");
}
} catch (Exception e) {
errors.add("Exception on " + species + " :"
+ e.getMessage());
e.printStackTrace();
}
if(i==0)
{
errors.add(species+" not found.");
}
} catch (Exception e) {
errors.add("Exception on "+species+" :"+ e.getMessage());
e.printStackTrace();
}
}
}
}catch(Throwable e){
out.close();
} catch (Throwable e) {
e.printStackTrace();
AnalysisLogger.getLogger().debug("An error occurred: "+e.getMessage());
AnalysisLogger.getLogger().debug(
"An error occurred: " + e.getMessage());
}
}
private String createQueryParameter(String species)
{
String query= "SEARCH BY SN '"+species +"'";
String where=new String();
String expand=new String();
String unfold=new String();
if(dataProvider.equals("ALL"))
where="";
else
where=" IN "+dataProvider;
if(dataProviderUnfold.equals("NO OPTION"))
unfold="";
else
unfold=" UNFOLD WITH "+dataProviderUnfold;
query= query +unfold;
AnalysisLogger.getLogger().debug("expand is : "+dataProviderExpand);
if(dataProviderExpand.equals("ALL"))
{expand=" EXPAND";}
else{
private String createQueryParameter(String species) {
String query = "SEARCH BY SN '" + species + "'";
String where = new String();
String expand = new String();
String unfold = new String();
if (dataProvider.equals("ALL"))
where = "";
else
where = " IN " + dataProvider;
if (dataProviderUnfold.equals("NO OPTION"))
unfold = "";
else
unfold = " UNFOLD WITH " + dataProviderUnfold;
query = query + unfold;
AnalysisLogger.getLogger().debug("expand is : " + dataProviderExpand);
if (dataProviderExpand.equals("ALL")) {
expand = " EXPAND";
} else {
AnalysisLogger.getLogger().debug("inside else ");
if(dataProviderExpand.equals("NO OPTION"))
expand="";
if (dataProviderExpand.equals("NO OPTION"))
expand = "";
else
expand=" EXPAND WITH "+dataProviderExpand;
expand = " EXPAND WITH " + dataProviderExpand;
}
query= query+ expand;
query=query+ where;
query= query +" RETURN occurrence";
query = query + expand;
query = query + where;
query = query + " RETURN occurrence";
return query;
}
private ArrayList<String> crateRowTable(OccurrencePoint p)
{
ArrayList<String> infoOcc= new ArrayList<String>();
infoOcc.add(p.getScientificName());
infoOcc.add(p.getAuthor());
infoOcc.add(p.getCatalogueNumber());
infoOcc.add(p.getCitation());
infoOcc.add(p.getCollectionCode());
infoOcc.add(p.getCoordinateUncertaintyInMeters());
infoOcc.add(p.getCountry());
infoOcc.add(p.getCredits());
infoOcc.add(p.getFamily());
infoOcc.add(p.getId());
infoOcc.add(p.getInstitutionCode());
infoOcc.add(p.getKingdom());
infoOcc.add(p.getLocality());
infoOcc.add(p.getProvider());
infoOcc.add((Double.toString(p.getDecimalLatitude())));
infoOcc.add((Double.toString(p.getDecimalLongitude())));
infoOcc.add((Double.toString(p.getMaxDepth())));
infoOcc.add((Double.toString(p.getMinDepth())));
private ArrayList<String> crateRowTable(OccurrencePoint occurrence) {
ArrayList<String> infoOcc = new ArrayList<String>();
infoOcc.add(occurrence.getInstitutionCode().replace(",", " "));
infoOcc.add(occurrence.getCollectionCode().replace(",", " "));
infoOcc.add(occurrence.getCatalogueNumber().replace(",", " "));
infoOcc.add(occurrence.getDataSet().getName());
infoOcc.add(occurrence.getDataSet().getDataProvider().getName());
infoOcc.add(occurrence.getProvider());
infoOcc.add(occurrence.getScientificNameAuthorship());
infoOcc.add(occurrence.getIdentifiedBy());
infoOcc.add(occurrence.getCredits());
infoOcc.add(occurrence.getRecordedBy());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
if (occurrence.getEventDate() == null
|| sdf.format(occurrence.getEventDate().getTime()).length() == 0)
infoOcc.add("");
else
infoOcc.add(sdf.format(occurrence.getEventDate().getTime()));
if (occurrence.getModified() == null
|| sdf.format(occurrence.getModified().getTime()).length() == 0)
infoOcc.add("");
else
infoOcc.add(sdf.format(occurrence.getModified().getTime()));
infoOcc.add(occurrence.getScientificName());
infoOcc.add(occurrence.getKingdom());
infoOcc.add(occurrence.getFamily());
infoOcc.add(occurrence.getLocality());
infoOcc.add(occurrence.getCountry());
infoOcc.add(occurrence.getCitation());
infoOcc.add(Double.toString(occurrence.getDecimalLatitude()));
infoOcc.add(Double.toString(occurrence.getDecimalLongitude()));
infoOcc.add(occurrence.getCoordinateUncertaintyInMeters());
infoOcc.add(Double.toString(occurrence.getMaxDepth()));
infoOcc.add(Double.toString(occurrence.getMinDepth()));
infoOcc.add(occurrence.getBasisOfRecord().toString());
return infoOcc;
}
public ArrayList<ArrayList<String>> getInfo()
{
return informations;
private void insertInTheFile(ArrayList<String> array) throws Exception {
// AnalysisLogger.getLogger().debug("INSIDE insertInTheFile");
// String query = "insert into " + outputtable + st + " values (";
String writeString = new String();
int i = 0;
for (String s : array) {
if (i == array.size() - 1) {
if (s == null)
writeString = writeString + " ";
else {
writeString = writeString + s.replace(",", " ");
}
} else if (s == null)
{
writeString = writeString + " ,";
//index of timestamp value, is needed void field
if(i==10||i==11)
writeString = writeString + ",";
}
else {
writeString = writeString + s.replace(",", " ") + ",";
}
i++;
}
// AnalysisLogger.getLogger().debug("record is "+writeString);
write(writeString);
out.newLine();
}
public ArrayList<String> getErrors()
{
private void write(String writeSt) {
try {
out.write(writeSt);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public File getInfo() {
return tempFile;
}
public ArrayList<String> getErrors() {
return errors;
}
}

View File

@ -143,7 +143,7 @@ public class ThreadExtractionTaxaFromSPD implements Runnable {
{
ArrayList<String> infoOcc= new ArrayList<String>();
infoOcc.add(p.getScientificName());
infoOcc.add(p.getAuthor());
infoOcc.add(p.getScientificNameAuthorship());
infoOcc.add(p.getCitation());
infoOcc.add(p.getCredits());
infoOcc.add(p.getId());

View File

@ -37,9 +37,9 @@ public class AbsoluteSpeciesBarChartsAlgorithm extends
static String urlParameterName = "DatabaseURL";
protected String fileName;
BufferedWriter out;
private String firstSpeciesNumber = " SpeciesNumber :";
private String yearStart = "Start year :";
private String yearEnd = "End year :";
private String firstSpeciesNumber = "Species_number";
private String yearStart = "Start_year";
private String yearEnd = "End_year";
private int speciesNumber;
String databaseJdbc;
String year_start;
@ -56,7 +56,7 @@ public class AbsoluteSpeciesBarChartsAlgorithm extends
@Override
public String getDescription() {
return ": A transducer algorithm that produces the list of top n most observed taxa, i.e. the species taxa having the largest number of occurrence records, in the OBIS database in a given time interval";
return "An algorithm producing a bar chart for the most observed species in a certain years range (with respect to the OBIS database)";
}
public void fulfilParameters() {
@ -122,7 +122,7 @@ public class AbsoluteSpeciesBarChartsAlgorithm extends
"10");
addStringInput(yearStart, "Starting year of the analysis", "1800");
addStringInput(yearEnd, "Ending year of the analysis", "2020");
addRemoteDatabaseInput("Obis2Repository", urlParameterName,
addRemoteDatabaseInput("TrendyLyzerObis", urlParameterName,
userParameterName, passwordParameterName, "driver", "dialect");
}

View File

@ -90,7 +90,7 @@ public class SimpleAlgorithm extends StandardLocalExternalAlgorithm{
@Override
protected void setInputParameters() {
addStringInput(species, "Slected species", "Solea solea");
addRemoteDatabaseInput("Obis2Repository", urlParameterName,
addRemoteDatabaseInput("TrendyLyzerObis", urlParameterName,
userParameterName, passwordParameterName, "driver", "dialect");

View File

@ -31,10 +31,10 @@ public class SpeciesObservationsAreaBarChart extends
static String userParameterName = "DatabaseUserName";
static String passwordParameterName = "DatabasePassword";
static String urlParameterName = "DatabaseURL";
private String species = "Species :";
private String yearStart = "Start year :";
private String yearEnd = "End year :";
private String area = "Area :";
private String species = "Species";
private String yearStart = "Start_year";
private String yearEnd = "End_year";
private String area = "Area";
private String selectedSpecies;
private DefaultCategoryDataset defaultcategorydataset;
private LinkedHashMap<String, StatisticalType> map = new LinkedHashMap<String, StatisticalType>();
@ -58,9 +58,9 @@ public class SpeciesObservationsAreaBarChart extends
"SpeciesObservationsAreaBarChart Initialization");
}
@Override
@Override
public String getDescription() {
return "A transducer algorithm that produces a chart reporting single species distribution per area (e.g. LME or MEOW) in the OBIS database in a given time interval for selected species.";
return "An algorithm producing a bar chart for the distribution of a species along a certain type of marine area (e.g. LME or MEOW)";
}
@ -135,7 +135,7 @@ public class SpeciesObservationsAreaBarChart extends
AreaEnum.LME.name());
addStringInput(yearStart, "Starting year of the analysis", "1800");
addStringInput(yearEnd, " Ending year of the analysis", "2020");
addRemoteDatabaseInput("Obis2Repository", urlParameterName,
addRemoteDatabaseInput("TrendyLyzerObis", urlParameterName,
userParameterName, passwordParameterName, "driver", "dialect");
}

View File

@ -40,11 +40,11 @@ public class SpeciesObservationsPerLMEAreaPerYearLineChart extends StandardLocal
static String userParameterName = "DatabaseUserName";
static String passwordParameterName = "DatabasePassword";
static String urlParameterName = "DatabaseURL";
private String yearStart = "Start Year";
private String yearEnd = "End Year";
private String yearStart = "Start_year";
private String yearEnd = "End_year";
private Hashtable areaTable= new Hashtable<String , String>();
private static String area = "AreaType";
private String choseArea = "Area Name:";
private static String area = "Area_type";
private String choseArea = "Area_name";
private String selectedAreaName;
static int justcall=0;
private String[] speciesNames;
@ -62,10 +62,10 @@ public class SpeciesObservationsPerLMEAreaPerYearLineChart extends StandardLocal
String databaseUser=new String() ;
String databasePwd =new String();
@Override
@Override
protected void setInputParameters() {
addRemoteDatabaseInput("Obis2Repository", urlParameterName,
addRemoteDatabaseInput("TrendyLyzerObis", urlParameterName,
userParameterName, passwordParameterName, "driver", "dialect");
if(justcall==0)
{ justcall=1;
@ -77,6 +77,7 @@ public class SpeciesObservationsPerLMEAreaPerYearLineChart extends StandardLocal
}
}
addEnumerateInput(LMEenumType.values(), area, "Choose the area name",
Util.formatAreaName("NORTH SEA"));
@ -175,7 +176,7 @@ public class SpeciesObservationsPerLMEAreaPerYearLineChart extends StandardLocal
}
@Override
public String getDescription() {
return "A transducer algorithm that calculates the number of species observation in the OBIS database during a given time interval for selected species and LME area.";
return "Algorithm returning most observed species in a specific years range (data collected from OBIS database).";
}
public void fulfilParameters() throws IOException {

View File

@ -38,11 +38,11 @@ public class SpeciesObservationsPerMEOWAreaPerYearLineChart extends StandardLoca
static String userParameterName = "DatabaseUserName";
static String passwordParameterName = "DatabasePassword";
static String urlParameterName = "DatabaseURL";
private String yearStart = "Start Year";
private String yearEnd = "End Year";
private String yearStart = "Start_year";
private String yearEnd = "End_year";
private Hashtable areaTable= new Hashtable<String , String>();
private static String area = "AreaType";
private String choseArea = "Area Name:";
private static String area = "Area_type";
private String choseArea = "Area_name";
private String selectedAreaName;
static int justcall=0;
private String[] speciesNames;
@ -62,11 +62,10 @@ public class SpeciesObservationsPerMEOWAreaPerYearLineChart extends StandardLoca
@Override
protected void setInputParameters() {
addRemoteDatabaseInput("Obis2Repository", urlParameterName,
addRemoteDatabaseInput("TrendyLyzerObis", urlParameterName,
userParameterName, passwordParameterName, "driver", "dialect");
if(justcall==0)
{ justcall=1;
try {
queryArea(getStaticConnection());
} catch (Exception e) {
@ -174,7 +173,7 @@ public class SpeciesObservationsPerMEOWAreaPerYearLineChart extends StandardLoca
}
@Override
public String getDescription() {
return "A transducer algorithm that calculates the number of species observation in the OBIS database during a given time interval for selected species and MEOW area.";
return "Algorithm returning most observed species in a specific years range (data collected from OBIS database).";
}
public void fulfilParameters() throws Exception {

View File

@ -37,8 +37,8 @@ public class SpeciesObservationsPerYear extends StandardLocalExternalAlgorithm {
static String userParameterName = "DatabaseUserName";
static String passwordParameterName = "DatabasePassword";
static String urlParameterName = "DatabaseURL";
private String yearStart = "Start Year :";
private String yearEnd = "End Year :";
private String yearStart = "Start_year";
private String yearEnd = "End_year";
private String[] speciesNames;
private TimeSeriesCollection dataset;
protected String fileName;
@ -53,7 +53,7 @@ public class SpeciesObservationsPerYear extends StandardLocalExternalAlgorithm {
@Override
public String getDescription() {
return "A transducer algorithm that calculates the number of species observation in the OBIS database per year in a given time interval for selected species.";
return "An algorithm producing the trend of the observations for a certain species in a certain years range.";
}
@ -157,7 +157,7 @@ public class SpeciesObservationsPerYear extends StandardLocalExternalAlgorithm {
addStringInput(yearEnd, "Ending year of the analysis", "2020");
PrimitiveTypesList speciesSelected = new PrimitiveTypesList(String.class.getName(),PrimitiveTypes.STRING, "Selected species", "List of the species to analyze", false);
super.inputs.add(speciesSelected);
addRemoteDatabaseInput("Obis2Repository", urlParameterName,
addRemoteDatabaseInput("TrendyLyzerObis", urlParameterName,
userParameterName, passwordParameterName, "driver", "dialect");
}

View File

@ -29,13 +29,13 @@ public class TaxaObservationsBarChartAlgorithm extends StandardLocalExternalAlg
static String userParameterName = "DatabaseUserName";
static String passwordParameterName = "DatabasePassword";
static String urlParameterName = "DatabaseURL";
private String yearStart = "Start Year :";
private String yearEnd = "End Year :";
private String taxa = "Level :";
private String yearStart = "Start_year";
private String yearEnd = "End_year";
private String taxa = "Level";
String tax;
protected String fileName;
BufferedWriter out;
private String firstTaxaNumber = "TaxaNumber :";
private String firstTaxaNumber = "Taxa_number";
private int taxaNumber;
LinkedHashMap<String, StatisticalType> map = new LinkedHashMap<String, StatisticalType>();
private DefaultCategoryDataset dataset;
@ -48,7 +48,7 @@ public class TaxaObservationsBarChartAlgorithm extends StandardLocalExternalAlg
@Override
public String getDescription() {
return "A transducer algorithm that calculates the number of observations in the OBIS database per year in a given time interval for a selected taxonomic group at a given rank.";
return "An algorithm producing a bar chart for the most observed taxa in a certain years range (with respect to the OBIS database)";
}
@ -125,7 +125,7 @@ public class TaxaObservationsBarChartAlgorithm extends StandardLocalExternalAlg
addStringInput(yearStart, "Starting year of the analysis", "1800");
addStringInput(yearEnd, "Ending year of the analysis", "2020");
// addStringInput("Species", "The species", config.getParam("Species"));
addRemoteDatabaseInput("Obis2Repository", urlParameterName,
addRemoteDatabaseInput("TrendyLyzerObis", urlParameterName,
userParameterName, passwordParameterName, "driver", "dialect");
}

View File

@ -34,9 +34,9 @@ public class TaxaObservationsPerYearLineChart
static String userParameterName = "DatabaseUserName";
static String passwordParameterName = "DatabasePassword";
static String urlParameterName = "DatabaseURL";
private String yearStart = "Start year :";
private String yearEnd = "End year :";
private String taxa = "Level :";
private String yearStart = "Start_year";
private String yearEnd = "End_year";
private String taxa = "Level";
private String tax;
private String[] taxaNames;
@ -145,7 +145,7 @@ public class TaxaObservationsPerYearLineChart
super.inputs.add(taxaSelected);
// addStringInput("Species", "The species", config.getParam("Species"));
addRemoteDatabaseInput("Obis2Repository", urlParameterName,
addRemoteDatabaseInput("TrendyLyzerObis", urlParameterName,
userParameterName, passwordParameterName, "driver", "dialect");
}