Revision 49200
Added by Alessia Bardi over 6 years ago
FacetWriter.java | ||
---|---|---|
21 | 21 |
@Component |
22 | 22 |
public class FacetWriter { |
23 | 23 |
|
24 |
protected void writeIdentifierFacet(final JsonGenerator jg, final String identifier) throws IOException {
|
|
24 |
public void writeP1Facet(final JsonGenerator jg, final String value, final IdentificationType type) throws IOException {
|
|
25 | 25 |
jg.writeStartObject(); |
26 | 26 |
jg.writeStringField("@class", "P1_is_identified_by"); |
27 | 27 |
jg.writeObjectFieldStart("target"); |
28 | 28 |
jg.writeStringField("@class", "IdentifierFacet"); |
29 |
jg.writeStringField("value", value); |
|
30 |
jg.writeStringField("type", type.name()); |
|
31 |
jg.writeEndObject(); |
|
32 |
jg.writeEndObject(); |
|
33 |
} |
|
34 |
|
|
35 |
public void writeIdentifierFacet(final JsonGenerator jg, final String identifier) throws IOException { |
|
36 |
jg.writeStartObject(); |
|
37 |
jg.writeStringField("@class", "isIdentifiedBy"); |
|
38 |
jg.writeObjectFieldStart("target"); |
|
39 |
jg.writeStringField("@class", "IdentifierFacet"); |
|
29 | 40 |
jg.writeStringField("value", identifier); |
30 | 41 |
jg.writeStringField("type", IdentificationType.URI.name()); |
31 | 42 |
jg.writeEndObject(); |
32 | 43 |
jg.writeEndObject(); |
33 | 44 |
} |
34 | 45 |
|
35 |
protected void writeInfoFacet(final JsonGenerator jg, final Resource res) throws IOException {
|
|
46 |
public void writeInfoFacet(final JsonGenerator jg, final Resource res) throws IOException {
|
|
36 | 47 |
jg.writeStartObject(); |
37 | 48 |
jg.writeStringField("@class", "PE_Info_Facet"); |
38 | 49 |
jg.writeObjectFieldStart("target"); |
39 | 50 |
jg.writeStringField("title", getTitleFromRDFResource(res)); |
40 | 51 |
jg.writeStringField("description", getDescriptionFromRDFResource(res)); |
52 |
//new object comp + field value + schema="noSchema" |
|
41 | 53 |
jg.writeStringField("competence", getCompetenceFromRDFResource(res)); |
42 | 54 |
//TODO: uncomment this when George adds the rel to the model, see method getAvailabilityFromRDFResource below |
43 | 55 |
//jg.writeStringField("availability", getAvailabilityFromRDFResource(res)); |
... | ... | |
45 | 57 |
jg.writeEndObject(); |
46 | 58 |
} |
47 | 59 |
|
48 |
|
|
49 |
protected void writeEventFacet(final JsonGenerator jg){ |
|
60 |
public void writeEventFacet(final JsonGenerator jg) { |
|
50 | 61 |
//TODO: implement me. get begin/end of operation from PP42_has_declarative_time |
51 | 62 |
} |
52 | 63 |
|
53 |
protected void writeRightsFacet(final JsonGenerator jg, final Resource res) throws IOException {
|
|
64 |
public void writeRightsFacet(final JsonGenerator jg, final Resource res) throws IOException {
|
|
54 | 65 |
//TODO: implement me. E30_Right facet extends from licenseFacet but it is not correct (textUrl is mandatory, we can't use it in Parthenos) |
55 | 66 |
} |
56 | 67 |
|
57 |
protected void writeContactReferenceFacet(final JsonGenerator jg, final Resource resource) throws IOException { |
|
58 |
//PP2_provided_by |
|
59 |
final Statement s = resource.getProperty(CRMpe.PP2_provided_by); |
|
60 |
|
|
61 |
if(s!=null){ |
|
62 |
String appellation = ""; |
|
63 |
String description = ""; |
|
64 |
String legalAddress = ""; |
|
65 |
String email =""; |
|
68 |
public void writeContactReferenceFacet(final JsonGenerator jg, final Resource actor) throws IOException { |
|
69 |
if (actor != null) { |
|
70 |
String appellation = getTitleFromRDFResource(actor); |
|
71 |
String description = getDescriptionFromRDFResource(actor); |
|
72 |
String legalAddress = ""; |
|
73 |
String email = ""; |
|
66 | 74 |
String website = ""; |
67 |
String address = ""; |
|
68 |
String phoneNumber =""; |
|
69 |
|
|
70 |
Resource provider = s.getResource(); |
|
71 |
if(provider != null){ |
|
72 |
//more contact point per provider |
|
73 |
StmtIterator contactPointsStm = provider.listProperties(CRM.P76_has_contact_point); |
|
74 |
while(contactPointsStm.hasNext()){ |
|
75 |
Resource cp = contactPointsStm.nextStatement().getResource(); |
|
76 |
appellation = getLabelFromRDFResource(cp); |
|
77 |
description = getDescriptionFromRDFResource(cp); |
|
78 |
//TODO: where to find email and legaladdress, address, phoneNumber, website? |
|
79 |
jg.writeStartObject(); |
|
80 |
jg.writeStringField("@class", "PE_Contact_Reference_Facet"); |
|
81 |
jg.writeObjectFieldStart("target"); |
|
82 |
jg.writeStringField("appellation", appellation); |
|
83 |
jg.writeStringField("description", description); |
|
84 |
jg.writeStringField("legalAddress", legalAddress); |
|
85 |
jg.writeStringField("email", email); |
|
86 |
jg.writeStringField("website", website); |
|
87 |
jg.writeStringField("address", address); |
|
88 |
jg.writeStringField("phoneNumber", phoneNumber); |
|
89 |
jg.writeEndObject(); |
|
90 |
jg.writeEndObject(); |
|
75 |
String address = ""; |
|
76 |
String phoneNumber = ""; |
|
77 |
//more contact point per provider |
|
78 |
StmtIterator contactPointsStm = actor.listProperties(CRM.P76_has_contact_point); |
|
79 |
while (contactPointsStm.hasNext()) { |
|
80 |
Resource cp = contactPointsStm.nextStatement().getResource(); |
|
81 |
//contact points can bean E45_Address or E51_Contact_Point |
|
82 |
if ((cp.hasProperty(RDF.type, CRM.E45_Address) || cp.hasProperty(RDF.type, CRM.E51_Contact_Point)) && cp.hasProperty(CRM.P2_has_type)) { |
|
83 |
Resource addressType = cp.getPropertyResourceValue(CRM.P2_has_type); |
|
84 |
String info = getLabelFromRDFResource(cp); |
|
85 |
String addressTypeLabel = getLabelFromRDFResource(addressType); |
|
86 |
switch (addressTypeLabel.toLowerCase()) { |
|
87 |
case "email": |
|
88 |
email = info; |
|
89 |
break; |
|
90 |
case "legal address": |
|
91 |
legalAddress = info; |
|
92 |
break; |
|
93 |
case "address": |
|
94 |
address = info; |
|
95 |
break; |
|
96 |
case "phone": |
|
97 |
phoneNumber = info; |
|
98 |
break; |
|
99 |
case "web": |
|
100 |
website = info; |
|
101 |
break; |
|
102 |
} |
|
91 | 103 |
} |
92 | 104 |
} |
105 |
jg.writeStartObject(); |
|
106 |
jg.writeStringField("@class", "PE_Contact_Reference_Facet"); |
|
107 |
jg.writeObjectFieldStart("target"); |
|
108 |
jg.writeStringField("appellation", appellation); |
|
109 |
jg.writeStringField("description", description); |
|
110 |
jg.writeStringField("legalAddress", legalAddress); |
|
111 |
jg.writeStringField("email", email); |
|
112 |
jg.writeStringField("website", website); |
|
113 |
jg.writeStringField("address", address); |
|
114 |
jg.writeStringField("phoneNumber", phoneNumber); |
|
115 |
jg.writeEndObject(); |
|
116 |
jg.writeEndObject(); |
|
93 | 117 |
} |
94 |
|
|
95 | 118 |
} |
96 | 119 |
|
97 |
protected void writeDesignatedAccessPointFacet(final JsonGenerator jg, final Resource resource) throws IOException {
|
|
120 |
public void writeDesignatedAccessPointFacet(final JsonGenerator jg, final Resource resource) throws IOException {
|
|
98 | 121 |
//PP28_has_designated_access_point |
99 | 122 |
StmtIterator apStms = resource.listProperties(CRMpe.PP28_has_designated_access_point); |
100 |
while(apStms.hasNext()){
|
|
123 |
while (apStms.hasNext()) {
|
|
101 | 124 |
String entryName = getLabelFromRDFResource(resource); |
102 | 125 |
//(mandatory) |
103 |
String endpoint= ""; |
|
104 |
String protocol= ""; |
|
105 |
String description= getDescriptionFromRDFResource(resource); |
|
126 |
String endpoint = "";
|
|
127 |
String protocol = "";
|
|
128 |
String description = getDescriptionFromRDFResource(resource);
|
|
106 | 129 |
//TODO: authorization is a ValueSchema, I do not understand how to use it and how to map it |
107 |
String authorization= ""; |
|
130 |
String authorization = "";
|
|
108 | 131 |
Resource ap = apStms.next().getResource(); |
109 | 132 |
endpoint = ap.getURI(); |
110 | 133 |
//TODO: where to get protocol and authorization? |
... | ... | |
123 | 146 |
|
124 | 147 |
} |
125 | 148 |
|
149 |
public void writeTemporalCoverageFacet(final JsonGenerator jg, final Resource resource) { |
|
150 |
//TODO: CoverageFacet wants a value and a mandatory schema. Can't be applied to Parthenos. |
|
151 |
} |
|
126 | 152 |
|
127 |
protected String getTitleFromRDFResource(final Resource resource){ |
|
153 |
protected String getTitleFromRDFResource(final Resource resource) {
|
|
128 | 154 |
String title = ""; |
129 | 155 |
final Statement s = resource.getProperty(CRM.P1_is_identified_by); |
130 |
if(s != null){
|
|
156 |
if (s != null) {
|
|
131 | 157 |
Resource titleRes = s.getResource(); |
132 |
if(titleRes != null && (titleRes.hasProperty(RDF.type, CRM.E35_Title) || titleRes.hasProperty(RDF.type, CRM.E41_Appellation) )){
|
|
158 |
if (titleRes != null && (titleRes.hasProperty(RDF.type, CRM.E35_Title) || titleRes.hasProperty(RDF.type, CRM.E41_Appellation))) {
|
|
133 | 159 |
title = getLabelFromRDFResource(titleRes); |
134 | 160 |
} |
135 | 161 |
} |
136 | 162 |
return title; |
137 | 163 |
} |
138 | 164 |
|
139 |
protected String getDescriptionFromRDFResource(final Resource resource){ |
|
140 |
if(resource.hasProperty(CRM.P3_has_note)){
|
|
165 |
protected String getDescriptionFromRDFResource(final Resource resource) {
|
|
166 |
if (resource.hasProperty(CRM.P3_has_note)) {
|
|
141 | 167 |
return resource.getProperty(CRM.P3_has_note).getString(); |
142 |
} |
|
143 |
else return ""; |
|
168 |
} else return ""; |
|
144 | 169 |
} |
145 | 170 |
|
146 |
protected String getLabelFromRDFResource(final Resource resource){ |
|
147 |
if(resource.hasProperty(RDFS.label)){
|
|
171 |
protected String getLabelFromRDFResource(final Resource resource) {
|
|
172 |
if (resource.hasProperty(RDFS.label)) {
|
|
148 | 173 |
return resource.getProperty(RDFS.label).getString(); |
149 |
} |
|
150 |
else return ""; |
|
174 |
} else return ""; |
|
151 | 175 |
} |
152 | 176 |
|
153 |
protected String getCompetenceFromRDFResource(final Resource resource){ |
|
177 |
protected String getCompetenceFromRDFResource(final Resource resource) {
|
|
154 | 178 |
String comp = ""; |
155 |
if(resource.hasProperty(CRMpe.PP45_has_competency)){
|
|
179 |
if (resource.hasProperty(CRMpe.PP45_has_competency)) {
|
|
156 | 180 |
Resource compRes = resource.getProperty(CRMpe.PP45_has_competency).getResource(); |
157 |
if(compRes.hasProperty(RDFS.label)) |
|
181 |
if (compRes.hasProperty(RDFS.label))
|
|
158 | 182 |
comp = compRes.getProperty(RDFS.label).getString(); |
159 | 183 |
} |
160 | 184 |
return comp; |
161 | 185 |
} |
162 | 186 |
|
163 |
protected String getAvailabilityFromRDFResource(final Resource resource){ |
|
187 |
protected String getAvailabilityFromRDFResource(final Resource resource) {
|
|
164 | 188 |
//TODO: implement this when George adds the rel to the model |
165 | 189 |
return ""; |
166 | 190 |
} |
Also available in: Unified diff
More mapping to gcube resources and facets