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/BerlinModelNameRelationExport.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
*/
......
54 54
	public BerlinModelNameRelationExport(){
55 55
		super();
56 56
	}
57
	
57

  
58 58
	/* (non-Javadoc)
59 59
	 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#doCheck(eu.etaxonomy.cdm.io.common.IImportConfigurator)
60 60
	 */
......
64 64
		logger.warn("Checking for " + pluralString + " not yet implemented");
65 65
		//result &= checkArticlesWithoutJournal(bmiConfig);
66 66
		//result &= checkPartOfJournal(bmiConfig);
67
		
67

  
68 68
		return result;
69 69
	}
70
	
70

  
71 71
	private CdmDbExportMapping<BerlinModelExportState, BerlinModelExportConfigurator, IExportTransformer> getMapping(){
72 72
		String tableName = dbTableName;
73 73
		CdmDbExportMapping<BerlinModelExportState, BerlinModelExportConfigurator, IExportTransformer> mapping = new CdmDbExportMapping<BerlinModelExportState, BerlinModelExportConfigurator, IExportTransformer>(tableName);
......
76 76
		mapping.addMapper(DbObjectMapper.NewInstance("fromName", "NameFk1"));
77 77
		mapping.addMapper(DbObjectMapper.NewInstance("toName", "NameFk2"));
78 78

  
79
		
79

  
80 80
		mapping.addMapper(MethodMapper.NewInstance("RelNameQualifierFk", this));
81
		
81

  
82 82
		mapping.addMapper(DbObjectMapper.NewInstance("citation", "RefFk"));
83 83
		mapping.addMapper(RefDetailMapper.NewInstance("citationMicroReference","citation", "RefDetailFk"));
84 84
		mapping.addMapper(CreatedAndNotesMapper.NewInstance());
85
		
85

  
86 86
		return mapping;
87 87
	}
88
	
89
	protected void doInvoke(BerlinModelExportState state){
88

  
89
	@Override
90
    protected void doInvoke(BerlinModelExportState state){
90 91
		try{
91 92
			logger.info("start make " + pluralString + " ...");
92 93
			boolean success = true ;
93 94
			doDelete(state);
94
			
95

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

  
97 98
			List<RelationshipBase> list = getNameService().getAllRelationships(100000000, 0);
98
			
99

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

  
102 103
			int count = 0;
103 104
			for (RelationshipBase<?,?,?> rel : list){
104 105
				if (rel.isInstanceOf(NameRelationship.class) || rel.isInstanceOf(HybridRelationship.class )){
......
107 108
				}
108 109
			}
109 110
			commitTransaction(txStatus);
110
			
111

  
111 112
			success &= makeIsHomotypicRelation(state, mapping);
112
			
113

  
113 114
			logger.info("end make " + pluralString + " ..." + getSuccessString(success));
114 115
			if (!success){
115
				state.setUnsuccessfull();
116
                String message = "An undefined error occurred during name relation export";
117
                state.getResult().addError(message);
116 118
			}
117 119
			return;
118 120
		}catch(SQLException e){
119 121
			e.printStackTrace();
120 122
			logger.error(e.getMessage());
121
			state.setUnsuccessfull();
123
			state.getResult().addException(e);
122 124
			return;
123 125
		}
124 126
	}
125 127

  
126
	
128

  
127 129
	private boolean makeIsHomotypicRelation(BerlinModelExportState state, CdmDbExportMapping<BerlinModelExportState, BerlinModelExportConfigurator, IExportTransformer> mapping){
128 130
		boolean success = true ;
129 131
		try{
......
132 134
				return success;
133 135
			}
134 136
			logger.info("start make IsHomotypicRelations ...");
135
			
137

  
136 138
			TransactionStatus txStatus = startTransaction(true);
137
			
139

  
138 140
			List<HomotypicalGroup> list = getNameService().getAllHomotypicalGroups(100000000, 0);
139
			
141

  
140 142
			int count = 0;
141 143
			modCount = 1000;
142
			Set<NameRelationship> basionymNameRels = new HashSet<NameRelationship>(); 
144
			Set<NameRelationship> basionymNameRels = new HashSet<NameRelationship>();
143 145
			for (HomotypicalGroup homoGroup : list){
144 146
				doCount(count++, modCount, "homotypical groups");
145 147
				Set<TaxonNameBase> allNames = homoGroup.getTypifiedNames();
......
157 159
				}
158 160
			}
159 161
			commitTransaction(txStatus);
160
			
162

  
161 163
			logger.info("end make homotypical groups ... " +  getSuccessString(success));
162 164
			return success;
163 165
		}catch(SQLException e){
164 166
			logger.error(e.getMessage());
165 167
			e.printStackTrace();
166 168
			return false;
167
		}	
169
		}
168 170
	}
169
	
171

  
170 172
	private boolean invokeIsHomotypic(BerlinModelExportState state, CdmDbExportMapping<BerlinModelExportState, BerlinModelExportConfigurator, IExportTransformer> mapping, TaxonNameBase fromName, TaxonNameBase toName, Reference refId, String microCitation) throws SQLException{
171 173
		try{
172 174
			logger.info(fromName.getTitleCache() + "->" + toName.getTitleCache());
......
179 181
			int fromNameId = state.getDbId(fromName);
180 182
			int toNameId = state.getDbId(toName);
181 183
			int catId = state.getConfig().getIsHomotypicId();
182
			String query = "INSERT INTO relName (relNameId, nameFk1, nameFk2, RelNameQualifierFk) " + 
184
			String query = "INSERT INTO relName (relNameId, nameFk1, nameFk2, RelNameQualifierFk) " +
183 185
				" VALUES ("+maxId+","+fromNameId+","+toNameId+","+catId+")";
184 186
			int ui = state.getConfig().getDestination().getConnection().createStatement().executeUpdate(query);
185 187
		}catch(SQLException e){
......
196 198
		}
197 199
		return result;
198 200
	}
199
	
201

  
200 202
	protected boolean doDelete(BerlinModelExportState state){
201 203
		BerlinModelExportConfigurator bmeConfig = state.getConfig();
202
		
204

  
203 205
		String sql;
204 206
		Source destination =  bmeConfig.getDestination();
205 207
		//RelPTaxon
......
209 211

  
210 212
		return true;
211 213
	}
212
		
213
	
214

  
215

  
214 216
	/* (non-Javadoc)
215 217
	 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
216 218
	 */
217
	protected boolean isIgnore(BerlinModelExportState state){
219
	@Override
220
    protected boolean isIgnore(BerlinModelExportState state){
218 221
		return ! state.getConfig().isDoRelNames();
219 222
	}
220
	
223

  
221 224
	//called by MethodMapper
222 225
	@SuppressWarnings("unused")
223 226
	private static Integer getRelNameQualifierFk(RelationshipBase<?, ?, ?> rel) throws Exception {
......
232 235
			return BerlinModelTransformer.nameRel2RelNameQualifierFk(rel);
233 236
//		}
234 237
	}
235
	
238

  
236 239
	/* (non-Javadoc)
237 240
	 * @see eu.etaxonomy.cdm.io.berlinModel.out.BerlinModelExportBase#getStandardMethodParameter()
238 241
	 */

Also available in: Unified diff