Project

General

Profile

Revision b3340748

IDb3340748c1db5b24b366318365d0b2fda4dab73a
Parent 4b1a00be
Child 11df83d8

Added by Andreas Müller 12 months ago

ref #6794 change FeatureTree to TermTree

View differences:

cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/descriptive/word/out/WordExport.java
21 21
import eu.etaxonomy.cdm.io.common.mapping.out.IExportTransformer;
22 22
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
23 23
import eu.etaxonomy.cdm.model.term.TermTreeNode;
24
import eu.etaxonomy.cdm.model.term.FeatureTree;
24
import eu.etaxonomy.cdm.model.term.TermTree;
25 25

  
26 26
/**
27 27
 *
......
44 44

  
45 45
        TransactionStatus txStatus = startTransaction(true);
46 46

  
47
        FeatureTree featureTree = state.getConfig().getFeatureTree();
47
        TermTree featureTree = state.getConfig().getFeatureTree();
48 48
        featureTree = getFeatureTreeService().load(featureTree.getUuid());
49 49
        TermTreeNode rootNode = featureTree.getRoot();
50 50

  
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/descriptive/word/out/WordExportConfigurator.java
15 15

  
16 16
import eu.etaxonomy.cdm.database.ICdmDataSource;
17 17
import eu.etaxonomy.cdm.io.common.XmlExportConfiguratorBase;
18
import eu.etaxonomy.cdm.model.term.FeatureTree;
18
import eu.etaxonomy.cdm.model.term.TermTree;
19 19

  
20 20

  
21 21
/**
......
31 31
    @SuppressWarnings("unused")
32 32
	private static final Logger logger = Logger.getLogger(WordExportConfigurator.class);
33 33

  
34
    private FeatureTree featureTree;
34
    private TermTree featureTree;
35 35

  
36 36

  
37
    private WordExportConfigurator(ICdmDataSource source, File destinationFolder, FeatureTree featureTree) {
37
    private WordExportConfigurator(ICdmDataSource source, File destinationFolder, TermTree featureTree) {
38 38
        super(destinationFolder, source, null);
39 39
        this.featureTree = featureTree;
40 40
    }
41 41

  
42
    public static WordExportConfigurator NewInstance(ICdmDataSource source, File destinationFolder, FeatureTree featureTree) {
42
    public static WordExportConfigurator NewInstance(ICdmDataSource source, File destinationFolder, TermTree featureTree) {
43 43
        return new WordExportConfigurator(source, destinationFolder, featureTree);
44 44
    }
45 45

  
......
55 55
        };
56 56
    }
57 57

  
58
    public FeatureTree getFeatureTree() {
58
    public TermTree getFeatureTree() {
59 59
        return featureTree;
60 60
    }
61 61

  
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/jaxb/CdmIDResolver.java
38 38
import eu.etaxonomy.cdm.model.reference.Reference;
39 39
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
40 40
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
41
import eu.etaxonomy.cdm.model.term.FeatureTree;
41
import eu.etaxonomy.cdm.model.term.TermTree;
42 42
import eu.etaxonomy.cdm.model.term.TermVocabulary;
43 43

  
44 44
public class CdmIDResolver extends IDResolver {
......
168 168
					  return resolveObject(uuid, targetType, vocabularyService);
169 169
				  } else if(DescriptionBase.class.isAssignableFrom(targetType)) {
170 170
					  return resolveObject(uuid, targetType, descriptionService);
171
				  } else if(FeatureTree.class.isAssignableFrom(targetType)) {
171
				  } else if(TermTree.class.isAssignableFrom(targetType)) {
172 172
					  return resolveObject(uuid, targetType, featureTreeService);
173 173
				  } else if(Media.class.isAssignableFrom(targetType)) {
174 174
					  return resolveObject(uuid, targetType, mediaService);
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/jaxb/DataSet.java
83 83
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
84 84
import eu.etaxonomy.cdm.model.term.DefinedTerm;
85 85
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
86
import eu.etaxonomy.cdm.model.term.FeatureTree;
86
import eu.etaxonomy.cdm.model.term.TermTree;
87 87
import eu.etaxonomy.cdm.model.term.OrderedTermVocabulary;
88 88
import eu.etaxonomy.cdm.model.term.TermVocabulary;
89 89

  
......
183 183

  
184 184
    @XmlElementWrapper(name = "FeatureTrees")
185 185
    @XmlElements({
186
      @XmlElement(name = "FeatureTree", namespace = "http://etaxonomy.eu/cdm/model/description/1.0", type = FeatureTree.class)
186
      @XmlElement(name = "FeatureTree", namespace = "http://etaxonomy.eu/cdm/model/description/1.0", type = TermTree.class)
187 187
    })
188
    protected List<FeatureTree> featureTrees = new ArrayList<>();
188
    protected List<TermTree> featureTrees = new ArrayList<>();
189 189

  
190 190
    @XmlElementWrapper(name = "PolytomousKeys")
191 191
    @XmlElements({
......
334 334
        this.references = value;
335 335
    }
336 336

  
337
    public List<FeatureTree> getFeatureTrees() {
337
    public List<TermTree> getFeatureTrees() {
338 338
        return featureTrees;
339 339
    }
340 340

  
......
356 356
        return taxonNodes;
357 357
    }
358 358

  
359
    public void setFeatureTrees(List<FeatureTree> value) {
359
    public void setFeatureTrees(List<TermTree> value) {
360 360
    	this.featureTrees = value;
361 361
    }
362 362

  
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/jaxb/JaxbExport.java
39 39
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
40 40
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
41 41
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
42
import eu.etaxonomy.cdm.model.term.FeatureTree;
42
import eu.etaxonomy.cdm.model.term.TermTree;
43 43

  
44 44
/**
45 45
 * @author a.babadshanjan
......
51 51
            implements ICdmExport<JaxbExportConfigurator, JaxbExportState> {
52 52

  
53 53
    private static final long serialVersionUID = -525533131708894145L;
54

  
55 54
    private static final Logger logger = Logger.getLogger(JaxbExport.class);
56 55

  
57 56
    private DataSet dataSet;
58 57

  
59
    /**
60
     *
61
     */
62 58
    public JaxbExport() {
63 59
        super();
64 60
    }
......
120 116
        }
121 117

  
122 118
        commitTransaction(txStatus);
123

  
124 119
        return;
125

  
126 120
    }
127 121

  
128 122
    public static void writeToFile(File file, DataSet dataSet) throws UnsupportedEncodingException, FileNotFoundException {
......
164 158
            logger.info("# User");
165 159
            List<User> users = getUserService().list(null, UserRows, 0, null, null);
166 160

  
167

  
168 161
            for (User user: users){
169 162
                dataSet.addUser(HibernateProxyHelper.deproxy(user));
170 163
            }
171

  
172 164
        }
173 165
        if (jaxbExpConfig.isDoTermVocabularies() == true) {
174 166
            if (termVocabularyRows == 0) { termVocabularyRows = MAX_ROWS; }
......
176 168
            dataSet.setTermVocabularies((List)getVocabularyService().list(null,termVocabularyRows, 0, null, null));
177 169
        }
178 170

  
179

  
180

  
181 171
        //		if (jaxbExpConfig.isDoLanguageData() == true) {
182 172
        //			if (languageDataRows == 0) { languageDataRows = MAX_ROWS; }
183 173
        //			logger.info("# Representation, Language String");
......
199 189
            dataSet.setAgents(getAgentService().list(null,agentRows, 0,null,null));
200 190
        }
201 191

  
202

  
203

  
204 192
        if (jaxbExpConfig.getDoReferences() != IExportConfigurator.DO_REFERENCES.NONE) {
205 193
            if (referenceBaseRows == 0) { referenceBaseRows = getReferenceService().count(Reference.class); }
206 194
            logger.info("# Reference: " + referenceBaseRows);
......
220 208
            dataSet.setTaxonomicNames(getNameService().list(null,taxonNameRows, 0,null,null));
221 209
        }
222 210

  
223

  
224

  
225 211
        if (jaxbExpConfig.isDoTaxa() == true) {
226 212
            if (taxonBaseRows == 0) { taxonBaseRows = getTaxonService().count(TaxonBase.class); }
227 213
            logger.info("# TaxonBase: " + taxonBaseRows);
......
265 251
            dataSet.addTypeDesignations(getNameService().getAllTypeDesignations(MAX_ROWS, 0));
266 252
        }
267 253

  
268

  
269

  
270 254
        if (jaxbExpConfig.isDoMedia() == true) {
271 255
            if (mediaRows == 0) { mediaRows = MAX_ROWS; }
272 256
            logger.info("# Media");
......
278 262
        if (jaxbExpConfig.isDoFeatureData() == true) {
279 263
            if (featureDataRows == 0) { featureDataRows = MAX_ROWS; }
280 264
            logger.info("# Feature Tree, Feature Node");
281
            List<FeatureTree> featureTrees = new ArrayList<FeatureTree>();
265
            List<TermTree> featureTrees = new ArrayList<>();
282 266
            featureTrees= getFeatureTreeService().list(null,featureDataRows, 0, null, null);
283
            List<FeatureTree> taxTreesdeproxy = new ArrayList<FeatureTree>();
284
            for (FeatureTree featureTree : featureTrees){
267
            List<TermTree> taxTreesdeproxy = new ArrayList<>();
268
            for (TermTree featureTree : featureTrees){
285 269
                HibernateProxyHelper.deproxy(featureTree);
286 270
                taxTreesdeproxy.add(featureTree);
287 271
            }
288

  
289 272
            dataSet.setFeatureTrees(getFeatureTreeService().list(null,null,null,null,null));
290 273
        }
291 274
        if (jaxbExpConfig.isDoClassificationData() == true) {
292 275
            if (classificationDataRows == 0) { classificationDataRows = MAX_ROWS; }
293 276
            logger.info("# Classification");
294 277

  
295

  
296 278
            List<Classification> taxTrees = new ArrayList<Classification>();
297 279
            taxTrees= getClassificationService().list(null,classificationDataRows, 0, null, null);
298 280

  
......
301 283
                HibernateProxyHelper.deproxy(taxTree);
302 284
                taxTreesdeproxy.add(taxTree);
303 285
            }
304
            List<TaxonNode> taxNodes = new ArrayList<TaxonNode>();
286
            List<TaxonNode> taxNodes = new ArrayList<>();
305 287
            taxNodes= getClassificationService().getAllNodes();
306
            List<TaxonNode> taxNodesdeproxy = new ArrayList<TaxonNode>();
288
            List<TaxonNode> taxNodesdeproxy = new ArrayList<>();
307 289
            for (TaxonNode taxNode : taxNodes){
308 290
                HibernateProxyHelper.deproxy(taxNode);
309 291
                taxNodesdeproxy.add(taxNode);
......
316 298
        dataSet.setLanguageStrings(null);
317 299
    }
318 300

  
319

  
320 301
    @Override
321 302
    protected boolean doCheck(JaxbExportState state) {
322 303
        boolean result = true;
......
324 305
        return result;
325 306
    }
326 307

  
327

  
328 308
    @Override
329 309
    protected boolean isIgnore(JaxbExportState state) {
330 310
        return false;
331 311
    }
332

  
333

  
334

  
335 312
}
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/jaxb/JaxbImport.java
38 38
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
39 39
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
40 40
import eu.etaxonomy.cdm.model.term.TermTreeNode;
41
import eu.etaxonomy.cdm.model.term.FeatureTree;
41
import eu.etaxonomy.cdm.model.term.TermTree;
42 42
import eu.etaxonomy.cdm.model.term.TermVocabulary;
43 43

  
44 44
/**
......
117 117
		List<DescriptionBase> descriptions;
118 118
		List<TypeDesignationBase<?>> typeDesignations;
119 119
		List<SpecimenOrObservationBase> occurrences;
120
		List<FeatureTree> featureTrees;
120
		List<TermTree> featureTrees;
121 121
		List<TermTreeNode> featureNodes;
122 122
		List<Media> media;
123 123
		List<LanguageStringBase> languageData;
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/sdd/in/SDDImport.java
83 83
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
84 84
import eu.etaxonomy.cdm.model.term.DefinedTerm;
85 85
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
86
import eu.etaxonomy.cdm.model.term.FeatureTree;
87 86
import eu.etaxonomy.cdm.model.term.Representation;
88 87
import eu.etaxonomy.cdm.model.term.TermBase;
88
import eu.etaxonomy.cdm.model.term.TermTree;
89 89
import eu.etaxonomy.cdm.model.term.TermTreeNode;
90 90
import eu.etaxonomy.cdm.model.term.TermType;
91 91
import eu.etaxonomy.cdm.model.term.TermVocabulary;
......
142 142

  
143 143
	private Set<StatisticalMeasure> statisticalMeasures = new HashSet<>();
144 144
	private Set<VersionableEntity> featureData = new HashSet<>();
145
	private Set<FeatureTree> featureTrees = new HashSet<>();
145
	private Set<TermTree> featureTrees = new HashSet<>();
146 146
	private Set<Classification> classifications = new HashSet<>();
147 147

  
148 148
	private final UUID uuidAnnotationTypeLocation = UUID.fromString("a3737e07-72e3-46d2-986d-fa4cf5de0b63");
......
675 675
			getReferenceService().save(source);
676 676
		}
677 677

  
678
		for (FeatureTree featureTree : featureTrees) {
678
		for (TermTree featureTree : featureTrees) {
679 679
			getFeatureTreeService().save(featureTree);
680 680
		}
681 681
		getDescriptiveDataSetService().save(descriptiveDataSet);
......
1751 1751
					String label = (String)ImportHelper.getXmlInputValue(elRepresentation,"Label",sddNamespace);
1752 1752
					//Element elDesignedFor = elCharacterTree.getChild("DesignedFor",sddNamespace);//TODO ?
1753 1753

  
1754
					FeatureTree featureTree =  FeatureTree.NewInstance();
1754
					TermTree featureTree =  TermTree.NewInstance();
1755 1755
					importRepresentation(elCharacterTree, sddNamespace, featureTree, "", cdmState);
1756 1756
					TermTreeNode<Feature> root = featureTree.getRoot();
1757 1757
					List<Element> listeOfNodes = elCharacterTree.getChildren("Nodes", sddNamespace);
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/sdd/out/SDDDataSet.java
80 80
import eu.etaxonomy.cdm.model.term.DefinedTerm;
81 81
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
82 82
import eu.etaxonomy.cdm.model.term.TermTreeNode;
83
import eu.etaxonomy.cdm.model.term.FeatureTree;
83
import eu.etaxonomy.cdm.model.term.TermTree;
84 84
import eu.etaxonomy.cdm.model.term.Representation;
85 85
import eu.etaxonomy.cdm.model.term.TermVocabulary;
86 86

  
......
134 134
    @XmlElementWrapper(name = "FeatureData")
135 135
        @XmlElements({
136 136
        @XmlElement(name = "FeatureNode", namespace = "http://etaxonomy.eu/cdm/model/description/1.0", type = TermTreeNode.class),
137
        @XmlElement(name = "FeatureTree", namespace = "http://etaxonomy.eu/cdm/model/description/1.0", type = FeatureTree.class)
137
        @XmlElement(name = "FeatureTree", namespace = "http://etaxonomy.eu/cdm/model/description/1.0", type = TermTree.class)
138 138
    })
139 139
//    protected List<VersionableEntity> featureData;
140 140
    protected List<VersionableEntity> featureData;
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/sdd/out/SDDDocumentBuilder.java
79 79
import eu.etaxonomy.cdm.model.term.DefinedTerm;
80 80
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
81 81
import eu.etaxonomy.cdm.model.term.TermTreeNode;
82
import eu.etaxonomy.cdm.model.term.FeatureTree;
82
import eu.etaxonomy.cdm.model.term.TermTree;
83 83
import eu.etaxonomy.cdm.model.term.Representation;
84 84
import eu.etaxonomy.cdm.model.term.TermBase;
85 85
import eu.etaxonomy.cdm.model.term.TermVocabulary;
......
1189 1189

  
1190 1190
			for (int i = 0; i < cdmSource.getFeatureData().size(); i++) {
1191 1191
				VersionableEntity featu = cdmSource.getFeatureData().get(i);
1192
				if (featu instanceof FeatureTree) {
1193
					FeatureTree ft = (FeatureTree) featu;
1192
				if (featu instanceof TermTree) {
1193
					TermTree ft = (TermTree) featu;
1194 1194
					ElementImpl elChartree = new ElementImpl(document,
1195 1195
							CHARACTER_TREE);
1196 1196
					chartreeCount = buildReference(featu, featuretrees, ID,
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/taxonx2013/TaxonXTreatmentExtractor.java
63 63
import eu.etaxonomy.cdm.model.taxon.Taxon;
64 64
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
65 65
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
66
import eu.etaxonomy.cdm.model.term.FeatureTree;
66
import eu.etaxonomy.cdm.model.term.TermTree;
67 67
import eu.etaxonomy.cdm.model.term.TermTreeNode;
68 68
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
69 69
import eu.etaxonomy.cdm.persistence.query.MatchMode;
......
94 94

  
95 95
    private  String treatmentMainName,originalTreatmentName;
96 96

  
97
    private final HashMap<String,Map<String,String>> namesMap = new HashMap<String, Map<String,String>>();
97
    private final HashMap<String,Map<String,String>> namesMap = new HashMap<>();
98 98

  
99 99

  
100 100
    private final Pattern keypattern = Pattern.compile("^(\\d+.*|-\\d+.*)");
......
142 142
    @SuppressWarnings({ "rawtypes", "unused" })
143 143

  
144 144
    protected void extractTreatment(Node treatmentnode, Reference refMods, URI sourceName) {        logger.info("extractTreatment");
145
        List<TaxonName> namesToSave = new ArrayList<TaxonName>();
145
        List<TaxonName> namesToSave = new ArrayList<>();
146 146
        NodeList children = treatmentnode.getChildNodes();
147 147
        Taxon acceptedTaxon =null;
148 148
        boolean hasRefgroup=false;
......
304 304
     */
305 305
    private void buildFeatureTree() {
306 306
        logger.info("buildFeatureTree");
307
        FeatureTree proibiospheretree = importer.getFeatureTreeService().find(proIbioTreeUUID);
307
        TermTree proibiospheretree = importer.getFeatureTreeService().find(proIbioTreeUUID);
308 308
        if (proibiospheretree == null){
309
            List<FeatureTree> trees = importer.getFeatureTreeService().list(FeatureTree.class, null, null, null, null);
309
            List<TermTree> trees = importer.getFeatureTreeService().list(TermTree.class, null, null, null, null);
310 310
            if (trees.size()==1) {
311
                FeatureTree<Feature> ft = trees.get(0);
311
                TermTree<Feature> ft = trees.get(0);
312 312
                if (featuresMap==null) {
313
                    featuresMap=new HashMap<String, Feature>();
313
                    featuresMap=new HashMap<>();
314 314
                }
315
                for (Feature feature: ft.getDistinctFeatures()){
315
                for (Feature feature: ft.getDistinctTerms()){
316 316
                    if(feature!=null) {
317 317
                        featuresMap.put(feature.getTitleCache(), feature);
318 318
                    }
319 319
                }
320 320
            }
321
            proibiospheretree = FeatureTree.NewInstance();
321
            proibiospheretree = TermTree.NewInstance();
322 322
            proibiospheretree.setUuid(proIbioTreeUUID);
323 323
        }
324 324

  
......
550 550
        logger.info("extractDistribution");
551 551
        //        logger.info("acceptedTaxon: "+acceptedTaxon);
552 552
        NodeList children = distribution.getChildNodes();
553
        Map<Integer,List<MySpecimenOrObservation>> specimenOrObservations = new HashMap<Integer, List<MySpecimenOrObservation>>();
554
        Map<Integer,String> descriptionsFulltext = new HashMap<Integer,String>();
553
        Map<Integer,List<MySpecimenOrObservation>> specimenOrObservations = new HashMap<>();
554
        Map<Integer,String> descriptionsFulltext = new HashMap<>();
555 555

  
556 556
        for (int i=0;i<children.getLength();i++){
557 557
            if (children.item(i).getNodeName().equalsIgnoreCase("tax:p")){
......
1099 1099
     * @param refMods: the current reference extracted from the MODS
1100 1100
     * @param featureName: the feature name
1101 1101
     */
1102
    @SuppressWarnings({ "unused", "rawtypes" })
1102
    @SuppressWarnings({ "unused"})
1103 1103
    private String extractSpecificFeatureNotStructured(Node description, Taxon acceptedTaxon, Taxon defaultTaxon,
1104 1104
            List<TaxonName> nameToSave, Reference refMods, String featureName ) {
1105 1105
        logger.info("extractSpecificFeatureNotStructured " + featureName);
......
2352 2352
        String fullName = "";
2353 2353
        String newName="";
2354 2354
        String identifier="";
2355
        HashMap<String, String> atomisedMap = new HashMap<String, String>();
2355
        HashMap<String, String> atomisedMap = new HashMap<>();
2356 2356
        List<String> atomisedName= new ArrayList<String>();
2357 2357

  
2358 2358
        String rankStr = "";
......
2498 2498
        String fullName = "";
2499 2499
        String newName = "";
2500 2500
        String identifier = "";
2501
        HashMap<String, String> atomisedMap = new HashMap<String, String>();
2502
        List<String> atomisedNameList= new ArrayList<String>();
2501
        HashMap<String, String> atomisedMap = new HashMap<>();
2502
        List<String> atomisedNameList= new ArrayList<>();
2503 2503

  
2504 2504
        String status= extractStatus(children);
2505 2505

  
......
3667 3667
                            classification.addChildTaxon((Taxon)tmpTaxonBase, refMods, null);
3668 3668
                        }
3669 3669
                    } else{
3670
                        hierarchy = new HashMap<Rank, Taxon>();
3670
                        hierarchy = new HashMap<>();
3671 3671
                        //System.out.println("LOOK FOR PARENT "+taxonname.toString()+", "+tmptaxonbase.toString());
3672 3672
                        if (!isSynonym){
3673 3673
                            lookForParentNode(taxonName,(Taxon)tmpTaxonBase, refMods,this);
......
4931 4931
        return costs[s2.length()];
4932 4932
    }
4933 4933

  
4934
    Map<Rank, Taxon> hierarchy = new HashMap<Rank, Taxon>();
4934
    Map<Rank, Taxon> hierarchy = new HashMap<>();
4935 4935
    /**
4936 4936
     * @param taxonName
4937 4937
     */
cdmlib-io/src/test/java/eu/etaxonomy/cdm/io/jaxb/FeatureTest.java
19 19

  
20 20
import eu.etaxonomy.cdm.model.description.Feature;
21 21
import eu.etaxonomy.cdm.model.term.TermTreeNode;
22
import eu.etaxonomy.cdm.model.term.FeatureTree;
22
import eu.etaxonomy.cdm.model.term.TermTree;
23 23

  
24 24
//@Ignore  //does not work anymore since FeatureNode + Tree was moved to term package
25 25
public class FeatureTest {
......
32 32
	        URI uri = new URI(URIEncoder.encode(this.getClass().getResource(resource).toString()));
33 33
	        DataSet dataSet = cdmDocumentBuilder.unmarshal(DataSet.class, new InputStreamReader(this.getClass().getResourceAsStream(resource)),uri.toString());
34 34

  
35
			FeatureTree<Feature> featureTree = dataSet.getFeatureTrees().get(0);
35
			TermTree<Feature> featureTree = dataSet.getFeatureTrees().get(0);
36 36
			Feature feature = (Feature)dataSet.getTerms().get(1);
37 37

  
38 38
			assertNotNull("FeatureTree must not be null", featureTree);
cdmlib-io/src/test/java/eu/etaxonomy/cdm/io/owl/out/OwlExportTest.java
31 31
import eu.etaxonomy.cdm.io.descriptive.owl.out.StructureTreeOwlExportConfigurator;
32 32
import eu.etaxonomy.cdm.model.common.CdmBase;
33 33
import eu.etaxonomy.cdm.model.description.Feature;
34
import eu.etaxonomy.cdm.model.term.FeatureTree;
34
import eu.etaxonomy.cdm.model.term.TermTree;
35 35
import eu.etaxonomy.cdm.model.term.TermTreeNode;
36 36
import eu.etaxonomy.cdm.model.term.TermType;
37 37
import eu.etaxonomy.cdm.model.term.TermVocabulary;
......
75 75
    }
76 76

  
77 77
    public List<UUID> createFeatureTree() {
78
        FeatureTree tree = FeatureTree.NewInstance();
79
        TermVocabulary voc = TermVocabulary.NewInstance(TermType.Feature, "voc description", "vocabulary", "voc", URI.create("http://test.voc"));
78
        TermTree<Feature> tree = TermTree.NewInstance();
79
        TermVocabulary<Feature> voc = TermVocabulary.NewInstance(TermType.Feature, "voc description", "vocabulary", "voc", URI.create("http://test.voc"));
80 80

  
81 81

  
82 82
        Feature featureA = Feature.NewInstance("A", "A", "A");
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/package-info.java
130 130
        @MetaValue(value = "Synonym", targetEntity = Synonym.class),
131 131
        @MetaValue(value = "Taxon", targetEntity = Taxon.class),
132 132

  
133
        @MetaValue(value = "FeatureTree", targetEntity = FeatureTree.class),
133
        @MetaValue(value = "TermTree", targetEntity = TermTree.class),
134 134
        @MetaValue(value = "PhylogeneticTree", targetEntity = PhylogeneticTree.class),
135 135
        @MetaValue(value = "MediaSpecimen", targetEntity = MediaSpecimen.class),
136 136
        @MetaValue(value = "TermVocabulary", targetEntity = TermVocabulary.class),
......
297 297
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
298 298
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
299 299
import eu.etaxonomy.cdm.model.term.DefinedTerm;
300
import eu.etaxonomy.cdm.model.term.FeatureTree;
301 300
import eu.etaxonomy.cdm.model.term.OrderedTerm;
302 301
import eu.etaxonomy.cdm.model.term.OrderedTermVocabulary;
303 302
import eu.etaxonomy.cdm.model.term.Representation;
303
import eu.etaxonomy.cdm.model.term.TermTree;
304 304
import eu.etaxonomy.cdm.model.term.TermVocabulary;
305 305

  
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/description/DescriptiveDataSet.java
41 41
import eu.etaxonomy.cdm.model.location.NamedArea;
42 42
import eu.etaxonomy.cdm.model.name.Rank;
43 43
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
44
import eu.etaxonomy.cdm.model.term.FeatureTree;
44
import eu.etaxonomy.cdm.model.term.TermTree;
45 45
import eu.etaxonomy.cdm.model.term.Representation;
46 46
import eu.etaxonomy.cdm.strategy.cache.description.DescriptiveDataSetDefaultCacheStrategy;
47 47

  
......
83 83
	@XmlSchemaType(name = "IDREF")
84 84
	@ManyToOne(fetch = FetchType.LAZY)
85 85
	@Cascade({CascadeType.SAVE_UPDATE,CascadeType.MERGE})
86
	private FeatureTree<Character> descriptiveSystem;
86
	private TermTree<Character> descriptiveSystem;
87 87

  
88 88
	@XmlElementWrapper(name = "Descriptions")
89 89
	@XmlElement(name = "Description")
......
307 307
		}
308 308
	}
309 309

  
310
	public FeatureTree<Character> getDescriptiveSystem() {
310
	public TermTree<Character> getDescriptiveSystem() {
311 311
		return descriptiveSystem;
312 312
	}
313
	public void setDescriptiveSystem(FeatureTree<Character> descriptiveSystem) {
313
	public void setDescriptiveSystem(TermTree<Character> descriptiveSystem) {
314 314
		this.descriptiveSystem = descriptiveSystem;
315 315
	}
316 316

  
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/description/DescriptiveSystemRole.java
14 14
import javax.xml.bind.annotation.XmlEnumValue;
15 15

  
16 16
import eu.etaxonomy.cdm.model.common.Language;
17
import eu.etaxonomy.cdm.model.term.FeatureTree;
17
import eu.etaxonomy.cdm.model.term.TermTree;
18 18

  
19 19
/**
20
 * The role of the descriptive system of type {@link FeatureTree}.<BR>
20
 * The role of the descriptive system of type {@link TermTree}.<BR>
21 21
 * A descriptive systeme may play different roles within a working set. 
22 22
 * The roles may be 
23 23
 * <li>
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/description/Feature.java
45 45
import eu.etaxonomy.cdm.model.taxon.Taxon;
46 46
import eu.etaxonomy.cdm.model.term.DefinedTerm;
47 47
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
48
import eu.etaxonomy.cdm.model.term.FeatureTree;
48
import eu.etaxonomy.cdm.model.term.TermTree;
49 49
import eu.etaxonomy.cdm.model.term.Representation;
50 50
import eu.etaxonomy.cdm.model.term.TermType;
51 51
import eu.etaxonomy.cdm.model.term.TermVocabulary;
......
67 67
 * ("generalization of") features. "Kind of" / "generalization of" relations
68 68
 * are bidirectional (a feature F1 is a "Kind of" a feature F2 if and only
69 69
 * if the feature F2 is a "generalization of" the feature F1. This hierarchical
70
 * structure has nothing in common with {@link FeatureTree feature trees} used for determination.
70
 * structure has nothing in common with {@link TermTree feature trees} used for determination.
71 71
 * <P>
72 72
 * A standard set of feature instances will be automatically
73 73
 * created as the project starts. But this class allows to extend this standard
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/term/FeatureTree.java
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9

  
10
package eu.etaxonomy.cdm.model.term;
11

  
12
import java.util.ArrayList;
13
import java.util.HashSet;
14
import java.util.List;
15
import java.util.Set;
16
import java.util.UUID;
17

  
18
import javax.persistence.Column;
19
import javax.persistence.Entity;
20
import javax.persistence.FetchType;
21
import javax.persistence.OneToMany;
22
import javax.persistence.OneToOne;
23
import javax.persistence.Transient;
24
import javax.validation.constraints.NotNull;
25
import javax.xml.bind.annotation.XmlAccessType;
26
import javax.xml.bind.annotation.XmlAccessorType;
27
import javax.xml.bind.annotation.XmlAttribute;
28
import javax.xml.bind.annotation.XmlElement;
29
import javax.xml.bind.annotation.XmlElementWrapper;
30
import javax.xml.bind.annotation.XmlRootElement;
31
import javax.xml.bind.annotation.XmlType;
32

  
33
import org.apache.log4j.Logger;
34
import org.hibernate.annotations.Cascade;
35
import org.hibernate.annotations.CascadeType;
36
import org.hibernate.annotations.Type;
37
import org.hibernate.envers.Audited;
38

  
39
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
40
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
41
import eu.etaxonomy.cdm.model.description.Feature;
42
import eu.etaxonomy.cdm.model.description.MediaKey;
43
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
44

  
45
/**
46
 * The class to arrange {@link Feature features} (characters) in a tree structure.
47
 * Feature trees are essential as interactive multiple-access keys for
48
 * determination process and for systematical output arrangement of
49
 * {@link DescriptionElementBase description elements} according to different goals
50
 * but may also be used to define flat feature subsets for filtering purposes.<BR>
51
 * A feature tree is build on {@link TermTreeNode feature nodes}.
52
 * <P>
53
 * This class corresponds partially to ConceptTreeDefType according to the SDD
54
 * schema.
55
 * <P>
56
 * Note: The tree structure of features used for purposes described above has
57
 * nothing in common with the possible hierarchical structure of features
58
 * depending on their grade of precision.
59
 *
60
 * @see		MediaKey
61
 *
62
 * @author  m.doering
63
 * @since 08-Nov-2007 13:06:16
64
 */
65
@XmlAccessorType(XmlAccessType.FIELD)
66
@XmlType(name = "FeatureTree", propOrder = {
67
    "root",
68
    "termType",
69
    "allowDuplicates",
70
    "representations"
71

  
72
})
73
@XmlRootElement(name = "FeatureTree")
74
@Entity
75
//@Indexed disabled to reduce clutter in indexes, since this type is not used by any search
76
//@Indexed(index = "eu.etaxonomy.cdm.model.term.FeatureTree")
77
@Audited
78
public class FeatureTree <T extends DefinedTermBase>
79
            extends IdentifiableEntity<IIdentifiableEntityCacheStrategy>
80
            implements IHasTermType, Cloneable{
81

  
82
	private static final long serialVersionUID = -6713834139003172735L;
83
	private static final Logger logger = Logger.getLogger(FeatureTree.class);
84

  
85
	@XmlElement(name = "Root")
86
	@OneToOne(fetch = FetchType.LAZY, targetEntity=TermTreeNode.class)
87
	@Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE})
88
	private TermTreeNode<T> root;
89

  
90
    /**
91
     * The {@link TermType type} of this term collection. All nodes in the graph must refer to a term of the same type.
92
     */
93
    @XmlAttribute(name ="TermType")
94
    @Column(name="termType")
95
    @NotNull
96
    @Type(type = "eu.etaxonomy.cdm.hibernate.EnumUserType",
97
        parameters = {@org.hibernate.annotations.Parameter(name  = "enumClass", value = "eu.etaxonomy.cdm.model.term.TermType")}
98
    )
99
    @Audited
100
    private TermType termType;
101

  
102
    // TODO needed? FeatureTree was a TermBase until v3.3 but was removed from
103
	//it as TermBase got the termType which does not apply to FeatureTree.
104
	//We need to check how far representations and uri is still required
105
	//or can be deleted. Current implementations seem all to use the title cache
106
	//instead of representation. This may not be correct.
107
	@XmlElementWrapper(name = "Representations")
108
    @XmlElement(name = "Representation")
109
    @OneToMany(fetch=FetchType.EAGER, orphanRemoval=true)
110
    @Cascade( { CascadeType.SAVE_UPDATE, CascadeType.MERGE, CascadeType.DELETE})
111
    // @IndexedEmbedded no need for embedding since we are using the DefinedTermBaseClassBridge
112
    private Set<Representation> representations = new HashSet<>();
113
    //make them private for now as we may delete representations in future
114
	//otherwise if we decide to use representations we can make the getters public
115
	private Set<Representation> getRepresentations() {return representations;}
116
    private void setRepresentations(Set<Representation> representations) {this.representations = representations;}
117

  
118
    //#7372 indicates if this tree/graph allows duplicated terms/features
119
    private boolean allowDuplicates = false;
120

  
121
//******************** FACTORY METHODS ******************************************/
122

  
123
    /**
124
     * Creates a new term collection instance for the given term type
125
     * with an empty {@link #getRoot() root node}.
126
     * @param termType the {@link TermType term type}, must not be null
127
     */
128
    public static <T extends DefinedTermBase<T>> FeatureTree<T> NewInstance(@NotNull TermType termType){
129
        return new FeatureTree<>(termType);
130
    }
131

  
132
    /**
133
	 * Creates a new feature tree instance with an empty {@link #getRoot() root node}.
134
	 *
135
	 * @see #NewInstance(UUID)
136
	 * @see #NewInstance(List)
137
	 */
138
	public static FeatureTree<Feature> NewInstance(){
139
		return new FeatureTree<>(TermType.Feature);
140
	}
141

  
142
	/**
143
	 * Creates a new feature tree instance with an empty {@link #getRoot() root node}
144
	 * and assigns to the new feature tree the given
145
	 * UUID (universally unique identifier).
146
	 *
147
	 * @param	uuid	the universally unique identifier
148
	 * @see 			#NewInstance()
149
	 * @see 			#NewInstance(List)
150
	 */
151
	public static <T extends DefinedTermBase<T>> FeatureTree<T> NewInstance(UUID uuid){
152
		FeatureTree<T> result =  new FeatureTree<>(TermType.Feature);
153
		result.setUuid(uuid);
154
		return result;
155
	}
156

  
157
	/**
158
	 * Creates a new feature tree instance with a {@link #getRoot() root node}
159
	 * the children of which are the feature nodes build on the base of the
160
	 * given list of {@link Feature features}. This corresponds to a flat feature tree.
161
	 * For each feature within the list a new {@link TermTreeNode feature node} without
162
	 * children nodes will be created.
163
	 *
164
	 * @param	featureList	the feature list
165
	 * @see 				#NewInstance()
166
	 * @see 				#NewInstance(UUID)
167
	 */
168
	public static FeatureTree<Feature> NewInstance(List<Feature> featureList){
169
		FeatureTree<Feature> result =  new FeatureTree<>(TermType.Feature);
170
		TermTreeNode<Feature> root = result.getRoot();
171

  
172
		for (Feature feature : featureList){
173
			root.addChild(feature);
174
		}
175

  
176
		return result;
177
	}
178

  
179

  
180
// ******************** CONSTRUCTOR *************************************/
181

  
182
    //for JAXB only, TODO needed?
183
    @Deprecated
184
    protected FeatureTree(){}
185

  
186
	/**
187
	 * Class constructor: creates a new feature tree instance with an empty
188
	 * {@link #getRoot() root node}.
189
	 */
190
	protected FeatureTree(TermType termType) {
191
        this.termType = termType;
192
        checkTermType(this);  //check not null
193
		root = new TermTreeNode<>(termType);
194
		root.setFeatureTree(this);
195
	}
196

  
197
// ****************** GETTER / SETTER **********************************/
198

  
199
	@Override
200
    public TermType getTermType() {
201
        return termType;
202
    }
203
    /**
204
	 * Returns the topmost {@link TermTreeNode feature node} (root node) of <i>this</i>
205
	 * feature tree. The root node does not have any parent. Since feature nodes
206
	 * recursively point to their child nodes the complete feature tree is
207
	 * defined by its root node.
208
	 */
209
	public TermTreeNode<T> getRoot() {
210
		return root;
211
	}
212

  
213
    /**
214
     * @deprecated this method is only for internal use when deleting a {@link FeatureTree}
215
     * from a database. It should never be called for other reasons.
216
     */
217
    @Deprecated
218
    public void removeRootNode() {
219
        this.root = null;
220
    }
221

  
222
	/**
223
	 * Returns the (ordered) list of {@link TermTreeNode feature nodes} which are immediate
224
	 * children of the root node of <i>this</i> feature tree.
225
	 */
226
	@Transient
227
	public List<TermTreeNode<T>> getRootChildren(){
228
		List<TermTreeNode<T>> result = new ArrayList<>();
229
		result.addAll(root.getChildNodes());
230
		return result;
231
	}
232

  
233
    public boolean isAllowDuplicates() {
234
        return allowDuplicates;
235
    }
236
    public void setAllowDuplicates(boolean allowDuplicates) {
237
        this.allowDuplicates = allowDuplicates;
238
    }
239

  
240
    /**
241
     * Throws {@link IllegalArgumentException} if the given
242
     * term has not the same term type as this term or if term type is null.
243
     * @param term
244
     */
245
    private void checkTermType(IHasTermType term) {
246
        IHasTermType.checkTermTypes(term, this);
247
    }
248

  
249
//******************** METHODS ***********************************************/
250

  
251
	/**
252
	 * Computes a set of distinct terms that are present in this feature tree
253
	 *
254
	 * @return
255
	 */
256
	@Transient
257
	public Set<T> getDistinctFeatures(){
258
	    Set<T> features = new HashSet<>();
259
	    return root.getDistinctFeaturesRecursive(features);
260
	}
261

  
262
//*********************** CLONE ********************************************************/
263

  
264
	/**
265
	 * Clones <i>this</i> {@link FeatureTree}. This is a shortcut that enables to create
266
	 * a new instance that differs only slightly from <i>this</i> tree by
267
	 * modifying only some of the attributes.
268
	 * {@link TermTreeNode tree nodes} always belong only to one tree, so all
269
	 * {@link TermTreeNode tree nodes} are cloned to build
270
	 * the new {@link FeatureTree}
271
	 *
272
	 *
273
	 * @see eu.etaxonomy.cdm.model.term.TermBase#clone()
274
	 * @see java.lang.Object#clone()
275
	 */
276
	@Override
277
	public Object clone() {
278
		FeatureTree<T> result;
279
		try {
280
			result = (FeatureTree<T>)super.clone();
281
		}catch (CloneNotSupportedException e) {
282
			logger.warn("Object does not implement cloneable");
283
			e.printStackTrace();
284
			return null;
285
		}
286
		TermTreeNode<T> rootClone = this.getRoot().cloneDescendants();
287
		result.root = rootClone;
288

  
289
		return result;
290

  
291
	}
292

  
293

  
294
}
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/term/TermTree.java
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9

  
10
package eu.etaxonomy.cdm.model.term;
11

  
12
import java.util.ArrayList;
13
import java.util.HashSet;
14
import java.util.List;
15
import java.util.Set;
16
import java.util.UUID;
17

  
18
import javax.persistence.Column;
19
import javax.persistence.Entity;
20
import javax.persistence.FetchType;
21
import javax.persistence.OneToMany;
22
import javax.persistence.OneToOne;
23
import javax.persistence.Transient;
24
import javax.validation.constraints.NotNull;
25
import javax.xml.bind.annotation.XmlAccessType;
26
import javax.xml.bind.annotation.XmlAccessorType;
27
import javax.xml.bind.annotation.XmlAttribute;
28
import javax.xml.bind.annotation.XmlElement;
29
import javax.xml.bind.annotation.XmlElementWrapper;
30
import javax.xml.bind.annotation.XmlRootElement;
31
import javax.xml.bind.annotation.XmlType;
32

  
33
import org.apache.log4j.Logger;
34
import org.hibernate.annotations.Cascade;
35
import org.hibernate.annotations.CascadeType;
36
import org.hibernate.annotations.Type;
37
import org.hibernate.envers.Audited;
38

  
39
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
40
import eu.etaxonomy.cdm.model.description.Feature;
41

  
42
/**
43
 * The class to arrange {@link Feature features} (characters) in a tree structure.
44
 * Feature trees are essential as interactive multiple-access keys for
45
 * determination process and for systematical output arrangement of
46
 * {@link DescriptionElementBase description elements} according to different goals
47
 * but may also be used to define flat feature subsets for filtering purposes.<BR>
48
 * A feature tree is build on {@link TermTreeNode feature nodes}.
49
 * <P>
50
 * This class corresponds partially to ConceptTreeDefType according to the SDD
51
 * schema.
52
 * <P>
53
 * Note: The tree structure of features used for purposes described above has
54
 * nothing in common with the possible hierarchical structure of features
55
 * depending on their grade of precision.
56
 *
57
 * @author  m.doering
58
 * @since 08-Nov-2007 13:06:16
59
 */
60
@XmlAccessorType(XmlAccessType.FIELD)
61
@XmlType(name = "TermTree", propOrder = {
62
    "root",
63
    "termType",
64
    "allowDuplicates",
65
    "representations"
66

  
67
})
68
@XmlRootElement(name = "TermTree")
69
@Entity
70
//@Indexed disabled to reduce clutter in indexes, since this type is not used by any search
71
//@Indexed(index = "eu.etaxonomy.cdm.model.term.TermTree")
72
@Audited
73
public class TermTree <T extends DefinedTermBase>
74
            extends TermGraphBase<T, TermTreeNode> {
75

  
76
	private static final long serialVersionUID = -6713834139003172735L;
77
	private static final Logger logger = Logger.getLogger(TermTree.class);
78

  
79

  
80
    // TODO representations needed? FeatureTree was a TermBase until v3.3 but was removed from
81
    //it as TermBase got the termType which does not apply to FeatureTree.
82
    //We need to check how far representations and uri is still required
83
    //or can be deleted. Current implementations seem all to use the title cache
84
    //instead of representation. This may not be correct.
85

  
86
	@XmlElement(name = "Root")
87
	@OneToOne(fetch = FetchType.LAZY, targetEntity=TermTreeNode.class)
88
	@Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE})
89
	private TermTreeNode<T> root;
90

  
91
    /**
92
     * The {@link TermType type} of this term collection. All nodes in the graph must refer to a term of the same type.
93
     */
94
    @XmlAttribute(name ="TermType")
95
    @Column(name="termType")
96
    @NotNull
97
    @Type(type = "eu.etaxonomy.cdm.hibernate.EnumUserType",
98
        parameters = {@org.hibernate.annotations.Parameter(name  = "enumClass", value = "eu.etaxonomy.cdm.model.term.TermType")}
99
    )
100
    @Audited
101
    private TermType termType;
102

  
103
    // TODO needed? FeatureTree was a TermBase until v3.3 but was removed from
104
	//it as TermBase got the termType which does not apply to FeatureTree.
105
	//We need to check how far representations and uri is still required
106
	//or can be deleted. Current implementations seem all to use the title cache
107
	//instead of representation. This may not be correct.
108
	@XmlElementWrapper(name = "Representations")
109
    @XmlElement(name = "Representation")
110
    @OneToMany(fetch=FetchType.EAGER, orphanRemoval=true)
111
    @Cascade( { CascadeType.SAVE_UPDATE, CascadeType.MERGE, CascadeType.DELETE})
112
    // @IndexedEmbedded no need for embedding since we are using the DefinedTermBaseClassBridge
113
    private Set<Representation> representations = new HashSet<>();
114
    //make them private for now as we may delete representations in future
115
	//otherwise if we decide to use representations we can make the getters public
116
	private Set<Representation> getRepresentations() {return representations;}
117
    private void setRepresentations(Set<Representation> representations) {this.representations = representations;}
118

  
119
    //#7372 indicates if this tree/graph allows duplicated terms/features
120
    private boolean allowDuplicates = false;
121

  
122
//******************** FACTORY METHODS ******************************************/
123

  
124
    /**
125
     * Creates a new term collection instance for the given term type
126
     * with an empty {@link #getRoot() root node}.
127
     * @param termType the {@link TermType term type}, must not be null
128
     */
129
    public static <T extends DefinedTermBase<T>> TermTree<T> NewInstance(@NotNull TermType termType){
130
        return new TermTree<>(termType);
131
    }
132

  
133
    /**
134
	 * Creates a new feature tree instance with an empty {@link #getRoot() root node}.
135
	 *
136
	 * @see #NewInstance(UUID)
137
	 * @see #NewInstance(List)
138
	 */
139
	public static TermTree<Feature> NewInstance(){
140
		return new TermTree<>(TermType.Feature);
141
	}
142

  
143
	/**
144
	 * Creates a new feature tree instance with an empty {@link #getRoot() root node}
145
	 * and assigns to the new feature tree the given
146
	 * UUID (universally unique identifier).
147
	 *
148
	 * @param	uuid	the universally unique identifier
149
	 * @see 			#NewInstance()
150
	 * @see 			#NewInstance(List)
151
	 */
152
	public static <T extends DefinedTermBase<T>> TermTree<T> NewInstance(UUID uuid){
153
		TermTree<T> result =  new TermTree<>(TermType.Feature);
154
		result.setUuid(uuid);
155
		return result;
156
	}
157

  
158
	/**
159
	 * Creates a new feature tree instance with a {@link #getRoot() root node}
160
	 * the children of which are the feature nodes build on the base of the
161
	 * given list of {@link Feature features}. This corresponds to a flat feature tree.
162
	 * For each feature within the list a new {@link TermTreeNode feature node} without
163
	 * children nodes will be created.
164
	 *
165
	 * @param	featureList	the feature list
166
	 * @see 				#NewInstance()
167
	 * @see 				#NewInstance(UUID)
168
	 */
169
	public static TermTree<Feature> NewInstance(List<Feature> featureList){
170
		TermTree<Feature> result =  new TermTree<>(TermType.Feature);
171
		TermTreeNode<Feature> root = result.getRoot();
172

  
173
		for (Feature feature : featureList){
174
			root.addChild(feature);
175
		}
176

  
177
		return result;
178
	}
179

  
180

  
181
// ******************** CONSTRUCTOR *************************************/
182

  
183
    //for JAXB only, TODO needed?
184
    @Deprecated
185
    protected TermTree(){}
186

  
187
	/**
188
	 * Class constructor: creates a new feature tree instance with an empty
189
	 * {@link #getRoot() root node}.
190
	 */
191
	protected TermTree(TermType termType) {
192
        this.termType = termType;
193
        checkTermType(this);  //check not null
194
		root = new TermTreeNode<>(termType);
195
		root.setFeatureTree(this);
196
	}
197

  
198
// ****************** GETTER / SETTER **********************************/
199

  
200
	@Override
201
    public TermType getTermType() {
202
        return termType;
203
    }
204
    /**
205
	 * Returns the topmost {@link TermTreeNode feature node} (root node) of <i>this</i>
206
	 * feature tree. The root node does not have any parent. Since feature nodes
207
	 * recursively point to their child nodes the complete feature tree is
208
	 * defined by its root node.
209
	 */
210
	public TermTreeNode<T> getRoot() {
211
		return root;
212
	}
213

  
214
    /**
215
     * @deprecated this method is only for internal use when deleting a {@link TermTree}
216
     * from a database. It should never be called for other reasons.
217
     */
218
    @Deprecated
219
    public void removeRootNode() {
220
        this.root = null;
221
    }
222

  
223
	/**
224
	 * Returns the (ordered) list of {@link TermTreeNode feature nodes} which are immediate
225
	 * children of the root node of <i>this</i> feature tree.
226
	 */
227
	@Transient
228
	public List<TermTreeNode<T>> getRootChildren(){
229
		List<TermTreeNode<T>> result = new ArrayList<>();
230
		result.addAll(root.getChildNodes());
231
		return result;
232
	}
233

  
234

  
235

  
236
//******************** METHODS ***********************************************/
237

  
238
	/**
239
	 * Computes a set of distinct terms that are present in this term tree
240
	 *
241
	 * @return
242
	 */
243
    @Override
244
    @Transient
245
	public Set<T> getDistinctTerms(){
246
	    Set<T> features = new HashSet<>();
247
	    return root.getDistinctTermsRecursive(features);
248
	}
249

  
250
    public List<T> asTermList() {
251
        List<T> result = new ArrayList<>();
252
        for (TermTreeNode<T> node : getRootChildren()){
253
            result.add(node.getTerm());
254
            result.addAll(node.asTermListRecursive(result));
255
        }
256
        return result;
257
    }
258

  
259
//*********************** CLONE ********************************************************/
260

  
261
	/**
262
	 * Clones <i>this</i> {@link TermTree}. This is a shortcut that enables to create
263
	 * a new instance that differs only slightly from <i>this</i> tree by
264
	 * modifying only some of the attributes.
265
	 * {@link TermTreeNode tree nodes} always belong only to one tree, so all
266
	 * {@link TermTreeNode tree nodes} are cloned to build
267
	 * the new {@link TermTree}
268
	 *
269
	 *
270
	 * @see eu.etaxonomy.cdm.model.term.TermBase#clone()
271
	 * @see java.lang.Object#clone()
272
	 */
273
	@Override
274
	public Object clone() {
275
		TermTree<T> result;
276
		try {
277
			result = (TermTree<T>)super.clone();
278
		}catch (CloneNotSupportedException e) {
279
			logger.warn("Object does not implement cloneable");
280
			e.printStackTrace();
281
			return null;
282
		}
283
		TermTreeNode<T> rootClone = this.getRoot().cloneDescendants();
284
		result.root = rootClone;
285

  
286
		return result;
287

  
288
	}
289

  
290

  
291
}
cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/generate/PolytomousKeyGenerator.java
22 22
import eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue;
23 23
import eu.etaxonomy.cdm.model.description.TaxonDescription;
24 24
import eu.etaxonomy.cdm.model.term.TermTreeNode;
25
import eu.etaxonomy.cdm.model.term.FeatureTree;
25
import eu.etaxonomy.cdm.model.term.TermTree;
26 26

  
27 27
/**
28 28
 * @author m.venin
......
37 37

  
38 38
	private boolean merge=true; // if this boolean is set to true, branches of the tree will be merged if the corresponding states can be used together without decreasing their score
39 39

  
40
	private FeatureTree dependenciesTree; // the tree containing the dependencies between states and features (InapplicableIf and OnlyApplicableIf)
40
	private TermTree dependenciesTree; // the tree containing the dependencies between states and features (InapplicableIf and OnlyApplicableIf)
41 41
	private Map<State,Set<Feature>> iIdependencies = new HashMap<>(); // map of a set of Features (value) inapplicables if a State (key) is present
42 42
	private Map<State,Set<Feature>> oAIdependencies = new HashMap<>(); // map of a set of Features (value) only applicables if a State (key) is present
43 43
	private Map<Feature,Set<Feature>> featureDependencies = new HashMap<>(); // map of all the sets of features (values) which have dependencies with states of other features (keys)
......
74 74
	 *
75 75
	 * @param tree
76 76
	 */
77
	public void setDependencies(FeatureTree tree){
77
	public void setDependencies(TermTree tree){
78 78
		this.dependenciesTree = tree;
79 79
	}
80 80

  
cdmlib-model/src/test/java/eu/etaxonomy/cdm/model/term/FeatureTreeTest.java
18 18
	@SuppressWarnings("unused")
19 19
	private static final Logger logger = Logger.getLogger(FeatureTreeTest.class);
20 20

  
21
	private FeatureTree testTree;
22
	private TermTreeNode node1;
23
	private TermTreeNode node2;
24
	private TermTreeNode node3;
25
	private TermTreeNode node4;
21
	private TermTree<Feature> testTree;
22
	private TermTreeNode<Feature> node1;
23
	private TermTreeNode<Feature> node2;
24
	private TermTreeNode<Feature> node3;
25
	private TermTreeNode<Feature> node4;
26 26

  
27 27
	@BeforeClass
28 28
	public static void setUpBeforeClass() {
......
35 35
	 */
36 36
	@Before
37 37
	public void setUp() throws Exception {
38
		testTree = FeatureTree.NewInstance();
38
		testTree = TermTree.NewInstance();
39 39

  
40 40
		node1 = testTree.getRoot().addChild(Feature.ANATOMY());
41 41
		node2 = node1.addChild(Feature.BIOLOGY_ECOLOGY());
......
64 64
	public void testClone(){
65 65

  
66 66
        TermTreeNode<Feature> node21 = node1.addChild(Feature.ADDITIONAL_PUBLICATION(), 1);
67
		FeatureTree clone = (FeatureTree) testTree.clone();
67
		TermTree<Feature> clone = (TermTree<Feature>) testTree.clone();
68

  
68 69
		assertEquals (clone.getRoot().getTerm(), testTree.getRoot().getTerm());
69 70
		assertNotSame(clone.getRoot(), testTree.getRoot());
70
		List<TermTreeNode> children = clone.getRootChildren();
71
		List<TermTreeNode<Feature>> children = clone.getRootChildren();
71 72

  
72 73

  
73 74
		assertEquals(children.get(0).getTerm(), node1.getTerm());
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/data/FullCoverageDataGenerator.java
128 128
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
129 129
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
130 130
import eu.etaxonomy.cdm.model.term.DefinedTerm;
131
import eu.etaxonomy.cdm.model.term.FeatureTree;
132 131
import eu.etaxonomy.cdm.model.term.Representation;
132
import eu.etaxonomy.cdm.model.term.TermTree;
133 133
import eu.etaxonomy.cdm.model.term.TermTreeNode;
134 134
import eu.etaxonomy.cdm.model.term.TermType;
135 135
import eu.etaxonomy.cdm.model.term.TermVocabulary;
......
412 412

  
413 413

  
414 414
		//Feature Tree
415
		FeatureTree<Feature> featureTree = FeatureTree.NewInstance();
415
		TermTree<Feature> featureTree = TermTree.NewInstance();
416 416
//		featureTree
417 417
        TermTreeNode<Feature> descriptionFeatureNode = featureTree.getRoot().addChild(Feature.DESCRIPTION());
418 418
        TermTreeNode<Feature> leaveLengthNode = descriptionFeatureNode.addChild(leaveLength);
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/update/v36_40/ReferencedObjTypeUpdater.java
114 114
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
115 115
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
116 116
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
117
import eu.etaxonomy.cdm.model.term.FeatureTree;
117
import eu.etaxonomy.cdm.model.term.TermTree;
118 118
import eu.etaxonomy.cdm.model.term.OrderedTerm;
119 119
import eu.etaxonomy.cdm.model.term.OrderedTermBase;
120 120
import eu.etaxonomy.cdm.model.term.OrderedTermVocabulary;
......
159 159
			    DescriptionElementSource.class,
160 160
			    Distribution.class,
161 161
			    Feature.class,
162
			    FeatureTree.class,
162
			    TermTree.class,
163 163
			    IndividualsAssociation.class,
164 164
			    MeasurementUnit.class,
165 165
			    MediaKey.class,
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/description/IFeatureTreeDao.java
13 13
import java.util.UUID;
14 14

  
15 15
import eu.etaxonomy.cdm.model.term.TermTreeNode;
16
import eu.etaxonomy.cdm.model.term.FeatureTree;
16
import eu.etaxonomy.cdm.model.term.TermTree;
17 17
import eu.etaxonomy.cdm.model.term.TermType;
18 18
import eu.etaxonomy.cdm.persistence.dao.common.IIdentifiableDao;
19 19
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
......
23 23
 * @since 10.07.2008
24 24
 * @version 1.0
25 25
 */
26
public interface IFeatureTreeDao extends IIdentifiableDao<FeatureTree> {
27
    public List<FeatureTree> list();
26
public interface IFeatureTreeDao extends IIdentifiableDao<TermTree> {
27
    public List<TermTree> list();
28 28

  
29 29
    public UUID DefaultFeatureTreeUuid = UUID.fromString("ac8d4e58-926d-4f81-ac77-cebdd295df7c");
30 30

  
......
35 35
     */
36 36
    public void deepLoadNodes(List<TermTreeNode> nodes, List<String> nodePaths);
37 37

  
38
    public <S extends FeatureTree> List<UuidAndTitleCache<S>> getUuidAndTitleCacheByTermType(Class<S> clazz, TermType termType, Integer limit,
38
    public <S extends TermTree> List<UuidAndTitleCache<S>> getUuidAndTitleCacheByTermType(Class<S> clazz, TermType termType, Integer limit,
39 39
            String pattern);
40 40
}
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/description/FeatureTreeDaoImpl.java
22 22

  
23 23
import eu.etaxonomy.cdm.model.description.Feature;
24 24
import eu.etaxonomy.cdm.model.term.TermTreeNode;
25
import eu.etaxonomy.cdm.model.term.FeatureTree;
25
import eu.etaxonomy.cdm.model.term.TermTree;
26 26
import eu.etaxonomy.cdm.model.term.TermType;
27 27
import eu.etaxonomy.cdm.model.term.TermVocabulary;
28 28
import eu.etaxonomy.cdm.model.term.VocabularyEnum;
......
37 37
 * @version 1.0
38 38
 */
39 39
@Repository
40
public class FeatureTreeDaoImpl extends IdentifiableDaoBase<FeatureTree> implements IFeatureTreeDao{
40
public class FeatureTreeDaoImpl extends IdentifiableDaoBase<TermTree> implements IFeatureTreeDao{
41 41
    @SuppressWarnings("unused")
42 42
    private static final Logger logger = Logger.getLogger(FeatureTreeDaoImpl.class);
43 43

  
......
45 45
    private ITermVocabularyDao termVocabularyDao;
46 46

  
47 47
    public FeatureTreeDaoImpl() {
48
        super(FeatureTree.class);
48
        super(TermTree.class);
49 49
        indexedClasses = new Class[1];
50
        indexedClasses[0] = FeatureTree.class;
50
        indexedClasses[0] = TermTree.class;
51 51
//		indexedClasses[1] = PolytomousKey.class;
52 52
    }
53 53

  
54 54
    @Override
55
    public List<FeatureTree> list() {
55
    public List<TermTree> list() {
56 56
        Criteria crit = getSession().createCriteria(type);
57 57
        return crit.list();
58 58
    }
......
74 74
    }
75 75

  
76 76
    @Override
77
    public FeatureTree load(UUID uuid, List<String> propertyPaths) {
77
    public TermTree load(UUID uuid, List<String> propertyPaths) {
78 78
        if (uuid.equals(DefaultFeatureTreeUuid) || count() == 0){
79 79
            return createDefaultFeatureTree();
80 80
        }
......
82 82
    }
83 83

  
84 84
    @Override
85
    public FeatureTree load(UUID uuid) {
85
    public TermTree load(UUID uuid) {
86 86
        if (uuid.equals(DefaultFeatureTreeUuid) || count() == 0){
87 87
            return createDefaultFeatureTree();
88 88
        }
......
92 92
    /**
93 93
     *
94 94
     */
95
    private FeatureTree createDefaultFeatureTree() {
95
    private TermTree createDefaultFeatureTree() {
96 96

  
97 97
        TermVocabulary featureVocabulary = termVocabularyDao.findByUuid(VocabularyEnum.Feature.getUuid());
98 98

  
......
103 103
                selectedFeatures.add(feature);
104 104
            }
105 105
        }
106
        FeatureTree featureTree = FeatureTree.NewInstance(selectedFeatures);
106
        TermTree featureTree = TermTree.NewInstance(selectedFeatures);
107 107
        featureTree.setUuid(DefaultFeatureTreeUuid);
108 108
        return featureTree;
109 109
    }
110 110

  
111 111
    @Override
112
    public <S extends FeatureTree> List<UuidAndTitleCache<S>> getUuidAndTitleCacheByTermType(Class<S> clazz, TermType termType, Integer limit,
112
    public <S extends TermTree> List<UuidAndTitleCache<S>> getUuidAndTitleCacheByTermType(Class<S> clazz, TermType termType, Integer limit,
113 113
            String pattern) {
114 114
        Session session = getSession();
115 115
        Query query = session.createQuery(
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/hibernate/PostMergeEntityListener.java
23 23
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
24 24
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
25 25
import eu.etaxonomy.cdm.model.term.TermTreeNode;
26
import eu.etaxonomy.cdm.model.term.FeatureTree;
26
import eu.etaxonomy.cdm.model.term.TermTree;
27 27

  
28 28
/**
29 29
 * @author cmathew
......
100 100

  
101 101
                }
102 102

  
103
            }   else if(FeatureTree.class.isAssignableFrom(entityClazz)){
103
            }   else if(TermTree.class.isAssignableFrom(entityClazz)){
104 104

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)