package controller;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Collections;
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 ListAllFilmsController implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
SearchableObjectArray results = new SearchableObjectArray();
String queryText = "SELECT DISTINCT ?uri ?title WHERE { " +
"?uri rdf:type h2mdb:Film . " +
"?uri h2mdb:name ?title . " +
"} ";
ResultSet resultSet = OntologyQueryer.resultQuery(queryText);
while (resultSet.hasNext()) {
QuerySolution result = resultSet.next();
results.add(new Movie(result.get("uri").toString(), result.get("title").toString().replace("@en", "")));
}
Collections.sort(results, new SearchableComparator());
Window window = MainController.getInstance().getWindow();
window.getHistory().add(new SearchResultView(window.getPanelCount(), new SearchController(), results));
}
}