use of org.collectionspace.chain.csp.config.ConfigException in project application by collectionspace.
the class WebAutoComplete method doAuthorityAutocomplete.
private JSONArray doAuthorityAutocomplete(CSPRequestCache cache, Storage storage, String fieldname, String start, String vocabConstraint, String pageSize, String pageNum) throws JSONException, ExistException, UnimplementedException, UnderlyingStorageException, ConfigException {
FieldSet fs = r.getFieldFullList(fieldname);
JSONArray out = new JSONArray();
Instance[] allInstances = null;
if (fs == null || !(fs instanceof Field)) {
if (r.hasHierarchyUsed("screen")) {
// Configures the hierarchy section.
Structure s = r.getStructure("screen");
if (s.hasOption(fieldname)) {
// This is one of the hierarchy fields
if (vocabConstraint != null) {
allInstances = new Instance[1];
String fullname = r.getID() + "-" + vocabConstraint;
allInstances[0] = r.getSpec().getInstance(fullname);
} else {
Option a = s.getOption(fieldname);
String[] data = a.getName().split(",");
allInstances = new Instance[data.length];
for (int i = 0; i < data.length; i++) {
allInstances[i] = (r.getSpec().getInstance(data[i]));
}
}
} else {
fs = r.getSpec().getRecord("hierarchy").getFieldFullList(fieldname);
if (fs instanceof Field) {
allInstances = ((Field) fs).getAllAutocompleteInstances();
}
}
}
} else {
allInstances = ((Field) fs).getAllAutocompleteInstances();
}
if (allInstances == null) {
// Cannot autocomplete
return out;
}
// support multiassign of autocomplete instances
for (Instance n : allInstances) {
try {
if (n == null) {
// Field has no autocomplete
} else {
String path = n.getRecord().getID() + "/" + n.getTitleRef();
JSONObject restriction = new JSONObject();
if (pageSize != null) {
restriction.put("pageSize", pageSize);
}
if (pageNum != null) {
restriction.put("pageNum", pageNum);
}
FieldSet dispNameFS = n.getRecord().getDisplayNameField();
if (dispNameFS == null) {
throw new ConfigException("WebAutoComplete for Instance has no displayName configured: " + n.getID());
}
String displayNameFieldID = dispNameFS.getID();
// May be something other than display name
restriction.put(displayNameFieldID, start);
JSONObject results = storage.getPathsJSON(path, restriction);
String[] paths = (String[]) results.get("listItems");
for (String csid : paths) {
JSONObject data = storage.retrieveJSON(path + "/" + csid + "/view", new JSONObject());
JSONObject entry = new JSONObject();
// TODO - handle multiple name matches
String displayNameString = data.getString(displayNameFieldID);
JSONArray displayNames = JSONUtils.createJSONArrayFromSeparatedString(displayNameString);
String primaryDN = displayNames.getString(0);
String refid = data.getString("refid");
// HACK - transition period with full instead of base URN value
if (refid.endsWith("'" + primaryDN + "'"))
refid = refid.substring(0, refid.length() - (primaryDN.length() + 2));
entry.put("baseUrn", refid);
entry.put("csid", data.getString("csid"));
entry.put("type", n.getRecord().getWebURL());
entry.put("displayNames", displayNames);
// RefName.AuthorityItem item = RefName.AuthorityItem.parse(refid);
// entry.put("namespace",item.getParentShortIdentifier());
entry.put("namespace", data.getString("namespace"));
entry.put("workflow", data.getString("workflow"));
out.put(entry);
}
}
} catch (UnderlyingStorageException x) {
if (x.getStatus() == 403) {
// permission error - keep calm and carry on
} else {
throw x;
}
}
}
// Instance n=((Field)fs).getAutocompleteInstance();
return out;
}
use of org.collectionspace.chain.csp.config.ConfigException in project application by collectionspace.
the class WebAutoComplete method autocomplete.
private void autocomplete(CSPRequestCache cache, Storage storage, UIRequest request) throws UIException {
try {
String[] path = request.getPrincipalPath();
// Last path element is the field on which user is querying.
String fieldName = path[path.length - 1];
JSONArray out = new JSONArray();
boolean hasHierarchy = r.hasHierarchyUsed("screen");
boolean isHierarchyAutoComplete = false;
if (hasHierarchy) {
// Configures the hierarchy section.
Structure s = r.getStructure("screen");
if (s.hasOption(fieldName)) {
// This is one of the hierarchy fields
isHierarchyAutoComplete = true;
}
}
if (r.isType("authority") || !isHierarchyAutoComplete) {
out = doAuthorityAutocomplete(cache, storage, fieldName, request.getRequestArgument(AUTO_COMPLETE_QUERY_PARAM), request.getRequestArgument(CONSTRAIN_VOCAB_PARAM), request.getRequestArgument(PAGE_SIZE_PARAM), request.getRequestArgument(PAGE_NUM_PARAM));
} else if (isHierarchyAutoComplete) {
out = doRecordAutocomplete(cache, storage, fieldName, request.getRequestArgument(AUTO_COMPLETE_QUERY_PARAM), request.getRequestArgument(PAGE_SIZE_PARAM), request.getRequestArgument(PAGE_NUM_PARAM));
} else {
throw new ConfigException("WebAutoComplete called for record that does not support autocomplete!: " + r.getID());
}
request.sendJSONResponse(out);
} catch (JSONException e) {
throw new UIException("JSONException during autocompletion", e);
} catch (ExistException e) {
throw new UIException("ExistException during autocompletion", e);
} catch (UnimplementedException e) {
throw new UIException("UnimplementedException during autocompletion", e);
} catch (ConfigException e) {
throw new UIException("ConfigException during autocompletion", e);
} catch (UnderlyingStorageException x) {
throw new UIException("UnderlyingStorageException during autocompletion" + x.getLocalizedMessage(), x.getStatus(), x.getUrl(), x);
}
}
use of org.collectionspace.chain.csp.config.ConfigException in project application by collectionspace.
the class WebAutoComplete method doRecordAutocomplete.
/**
* Handles autocomplete for non-authority records. Simpler model that does not involve
* multiple namespaces (a.k.a., vocabs, a.k.a., Instances).
* @param cache
* @param storage
* @param fieldname Should generally only be one of broader* or narrower*
* @param start The partial string to match
* @param pageSize
* @param pageNum
* @return the JSON output payload of results.
* @throws JSONException
* @throws ExistException
* @throws UnimplementedException
* @throws UnderlyingStorageException
* @throws ConfigException
*/
private JSONArray doRecordAutocomplete(CSPRequestCache cache, Storage storage, String fieldname, String start, String pageSize, String pageNum) throws JSONException, ExistException, UnimplementedException, UnderlyingStorageException, ConfigException {
// FieldSet fs=r.getFieldFullList(fieldname); we do not really care, frankly
JSONArray out = new JSONArray();
JSONObject restriction = new JSONObject();
if (pageSize != null) {
restriction.put("pageSize", pageSize);
}
if (pageNum != null) {
restriction.put("pageNum", pageNum);
}
FieldSet dispNameFS = r.getDisplayNameField();
if (dispNameFS == null) {
throw new ConfigException("WebAutoComplete for record has no displayName configured: " + r.getID());
}
String displayNameFieldID = dispNameFS.getID();
// May be something other than display name
restriction.put(displayNameFieldID, start);
String path = r.getID();
JSONObject results = storage.getPathsJSON(path, restriction);
String[] paths = (String[]) results.get("listItems");
for (String csid : paths) {
// Appending the "list" to the path will glean the "list" marked fields, into a "summarylist"
JSONObject data = storage.retrieveJSON(path + "/" + csid + "/view/list", new JSONObject());
JSONObject entry = new JSONObject();
JSONObject summarylist = data.getJSONObject("summarylist");
String displayNameString = summarylist.getString(displayNameFieldID);
String refName = summarylist.getString("refName");
// Build a base refName without trailing displayName suffix
if (refName.endsWith("'" + displayNameString + "'"))
refName = refName.substring(0, refName.length() - (displayNameString.length() + 2));
entry.put("baseUrn", refName);
entry.put("csid", summarylist.getString("csid"));
entry.put("type", r.getWebURL());
// Standard temCompletion widget handles arrays of alternate terms, so
// we pass an array for consistency.
JSONArray displayNames = new JSONArray();
displayNames.put(displayNameString);
entry.put("displayNames", displayNames);
out.put(entry);
}
return out;
}
use of org.collectionspace.chain.csp.config.ConfigException in project application by collectionspace.
the class CSPManagerImpl method configure.
@Override
public void configure(InputSource in, EntityResolver er, boolean forXsdGeneration) throws CSPDependencyException {
RuleSetImpl rules = new RuleSetImpl();
for (Configurable config : config_csps) {
config.configure(rules);
}
if (forXsdGeneration == true) {
String msg = String.format("Config Generation: '%s' - ### Generating Service configuration from '%s'.", in.getPublicId(), in.getPublicId());
log.trace(msg);
}
try {
ConfigParser parser = new ConfigParser(rules, er);
parser.parse(in);
// Finish up all the config-related tasks
for (Configurable config : config_csps) {
config.config_finish();
}
// Run the post-config init tasks
for (Configurable config : config_csps) {
config.complete_init(this, forXsdGeneration);
}
} catch (ConfigException e) {
String msg = String.format("Config Generation: '%s' - Trouble parsing configuration files.", in.getPublicId());
// XXX
throw new CSPDependencyException(msg, e);
}
}
use of org.collectionspace.chain.csp.config.ConfigException in project application by collectionspace.
the class AssemblingContentHandler method apply_include.
private void apply_include(InputSource src, boolean strip) throws SAXException {
String errMsg = String.format("Config Generation: '%s' - Could not create inner parser.", getSrcFileName());
try {
SAXParser sp = factory.newSAXParser();
DefaultHandler inner = new AssemblingContentHandler(parser, up, false, strip, this);
sp.parse(src, inner);
} catch (ParserConfigurationException e) {
throw new SAXException(errMsg, e);
} catch (ConfigException e) {
throw new SAXException(errMsg, e);
} catch (IOException e) {
throw new SAXException(errMsg, e);
}
}
Aggregations