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.setEmailAddress(emailAddress);
|
||||||
userAccount.setFirstName(firstName);
|
userAccount.setFirstName(firstName);
|
||||||
userAccount.setLastName(lastName);
|
userAccount.setLastName(lastName);
|
||||||
userAccount.setProxiedIndividualUris(proxyUris);
|
|
||||||
|
Individual profilePage = getProfilePage(userAccount);
|
||||||
|
if (profilePage != null) {
|
||||||
|
userAccountsDao.setProxyAccountsOnProfile(profilePage.getURI(),
|
||||||
|
proxyUris);
|
||||||
|
}
|
||||||
|
|
||||||
strategy.setAdditionalProperties(userAccount);
|
strategy.setAdditionalProperties(userAccount);
|
||||||
|
|
||||||
|
@ -199,10 +204,15 @@ public class UserAccountsMyAccountPage extends UserAccountsPage {
|
||||||
|
|
||||||
Individual profilePage = getProfilePage(userAccount);
|
Individual profilePage = getProfilePage(userAccount);
|
||||||
if (profilePage == null) {
|
if (profilePage == null) {
|
||||||
|
log.debug("no profile page");
|
||||||
proxyUsers = Collections.emptyList();
|
proxyUsers = Collections.emptyList();
|
||||||
} else {
|
} else {
|
||||||
String uri = profilePage.getURI();
|
String uri = profilePage.getURI();
|
||||||
|
log.debug("profile page at " + uri);
|
||||||
proxyUsers = userAccountsDao.getUserAccountsWhoProxyForPage(uri);
|
proxyUsers = userAccountsDao.getUserAccountsWhoProxyForPage(uri);
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug(getUrisFromUserAccounts(proxyUsers));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return buildProxyListFromUserAccounts(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 {
|
public static class ProxyInfo {
|
||||||
private final String uri;
|
private final String uri;
|
||||||
private final String label;
|
private final String label;
|
||||||
|
|
|
@ -84,6 +84,12 @@ public interface UserAccountsDao {
|
||||||
*/
|
*/
|
||||||
void deleteUserAccount(String userAccountUri);
|
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.
|
* Get the PermissionSet for this URI.
|
||||||
*
|
*
|
||||||
|
|
|
@ -68,6 +68,12 @@ public class UserAccountsDaoFiltering extends BaseFiltering implements
|
||||||
innerDao.deleteUserAccount(userAccountUri);
|
innerDao.deleteUserAccount(userAccountUri);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setProxyAccountsOnProfile(String profilePageUri,
|
||||||
|
Collection<String> userAccountUris) {
|
||||||
|
innerDao.setProxyAccountsOnProfile(profilePageUri, userAccountUris);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PermissionSet getPermissionSetByUri(String uri) {
|
public PermissionSet getPermissionSetByUri(String uri) {
|
||||||
return innerDao.getPermissionSetByUri(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
|
@Override
|
||||||
public PermissionSet getPermissionSetByUri(String uri) {
|
public PermissionSet getPermissionSetByUri(String uri) {
|
||||||
if (uri == null) {
|
if (uri == null) {
|
||||||
|
|
|
@ -58,6 +58,9 @@ public class UserAccountsDaoJenaTest extends AbstractTestClass {
|
||||||
private static final String URI_ROLE2 = NS_MINE + "role2";
|
private static final String URI_ROLE2 = NS_MINE + "role2";
|
||||||
private static final String URI_ROLE3 = NS_MINE + "role3";
|
private static final String URI_ROLE3 = NS_MINE + "role3";
|
||||||
|
|
||||||
|
private static final String URI_PROFILE1 = NS_MINE + "profile1";
|
||||||
|
private static final String URI_PROFILE2 = NS_MINE + "profile2";
|
||||||
|
|
||||||
private OntModel ontModel;
|
private OntModel ontModel;
|
||||||
private WebappDaoFactoryJena wadf;
|
private WebappDaoFactoryJena wadf;
|
||||||
private UserAccountsDaoJena dao;
|
private UserAccountsDaoJena dao;
|
||||||
|
@ -65,6 +68,10 @@ public class UserAccountsDaoJenaTest extends AbstractTestClass {
|
||||||
private UserAccount user1;
|
private UserAccount user1;
|
||||||
private UserAccount userNew;
|
private UserAccount userNew;
|
||||||
|
|
||||||
|
private UserAccount userA;
|
||||||
|
private UserAccount userB;
|
||||||
|
private UserAccount userC;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() throws IOException {
|
public void setup() throws IOException {
|
||||||
InputStream stream = UserAccountsDaoJenaTest.class
|
InputStream stream = UserAccountsDaoJenaTest.class
|
||||||
|
@ -89,6 +96,16 @@ public class UserAccountsDaoJenaTest extends AbstractTestClass {
|
||||||
userNew = userAccount("", "email@here", "Joe", "Blow", "XXXX", "YYYY",
|
userNew = userAccount("", "email@here", "Joe", "Blow", "XXXX", "YYYY",
|
||||||
0L, false, 1, 0L, Status.ACTIVE, "jblow", false, EMPTY, false,
|
0L, false, 1, 0L, Status.ACTIVE, "jblow", false, EMPTY, false,
|
||||||
EMPTY);
|
EMPTY);
|
||||||
|
|
||||||
|
userA = userAccount("", "aahern@here", "Alf", "Ahern", "XXXX", "YYYY",
|
||||||
|
0L, false, 1, 0L, Status.ACTIVE, "aahern", false, EMPTY, false,
|
||||||
|
collection(URI_PROFILE1));
|
||||||
|
userB = userAccount("", "email@here", "Betty", "Boop", "XXXX", "YYYY",
|
||||||
|
0L, false, 1, 0L, Status.ACTIVE, "bboop", false, EMPTY, false,
|
||||||
|
collection(URI_PROFILE1, URI_PROFILE2));
|
||||||
|
userC = userAccount("", "ccallas@here", "Charlie", "Callas", "XXXX",
|
||||||
|
"YYYY", 0L, false, 1, 0L, Status.ACTIVE, "ccallas", false,
|
||||||
|
EMPTY, false, collection(URI_PROFILE2));
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
@ -232,6 +249,10 @@ public class UserAccountsDaoJenaTest extends AbstractTestClass {
|
||||||
assertEqualAccounts(user1, updated);
|
assertEqualAccounts(user1, updated);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
// Tests for proxy-related methods
|
||||||
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getProxyEditorsFirst() {
|
public void getProxyEditorsFirst() {
|
||||||
String profileOne = NS_MINE + "userNewProxyOne";
|
String profileOne = NS_MINE + "userNewProxyOne";
|
||||||
|
@ -274,6 +295,22 @@ public class UserAccountsDaoJenaTest extends AbstractTestClass {
|
||||||
dao.getUserAccountsWhoProxyForPage(bogusProfile));
|
dao.getUserAccountsWhoProxyForPage(bogusProfile));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setProxyEditorsOnProfile() {
|
||||||
|
String uriA = dao.insertUserAccount(userA);
|
||||||
|
String uriB = dao.insertUserAccount(userB);
|
||||||
|
String uriC = dao.insertUserAccount(userC);
|
||||||
|
|
||||||
|
dao.setProxyAccountsOnProfile(URI_PROFILE1, collection(uriB, uriC));
|
||||||
|
|
||||||
|
assertExpectedProxies("userA", collection(),
|
||||||
|
dao.getUserAccountByUri(uriA).getProxiedIndividualUris());
|
||||||
|
assertExpectedProxies("userB", collection(URI_PROFILE1, URI_PROFILE2),
|
||||||
|
dao.getUserAccountByUri(uriB).getProxiedIndividualUris());
|
||||||
|
assertExpectedProxies("userC", collection(URI_PROFILE1, URI_PROFILE2),
|
||||||
|
dao.getUserAccountByUri(uriC).getProxiedIndividualUris());
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
// Tests for PermissionSet methods
|
// Tests for PermissionSet methods
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
@ -448,6 +485,12 @@ public class UserAccountsDaoJenaTest extends AbstractTestClass {
|
||||||
assertEqualSets(label, expectedUris, actualUris);
|
assertEqualSets(label, expectedUris, actualUris);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void assertExpectedProxies(String label,
|
||||||
|
Collection<String> expected, Set<String> actual) {
|
||||||
|
Set<String> expectedSet = new HashSet<String>(expected);
|
||||||
|
assertEqualSets(label, expectedSet, actual);
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private void dumpModelStatements() {
|
private void dumpModelStatements() {
|
||||||
StmtIterator stmts = ontModel.listStatements();
|
StmtIterator stmts = ontModel.listStatements();
|
||||||
|
|
|
@ -97,4 +97,11 @@ public class UserAccountsDaoStub implements UserAccountsDao {
|
||||||
"UserAccountsDaoStub.getUserAccountsWhoProxyForPage() not implemented.");
|
"UserAccountsDaoStub.getUserAccountsWhoProxyForPage() not implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setProxyAccountsOnProfile(String profilePageUri,
|
||||||
|
Collection<String> userAccountUris) {
|
||||||
|
throw new RuntimeException(
|
||||||
|
"UserAccountsDaoStub.setProxyAccountsOnProfile() not implemented.");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue