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:
parent
7f8557bee5
commit
f1b98d738e
2 changed files with 108 additions and 12 deletions
|
@ -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.UrlBuilder;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
|
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.controller.freemarker.responsevalues.TemplateResponseValues;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.utils.ImageUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO
|
* TODO
|
||||||
|
@ -99,7 +101,7 @@ public class ManageProxiesListPage extends AbstractPageHandler {
|
||||||
body.put("profileTypes", buildProfileTypesString());
|
body.put("profileTypes", buildProfileTypesString());
|
||||||
|
|
||||||
body.put("formUrls", buildUrlsMap());
|
body.put("formUrls", buildUrlsMap());
|
||||||
|
|
||||||
applyMessage(vreq, body);
|
applyMessage(vreq, body);
|
||||||
|
|
||||||
log.debug("body map is: " + body);
|
log.debug("body map is: " + body);
|
||||||
|
@ -115,28 +117,48 @@ public class ManageProxiesListPage extends AbstractPageHandler {
|
||||||
ProxyRelationshipSelection selection) {
|
ProxyRelationshipSelection selection) {
|
||||||
List<ProxyRelationship> wrapped = new ArrayList<ProxyRelationship>();
|
List<ProxyRelationship> wrapped = new ArrayList<ProxyRelationship>();
|
||||||
for (ProxyRelationship r : selection.getProxyRelationships()) {
|
for (ProxyRelationship r : selection.getProxyRelationships()) {
|
||||||
wrapped.add(new ProxyRelationship(wrapItemList(r.getProxyInfos()),
|
wrapped.add(new ProxyRelationship(wrapProxyItemList(r
|
||||||
wrapItemList(r.getProfileInfos())));
|
.getProxyInfos()), wrapProfileItemList(r.getProfileInfos())));
|
||||||
}
|
}
|
||||||
return wrapped;
|
return wrapped;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<ProxyItemInfo> wrapItemList(List<ProxyItemInfo> items) {
|
private List<ProxyItemInfo> wrapProxyItemList(List<ProxyItemInfo> items) {
|
||||||
List<ProxyItemInfo> wrapped = new ArrayList<ProxyItemInfo>();
|
List<ProxyItemInfo> wrapped = new ArrayList<ProxyItemInfo>();
|
||||||
for (ProxyItemInfo item : items) {
|
for (ProxyItemInfo item : items) {
|
||||||
wrapped.add(wrapItem(item));
|
wrapped.add(wrapProxyItem(item));
|
||||||
}
|
}
|
||||||
return wrapped;
|
return wrapped;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ProxyItemInfo wrapItem(ProxyItemInfo item) {
|
private List<ProxyItemInfo> wrapProfileItemList(List<ProxyItemInfo> items) {
|
||||||
if (item.getImageUrl().isEmpty()) {
|
List<ProxyItemInfo> wrapped = new ArrayList<ProxyItemInfo>();
|
||||||
return new ProxyItemInfo(item.getUri(), item.getLabel(),
|
for (ProxyItemInfo item : items) {
|
||||||
item.getClassLabel(), DEFAULT_IMAGE_URL);
|
wrapped.add(wrapProfileItem(item));
|
||||||
} else {
|
|
||||||
return new ProxyItemInfo(item.getUri(), item.getLabel(),
|
|
||||||
item.getClassLabel(), UrlBuilder.getUrl(item.getImageUrl()));
|
|
||||||
}
|
}
|
||||||
|
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(
|
private Map<String, Integer> buildPageMap(
|
||||||
|
@ -175,4 +197,17 @@ public class ManageProxiesListPage extends AbstractPageHandler {
|
||||||
return map;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue