2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.cdm
.io
.mexico
;
11 import java
.net
.URISyntaxException
;
13 import org
.apache
.log4j
.Logger
;
14 import org
.springframework
.stereotype
.Component
;
16 import eu
.etaxonomy
.cdm
.common
.DOI
;
17 import eu
.etaxonomy
.cdm
.common
.URI
;
18 import eu
.etaxonomy
.cdm
.model
.agent
.TeamOrPersonBase
;
19 import eu
.etaxonomy
.cdm
.model
.common
.VerbatimTimePeriod
;
20 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
21 import eu
.etaxonomy
.cdm
.model
.term
.DefinedTerm
;
22 import eu
.etaxonomy
.cdm
.strategy
.parser
.BibliographicAuthorParser
;
23 import eu
.etaxonomy
.cdm
.strategy
.parser
.TimePeriodParser
;
30 public abstract class MexicoEfloraReferenceImportBase
extends MexicoEfloraImportBase
{
32 public static final String NAMESPACE
= "References";
34 private static final long serialVersionUID
= -5161951752826380728L;
35 private static final Logger logger
= Logger
.getLogger(MexicoEfloraReferenceImportBase
.class);
37 public MexicoEfloraReferenceImportBase(String dbTableName
, String pluralString
){
38 super(dbTableName
, pluralString
);
42 protected String
getIdQuery(MexicoEfloraImportState state
) {
43 String sql
= " SELECT 'CONABIO-BIB-ID' "
44 + " FROM " + getTableName()
45 + " ORDER BY 'CONABIO-BIB-ID' ";
50 protected String
getRecordQuery(MexicoEfloraImportConfigurator config
) {
51 String sqlSelect
= " SELECT * ";
52 String sqlFrom
= " FROM " + getTableName();
53 String sqlWhere
= " WHERE ( 'CONABIO-BIB-ID' IN (" + ID_LIST_TOKEN
+ ") )";
55 String strRecordQuery
=sqlSelect
+ " " + sqlFrom
+ " " + sqlWhere
;
56 return strRecordQuery
;
60 protected boolean doCheck(MexicoEfloraImportState state
){
64 protected void handleAuthorStr(MexicoEfloraImportState state
, String authorStr
, Reference ref
, int refId
) {
67 if (isNotBlank(authorStr
)) {
68 TeamOrPersonBase
<?
> author
= BibliographicAuthorParser
69 .Instance().parse(authorStr
);
70 //TODO is parsed really ok?
71 state
.getDeduplicationHelper().getExistingAgent(author
, true);
72 ref
.setAuthorship(author
);
74 logger
.warn(refId
+ ": No author");
78 protected void handleYearStr(@SuppressWarnings("unused") MexicoEfloraImportState state
,
79 String yearStr
, Reference ref
, int refId
) {
81 if (isNotBlank(yearStr
)) {
82 VerbatimTimePeriod tp
= TimePeriodParser
.parseStringVerbatim(yearStr
);
83 ref
.setDatePublished(tp
);
85 logger
.warn(refId
+ ": No year");
89 protected void handleTitleStr(@SuppressWarnings("unused") MexicoEfloraImportState state
,
90 String titleStr
, Reference ref
, int refId
) {
93 if (isNotBlank(titleStr
)) {
94 ref
.setTitle(titleStr
);
96 // logger.warn(refId + ": No title");
100 protected void handleUrlStr(@SuppressWarnings("unused") MexicoEfloraImportState state
,
101 String urlStr
, Reference ref
, int refId
) {
104 if (isNotBlank(urlStr
)) {
106 URI uri
= new URI(urlStr
);
107 //for now we handle the uri in the URI field also for non-websites
108 //will be moved to external link by model update script in future
110 } catch (URISyntaxException e
) {
111 logger
.warn(refId
+ ": URL could not be parsed: " + urlStr
);
116 protected void handleDoiStr(@SuppressWarnings("unused") MexicoEfloraImportState state
,
117 String doiStr
, Reference ref
, int refId
) {
120 if (isNotBlank(doiStr
)) {
123 doi
= DOI
.fromString(doiStr
);
125 } catch (Exception e
) {
126 logger
.warn(refId
+ ": Doi could not be parsed: " + doiStr
);
131 protected void handleId(MexicoEfloraImportState state
, int refId
, Reference ref
) {
132 state
.getReferenceUuidMap().put(refId
, ref
.getUuid());
133 // state.getRefDetailMap().put(refId, detail);
135 //TODO not needed anymore once "related objects" are adapted everywhere
136 Reference sourceRef
= getSourceReference(state
.getConfig().getSourceReference());
137 ref
.addImportSource(String
.valueOf(refId
), MexicoEfloraReferenceImportBase
.NAMESPACE
,
141 DefinedTerm conabioIdentifier
= getIdentiferType(state
, MexicoConabioTransformer
.uuidConabioReferenceIdIdentifierType
,
142 "CONABIO Reference Identifier", "CONABIO Reference Identifier", "CONABIO", null);
143 ref
.addIdentifier(String
.valueOf(refId
), conabioIdentifier
);
147 protected boolean isIgnore(MexicoEfloraImportState state
){
148 return ! state
.getConfig().isDoReferences();