Class FormItemsRestController

java.lang.Object
sk.iway.iwcm.system.datatable.DatatableRestControllerV2<FormItemEntity,Long>
sk.iway.iwcm.components.multistep_form.rest.FormItemsRestController

@RestController @RequestMapping("/admin/rest/form-items") @PreAuthorize("@WebjetSecurityService.hasPermission(\'cmp_form\')") public class FormItemsRestController extends DatatableRestControllerV2<FormItemEntity,Long>
Manages multistep form items through the administration DataTable.

The controller scopes records to a form, step, and domain, prepares editor options and previews, validates field dependencies, and keeps the generated form pattern synchronized after changes.

  • Constructor Details

  • Method Details

    • getAllItems

      public org.springframework.data.domain.Page<FormItemEntity> getAllItems(org.springframework.data.domain.Pageable pageable)
      Loads form items and enriches the page with row styling and editor options.
      Overrides:
      getAllItems in class DatatableRestControllerV2<FormItemEntity,Long>
      Parameters:
      pageable - requested page and sorting information
      Returns:
      page of form items prepared for the administration DataTable
    • addSpecSearch

      public void addSpecSearch(Map<String,String> params, List<jakarta.persistence.criteria.Predicate> predicates, jakarta.persistence.criteria.Root<FormItemEntity> root, jakarta.persistence.criteria.CriteriaBuilder builder)
      Restricts table search to the requested form and, when supplied, its step.
      Overrides:
      addSpecSearch in class DatatableRestControllerV2<FormItemEntity,Long>
      Parameters:
      params - submitted search parameters
      predicates - predicates to extend with form-specific constraints
      root - form item query root
      builder - criteria builder used to create predicates
    • addSpecSort

      public org.springframework.data.domain.Pageable addSpecSort(Map<String,String> params, org.springframework.data.domain.Pageable pageable)
      Applies the fixed step and item-priority ordering required by the form editor.
      Overrides:
      addSpecSort in class DatatableRestControllerV2<FormItemEntity,Long>
      Parameters:
      params - request parameters from which any client-provided sort is removed
      pageable - requested paging information
      Returns:
      paging information ordered by step and item priority
    • validateEditor

      public void validateEditor(jakarta.servlet.http.HttpServletRequest request, DatatableRequest<Long,FormItemEntity> target, Identity user, org.springframework.validation.Errors errors, Long id, FormItemEntity entity)
      Validates form identity, row-view compatibility, and field condition dependencies.

      Chart-statistics edits bypass these form-item checks because they only update reporting options on an existing field.

      Overrides:
      validateEditor in class DatatableRestControllerV2<FormItemEntity,Long>
      Parameters:
      request - current HTTP request
      target - submitted DataTable request, including the editor action
      user - authenticated user performing the operation
      errors - validation result to which inherited checks may add errors
      id - identifier of the edited item
      entity - submitted form item
    • getOneItem

      public FormItemEntity getOneItem(long id)
      Loads an item for editing or creates an editor model with context-specific defaults.

      Chart-statistics requests resolve the field identified by the chart context; an ID of -1 creates a new item for the requested form and step.

      Overrides:
      getOneItem in class DatatableRestControllerV2<FormItemEntity,Long>
      Parameters:
      id - item identifier, or -1 when preparing a new item
      Returns:
      form item prepared for the editor
    • insertItem

      public FormItemEntity insertItem(FormItemEntity entity)
      Inserts a form item or updates only reporting options in chart-statistics mode.
      Overrides:
      insertItem in class DatatableRestControllerV2<FormItemEntity,Long>
      Parameters:
      entity - submitted form item
      Returns:
      persisted form item, or null when chart-statistics mode receives no entity
    • beforeSave

      public void beforeSave(FormItemEntity entity)
      Normalizes a form item before persistence.

      The hook removes unsupported values, enforces CAPTCHA requirements, serializes regular-expression selections, assigns a valid item identifier, and prevents duplicate sort priorities within a step.

      Overrides:
      beforeSave in class DatatableRestControllerV2<FormItemEntity,Long>
      Parameters:
      entity - form item to normalize
    • checkItemPerms

      public boolean checkItemPerms(FormItemEntity entity, Long id)
      Verifies that an item belongs to an accessible form, valid step, and current domain.
      Overrides:
      checkItemPerms in class DatatableRestControllerV2<FormItemEntity,Long>
      Parameters:
      entity - submitted form item
      id - persisted item identifier, or null or a non-positive value for a new item
      Returns:
      true when the current user may access the item
    • afterSave

      public void afterSave(FormItemEntity entity, FormItemEntity saved)
      Clears cached validation fields and regenerates the form pattern after a standard item save.
      Overrides:
      afterSave in class DatatableRestControllerV2<FormItemEntity,Long>
      Parameters:
      entity - submitted form item
      saved - persisted form item
    • beforeDelete

      public boolean beforeDelete(FormItemEntity entity)
      Prevents deletion of a field referenced by another field condition.
      Overrides:
      beforeDelete in class DatatableRestControllerV2<FormItemEntity,Long>
      Parameters:
      entity - form item requested for deletion
      Returns:
      result of the inherited pre-delete hook when no dependency blocks deletion
    • afterDelete

      public void afterDelete(FormItemEntity entity, long id)
      Clears cached validation fields and regenerates the form pattern after an item is deleted.
      Overrides:
      afterDelete in class DatatableRestControllerV2<FormItemEntity,Long>
      Parameters:
      entity - deleted form item
      id - identifier of the deleted item
    • rowReorder

      @PostMapping(value="/row-reorder", consumes="application/json") public org.springframework.http.ResponseEntity<Boolean> rowReorder(jakarta.servlet.http.HttpServletRequest request, @RequestBody RowReorderDto rowReorderDto)
      Clears cached field ordering after a successful row reorder, which bypasses the save hooks.
      Overrides:
      rowReorder in class DatatableRestControllerV2<FormItemEntity,Long>
      Parameters:
      request - request identifying the form and step
      rowReorderDto - requested item order
      Returns:
      result of the data-table reorder operation
    • processFromEntity

      public FormItemEntity processFromEntity(FormItemEntity entity, ProcessItemAction action)
      Prepares persisted values and transient editor fields for a DataTable response.
      Overrides:
      processFromEntity in class DatatableRestControllerV2<FormItemEntity,Long>
      Parameters:
      entity - form item returned from persistence
      action - operation for which the entity is being prepared
      Returns:
      the enriched form item
    • processToEntity

      public FormItemEntity processToEntity(FormItemEntity entity, ProcessItemAction action)
      Maps transient editor values to persistent fields and clears incompatible settings.
      Overrides:
      processToEntity in class DatatableRestControllerV2<FormItemEntity,Long>
      Parameters:
      entity - submitted form item
      action - operation for which the entity is being prepared
      Returns:
      normalized form item ready for persistence
    • checkRowReorderScope

      protected boolean checkRowReorderScope(jakarta.servlet.http.HttpServletRequest request, List<FormItemEntity> entities)
      Verifies that every reordered item belongs to the requested form, step, and domain.
      Overrides:
      checkRowReorderScope in class DatatableRestControllerV2<FormItemEntity,Long>
      Parameters:
      request - current HTTP request containing the form and step scope
      entities - complete batch of form items requested for reordering
      Returns:
      true when the batch is within an accessible and valid step
    • getDefaultRegex

      @GetMapping("/default-regex") public List<Long> getDefaultRegex(@RequestParam("fieldType") String fieldType)
      Resolves default regular-expression validators from a field template's input classes.
      Parameters:
      fieldType - form field type whose template is inspected
      Returns:
      identifiers of matching regular-expression validators, or an empty list when none apply