Project

General

Profile

1
package eu.dnetlib.data.collector.plugins.excel;
2

    
3
import java.util.HashMap;
4
import java.util.Iterator;
5

    
6
import eu.dnetlib.data.collector.plugins.HttpCSVCollectorPlugin;
7
import eu.dnetlib.data.collector.rmi.InterfaceDescriptor;
8
import org.junit.Assert;
9
import org.junit.Before;
10
import org.junit.Ignore;
11
import org.junit.Test;
12
/**
13
 * Created by miriam on 10/05/2017.
14
 */
15
@Ignore
16
public class ReadExcelTest {
17
	private InterfaceDescriptor descr;
18
	private Read r;
19

    
20
	private String excelPath = "eu/dnetlib/data/collector/plugins/excel/fwf_projects_100.xlsx";
21

    
22
	@Before
23
	public void setUp() throws Exception {
24
		descr = new InterfaceDescriptor();
25
		descr.setBaseUrl("https://pf.fwf.ac.at/en/research-in-practice/project-finder.xlsx?&&&search%5Bcall%5D=&search%5Bdecision_board_ids%5D=&search%5Bend_date%5D=&search%5Binstitute_name%5D=&search%5Blead_firstname%5D=&search%5Blead_lastname%5D=&search%5Bper_page%5D=10&search%5Bproject_number%5D=&search%5Bproject_title%5D=&search%5Bscience_discipline_id%5D=&search%5Bstart_date%5D=&search%5Bstatus_id%5D=&search%5Bwhat%5D=&action=index&controller=projects&locale=en&per_page=10" );
26
		HashMap<String, String> params = new HashMap<String, String>();
27

    
28
		params.put("argument", "{\"replace\":{\"header\":[{\"from\":\"&\",\"to\":\"and\"}],\"body\":[{\"from\":\"\\n\",\"to\":\" \"}]}}");
29

    
30
		params.put("header_row","4");
31
		params.put("tmp_file","//tmp//fwf.xslx");
32
		params.put("remove_empty_lines","yes");
33
		params.put("remove_lines_with_id"," – ");
34
		params.put("col_id","1");
35
		params.put("remove_tmp_file","no");
36
		params.put("sheet_number","0");
37
		params.put("file_to_save","/tmp/project_search.2017.05.10.csv");
38
		params.put("separator", ",");
39
		params.put("quote","\"");
40
		descr.setParams(params);
41
//		descr.setBaseUrl("file:///tmp/gsrt_whole.xlsx");
42
//		HashMap<String, String> params = new HashMap<String, String>();
43
//
44
//		params.put("header_row","0");
45
//		params.put("tmp_file","/tmp/ERC.xslx");
46
//		params.put("remove_empty_lines","yes");
47
//		params.put("remove_lines_with_id"," – ");
48
//		params.put("col_id","2");
49
//		params.put("remove_tmp_file","no");
50
//		params.put("sheet_number","0");
51
//		params.put("file_to_save","/tmp/ERC.csv");
52
//		params.put("separator", ",");
53
//		params.put("quote","\"");
54
//		descr.setParams(params);
55
		r = new Read(descr);
56
		r.setCollector(new HttpCSVCollectorPlugin());
57
	}
58

    
59
	@Test
60
	//@Ignore
61
	public void readExcelFromUrl()throws Exception{
62
		Iterator<String> it = r.parseFile().iterator();
63
		int i = 0;
64
		String st = null;
65
		try {
66
			while (it.hasNext()) {
67
				st = it.next();
68
				Assert.assertNotNull(st);
69
				i++;
70
				//System.out.println(it.next());
71
			}
72
		}catch(Exception e){
73
			System.out.println("linea " + i);
74
			e.printStackTrace();
75
			System.out.println(st);
76
		}
77

    
78
	}
79

    
80
//	@Test
81
//	public void readExcelFromFile() throws Exception{
82
//		Iterator<String> it = r.parseFile().iterator();
83
//		int i =1;
84
//		String st = null;
85
//		try {
86
//			while (it.hasNext()) {
87
//				st = it.next();
88
//				Assert.assertNotNull(st);
89
//				i++;
90
//				//System.out.println(it.next());
91
//			}
92
//		}catch(Exception e){
93
//			System.out.println("linea " + i);
94
//			e.printStackTrace();
95
//			System.out.println(st);
96
//		}
97
//
98
//
99
//	}
100
}
    (1-1/1)