package au.gov.ga.geodesy.support.mapper.orika.sopac;

import org.geotools.metadata.iso.citation.ContactImpl;
import org.geotools.metadata.iso.citation.ResponsiblePartyImpl;
import org.geotools.metadata.iso.citation.TelephoneImpl;
import org.opengis.metadata.citation.Telephone;
import org.springframework.stereotype.Component;

import au.gov.ga.geodesy.domain.model.sitelog.SiteLog;
import au.gov.ga.geodesy.igssitelog.domain.model.Agency;
import au.gov.ga.geodesy.igssitelog.domain.model.IgsSiteLog;
import au.gov.ga.geodesy.port.adapter.sopac.SopacSiteLogMapper;
import au.gov.ga.geodesy.support.mapper.orika.StringToInternationalStringConverter;
import au.gov.ga.geodesy.support.mapper.orika.StringToStringPropertyConverter;
import ma.glasnost.orika.MapperFacade;
import ma.glasnost.orika.MapperFactory;
import ma.glasnost.orika.impl.DefaultMapperFactory;
import ma.glasnost.orika.impl.generator.EclipseJdtCompilerStrategy;

@Component
public class SiteLogSopacOrikaMapper implements SopacSiteLogMapper {

    private MapperFacade mapper;

    public SiteLogSopacOrikaMapper() {
        MapperFactory factory = new DefaultMapperFactory.Builder()
            .compilerStrategy(new EclipseJdtCompilerStrategy())
            .build();

        factory.classMap(IgsSiteLog.class, SiteLog.class)
            .field("contactAgency", "siteContact.party")
            .field("responsibleAgency", "siteMetadataCustodian.party")
            .exclude("equipmentLogItems")
            .byDefault()
            .register();

        factory.classMap(Agency.class, ResponsiblePartyImpl.class)
            .field("name", "organisationName")
            .field("primaryContact.name", "individualName")
            .field("primaryContact", "contactInfo")
            .byDefault()
            .register();

        factory.classMap(au.gov.ga.geodesy.igssitelog.domain.model.Contact.class, ContactImpl.class)
            .fieldMap("telephonePrimary", "phone.voices.fst:{|add(%s)}").mapNulls(false).add()
            .fieldMap("telephoneSecondary", "phone.voices.fst:{|add(%s)}").mapNulls(false).add()
            .fieldMap("fax", "phone.facsimiles.fst:{|add(%s)}").mapNulls(false).add()
            .byDefault()
            .register();

        factory.getConverterFactory().registerConverter(new StringToInternationalStringConverter());
        factory.getConverterFactory().registerConverter(new StringToStringPropertyConverter());
        factory.registerConcreteType(Telephone.class, TelephoneImpl.class);
        mapper = factory.getMapperFacade();
    }

    public SiteLog fromDTO(IgsSiteLog siteLogSopac) {
        return mapper.map(siteLogSopac, SiteLog.class);
    }

    public IgsSiteLog toDTO(SiteLog siteLog) {
        return mapper.map(siteLog, IgsSiteLog.class);
    }
}

@@ -52,282 +52,8 @@
 c;%0A%0A
-import org.geotools.metadata.iso.citation.ContactImpl;%0Aimport org.geotools.metadata.iso.citation.ResponsiblePartyImpl;%0Aimport org.geotools.metadata.iso.citation.TelephoneImpl;%0Aimport org.opengis.metadata.citation.Telephone;%0Aimport org.springframework.stereotype.Component;%0A%0A
 impo
@@ -651,184 +651,751 @@
 gy;%0A
-%0A@Component%0Apublic class SiteLogSopacOrikaMapper implements SopacSiteLogMapper %7B%0A%0A    private MapperFacade mapper;%0A%0A    public SiteLogSopacOrikaMapper() %7B%0A        MapperFactory
+import org.geotools.metadata.iso.citation.ContactImpl;%0Aimport org.geotools.metadata.iso.citation.ResponsiblePartyImpl;%0Aimport org.geotools.metadata.iso.citation.TelephoneImpl;%0Aimport org.opengis.metadata.citation.Telephone;%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0Aimport org.springframework.stereotype.Component;%0A%0A@Component%0Apublic class SiteLogSopacOrikaMapper implements SopacSiteLogMapper %7B%0A    private Logger logger = LoggerFactory.getLogger(SiteLogSopacOrikaMapper.class);%0A    private MapperFacade mapper;%0A%0A    public SiteLogSopacOrikaMapper() %7B%0A        MapperFactory factory;%0A%0A        if (logger.isDebugEnabled()) %7B%0A            // This configuration will dump the generated java files to the target directory%0A           
  fac
@@ -1435,29 +1435,16 @@
 uilder()
-%0A            
 .compile
@@ -1490,30 +1490,110 @@
 y())
-%0A            .build();
+.build();%0A        %7D else %7B%0A            factory = new DefaultMapperFactory.Builder().build();%0A        %7D
 %0A%0A  
@@ -1640,32 +1640,36 @@
  SiteLog.class)%0A
+    
             .fie
@@ -1713,32 +1713,36 @@
 y%22)%0A            
+    
 .field(%22responsi
@@ -1796,16 +1796,20 @@
         
+    
 .exclude
@@ -1834,32 +1834,36 @@
 s%22)%0A            
+   
+ 
 .byDefault()%0A   
@@ -1851,32 +1851,36 @@
    .byDefault()%0A
+    
             .reg
@@ -1960,32 +1960,36 @@
 ss)%0A            
+    
 .field(%22name%22, %22
@@ -2011,32 +2011,36 @@
 e%22)%0A            
+   
+ 
 .field(%22primaryC
@@ -2075,32 +2075,36 @@
 e%22)%0A            
+    
 .field(%22primaryC
@@ -2131,32 +2131,36 @@
 o%22)%0A            
+ 
+   
 .byDefault()%0A   
@@ -2160,32 +2160,36 @@
 t()%0A            
+  
+  
 .register();%0A%0A  
@@ -2279,32 +2279,36 @@
 tactImpl.class)%0A
+    
             .fie
@@ -2390,32 +2390,36 @@
 d()%0A            
+    
 .fieldMap(%22telep
@@ -2491,32 +2491,36 @@
 d()%0A            
+ 
+   
 .fieldMap(%22fax%22,
@@ -2581,32 +2581,36 @@
 d()%0A            
+    
 .byDefault()%0A   
@@ -2598,32 +2598,36 @@
    .byDefault()%0A
+    
             .reg

Use Orika's default compiler strategy