keywords) {this.keywordObjects = keywords;}
+
+ public Float getSearchBoost() { return searchBoost; }
+ public void setSearchBoost(Float boost) { searchBoost = boost; }
+
+ /**
+ * Sorts the ents2ents records into the proper order for display.
+ *
+ */
+ public void sortForDisplay(){
+ if( sorted ) return;
+ if( getObjectPropertyList() == null ) return;
+ sortPropertiesForDisplay();
+ sortEnts2EntsForDisplay();
+ sorted = true;
+ }
+
+ protected void sortEnts2EntsForDisplay(){
+ if( getObjectPropertyList() == null ) return;
+
+ Iterator it = getObjectPropertyList().iterator();
+ while(it.hasNext()){
+ ObjectProperty prop = (ObjectProperty)it.next();
+ prop.sortObjectPropertyStatementsForDisplay(prop,prop.getObjectPropertyStatements());
+ }
+ }
+
+ protected void sortPropertiesForDisplay( ){
+ //here we sort the Property objects
+ Collections.sort(getObjectPropertyList(), new ObjectProperty.DisplayComparator());
+ }
+
+ public static final String [] INCLUDED_IN_JSON = {
+ "URI",
+ "name",
+ "moniker",
+ "vClassId"
+ };
+
+
+ public JSONObject toJSON() throws JSONException {
+ JSONObject jsonObj = new JSONObject(this, INCLUDED_IN_JSON);
+ return jsonObj;
+ }
+ /**
+ *
+ * @param fieldName- expected to be the field name in the format
+ * @return
+ * @throws NoSuchMethodException
+ */
+ public Object getField(String fieldName) throws NoSuchMethodException{
+ if( fieldName == null || fieldName.length() == 0) return null;
+
+ if( "name".equalsIgnoreCase(fieldName) )
+ return getName();
+ if( "timekey".equalsIgnoreCase(fieldName) )
+ return getTimekey();
+
+ //not one of the more common ones, try reflection
+
+ //capitalize first letter
+ String methodName = "get" + fieldName.substring(0,1).toUpperCase()
+ + fieldName.substring(1,fieldName.length());
+
+ Class cls = this.getClass();
+ try {
+ Method meth = cls.getMethod(methodName, (Class[]) null);
+ return meth.invoke(this,(Object[])null);
+ } catch (Exception e) { }
+ //should never get here
+ throw new NoSuchMethodException("Entity.getField() attempt to use a method called "
+ + methodName +"() for field " + fieldName + " but the method doesn't exist.");
+ }
+
+ public int compareTo(Individual o2) {
+ Collator collator = Collator.getInstance();
+ if (o2 == null) {
+ return 1;
+ } else {
+ return collator.compare(this.getName(),o2.getName());
+ }
+ }
+
+}
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/EntityController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/EntityController.java
index 6daa5da4e..587d1b90e 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/EntityController.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/EntityController.java
@@ -25,7 +25,6 @@ import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
-import com.hp.hpl.jena.rdf.model.ModelMaker;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Resource;
@@ -42,6 +41,10 @@ import edu.cornell.mannlib.vitro.webapp.beans.Portal;
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDao;
+import edu.cornell.mannlib.vitro.webapp.filestorage.FileModelHelper;
+import edu.cornell.mannlib.vitro.webapp.filestorage.FileServingHelper;
+import edu.cornell.mannlib.vitro.webapp.filestorage.backend.FileStorage;
+import edu.cornell.mannlib.vitro.webapp.filestorage.backend.FileStorageSetup;
import edu.cornell.mannlib.vitro.webapp.search.beans.VitroQuery;
import edu.cornell.mannlib.vitro.webapp.search.beans.VitroQueryWrapper;
import edu.cornell.mannlib.vitro.webapp.utils.NamespaceMapper;
@@ -97,6 +100,13 @@ public class EntityController extends VitroHttpServlet {
doNotFound(vreq, res);
return;
}
+
+ // If this is an uploaded file, redirect to its "alias URL".
+ String aliasUrl = getAliasUrlForBytestreamIndividual(indiv);
+ if (aliasUrl != null) {
+ res.sendRedirect(req.getContextPath() + aliasUrl);
+ return;
+ }
doHtml( vreq, res , indiv);
return;
@@ -476,6 +486,47 @@ public class EntityController extends VitroHttpServlet {
// TODO Auto-generated method stub
return false;
}
+
+ /**
+ * If this entity represents a File Bytestream, get its alias URL so we can
+ * properly serve the file contents.
+ */
+ private String getAliasUrlForBytestreamIndividual(Individual entity)
+ throws IOException {
+ if (!FileModelHelper.isFileBytestream(entity)) {
+ log.debug("Entity at '" + entity.getURI()
+ + "' is not recognized as a FileByteStream.");
+ return null;
+ }
+
+ FileStorage fs = (FileStorage) getServletContext().getAttribute(
+ FileStorageSetup.ATTRIBUTE_NAME);
+ if (fs == null) {
+ log.error("Servlet context does not contain file storage at '"
+ + FileStorageSetup.ATTRIBUTE_NAME + "'");
+ return null;
+ }
+
+ String filename = fs.getFilename(entity.getURI());
+ if (filename == null) {
+ log.error("Entity at '" + entity.getURI()
+ + "' is recognized as a FileByteStream, "
+ + "but the file system does not recognize it.");
+ return null;
+ }
+
+ String url = FileServingHelper.getBytestreamAliasUrl(entity.getURI(),
+ filename);
+ if (url.equals(entity.getURI())) {
+ log.error("Entity at '" + entity.getURI()
+ + "' is recognized as a FileByteStream, "
+ + "but can't be translated to an alias URL.");
+ return null;
+ }
+
+ log.debug("Alias URL for '" + entity.getURI() + "' is '" + url + "'");
+ return url;
+ }
private Model getRDF(Individual entity, OntModel contextModel, Model newModel, int recurseDepth ) {
Resource subj = newModel.getResource(entity.getURI());
@@ -578,7 +629,7 @@ public class EntityController extends VitroHttpServlet {
out.println("id is the id of the entity to query for. netid also works.
");
out.println("