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

import org.geotools.metadata.iso.citation.ResponsiblePartyImpl;
import org.geotools.util.SimpleInternationalString;
import org.opengis.metadata.citation.Address;
import org.opengis.metadata.citation.ResponsibleParty;
import org.opengis.metadata.citation.Role;
import org.opengis.metadata.citation.Telephone;
import org.opengis.util.InternationalString;

import ma.glasnost.orika.MapperFacade;
import ma.glasnost.orika.MapperFactory;
import ma.glasnost.orika.impl.DefaultMapperFactory;

import net.opengis.gml.v_3_2_1.CodeListType;
import net.opengis.iso19139.gco.v_20070417.CodeListValueType;
import net.opengis.iso19139.gmd.v_20070417.CIAddressType;
import net.opengis.iso19139.gmd.v_20070417.CIResponsiblePartyType;
import net.opengis.iso19139.gmd.v_20070417.CITelephoneType;

public class ResponsiblePartyOrikaMapper {

    MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();

    MapperFacade mapper;

    public ResponsiblePartyOrikaMapper() {

        mapperFactory.classMap(Telephone.class, CITelephoneType.class)
            .field("voices", "voice")
            .field("facsimiles", "facsimile")
            .byDefault()
            .register();

        mapperFactory.classMap(Address.class, CIAddressType.class)
            .field("deliveryPoints", "deliveryPoint")
            .field("electronicMailAddresses", "electronicMailAddress")
            .byDefault()
            .register();

        mapperFactory.classMap(ResponsiblePartyImpl.class, CIResponsiblePartyType.class)
            .field("role", "role.CIRoleCode")
            .field("contactInfo", "contactInfo.CIContact")
            .field("contactInfo.address", "contactInfo.CIContact.address.CIAddress")
            .field("contactInfo.phone", "contactInfo.CIContact.phone.CITelephone")
            .byDefault()
            .register();

        mapperFactory.getConverterFactory().registerConverter(new InternationalStringToStringPropertyConverter());
        mapperFactory.getConverterFactory().registerConverter(new RoleToCodeListValueConverter());
        mapperFactory.getConverterFactory().registerConverter(new StringToStringPropertyConverter());
        mapperFactory.registerConcreteType(InternationalString.class, SimpleInternationalString.class);
        mapper = mapperFactory.getMapperFacade();
    }

    public ResponsibleParty mapFromDto(CIResponsiblePartyType partyType) {
        return mapper.map(partyType, ResponsibleParty.class);
    }

    public CIResponsiblePartyType mapToDto(ResponsibleParty party) {
        return mapper.map(party, CIResponsiblePartyType.class);
    }
}

@@ -84,32 +84,144 @@
 itation.
-ResponsibleParty
+ContactImpl;%0Aimport org.geotools.metadata.iso.citation.ResponsiblePartyImpl;%0Aimport org.geotools.metadata.iso.citation.Telephone
 Impl;%0Aim
@@ -375,99 +375,8 @@
 ty;%0A
-import org.opengis.metadata.citation.Role;%0Aimport org.opengis.metadata.citation.Telephone;%0A
 impo
@@ -553,53 +553,8 @@
 y;%0A%0A
-import net.opengis.gml.v_3_2_1.CodeListType;%0A
 impo
@@ -578,18 +578,18 @@
 o19139.g
-co
+md
 .v_20070
@@ -593,28 +593,24 @@
 070417.C
-odeListValue
+IAddress
 Type;%0Aim
@@ -644,39 +644,39 @@
 md.v_20070417.CI
-Address
+Contact
 Type;%0Aimport net
@@ -990,214 +990,8 @@
  %7B%0A%0A
-        mapperFactory.classMap(Telephone.class, CITelephoneType.class)%0A            .field(%22voices%22, %22voice%22)%0A            .field(%22facsimiles%22, %22facsimile%22)%0A            .byDefault()%0A            .register();%0A%0A
     
@@ -1440,159 +1440,423 @@
    .
-field(%22contactInfo.address%22, %22contactInfo.CIContact.address.CIAddress%22)%0A            .field(%22contactInfo.phone%22, %22contactInfo.CIContact.phone.CITelephon
+byDefault()%0A            .register();%0A%0A        mapperFactory.classMap(ContactImpl.class, CIContactType.class)%0A            .field(%22address%22, %22address.CIAddress%22)%0A            .field(%22phone%22, %22phone.CITelephone%22)%0A            .byDefault()%0A            .register();%0A%0A        mapperFactory.classMap(TelephoneImpl.class, CITelephoneType.class)%0A            .field(%22voices%22, %22voice%22)%0A            .field(%22facsimiles%22, %22facsimil
 e%22)%0A

Complete ResponsiblePartyOrikaMapper