Skip to content

Commit

Permalink
Merge pull request #201 from socrata/rjm/licenses-refresh
Browse files Browse the repository at this point in the history
EN-44615: Load licenses from a JSON file rather than an enum
  • Loading branch information
rjmac authored Mar 11, 2021
2 parents d828ebf + ff688ea commit e95fa3d
Show file tree
Hide file tree
Showing 4 changed files with 204 additions and 28 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
bin/
doc/
misc/
target/
Expand Down
10 changes: 10 additions & 0 deletions bin/refresh-licenses
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh

set -e

REALPATH="$(env script="$0" python3 -c "import os; print(os.path.realpath(os.getenv('script')))")"
BASEDIR="$(dirname "$(dirname "$REALPATH")")"

cd "$BASEDIR"

curl https://opendata.socrata.com/api/licenses >src/main/resources/com/socrata/datasync/licenses.json
82 changes: 55 additions & 27 deletions src/main/java/com/socrata/datasync/LicenseType.java
Original file line number Diff line number Diff line change
@@ -1,39 +1,67 @@
package com.socrata.datasync;

public enum LicenseType {
no_license("-- No License --", ""), //this doesn't work, need to figure out what value is needed to remove a license. Tried "", "''", "null"

cc0_10("Creative Commons (CC) - 1.0 Universal", "CC0_10"),

cc_30_by_aus("CC - Attribution 3.0 Australia", "CC_30_BY_AUS"),

cc_30_by("CC - Attribution 3.0 Unported", "CC_30_BY"),

cc_30_by_nd("CC - Attribution | No Derivative Works 3.0 Unported", "CC_30_BY_ND"),

cc_30_by_nc("CC - Attribution | Noncommercial 3.0 Unported", "CC_30_BY_NC"),

cc_30_by_nc_nd("CC - Attribution | Noncommercial | No Derivative Works 3.0 Unported", "CC_30_BY_NC_ND"),

cc_30_by_nc_sa("CC - Attribution | Noncommercial | Share Alike 3.0 Unported", "CC_30_BY_NC_SA"),

cc_30_by_sa("CC - Share Alike 3.0 Unported", "CC_30_BY_SA"),

iodl("Italian Open Data License 2.0", "IODL"),

open_database_license("Open Database License", "OPEN_DATABASE_LICENSE"),

public_domain("Public Domain", "PUBLIC_DOMAIN");

import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

public final class LicenseType {
public static final LicenseType no_license = new LicenseType("-- No License --", ""); //this doesn't work, need to figure out what value is needed to remove a license. Tried "", "''", "null"

private static final List<LicenseType> values = loadLicenses();
public static List<LicenseType> values() {
return values;
}

private String label;
private String value;
private final String label;
private final String value;

private LicenseType(final String label, final String value) {
this.label = label;
this.value = value;
}

@JsonIgnoreProperties(ignoreUnknown=true)
private static class License {
@JsonProperty String id;
@JsonProperty String name;
}

private static List<LicenseType> loadLicenses() {
try(InputStream is = LicenseType.class.getResourceAsStream("licenses.json")) {
if(is == null) throw new FileNotFoundException("licenses.json");
ObjectMapper mapper = new ObjectMapper();

List<LicenseType> resourceLicenses = new ArrayList<>();
for(License l : mapper.<List<License>>readValue(new InputStreamReader(is, StandardCharsets.UTF_8),
new TypeReference<List<License>>() {})) {
resourceLicenses.add(new LicenseType(l.name, l.id));
}
resourceLicenses.sort(new Comparator<LicenseType>() {
public int compare(LicenseType a, LicenseType b) {
return a.getLabel().compareTo(b.getLabel());
}
});
List<LicenseType> result = new ArrayList<>();
result.add(no_license);
result.addAll(resourceLicenses);
return Collections.unmodifiableList(result);
} catch (IOException e) {
throw new RuntimeException("Failed to load licenses", e);
}
}


public String toString() {
return label;
}
Expand Down
139 changes: 139 additions & 0 deletions src/main/resources/com/socrata/datasync/licenses.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
[ {
"id" : "PUBLIC_DOMAIN",
"name" : "Public Domain"
}, {
"id" : "USGOV_WORKS",
"name" : "Public Domain U.S. Government",
"termsLink" : "https://www.usa.gov/government-works"
}, {
"id" : "CC_30_BY",
"name" : "Creative Commons Attribution 3.0 Unported",
"logoUrl" : "images/licenses/cc30by.png",
"termsLink" : "http://creativecommons.org/licenses/by/3.0/legalcode"
}, {
"id" : "OGL_CANADA",
"name" : "Canada Open Government Licence",
"termsLink" : "http://open.canada.ca/en/open-government-licence-canada"
}, {
"id" : "CC_40_BY_ND",
"name" : "Creative Commons Attribution | NoDerivatives 4.0 International License",
"logoUrl" : "images/licenses/cc40bynd.png",
"termsLink" : "http://creativecommons.org/licenses/by-nd/4.0/legalcode"
}, {
"id" : "CC_30_BY_NC_ND_IGO",
"name" : "Creative Commons Attribution | Noncommercial | No Derivative Works 3.0 IGO",
"termsLink" : "https://creativecommons.org/licenses/by-nc-nd/3.0/igo/legalcode"
}, {
"id" : "SEE_TERMS_OF_USE",
"name" : "See Terms of Use"
}, {
"id" : "NIST_SRD",
"name" : "National Institute of Standards and Technology Licensing",
"termsLink" : "http://www.nist.gov/data/license.cfm"
}, {
"id" : "IODL",
"name" : "Italian Open Data License 2.0",
"logoUrl" : "images/licenses/iodl.png",
"termsLink" : "http://www.dati.gov.it/iodl/2.0/"
}, {
"id" : "NBOGL",
"name" : "New Brunswick Open Government Licence"
}, {
"id" : "CC_30_BY_AUS",
"name" : "Creative Commons Attribution 3.0 Australia",
"logoUrl" : "images/licenses/cc30by.png",
"termsLink" : "http://creativecommons.org/licenses/by/3.0/au/deed.en"
}, {
"id" : "PDDL",
"name" : "Open Data Commons Public Domain Dedication and License",
"termsLink" : "http://opendatacommons.org/licenses/pddl/1.0/"
}, {
"id" : "OSODL",
"name" : "OS Open Data Licence",
"termsLink" : "http://www.ordnancesurvey.co.uk/docs/licences/os-opendata-licence.pdf"
}, {
"id" : "UK_OGLV3.0",
"name" : "UK Open Government Licence v3",
"logoUrl" : "images/licenses/ogl.png",
"termsLink" : "http://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/"
}, {
"id" : "CC0_10",
"name" : "Creative Commons 1.0 Universal (Public Domain Dedication)",
"logoUrl" : "images/licenses/ccZero.png",
"termsLink" : "http://creativecommons.org/publicdomain/zero/1.0/legalcode"
}, {
"id" : "CC_30_BY_SA",
"name" : "Creative Commons Attribution | Share Alike 3.0 Unported",
"logoUrl" : "images/licenses/cc30bysa.png",
"termsLink" : "http://creativecommons.org/licenses/by-sa/3.0/legalcode"
}, {
"id" : "CC_30_BY_ND",
"name" : "Creative Commons Attribution | No Derivative Works 3.0 Unported",
"logoUrl" : "images/licenses/cc30bynd.png",
"termsLink" : "http://creativecommons.org/licenses/by-nd/3.0/legalcode"
}, {
"id" : "CC_30_BY_NC",
"name" : "Creative Commons Attribution | Noncommercial 3.0 Unported",
"logoUrl" : "images/licenses/cc30bync.png",
"termsLink" : "http://creativecommons.org/licenses/by-nc/3.0/legalcode"
}, {
"id" : "CC_30_BY_NC_SA",
"name" : "Creative Commons Attribution | Noncommercial | Share Alike 3.0 Unported",
"logoUrl" : "images/licenses/cc30byncsa.png",
"termsLink" : "http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode"
}, {
"id" : "CC_30_BY_NC_ND",
"name" : "Creative Commons Attribution | Noncommercial | No Derivative Works 3.0 Unported",
"logoUrl" : "images/licenses/cc30byncnd.png",
"termsLink" : "http://creativecommons.org/licenses/by-nc-nd/3.0/legalcode"
}, {
"id" : "CC_40_BY",
"name" : "Creative Commons Attribution 4.0 International",
"logoUrl" : "images/licenses/cc30by.png",
"termsLink" : "http://creativecommons.org/licenses/by/4.0/legalcode"
}, {
"id" : "CC_40_BY_SA",
"name" : "Creative Commons Attribution | Share Alike 4.0 International",
"logoUrl" : "images/licenses/cc30bysa.png",
"termsLink" : "http://creativecommons.org/licenses/by-sa/4.0/legalcode"
}, {
"id" : "ODBL",
"name" : "Open Data Commons Open Database License",
"termsLink" : "http://opendatacommons.org/licenses/odbl/1.0/"
}, {
"id" : "ODC_BY",
"name" : "Open Data Commons Attribution License",
"termsLink" : "http://opendatacommons.org/licenses/by/1.0/"
}, {
"id" : "OPEN_DATABASE_LICENSE",
"name" : "Open Database License",
"termsLink" : "http://opendatacommons.org/licenses/odbl/1.0/"
}, {
"id" : "CC_30_BY_IGO",
"name" : "Creative Commons Attribution 3.0 IGO",
"logoUrl" : "images/licenses/cc30by.png",
"termsLink" : "https://creativecommons.org/licenses/by/3.0/igo/legalcode"
}, {
"id" : "CC_30_BY_NZ",
"name" : "Creative Commons Attribution 3.0 New Zealand",
"logoUrl" : "images/licenses/cc30by.png",
"termsLink" : "https://creativecommons.org/licenses/by/3.0/nz/legalcode"
}, {
"id" : "CC_30_BY_NC_NZ",
"name" : "Creative Commons Attribution | Noncommercial 3.0 New Zealand",
"logoUrl" : "images/licenses/cc30bync.png",
"termsLink" : "https://creativecommons.org/licenses/by-nc/3.0/nz/legalcode"
}, {
"id" : "CC_30_BY_NC_SA_NZ",
"name" : "Creative Commons Attribution | Noncommercial | Share Alike 3.0 New Zealand",
"logoUrl" : "images/licenses/cc30byncsa.png",
"termsLink" : "https://creativecommons.org/licenses/by-nc-sa/3.0/nz/legalcode"
}, {
"id" : "OGL_NOVA_SCOTIA",
"name" : "Nova Scotia Open Government Licence",
"termsLink" : "http://novascotia.ca/opendata/licence.asp"
}, {
"id" : "OGL-PEI",
"name" : "Open Government Licence - Prince Edward Island",
"termsLink" : "https://www.princeedwardisland.ca/en/information/finance/open-government-licence-prince-edward-island"
} ]

0 comments on commit e95fa3d

Please sign in to comment.