Project

General

Profile

« Previous | Next » 

Revision 37008

Added by Eri Katsari over 9 years ago

View differences:

modules/dnet-openaire-stats/trunk/src/main/java/eu/dnetlib/data/mapreduce/hbase/statsExport/utils/FundingParser.java
6 6

  
7 7
public class FundingParser {
8 8
    private String NULL_STRING = "null";
9

  
10 9
    private String ENCLOSED ="#";
11 10
    private String DELIM ="!";
12 11

  
......
14 13

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

  
17

  
18 16
        if (funding_level.isEmpty()) {
19 17
            return ENCLOSED  + NULL_STRING  + ENCLOSED + DELIM;
20 18
        }
......
31 29
        funding_level = split[1];
32 30

  
33 31
        funding_level = funding_level.substring(0, funding_level.indexOf("</name>"));
34
         log.info("Funding lvl out" + funding_level);
35 32

  
36 33
        return ENCLOSED + funding_level + ENCLOSED + DELIM;
37 34
    }
38 35

  
39

  
40 36
    public String getFundingInfo(String buff) {
41
   log.info("Funding lvl input" + buff);
42
        
43
         return getFunder(buff) + getFundingLevel(buff, 0)
44
                + (getFundingLevel(buff, 1) + getFundingLevel(buff, 2) + getFundingLevel(buff, 3));
45

  
37
        return getFunder(buff) + getFundingLevel(buff, 0)+ (getFundingLevel(buff, 1) + getFundingLevel(buff, 2) + getFundingLevel(buff, 3));
46 38
    }
47 39

  
48 40
    public String getFunder(String buff) {
49 41

  
50
        return  ENCLOSED  + "STARTS HERE" +buff +"ENDS HERE" + ENCLOSED + DELIM;
51 42

  
52
  //      if (buff.isEmpty()) {
53
//            return ENCLOSED  + NULL_STRING  + ENCLOSED + DELIM;
43
       if (buff.isEmpty()) {
44
           return ENCLOSED  + NULL_STRING  + ENCLOSED + DELIM;
54 45

  
55
    //    }
46
        }
56 47

  
57
      //  if (!buff.contains("<funder>")) {
58
        //    return ENCLOSED  + NULL_STRING  + ENCLOSED + DELIM;
59
        //}
48
        if (!buff.contains("<funder>")) {
49
            return ENCLOSED  + NULL_STRING  + ENCLOSED + DELIM;
50
        }
51
        String[] split = buff.split("<funder>");
52
        String funder = split[1];
60 53

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

  
62
//        String[] split = buff.split("<funder>");
63
//        String funder = split[1];
64
//
65
//        split = funder.split("<name>");
66
//
67
//        funder = split[1];
68
//
69
//        funder = funder.substring(0, funder.indexOf("</name>"));
70
//        log.info("Funder" + funder);
71
//
72
//        return ENCLOSED + funder + ENCLOSED + DELIM;
56
         funder = split[1];
57

  
58
        funder = funder.substring(0, funder.indexOf("</name>"));
59

  
60
       return ENCLOSED + funder + ENCLOSED + DELIM;
73 61
    }
74 62

  
75 63
    public String getNULL_STRING() {
......
96 84
        this.DELIM = DELIM;
97 85
    }
98 86
}
87

  
modules/dnet-openaire-stats/trunk/src/main/java/eu/dnetlib/data/mapreduce/hbase/statsExport/utils/Serializer.java
30 30
 */
