3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
11 package eu
.etaxonomy
.cdm
.app
.wp6
.palmae
;
13 import java
.util
.List
;
14 import java
.util
.UUID
;
16 import org
.apache
.log4j
.Logger
;
17 import org
.springframework
.transaction
.TransactionStatus
;
19 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationController
;
20 import eu
.etaxonomy
.cdm
.app
.common
.CdmDestinations
;
21 import eu
.etaxonomy
.cdm
.database
.DbSchemaValidation
;
22 import eu
.etaxonomy
.cdm
.database
.ICdmDataSource
;
23 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
24 import eu
.etaxonomy
.cdm
.model
.description
.FeatureNode
;
25 import eu
.etaxonomy
.cdm
.model
.description
.FeatureTree
;
32 public class PalmaeFeatureTreeUpdater
{
33 private static final Logger logger
= Logger
.getLogger(PalmaeFeatureTreeUpdater
.class);
35 static final ICdmDataSource cdmDestination
= CdmDestinations
.localH2Palmae();
38 private String relationships
= "relationships";
39 private String taxonomicAccounts
= "taxonomic accounts";
40 private String fossilRecord
= "fossil record";
42 public boolean updateMissingFeatures(ICdmDataSource dataSource
) {
45 UUID featureTreeUuid
= PalmaeActivator
.featureTreeUuid
;
46 CdmApplicationController cdmApp
= CdmApplicationController
.NewInstance(dataSource
, DbSchemaValidation
.VALIDATE
);
48 TransactionStatus tx
= cdmApp
.startTransaction();
50 FeatureTree tree
= cdmApp
.getDescriptionService().getFeatureTreeByUuid(featureTreeUuid
);
51 FeatureNode root
= tree
.getRoot();
53 List
<Feature
> featureList
= cdmApp
.getDescriptionService().getFeaturesAll();
54 for (Feature feature
: featureList
){
55 String label
= feature
.getLabel();
56 if (relationships
.equals(label
)){
57 FeatureNode newNode
= FeatureNode
.NewInstance(feature
);
58 root
.addChild(newNode
);
60 }else if(taxonomicAccounts
.equals(label
)){
61 FeatureNode newNode
= FeatureNode
.NewInstance(feature
);
62 root
.addChild(newNode
);
64 }else if(fossilRecord
.equals(label
)){
65 FeatureNode newNode
= FeatureNode
.NewInstance(feature
);
66 root
.addChild(newNode
);
70 cdmApp
.commitTransaction(tx
);
72 logger
.warn("Did not find 3 additional features but " + count
);
75 logger
.info("Feature tree updated!");
77 } catch (Exception e
) {
79 logger
.error("ERROR in feature tree update");
89 public static void main(String
[] args
) {
90 PalmaeFeatureTreeUpdater updater
= new PalmaeFeatureTreeUpdater();
92 updater
.updateMissingFeatures(cdmDestination
);
93 } catch (Exception e
) {
95 logger
.error("ERROR in feature tree update");