\r
import java.util.Hashtable;\r
\r
+import org.apache.log4j.Level;\r
+import org.joda.time.DateTime;\r
+import org.joda.time.format.DateTimeFormat;\r
+import org.joda.time.format.DateTimeFormatter;\r
import org.springframework.beans.factory.annotation.Autowired;\r
import org.springframework.context.ResourceLoaderAware;\r
import org.springframework.core.io.Resource;\r
import org.springframework.web.servlet.ModelAndView;\r
\r
import eu.etaxonomy.cdm.api.service.IClassificationService;\r
+import eu.etaxonomy.cdm.api.service.ICommonService;\r
import eu.etaxonomy.cdm.api.service.INameService;\r
import eu.etaxonomy.cdm.api.service.ITaxonService;\r
+import eu.etaxonomy.cdm.api.service.ITermService;\r
import eu.etaxonomy.cdm.common.DocUtils;\r
\r
import eu.etaxonomy.cdm.remote.dto.common.ErrorResponse;\r
import eu.etaxonomy.cdm.remote.dto.namecatalogue.TaxonInformation;\r
import eu.etaxonomy.cdm.remote.view.HtmlView;\r
import eu.etaxonomy.cdm.model.common.CdmBase;\r
+import eu.etaxonomy.cdm.model.common.DefinedTermBase;\r
+import eu.etaxonomy.cdm.model.common.IdentifiableSource;\r
import eu.etaxonomy.cdm.model.common.Language;\r
+import eu.etaxonomy.cdm.model.common.Representation;\r
+import eu.etaxonomy.cdm.model.description.Feature;\r
import eu.etaxonomy.cdm.model.name.NonViralName;\r
import eu.etaxonomy.cdm.model.name.TaxonNameBase;\r
import eu.etaxonomy.cdm.model.reference.Reference;\r
\r
/** Classifcation 'all' key */\r
public static final String CLASSIFICATION_ALL = "all";\r
+ \r
+ private static final String DWC_DATASET_ID = "http://rs.tdwg.org/dwc/terms/datasetID";\r
\r
+ private static final DateTimeFormatter fmt = DateTimeFormat.forPattern("dd-MM-yyyy");\r
@Autowired\r
private ITaxonService taxonService;\r
-\r
+ \r
+ \r
@Autowired\r
private IClassificationService classificationService;\r
-\r
+ \r
+ @Autowired\r
+ private ICommonService commonService;\r
/** Hibernate name search initialisation strategy */\r
private static final List<String> NAME_SEARCH_INIT_STRATEGY = Arrays.asList(new String[] {\r
"combinationAuthorTeam.$",\r
/** Hibernate taxon information initialisation strategy */\r
private static final List<String> TAXON_INFORMATION_INIT_STRATEGY = Arrays.asList(new String[] {\r
"name.titleCache",\r
- "name.rank.titleCache",\r
+ "name.rank.titleCache", \r
+ \r
+ "sec.updated",\r
+ "sec.titleCache",\r
+ "sources.citation.sources.idNamespace",\r
+ "sources.citation.sources.idInSource",\r
+ \r
"synonymRelations.synonym.name.rank.titleCache",\r
+ "synonymRelations.synonym.sec.updated",\r
+ "synonymRelations.synonym.sec.titleCache", \r
+ "synonymRelations.synonym.sources.citation.sources.idNamespace",\r
+ "synonymRelations.synonym.sources.citation.sources.idInSource", \r
"synonymRelations.acceptedTaxon.name.rank.titleCache",\r
+ "synonymRelations.acceptedTaxon.sec.titleCache",\r
+ "synonymRelations.acceptedTaxon.sources.citation.sources.idNamespace",\r
+ "synonymRelations.acceptedTaxon.sources.citation.sources.idInSource", \r
"synonymRelations.type.$",\r
- "taxonRelations.toTaxon.$",\r
- "taxonRelations.fromTaxon.$",\r
- "taxonRelations.type.$", \r
- "synonymRelations.relatedTo.name.rank.titleCache",\r
+ \r
"relationsFromThisTaxon.type.$",\r
- "relationsFromThisTaxon.relatedTo.name.rank.titleCache",\r
+ "relationsFromThisTaxon.toTaxon.name.rank.titleCache",\r
+ "relationsFromThisTaxon.toTaxon.sec.updated",\r
+ "relationsFromThisTaxon.toTaxon.sec.titleCache",\r
+ "relationsFromThisTaxon.toTaxon.sources.citation.sources.idNamespace",\r
+ "relationsFromThisTaxon.toTaxon.sources.citation.sources.idInSource",\r
+ \r
"relationsToThisTaxon.type.$",\r
- "relationsToThisTaxon.relatedFrom.name.rank.titleCache",\r
+ "relationsToThisTaxon.fromTaxon.name.rank.titleCache",\r
+ "relationsToThisTaxon.fromTaxon.sec.updated",\r
+ "relationsToThisTaxon.fromTaxon.sec.titleCache",\r
+ "relationsToThisTaxon.fromTaxon.sources.citation.sources.idNamespace",\r
+ "relationsToThisTaxon.fromTaxon.sources.citation.sources.idInSource",\r
+ \r
"taxonNodes",\r
"taxonNodes.classification" });\r
\r
"classification",\r
"classification.reference.$",\r
"classification.reference.authorTeam.$" });\r
+ \r
+ /** Hibernate classification vocabulary initialisation strategy */\r
+ private static final List<String> COMMON_INIT_STRATEGY = Arrays.asList(new String[] {});\r
+ \r
public NameCatalogueController() {\r
super();\r
setInitializationStrategy(Arrays.asList(new String[] { "$" }));\r
er.setErrorMessage("No Taxon Name for given query : " + query);\r
nsList.add(er);\r
}\r
- }\r
+ } \r
+\r
mv.addObject(nsList);\r
return mv;\r
}\r
// find name by uuid\r
TaxonBase tb = taxonService.findTaxonByUuid(UUID.fromString(taxonUuid),\r
TAXON_INFORMATION_INIT_STRATEGY);\r
+ \r
// if search is successful then get related information, else return error\r
if (tb != null) {\r
TaxonInformation ti = new TaxonInformation();\r
logger.info("taxon uuid " + taxon.getUuid().toString() + " original hash code : " + System.identityHashCode(taxon) + ", name class " + taxon.getName().getClass().getName());
// update taxon information object with taxon related data\r
NonViralName nvn = (NonViralName) taxon.getName();\r
+\r
+ String secTitle = "" ;\r
+ String modified = "";\r
+ if(taxon.getSec() != null) {\r
+ secTitle = taxon.getSec().getTitleCache();\r
+ DateTime dt = taxon.getUpdated(); \r
+ modified = fmt.print(dt);\r
+ }\r
+ \r
+ Set<IdentifiableSource> sources = taxon.getSources();\r
+ String[] didname = getDatasetIdName(sources); \r
+\r
ti.setResponseTaxon(tb.getTitleCache(),\r
nvn.getTitleCache(),\r
nvn.getRank().getTitleCache(),\r
ACCEPTED_NAME_STATUS,\r
buildFlagMap(tb),\r
- classificationMap);\r
-\r
+ classificationMap,\r
+ "",\r
+ didname[0],\r
+ didname[1],\r
+ secTitle,\r
+ modified);\r
+ \r
+ \r
Set<SynonymRelationship> synRelationships = taxon.getSynonymRelations();\r
// add synonyms (if exists) to taxon information object\r
for (SynonymRelationship sr : synRelationships) {\r
String relLabel = sr.getType()\r
.getInverseRepresentation(Language.DEFAULT())\r
.getLabel();\r
- ti.addToResponseRelatedTaxa(uuid, title, name, rank, status, "", relLabel);\r
+ \r
+ secTitle = "" ;\r
+ modified = "";\r
+ if(syn.getSec() != null) {\r
+ secTitle = syn.getSec().getTitleCache();\r
+ DateTime dt = syn.getUpdated(); \r
+ modified = fmt.print(dt);\r
+ }\r
+ \r
+ sources = syn.getSources();\r
+ didname = getDatasetIdName(sources);\r
+ \r
+ ti.addToResponseRelatedTaxa(uuid, \r
+ title, \r
+ name, \r
+ rank, \r
+ status, \r
+ relLabel,\r
+ "",\r
+ didname[0],\r
+ didname[1],\r
+ secTitle,\r
+ modified);\r
}\r
\r
// build relationship information as,\r
String status = ACCEPTED_NAME_STATUS;\r
String relLabel = tr.getType().getRepresentation(Language.DEFAULT())\r
.getLabel();\r
- ti.addToResponseRelatedTaxa(uuid, titleTo, name, rank, status, "", relLabel);\r
+\r
+ secTitle = "" ;\r
+ modified = "";\r
+ if(tr.getToTaxon().getSec() != null) {\r
+ secTitle = tr.getToTaxon().getSec().getTitleCache();\r
+ DateTime dt = tr.getToTaxon().getUpdated(); \r
+ modified = fmt.print(dt);\r
+ }\r
+ \r
+ sources = tr.getToTaxon().getSources();\r
+ didname = getDatasetIdName(sources);\r
+ \r
+ ti.addToResponseRelatedTaxa(uuid, \r
+ titleTo, \r
+ name, \r
+ rank, \r
+ status, \r
+ relLabel,\r
+ "",\r
+ didname[0],\r
+ didname[1],\r
+ secTitle,\r
+ modified);\r
+ //logger.info("titleTo : " + titleTo + " , name : " + name);\r
}\r
\r
- // - relationships from the requested taxon\r
+ // - relationships to the requested taxon\r
Set<TaxonRelationship> trToSet = taxon.getRelationsToThisTaxon();\r
for (TaxonRelationship tr : trToSet) {\r
String titleFrom = tr.getFromTaxon().getTitleCache();\r
- TaxonNameBase fromnvn = (TaxonNameBase) tr.getToTaxon().getName();\r
+ TaxonNameBase fromnvn = (TaxonNameBase) tr.getFromTaxon().getName();\r
String name = fromnvn.getTitleCache();\r
String rank = fromnvn.getRank().getTitleCache();\r
String uuid = tr.getFromTaxon().getUuid().toString();\r
String relLabel = tr.getType()\r
.getInverseRepresentation(Language.DEFAULT())\r
.getLabel();\r
- ti.addToResponseRelatedTaxa(uuid, titleFrom, name, rank, status, "", relLabel);\r
+\r
+ if(tr.getFromTaxon().getSec() != null) {\r
+ secTitle = tr.getFromTaxon().getSec().getTitleCache();\r
+ DateTime dt = tr.getFromTaxon().getSec().getUpdated(); \r
+ modified = fmt.print(dt);\r
+ }\r
+ \r
+ sources = tr.getFromTaxon().getSources();\r
+ didname = getDatasetIdName(sources);\r
+ \r
+ secTitle = (tr.getFromTaxon().getSec() == null) ? "" : tr.getFromTaxon().getSec().getTitleCache();\r
+ ti.addToResponseRelatedTaxa(uuid, \r
+ titleFrom, \r
+ name, \r
+ rank, \r
+ status,\r
+ relLabel,\r
+ "",\r
+ didname[0],\r
+ didname[1],\r
+ secTitle,\r
+ modified);\r
+ //logger.info("titleFrom : " + titleFrom + " , name : " + name);\r
}\r
} else if (tb instanceof Synonym) {\r
Synonym synonym = (Synonym) tb;\r
TaxonNameBase nvn = (TaxonNameBase) synonym.getName();\r
// update taxon information object with synonym related data\r
+ DateTime dt = synonym.getUpdated(); \r
+ String modified = fmt.print(dt);\r
+ \r
+ Set<IdentifiableSource> sources = synonym.getSources();\r
+ String[] didname = getDatasetIdName(sources);\r
+ \r
+ String secTitle = (synonym.getSec() == null) ? "" : synonym.getSec().getTitleCache();\r
ti.setResponseTaxon(synonym.getTitleCache(),\r
nvn.getTitleCache(),\r
nvn.getRank().getTitleCache(),\r
SYNONYM_STATUS,\r
buildFlagMap(synonym),\r
- new TreeMap<String,Map>());\r
+ new TreeMap<String,Map>(),\r
+ "",\r
+ didname[0],\r
+ didname[1],\r
+ secTitle,\r
+ modified);\r
// add accepted taxa (if exists) to taxon information object\r
\r
Set<SynonymRelationship> synRelationships = synonym.getSynonymRelations();\r
String status = ACCEPTED_NAME_STATUS;\r
String relLabel = sr.getType().getRepresentation(Language.DEFAULT())\r
.getLabel();\r
- ti.addToResponseRelatedTaxa(uuid, title, name, rank, status, "", relLabel);\r
+ dt = accTaxon.getUpdated(); \r
+ modified = fmt.print(dt);\r
+ \r
+ sources = accTaxon.getSources();\r
+ didname = getDatasetIdName(sources);\r
+ \r
+ secTitle = (accTaxon.getSec() == null) ? "" : accTaxon.getSec().getTitleCache();\r
+ ti.addToResponseRelatedTaxa(uuid, \r
+ title, \r
+ name, \r
+ rank, \r
+ status, \r
+ relLabel,\r
+ "",\r
+ didname[0],\r
+ didname[1],\r
+ secTitle,\r
+ modified);\r
}\r
\r
}\r
return mv;\r
}\r
\r
+ /**\r
+ * Returns the Dataset ID / Name of the given original source.\r
+ * FIXME: Very hacky and needs to be revisited. Mainly for deciding on which objects to use during import.\r
+ * FIXME: dataset id is mapped to a DWC term - is that right?\r
+ * \r
+ * @param sources Set of sources attached to a taxa / synonym\r
+ * \r
+ *\r
+ * @return String array where [0] is the datsetID and [1] is the datsetName\r
+ */\r
+ private String[] getDatasetIdName(Set<IdentifiableSource> sources) {\r
+ String didname[] = {"",""};\r
+ Iterator<IdentifiableSource> itr = sources.iterator();\r
+ while(itr.hasNext()) {\r
+ IdentifiableSource source = itr.next(); \r
+ Reference ref = source.getCitation(); \r
+ Set<IdentifiableSource> ref_sources = ref.getSources();\r
+ Iterator<IdentifiableSource> ref_itr = ref_sources.iterator();\r
+ while(ref_itr.hasNext()) {\r
+ IdentifiableSource ref_source = ref_itr.next(); \r
+ if(ref_source.getIdNamespace().equals(DWC_DATASET_ID)) {\r
+ didname[0] = ref_source.getIdInSource();\r
+ break;\r
+ }\r
+ }\r
+ if(!didname[0].isEmpty()) {\r
+ didname[1] = ref.getTitleCache();\r
+ break;\r
+ }\r
+ }\r
+ return didname;\r
+ }\r
+ \r
/**\r
* Returns the match mode by parsing the input string of wildcards.\r
*\r