@@ -512,121 +512,167 @@ protected Map<String, Object> transform(final DomainResponse response) {
512
512
}
513
513
}
514
514
515
- static class Enterprise extends AbstractBase <EnterpriseResponse , EnterpriseResponse > {
515
+ record CacheableEnterpriseResponse (
516
+ Integer countryConfidence ,
517
+ Boolean isInEuropeanUnion ,
518
+ String countryIsoCode ,
519
+ String countryName ,
520
+ String continentCode ,
521
+ String continentName ,
522
+ String regionIsoCode ,
523
+ String regionName ,
524
+ Integer cityConfidence ,
525
+ String cityName ,
526
+ String timezone ,
527
+ Double latitude ,
528
+ Double longitude ,
529
+ Integer accuracyRadius ,
530
+ String postalCode ,
531
+ Integer postalConfidence ,
532
+ Long asn ,
533
+ String organizationName ,
534
+ boolean isHostingProvider ,
535
+ boolean isTorExitNode ,
536
+ boolean isAnonymousVpn ,
537
+ boolean isAnonymous ,
538
+ boolean isPublicProxy ,
539
+ boolean isResidentialProxy ,
540
+ String domain ,
541
+ String isp ,
542
+ String ispOrganization ,
543
+ String mobileCountryCode ,
544
+ String mobileNetworkCode ,
545
+ String userType ,
546
+ String connectionType ,
547
+ Boolean registeredCountryIsInEuropeanUnion ,
548
+ String registeredCountryIsoCode ,
549
+ String registeredCountryName
550
+ ) {}
551
+
552
+ static class Enterprise extends AbstractBase <EnterpriseResponse , Result <CacheableEnterpriseResponse >> {
516
553
Enterprise (final Set <Database .Property > properties ) {
517
554
super (properties , EnterpriseResponse .class , EnterpriseResponse ::new );
518
555
}
519
556
520
557
@ Override
521
- protected EnterpriseResponse cacheableRecord (EnterpriseResponse response ) {
522
- return response ;
558
+ protected Result <CacheableEnterpriseResponse > cacheableRecord (EnterpriseResponse response ) {
559
+ final com .maxmind .geoip2 .record .Country country = response .getCountry ();
560
+ final Continent continent = response .getContinent ();
561
+ final Subdivision subdivision = response .getMostSpecificSubdivision ();
562
+ final com .maxmind .geoip2 .record .City city = response .getCity ();
563
+ final Location location = response .getLocation ();
564
+ final Postal postal = response .getPostal ();
565
+ final com .maxmind .geoip2 .record .Country registeredCountry = response .getRegisteredCountry ();
566
+ final Traits traits = response .getTraits ();
567
+
568
+ return new Result <>(
569
+ new CacheableEnterpriseResponse (
570
+ country .getConfidence (),
571
+ isInEuropeanUnion (country ),
572
+ country .getIsoCode (),
573
+ country .getName (),
574
+ continent .getCode (),
575
+ continent .getName (),
576
+ regionIsoCode (country , subdivision ),
577
+ subdivision .getName (),
578
+ city .getConfidence (),
579
+ city .getName (),
580
+ location .getTimeZone (),
581
+ location .getLatitude (),
582
+ location .getLongitude (),
583
+ location .getAccuracyRadius (),
584
+ postal .getCode (),
585
+ postal .getConfidence (),
586
+ traits .getAutonomousSystemNumber (),
587
+ traits .getAutonomousSystemOrganization (),
588
+ traits .isHostingProvider (),
589
+ traits .isTorExitNode (),
590
+ traits .isAnonymousVpn (),
591
+ traits .isAnonymous (),
592
+ traits .isPublicProxy (),
593
+ traits .isResidentialProxy (),
594
+ traits .getDomain (),
595
+ traits .getIsp (),
596
+ traits .getOrganization (),
597
+ traits .getMobileCountryCode (),
598
+ traits .getMobileNetworkCode (),
599
+ traits .getUserType (),
600
+ traits .getConnectionType () == null ? null : traits .getConnectionType ().toString (),
601
+ isInEuropeanUnion (registeredCountry ),
602
+ registeredCountry .getIsoCode (),
603
+ registeredCountry .getName ()
604
+ ),
605
+ traits .getIpAddress (),
606
+ traits .getNetwork ().toString ()
607
+ );
523
608
}
524
609
525
610
@ Override
526
- protected Map <String , Object > transform (final EnterpriseResponse response ) {
527
- com .maxmind .geoip2 .record .Country country = response .getCountry ();
528
- com .maxmind .geoip2 .record .Country registeredCountry = response .getRegisteredCountry ();
529
- com .maxmind .geoip2 .record .City city = response .getCity ();
530
- Location location = response .getLocation ();
531
- Continent continent = response .getContinent ();
532
- Subdivision subdivision = response .getMostSpecificSubdivision ();
533
- Postal postal = response .getPostal ();
534
-
535
- Long asn = response .getTraits ().getAutonomousSystemNumber ();
536
- String organizationName = response .getTraits ().getAutonomousSystemOrganization ();
537
- Network network = response .getTraits ().getNetwork ();
538
-
539
- String isp = response .getTraits ().getIsp ();
540
- String ispOrganization = response .getTraits ().getOrganization ();
541
- String mobileCountryCode = response .getTraits ().getMobileCountryCode ();
542
- String mobileNetworkCode = response .getTraits ().getMobileNetworkCode ();
543
-
544
- boolean isHostingProvider = response .getTraits ().isHostingProvider ();
545
- boolean isTorExitNode = response .getTraits ().isTorExitNode ();
546
- boolean isAnonymousVpn = response .getTraits ().isAnonymousVpn ();
547
- boolean isAnonymous = response .getTraits ().isAnonymous ();
548
- boolean isPublicProxy = response .getTraits ().isPublicProxy ();
549
- boolean isResidentialProxy = response .getTraits ().isResidentialProxy ();
550
-
551
- String userType = response .getTraits ().getUserType ();
552
-
553
- String domain = response .getTraits ().getDomain ();
554
-
555
- ConnectionTypeResponse .ConnectionType connectionType = response .getTraits ().getConnectionType ();
611
+ protected Map <String , Object > transform (final Result <CacheableEnterpriseResponse > result ) {
612
+ CacheableEnterpriseResponse response = result .result ();
556
613
557
614
Map <String , Object > data = new HashMap <>();
558
615
for (Database .Property property : this .properties ) {
559
616
switch (property ) {
560
- case IP -> data .put ("ip" , response . getTraits (). getIpAddress ());
617
+ case IP -> data .put ("ip" , result . ip ());
561
618
case COUNTRY_CONFIDENCE -> {
562
- Integer countryConfidence = country .getConfidence ();
563
- if (countryConfidence != null ) {
564
- data .put ("country_confidence" , countryConfidence );
619
+ if (response .countryConfidence != null ) {
620
+ data .put ("country_confidence" , response .countryConfidence );
565
621
}
566
622
}
567
623
case COUNTRY_IN_EUROPEAN_UNION -> {
568
- Boolean isInEuropeanUnion = isInEuropeanUnion (country );
569
- if (isInEuropeanUnion != null ) {
570
- data .put ("country_in_european_union" , isInEuropeanUnion );
624
+ if (response .isInEuropeanUnion != null ) {
625
+ data .put ("country_in_european_union" , response .isInEuropeanUnion );
571
626
}
572
627
}
573
628
case COUNTRY_ISO_CODE -> {
574
- String countryIsoCode = country .getIsoCode ();
575
- if (countryIsoCode != null ) {
576
- data .put ("country_iso_code" , countryIsoCode );
629
+ if (response .countryIsoCode != null ) {
630
+ data .put ("country_iso_code" , response .countryIsoCode );
577
631
}
578
632
}
579
633
case COUNTRY_NAME -> {
580
- String countryName = country .getName ();
581
- if (countryName != null ) {
582
- data .put ("country_name" , countryName );
634
+ if (response .countryName != null ) {
635
+ data .put ("country_name" , response .countryName );
583
636
}
584
637
}
585
638
case CONTINENT_CODE -> {
586
- String continentCode = continent .getCode ();
587
- if (continentCode != null ) {
588
- data .put ("continent_code" , continentCode );
639
+ if (response .continentCode != null ) {
640
+ data .put ("continent_code" , response .continentCode );
589
641
}
590
642
}
591
643
case CONTINENT_NAME -> {
592
- String continentName = continent .getName ();
593
- if (continentName != null ) {
594
- data .put ("continent_name" , continentName );
644
+ if (response .continentName != null ) {
645
+ data .put ("continent_name" , response .continentName );
595
646
}
596
647
}
597
648
case REGION_ISO_CODE -> {
598
- String regionIsoCode = regionIsoCode (country , subdivision );
599
- if (regionIsoCode != null ) {
600
- data .put ("region_iso_code" , regionIsoCode );
649
+ if (response .regionIsoCode != null ) {
650
+ data .put ("region_iso_code" , response .regionIsoCode );
601
651
}
602
652
}
603
653
case REGION_NAME -> {
604
- String subdivisionName = subdivision .getName ();
605
- if (subdivisionName != null ) {
606
- data .put ("region_name" , subdivisionName );
654
+ if (response .regionName != null ) {
655
+ data .put ("region_name" , response .regionName );
607
656
}
608
657
}
609
658
case CITY_CONFIDENCE -> {
610
- Integer cityConfidence = city .getConfidence ();
611
- if (cityConfidence != null ) {
612
- data .put ("city_confidence" , cityConfidence );
659
+ if (response .cityConfidence != null ) {
660
+ data .put ("city_confidence" , response .cityConfidence );
613
661
}
614
662
}
615
663
case CITY_NAME -> {
616
- String cityName = city .getName ();
617
- if (cityName != null ) {
618
- data .put ("city_name" , cityName );
664
+ if (response .cityName != null ) {
665
+ data .put ("city_name" , response .cityName );
619
666
}
620
667
}
621
668
case TIMEZONE -> {
622
- String locationTimeZone = location .getTimeZone ();
623
- if (locationTimeZone != null ) {
624
- data .put ("timezone" , locationTimeZone );
669
+ if (response .timezone != null ) {
670
+ data .put ("timezone" , response .timezone );
625
671
}
626
672
}
627
673
case LOCATION -> {
628
- Double latitude = location . getLatitude () ;
629
- Double longitude = location . getLongitude () ;
674
+ Double latitude = response . latitude ;
675
+ Double longitude = response . longitude ;
630
676
if (latitude != null && longitude != null ) {
631
677
Map <String , Object > locationObject = HashMap .newHashMap (2 );
632
678
locationObject .put ("lat" , latitude );
@@ -635,103 +681,101 @@ protected Map<String, Object> transform(final EnterpriseResponse response) {
635
681
}
636
682
}
637
683
case ACCURACY_RADIUS -> {
638
- Integer accuracyRadius = location .getAccuracyRadius ();
639
- if (accuracyRadius != null ) {
640
- data .put ("accuracy_radius" , accuracyRadius );
684
+ if (response .accuracyRadius != null ) {
685
+ data .put ("accuracy_radius" , response .accuracyRadius );
641
686
}
642
687
}
643
688
case POSTAL_CODE -> {
644
- if (postal . getCode () != null ) {
645
- data .put ("postal_code" , postal . getCode () );
689
+ if (response . postalCode != null ) {
690
+ data .put ("postal_code" , response . postalCode );
646
691
}
647
692
}
648
693
case POSTAL_CONFIDENCE -> {
649
- if (postal . getConfidence () != null ) {
650
- data .put ("postal_confidence" , postal . getConfidence () );
694
+ if (response . postalConfidence != null ) {
695
+ data .put ("postal_confidence" , response . postalConfidence );
651
696
}
652
697
}
653
698
case ASN -> {
654
- if (asn != null ) {
655
- data .put ("asn" , asn );
699
+ if (response . asn != null ) {
700
+ data .put ("asn" , response . asn );
656
701
}
657
702
}
658
703
case ORGANIZATION_NAME -> {
659
- if (organizationName != null ) {
660
- data .put ("organization_name" , organizationName );
704
+ if (response . organizationName != null ) {
705
+ data .put ("organization_name" , response . organizationName );
661
706
}
662
707
}
663
708
case NETWORK -> {
664
- if (network != null ) {
665
- data .put ("network" , network . toString ());
709
+ if (result . network () != null ) {
710
+ data .put ("network" , result . network ());
666
711
}
667
712
}
668
713
case HOSTING_PROVIDER -> {
669
- data .put ("hosting_provider" , isHostingProvider );
714
+ data .put ("hosting_provider" , response . isHostingProvider );
670
715
}
671
716
case TOR_EXIT_NODE -> {
672
- data .put ("tor_exit_node" , isTorExitNode );
717
+ data .put ("tor_exit_node" , response . isTorExitNode );
673
718
}
674
719
case ANONYMOUS_VPN -> {
675
- data .put ("anonymous_vpn" , isAnonymousVpn );
720
+ data .put ("anonymous_vpn" , response . isAnonymousVpn );
676
721
}
677
722
case ANONYMOUS -> {
678
- data .put ("anonymous" , isAnonymous );
723
+ data .put ("anonymous" , response . isAnonymous );
679
724
}
680
725
case PUBLIC_PROXY -> {
681
- data .put ("public_proxy" , isPublicProxy );
726
+ data .put ("public_proxy" , response . isPublicProxy );
682
727
}
683
728
case RESIDENTIAL_PROXY -> {
684
- data .put ("residential_proxy" , isResidentialProxy );
729
+ data .put ("residential_proxy" , response . isResidentialProxy );
685
730
}
686
731
case DOMAIN -> {
687
- if (domain != null ) {
688
- data .put ("domain" , domain );
732
+ if (response . domain != null ) {
733
+ data .put ("domain" , response . domain );
689
734
}
690
735
}
691
736
case ISP -> {
692
- if (isp != null ) {
693
- data .put ("isp" , isp );
737
+ if (response . isp != null ) {
738
+ data .put ("isp" , response . isp );
694
739
}
695
740
}
696
741
case ISP_ORGANIZATION_NAME -> {
697
- if (ispOrganization != null ) {
698
- data .put ("isp_organization_name" , ispOrganization );
742
+ if (response . ispOrganization != null ) {
743
+ data .put ("isp_organization_name" , response . ispOrganization );
699
744
}
700
745
}
701
746
case MOBILE_COUNTRY_CODE -> {
702
- if (mobileCountryCode != null ) {
703
- data .put ("mobile_country_code" , mobileCountryCode );
747
+ if (response . mobileCountryCode != null ) {
748
+ data .put ("mobile_country_code" , response . mobileCountryCode );
704
749
}
705
750
}
706
751
case MOBILE_NETWORK_CODE -> {
707
- if (mobileNetworkCode != null ) {
708
- data .put ("mobile_network_code" , mobileNetworkCode );
752
+ if (response . mobileNetworkCode != null ) {
753
+ data .put ("mobile_network_code" , response . mobileNetworkCode );
709
754
}
710
755
}
711
756
case USER_TYPE -> {
712
- if (userType != null ) {
713
- data .put ("user_type" , userType );
757
+ if (response . userType != null ) {
758
+ data .put ("user_type" , response . userType );
714
759
}
715
760
}
716
761
case CONNECTION_TYPE -> {
717
- if (connectionType != null ) {
718
- data .put ("connection_type" , connectionType . toString () );
762
+ if (response . connectionType != null ) {
763
+ data .put ("connection_type" , response . connectionType );
719
764
}
720
765
}
721
766
case REGISTERED_COUNTRY_IN_EUROPEAN_UNION -> {
722
- Boolean isInEuropeanUnion = isInEuropeanUnion (registeredCountry );
723
- if (isInEuropeanUnion != null ) {
724
- data .put ("registered_country_in_european_union" , isInEuropeanUnion );
767
+ if (response .registeredCountryIsInEuropeanUnion != null ) {
768
+ data .put ("registered_country_in_european_union" , response .registeredCountryIsInEuropeanUnion );
725
769
}
726
770
}
727
771
case REGISTERED_COUNTRY_ISO_CODE -> {
728
- if (registeredCountry . getIsoCode () != null ) {
729
- data .put ("registered_country_iso_code" , registeredCountry . getIsoCode () );
772
+ if (response . registeredCountryIsoCode != null ) {
773
+ data .put ("registered_country_iso_code" , response . registeredCountryIsoCode );
730
774
}
731
775
}
732
776
case REGISTERED_COUNTRY_NAME -> {
733
- if (registeredCountry . getName () != null ) {
734
- data .put ("registered_country_name" , registeredCountry . getName () );
777
+ if (response . registeredCountryName != null ) {
778
+ data .put ("registered_country_name" , response . registeredCountryName );
735
779
}
736
780
}
737
781
}
0 commit comments