NIHVIVO-3295 show the correct placeholder image for profiles that are displayed with the page - does not cover profiles that are obtained by AJAX calls.

This commit is contained in:
j2blake 2011-11-09 21:42:19 +00:00
parent 7f8557bee5
commit f1b98d738e
2 changed files with 108 additions and 12 deletions

View file

@ -20,6 +20,8 @@ import edu.cornell.mannlib.vitro.webapp.controller.accounts.manageproxies.ProxyR
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.utils.ImageUtil;
/**
* TODO
@ -115,28 +117,48 @@ public class ManageProxiesListPage extends AbstractPageHandler {
ProxyRelationshipSelection selection) {
List<ProxyRelationship> wrapped = new ArrayList<ProxyRelationship>();
for (ProxyRelationship r : selection.getProxyRelationships()) {
wrapped.add(new ProxyRelationship(wrapItemList(r.getProxyInfos()),
wrapItemList(r.getProfileInfos())));
wrapped.add(new ProxyRelationship(wrapProxyItemList(r
.getProxyInfos()), wrapProfileItemList(r.getProfileInfos())));
}
return wrapped;
}
private List<ProxyItemInfo> wrapItemList(List<ProxyItemInfo> items) {
private List<ProxyItemInfo> wrapProxyItemList(List<ProxyItemInfo> items) {
List<ProxyItemInfo> wrapped = new ArrayList<ProxyItemInfo>();
for (ProxyItemInfo item : items) {
wrapped.add(wrapItem(item));
wrapped.add(wrapProxyItem(item));
}
return wrapped;
}
private ProxyItemInfo wrapItem(ProxyItemInfo item) {
if (item.getImageUrl().isEmpty()) {
return new ProxyItemInfo(item.getUri(), item.getLabel(),
item.getClassLabel(), DEFAULT_IMAGE_URL);
} else {
return new ProxyItemInfo(item.getUri(), item.getLabel(),
item.getClassLabel(), UrlBuilder.getUrl(item.getImageUrl()));
private List<ProxyItemInfo> wrapProfileItemList(List<ProxyItemInfo> items) {
List<ProxyItemInfo> wrapped = new ArrayList<ProxyItemInfo>();
for (ProxyItemInfo item : items) {
wrapped.add(wrapProfileItem(item));
}
return wrapped;
}
private ProxyItemInfo wrapProxyItem(ProxyItemInfo item) {
String imagePath = item.getImageUrl();
if (imagePath.isEmpty()) {
imagePath = ImageUtil
.getPlaceholderImagePathForType(VitroVocabulary.USERACCOUNT);
}
return new ProxyItemWrapper(item.getUri(), item.getLabel(),
item.getClassLabel(), UrlBuilder.getUrl(imagePath));
}
private ProxyItemInfo wrapProfileItem(ProxyItemInfo item) {
String imagePath = item.getImageUrl();
if (imagePath.isEmpty()) {
imagePath = ImageUtil
.getPlaceholderImagePathForIndividual(vreq, item.getUri());
}
return new ProfileItemWrapper(item.getUri(), item.getLabel(),
item.getClassLabel(), UrlBuilder.getUrl(imagePath));
}
private Map<String, Integer> buildPageMap(
@ -175,4 +197,17 @@ public class ManageProxiesListPage extends AbstractPageHandler {
return map;
}
private static class ProxyItemWrapper extends ProxyItemInfo {
public ProxyItemWrapper(String uri, String label, String classLabel,
String imageUrl) {
super(uri, label, classLabel, imageUrl);
}
}
private static class ProfileItemWrapper extends ProxyItemInfo {
public ProfileItemWrapper(String uri, String label, String classLabel,
String imageUrl) {
super(uri, label, classLabel, imageUrl);
}
}
}

View file

@ -0,0 +1,61 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.utils;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
/**
* Some static methods that help in dealing with image files.
*/
public class ImageUtil {
private static final String DEFAULT_IMAGE_PATH = "/images/placeholders/thumbnail.jpg";
private static final Map<String, String> DEFAULT_IMAGE_PATHS_BY_TYPE = initImagePaths();
private static Map<String, String> initImagePaths() {
Map<String, String> map = new HashMap<String, String>();
// No images other than the default.
return Collections.unmodifiableMap(map);
}
/**
* If we have a placeholder image for this exact type, return it. Otherwise,
* return the default.
*/
public static String getPlaceholderImagePathForType(String typeUri) {
for (Entry<String, String> entry : DEFAULT_IMAGE_PATHS_BY_TYPE
.entrySet()) {
if (typeUri.equals(entry.getKey())) {
return entry.getValue();
}
}
return DEFAULT_IMAGE_PATH;
}
/**
* If there is a placeholder image for any type that this Individual
* instantiates, return that image. Otherwise, return the default.
*/
public static String getPlaceholderImagePathForIndividual(
VitroRequest vreq, String individualUri) {
IndividualDao indDao = vreq.getWebappDaoFactory().getIndividualDao();
for (Entry<String, String> entry : DEFAULT_IMAGE_PATHS_BY_TYPE
.entrySet()) {
if (indDao.isIndividualOfClass(entry.getKey(), individualUri)) {
return entry.getValue();
}
}
return DEFAULT_IMAGE_PATH;
}
/** Never need to instantiate this -- all methods are static. */
private ImageUtil() {
// Nothing to do
}
}