Skip to content

Commit

Permalink
Release 1.0.0 (develop) (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarekSuchanek authored Jan 20, 2020
1 parent 59572d6 commit e5eef27
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 57 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.0.0]

Initial version based on reproducing functionality of deprecated [FAIRifier](https://github.com/FAIRDataTeam/FAIRifier).

### Added
Expand All @@ -21,3 +23,6 @@ Initial version based on reproducing functionality of deprecated [FAIRifier](htt
supports: FTP, Virtuoso, and Triple Stores with HTTP API
- About dialog with basic information about the extension and its compatibility
- Report a bug link to create a GitHub issue easily

[Unreleased]: /../../compare/v1.0.0...develop
[1.0.0]: /../../tree/v1.0.0
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

<groupId>solutions.fairdata.openrefine</groupId>
<artifactId>metadata</artifactId>
<version>0.1.0-SNAPSHOT</version>
<version>1.0.0</version>
<packaging>jar</packaging>

<name>OpenRefine - FAIR Metadata extension</name>
Expand Down Expand Up @@ -137,6 +137,7 @@
<groupId>org.eclipse.rdf4j</groupId>
<artifactId>rdf4j-rio-turtle</artifactId>
<version>${rdf4j.version}</version>
<scope>runtime</scope>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@
import nl.dtl.fairmetadata4j.model.DistributionMetadata;
import nl.dtl.fairmetadata4j.model.FDPMetadata;
import nl.dtl.fairmetadata4j.utils.MetadataUtils;
import org.apache.http.HttpHeaders;
import org.eclipse.rdf4j.model.Statement;
import org.eclipse.rdf4j.model.impl.SimpleValueFactory;
import org.eclipse.rdf4j.rio.RDFFormat;
import org.eclipse.rdf4j.rio.RDFParser;
import org.eclipse.rdf4j.rio.Rio;
import org.eclipse.rdf4j.rio.helpers.StatementCollector;
import org.eclipse.rdf4j.rio.turtle.TurtleParser;

import java.io.BufferedReader;
import java.io.BufferedWriter;
Expand Down Expand Up @@ -84,12 +86,15 @@ public class FairDataPointClient {
308 // HTTP Permanent Redirect
));

private static final String CATALOG_PART = "/catalog";
private static final String DATASET_PART = "/dataset";
private static final String DISTRIBUTION_PART = "/distribution";
private static final String SPEC_PART = "/spec";
private static final String AUTH_PART = "/tokens";;
private static final String DASHBOARD_PART = "/dashboard";
private static final String CATALOG_PART = "catalog";
private static final String DATASET_PART = "dataset";
private static final String DISTRIBUTION_PART = "distribution";
private static final String SPEC_PART = "spec";
private static final String AUTH_PART = "tokens";
private static final String DASHBOARD_PART = "dashboard";

private static final String MEDIA_TYPE_JSON = "application/json";
private static final String MEDIA_TYPE_TURTLE = "text/turtle";

private static final String USER_AGENT = MetadataModuleImpl.USER_AGENT;

Expand All @@ -116,8 +121,8 @@ public FairDataPointClient(String fdpBaseURI, String token, Logger logger) {
* @throws FairDataPointException in case that FDP responds with an unexpected code
*/
public TokenDTO postAuthentication(AuthDTO auth) throws IOException, FairDataPointException {
HttpURLConnection conn = createConnection(fdpBaseURI + AUTH_PART, "POST", "application/json");
conn.addRequestProperty("Content-Type", "application/json; utf-8");
HttpURLConnection conn = createConnection(url(fdpBaseURI, AUTH_PART), "POST", MEDIA_TYPE_JSON);
conn.addRequestProperty(HttpHeaders.CONTENT_TYPE, MEDIA_TYPE_JSON);
conn.setDoOutput(true);
objectMapper.writeValue(conn.getOutputStream(), auth);

Expand All @@ -136,7 +141,7 @@ public TokenDTO postAuthentication(AuthDTO auth) throws IOException, FairDataPoi
* @throws FairDataPointException in case that FDP responds with an unexpected code
*/
public List<DashboardCatalogDTO> getDashboard() throws IOException, FairDataPointException {
HttpURLConnection conn = request(fdpBaseURI + DASHBOARD_PART, "GET", "application/json", true);
HttpURLConnection conn = request(url(fdpBaseURI,DASHBOARD_PART), "GET", MEDIA_TYPE_JSON, true);

if(conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
return objectMapper.readValue(conn.getInputStream(), new TypeReference<List<DashboardCatalogDTO>>(){});
Expand All @@ -153,7 +158,7 @@ public List<DashboardCatalogDTO> getDashboard() throws IOException, FairDataPoin
* @throws FairDataPointException in case that FDP responds with an unexpected code
*/
public FDPMetadataDTO getFairDataPointMetadata() throws IOException, FairDataPointException {
HttpURLConnection conn = request(fdpBaseURI, "GET", "text/turtle", true);
HttpURLConnection conn = request(fdpBaseURI, "GET", MEDIA_TYPE_TURTLE, true);

if(conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
String actualURI = conn.getURL().toString();
Expand All @@ -178,7 +183,7 @@ public FDPMetadataDTO getFairDataPointMetadata() throws IOException, FairDataPoi
* @throws FairDataPointException in case that FDP responds with an unexpected code
*/
public CatalogDTO getCatalogMetadata(String catalogURI) throws IOException, FairDataPointException {
HttpURLConnection conn = request(catalogURI, "GET", "text/turtle", true);
HttpURLConnection conn = request(catalogURI, "GET", MEDIA_TYPE_TURTLE, true);

if(conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
String actualURI = conn.getURL().toString();
Expand All @@ -203,7 +208,7 @@ public CatalogDTO getCatalogMetadata(String catalogURI) throws IOException, Fair
* @throws FairDataPointException in case that FDP responds with an unexpected code
*/
public DatasetDTO getDatasetMetadata(String datasetURI) throws IOException, FairDataPointException {
HttpURLConnection conn = request(datasetURI, "GET", "text/turtle", true);
HttpURLConnection conn = request(datasetURI, "GET", MEDIA_TYPE_TURTLE, true);

if(conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
String actualURI = conn.getURL().toString();
Expand All @@ -228,7 +233,7 @@ public DatasetDTO getDatasetMetadata(String datasetURI) throws IOException, Fair
* @throws FairDataPointException in case that FDP responds with an unexpected code
*/
public DistributionDTO getDistributionMetadata(String distributionURI) throws IOException, FairDataPointException {
HttpURLConnection conn = request(distributionURI, "GET", "text/turtle", true);
HttpURLConnection conn = request(distributionURI, "GET", MEDIA_TYPE_TURTLE, true);

if(conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
String actualURI = conn.getURL().toString();
Expand Down Expand Up @@ -289,7 +294,7 @@ public Object getDistributionSpec() throws IOException, FairDataPointException {
* @throws FairDataPointException in case that FDP responds with an unexpected code
*/
private Object getMetadataSpec(String metadataPart) throws IOException, FairDataPointException {
HttpURLConnection conn = request(fdpBaseURI + metadataPart + SPEC_PART, "GET", "application/json", true);
HttpURLConnection conn = request(url(fdpBaseURI, metadataPart, SPEC_PART), "GET", MEDIA_TYPE_JSON, true);

if(conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
return objectMapper.readValue(conn.getInputStream(), Object.class);
Expand All @@ -307,12 +312,12 @@ private Object getMetadataSpec(String metadataPart) throws IOException, FairData
* @throws FairDataPointException in case that FDP responds with an unexpected code
*/
public CatalogDTO postCatalog(CatalogDTO catalogDTO) throws IOException, MetadataException, FairDataPointException {
HttpURLConnection conn = createConnection(fdpBaseURI + CATALOG_PART, "POST", "text/turtle");
conn.addRequestProperty("Content-Type", "text/turtle");
HttpURLConnection conn = createConnection(fdpBaseURI + CATALOG_PART, "POST", MEDIA_TYPE_TURTLE);
conn.addRequestProperty(HttpHeaders.CONTENT_TYPE, MEDIA_TYPE_TURTLE);
conn.setDoOutput(true);

// Generate random IRI, FDP will replace it with really unique
String uri = fdpBaseURI + "/fdp/catalog/" + UUID.randomUUID();
String uri = url(fdpBaseURI, CATALOG_PART, UUID.randomUUID().toString());
catalogDTO.setIri(uri);

CatalogMetadata catalogMetadata = CatalogTransformerUtils.dto2Metadata(catalogDTO);
Expand All @@ -326,7 +331,7 @@ public CatalogDTO postCatalog(CatalogDTO catalogDTO) throws IOException, Metadat
bw.close();

if(conn.getResponseCode() == HttpURLConnection.HTTP_CREATED) {
String actualURI = conn.getHeaderField("Location");
String actualURI = conn.getHeaderField(HttpHeaders.LOCATION);
CatalogMetadataParser catalogMetadataParser = new CatalogMetadataParser();

CatalogMetadata returnCatalogMetadata = catalogMetadataParser.parse(
Expand All @@ -348,12 +353,12 @@ public CatalogDTO postCatalog(CatalogDTO catalogDTO) throws IOException, Metadat
* @throws FairDataPointException in case that FDP responds with an unexpected code
*/
public DatasetDTO postDataset(DatasetDTO datasetDTO) throws IOException, MetadataException, FairDataPointException {
HttpURLConnection conn = createConnection(fdpBaseURI + DATASET_PART, "POST", "text/turtle");
conn.addRequestProperty("Content-Type", "text/turtle");
HttpURLConnection conn = createConnection(fdpBaseURI + DATASET_PART, "POST", MEDIA_TYPE_TURTLE);
conn.addRequestProperty(HttpHeaders.CONTENT_TYPE, MEDIA_TYPE_TURTLE);
conn.setDoOutput(true);

// Generate random IRI, FDP will replace it with really unique
String uri = fdpBaseURI + "/fdp/dataset/" + UUID.randomUUID();
String uri = url(fdpBaseURI, DATASET_PART, UUID.randomUUID().toString());
datasetDTO.setIri(uri);

DatasetMetadata datasetMetadata = DatasetTransformerUtils.dto2Metadata(datasetDTO);
Expand All @@ -367,7 +372,7 @@ public DatasetDTO postDataset(DatasetDTO datasetDTO) throws IOException, Metadat
bw.close();

if(conn.getResponseCode() == HttpURLConnection.HTTP_CREATED) {
String actualURI = conn.getHeaderField("Location");
String actualURI = conn.getHeaderField(HttpHeaders.LOCATION);
DatasetMetadataParser datasetMetadataParser = new DatasetMetadataParser();

DatasetMetadata returnDatasetMetadata = datasetMetadataParser.parse(
Expand All @@ -389,12 +394,12 @@ public DatasetDTO postDataset(DatasetDTO datasetDTO) throws IOException, Metadat
* @throws FairDataPointException in case that FDP responds with an unexpected code
*/
public DistributionDTO postDistribution(DistributionDTO distributionDTO) throws IOException, MetadataException, FairDataPointException {
HttpURLConnection conn = createConnection(fdpBaseURI + DISTRIBUTION_PART, "POST", "text/turtle");
conn.addRequestProperty("Content-Type", "text/turtle");
HttpURLConnection conn = createConnection(url(fdpBaseURI, DISTRIBUTION_PART), "POST", MEDIA_TYPE_TURTLE);
conn.addRequestProperty(HttpHeaders.CONTENT_TYPE, MEDIA_TYPE_TURTLE);
conn.setDoOutput(true);

// Generate random IRI, FDP will replace it with really unique
String uri = fdpBaseURI + "/fdp/distribution/" + UUID.randomUUID();
String uri = url(fdpBaseURI, DISTRIBUTION_PART, UUID.randomUUID().toString());
distributionDTO.setIri(uri);

DistributionMetadata distributionMetadata = DistributionTransformerUtils.dto2Metadata(distributionDTO);
Expand All @@ -408,7 +413,7 @@ public DistributionDTO postDistribution(DistributionDTO distributionDTO) throws
bw.close();

if(conn.getResponseCode() == HttpURLConnection.HTTP_CREATED) {
String actualURI = conn.getHeaderField("Location");
String actualURI = conn.getHeaderField(HttpHeaders.LOCATION);
DistributionMetadataParser distributionMetadataParser = new DistributionMetadataParser();

DistributionMetadata returnDistributionMetadata = distributionMetadataParser.parse(
Expand All @@ -430,7 +435,7 @@ public DistributionDTO postDistribution(DistributionDTO distributionDTO) throws
* @throws IOException in case of communication error with FDP
*/
private ArrayList<Statement> parseStatements(HttpURLConnection conn, String uri) throws IOException {
TurtleParser parser = new TurtleParser();
RDFParser parser = Rio.createParser(RDFFormat.TURTLE);
StatementCollector collector = new StatementCollector();
parser.setRDFHandler(collector);

Expand All @@ -450,10 +455,12 @@ private ArrayList<Statement> parseStatements(HttpURLConnection conn, String uri)
private HttpURLConnection createConnection(String url, String method, String accept) throws IOException {
HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
conn.setRequestMethod(method);
conn.addRequestProperty("Accept", accept);
conn.addRequestProperty("User-Agent", USER_AGENT);
conn.addRequestProperty(HttpHeaders.ACCEPT, accept);
conn.addRequestProperty(HttpHeaders.USER_AGENT, USER_AGENT);
conn.addRequestProperty(HttpHeaders.CONTENT_ENCODING, StandardCharsets.UTF_8.displayName());

if (token != null) {
conn.addRequestProperty("Authorization", "Bearer " + token);
conn.addRequestProperty(HttpHeaders.AUTHORIZATION, "Bearer " + token);
}
return conn;
}
Expand All @@ -480,7 +487,7 @@ private HttpURLConnection request(String url, String method, String accept, bool
visited.add(url);

while (REDIRECTS.contains(conn.getResponseCode())) {
String nextUrl = conn.getHeaderField("Location");
String nextUrl = conn.getHeaderField(HttpHeaders.LOCATION);
String cookies = conn.getHeaderField("Set-Cookie");

logger.info("HTTP request (caused by redirect) to " + nextUrl);
Expand All @@ -499,4 +506,12 @@ private HttpURLConnection request(String url, String method, String accept, bool
}
return conn;
}

public static String url(String base, String ... fragment) {
StringBuilder sb = new StringBuilder(base);
for (String f: fragment) {
sb.append("/").append(f);
}
return sb.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

public class TripleStoreHTTPStorage extends Storage {

Expand All @@ -39,9 +41,12 @@ public class TripleStoreHTTPStorage extends Storage {
private final HTTPRepository repository;

static {
formats.put("application/x-turtle", RDFFormat.TURTLE);
formats.put("text/turtle", RDFFormat.TURTLE);
formats.put("application/rdf+xml", RDFFormat.RDFXML);
List<RDFFormat> rdfFormats = Arrays.asList(RDFFormat.TURTLE, RDFFormat.RDFXML);
for (RDFFormat rdfFormat: rdfFormats) {
for (String mimeType: rdfFormat.getMIMETypes()) {
formats.put(mimeType, rdfFormat);
}
}
}

public TripleStoreHTTPStorage(StorageDTO storageDTO) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/module/MOD-INF/controller.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Main JS file for FAIR Metadata extension of OpenRefine
*/
/* global importPackage, module, Packages, ClientSideResourceManager */
/* global importPackage, Packages, ClientSideResourceManager */
/* eslint-disable no-unused-vars */

function init() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/module/scripts/api-client.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global $, MetadataHelpers */
/* global MetadataHelpers */

class MetadataApiClient {

Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/module/scripts/dialogs/about-dialog.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<dt data-i18n="about-dialog/version"></dt>
<dd>
<div class="version"><a href="https://github.com/FAIRDataTeam/OpenRefine-metadata-extension/releases" target="_blank">X.Y.Z</a></div>
<div class="version"><a href="https://github.com/FAIRDataTeam/OpenRefine-metadata-extension/releases/tag/v1.0.0" target="_blank">1.0.0</a></div>
</dd>

<dt data-i18n="about-dialog/license"></dt>
Expand All @@ -37,7 +37,7 @@
<dt data-i18n="about-dialog/authors"></dt>
<dd>
<ul class="authors">
<li class="author">Marek Suchánek (<a href="https://github.com/MarekSuchanek">@MarekSuchanek</a>&raquo)</li>
<li class="author">Marek Suchánek (<a href="https://github.com/MarekSuchanek">@MarekSuchanek</a>)</li>
</ul>
</dd>

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/module/scripts/dialogs/about-dialog.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global $, DOM, DialogSystem */
/* global DOM, DialogSystem */

class MetadataAboutDialog {
constructor(type, specs, callbackFn, prefill) {
Expand Down
27 changes: 17 additions & 10 deletions src/main/resources/module/scripts/dialogs/metadata-form-dialog.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global $, DOM, DialogSystem, Refine, MetadataApiClient, StoreDataDialog */
/* global DOM, DialogSystem, Refine, MetadataApiClient, StoreDataDialog */

class MetadataFormDialog {
constructor(specs, callbackFn, prefill) {
Expand Down Expand Up @@ -65,7 +65,7 @@ class MetadataFormDialog {

setValue(fieldId, value) {
const input = this.elements.metadataForm.find(`#${fieldId}`);
if (input != null) {
if (input !== null) {
if (input.is(":radio") && value === true) {
input.prop("checked", true);
} else {
Expand Down Expand Up @@ -226,24 +226,31 @@ class MetadataFormDialog {
});
}

makeInputField(field) {
const input = $(field.type === "text" ? "<textarea>" : "<input>")
.attr("id", field.id)
.attr("name", field.id)
.attr("type", "text")
.attr("title", $.i18n(`metadata/${this.specs.id}/${field.id}/description`))
.prop("required", field.required);

handleInputType(field, input) {
if (field.hidden) {
input.attr("type", "hidden");
} else if (field.type === "iri") {
input
.attr("type", "uri")
.attr("placeholder", "http://");
}
}

handleTypehints(field, input) {
if (field.typehints) {
this.makeDataList(field, input);
}
}

makeInputField(field) {
let input = $(field.type === "text" ? "<textarea>" : "<input>")
.attr("id", field.id)
.attr("name", field.id)
.attr("type", "text")
.attr("title", $.i18n(`metadata/${this.specs.id}/${field.id}/description`))
.prop("required", field.required);
this.handleInputType(field, input);
this.handleTypehints(field, input);
return input;
}

Expand Down
Loading

0 comments on commit e5eef27

Please sign in to comment.