Project

General

Profile

« Previous | Next » 

Revision de3c38ba

Added by Andreas Müller over 4 years ago

ref #8509 fix link (and ecology) export ERMS

View differences:

cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/erms/ErmsLinkImport.java
57 57
	protected String getRecordQuery(ErmsImportConfigurator config) {
58 58
		String strRecordQuery =
59 59
			" SELECT l.* " +
60
			        ",'%s' + link_url + '%s' + ISNULL(link_text, '')   valueAll" + //+ ' ,@Note: ' + ISNULL(CAST(note as nvarchar(max)), '')
60
			        ",'%s' + link_url + '%s' + ISNULL(link_text, ' ')   valueAll" + //+ ' ,@Note: ' + ISNULL(CAST(note as nvarchar(max)), ' ')
61 61
			" FROM links l " +
62 62
			" WHERE ( l.id IN (" + ID_LIST_TOKEN + ") )";
63 63
		strRecordQuery = String.format(strRecordQuery, TOKEN_URL, TOKEN_LINKTEXT);
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/out/PesiEcologyAndLinkExport.java
70 70
			boolean success = true;
71 71

  
72 72
			// Get specific mappings: (CDM) TaxonBase.marker -> (PESI) Note (ecology)
73
			PesiExportMapping mapping = getMapping();
73
			PesiExportMapping mapping = getEcologyMapping();
74 74
			mapping.initialize(state);
75 75

  
76 76
			PesiExportMapping urlMapping = getUrlMapping();
77
			mapping.initialize(state);
77
			urlMapping.initialize(state);
78 78

  
79 79
			//All
80 80
			success &= doPhase01(state, mapping, urlMapping);
......
111 111
		    ProfilerController.memorySnapshot();
112 112
		}
113 113

  
114
		List<String> propPath = Arrays.asList(new String[]{"markers.*"});
114
		List<String> propPath = Arrays.asList(new String[]{"markers.*","extensions.*"});
115 115
		int partitionCount = 0;
116 116
		while ((taxonList = getNextTaxonPartition(TaxonBase.class, limit, partitionCount++, propPath )) != null   ) {
117 117

  
......
217 217
    }
218 218

  
219 219
    @SuppressWarnings("unused")  //used by mapper
