Project

General

Profile

« Previous | Next » 

Revision 49200

More mapping to gcube resources and facets

View differences:

GCubeResourceGenerator.java
44 44

  
45 45
	@Autowired
46 46
	private FacetWriter facetWriter;
47
	@Autowired
48
	private RelWriter relWriter;
47 49

  
48 50
	public GCubeResourceGenerator() {
49
		final String url = "http://www.w3.org/TR/REC-rdf-syntax/example14.nt";
50 51
		baseModel = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM_TRANS_INF);
51 52
		baseModel.read(CRMpe.RDFS_URL);
52 53
		baseModel.read(CRM.RDFS_URL);
......
77 78
		JsonFactory jsonFactory = new JsonFactory();
78 79
		Set<String> uriProcessed = Sets.newHashSet();
79 80

  
81
		//TODO: many things in common in the code below: re-factor it!
82

  
83

  
84
		log.debug("Processing services");
80 85
		//let's start with services
81 86
		ResIterator iter = model.listResourcesWithProperty(RDF.type, CRMpe.PE1_Service);
82 87
		while (iter.hasNext()) {
......
89 94
				JsonGenerator jg = jsonFactory.createGenerator(sw);
90 95
				jg.writeStartObject();
91 96

  
92
				jg.writeStringField("@class", specificType.getURI());
97
				//TODO: generate header with uuid for all type of entities, so we can also generate the rels. Need a map for uri --> uuid.
98
				jg.writeStringField("@class", specificType.getLocalName());
93 99

  
94 100
				//******THE FACETS *******//
95 101
				jg.writeArrayFieldStart("consistsOf");
96 102
				//list of facets
97

  
103
				//TODO: write P1 identifier facet following the existing links (for all types)
98 104
				facetWriter.writeIdentifierFacet(jg, resourceURI);
99 105
				facetWriter.writeInfoFacet(jg, res);
100 106
				facetWriter.writeEventFacet(jg);
101 107
				facetWriter.writeRightsFacet(jg, res);
102
				facetWriter.writeContactReferenceFacet(jg, res);
108
				if(res.hasProperty(CRMpe.PP2_provided_by)){
109
					//TODO: shouldn't this be a rel to an actor?
110
					Resource provider = res.getPropertyResourceValue(CRMpe.PP2_provided_by);
111
					facetWriter.writeContactReferenceFacet(jg, provider);
112
				}
113

  
103 114
				facetWriter.writeDesignatedAccessPointFacet(jg, res);
104 115

  
105 116
				jg.writeEndArray();
106 117

  
107
				// ******* RELATIONSHIPS *****//
108
				jg.writeArrayFieldStart("isRelatedto");
118
				// ******* RELATIONSHIPS ***** ??? or separately after we got the ids of everything?//
119
				//jg.writeArrayFieldStart("isRelatedto");
120
				//jg.writeEndArray();
109 121

  
122
				jg.writeEndObject();
123
				jg.close();
124
				String json = sw.toString();
125
				log.debug(json);
126
				jsonResources.add(json);
127
				uriProcessed.add(resourceURI);
128
			} else {
129
				log.debug(resourceURI+" already processed, now skipping it");
130
			}
131
		}
132

  
133
		log.debug("Processing digital objects (include dataset and software)");
134
		//and then the datasets
135
		ResIterator iterDo = model.listResourcesWithProperty(RDF.type, CRMdig.D1_Digital_Object);
136
		while (iterDo.hasNext()) {
137
			Resource res = iterDo.nextResource();
138
			String resourceURI = res.getURI();
139
			if (!uriProcessed.contains(resourceURI)) {
140
				log.debug("Processing " + resourceURI);
141
				Resource specificType = findSpecificType(res, CRMdig.D1_Digital_Object);
142
				StringWriter sw = new StringWriter();
143
				JsonGenerator jg = jsonFactory.createGenerator(sw);
144
				jg.writeStartObject();
145

  
146
				jg.writeStringField("@class", specificType.getLocalName());
147
				//******THE FACETS *******//
148
				jg.writeArrayFieldStart("consistsOf");
149
				//list of facets
150
				facetWriter.writeIdentifierFacet(jg, resourceURI);
151
				facetWriter.writeInfoFacet(jg, res);
152
				facetWriter.writeTemporalCoverageFacet(jg, res);
153
				facetWriter.writeRightsFacet(jg, res);
154

  
110 155
				jg.writeEndArray();
156
				jg.writeEndObject();
157
				jg.close();
158
				String json = sw.toString();
159
				log.debug(json);
160
				jsonResources.add(json);
161
				uriProcessed.add(resourceURI);
111 162

  
163
			} else {
164
				log.debug(resourceURI + " already processed, now skipping it");
165
			}
166
		}
112 167

  
168
			log.debug("Processing actors");
169
			//and then the datasets
170
			ResIterator iterActors = model.listResourcesWithProperty(RDF.type, CRM.E39_Actor);
171
			while (iterActors.hasNext()) {
172
				Resource res = iterActors.nextResource();
173
				String resourceURI = res.getURI();
174
				if (!uriProcessed.contains(resourceURI)) {
175
					log.debug("Processing " + resourceURI);
176
					Resource specificType = findSpecificType(res, CRM.E39_Actor);
177
					StringWriter sw = new StringWriter();
178
					JsonGenerator jg = jsonFactory.createGenerator(sw);
179
					jg.writeStartObject();
180

  
181
					jg.writeStringField("@class", specificType.getLocalName());
182
					//******THE FACETS *******//
183
					jg.writeArrayFieldStart("consistsOf");
184
					//list of facets
185
					facetWriter.writeIdentifierFacet(jg, resourceURI);
186
					facetWriter.writeContactReferenceFacet(jg, res);
187

  
188
					jg.writeEndArray();
189
					jg.writeEndObject();
190
					jg.close();
191
					String json = sw.toString();
192
					log.debug(json);
193
					jsonResources.add(json);
194
					uriProcessed.add(resourceURI);
195

  
196
				} else {
197
					log.debug(resourceURI + " already processed, now skipping it");
198
				}
199
			}
200
		log.debug("Processing software");
201
		ResIterator iterSw = model.listResourcesWithProperty(RDF.type, CRMdig.D14_Software);
202
		while (iterSw.hasNext()) {
203
			Resource res = iterSw.nextResource();
204
			String resourceURI = res.getURI();
205
			if (!uriProcessed.contains(resourceURI)) {
206
				log.debug("Processing " + resourceURI);
207
				Resource specificType = findSpecificType(res, CRMdig.D14_Software);
208
				StringWriter sw = new StringWriter();
209
				JsonGenerator jg = jsonFactory.createGenerator(sw);
210
				jg.writeStartObject();
211

  
212
				jg.writeStringField("@class", specificType.getLocalName());
213
				//******THE FACETS *******//
214
				jg.writeArrayFieldStart("consistsOf");
215
				//list of facets
216
				facetWriter.writeIdentifierFacet(jg, resourceURI);
217
				facetWriter.writeInfoFacet(jg, res);
218

  
219
				jg.writeEndArray();
113 220
				jg.writeEndObject();
114 221
				jg.close();
115 222
				String json = sw.toString();
116 223
				log.debug(json);
117 224
				jsonResources.add(json);
118 225
				uriProcessed.add(resourceURI);
226

  
119 227
			} else {
120
				log.debug(resourceURI+" already processed, now skipping it");
228
				log.debug(resourceURI + " already processed, now skipping it");
121 229
			}
122 230
		}
231
		log.debug("Processing projects");
232
		//and then the projects
233
		ResIterator iterProjects = model.listResourcesWithProperty(RDF.type, CRMpe.PE35_Project);
234
		while (iterProjects.hasNext()) {
235
			Resource res = iterProjects.nextResource();
236
			String resourceURI = res.getURI();
237
			if (!uriProcessed.contains(resourceURI)) {
238
				log.debug("Processing " + resourceURI);
239
				Resource specificType = findSpecificType(res, CRMpe.PE35_Project);
240
				StringWriter sw = new StringWriter();
241
				JsonGenerator jg = jsonFactory.createGenerator(sw);
242
				jg.writeStartObject();
243

  
244
				jg.writeStringField("@class", specificType.getLocalName());
245
				//******THE FACETS *******//
246
				jg.writeArrayFieldStart("consistsOf");
247
				//list of facets
248
				facetWriter.writeIdentifierFacet(jg, resourceURI);
249
				facetWriter.writeInfoFacet(jg, res);
250

  
251
				jg.writeEndArray();
252
				jg.writeEndObject();
253
				jg.close();
254
				String json = sw.toString();
255
				log.debug(json);
256
				jsonResources.add(json);
257
				uriProcessed.add(resourceURI);
258

  
259
			} else {
260
				log.debug(resourceURI + " already processed, now skipping it");
261
			}
262
		}
123 263
		return jsonResources;
124 264
	}
125 265

  
266

  
267

  
268

  
126 269
	/**
127 270
	 * Finds the most specific type of res.
128 271
	 * @param res Resource you want to find the most specific type

Also available in: Unified diff