NIHVIVO-161 Change how the Individual page shows images, editable or non-editable; for Persons or non-Persons, in accordance with the wireframes.

This commit is contained in:
jeb228 2010-06-25 21:19:39 +00:00
parent bf0d9bdb08
commit 8dc823f663
3 changed files with 114 additions and 61 deletions

View file

@ -6,6 +6,7 @@ import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
@ -44,6 +45,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatementImpl;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.RdfLiteralHash;
import edu.cornell.mannlib.vitro.webapp.filestorage.FileModelHelper;
import edu.cornell.mannlib.vitro.webapp.utils.FrontEndEditingUtils;
import edu.cornell.mannlib.vitro.webapp.utils.StringUtils;
@ -157,8 +159,10 @@ public class PropertyEditLinks extends TagSupport{
ObjectPropertyStatement prop = new ObjectPropertyStatementImpl(subjectUri, predicateUri, data);
links = doObjPropStmt( prop, policyToAccess(ids, policy, prop), contextPath );
}
}
else {
} else if (VitroVocabulary.IND_MAIN_IMAGE.equals(predicateUri)) {
links = doImageLinks(entity, ids, policy, contextPath);
} else {
log.error("PropertyEditLinks cannot make links for an object of type " + predicateUri);
return SKIP_BODY;
}
@ -234,18 +238,14 @@ public class PropertyEditLinks extends TagSupport{
if( contains( allowedAccessTypeArray, EditLinkAccess.ADDNEW ) ){
log.debug("vitro namespace property "+propertyUri+" gets an \"add\" link");
LinkStruct ls = null;
if (propertyUri.equals(VitroVocabulary.IND_MAIN_IMAGE)) {
ls = getImageLink(subjectUri, contextPath, "add");
} else {
String url = makeRelativeHref(contextPath +"edit/editDatapropStmtRequestDispatch.jsp",
"subjectUri", subjectUri,
"predicateUri", propertyUri,
"vitroNsProp", "true");
ls = new LinkStruct();
ls.setHref( url );
ls.setType("add");
ls.setMouseoverText("add a new entry");
}
String url = makeRelativeHref(contextPath +"edit/editDatapropStmtRequestDispatch.jsp",
"subjectUri", subjectUri,
"predicateUri", propertyUri,
"vitroNsProp", "true");
ls = new LinkStruct();
ls.setHref( url );
ls.setType("add");
ls.setMouseoverText("add a new entry");
links[0] = ls;
} else {
log.debug("no add link generated for vitro namespace property "+propertyUri);
@ -345,17 +345,6 @@ public class PropertyEditLinks extends TagSupport{
LinkStruct[] links = new LinkStruct[2];
if (predicateUri.equals(VitroVocabulary.IND_MAIN_IMAGE)) {
if( contains( allowedAccessTypeArray, EditLinkAccess.MODIFY ) ){
log.debug("permission found to UPDATE vitro namepsace property statement "+ predicateUri);
links[0] = getImageLink(subjectUri, contextPath, "edit");
return links;
}
else {
log.debug("NO permission found to DELETE vitro namespace property " + predicateUri);
}
}
String value = dpropStmt.getData();
Model model = (Model)pageContext.getServletContext().getAttribute("jenaOntModel");
@ -479,6 +468,53 @@ public class PropertyEditLinks extends TagSupport{
return links;
}
protected LinkStruct[] doImageLinks(Individual entity,
IdentifierBundle ids, PolicyIface policy, String contextPath) {
Individual mainImage = FileModelHelper.getMainImage(entity);
String subjectUri = entity.getURI();
String predicateUri = VitroVocabulary.IND_MAIN_IMAGE;
if (mainImage == null) {
EditLinkAccess[] accesses = policyToAccess(ids, policy, subjectUri,
predicateUri);
if (contains(accesses, EditLinkAccess.ADDNEW)) {
log.debug("permission to ADD main image to " + subjectUri);
return new LinkStruct[] { getImageLink(subjectUri, contextPath,
"edit", "upload an image") };
} else {
log.debug("NO permission to ADD main image to " + subjectUri);
return empty_array;
}
} else {
ObjectPropertyStatement prop = new ObjectPropertyStatementImpl(
subjectUri, predicateUri, mainImage.getURI());
EditLinkAccess[] allowedAccessTypeArray = policyToAccess(ids,
policy, prop);
List<LinkStruct> links = new ArrayList<LinkStruct>();
if (contains(allowedAccessTypeArray, EditLinkAccess.MODIFY)) {
log.debug("permission to MODIFY main image to " + subjectUri);
links.add(getImageLink(subjectUri, contextPath, "edit",
"replace this image"));
} else {
log.debug("NO permission to MODIFY main image to "
+ subjectUri);
}
if (contains(allowedAccessTypeArray, EditLinkAccess.DELETE)) {
log.debug("permission to DELETE main image to " + subjectUri);
links.add(getImageLink(subjectUri, contextPath, "delete",
"delete this image"));
} else {
log.debug("NO permission to DELETE main image to "
+ subjectUri);
}
return links.toArray(new LinkStruct[links.size()]);
}
}
/* ********************* utility methods ********************************* */
protected static String makeRelativeHref( String baseUrl, String ... queries ) {
@ -636,15 +672,16 @@ public class PropertyEditLinks extends TagSupport{
private LinkStruct[] empty_array = {};
private LinkStruct getImageLink(String subjectUri, String contextPath, String action) {
LinkStruct ls = new LinkStruct();
String url = makeRelativeHref(contextPath + "uploadimages.jsp",
"entityUri", subjectUri);
ls.setHref(url);
ls.setType(action);
ls.setMouseoverText("upload a new image");
return ls;
}
private LinkStruct getImageLink(String subjectUri, String contextPath,
String action, String mouseOverText) {
LinkStruct ls = new LinkStruct();
String url = makeRelativeHref(contextPath + "uploadimages.jsp",
"entityUri", subjectUri);
ls.setHref(url);
ls.setType(action);
ls.setMouseoverText(mouseOverText);
return ls;
}
private String getObjPropMouseoverLabel(String propertyUri) {
String mouseoverText = "relationship"; // default