Menu

OpenL Mapper

Help
Jo F
2020-01-11
2022-08-10
  • Jo F

    Jo F - 2020-01-11

    Do you have example projects that use OpenL Mappers. I have having a hard time trying to setup an project using the reference document. It is outdated.

    here is the sample code and xls:

    package org.jof.prototype;

    import static org.assertj.core.api.Assertions.assertThat;

    import java.util.LinkedHashMap;
    import java.util.Map;
    import lombok.Getter;
    import lombok.Setter;
    import org.apache.commons.lang3.builder.ToStringBuilder;
    import org.apache.commons.lang3.builder.ToStringStyle;
    import org.junit.jupiter.api.BeforeEach;
    import org.junit.jupiter.api.Test;
    import org.openl.rules.mapping.Mapper;
    import org.openl.rules.mapping.RulesBeanMapperFactory;
    import org.springframework.core.io.ClassPathResource;
    import org.springframework.core.io.Resource;

    class RuleDataMappingTest {
    
      Mapper mapper;
    
      @BeforeEach
      void setUp() throws Exception {
    
        Resource resource = new ClassPathResource("mappinga.xls");
        mapper = RulesBeanMapperFactory.createMapperInstance(resource.getFile());
      }
    
      @Getter
      @Setter
      static class StandardEvent {
        private String eventId;
        private String eventName;
    
        @Override
        public String toString() {
          return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
        }
      }
    
      @Test
      void test() {
        Map<String, Object> test = new LinkedHashMap<>();
        test.put("id", 298798);
        test.put("eventName", "sampleEvent");
    
        final StandardEvent map = mapper.map(test, StandardEvent.class);
    
        System.out.println(map.toString());
    
        assertThat(map.getEventId()).isEqualTo("298798");
    
        assertThat(map.getEventName()).isEqualTo("sampleEvent");
      }
    }
    
     
  • Elena Kosolapova

    Hello,
    Your question is moved to the Github OpenL Discussions.
    You can track it by the following link:
    https://github.com/openl-tablets/openl-tablets/discussions/637

    Best regards,
    Alena.

     

Log in to post a comment.