<commit_before>package eu.nimble.core.infrastructure.identity.utils;

import eu.nimble.service.model.solr.party.PartyType;
import eu.nimble.service.model.ubl.commonaggregatecomponents.DocumentReferenceType;
import eu.nimble.service.model.ubl.commonaggregatecomponents.QualifyingPartyType;
import eu.nimble.service.model.ubl.commonbasiccomponents.TextType;
import eu.nimble.service.model.ubl.extension.QualityIndicatorParameter;
import eu.nimble.utility.country.CountryUtil;

import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * Created by <NAME> on 15/03/19
 * This util class gives helper methods to convert UBL data models to Solr Data Models for indexing.
 */
public class DataModelUtils {

    private static final String circularEconomyCertificateGroup = "Circular Economy (Environment / Sustainability)";
    /**
     * UBL data model to Solr model converter
     */

    public static eu.nimble.service.model.solr.party.PartyType toIndexParty(eu.nimble.service.model.ubl.commonaggregatecomponents.PartyType party, QualifyingPartyType qualifyingParty) {
        PartyType indexParty = new PartyType();
        party.getBrandName().forEach(name -> indexParty.addBrandName(name.getLanguageID(), name.getValue()));
        if(party.getPartyName() != null && party.getPartyName().size() > 0){
            indexParty.setLegalName(party.getPartyName().get(0).getName().getValue());
        }
        // postal address
        if(party.getPostalAddress() != null){
            // country
            if(party.getPostalAddress().getCountry() != null && party.getPostalAddress().getCountry().getIdentificationCode() != null){
                Map<String ,String> countryNames = CountryUtil.getCountryNamesByISOCode(party.getPostalAddress().getCountry().getIdentificationCode().getValue());
                if(countryNames == null){
                    indexParty.addOrigin("en",party.getPostalAddress().getCountry().getIdentificationCode().getValue());
                } else {
                    countryNames.forEach(indexParty::addOrigin);
                }
            }
            // location longitude and latitude
            if(party.getPostalAddress().getCoordinate() != null){
                indexParty.setLocationLatitude(party.getPostalAddress().getCoordinate().getLatitude().doubleValue());
                indexParty.setLocationLongitude(party.getPostalAddress().getCoordinate().getLongitude().doubleValue());
            }
        }

        indexParty.setId(party.getHjid().toString());
        indexParty.setUri(party.getHjid().toString());

        // TODO currently we do not support multilingual certificate types
        indexParty.setCertificateType(getOtherCertificates(party));
        indexParty.setCircularEconomyCertificates(getCircularEconomyRelatedCertificateNames(party));
        if(party.getPpapCompatibilityLevel() != null) {
            indexParty.setPpapComplianceLevel(party.getPpapCompatibilityLevel().intValue());
        }
        // TODO currently we do not support multilingual ppap document types
        party.getPpapDocumentReference().forEach(ppapDocument -> indexParty.addPpapDocumentType("", ppapDocument.getDocumentType()));<commit_msg>handle the null longitude and latitude while indexing company coordinate<commit_after>package eu.nimble.core.infrastructure.identity.utils;

import eu.nimble.service.model.solr.party.PartyType;
import eu.nimble.service.model.ubl.commonaggregatecomponents.DocumentReferenceType;
import eu.nimble.service.model.ubl.commonaggregatecomponents.QualifyingPartyType;
import eu.nimble.service.model.ubl.commonbasiccomponents.TextType;
import eu.nimble.service.model.ubl.extension.QualityIndicatorParameter;
import eu.nimble.utility.country.CountryUtil;

import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * Created by <NAME> on 15/03/19
 * This util class gives helper methods to convert UBL data models to Solr Data Models for indexing.
 */
public class DataModelUtils {

    private static final String circularEconomyCertificateGroup = "Circular Economy (Environment / Sustainability)";
    /**
     * UBL data model to Solr model converter
     */

    public static eu.nimble.service.model.solr.party.PartyType toIndexParty(eu.nimble.service.model.ubl.commonaggregatecomponents.PartyType party, QualifyingPartyType qualifyingParty) {
        PartyType indexParty = new PartyType();
        party.getBrandName().forEach(name -> indexParty.addBrandName(name.getLanguageID(), name.getValue()));
        if(party.getPartyName() != null && party.getPartyName().size() > 0){
            indexParty.setLegalName(party.getPartyName().get(0).getName().getValue());
        }
        // postal address
        if(party.getPostalAddress() != null){
            // country
            if(party.getPostalAddress().getCountry() != null && party.getPostalAddress().getCountry().getIdentificationCode() != null){
                Map<String ,String> countryNames = CountryUtil.getCountryNamesByISOCode(party.getPostalAddress().getCountry().getIdentificationCode().getValue());
                if(countryNames == null){
                    indexParty.addOrigin("en",party.getPostalAddress().getCountry().getIdentificationCode().getValue());
                } else {
                    countryNames.forEach(indexParty::addOrigin);
                }
            }
            // location longitude and latitude
            if(party.getPostalAddress().getCoordinate() != null && party.getPostalAddress().getCoordinate().getLatitude() != null && party.getPostalAddress().getCoordinate().getLongitude() != null){
                indexParty.setLocationLatitude(party.getPostalAddress().getCoordinate().getLatitude().doubleValue());
                indexParty.setLocationLongitude(party.getPostalAddress().getCoordinate().getLongitude().doubleValue());
            }
        }

        indexParty.setId(party.getHjid().toString());
        indexParty.setUri(party.getHjid().toString());

        // TODO currently we do not support multilingual certificate types
        indexParty.setCertificateType(getOtherCertificates(party));
        indexParty.setCircularEconomyCertificates(getCircularEconomyRelatedCertificateNames(party));
        if(party.getPpapCompatibilityLevel() != null) {
            indexParty.setPpapComplianceLevel(party.getPpapCompatibilityLevel().intValue());
        }
        // TODO currently we do not support multilingual ppap document types
        party.getPpapDocumentReference().forEach(ppapDocument -> indexParty.addPpapDocumentType("", ppapDocument.getDocumentType()));
{'fraction_non_alphanumeric': 0.11515333734215273, 'fraction_numerical': 0.0024052916416115455, 'mean_word_length': 3.6459497206703912, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '381692', 'n_tokens_mistral': 1843, 'n_tokens_neox': 1743, 'n_words': 286}