Changeset 15082 in josm for trunk/scripts
- Timestamp:
- 2019-05-18T15:17:37+02:00 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/scripts/SyncEditorLayerIndex.java
r15037 r15082 28 28 import java.util.Map.Entry; 29 29 import java.util.Objects; 30 import java.util.Set; 31 import java.util.function.Function; 30 32 import java.util.regex.Matcher; 31 33 import java.util.regex.Pattern; … … 720 722 ImageryInfo j = josmUrls.get(url); 721 723 722 String et = getDescriptions(e).getOrDefault("en", ""); 723 String jt = getDescriptions(j).getOrDefault("en", ""); 724 if (!et.equals(jt)) { 725 if (jt.isEmpty()) { 726 myprintln("- Missing JOSM description ("+et+"): "+getDescription(j)); 727 } else if (!et.isEmpty()) { 728 myprintln("* Description differs ('"+et+"' != '"+jt+"'): "+getDescription(j)); 729 } else if (!optionNoEli) { 730 myprintln("+ Missing ELI description ('"+jt+"'): "+getDescription(j)); 731 } 732 } 733 734 et = getPermissionReferenceUrl(e); 735 jt = getPermissionReferenceUrl(j); 736 String jt2 = getTermsOfUseUrl(j); 737 if (isBlank(jt)) jt = jt2; 738 if (!Objects.equals(et, jt)) { 739 if (isBlank(jt)) { 740 myprintln("- Missing JOSM license URL ("+et+"): "+getDescription(j)); 741 } else if (isNotBlank(et)) { 742 String ethttps = et.replace("http:", "https:"); 743 if (isBlank(jt2) || !(jt2.equals(ethttps) || jt2.equals(et+"/") || jt2.equals(ethttps+"/"))) { 744 if (jt.equals(ethttps) || jt.equals(et+"/") || jt.equals(ethttps+"/")) { 745 myprintln("+ License URL differs ('"+et+"' != '"+jt+"'): "+getDescription(j)); 724 compareDescriptions(e, j); 725 comparePermissionReferenceUrls(e, j); 726 compareAttributionUrls(e, j); 727 compareAttributionTexts(e, j); 728 compareProjections(e, j); 729 compareDefaults(e, j); 730 compareOverlays(e, j); 731 compareNoTileHeaders(e, j); 732 } 733 } 734 735 void compareDescriptions(JsonObject e, ImageryInfo j) throws IOException { 736 String et = getDescriptions(e).getOrDefault("en", ""); 737 String jt = getDescriptions(j).getOrDefault("en", ""); 738 if (!et.equals(jt)) { 739 if (jt.isEmpty()) { 740 myprintln("- Missing JOSM description ("+et+"): "+getDescription(j)); 741 } else if (!et.isEmpty()) { 742 myprintln("* Description differs ('"+et+"' != '"+jt+"'): "+getDescription(j)); 743 } else if (!optionNoEli) { 744 myprintln("+ Missing ELI description ('"+jt+"'): "+getDescription(j)); 745 } 746 } 747 } 748 749 void comparePermissionReferenceUrls(JsonObject e, ImageryInfo j) throws IOException { 750 String et = getPermissionReferenceUrl(e); 751 String jt = getPermissionReferenceUrl(j); 752 String jt2 = getTermsOfUseUrl(j); 753 if (isBlank(jt)) jt = jt2; 754 if (!Objects.equals(et, jt)) { 755 if (isBlank(jt)) { 756 myprintln("- Missing JOSM license URL ("+et+"): "+getDescription(j)); 757 } else if (isNotBlank(et)) { 758 String ethttps = et.replace("http:", "https:"); 759 if (isBlank(jt2) || !(jt2.equals(ethttps) || jt2.equals(et+"/") || jt2.equals(ethttps+"/"))) { 760 if (jt.equals(ethttps) || jt.equals(et+"/") || jt.equals(ethttps+"/")) { 761 myprintln("+ License URL differs ('"+et+"' != '"+jt+"'): "+getDescription(j)); 762 } else { 763 String ja = getAttributionUrl(j); 764 if (ja != null && (ja.equals(et) || ja.equals(ethttps) || ja.equals(et+"/") || ja.equals(ethttps+"/"))) { 765 myprintln("+ ELI License URL in JOSM Attribution: "+getDescription(j)); 746 766 } else { 747 String ja = getAttributionUrl(j); 748 if (ja != null && (ja.equals(et) || ja.equals(ethttps) || ja.equals(et+"/") || ja.equals(ethttps+"/"))) { 749 myprintln("+ ELI License URL in JOSM Attribution: "+getDescription(j)); 750 } else { 751 myprintln("* License URL differs ('"+et+"' != '"+jt+"'): "+getDescription(j)); 752 } 767 myprintln("* License URL differs ('"+et+"' != '"+jt+"'): "+getDescription(j)); 753 768 } 754 769 } 755 } else if (!optionNoEli) { 756 myprintln("+ Missing ELI license URL ('"+jt+"'): "+getDescription(j)); 757 } 758 } 759 760 et = getAttributionUrl(e); 761 jt = getAttributionUrl(j); 762 if (!Objects.equals(et, jt)) { 763 if (isBlank(jt)) { 764 myprintln("- Missing JOSM attribution URL ("+et+"): "+getDescription(j)); 765 } else if (isNotBlank(et)) { 766 String ethttps = et.replace("http:", "https:"); 767 if (jt.equals(ethttps) || jt.equals(et+"/") || jt.equals(ethttps+"/")) { 768 myprintln("+ Attribution URL differs ('"+et+"' != '"+jt+"'): "+getDescription(j)); 769 } else { 770 myprintln("* Attribution URL differs ('"+et+"' != '"+jt+"'): "+getDescription(j)); 771 } 772 } else if (!optionNoEli) { 773 myprintln("+ Missing ELI attribution URL ('"+jt+"'): "+getDescription(j)); 774 } 775 } 776 777 et = getAttributionText(e); 778 jt = getAttributionText(j); 779 if (!Objects.equals(et, jt)) { 780 if (isBlank(jt)) { 781 myprintln("- Missing JOSM attribution text ("+et+"): "+getDescription(j)); 782 } else if (isNotBlank(et)) { 783 myprintln("* Attribution text differs ('"+et+"' != '"+jt+"'): "+getDescription(j)); 784 } else if (!optionNoEli) { 785 myprintln("+ Missing ELI attribution text ('"+jt+"'): "+getDescription(j)); 786 } 787 } 788 789 et = getProjections(e).stream().sorted().collect(Collectors.joining(" ")); 790 jt = getProjections(j).stream().sorted().collect(Collectors.joining(" ")); 791 if (!Objects.equals(et, jt)) { 792 if (isBlank(jt)) { 793 String t = getType(e); 794 if ("wms_endpoint".equals(t) || "tms".equals(t)) { 795 myprintln("+ ELI projections for type "+t+": "+getDescription(j)); 796 } else { 797 myprintln("- Missing JOSM projections ("+et+"): "+getDescription(j)); 798 } 799 } else if (isNotBlank(et)) { 800 if ("EPSG:3857 EPSG:4326".equals(et) || "EPSG:3857".equals(et) || "EPSG:4326".equals(et)) { 801 myprintln("+ ELI has minimal projections ('"+et+"' != '"+jt+"'): "+getDescription(j)); 802 } else { 803 myprintln("* Projections differ ('"+et+"' != '"+jt+"'): "+getDescription(j)); 804 } 805 } else if (!optionNoEli && !"tms".equals(getType(e))) { 806 myprintln("+ Missing ELI projections ('"+jt+"'): "+getDescription(j)); 807 } 808 } 809 810 boolean ed = getDefault(e); 811 boolean jd = getDefault(j); 812 if (ed != jd) { 813 if (!jd) { 814 myprintln("- Missing JOSM default: "+getDescription(j)); 815 } else if (!optionNoEli) { 816 myprintln("+ Missing ELI default: "+getDescription(j)); 817 } 818 } 819 boolean eo = getOverlay(e); 820 boolean jo = getOverlay(j); 821 if (eo != jo) { 822 if (!jo) { 823 myprintln("- Missing JOSM overlay flag: "+getDescription(j)); 824 } else if (!optionNoEli) { 825 myprintln("+ Missing ELI overlay flag: "+getDescription(j)); 826 } 770 } 771 } else if (!optionNoEli) { 772 myprintln("+ Missing ELI license URL ('"+jt+"'): "+getDescription(j)); 773 } 774 } 775 } 776 777 void compareAttributionUrls(JsonObject e, ImageryInfo j) throws IOException { 778 String et = getAttributionUrl(e); 779 String jt = getAttributionUrl(j); 780 if (!Objects.equals(et, jt)) { 781 if (isBlank(jt)) { 782 myprintln("- Missing JOSM attribution URL ("+et+"): "+getDescription(j)); 783 } else if (isNotBlank(et)) { 784 String ethttps = et.replace("http:", "https:"); 785 if (jt.equals(ethttps) || jt.equals(et+"/") || jt.equals(ethttps+"/")) { 786 myprintln("+ Attribution URL differs ('"+et+"' != '"+jt+"'): "+getDescription(j)); 787 } else { 788 myprintln("* Attribution URL differs ('"+et+"' != '"+jt+"'): "+getDescription(j)); 789 } 790 } else if (!optionNoEli) { 791 myprintln("+ Missing ELI attribution URL ('"+jt+"'): "+getDescription(j)); 792 } 793 } 794 } 795 796 void compareAttributionTexts(JsonObject e, ImageryInfo j) throws IOException { 797 String et = getAttributionText(e); 798 String jt = getAttributionText(j); 799 if (!Objects.equals(et, jt)) { 800 if (isBlank(jt)) { 801 myprintln("- Missing JOSM attribution text ("+et+"): "+getDescription(j)); 802 } else if (isNotBlank(et)) { 803 myprintln("* Attribution text differs ('"+et+"' != '"+jt+"'): "+getDescription(j)); 804 } else if (!optionNoEli) { 805 myprintln("+ Missing ELI attribution text ('"+jt+"'): "+getDescription(j)); 806 } 807 } 808 } 809 810 void compareProjections(JsonObject e, ImageryInfo j) throws IOException { 811 String et = getProjections(e).stream().sorted().collect(Collectors.joining(" ")); 812 String jt = getProjections(j).stream().sorted().collect(Collectors.joining(" ")); 813 if (!Objects.equals(et, jt)) { 814 if (isBlank(jt)) { 815 String t = getType(e); 816 if ("wms_endpoint".equals(t) || "tms".equals(t)) { 817 myprintln("+ ELI projections for type "+t+": "+getDescription(j)); 818 } else { 819 myprintln("- Missing JOSM projections ("+et+"): "+getDescription(j)); 820 } 821 } else if (isNotBlank(et)) { 822 if ("EPSG:3857 EPSG:4326".equals(et) || "EPSG:3857".equals(et) || "EPSG:4326".equals(et)) { 823 myprintln("+ ELI has minimal projections ('"+et+"' != '"+jt+"'): "+getDescription(j)); 824 } else { 825 myprintln("* Projections differ ('"+et+"' != '"+jt+"'): "+getDescription(j)); 826 } 827 } else if (!optionNoEli && !"tms".equals(getType(e))) { 828 myprintln("+ Missing ELI projections ('"+jt+"'): "+getDescription(j)); 829 } 830 } 831 } 832 833 void compareDefaults(JsonObject e, ImageryInfo j) throws IOException { 834 boolean ed = getDefault(e); 835 boolean jd = getDefault(j); 836 if (ed != jd) { 837 if (!jd) { 838 myprintln("- Missing JOSM default: "+getDescription(j)); 839 } else if (!optionNoEli) { 840 myprintln("+ Missing ELI default: "+getDescription(j)); 841 } 842 } 843 } 844 845 void compareOverlays(JsonObject e, ImageryInfo j) throws IOException { 846 boolean eo = getOverlay(e); 847 boolean jo = getOverlay(j); 848 if (eo != jo) { 849 if (!jo) { 850 myprintln("- Missing JOSM overlay flag: "+getDescription(j)); 851 } else if (!optionNoEli) { 852 myprintln("+ Missing ELI overlay flag: "+getDescription(j)); 853 } 854 } 855 } 856 857 void compareNoTileHeaders(JsonObject e, ImageryInfo j) throws IOException { 858 Map<String, Set<String>> eh = getNoTileHeader(e); 859 Map<String, Set<String>> jh = getNoTileHeader(j); 860 if (!Objects.equals(eh, jh)) { 861 if (jh == null || jh.isEmpty()) { 862 myprintln("- Missing JOSM no tile headers ("+eh+"): "+getDescription(j)); 863 } else if (eh != null && !eh.isEmpty()) { 864 myprintln("* No tile headers differ ('"+eh+"' != '"+jh+"'): "+getDescription(j)); 865 } else if (!optionNoEli) { 866 myprintln("+ Missing ELI no tile headers ('"+jh+"'): "+getDescription(j)); 827 867 } 828 868 } … … 1335 1375 } 1336 1376 1377 static Map<String, Set<String>> getNoTileHeader(Object e) { 1378 if (e instanceof ImageryInfo) return ((ImageryInfo) e).getNoTileHeaders(); 1379 JsonObject nth = ((Map<String, JsonObject>) e).get("properties").getJsonObject("no_tile_header"); 1380 return nth == null ? null : nth.keySet().stream().collect(Collectors.toMap( 1381 Function.identity(), 1382 k -> nth.getJsonArray(k).stream().map(x -> ((JsonString) x).getString()).collect(Collectors.toSet()))); 1383 } 1384 1337 1385 static Map<String, String> getDescriptions(Object e) { 1338 Map<String, String> res = new HashMap< String, String>();1386 Map<String, String> res = new HashMap<>(); 1339 1387 if (e instanceof ImageryInfo) { 1340 1388 String a = ((ImageryInfo) e).getDescription();
Note:
See TracChangeset
for help on using the changeset viewer.