NIHVIVO-2343 Create method: UserAccountsDao.setProxyAccountsOnProfile() and use it.
This commit is contained in:
parent
7b581308af
commit
6f651fcf4f
6 changed files with 129 additions and 2 deletions
|
@ -165,7 +165,12 @@ public class UserAccountsMyAccountPage extends UserAccountsPage {
|
|||
userAccount.setEmailAddress(emailAddress);
|
||||
userAccount.setFirstName(firstName);
|
||||
userAccount.setLastName(lastName);
|
||||
userAccount.setProxiedIndividualUris(proxyUris);
|
||||
|
||||
Individual profilePage = getProfilePage(userAccount);
|
||||
if (profilePage != null) {
|
||||
userAccountsDao.setProxyAccountsOnProfile(profilePage.getURI(),
|
||||
proxyUris);
|
||||
}
|
||||
|
||||
strategy.setAdditionalProperties(userAccount);
|
||||
|
||||
|
@ -199,10 +204,15 @@ public class UserAccountsMyAccountPage extends UserAccountsPage {
|
|||
|
||||
Individual profilePage = getProfilePage(userAccount);
|
||||
if (profilePage == null) {
|
||||
log.debug("no profile page");
|
||||
proxyUsers = Collections.emptyList();
|
||||
} else {
|
||||
String uri = profilePage.getURI();
|
||||
log.debug("profile page at " + uri);
|
||||
proxyUsers = userAccountsDao.getUserAccountsWhoProxyForPage(uri);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug(getUrisFromUserAccounts(proxyUsers));
|
||||
}
|
||||
}
|
||||
|
||||
return buildProxyListFromUserAccounts(proxyUsers);
|
||||
|
@ -268,6 +278,15 @@ public class UserAccountsMyAccountPage extends UserAccountsPage {
|
|||
}
|
||||
}
|
||||
|
||||
private List<String> getUrisFromUserAccounts(
|
||||
Collection<UserAccount> proxyUsers) {
|
||||
List<String> list = new ArrayList<String>();
|
||||
for (UserAccount u : proxyUsers) {
|
||||
list.add(u.getUri());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static class ProxyInfo {
|
||||
private final String uri;
|
||||
private final String label;
|
||||
|
|
|
@ -84,6 +84,12 @@ public interface UserAccountsDao {
|
|||
*/
|
||||
void deleteUserAccount(String userAccountUri);
|
||||
|
||||
/**
|
||||
* Set so that these UserAccounts, and only these, are authorized as proxies on this
|
||||
* profile page.
|
||||
*/
|
||||
void setProxyAccountsOnProfile(String profilePageUri, Collection<String> userAccountUris);
|
||||
|
||||
/**
|
||||
* Get the PermissionSet for this URI.
|
||||
*
|
||||
|
|
|
@ -46,7 +46,7 @@ public class UserAccountsDaoFiltering extends BaseFiltering implements
|
|||
public UserAccount getUserAccountByExternalAuthId(String externalAuthId) {
|
||||
return innerDao.getUserAccountByExternalAuthId(externalAuthId);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Collection<UserAccount> getUserAccountsWhoProxyForPage(
|
||||
String profilePageUri) {
|
||||
|
@ -68,6 +68,12 @@ public class UserAccountsDaoFiltering extends BaseFiltering implements
|
|||
innerDao.deleteUserAccount(userAccountUri);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProxyAccountsOnProfile(String profilePageUri,
|
||||
Collection<String> userAccountUris) {
|
||||
innerDao.setProxyAccountsOnProfile(profilePageUri, userAccountUris);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionSet getPermissionSetByUri(String uri) {
|
||||
return innerDao.getPermissionSetByUri(uri);
|
||||
|
|
|
@ -345,6 +345,52 @@ public class UserAccountsDaoJena extends JenaBaseDao implements UserAccountsDao
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProxyAccountsOnProfile(String profilePageUri,
|
||||
Collection<String> userAccountUris) {
|
||||
Property p = getOntModel().getProperty(
|
||||
VitroVocabulary.USERACCOUNT_PROXY_EDITOR_FOR);
|
||||
Resource o = getOntModel().createResource(profilePageUri);
|
||||
|
||||
// figure out what needs to be added and what needs to be removed.
|
||||
List<String> removeThese = new ArrayList<String>();
|
||||
List<String> addThese = new ArrayList<String>(userAccountUris);
|
||||
getOntModel().enterCriticalSection(Lock.READ);
|
||||
try {
|
||||
Resource s = null;
|
||||
StmtIterator stmts = getOntModel().listStatements(s, p, o);
|
||||
while (stmts.hasNext()) {
|
||||
Resource subject = stmts.next().getSubject();
|
||||
if (subject != null) {
|
||||
String uri = subject.getURI();
|
||||
if (addThese.contains(uri)) {
|
||||
addThese.remove(uri);
|
||||
} else {
|
||||
removeThese.add(uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
stmts.close();
|
||||
} finally {
|
||||
getOntModel().leaveCriticalSection();
|
||||
}
|
||||
|
||||
// now do it.
|
||||
getOntModel().enterCriticalSection(Lock.WRITE);
|
||||
try {
|
||||
for (String uri : removeThese) {
|
||||
Resource s = getOntModel().createResource(uri);
|
||||
getOntModel().remove(s, p, o);
|
||||
}
|
||||
for (String uri: addThese) {
|
||||
Resource s = getOntModel().createResource(uri);
|
||||
getOntModel().add(s, p, o);
|
||||
}
|
||||
} finally {
|
||||
getOntModel().leaveCriticalSection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionSet getPermissionSetByUri(String uri) {
|
||||
if (uri == null) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue