Skip to content

Commit

Permalink
Merge branch 'master' into translation_master
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-podolskiy90 authored Jan 28, 2025
2 parents 7b31f31 + 9902211 commit 68a347f
Show file tree
Hide file tree
Showing 34 changed files with 288 additions and 15 deletions.
2 changes: 1 addition & 1 deletion docs/translations/releases.adoc.pot
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2024-12-18 13:26+0000\n"
"POT-Creation-Date: 2024-12-18 16:49+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down
14 changes: 13 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<gbif-api.version>1.16.18</gbif-api.version>
<gbif-common.version>0.60</gbif-common.version>
<gbif-doi.version>2.21</gbif-doi.version>
<gbif-metadata-profile.version>2.6</gbif-metadata-profile.version>
<gbif-metadata-profile.version>2.7</gbif-metadata-profile.version>
<gbif-parsers.version>0.67</gbif-parsers.version>
<gbif-httputils.version>1.4</gbif-httputils.version>

Expand All @@ -63,11 +63,13 @@
<excel-streaming-reader.version>4.4.0</excel-streaming-reader.version>
<freemarker.version>2.3.33</freemarker.version>
<frictionless.datapackage-java.version>0.6.16.1-gbif</frictionless.datapackage-java.version>
<frictionless.tableschema-java.version>0.6.16.2-gbif</frictionless.tableschema-java.version>
<gson.version>2.11.0</gson.version>
<guava.version>20.0</guava.version>
<guice.version>4.2.3</guice.version>
<httpclient.version>4.5.14</httpclient.version>
<httpcore.version>4.4.16</httpcore.version>
<jackson.version>2.15.1</jackson.version> <!-- Fixed to the version used in tableschema-java -->
<jackson-dataformat-yaml.version>2.14.0</jackson-dataformat-yaml.version> <!-- Fixed to 2.14.0 for now because of issues with jackson-datatype-jts -->
<jackson-datatype-jts.version>2.14</jackson-datatype-jts.version>
<javassist.version>3.12.1.GA</javassist.version>
Expand Down Expand Up @@ -532,6 +534,11 @@
<artifactId>datapackage-java</artifactId>
<version>${frictionless.datapackage-java.version}</version>
</dependency>
<dependency>
<groupId>io.frictionlessdata</groupId>
<artifactId>tableschema-java</artifactId>
<version>${frictionless.tableschema-java.version}</version>
</dependency>

<!-- excel parsing -->
<dependency>
Expand Down Expand Up @@ -678,6 +685,11 @@
<artifactId>gson</artifactId>
<version>${gson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>

<!-- Annotations -->
<dependency>
Expand Down
4 changes: 4 additions & 0 deletions renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
{
"matchPackageNames": ["com.fasterxml.jackson.dataformat:jackson-dataformat-yaml"],
"automerge": false
},
{
"matchPackageNames": ["com.fasterxml.jackson.core:jackson-databind"],
"automerge": false
}
],
"ignorePaths": ["package/**", "docs/**"],
Expand Down
135 changes: 135 additions & 0 deletions src/main/java/org/gbif/ipt/action/manage/ResourceFileAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gbif.ipt.action.manage;

import org.gbif.ipt.config.AppConfig;
import org.gbif.ipt.config.Constants;
import org.gbif.ipt.config.DataDir;
import org.gbif.ipt.service.admin.RegistrationManager;
import org.gbif.ipt.service.manage.ResourceManager;
import org.gbif.ipt.struts2.SimpleTextProvider;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.google.inject.Inject;
import lombok.Getter;

