Project

General

Profile

Download (6.32 KB) Statistics
| Branch: | Tag: | Revision:
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.print;
11

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

    
18
import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;
19
import org.jdom.Element;
20
import org.junit.BeforeClass;
21
import org.junit.Ignore;
22
import eu.etaxonomy.cdm.print.out.IPublishOutputModule;
23
import eu.etaxonomy.cdm.print.out.mediawiki.MediawikiOutputModule;
24
import eu.etaxonomy.cdm.print.out.odf.OdfOutputModule;
25

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

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

    
57
		factory = configurator.getFactory();
58
		
59
		//setClassification();
60
		setTaxonNode();
61
		
62
		//TODO: How do we get the uuid for the feature tree from the classification or taxonNode without hardcoding it?
63
		//configurator.setFeatureTree(UUID.fromString("ac8d4e58-926d-4f81-ac77-cebdd295df7c"));//caryophyllales		
64
		//configurator.setFeatureTree(UUID.fromString("051d35ee-22f1-42d8-be07-9e9bfec5bcf7"));//Ericaceae
65
		configurator.setFeatureTree(UUID.fromString("051d35ee-22f1-42d8-be07-9e9bfec5bcf7"));
66
		//configurator.setFeatureTree(UUID.fromString("ae9615b8-bc60-4ed0-ad96-897f9226d568"));//ae9615b8-bc60-4ed0-ad96-897f9226d568 cichorieae
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");//restionaceae
82
		//UUID taxonNodeUuid = UUID.fromString("6a7ac1ad-2fd9-4218-8132-12dd463d04b9");// cf74ab02-2385-4818-9d56-902fa3e6fe6b 4f6c68d0-63f2-4235-83c2-5bff14532f90 cichorieae.
83
		//restionaceae 0044aae4-721b-4726-85ff-752a89cff748
84
		//UUID taxonNodeUuid = UUID.fromString("9440bd28-b462-4112-8906-a643b7d3f195");//caryophyllales
85
		Element taxonNodeElement = factory.getTaxonNode(taxonNodeUuid);
86
		configurator.addSelectedTaxonNodeElements(taxonNodeElement);		
87
		
88
	}
89
	
90
	/*
91
	 * Adds all TaxonNodes from a classification to the PublishConfigurator. Only tested with the smaller database Caryophyllales. 
92
	 * To run the Publisher on a single TaxonNode e.g. family or genus, call setTaxonNode instead.
93
	 */
94
	private static void setClassification() {
95

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

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

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

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

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

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

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