package controller;
import java.util.Collections;
import model.array.HistoryArray;
import model.array.SearchableObjectArray;
import model.array.tools.SearchableComparator;
import model.movie.Movie;
import model.query.OntologyQueryer;
import view.Window;
import view.panels.SearchResultView;
import com.hp.hpl.jena.query.QuerySolution;
import com.hp.hpl.jena.query.ResultSet;
public class FilmDecadeController extends DecadeController {
@Override
public void decadeSelected(String uri) {
SearchableObjectArray results = new SearchableObjectArray();
Window window = MainController.getInstance().getWindow();
HistoryArray history = window.getHistory();
String queryText = "SELECT ?uri ?title WHERE { " +
"?uri rdf:type <" + uri + "> . " +
"?uri h2mdb:name ?title . " +
"} ";
ResultSet resultSet = OntologyQueryer.resultQuery(queryText);
while(resultSet.hasNext()) {
QuerySolution solution = resultSet.next();
results.add(new Movie(solution.get("uri").toString(), solution.get("title").toString().replace("@en", "")));
}
Collections.sort(results, new SearchableComparator());
history.add(new SearchResultView(window.getPanelCount(), new SearchController(), results));
}
}