Skip to content

Commit

Permalink
Merge branch 'eml-2.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-podolskiy90 committed Oct 9, 2024
2 parents 31def6d + 16db625 commit d42e9e3
Show file tree
Hide file tree
Showing 43 changed files with 5,701 additions and 1,744 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</parent>

<artifactId>ipt</artifactId>
<version>3.0.7-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
<packaging>war</packaging>

<name>IPT</name>
Expand Down Expand Up @@ -43,7 +43,7 @@
<gbif-api.version>1.16.13</gbif-api.version>
<gbif-common.version>0.60</gbif-common.version>
<gbif-doi.version>2.21</gbif-doi.version>
<gbif-metadata-profile.version>2.2</gbif-metadata-profile.version>
<gbif-metadata-profile.version>2.3</gbif-metadata-profile.version>
<gbif-parsers.version>0.67</gbif-parsers.version>
<gbif-httputils.version>1.4</gbif-httputils.version>

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/gbif/ipt/action/BaseAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public String getRequestURL() {
.replaceQueryParam("request_locale")
.build().toString();
} catch (RuntimeException e) {
LOG.warn("Failed to reconstruct requestURL from " + req.getRequestURL(), e);
LOG.warn("Failed to reconstruct requestURL from {}. Error: {}", req.getRequestURL(), e.getMessage());
}
return getBaseURL();
}
Expand Down
62 changes: 40 additions & 22 deletions src/main/java/org/gbif/ipt/action/manage/MetadataAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -362,14 +362,25 @@ public void prepare() {

// update frequencies list, derived from XML vocabulary, and displayed in drop-down on basic metadata page
frequencies = new LinkedHashMap<>();
frequencies.putAll(vocabManager.getI18nVocab(Constants.VOCAB_URI_UPDATE_FREQUENCIES, getLocaleLanguage(), false));

// temporary fix: remove "unkown" from vocabulary
vocabManager.getI18nVocab(Constants.VOCAB_URI_UPDATE_FREQUENCIES, getLocaleLanguage(), false)
.entrySet()
.stream()
.filter(p -> !"unkown".equals(p.getKey()))
.forEach(p -> frequencies.put(p.getKey(), p.getValue()));

// sanitize intellectualRights - pre-v2.2 text was manually entered and may have characters that break js
if (getEml().getIntellectualRights() != null) {
getEml().setIntellectualRights(removeNewlineCharacters(getEml().getIntellectualRights()));
}

// Public, published occurrence resources have a distribution download URL
if (CoreRowType.OCCURRENCE.toString().equalsIgnoreCase(resource.getCoreType())
&& resource.isPublished()
&& resource.isPubliclyAvailable()) {
resource.getEml().setDistributionDownloadUrl(cfg.getBaseUrl() + "/archive.do?r=" + resource.getShortname());
}

// populate agent vocabularies
loadAgentVocabularies();

Expand Down Expand Up @@ -397,10 +408,6 @@ public void prepare() {
}

if (isHttpPost()) {
resource.getEml().getDescription().clear();
resource.getEml().getContacts().clear();
resource.getEml().getCreators().clear();
resource.getEml().getMetadataProviders().clear();
resource.getEml().setIntellectualRights(null);

// publishing organisation, if provided must match organisation
Expand All @@ -415,6 +422,17 @@ public void prepare() {
}
break;

case CONTACTS_SECTION:
// populate agent vocabularies
loadAgentVocabularies();
if (isHttpPost()) {
resource.getEml().getContacts().clear();
resource.getEml().getCreators().clear();
resource.getEml().getMetadataProviders().clear();
resource.getEml().getAssociatedParties().clear();
}
break;

case GEOGRAPHIC_COVERAGE_SECTION:
if (isHttpPost()) {
resource.getEml().getGeospatialCoverages().clear();
Expand Down Expand Up @@ -443,19 +461,13 @@ public void prepare() {
}
break;

case PARTIES_SECTION:
// populate agent vocabularies
loadAgentVocabularies();
if (isHttpPost()) {
resource.getEml().getAssociatedParties().clear();
}
break;

case PROJECT_SECTION:
// populate agent vocabularies
loadAgentVocabularies();
if (isHttpPost()) {
resource.getEml().getProject().getPersonnel().clear();
resource.getEml().getProject().getAwards().clear();
resource.getEml().getProject().getRelatedProjects().clear();
}
break;

Expand Down Expand Up @@ -506,9 +518,9 @@ public void prepare() {

@Override
public String save() throws Exception {
// before saving, the minimum amount of mandatory metadata must have been provided, and ALL metadata sections must
// be valid, otherwise an error is displayed
if (emlValidator.areAllSectionsValid(this, resource)) {
// before saving, the minimum amount of mandatory metadata must have been provided, and the current metadata section
// must be valid, otherwise an error is displayed
if (emlValidator.isSectionValid(this, resource, section)) {
// Save metadata information (eml.xml)
resourceManager.saveEml(resource);
// save date metadata was last modified
Expand All @@ -520,6 +532,12 @@ public String save() throws Exception {
// progress to next section, since save succeeded
switch (section) {
case BASIC_SECTION:
next = MetadataSection.CONTACTS_SECTION;
break;
case CONTACTS_SECTION:
next = MetadataSection.ACKNOWLEDGEMENTS_SECTION;
break;
case ACKNOWLEDGEMENTS_SECTION:
next = MetadataSection.GEOGRAPHIC_COVERAGE_SECTION;
break;
case GEOGRAPHIC_COVERAGE_SECTION:
Expand All @@ -529,12 +547,12 @@ public String save() throws Exception {
next = MetadataSection.TEMPORAL_COVERAGE_SECTION;
break;
case TEMPORAL_COVERAGE_SECTION:
next = MetadataSection.ADDITIONAL_DESCRIPTION_SECTION;
break;
case ADDITIONAL_DESCRIPTION_SECTION:
next = MetadataSection.KEYWORDS_SECTION;
break;
case KEYWORDS_SECTION:
next = MetadataSection.PARTIES_SECTION;
break;
case PARTIES_SECTION:
next = MetadataSection.PROJECT_SECTION;
break;
case PROJECT_SECTION:
Expand Down Expand Up @@ -689,7 +707,7 @@ public String getResourceHasCore() {

/**
* On the basic metadata page, this map populates the update frequencies dropdown. The map is derived from the
* vocabulary {@link -linkoffline http://rs.gbif.org/vocabulary/eml/update_frequency.xml}.
* vocabulary <a href="http://rs.gbif.org/vocabulary/eml/update_frequency.xml">http://rs.gbif.org/vocabulary/eml/update_frequency.xml</a>.
*
* @return update frequencies map
*/
Expand Down Expand Up @@ -859,7 +877,7 @@ private void loadAgentVocabularies() {
Agent current = new Agent();
current.setFirstName(getCurrentUser().getFirstname());
current.setLastName(getCurrentUser().getLastname());
current.setEmail(getCurrentUser().getEmail());
current.setEmail(Collections.singletonList(getCurrentUser().getEmail()));

// contacts list
Agent firstContact = null;
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/org/gbif/ipt/action/manage/OverviewAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Stream;

import javax.annotation.Nullable;
import javax.validation.constraints.NotNull;
import javax.xml.parsers.ParserConfigurationException;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -1252,6 +1252,14 @@ public void prepare() {

usableSpace = cfg.getDataDir().getDataDirUsableSpace();
freeDiscSpaceReadable = org.apache.commons.io.FileUtils.byteCountToDisplaySize(usableSpace);

if (resource.isPublished()
&& resource.getEml() != null
&& resource.getEml().getProject() != null
&& resource.getEml().getProject().getTitle() != null
&& resource.getEml().getProject().getPersonnel().isEmpty()) {
addActionWarning(getText("validation.personnel.now.required"));
}
}
}

Expand Down Expand Up @@ -1652,7 +1660,7 @@ public String replaceEml() {
LOG.error("Failed to replace EML", e);
addActionError(getText("manage.overview.failed.replace.eml"));
return ERROR;
} catch (SAXException e) {
} catch (SAXException | ParserConfigurationException e) {
LOG.error("Failed to create EML validator", e);
addActionError(getText("manage.overview.failed.replace.eml.validator"));
return ERROR;
Expand Down
16 changes: 14 additions & 2 deletions src/main/java/org/gbif/ipt/action/portal/ResourceAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -899,15 +899,27 @@ private boolean isValidAgent(Agent agent) {
*/
private boolean agentsMatch(Agent agent1, Agent agent2) {
boolean namesMatch = false;
boolean emailsMatch;
boolean emailsMatch = false;
boolean positionsMatch;

if (agent1.getFullName() != null && agent2.getFullName() != null) {
namesMatch = agent1.getFullName().equals(agent2.getFullName());
}

if (agent1.getEmail() != null && agent2.getEmail() != null) {
emailsMatch = agent1.getEmail().equalsIgnoreCase(agent2.getEmail());
emailsMatch = true;
if (agent1.getEmail().size() != agent2.getEmail().size()) {
emailsMatch = false;
} else {
for (int i = 0; i < agent1.getEmail().size(); i++) {
String email1 = agent1.getEmail().get(i);
String email2 = agent2.getEmail().get(i);
if (!email1.equalsIgnoreCase(email2)) {
emailsMatch = false;
break;
}
}
}
} else {
emailsMatch = true;
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/gbif/ipt/config/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ public final class Constants {
public static final Set<String> GBIF_SUPPORTED_LICENSES;
public static final Set<String> GBIF_SUPPORTED_LICENSES_CODES;

public static final String EML_2_1_1_SCHEMA = "eml://ecoinformatics.org/eml-2.1.1";
public static final String EML_2_2_0_SCHEMA = "https://eml.ecoinformatics.org/eml-2.2.0";

static {
Set<String> licencesInternal = new HashSet<>();
licencesInternal.add("http://creativecommons.org/publicdomain/zero/1.0/legalcode");
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/org/gbif/ipt/model/Resource.java
Original file line number Diff line number Diff line change
Expand Up @@ -1464,7 +1464,12 @@ public String generateResourceCitation(@NotNull BigDecimal version, @NotNull URI

// make list of verified agents (having first and last name)
Set<String> verifiedAuthorList = new LinkedHashSet<>();
Stream.of(getEml().getCreators(), getEml().getMetadataProviders())

List<Agent> suitableAssociatedParties = getEml().getAssociatedParties().stream()
.filter(p -> "originator".equalsIgnoreCase(p.getRole()) || "metadataProvider".equalsIgnoreCase(p.getRole()))
.collect(Collectors.toList());

Stream.of(getEml().getCreators(), getEml().getMetadataProviders(), suitableAssociatedParties)
.flatMap(Collection::stream)
.map(this::getCitationAgentName)
.filter(StringUtils::isNotEmpty)
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/gbif/ipt/model/voc/MetadataSection.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@
*/
public enum MetadataSection {
BASIC_SECTION("basic"),
CONTACTS_SECTION("contacts"),
ACKNOWLEDGEMENTS_SECTION("acknowledgements"),
GEOGRAPHIC_COVERAGE_SECTION ("geocoverage"),
TAXANOMIC_COVERAGE_SECTION ("taxcoverage"),
TEMPORAL_COVERAGE_SECTION ("tempcoverage"),
ADDITIONAL_DESCRIPTION_SECTION("additionalDescription"),
PROJECT_SECTION ("project"),
METHODS_SECTION ("methods"),
CITATIONS_SECTION ("citations"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.util.concurrent.ThreadPoolExecutor;

import javax.annotation.Nullable;
import javax.xml.parsers.ParserConfigurationException;

import org.apache.commons.collections4.ListValuedMap;
import org.xml.sax.SAXException;
Expand Down Expand Up @@ -421,7 +422,7 @@ Resource create(String shortname, String type, File dwca, User creator, BaseActi
* @param emlFile
* @param validate
*/
void replaceEml(Resource resource, File emlFile, boolean validate) throws SAXException, IOException, InvalidEmlException, ImportException;
void replaceEml(Resource resource, File emlFile, boolean validate) throws SAXException, ParserConfigurationException, IOException, InvalidEmlException, ImportException;

/**
* Replace the datapackage metadata file in a resource by the provided file
Expand Down
Loading

0 comments on commit d42e9e3

Please sign in to comment.