use of com.vaadin.v7.data.fieldgroup.FieldGroup.CommitException in project SORMAS-Project by hzi-braunschweig.
the class CommitDiscardWrapperComponent method doCommit.
private void doCommit() throws InvalidValueException, SourceException, CommitRuntimeException {
if (fieldGroups != null) {
if (fieldGroups.size() > 1) {
List<InvalidValueException> invalidValueExceptions = fieldGroups.stream().filter(fieldGroup -> !fieldGroup.isValid()).map(fieldGroup -> {
try {
// all invalid fieldGroups are committed to fetch the CommitExceptions
fieldGroup.commit();
} catch (CommitException e) {
return e;
}
// when the fieldGroup did not throw a CommitException, it is invalid and committed
throw new IllegalStateException();
}).map(e -> {
// keep invalid value exceptions, throw the rest
Throwable c = e.getCause();
if (c instanceof InvalidValueException) {
return (InvalidValueException) c;
} else if (c instanceof SourceException) {
throw (SourceException) c;
} else {
throw new CommitRuntimeException(e);
}
}).collect(Collectors.toList());
if (invalidValueExceptions.isEmpty()) {
// NOOP
} else if (invalidValueExceptions.size() == 1) {
throw invalidValueExceptions.get(0);
} else {
throw new InvalidValueException(null, invalidValueExceptions.stream().map(InvalidValueException::getCauses).flatMap(Arrays::stream).toArray(InvalidValueException[]::new));
}
}
try {
for (FieldGroup fieldGroup : fieldGroups) {
fieldGroup.commit();
}
} catch (CommitException e) {
Throwable c = e.getCause();
if (c instanceof InvalidValueException) {
throw (InvalidValueException) c;
} else if (c instanceof SourceException) {
throw (SourceException) c;
} else {
throw new CommitRuntimeException(e);
}
}
} else if (wrappedComponent instanceof Buffered) {
((Buffered) wrappedComponent).commit();
} else {
// NOOP
}
dirty = false;
onCommit();
commited = true;
onDone();
}
use of com.vaadin.v7.data.fieldgroup.FieldGroup.CommitException in project opencms-core by alkacon.
the class CmsEditModuleForm method updateModule.
/**
* Writes the form data back to the module.<p>
*/
public void updateModule() {
try {
m_fieldGroup.commit();
// validate 'dynamic' tabs here
TreeMap<String, String> params = Maps.newTreeMap();
for (I_CmsEditableGroupRow row : m_parameterGroup.getRows()) {
TextField paramField = (TextField) (row.getComponent());
String paramStr = paramField.getValue();
int eqPos = paramStr.indexOf("=");
if (eqPos >= 0) {
String key = paramStr.substring(0, eqPos);
key = key.trim();
String value = paramStr.substring(eqPos + 1);
value = value.trim();
if (!CmsStringUtil.isEmpty(key)) {
params.put(key, value);
}
}
}
m_module.setParameters(params);
List<CmsExportPoint> exportPoints = Lists.newArrayList();
for (I_CmsEditableGroupRow row : m_exportPointGroup.getRows()) {
CmsExportPointWidget widget = (CmsExportPointWidget) (row.getComponent());
String source = widget.getUri().trim();
String target = widget.getDestination().trim();
if (CmsStringUtil.isEmpty(source) || CmsStringUtil.isEmpty(target)) {
continue;
}
CmsExportPoint point = new CmsExportPoint(source, target);
exportPoints.add(point);
}
m_module.setExportPoints(exportPoints);
List<CmsModuleDependency> dependencies = Lists.newArrayList();
for (CmsModuleDependencyWidget widget : getFormRowChildren(m_dependencies, CmsModuleDependencyWidget.class)) {
String moduleName = widget.getModuleName();
String moduleVersion = widget.getModuleVersion();
try {
CmsModuleDependency dep = new CmsModuleDependency(moduleName, new CmsModuleVersion(moduleVersion));
dependencies.add(dep);
} catch (Exception e) {
LOG.debug(e.getLocalizedMessage(), e);
}
}
m_module.setDependencies(dependencies);
List<String> moduleResources = Lists.newArrayList();
for (I_CmsEditableGroupRow row : m_moduleResourcesGroup.getRows()) {
CmsModuleResourceSelectField field = (CmsModuleResourceSelectField) (row.getComponent());
String moduleResource = field.getValue().trim();
if (!moduleResource.isEmpty()) {
moduleResources.add(moduleResource);
}
}
m_module.setResources(moduleResources);
List<String> excludedResources = Lists.newArrayList();
for (I_CmsEditableGroupRow row : m_excludedResourcesGroup.getRows()) {
CmsModuleResourceSelectField field = (CmsModuleResourceSelectField) (row.getComponent());
String moduleResource = field.getValue().trim();
if (!moduleResource.isEmpty()) {
excludedResources.add(moduleResource);
}
}
m_module.setExcludeResources(excludedResources);
if (!m_oldModuleInstance.isAutoIncrement() && m_module.isAutoIncrement()) {
m_module.setCheckpointTime(System.currentTimeMillis());
}
CmsObject cms = A_CmsUI.getCmsObject();
if (m_new) {
createModuleFolders(cms, m_module);
OpenCms.getModuleManager().addModule(cms, m_module);
} else {
OpenCms.getModuleManager().updateModule(cms, m_module);
}
CmsVaadinUtils.getWindow(this).close();
m_updateCallback.run();
} catch (CommitException e) {
if (e.getCause() instanceof FieldGroup.FieldGroupInvalidValueException) {
int minTabIdx = 999;
for (Field<?> field : e.getInvalidFields().keySet()) {
int tabIdx = getTabIndex(field);
if (tabIdx != -1) {
minTabIdx = Math.min(tabIdx, minTabIdx);
}
}
m_tabs.setSelectedTab(minTabIdx);
} else {
CmsErrorDialog.showErrorDialog(e);
}
return;
} catch (Exception e) {
CmsErrorDialog.showErrorDialog(e);
}
}
use of com.vaadin.v7.data.fieldgroup.FieldGroup.CommitException in project opencms-core by alkacon.
the class CmsUserDataFormLayout method submit.
/**
* Store fields to given user.<p>
*
* @param user User to write information to
* @param cms CmsObject
* @param afterWrite runnable which gets called after writing user
* @param force force write even if data are not valid
*/
public void submit(CmsUser user, CmsObject cms, Runnable afterWrite, boolean force) {
try {
if (isValid() | force) {
if (force) {
removeValidators();
}
m_binder.commit();
PropertyUtilsBean propUtils = new PropertyUtilsBean();
for (CmsAccountInfo info : OpenCms.getWorkplaceManager().getAccountInfos()) {
boolean editable = (m_editLevel == EditLevel.all) || ((m_editLevel == EditLevel.configured) && info.isEditable());
if (editable) {
if (info.isAdditionalInfo()) {
user.setAdditionalInfo(info.getAddInfoKey(), m_infos.getItemProperty(info).getValue());
} else {
if (!CmsStringUtil.isEmptyOrWhitespaceOnly((String) m_infos.getItemProperty(info).getValue())) {
propUtils.setProperty(user, info.getField().name(), m_infos.getItemProperty(info).getValue());
}
}
}
}
cms.writeUser(user);
afterWrite.run();
}
} catch (CmsException | CommitException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
LOG.error("Unable to commit changes to user..", e);
}
}
Aggregations