Project

General

Profile

Download (5.68 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy 
5
* http://www.e-taxonomy.eu
6
* 
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.
9
*/
10

    
11
package eu.etaxonomy.cdm.print;
12

    
13
import java.io.File;
14
import java.util.ArrayList;
15
import java.util.Arrays;
16
import java.util.List;
17
import java.util.UUID;
18

    
19
import org.apache.log4j.Logger;
20
import org.jdom.Element;
21
import org.junit.BeforeClass;
22
import org.junit.Ignore;
23
import org.junit.Test;
24

    
25
import eu.etaxonomy.cdm.print.out.IPublishOutputModule;
26
import eu.etaxonomy.cdm.print.out.odf.OdfOutputModule;
27
import eu.etaxonomy.cdm.print.out.xml.XMLOutputModule;
28

    
29
/**
30
 * @author n.hoffmann
31
 * @created Apr 9, 2010
32
 * @version 1.0
33
 */
34
//@Ignore // Implement this test in a more generic way
35
public class PublisherTest {
36
	private static final Logger logger = Logger.getLogger(PublisherTest.class);
37

    
38
	private static PublishConfigurator configurator; 
39
	
40
	private static Publisher publisher;
41
	
42
	private static IXMLEntityFactory factory;
43
	
44
	
45
	/**
46
	 * @throws java.lang.Exception
47
	 */
48
	@BeforeClass
49
	public static void setUpBeforeClass() throws Exception {
50
		
51
		configurator = PublishConfigurator.NewRemoteInstance();
52
		
53
		configurator.setWebserviceUrl("http://localhost:8080/");
54
		/////configurator.setWebserviceUrl("http://dev.e-taxonomy.eu/cdmserver/flora_central_africa/");//central africa production
55
		//configurator.setWebserviceUrl("http://dev.e-taxonomy.eu/cdmserver/caryophyllales/");					
56
		//http://160.45.63.201/cdmserver/flora_central_africa
57
		//http://dev.e-taxonomy.eu/cdmserver/flora_central_africa/
58

    
59
		factory = configurator.getFactory();
60
		
61
		//setClassification();
62
		setTaxonNode();
63
		
64
		//TODO: How do we get the uuid for the feature tree from the classification or taxonNode without hardcoding it?
65
		//configurator.setFeatureTree(UUID.fromString("ac8d4e58-926d-4f81-ac77-cebdd295df7c"));//caryophyllales		
66
		configurator.setFeatureTree(UUID.fromString("051d35ee-22f1-42d8-be07-9e9bfec5bcf7"));//Ericaceae
67
		
68
//		Element selectedTaxonNodeElement = new Element("TaxonNode");
69
//		configurator.addSelectedTaxonNodeElements(selectedTaxonNodeElement);		
70
//		configurator.setExportFolder(new File("/home/sybille/tmp/"));
71
		configurator.setExportFolder(new File("/Users/l.morris/Documents")); //TODO: use a relative path
72
	}
73
	
74
	private static void setTaxonNode() {
75
		
76
		//http://dev.e-taxonomy.eu/cdmserver/flora_central_africa/taxonNode/a605e87e-113e-4ebd-ad97-f086b734b4da
77
		//a95f7122-87c9-478b-a1e6-d9199d855356 agarista
78
		//taxonNodeUuid a605e87e-113e-4ebd-ad97-f086b734b4da FeatureTree UUID 051d35ee-22f1-42d8-be07-9e9bfec5bcf7
79
		//UUID taxonNodeUuid = UUID.fromString("be6566eb-4661-41fe-8ec2-caf885a12cbd");//5168a18b-c0b1-44cc-80aa-7a5572fefe04
80
		//UUID taxonNodeUuid = UUID.fromString("a605e87e-113e-4ebd-ad97-f086b734b4da");//Ericaceae
81
		UUID taxonNodeUuid = UUID.fromString("0044aae4-721b-4726-85ff-752a89cff748");
82
		//restionaceae 0044aae4-721b-4726-85ff-752a89cff748
83
		//UUID taxonNodeUuid = UUID.fromString("9440bd28-b462-4112-8906-a643b7d3f195");//caryophyllales
84
		Element taxonNodeElement = factory.getTaxonNode(taxonNodeUuid);
85
		configurator.addSelectedTaxonNodeElements(taxonNodeElement);		
86
		
87
	}
88
	
89
	/*
90
	 * Adds all TaxonNodes from a classification to the PublishConfigurator. Only tested with the smaller database Caryophyllales. 
91
	 * To run the Publisher on a single TaxonNode e.g. family or genus, call setTaxonNode instead.
92
	 */
93
	private static void setClassification() {
94

    
95
		List<Element> classifications = configurator.getFactory().getClassifications();
96

    
97
		for(Element child : classifications){
98
			List<Element> children = child.getChildren();
99

    
100
			List<Element> elements = configurator.getFactory().getChildNodes(child);
101

    
102
			//for(Element child2 : children){
103
			//logger.warn("The element name is " + child2.getName() + " and value is " + child2.getValue());
104
			// 1. get the value where the child2.getName is uuid
105
			//}
106
			// 2. http://dev.e-taxonomy.eu/cdmserver/caryophyllales/portal/classification/9edc58b5-de3b-43aa-9f31-1ede7c009c2b/childNodes
107
			// 3. get the taxonNode uuid from the classification
108
			int count = 0;
109
			
110
			for(Element child2 : elements){
111
				logger.warn("2 The element name is " + child2.getName() + " and value is " + child2.getValue());
112
				// 1. get the value where the child2.getName is uuid
113

    
114
				logger.warn("3 The uuid is " + child2.getChildText("uuid")); 
115
				logger.warn("4 The uuid is " + child2.getChild("uuid")); 
116
				logger.warn("5 The count is " + count); 
117
				
118
				//filter out Fabales in FoCE - as it's huge and seems to cause the harvetsing to crash.
119
				if (child2.getChildText("uuid") == "94bb5507-201d-4e34-9aa7-dce58fcd6a25") {
120
					break;
121
				}
122
				//temporarily filter c15e12c1-6118-4929-aed0-b0cc90f5ab22 as it's causing a lazyInitializationException in caryophyllales
123
				if (child2.getChildText("uuid") == "c15e12c1-6118-4929-aed0-b0cc90f5ab22") {
124
					break;
125
				}
126

    
127
				UUID taxonNodeUuid = UUID.fromString(child2.getChildText("uuid"));
128
				Element taxonNodeElement = factory.getTaxonNode(taxonNodeUuid);
129
				configurator.addSelectedTaxonNodeElements(taxonNodeElement);
130
				count++;
131
			}
132
		}
133
	}
134

    
135
	/**
136
	 * Test method for {@link eu.etaxonomy.cdm.print.Publisher#publish()}.
137
	 */
138
	@Ignore
139
	public void testPublishXml() {
140
		configurator.setOutputModules(Arrays.asList(new IPublishOutputModule[]{new XMLOutputModule()}));
141
		logger.warn("The number of selected taxon node elements is........ " + configurator.getSelectedTaxonNodeElements().size());
142
		
143
		Publisher.publish(configurator);
144
	}
145
	
146
	@Ignore
147
	public void textPublishOdf() {
148
		configurator.setOutputModules(Arrays.asList(new IPublishOutputModule[]{new OdfOutputModule()}));
149
		
150
		Publisher.publish(configurator);
151
	}
152
}
(2-2/3)