NIHVIVO-2299 Continue converting from older Identifiers to newer Identifiers.

This commit is contained in:
j2blake 2011-05-11 21:19:57 +00:00
parent 491f5d3728
commit f41d69753b
3 changed files with 24 additions and 42 deletions

View file

@ -2,31 +2,31 @@
package edu.cornell.mannlib.vitro.webapp.edit.n3editing; package edu.cornell.mannlib.vitro.webapp.edit.n3editing;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import org.apache.xerces.util.XMLChar; import org.apache.xerces.util.XMLChar;
import edu.cornell.mannlib.vitro.webapp.auth.identifier.HasAssociatedIndividual;
import edu.cornell.mannlib.vitro.webapp.auth.identifier.HasRoleLevel;
import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle; import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle;
import edu.cornell.mannlib.vitro.webapp.auth.identifier.IsUser;
import edu.cornell.mannlib.vitro.webapp.auth.identifier.RequestIdentifiers; import edu.cornell.mannlib.vitro.webapp.auth.identifier.RequestIdentifiers;
import edu.cornell.mannlib.vitro.webapp.auth.identifier.RoleIdentifier;
import edu.cornell.mannlib.vitro.webapp.auth.identifier.SelfEditingIdentifierFactory;
public class EditN3Utils { public class EditN3Utils {
/** Several places could give an editor URI. Return the first one. */
public static String getEditorUri(HttpServletRequest request) { public static String getEditorUri(HttpServletRequest request) {
IdentifierBundle ids = RequestIdentifiers.getIdBundleForRequest(request); IdentifierBundle ids = RequestIdentifiers.getIdBundleForRequest(request);
String editorUri = SelfEditingIdentifierFactory.getSelfEditingUri(ids); List<String> uris = new ArrayList<String>();
uris.addAll(IsUser.getUserUris(ids));
if (editorUri == null) { uris.addAll(HasAssociatedIndividual.getIndividualUris(ids));
editorUri = RoleIdentifier.getUri(ids); uris.addAll(HasRoleLevel.getRoleLevelUris(ids));
} uris.add("Unknown N3 Editor");
return uris.get(0);
if (editorUri == null) {
editorUri = "Unknown N3 Editor";
}
return editorUri;
} }
/** /**

View file

@ -15,8 +15,8 @@ import stubs.edu.cornell.mannlib.vitro.webapp.auth.policy.bean.PropertyRestricti
import stubs.javax.servlet.ServletContextStub; import stubs.javax.servlet.ServletContextStub;
import edu.cornell.mannlib.vitro.testing.AbstractTestClass; import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
import edu.cornell.mannlib.vitro.webapp.auth.identifier.ArrayIdentifierBundle; import edu.cornell.mannlib.vitro.webapp.auth.identifier.ArrayIdentifierBundle;
import edu.cornell.mannlib.vitro.webapp.auth.identifier.HasAssociatedIndividual;
import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle; import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle;
import edu.cornell.mannlib.vitro.webapp.auth.identifier.SelfEditingIdentifierFactory;
import edu.cornell.mannlib.vitro.webapp.auth.policy.bean.PropertyRestrictionPolicyHelper; import edu.cornell.mannlib.vitro.webapp.auth.policy.bean.PropertyRestrictionPolicyHelper;
import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.Authorization; import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.Authorization;
import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.PolicyDecision; import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.PolicyDecision;
@ -69,14 +69,11 @@ public class SelfEditingPolicyTest extends AbstractTestClass {
policy = new SelfEditingPolicy(ctx); policy = new SelfEditingPolicy(ctx);
ids = new ArrayIdentifierBundle();
ids.add(new SelfEditingIdentifierFactory.NetId("test223"));
IndividualImpl ind = new IndividualImpl(); IndividualImpl ind = new IndividualImpl();
ind.setURI(SELFEDITOR_URI); ind.setURI(SELFEDITOR_URI);
ids.add(new SelfEditingIdentifierFactory.SelfEditing(ind,
SelfEditingIdentifierFactory.NOT_BLACKLISTED)); ids = new ArrayIdentifierBundle();
ids.add(new HasAssociatedIndividual(SELFEDITOR_URI));
} }
@Test @Test
@ -323,19 +320,13 @@ public class SelfEditingPolicyTest extends AbstractTestClass {
private void setUpTwoSEIs() { private void setUpTwoSEIs() {
ids = new ArrayIdentifierBundle(); ids = new ArrayIdentifierBundle();
ids.add(new SelfEditingIdentifierFactory.NetId("bozoUser"));
IndividualImpl ind1 = new IndividualImpl(); IndividualImpl ind1 = new IndividualImpl();
ind1.setURI(SAFE_NS + "bozoUri"); ind1.setURI(SAFE_NS + "bozoUri");
ids.add(new SelfEditingIdentifierFactory.SelfEditing(ind1, ids.add(new HasAssociatedIndividual(ind1.getURI()));
SelfEditingIdentifierFactory.NOT_BLACKLISTED));
ids.add(new SelfEditingIdentifierFactory.NetId("test223"));
IndividualImpl ind2 = new IndividualImpl(); IndividualImpl ind2 = new IndividualImpl();
ind2.setURI(SELFEDITOR_URI); ind2.setURI(SELFEDITOR_URI);
ids.add(new SelfEditingIdentifierFactory.SelfEditing(ind2, ids.add(new HasAssociatedIndividual(ind2.getURI()));
SelfEditingIdentifierFactory.NOT_BLACKLISTED));
} }
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------

View file

@ -20,9 +20,9 @@ import com.hp.hpl.jena.rdf.model.impl.RDFDefaultErrorHandler;
import edu.cornell.mannlib.vitro.testing.AbstractTestClass; import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
import edu.cornell.mannlib.vitro.webapp.auth.identifier.ArrayIdentifierBundle; import edu.cornell.mannlib.vitro.webapp.auth.identifier.ArrayIdentifierBundle;
import edu.cornell.mannlib.vitro.webapp.auth.identifier.HasAssociatedIndividual;
import edu.cornell.mannlib.vitro.webapp.auth.identifier.Identifier; import edu.cornell.mannlib.vitro.webapp.auth.identifier.Identifier;
import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle; import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle;
import edu.cornell.mannlib.vitro.webapp.auth.identifier.SelfEditingIdentifierFactory;
import edu.cornell.mannlib.vitro.webapp.auth.policy.SelfEditingPolicy; import edu.cornell.mannlib.vitro.webapp.auth.policy.SelfEditingPolicy;
import edu.cornell.mannlib.vitro.webapp.auth.policy.bean.PropertyRestrictionPolicyHelper; import edu.cornell.mannlib.vitro.webapp.auth.policy.bean.PropertyRestrictionPolicyHelper;
import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.Authorization; import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.Authorization;
@ -88,7 +88,7 @@ public class SelfEditingPolicySetupTest extends AbstractTestClass {
PropertyRestrictionPolicyHelper.setBean(ctx, PropertyRestrictionPolicyHelper.setBean(ctx,
PropertyRestrictionPolicyHelperStub PropertyRestrictionPolicyHelperStub
.getInstance(new String[] { ADMIN_NS })); .getInstance(new String[] { ADMIN_NS }));
policy = new SelfEditingPolicy(ctx); policy = new SelfEditingPolicy(ctx);
Assert.assertNotNull(policy); Assert.assertNotNull(policy);
@ -96,8 +96,7 @@ public class SelfEditingPolicySetupTest extends AbstractTestClass {
seIndividual.setURI(SELFEDITOR_URI); seIndividual.setURI(SELFEDITOR_URI);
ids = new ArrayIdentifierBundle(); ids = new ArrayIdentifierBundle();
ids.add(new SelfEditingIdentifierFactory.SelfEditing(seIndividual, ids.add(new HasAssociatedIndividual(SELFEDITOR_URI));
SelfEditingIdentifierFactory.NOT_BLACKLISTED));
// setLoggerLevel(SelfEditingPolicySetupTest.class, Level.DEBUG); // setLoggerLevel(SelfEditingPolicySetupTest.class, Level.DEBUG);
} }
@ -125,16 +124,8 @@ public class SelfEditingPolicySetupTest extends AbstractTestClass {
@Test @Test
public void noSelfEditorIdentifier() { public void noSelfEditorIdentifier() {
ids.clear(); ids.clear();
ids.add(new Identifier() { /* empty identifier */ }); ids.add(new Identifier() { /* empty identifier */
assertAddObjectPropStmt(SELFEDITOR_URI, SAFE_PREDICATE, SAFE_RESOURCE, });
Authorization.INCONCLUSIVE);
}
@Test
public void blacklistedSelfEditor() {
ids.clear();
ids.add(new SelfEditingIdentifierFactory.SelfEditing(seIndividual,
"Don't like this guy."));
assertAddObjectPropStmt(SELFEDITOR_URI, SAFE_PREDICATE, SAFE_RESOURCE, assertAddObjectPropStmt(SELFEDITOR_URI, SAFE_PREDICATE, SAFE_RESOURCE,
Authorization.INCONCLUSIVE); Authorization.INCONCLUSIVE);
} }