/**\r
* Copyright (C) 2007 EDIT\r
-* European Distributed Institute of Taxonomy \r
+* European Distributed Institute of Taxonomy\r
* http://www.e-taxonomy.eu\r
-* \r
+*\r
* The contents of this file are subject to the Mozilla Public License Version 1.1\r
* See LICENSE.TXT at the top of this package for the full license terms.\r
*/\r
import eu.etaxonomy.cdm.model.reference.Reference;\r
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;\r
import eu.etaxonomy.cdm.model.taxon.Synonym;\r
-import eu.etaxonomy.cdm.model.taxon.SynonymRelationship;\r
import eu.etaxonomy.cdm.model.taxon.Taxon;\r
import eu.etaxonomy.cdm.model.taxon.TaxonBase;\r
\r
*/\r
public class CyprusAltitudeActivator {\r
private static final Logger logger = Logger.getLogger(CyprusAltitudeActivator.class);\r
- \r
+\r
//database validation status (create, update, validate ...)\r
static DbSchemaValidation hbm2dll = DbSchemaValidation.VALIDATE;\r
// static final URI source = cyprus_distribution();\r
static final URI source = cyprus_altitude();\r
\r
- \r
+\r
static final ICdmDataSource cdmDestination = CdmDestinations.localH2();\r
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql_test();\r
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_cyprus_dev();\r
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_cyprus_production();\r
\r
- \r
+\r
//feature tree uuid\r
public static final UUID featureTreeUuid = UUID.fromString("14d1e912-5ec2-4d10-878b-828788b70a87");\r
- \r
+\r
//classification\r
static final UUID classificationUuid = UUID.fromString("0c2b5d25-7b15-4401-8b51-dd4be0ee5cab");\r
- \r
+\r
private static final String sourceReferenceTitle = "Cyprus Excel Altitude Import";\r
- \r
- \r
+\r
+\r
//TODO move to Feature vocabulary\r
private static final UUID uuidAltitudeFeature = UUID.fromString("1a28ed59-e15f-4001-b5c2-ea89f0012671");\r
- \r
+\r
//check - import\r
static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK;\r
- \r
+\r
private void doImport(ICdmDataSource cdmDestination){\r
- \r
- \r
+\r
+\r
ArrayList<HashMap<String, String>> excel;\r
try {\r
excel = ExcelUtils.parseXLS(source, "coreTax");\r
e.printStackTrace();\r
return;\r
}\r
- \r
+\r
CdmApplicationController app = CdmIoApplicationController.NewInstance(cdmDestination, hbm2dll);\r
\r
Set<TaxonBase> taxaToSave = new HashSet<TaxonBase>();\r
- \r
+\r
TransactionStatus tx = app.startTransaction();\r
- \r
+\r
UUID uuidMikle77 = UUID.fromString("9f5fa7ee-538b-4ae5-bd82-2a9503fea1d6");\r
UUID uuidMikle85 = UUID.fromString("994403c4-c400-413d-9a1a-8531a40bfd8c");\r
- \r
- Reference<?> mikle77 = app.getReferenceService().find(uuidMikle77);\r
- Reference<?> mikle85 = app.getReferenceService().find(uuidMikle85);\r
- \r
- \r
+\r
+ Reference mikle77 = app.getReferenceService().find(uuidMikle77);\r
+ Reference mikle85 = app.getReferenceService().find(uuidMikle85);\r
+\r
+\r
Feature altitudeFeature = (Feature) app.getTermService().find(uuidAltitudeFeature);\r
if (altitudeFeature == null){\r
// altitudeFeature = Feature.NewInstance("Altitude", "Altitude", "alt.");\r
// featureVoc.addTerm(altitudeFeature);\r
throw new RuntimeException("Could not find altitudinal range feature");\r
}\r
- \r
+\r
MeasurementUnit meter = (MeasurementUnit)app.getTermService().find(UUID.fromString("8bef5055-789c-41e5-bea2-8dc2ea8ecdf6"));\r
// NamedArea cyprus = (NamedArea)app.getTermService().find(UUID.fromString("da4cce9a-439b-4cc4-8073-85dc75bae169"));\r
- \r
+\r
int count =1;\r
for (HashMap<String, String> row : excel){\r
count++;\r
UUID baseUuid = makeUuid(row, "uuid");\r
UUID acceptedUuid = makeUuid(row, "acceptedNameUuid");\r
UUID parentUuid = makeUuid(row, "parentUuid");\r
- \r
+\r
// String altitude = row.get("Altitude-kumuliert");\r
- \r
+\r
String altitudeMin = row.get("Min");\r
String altitudeMax = row.get("Max");\r
String acceptedName = row.get("AcceptedName");\r
- \r
- \r
- \r
+\r
+\r
+\r
String source = row.get("Source");\r
- \r
+\r
if (StringUtils.isBlank(altitudeMin)){\r
continue;\r
}\r
- \r
+\r
boolean hasAltitude = false;\r
- Reference<?> sourceRef = getSource(source, mikle77, mikle85);\r
+ Reference sourceRef = getSource(source, mikle77, mikle85);\r
Taxon taxon = getTaxon(app, baseUuid, acceptedUuid, parentUuid, acceptedName, count);\r
if (taxon != null){\r
TaxonDescription desc = getDescription(taxon, sourceRef);\r
- \r
+\r
hasAltitude = makeAltitude(altitudeMin, altitudeMax, altitudeFeature, sourceRef, desc, meter, count);\r
// hasAltitude = makeAltitudeOld(altitude, altitudeFeature, sourceRef, desc, meter, count);\r
if (hasAltitude){\r
}\r
\r
app.getTaxonService().saveOrUpdate(taxaToSave);\r
- \r
+\r
// tx.setRollbackOnly();\r
app.commitTransaction(tx);\r
}\r
private Taxon getTaxon(CdmApplicationController app, UUID baseUuid, UUID acceptedUuid, UUID parentUuid, String acceptedName, int row) {\r
TaxonBase<?> base = app.getTaxonService().find(baseUuid);\r
// TaxonBase<?> parent = app.getTaxonService().find(parentUuid);\r
- \r
+\r
//TODO\r
Taxon result = null;\r
if (base.isInstanceOf(Taxon.class)){\r
}else{\r
logger.warn("Synonym relation has changed somehow. Row: " + row + ", Taxon: " + base.getTitleCache());\r
}\r
- \r
+\r
}else{\r
logger.warn("Accepted taxon not in classification. Row: " + row + ", Taxon: " + base.getTitleCache());\r
}\r
}\r
- \r
+\r
if (result != null){\r
if (! result.getName().getTitleCache().equals(acceptedName)){\r
logger.warn("AcceptedName and taxon name is not equal in " + row + ".\n" +\r
" Taxon Name: " + result.getName().getTitleCache());\r
}\r
}\r
- \r
+\r
return result;\r
}\r
\r
private boolean hasSynonym(Taxon t, TaxonBase<?> base) {\r
if (base.isInstanceOf(Synonym.class)){\r
- for (SynonymRelationship rel : t.getSynonymRelations()){\r
- if (rel.getSynonym().equals(base)){\r
+ for (Synonym syn : t.getSynonyms()){\r
+ if (syn.equals(base)){\r
return true;\r
}\r
}\r
// private static final Pattern altitudePattern = Pattern.compile("\\d{1,4}(-\\d{1,4})?");\r
\r
\r
- private boolean makeAltitude(String altitudeMin, String altitudeMax, Feature altitudeFeature, \r
- Reference<?> sourceRef, TaxonDescription desc, MeasurementUnit meter, int row) {\r
- \r
+ private boolean makeAltitude(String altitudeMin, String altitudeMax, Feature altitudeFeature,\r
+ Reference sourceRef, TaxonDescription desc, MeasurementUnit meter, int row) {\r
+\r
QuantitativeData data = QuantitativeData.NewInstance(altitudeFeature);\r
- \r
+\r
//Meikle\r
if (source != null){\r
TaxonNameBase<?,?> nameUsedInSource = null; //TODO\r
// //Excel //excel source not wanted by Ralf\r
// TaxonNameBase<?,?> nameUsedInSource = null; //TODO probably we don't want this\r
// data.addSource(OriginalSourceType.Import, String.valueOf(row), "row", getSourceReference(), null, nameUsedInSource, null);\r
- \r
+\r
data.setUnit(meter);\r
- \r
+\r
Integer min = Integer.valueOf(altitudeMin);\r
StatisticalMeasurementValue minValue = StatisticalMeasurementValue.NewInstance(StatisticalMeasure.MIN(), min);\r
data.addStatisticalValue(minValue);\r
Integer max = Integer.valueOf(altitudeMax);\r
StatisticalMeasurementValue maxValue = StatisticalMeasurementValue.NewInstance(StatisticalMeasure.MAX(), max);\r
data.addStatisticalValue(maxValue);\r
- \r
+\r
desc.addElement(data);\r
return true;\r
}\r
- \r
-// private boolean makeAltitudeOld(String altitudeOrig, Feature feature, Reference<?> source, TaxonDescription desc, MeasurementUnit meter, int row) {\r
+\r
+// private boolean makeAltitudeOld(String altitudeOrig, Feature feature, Reference source, TaxonDescription desc, MeasurementUnit meter, int row) {\r
// String altitude = altitudeOrig.trim().replace(" ", "");\r
// Matcher matcher = altitudePattern.matcher(altitude);\r
-// \r
+//\r
// if (matcher.matches()){\r
// QuantitativeData data = QuantitativeData.NewInstance(feature);\r
-// \r
+//\r
// //Meikle\r
// if (source != null){\r
// TaxonNameBase<?,?> nameUsedInSource = null; //TODO\r
// TaxonNameBase<?,?> nameUsedInSource = null; //TODO probably we don't want this\r
// data.addSource(OriginalSourceType.Import, String.valueOf(row), "row", getSourceReference(), null, nameUsedInSource, null);\r
// data.setUnit(meter);\r
-// \r
+//\r
// String[] split = altitude.split("-");\r
//\r
// Integer min = Integer.valueOf(split[0]);\r
// }\r
// }\r
\r
- private TaxonDescription getDescription(Taxon taxon, Reference<?> sourceRef) {\r
+ private TaxonDescription getDescription(Taxon taxon, Reference sourceRef) {\r
if (taxon != null){\r
//TODO Mikle existiert derzeit nicht also Source\r
- \r
+\r
TaxonDescription desc = TaxonDescription.NewInstance();\r
desc.setTitleCache("Import from " + getSourceReference().getTitleCache(), true);\r
desc.addSource(OriginalSourceType.PrimaryTaxonomicSource, null, null, sourceRef,null);\r
desc.addSource(OriginalSourceType.Import, null, null, getSourceReference(), null);\r
- \r
+\r
return desc;\r
}\r
return null;\r
}\r
\r
- private Reference<?> getSource(String source, Reference<?> m77, Reference<?> m85) {\r
+ private Reference getSource(String source, Reference m77, Reference m85) {\r
if(StringUtils.isNotBlank(source)){\r
if (source.equals("Meikle 1977")){\r
return m77;\r
// // TODO Auto-generated method stub\r
// HashMap<String, Object> = new HashM\r
// row\r
-// \r
-// \r
+//\r
+//\r
// }\r
\r
- \r
- Reference<?> sourceReference;\r
- private Reference<?> getSourceReference() {\r
+\r
+ Reference sourceReference;\r
+ private Reference getSourceReference() {\r
if (sourceReference == null){\r
sourceReference = ReferenceFactory.newGeneric();\r
sourceReference.setTitleCache(sourceReferenceTitle, true);\r
- \r
+\r
}\r
return sourceReference;\r
- \r
+\r
}\r
\r
- \r
+\r
//Cyprus\r
public static URI cyprus_altitude() {\r
URI sourceUrl;\r
\r
private void testMatcher() {\r
// makeAltitude("0-4400", null, null);\r
- \r
+\r
}\r
- \r
+\r
}\r