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

it.uniroma2.art.sheet2rdf.header.SimpleGraphApplication Maven / Gradle / Ivy

There is a newer version: 6.0.6
Show newest version
package it.uniroma2.art.sheet2rdf.header;

import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.impl.SimpleValueFactory;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;

import it.uniroma2.art.sheet2rdf.utils.JsonConstants;

public class SimpleGraphApplication extends GraphApplication {
	
	private String nodeId; //id of the node that represent the subject in the s-p-o triple defined by the graph application
	private IRI property;
	private IRI type;	//in case of rangeType resource
	
	public SimpleGraphApplication() {
		super();
	}
	
	public String getNodeId() {
		return nodeId;
	}

	public void setNodeId(String nodeId) {
		this.nodeId = nodeId;
	}
	
	@Override
	public void removeNode(String nodeId) {
		if (this.nodeId == nodeId) {
			this.nodeId = null;
		}
	}

	public IRI getProperty() {
		return property;
	}
	
	public void setProperty(IRI property) {
		this.property = property;
	}
	
	public IRI getType() {
		return type;
	}
	
	public void setType(IRI type) {
		this.type = type;
	}
	
	@Override
	public JsonNode toJson() {
		JsonNodeFactory jsonFactory = JsonNodeFactory.instance;
		ObjectNode graphJson = jsonFactory.objectNode();
		graphJson.set(JsonConstants.SIMPLE_GRAPH_APPLICATION_ID, jsonFactory.textNode(getId()));
		if (property != null) {
			graphJson.set(JsonConstants.SIMPLE_GRAPH_APPLICATION_PROPERY, jsonFactory.textNode(property.stringValue()));
		} else {
			graphJson.set(JsonConstants.SIMPLE_GRAPH_APPLICATION_PROPERY, null);
		}
		if (type != null) {
			graphJson.set(JsonConstants.SIMPLE_GRAPH_APPLICATION_TYPE, jsonFactory.textNode(type.stringValue()));
		} else {
			graphJson.set(JsonConstants.SIMPLE_GRAPH_APPLICATION_TYPE, null);
		}
		graphJson.set(JsonConstants.SIMPLE_GRAPH_APPLICATION_NODE_ID, jsonFactory.textNode(nodeId));
		return graphJson;
	}
	
	@Override
	public void fromJson(JsonNode jsonNode) {
		SimpleValueFactory svf = SimpleValueFactory.getInstance();
		this.id = jsonNode.get(JsonConstants.SIMPLE_GRAPH_APPLICATION_ID).asText();
		String propertyJson = jsonNode.get(JsonConstants.SIMPLE_GRAPH_APPLICATION_PROPERY).asText();
		this.property = (!propertyJson.equals("null")) ? svf.createIRI(propertyJson) : null;
		String typeJson = jsonNode.get(JsonConstants.SIMPLE_GRAPH_APPLICATION_TYPE).asText();
		this.type = (!typeJson.equals("null")) ? svf.createIRI(typeJson) : null;
		this.nodeId = jsonNode.get(JsonConstants.SIMPLE_GRAPH_APPLICATION_NODE_ID).asText();
	}
	
	@Override
	public String toString() {
		String s = "";
		s += "id:\t" + this.id + "\n";
		s += "prop:\t" + (this.property != null ? this.property.stringValue() : null) + "\n";
		s += "type:\t" + (this.type != null ? this.type.stringValue() : null) + "\n";
		s += "nodeId:\t" + this.nodeId;
		return s;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy