All Downloads are FREE. Search and download functionalities are using the official Maven repository.

it.uniroma2.art.semanticturkey.extensions.sheet2rdf.services.Sheet2RDF Maven / Gradle / Ivy

Go to download

Sheet2RDF extension for Semantic Turkey. Sheet2RDF is a platform for acquisition and transformation of datasheets into RDF.

The newest version!
package it.uniroma2.art.semanticturkey.extensions.sheet2rdf.services;

import it.uniroma2.art.coda.core.CODACore;
import it.uniroma2.art.coda.exception.ConverterException;
import it.uniroma2.art.coda.exception.DependencyException;
import it.uniroma2.art.coda.exception.PRParserException;
import it.uniroma2.art.coda.exception.RDFModelNotSetException;
import it.uniroma2.art.coda.interfaces.annotations.converters.RDFCapabilityType;
import it.uniroma2.art.coda.osgi.bundle.CODAOSGiFactory;
import it.uniroma2.art.coda.pearl.parser.PearlParser;
import it.uniroma2.art.coda.provisioning.ComponentProvisioningException;
import it.uniroma2.art.coda.provisioning.ConverterContractDescription;
import it.uniroma2.art.coda.structures.ARTTriple;
import it.uniroma2.art.coda.structures.SuggOntologyCoda;
import it.uniroma2.art.owlart.exceptions.ModelAccessException;
import it.uniroma2.art.owlart.exceptions.ModelUpdateException;
import it.uniroma2.art.owlart.exceptions.QueryEvaluationException;
import it.uniroma2.art.owlart.exceptions.UnavailableResourceException;
import it.uniroma2.art.owlart.exceptions.UnsupportedQueryLanguageException;
import it.uniroma2.art.owlart.exceptions.UnsupportedRDFFormatException;
import it.uniroma2.art.owlart.io.RDFFormat;
import it.uniroma2.art.owlart.io.RDFNodeSerializer;
import it.uniroma2.art.owlart.model.ARTURIResource;
import it.uniroma2.art.owlart.model.NodeFilters;
import it.uniroma2.art.owlart.models.BaseRDFTripleModel;
import it.uniroma2.art.owlart.models.ModelFactory;
import it.uniroma2.art.owlart.models.OWLArtModelFactory;
import it.uniroma2.art.owlart.models.OWLModel;
import it.uniroma2.art.owlart.models.RDFSModel;
import it.uniroma2.art.owlart.models.conf.ModelConfiguration;
import it.uniroma2.art.owlart.query.MalformedQueryException;
import it.uniroma2.art.owlart.sesame2impl.factory.ARTModelFactorySesame2Impl;
import it.uniroma2.art.owlart.sesame2impl.models.conf.Sesame2ModelConfiguration;
import it.uniroma2.art.owlart.vocabulary.RDFTypesEnum;
import it.uniroma2.art.semanticturkey.exceptions.ProjectInconsistentException;
import it.uniroma2.art.semanticturkey.extensions.sheet2rdf.S2RDFContext;
import it.uniroma2.art.semanticturkey.generation.annotation.GenerateSTServiceController;
import it.uniroma2.art.semanticturkey.generation.annotation.RequestMethod;
import it.uniroma2.art.semanticturkey.ontology.utilities.RDFXMLHelp;
import it.uniroma2.art.semanticturkey.plugin.PluginManager;
import it.uniroma2.art.semanticturkey.services.STServiceAdapter;
import it.uniroma2.art.semanticturkey.services.STServiceContext;
import it.uniroma2.art.semanticturkey.services.annotations.Optional;
import it.uniroma2.art.semanticturkey.servlet.Response;
import it.uniroma2.art.semanticturkey.servlet.ServiceVocabulary.RepliesStatus;
import it.uniroma2.art.semanticturkey.servlet.XMLResponseREPLY;
import it.uniroma2.art.semanticturkey.utilities.XMLHelp;
import it.uniroma2.art.sheet2rdf.coda.Sheet2RDFCODA;
import it.uniroma2.art.sheet2rdf.core.Sheet2RDFCore;
import it.uniroma2.art.sheet2rdf.header.Header;
import it.uniroma2.art.sheet2rdf.header.HeadersStruct;
import it.uniroma2.art.sheet2rdf.sheet.SheetManager;
import it.uniroma2.art.sheet2rdf.sheet.SheetManagerFactory;
import it.uniroma2.art.sheet2rdf.utils.S2RDFUtils;

