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; 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.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
@ -52,6 +55,7 @@ public class CommonIdentifierBundleFactory implements IdentifierBundleFactory {
bundle.addAll(createRootUserIdentifiers(req)); bundle.addAll(createRootUserIdentifiers(req));
bundle.addAll(createRoleLevelIdentifiers(req)); bundle.addAll(createRoleLevelIdentifiers(req));
bundle.addAll(createBlacklistOrAssociatedIndividualIdentifiers(req)); bundle.addAll(createBlacklistOrAssociatedIndividualIdentifiers(req));
bundle.addAll(createExplicitProxyEditingIdentifiers(req));
return bundle; return bundle;
} }
@ -104,7 +108,7 @@ public class CommonIdentifierBundleFactory implements IdentifierBundleFactory {
if (id != null) { if (id != null) {
ids.add(id); ids.add(id);
} else { } 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. * Get all Individuals associated with the current user as SELF.
*
* TODO Currently only uses the matching property. Should also use
* "mayEditAs" type of association.
*/ */
private Collection<Individual> getAssociatedIndividuals( private Collection<Individual> getAssociatedIndividuals(
HttpServletRequest req) { HttpServletRequest req) {
@ -142,6 +143,23 @@ public class CommonIdentifierBundleFactory implements IdentifierBundleFactory {
return individuals; 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 @Override
public String toString() { public String toString() {
return this.getClass().getSimpleName() + " - " + hashCode(); 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 * This includes a thick factory method that will look through a directory of
* files to determine whether the associated individual is blacklisted. * 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 public class HasAssociatedIndividual extends AbstractCommonIdentifier implements
Identifier { Identifier {
@ -31,10 +33,14 @@ public class HasAssociatedIndividual extends AbstractCommonIdentifier implements
return set; return set;
} }
private final String associatedIndividualUri; public enum Mechanism {SELF, EXPLICIT_PROXY}
public HasAssociatedIndividual(String associatedIndividualUri) { private final String associatedIndividualUri;
private final Mechanism mechanism;
public HasAssociatedIndividual(String associatedIndividualUri, Mechanism mechanism) {
this.associatedIndividualUri = associatedIndividualUri; this.associatedIndividualUri = associatedIndividualUri;
this.mechanism = mechanism;
} }
public String getAssociatedIndividualUri() { public String getAssociatedIndividualUri() {
@ -43,6 +49,7 @@ public class HasAssociatedIndividual extends AbstractCommonIdentifier implements
@Override @Override
public String toString() { public String toString() {
return "HasAssociatedIndividual[" + associatedIndividualUri + "]"; return "HasAssociatedIndividual[" + associatedIndividualUri + " (" + mechanism +
")]";
} }
} }