use of org.collectionspace.csp.api.ui.UIException in project application by collectionspace.
the class RelateRead method relate_get.
private void relate_get(Storage storage, UIRequest request, String path) throws UIException {
try {
JSONObject relation = convertPayload(storage, storage.retrieveJSON("/relations/" + searchPath + "/" + path, new JSONObject()), path);
request.sendJSONResponse(relation);
} catch (ExistException e) {
throw new UIException("JSON Not found ", e);
} catch (UnimplementedException e) {
throw new UIException("Unimplemented", e);
} catch (UnderlyingStorageException x) {
UIException uiexception = new UIException(x.getMessage(), x.getStatus(), x.getUrl(), x);
request.sendJSONResponse(uiexception.getJSON());
} catch (JSONException e) {
throw new UIException("Could not build JSON ", e);
}
}
use of org.collectionspace.csp.api.ui.UIException in project application by collectionspace.
the class WebUI method serviceRequest.
@Override
public void serviceRequest(UIRequest ui) throws UIException, UnauthorizedException {
CSPRequestCache cache = new RequestCache();
String[] path = ui.getPrincipalPath();
Request r = new Request(xxx_storage, cache, ui);
String test = ui.getRequestedOperation().toString();
log.debug("ServiceRequest path: " + StringUtils.join(path, "/"));
log.debug(test);
try {
if (tries.get(ui.getRequestedOperation()).call(path, r))
return;
} catch (UIException e) {
throw e;
} catch (UnauthorizedException ue) {
throw ue;
} catch (Exception e) {
log.error("Error in WebUI.serviceRequest", e);
log.error(String.format("Request body= %s", ui.getBody()));
throw new UIException("Error in read", e);
}
throw new UIException("path not used");
}
use of org.collectionspace.csp.api.ui.UIException in project application by collectionspace.
the class ServicesStorageGenerator method initializeAuthorities.
private void initializeAuthorities(CSPManager cspManager, Spec spec) {
AdminData ad = spec.getAdminData();
String adminUsername = ad.getAuthUser();
String adminPass = ad.getAuthPass();
// request.getSession().setValue(UISession.USERID,ad.getAuthUser());
// request.getSession().setValue(UISession.PASSWORD,ad.getAuthPass());
CSPRequestCredentials creds = this.createCredentials();
creds.setCredential(CRED_USERID, spec.getAdminData().getAuthUser());
creds.setCredential(CRED_PASSWORD, spec.getAdminData().getAuthPass());
WebReset webReset = new WebReset(false, false);
webReset.configure((WebUI) cspManager.getUI(""), spec);
try {
webReset.run(getStorage(creds, new RequestCache()), null, new String[0], false);
} catch (UIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of org.collectionspace.csp.api.ui.UIException in project application by collectionspace.
the class AuthoritiesVocabulariesInitialize method initializeVocab.
private void initializeVocab(Storage storage, UIRequest request, String path) throws UIException {
try {
if (fInstance == null) {
// For now simply loop through all the instances one after the other.
for (Instance instance : r.getAllInstances()) {
log.info(instance.getID());
// does instance exist?
if (createIfMissingAuthority(storage, null, this.r, instance) == -1) {
log.warn(String.format("The currently authenticated user does not have sufficient permission to determine if the '%s' authority/term-list is properly initialized.", instance.getID()));
}
resetvocabdata(storage, request, instance);
}
} else {
log.info(fInstance.getID());
resetvocabdata(storage, request, this.fInstance);
}
} catch (JSONException e) {
throw new UIException("Cannot generate JSON", e);
} catch (ExistException e) {
throw new UIException("Exist exception", e);
} catch (UnimplementedException e) {
throw new UIException("Unimplemented exception", e);
} catch (UnderlyingStorageException x) {
UIException uiexception = new UIException(x.getMessage(), x.getStatus(), x.getUrl(), x);
request.sendJSONResponse(uiexception.getJSON());
}
}
use of org.collectionspace.csp.api.ui.UIException in project application by collectionspace.
the class AuthoritiesVocabulariesInitialize method resetvocabdata.
private void resetvocabdata(Storage storage, UIRequest request, Instance instance) throws UIException, ExistException, UnimplementedException, UnderlyingStorageException, JSONException {
StringBuffer tty = new StringBuffer();
tty.append("Initializing Vocab " + instance.getID() + '\n');
// Where do we get the list from?
// from Spec
Option[] allOpts = instance.getAllOptions();
// but first check: do we have a path?
Set<String> args = request.getAllRequestArgument();
if (args.contains("datapath")) {
tty.append("Using Datapath \n");
// remove all opts from instance as we have a path
if (allOpts != null && allOpts.length > 0) {
tty.append("Removing all opts from instance as we have a path\n");
for (Option opt : allOpts) {
String name = opt.getName();
String shortIdentifier = opt.getID();
String sample = opt.getSample();
Boolean dfault = opt.isDefault();
instance.deleteOption(shortIdentifier, name, sample, dfault);
}
}
// add from path
String value = request.getRequestArgument("datapath");
// log.info("getting data from path: "+value);
try {
tty.append("Getting data from path: " + value + '\n');
String names = getResource(value);
for (String line : names.split("\n")) {
line = line.trim();
String[] bits = line.split("\\|");
if (bits.length > 1) {
instance.addOption(bits[0], bits[1], null, false);
} else {
instance.addOption(null, line, null, false);
}
}
} catch (IOException e) {
throw new UIException("IOException", e);
}
allOpts = instance.getAllOptions();
}
fillVocab(storage, r, instance, tty, allOpts, this.append);
if (this.modifyResponse == true) {
TTYOutputter ttyOut = request.getTTYOutputter();
ttyOut.line(tty.toString());
}
}
Aggregations