Commit 20c6e168 authored by Konstantinos Poulakakis's avatar Konstantinos Poulakakis
Browse files

Add update service method for GeoAddressValidation and GeoAddress

parent de23e83e
Loading
Loading
Loading
Loading
+39 −0
Original line number Diff line number Diff line
package org.etsi.osl.tmf.gam673.mapper;

import org.etsi.osl.tmf.gam673.model.GeographicAddress;
import org.etsi.osl.tmf.gam673.model.GeographicSubAddress;

public class MapperUtils {

    public static GeographicAddress geographicAddressMap(GeographicAddress newGeographicAddress, GeographicAddress existingGeographicAddress){
        if(newGeographicAddress.getCity()!=null) existingGeographicAddress.setCity(newGeographicAddress.getCity());
        if(newGeographicAddress.getCountry()!=null) existingGeographicAddress.setCountry(newGeographicAddress.getCountry());
        if(newGeographicAddress.getLocality()!=null) existingGeographicAddress.setLocality(newGeographicAddress.getLocality());
        if(newGeographicAddress.getPostcode()!=null) existingGeographicAddress.setPostcode(newGeographicAddress.getPostcode());
        if(newGeographicAddress.getStateOrProvince()!=null) existingGeographicAddress.setStateOrProvince(newGeographicAddress.getStateOrProvince());
        if(newGeographicAddress.getStreetName()!=null) existingGeographicAddress.setStreetName(newGeographicAddress.getStreetName());
        if(newGeographicAddress.getStreetNr()!=null) existingGeographicAddress.setStreetNr(newGeographicAddress.getStreetNr());
        if(newGeographicAddress.getStreetNrLast()!=null) existingGeographicAddress.setStreetNrLast(newGeographicAddress.getStreetNrLast());
        if(newGeographicAddress.getStreetNrLastSuffix()!=null) existingGeographicAddress.setStreetNrLastSuffix(newGeographicAddress.getStreetNrLastSuffix());
        if(newGeographicAddress.getStreetSuffix()!=null) existingGeographicAddress.setStreetSuffix(newGeographicAddress.getStreetSuffix());
        if(newGeographicAddress.getStreetType()!=null) existingGeographicAddress.setStreetType(newGeographicAddress.getStreetType());
        if(newGeographicAddress.getHref()!=null) existingGeographicAddress.setHref(newGeographicAddress.getHref());
        if(newGeographicAddress.getName()!=null) existingGeographicAddress.setName(newGeographicAddress.getName());

        if(newGeographicAddress.getGeographicLocation()!=null){
            if(newGeographicAddress.getGeographicLocation().getReferredType()!=null) existingGeographicAddress.getGeographicLocation().setReferredType(newGeographicAddress.getGeographicLocation().getReferredType());
            if(newGeographicAddress.getGeographicLocation().getRole()!=null) existingGeographicAddress.getGeographicLocation().setRole(newGeographicAddress.getGeographicLocation().getRole());
        }


        if(newGeographicAddress.getGeographicSubAddresses()!=null){
            for(GeographicSubAddress n : newGeographicAddress.getGeographicSubAddresses()){
                if(n.getUuid()==null){
                    existingGeographicAddress.addGeographicSubAddress(n);
                }
            }
        }
        return existingGeographicAddress;
    }

}
+8 −3
Original line number Diff line number Diff line
package org.etsi.osl.tmf.gam673.reposervices;

import org.etsi.osl.tmf.gam673.mapper.MapperUtils;
import org.etsi.osl.tmf.gam673.model.GeographicAddress;
import org.etsi.osl.tmf.gam673.model.GeographicSubAddress;
import org.etsi.osl.tmf.gam673.repo.GeographicAddressManagementRepository;
@@ -22,6 +23,8 @@ public class GeographicAddressManagementService {

    private final GeographicAddressManagementRepository geographicAddressManagementRepository;

    private MapperUtils mapperUtils;

    @Autowired
    public GeographicAddressManagementService(GeographicAddressManagementRepository geographicAddressManagementRepository) {
        this.geographicAddressManagementRepository = geographicAddressManagementRepository;
@@ -67,10 +70,12 @@ public class GeographicAddressManagementService {
        return null;
    }

    private GeographicAddress updateFields(GeographicAddress newSite, GeographicAddress existingSite){
    private GeographicAddress updateFields(GeographicAddress newGeographicAddress, GeographicAddress existingGeographicAddress){

        existingGeographicAddress = mapperUtils.geographicAddressMap(newGeographicAddress, existingGeographicAddress);

        geographicAddressManagementRepository.save(existingSite);
        return existingSite;
        geographicAddressManagementRepository.save(existingGeographicAddress);
        return existingGeographicAddress;
    }


+25 −3
Original line number Diff line number Diff line
package org.etsi.osl.tmf.gam673.reposervices;

import org.etsi.osl.tmf.gam673.mapper.MapperUtils;
import org.etsi.osl.tmf.gam673.model.GeographicAddress;
import org.etsi.osl.tmf.gam673.model.GeographicAddressValidation;
import org.etsi.osl.tmf.gam673.repo.GeographicAddressValidationManagementRepository;
import org.slf4j.Logger;
@@ -19,6 +21,8 @@ public class GeographicAddressValidationManagementService {

    private final GeographicAddressValidationManagementRepository geographicAddressValidationManagementRepository;

    private MapperUtils mapperUtils;

    @Autowired
    public GeographicAddressValidationManagementService(GeographicAddressValidationManagementRepository geographicAddressValidationManagementRepository) {
        this.geographicAddressValidationManagementRepository = geographicAddressValidationManagementRepository;
@@ -51,10 +55,28 @@ public class GeographicAddressValidationManagementService {
        return null;
    }

    private GeographicAddressValidation updateFields(GeographicAddressValidation newSite, GeographicAddressValidation existingSite){
    private GeographicAddressValidation updateFields(GeographicAddressValidation newGeographicAddressValidation, GeographicAddressValidation existingGeographicAddressValidation){

        if(newGeographicAddressValidation.getValidationDate()!=null) existingGeographicAddressValidation.setValidationDate(newGeographicAddressValidation.getValidationDate());
        if(newGeographicAddressValidation.getStatus()!=null) existingGeographicAddressValidation.setStatus(newGeographicAddressValidation.getStatus());
        if(newGeographicAddressValidation.getValidationResult()!=null) existingGeographicAddressValidation.setValidationResult(newGeographicAddressValidation.getValidationResult());
        if(newGeographicAddressValidation.getProvideAlternative()!=null) existingGeographicAddressValidation.setProvideAlternative(newGeographicAddressValidation.getProvideAlternative());

        if(newGeographicAddressValidation.getAlternateGeographicAddresses()!=null){
            for(GeographicAddress n : newGeographicAddressValidation.getAlternateGeographicAddresses()){
                if(n.getUuid()==null){
                    existingGeographicAddressValidation.addGeographicAddress(n);
                }
            }
        }

        if(newGeographicAddressValidation.getValidAddress()!=null){
            GeographicAddress geographicAddress = mapperUtils.geographicAddressMap(newGeographicAddressValidation.getValidAddress(), existingGeographicAddressValidation.getValidAddress());
            existingGeographicAddressValidation.setValidAddress(geographicAddress);
        }

        geographicAddressValidationManagementRepository.save(existingSite);
        return existingSite;
        geographicAddressValidationManagementRepository.save(existingGeographicAddressValidation);
        return existingGeographicAddressValidation;
    }