Skip to content

Commit

Permalink
[DS-839] Adding Field to Choice Authority to allow Authorities to be …
Browse files Browse the repository at this point in the history
…able to know of the field being authority controlled.

git-svn-id: http://scm.dspace.org/svn/repo/dspace/trunk@6138 9c30dcfa-912a-0410-8fc2-9e0234be79fd
  • Loading branch information
mdiggory committed Mar 15, 2011
1 parent 03ab1fd commit 46fedd6
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 27 deletions.
Expand Up @@ -31,14 +31,15 @@ public interface ChoiceAuthority
* defaultSelected index in the Choices instance to the choice, if any,
* that matches the value.
*
* @param field being matched for
* @param text user's value to match
* @param collection database ID of Collection for context (owner of Item)
* @param start choice at which to start, 0 is first.
* @param limit maximum number of choices to return, 0 for no limit.
* @param locale explicit localization key if available, or null
* @return a Choices object (never null).
*/
public Choices getMatches(String text, int collection, int start, int limit, String locale);
public Choices getMatches(String field, String text, int collection, int start, int limit, String locale);

/**
* Get the single "best" match (if any) of a value in the authority
Expand All @@ -49,12 +50,13 @@ public interface ChoiceAuthority
* This call is typically used in non-interactive metadata ingest
* where there is no interactive agent to choose from among options.
*
* @param field being matched for
* @param text user's value to match
* @param collection database ID of Collection for context (owner of Item)
* @param locale explicit localization key if available, or null
* @return a Choices object (never null) with 1 or 0 values.
*/
public Choices getBestMatch(String text, int collection, String locale);
public Choices getBestMatch(String field, String text, int collection, String locale);

/**
* Get the canonical user-visible "label" (i.e. short descriptive text)
Expand All @@ -64,9 +66,10 @@ public interface ChoiceAuthority
* This may get called many times while populating a Web page so it should
* be implemented as efficiently as possible.
*
* @param field being matched for
* @param key authority key known to this authority.
* @param locale explicit localization key if available, or null
* @return descriptive label - should always return something, never null.
*/
public String getLabel(String key, String locale);
public String getLabel(String field, String key, String locale);
}
Expand Up @@ -153,7 +153,7 @@ private String config2fkey(String field)
* Wrapper that calls getMatches method of the plugin corresponding to
* the metadata field defined by schema,element,qualifier.
*
* @see ChoiceAuthority#getMatches(String, int, int, int, String)
* @see ChoiceAuthority#getMatches(String, String, int, int, int, String)
* @param schema schema of metadata field
* @param element element of metadata field
* @param qualifier qualifier of metadata field
Expand All @@ -175,7 +175,7 @@ public Choices getMatches(String schema, String element, String qualifier,
* Wrapper calls getMatches method of the plugin corresponding to
* the metadata field defined by single field key.
*
* @see ChoiceAuthority#getMatches(String, int, int, int, String)
* @see ChoiceAuthority#getMatches(String, String, int, int, int, String)
* @param fieldKey single string identifying metadata field
* @param query user's value to match
* @param collection database ID of Collection for context (owner of Item)
Expand All @@ -194,14 +194,14 @@ public Choices getMatches(String fieldKey, String query, int collection,
"No choices plugin was configured for field \"" + fieldKey
+ "\".");
}
return ma.getMatches(query, collection, start, limit, locale);
return ma.getMatches(fieldKey, query, collection, start, limit, locale);
}

