Project

General

Profile

« Previous | Next » 

Revision 79de4982

Added by Andreas Müller about 7 years ago

ref #6519 adapt app-import to ExportResult

View differences:

app-import/src/main/java/eu/etaxonomy/cdm/io/berlinModel/out/BerlinModelClassificationExport.java
1 1
/**
2 2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
3
* European Distributed Institute of Taxonomy
4 4
* http://www.e-taxonomy.eu
5
* 
5
*
6 6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7 7
* See LICENSE.TXT at the top of this package for the full license terms.
8 8
*/
......
25 25
import eu.etaxonomy.cdm.io.common.mapping.out.MethodMapper;
26 26
import eu.etaxonomy.cdm.model.common.CdmBase;
27 27
import eu.etaxonomy.cdm.model.common.RelationshipBase;
28
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
28
import eu.etaxonomy.cdm.model.taxon.Classification;
29 29
import eu.etaxonomy.cdm.model.taxon.Taxon;
30 30
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
31
import eu.etaxonomy.cdm.model.taxon.Classification;
32 31

  
33 32

  
34 33
/**
......
49 48
	public BerlinModelClassificationExport(){
50 49
		super();
51 50
	}
52
	
51

  
53 52
	/* (non-Javadoc)
54 53
	 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#doCheck(eu.etaxonomy.cdm.io.common.IImportConfigurator)
55 54
	 */
......
59 58
		logger.warn("Checking for " + pluralString + " not yet implemented");
60 59
		//result &= checkArticlesWithoutJournal(bmiConfig);
61 60
		//result &= checkPartOfJournal(bmiConfig);
62
		
61

  
63 62
		return result;
64 63
	}
65
	
64

  
66 65
	private CdmDbExportMapping<BerlinModelExportState, BerlinModelExportConfigurator, IExportTransformer> getMapping(){
67 66
		String tableName = dbTableName;
68 67
		CdmDbExportMapping<BerlinModelExportState, BerlinModelExportConfigurator, IExportTransformer> mapping = new CdmDbExportMapping<BerlinModelExportState, BerlinModelExportConfigurator, IExportTransformer>(tableName);
69 68
//		mapping.addMapper(IdMapper.NewInstance("RelPTaxonId"));  //is Identity column
70
		
69

  
71 70
		mapping.addMapper(MethodMapper.NewInstance("PTNameFk1", this.getClass(), "getPTNameFk1", standardMethodParameter, DbExportStateBase.class));
72 71
		mapping.addMapper(MethodMapper.NewInstance("PTRefFk1", this.getClass(), "getPTRefFk1", standardMethodParameter, DbExportStateBase.class));
73
		
72

  
74 73
		mapping.addMapper(MethodMapper.NewInstance("PTNameFk2", this.getClass(), "getPTNameFk2", standardMethodParameter, DbExportStateBase.class));
75 74
		mapping.addMapper(MethodMapper.NewInstance("PTRefFk2", this.getClass(), "getPTRefFk2", standardMethodParameter, DbExportStateBase.class));
76
		
75

  
77 76
		mapping.addMapper(DbConstantMapper.NewInstance("RelQualifierFk", Types.INTEGER, 1));
78
		
77

  
79 78
		mapping.addMapper(DbObjectMapper.NewInstance("referenceForParentChildRelation", "RelRefFk"));
80 79
//		mapping.addMapper(RefDetailMapper.NewInstance("citationMicroReference","citation", "FactRefDetailFk"));
81 80
		mapping.addMapper(CreatedAndNotesMapper.NewInstance());
82 81

  
83 82
		return mapping;
84 83
	}
85
	
86
	protected void doInvoke(BerlinModelExportState state){
84

  
85
	@Override
86
    protected void doInvoke(BerlinModelExportState state){
87 87
		if (state.getConfig().isUseClassification() == false){
88 88
			return;
89 89
		}
90
		
90

  
91 91
		try{
92 92
			logger.info("start make " + pluralString + " ...");
93 93
			boolean success = true ;
94 94
			doDelete(state);
95
			
95

  
96 96
			TransactionStatus txStatus = startTransaction(true);
97
			
97

  
98 98
			List<Classification> list = getClassificationService().list(null,10000000,0,null,null);
99
			
99

  
100 100
			CdmDbExportMapping<BerlinModelExportState, BerlinModelExportConfigurator, IExportTransformer> mapping = getMapping();
101 101
			mapping.initialize(state);
102
			
102

  
103 103
			int count = 0;
104 104
			for (Classification tree : list){
105 105
				for (TaxonNode node : tree.getAllNodes()){
......
114 114
			commitTransaction(txStatus);
115 115
			logger.info("end make " + pluralString + " ..." + getSuccessString(success));
116 116
			if (!success){
117
				state.setUnsuccessfull();
117
                String message = "An undefined error occurred during Classification export";
118
                state.getResult().addError(message);
118 119
			}
119 120
			return;
120 121
		}catch(SQLException e){
121 122
			e.printStackTrace();
122 123
			logger.error(e.getMessage());
123
			state.setUnsuccessfull();
124
			state.getResult().addException(e);
124 125
			return;
125 126
		}
126 127
	}
127 128

  
128
	
129

  
129 130
	protected boolean doDelete(BerlinModelExportState state){
130 131
		BerlinModelExportConfigurator bmeConfig = state.getConfig();
131
		
132

  
132 133
		//already deleted in BerlinModelTaxonRelationExport
133 134
//		String sql;
134 135
//		Source destination =  bmeConfig.getDestination();
......
139 140

  
140 141
		return true;
141 142
	}
142
		
143
	
143

  
144

  
144 145
	/* (non-Javadoc)
145 146
	 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
146 147
	 */
147
	protected boolean isIgnore(BerlinModelExportState state){
148
	@Override
149
    protected boolean isIgnore(BerlinModelExportState state){
148 150
		return ! state.getConfig().isDoRelTaxa();
149 151
	}
150
	
152

  
151 153
	//called by MethodMapper
152
	
154

  
153 155
	@SuppressWarnings("unused")
154 156
	private static Integer getPTNameFk1(TaxonNode node, DbExportStateBase<?, IExportTransformer> state){
155 157
		return getObjectFk(node, state, true, true);
156 158
	}
157
	
159

  
158 160
	@SuppressWarnings("unused")
159 161
	private static Integer getPTRefFk1(TaxonNode node, DbExportStateBase<?, IExportTransformer> state){
160 162
		return getObjectFk(node, state, false, true);
161 163
	}
162
	
164

  
163 165
	@SuppressWarnings("unused")
164 166
	private static Integer getPTNameFk2(TaxonNode node, DbExportStateBase<?, IExportTransformer> state){
165 167
		return getObjectFk(node, state, true, false);
166 168
	}
167
	
169

  
168 170
	@SuppressWarnings("unused")
169 171
	private static Integer getPTRefFk2(TaxonNode node, DbExportStateBase<?, IExportTransformer> state){
170 172
		return getObjectFk(node, state, false, false);
......
180 182
		logger.warn("No taxon or parent taxon found for taxon node: " + node.toString());
181 183
		return null;
182 184
	}
183
	
184
	
185

  
186

  
185 187
	/* (non-Javadoc)
186 188
	 * @see eu.etaxonomy.cdm.io.berlinModel.out.BerlinModelExportBase#getStandardMethodParameter()
187 189
	 */

Also available in: Unified diff