Commit 0a7b4ecf authored by Matija Obreza's avatar Matija Obreza

RDF crop, descriptor controllers updated for production

parent 04980747
......@@ -497,9 +497,8 @@
<dependency>
<groupId>org.bioversityinternational</groupId>
<artifactId>org.bioversityinternational.ontology</artifactId>
<version>0.0.6</version>
<version>0.6.2</version>
</dependency>
</dependencies>
<build>
......
......@@ -19,6 +19,12 @@ package org.genesys2.server.servlet.controller.rdf;
import java.util.List;
import java.util.Map;
import org.bioversityinternational.model.germplasm.CCO;
import org.bioversityinternational.model.rdf.dwc.DarwinCore;
import org.genesys2.server.model.impl.Crop;
import org.genesys2.server.model.impl.CropRule;
import org.genesys2.server.service.CropService;
import org.genesys2.spring.ResourceNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
......@@ -33,19 +39,12 @@ import com.hp.hpl.jena.vocabulary.DC;
import com.hp.hpl.jena.vocabulary.RDF;
import com.hp.hpl.jena.vocabulary.RDFS;
import org.genesys2.server.model.impl.Crop;
import org.genesys2.server.model.impl.CropRule;
import org.genesys2.server.service.CropService;
import org.genesys2.spring.ResourceNotFoundException;
import org.bioversityinternational.model.germplasm.CCO;
import org.bioversityinternational.model.rdf.dwc.DarwinCore;
@Controller
@RequestMapping(value = "/crops", method = RequestMethod.GET, headers = "accept=text/turtle", produces = RdfBaseController.RDF_MEDIATYPE_TURTLE)
public class CropControllerRdf extends RdfBaseController {
public static final String CROPS_NS = getBaseUri()+"/crops/";;
public static final String SPECIES_NS = CROPS_NS+"species/" ;
private final String CROPS_NS = "/crops/";
private final String SPECIES_NS = CROPS_NS + "species/";
@Autowired
private CropService cropService;
......@@ -71,44 +70,41 @@ public class CropControllerRdf extends RdfBaseController {
.
*/
private void wrapCrop(Model model, Crop crop) {
Resource cropSubj = createSubject(model, crop, CROPS_NS+crop.getId(), crop.getShortName()+" Taxon") ;
cropSubj.addProperty(DarwinCore.scientificName, crop.getShortName()) ;
String seeAlso = crop.getRdfUri() ;
if(seeAlso!=null)
cropSubj.addProperty(
RDFS.seeAlso,
model.createResource(seeAlso)
) ;
Resource cropSubj = createSubject(model, crop, CROPS_NS + crop.getShortName(), crop.getShortName() + " Taxon");
// FIXME That's probably not right
cropSubj.addProperty(DarwinCore.scientificName, crop.getShortName());
String seeAlso = crop.getRdfUri();
if (seeAlso != null)
cropSubj.addProperty(RDFS.seeAlso, model.createResource(seeAlso));
/*
* vernacular names & descriptions in i18n
*/
Map<String,String> vernacularNameMap = crop.getLocalNameMap() ;
if(vernacularNameMap!=null)
for( String language : vernacularNameMap.keySet() ) {
Literal vernacularNameLiteral =
model.createLiteral(vernacularNameMap.get(language), language) ;
cropSubj.addLiteral(DarwinCore.vernacularName,vernacularNameLiteral) ;
*/
Map<String, String> vernacularNameMap = crop.getLocalNameMap();
if (vernacularNameMap != null)
for (String language : vernacularNameMap.keySet()) {
Literal vernacularNameLiteral = model.createLiteral(vernacularNameMap.get(language), language);
cropSubj.addLiteral(DarwinCore.vernacularName, vernacularNameLiteral);
}
else
this._logger.warn("Empty vernacular crop name map for crop "+crop.getShortName());
Map<String,String> vernacularDefinitionMap = crop.getLocalDefinitionMap() ;
if(vernacularDefinitionMap!=null)
for( String language : vernacularDefinitionMap.keySet() ) {
Literal vernacularDefinitionLiteral =
model.createLiteral(vernacularDefinitionMap.get(language), language) ;
cropSubj.addLiteral(DC.description,vernacularDefinitionLiteral) ;
this._logger.warn("Empty vernacular crop name map for crop " + crop.getShortName());
Map<String, String> vernacularDefinitionMap = crop.getLocalDefinitionMap();
if (vernacularDefinitionMap != null)
for (String language : vernacularDefinitionMap.keySet()) {
Literal vernacularDefinitionLiteral = model.createLiteral(vernacularDefinitionMap.get(language), language);
cropSubj.addLiteral(DC.description, vernacularDefinitionLiteral);
}
else
this._logger.warn("Empty vernacular crop description map for crop "+crop.getShortName());
this._logger.warn("Empty vernacular crop description map for crop " + crop.getShortName());
/* Exemplar for CropRule species...
/*
* Exemplar for CropRule species...
*
genesys:MusaAcuminata a cco:Species;
dwc:scientificName "Musa acuminata" ;
......@@ -122,55 +118,53 @@ public class CropControllerRdf extends RdfBaseController {
Note: current GENESYS data model does NOT track the description of a species...
*/
List<CropRule> rules = cropService.getCropRules(crop) ;
for(CropRule cr : rules) {
String species = cr.getSpecies() ;
String genus = cr.getGenus() ;
Boolean isIncluded = cr.isIncluded() ;
Resource speciesSubj =
createSubject(
model,
crop,
SPECIES_NS+canonicalID(species,true),
species
) ;
speciesSubj.addProperty(RDF.type, CCO.Species ) ;
speciesSubj.addProperty(DarwinCore.scientificName, species ) ;
speciesSubj.addProperty(DarwinCore.genus, genus ) ;
speciesSubj.addProperty(CCO.speciesIncluded, isIncluded.toString() ) ;
List<CropRule> rules = cropService.getCropRules(crop);
for (CropRule cr : rules) {
String species = cr.getSpecies();
String genus = cr.getGenus();
Boolean isIncluded = cr.isIncluded();
// FIXME in CropRule the Genus is required, species is not.
if (species != null) {
Resource speciesSubj = createSubject(model, crop, SPECIES_NS + canonicalID(species, true), species);
speciesSubj.addProperty(RDF.type, CCO.Species);
speciesSubj.addProperty(DarwinCore.scientificName, species);
speciesSubj.addProperty(DarwinCore.genus, genus);
speciesSubj.addProperty(CCO.speciesIncluded, isIncluded.toString());
}
}
}
@RequestMapping
public @ResponseBody
String dumpCrops() {
Model model = startModel() ;
List<Crop> crops = cropService.listCrops() ;
for(Crop crop : crops) wrapCrop( model, crop) ;
Model model = startModel();
List<Crop> crops = cropService.listCrops();
for (Crop crop : crops)
wrapCrop(model, crop);
return endModel(model) ;
return endModel(model);
}
@RequestMapping("/{shortName}")
public @ResponseBody
String dumpCrop(@PathVariable(value = "shortName") String shortName) {
_logger.debug("Dump RDF data for crop: " + shortName);
Model model = startModel() ;
Model model = startModel();
Crop crop = cropService.getCrop(shortName);
if (crop == null) {
throw new ResourceNotFoundException();
}
wrapCrop(model,crop) ;
return endModel(model) ;
wrapCrop(model, crop);
return endModel(model);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment