Project

General

Profile

« Previous | Next » 

Revision 37693

Added by Eri Katsari almost 9 years ago

funding tree change for beta

View differences:

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();
41 40

  
41
    private FundingParser fundingParser;
42 42

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

  
50
    ;
46 51

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

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

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

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

  
58
					case organization:
63
                    case organization:
59 64

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

  
62
					case project:
67
                    case project:
63 68

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

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

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

  
81
		}
86
        }
82 87

  
83
		return null;
88
        return null;
84 89

  
85
	}
90
    }
86 91

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

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

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

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

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

  
103 108

  
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:
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:
119 124

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

  
123
	}
128
    }
124 129

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

  
129 134

  
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));
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));
137 142

  
138 143

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

  
142 147

  
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>();
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>();
146 151

  
147 152

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

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

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

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

  
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();
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();
164 169

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

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

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

  
174
	}
179
    }
175 180

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

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

  
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;
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;
192 197

  
193
	}
198
    }
194 199

  
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>();
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>();
198 203

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

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

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

  
208
	}
213
    }
209 214

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

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

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

  
219 224

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

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

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

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

  
236
	}
241
    }
237 242

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

  
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
	}
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
    }
245 250

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

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

  
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
		}
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
        }
259 264

  
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
	}
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
    }
269 274

  
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();
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();
274 279

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

  
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 + " ";
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 + " ";
286 291

  
287
					}
292
                    }
288 293

  
289
				}
290
			}
294
                }
295
            }
291 296

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

  
299
		return rels;
304
        return rels;
300 305

  
301
	}
306
    }
302 307

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

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

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

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

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

  
317 322

  
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
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
325 330

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  
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`,
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`,
374 379

  
375 380

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

  
378 383

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

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

  
384
	}
389
    }
385 390

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  
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#!
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#!
444 449

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

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

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

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

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

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

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

  
469
		// bestlicense
474
        // bestlicense
470 475

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

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

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

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

  
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
			{
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
            {
490 495

  
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);
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);
499 504

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

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

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

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

  
513
	}
518
    }
514 519

  
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
	}
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
    }
523 528

  
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
	}
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
    }
538 543

  
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
			}
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
            }
547 552

  
548
		}
553
        }
549 554

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

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

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

  
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;
562
        Project project = data.getProject();
563
        eu.dnetlib.data.proto.ProjectProtos.Project.Metadata metadata = project.getMetadata();
564
        // project_organizations
564 565

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

  
570
		// `acronym`,
571
		buff += getStringField(acronym);
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
        }
572 576

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

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

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

  
580 585

  
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
			buff += this.fundingParser.getFundingInfo(fundList.get(0).getValue());
586
        if (!fundList.isEmpty()) // `funding_lvl0`,
587
        {
588
            //TODO funder + 3 funding levels
590 589

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

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

  
596
        }
596 597

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

  
604
		// `sc39`,
605
		buff += getStringField(sc39);
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
        //}
606 603

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

  
610
		// start_year
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 612

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

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

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

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

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

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

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

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

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

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

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

  
649
		person.getCoauthorsCount();
648
    }
650 649

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

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

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

  
672
	}
658
        person.getCoauthorsCount();
673 659

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

  
676
		if (funding_level.isEmpty()) {
677
			return NULL_STRING;
666
        // `fullname`,
667
        buff += metadata.getFullname();
678 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
		if (!funding_level.contains("funding_level_" + level)) {
682
			return NULL_STRING;
683
		}
684
		String[] split = funding_level.split("funding_level_" + level);
681
    }
685 682

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

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

  
694
		return funding_level;
695
	}
688
        }
696 689

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

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

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

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

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

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

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

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

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

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

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

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

  
728
			return ENCLOSED + year + ENCLOSED + DELIM;
729
		} else {
730
			return ENCLOSED + NULL_NUM + ENCLOSED + DELIM;
731
		}
724
        return ENCLOSED + NULL_NUM + ENCLOSED + DELIM;
725
    }
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
	private String cleanNumber(String number) {
736
		number = number.replaceAll("[^A-Za-z0-9:,____]", "");
732
        String[] split = data.split("-");
737 733

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

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

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

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

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

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

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

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

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

  
773
	private String getNumericField(String data) {
774
		if (data == null || data.isEmpty() || data.equals("")) {
775
			return ENCLOSED + NULL_NUM + ENCLOSED + DELIM;
776
		} else {
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
    }
777 767

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

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

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

  
789
				return cleanId(oaf.getRel().getSource());
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 783

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

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

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

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

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

  
802
        }
803
        return null;
814 804

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

  
818
		}
819
		if (value == null) {
820
			return null;
821
		}
822
		return ENCLOSED + value + ENCLOSED;
807
    public String getId(OafRel relOaf) {
808
        return cleanId(relOaf.getSource());
809
    }
823 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
	public static String cleanId(String value) {
827
		if (value != null) {
828
			// TODO DO NOT CHANGE THIS: IT REMOVES ID PREFIX ( 5|datacite____::
821
            value = value.replaceAll("\\s+", " ");
822
            value = value.replaceAll("(\\r|\\n)", " ");
823
            value = value.replaceAll("\\t", " ");
829 824

  
830 825

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

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

  
845
	}
835
    }
846 836

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

  
856
		if (startDate == null || startDate.isEmpty() || endDate == null || endDate.isEmpty()) {
857
			return 0;
858
		}
859
		try {
860
			dateIni = (Date) format.parse(startDate);
861
			dateFin = (Date) format.parse(endDate);
862
			days = (dateFin.getTime() - dateIni.getTime()) / MILLISECS_PER_DAY;
863
		} catch (Exception e) {
864
			log.error(e.toString());
865
			return 0;
866
		}
867 841

  
868
		return days;
869
	}
842
            // to datacite____:: )
843
            // AND REPLACES OCCURENCES OF DELIM CHARS IN DATA
844
            value = value.replaceFirst(".*\\|", "");
845
            value = value.replaceAll("\n", "");
846
            value = value.replaceAll(DELIM, "");
847
            value = value.replaceAll(ENCLOSED, "");
848
            value = value.trim();
870 849

  
871
	public String getDELIM() {
872
		return DELIM;
873
	}
850
        }
851
        if (value == null) {
852
            return null;
853
        }
854
        return ENCLOSED + value + ENCLOSED;
874 855

  
875
	public void setDELIM(String dELIM) {
876
		DELIM = dELIM;
877
	}
856
    }
878 857

  
879
	public String getNULL_STRING() {
880
		return NULL_STRING;
881
	}
858
    public long DATEDIFF(String startDate, String endDate) {
859
        long MILLISECS_PER_DAY = 24 * 60 * 60 * 1000;
860
        long days = 0l;
861
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); // "dd/MM/yyyy HH:mm:ss");
862
        // <startdate>2011-09-01</startdate>
863
        // <enddate>2015-08-31</enddate>
864
        Date dateIni = null;
865
        Date dateFin = null;
882 866

  
883
	public void setNULL_STRING(String nULL_STRING) {
884
		NULL_STRING = nULL_STRING;
885
	}
867
        if (startDate == null || startDate.isEmpty() || endDate == null || endDate.isEmpty()) {
868
            return 0;
869
        }
870
        try {
871
            dateIni = (Date) format.parse(startDate);
872
            dateFin = (Date) format.parse(endDate);
873
            days = (dateFin.getTime() - dateIni.getTime()) / MILLISECS_PER_DAY;
874
        } catch (Exception e) {
875
            log.error(e.toString());
876
            return 0;
877
        }
886 878

  
887
	public String getNULL_NUM() {
888
		return NULL_NUM;
889
	}
879
        return days;
880
    }
890 881

  
891
	public void setNULL_NUM(String nULL_NUM) {
892
		NULL_NUM = nULL_NUM;
893
	}
882
    public String getDELIM() {
883
        return DELIM;
884
    }
894 885

  
895
	public String getENCLOSED() {
896
		return ENCLOSED;
897
	}
886
    public void setDELIM(String dELIM) {
887
        DELIM = dELIM;
888
    }
898 889

  
899
	public void setENCLOSED(String eNCLOSED) {
900
		ENCLOSED = eNCLOSED;
901
	}
890
    public String getNULL_STRING() {
891
        return NULL_STRING;
892
    }
902 893

  
894
    public void setNULL_STRING(String nULL_STRING) {
895
        NULL_STRING = nULL_STRING;
896
    }
897

  
898
    public String getNULL_NUM() {
899
        return NULL_NUM;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff