List of usage examples for java.lang Exception getLocalizedMessage
public String getLocalizedMessage()
From source file:com.amalto.workbench.actions.XSDDeleteIdentityConstraintAction.java
public IStatus doAction() { try {// w w w .j av a 2 s. com // xsdIdenty is to support the multiple delete action on key press, // which each delete action on identity must be explicit passed a xsd key to // delete XSDIdentityConstraintDefinition constraint = xsdIdenty; XSDElementDeclaration decl = null; if (constraint != null) { decl = (XSDElementDeclaration) constraint.getContainer(); if (decl == null) return Status.CANCEL_STATUS; } if (decl == null) { IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection(); constraint = (XSDIdentityConstraintDefinition) selection.getFirstElement(); decl = (XSDElementDeclaration) constraint.getContainer(); } /* * REMOVE so that simple elements can be made if ( * (constraint.getIdentityConstraintCategory().equals(XSDIdentityConstraintCategory.UNIQUE_LITERAL)) && * (decl.getContainer().equals(decl.getSchema())) ) { MessageDialog.openError( * this.page.getSite().getShell(), "Error", "Entities must have an unique key" ); return; } */ decl.getIdentityConstraintDefinitions().remove(constraint); decl.updateElement(); xsdIdenty = null; page.refresh(); page.markDirty(); } catch (Exception e) { log.error(e.getMessage(), e); MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDDeleteXX_ErrorMsg, e.getLocalizedMessage())); return Status.CANCEL_STATUS; } return Status.OK_STATUS; }
From source file:es.urjc.mctwp.bbeans.research.image.DownloadBean.java
private void downloadImages(List<ImageData> images, ZipOutputStream zos, String path) { if (images != null && zos != null && !images.isEmpty()) { try {//from w ww.j av a 2s . co m for (ImageData imdt : images) { LoadImage cmd = (LoadImage) getCommand(LoadImage.class); cmd.setCollection(getSession().getTrial().getCollection()); cmd.setImageId(imdt.getImageId()); cmd = (LoadImage) runCommand(cmd); if (cmd != null && cmd.getResult() != null) addImageToZos(zos, cmd.getResult(), path); } } catch (Exception e) { setErrorMessage(e.getLocalizedMessage()); e.printStackTrace(); } } }
From source file:com.amalto.workbench.actions.XSDGetXPathAction.java
@Override public IStatus doAction() { try {/* w w w .j a v a 2 s .c o m*/ IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection(); XSDParticle particle = (XSDParticle) selection.getFirstElement(); XSDTerm term = particle.getTerm(); if (!(term instanceof XSDElementDeclaration)) return Status.CANCEL_STATUS; Clipboard clipboard = Util.getClipboard(); String path = ""; //$NON-NLS-1$ TreeItem item = page.getTreeViewer().getTree().getSelection()[0]; do { XSDConcreteComponent component = (XSDConcreteComponent) item.getData(); if (component instanceof XSDParticle) { if (((XSDParticle) component).getTerm() instanceof XSDElementDeclaration) path = "/" + ((XSDElementDeclaration) ((XSDParticle) component).getTerm()).getName() + path; //$NON-NLS-1$ } else if (component instanceof XSDElementDeclaration) { path = ((XSDElementDeclaration) component).getName() + path; } // System.out.println(" "+path+ " $$"+component.toString()+"$$"); item = item.getParentItem(); } while (item != null); xpath = path; clipboard.setContents(new Object[] { path }, new Transfer[] { TextTransfer.getInstance() }); } catch (Exception e) { log.error(e.getMessage(), e); MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDGetXPathAction_ErrorMsg, e.getLocalizedMessage())); return Status.CANCEL_STATUS; } return Status.OK_STATUS; }
From source file:com.amalto.workbench.editors.actions.EditItemAction.java
@Override public void run() { try {//from w ww . ja v a2 s .co m super.run(); IStructuredSelection selection = ((IStructuredSelection) viewer.getSelection()); if (selection.isEmpty()) { return; } WSRoutingOrderV2 routingOrder = (WSRoutingOrderV2) selection.getFirstElement(); StringWriter sw = new StringWriter(); Marshaller.marshal(routingOrder, sw); final DOMViewDialog d = new DOMViewDialog(shell, Util.parse(sw.toString())); d.addListener(new Listener() { public void handleEvent(Event event) { d.close(); }// handleEvent }); d.setBlockOnOpen(true); d.open(); } catch (Exception e) { log.error(e.getMessage(), e); MessageDialog.openError(shell, Messages._Error, Messages.bind( Messages.RoutingEngineV2BrowserMainPage_ErrorToViewRoutingOrder, e.getLocalizedMessage())); } }
From source file:net.bhira.sample.api.controller.CompanyController.java
/** * Fetch all the companies in the system. It will return a light weight version of * {@link net.bhira.sample.model.Company} model without the address and contactInfo objects. * /* w ww .j a v a 2s.c om*/ * @param response * the http response to which the results will be written. * @return an array of {@link net.bhira.sample.model.Company} instances as JSON. */ @RequestMapping(value = "/company", method = RequestMethod.GET) @ResponseBody public Callable<String> getAll(HttpServletResponse response) { return new Callable<String>() { public String call() throws Exception { String body = ""; try { LOG.debug("servicing GET company/"); List<Company> list = companyService.loadAll(); int count = (list == null) ? 0 : list.size(); LOG.debug("GET company/ count = {}", count); body = JsonUtil.createGson().toJson(list); } catch (Exception ex) { response.setStatus(HttpServletResponse.SC_FORBIDDEN); body = ex.getLocalizedMessage(); LOG.warn("Error loading companies. {}", body); LOG.debug("Load error stacktrace: ", ex); } return body; } }; }
From source file:org.openmrs.module.yank.web.controller.QueryController.java
@RequestMapping(method = RequestMethod.POST) public String yank(@RequestParam(value = "server", required = true) String server, @RequestParam(value = "username", required = true) String username, @RequestParam(value = "password", required = true) String password, @RequestParam(value = "datatype", required = true) String datatype, @RequestParam(value = "uuids") String uuids, @RequestParam(value = "file") MultipartFile file, WebRequest request) throws FileNotFoundException, UnsupportedEncodingException, IOException { YankService service = Context.getService(YankService.class); List<String> successes = new ArrayList<String>(); List<String> errors = new ArrayList<String>(); // build uuids from file if it was uploaded if (file != null) { String fileUuids = new String(file.getBytes()); if (!StringUtils.isBlank(fileUuids)) uuids = fileUuids;// www . j av a2 s . c om } if (StringUtils.isNotEmpty(uuids)) for (String uuid : uuids.split(",")) { // clean it up uuid = uuid.trim(); try { // look it up // TODO encrypt username and password here and decrypt in RestUtil String data = service.yankFromServer(server, username, password, datatype, uuid); if (StringUtils.isBlank(data)) throw new APIException("nothing retrieved from server"); // make a yank out of it Yank yank = new Yank(); yank.setDatatype(datatype); yank.setData(data); yank.setSummary(service.getSummaryForType(datatype, data)); service.saveYank(yank); successes.add("\"" + uuid + "\" successfully yanked."); } catch (Exception ex) { log.warn("error querying for uuid " + uuid, ex); errors.add("\"" + uuid + "\" could not be yanked [" + ex.getLocalizedMessage() + "]"); } } if (!successes.isEmpty()) request.setAttribute(WebConstants.OPENMRS_MSG_ATTR, renderMessage(successes, "Successfully yanked $count items."), WebRequest.SCOPE_SESSION); if (!errors.isEmpty()) request.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, renderMessage(errors, "Could not yank $count items. See log for details."), WebRequest.SCOPE_SESSION); return "redirect:process.form"; }
From source file:net.bhira.sample.api.controller.CompanyController.java
/** * Delete the instance of {@link net.bhira.sample.model.Company} represented by given companyId. * In case of an error return the error message. * // w w w .j a va 2 s. co m * @param companyId * the ID for {@link net.bhira.sample.model.Company}. * @param response * the http response to which the results will be written. * @return the error message, if save was not successful. */ @RequestMapping(value = "/company/{companyId}", method = RequestMethod.DELETE) @ResponseBody public Callable<String> deleteCompany(@PathVariable long companyId, HttpServletResponse response) { return new Callable<String>() { public String call() throws Exception { LOG.debug("servicing DELETE company/{}", companyId); String body = ""; try { boolean success = companyService.delete(companyId); LOG.debug("DELETE company/{} status = {}", companyId, success); if (!success) { response.setStatus(HttpServletResponse.SC_FORBIDDEN); } } catch (Exception ex) { response.setStatus(HttpServletResponse.SC_FORBIDDEN); body = ex.getLocalizedMessage(); LOG.warn("Error deleting company/{}. {}", companyId, body); LOG.debug("Delete error stacktrace: ", ex); } return body; } }; }
From source file:com.epam.dlab.core.parser.ConditionEvaluate.java
/** Instantiate the engine to evaluate condition. * @param columnNames the list of column names. * @param condition condition for filtering data. * @throws InitializationException/* w w w . ja va 2 s . c o m*/ */ public ConditionEvaluate(List<String> columnNames, String condition) throws InitializationException { //Replace : to . in column names List<String> colNames = new ArrayList<>(columnNames.size()); for (int i = 0; i < columnNames.size(); i++) { String name = columnNames.get(i); if (name.indexOf(':') > -1 && condition.indexOf(name) > -1) { String newName = StringUtils.replaceChars(name, ':', '.'); colNames.add(newName); condition = StringUtils.replace(condition, name, newName); } else { colNames.add(name); } } try { JexlEngine engine = new JexlBuilder().strict(true).silent(false).debug(true).create(); expression = (Script) engine.createExpression(condition); jexlContext = new MapContext(); } catch (Exception e) { throw new InitializationException( "Cannot initialize JEXL engine for condition: " + condition + ". " + e.getLocalizedMessage(), e); } // Create mapping of columns for evaluations. List<String> names = new ArrayList<>(); List<Integer> indexes = new ArrayList<>(); for (List<String> variableList : expression.getVariables()) { String columnName = StringUtils.join(variableList, '.'); int index = getColumnIndex(colNames, columnName); if (index == -1) { throw new InitializationException("Unknow source column name \"" + columnName + "\" in condition: " + expression.getSourceText() + ". Known column names: " + StringUtils.join(columnNames, ", ") + "."); } names.add(columnName); indexes.add(index); } this.columnNames = new String[names.size()]; this.columnIndexes = new int[indexes.size()]; for (int i = 0; i < indexes.size(); i++) { this.columnNames[i] = names.get(i); this.columnIndexes[i] = indexes.get(i); } }
From source file:net.bhira.sample.api.controller.DepartmentController.java
/** * Fetch all the departments for the given company ID. It will return a light weight version of * {@link net.bhira.sample.model.Department} model without the address and contactInfo objects. * //from w w w .j a v a2 s. c o m * @param companyId * the ID for {@link net.bhira.sample.model.Company}. * @param response * the http response to which the results will be written. * @return an array of {@link net.bhira.sample.model.Department} instances as JSON. */ @RequestMapping(value = "/department/company/{companyId}", method = RequestMethod.GET) @ResponseBody public Callable<String> getDepartmentsByCompany(@PathVariable long companyId, HttpServletResponse response) { return new Callable<String>() { public String call() throws Exception { String body = ""; try { LOG.debug("servicing GET department/company/{}", companyId); List<Department> list = departmentService.loadByCompany(companyId); int count = (list == null) ? 0 : list.size(); LOG.debug("GET department/company/{} count = {}", companyId, count); body = JsonUtil.createGson().toJson(list); } catch (Exception ex) { response.setStatus(HttpServletResponse.SC_FORBIDDEN); body = ex.getLocalizedMessage(); LOG.warn("Error loading department/company/{}. {}", companyId, body); LOG.debug("Load error stacktrace: ", ex); } return body; } }; }
From source file:com.amalto.workbench.actions.XSDDeleteElementAction.java
public IStatus doAction() { try {//from ww w.j a va2 s .com // xsdElem is to support the multiple delete action on key press, // which each delete action on element must be explicit passed a xsdElem to // delete XSDElementDeclaration decl = xsdElem; if (decl == null) { ISelection selection = page.getTreeViewer().getSelection(); decl = (XSDElementDeclaration) ((IStructuredSelection) selection).getFirstElement(); } ArrayList<Object> objList = new ArrayList<Object>(); IStructuredContentProvider provider = (IStructuredContentProvider) page.getTreeViewer() .getContentProvider(); Object[] all = Util.getAllObject(page.getSite(), objList, provider); Util.deleteReference(decl, all); // remove declaration schema.getContents().remove(decl); schema.update(); xsdElem = null; page.refresh(); page.markDirtyWithoutCommit(); } catch (Exception e) { log.error(e.getMessage(), e); MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDDeleteElementAction_ErrorMsg, e.getLocalizedMessage())); return Status.CANCEL_STATUS; } return Status.OK_STATUS; }