import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.IOUtils;
import org.apache.uima.UIMAException;
import org.apache.uima.jcas.JCas;
import org.osgi.framework.BundleContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.w3c.dom.DOMException;
import org.w3c.dom.Element;

@GenerateSTServiceController
@Validated
@Component
@Controller //needed for export triples
public class Sheet2RDF extends STServiceAdapter {
	
	private static final String SERVICE_NAME = "Sheet2RDF";
	
	//map that contain  pairs to handle multiple sessions
	private Map contextMap = new HashMap();
	
	@Autowired
	private STServiceContext stServiceContext;
	@Autowired
	private CODAOSGiFactory codaOSGiFactory;
	@Autowired
	private BundleContext bundleContext;
	
	public Sheet2RDF() {
		System.out.println(SERVICE_NAME + " started");
	}
	
	/**
	 * Uploads an excel file into a server directory
	 * @param name
	 * @param file
	 * @return
	 */
	@GenerateSTServiceController (method = RequestMethod.POST)
	public Response uploadSpreadsheet(String name, MultipartFile file) {
		try {
            //create a temp file (in karaf data/temp folder) to copy the received file 
			File serverSpreadsheetFile = File.createTempFile("sheet", name.substring(name.lastIndexOf(".")));
			BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(serverSpreadsheetFile));
			byte[] bytes = file.getBytes();
            stream.write(bytes);
			stream.close();

			// initialize the S2RDFContext and register it
			CODACore codaCore = codaOSGiFactory.getInstance(bundleContext);
			OWLModel model = stServiceContext.getProject().getOWLModel();
			OWLArtModelFactory mf = OWLArtModelFactory.createModelFactory(PluginManager.getOntManagerImpl(
					getProject().getOntologyManagerImplID()).createModelFactory());
			codaCore.initialize(model, mf);
			Sheet2RDFCore s2rdfCore = new Sheet2RDFCore(serverSpreadsheetFile, model);
			S2RDFContext s2rdfCtx = new S2RDFContext(s2rdfCore, codaCore, serverSpreadsheetFile, model);
			String token = stServiceContext.getSessionToken();
			contextMap.put(token, s2rdfCtx);

			XMLResponseREPLY response = createReplyResponse(RepliesStatus.ok);
       		return response;
		} catch (IOException | UnavailableResourceException | ProjectInconsistentException e) {
			e.printStackTrace();
			XMLResponseREPLY response = createReplyFAIL("An exception has been thrown while the excel was uploading");
			return response;
		}
	}
	
	/**
	 * Returns an array list containing the headers of the Excel file's data sheet
	 * @return
	 * @throws ModelAccessException 
	 * @throws DOMException 
	 */
	@GenerateSTServiceController
	public Response getHeaders() throws DOMException, ModelAccessException{
		XMLResponseREPLY resp = createReplyResponse(RepliesStatus.ok);
		Element dataElem = resp.getDataElement();
		S2RDFContext ctx = contextMap.get(stServiceContext.getSessionToken());
		HeadersStruct headersStruct = ctx.getSheet2RDFCore().getHeadersStruct();
		List
headers = headersStruct.getHeaders(); for (Header h : headers){ Element headerElement = XMLHelp.newElement(dataElem, "header"); fillHeaderXMLElement(headerElement, h, headersStruct, ctx.getModel(), ctx.getCodaCore()); } return resp; } /** * Returns information about the header structure with the given id * @param headerId * @return * @throws ModelAccessException * @throws DOMException */ @GenerateSTServiceController public Response getHeaderFromId(String headerId) throws DOMException, ModelAccessException { S2RDFContext ctx = contextMap.get(stServiceContext.getSessionToken()); HeadersStruct headersStruct = ctx.getSheet2RDFCore().getHeadersStruct(); Header h = headersStruct.getHeaderFromId(headerId); XMLResponseREPLY response = createReplyResponse(RepliesStatus.ok); Element dataElem = response.getDataElement(); Element headerElement = XMLHelp.newElement(dataElem, "header"); fillHeaderXMLElement(headerElement, h, headersStruct, ctx.getModel(), ctx.getCodaCore()); return response; } private void fillHeaderXMLElement(Element headerElement, Header h, HeadersStruct headersStruct, RDFSModel model, CODACore codaCore) throws DOMException, ModelAccessException{ XMLHelp.newElement(headerElement, "id", h.getId()); Element nameElement = XMLHelp.newElement(headerElement, "name", h.getHeaderName()); nameElement.setAttribute("isMultiple", headersStruct.isHeaderMultiple(h.getHeaderName())+""); Element propertyElement = XMLHelp.newElement(headerElement, "property", h.getRdfProperty()); //check if h.getRdfProperty is a valid propery or a class String type = "unknown"; try { ARTURIResource resource = model.createURIResource(model.expandQName(h.getRdfProperty())); boolean isProperty = model.isProperty(resource, NodeFilters.ANY); if (isProperty){ type = "property"; } else { boolean isClass = model.isClass(resource, NodeFilters.ANY); if (isClass) type = "class"; } } catch (IllegalArgumentException | ModelAccessException e) {} propertyElement.setAttribute("type", type); XMLHelp.newElement(headerElement, "lang", h.getRangeLanguage()); Element rangeElement = XMLHelp.newElement(headerElement, "range"); rangeElement.setAttribute("rangeType", h.getRangeType().toString()); if (h.getRangeType().equals(RDFTypesEnum.resource) && h.getRangeClass() != null) { RDFXMLHelp.addRDFNode(rangeElement, model, h.getRangeClass(), true, true); } else if (h.getRangeType().equals(RDFTypesEnum.typedLiteral) && h.getRangeDatatype() != null) { RDFXMLHelp.addRDFNode(rangeElement, model, h.getRangeDatatype(), true, true); } Element convElement = XMLHelp.newElement(headerElement, "converter"); convElement.setTextContent(h.getConverterContract().getContractURI()); convElement.setAttribute("name", h.getConverterContract().getContractName()); } /** * Updates information about the header with the given id. In particulars, update the associated * property, eventually the rangeType and the language (if available for the property). * If there are multiple headers with the same name, is possible to apply the changes to all of * them. * @param headerId * @param property * @param rangeType * @param lang * @param applyToAll Tells if the changes must be applied to all the headers with the same name * @return */ @GenerateSTServiceController public Response updateHeader(String headerId, String property, String rangeType, String converter, @Optional String lang, @Optional ARTURIResource rangeClass, @Optional ARTURIResource rangeDatatype, @Optional (defaultValue = "false") boolean applyToAll) { S2RDFContext ctx = contextMap.get(stServiceContext.getSessionToken()); HeadersStruct headersStruct = ctx.getSheet2RDFCore().getHeadersStruct(); Header header = headersStruct.getHeaderFromId(headerId); RDFTypesEnum rngType = RDFTypesEnum.valueOf(rangeType); List
headers = new ArrayList<>(); //headers to update if (applyToAll){ //apply changes to all the headers with same name headers = headersStruct.getHeadersFromName(header.getHeaderName()); } else { headers.add(header); } for (Header h : headers){ h.setRdfProperty(property); h.setRangeType(rngType); //set converter contract description retrieving the ConverterContractDescription object from its uri Collection codaConvList = ctx.getCodaCore().listConverterContracts(); for (ConverterContractDescription convDescr : codaConvList) { if (convDescr.getContractURI().equals(converter)) { h.setConverterContract(convDescr); break; } } //independently from range type, set all the optional fields, so that if not passed //they will be set to null h.setRangeLanguage(lang); h.setRangeClass(rangeClass); h.setRangeDatatype(rangeDatatype); } XMLResponseREPLY response = createReplyResponse(RepliesStatus.ok); return response; } //TODO: soon it will be useful to pass a parameter to indicate whether is required the list //of CODA converter for uri or literal type /** * Returns the list of available CODA converters * rangeType values: resource, plainLiteral, typedLiteral * @return */ @GenerateSTServiceController public Response listConverters(@Optional String rangeType, @Optional ARTURIResource datatype) { XMLResponseREPLY resp = createReplyResponse(RepliesStatus.ok); Element dataElem = resp.getDataElement(); Element collElem = XMLHelp.newElement(dataElem, "collection"); //align range type with RDFCapability name if (rangeType != null && rangeType.equals("resource")) { rangeType = "uri"; } S2RDFContext ctx = contextMap.get(stServiceContext.getSessionToken()); Collection codaConvList = ctx.getCodaCore().listConverterContracts(); for (ConverterContractDescription convDescr : codaConvList) { RDFCapabilityType rdfCapability = convDescr.getRDFCapability(); Set datatypes = convDescr.getDatatypes(); if (rangeType != null && datatype != null) { /* if datatype is provided, return converters only if the required range is typedLiteral * since "reource" and "plainLiteral" range cannot have a datatype */ if (rangeType.equals("typedLiteral") && (rdfCapability.equals(RDFCapabilityType.node) || rdfCapability.equals(RDFCapabilityType.literal) || (rdfCapability.equals(RDFCapabilityType.typedLiteral) && datatypes.contains(datatype)))) { addConverterXMLElement(collElem, convDescr); } } else if (rangeType != null && datatype == null) { //return converter with the required range or which the RDFCapabillity includes the required one //(rdfCapability is node or is literal && required range is typed/plainLiteral) if (rdfCapability.name().equals(rangeType) || rdfCapability.equals(RDFCapabilityType.node) || (rdfCapability.equals(RDFCapabilityType.literal) && (rangeType.contains("Literal")))) { addConverterXMLElement(collElem, convDescr); } } else if (rangeType == null && datatype != null) { //return converters with RDFCapabililty node || literal || typedLiteral with the given datatype if (rdfCapability.equals(RDFCapabilityType.literal) || rdfCapability.equals(RDFCapabilityType.node)) { addConverterXMLElement(collElem, convDescr); } else if (rdfCapability.equals(RDFCapabilityType.typedLiteral) && datatypes.contains(datatype)) { addConverterXMLElement(collElem, convDescr); } } else if (rangeType == null && datatype == null) {//return all converters addConverterXMLElement(collElem, convDescr); } } return resp; } private void addConverterXMLElement(Element collElement, ConverterContractDescription convDescr) { Element contractElem = XMLHelp.newElement(collElement, "converterContract"); contractElem.setAttribute("uri", convDescr.getContractURI()); contractElem.setAttribute("name", convDescr.getContractName()); contractElem.setAttribute("description", convDescr.getContractDescription()); } /** * Returns a preview of the sheet containing the first maxRows rows * @param maxRows * @return */ @GenerateSTServiceController public Response getTablePreview(int maxRows){ S2RDFContext ctx = contextMap.get(stServiceContext.getSessionToken()); SheetManager sheetMgr = SheetManagerFactory.getSheetManager(ctx.getSpreadsheetFile()); ArrayList> table = sheetMgr.getDataTable(); XMLResponseREPLY resp = createReplyResponse(RepliesStatus.ok); Element dataElem = resp.getDataElement(); int rowsToReturn = maxRows; if (table.size() < rowsToReturn) rowsToReturn = table.size(); Element collElem = XMLHelp.newElement(dataElem, "collection"); collElem.setAttribute("returned", rowsToReturn+""); collElem.setAttribute("total", table.size()+""); for (int r = 0; r < rowsToReturn; r++){ Element rowElem = XMLHelp.newElement(collElem, "row"); rowElem.setAttribute("idx", r+""); for (int c = 0; c < table.get(0).size(); c++){ String cellValue = table.get(r).get(c); if (!cellValue.equals("")){ Element cellElem = XMLHelp.newElement(rowElem, "cell"); cellElem.setAttribute("idx", c+"");//column index in excel spreadsheet cellElem.setAttribute("value", cellValue); } } } return resp; } /** * Returns the PEARL code generated by Excel2RDF * @return * @throws IOException * @throws ModelAccessException */ @GenerateSTServiceController public Response getPearl(@Optional String skosSchema) throws IOException, ModelAccessException{ File pearlFile = File.createTempFile("pearl", ".pr"); S2RDFContext ctx = contextMap.get(stServiceContext.getSessionToken()); Sheet2RDFCore s2rdfCore = ctx.getSheet2RDFCore(); if (skosSchema != null) s2rdfCore.generatePearlFile(pearlFile, skosSchema); else s2rdfCore.generatePearlFile(pearlFile); ctx.setPearlFile(pearlFile); String pearl = S2RDFUtils.pearlFileToString(pearlFile); XMLResponseREPLY resp = createReplyResponse(RepliesStatus.ok); Element dataElem = resp.getDataElement(); dataElem.setTextContent(pearl); return resp; } /** * Saves/updates the PEARL code eventually edited by user * @return * @throws FileNotFoundException */ @GenerateSTServiceController (method = RequestMethod.POST) public Response savePearl(String pearlCode) throws FileNotFoundException{ S2RDFContext ctx = contextMap.get(stServiceContext.getSessionToken()); PrintWriter pw = new PrintWriter(ctx.getPearlFile()); pw.print(pearlCode); pw.close(); XMLResponseREPLY response = createReplyResponse(RepliesStatus.ok); return response; } @GenerateSTServiceController (method = RequestMethod.POST) public Response validatePearl(String pearlCode){ InputStream pearlStream = new ByteArrayInputStream(pearlCode.getBytes(StandardCharsets.UTF_8)); PearlParser pearlParser = new PearlParser("", ""); boolean pearlValid; try { pearlParser.parsePearlDocument(pearlStream, getOWLModel()); pearlValid = true; } catch (PRParserException e) { pearlValid = false; } XMLResponseREPLY response = createBooleanResponse(pearlValid); return response; } /** * Uploads a pearl file into a server directory and returns the code * @param name * @param file * @return */ @GenerateSTServiceController (method = RequestMethod.POST) public Response uploadPearl(MultipartFile file) { try { //upload the file on the server (in karaf data/temp folder) S2RDFContext s2rdfCtx = contextMap.get(stServiceContext.getSessionToken()); File pearlServerFile = File.createTempFile("pearl", ".pr"); BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(pearlServerFile)); byte[] bytes = file.getBytes(); stream.write(bytes); stream.close(); //update the pearl in the context s2rdfCtx.setPearlFile(pearlServerFile); XMLResponseREPLY response = createReplyResponse(RepliesStatus.ok); Element dataElem = response.getDataElement(); String pearlCode = S2RDFUtils.pearlFileToString(pearlServerFile); dataElem.setTextContent(pearlCode); return response; } catch (IOException e) { e.printStackTrace(); XMLResponseREPLY response = createReplyFAIL("An exception has been thrown while the pearl file was uploading"); return response; } } /** * Returns triples generated by Sheet2RDF * XML Response structure: data -> triple -> subject, predicate, object. This means that inside * data element will be some triple element containing subject predicate and object element * @param maxTriples number of max triples to return to the preview * @return * @throws QueryEvaluationException * @throws MalformedQueryException * @throws ModelAccessException * @throws UnsupportedQueryLanguageException * @throws ConverterException * @throws ComponentProvisioningException * @throws PRParserException * @throws UIMAException * @throws DependencyException * @throws ProjectInconsistentException * @throws UnavailableResourceException * @throws RDFModelNotSetException * @throws Exception */ @GenerateSTServiceController public Response getTriplesPreview(int maxTriples) throws UIMAException, PRParserException, ComponentProvisioningException, ConverterException, UnsupportedQueryLanguageException, ModelAccessException, MalformedQueryException, QueryEvaluationException, DependencyException, UnavailableResourceException, ProjectInconsistentException, RDFModelNotSetException { S2RDFContext ctx = contextMap.get(stServiceContext.getSessionToken()); JCas jcas = ctx.getSheet2RDFCore().executeAnnotator(); ModelFactory modelFact = PluginManager.getOntManagerImpl( stServiceContext.getProject().getOntologyManagerImplID()).createModelFactory(); Sheet2RDFCODA s2rdfCoda = new Sheet2RDFCODA(ctx.getModel(), modelFact, ctx.getCodaCore()); List listSuggOntCoda = new ArrayList(); listSuggOntCoda = s2rdfCoda.suggestTriples(jcas, ctx.getPearlFile()); ctx.setSuggestedTriples(listSuggOntCoda); int triplesToReturn = maxTriples; if (listSuggOntCoda.size() < triplesToReturn) triplesToReturn = listSuggOntCoda.size(); XMLResponseREPLY resp = createReplyResponse(RepliesStatus.ok); Element dataElem = resp.getDataElement(); Element collElem = XMLHelp.newElement(dataElem, "collection"); int tripleSetCount = 0; for (int i=0; i tripleList = suggOntCoda.getAllARTTriple(); if (!tripleList.isEmpty()){ tripleSetCount++; } for (ARTTriple t : tripleList){ Element tripleElem = XMLHelp.newElement(collElem, "triple"); //to specify which row of excel datasheet generate that triple tripleElem.setAttribute("row", suggOntCoda.getAnnotation().getBegin()+""); XMLHelp.newElement(tripleElem, "subject", RDFNodeSerializer.toNT(t.getSubject())); XMLHelp.newElement(tripleElem, "predicate", RDFNodeSerializer.toNT(t.getPredicate())); XMLHelp.newElement(tripleElem, "object", RDFNodeSerializer.toNT(t.getObject())); } } collElem.setAttribute("total", tripleSetCount+""); if (tripleSetCount > triplesToReturn) collElem.setAttribute("returned", triplesToReturn+""); else collElem.setAttribute("returned", tripleSetCount+""); return resp; } /** * Simply adds the triples generated to the model * @return * @throws UnsupportedRDFFormatException * @throws ModelUpdateException * @throws ModelAccessException * @throws IOException * @throws FileNotFoundException */ @GenerateSTServiceController public Response addTriples() throws FileNotFoundException, IOException, ModelAccessException, ModelUpdateException, UnsupportedRDFFormatException{ S2RDFContext ctx = contextMap.get(stServiceContext.getSessionToken()); RDFSModel model = ctx.getModel(); List suggTriples = ctx.getCachedSuggestedTriples(); for (SuggOntologyCoda sugg : suggTriples){ List triples = sugg.getAllARTTriple(); for (ARTTriple t : triples){ model.addTriple(t.getSubject(), t.getPredicate(), t.getObject(), NodeFilters.MAINGRAPH); } } XMLResponseREPLY response = createReplyResponse(RepliesStatus.ok); return response; } @RequestMapping(value = "/Sheet2RDF/exportTriples", method = org.springframework.web.bind.annotation.RequestMethod.GET) public void exportTriples(HttpServletResponse oRes, @RequestParam(value = "format") String format, @RequestParam(value = "allNGs", defaultValue = "false") boolean allNGs) throws IOException, ModelAccessException, UnsupportedRDFFormatException, ModelUpdateException{ S2RDFContext ctx = contextMap.get(stServiceContext.getSessionToken()); //Write suggested triples in a temporary model List suggTriples = ctx.getCachedSuggestedTriples(); OWLArtModelFactory fact = OWLArtModelFactory.createModelFactory(new ARTModelFactorySesame2Impl()); BaseRDFTripleModel tempModel = fact.createLightweightRDFModel(); for (SuggOntologyCoda sugg : suggTriples){ List triples = sugg.getAllARTTriple(); for (ARTTriple t : triples){ tempModel.addTriple(t.getSubject(), t.getPredicate(), t.getObject(), NodeFilters.MAINGRAPH); } } //serialize the temporary model on a server side temporary file File tempServerFile = File.createTempFile("triples", "."+format); RDFFormat rdfFormat = RDFFormat.guessRDFFormatFromFile(tempServerFile); if (rdfFormat == null) rdfFormat = RDFFormat.RDFXML; if (allNGs) tempModel.writeRDF(tempServerFile, rdfFormat, getUserNamedGraphs()); else tempModel.writeRDF(tempServerFile, rdfFormat, getWorkingGraph()); //return the temporary file on the response output stream FileInputStream is = new FileInputStream(tempServerFile); IOUtils.copy(is, oRes.getOutputStream()); oRes.setContentType(rdfFormat.getMIMEType()); oRes.setContentLength((int) tempServerFile.length()); oRes.setHeader("Content-Disposition", "attachment; filename=triples." + format); oRes.flushBuffer(); is.close(); } @GenerateSTServiceController public Response closeSession() { String token = stServiceContext.getSessionToken(); contextMap.remove(token); XMLResponseREPLY response = createReplyResponse(RepliesStatus.ok); return response; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy