Project

General

Profile

« Previous | Next » 

Revision 37023

Added by Eri Katsari over 9 years ago

final commit for new funding tree xml represenatation

View differences:

modules/dnet-openaire-stats/trunk/src/test/java/eu/dnetlib/data/mapreduce/hbase/statsExport/utils/GeneralTests.java
109 109

  
110 110
	public void testFunding() {
111 111
		FundingParser fundingParser = new FundingParser();
112
		log.info(fundingParser.getFundingInfo(""));
112
		String funding_level = "\"test\" &"; funding_level = funding_level.replaceAll("\"","");
113
		funding_level = funding_level.replaceAll("&", "");
114
		log.info(funding_level);
113 115

  
116

  
114 117
	}
115 118
}
modules/dnet-openaire-stats/trunk/src/main/java/eu/dnetlib/data/mapreduce/hbase/statsExport/utils/FundingParser.java
1 1
package eu.dnetlib.data.mapreduce.hbase.statsExport.utils;
2

  
2 3
import org.apache.log4j.Logger;
4

  
3 5
/**
4 6
 * Created by envy17 j110ea on 4/5/2015.
5 7
 */
6 8

  
7 9
public class FundingParser {
8
    private String NULL_STRING = "null";
9
    private String ENCLOSED ="#";
10
    private String DELIM ="!";
10
	private String NULL_STRING = "null";
11
	private String ENCLOSED = "#";
12
	private String DELIM = "!";
11 13

  
12
    private Logger log = Logger.getLogger(this.getClass());
14
	private Logger log = Logger.getLogger(this.getClass());
13 15

  
14
    String getFundingLevel(String funding_level, int level) {
16
	String getFundingLevel(String funding_level, int level) {
15 17

  
16
        if (funding_level.isEmpty()) {
17
            return ENCLOSED  + NULL_STRING  + ENCLOSED + DELIM;
18
        }
18
		if (funding_level.isEmpty()) {
19
			return ENCLOSED + NULL_STRING + ENCLOSED + DELIM;
20
		}
19 21

  
20
        if (!funding_level.contains("<funding_level_" + level + ">")) {
21
            return ENCLOSED  + NULL_STRING  + ENCLOSED + DELIM;
22
        }
23
        
24
       String[] split = funding_level.split("<funding_level_" + level + ">");
22
		if (!funding_level.contains("<funding_level_" + level + ">")) {
23
			return ENCLOSED + NULL_STRING + ENCLOSED + DELIM;
24
		}
25 25

  
26
        funding_level = split[1];
26
		String[] split = funding_level.split("<funding_level_" + level + ">");
27 27

  
28
        split = funding_level.split("<name>");
29
        funding_level = split[1];
28
		funding_level = split[1];
30 29

  
31
        funding_level = funding_level.substring(0, funding_level.indexOf("</name>"));
30
		split = funding_level.split("<name>");
31
		funding_level = split[1];
32 32

  
33
        return ENCLOSED + funding_level + ENCLOSED + DELIM;
34
    }
33
		funding_level = funding_level.substring(0, funding_level.indexOf("</name>"));
34
		funding_level = funding_level.replaceAll("\"", "");
35
		funding_level = funding_level.replaceAll("&amp;", "");
36
		return ENCLOSED + funding_level + ENCLOSED + DELIM;
37
	}
35 38

  
36
    public String getFundingInfo(String buff) {
37
        return getFunder(buff) + getFundingLevel(buff, 0)+ (getFundingLevel(buff, 1) + getFundingLevel(buff, 2) + getFundingLevel(buff, 3));
38
    }
39
	public String getFundingInfo(String buff) {
40
		return getFunder(buff) + getFundingLevel(buff, 0) + (getFundingLevel(buff, 1) + getFundingLevel(buff, 2) + getFundingLevel(buff, 3));
41
	}
39 42

  
40
    public String getFunder(String buff) {
43
	public String getFunder(String buff) {
41 44

  
42 45

  
43
       if (buff.isEmpty()) {
44
           return ENCLOSED  + NULL_STRING  + ENCLOSED + DELIM;
46
		if (buff.isEmpty()) {
47
			return ENCLOSED + NULL_STRING + ENCLOSED + DELIM;
45 48

  
46
        }
49
		}
47 50

  
48
        if (!buff.contains("<funder>")) {
49
            return ENCLOSED  + NULL_STRING  + ENCLOSED + DELIM;
50
        }
51
        String[] split = buff.split("<funder>");
52
        String funder = split[1];
51
		if (!buff.contains("<funder>")) {
52
			return ENCLOSED + NULL_STRING + ENCLOSED + DELIM;
53
		}
54
		String[] split = buff.split("<funder>");
55
		String funder = split[1];
53 56

  
54
        split = funder.split("<name>");
57
		split = funder.split("<name>");
55 58

  
56
         funder = split[1];
59
		funder = split[1];
57 60

  
58
        funder = funder.substring(0, funder.indexOf("</name>"));
61
		funder = funder.substring(0, funder.indexOf("</name>"));
62
		funder = funder.replaceAll("\"", "");
63
		funder = funder.replaceAll("&amp;", "");
59 64

  
60
       return ENCLOSED + funder + ENCLOSED + DELIM;
61
    }
62 65

  
63
    public String getNULL_STRING() {
64
        return NULL_STRING;
65
    }
66
		return ENCLOSED + funder + ENCLOSED + DELIM;
67
	}
66 68

  
67
    public void setNULL_STRING(String NULL_STRING) {
68
        this.NULL_STRING = NULL_STRING;
69
    }
69
	public String getNULL_STRING() {
70
		return NULL_STRING;
71
	}
70 72

  
71
    public String getENCLOSED() {
72
        return ENCLOSED;
73
    }
73
	public void setNULL_STRING(String NULL_STRING) {
74
		this.NULL_STRING = NULL_STRING;
75
	}
74 76

  
75
    public void setENCLOSED(String ENCLOSED) {
76
        this.ENCLOSED = ENCLOSED;
77
    }
77
	public String getENCLOSED() {
78
		return ENCLOSED;
79
	}
78 80

  
79
    public String getDELIM() {
80
        return DELIM;
81
    }
81
	public void setENCLOSED(String ENCLOSED) {
82
		this.ENCLOSED = ENCLOSED;
83
	}
82 84

  
83
    public void setDELIM(String DELIM) {
84
        this.DELIM = DELIM;
85
    }
85
	public String getDELIM() {
86
		return DELIM;
87
	}
88

  
89
	public void setDELIM(String DELIM) {
90
		this.DELIM = DELIM;
91
	}
86 92
}
87 93

  

Also available in: Unified diff