Revision 49324
Added by Alessia Bardi over 6 years ago
RelWriter.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.parthenos.registry; |
2 | 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; |
|
3 | 8 |
import org.springframework.stereotype.Component; |
4 | 9 |
|
5 | 10 |
/** |
... | ... | |
10 | 15 |
@Component |
11 | 16 |
public class RelWriter { |
12 | 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 |
} |
|
13 | 39 |
} |
Also available in: Unified diff
feeding the registry with resources and relationships