/**
* The Action responsible for serving datadir resource files.
*/
public class ResourceFileAction extends ManagerBaseAction {

// logging
private static final Logger LOG = LogManager.getLogger(ResourceFileAction.class);

private static final long serialVersionUID = -3304799051086050164L;

private final DataDir dataDir;
@Getter
private InputStream inputStream;
@Getter
protected File data;
@Getter
protected String mimeType = "text/plain";
@Getter
protected String filename;

@Inject
public ResourceFileAction(SimpleTextProvider textProvider, AppConfig cfg, RegistrationManager registrationManager,
DataDir dataDir, ResourceManager resourceManager) {
super(textProvider, cfg, registrationManager, resourceManager);
this.dataDir = dataDir;
}

/**
* Handles metadata file download request.
*
* @return Struts2 result string
*/
public String metadata() {
if (resource == null) {
return NOT_FOUND;
}

boolean isDataPackageResource = resource.getDataPackageIdentifier() != null;
// construct download filename
StringBuilder sb = new StringBuilder();

// serve file
if (isDataPackageResource) {
if (Constants.COL_DP.equals(resource.getCoreType())) {
data = dataDir.resourceDatapackageMetadataFile(resource.getShortname(), resource.getCoreType());
mimeType = "text/yaml";
sb.append("metadata-").append(resource.getShortname());
sb.append(".yaml");
} else {
data = dataDir.resourceDatapackageMetadataFile(resource.getShortname(), resource.getCoreType());
mimeType = "application/json";
sb.append("datapackage-").append(resource.getShortname());
sb.append(".json");
}
} else {
data = dataDir.resourceEmlFile(resource.getShortname());
mimeType = "text/xml";
sb.append("eml-").append(resource.getShortname());
sb.append(".xml");
}

filename = sb.toString();
return execute();
}

@Override
public String execute() {
// make sure we have a download filename
if (data == null) {
return NOT_FOUND;
} else if (filename == null) {
filename = data.getName();
}
try {
inputStream = new FileInputStream(data);
// Set a Last-Modified header, even on 304 Not Modified responses.
// Round to the nearest second, as HTTP doesn't support milliseconds.
long lastModified = 1000 * ((data.lastModified() + 500) / 1000);
response.setDateHeader("Last-Modified", lastModified);

// see if we have a conditional get with If-Modified-Since header
try {
long since = req.getDateHeader("If-Modified-Since");
if (since >= lastModified) {
return NOT_MODIFIED;
}
} catch (IllegalArgumentException e) {
// headers might not be formed correctly, swallow
LOG.warn("Conditional get with If-Modified-Since header couldn't be interpreted", e);
}
} catch (FileNotFoundException e) {
LOG.warn("Data dir file not found", e);
return NOT_FOUND;
}
return SUCCESS;
}

@Override
public void prepare() {
super.prepare();
}
}
1 change: 1 addition & 0 deletions src/main/java/org/gbif/ipt/task/GenerateDataPackage.java
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,7 @@ private void addMetadata() throws GeneratorException, InterruptedException {
}

} catch (Exception e) {
addMessage(Level.ERROR, e.getMessage());
throw new GeneratorException("Problem occurred while adding metadata file to data package folder", e);
}
// final reporting
Expand Down
36 changes: 31 additions & 5 deletions src/main/java/org/gbif/ipt/validation/EmlValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ public void validate(BaseAction action, Resource resource, @Nullable MetadataSec

String strippedDescription = Optional.ofNullable(eml.getDescription())
.map(d -> d.replaceAll("<[^>]*>", "")) // get rid of tags
.map(d -> d.replace("&nbsp;", " ")) // replace &nbsp; with a space
.map(String::trim)
.orElse("");

Expand All @@ -251,7 +252,12 @@ public void validate(BaseAction action, Resource resource, @Nullable MetadataSec
} else {
try {
Eml stubValidationEml = getStubEml();
stubValidationEml.setDescription(eml.getDescription());

String descriptionWithNbspReplaced = Optional.ofNullable(eml.getDescription())
.map(d -> d.replace("&nbsp;", " ")) // replace &nbsp; with a space
.orElse("");

stubValidationEml.setDescription(descriptionWithNbspReplaced);
String emlString = IptEmlWriter.writeEmlAsString(stubValidationEml);
emlProfileValidator.validate(emlString);
} catch (InvalidEmlException e) {
Expand Down Expand Up @@ -541,7 +547,12 @@ public void validate(BaseAction action, Resource resource, @Nullable MetadataSec
} else {
try {
Eml stubValidationEml = getStubEml();
stubValidationEml.setAcknowledgements(eml.getAcknowledgements());

String acknowledgementsWithNbspReplaced = Optional.ofNullable(eml.getAcknowledgements())
.map(d -> d.replace("&nbsp;", " ")) // replace &nbsp; with a space
.orElse("");

stubValidationEml.setAcknowledgements(acknowledgementsWithNbspReplaced);
String emlString = IptEmlWriter.writeEmlAsString(stubValidationEml);
emlProfileValidator.validate(emlString);
} catch (InvalidEmlException e) {
Expand Down Expand Up @@ -713,7 +724,12 @@ public void validate(BaseAction action, Resource resource, @Nullable MetadataSec
} else {
try {
Eml stubValidationEml = getStubEml();
stubValidationEml.setGettingStarted(eml.getPurpose());

String purposeWithNbspReplaced = Optional.ofNullable(eml.getPurpose())
.map(d -> d.replace("&nbsp;", " ")) // replace &nbsp; with a space
.orElse("");

stubValidationEml.setGettingStarted(purposeWithNbspReplaced);
String emlString = IptEmlWriter.writeEmlAsString(stubValidationEml);
emlProfileValidator.validate(emlString);
} catch (InvalidEmlException e) {
Expand All @@ -725,7 +741,12 @@ public void validate(BaseAction action, Resource resource, @Nullable MetadataSec

try {
Eml stubValidationEml = getStubEml();
stubValidationEml.setGettingStarted(eml.getGettingStarted());

String gettingStartedWithNbspReplaced = Optional.ofNullable(eml.getGettingStarted())
.map(d -> d.replace("&nbsp;", " ")) // replace &nbsp; with a space
.orElse("");

stubValidationEml.setGettingStarted(gettingStartedWithNbspReplaced);
String emlString = IptEmlWriter.writeEmlAsString(stubValidationEml);
emlProfileValidator.validate(emlString);
} catch (InvalidEmlException e) {
Expand All @@ -737,7 +758,12 @@ public void validate(BaseAction action, Resource resource, @Nullable MetadataSec

try {
Eml stubValidationEml = getStubEml();
stubValidationEml.setIntroduction(eml.getIntroduction());

String introductionWithNbspReplaced = Optional.ofNullable(eml.getIntroduction())
.map(d -> d.replace("&nbsp;", " ")) // replace &nbsp; with a space
.orElse("");

stubValidationEml.setIntroduction(introductionWithNbspReplaced);
String emlString = IptEmlWriter.writeEmlAsString(stubValidationEml);
emlProfileValidator.validate(emlString);
} catch (InvalidEmlException e) {
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/ApplicationResources_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,6 @@ portal.resource.other=Other Metadata
portal.resource.spatial.coordinates=Coordinates
portal.resource.spatial.coordinatePrecision=Coordinate precision
portal.resource.taxonomic.taxonId=Taxon id
portal.resource.taxonomic.taxonIdReference=Taxon id reference
portal.resource.taxonomic.scientificName=Scientific name
portal.resource.taxonomic.taxonRank=Taxon rank
portal.resource.taxonomic.vernacularNames=Vernacular names
Expand Down
10 changes: 10 additions & 0 deletions src/main/resources/struts-manage.xml
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,16 @@
<result name="error" type="redirect">${baseURL}/manage/resource.do?r=${resource.shortname}</result>
</action>

<action name="eml" class="org.gbif.ipt.action.manage.ResourceFileAction" method="metadata">
<result name="success" type="stream">
<param name="contentType">${mimeType}</param>
<param name="contentCharSet">UTF-8</param>
<param name="inputName">inputStream</param>
<param name="contentDisposition">filename="${filename}"</param>
<param name="bufferSize">1024</param>
</result>
</action>

<action name="delete-mapping" class="org.gbif.ipt.action.manage.MappingAction" method="delete">
<result name="success" type="redirect">${baseURL}/manage/resource.do?r=${resource.shortname}</result>
<result name="error" type="redirect">${baseURL}/manage/resource.do?r=${resource.shortname}</result>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,8 @@
allowClear: true,
theme: 'bootstrap4'
});
makeSureResourceParameterIsPresentInURL('${resource.shortname}');
});
</script>
<#assign currentMenu="manage"/>
Expand All @@ -413,6 +415,8 @@
</div>

<form class="needs-validation" action="camtrap-metadata-${section}.do" method="post" novalidate>
<input type="hidden" name="r" value="${resource.shortname}" />

<div class="container-fluid bg-body border-bottom">
<div class="container bg-body border rounded-2 mb-4">
<div class="container my-3 p-3">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
$("#generateOn").show();
$("#generateOff").hide();
});
makeSureResourceParameterIsPresentInURL('${resource.shortname}');
});
</script>
<#assign currentMenu="manage"/>
Expand All @@ -50,6 +52,8 @@
</div>
<form class="needs-validation" action="camtrap-metadata-${section}.do" method="post" novalidate>
<input type="hidden" name="r" value="${resource.shortname}" />
<div class="container-fluid bg-body border-bottom">
<div class="container bg-body border rounded-2 mb-4">
<div class="container my-3 p-3">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
});
$("#re-infer-link").on('click', displayProcessing);
makeSureResourceParameterIsPresentInURL('${resource.shortname}');
});
</script>
<#assign currentMenu="manage"/>
Expand All @@ -87,6 +89,8 @@
</div>

<form id="geographic-scope-form" class="needs-validation" action="camtrap-metadata-${section}.do" method="post" novalidate>
<input type="hidden" name="r" value="${resource.shortname}" />

<div class="container-fluid bg-body border-bottom">
<div class="container bg-body border rounded-2 mb-4">
<div class="container my-3 p-3">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
// scroll to the element
$('body, html').animate({scrollTop: pos});
}
makeSureResourceParameterIsPresentInURL('${resource.shortname}');
});
</script>
<#assign currentMenu="manage"/>
Expand All @@ -85,6 +87,8 @@
</div>

<form class="needs-validation" action="camtrap-metadata-${section}.do" method="post" novalidate>
<input type="hidden" name="r" value="${resource.shortname}" />

<div class="container-fluid bg-body border-bottom">
<div class="container bg-body border rounded-2 mb-4">
<div class="container my-3 p-3">
Expand Down
Loading

0 comments on commit 68a347f

Please sign in to comment.