package de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction;

import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.jena.ontology.Individual;
import org.apache.jena.ontology.OntClass;
import org.apache.jena.ontology.OntModel;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.util.iterator.ExtendedIterator;

public class CityService {
	private String uri;
	private ArrayList<String> domains;
	private Map<String,ArrayList<String>> superDomains;

	public CityService() {
		uri = "";
		domains = new ArrayList<>();
		setSuperDomains(new HashMap<>());
	}

	public String getUri() {
		return uri;
	}

	public void setUri(String uri) {
		this.uri = uri;
	}

	public ArrayList<String> getDomains() {
		return domains;
	}

	public void setDomains(ArrayList<String> domains) {
		this.domains = domains;
	}

	public Map<String,ArrayList<String>> getSuperDomains() {
		return superDomains;
	}

	public void setSuperDomains(Map<String,ArrayList<String>> superDomains) {
		this.superDomains = superDomains;
	}
	
	public void loadSuperDomains(){
		OntModel m = ModelFactory.createOntologyModel("http://www.w3.org/2002/07/owl#");
		try{
			FileInputStream inputStream;
			inputStream = new FileInputStream("../../SmartCitySD/Data/ontologies/surfOntology-1-0-0/surfOntology-1.0.0.owl");
			m.read(inputStream,null);
			inputStream.close();
			for(int i=0; i<this.getDomains().size();i++){
				ArrayList<String> superDomainsList = new ArrayList<String>();
				Individual individual = m.getIndividual(this.getDomains().get(i));
				OntClass c = individual.getOntClass(true);
				superDomainsList.add(c.getURI());
				ExtendedIterator<OntClass> superClasses = c.listSuperClasses();
				List<OntClass> superClassesDomain = superClasses.toList();
				for(int j=0; j<superClassesDomain.size();j++){
					if(!superDomainsList.contains(superClassesDomain.get(j).getURI()) && !superClassesDomain.get(j).getURI().equals("http://www.surf.scss.tcd.ie/cityOntology/#Domain") && !superClassesDomain.get(j).getURI().equals("http://www.w3.org/2000/01/rdf-schema#Resource"))
						superDomainsList.add(superClassesDomain.get(j).getURI());
				}
				this.getSuperDomains().put(this.getDomains().get(i), superDomainsList);
			}
		}catch(Exception ex){
			ex.printStackTrace();
		}
	}
}
