Search in sources :

Example 1 with FareZoneRefStructure

use of org.rutebanken.netex.model.FareZoneRefStructure in project tiamat by entur.

the class FareZoneMapper method mapBtoA.

@Override
public void mapBtoA(org.rutebanken.tiamat.model.FareZone tiamatFareZone, FareZone netexFareZone, MappingContext context) {
    super.mapBtoA(tiamatFareZone, netexFareZone, context);
    if (tiamatFareZone.getTransportOrganisationRef() != null) {
        final JAXBElement<AuthorityRefStructure> authorityRef = objectFactory.createAuthorityRef(new AuthorityRefStructure().withRef(tiamatFareZone.getTransportOrganisationRef()));
        netexFareZone.withTransportOrganisationRef(authorityRef);
    }
    if (!tiamatFareZone.getNeighbours().isEmpty()) {
        final List<FareZoneRefStructure> fareZoneRefs = tiamatFareZone.getNeighbours().stream().map(tariffZoneRef -> new FareZoneRefStructure().withRef(tariffZoneRef.getRef())).collect(Collectors.toList());
        final FareZoneRefs_RelStructure fareZoneRefsRelStructure = new FareZoneRefs_RelStructure().withFareZoneRef(fareZoneRefs);
        netexFareZone.withNeighbours(fareZoneRefsRelStructure);
    }
    if (!tiamatFareZone.getFareZoneMembers().isEmpty()) {
        List<JAXBElement<? extends PointRefStructure>> fareZoneMember = tiamatFareZone.getFareZoneMembers().stream().map(members -> convertStopPlaceRefToScheduledStopPointRef(members.getRef())).filter(Objects::nonNull).map(spRef -> new ObjectFactory().createScheduledStopPointRef(new ScheduledStopPointRefStructure().withRef(spRef))).collect(Collectors.toList());
        PointRefs_RelStructure pointRefsRelStructure = new PointRefs_RelStructure().withPointRef(fareZoneMember);
        netexFareZone.withMembers(pointRefsRelStructure);
    }
}
Also used : CustomMapper(ma.glasnost.orika.CustomMapper) FareZone(org.rutebanken.netex.model.FareZone) PointRefs_RelStructure(org.rutebanken.netex.model.PointRefs_RelStructure) ScheduledStopPointRefStructure(org.rutebanken.netex.model.ScheduledStopPointRefStructure) StopPlaceReference(org.rutebanken.tiamat.model.StopPlaceReference) JAXBElement(javax.xml.bind.JAXBElement) Set(java.util.Set) FareZoneRefs_RelStructure(org.rutebanken.netex.model.FareZoneRefs_RelStructure) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) MappingContext(ma.glasnost.orika.MappingContext) TariffZoneRef(org.rutebanken.tiamat.model.TariffZoneRef) HashSet(java.util.HashSet) Objects(java.util.Objects) AuthorityRefStructure(org.rutebanken.netex.model.AuthorityRefStructure) List(java.util.List) FareZoneRefStructure(org.rutebanken.netex.model.FareZoneRefStructure) ObjectFactory(org.rutebanken.netex.model.ObjectFactory) PointRefStructure(org.rutebanken.netex.model.PointRefStructure) ScopingMethodEnumeration(org.rutebanken.netex.model.ScopingMethodEnumeration) AuthorityRefStructure(org.rutebanken.netex.model.AuthorityRefStructure) ScheduledStopPointRefStructure(org.rutebanken.netex.model.ScheduledStopPointRefStructure) PointRefStructure(org.rutebanken.netex.model.PointRefStructure) ScheduledStopPointRefStructure(org.rutebanken.netex.model.ScheduledStopPointRefStructure) JAXBElement(javax.xml.bind.JAXBElement) FareZoneRefStructure(org.rutebanken.netex.model.FareZoneRefStructure) FareZoneRefs_RelStructure(org.rutebanken.netex.model.FareZoneRefs_RelStructure) ObjectFactory(org.rutebanken.netex.model.ObjectFactory) PointRefs_RelStructure(org.rutebanken.netex.model.PointRefs_RelStructure) Objects(java.util.Objects)

Example 2 with FareZoneRefStructure

use of org.rutebanken.netex.model.FareZoneRefStructure in project tiamat by entur.

the class FareZoneMapper method mapAtoB.

@Override
public void mapAtoB(FareZone netexFareZone, org.rutebanken.tiamat.model.FareZone tiamatFareZone, MappingContext context) {
    super.mapAtoB(netexFareZone, tiamatFareZone, context);
    if (netexFareZone.getTransportOrganisationRef() != null && netexFareZone.getTransportOrganisationRef().getValue() != null) {
        tiamatFareZone.setTransportOrganisationRef(netexFareZone.getTransportOrganisationRef().getValue().getRef());
    }
    if (netexFareZone.getNeighbours() != null && !netexFareZone.getNeighbours().getFareZoneRef().isEmpty()) {
        Set<TariffZoneRef> tiamatNeighbours = new HashSet<>();
        final List<FareZoneRefStructure> fareZoneRef = netexFareZone.getNeighbours().getFareZoneRef();
        for (FareZoneRefStructure fareZoneRefStructure : fareZoneRef) {
            tiamatNeighbours.add(new TariffZoneRef(fareZoneRefStructure.getRef()));
        }
        tiamatFareZone.setNeighbours(tiamatNeighbours);
    }
    if (netexFareZone.getScopingMethod() != null && netexFareZone.getScopingMethod().equals(ScopingMethodEnumeration.EXPLICIT_STOPS) && netexFareZone.getMembers() != null && !netexFareZone.getMembers().getPointRef().isEmpty()) {
        var fareZoneMembers = netexFareZone.getMembers().getPointRef().stream().map(jaxbElement -> convertScheduledStopPointRefToStopPlaceRef(jaxbElement.getValue().getRef())).filter(Objects::nonNull).map(StopPlaceReference::new).collect(Collectors.toSet());
        tiamatFareZone.setFareZoneMembers(fareZoneMembers);
    }
}
Also used : CustomMapper(ma.glasnost.orika.CustomMapper) FareZone(org.rutebanken.netex.model.FareZone) PointRefs_RelStructure(org.rutebanken.netex.model.PointRefs_RelStructure) ScheduledStopPointRefStructure(org.rutebanken.netex.model.ScheduledStopPointRefStructure) StopPlaceReference(org.rutebanken.tiamat.model.StopPlaceReference) JAXBElement(javax.xml.bind.JAXBElement) Set(java.util.Set) FareZoneRefs_RelStructure(org.rutebanken.netex.model.FareZoneRefs_RelStructure) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) MappingContext(ma.glasnost.orika.MappingContext) TariffZoneRef(org.rutebanken.tiamat.model.TariffZoneRef) HashSet(java.util.HashSet) Objects(java.util.Objects) AuthorityRefStructure(org.rutebanken.netex.model.AuthorityRefStructure) List(java.util.List) FareZoneRefStructure(org.rutebanken.netex.model.FareZoneRefStructure) ObjectFactory(org.rutebanken.netex.model.ObjectFactory) PointRefStructure(org.rutebanken.netex.model.PointRefStructure) ScopingMethodEnumeration(org.rutebanken.netex.model.ScopingMethodEnumeration) FareZoneRefStructure(org.rutebanken.netex.model.FareZoneRefStructure) Objects(java.util.Objects) TariffZoneRef(org.rutebanken.tiamat.model.TariffZoneRef) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)2 List (java.util.List)2 Objects (java.util.Objects)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 JAXBElement (javax.xml.bind.JAXBElement)2 CustomMapper (ma.glasnost.orika.CustomMapper)2 MappingContext (ma.glasnost.orika.MappingContext)2 StringUtils (org.apache.commons.lang3.StringUtils)2 AuthorityRefStructure (org.rutebanken.netex.model.AuthorityRefStructure)2 FareZone (org.rutebanken.netex.model.FareZone)2 FareZoneRefStructure (org.rutebanken.netex.model.FareZoneRefStructure)2 FareZoneRefs_RelStructure (org.rutebanken.netex.model.FareZoneRefs_RelStructure)2 ObjectFactory (org.rutebanken.netex.model.ObjectFactory)2 PointRefStructure (org.rutebanken.netex.model.PointRefStructure)2 PointRefs_RelStructure (org.rutebanken.netex.model.PointRefs_RelStructure)2 ScheduledStopPointRefStructure (org.rutebanken.netex.model.ScheduledStopPointRefStructure)2 ScopingMethodEnumeration (org.rutebanken.netex.model.ScopingMethodEnumeration)2 StopPlaceReference (org.rutebanken.tiamat.model.StopPlaceReference)2 TariffZoneRef (org.rutebanken.tiamat.model.TariffZoneRef)2