Skip to content
This repository has been archived by the owner on Mar 25, 2022. It is now read-only.
/ form-field-mapper Public archive

Project for mapping java field values into FirstSpirit Fields via annotations and vise versa.

License

Notifications You must be signed in to change notification settings

diva-e/form-field-mapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Description

This is a FirstSpirit form field mapper that transfer data from a java class via annotations to a form field and vise versa.

Features

  • Map different kind of java types from and to java class via annotations
    • String <-> String
    • Date <-> Date
    • Boolean <-> Boolean
    • Number<-> Number
    • String (HTML) <-> DomElement
    • Collection <-> FormDataList (inline, database)
    • String <-> Option
    • Entity (native, database) <-> Option
    • Collection <-> Collection
    • Collection ((native, database) <-> Collection
    • DatasetContainer <-> Class
    • Annotations can be used in Setter, Getter or accessible class attributes
    • Map nested java classes for example FirstSpirit FormDataList with section templates
    • Installation

      • Maven is required
      • Git is required
      • Clone project via git because no public artifact is available.

      Via Maven Repo (local or remote)

      Maven

      <dependency>
          <groupId>com.diva-e.firstspirit</groupId>
          <artifactId>form-field-mapper</artifactId>
          <version>${form-field-mapper-version}</version>
      </dependency>
      

      Ho to use it

      Usage start with creation of a reusable (stateless) FormFieldMapper instance:

      FormFieldMapper formFieldMapper = new FormFieldMapper();

      Usage, reading from FirstSpirit

      FormData formData = <getFormDataViaAPI()>
      Language language = <getLanguageForAllFormFieldFromViaAPIOrNull()>
      
      DTO dto = new DTO() {
      
      	@FormField("<FirstSpiritFormFieldName>")
      	public <SupportedClassOrCollection> attribute;
      
      	@FormField("<OtherFirstSpiritFormFieldName>")
      	public void setOtherAttribute(<SupportedClassOrCollection> otherAttribute) {
      		...
      	}
      }
      

      formFieldMapper.map(formData, dto, language);

      Usage, writing to FirstSpirit

      DTO dto = new DTO() {
      
      	@FormField("<FirstSpiritFormFieldName>")
      	public <SupportedClassOrCollection> attribute;
      
      	@FormField("<OtherFirstSpiritFormFieldName>")
      	public <SupportedClassOrCollection> getOtherAttribute() {
      		...
      	}
      }
      
      FormData formData = <getFormDataViaAPI()>
      Language language = <getLanguageForAllFormFieldFromViaAPIOrNull()>
      

      formFieldMapper.map(dto, formData, language);

      Mapping FormFields with section templates like in FormDataList

      @Template("<FirstSpiritTemplateName>")
      public class Source {
      
      	@FormField(<FirstSpiritFormFieldName>")
      	public <SupportedClassOrCollection> attribute;
      }
      
      public class DTO {
      
      	@FormField(<FirstSpiritFormFieldName>")
      	public Collection<Source> attribute;
      }
      
      FormData formData = <getFormDataViaAPI()>
      Language language = <getLanguageForAllFormFieldFromViaAPIOrNull()>
      

      formFieldMapper.map(dto, formData, language);

      Mapping Entities with extra class as database query like in Option

      public static class Source {
          @FormField(<FirstSpiritFormFieldName>")
       	public <SupportedClass> attribute;
      }
      
      @Database("database")
      public static class SupportedClass {
          @FormField(value = "fs_id", isEntityName = true)
          public Long fsId;
      }
      
      FormData formData = <getFormDataViaAPI()>
      Language language = <getLanguageForAllFormFieldFromViaAPIOrNull()>
      

      formFieldMapper.map(dto, formData, language);

      Ho to add custom mapping strategies

      You can add new mapping strategies by using this method FormFieldMapper#addStrategy

About

Project for mapping java field values into FirstSpirit Fields via annotations and vise versa.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages