git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/branches/data-access/obis-spd-plugin/1.8@101888 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
dcc51657cb
commit
77c461eeaa
|
@ -1,4 +1,7 @@
|
|||
<ReleaseNotes>
|
||||
<Changeset component="org.gcube.data-access.obis-spd-plugin.1-8-1" date="2013-11-28">
|
||||
<Change> Added field SNAutorship and Dataset to occurrence points</Change>
|
||||
</Changeset>
|
||||
<Changeset component="org.gcube.data-access.obis-spd-plugin.1-7-0" date="2013-07-18">
|
||||
<Change> Sync with spd-model-library changes</Change>
|
||||
</Changeset>
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -11,7 +11,7 @@
|
|||
|
||||
<groupId>org.gcube.data.spd</groupId>
|
||||
<artifactId>obis-spd-plugin</artifactId>
|
||||
<version>1.8.0-SNAPSHOT</version>
|
||||
<version>1.8.1-SNAPSHOT</version>
|
||||
<name>ObisPlugin</name>
|
||||
<description>obis plugin for species manager service</description>
|
||||
|
||||
|
|
|
@ -79,17 +79,40 @@ public class ObisClient {
|
|||
String credits = generateCredits();
|
||||
//String citation = generateCitation();
|
||||
|
||||
DataSet dataset = getDataSetById(session, productKey.getDataSetId());
|
||||
|
||||
boolean continueWrite = true;
|
||||
while(rs.next() && continueWrite) {
|
||||
|
||||
OccurrencePoint occurrence = generateOccurrencePoint(rs, credits);
|
||||
OccurrencePoint occurrence = generateOccurrencePoint(rs, credits, dataset);
|
||||
continueWrite = writer.write(occurrence);
|
||||
|
||||
};
|
||||
|
||||
rs.close();
|
||||
}
|
||||
|
||||
protected static OccurrencePoint generateOccurrencePoint(ResultSet rs, String credits) throws SQLException
|
||||
private static DataSet getDataSetById(PluginSession session, int datasetId){
|
||||
logger.debug("retrieving dataset for id "+datasetId);
|
||||
DataSet dataset = null;
|
||||
ResultSet datasetRs = null;
|
||||
try{
|
||||
PreparedStatement datasetStatement = session.getDatasetPerDatasetIdPreparedStatement(datasetId);
|
||||
datasetRs = datasetStatement.executeQuery();
|
||||
if (!datasetRs.next()) return null;
|
||||
dataset = retrieveDatasetInformation(datasetRs);
|
||||
}catch(Exception e){
|
||||
logger.warn("cannot retrieve dataset for occurrence point with id "+datasetId,e);
|
||||
}finally{
|
||||
try{
|
||||
if (datasetRs!=null)
|
||||
datasetRs.close();
|
||||
}catch(Exception e) {}
|
||||
}
|
||||
logger.debug("dataset returned "+dataset);
|
||||
return dataset;
|
||||
}
|
||||
|
||||
protected static OccurrencePoint generateOccurrencePoint(ResultSet rs, String credits, DataSet dataSet) throws SQLException
|
||||
{
|
||||
int id = rs.getInt("id");
|
||||
OccurrencePoint occurrence = new OccurrencePoint(String.valueOf(id));
|
||||
|
@ -171,7 +194,7 @@ Species: C. carcharias
|
|||
if (scientificNameStartIndex>0) {
|
||||
String author = (authorStartIndex+1<concatenated.length())?concatenated.substring(authorStartIndex+1):"";
|
||||
String sn = (scientificNameStartIndex+1<snPart.length())?snPart.substring(scientificNameStartIndex+1):"";
|
||||
occurrence.setScientificName(sn+" ("+author+")");
|
||||
occurrence.setScientificName(sn/*+" ("+author+")"*/);
|
||||
}
|
||||
}
|
||||
/*String[] taxon = concatenated.split("|");
|
||||
|
@ -183,8 +206,13 @@ Species: C. carcharias
|
|||
}*/
|
||||
}
|
||||
|
||||
occurrence.setScientificNameAuthorship(rs.getString("identifiedBy"));
|
||||
occurrence.setScientificNameAuthorship(rs.getString("snAuthor"));
|
||||
|
||||
occurrence.setIdentifiedBy(rs.getString("identifiedBy"));
|
||||
|
||||
occurrence.setDataSet(dataSet);
|
||||
|
||||
//retrieving dataset
|
||||
return occurrence;
|
||||
}
|
||||
|
||||
|
@ -195,7 +223,10 @@ Species: C. carcharias
|
|||
|
||||
OccurrencePoint occurrence = null;
|
||||
String credits = generateCredits();
|
||||
if(rs.next()) occurrence = generateOccurrencePoint(rs, credits);
|
||||
if(rs.next()){
|
||||
int objId = rs.getInt("valid_id");
|
||||
occurrence = generateOccurrencePoint(rs, credits, getDataSetById(session, objId));
|
||||
}
|
||||
rs.close();
|
||||
|
||||
return occurrence;
|
||||
|
@ -237,10 +268,13 @@ Species: C. carcharias
|
|||
|
||||
//OCCURRENCES
|
||||
Product occurences = new Product(ProductType.Occurrence, key);
|
||||
|
||||
int occurencesCount = getOccurrencesCount(session, speciesId, datasetId, filters);
|
||||
occurences.setCount(occurencesCount);
|
||||
products.add(occurences);
|
||||
|
||||
logger.trace("product is "+occurences);
|
||||
|
||||
item.setProducts(products);
|
||||
}
|
||||
|
||||
|
@ -271,6 +305,7 @@ Species: C. carcharias
|
|||
|
||||
fillCommonNames(session, id, baseItem);
|
||||
|
||||
|
||||
PreparedStatement datasetStatement = session.getDatasetPreparedStatement(id);
|
||||
ResultSet dataSetrs = datasetStatement.executeQuery();
|
||||
|
||||
|
@ -278,10 +313,16 @@ Species: C. carcharias
|
|||
|
||||
ResultItem item = Util.cloneResultItem(baseItem);
|
||||
|
||||
int dataSetId = fillDatasetInformation(dataSetrs, item);
|
||||
DataSet dataset = retrieveDatasetInformation(dataSetrs);
|
||||
|
||||
item.setDataSet(dataset);
|
||||
|
||||
int dataSetId = Integer.parseInt(dataset.getId());
|
||||
|
||||
ProductKey key = new ProductKey(id, dataSetId, filters);
|
||||
|
||||
logger.trace("datasetid is "+dataSetId+" and product key created is "+key);
|
||||
|
||||
fillProducts(session, id, dataSetId, key.serialize(), filters, item);
|
||||
|
||||
continueWrite = writer.write(item);
|
||||
|
@ -400,8 +441,7 @@ Species: C. carcharias
|
|||
item.setCommonNames(commonNames);
|
||||
}
|
||||
|
||||
protected static int fillDatasetInformation(ResultSet rs, ResultItem item) throws SQLException
|
||||
{
|
||||
private static DataSet retrieveDatasetInformation(ResultSet rs) throws SQLException{
|
||||
int dataSetId = rs.getInt("datasetId");
|
||||
DataSet dataSet = new DataSet(String.valueOf(dataSetId));
|
||||
dataSet.setCitation(rs.getString("datasetCitation"));
|
||||
|
@ -410,10 +450,7 @@ Species: C. carcharias
|
|||
DataProvider dataProvider = new DataProvider(String.valueOf(rs.getInt("providerId")));
|
||||
dataProvider.setName(rs.getString("providerName"));
|
||||
dataSet.setDataProvider(dataProvider);
|
||||
|
||||
item.setDataSet(dataSet);
|
||||
|
||||
return dataSetId;
|
||||
return dataSet;
|
||||
}
|
||||
|
||||
public static Set<String> getCommonNames(PluginSession session, String scientificName) throws SQLException
|
||||
|
|
|
@ -37,6 +37,7 @@ public class PluginSession {
|
|||
protected PreparedStatement commonNamePreparedStatement;
|
||||
protected PreparedStatement childrenTaxonPreparedStatement;
|
||||
protected PreparedStatement occurrenceByIdPreparedStatement;
|
||||
protected PreparedStatement datasetPerIdPreparedStatement;
|
||||
|
||||
/**
|
||||
* @param connection
|
||||
|
@ -100,6 +101,7 @@ public class PluginSession {
|
|||
createCommonNamePreparedStatement();
|
||||
createChildrenTaxonPreparedStatement();
|
||||
createOccurrenceByIdPreparedStatement();
|
||||
createDatasetPerDatasetIdPreparedStatement();
|
||||
}
|
||||
|
||||
|
||||
|
@ -141,16 +143,12 @@ public class PluginSession {
|
|||
return datasetPreparedStatement;
|
||||
}
|
||||
|
||||
protected void createDatasetPreparedStatement() throws SQLException
|
||||
public PreparedStatement getDatasetPerDatasetIdPreparedStatement(int dataSetId) throws SQLException
|
||||
{
|
||||
/*String query = "SELECT r.id as datasetId, r.resname as datasetName, r.citation as datasetCitation, p.id as providerId, p.providername as providerName " +
|
||||
"FROM obis.resources r, obis.providers p WHERE " +
|
||||
"exists (SELECT r.id FROM obis.drs d WHERE d.valid_id = ? AND d.resource_id = r.id) AND r.provider_id = p.id";*/
|
||||
|
||||
String query = "SELECT r.id as datasetId, r.resname as datasetName, r.citation as datasetCitation, p.id as providerId, p.providername as providerName " +
|
||||
"FROM obis.resources r, obis.providers p WHERE " +
|
||||
"r.id in (SELECT resource_id from portal.species_per_resource where valid_id = ?) AND r.provider_id = p.id";
|
||||
datasetPreparedStatement = connection.prepareStatement(query);
|
||||
if (datasetPerIdPreparedStatement==null) createDatasetPerDatasetIdPreparedStatement();
|
||||
datasetPerIdPreparedStatement.clearParameters();
|
||||
datasetPerIdPreparedStatement.setInt(1, dataSetId);
|
||||
return datasetPerIdPreparedStatement;
|
||||
}
|
||||
|
||||
public PreparedStatement getCommonNameFromScientificNamePreparedStatement(String scientificaName) throws SQLException
|
||||
|
@ -314,7 +312,7 @@ public class PluginSession {
|
|||
protected PreparedStatement getOccurrencesPreparedStatement(int taxonId, int datasetId, SearchFilters filters) throws SQLException
|
||||
{
|
||||
//We don't cache it because in this case a PS is less performant
|
||||
StringBuilder query = new StringBuilder("SELECT drs.id, drs.latitude, drs.longitude, drs.datecollected, drs.basisofrecord, dxs.citation, dxs.institutioncode, dxs.collectioncode, dxs.catalognumber, dxs.collector, dxs.datelastmodified, dxs.country, dxs.locality, dxs.minimumdepth, dxs.maximumdepth, dxs.coordinateprecision, dxs.concatenated, dxs.identifiedBy, dxs.yearcollected, dxs.monthcollected, dxs.daycollected FROM obis.drs drs, obis.dxs dxs WHERE drs.valid_id = ? AND drs.resource_id = ? AND drs.id = dxs.dr_id");
|
||||
StringBuilder query = new StringBuilder("SELECT drs.id, drs.valid_id, drs.latitude, drs.longitude, drs.datecollected, drs.basisofrecord, dxs.citation, dxs.institutioncode, dxs.collectioncode, dxs.catalognumber, dxs.collector, dxs.datelastmodified, dxs.country, dxs.locality, dxs.minimumdepth, dxs.maximumdepth, dxs.coordinateprecision, dxs.concatenated, dxs.identifiedBy, dxs.yearcollected, dxs.monthcollected, dxs.daycollected, tn.tauthor as snAuthor FROM obis.drs drs, obis.dxs dxs, obis.tnames tn WHERE drs.valid_id = ? AND drs.resource_id = ? AND drs.id = dxs.dr_id AND tn.id = drs.valid_id ");
|
||||
|
||||
buildConditions(query, "drs.", filters.getConditions());
|
||||
|
||||
|
@ -400,9 +398,32 @@ public class PluginSession {
|
|||
|
||||
protected void createOccurrenceByIdPreparedStatement() throws SQLException
|
||||
{
|
||||
String query = "SELECT drs.id, drs.latitude, drs.longitude, drs.datecollected, drs.basisofrecord, dxs.citation, dxs.institutioncode, dxs.collectioncode, dxs.catalognumber, dxs.collector, dxs.datelastmodified, dxs.country, dxs.locality, dxs.minimumdepth, dxs.maximumdepth, dxs.coordinateprecision, dxs.concatenated, dxs.yearcollected, dxs.monthcollected, dxs.daycollected FROM obis.drs drs, obis.dxs dxs WHERE drs.id = ? AND drs.id = dxs.dr_id";
|
||||
String query = "SELECT drs.id, drs.latitude, drs.longitude, drs.datecollected, drs.basisofrecord, dxs.citation, dxs.institutioncode, dxs.collectioncode, dxs.catalognumber, dxs.collector, dxs.datelastmodified, dxs.country, dxs.locality, dxs.minimumdepth, dxs.maximumdepth, dxs.coordinateprecision, dxs.concatenated, dxs.yearcollected, dxs.monthcollected, dxs.daycollected, tn.tauthor as snAuthor FROM obis.drs drs, obis.dxs dxs, obis.tnames as tn WHERE drs.id = ? AND drs.id = dxs.dr_id AND drs.valid_id = tn.id";
|
||||
occurrenceByIdPreparedStatement = connection.prepareStatement(query);
|
||||
}
|
||||
|
||||
protected void createDatasetPreparedStatement() throws SQLException
|
||||
{
|
||||
/*String query = "SELECT r.id as datasetId, r.resname as datasetName, r.citation as datasetCitation, p.id as providerId, p.providername as providerName " +
|
||||
"FROM obis.resources r, obis.providers p WHERE " +
|
||||
"exists (SELECT r.id FROM obis.drs d WHERE d.valid_id = ? AND d.resource_id = r.id) AND r.provider_id = p.id";*/
|
||||
|
||||
String query = "SELECT r.id as datasetId, r.resname as datasetName, r.citation as datasetCitation, p.id as providerId, p.providername as providerName " +
|
||||
"FROM obis.resources r, obis.providers p WHERE " +
|
||||
"r.id in (SELECT resource_id from portal.species_per_resource where valid_id = ?) AND r.provider_id = p.id";
|
||||
datasetPreparedStatement = connection.prepareStatement(query);
|
||||
}
|
||||
|
||||
protected void createDatasetPerDatasetIdPreparedStatement() throws SQLException
|
||||
{
|
||||
/*String query = "SELECT r.id as datasetId, r.resname as datasetName, r.citation as datasetCitation, p.id as providerId, p.providername as providerName " +
|
||||
"FROM obis.resources r, obis.providers p WHERE " +
|
||||
"exists (SELECT r.id FROM obis.drs d WHERE d.valid_id = ? AND d.resource_id = r.id) AND r.provider_id = p.id";*/
|
||||
|
||||
String query = "SELECT r.id as datasetId, r.resname as datasetName, r.citation as datasetCitation, p.id as providerId, p.providername as providerName " +
|
||||
"FROM obis.resources r, obis.providers p WHERE " +
|
||||
"r.id = ? AND r.provider_id = p.id";
|
||||
datasetPerIdPreparedStatement = connection.prepareStatement(query);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -29,6 +29,8 @@ public class ProductKey {
|
|||
this.filters = filters;
|
||||
}
|
||||
|
||||
protected ProductKey() {}
|
||||
|
||||
/**
|
||||
* @return the taxonId
|
||||
*/
|
||||
|
|
|
@ -17,6 +17,8 @@ public class SearchFilters {
|
|||
|
||||
protected List<Condition> conditions;
|
||||
|
||||
protected SearchFilters(){}
|
||||
|
||||
public SearchFilters(Condition ... conditions){
|
||||
this.conditions = new ArrayList<Condition>(Arrays.asList(conditions));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue