Skip to content

Commit

Permalink
Standard / Processes / Collection merge
Browse files Browse the repository at this point in the history
* Add limit configuration option (eg. only collect 1 overview from
  children - we have catalogues with 100+ of children which makes series
records with lot of overviews with no benefit)
* Add test
  • Loading branch information
fxprunayre committed Oct 17, 2023
1 parent 5b89070 commit fd3e013
Show file tree
Hide file tree
Showing 6 changed files with 771 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@
merge="mri:defaultLocaleCode"/>
<tag name="mri:graphicOverview" context="mri:MD_DataIdentification|srv:SV_ServiceIdentification"
groupBy="*/mcc:fileName/*/text()"
merge="."/>
merge="."
limit="1"/>
<tag name="mri:spatialRepresentationType" context="mri:MD_DataIdentification|srv:SV_ServiceIdentification"
groupBy="mcc:MD_SpatialRepresentationTypeCode/@codeListValue"
merge="mri:spatialRepresentationType"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
extension-element-prefixes="saxon"
exclude-result-prefixes="#all">


<xsl:template match="*[name() = $elements/@name]" mode="merge" priority="2">
<xsl:variable name="name"
select="name()"/>
Expand All @@ -51,6 +50,8 @@
select="$existingMembers//*[name() = $current/@name]"/>
<xsl:variable name="groupBy"
select="$current/@groupBy"/>
<xsl:variable name="limit"
select="$current/@limit"/>
<xsl:variable name="groupKey"
select="saxon:evaluate(concat('$p1/', $groupBy), $match)"/>
<xsl:variable name="elementName"
Expand All @@ -68,7 +69,9 @@
<xsl:copy-of select="string-join(distinct-values($groupKey), ' ,')"/>
</xsl:message>-->

<xsl:for-each select="distinct-values($groupKey)">
<xsl:for-each select="if ($limit castable as xs:integer)
then distinct-values($groupKey)[position() &lt;= $limit]
else distinct-values($groupKey)">
<xsl:sort select="." order="ascending"/>
<xsl:variable name="groupKey"
select="current()"/>
Expand All @@ -81,7 +84,8 @@

<!--
<xsl:message>empty: <xsl:value-of select="$emptyKey"/> </xsl:message>
<xsl:message> Groups: <xsl:copy-of select="$groupValues"/></xsl:message>-->
<xsl:message> Groups: <xsl:copy-of select="$groupValues"/></xsl:message>
-->

<!-- Copy the first instance -->
<xsl:for-each select="$groupValues[1]">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@
merge="gmd:LanguageCode"/>
<tag name="gmd:graphicOverview" context="gmd:MD_DataIdentification|srv:SV_ServiceIdentification"
groupBy="*/gmd:fileName/*/text()"
merge="."/>
merge="."
limit="1"/>
<tag name="gmd:characterSet" context="gmd:MD_DataIdentification|srv:SV_ServiceIdentification"
groupBy="gmd:MD_CharacterSetCode/@codeListValue"
merge="gmd:characterSet"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* Copyright (C) 2001-2016 Food and Agriculture Organization of the
* United Nations (FAO-UN), United Nations World Food Programme (WFP)
* and United Nations Environment Programme (UNEP)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*
* Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2,
* Rome - Italy. email: geonetwork@osgeo.org
*/
package org.fao.geonet.api.records.editing;

import jeeves.server.context.ServiceContext;
import org.fao.geonet.kernel.mef.MEFLibIntegrationTest;
import org.fao.geonet.services.AbstractServiceIntegrationTest;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockHttpSession;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.util.StreamUtils;
import org.springframework.web.context.WebApplicationContext;

import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;

import static org.junit.Assert.assertEquals;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;


public class ProcessApiTest extends AbstractServiceIntegrationTest {
@Autowired
private WebApplicationContext wac;
private String seriesUuid;

private ServiceContext context;

public static Collection<String[]> data() throws Exception {
ArrayList<String[]> data = new ArrayList<>();
data.add(new String[]{"collection-updater", "", "iso19139", "output.xml"});
return data;
}

@Before
public void setUp() throws Exception {
this.context = createServiceContext();
createTestData();
}

private void createTestData() throws Exception {
final MEFLibIntegrationTest.ImportMetadata importMetadata =
new MEFLibIntegrationTest.ImportMetadata(this, context);
importMetadata.getMefFilesToLoad().add("/org/fao/geonet/api/records/samples/series-with-three-children.zip");
importMetadata.invoke();
seriesUuid = "46fccbdc-d848-47a7-a58d-2aabc21c07cf";
}

@Test
public void checkProcess() throws Exception {
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
MockHttpSession mockHttpSession = loginAsAdmin();

for (String[] testParameter : data()) {
String process = testParameter[0];
String urlParams = testParameter[1];
String schema = testParameter[2];
String checkfile = testParameter[3];
try {
String url = "/srv/api/processes/" + process
+ "?uuids=" + seriesUuid + urlParams;
MvcResult result = mockMvc.perform(get(url)
.session(mockHttpSession)
.accept(MediaType.ALL_VALUE))
.andExpect(status().isOk())
.andReturn();

assertEquals(
url,
StreamUtils.copyToString(
ProcessApiTest.class.getResourceAsStream(
String.format("%s-%s-%s",
schema, process, checkfile)
),
StandardCharsets.UTF_8)
.trim(),
result.getResponse().getContentAsString()
.replaceAll("\\r\\n?", "\n")
.trim()
);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
Loading

0 comments on commit fd3e013

Please sign in to comment.