use of com.haulmont.cuba.gui.GuiDevelopmentException in project cuba by cuba-platform.
the class DefaultExceptionHandler method createErrorInfo.
protected ErrorInfo createErrorInfo(Throwable exception) {
UserSessionSource userSessionSource = AppBeans.get(UserSessionSource.NAME);
Security security = AppBeans.get(Security.NAME);
if (userSessionSource.getUserSession() == null || !security.isSpecificPermitted("cuba.gui.showExceptionDetails")) {
return new ErrorInfo(getMessage("errorPane.title"), getMessage("exceptionDialog.contactAdmin"), null, null, null, null, null);
}
Throwable rootCause = ExceptionUtils.getRootCause(exception);
if (rootCause == null)
rootCause = exception;
StringBuilder msg = new StringBuilder();
if (rootCause instanceof RemoteException) {
RemoteException re = (RemoteException) rootCause;
if (!re.getCauses().isEmpty()) {
RemoteException.Cause cause = re.getCauses().get(re.getCauses().size() - 1);
if (cause.getThrowable() != null)
rootCause = cause.getThrowable();
else {
// root cause is not supported by client
String className = cause.getClassName();
if (className != null && className.indexOf('.') > 0) {
className = className.substring(className.lastIndexOf('.') + 1);
}
msg.append(className).append(": ").append(cause.getMessage());
}
}
}
if (msg.length() == 0) {
msg.append(rootCause.getClass().getSimpleName());
if (!StringUtils.isBlank(rootCause.getMessage()))
msg.append(": ").append(rootCause.getMessage());
if (rootCause instanceof DevelopmentException) {
Map<String, Object> params = new LinkedHashMap<>();
if (rootCause instanceof GuiDevelopmentException) {
GuiDevelopmentException guiDevException = (GuiDevelopmentException) rootCause;
if (guiDevException.getFrameId() != null) {
params.put("Frame ID", guiDevException.getFrameId());
try {
WindowConfig windowConfig = AppBeans.get(WindowConfig.NAME);
params.put("XML descriptor", windowConfig.getWindowInfo(guiDevException.getFrameId()).getTemplate());
} catch (Exception e) {
params.put("XML descriptor", "not found for " + guiDevException.getFrameId());
}
}
}
params.putAll(((DevelopmentException) rootCause).getParams());
if (!params.isEmpty()) {
msg.append("\n\n");
for (Map.Entry<String, Object> entry : params.entrySet()) {
msg.append(entry.getKey()).append(": ").append(entry.getValue()).append("\n");
}
}
}
}
return new ErrorInfo(getMessage("errorPane.title"), msg.toString(), null, null, rootCause, null, null);
}
use of com.haulmont.cuba.gui.GuiDevelopmentException in project cuba by cuba-platform.
the class LayoutLoader method getLoader.
protected ComponentLoader getLoader(Element element) {
Class<? extends ComponentLoader> loaderClass = config.getLoader(element.getName());
if (loaderClass == null) {
throw new GuiDevelopmentException("Unknown component: " + element.getName(), context.getFullFrameId());
}
ComponentLoader loader;
try {
Constructor<? extends ComponentLoader> constructor = loaderClass.getConstructor();
loader = constructor.newInstance();
loader.setLocale(locale);
loader.setMessagesPack(messagesPack);
loader.setContext(context);
loader.setLayoutLoaderConfig(config);
loader.setFactory(factory);
loader.setElement(element);
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException | InstantiationException e) {
throw new GuiDevelopmentException("Loader instantiation error: " + e, context.getFullFrameId());
}
return loader;
}
use of com.haulmont.cuba.gui.GuiDevelopmentException in project cuba by cuba-platform.
the class AbstractComponentLoader method loadValidator.
@SuppressWarnings("unchecked")
protected Field.Validator loadValidator(Element validatorElement) {
final String className = validatorElement.attributeValue("class");
final String scriptPath = validatorElement.attributeValue("script");
final String script = validatorElement.getText();
Field.Validator validator = null;
if (StringUtils.isNotBlank(scriptPath) || StringUtils.isNotBlank(script)) {
validator = new ScriptValidator(validatorElement, getMessagesPack());
} else {
Class aClass = scripting.loadClass(className);
if (aClass == null)
throw new GuiDevelopmentException("Class " + className + " is not found", context.getFullFrameId());
if (!StringUtils.isBlank(getMessagesPack()))
try {
validator = (Field.Validator) ReflectionHelper.newInstance(aClass, validatorElement, getMessagesPack());
} catch (NoSuchMethodException e) {
//
}
if (validator == null) {
try {
validator = (Field.Validator) ReflectionHelper.newInstance(aClass, validatorElement);
} catch (NoSuchMethodException e) {
try {
validator = (Field.Validator) ReflectionHelper.newInstance(aClass);
} catch (NoSuchMethodException e1) {
//
}
}
}
if (validator == null) {
throw new GuiDevelopmentException("Validator class " + aClass + " has no supported constructors", context.getFullFrameId());
}
}
return validator;
}
use of com.haulmont.cuba.gui.GuiDevelopmentException in project cuba by cuba-platform.
the class AbstractComponentLoader method loadPickerDeclarativeAction.
protected Action loadPickerDeclarativeAction(Component.ActionsHolder actionsHolder, Element element) {
String id = element.attributeValue("id");
if (id == null) {
Element component = element;
for (int i = 0; i < 2; i++) {
if (component.getParent() != null) {
component = component.getParent();
} else {
throw new GuiDevelopmentException("No action ID provided for " + element.getName(), context.getFullFrameId());
}
}
throw new GuiDevelopmentException("No action ID provided for " + element.getName(), context.getFullFrameId(), "PickerField ID", component.attributeValue("id"));
}
if (StringUtils.isBlank(element.attributeValue("invoke"))) {
// Try to create a standard picker action
for (PickerField.ActionType type : PickerField.ActionType.values()) {
if (type.getId().equals(id)) {
Action action = type.createAction((PickerField) actionsHolder);
if (type != PickerField.ActionType.LOOKUP && type != PickerField.ActionType.OPEN) {
return action;
}
String openTypeString = element.attributeValue("openType");
if (openTypeString == null) {
return action;
}
WindowManager.OpenType openType;
try {
openType = WindowManager.OpenType.valueOf(openTypeString);
} catch (IllegalArgumentException e) {
throw new GuiDevelopmentException("Unknown open type: '" + openTypeString + "' for action: '" + id + "'", context.getFullFrameId());
}
if (action instanceof PickerField.LookupAction) {
((PickerField.LookupAction) action).setLookupScreenOpenType(openType);
} else if (action instanceof PickerField.OpenAction) {
((PickerField.OpenAction) action).setEditScreenOpenType(openType);
}
return action;
}
}
}
return loadDeclarativeActionDefault(actionsHolder, element);
}
use of com.haulmont.cuba.gui.GuiDevelopmentException in project cuba by cuba-platform.
the class AbstractResourceViewLoader method loadFileResource.
protected boolean loadFileResource(ResourceView resultComponent, Element element) {
Element fileResource = element.element("file");
if (fileResource == null)
return false;
String filePath = fileResource.attributeValue("path");
if (StringUtils.isEmpty(filePath)) {
throw new GuiDevelopmentException("No path provided for the FileResource", context.getFullFrameId());
}
File file = new File(filePath);
if (!file.exists()) {
String msg = String.format("Can't load FileResource. File with given path does not exists: %s", filePath);
throw new GuiDevelopmentException(msg, context.getFullFrameId());
}
FileResource resource = resultComponent.createResource(FileResource.class);
resource.setFile(file);
loadStreamSettings(resource, fileResource);
resultComponent.setSource(resource);
return true;
}
Aggregations