220
    private static String getUrlNote_1(Extension extension, PesiExportState state) {
220
    private static String getUrlNote_1(Extension extension) {
221 221
        String value = extension.getValue();
222 222
        if (value == null){
223 223
            return null;
224 224
        }else{
225 225
            //TODO use regex grouping
226 226
            String result = value.split(ErmsLinkImport.TOKEN_LINKTEXT)[0];
227
            result = result.trim();
227
            result = result.replace(ErmsLinkImport.TOKEN_URL, "").trim();
228 228
            return result;
229 229
        }
230 230
    }
231 231

  
232
    @SuppressWarnings("unused")  //used by mapper
233
    private static String getUrlNote_2(Extension extension, PesiExportState state) {
232
//  @SuppressWarnings("unused")  //used by mapper
233
    private static String getUrlNote_2(Extension extension) {
234 234
        String value = extension.getValue();
235 235
        if (value == null){
236 236
            return null;
237 237
        }else{
238 238
            //TODO use regex grouping
239
            String result = value.split(ErmsLinkImport.TOKEN_LINKTEXT)[1];
240
            result = result.trim();
241
            return result;
239
            String[] split = value.split(ErmsLinkImport.TOKEN_LINKTEXT);
240
            if (split.length > 1){
241
                String result = split[1];
242
                result = result.trim();
243
                return CdmUtils.Ne(result);
244
            }else{
245
                return null;
246
            }
242 247
        }
243 248
    }
244 249

  
245
    @SuppressWarnings("unused")  //used by mapper
246
    private static Integer getNoteCategoryFk(Extension extension, PesiExportState state) {
247
        String linktext = getUrlNote_2(extension, state);
250
//  @SuppressWarnings("unused")  //used by mapper
251
    private static Integer getNoteCategoryFk(Extension extension) {
252
        String linktext = getUrlNote_2(extension);
248 253
        int catFk = categoryByLinkText(linktext);
249 254
        return catFk;
250 255
    }
......
252 257
    private static int categoryByLinkText(String linktext) {
253 258
        if (linktext == null){
254 259
            return PesiTransformer.NoteCategory_undefined_link;
255
        }else if (linktext.matches("(to fishbase|marine life inf).*")){
260
        }else if (linktext.matches("(?i)(to fishbase|marine life inf).*")){
256 261
            return PesiTransformer.NoteCategory_Link_to_general_information;
257
        }else if (linktext.matches(".*(clemam|nemys|algaebase|fishbase).*")){
262
        }else if (linktext.matches("(?i).*(clemam|nemys|algaebase|fishbase).*")){
258 263
            return PesiTransformer.NoteCategory_Link_to_taxonomy;
259 264
        }else{
260 265
            return PesiTransformer.NoteCategory_undefined_link;
......
262 267
    }
263 268

  
264 269
    @SuppressWarnings("unused")  //used by mapper
265
    private static String getNoteCategoryCache(Extension extension, PesiExportState state) {
266
        int catFk = getNoteCategoryFk(extension, state);
270
    private static String getNoteCategoryCache(Extension extension) {
271
        int catFk = getNoteCategoryFk(extension);
267 272
        String result = categoryByLinkText(catFk);
268 273
        return result;
269 274
    }
......
283 288

  
284 289
//******************************* MAPPINGS ********************************************
285 290

  
286
    private PesiExportMapping getMapping() {
291
    private IdIncMapper idIncMapperEcology = IdIncMapper.NewComputedInstance("NoteId");
292
    private PesiExportMapping getEcologyMapping() {
287 293
        PesiExportMapping mapping = new PesiExportMapping(dbTableName);
288 294

  
289
        mapping.addMapper(idIncMapper);
295
        mapping.addMapper(idIncMapperEcology);
290 296
        mapping.addMapper(MethodMapper.NewInstance("Note_1", this, standardMethodParameter));
291 297

  
292 298
        mapping.addMapper(DbFixedIntegerMapper.NewInstance(PesiTransformer.NoteCategory_ecology, "NoteCategoryFk"));
......
296 302

  
297 303
        mapping.addMapper(MethodMapper.NewInstance("TaxonFk", this, standardMethodParameter, PesiExportState.class));
298 304

  
299
        mapping.addMapper(DbExportIgnoreMapper.NewInstance("Note_2", "Note_2 not used for ecology fact"));
300
        mapping.addMapper(DbExportIgnoreMapper.NewInstance("Region", "Region not used for ecology fact"));
301
        mapping.addMapper(DbExportIgnoreMapper.NewInstance("SpeciesExpertGUID", "SpeciesExpertGUID not used for ecology fact"));
302
        mapping.addMapper(DbExportIgnoreMapper.NewInstance("SpeciesExpertName", "SpeciesExpertName not used for ecology fact"));
303
        mapping.addMapper(DbExportIgnoreMapper.NewInstance("LastAction", "LastAction not used for ecology fact"));
304
        mapping.addMapper(DbExportIgnoreMapper.NewInstance("LastActionDate", "LastActionDate not used for ecology fact"));
305
        mapping.addMapper(DbExportIgnoreMapper.NewInstance("Note_2", "not used for ecology fact"));
306
        mapping.addMapper(DbExportIgnoreMapper.NewInstance("Region", "not used for ecology fact"));
307
        mapping.addMapper(DbExportIgnoreMapper.NewInstance("SpeciesExpertGUID", "not used for ecology fact"));
308
        mapping.addMapper(DbExportIgnoreMapper.NewInstance("SpeciesExpertName", "not used for ecology fact"));
309
        mapping.addMapper(DbExportIgnoreMapper.NewInstance("LastAction", "not used for ecology fact"));
310
        mapping.addMapper(DbExportIgnoreMapper.NewInstance("LastActionDate", "not used for ecology fact"));
305 311

  
306 312
        return mapping;
307 313
    }
308
    private IdIncMapper idIncMapper = IdIncMapper.NewComputedInstance("NoteId");
309 314
    private PesiExportMapping getUrlMapping() {
310 315
        PesiExportMapping mapping = new PesiExportMapping(dbTableName);
311

  
316
        IdIncMapper idIncMapper = IdIncMapper.NewDependendInstance("NoteId", idIncMapperEcology);
312 317
        mapping.addMapper(idIncMapper);
313 318
        mapping.addMapper(MethodMapper.NewInstance("Note_1", this.getClass(), "getUrlNote_1", Extension.class));
314 319
        mapping.addMapper(MethodMapper.NewInstance("Note_2", this.getClass(), "getUrlNote_2", Extension.class));
......
316 321
        mapping.addMapper(MethodMapper.NewInstance("NoteCategoryCache", this.getClass(), Extension.class));
317 322
        mapping.addMapper(MethodMapper.NewInstance("TaxonFk", this.getClass(), "getCurrentTaxonFk", Extension.class, PesiExportState.class));
318 323

  
319
        mapping.addMapper(DbExportIgnoreMapper.NewInstance("LanguageFk", "LanguageFk not used for link fact"));
320
        mapping.addMapper(DbExportIgnoreMapper.NewInstance("LanguageCache", "LanguageCache not used for link fact"));
321
        mapping.addMapper(DbExportIgnoreMapper.NewInstance("Region", "Region not used for link fact"));
322
        mapping.addMapper(DbExportIgnoreMapper.NewInstance("SpeciesExpertGUID", "SpeciesExpertGUID not used for link fact"));
323
        mapping.addMapper(DbExportIgnoreMapper.NewInstance("SpeciesExpertName", "SpeciesExpertName not used for link fact"));
324
        mapping.addMapper(DbExportIgnoreMapper.NewInstance("LastAction", "LastAction not used for link fact"));
325
        mapping.addMapper(DbExportIgnoreMapper.NewInstance("LastActionDate", "LastActionDate not used for link fact"));
324
        mapping.addMapper(DbExportIgnoreMapper.NewInstance("LanguageFk", "not used for link fact"));
325
        mapping.addMapper(DbExportIgnoreMapper.NewInstance("LanguageCache", "not used for link fact"));
326
        mapping.addMapper(DbExportIgnoreMapper.NewInstance("Region", "not used for link fact"));
327
        mapping.addMapper(DbExportIgnoreMapper.NewInstance("SpeciesExpertGUID", "not used for link fact"));
328
        mapping.addMapper(DbExportIgnoreMapper.NewInstance("SpeciesExpertName", "not used for link fact"));
329
        mapping.addMapper(DbExportIgnoreMapper.NewInstance("LastAction", "not used for link fact"));
330
        mapping.addMapper(DbExportIgnoreMapper.NewInstance("LastActionDate", "not used for link fact"));
326 331

  
327 332
        return mapping;
328 333
    }

Also available in: Unified diff