Project

General

Profile

« Previous | Next » 

Revision 244c2806

Added by Andreas Müller over 4 years ago

ref #2717 adapt export for DisplayName, WebShowName etc. to E+M requirements

View differences:

cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/out/PesiTaxonExport.java
1300 1300
        }
1301 1301
    }
1302 1302

  
1303
    /**
1304
	 * Returns the <code>DisplayName</code> attribute.
1305
	 * @param taxon The {@link TaxonBase Taxon}.
1306
	 * @return The <code>DisplayName</code> attribute.
1307
	 * @see MethodMapper
1308
	 */
1309
	@SuppressWarnings("unused")  //used by Mapper
1310
	private static String getDisplayName(TaxonBase<?> taxon) {
1311
		TaxonName taxonName = taxon.getName();
1312
		String result = getDisplayName(taxonName);
1313
		if (isMisappliedName(taxon)){
1314
			result = result + " " + getAuthorString(taxon);
1315
		}
1316
		return result;
1317
	}
1318

  
1319 1303
	/**
1320 1304
	 * Returns the <code>AuthorString</code> attribute.
1321 1305
	 * @param taxonName The {@link TaxonNameBase TaxonName}.
......
1325 1309
	//used by mapper
1326 1310
	protected static String getAuthorString(TaxonBase<?> taxon) {
1327 1311
		try {
1328
			String result = null;
1312
		    // For misapplied names there are special rules
1313
            if (isMisappliedName(taxon)){
1314
                return getMisappliedNameAuthorship(taxon);
1315
            }
1329 1316
			boolean isNonViralName = false;
1330 1317
			String authorshipCache = null;
1331 1318
			TaxonName taxonName = taxon.getName();
......
1333 1320
				authorshipCache = taxonName.getAuthorshipCache();
1334 1321
				isNonViralName = true;
1335 1322
			}
1336
			result = authorshipCache;
1337

  
1338
			// For a misapplied names there are special rules
1339
			if (isMisappliedName(taxon)){
1340
				if (taxon.getSec() != null){
1341
					String secTitle = taxon.getSec().getTitleCache();
1342
					if (! secTitle.startsWith("auct")){
1343
						secTitle = "sensu " + secTitle;
1344
					}else if (secTitle.equals("auct")){  //may be removed once the title cache is generated correctly for references with title auct. #
1345
						secTitle = "auct.";
1346
					}
1347
					return secTitle;
1348
				}else if (StringUtils.isBlank(authorshipCache)) {
1349
					// Set authorshipCache to "auct."
1350
					result = PesiTransformer.AUCT_STRING;
1351
				}else{
1352
					result = PesiTransformer.AUCT_STRING;
1353
//					result = authorshipCache;
1354
				}
1355
			}
1323
			String result = authorshipCache;
1356 1324

  
1357 1325
			if (taxonName == null){
1358 1326
				logger.warn("TaxonName does not exist for taxon: " + taxon.getUuid() + " (" + taxon.getTitleCache() + ")");
......
1371 1339
		}
1372 1340
	}
1373 1341

  
1374
	/**
1375
	 * Returns the <code>DisplayName</code> attribute.
1376
	 * @param taxonName The {@link TaxonNameBase TaxonName}.
1377
	 * @return The <code>DisplayName</code> attribute.
1378
	 * @see MethodMapper
1379
	 */
1380
	 //used by Mapper
1381
	private static String getDisplayName(TaxonName taxonName) {
1342
	private static String getMisappliedNameAuthorship(TaxonBase<?> taxon){
1343
        String result;
1344
	    String relAppendedPhrase = taxon.getAppendedPhrase();
1345
        Reference sec = taxon.getSec();
1346
        String secTitle = sec != null ? sec.getTitleCache(): null;
1347
        if(relAppendedPhrase == null && sec == null) {
1348
            result = "auct.";
1349
        }else if (relAppendedPhrase != null && sec == null){
1350
            result = relAppendedPhrase;
1351
        }else if (relAppendedPhrase == null && sec != null){
1352
            result = "sensu " + secTitle;
1353
        }else{  //append!=null && sec!=null
1354
            result = relAppendedPhrase + " " + secTitle;
1355
        }
1356
        String authorship = taxon.getName().getAuthorshipCache();
1357
        if (isNotBlank(authorship)){
1358
            result += ", non " + authorship;
1359
        }
1360
        return result;
1361
	}
1362

  
1363
    /**
1364
     * Returns the <code>DisplayName</code> attribute.
1365
     * @param taxon The {@link TaxonBase Taxon}.
1366
     * @return The <code>DisplayName</code> attribute.
1367
     * @see MethodMapper
1368
     */
1369
    //used by Mapper
1370
    private static String getDisplayName(TaxonBase<?> taxon) {
1371
        boolean isMisapplied = isMisappliedName(taxon);
1372
        TaxonName taxonName = taxon.getName();
1373
        String result = getDisplayName(taxonName, isMisapplied);
1374
        if (isMisapplied){
1375
            result = result + " " + getMisappliedNameAuthorship(taxon);
1376
        }
1377
        return result;
1378
    }
1379

  
1380
    /**
1381
     * Returns the <code>DisplayName</code> attribute.
1382
     * @param taxonName The {@link TaxonNameBase TaxonName}.
1383
     * @return The <code>DisplayName</code> attribute.
1384
     * @see MethodMapper
1385
     */
1386
    @SuppressWarnings("unused")  //used by Mapper
1387
    private static String getDisplayName(TaxonName taxonName) {
1388
        return getDisplayName(taxonName, false);
1389
    }
1390

  
1391
	private static String getDisplayName(TaxonName taxonName, boolean useNameCache) {
1382 1392
		// TODO: extension?
1383 1393
		if (taxonName == null) {
1384 1394
			return null;
......
1393 1403
			if (getSources(taxonName).contains(PesiSource.ERMS)){
1394 1404
			    result = cacheStrategy.getTitleCache(taxonName, tagRules);  //according to SQL script (also in ERMS sources are not abbreviated)
1395 1405
			}else if (getSources(taxonName).contains(PesiSource.EM)){
1396
			    result = cacheStrategy.getFullTitleCache(taxonName, tagRules);
1406
			    if (useNameCache){
1407
			        result = cacheStrategy.getNameCache(taxonName, tagRules);
1408
			    }{
1409
			        result = cacheStrategy.getFullTitleCache(taxonName, tagRules);
1410
			    }
1397 1411
			}else{
1398 1412
			    //TODO define for FE + IF and for multiple sources
1399
			    result = cacheStrategy.getFullTitleCache(taxonName, tagRules);
1413
	             if (useNameCache){
1414
                    result = cacheStrategy.getNameCache(taxonName, tagRules);
1415
                }{
1416
                    result = cacheStrategy.getFullTitleCache(taxonName, tagRules);
1417
                }
1400 1418
			}
1401 1419
			return result.replaceAll("(, ?)?\\<@status@\\>.*\\</@status@\\>", "").trim();
1402 1420
		}
......
1411 1429

  
1412 1430
	/**
1413 1431
	 * Returns the <code>WebShowName</code> attribute for a taxon.
1414
	 * @param taxonName The {@link TaxonNameBase TaxonName}.
1432
	 * See {@link #getWebShowName(TaxonName)} for further explanations.
1433
	 * @param taxon The {@link TaxonBase taxon}.
1415 1434
	 * @return The <code>WebShowName</code> attribute.
1435
	 * @see #getWebShowName(TaxonName)
1436
	 * @see #getDisplayName(TaxonBase)
1437
	 * @see #getFullName(TaxonBase)
1416 1438
	 * @see MethodMapper
1417 1439
	*/
1418 1440
	@SuppressWarnings("unused")
1419 1441
	private static String getWebShowName(TaxonBase<?> taxon) {
1420
		TaxonName taxonName = taxon.getName();
1421
		String result = getWebShowName(taxonName);
1422
		if (isMisappliedName(taxon)){
1423
			result = result + " " + getAuthorString(taxon);
1424
		}
1425
		return result;
1442
	    if (isMisappliedName(taxon)){
1443
	        //for misapplications the webshowname is the same as the displayname as they do not show the nom.ref. in displayname
1444
	        return getDisplayName(taxon);
1445
	    }else{
1446
	        TaxonName taxonName = taxon.getName();
1447
	        return getWebShowName(taxonName);
1448
	    }
1426 1449
	}
1427 1450

  
1428 1451
	/**
1429
	 * Returns the <code>WebShowName</code> attribute.
1452
	 * Returns the <code>WebShowName</code> attribute for a name. The
1453
	 * <code>WebShowName</code> is like fullName but with
1454
	 * tagged (<i>) name part. It is also similar to
1455
	 * <code>DisplayName</code> but for titleCache not fullTitleCache.
1456
	 * For misapplications it slightly differs (see {@link #getWebShowName(TaxonBase)} )
1457
	 *
1430 1458
	 * @param taxonName The {@link TaxonNameBase TaxonName}.
1431 1459
	 * @return The <code>WebShowName</code> attribute.
1460
	 * @see #getDisplayName(TaxonName)
1461
	 * @see #getFullName(TaxonName)
1462
	 * @see #getWebShowName(TaxonBase)
1432 1463
	 * @see MethodMapper
1433 1464
	 */
1434 1465
	private static String getWebShowName(TaxonName taxonName) {
......
1458 1489
		return result;
1459 1490
	}
1460 1491

  
1492
    @SuppressWarnings("unused")     //used by mapper
1493
    private static String getFullName(TaxonBase<?> taxon) {
1494
        if (isMisappliedName(taxon)){
1495
            String result = getCacheStrategy(taxon.getName()).getTitleCache(taxon.getName());
1496
            result = result + " " + getMisappliedNameAuthorship(taxon);
1497
            return result;
1498
        }else{
1499
            return getFullName(taxon.getName());
1500
        }
1501
    }
1502

  
1503

  
1461 1504
	/**
1462 1505
	 * Returns the <code>FullName</code> attribute.
1463 1506
	 * @param taxonName The {@link NonViralName NonViralName}.
1464 1507
	 * @return The <code>FullName</code> attribute.
1465 1508
	 * @see MethodMapper
1466 1509
	 */
1467
	@SuppressWarnings("unused")
1510
    //used by mapper
1468 1511
	private static String getFullName(TaxonName taxonName) {
1469 1512
		//TODO extensions?
1470 1513
		String result = getCacheStrategy(taxonName).getTitleCache(taxonName);
......
1475 1518
				if (isMisappliedName(taxon)){
1476 1519
					result = result + " " + getAuthorString(taxon);
1477 1520
				}
1478
				taxon = null;
1479 1521
			}
1480 1522
		}
1481 1523
		return result;
......
1575 1617
		try {
1576 1618
			if (taxonName != null) {
1577 1619
			    Set<NomenclaturalStatus> states = taxonName.getStatus();
1578
				if (states.size() == 1) {
1579
					NomenclaturalStatus status = states.iterator().next();
1620
				if (states.size() >= 1) {
1621
				    if (states.size() > 1) {
1622
				        String statusStr = null;
1623
				        for (NomenclaturalStatus status: states){
1624
				            statusStr = CdmUtils.concat(",", statusStr, status.getType()== null? null:status.getType().getTitleCache());
1625
				        }
1626
				        //a known case is ad43508a-8a10-480a-8519-2a76de2c0a0f (Labiatae Juss.) from E+M
1627
	                    logger.warn("This TaxonName has more than one nomenclatural status. This may happen in very rare cases but is not handled by the PESI data warehouse. Taxon name: " + taxonName.getUuid() + " (" + taxonName.getTitleCache() + ")Status:" + statusStr);
1628
	                }
1629
				    NomenclaturalStatus status = states.iterator().next();
1580 1630
					return status;
1581
				} else if (states.size() > 1) {
1582
					logger.error("This TaxonName has more than one Nomenclatural Status: " + taxonName.getUuid() + " (" + taxonName.getTitleCache() + ")");
1583 1631
				}
1584 1632
			}
1585 1633
		} catch (Exception e) {
......
2160 2208

  
2161 2209
		mapping.addMapper(MethodMapper.NewInstance("DerivedFromGuid", this));
2162 2210
		mapping.addMapper(MethodMapper.NewInstance("CacheCitation", this));
2163
		mapping.addMapper(MethodMapper.NewInstance("AuthorString", this));  //For Taxon because Misapllied Names are handled differently
2211
		mapping.addMapper(MethodMapper.NewInstance("AuthorString", this));  //For Taxon because misapplied names are handled differently
2212
		mapping.addMapper(MethodMapper.NewInstance("FullName", this));    //For Taxon because misapplied names are handled differently
2164 2213
		mapping.addMapper(MethodMapper.NewInstance("WebShowName", this));
2165 2214

  
2166 2215
		// DisplayName
......
2206 2255
		mapping.addMapper(DbConstantMapper.NewInstance("TaxonStatusFk", Types.INTEGER, PesiTransformer.T_STATUS_UNACCEPTED));
2207 2256
		mapping.addMapper(DbConstantMapper.NewInstance("TaxonStatusCache", Types.VARCHAR, state.getTransformer().getTaxonStatusCacheByKey( PesiTransformer.T_STATUS_UNACCEPTED)));
2208 2257
		mapping.addMapper(DbStringMapper.NewInstance("AuthorshipCache", "AuthorString").setBlankToNull(true));
2258
		mapping.addMapper(MethodMapper.NewInstance("FullName", this, TaxonName.class));
2209 2259
		mapping.addMapper(MethodMapper.NewInstance("WebShowName", this, TaxonName.class));
2210 2260
		mapping.addMapper(MethodMapper.NewInstance("GUID", this, TaxonName.class));
2211 2261

  
......
2230 2280
		//full name
2231 2281
//		mapping.addMapper(DbStringMapper.NewInstance("NameCache", "WebSearchName"));  //does not work as we need other cache strategy
2232 2282
		mapping.addMapper(MethodMapper.NewInstance("WebSearchName", this, TaxonName.class));
2233
		mapping.addMapper(MethodMapper.NewInstance("FullName", this, TaxonName.class));
2234 2283

  
2235 2284
		//nom ref
2236 2285
		mapping.addMapper(MethodMapper.NewInstance("NomRefString", this, TaxonName.class));

Also available in: Unified diff