Project

General

Profile

« Previous | Next » 

Revision 39938

Added by Eri Katsari over 8 years ago

updates for lod

View differences:

Serializer.java
7 7
import eu.dnetlib.data.proto.FieldTypeProtos.Qualifier;
8 8
import eu.dnetlib.data.proto.FieldTypeProtos.StringField;
9 9
import eu.dnetlib.data.proto.FieldTypeProtos.StructuredProperty;
10
import eu.dnetlib.data.proto.OafProtos;
10 11
import eu.dnetlib.data.proto.OafProtos.Oaf;
11 12
import eu.dnetlib.data.proto.OafProtos.OafEntity;
12 13
import eu.dnetlib.data.proto.OafProtos.OafRel;
......
14 15
import eu.dnetlib.data.proto.PersonProtos;
15 16
import eu.dnetlib.data.proto.ProjectProtos.Project;
16 17
import eu.dnetlib.data.proto.RelTypeProtos.RelType;
18
import eu.dnetlib.data.proto.ResultProtos;
17 19
import eu.dnetlib.data.proto.ResultProtos.Result;
18 20
import eu.dnetlib.data.proto.ResultProtos.Result.Instance;
19 21
import org.apache.log4j.Logger;
......
28 30
 */
29 31
public class Serializer {
30 32

  
31
	private static String DELIM;
32
	private Logger log = Logger.getLogger(this.getClass());
33
	private String NULL_STRING = null;
34
	private String NULL_NUM = "0";
33
    private static String DELIM;
34
    private Logger log = Logger.getLogger(this.getClass());
35
    private String NULL_STRING = null;
36
    private String NULL_NUM = "0";
35 37

  
36
	private static String ENCLOSED;
38
    private static String ENCLOSED;
37 39
    private FundingParser fundingParser = new FundingParser();
38 40

  
39 41

  
40
	public Serializer() {
41
	}
42
    public Serializer() {
43
    }
42 44

  
45
    public String serialize(Oaf oaf) {
43 46

  
44
	public String serialize(Oaf oaf) {
47
        switch (oaf.getKind()) {
48
            case entity:
49
                OafEntity valueEntity = oaf.getEntity();
45 50

  
46
		switch (oaf.getKind()) {
47
			case entity:
48
				OafEntity valueEntity = oaf.getEntity();
51
                switch (valueEntity.getType()) {
52
                    case datasource:
49 53

  
50
				switch (valueEntity.getType()) {
51
					case datasource:
54
                        return buildDatasource(valueEntity);
52 55

  
53
						return buildDatasource(valueEntity);
56
                    case organization:
54 57

  
55
					case organization:
58
                        return buildOrganization(valueEntity);
56 59

  
57
						return buildOrganization(valueEntity);
60
                    case project:
58 61

  
59
					case project:
62
                        return buildProject(valueEntity);
63
                    case result:
60 64

  
61
						return buildProject(valueEntity);
62
					case result:
65
                        return buildResult(valueEntity);
66
                    case person:
67
                        return buildPerson(valueEntity);
68
                    default:
69
                        log.error("wrong type");
70
                        break;
71
                }
72
                break;
73
            case relation:
74
                OafRel valueRel = oaf.getRel();
63 75

  
64
						return buildResult(valueEntity);
65
					case person:
66
						return buildPerson(valueEntity);
67
					default:
68
						log.error("wrong type");
69
						break;
70
				}
71
				break;
72
			case relation:
73
				OafRel valueRel = oaf.getRel();
76
                return buildRel(valueRel);
74 77

  
75
				return buildRel(valueRel);
78
        }
76 79

  
77
		}
80
        return null;
78 81

  
79
		return null;
82
    }
80 83

  
81
	}
84
    public String serialize(OafRel oaf) {
82 85

  
83
	public String serialize(OafRel oaf) {
86
        switch (oaf.getRelType()) {
87
            case resultProject:
84 88

  
85
		switch (oaf.getRelType()) {
86
			case resultProject:
89
                return getResultProject(oaf);
87 90

  
88
				return getResultProject(oaf);
91
            default:
92
                return buildRel(oaf);
93
        }
94
    }
89 95

  
90
			default:
91
				return buildRel(oaf);
92
		}
93
	}
96
    private String buildRel(OafRel Rel) {
97
        return getStringField(Rel.getTarget());
98
    }
94 99

  
95
	private String buildRel(OafRel Rel) {
96
		return getStringField(Rel.getTarget());
97
	}
98 100

  
101
    private String getResultProject(OafRel oaf) {
102
        String buff = new String();
103
        String result = oaf.getTarget();
99 104

  
100
	private String getResultProject(OafRel oaf) {
101
		String buff = new String();
102
		String result = oaf.getTarget();
103 105

  
106
        buff += getStringField(result);
107
        //   is declared as int!!!
108
        long diff = DATEDIFF(oaf.getResultProject().getOutcome().getRelMetadata().getEnddate(), oaf.getResultProject().getOutcome().getRelMetadata().getStartdate());
109
        if (diff < 0) {
110
            diff = 0;
111
        }
112
        buff += getNumericField(String.valueOf(diff));
104 113

  
105
		buff += getStringField(result);
106
		//   is declared as int!!!
107
		long diff = DATEDIFF(oaf.getResultProject().getOutcome().getRelMetadata().getEnddate(), oaf.getResultProject().getOutcome().getRelMetadata().getStartdate());
108
		if (diff < 0) {
109
			diff = 0;
110
		}
111
		buff += getNumericField(String.valueOf(diff));
114
        return buff;
115
    }
112 116

  
113 117

  
114
		return buff;
115
	}
118
    private String buildDatasource(OafEntity data) {
116 119

  
120
        String buff = new String();
117 121

  
118
	public static boolean isNumeric(String str) {
122
        Datasource d = data.getDatasource();
119 123

  
120
		str = str.replaceAll("[^A-Za-z0-9 ]", "");
121
		str = str.replaceAll(" ", "");
122
		return str.matches("-?\\d+(\\.\\d+)?"); // match a number with optional
123
		// '-' and decimal.
124
	}
124
        Metadata metadata = d.getMetadata();
125 125

  
126
	//   there are topics with "null" as value -> replace them
127
	private boolean isValidTopic(String t) {
126
        //`original Id`
127
        String originalId = new String();
128 128

  
129
		if (t == null || t.isEmpty()) {
130
			return false;
131
		}
129
        for (String oid : data.getOriginalIdList()) {
130
            originalId += oid + ";";
131
        }
132 132

  
133
		if (t.equals("") || t.equals(" ")) {
134
			return false;
135
		}
136
		if (t.equals("null") || t.equals("Null") || t.equals("NULL")) {
137
			return false;
138
		}
133
        buff += getStringField(originalId);
139 134

  
140
		if (t.equals(ENCLOSED + ENCLOSED + DELIM) || t.equals(ENCLOSED + NULL_STRING + ENCLOSED + DELIM)) {
141
			return false;
142
		}
143
		// skip dedups
144
		if (t.contains("ddc:")) {
135
        //dateOfCollection
136
        buff += getStringDateField(data.getDateofcollection());
145 137

  
146
			return false;
147
		}
148
		return true;
149
	}
138
        //Provider Type
139
        if (metadata.hasDatasourcetype()) {
140
            buff += getStringField(metadata.getDatasourcetype().getClassname().replaceFirst(".*::", ""));
141
        } else {
142
            buff += getStringField(null);
143
        }
150 144

  
145
        //Compatibility
146
        buff += getStringField(metadata.getOpenairecompatibility().getClassname());
151 147

  
152
	private String buildDatasource(OafEntity data) {
148
        //Official Name
149
        buff += getStringField(metadata.getOfficialname().getValue());
153 150

  
154
		String buff = new String();
151
        // English Name
152
        buff += getStringField(metadata.getEnglishname().getValue());
155 153

  
156
		Datasource d = data.getDatasource();
154
        //Website URL
155
        buff += getStringField(metadata.getWebsiteurl().getValue());
157 156

  
158
		Metadata metadata = d.getMetadata();
157
        //LogoURL
158
        buff += getStringField(metadata.getLogourl().getValue());
159 159

  
160
		//`original Id`
161
		String originalId = new String();
160
        //Email
161
        buff += getStringField(metadata.getContactemail().getValue());
162 162

  
163
		for (String oid : data.getOriginalIdList()) {
164
			originalId += oid;
165
			break;
166
		}
163
        //Namespaceprefix
164
        buff += getStringField(metadata.getNamespaceprefix().getValue());
167 165

  
168
		buff += getStringField(originalId);
169
		//dateOfCollection
170
		buff += getStringDateField(data.getDateofcollection());
166
        // latitude
167
        buff += getStringField(metadata.getLatitude().getValue());
171 168

  
172
		// name
173
		if (metadata.getOfficialname().getValue().equalsIgnoreCase("unknown")) {
174
			buff += getStringField("Unknown Repository");
175
		} else {
176
			buff += getStringField(metadata.getOfficialname().getValue());
177
		}
178
		// type
169
        // longtitude
170
        buff += getStringField(metadata.getLongitude().getValue());
179 171

  
180
		if (metadata.hasDatasourcetype())
172
        // dateofvalidation,
173
        buff += getStringField(metadata.getDateofvalidation().getValue());
181 174

  
182
		{
183
			buff += getStringField(metadata.getDatasourcetype().getClassname().replaceFirst(".*::", ""));
175
        //Description
176
        buff += getStringField(metadata.getDescription().getValue());
184 177

  
185
		} else {
186
			buff += getStringField(null);
187
		}
188
		//languages
189
		String languages = new String();
190
		for (StringField lang : metadata.getOdlanguagesList()) {
191
			languages += lang.getValue() + ";";
192
		}
193
		buff += getStringField(languages);
194
		// compatibility,
195
		buff += getStringField(metadata.getOpenairecompatibility().getClassname());
178
        //subjects
179
        String subj = new String();
180
        for (StructuredProperty s : metadata.getSubjectsList()) {
181
            subj += s.getValue() + ';';
196 182

  
197
		// latitude
198
		buff += getStringField(metadata.getLatitude().getValue());
183
        }
199 184

  
200
		// longtitude
201
		buff += getStringField(metadata.getLongitude().getValue());
185
        //subjects
186
        buff += getStringField(subj);
202 187

  
203
		// dateofvalidation,
204
		buff += getStringField(metadata.getDateofvalidation().getValue());
188
        //Number of items
189
        buff += getStringField(metadata.getOdnumberofitems().getValue());
205 190

  
191
        //Date of number of items
192
        buff += getStringField(metadata.getOdnumberofitemsdate().getValue());
206 193

  
207
		// Website URL
208
		buff += getStringField(metadata.getWebsiteurl().getValue());
209
		// certificates
210
		buff += getStringField(metadata.getCertificates().getValue());
211
		// /citation guideline
212
		buff += getStringField(metadata.getCitationguidelineurl().getValue());
194
        // Policies
195
        buff += getStringField(metadata.getOdpolicies().getValue());
213 196

  
214
		// contact mail
215
		buff += getStringField(metadata.getContactemail().getValue());
197
        //languages
198
        String languages = new String();
199
        for (StringField lang : metadata.getOdlanguagesList()) {
200
            languages += lang.getValue() + ";";
201
        }
202
        buff += getStringField(languages);
216 203

  
217
		// isDataProvider
218
		buff += getStringField(String.valueOf(metadata.getDataprovider().getValue()));
219
		//Description
220
		buff += getStringField(metadata.getDescription().getValue());
221
		//EnglishName
222
		buff += getStringField(metadata.getEnglishname().getValue());
223
		//access restriction
224
		buff += getStringField(metadata.getDatabaseaccessrestriction().getValue());
225
		//logoURL
226
		buff += getStringField(metadata.getLogourl().getValue());
227
		//mission statament
228
		buff += getStringField(metadata.getMissionstatementurl().getValue());
229
		//namespace prefix
230
		buff += getStringField(metadata.getNamespaceprefix().getValue());
231
		//number of items
232
		buff += getStringField(metadata.getOdnumberofitems().getValue());
233
		//OD policies
234
		buff += getStringField(metadata.getOdpolicies().getValue());
235
		//subjects
236 204

  
205
        // Content type
206
        String contentType = new String();
207
        for (StringField c : metadata.getOdcontenttypesList()) {
208
            contentType += c.getValue() + ";";
209
        }
210
        buff += getStringField(contentType);
237 211

  
238
		String subj = new String();
239
		for (StructuredProperty s : metadata.getSubjectsList()) {
240
			subj += s.getValue() + ';';
212
        //Access info package
213
        String accessInfo = new String();
214
        for (StringField c : metadata.getAccessinfopackageList()) {
215
            accessInfo += c.getValue() + ";";
216
        }
217
        buff += getStringField(accessInfo);
241 218

  
242
		}
243
		//subjects
244
		buff += getStringField(subj);
219
        //Release start date
220
        buff += getStringField(metadata.getReleasestartdate().getValue());
245 221

  
222
        //Release end date
223
        buff += getStringField(metadata.getReleaseenddate().getValue());
246 224

  
247
		return buff;
248
	}
249
	/*Legal short name
250
	Legal name
251
	Web site url  
252
	logo url
253
*/
225
        //Mission statement url
226
        buff += getStringField(metadata.getMissionstatementurl().getValue());
254 227

  
255
	private String buildOrganization(OafEntity data) {
228
        //Data provider
229
        buff += getStringField(String.valueOf(metadata.getDataprovider().getValue()));
256 230

  
257
		String buff = new String();
231
        //Service provider
232
        buff += getStringField(String.valueOf(metadata.getServiceprovider().getValue()));
258 233

  
259
		Organization organization = data.getOrganization();
260
		eu.dnetlib.data.proto.OrganizationProtos.Organization.Metadata metadata = organization.getMetadata();
234
        //Database access type
235
        buff += getStringField(metadata.getDatabaseaccessrestriction().getValue());
261 236

  
262
		//`original Id`
263
		String originalId = new String();
237
        //Data upload type
238
        buff += getStringField(metadata.getDatauploadtype().getValue());
264 239

  
265
		for (String oid : data.getOriginalIdList()) {
266
			originalId += oid;
267
			break;
268
		}
240
        //Data upload restrictions
241
        buff += getStringField(metadata.getDatauploadrestriction().getValue());
269 242

  
270
		buff += getStringField(originalId);
271
		//dateOfCollection
272
		buff += getStringDateField(data.getDateofcollection());
243
        //Versioning
244
        buff += getStringField(String.valueOf(metadata.getVersioning().getValue()));
273 245

  
246
        //Citation guideline url
247
        buff += getStringField(String.valueOf(metadata.getCitationguidelineurl().getValue()));
274 248

  
275
		//getLegalshortname
276
		buff += getStringField(metadata.getLegalshortname().getValue());
277
		// `name`,
278
		buff += getStringField(metadata.getLegalname().getValue());
279
		//website URL
280
		buff += getStringField(metadata.getWebsiteurl().getValue());
281
		//logourl
282
		buff += getStringField(metadata.getLogourl().getValue());
283
		// `country`,
284
		buff += getStringField(metadata.getCountry().getClassname());
249
        //Quality management kind
250
        buff += getStringField(String.valueOf(metadata.getQualitymanagementkind().getValue()));
285 251

  
252
        //PID systems
253
        buff += getStringField(metadata.getPidsystems().getValue());
286 254

  
287
		return buff;
255
        //Certificates
256
        buff += getStringField(metadata.getCertificates().getValue());
288 257

  
289
	}
290
/*
258
        //Policies
259
        String policies = new String();
260
        for (FieldTypeProtos.KeyValue property : metadata.getPoliciesList()) {
261
            policies += property.getValue() + ";";
262
        }
263
        buff += getStringField(policies);
291 264

  
292
	Title DateOfAcceptance
265
        return buff;
266
    }
293 267

  
294
	Publisher(optional)
295 268

  
296
	Description PID
297
	Language RelevantDate
298
	Subject Instance
299
	ExternalReference Source
300
	Format Context
301
	Country
302
	journalName     
269
    private String buildOrganization(OafEntity data) {
303 270

  
304
	Best License
305
Description                
306
Source                               
307
Format      
308
Journal   
271
        String buff = new String();
309 272

  
310
                 
311
title                                   
312
ISSN                                   
313
embargoEndDate     
314
hasAuthor
315
isRelatedTo
273
        Organization organization = data.getOrganization();
274
        eu.dnetlib.data.proto.OrganizationProtos.Organization.Metadata metadata = organization.getMetadata();
316 275

  
317
Resource Type
318
Device
319
Size
320
Version
321
Last Metadata Update
322
Metadata Version
276
        //`original Id`
277
        String originalId = new String();
278
        for (String oid : data.getOriginalIdList()) {
279
            originalId += oid + ";";
280
        }
323 281

  
324
*/
325 282

  
326
	private String buildResult(OafEntity data) {
283
        buff += getStringField(originalId);
284
        //dateOfCollection
285
        buff += getStringDateField(data.getDateofcollection());
327 286

  
328 287

  
329
		String buff = new String();
288
        //getLegalshortname
289
        buff += getStringField(metadata.getLegalshortname().getValue());
290
        // `name`,
291
        buff += getStringField(metadata.getLegalname().getValue());
292
        //website URL
293
        buff += getStringField(metadata.getWebsiteurl().getValue());
294
        //logourl
295
        buff += getStringField(metadata.getLogourl().getValue());
296
        // `country`,
297
        buff += getStringField(metadata.getCountry().getClassname());
330 298

  
331
		Result result = data.getResult();
332
		eu.dnetlib.data.proto.ResultProtos.Result.Metadata metadata = result.getMetadata();
333 299

  
300
        return buff;
334 301

  
335
		//`original Id`
336
		String originalId = new String();
302
    }
337 303

  
338
		for (String oid : data.getOriginalIdList()) {
339
			originalId += oid;
340
			break;
341
		}
304
    private String buildResult(OafEntity data) {
305
        String buff = new String();
342 306

  
343
		buff += getStringField(originalId);
307
        Result result = data.getResult();
308
        eu.dnetlib.data.proto.ResultProtos.Result.Metadata metadata = result.getMetadata();
344 309

  
345
		//dateOfCollection
346
		buff += getStringDateField(data.getDateofcollection());
310
        //`original Id`
311
        String originalId = new String();
347 312

  
348
		//   titleString
313
        for (String oid : data.getOriginalIdList()) {
314
            originalId += oid + ";";
315
        }
349 316

  
350
		String titleString = new String();
351
		String alternativeTitles = new String();
317
        buff += getStringField(originalId);
352 318

  
319
        //dateOfCollection
320
        buff += getStringDateField(data.getDateofcollection());
321
        //   titleString
322
        String titleString = new String();
323
        String alternativeTitles = new String();
353 324

  
354
		for (int i = 0; i < metadata.getTitleList().size(); i++) {
355
			StructuredProperty title = metadata.getTitleList().get(i);
356
			if (i == 0) {
357
				titleString = title.getValue().replaceAll("\\s+", " ");
358
				titleString = titleString.replaceAll("\n", " ");
359
			} else {
360
				alternativeTitles += title.getValue().replaceAll("\\s+", " ") + " ; ";
361
				alternativeTitles = alternativeTitles.replaceAll("\n", " ");
362
			}
363
			break;
364
		}
365
		//  pubtitle
366
		buff += getStringField(titleString);
367
		//  alternative titles
368
		//buff += getStringField(alternativeTitles);    //  null#!
325
        for (int i = 0; i < metadata.getTitleList().size(); i++) {
326
            StructuredProperty title = metadata.getTitleList().get(i);
327
            if (i == 0) {
328
                titleString = title.getValue().replaceAll("\\s+", " ");
329
                titleString = titleString.replaceAll("\n", " ");
330
            } else {
331
                alternativeTitles += title.getValue().replaceAll("\\s+", " ") + " ; ";
332
                alternativeTitles = alternativeTitles.replaceAll("\n", " ");
333
            }
334
            break;
335
        }
369 336

  
370
		//   format
371
		String formatString = new String();
372
		for (StringField format : metadata.getFormatList()) {
373
			formatString = format.getValue();
374
			break;
375
		}
337
        //  pubtitle
338
        buff += getStringField(titleString);
376 339

  
377
		buff += getStringField(formatString);
378
		// publisher
340
        // alternative titles
341
        //buff += getStringField(alternativeTitles);    //  null#!
342
        // date of acceptance CHANGED THIS TO DATE FORMAT
343
        buff += getStringDateField(metadata.getDateofacceptance().getValue());
379 344

  
380
		buff += getStringField(metadata.getPublisher().getValue());
381
		// journal
345
        // publisher
346
        buff += getStringField(metadata.getPublisher().getValue());
382 347

  
383
		buff += getStringField(metadata.getJournal().getName().replaceAll("\n", " "));  //#null#!
384
		// isssnLinking
385
		buff += getStringField(metadata.getJournal().getIssnLinking());  //#null#!
386
		// year
387
		buff += getYearInt(metadata.getDateofacceptance().getValue());
388 348

  
389
		// date CHANGED THIS TO DATE FORMAT
390
		buff += getStringDateField(metadata.getDateofacceptance().getValue());
349
        //PID
350
        String pids = new String();
351
        for (StructuredProperty p : data.getPidList()) {
352
            pids += p.getValue() + ";";
353
        }
354
        buff += getStringField(pids);
391 355

  
392
		// access_mode,
393
		buff += getStringField(getAccessMode(result));
356
        //language
357
        buff += getStringField(metadata.getLanguage().getClassname());
394 358

  
395
		// bestlicense
359
        // RelevantDate
360
        String reldate = new String();
396 361

  
397
		buff += getStringField(getBestLicense(result));
398
		// type
399
		buff += getStringField(metadata.getResulttype().getClassname());
400
		// embargo_end_date
401
		buff += getStringField(metadata.getEmbargoenddate().getValue());
362
        for (StructuredProperty p : metadata.getRelevantdateList()) {
363
            reldate += p.getValue();
364
            break;
365
        }
366
        buff += getStringField(reldate);
402 367

  
403
		//language
368
        //Subject
369
        String subjects = new String();
370
        for (StructuredProperty subj : metadata.getSubjectList()) {
404 371

  
405
		buff += getStringField(metadata.getLanguage().getClassname());
406
		//classification
372
            if (isValidTopic(subj.getValue())) {
373
                if (!isNumeric(subj.getValue())) {
374
                    subjects += subj.getValue() + ";";
375
                }
376
            }
377
        }
407 378

  
408
		String classification = new String();
409
		for (Instance instance : (result.getInstanceList())) {
379
        buff += subjects;
410 380

  
411
			if (instance.getInstancetype().getClassname() != null && !instance.getInstancetype().getClassname().isEmpty()) {
412
				classification += instance.getInstancetype().getClassname() + ';';
413
			}
381
        // TODO Instance
382
        // buff += getStringField();
414 383

  
415
		}
416
		buff += getStringField(classification);
384
        //TODO ExternalReference
417 385

  
418 386

  
419
		String hostedBy = new String();
420
		//  hosted by
421
		for (Instance instance : (result.getInstanceList())) {
387
        //Source
388
        String source = new String();
389
        for (StringField s : metadata.getSourceList()) {
390
            source += s.getValue() + ";";
391
        }
422 392

  
393
        buff += getStringField(source);
423 394

  
424
			String host = instance.getHostedby().getKey();
425
			if (host != null && !host.isEmpty()) {
426
				hostedBy += host + ";";
427
			}
428
		}
429 395

  
430
		buff += getStringField(hostedBy);
396
        //TODO Format     
397
        buff += getStringField("");
398
        //DOES NOT EXIST
399
          /*String formatString = new String();
400
        for (StringField format : metadata.getFormatList()) {
401
            formatString = format.getValue();
402
            break;}
403
               buff += getStringField(formatString);
404
        }*/
405
        //Context
406
        String context = new String();
407
        for (Result.Context s : metadata.getContextList()) {
408
            context += s.getId() + ";";
409
        }
410
        buff += getStringField(context);
431 411

  
432
		String collectedFrom = new String();
433
		//TODO  collectedfrom
412
        //country
413
        String country = new String();
414
        for (Qualifier s : metadata.getCountryList()) {
415
            country += s.getClassname() + ";";
416
        }
434 417

  
435
		for (FieldTypeProtos.KeyValue collectedFromValue : (data.getCollectedfromList())) {
418
        buff += getStringField(country);
436 419

  
437
			String host = collectedFromValue.getKey();
438
			if (host != null && !host.isEmpty()) {
439
				collectedFrom += host + ';';
420
        // access_mode,
421
        buff += getStringField(getAccessMode(result));
422
        //Best License
423
        buff += getStringField(getBestLicense(result));
424
        //Description
425
        String description = new String();
440 426

  
441
			}
442
		}
427
        for (StringField desc : metadata.getDescriptionList()) {
428
            description += desc;
429
            break;
430
        }
431
        buff += getStringField(description);
432
        //Journal  
433
        buff += getStringField(metadata.getJournal().getName().replaceAll("\n", " "));  //#null#!
443 434

  
444
		buff += getStringField(collectedFrom);
435
        //journalName                     
436
        buff += getStringField(metadata.getJournal().getName().replaceAll("\n", " "));  //#null#!
445 437

  
446
		String subjects = new String();
447
		for (StructuredProperty subj : metadata.getSubjectList()) {
438
        // TODO ERI SOS : HERE IN GET JOUTNAL. GET DATA INFO I CAN FIND PROVENANCE AND SIMILARITY
448 439

  
449
			if (isValidTopic(subj.getValue())) {
450
				if (!isNumeric(subj.getValue())) {
451
					subjects += subj.getValue() + ";";
452
				}
453
			}
454
		}
440
        //ISSN                                  
441
        buff += getStringField(metadata.getJournal().getIssnLinking());
455 442

  
456
		buff += subjects;
443
        //embargoEndDate    
444
        buff += getStringField(metadata.getEmbargoenddate().getValue());
457 445

  
458
		// `authors`,
459
		int authors = 0;
460
		String delayed = "no";
461 446

  
462
		for (OafRel rel : data.getCachedRelList()) {
447
        // `authors`,
448
        int authors = 0;
449
        String delayed = "no";
463 450

  
464
			if (rel.getRelType().equals(RelType.personResult)) {
451
        for (OafRel rel : data.getCachedRelList()) {
465 452

  
466
				authors++;
467
			} else if (rel.getRelType().equals(RelType.resultProject))
468
			// TODO remember : in result Project, first id is project, second is  result.
453
            if (rel.getRelType().equals(RelType.personResult)) {
469 454

  
470
			{
471
				String daysfromend = getYearDifferenceInteger(rel.getResultProject().getOutcome().getRelMetadata().getEnddate(), rel.getResultProject().getOutcome().getRelMetadata().getStartdate());
472
				if (Integer.parseInt(daysfromend) > 0) {
473
					delayed = "yes";
474
				}
475
			}
476
		}
477
		// `delayed`,
478
		buff += getStringField(delayed);
455
                authors++;
456
            } else if (rel.getRelType().equals(RelType.resultProject))
457
            // TODO remember : in result Project, first id is project, second is  result.
479 458

  
480
		// log.info("Result " + full_id +"Author count : " + authors );
481
		buff += getNumericField(String.valueOf(authors));
459
            {
460
                String daysfromend = getYearDifferenceInteger(rel.getResultProject().getOutcome().getRelMetadata().getEnddate(), rel.getResultProject().getOutcome().getRelMetadata().getStartdate());
461
                if (Integer.parseInt(daysfromend) > 0) {
462
                    delayed = "yes";
463
                }
464
            }
465
        }
482 466

  
483
		// `context `,
467
        buff += getNumericField(String.valueOf(authors));
484 468

  
485
		String context = new String();
486 469

  
487
		for (Result.Context s : metadata.getContextList()) {
488
			context += s.getId() + ";";
470
        // TODO isRelatedTo
489 471

  
490
		}
472
        //   resource type
473
        buff += getStringField(metadata.getResourcetype().getClassname());
474
        //   device
475
        buff += getStringField(metadata.getDevice().getValue());
476
        //   size
477
        buff += getStringField(metadata.getSize().getValue());
478
        //     version
479
        buff += getStringField(metadata.getVersion().getValue());
480
        //   metadata update
481
        buff += getStringField(metadata.getLastmetadataupdate().getValue());
482
        //   metadata version
483
        buff += getStringField(metadata.getMetadataversionnumber().getValue());
491 484

  
492
		buff += getStringField(context);
485
        // `delayed`,
486
        buff += getStringField(delayed);
493 487

  
488
        // year
489
        buff += getYearInt(metadata.getDateofacceptance().getValue());
494 490

  
495
		String country = new String();
491
        // type
492
        buff += getStringField(metadata.getResulttype().getClassname());
493
        //classification
494
        String classification = new String();
495
        for (Instance instance : (result.getInstanceList())) {
496 496

  
497
		for (Qualifier s : metadata.getCountryList()) {
498
			country += s.getClassname() + ";";
499
		}
497
            if (instance.getInstancetype().getClassname() != null && !instance.getInstancetype().getClassname().isEmpty()) {
498
                classification += instance.getInstancetype().getClassname() + ';';
499
            }
500
        }
500 501

  
501
		buff += getStringField(country);
502
        buff += getStringField(classification);
502 503

  
503
		String desc = new String();
504
		for (StringField s : metadata.getDescriptionList()) {
505
			desc += s.getValue() + ";";
506
		}
504
        //  hosted by
505
        String hostedBy = new String();
506
        for (Instance instance : (result.getInstanceList())) {
507
            String host = instance.getHostedby().getKey();
508
            if (host != null && !host.isEmpty()) {
509
                hostedBy += host + ";";
510
            }
511
        }
507 512

  
508
		buff += getStringField(desc);
509
		// embargo_end_date
513
        buff += getStringField(hostedBy);
510 514

  
511
		String relevantDate = new String();
512
		for (StructuredProperty s : metadata.getRelevantdateList()) {
513
			relevantDate += s.getValue();
514
			break;
515
		}
516
		buff += getStringField(relevantDate);
515
        //   collectedfrom
516
        String collectedFrom = new String();
517
        for (FieldTypeProtos.KeyValue collectedFromValue : (data.getCollectedfromList())) {
517 518

  
519
            String host = collectedFromValue.getKey();
520
            if (host != null && !host.isEmpty()) {
521
                collectedFrom += host + ';';
518 522

  
519
		// device
520
		buff += getStringField(metadata.getDevice().getValue());
521
		// size
522
		buff += getStringField(metadata.getSize().getValue());
523
            }
524
        }
525
        buff += getStringField(collectedFrom);
526
        return buff;
527
    }
523 528

  
524 529

  
525
		return buff;
526
	}
530
    private String buildProject(OafEntity data) {
527 531

  
532
        String buff = new String();
528 533

  
529
	private boolean isValid(String buff, String id) {
530
		if (buff.endsWith(ENCLOSED)) {
531
			log.error("Empty Result with  " + id + " with body: \n" + buff);
532
			return false;
533
		}
534
		return true;
535
	}
534
        Project project = data.getProject();
535
        eu.dnetlib.data.proto.ProjectProtos.Project.Metadata metadata = project.getMetadata();
536 536

  
537
	private String getBestLicense(Result result) {
538
		Qualifier bestLicense = null;
539
		LicenseComparator lc = new LicenseComparator();
540
		for (Instance instance : (result.getInstanceList())) {
541
			if (lc.compare(bestLicense, instance.getLicence()) > 0) {
542
				bestLicense = instance.getLicence();
543
			}
544
		}
545
		if (bestLicense != null) {
546
			return bestLicense.getClassname();
547
		} else {
548
			return null;
549
		}
550
	}
537
        //`original Id`
538
        String originalId = new String();
551 539

  
552
	//   here iterate over all values
553
	private String getAccessMode(Result result) {
554
		String accessMode = NULL_STRING;
555
		for (Instance instance : (result.getInstanceList())) {
556
			if (instance.getLicence().getClassname() != null && !instance.getLicence().getClassname().isEmpty()) {
557
				accessMode = instance.getLicence().getClassname();
558
				break;
559
			}
540
        for (String oid : data.getOriginalIdList()) {
541
            originalId += oid + ";";
542
        }
560 543

  
561
		}
544
        buff += getStringField(originalId);
562 545

  
546
        //dateOfCollection
547
        buff += getStringDateField(data.getDateofcollection());
563 548

  
564
		return accessMode;
565
	}
549
        //Code
550
        buff += getStringField(metadata.getCode().getValue());
551
        // `url`,
552
        buff += getStringField(metadata.getWebsiteurl().getValue());
566 553

  
554
        // `acronym`,
555
        String acronym = metadata.getAcronym().getValue();
556
        if (acronym.equalsIgnoreCase("UNKNOWN")) {
557
            acronym = metadata.getTitle().getValue();
558
        }
567 559

  
568
	private String buildProject(OafEntity data) {
560
        buff += getStringField(acronym);
569 561

  
570
		String buff = new String();
562
        //title!
563
        String title = getStringField(metadata.getTitle().getValue());
564
        buff += getStringField(title);
571 565

  
572
		Project project = data.getProject();
573
		eu.dnetlib.data.proto.ProjectProtos.Project.Metadata metadata = project.getMetadata();
566
        // startdate
567
        buff += getNumericField(metadata.getStartdate().getValue());
574 568

  
575
		//`original Id`
576
		String originalId = new String();
569
        // enddate
570
        buff += getNumericField(metadata.getEnddate().getValue());
577 571

  
578
		for (String oid : data.getOriginalIdList()) {
579
			originalId += (oid);
580
			break;
581
		}
582
		buff += getStringField(originalId);
572
        //`Call identifer`
573
        buff += getStringField(metadata.getCallidentifier().getValue());
583 574

  
584
		//dateOfCollection
585
		buff += getStringDateField(data.getDateofcollection());
586
		//code
587
		buff += getStringField(metadata.getCode().getValue());
575
        //`KeyWords`
576
        buff += getStringField(metadata.getKeywords().getValue());
588 577

  
589
		// `acronym`,
590
		String acronym = metadata.getAcronym().getValue();
591
		if (acronym.equalsIgnoreCase("UNKNOWN")) {
592
			acronym = metadata.getTitle().getValue();
593
		}
578
        //`Duration`
579
        buff += getStringField(metadata.getDuration().getValue());
594 580

  
595
		buff += getStringField(acronym);
581
        //esc39
582
        buff += getStringField(metadata.getEcsc39().getValue().toString());
596 583

  
597
		//title!
598
		String title = getStringField(metadata.getTitle().getValue());
599
		buff += getStringField(title);
584
        //`Contracttype`
585
        buff += getStringField(metadata.getContracttype().getClassname());
600 586

  
601
		List<StringField> fundList = metadata.getFundingtreeList();
587
        //`OA mandate pubs`
588
        buff += getStringField(metadata.getOamandatepublications().getValue());
602 589

  
590
        //`Subjects`
591
        String subjects = new String();
592
        for (StructuredProperty s : metadata.getSubjectsList()) {
603 593

  
604
		if (!fundList.isEmpty()) // `funding_lvl0`,
605
		{
606
			//TODO funder + 3 funding levels
607
		   /* funder text,
608
		    funding_lvl0 text,
594
            subjects += s.getValue() + ';';
595
        }
596
        buff += getStringField(subjects);
597

  
598

  
599
        //`EC293`
600
        buff += getStringField(metadata.getEcarticle293().getValue());
601

  
602

  
603
        List<StringField> fundList = metadata.getFundingtreeList();
604

  
605
//TODO possible to have multiple funders per project?
606
        if (!fundList.isEmpty()) // `funding_lvl0`,
607
        {
608
            //TODO funder + 3 funding levels
609
           /* funder text,
610
            funding_lvl0 text,
609 611
	        funding_lvl1 text,
610 612
	        funding_lvl2 text,
611 613
	        funding_lvl3 text,*/
612
			buff += this.fundingParser.getFundingInfo(fundList.get(0).getValue());
614
            buff += this.fundingParser.getFundingInfo(fundList.get(0).getValue());
613 615

  
614
		} else {
616
        } else {
615 617

  
616
			buff += this.fundingParser.getFundingInfo("");
617
		}
618
            buff += this.fundingParser.getFundingInfo("");
619
        }
618 620

  
621
        return buff;
619 622

  
620
		//esc39
623
    }
621 624

  
622
		buff += getStringField(metadata.getEcsc39().getValue().toString());
623 625

  
624
		// `url`,
625
		buff += getStringField(metadata.getWebsiteurl().getValue());
626
    private String buildPerson(OafEntity data) {
626 627

  
627
		// enddate
628
		buff += getNumericField(metadata.getEnddate().getValue());
629
		// startdate
630
		buff += getNumericField(metadata.getStartdate().getValue());
631
		//`Call identifer`
632
		buff += getStringField(metadata.getCallidentifier().getValue());
633
		//`EC293`
634
		buff += getStringField(metadata.getEcarticle293().getValue());
635
		//`KeyWords`
636
		buff += getStringField(metadata.getKeywords().getValue());
637
		//`OA mandate pubs`
638
		buff += getStringField(metadata.getOamandatepublications().getValue());
639
		//`Contracttype`
640
		buff += getStringField(metadata.getContracttype().getClassname());
641
		//`Duration`
642
		buff += getStringField(metadata.getDuration().getValue());
628
        String buff = new String();
643 629

  
644
		//`Code`
645
		buff += getStringField(metadata.getCode().getValue());
646
		//`Keywords`
647
		buff += getStringField(metadata.getKeywords().getValue());
630
        PersonProtos.Person person = data.getPerson();
631
        eu.dnetlib.data.proto.PersonProtos.Person.Metadata metadata = person.getMetadata();
648 632

  
649
		//`Subjects`
650 633

  
651
		String subjects = new String();
652
		for (StructuredProperty s : metadata.getSubjectsList()) {
634
        //`original Id`
635
        String originalId = new String();
653 636

  
654
			subjects += s.getValue() + ';';
655
		}
656
		buff += getStringField(subjects);
637
        for (String oid : data.getOriginalIdList()) {
638
            originalId += oid + ";";
639
        }
657 640

  
641
        buff += getStringField(originalId);
642
        //dateOfCollection
643
        buff += getStringDateField(data.getDateofcollection());
658 644

  
659
		return buff;
645
        // `firstname`,
646
        buff += metadata.getFirstname();
660 647

  
661
	}
648
        // `secondNames`,
662 649

  
650
        String secondNames = new String();
651
        for (StringField s : metadata.getSecondnamesList()) {
663 652

  
664
	private String buildPerson(OafEntity data) {
653
            secondNames += s.getValue() + ' ';
654
        }
665 655

  
666
		String buff = new String();
656
        buff += getStringField(secondNames);
667 657

  
668
		PersonProtos.Person person = data.getPerson();
669
		eu.dnetlib.data.proto.PersonProtos.Person.Metadata metadata = person.getMetadata();
658
        // `fullname`,
659
        buff += getStringField(metadata.getFullname().getValue());
660
        // `Fax`,
661
        buff += getStringField(metadata.getFax().getValue());
662
        // `Email`,
663
        buff += getStringField(metadata.getEmail().getValue());
664
        // `Phone`,
665
        buff += getStringField(metadata.getPhone().getValue());
670 666

  
667
        // `Nationality`,
668
        buff += getStringField(metadata.getNationality().getClassname());
671 669

  
672
		//`original Id`
673
		String originalId = new String();
670
        // `PIDS`,
671
        String pids = new String();
672
        for (StructuredProperty s : data.getPidList()) {
674 673

  
675
		for (String oid : data.getOriginalIdList()) {
676
			originalId += oid;
677
			break;
678
		}
674
            pids += s.getValue() + ";";
679 675

  
680
		buff += getStringField(originalId);
681
		//dateOfCollection
682
		buff += getStringDateField(data.getDateofcollection());
683 676

  
684
		// `firstname`,
685
		buff += metadata.getFirstname();
677
        }
678
        buff += getStringField(pids);
686 679

  
687
		// `secondNames`,
680
        // `collected from`,
681
        String collectedFrom = new String();
682
        for (FieldTypeProtos.KeyValue s : data.getCollectedfromList()) {
683
            collectedFrom += s.getValue() + ";";
684
        }
685
        buff += getStringField(collectedFrom);
686
        return buff;
688 687

  
689
		String secondNames = new String();
690
		for (StringField s : metadata.getSecondnamesList()) {
688
    }
691 689

  
692
			secondNames += s.getValue() + ' ';
693
		}
690
    public String cleanId(String value) {
691
        if (value != null) {
692
            //   DO NOT CHANGE THIS: IT REMOVES ID PREFIX ( 5|datacite____::
694 693

  
695
		buff += getStringField(secondNames);
696 694

  
697
		// `fullname`,
698
		buff += getStringField(metadata.getFullname().getValue());
695
            // to datacite____:: )
696
            // AND REPLACES OCCURENCES OF DELIM CHARS IN DATA
697
            value = value.replaceFirst(".*\\|", "");
698
            value = value.replaceAll("\n", "");
699
            value = value.replaceAll(DELIM, "");
700
            value = value.replaceAll(ENCLOSED, "");
701
            value = value.trim();
699 702

  
700
		// `Nationality`,
701
		buff += getStringField(metadata.getNationality().getClassname());
702
		// `Email`,
703
		buff += getStringField(metadata.getEmail().getValue());
704
		// `Phone`,
705
		buff += getStringField(metadata.getPhone().getValue());
706
		// `Fax`,
707
		buff += getStringField(metadata.getFax().getValue());
703
        }
704
        if (value == null) {
705
            return null;
706
        }
707
        return ENCLOSED + value + ENCLOSED;
708 708

  
709
		// `collected from`,
710
		String collectedFrom = new String();
711
		for (FieldTypeProtos.KeyValue s : data.getCollectedfromList()) {
709
    }
712 710

  
713
			collectedFrom += s.getValue();
714
			break;
715 711

  
716
		}
717
		buff += getStringField(collectedFrom);
712
    private String getNumericField(String data) {
713
        if (data == null || data.isEmpty() || data.equals("")) {
714
            return ENCLOSED + NULL_NUM + ENCLOSED + DELIM;
715
        } else {
718 716

  
717
            return ENCLOSED + data + ENCLOSED + DELIM;
718
        }
719
    }
719 720

  
720
		return buff;
721 721

  
722
	}
722
    private String getYearDifferenceInteger(String enddate, String startdate) {
723 723

  
724
        if (enddate != null && !enddate.isEmpty() && startdate != null && !startdate.isEmpty()) {
724 725

  
725
	private String getYearDifferenceInteger(String enddate, String startdate) {
726
            String[] split = startdate.split("-");
726 727

  
727
		if (enddate != null && !enddate.isEmpty() && startdate != null && !startdate.isEmpty()) {
728
            if (split == null || split.length == 0) {
729
                return ENCLOSED + NULL_NUM + ENCLOSED + DELIM;
730
            }
728 731

  
729
			String[] split = startdate.split("-");
732
            int Startdate = Integer.parseInt(split[0]);
730 733

  
731
			if (split == null || split.length == 0) {
732
				return ENCLOSED + NULL_NUM + ENCLOSED + DELIM;
733
			}
734
            split = enddate.split("-");
734 735

  
735
			int Startdate = Integer.parseInt(split[0]);
736
            if (split == null || split.length == 0) {
737
                return ENCLOSED + NULL_NUM + ENCLOSED + DELIM;
738
            }
736 739

  
737
			split = enddate.split("-");
740
            int Enddate = Integer.parseInt(split[0]);
738 741

  
739
			if (split == null || split.length == 0) {
740
				return ENCLOSED + NULL_NUM + ENCLOSED + DELIM;
741
			}
742
            int diff = Enddate - Startdate;
742 743

  
743
			int Enddate = Integer.parseInt(split[0]);
744
            return ENCLOSED + diff + ENCLOSED + DELIM;
744 745

  
745
			int diff = Enddate - Startdate;
746
        }
746 747

  
747
			return ENCLOSED + diff + ENCLOSED + DELIM;
748
        return ENCLOSED + NULL_NUM + ENCLOSED + DELIM;
749
    }
748 750

  
749
		}
751
    private String getYearInt(String data) {
752
        if (data == null || data.isEmpty() || data.equals("-1")) {
753
            return ENCLOSED + NULL_NUM + ENCLOSED + DELIM;
754
        }
750 755

  
751
		return ENCLOSED + NULL_NUM + ENCLOSED + DELIM;
752
	}
756
        String[] split = data.split("-");
753 757

  
754
	private String getYearInt(String data) {
755
		if (data == null || data.isEmpty() || data.equals("-1")) {
756
			return ENCLOSED + NULL_NUM + ENCLOSED + DELIM;
757
		}
758
        if (split == null || split.length == 0) {
759
            return ENCLOSED + NULL_NUM + ENCLOSED + DELIM;
760
        }
758 761

  
759
		String[] split = data.split("-");
762
        String year = split[0];
760 763

  
761
		if (split == null || split.length == 0) {
762
			return ENCLOSED + NULL_NUM + ENCLOSED + DELIM;
763
		}
764
        year = cleanNumber(year);
764 765

  
765
		String year = split[0];
766
        return ENCLOSED + year + ENCLOSED + DELIM;
766 767

  
767
		year = cleanNumber(year);
768 768

  
769
		return ENCLOSED + year + ENCLOSED + DELIM;
769
    }
770 770

  
771
    private static String cleanNumber(String number) {
772
        number = number.replaceAll("[^A-Za-z0-9:,____]", "");
771 773

  
772
	}
774
        return number;
775
    }
773 776

  
774
	private String cleanNumber(String number) {
775
		number = number.replaceAll("[^A-Za-z0-9:,____]", "");
777
    private String getStringField(String data) {
776 778

  
777
		return number;
778
	}
779
        if (data == null || data.isEmpty() || data.equals("")) {
779 780

  
780
	private String getStringField(String data) {
781
            return ENCLOSED + NULL_STRING + ENCLOSED + DELIM;
782
        } else {
781 783

  
782
		if (data == null || data.isEmpty() || data.equals("")) {
784
            String field = clean(data);
785
            if (field == null) {
786
                return ENCLOSED + NULL_STRING + ENCLOSED + DELIM;
787
            } else {
788
                return field + DELIM;
789
            }
790
        }
791
    }
783 792

  
784
			return ENCLOSED + NULL_STRING + ENCLOSED + DELIM;
785
		} else {
793
    private String getStringDateField(String data) {
786 794

  
787
			String field = clean(data);
788
			if (field == null) {
789
				return ENCLOSED + NULL_STRING + ENCLOSED + DELIM;
790
			} else {
791
				return field + DELIM;
792
			}
793
		}
794
	}
795
        if (data == null || data.isEmpty() || data.equals("") || data.equals("-1")) {
795 796

  
796
	private String getStringDateField(String data) {
797
            return ENCLOSED + NULL_NUM + ENCLOSED + DELIM;
798
        } else {
797 799

  
798
		if (data == null || data.isEmpty() || data.equals("") || data.equals("-1")) {
800
            String field = clean(data);
801
            if (field == null) {
802
                return ENCLOSED + NULL_NUM + ENCLOSED + DELIM;
803
            } else {
804
                return field + DELIM;
805
            }
806
        }
807
    }
799 808

  
800
			return ENCLOSED + NULL_NUM + ENCLOSED + DELIM;
801
		} else {
802 809

  
803
			String field = clean(data);
804
			if (field == null) {
805
				return ENCLOSED + NULL_NUM + ENCLOSED + DELIM;
806
			} else {
807
				return field + DELIM;
808
			}
809
		}
810
	}
810
    public String getId(OafProtos.Oaf oaf) {
811
        switch (oaf.getKind()) {
812
            case entity:
811 813

  
812
	private String getNumericField(String data) {
813
		if (data == null || data.isEmpty() || data.equals("")) {
814
			return ENCLOSED + NULL_NUM + ENCLOSED + DELIM;
815
		} else {
814
                return cleanId(oaf.getEntity().getId());
815
            case relation:
816 816

  
817
			return ENCLOSED + data + ENCLOSED + DELIM;
818
		}
819
	}
817
                return cleanId(oaf.getRel().getSource());
820 818

  
821
	public String getId(Oaf oaf) {
822
		switch (oaf.getKind()) {
823
			case entity:
819
        }
820
        return null;
824 821

  
825
				return cleanId(oaf.getEntity().getId());
826
			case relation:
822
    }
827 823

  
828
				return cleanId(oaf.getRel().getSource());
824
    private boolean isNumeric(String str) {
829 825

  
830
		}
831
		return null;
826
        str = str.replaceAll("[^A-Za-z0-9 ]", "");
827
        str = str.replaceAll(" ", "");
828
        return str.matches("-?\\d+(\\.\\d+)?"); // match a number with optional
829
        // '-' and decimal.
830
    }
832 831

  
833
	}
832
    //   there are topics with "null" as value -> replace them
833
    private boolean isValidTopic(String t) {
834 834

  
835
	public String getId(OafRel relOaf) {
836
		return cleanId(relOaf.getSource());
837
	}
835
        if (t == null || t.isEmpty()) {
836
            return false;
837
        }
838 838

  
839
	public static String clean(String value) {
840
		if (value != null) {
841
			// TODO DO NOT CHANGE THIS: IT REMOVES ID PREFIX ( 5|datacite____::
842
			// to datacite____:: )
843
			// AND REPLACES OCCURENCES OF DELIM CHARS IN DATA
844
			value = value.replaceFirst(".*\\|", "");
845
			value = value.replaceAll(DELIM, "");
846
			value = value.replaceAll(",", "");
847
			value = value.replaceAll("\"", "");
848
			value = value.replaceAll("'", "");
849
			value = value.replaceAll(ENCLOSED, "");
850
			value = value.replaceAll("\\r\\n|\\r|\\n", " ");
851
			value = value.replaceAll("\\s+", " ");
852
			value = value.replaceAll("(\\r|\\n)", " ");
853
			value = value.replaceAll("\\t", " ");
839
        if (t.equals("") || t.equals(" ")) {
840
            return false;
841
        }
842
        if (t.equals("null") || t.equals("Null") || t.equals("NULL")) {
843
            return false;
844
        }
854 845

  
855
			// value = value.replaceAll("[^A-Za-z0-9:,____-;:]", " ");
856
			value = value.trim();
846
        if (t.equals(ENCLOSED + ENCLOSED + DELIM) || t.equals(ENCLOSED + NULL_STRING + ENCLOSED + DELIM)) {
847
            return false;
848
        }
849
        // skip dedups
850
        if (t.contains("ddc:")) {
857 851

  
858
		}
859
		if (value == null) {
860
			return null;
861
		}
862
		return ENCLOSED + value + ENCLOSED;
852
            return false;
853
        }
854
        return true;
855
    }
863 856

  
864
	}
865 857

  
866
	public static String cleanId(String value) {
867
		if (value != null) {
868
			//   DO NOT CHANGE THIS: IT REMOVES ID PREFIX ( 5|datacite____::
858
    private String getBestLicense(ResultProtos.Result result) {
859
        FieldTypeProtos.Qualifier bestLicense = null;
860
        LicenseComparator lc = new LicenseComparator();
861
        for (ResultProtos.Result.Instance instance : (result.getInstanceList())) {
862
            if (lc.compare(bestLicense, instance.getLicence()) > 0) {
863
                bestLicense = instance.getLicence();
864
            }
865
        }
866
        if (bestLicense != null) {
867
            return bestLicense.getClassname();
868
        } else {
869
            return null;
870
        }
871
    }
869 872

  
873
    //   here iterate over all values
874
    private String getAccessMode(ResultProtos.Result result) {
875
        String accessMode = null;
876
        for (ResultProtos.Result.Instance instance : (result.getInstanceList())) {
877
            if (instance.getLicence().getClassname() != null && !instance.getLicence().getClassname().isEmpty()) {
878
                accessMode = instance.getLicence().getClassname();
879
                break;
880
            }
870 881

  
871
			// to datacite____:: )
872
			// AND REPLACES OCCURENCES OF DELIM CHARS IN DATA
873
			value = value.replaceFirst(".*\\|", "");
874
			value = value.replaceAll("\n", "");
875
			value = value.replaceAll(DELIM, "");
876
			value = value.replaceAll(ENCLOSED, "");
877
			value = value.trim();
882
        }
878 883

  
879
		}
880
		if (value == null) {
881
			return null;
882
		}
883
		return ENCLOSED + value + ENCLOSED;
884 884

  
885
	}
885
        return accessMode;
886
    }
886 887

  
887
	public long DATEDIFF(String startDate, String endDate) {
888
		long MILLISECS_PER_DAY = 24 * 60 * 60 * 1000;
889
		long days = 0l;
890
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); // "dd/MM/yyyy HH:mm:ss");
891
		// <startdate>2011-09-01</startdate>
892
		// <enddate>2015-08-31</enddate>
893
		Date dateIni = null;
894
		Date dateFin = null;
895 888

  
896
		if (startDate == null || startDate.isEmpty() || endDate == null || endDate.isEmpty()) {
897
			return 0;
898
		}
899
		try {
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff