Project

General

Profile

Download (6.28 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 eu.etaxonomy.cdm.print.out.IPublishOutputModule;
24
import eu.etaxonomy.cdm.print.out.mediawiki.MediawikiOutputModule;
25
import eu.etaxonomy.cdm.print.out.odf.OdfOutputModule;
26

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

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

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

    
97
		List<Element> classifications = configurator.getFactory().getClassifications();
98

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

    
102
			List<Element> elements = configurator.getFactory().getChildNodes(child);
103

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

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

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

    
137
	/**
138
	 * Test method for {@link eu.etaxonomy.cdm.print.Publisher#publish()}.
139
	 */
140
//	@Ignore
141
	@Ignore
142
	public void testPublishXml() {
143
		
144
		List<IPublishOutputModule> modules = new ArrayList();
145
		//modules.add(new XMLOutputModule());
146
		modules.add(new MediawikiOutputModule(""));
147
		configurator.setOutputModules(modules);
148
		
149
		//configurator.setOutputModules(Arrays.asList(new IPublishOutputModule[]{new XMLOutputModule()}));
150
		logger.warn("The number of selected taxon node elements is........ " + configurator.getSelectedTaxonNodeElements().size());
151
		
152
		Publisher.publish(configurator);
153
	}
154
	
155
	@Ignore
156
	public void textPublishOdf() {
157
		configurator.setOutputModules(Arrays.asList(new IPublishOutputModule[]{new OdfOutputModule()}));
158
		
159
		Publisher.publish(configurator);
160
	}
161
}
(2-2/3)