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.
10 package eu
.etaxonomy
.cdm
.app
.viennaImport
;
13 import java
.net
.URISyntaxException
;
14 import java
.sql
.ResultSet
;
15 import java
.sql
.SQLException
;
16 import java
.util
.List
;
18 import org
.apache
.log4j
.Logger
;
20 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationController
;
21 import eu
.etaxonomy
.cdm
.api
.facade
.DerivedUnitFacade
;
22 import eu
.etaxonomy
.cdm
.app
.common
.CdmDestinations
;
23 import eu
.etaxonomy
.cdm
.common
.AccountStore
;
24 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
25 import eu
.etaxonomy
.cdm
.io
.common
.Source
;
26 import eu
.etaxonomy
.cdm
.model
.agent
.Person
;
27 import eu
.etaxonomy
.cdm
.model
.common
.Annotation
;
28 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableSource
;
29 import eu
.etaxonomy
.cdm
.model
.common
.OriginalSourceType
;
30 import eu
.etaxonomy
.cdm
.model
.media
.ImageFile
;
31 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
32 import eu
.etaxonomy
.cdm
.model
.name
.BotanicalName
;
33 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
34 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnit
;
35 import eu
.etaxonomy
.cdm
.model
.occurrence
.DeterminationEvent
;
36 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationType
;
37 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
38 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceFactory
;
39 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
40 import eu
.etaxonomy
.cdm
.strategy
.parser
.NonViralNameParserImpl
;
47 public class ViennaActivator
{
48 private static final Logger logger
= Logger
.getLogger(ViennaActivator
.class);
50 static final Source berlinModelSource
= ViennaActivator
.VIENNA();
53 public static Source
VIENNA(){
56 String strServer
= "AsteraceaeViennaAccess";
57 String strDB
= "AsteraceaeViennaAccess";
58 String userName
= "webUser";
59 return makeSource(dbms
, strServer
, strDB
, -1, userName
, null);
62 public boolean invoke(){
63 boolean result
= true;
64 boolean withCdm
= false;
65 berlinModelSource
.setQuery("SELECT * FROM vienna"); // WHERE ID1 <> 1
66 CdmApplicationController app
= null;
71 app
= CdmApplicationController
.NewInstance(CdmDestinations
.localH2());
73 //app = CdmApplicationController.NewInstance(DbSchemaValidation.VALIDATE);
75 } catch (Exception e1
) {
82 ResultSet rs
= berlinModelSource
.getResultSet();
85 String uriPath
= "http://131.130.131.9/database/img/imgBrowser.php?ID=";
86 int id
= rs
.getInt("ID");
87 String strId
= String
.valueOf(id
);
88 String catalogNumber
= rs
.getString("catalogueNumber");
89 String strTaxonName
= rs
.getString("TaxonName");
90 String annotation
= rs
.getString("Annotation");
91 String typeInformation
= rs
.getString("TypeInformation");
92 String typifiedBy
= rs
.getString("TypifiedBy");
93 String family
= rs
.getString("Family");
94 String strActor
= rs
.getString("Actor");
95 String timePeriod
= rs
.getString("TimePeriod");
96 String collectingArea
= rs
.getString("CollectingArea");
97 String locality
= rs
.getString("Locality");
98 String assigned
= rs
.getString("assigned");
99 String history
= rs
.getString("history");
101 if (! family
.equals("Asteraceae")){
102 logger
.warn("Family not Asteracea: ID= " + strId
);
104 Reference
<?
> sec
= ReferenceFactory
.newDatabase();
105 sec
.setTitleCache("Vienna Asteraceae Images", true);
107 TaxonNameBase
<?
,?
> taxonName
= (BotanicalName
)NonViralNameParserImpl
.NewInstance().parseFullName(strTaxonName
);
109 List
<TaxonNameBase
> names
= app
.getNameService().getNamesByName(strTaxonName
);
110 if (names
.size() == 0){
111 logger
.warn("Name not found: " + strTaxonName
);
113 if (names
.size() > 1){
114 logger
.warn("More then 1 name found: " + strTaxonName
);
116 taxonName
= names
.get(0);
119 Taxon taxon
= Taxon
.NewInstance(taxonName
, sec
);
121 logger
.info("Create new specimen ...");
122 DerivedUnit specimenx
= DerivedUnit
.NewPreservedSpecimenInstance();
123 DerivedUnitFacade specimen
= DerivedUnitFacade
.NewInstance(SpecimenOrObservationType
.PreservedSpecimen
);
125 specimen
.setCatalogNumber(catalogNumber
);
126 specimen
.setStoredUnder(taxonName
); //??
128 //specimen.setCollection(collection);
129 specimen
.addAnnotation(Annotation
.NewDefaultLanguageInstance(annotation
));
130 specimen
.addDetermination(getDetermination(taxon
, strActor
));
131 specimen
.addDerivedUnitMedia(getMedia(uriPath
, strId
));
134 specimen
.addSource(IdentifiableSource
.NewDataImportInstance(strId
));
138 } catch (SQLException e
) {
139 logger
.warn("Error when reading record!!");
146 private Media
getMedia(String uriPath
, String id
){
147 //"http://131.130.131.9/database/img/imgBrowser.php?ID=50599";
148 String uriString
= uriPath
+ id
;
149 if (CdmUtils
.urlExists(uriString
, false)){
150 String suffix
= "jpg";
151 String mimeType
= "image/jpg";
154 uri
= new URI(uriString
);
155 } catch (URISyntaxException e
) {
158 Media media
= ImageFile
.NewMediaInstance(null, null, uri
, mimeType
, suffix
, null, null, null);
161 logger
.warn("URI does not exist: " + uriString
);
166 private DeterminationEvent
getDetermination(Taxon taxon
, String actor
){
167 logger
.info("Create determination event");
168 DeterminationEvent determinationEvent
= DeterminationEvent
.NewInstance();
169 determinationEvent
.setTaxon(taxon
);
170 Person person
= Person
.NewTitledInstance(actor
);
171 determinationEvent
.setActor(person
);
172 return determinationEvent
;
180 public static void main(String
[] args
) {
181 ViennaActivator viennaAct
= new ViennaActivator();
188 * @return true, if connection established
190 private static Source
makeSource(String dbms
, String strServer
, String strDB
, int port
, String userName
, String pwd
){
191 //establish connection
192 pwd
= AccountStore
.readOrStorePassword(dbms
, strServer
, userName
, pwd
);
193 Source source
= new Source(dbms
, strServer
, strDB
);
194 source
.setPort(port
);
195 source
.setUserAndPwd(userName
, pwd
);