NIHVIVO-2343 Modify "MyAccount" controller to handle proxy URIs.
This commit is contained in:
parent
9f1b67e3b5
commit
5de648f465
2 changed files with 146 additions and 0 deletions
|
@ -3,6 +3,7 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.controller.accounts;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
|
@ -30,6 +31,7 @@ import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
|
|||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.ParamMap;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyStatementDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyStatementDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.UserAccountsDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
|
@ -57,6 +59,7 @@ public abstract class UserAccountsPage {
|
|||
protected final VClassDao vclassDao;
|
||||
protected final IndividualDao indDao;
|
||||
protected final DataPropertyStatementDao dpsDao;
|
||||
protected final ObjectPropertyStatementDao opsDao;
|
||||
|
||||
protected UserAccountsPage(VitroRequest vreq) {
|
||||
this.vreq = vreq;
|
||||
|
@ -72,6 +75,7 @@ public abstract class UserAccountsPage {
|
|||
vclassDao = wdf.getVClassDao();
|
||||
indDao = wdf.getIndividualDao();
|
||||
dpsDao = wdf.getDataPropertyStatementDao();
|
||||
opsDao = wdf.getObjectPropertyStatementDao();
|
||||
}
|
||||
|
||||
protected boolean isEmailEnabled() {
|
||||
|
@ -83,6 +87,15 @@ public abstract class UserAccountsPage {
|
|||
return (value == null) ? defaultValue : value;
|
||||
}
|
||||
|
||||
protected List<String> getStringParameters(String key) {
|
||||
String[] values = vreq.getParameterValues(key);
|
||||
if (values == null) {
|
||||
return Collections.emptyList();
|
||||
} else {
|
||||
return new ArrayList<String>(Arrays.asList(values));
|
||||
}
|
||||
}
|
||||
|
||||
protected int getIntegerParameter(String key, int defaultValue) {
|
||||
String value = vreq.getParameter(key);
|
||||
if (value == null) {
|
||||
|
|
|
@ -2,18 +2,25 @@
|
|||
|
||||
package edu.cornell.mannlib.vitro.webapp.controller.accounts.user;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
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.vedit.beans.LoginStatusBean;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.SelfEditingConfiguration;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.accounts.UserAccountsPage;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.accounts.admin.UserAccountsEditPage;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.authenticate.Authenticator;
|
||||
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;
|
||||
|
||||
|
@ -28,6 +35,7 @@ public class UserAccountsMyAccountPage extends UserAccountsPage {
|
|||
private static final String PARAMETER_EMAIL_ADDRESS = "emailAddress";
|
||||
private static final String PARAMETER_FIRST_NAME = "firstName";
|
||||
private static final String PARAMETER_LAST_NAME = "lastName";
|
||||
private static final String PARAMETER_PROXY_URI = "proxyUri";
|
||||
|
||||
private static final String ERROR_NO_EMAIL = "errorEmailIsEmpty";
|
||||
private static final String ERROR_EMAIL_IN_USE = "errorEmailInUse";
|
||||
|
@ -46,6 +54,7 @@ public class UserAccountsMyAccountPage extends UserAccountsPage {
|
|||
private String emailAddress = "";
|
||||
private String firstName = "";
|
||||
private String lastName = "";
|
||||
private List<String> proxyUris = new ArrayList<String>();
|
||||
|
||||
/** The result of validating a "submit" request. */
|
||||
private String errorCode = "";
|
||||
|
@ -76,6 +85,7 @@ public class UserAccountsMyAccountPage extends UserAccountsPage {
|
|||
emailAddress = getStringParameter(PARAMETER_EMAIL_ADDRESS, "");
|
||||
firstName = getStringParameter(PARAMETER_FIRST_NAME, "");
|
||||
lastName = getStringParameter(PARAMETER_LAST_NAME, "");
|
||||
proxyUris = getStringParameters(PARAMETER_PROXY_URI);
|
||||
|
||||
strategy.parseAdditionalParameters();
|
||||
}
|
||||
|
@ -127,10 +137,12 @@ public class UserAccountsMyAccountPage extends UserAccountsPage {
|
|||
body.put("emailAddress", emailAddress);
|
||||
body.put("firstName", firstName);
|
||||
body.put("lastName", lastName);
|
||||
body.put("proxies", buildOngoingProxyList());
|
||||
} else {
|
||||
body.put("emailAddress", userAccount.getEmailAddress());
|
||||
body.put("firstName", userAccount.getFirstName());
|
||||
body.put("lastName", userAccount.getLastName());
|
||||
body.put("proxies", buildOriginalProxyList());
|
||||
}
|
||||
body.put("formUrls", buildUrlsMap());
|
||||
|
||||
|
@ -153,6 +165,7 @@ public class UserAccountsMyAccountPage extends UserAccountsPage {
|
|||
userAccount.setEmailAddress(emailAddress);
|
||||
userAccount.setFirstName(firstName);
|
||||
userAccount.setLastName(lastName);
|
||||
userAccount.setProxiedIndividualUris(proxyUris);
|
||||
|
||||
strategy.setAdditionalProperties(userAccount);
|
||||
|
||||
|
@ -165,4 +178,124 @@ public class UserAccountsMyAccountPage extends UserAccountsPage {
|
|||
boolean isExternalAuthOnly() {
|
||||
return (userAccount != null) && userAccount.isExternalAuthOnly();
|
||||
}
|
||||
|
||||
private List<ProxyInfo> buildOngoingProxyList() {
|
||||
List<UserAccount> proxyUsers = new ArrayList<UserAccount>();
|
||||
for (String proxyUri : proxyUris) {
|
||||
UserAccount proxyUser = userAccountsDao
|
||||
.getUserAccountByUri(proxyUri);
|
||||
if (proxyUser == null) {
|
||||
log.warn("No UserAccount found for proxyUri: " + proxyUri);
|
||||
} else {
|
||||
proxyUsers.add(proxyUser);
|
||||
}
|
||||
}
|
||||
|
||||
return buildProxyListFromUserAccounts(proxyUsers);
|
||||
}
|
||||
|
||||
private List<ProxyInfo> buildOriginalProxyList() {
|
||||
Collection<UserAccount> proxyUsers;
|
||||
|
||||
Individual profilePage = getProfilePage(userAccount);
|
||||
if (profilePage == null) {
|
||||
proxyUsers = Collections.emptyList();
|
||||
} else {
|
||||
String uri = profilePage.getURI();
|
||||
proxyUsers = userAccountsDao.getUserAccountsWhoProxyForPage(uri);
|
||||
}
|
||||
|
||||
return buildProxyListFromUserAccounts(proxyUsers);
|
||||
}
|
||||
|
||||
private Individual getProfilePage(UserAccount ua) {
|
||||
SelfEditingConfiguration sec = SelfEditingConfiguration.getBean(vreq);
|
||||
List<Individual> profilePages = sec
|
||||
.getAssociatedIndividuals(indDao, ua);
|
||||
if (profilePages.isEmpty()) {
|
||||
return null;
|
||||
} else {
|
||||
return profilePages.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
private List<ProxyInfo> buildProxyListFromUserAccounts(
|
||||
Collection<UserAccount> proxyUsers) {
|
||||
List<ProxyInfo> proxyInfos = new ArrayList<ProxyInfo>();
|
||||
for (UserAccount proxyUser : proxyUsers) {
|
||||
proxyInfos.add(assembleProxyInfoForUser(proxyUser));
|
||||
}
|
||||
return proxyInfos;
|
||||
}
|
||||
|
||||
private ProxyInfo assembleProxyInfoForUser(UserAccount proxyUser) {
|
||||
String userUri = proxyUser.getUri();
|
||||
String label = assembleUserAccountLabel(proxyUser);
|
||||
String classLabel = "";
|
||||
String imageUrl = "";
|
||||
|
||||
// Does this user have a profile? Can we get better info?
|
||||
Individual proxyProfilePage = getProfilePage(proxyUser);
|
||||
if (proxyProfilePage != null) {
|
||||
String thumbUrl = proxyProfilePage.getThumbUrl();
|
||||
if ((thumbUrl != null) && (!thumbUrl.isEmpty())) {
|
||||
imageUrl = UrlBuilder.getUrl(thumbUrl);
|
||||
}
|
||||
classLabel = getMostSpecificTypeLabel(proxyProfilePage.getURI());
|
||||
}
|
||||
return new ProxyInfo(userUri, label, classLabel, imageUrl);
|
||||
}
|
||||
|
||||
private String assembleUserAccountLabel(UserAccount userAccount) {
|
||||
String last = userAccount.getLastName();
|
||||
String first = userAccount.getFirstName();
|
||||
if (last.isEmpty()) {
|
||||
return first;
|
||||
} else if (first.isEmpty()) {
|
||||
return last;
|
||||
} else {
|
||||
return last + ", " + first;
|
||||
}
|
||||
}
|
||||
|
||||
private String getMostSpecificTypeLabel(String uri) {
|
||||
Map<String, String> types = opsDao
|
||||
.getMostSpecificTypesInClassgroupsForIndividual(uri);
|
||||
if (types.isEmpty()) {
|
||||
return "";
|
||||
} else {
|
||||
return types.values().iterator().next();
|
||||
}
|
||||
}
|
||||
|
||||
public static class ProxyInfo {
|
||||
private final String uri;
|
||||
private final String label;
|
||||
private final String classLabel;
|
||||
private final String imageUrl;
|
||||
|
||||
public ProxyInfo(String uri, String label, String classLabel,
|
||||
String imageUrl) {
|
||||
this.uri = uri;
|
||||
this.label = label;
|
||||
this.classLabel = classLabel;
|
||||
this.imageUrl = imageUrl;
|
||||
}
|
||||
|
||||
public String getUri() {
|
||||
return uri;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public String getClassLabel() {
|
||||
return classLabel;
|
||||
}
|
||||
|
||||
public String getImageUrl() {
|
||||
return imageUrl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue