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
.berlinModel
.out
;
11 import java
.sql
.SQLException
;
12 import java
.util
.List
;
14 import org
.apache
.log4j
.Logger
;
15 import org
.springframework
.stereotype
.Component
;
16 import org
.springframework
.transaction
.TransactionStatus
;
18 import eu
.etaxonomy
.cdm
.io
.common
.Source
;
19 import eu
.etaxonomy
.cdm
.io
.common
.mapping
.out
.CdmDbExportMapping
;
20 import eu
.etaxonomy
.cdm
.io
.common
.mapping
.out
.CollectionExportMapping
;
21 import eu
.etaxonomy
.cdm
.io
.common
.mapping
.out
.CreatedAndNotesMapper
;
22 import eu
.etaxonomy
.cdm
.io
.common
.mapping
.out
.DbBooleanMapper
;
23 import eu
.etaxonomy
.cdm
.io
.common
.mapping
.out
.IExportTransformer
;
24 import eu
.etaxonomy
.cdm
.io
.common
.mapping
.out
.IdMapper
;
25 import eu
.etaxonomy
.cdm
.io
.common
.mapping
.out
.MethodMapper
;
26 import eu
.etaxonomy
.cdm
.model
.agent
.AgentBase
;
27 import eu
.etaxonomy
.cdm
.model
.agent
.Team
;
28 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
37 public class BerlinModelAuthorTeamExport
extends BerlinModelExportBase
<Team
> {
38 private static final Logger logger
= Logger
.getLogger(BerlinModelAuthorTeamExport
.class);
40 private static int modCount
= 1000;
41 private static final String dbTableName
= "AuthorTeam";
42 private static final String pluralString
= "AuthorTeams";
43 private static final Class
<?
extends CdmBase
> standardMethodParameter
= Team
.class;
45 public BerlinModelAuthorTeamExport(){
50 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#doCheck(eu.etaxonomy.cdm.io.common.IImportConfigurator)
53 protected boolean doCheck(BerlinModelExportState state
){
54 boolean result
= true;
55 logger
.warn("Checking for "+pluralString
+" not yet implemented");
56 //result &= checkArticlesWithoutJournal(bmiConfig);
61 public CdmDbExportMapping
<BerlinModelExportState
, BerlinModelExportConfigurator
, IExportTransformer
> getMapping(){
62 String tableName
= dbTableName
;
63 CdmDbExportMapping
<BerlinModelExportState
, BerlinModelExportConfigurator
, IExportTransformer
> mapping
= new CdmDbExportMapping
<BerlinModelExportState
, BerlinModelExportConfigurator
, IExportTransformer
>(tableName
);
64 mapping
.addMapper(IdMapper
.NewInstance("AuthorTeamId"));
65 mapping
.addMapper(MethodMapper
.NewInstance("AuthorTeamCache", this));
66 mapping
.addMapper(MethodMapper
.NewInstance("FullAuthorTeamCache", this));
67 mapping
.addMapper(DbBooleanMapper
.NewFalseInstance("isProtectedTitleCache", "PreliminaryFlag"));
68 mapping
.addMapper(CreatedAndNotesMapper
.NewInstance());
69 mapping
.addCollectionMapping(getTeamMemberMapping());
73 private CollectionExportMapping
getTeamMemberMapping(){
74 String tableName
= "AuthorTeamSequence";
75 String collectionAttribute
= "teamMembers";
76 IdMapper parentMapper
= IdMapper
.NewInstance("AuthorTeamFk");
77 int sequenceStart
= 0;
78 String sequenceAttribute
= "Sequence";
79 CollectionExportMapping mapping
= CollectionExportMapping
.NewInstance(tableName
, collectionAttribute
, parentMapper
, sequenceAttribute
, sequenceStart
);
80 mapping
.addMapper(IdMapper
.NewInstance("AuthorFk"));
85 protected void doInvoke(BerlinModelExportState state
){
87 BerlinModelExportConfigurator bmeConfig
= (BerlinModelExportConfigurator
)state
.getConfig();
89 logger
.info("start make "+pluralString
+" ...");
90 boolean success
= true ;
93 TransactionStatus txStatus
= startTransaction(true);
94 Class
<Team
> clazz
= Team
.class;
95 List
<?
extends AgentBase
> list
= getAgentService().list(clazz
, 100000000, 0,null,null);
97 CdmDbExportMapping
<BerlinModelExportState
, BerlinModelExportConfigurator
, IExportTransformer
> mapping
= getMapping();
98 mapping
.initialize(state
);
100 logger
.info("save "+pluralString
+" ...");
102 for (AgentBase
<?
> team
: list
){
103 doCount(count
++, modCount
, pluralString
);
104 if (team
instanceof Team
){
105 success
&= mapping
.invoke(team
);
109 commitTransaction(txStatus
);
111 logger
.info("end make "+pluralString
+" ..." + getSuccessString(success
));
113 state
.setUnsuccessfull();
116 }catch(SQLException e
){
118 logger
.error(e
.getMessage());
119 state
.setUnsuccessfull();
124 protected boolean doDelete(BerlinModelExportConfigurator config
){
126 Source destination
= config
.getDestination();
128 sql
= "DELETE FROM RelPTaxon";
129 destination
.setQuery(sql
);
130 destination
.update(sql
);
132 sql
= "DELETE FROM Fact";
133 destination
.setQuery(sql
);
134 destination
.update(sql
);
136 sql
= "DELETE FROM PTaxon";
137 destination
.setQuery(sql
);
138 destination
.update(sql
);
141 sql
= "DELETE FROM NameHistory";
142 destination
.setQuery(sql
);
143 destination
.update(sql
);
145 sql
= "DELETE FROM RelName";
146 destination
.setQuery(sql
);
147 destination
.update(sql
);
149 sql
= "DELETE FROM NomStatusRel";
150 destination
.setQuery(sql
);
151 destination
.update(sql
);
153 sql
= "DELETE FROM Name";
154 destination
.setQuery(sql
);
155 destination
.update(sql
);
157 sql
= "DELETE FROM RefDetail";
158 destination
.setQuery(sql
);
159 destination
.update(sql
);
161 sql
= "DELETE FROM Reference";
162 destination
.setQuery(sql
);
163 destination
.update(sql
);
165 sql
= "DELETE FROM AuthorTeamSequence";
166 destination
.setQuery(sql
);
167 destination
.update(sql
);
169 sql
= "DELETE FROM AuthorTeam";
170 destination
.setQuery(sql
);
171 destination
.update(sql
);
175 //called by MethodMapper
176 @SuppressWarnings("unused")
177 private static String
getAuthorTeamCache(Team team
){
178 if (team
.isProtectedTitleCache()){
179 return team
.getTitleCache();
185 //called by MethodMapper
186 @SuppressWarnings("unused")
187 private static String
getFullAuthorTeamCache(Team team
){
188 if (team
.isProtectedTitleCache()){
189 return team
.getNomenclaturalTitle();
197 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
199 protected boolean isIgnore(BerlinModelExportState state
){
200 return ! state
.getConfig().isDoAuthors();
204 * @see eu.etaxonomy.cdm.io.berlinModel.out.BerlinModelExportBase#getStandardMethodParameter()
207 public Class
<?
extends CdmBase
> getStandardMethodParameter() {
208 return standardMethodParameter
;