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

org.linkedopenactors.rdfpub.domain.InstanceProfileDefault Maven / Gradle / Ivy

The newest version!
package org.linkedopenactors.rdfpub.domain;

import java.net.URL;

import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.Literal;
import org.eclipse.rdf4j.model.Model;
import org.eclipse.rdf4j.model.util.Models;
import org.eclipse.rdf4j.model.util.Values;
import org.linkedopenactors.ns.rdfpub.RDFPUB;

import de.naturzukunft.rdf4j.vocabulary.AS;
import de.naturzukunft.rdf4j.vocabulary.SCHEMA_ORG;

/**
 * Representation of the actor-object of this rdf-pub instance.
 * @author [email protected]
 */
class InstanceProfileDefault implements InstanceProfile {

	private URL instanceDomain;
	private RdfObject rdfObject;
	
	/**
	 * 
	 * @param rdfObject
	 * @param instanceDomain
	 */
	public InstanceProfileDefault(RdfObject rdfObject, URL instanceDomain) {
		this.rdfObject = rdfObject;
		this.instanceDomain = instanceDomain;
	}

	/**
	 * Gives you the RDF representation of the actor.
	 * @return The RDF representation of the actor.
	 */
	@Override
	public Model asModel() {
		return rdfObject.getModel();
	}

	public URL getDomain() {
		return instanceDomain;
	}

	@Override
	public IRI getCollectionInbox() {
		return getPropertyIRI(AS.inbox);
	}

	@Override
	public IRI getCollectionOutbox() {
		return getPropertyIRI(AS.outbox);
	}

	@Override
	public IRI getCollectionPublic() {
		return getPropertyIRI(AS.Public);
		
	}

	@Override
	public String getAppVersion() {
		return getPropertyLiteral(RDFPUB.VERSION).stringValue();
	}

	@Override
	public String getIdentifier() {
		return getPropertyLiteral(SCHEMA_ORG.identifier).stringValue();
	}

	@Override
	public IRI getPublicSparqlEndpoint() {
		return getPropertyIRI(RDFPUB.PUBLIC_SPARQL);
	}

	@Override
	public String getPreferedUsername() {
		return getPropertyLiteral(AS.preferredUsername).stringValue();
	}
	
	private IRI getPropertyIRI(IRI predicate) {
		return Models.getPropertyIRI(asModel(), Values.iri(getDomain().toString()), predicate, null, AS.Public)
				.orElseThrow(()->new IllegalStateException("prdicate '"+predicate+"' not found!"));
	}
	
	private Literal getPropertyLiteral(IRI predicate) {
		return Models.getPropertyLiteral(asModel(), Values.iri(getDomain().toString()), predicate, null, AS.Public)
				.orElseThrow(()->new IllegalStateException("prdicate '"+predicate+"' not found!"));
	}

	@Override
	public int getProfileVersion() {
		return getPropertyLiteral(SCHEMA_ORG.version).intValue();
	}

	@Override
	public String toString() {
		return "InstanceProfileDefault [instanceDomain=" + instanceDomain + ", rdfObject=" + rdfObject.getModelAsTurtle() + "]";
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy