Interface FormItemsRepository

All Superinterfaces:
org.springframework.data.repository.CrudRepository<FormItemEntity,Long>, DomainIdRepository<FormItemEntity,Long>, org.springframework.data.jpa.repository.JpaRepository<FormItemEntity,Long>, org.springframework.data.jpa.repository.JpaSpecificationExecutor<FormItemEntity>, org.springframework.data.repository.ListCrudRepository<FormItemEntity,Long>, org.springframework.data.repository.ListPagingAndSortingRepository<FormItemEntity,Long>, org.springframework.data.repository.PagingAndSortingRepository<FormItemEntity,Long>, org.springframework.data.repository.query.QueryByExampleExecutor<FormItemEntity>, org.springframework.data.repository.Repository<FormItemEntity,Long>

@Repository public interface FormItemsRepository extends DomainIdRepository<FormItemEntity,Long>
Persists multistep form items and provides queries for editing, validation, duplication, and validation-error statistics within a domain.
  • Method Details

    • deleteAllByStepIdAndDomainId

      @Transactional @Modifying void deleteAllByStepIdAndDomainId(Long stepId, Integer domainId)
    • getAllStepItems

      @Query("SELECT fie FROM FormItemEntity fie WHERE fie.stepId = :stepId AND fie.domainId = :domainId ORDER BY fie.sortPriority ASC") List<FormItemEntity> getAllStepItems(@Param("stepId") Long stepId, @Param("domainId") Integer domainId)
      Loads all items of a step in their configured display order.
      Parameters:
      stepId - step identifier
      domainId - domain owning the items
      Returns:
      items ordered by ascending sort priority, including layout items and radio options
    • getItemFormIds

      @Query("SELECT fie.itemFormId FROM FormItemEntity fie WHERE fie.formName = :formName AND fie.domainId = :domainId") List<String> getItemFormIds(@Param("formName") String formName, @Param("domainId") Integer domainId)
      Loads the logical field identifiers used to detect identifier collisions in a form.
      Parameters:
      formName - logical form name
      domainId - domain owning the form
      Returns:
      identifiers across all field types and steps, including duplicate radio identifiers
    • countItemsThatHasType

      @Query("SELECT count(fie.id) FROM FormItemEntity fie WHERE fie.formName = :formName AND fie.domainId = :domainId AND fie.fieldType IN :fieldTypes") int countItemsThatHasType(@Param("formName") String formName, @Param("domainId") Integer domainId, @Param("fieldTypes") List<String> fieldTypes)
      Counts items whose configured type matches any of the supplied types.
      Parameters:
      formName - logical form name
      domainId - domain owning the form
      fieldTypes - field types to include in the count
      Returns:
      number of matching item entities across the form
    • deleteAllByFormNameAndStepIdAndDomainId

      @Transactional @Modifying void deleteAllByFormNameAndStepIdAndDomainId(String formName, Long stepId, Integer domainId)
    • deleteAllByFormNameAndDomainId

      @Transactional @Modifying void deleteAllByFormNameAndDomainId(String formName, Integer domainId)
    • findItemsToDuplicate

      @Query("SELECT fie FROM FormItemEntity fie WHERE fie.formName = :formName AND fie.stepId = :stepId AND fie.domainId = :domainId") List<FormItemEntity> findItemsToDuplicate(@Param("formName") String formName, @Param("stepId") Long stepId, @Param("domainId") Integer domainId)
      Loads the source items to copy when duplicating a form step.
      Parameters:
      formName - logical form name
      stepId - source step identifier
      domainId - domain owning the form
      Returns:
      existing source entities; no copies are created by this query
    • findAllByFormNameAndDomainId

      List<FormItemEntity> findAllByFormNameAndDomainId(String formName, Integer domainId)
    • findAllForValidation

      @Query("SELECT fie FROM FormItemEntity fie, FormStepEntity step WHERE fie.formName = :formName AND fie.domainId = :domainId AND fie.stepId = step.id AND step.formName = :formName AND step.domainId = :domainId ORDER BY step.sortPriority ASC, fie.sortPriority ASC") List<FormItemEntity> findAllForValidation(@Param("formName") String formName, @Param("domainId") Integer domainId)
      Loads items whose steps belong to the same form and domain, in form display order.
      Parameters:
      formName - logical form name
      domainId - domain owning both the items and their steps
      Returns:
      all matching items ordered by step and item sort priority, including individual radio options
    • findFirstByFormNameAndItemFormIdAndDomainIdOrderBySortPriorityAsc

      FormItemEntity findFirstByFormNameAndItemFormIdAndDomainIdOrderBySortPriorityAsc(String formName, String itemFormId, Integer domainId)
      Resolves the first item for a logical field, which can be shared by several radio options.
      Parameters:
      formName - logical form name
      itemFormId - logical field identifier
      domainId - domain owning the form
      Returns:
      matching item with the lowest sort priority, or null when none exists
    • incrementErrorCountByItemFormIds

      @Transactional @Modifying @Query("UPDATE FormItemEntity fie SET fie.errorCount = COALESCE(fie.errorCount, 0) + 1 WHERE fie.formName = :formName AND fie.domainId = :domainId AND fie.itemFormId IN :itemFormIds") int incrementErrorCountByItemFormIds(@Param("formName") String formName, @Param("domainId") Integer domainId, @Param("itemFormIds") List<String> itemFormIds)
      Increments the validation-error counter of every item matching the supplied field identifiers. A missing counter is treated as zero; radio options sharing an identifier are all updated.
      Parameters:
      formName - logical form name
      domainId - domain owning the form
      itemFormIds - logical identifiers of fields with validation errors
      Returns:
      number of item entities updated
    • countByFormNameAndStepIdAndSortPriorityAndIdNot

      Integer countByFormNameAndStepIdAndSortPriorityAndIdNot(String formName, Long stepId, Integer sortPriority, Integer id)
    • getMaxSortPriority

      @Query("SELECT COALESCE(MAX(fie.sortPriority), 0) FROM FormItemEntity fie WHERE fie.formName = :formName AND fie.stepId = :stepId AND fie.domainId = :domainId") Integer getMaxSortPriority(@Param("formName") String formName, @Param("stepId") Long stepId, @Param("domainId") Integer domainId)
      Returns the last item position in a step, including items hidden by administration filters.
    • findAllByFormNameAndStepIdInAndDomainId

      List<FormItemEntity> findAllByFormNameAndStepIdInAndDomainId(String formName, List<Long> stepIds, Integer domainId)
    • countItemsByIdAndItemFormId

      @Query("SELECT COUNT(fie.id) FROM FormItemEntity fie WHERE fie.formName = :formName AND fie.id = :id AND fie.itemFormId = :itemFormId AND fie.domainId = :domainId") Optional<Integer> countItemsByIdAndItemFormId(@Param("formName") String formName, @Param("id") Long id, @Param("itemFormId") String itemFormId, @Param("domainId") Integer domainId)
      Checks whether an item has the requested logical identifier and belongs to the form and domain.
      Parameters:
      formName - logical form name
      id - item entity identifier
      itemFormId - expected logical field identifier
      domainId - domain owning the form
      Returns:
      count wrapped in an optional: one for a match, zero otherwise
    • findAllByFormNameAndIdInAndDomainId

      List<FormItemEntity> findAllByFormNameAndIdInAndDomainId(String formName, List<Long> ids, Integer domainId)