Revision 49324
Added by Alessia Bardi over 6 years ago
FacetWriter.java | ||
---|---|---|
5 | 5 |
import com.fasterxml.jackson.core.JsonGenerator; |
6 | 6 |
import eu.dnetlib.parthenos.CRM; |
7 | 7 |
import eu.dnetlib.parthenos.CRMpe; |
8 |
import org.apache.commons.lang3.StringUtils; |
|
8 | 9 |
import org.apache.jena.rdf.model.Resource; |
9 | 10 |
import org.apache.jena.rdf.model.Statement; |
10 | 11 |
import org.apache.jena.rdf.model.StmtIterator; |
11 | 12 |
import org.apache.jena.vocabulary.RDF; |
12 | 13 |
import org.apache.jena.vocabulary.RDFS; |
13 |
import org.gcube.informationsystem.model.entity.facet.IdentifierFacet.IdentificationType; |
|
14 | 14 |
import org.springframework.stereotype.Component; |
15 | 15 |
|
16 | 16 |
/** |
... | ... | |
21 | 21 |
@Component |
22 | 22 |
public class FacetWriter { |
23 | 23 |
|
24 |
public void writeP1Facet(final JsonGenerator jg, final String value, final IdentificationType type) throws IOException { |
|
24 |
//final IdentificationType type |
|
25 |
public void writeP1Facet(final JsonGenerator jg, final String value) throws IOException { |
|
25 | 26 |
jg.writeStartObject(); |
26 | 27 |
jg.writeStringField("@class", "P1_is_identified_by"); |
27 | 28 |
jg.writeObjectFieldStart("target"); |
28 | 29 |
jg.writeStringField("@class", "IdentifierFacet"); |
29 | 30 |
jg.writeStringField("value", value); |
30 |
jg.writeStringField("type", type.name()); |
|
31 |
//jg.writeStringField("type", type.name());
|
|
31 | 32 |
jg.writeEndObject(); |
32 | 33 |
jg.writeEndObject(); |
33 | 34 |
} |
... | ... | |
38 | 39 |
jg.writeObjectFieldStart("target"); |
39 | 40 |
jg.writeStringField("@class", "IdentifierFacet"); |
40 | 41 |
jg.writeStringField("value", identifier); |
41 |
jg.writeStringField("type", IdentificationType.URI.name()); |
|
42 |
//jg.writeStringField("type", IdentificationType.URI.name());
|
|
42 | 43 |
jg.writeEndObject(); |
43 | 44 |
jg.writeEndObject(); |
44 | 45 |
} |
45 | 46 |
|
47 |
public void writeP1Facets(final JsonGenerator jg, final Resource res) throws IOException { |
|
48 |
if(res.hasProperty(CRM.P1_is_identified_by)){ |
|
49 |
StmtIterator idRelsIt = res.listProperties(CRM.P1_is_identified_by); |
|
50 |
while(idRelsIt.hasNext()){ |
|
51 |
Resource target = idRelsIt.nextStatement().getResource(); |
|
52 |
String label = getLabelFromRDFResource(target); |
|
53 |
if(StringUtils.isNotBlank(label)) { |
|
54 |
writeP1Facet(jg, label); |
|
55 |
} |
|
56 |
} |
|
57 |
} |
|
58 |
} |
|
59 |
|
|
46 | 60 |
public void writeInfoFacet(final JsonGenerator jg, final Resource res) throws IOException { |
47 | 61 |
jg.writeStartObject(); |
62 |
jg.writeStringField("@class", "consistsOf"); |
|
63 |
jg.writeObjectFieldStart("target"); |
|
48 | 64 |
jg.writeStringField("@class", "PE_Info_Facet"); |
49 |
jg.writeObjectFieldStart("target"); |
|
50 | 65 |
jg.writeStringField("title", getTitleFromRDFResource(res)); |
51 | 66 |
jg.writeStringField("description", getDescriptionFromRDFResource(res)); |
52 | 67 |
//new object comp + field value + schema="noSchema" |
53 |
jg.writeStringField("competence", getCompetenceFromRDFResource(res)); |
|
68 |
String competence = getCompetenceFromRDFResource(res); |
|
69 |
if(StringUtils.isNotBlank(competence)) { |
|
70 |
writeValueSchema(jg, "competence", competence, "noSchema"); |
|
71 |
} |
|
54 | 72 |
//TODO: uncomment this when George adds the rel to the model, see method getAvailabilityFromRDFResource below |
55 |
//jg.writeStringField("availability", getAvailabilityFromRDFResource(res)); |
|
73 |
//String availability = getAvailabilityFromRDFResource(res); |
|
74 |
// if(StringUtils.isNotBlank(availability)) { |
|
75 |
// writeValueSchema(jg, "availability", availability, "noSchema"); |
|
76 |
// } |
|
56 | 77 |
jg.writeEndObject(); |
57 | 78 |
jg.writeEndObject(); |
58 | 79 |
} |
59 | 80 |
|
81 |
protected void writeValueSchema(final JsonGenerator jg, final String fieldName, final String value, final String schema) throws IOException { |
|
82 |
jg.writeObjectFieldStart(fieldName); |
|
83 |
jg.writeStringField("value", value); |
|
84 |
jg.writeStringField("schema", schema); |
|
85 |
jg.writeEndObject(); |
|
86 |
} |
|
87 |
|
|
60 | 88 |
public void writeEventFacet(final JsonGenerator jg) { |
61 | 89 |
//TODO: implement me. get begin/end of operation from PP42_has_declarative_time |
62 | 90 |
} |
Also available in: Unified diff
feeding the registry with resources and relationships