31 31
public class Serializer {
32 32

  
33
    private static String DELIM;
34
    private Logger log = Logger.getLogger(this.getClass());
35
    private String NULL_STRING;
36
    private String NULL_NUM;
37
    //TODO no longer used
38
    private static String ENCLOSED;
33
	private static String DELIM;
34
	private Logger log = Logger.getLogger(this.getClass());
35
	private String NULL_STRING;
36
	private String NULL_NUM;
37
	//TODO no longer used
38
	private static String ENCLOSED;
39 39

  
40
	private FundingParser fundingParser = new FundingParser();
40 41

  
41
    private FundingParser fundingParser;
42 42

  
43
    public Serializer() {
44
        fundingParser = new FundingParser();
45
        fundingParser.setDELIM(DELIM);
46
        fundingParser.setENCLOSED(ENCLOSED);
47
        fundingParser.setNULL_STRING(NULL_STRING);
48
    }
43
	public Serializer() {
44
	}
49 45

  
50
    ;
51 46

  
52
    public String serialize(Oaf oaf) {
47
	public String serialize(Oaf oaf) {
53 48

  
54
        switch (oaf.getKind()) {
55
            case entity:
56
                OafEntity valueEntity = oaf.getEntity();
49
		switch (oaf.getKind()) {
50
			case entity:
51
				OafEntity valueEntity = oaf.getEntity();
57 52

  
58
                switch (valueEntity.getType()) {
59
                    case datasource:
53
				switch (valueEntity.getType()) {
54
					case datasource:
60 55

  
61
                        return buildDatasource(valueEntity);
56
						return buildDatasource(valueEntity);
62 57

  
63
                    case organization:
58
					case organization:
64 59

  
65
                        return buildOrganization(valueEntity);
60
						return buildOrganization(valueEntity);
66 61

  
67
                    case project:
62
					case project:
68 63

  
69
                        return buildProject(valueEntity);
70
                    case result:
64
						return buildProject(valueEntity);
65
					case result:
71 66

  
72
                        return buildResult(valueEntity);
67
						return buildResult(valueEntity);
73 68
//                    case person:
74 69
//
75 70
//                        return buildPerson(valueEntity);
76
                    default:
77
                        log.error("wrong type");
78
                        break;
79
                }
80
                break;
81
            case relation:
82
                OafRel valueRel = oaf.getRel();
71
					default:
72
						log.error("wrong type");
73
						break;
74
				}
75
				break;
76
			case relation:
77
				OafRel valueRel = oaf.getRel();
83 78

  
84
                return buildRel(valueRel);
79
				return buildRel(valueRel);
85 80

  
86
        }
81
		}
87 82

  
88
        return null;
83
		return null;
89 84

  
90
    }
85
	}
91 86

  
92
    public String serialize(OafRel oaf) {
87
	public String serialize(OafRel oaf) {
93 88

  
94
        switch (oaf.getRelType()) {
95
            case resultProject:
89
		switch (oaf.getRelType()) {
90
			case resultProject:
96 91

  
97
                return getResultProject(oaf);
92
				return getResultProject(oaf);
98 93

  
99
            default:
100
                return buildRel(oaf);
101
        }
102
    }
94
			default:
95
				return buildRel(oaf);
96
		}
97
	}
103 98

  
104
    private String buildRel(OafRel Rel) {
105
        return getStringField(Rel.getTarget());
106
    }
99
	private String buildRel(OafRel Rel) {
100
		return getStringField(Rel.getTarget());
101
	}
107 102

  
108 103

  
109
    public HashMap<String, List<String>> extractRelations(Oaf oaf) {
110
        OafEntity valueEntity = oaf.getEntity();
111
        switch (valueEntity.getType()) {
112
            case datasource:
113
                return getDatasourceLanguages(valueEntity);
114
            case result:
115
                HashMap<String, List<String>> relations = new HashMap<String, List<String>>();
116
                relations.putAll(getResultLanguages(valueEntity));
117
                //TODO no more resultTopics needed!!!
118
                // relations.putAll(getResultTopics(valueEntity));
119
                relations.putAll(getResultClassifications(valueEntity));
120
                relations.putAll(getResultDatasources(valueEntity));
121
                relations.putAll(getResultConcepts(valueEntity));
122
                return relations;
123
            default:
104
	public HashMap<String, List<String>> extractRelations(Oaf oaf) {
105
		OafEntity valueEntity = oaf.getEntity();
106
		switch (valueEntity.getType()) {
107
			case datasource:
108
				return getDatasourceLanguages(valueEntity);
109
			case result:
110
				HashMap<String, List<String>> relations = new HashMap<String, List<String>>();
111
				relations.putAll(getResultLanguages(valueEntity));
112
				//TODO no more resultTopics needed!!!
113
				// relations.putAll(getResultTopics(valueEntity));
114
				relations.putAll(getResultClassifications(valueEntity));
115
				relations.putAll(getResultDatasources(valueEntity));
116
				relations.putAll(getResultConcepts(valueEntity));
117
				return relations;
118
			default:
124 119

  
125
                return null;
126
        }
120
				return null;
121
		}
127 122

  
128
    }
123
	}
129 124

  
130
    private String getResultProject(OafRel oaf) {
131
        String buff = new String();
132
        String result = oaf.getTarget();
125
	private String getResultProject(OafRel oaf) {
126
		String buff = new String();
127
		String result = oaf.getTarget();
133 128

  
134 129

  
135
        buff += getStringField(result);
136
        // TODO is declared as int!!!
137
        long diff = DATEDIFF(oaf.getResultProject().getOutcome().getRelMetadata().getEnddate(), oaf.getResultProject().getOutcome().getRelMetadata().getStartdate());
138
        if (diff < 0) {
139
            diff = 0;
140
        }
141
        buff += getNumericField(String.valueOf(diff));
130
		buff += getStringField(result);
131
		// TODO is declared as int!!!
132
		long diff = DATEDIFF(oaf.getResultProject().getOutcome().getRelMetadata().getEnddate(), oaf.getResultProject().getOutcome().getRelMetadata().getStartdate());
133
		if (diff < 0) {
134
			diff = 0;
135
		}
136
		buff += getNumericField(String.valueOf(diff));
142 137

  
143 138

  
144
        return buff;
145
    }
139
		return buff;
140
	}
146 141

  
147 142

  
148
    private HashMap<String, List<String>> getDatasourceLanguages(OafEntity valueEntity) {
149
        HashMap<String, List<String>> rels = new HashMap<String, List<String>>();
150
        List<String> buffs = new ArrayList<String>();
143
	private HashMap<String, List<String>> getDatasourceLanguages(OafEntity valueEntity) {
144
		HashMap<String, List<String>> rels = new HashMap<String, List<String>>();
145
		List<String> buffs = new ArrayList<String>();
151 146

  
152 147

  
153
        Datasource d = valueEntity.getDatasource();
148
		Datasource d = valueEntity.getDatasource();
154 149

  
155
        Metadata metadata = d.getMetadata();
150
		Metadata metadata = d.getMetadata();
156 151

  
157
        for (StringField lang : metadata.getOdlanguagesList()) {
152
		for (StringField lang : metadata.getOdlanguagesList()) {
158 153

  
159
            buffs.add(getStringField(lang.getValue()));
160
        }
161
        rels.put("datasourceLanguage", buffs);
162
        return rels;
163
    }
154
			buffs.add(getStringField(lang.getValue()));
155
		}
156
		rels.put("datasourceLanguage", buffs);
157
		return rels;
158
	}
164 159

  
165
    private HashMap<String, List<String>> getResultLanguages(OafEntity valueEntity) {
166
        HashMap<String, List<String>> rels = new HashMap<String, List<String>>();
167
        List<String> buffs = new ArrayList<String>();
168
        Result d = valueEntity.getResult();
160
	private HashMap<String, List<String>> getResultLanguages(OafEntity valueEntity) {
161
		HashMap<String, List<String>> rels = new HashMap<String, List<String>>();
162
		List<String> buffs = new ArrayList<String>();
163
		Result d = valueEntity.getResult();
169 164

  
170
        eu.dnetlib.data.proto.ResultProtos.Result.Metadata metadata = d.getMetadata();
165
		eu.dnetlib.data.proto.ResultProtos.Result.Metadata metadata = d.getMetadata();
171 166

  
172
        if (metadata.getLanguage().getClassname() != null && !metadata.getLanguage().getClassname().isEmpty()) {
167
		if (metadata.getLanguage().getClassname() != null && !metadata.getLanguage().getClassname().isEmpty()) {
173 168

  
174
            buffs.add(getStringField(metadata.getLanguage().getClassname()));
175
        }
176
        rels.put("resultLanguage", buffs);
177
        return rels;
169
			buffs.add(getStringField(metadata.getLanguage().getClassname()));
170
		}
171
		rels.put("resultLanguage", buffs);
172
		return rels;
178 173

  
179
    }
174
	}
180 175

  
181
    private HashMap<String, List<String>> getResultClassifications(OafEntity valueEntity) {
176
	private HashMap<String, List<String>> getResultClassifications(OafEntity valueEntity) {
182 177

  
183
        HashMap<String, List<String>> rels = new HashMap<String, List<String>>();
184
        List<String> buffs = new ArrayList<String>();
185
        Result result = valueEntity.getResult();
178
		HashMap<String, List<String>> rels = new HashMap<String, List<String>>();
179
		List<String> buffs = new ArrayList<String>();
180
		Result result = valueEntity.getResult();
186 181

  
187
        for (Instance instance : (result.getInstanceList())) {
188
            String classification = instance.getInstancetype().getClassname();
189
            if (classification != null && !classification.isEmpty()) {
190
                buffs.add(getStringField(instance.getInstancetype().getClassname()));
191
                // TODO HERE KEEP ONLY ONE CLASSIFICATIONS PER RESULT
192
                break;
193
            }
194
        }
195
        rels.put("resultClassification", buffs);
196
        return rels;
182
		for (Instance instance : (result.getInstanceList())) {
183
			String classification = instance.getInstancetype().getClassname();
184
			if (classification != null && !classification.isEmpty()) {
185
				buffs.add(getStringField(instance.getInstancetype().getClassname()));
186
				// TODO HERE KEEP ONLY ONE CLASSIFICATIONS PER RESULT
187
				break;
188
			}
189
		}
190
		rels.put("resultClassification", buffs);
191
		return rels;
197 192

  
198
    }
193
	}
199 194

  
200
    private HashMap<String, List<String>> getResultConcepts(OafEntity valueEntity) {
201
        HashMap<String, List<String>> rels = new HashMap<String, List<String>>();
202
        List<String> buffs = new ArrayList<String>();
195
	private HashMap<String, List<String>> getResultConcepts(OafEntity valueEntity) {
196
		HashMap<String, List<String>> rels = new HashMap<String, List<String>>();
197
		List<String> buffs = new ArrayList<String>();
203 198

  
204
        Result result = valueEntity.getResult();
199
		Result result = valueEntity.getResult();
205 200

  
206
        for (eu.dnetlib.data.proto.ResultProtos.Result.Context context : result.getMetadata().getContextList()) {
201
		for (eu.dnetlib.data.proto.ResultProtos.Result.Context context : result.getMetadata().getContextList()) {
207 202

  
208
            buffs.add(getStringField(context.getId()));
209
        }
210
        rels.put("resultConcept", buffs);
211
        return rels;
203
			buffs.add(getStringField(context.getId()));
204
		}
205
		rels.put("resultConcept", buffs);
206
		return rels;
212 207

  
213
    }
208
	}
214 209

  
215
    private HashMap<String, List<String>> getResultDatasources(OafEntity valueEntity) {
210
	private HashMap<String, List<String>> getResultDatasources(OafEntity valueEntity) {
216 211

  
217
        HashMap<String, List<String>> rels = new HashMap<String, List<String>>();
218
        List<String> buffs = new ArrayList<String>();
219
        Result result = valueEntity.getResult();
212
		HashMap<String, List<String>> rels = new HashMap<String, List<String>>();
213
		List<String> buffs = new ArrayList<String>();
214
		Result result = valueEntity.getResult();
220 215

  
221 216
//TODO hosted by
222
        for (Instance instance : (result.getInstanceList())) {
217
		for (Instance instance : (result.getInstanceList())) {
223 218

  
224 219

  
225
            String hostedBy = instance.getHostedby().getKey();
226
            if (hostedBy != null && !hostedBy.isEmpty()) {
227
                buffs.add((getStringField(hostedBy)));
228
            }
229
        }
220
			String hostedBy = instance.getHostedby().getKey();
221
			if (hostedBy != null && !hostedBy.isEmpty()) {
222
				buffs.add((getStringField(hostedBy)));
223
			}
224
		}
230 225

  
231 226
//TODO  collected froms
232
        for (FieldTypeProtos.KeyValue collectedFromValue : (valueEntity.getCollectedfromList())) {
227
		for (FieldTypeProtos.KeyValue collectedFromValue : (valueEntity.getCollectedfromList())) {
233 228

  
234
            String collectedFrom = collectedFromValue.getKey();
235
            if (collectedFrom != null && !collectedFrom.isEmpty()) buffs.add((getStringField(collectedFrom)));
229
			String collectedFrom = collectedFromValue.getKey();
230
			if (collectedFrom != null && !collectedFrom.isEmpty()) buffs.add((getStringField(collectedFrom)));
236 231

  
237
        }
238
        rels.put("resultDatasource", buffs);
239
        return rels;
232
		}
233
		rels.put("resultDatasource", buffs);
234
		return rels;
240 235

  
241
    }
236
	}
242 237

  
243
    public static boolean isNumeric(String str) {
238
	public static boolean isNumeric(String str) {
244 239

  
245
        str = str.replaceAll("[^A-Za-z0-9 ]", "");
246
        str = str.replaceAll(" ", "");
247
        return str.matches("-?\\d+(\\.\\d+)?"); // match a number with optional
248
        // '-' and decimal.
249
    }
240
		str = str.replaceAll("[^A-Za-z0-9 ]", "");
241
		str = str.replaceAll(" ", "");
242
		return str.matches("-?\\d+(\\.\\d+)?"); // match a number with optional
243
		// '-' and decimal.
244
	}
250 245

  
251
    // TODO there are topics with "null" as value -> replace them
252
    private boolean isValidTopic(String t) {
246
	// TODO there are topics with "null" as value -> replace them
247
	private boolean isValidTopic(String t) {
253 248

  
254
        if (t == null || t.isEmpty()) {
255
            return false;
256
        }
249
		if (t == null || t.isEmpty()) {
250
			return false;
251
		}
257 252

  
258
        if (t.equals("") || t.equals(" ")) {
259
            return false;
260
        }
261
        if (t.equals("null") || t.equals("Null") || t.equals("NULL")) {
262
            return false;
263
        }
253
		if (t.equals("") || t.equals(" ")) {
254
			return false;
255
		}
256
		if (t.equals("null") || t.equals("Null") || t.equals("NULL")) {
257
			return false;
258
		}
264 259

  
265
        if (t.equals(ENCLOSED + ENCLOSED + DELIM) || t.equals(ENCLOSED + NULL_STRING + ENCLOSED + DELIM)) {
266
            return false;
267
        }
268
        // skip dedups
269
        if (t.contains("ddc:")) {
270
            return false;
271
        }
272
        return true;
273
    }
260
		if (t.equals(ENCLOSED + ENCLOSED + DELIM) || t.equals(ENCLOSED + NULL_STRING + ENCLOSED + DELIM)) {
261
			return false;
262
		}
263
		// skip dedups
264
		if (t.contains("ddc:")) {
265
			return false;
266
		}
267
		return true;
268
	}
274 269

  
275
    private HashMap<String, List<String>> getResultTopics(OafEntity valueEntity) {
276
        HashMap<String, List<String>> rels = new HashMap<String, List<String>>();
277
        List<String> buffs = new ArrayList<String>();
278
        Result d = valueEntity.getResult();
270
	private HashMap<String, List<String>> getResultTopics(OafEntity valueEntity) {
271
		HashMap<String, List<String>> rels = new HashMap<String, List<String>>();
272
		List<String> buffs = new ArrayList<String>();
273
		Result d = valueEntity.getResult();
279 274

  
280
        eu.dnetlib.data.proto.ResultProtos.Result.Metadata metadata = d.getMetadata();
275
		eu.dnetlib.data.proto.ResultProtos.Result.Metadata metadata = d.getMetadata();
281 276

  
282
        List<StructuredProperty> Topics = metadata.getSubjectList();
283
        String buff = new String();
284
        for (StructuredProperty topic : Topics) {
285
            // TODOs
286
            if (isValidTopic(topic.getValue())) {
287
                if (!isNumeric(topic.getValue())) {
288
                    String t = getStringField(topic.getValue());
289
                    if (isValidTopic(t)) {
290
                        buff += t + " ";
277
		List<StructuredProperty> Topics = metadata.getSubjectList();
278
		String buff = new String();
279
		for (StructuredProperty topic : Topics) {
280
			// TODOs
281
			if (isValidTopic(topic.getValue())) {
282
				if (!isNumeric(topic.getValue())) {
283
					String t = getStringField(topic.getValue());
284
					if (isValidTopic(t)) {
285
						buff += t + " ";
291 286

  
292
                    }
287
					}
293 288

  
294
                }
295
            }
289
				}
290
			}
296 291

  
297
        }
298
        if (!buff.isEmpty()) {
299
            buff = getStringField(buff);
300
            buffs.add(buff);
301
        }
302
        rels.put("resultTopic", buffs);
292
		}
293
		if (!buff.isEmpty()) {
294
			buff = getStringField(buff);
295
			buffs.add(buff);
296
		}
297
		rels.put("resultTopic", buffs);
303 298

  
304
        return rels;
299
		return rels;
305 300

  
306
    }
301
	}
307 302

  
308
    private String buildDatasource(OafEntity data) {
303
	private String buildDatasource(OafEntity data) {
309 304

  
310
        String buff = new String();
305
		String buff = new String();
311 306

  
312
        Datasource d = data.getDatasource();
307
		Datasource d = data.getDatasource();
313 308

  
314
        Metadata metadata = d.getMetadata();
315
        String full_id = getStringField(data.getId());
309
		Metadata metadata = d.getMetadata();
310
		String full_id = getStringField(data.getId());
316 311

  
317
        buff += full_id;
318
        buff += full_id;
319
        buff += full_id;
320
        buff += full_id;
312
		buff += full_id;
313
		buff += full_id;
314
		buff += full_id;
315
		buff += full_id;
321 316

  
322 317

  
323
        // name
324
        if (metadata.getOfficialname().getValue().equalsIgnoreCase("unknown")) {
325
            buff += getStringField("Unknown Repository");
326
        } else {
327
            buff += getStringField(metadata.getOfficialname().getValue());
328
        }
329
        // type
318
		// name
319
		if (metadata.getOfficialname().getValue().equalsIgnoreCase("unknown")) {
320
			buff += getStringField("Unknown Repository");
321
		} else {
322
			buff += getStringField(metadata.getOfficialname().getValue());
323
		}
324
		// type
330 325

  
331
        if (metadata.hasDatasourcetype())
326
		if (metadata.hasDatasourcetype())
332 327

  
333
        {
334
            buff += getStringField(metadata.getDatasourcetype().getClassname().replaceFirst(".*::", ""));
328
		{
329
			buff += getStringField(metadata.getDatasourcetype().getClassname().replaceFirst(".*::", ""));
335 330

  
336
        } else {
337
            buff += getStringField(null);
338
        }
331
		} else {
332
			buff += getStringField(null);
333
		}
339 334

  
340
        // compatibility,
341
        buff += getStringField(metadata.getOpenairecompatibility().getClassname());
335
		// compatibility,
336
		buff += getStringField(metadata.getOpenairecompatibility().getClassname());
342 337

  
343
        // latitude
344
        buff += getStringField(metadata.getLatitude().getValue());
338
		// latitude
339
		buff += getStringField(metadata.getLatitude().getValue());
345 340

  
346
        // longtitude
347
        buff += getStringField(metadata.getLongitude().getValue());
341
		// longtitude
342
		buff += getStringField(metadata.getLongitude().getValue());
348 343

  
349
        // dateofvalidation,
350
        buff += getStringField(metadata.getDateofvalidation().getValue());
344
		// dateofvalidation,
345
		buff += getStringField(metadata.getDateofvalidation().getValue());
351 346

  
352
        // yearofvalidation,
347
		// yearofvalidation,
353 348

  
354
        // parse year of validation
355
        buff += getYearInt(metadata.getDateofvalidation().getValue());
349
		// parse year of validation
350
		buff += getYearInt(metadata.getDateofvalidation().getValue());
356 351

  
357
        // number??
352
		// number??
358 353

  
359
        buff += getStringField("1");
354
		buff += getStringField("1");
360 355

  
361
        return buff;
362
    }
356
		return buff;
357
	}
363 358

  
364
    private String buildOrganization(OafEntity data) {
359
	private String buildOrganization(OafEntity data) {
365 360

  
366
        String buff = new String();
361
		String buff = new String();
367 362

  
368
        Organization organization = data.getOrganization();
369
        eu.dnetlib.data.proto.OrganizationProtos.Organization.Metadata metadata = organization.getMetadata();
363
		Organization organization = data.getOrganization();
364
		eu.dnetlib.data.proto.OrganizationProtos.Organization.Metadata metadata = organization.getMetadata();
370 365

  
371
        // `organization_datasources`,
372
        String full_id = getStringField(data.getId());
373
        buff += full_id;
374
        // organization_projects
375
        buff += full_id;
376
        // `name`,
377
        buff += getStringField(metadata.getLegalname().getValue());
378
        // `country`,
366
		// `organization_datasources`,
367
		String full_id = getStringField(data.getId());
368
		buff += full_id;
369
		// organization_projects
370
		buff += full_id;
371
		// `name`,
372
		buff += getStringField(metadata.getLegalname().getValue());
373
		// `country`,
379 374

  
380 375

  
381
        buff += getStringField(metadata.getCountry().getClassname());
376
		buff += getStringField(metadata.getCountry().getClassname());
382 377

  
383 378

  
384
        // `number`,
379
		// `number`,
385 380

  
386
        buff += getStringField("1");
387
        return buff;
381
		buff += getStringField("1");
382
		return buff;
388 383

  
389
    }
384
	}
390 385

  
391
    private String buildResult(OafEntity data) {
386
	private String buildResult(OafEntity data) {
392 387

  
393
        String buff = new String();
388
		String buff = new String();
394 389

  
395
        Result result = data.getResult();
396
        eu.dnetlib.data.proto.ResultProtos.Result.Metadata metadata = result.getMetadata();
390
		Result result = data.getResult();
391
		eu.dnetlib.data.proto.ResultProtos.Result.Metadata metadata = result.getMetadata();
397 392

  
398
        // result_topics/
399
        String full_id = getStringField(data.getId());
393
		// result_topics/
394
		String full_id = getStringField(data.getId());
400 395

  
401
        buff += full_id;
396
		buff += full_id;
402 397

  
403
        // result_languages
404
        buff += full_id;
398
		// result_languages
399
		buff += full_id;
405 400

  
406
        // `result_projects`,
407
        buff += full_id;
401
		// `result_projects`,
402
		buff += full_id;
408 403

  
409
        // `result_datasources`,
410
        buff += full_id;
404
		// `result_datasources`,
405
		buff += full_id;
411 406

  
412
        // `result_classifications`,
413
        buff += full_id;
407
		// `result_classifications`,
408
		buff += full_id;
414 409

  
415
        // / `result_infrastructures`,
416
        buff += full_id;
410
		// / `result_infrastructures`,
411
		buff += full_id;
417 412

  
418
        // `result_claims`,
419
        buff += full_id;
413
		// `result_claims`,
414
		buff += full_id;
420 415

  
421
        // `result_results`,
422
        buff += full_id;
416
		// `result_results`,
417
		buff += full_id;
423 418

  
424
        //TODO pubtitle
419
		//TODO pubtitle
425 420

  
426
        String titleString = new String();
427
        String alternativeTitles = new String();
421
		String titleString = new String();
422
		String alternativeTitles = new String();
428 423

  
429
        //  for (StructuredProperty title : metadata.getTitleList()) {
430
        //    titleString = title.getValue();
431
        //  break;
432
        //}
424
		//  for (StructuredProperty title : metadata.getTitleList()) {
425
		//    titleString = title.getValue();
426
		//  break;
427
		//}
433 428

  
434
        for (int i = 0; i < metadata.getTitleList().size(); i++) {
435
            StructuredProperty title = metadata.getTitleList().get(i);
436
            if (i == 0) {
437
                titleString = title.getValue().replaceAll("\\s+", " ");
438
                titleString = titleString.replaceAll("\n", " ");
439
            } else {
440
                alternativeTitles += title.getValue().replaceAll("\\s+", " ") + " ; ";
441
                alternativeTitles = alternativeTitles.replaceAll("\n", " ");
442
            }
443
            break;
444
        }
445
        //TODO pubtitle
446
        buff += getStringField(titleString);  //!#Osvaldo Raineri: Gli Atti etiopici del martire egiziano Giorgio il nuovo (β  978)#!#
447
        //TODO alternative titles
448
        //buff += getStringField(alternativeTitles);    //  null#!
429
		for (int i = 0; i < metadata.getTitleList().size(); i++) {
430
			StructuredProperty title = metadata.getTitleList().get(i);
431
			if (i == 0) {
432
				titleString = title.getValue().replaceAll("\\s+", " ");
433
				titleString = titleString.replaceAll("\n", " ");
434
			} else {
435
				alternativeTitles += title.getValue().replaceAll("\\s+", " ") + " ; ";
436
				alternativeTitles = alternativeTitles.replaceAll("\n", " ");
437
			}
438
			break;
439
		}
440
		//TODO pubtitle
441
		buff += getStringField(titleString);  //!#Osvaldo Raineri: Gli Atti etiopici del martire egiziano Giorgio il nuovo (β  978)#!#
442
		//TODO alternative titles
443
		//buff += getStringField(alternativeTitles);    //  null#!
449 444

  
450
        // TODO format
451
        String formatString = NULL_STRING;
452
        //for (StringField format : metadata.getFormatList()) {
453
        //	formatString = format.getValue();
454
        //	break;
455
        //}
445
		// TODO format
446
		String formatString = NULL_STRING;
447
		//for (StringField format : metadata.getFormatList()) {
448
		//	formatString = format.getValue();
449
		//	break;
450
		//}
456 451

  
457
        buff += getStringField(formatString);
458
        //TODO publisher
452
		buff += getStringField(formatString);
453
		//TODO publisher
459 454

  
460
        buff += getStringField(metadata.getPublisher().getValue());
461
        //TODO journal
455
		buff += getStringField(metadata.getPublisher().getValue());
456
		//TODO journal
462 457

  
463
        buff += getStringField(metadata.getJournal().getName().replaceAll("\n", " "));  //#null#!
458
		buff += getStringField(metadata.getJournal().getName().replaceAll("\n", " "));  //#null#!
464 459

  
465
        // year
466
        buff += getYearInt(metadata.getDateofacceptance().getValue());
460
		// year
461
		buff += getYearInt(metadata.getDateofacceptance().getValue());
467 462

  
468
        // date CHANGED THIS TO DATE FORMAT
469
        buff += getStringDateField(metadata.getDateofacceptance().getValue());
463
		// date CHANGED THIS TO DATE FORMAT
464
		buff += getStringDateField(metadata.getDateofacceptance().getValue());
470 465

  
471
        // access_mode,
472
        buff += getStringField(getAccessMode(result));
466
		// access_mode,
467
		buff += getStringField(getAccessMode(result));
473 468

  
474
        // bestlicense
469
		// bestlicense
475 470

  
476
        buff += getStringField(getBestLicense(result));
477
        // type
478
        buff += getStringField(metadata.getResulttype().getClassname());
479
        // embargo_end_date
480
        buff += getStringField(metadata.getEmbargoenddate().getValue());
471
		buff += getStringField(getBestLicense(result));
472
		// type
473
		buff += getStringField(metadata.getResulttype().getClassname());
474
		// embargo_end_date
475
		buff += getStringField(metadata.getEmbargoenddate().getValue());
481 476

  
482
        // `authors`,
483
        int authors = 0;
484
        String delayed = "no";
477
		// `authors`,
478
		int authors = 0;
479
		String delayed = "no";
485 480

  
486
        for (OafRel rel : data.getCachedRelList()) {
481
		for (OafRel rel : data.getCachedRelList()) {
487 482

  
488
            if (rel.getRelType().equals(RelType.personResult)) {
483
			if (rel.getRelType().equals(RelType.personResult)) {
489 484

  
490
                authors++;
491
            } else if (rel.getRelType().equals(RelType.resultProject))
492
            // TODO remember : in result Project, first id is project, second is
493
            // result.
494
            {
485
				authors++;
486
			} else if (rel.getRelType().equals(RelType.resultProject))
487
			// TODO remember : in result Project, first id is project, second is
488
			// result.
489
			{
495 490

  
496
                String daysfromend = getYearDifferenceInteger(rel.getResultProject().getOutcome().getRelMetadata().getEnddate(), rel.getResultProject().getOutcome().getRelMetadata().getStartdate());
497
                if (Integer.parseInt(daysfromend) > 0) {
498
                    delayed = "yes";
499
                }
500
            }
501
        }
502
        // `delayed`,
503
        buff += getStringField(delayed);
491
				String daysfromend = getYearDifferenceInteger(rel.getResultProject().getOutcome().getRelMetadata().getEnddate(), rel.getResultProject().getOutcome().getRelMetadata().getStartdate());
492
				if (Integer.parseInt(daysfromend) > 0) {
493
					delayed = "yes";
494
				}
495
			}
496
		}
497
		// `delayed`,
498
		buff += getStringField(delayed);
504 499

  
505
        // log.info("Result " + full_id +"Author count : " + authors );
506
        buff += getNumericField(String.valueOf(authors));
500
		// log.info("Result " + full_id +"Author count : " + authors );
501
		buff += getNumericField(String.valueOf(authors));
507 502

  
508
        // number??
503
		// number??
509 504

  
510
        buff += getStringField("1");
505
		buff += getStringField("1");
511 506

  
512
        if (isValid(buff, full_id)) {
513
            return buff;
514
        } else {
515
            return null;
516
        }
507
		if (isValid(buff, full_id)) {
508
			return buff;
509
		} else {
510
			return null;
511
		}
517 512

  
518
    }
513
	}
519 514

  
520
    //TODO here see if check is ok
521
    private boolean isValid(String buff, String id) {
522
        if (buff.endsWith(ENCLOSED)) {
523
            log.error("Empty Result with  " + id + " with body: \n" + buff);
524
            return false;
525
        }
526
        return true;
527
    }
515
	//TODO here see if check is ok
516
	private boolean isValid(String buff, String id) {
517
		if (buff.endsWith(ENCLOSED)) {
518
			log.error("Empty Result with  " + id + " with body: \n" + buff);
519
			return false;
520
		}
521
		return true;
522
	}
528 523

  
529
    private String getBestLicense(Result result) {
530
        Qualifier bestLicense = null;
531
        LicenseComparator lc = new LicenseComparator();
532
        for (Instance instance : (result.getInstanceList())) {
533
            if (lc.compare(bestLicense, instance.getLicence()) > 0) {
534
                bestLicense = instance.getLicence();
535
            }
536
        }
537
        if (bestLicense != null) {
538
            return bestLicense.getClassname();
539
        } else {
540
            return null;
541
        }
542
    }
524
	private String getBestLicense(Result result) {
525
		Qualifier bestLicense = null;
526
		LicenseComparator lc = new LicenseComparator();
527
		for (Instance instance : (result.getInstanceList())) {
528
			if (lc.compare(bestLicense, instance.getLicence()) > 0) {
529
				bestLicense = instance.getLicence();
530
			}
531
		}
532
		if (bestLicense != null) {
533
			return bestLicense.getClassname();
534
		} else {
535
			return null;
536
		}
537
	}
543 538

  
544
    // TODO here iterate over all values
545
    private String getAccessMode(Result result) {
546
        String accessMode = NULL_STRING;
547
        for (Instance instance : (result.getInstanceList())) {
548
            if (instance.getLicence().getClassname() != null && !instance.getLicence().getClassname().isEmpty()) {
549
                accessMode = instance.getLicence().getClassname();
550
                break;
551
            }
539
	// TODO here iterate over all values
540
	private String getAccessMode(Result result) {
541
		String accessMode = NULL_STRING;
542
		for (Instance instance : (result.getInstanceList())) {
543
			if (instance.getLicence().getClassname() != null && !instance.getLicence().getClassname().isEmpty()) {
544
				accessMode = instance.getLicence().getClassname();
545
				break;
546
			}
552 547

  
553
        }
548
		}
554 549

  
555
        return accessMode;
556
    }
550
		return accessMode;
551
	}
557 552

  
558
    private String buildProject(OafEntity data) {
553
	private String buildProject(OafEntity data) {
559 554

  
560
        String buff = new String();
555
		String buff = new String();
561 556

  
562
        Project project = data.getProject();
563
        eu.dnetlib.data.proto.ProjectProtos.Project.Metadata metadata = project.getMetadata();
564
        // project_organizations
557
		Project project = data.getProject();
558
		eu.dnetlib.data.proto.ProjectProtos.Project.Metadata metadata = project.getMetadata();
559
		// project_organizations
560
		String full_id = getStringField(data.getId());
561
		buff += full_id;
562
		// project_results
563
		buff += full_id;
565 564

  
566
        String full_id = getStringField(data.getId());
567
        buff += full_id;
565
		String acronym = metadata.getAcronym().getValue();
566
		if (acronym.equalsIgnoreCase("UNKNOWN")) {
567
			acronym = metadata.getTitle().getValue();
568
		}
568 569

  
569
        // project_results
570
        buff += full_id;
571
        // `acronym`,
572
        String acronym = metadata.getAcronym().getValue();
573
        if (acronym.equalsIgnoreCase("UNKNOWN")) {
574
            acronym = metadata.getTitle().getValue();
575
        }
570
		// `acronym`,
571
		buff += getStringField(acronym);
576 572

  
577
        buff += getStringField(acronym);
573
		//title!
574
		String title = getStringField(metadata.getTitle().getValue());
575
		buff += getStringField(title);
578 576

  
579
        //title!
580
        String title = getStringField(metadata.getTitle().getValue());
581
        buff += getStringField(title);
582 577

  
583
        List<StringField> fundList = metadata.getFundingtreeList();
578
		List<StringField> fundList = metadata.getFundingtreeList();
584 579

  
585 580

  
586
        if (!fundList.isEmpty()) // `funding_lvl0`,
587
        {
588
            //TODO funder + 3 funding levels
581
		if (!fundList.isEmpty()) // `funding_lvl0`,
582
		{
583
			//TODO funder + 3 funding levels
584
		   /* funder text,
585
		    funding_lvl0 text,
586
	        funding_lvl1 text,
587
	        funding_lvl2 text,
588
	        funding_lvl3 text,
589
*/
590
			buff += this.fundingParser.getFundingInfo(fundList.get(0).getValue());
589 591

  
590
            for (int i = 0; i < fundList.size(); i++) {
591
                buff += fundingParser.getFundingInfo(fundList.get(i).getValue());
592
            }
592
		} else {
593
			buff += getStringField(NULL_STRING);
593 594

  
594
            //buff += this.fundingParser.getFundingInfo(fundList.get(0).getValue());
595
		}
595 596

  
596
        }
597 597

  
598
		String sc39 = metadata.getEcsc39().getValue().toString();
599
		if (sc39.equalsIgnoreCase("true") || sc39.equalsIgnoreCase("t") || sc39.contains("yes")) {
600
			sc39 = "yes";
601
		} else if (sc39.equalsIgnoreCase("false") || sc39.equalsIgnoreCase("f") || sc39.contains("no")) {
602
			sc39 = "no";
603
		}
598 604

  
599
        // if (funding_tree_2.equals(NULL_STRING)&&fundList.size() > 1) {
600
        //  funding_tree_2 = (fundingParser.getFundingLevel(fundList.get(1).getValue(), 2));
601
        // funding_tree_3 = (fundingParser.getFundingLevel(fundList.get(1).getValue(), 3));
602
        //}
605
		// `sc39`,
606
		buff += getStringField(sc39);
603 607

  
604
        // `sc39`,
608
		// `url`,
609
		buff += getStringField(metadata.getWebsiteurl().getValue());
605 610

  
606
        String sc39 = metadata.getEcsc39().getValue().toString();
607
        if (sc39.equalsIgnoreCase("true") || sc39.equalsIgnoreCase("t") || sc39.contains("yes")) {
608
            sc39 = "yes";
609
        } else if (sc39.equalsIgnoreCase("false") || sc39.equalsIgnoreCase("f") || sc39.contains("no")) {
610
            sc39 = "no";
611
        }
611
		// start_year
612 612

  
613
        buff += getStringField(sc39);
613
		buff += getYearInt(metadata.getStartdate().getValue());
614 614

  
615
        // `url`,
615
		// end_year
616
		buff += getYearInt(metadata.getEnddate().getValue());
616 617

  
617
        buff += getStringField(metadata.getWebsiteurl().getValue());
618
		// duration enddate-startdate
618 619

  
619
        // start_year
620
		buff += getYearDifferenceInteger(metadata.getEnddate().getValue(), metadata.getStartdate().getValue());
620 621

  
621
        buff += getYearInt(metadata.getStartdate().getValue());
622
		// haspubs
623
		buff += getStringField("no");
622 624

  
623
        // end_year
624
        buff += getYearInt(metadata.getEnddate().getValue());
625
		// numpubs
626
		buff += getNumericField("0");
627
		// enddate
628
		buff += getNumericField(metadata.getEnddate().getValue());
629
		// startdate
630
		buff += getNumericField(metadata.getStartdate().getValue());
625 631

  
626
        // duration enddate-startdate
632
		// `daysforlastpub`,
633
		buff += getNumericField("");
634
		// `delayedpubs`,
635
		buff += getNumericField("");
636
		// `number`
637
		buff += getStringField("1");
638
		return buff;
627 639

  
628
        buff += getYearDifferenceInteger(metadata.getEnddate().getValue(), metadata.getStartdate().getValue());
640
	}
629 641

  
630
        // haspubs
631
        buff += getStringField("no");
642
	//TODO remove for production - not yet ready
643
	private String buildPerson(OafEntity data) {
632 644

  
633
        // numpubs
634
        buff += getNumericField("0");
635
        // enddate
636
        buff += getNumericField(metadata.getEnddate().getValue());
637
        // startdate
638
        buff += getNumericField(metadata.getStartdate().getValue());
645
		String buff = new String();
639 646

  
640
        // `daysforlastpub`,
641
        buff += getNumericField("");
642
        // `delayedpubs`,
643
        buff += getNumericField("");
644
        // `number`
645
        buff += getStringField("1");
646
        return buff;
647
		PersonProtos.Person person = data.getPerson();
648
		eu.dnetlib.data.proto.PersonProtos.Person.Metadata metadata = person.getMetadata();
647 649

  
648
    }
650
		person.getCoauthorsCount();
649 651

  
650
    //TODO remove for production - not yet ready
651
    private String buildPerson(OafEntity data) {
652
		// `person_id`,
653
		String full_id = getStringField(data.getId());
654
		buff += full_id;
655
		// person_result
656
		buff += full_id;
652 657

  
653
        String buff = new String();
658
		// `fullname`,
659
		buff += metadata.getFullname();
654 660

  
655
        PersonProtos.Person person = data.getPerson();
656
        eu.dnetlib.data.proto.PersonProtos.Person.Metadata metadata = person.getMetadata();
661
		// `Nationality`,
662
		buff += metadata.getNationality();
663
		// `Email`,
664
		buff += metadata.getEmail();
665
		// `Phone`,
666
		buff += metadata.getPhone();
667
		// `CoauthorsCount`
668
		buff += person.getCoauthorsCount();
669
		// `number`,
670
		buff += getStringField("1");
671
		return buff;
657 672

  
658
        person.getCoauthorsCount();
673
	}
659 674

  
660
        // `person_id`,
661
        String full_id = getStringField(data.getId());
662
        buff += full_id;
663
        // person_result
664
        buff += full_id;
675
	private String getFundingLevel(String funding_level, int level) {
665 676

  
666
        // `fullname`,
667
        buff += metadata.getFullname();
677
		if (funding_level.isEmpty()) {
678
			return NULL_STRING;
668 679

  
669
        // `Nationality`,
670
        buff += metadata.getNationality();
671
        // `Email`,
672
        buff += metadata.getEmail();
673
        // `Phone`,
674
        buff += metadata.getPhone();
675
        // `CoauthorsCount`
676
        buff += person.getCoauthorsCount();
677
        // `number`,
678
        buff += getStringField("1");
679
        return buff;
680
		}
680 681

  
681
    }
682
		if (!funding_level.contains("funding_level_" + level)) {
683
			return NULL_STRING;
684
		}
685
		String[] split = funding_level.split("funding_level_" + level);
682 686

  
683
    private String getFundingLevel(String funding_level, int level) {
687
		funding_level = split[1];
688
		split = funding_level.split("name");
689
		split = split[1].split(",");
684 690

  
685
        if (funding_level.isEmpty()) {
686
            return NULL_STRING;
691
		funding_level = split[0].replaceAll(".*:\"", "");
692
		funding_level = funding_level.replaceFirst(ENCLOSED, "");
693
		funding_level = funding_level.trim();
687 694

  
688
        }
695
		return funding_level;
696
	}
689 697

  
690
        if (!funding_level.contains("funding_level_" + level)) {
691
            return NULL_STRING;
692
        }
693
        String[] split = funding_level.split("funding_level_" + level);
698
	private String getYearDifferenceInteger(String enddate, String startdate) {
694 699

  
695
        funding_level = split[1];
696
        split = funding_level.split("name");
697
        split = split[1].split(",");
700
		if (enddate != null && !enddate.isEmpty() && startdate != null && !startdate.isEmpty()) {
698 701

  
699
        funding_level = split[0].replaceAll(".*:\"", "");
700
        funding_level = funding_level.replaceFirst(ENCLOSED, "");
701
        funding_level = funding_level.trim();
702
			String[] split = startdate.split("-");
702 703

  
703
        return funding_level;
704
    }
704
			int Startdate = Integer.parseInt(split[0]);
705 705

  
706
    private String getYearDifferenceInteger(String enddate, String startdate) {
706
			split = enddate.split("-");
707 707

  
708
        if (!enddate.isEmpty() && enddate != null && startdate != null && !startdate.isEmpty()) {
708
			int Enddate = Integer.parseInt(split[0]);
709 709

  
710
            // if (enddate != null && startdate != null&&) {
710
			int diff = Enddate - Startdate;
711
			return ENCLOSED + diff + ENCLOSED + DELIM;
712
		}
711 713

  
712
            String[] split = startdate.split("-");
714
		return ENCLOSED + NULL_NUM + ENCLOSED + DELIM;
715
	}
713 716

  
714
            int Startdate = Integer.parseInt(split[0]);
717
	private String getYearInt(String data) {
718
		if (data == null || data.isEmpty() || data.equals("-1")) {
719
			return ENCLOSED + NULL_NUM + ENCLOSED + DELIM;
720
		}
715 721

  
716
            split = enddate.split("-");
722
		String[] split = data.split("-");
717 723

  
718
            int Enddate = Integer.parseInt(split[0]);
724
		if (split != null) {
719 725

  
720
            int diff = Enddate - Startdate;
721
            return ENCLOSED + diff + ENCLOSED + DELIM;
722
        }
726
			String year = split[0];
727
			year = cleanNumber(year);
723 728

  
724
        return ENCLOSED + NULL_NUM + ENCLOSED + DELIM;
725
    }
729
			return ENCLOSED + year + ENCLOSED + DELIM;
730
		} else {
731
			return ENCLOSED + NULL_NUM + ENCLOSED + DELIM;
732
		}
726 733

  
727
    private String getYearInt(String data) {
728
        if (data == null || data.isEmpty() || data.equals("-1")) {
729
            return ENCLOSED + NULL_NUM + ENCLOSED + DELIM;
730
        }
734
	}
731 735

  
732
        String[] split = data.split("-");
736
	private String cleanNumber(String number) {
737
		number = number.replaceAll("[^A-Za-z0-9:,____]", "");
733 738

  
734
        if (split != null) {
739
		return number;
740
	}
735 741

  
736
            String year = split[0];
737
            year = cleanNumber(year);
742
	private String getStringField(String data) {
738 743

  
739
            return ENCLOSED + year + ENCLOSED + DELIM;
740
        } else {
741
            return ENCLOSED + NULL_NUM + ENCLOSED + DELIM;
742
        }
744
		if (data == null || data.isEmpty() || data.equals("")) {
743 745

  
744
    }
746
			return ENCLOSED + NULL_STRING + ENCLOSED + DELIM;
747
		} else {
745 748

  
746
    private String cleanNumber(String number) {
747
        number = number.replaceAll("[^A-Za-z0-9:,____]", "");
749
			String field = clean(data);
750
			if (field == null) {
751
				return ENCLOSED + NULL_STRING + ENCLOSED + DELIM;
752
			} else {
753
				return field + DELIM;
754
			}
755
		}
756
	}
748 757

  
749
        return number;
750
    }
758
	private String getStringDateField(String data) {
751 759

  
752
    private String getStringField(String data) {
760
		if (data == null || data.isEmpty() || data.equals("") || data.equals("-1")) {
753 761

  
754
        if (data == null || data.isEmpty() || data.equals("")) {
762
			return ENCLOSED + NULL_NUM + ENCLOSED + DELIM;
763
		} else {
755 764

  
756
            return ENCLOSED + NULL_STRING + ENCLOSED + DELIM;
757
        } else {
765
			String field = clean(data);
766
			if (field == null) {
767
				return ENCLOSED + NULL_NUM + ENCLOSED + DELIM;
768
			} else {
769
				return field + DELIM;
770
			}
771
		}
772
	}
758 773

  
759
            String field = clean(data);
760
            if (field == null) {
761
                return ENCLOSED + NULL_STRING + ENCLOSED + DELIM;
762
            } else {
763
                return field + DELIM;
764
            }
765
        }
766
    }
774
	private String getNumericField(String data) {
775
		if (data == null || data.isEmpty() || data.equals("")) {
776
			return ENCLOSED + NULL_NUM + ENCLOSED + DELIM;
777
		} else {
767 778

  
768
    private String getStringDateField(String data) {
779
			return ENCLOSED + data + ENCLOSED + DELIM;
780
		}
781
	}
769 782

  
770
        if (data == null || data.isEmpty() || data.equals("") || data.equals("-1")) {
783
	public String getId(Oaf oaf) {
784
		switch (oaf.getKind()) {
785
			case entity:
771 786

  
772
            return ENCLOSED + NULL_NUM + ENCLOSED + DELIM;
773
        } else {
787
				return cleanId(oaf.getEntity().getId());
788
			case relation:
774 789

  
775
            String field = clean(data);
776
            if (field == null) {
777
                return ENCLOSED + NULL_NUM + ENCLOSED + DELIM;
778
            } else {
779
                return field + DELIM;
780
            }
781
        }
782
    }
790
				return cleanId(oaf.getRel().getSource());
783 791

  
784
    private String getNumericField(String data) {
785
        if (data == null || data.isEmpty() || data.equals("")) {
786
            return ENCLOSED + NULL_NUM + ENCLOSED + DELIM;
787
        } else {
792
		}
793
		return null;
788 794

  
789
            return ENCLOSED + data + ENCLOSED + DELIM;
790
        }
791
    }
795
	}
792 796

  
793
    public String getId(Oaf oaf) {
794
        switch (oaf.getKind()) {
795
            case entity:
797
	public String getId(OafRel relOaf) {
798
		return cleanId(relOaf.getSource());
799
	}
796 800

  
797
                return cleanId(oaf.getEntity().getId());
798
            case relation:
801
	public static String clean(String value) {
802
		if (value != null) {
803
			// TODO DO NOT CHANGE THIS: IT REMOVES ID PREFIX ( 5|datacite____::
804
			// to datacite____:: )
805
			// AND REPLACES OCCURENCES OF DELIM CHARS IN DATA
806
			value = value.replaceFirst(".*\\|", "");
807
			value = value.replaceAll(DELIM, "");
808
			value = value.replaceAll(ENCLOSED, "");
809
			value = value.replaceAll("\\r\\n|\\r|\\n", " ");
799 810

  
800
                return cleanId(oaf.getRel().getSource());
811
			value = value.replaceAll("\\s+", " ");
812
			value = value.replaceAll("(\\r|\\n)", " ");
813
			value = value.replaceAll("\\t", " ");
801 814

  
802
        }
803
        return null;
804 815

  
805
    }
816
			// value = value.replaceAll("[^A-Za-z0-9:,____-;:]", " ");
817
			value = value.trim();
806 818

  
807
    public String getId(OafRel relOaf) {
808
        return cleanId(relOaf.getSource());
809
    }
819
		}
820
		if (value == null) {
821
			return null;
822
		}
823
		return ENCLOSED + value + ENCLOSED;
810 824

  
811
    public static String clean(String value) {
812
        if (value != null) {
813
            // TODO DO NOT CHANGE THIS: IT REMOVES ID PREFIX ( 5|datacite____::
814
            // to datacite____:: )
815
            // AND REPLACES OCCURENCES OF DELIM CHARS IN DATA
816
            value = value.replaceFirst(".*\\|", "");
817
            value = value.replaceAll(DELIM, "");
818
            value = value.replaceAll(ENCLOSED, "");
819
            value = value.replaceAll("\\r\\n|\\r|\\n", " ");
825
	}
820 826

  
821
            value = value.replaceAll("\\s+", " ");
822
            value = value.replaceAll("(\\r|\\n)", " ");
823
            value = value.replaceAll("\\t", " ");
827
	public static String cleanId(String value) {
828
		if (value != null) {
829
			// TODO DO NOT CHANGE THIS: IT REMOVES ID PREFIX ( 5|datacite____::
824 830

  
825 831

  
826
            // value = value.replaceAll("[^A-Za-z0-9:,____-;:]", " ");
827
            value = value.trim();
832
			// to datacite____:: )
833
			// AND REPLACES OCCURENCES OF DELIM CHARS IN DATA
834
			value = value.replaceFirst(".*\\|", "");
835
			value = value.replaceAll("\n", "");
836
			value = value.replaceAll(DELIM, "");
837
			value = value.replaceAll(ENCLOSED, "");
838
			value = value.trim();
828 839

  
829
        }
830
        if (value == null) {
831
            return null;
832
        }
833
        return ENCLOSED + value + ENCLOSED;
840
		}
841
		if (value == null) {
842
			return null;
843
		}
844
		return ENCLOSED + value + ENCLOSED;
834 845

  
835
    }
846
	}
836 847

  
837
    public static String cleanId(String value) {
838
        if (value != null) {
839
            // TODO DO NOT CHANGE THIS: IT REMOVES ID PREFIX ( 5|datacite____::
848
	public long DATEDIFF(String startDate, String endDate) {
849
		long MILLISECS_PER_DAY = 24 * 60 * 60 * 1000;
850
		long days = 0l;
851
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); // "dd/MM/yyyy HH:mm:ss");
852
		// <startdate>2011-09-01</startdate>
853
		// <enddate>2015-08-31</enddate>
854
		Date dateIni = null;
855
		Date dateFin = null;
840 856

  
857
		if (startDate == null || startDate.isEmpty() || endDate == null || endDate.isEmpty()) {
858
			return 0;
859
		}
860
		try {
861
			dateIni = (Date) format.parse(startDate);
862
			dateFin = (Date) format.parse(endDate);
863
			days = (dateFin.getTime() - dateIni.getTime()) / MILLISECS_PER_DAY;
864
		} catch (Exception e) {
865
			log.error(e.toString());
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff