SEBSERV-170 fixed update page after import
This commit is contained in:
parent
89ebf4da4b
commit
5cb771c2c2
3 changed files with 125 additions and 122 deletions
|
@ -245,13 +245,6 @@ public class SEBExamConfigForm implements TemplateComposer {
|
||||||
.noEventPropagation()
|
.noEventPropagation()
|
||||||
.publishIf(() -> modifyGrant && isReadonly)
|
.publishIf(() -> modifyGrant && isReadonly)
|
||||||
|
|
||||||
// // TODO shall this got to settings form?
|
|
||||||
// .newAction(ActionDefinition.SEB_EXAM_CONFIG_IMPORT_TO_EXISTING_CONFIG)
|
|
||||||
// .withEntityKey(entityKey)
|
|
||||||
// .withExec(this.sebExamConfigImportPopup.importFunction(false))
|
|
||||||
// .noEventPropagation()
|
|
||||||
// .publishIf(() -> modifyGrant && isReadonly && !isAttachedToExam)
|
|
||||||
|
|
||||||
.newAction(ActionDefinition.SEB_EXAM_CONFIG_PROP_SAVE)
|
.newAction(ActionDefinition.SEB_EXAM_CONFIG_PROP_SAVE)
|
||||||
.withEntityKey(entityKey)
|
.withEntityKey(entityKey)
|
||||||
.withExec(formHandle::processFormSave)
|
.withExec(formHandle::processFormSave)
|
||||||
|
|
|
@ -104,133 +104,92 @@ public class SEBExamConfigImportPopup {
|
||||||
final Control fieldControl = form.getFieldInput(API.IMPORT_FILE_ATTR_NAME);
|
final Control fieldControl = form.getFieldInput(API.IMPORT_FILE_ATTR_NAME);
|
||||||
final PageContext context = formHandle.getContext();
|
final PageContext context = formHandle.getContext();
|
||||||
|
|
||||||
// Ad-hoc field validation
|
if (!(fieldControl instanceof FileUploadSelection)) {
|
||||||
if (newConfig) {
|
return false;
|
||||||
formHandle.process(name -> true, Form.FormFieldAccessor::resetError);
|
|
||||||
final String fieldValue = form.getFieldValue(Domain.CONFIGURATION_NODE.ATTR_NAME);
|
|
||||||
if (StringUtils.isBlank(fieldValue)) {
|
|
||||||
form.setFieldError(
|
|
||||||
Domain.CONFIGURATION_NODE.ATTR_NAME,
|
|
||||||
this.pageService
|
|
||||||
.getI18nSupport()
|
|
||||||
.getText(new LocTextKey("sebserver.form.validation.fieldError.notNull")));
|
|
||||||
return false;
|
|
||||||
} else if (fieldValue.length() < 3 || fieldValue.length() > 255) {
|
|
||||||
form.setFieldError(
|
|
||||||
Domain.CONFIGURATION_NODE.ATTR_NAME,
|
|
||||||
this.pageService
|
|
||||||
.getI18nSupport()
|
|
||||||
.getText(new LocTextKey("sebserver.form.validation.fieldError.size",
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
3,
|
|
||||||
255)));
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
// check if name already exists
|
|
||||||
try {
|
|
||||||
if (this.pageService.getRestService()
|
|
||||||
.getBuilder(GetExamConfigNodeNames.class)
|
|
||||||
.call()
|
|
||||||
.getOrThrow()
|
|
||||||
.stream()
|
|
||||||
.filter(n -> n.name.equals(fieldValue))
|
|
||||||
.findFirst()
|
|
||||||
.isPresent()) {
|
|
||||||
|
|
||||||
form.setFieldError(
|
|
||||||
Domain.CONFIGURATION_NODE.ATTR_NAME,
|
|
||||||
this.pageService
|
|
||||||
.getI18nSupport()
|
|
||||||
.getText(new LocTextKey(
|
|
||||||
"sebserver.form.validation.fieldError.name.notunique")));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} catch (final Exception e) {
|
|
||||||
log.error("Failed to verify unique name: {}", e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fieldControl instanceof FileUploadSelection) {
|
if (!checkInput(formHandle, newConfig, form)) {
|
||||||
final FileUploadSelection fileUpload = (FileUploadSelection) fieldControl;
|
return false;
|
||||||
final InputStream inputStream = fileUpload.getInputStream();
|
}
|
||||||
if (inputStream != null) {
|
|
||||||
final RestCall<Configuration>.RestCallBuilder restCall = (newConfig)
|
|
||||||
? this.pageService.getRestService()
|
|
||||||
.getBuilder(ImportNewExamConfig.class)
|
|
||||||
: this.pageService.getRestService()
|
|
||||||
.getBuilder(ImportExamConfigOnExistingConfig.class);
|
|
||||||
|
|
||||||
|
final FileUploadSelection fileUpload = (FileUploadSelection) fieldControl;
|
||||||
|
final InputStream inputStream = fileUpload.getInputStream();
|
||||||
|
if (inputStream != null) {
|
||||||
|
final RestCall<Configuration>.RestCallBuilder restCall = (newConfig)
|
||||||
|
? this.pageService.getRestService()
|
||||||
|
.getBuilder(ImportNewExamConfig.class)
|
||||||
|
: this.pageService.getRestService()
|
||||||
|
.getBuilder(ImportExamConfigOnExistingConfig.class);
|
||||||
|
|
||||||
|
restCall
|
||||||
|
.withHeader(
|
||||||
|
API.IMPORT_PASSWORD_ATTR_NAME,
|
||||||
|
form.getFieldValue(API.IMPORT_PASSWORD_ATTR_NAME))
|
||||||
|
.withBody(inputStream);
|
||||||
|
|
||||||
|
if (newConfig) {
|
||||||
restCall
|
restCall
|
||||||
.withHeader(
|
.withHeader(
|
||||||
API.IMPORT_PASSWORD_ATTR_NAME,
|
Domain.CONFIGURATION_NODE.ATTR_NAME,
|
||||||
form.getFieldValue(API.IMPORT_PASSWORD_ATTR_NAME))
|
form.getFieldValue(Domain.CONFIGURATION_NODE.ATTR_NAME))
|
||||||
.withBody(inputStream);
|
.withHeader(
|
||||||
|
Domain.CONFIGURATION_NODE.ATTR_DESCRIPTION,
|
||||||
|
form.getFieldValue(Domain.CONFIGURATION_NODE.ATTR_DESCRIPTION))
|
||||||
|
.withHeader(
|
||||||
|
Domain.CONFIGURATION_NODE.ATTR_TEMPLATE_ID,
|
||||||
|
form.getFieldValue(Domain.CONFIGURATION_NODE.ATTR_TEMPLATE_ID));
|
||||||
|
} else {
|
||||||
|
restCall.withURIVariable(API.PARAM_MODEL_ID, entityKey.modelId);
|
||||||
|
}
|
||||||
|
|
||||||
if (newConfig) {
|
final Result<Configuration> configuration = restCall
|
||||||
restCall
|
.call();
|
||||||
.withHeader(
|
|
||||||
Domain.CONFIGURATION_NODE.ATTR_NAME,
|
|
||||||
form.getFieldValue(Domain.CONFIGURATION_NODE.ATTR_NAME))
|
|
||||||
.withHeader(
|
|
||||||
Domain.CONFIGURATION_NODE.ATTR_DESCRIPTION,
|
|
||||||
form.getFieldValue(Domain.CONFIGURATION_NODE.ATTR_DESCRIPTION))
|
|
||||||
.withHeader(
|
|
||||||
Domain.CONFIGURATION_NODE.ATTR_TEMPLATE_ID,
|
|
||||||
form.getFieldValue(Domain.CONFIGURATION_NODE.ATTR_TEMPLATE_ID));
|
|
||||||
} else {
|
|
||||||
restCall.withURIVariable(API.PARAM_MODEL_ID, entityKey.modelId);
|
|
||||||
}
|
|
||||||
|
|
||||||
final Result<Configuration> configuration = restCall
|
if (!configuration.hasError()) {
|
||||||
.call();
|
context.publishInfo(SEBExamConfigForm.FORM_IMPORT_CONFIRM_TEXT_KEY);
|
||||||
|
final PageAction action = (newConfig)
|
||||||
if (!configuration.hasError()) {
|
? this.pageService.pageActionBuilder(context)
|
||||||
context.publishInfo(SEBExamConfigForm.FORM_IMPORT_CONFIRM_TEXT_KEY);
|
|
||||||
if (newConfig) {
|
|
||||||
|
|
||||||
final PageAction action = this.pageService.pageActionBuilder(context)
|
|
||||||
.newAction(ActionDefinition.SEB_EXAM_CONFIG_IMPORT_TO_NEW_CONFIG)
|
.newAction(ActionDefinition.SEB_EXAM_CONFIG_IMPORT_TO_NEW_CONFIG)
|
||||||
|
.create()
|
||||||
|
: this.pageService.pageActionBuilder(context)
|
||||||
|
.newAction(ActionDefinition.SEB_EXAM_CONFIG_MODIFY)
|
||||||
.create();
|
.create();
|
||||||
|
|
||||||
this.pageService.firePageEvent(
|
this.pageService.firePageEvent(
|
||||||
new ActionEvent(action),
|
new ActionEvent(action),
|
||||||
action.pageContext());
|
action.pageContext());
|
||||||
}
|
|
||||||
} else {
|
|
||||||
final Exception error = configuration.getError();
|
|
||||||
if (error instanceof RestCallError) {
|
|
||||||
((RestCallError) error)
|
|
||||||
.getErrorMessages()
|
|
||||||
.stream()
|
|
||||||
.findFirst()
|
|
||||||
.ifPresent(message -> {
|
|
||||||
if (APIMessage.ErrorMessage.MISSING_PASSWORD.isOf(message)) {
|
|
||||||
formHandle
|
|
||||||
.getContext()
|
|
||||||
.publishPageMessage(MISSING_PASSWORD);
|
|
||||||
} else {
|
|
||||||
formHandle
|
|
||||||
.getContext()
|
|
||||||
.notifyImportError(EntityType.CONFIGURATION_NODE, error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
formHandle.getContext().notifyError(
|
|
||||||
SEBExamConfigForm.FORM_TITLE,
|
|
||||||
configuration.getError());
|
|
||||||
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
} else {
|
} else {
|
||||||
formHandle.getContext().publishPageMessage(
|
final Exception error = configuration.getError();
|
||||||
new LocTextKey("sebserver.error.unexpected"),
|
if (error instanceof RestCallError) {
|
||||||
new LocTextKey("Please select a valid SEB Exam Configuration File"));
|
((RestCallError) error)
|
||||||
|
.getErrorMessages()
|
||||||
|
.stream()
|
||||||
|
.findFirst()
|
||||||
|
.ifPresent(message -> {
|
||||||
|
if (APIMessage.ErrorMessage.MISSING_PASSWORD.isOf(message)) {
|
||||||
|
formHandle
|
||||||
|
.getContext()
|
||||||
|
.publishPageMessage(MISSING_PASSWORD);
|
||||||
|
} else {
|
||||||
|
formHandle
|
||||||
|
.getContext()
|
||||||
|
.notifyImportError(EntityType.CONFIGURATION_NODE, error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
formHandle.getContext().notifyError(
|
||||||
|
SEBExamConfigForm.FORM_TITLE,
|
||||||
|
configuration.getError());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
formHandle.getContext().publishPageMessage(
|
||||||
|
new LocTextKey("sebserver.error.unexpected"),
|
||||||
|
new LocTextKey("Please select a valid SEB Exam Configuration File"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -240,6 +199,58 @@ public class SEBExamConfigImportPopup {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean checkInput(final FormHandle<ConfigurationNode> formHandle, final boolean newConfig,
|
||||||
|
final Form form) {
|
||||||
|
if (newConfig) {
|
||||||
|
formHandle.process(name -> true, Form.FormFieldAccessor::resetError);
|
||||||
|
final String fieldValue = form.getFieldValue(Domain.CONFIGURATION_NODE.ATTR_NAME);
|
||||||
|
if (StringUtils.isBlank(fieldValue)) {
|
||||||
|
form.setFieldError(
|
||||||
|
Domain.CONFIGURATION_NODE.ATTR_NAME,
|
||||||
|
this.pageService
|
||||||
|
.getI18nSupport()
|
||||||
|
.getText(new LocTextKey("sebserver.form.validation.fieldError.notNull")));
|
||||||
|
return false;
|
||||||
|
} else if (fieldValue.length() < 3 || fieldValue.length() > 255) {
|
||||||
|
form.setFieldError(
|
||||||
|
Domain.CONFIGURATION_NODE.ATTR_NAME,
|
||||||
|
this.pageService
|
||||||
|
.getI18nSupport()
|
||||||
|
.getText(new LocTextKey("sebserver.form.validation.fieldError.size",
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
3,
|
||||||
|
255)));
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
// check if name already exists
|
||||||
|
try {
|
||||||
|
if (this.pageService.getRestService()
|
||||||
|
.getBuilder(GetExamConfigNodeNames.class)
|
||||||
|
.call()
|
||||||
|
.getOrThrow()
|
||||||
|
.stream()
|
||||||
|
.filter(n -> n.name.equals(fieldValue))
|
||||||
|
.findFirst()
|
||||||
|
.isPresent()) {
|
||||||
|
|
||||||
|
form.setFieldError(
|
||||||
|
Domain.CONFIGURATION_NODE.ATTR_NAME,
|
||||||
|
this.pageService
|
||||||
|
.getI18nSupport()
|
||||||
|
.getText(new LocTextKey(
|
||||||
|
"sebserver.form.validation.fieldError.name.notunique")));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} catch (final Exception e) {
|
||||||
|
log.error("Failed to verify unique name: {}", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private final class ImportFormContext implements ModalInputDialogComposer<FormHandle<ConfigurationNode>> {
|
private final class ImportFormContext implements ModalInputDialogComposer<FormHandle<ConfigurationNode>> {
|
||||||
|
|
||||||
private final PageService pageService;
|
private final PageService pageService;
|
||||||
|
|
|
@ -255,7 +255,6 @@ public class SEBSettingsForm implements TemplateComposer {
|
||||||
.newAction(ActionDefinition.SEB_EXAM_CONFIG_IMPORT_TO_EXISTING_CONFIG)
|
.newAction(ActionDefinition.SEB_EXAM_CONFIG_IMPORT_TO_EXISTING_CONFIG)
|
||||||
.withEntityKey(entityKey)
|
.withEntityKey(entityKey)
|
||||||
.withExec(this.sebExamConfigImportPopup.importFunction(false))
|
.withExec(this.sebExamConfigImportPopup.importFunction(false))
|
||||||
.noEventPropagation()
|
|
||||||
.publishIf(() -> examConfigGrant.iw() && !readonly && !isAttachedToExam)
|
.publishIf(() -> examConfigGrant.iw() && !readonly && !isAttachedToExam)
|
||||||
|
|
||||||
.newAction(ActionDefinition.SEB_EXAM_CONFIG_VIEW_PROP)
|
.newAction(ActionDefinition.SEB_EXAM_CONFIG_VIEW_PROP)
|
||||||
|
|
Loading…
Reference in a new issue