NIHVIVO-2343 First shot at the Manage Proxies page.
This commit is contained in:
parent
23329bd5fc
commit
d1ecaccc5b
12 changed files with 604 additions and 5 deletions
|
@ -38,6 +38,7 @@ public abstract class AbstractPageHandler {
|
|||
protected final VitroRequest vreq;
|
||||
protected final ServletContext ctx;
|
||||
protected final OntModel userAccountsModel;
|
||||
protected final OntModel unionModel;
|
||||
protected final UserAccountsDao userAccountsDao;
|
||||
protected final VClassDao vclassDao;
|
||||
protected final IndividualDao indDao;
|
||||
|
@ -48,8 +49,9 @@ public abstract class AbstractPageHandler {
|
|||
this.vreq = vreq;
|
||||
this.ctx = vreq.getSession().getServletContext();
|
||||
|
||||
OntModelSelector oms = ModelContext.getBaseOntModelSelector(ctx);
|
||||
OntModelSelector oms = ModelContext.getUnionOntModelSelector(ctx);
|
||||
userAccountsModel = oms.getUserAccountsModel();
|
||||
unionModel = oms.getFullModel();
|
||||
|
||||
WebappDaoFactory wdf = (WebappDaoFactory) this.ctx
|
||||
.getAttribute("webappDaoFactory");
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.controller.accounts.manageproxies;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.Actions;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.usepages.ManageProxies;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
|
||||
|
||||
/**
|
||||
* Parcel out the different actions required of the ManageProxies GUI.
|
||||
*/
|
||||
public class ManageProxiesController extends FreemarkerHttpServlet {
|
||||
private static final Log log = LogFactory
|
||||
.getLog(ManageProxiesController.class);
|
||||
|
||||
@Override
|
||||
protected Actions requiredActions(VitroRequest vreq) {
|
||||
return new Actions(new ManageProxies());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResponseValues processRequest(VitroRequest vreq) {
|
||||
if (log.isDebugEnabled()) {
|
||||
dumpRequestParameters(vreq);
|
||||
}
|
||||
|
||||
String action = vreq.getPathInfo();
|
||||
log.debug("action = '" + action + "'");
|
||||
|
||||
return handleListRequest(vreq);
|
||||
}
|
||||
|
||||
private ResponseValues handleListRequest(VitroRequest vreq) {
|
||||
ManageProxiesListPage page = new ManageProxiesListPage(vreq);
|
||||
return page.showPage();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,166 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.controller.accounts.manageproxies;
|
||||
|
||||
import static edu.cornell.mannlib.vitro.webapp.controller.accounts.manageproxies.ProxyRelationshipSelectionCriteria.DEFAULT_RELATIONSHIPS_PER_PAGE;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.AbstractPageHandler;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.accounts.manageproxies.ProxyRelationshipSelectionCriteria.ProxyRelationshipView;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.accounts.manageproxies.ProxyRelationshipSelector.Context;
|
||||
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;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*/
|
||||
public class ManageProxiesListPage extends AbstractPageHandler {
|
||||
private static final Log log = LogFactory
|
||||
.getLog(ManageProxiesListPage.class);
|
||||
|
||||
public static final String PARAMETER_RELATIONSHIPS_PER_PAGE = "relationshipsPerPage";
|
||||
public static final String PARAMETER_PAGE_INDEX = "pageIndex";
|
||||
public static final String PARAMETER_VIEW_TYPE = "viewType";
|
||||
public static final String PARAMETER_SEARCH_TERM = "searchTerm";
|
||||
|
||||
private static final String TEMPLATE_NAME = "manageProxies-list.ftl";
|
||||
|
||||
private static final String DEFAULT_IMAGE_URL = UrlBuilder
|
||||
.getUrl("/images/placeholders/person.thumbnail.jpg");
|
||||
|
||||
private final Context selectorContext;
|
||||
|
||||
private ProxyRelationshipSelectionCriteria criteria = ProxyRelationshipSelectionCriteria.DEFAULT_CRITERIA;
|
||||
|
||||
public ManageProxiesListPage(VitroRequest vreq) {
|
||||
super(vreq);
|
||||
|
||||
selectorContext = new Context(userAccountsModel, unionModel,
|
||||
getMatchingProperty());
|
||||
parseParameters();
|
||||
}
|
||||
|
||||
private String getMatchingProperty() {
|
||||
return ConfigurationProperties.getBean(vreq).getProperty(
|
||||
"selfEditing.idMatchingProperty", "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the criteria from the request parameters.
|
||||
*/
|
||||
private void parseParameters() {
|
||||
int relationshipsPerPage = getIntegerParameter(
|
||||
PARAMETER_RELATIONSHIPS_PER_PAGE,
|
||||
DEFAULT_RELATIONSHIPS_PER_PAGE);
|
||||
int pageIndex = getIntegerParameter(PARAMETER_PAGE_INDEX, 1);
|
||||
ProxyRelationshipView viewType = ProxyRelationshipView.fromKeyword(vreq
|
||||
.getParameter(PARAMETER_VIEW_TYPE));
|
||||
String searchTerm = getStringParameter(PARAMETER_SEARCH_TERM, "");
|
||||
|
||||
criteria = new ProxyRelationshipSelectionCriteria(relationshipsPerPage,
|
||||
pageIndex, viewType, searchTerm);
|
||||
|
||||
log.debug("selection criteria is: " + criteria);
|
||||
}
|
||||
|
||||
public ResponseValues showPage() {
|
||||
ProxyRelationshipSelection selection = ProxyRelationshipSelector
|
||||
.select(selectorContext, criteria);
|
||||
Map<String, Object> body = buildTemplateBodyMap(selection);
|
||||
return new TemplateResponseValues(TEMPLATE_NAME, body);
|
||||
}
|
||||
|
||||
private Map<String, Object> buildTemplateBodyMap(
|
||||
ProxyRelationshipSelection selection) {
|
||||
Map<String, Object> body = new HashMap<String, Object>();
|
||||
|
||||
body.put("relationshipsPerPage", criteria.getRelationshipsPerPage());
|
||||
body.put("pageIndex", criteria.getPageIndex());
|
||||
body.put("viewType", criteria.getViewBy());
|
||||
body.put("searchTerm", criteria.getSearchTerm());
|
||||
|
||||
body.put("relationships", wrapProxyRelationships(selection));
|
||||
body.put("total", selection.getTotalResultCount());
|
||||
body.put("page", buildPageMap(selection));
|
||||
|
||||
body.put("matchingProperty", getMatchingProperty());
|
||||
|
||||
body.put("formUrls", buildUrlsMap());
|
||||
|
||||
return body;
|
||||
}
|
||||
|
||||
private List<ProxyRelationship> wrapProxyRelationships(
|
||||
ProxyRelationshipSelection selection) {
|
||||
List<ProxyRelationship> wrapped = new ArrayList<ProxyRelationship>();
|
||||
for (ProxyRelationship r : selection.getProxyRelationships()) {
|
||||
wrapped.add(new ProxyRelationship(wrapItemList(r.getProxyInfos()),
|
||||
wrapItemList(r.getProfileInfos())));
|
||||
}
|
||||
return wrapped;
|
||||
}
|
||||
|
||||
private List<ProxyItemInfo> wrapItemList(List<ProxyItemInfo> items) {
|
||||
List<ProxyItemInfo> wrapped = new ArrayList<ProxyItemInfo>();
|
||||
for (ProxyItemInfo item : items) {
|
||||
wrapped.add(wrapItem(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 Map<String, Integer> buildPageMap(
|
||||
ProxyRelationshipSelection selection) {
|
||||
int currentPage = selection.getCriteria().getPageIndex();
|
||||
|
||||
float pageCount = ((float) selection.getTotalResultCount())
|
||||
/ selection.getCriteria().getRelationshipsPerPage();
|
||||
int lastPage = (int) Math.ceil(pageCount);
|
||||
|
||||
Map<String, Integer> map = new HashMap<String, Integer>();
|
||||
|
||||
map.put("current", currentPage);
|
||||
map.put("first", 1);
|
||||
map.put("last", lastPage);
|
||||
|
||||
if (currentPage < lastPage) {
|
||||
map.put("next", currentPage + 1);
|
||||
}
|
||||
if (currentPage > 1) {
|
||||
map.put("previous", currentPage - 1);
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
protected Map<String, String> buildUrlsMap() {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
|
||||
map.put("list", UrlBuilder.getUrl("/manageProxies/list"));
|
||||
map.put("edit", UrlBuilder.getUrl("/manageProxies/edit"));
|
||||
map.put("sparqlQueryAjax", UrlBuilder.getUrl("/ajax/sparqlQuery"));
|
||||
map.put("defaultImageUrl", DEFAULT_IMAGE_URL);
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
package edu.cornell.mannlib.vitro.webapp.controller.accounts.manageproxies;
|
||||
|
||||
|
||||
/**
|
||||
* On what basis are we selecting proxy relationships?
|
||||
*
|
||||
|
@ -23,6 +24,21 @@ public class ProxyRelationshipSelectionCriteria {
|
|||
BY_PROXY, BY_PROFILE;
|
||||
|
||||
public static ProxyRelationshipView DEFAULT_VIEW = BY_PROXY;
|
||||
|
||||
public static ProxyRelationshipView fromKeyword(String keyword) {
|
||||
if (keyword == null) {
|
||||
return DEFAULT_VIEW;
|
||||
}
|
||||
|
||||
for (ProxyRelationshipView v : ProxyRelationshipView.values()) {
|
||||
if (v.toString().equals(keyword)) {
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
return DEFAULT_VIEW;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** How many relationships should we bring back, at most? */
|
||||
|
|
|
@ -21,6 +21,7 @@ import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.usepages.EditIndivi
|
|||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.usepages.EditOntology;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.usepages.EditSiteInformation;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.usepages.ManageMenus;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.usepages.ManageOwnProxies;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.usepages.ManageUserAccounts;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.usepages.SeeSiteAdminPage;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.usepages.SeeStartupStatus;
|
||||
|
@ -131,6 +132,10 @@ public class BaseSiteAdminController extends FreemarkerHttpServlet {
|
|||
data.put("userAccounts", UrlBuilder.getUrl("/accountsAdmin"));
|
||||
}
|
||||
|
||||
if (PolicyHelper.isAuthorizedForActions(vreq, new ManageOwnProxies())) {
|
||||
data.put("manageProxies", UrlBuilder.getUrl("/manageProxies"));
|
||||
}
|
||||
|
||||
if (PolicyHelper.isAuthorizedForActions(vreq, new EditSiteInformation())) {
|
||||
data.put("siteInfo", UrlBuilder.getUrl("/editForm", "controller", "ApplicationBean"));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue