NIHVIVO-2343 Create method: UserAccountsDao.getUserAccountsWhoProxyForPage(String profilePageUri)
This commit is contained in:
parent
202a657178
commit
7bb12dbeb9
5 changed files with 116 additions and 4 deletions
|
@ -39,6 +39,11 @@ public interface UserAccountsDao {
|
||||||
* @return null if the ID is null, or if there is no such UserAccount
|
* @return null if the ID is null, or if there is no such UserAccount
|
||||||
*/
|
*/
|
||||||
UserAccount getUserAccountByExternalAuthId(String externalAuthId);
|
UserAccount getUserAccountByExternalAuthId(String externalAuthId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get any UserAccounts who act as proxy editors for this profile page.
|
||||||
|
*/
|
||||||
|
Collection<UserAccount> getUserAccountsWhoProxyForPage(String profilePageUri);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new UserAccount in the model.
|
* Create a new UserAccount in the model.
|
||||||
|
|
|
@ -47,6 +47,12 @@ public class UserAccountsDaoFiltering extends BaseFiltering implements
|
||||||
return innerDao.getUserAccountByExternalAuthId(externalAuthId);
|
return innerDao.getUserAccountByExternalAuthId(externalAuthId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<UserAccount> getUserAccountsWhoProxyForPage(
|
||||||
|
String profilePageUri) {
|
||||||
|
return innerDao.getUserAccountsWhoProxyForPage(profilePageUri);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String insertUserAccount(UserAccount userAccount) {
|
public String insertUserAccount(UserAccount userAccount) {
|
||||||
return innerDao.insertUserAccount(userAccount);
|
return innerDao.insertUserAccount(userAccount);
|
||||||
|
|
|
@ -12,6 +12,8 @@ import java.util.Random;
|
||||||
import com.hp.hpl.jena.ontology.OntClass;
|
import com.hp.hpl.jena.ontology.OntClass;
|
||||||
import com.hp.hpl.jena.ontology.OntModel;
|
import com.hp.hpl.jena.ontology.OntModel;
|
||||||
import com.hp.hpl.jena.ontology.OntResource;
|
import com.hp.hpl.jena.ontology.OntResource;
|
||||||
|
import com.hp.hpl.jena.rdf.model.Literal;
|
||||||
|
import com.hp.hpl.jena.rdf.model.Property;
|
||||||
import com.hp.hpl.jena.rdf.model.Resource;
|
import com.hp.hpl.jena.rdf.model.Resource;
|
||||||
import com.hp.hpl.jena.rdf.model.Statement;
|
import com.hp.hpl.jena.rdf.model.Statement;
|
||||||
import com.hp.hpl.jena.rdf.model.StmtIterator;
|
import com.hp.hpl.jena.rdf.model.StmtIterator;
|
||||||
|
@ -24,6 +26,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.PermissionSet;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
|
import edu.cornell.mannlib.vitro.webapp.beans.UserAccount;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.InsertException;
|
import edu.cornell.mannlib.vitro.webapp.dao.InsertException;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.UserAccountsDao;
|
import edu.cornell.mannlib.vitro.webapp.dao.UserAccountsDao;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implement UserAccountsDao for Jena models.
|
* Implement UserAccountsDao for Jena models.
|
||||||
|
@ -164,6 +167,41 @@ public class UserAccountsDaoJena extends JenaBaseDao implements UserAccountsDao
|
||||||
return getUserAccountByUri(userUri);
|
return getUserAccountByUri(userUri);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<UserAccount> getUserAccountsWhoProxyForPage(
|
||||||
|
String profilePageUri) {
|
||||||
|
List<String> userUris = new ArrayList<String>();
|
||||||
|
|
||||||
|
Resource s = null;
|
||||||
|
Property p = getOntModel().getProperty(
|
||||||
|
VitroVocabulary.USERACCOUNT_PROXY_EDITOR_FOR);
|
||||||
|
Resource o = getOntModel().createResource(profilePageUri);
|
||||||
|
|
||||||
|
getOntModel().enterCriticalSection(Lock.READ);
|
||||||
|
try {
|
||||||
|
StmtIterator stmts = getOntModel().listStatements(s, p, o);
|
||||||
|
while (stmts.hasNext()) {
|
||||||
|
Resource subject = stmts.next().getSubject();
|
||||||
|
if (subject != null) {
|
||||||
|
userUris.add(subject.getURI());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stmts.close();
|
||||||
|
} finally {
|
||||||
|
getOntModel().leaveCriticalSection();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<UserAccount> userAccounts = new ArrayList<UserAccount>();
|
||||||
|
for (String userUri : userUris) {
|
||||||
|
UserAccount ua = getUserAccountByUri(userUri);
|
||||||
|
if (ua != null) {
|
||||||
|
userAccounts.add(ua);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return userAccounts;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String insertUserAccount(UserAccount userAccount) {
|
public String insertUserAccount(UserAccount userAccount) {
|
||||||
if (userAccount == null) {
|
if (userAccount == null) {
|
||||||
|
@ -214,8 +252,7 @@ public class UserAccountsDaoJena extends JenaBaseDao implements UserAccountsDao
|
||||||
model.add(res, RDF.type, USERACCOUNT_ROOT_USER);
|
model.add(res, RDF.type, USERACCOUNT_ROOT_USER);
|
||||||
}
|
}
|
||||||
|
|
||||||
updatePropertyResourceURIValues(res,
|
updatePropertyResourceURIValues(res, USERACCOUNT_PROXY_EDITOR_FOR,
|
||||||
USERACCOUNT_PROXY_EDITOR_FOR,
|
|
||||||
userAccount.getProxiedIndividualUris(), model);
|
userAccount.getProxiedIndividualUris(), model);
|
||||||
|
|
||||||
userAccount.setUri(userUri);
|
userAccount.setUri(userUri);
|
||||||
|
@ -283,8 +320,7 @@ public class UserAccountsDaoJena extends JenaBaseDao implements UserAccountsDao
|
||||||
model.remove(res, RDF.type, USERACCOUNT_ROOT_USER);
|
model.remove(res, RDF.type, USERACCOUNT_ROOT_USER);
|
||||||
}
|
}
|
||||||
|
|
||||||
updatePropertyResourceURIValues(res,
|
updatePropertyResourceURIValues(res, USERACCOUNT_PROXY_EDITOR_FOR,
|
||||||
USERACCOUNT_PROXY_EDITOR_FOR,
|
|
||||||
userAccount.getProxiedIndividualUris(), model);
|
userAccount.getProxiedIndividualUris(), model);
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -232,6 +232,48 @@ public class UserAccountsDaoJenaTest extends AbstractTestClass {
|
||||||
assertEqualAccounts(user1, updated);
|
assertEqualAccounts(user1, updated);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getProxyEditorsFirst() {
|
||||||
|
String profileOne = NS_MINE + "userNewProxyOne";
|
||||||
|
String profileTwo = NS_MINE + "userNewProxyTwo";
|
||||||
|
userNew.setProxiedIndividualUris(collection(profileOne, profileTwo));
|
||||||
|
|
||||||
|
String userUri = dao.insertUserAccount(userNew);
|
||||||
|
UserAccount user = dao.getUserAccountByUri(userUri);
|
||||||
|
|
||||||
|
assertExpectedAccountUris("proxy for profile one",
|
||||||
|
Collections.singleton(user),
|
||||||
|
dao.getUserAccountsWhoProxyForPage(profileOne));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getProxyEditorsSecond() {
|
||||||
|
String profileOne = NS_MINE + "userNewProxyOne";
|
||||||
|
String profileTwo = NS_MINE + "userNewProxyTwo";
|
||||||
|
userNew.setProxiedIndividualUris(collection(profileOne, profileTwo));
|
||||||
|
|
||||||
|
String userUri = dao.insertUserAccount(userNew);
|
||||||
|
UserAccount user = dao.getUserAccountByUri(userUri);
|
||||||
|
|
||||||
|
assertExpectedAccountUris("proxy for profile two",
|
||||||
|
Collections.singleton(user),
|
||||||
|
dao.getUserAccountsWhoProxyForPage(profileTwo));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getProxyEditorsBogus() {
|
||||||
|
String profileOne = NS_MINE + "userNewProxyOne";
|
||||||
|
String profileTwo = NS_MINE + "userNewProxyTwo";
|
||||||
|
String bogusProfile = NS_MINE + "bogus";
|
||||||
|
userNew.setProxiedIndividualUris(collection(profileOne, profileTwo));
|
||||||
|
|
||||||
|
dao.insertUserAccount(userNew);
|
||||||
|
|
||||||
|
assertExpectedAccountUris("proxy for bogus profile",
|
||||||
|
Collections.<UserAccount> emptySet(),
|
||||||
|
dao.getUserAccountsWhoProxyForPage(bogusProfile));
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
// Tests for PermissionSet methods
|
// Tests for PermissionSet methods
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
@ -390,6 +432,22 @@ public class UserAccountsDaoJenaTest extends AbstractTestClass {
|
||||||
assertEquals("all permission sets", expectedMaps, actualMaps);
|
assertEquals("all permission sets", expectedMaps, actualMaps);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void assertExpectedAccountUris(String label,
|
||||||
|
Set<UserAccount> expectedUserAccounts,
|
||||||
|
Collection<UserAccount> actualUserAccounts) {
|
||||||
|
Set<String> expectedUris = new HashSet<String>();
|
||||||
|
for (UserAccount ua : expectedUserAccounts) {
|
||||||
|
expectedUris.add(ua.getUri());
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<String> actualUris = new HashSet<String>();
|
||||||
|
for (UserAccount ua : actualUserAccounts) {
|
||||||
|
actualUris.add(ua.getUri());
|
||||||
|
}
|
||||||
|
|
||||||
|
assertEqualSets(label, expectedUris, actualUris);
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private void dumpModelStatements() {
|
private void dumpModelStatements() {
|
||||||
StmtIterator stmts = ontModel.listStatements();
|
StmtIterator stmts = ontModel.listStatements();
|
||||||
|
|
|
@ -90,4 +90,11 @@ public class UserAccountsDaoStub implements UserAccountsDao {
|
||||||
"UserAccountsDao.getAllUserAccounts() not implemented.");
|
"UserAccountsDao.getAllUserAccounts() not implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<UserAccount> getUserAccountsWhoProxyForPage(
|
||||||
|
String profilePageUri) {
|
||||||
|
throw new RuntimeException(
|
||||||
|
"UserAccountsDaoStub.getUserAccountsWhoProxyForPage() not implemented.");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue