示例#1
0
 @Execute
 public HtmlResponse delete(final EditForm form) {
   verifyCrudMode(form.crudMode, CrudMode.DETAILS);
   validate(form, messages -> {}, () -> asDetailsHtml());
   verifyToken(() -> asDetailsHtml());
   final String id = form.id;
   fileConfigService
       .getFileConfig(id)
       .ifPresent(
           entity -> {
             try {
               fileConfigService.delete(entity);
               saveInfo(messages -> messages.addSuccessCrudDeleteCrudTable(GLOBAL));
             } catch (final Exception e) {
               throwValidationError(
                   messages ->
                       messages.addErrorsCrudFailedToDeleteCrudTable(
                           GLOBAL, buildThrowableMessage(e)),
                   () -> asEditHtml());
             }
           })
       .orElse(
           () -> {
             throwValidationError(
                 messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id),
                 () -> asDetailsHtml());
           });
   return redirect(getClass());
 }
示例#2
0
 public FileConfig getFileConfig() {
   if (fileConfig == null) {
     final FileConfigService fileConfigService =
         ComponentUtil.getComponent(FileConfigService.class);
     fileConfig = fileConfigService.getFileConfig(getFileConfigId()).get();
   }
   return fileConfig;
 }
示例#3
0
 // -----------------------------------------------------
 //                                         Actually Crud
 //                                         -------------
 @Execute
 public HtmlResponse create(final CreateForm form) {
   verifyCrudMode(form.crudMode, CrudMode.CREATE);
   validate(form, messages -> {}, () -> asEditHtml());
   verifyToken(() -> asEditHtml());
   getFileConfig(form)
       .ifPresent(
           entity -> {
             try {
               fileConfigService.store(entity);
               saveInfo(messages -> messages.addSuccessCrudCreateCrudTable(GLOBAL));
             } catch (final Exception e) {
               throwValidationError(
                   messages ->
                       messages.addErrorsCrudFailedToCreateCrudTable(
                           GLOBAL, buildThrowableMessage(e)),
                   () -> asEditHtml());
             }
           })
       .orElse(
           () -> {
             throwValidationError(
                 messages -> messages.addErrorsCrudFailedToCreateInstance(GLOBAL),
                 () -> asEditHtml());
           });
   return redirect(getClass());
 }
示例#4
0
  protected void searchPaging(final RenderData data, final SearchForm form) {
    RenderDataUtil.register(
        data, "fileConfigItems", fileConfigService.getFileConfigList(fileConfigPager)); // page navi

    // restore from pager
    copyBeanToBean(fileConfigPager, form, op -> op.include("id"));
  }
示例#5
0
 private HtmlResponse asListHtml() {
   return asHtml(path_AdminFileconfig_AdminFileconfigJsp)
       .renderWith(
           data -> {
             RenderDataUtil.register(
                 data,
                 "fileConfigItems",
                 fileConfigService.getFileConfigList(fileConfigPager)); // page navi
           })
       .useForm(
           SearchForm.class,
           setup -> {
             setup.setup(
                 form -> {
                   copyBeanToBean(fileConfigPager, form, op -> op.include("id"));
                 });
           });
 }
示例#6
0
 // -----------------------------------------------------
 //                                               Details
 //                                               -------
 @Execute
 public HtmlResponse details(final int crudMode, final String id) {
   verifyCrudMode(crudMode, CrudMode.DETAILS);
   saveToken();
   return asHtml(path_AdminFileconfig_AdminFileconfigDetailsJsp)
       .useForm(
           EditForm.class,
           op ->
               op.setup(
                   form -> {
                     fileConfigService
                         .getFileConfig(id)
                         .ifPresent(
                             entity -> {
                               copyBeanToBean(
                                   entity,
                                   form,
                                   copyOp -> {
                                     copyOp.excludeNull();
                                     copyOp.exclude(Constants.PERMISSIONS);
                                   });
                               final PermissionHelper permissionHelper =
                                   ComponentUtil.getPermissionHelper();
                               form.permissions =
                                   stream(entity.getPermissions())
                                       .get(
                                           stream ->
                                               stream
                                                   .map(s -> permissionHelper.decode(s))
                                                   .filter(StringUtil::isNotBlank)
                                                   .distinct()
                                                   .collect(Collectors.joining("\n")));
                               form.crudMode = crudMode;
                             })
                         .orElse(
                             () ->
                                 throwValidationError(
                                     messages ->
                                         messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id),
                                     () -> asListHtml()));
                   }))
       .renderWith(data -> registerRolesAndLabels(data));
 }
示例#7
0
 @Execute
 public HtmlResponse edit(final EditForm form) {
   validate(form, messages -> {}, () -> asListHtml());
   final PermissionHelper permissionHelper = ComponentUtil.getPermissionHelper();
   final String id = form.id;
   fileConfigService
       .getFileConfig(id)
       .ifPresent(
           entity -> {
             copyBeanToBean(
                 entity,
                 form,
                 copyOp -> {
                   copyOp.excludeNull();
                   copyOp.exclude(Constants.PERMISSIONS);
                 });
             form.permissions =
                 stream(entity.getPermissions())
                     .get(
                         stream ->
                             stream
                                 .map(permissionHelper::decode)
                                 .filter(StringUtil::isNotBlank)
                                 .distinct()
                                 .collect(Collectors.joining("\n")));
           })
       .orElse(
           () ->
               throwValidationError(
                   messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id),
                   () -> asListHtml()));
   saveToken();
   if (form.crudMode.intValue() == CrudMode.EDIT) {
     // back
     form.crudMode = CrudMode.DETAILS;
     return asDetailsHtml();
   } else {
     form.crudMode = CrudMode.EDIT;
     return asEditHtml();
   }
 }
示例#8
0
 // ===================================================================================
 //                                                                        Assist Logic
 //                                                                        ============
 private OptionalEntity<FileConfig> getEntity(
     final CreateForm form, final String username, final long currentTime) {
   switch (form.crudMode) {
     case CrudMode.CREATE:
       return OptionalEntity.of(new FileConfig())
           .map(
               entity -> {
                 entity.setCreatedBy(username);
                 entity.setCreatedTime(currentTime);
                 return entity;
               });
     case CrudMode.EDIT:
       if (form instanceof EditForm) {
         return fileConfigService.getFileConfig(((EditForm) form).id);
       }
       break;
     default:
       break;
   }
   return OptionalEntity.empty();
 }