NIHVIVO-2850 Implement the creation of new profiles when editing or adding a User Account.
This commit is contained in:
parent
a0e962774e
commit
7f4e15256c
3 changed files with 93 additions and 9 deletions
|
@ -6,6 +6,9 @@ import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.SelfEditingConfiguration;
|
import edu.cornell.mannlib.vitro.webapp.beans.SelfEditingConfiguration;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
|
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount.Status;
|
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount.Status;
|
||||||
|
@ -14,13 +17,14 @@ import edu.cornell.mannlib.vitro.webapp.controller.accounts.UserAccountsPage;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.authenticate.Authenticator;
|
import edu.cornell.mannlib.vitro.webapp.controller.authenticate.Authenticator;
|
||||||
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.InsertException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle the "Add new account" form display and submission.
|
* Handle the "Add new account" form display and submission.
|
||||||
*
|
|
||||||
* TODO Associate a profile from this account
|
|
||||||
*/
|
*/
|
||||||
public class UserAccountsAddPage extends UserAccountsPage {
|
public class UserAccountsAddPage extends UserAccountsPage {
|
||||||
|
private static final Log log = LogFactory.getLog(UserAccountsAddPage.class);
|
||||||
|
|
||||||
private static final String PARAMETER_SUBMIT = "submitAdd";
|
private static final String PARAMETER_SUBMIT = "submitAdd";
|
||||||
private static final String PARAMETER_EMAIL_ADDRESS = "emailAddress";
|
private static final String PARAMETER_EMAIL_ADDRESS = "emailAddress";
|
||||||
private static final String PARAMETER_EXTERNAL_AUTH_ID = "externalAuthId";
|
private static final String PARAMETER_EXTERNAL_AUTH_ID = "externalAuthId";
|
||||||
|
@ -28,6 +32,7 @@ public class UserAccountsAddPage extends UserAccountsPage {
|
||||||
private static final String PARAMETER_LAST_NAME = "lastName";
|
private static final String PARAMETER_LAST_NAME = "lastName";
|
||||||
private static final String PARAMETER_ROLE = "role";
|
private static final String PARAMETER_ROLE = "role";
|
||||||
private static final String PARAMETER_ASSOCIATED_PROFILE_URI = "associatedProfileUri";
|
private static final String PARAMETER_ASSOCIATED_PROFILE_URI = "associatedProfileUri";
|
||||||
|
private static final String PARAMETER_NEW_PROFILE_CLASS_URI = "degreeUri";
|
||||||
|
|
||||||
private static final String ERROR_NO_EMAIL = "errorEmailIsEmpty";
|
private static final String ERROR_NO_EMAIL = "errorEmailIsEmpty";
|
||||||
private static final String ERROR_EMAIL_IN_USE = "errorEmailInUse";
|
private static final String ERROR_EMAIL_IN_USE = "errorEmailInUse";
|
||||||
|
@ -50,6 +55,7 @@ public class UserAccountsAddPage extends UserAccountsPage {
|
||||||
private String lastName = "";
|
private String lastName = "";
|
||||||
private String selectedRoleUri = "";
|
private String selectedRoleUri = "";
|
||||||
private String associatedProfileUri = "";
|
private String associatedProfileUri = "";
|
||||||
|
private String newProfileClassUri = "";
|
||||||
|
|
||||||
/** The result of validating a "submit" request. */
|
/** The result of validating a "submit" request. */
|
||||||
private String errorCode = "";
|
private String errorCode = "";
|
||||||
|
@ -82,6 +88,8 @@ public class UserAccountsAddPage extends UserAccountsPage {
|
||||||
selectedRoleUri = getStringParameter(PARAMETER_ROLE, "");
|
selectedRoleUri = getStringParameter(PARAMETER_ROLE, "");
|
||||||
associatedProfileUri = getStringParameter(
|
associatedProfileUri = getStringParameter(
|
||||||
PARAMETER_ASSOCIATED_PROFILE_URI, "");
|
PARAMETER_ASSOCIATED_PROFILE_URI, "");
|
||||||
|
newProfileClassUri = getStringParameter(
|
||||||
|
PARAMETER_NEW_PROFILE_CLASS_URI, "");
|
||||||
|
|
||||||
strategy.parseAdditionalParameters();
|
strategy.parseAdditionalParameters();
|
||||||
}
|
}
|
||||||
|
@ -153,6 +161,19 @@ public class UserAccountsAddPage extends UserAccountsPage {
|
||||||
|
|
||||||
// Associate the profile, as appropriate.
|
// Associate the profile, as appropriate.
|
||||||
if (matchingIsEnabled) {
|
if (matchingIsEnabled) {
|
||||||
|
if (!newProfileClassUri.isEmpty()) {
|
||||||
|
try {
|
||||||
|
String newProfileUri = UserAccountsProfileCreator
|
||||||
|
.createProfile(indDao, dpsDao, newProfileClassUri,
|
||||||
|
this.addedAccount);
|
||||||
|
associatedProfileUri = newProfileUri;
|
||||||
|
} catch (InsertException e) {
|
||||||
|
log.error("Failed to create new profile of class '"
|
||||||
|
+ newProfileClassUri + "' for user '"
|
||||||
|
+ this.addedAccount.getEmailAddress() + "'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SelfEditingConfiguration.getBean(vreq)
|
SelfEditingConfiguration.getBean(vreq)
|
||||||
.associateIndividualWithUserAccount(indDao, dpsDao,
|
.associateIndividualWithUserAccount(indDao, dpsDao,
|
||||||
this.addedAccount, associatedProfileUri);
|
this.addedAccount, associatedProfileUri);
|
||||||
|
@ -164,19 +185,20 @@ public class UserAccountsAddPage extends UserAccountsPage {
|
||||||
public final ResponseValues showPage() {
|
public final ResponseValues showPage() {
|
||||||
Map<String, Object> body = new HashMap<String, Object>();
|
Map<String, Object> body = new HashMap<String, Object>();
|
||||||
|
|
||||||
body.put("emailAddress", emailAddress);
|
body.put(PARAMETER_EMAIL_ADDRESS, emailAddress);
|
||||||
body.put("externalAuthId", externalAuthId);
|
body.put(PARAMETER_EXTERNAL_AUTH_ID, externalAuthId);
|
||||||
body.put("firstName", firstName);
|
body.put(PARAMETER_FIRST_NAME, firstName);
|
||||||
body.put("lastName", lastName);
|
body.put(PARAMETER_LAST_NAME, lastName);
|
||||||
body.put("selectedRole", selectedRoleUri);
|
body.put("selectedRole", selectedRoleUri);
|
||||||
body.put("roles", buildRolesList());
|
body.put("roles", buildRolesList());
|
||||||
body.put("profileTypes", buildProfileTypesList());
|
body.put("profileTypes", buildProfileTypesList());
|
||||||
|
body.put(PARAMETER_NEW_PROFILE_CLASS_URI, newProfileClassUri);
|
||||||
body.put("formUrls", buildUrlsMap());
|
body.put("formUrls", buildUrlsMap());
|
||||||
|
|
||||||
if (!errorCode.isEmpty()) {
|
if (!errorCode.isEmpty()) {
|
||||||
body.put(errorCode, Boolean.TRUE);
|
body.put(errorCode, Boolean.TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (matchingIsEnabled) {
|
if (matchingIsEnabled) {
|
||||||
body.put("showAssociation", Boolean.TRUE);
|
body.put("showAssociation", Boolean.TRUE);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ import edu.cornell.mannlib.vitro.webapp.controller.accounts.user.UserAccountsUse
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.authenticate.Authenticator;
|
import edu.cornell.mannlib.vitro.webapp.controller.authenticate.Authenticator;
|
||||||
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.InsertException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle the "Edit Account" form display and submission.
|
* Handle the "Edit Account" form display and submission.
|
||||||
|
@ -34,6 +35,7 @@ public class UserAccountsEditPage extends UserAccountsPage {
|
||||||
private static final String PARAMETER_LAST_NAME = "lastName";
|
private static final String PARAMETER_LAST_NAME = "lastName";
|
||||||
private static final String PARAMETER_ROLE = "role";
|
private static final String PARAMETER_ROLE = "role";
|
||||||
private static final String PARAMETER_ASSOCIATED_PROFILE_URI = "associatedProfileUri";
|
private static final String PARAMETER_ASSOCIATED_PROFILE_URI = "associatedProfileUri";
|
||||||
|
private static final String PARAMETER_NEW_PROFILE_CLASS_URI = "degreeUri";
|
||||||
|
|
||||||
private static final String ERROR_NO_EMAIL = "errorEmailIsEmpty";
|
private static final String ERROR_NO_EMAIL = "errorEmailIsEmpty";
|
||||||
private static final String ERROR_EMAIL_IN_USE = "errorEmailInUse";
|
private static final String ERROR_EMAIL_IN_USE = "errorEmailInUse";
|
||||||
|
@ -57,6 +59,7 @@ public class UserAccountsEditPage extends UserAccountsPage {
|
||||||
private String lastName = "";
|
private String lastName = "";
|
||||||
private String selectedRoleUri = "";
|
private String selectedRoleUri = "";
|
||||||
private String associatedProfileUri = "";
|
private String associatedProfileUri = "";
|
||||||
|
private String newProfileClassUri = "";
|
||||||
|
|
||||||
private UserAccount userAccount;
|
private UserAccount userAccount;
|
||||||
|
|
||||||
|
@ -93,6 +96,8 @@ public class UserAccountsEditPage extends UserAccountsPage {
|
||||||
selectedRoleUri = getStringParameter(PARAMETER_ROLE, "");
|
selectedRoleUri = getStringParameter(PARAMETER_ROLE, "");
|
||||||
associatedProfileUri = getStringParameter(
|
associatedProfileUri = getStringParameter(
|
||||||
PARAMETER_ASSOCIATED_PROFILE_URI, "");
|
PARAMETER_ASSOCIATED_PROFILE_URI, "");
|
||||||
|
newProfileClassUri = getStringParameter(
|
||||||
|
PARAMETER_NEW_PROFILE_CLASS_URI, "");
|
||||||
|
|
||||||
strategy.parseAdditionalParameters();
|
strategy.parseAdditionalParameters();
|
||||||
}
|
}
|
||||||
|
@ -174,25 +179,27 @@ public class UserAccountsEditPage extends UserAccountsPage {
|
||||||
Map<String, Object> body = new HashMap<String, Object>();
|
Map<String, Object> body = new HashMap<String, Object>();
|
||||||
|
|
||||||
body.put("userUri", userUri);
|
body.put("userUri", userUri);
|
||||||
|
|
||||||
if (isSubmit()) {
|
if (isSubmit()) {
|
||||||
body.put("emailAddress", emailAddress);
|
body.put("emailAddress", emailAddress);
|
||||||
body.put("externalAuthId", externalAuthId);
|
body.put("externalAuthId", externalAuthId);
|
||||||
body.put("firstName", firstName);
|
body.put("firstName", firstName);
|
||||||
body.put("lastName", lastName);
|
body.put("lastName", lastName);
|
||||||
body.put("selectedRole", selectedRoleUri);
|
body.put("selectedRole", selectedRoleUri);
|
||||||
|
body.put(PARAMETER_NEW_PROFILE_CLASS_URI, newProfileClassUri);
|
||||||
} else {
|
} else {
|
||||||
body.put("emailAddress", userAccount.getEmailAddress());
|
body.put("emailAddress", userAccount.getEmailAddress());
|
||||||
body.put("externalAuthId", userAccount.getExternalAuthId());
|
body.put("externalAuthId", userAccount.getExternalAuthId());
|
||||||
body.put("firstName", userAccount.getFirstName());
|
body.put("firstName", userAccount.getFirstName());
|
||||||
body.put("lastName", userAccount.getLastName());
|
body.put("lastName", userAccount.getLastName());
|
||||||
body.put("selectedRole", getExistingRoleUri());
|
body.put("selectedRole", getExistingRoleUri());
|
||||||
|
body.put(PARAMETER_NEW_PROFILE_CLASS_URI, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isRootUser()) {
|
if (!isRootUser()) {
|
||||||
body.put("roles", buildRolesList());
|
body.put("roles", buildRolesList());
|
||||||
}
|
}
|
||||||
|
|
||||||
body.put("profileTypes", buildProfileTypesList());
|
body.put("profileTypes", buildProfileTypesList());
|
||||||
body.put("formUrls", buildUrlsMapWithEditUrl());
|
body.put("formUrls", buildUrlsMapWithEditUrl());
|
||||||
|
|
||||||
|
@ -244,6 +251,19 @@ public class UserAccountsEditPage extends UserAccountsPage {
|
||||||
|
|
||||||
// Associate the profile, as appropriate.
|
// Associate the profile, as appropriate.
|
||||||
if (matchingIsEnabled) {
|
if (matchingIsEnabled) {
|
||||||
|
if (!newProfileClassUri.isEmpty()) {
|
||||||
|
try {
|
||||||
|
String newProfileUri = UserAccountsProfileCreator
|
||||||
|
.createProfile(indDao, dpsDao, newProfileClassUri,
|
||||||
|
userAccount);
|
||||||
|
associatedProfileUri = newProfileUri;
|
||||||
|
} catch (InsertException e) {
|
||||||
|
log.error("Failed to create new profile of class '"
|
||||||
|
+ newProfileClassUri + "' for user '"
|
||||||
|
+ userAccount.getEmailAddress() + "'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SelfEditingConfiguration.getBean(vreq)
|
SelfEditingConfiguration.getBean(vreq)
|
||||||
.associateIndividualWithUserAccount(indDao, dpsDao,
|
.associateIndividualWithUserAccount(indDao, dpsDao,
|
||||||
userAccount, associatedProfileUri);
|
userAccount, associatedProfileUri);
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.controller.accounts.admin;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatementImpl;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyStatementDao;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.InsertException;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new profile with the given VClass URI, and info from the user account.
|
||||||
|
*/
|
||||||
|
public class UserAccountsProfileCreator {
|
||||||
|
private static final String URI_FOAF_FIRST_NAME = "http://xmlns.com/foaf/0.1/firstName";
|
||||||
|
private static final String URI_FOAF_LAST_NAME = "http://xmlns.com/foaf/0.1/lastName";
|
||||||
|
|
||||||
|
public static String createProfile(IndividualDao indDao,
|
||||||
|
DataPropertyStatementDao dpsDao, String profileClassUri,
|
||||||
|
UserAccount account) throws InsertException {
|
||||||
|
IndividualImpl i = new IndividualImpl();
|
||||||
|
i.setVClassURI(profileClassUri);
|
||||||
|
String indUri = indDao.insertNewIndividual(i);
|
||||||
|
|
||||||
|
addProp(dpsDao, indUri, URI_FOAF_FIRST_NAME, account.getFirstName());
|
||||||
|
addProp(dpsDao, indUri, URI_FOAF_LAST_NAME, account.getLastName());
|
||||||
|
|
||||||
|
String label = account.getLastName() + ", " + account.getFirstName();
|
||||||
|
addProp(dpsDao, indUri, VitroVocabulary.LABEL, label);
|
||||||
|
|
||||||
|
return indUri;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void addProp(DataPropertyStatementDao dpsDao, String indUri,
|
||||||
|
String propertyUri, String value) {
|
||||||
|
DataPropertyStatementImpl dps = new DataPropertyStatementImpl(indUri,
|
||||||
|
propertyUri, value);
|
||||||
|
dpsDao.insertNewDataPropertyStatement(dps);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue