1
|
package eu.dnetlib.parthenos.registry;
|
2
|
|
3
|
import java.io.IOException;
|
4
|
import java.io.StringWriter;
|
5
|
|
6
|
import com.fasterxml.jackson.core.JsonFactory;
|
7
|
import com.fasterxml.jackson.core.JsonGenerator;
|
8
|
import org.springframework.stereotype.Component;
|
9
|
|
10
|
/**
|
11
|
* Created by Alessia Bardi on 02/10/2017.
|
12
|
*
|
13
|
* @author Alessia Bardi
|
14
|
*/
|
15
|
@Component
|
16
|
public class RelWriter {
|
17
|
|
18
|
protected String writeRelationship(final JsonFactory jsonFactory, final String relType, final String sourceUUID, final String sourceType, final String targetUUID, final String targetType)
|
19
|
throws IOException {
|
20
|
StringWriter sw = new StringWriter();
|
21
|
JsonGenerator jg = jsonFactory.createGenerator(sw);
|
22
|
jg.writeStartObject();
|
23
|
jg.writeStringField("@class", relType);
|
24
|
jg.writeObjectFieldStart("source");
|
25
|
jg.writeObjectFieldStart("header");
|
26
|
jg.writeStringField("uuid", sourceUUID);
|
27
|
jg.writeEndObject();
|
28
|
jg.writeStringField("@class", sourceType);
|
29
|
jg.writeEndObject();
|
30
|
jg.writeObjectFieldStart("target");
|
31
|
jg.writeObjectFieldStart("header");
|
32
|
jg.writeStringField("uuid", targetUUID);
|
33
|
jg.writeEndObject();
|
34
|
jg.writeStringField("@class", targetType);
|
35
|
jg.writeEndObject();
|
36
|
jg.close();
|
37
|
return sw.toString();
|
38
|
}
|
39
|
}
|