NIHVIVO-2343 Create identifier so a ProxyEditor works like a SelfEditor

This commit is contained in:
j2blake 2011-10-28 22:42:16 +00:00
parent 6f651fcf4f
commit 743b96281e
2 changed files with 32 additions and 7 deletions

View file

@ -2,6 +2,9 @@
package edu.cornell.mannlib.vitro.webapp.auth.identifier.common;
import static edu.cornell.mannlib.vitro.webapp.auth.identifier.common.HasAssociatedIndividual.Mechanism.EXPLICIT_PROXY;
import static edu.cornell.mannlib.vitro.webapp.auth.identifier.common.HasAssociatedIndividual.Mechanism.SELF;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@ -52,6 +55,7 @@ public class CommonIdentifierBundleFactory implements IdentifierBundleFactory {
bundle.addAll(createRootUserIdentifiers(req));
bundle.addAll(createRoleLevelIdentifiers(req));
bundle.addAll(createBlacklistOrAssociatedIndividualIdentifiers(req));
bundle.addAll(createExplicitProxyEditingIdentifiers(req));
return bundle;
}
@ -104,7 +108,7 @@ public class CommonIdentifierBundleFactory implements IdentifierBundleFactory {
if (id != null) {
ids.add(id);
} else {
ids.add(new HasAssociatedIndividual(ind.getURI()));
ids.add(new HasAssociatedIndividual(ind.getURI(), SELF));
}
}
@ -112,10 +116,7 @@ public class CommonIdentifierBundleFactory implements IdentifierBundleFactory {
}
/**
* Get all Individuals associated with the current user.
*
* TODO Currently only uses the matching property. Should also use
* "mayEditAs" type of association.
* Get all Individuals associated with the current user as SELF.
*/
private Collection<Individual> getAssociatedIndividuals(
HttpServletRequest req) {
@ -142,6 +143,23 @@ public class CommonIdentifierBundleFactory implements IdentifierBundleFactory {
return individuals;
}
/**
* Get all Individuals associated with the current user by explicit proxy relationship.
*/
private Collection<? extends Identifier> createExplicitProxyEditingIdentifiers(
HttpServletRequest req) {
Collection<Identifier> ids = new ArrayList<Identifier>();
UserAccount user = LoginStatusBean.getCurrentUser(req);
if (user != null) {
for(String proxiedUri: user.getProxiedIndividualUris()) {
ids.add(new HasAssociatedIndividual(proxiedUri, EXPLICIT_PROXY));
}
}
return ids;
}
@Override
public String toString() {
return this.getClass().getSimpleName() + " - " + hashCode();

View file

@ -14,6 +14,8 @@ import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle;
*
* This includes a thick factory method that will look through a directory of
* files to determine whether the associated individual is blacklisted.
*
* The mechanism is only to record how this was created, for diagnostic purposes.
*/
public class HasAssociatedIndividual extends AbstractCommonIdentifier implements
Identifier {
@ -30,11 +32,15 @@ public class HasAssociatedIndividual extends AbstractCommonIdentifier implements
}
return set;
}
public enum Mechanism {SELF, EXPLICIT_PROXY}
private final String associatedIndividualUri;
private final Mechanism mechanism;
public HasAssociatedIndividual(String associatedIndividualUri) {
public HasAssociatedIndividual(String associatedIndividualUri, Mechanism mechanism) {
this.associatedIndividualUri = associatedIndividualUri;
this.mechanism = mechanism;
}
public String getAssociatedIndividualUri() {
@ -43,6 +49,7 @@ public class HasAssociatedIndividual extends AbstractCommonIdentifier implements
@Override
public String toString() {
return "HasAssociatedIndividual[" + associatedIndividualUri + "]";
return "HasAssociatedIndividual[" + associatedIndividualUri + " (" + mechanism +
")]";
}
}