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.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
\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
- @Autowired\r
- private ITermService termService;\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
- "sec.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
// 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
- DateTime dt = taxon.getUpdated(); \r
- String modified = fmt.print(dt);\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
buildFlagMap(tb),\r
classificationMap,\r
"",\r
- "",\r
- "",\r
- taxon.getSec().getTitleCache(),\r
+ didname[0],\r
+ didname[1],\r
+ secTitle,\r
modified);\r
-\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
- dt = syn.getUpdated();\r
- modified = fmt.print(dt);\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
status, \r
relLabel,\r
"",\r
- "",\r
- "",\r
- syn.getSec().getTitleCache(),\r
+ didname[0],\r
+ didname[1],\r
+ secTitle,\r
modified);\r
}\r
\r
String status = ACCEPTED_NAME_STATUS;\r
String relLabel = tr.getType().getRepresentation(Language.DEFAULT())\r
.getLabel();\r
- dt = tr.getToTaxon().getUpdated();\r
- modified = fmt.print(dt);\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
status, \r
relLabel,\r
"",\r
- "",\r
- "",\r
- tr.getToTaxon().getSec().getTitleCache(),\r
+ didname[0],\r
+ didname[1],\r
+ secTitle,\r
modified);\r
//logger.info("titleTo : " + titleTo + " , name : " + name);\r
}\r
String relLabel = tr.getType()\r
.getInverseRepresentation(Language.DEFAULT())\r
.getLabel();\r
- dt = tr.getFromTaxon().getUpdated();\r
- modified = fmt.print(dt);\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
status,\r
relLabel,\r
"",\r
- "",\r
- "",\r
- tr.getFromTaxon().getSec().getTitleCache(),\r
+ didname[0],\r
+ didname[1],\r
+ secTitle,\r
modified);\r
//logger.info("titleFrom : " + titleFrom + " , name : " + name);\r
}\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
buildFlagMap(synonym),\r
new TreeMap<String,Map>(),\r
"",\r
- "",\r
- "",\r
- synonym.getSec().getTitleCache(),\r
+ didname[0],\r
+ didname[1],\r
+ secTitle,\r
modified);\r
// add accepted taxa (if exists) to taxon information object\r
\r
.getLabel();\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
status, \r
relLabel,\r
"",\r
- "",\r
- "",\r
- synonym.getSec().getTitleCache(),\r
+ didname[0],\r
+ didname[1],\r
+ secTitle,\r
modified);\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