/**
* Wrapper that calls getBestMatch method of the plugin corresponding to
* the metadata field defined by single field key.
*
* @see ChoiceAuthority#getBestMatch(String, int, String)
* @see ChoiceAuthority#getBestMatch(String, String, int, String)
* @param fieldKey single string identifying metadata field
* @param query user's value to match
* @param collection database ID of Collection for context (owner of Item)
Expand All @@ -218,7 +218,7 @@ public Choices getBestMatch(String fieldKey, String query, int collection,
"No choices plugin was configured for field \"" + fieldKey
+ "\".");
}
return ma.getBestMatch(query, collection, locale);
return ma.getBestMatch(fieldKey, query, collection, locale);
}

/**
Expand All @@ -242,7 +242,7 @@ public String getLabel(String fieldKey, String authKey, String locale)
{
throw new IllegalArgumentException("No choices plugin was configured for field \"" + fieldKey + "\".");
}
return ma.getLabel(authKey, locale);
return ma.getLabel(fieldKey, authKey, locale);
}

/**
Expand Down
Expand Up @@ -117,7 +117,7 @@ private void init()
}


public Choices getMatches(String query, int collection, int start, int limit, String locale)
public Choices getMatches(String field, String query, int collection, int start, int limit, String locale)
{
init();

Expand All @@ -134,7 +134,7 @@ public Choices getMatches(String query, int collection, int start, int limit, St
return new Choices(v, 0, v.length, Choices.CF_AMBIGUOUS, false, dflt);
}

public Choices getBestMatch(String text, int collection, String locale)
public Choices getBestMatch(String field, String text, int collection, String locale)
{
init();
for (int i = 0; i < values.length; ++i)
Expand All @@ -149,7 +149,7 @@ public Choices getBestMatch(String text, int collection, String locale)
return new Choices(Choices.CF_NOTFOUND);
}

public String getLabel(String key, String locale)
public String getLabel(String field, String key, String locale)
{
init();
return labels[Integer.parseInt(key)];
Expand Down
Expand Up @@ -154,7 +154,7 @@ private String buildString(Node node)
}
}

public Choices getMatches(String text, int collection, int start, int limit, String locale)
public Choices getMatches(String field, String text, int collection, int start, int limit, String locale)
{
init();
log.debug("Getting matches for '" + text + "'");
Expand Down Expand Up @@ -203,14 +203,14 @@ public Choices getMatches(String text, int collection, int start, int limit, Str
return new Choices(choices, 0, choices.length, Choices.CF_AMBIGUOUS, false);
}

public Choices getBestMatch(String text, int collection, String locale)
public Choices getBestMatch(String field, String text, int collection, String locale)
{
init();
log.debug("Getting best match for '" + text + "'");
return getMatches(text, collection, 0, 2, locale);
return getMatches(field, text, collection, 0, 2, locale);
}

public String getLabel(String key, String locale)
public String getLabel(String field, String key, String locale)
{
init();
String xpathExpression = String.format(idTemplate, key);
Expand All @@ -222,4 +222,4 @@ public String getLabel(String key, String locale)
return("");
}
}
}
}
Expand Up @@ -83,16 +83,16 @@ public LCNameAuthority()
}

// punt! this is a poor implementation..
public Choices getBestMatch(String text, int collection, String locale)
public Choices getBestMatch(String field, String text, int collection, String locale)
{
return getMatches(text, collection, 0, 2, locale);
return getMatches(field, text, collection, 0, 2, locale);
}

/**
* Match a proposed value against name authority records
* Value is assumed to be in "Lastname, Firstname" format.
*/
public Choices getMatches(String text, int collection, int start, int limit, String locale)
public Choices getMatches(String field, String text, int collection, int start, int limit, String locale)
{
Choices result = queryPerson(text, start, limit);
if (result == null)
Expand All @@ -105,7 +105,7 @@ public Choices getMatches(String text, int collection, int start, int limit, Str

// punt; supposed to get the canonical display form of a metadata authority key
// XXX FIXME implement this with a query on the authority key, cache results
public String getLabel(String key, String locale)
public String getLabel(String field, String key, String locale)
{
return key;
}
Expand Down
Expand Up @@ -52,4 +52,8 @@ public Choices getMatches(String text, int collection, int start, int limit, Str
return result;
}

@Override
public Choices getMatches(String field, String text, int collection, int start, int limit, String locale) {
return getMatches(text, collection, start, limit, locale);
}
}
Expand Up @@ -72,14 +72,14 @@ public SHERPARoMEOProtocol()
// this implements the specific RoMEO API args and XML tag naming
public abstract Choices getMatches(String text, int collection, int start, int limit, String locale);

public Choices getBestMatch(String text, int collection, String locale)
public Choices getBestMatch(String field, String text, int collection, String locale)
{
return getMatches(text, collection, 0, 2, locale);
return getMatches(field, text, collection, 0, 2, locale);
}

// XXX FIXME just punt, returning value, never got around to
// implementing a reverse query.
public String getLabel(String key, String locale)
public String getLabel(String field, String key, String locale)
{
return key;
}
Expand Down
Expand Up @@ -53,4 +53,9 @@ public Choices getMatches(String text, int collection, int start, int limit, Str
}
return result;
}

@Override
public Choices getMatches(String field, String text, int collection, int start, int limit, String locale) {
return getMatches(text, collection, start, limit, locale);
}
}
Expand Up @@ -33,7 +33,7 @@ public class SampleAuthority implements ChoiceAuthority
"Saturday"
};

public Choices getMatches(String query, int collection, int start, int limit, String locale)
public Choices getMatches(String field, String query, int collection, int start, int limit, String locale)
{
int dflt = -1;
Choice v[] = new Choice[values.length];
Expand All @@ -48,7 +48,7 @@ public Choices getMatches(String query, int collection, int start, int limit, St
return new Choices(v, 0, v.length, Choices.CF_AMBIGUOUS, false, dflt);
}

public Choices getBestMatch(String text, int collection, String locale)
public Choices getBestMatch(String field, String text, int collection, String locale)
{
for (int i = 0; i < values.length; ++i)
{
Expand All @@ -62,7 +62,7 @@ public Choices getBestMatch(String text, int collection, String locale)
return new Choices(Choices.CF_NOTFOUND);
}

public String getLabel(String key, String locale)
public String getLabel(String field, String key, String locale)
{
return labels[Integer.parseInt(key)];
}
Expand Down

0 comments on commit 46fedd6

Please sign in to comment.