list = body.getChildren();
- if (list.size() == 0)
+ if (list.isEmpty())
throw new BadSoapResponseEx(envelope);
return list.get(0);
diff --git a/common/src/main/java/org/fao/geonet/utils/GeonetHttpRequestFactory.java b/common/src/main/java/org/fao/geonet/utils/GeonetHttpRequestFactory.java
index 7ba666fd2a..bd548561c0 100644
--- a/common/src/main/java/org/fao/geonet/utils/GeonetHttpRequestFactory.java
+++ b/common/src/main/java/org/fao/geonet/utils/GeonetHttpRequestFactory.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2001-2016 Food and Agriculture Organization of the
+ * Copyright (C) 2001-2023 Food and Agriculture Organization of the
* United Nations (FAO-UN), United Nations World Food Programme (WFP)
* and United Nations Environment Programme (UNEP)
*
@@ -200,6 +200,7 @@ public HttpClientBuilder getDefaultHttpClientBuilder() {
final HttpClientBuilder builder = HttpClientBuilder.create();
builder.setRedirectStrategy(new LaxRedirectStrategy());
builder.disableContentCompression();
+ builder.useSystemProperties();
synchronized (this) {
if (connectionManager == null) {
@@ -249,40 +250,40 @@ public void closeIdleConnections(long idleTimeout, TimeUnit tunit) {
private static class AdaptingResponse extends AbstractClientHttpResponse {
- private final CloseableHttpResponse _response;
- private final CloseableHttpClient _client;
+ private final CloseableHttpResponse response;
+ private final CloseableHttpClient client;
public AdaptingResponse(CloseableHttpClient client, CloseableHttpResponse response) {
- this._response = response;
- this._client = client;
+ this.response = response;
+ this.client = client;
}
@Override
public int getRawStatusCode() throws IOException {
- return _response.getStatusLine().getStatusCode();
+ return response.getStatusLine().getStatusCode();
}
@Override
public String getStatusText() throws IOException {
- return _response.getStatusLine().getReasonPhrase();
+ return response.getStatusLine().getReasonPhrase();
}
@Override
public void close() {
- IOUtils.closeQuietly(_response);
- IOUtils.closeQuietly(_client);
+ IOUtils.closeQuietly(response);
+ IOUtils.closeQuietly(client);
}
@Override
public InputStream getBody() throws IOException {
- return _response.getEntity().getContent();
+ return response.getEntity().getContent();
}
@Override
public HttpHeaders getHeaders() {
final HttpHeaders httpHeaders = new HttpHeaders();
- final Header[] headers = _response.getAllHeaders();
+ final Header[] headers = response.getAllHeaders();
for (Header header : headers) {
final HeaderElement[] elements = header.getElements();
diff --git a/common/src/main/java/org/fao/geonet/utils/IO.java b/common/src/main/java/org/fao/geonet/utils/IO.java
index f3eaeeb034..bfdcb57dd2 100644
--- a/common/src/main/java/org/fao/geonet/utils/IO.java
+++ b/common/src/main/java/org/fao/geonet/utils/IO.java
@@ -1,5 +1,5 @@
//=============================================================================
-//=== Copyright (C) 2001-2005 Food and Agriculture Organization of the
+//=== Copyright (C) 2001-2023 Food and Agriculture Organization of the
//=== United Nations (FAO-UN), United Nations World Food Programme (WFP)
//=== and United Nations Environment Programme (UNEP)
//===
@@ -30,6 +30,8 @@
import org.fao.geonet.utils.debug.DebuggingInputStream;
import org.fao.geonet.utils.debug.DebuggingReader;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
@@ -37,31 +39,15 @@
import java.net.URI;
import java.net.URL;
import java.nio.charset.Charset;
-import java.nio.file.DirectoryStream;
-import java.nio.file.FileSystem;
-import java.nio.file.FileSystemNotFoundException;
-import java.nio.file.FileSystems;
-import java.nio.file.FileVisitResult;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.nio.file.SimpleFileVisitor;
-import java.nio.file.StandardCopyOption;
+import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.FileTime;
import java.sql.ResultSet;
import java.sql.Statement;
-import java.util.Comparator;
-import java.util.HashMap;
import java.util.Iterator;
-import java.util.Map;
import java.util.Objects;
-import java.util.TreeSet;
import java.util.concurrent.TimeUnit;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-
//=============================================================================
/**
diff --git a/common/src/main/java/org/fao/geonet/utils/Log.java b/common/src/main/java/org/fao/geonet/utils/Log.java
index 5521672ab0..094dfb4942 100644
--- a/common/src/main/java/org/fao/geonet/utils/Log.java
+++ b/common/src/main/java/org/fao/geonet/utils/Log.java
@@ -105,6 +105,16 @@ public final class Log {
public static final String TRANSFORMER_FACTORY = JEEVES
+ ".transformerFactory";
+ /**
+ * This is the name of the RollingFileAppender in your log4j2.xml configuration file.
+ *
+ * LogConfig uses this name to lookup RollingFileAppender to check configuration in
+ * case a custom log file location has been used.
+ */
+ private static final String FILE_APPENDER_NAME = "File";
+
+ public static final String GEONETWORK_MODULE = "geonetwork";
+
/**
* Default constructor. Builds a Log.
*/
@@ -331,4 +341,62 @@ public static File toLogFile(Appender appender) {
return null;
}
+ public static File getLogfile() {
+ // Appender is supplied by LogUtils based on parsing log4j2.xml file indicated
+ // by database settings
+
+ // First, try the fileappender from the logger named "geonetwork"
+ org.apache.log4j.Appender appender = org.apache.log4j.Logger.getLogger(GEONETWORK_MODULE).getAppender(FILE_APPENDER_NAME);
+ // If still not found, try the one from the logger named "jeeves"
+ if (appender == null) {
+ appender = org.apache.log4j.Logger.getLogger(Log.JEEVES).getAppender(FILE_APPENDER_NAME);
+ }
+ if (appender != null) {
+ if (appender instanceof AppenderWrapper) {
+ AppenderWrapper wrapper = (AppenderWrapper) appender;
+ org.apache.logging.log4j.core.Appender appender2 = wrapper.getAppender();
+
+ if (appender2 instanceof FileAppender) {
+ FileAppender fileAppender = (FileAppender) appender2;
+ String logFileName = fileAppender.getFileName();
+ if (logFileName != null) {
+ File logFile = new File(logFileName);
+ if (logFile.exists()) {
+ return logFile;
+ }
+ }
+ }
+ if (appender2 instanceof RollingFileAppender) {
+ RollingFileAppender fileAppender = (RollingFileAppender) appender2;
+ String logFileName = fileAppender.getFileName();
+ if (logFileName != null) {
+ File logFile = new File(logFileName);
+ if (logFile.exists()) {
+ return logFile;
+ }
+ }
+ }
+ }
+ }
+ Log.warning(GEONETWORK_MODULE, "Error when getting logger file for the " + "appender named '" + FILE_APPENDER_NAME + "'. "
+ + "Check your log configuration file. "
+ + "A FileAppender or RollingFileAppender is required to return last activity to the user interface."
+ + "Appender file not found.");
+
+ if (System.getProperties().containsKey("log_dir")) {
+ File logDir = new File(System.getProperty("log_dir"));
+ if (logDir.exists() && logDir.isDirectory()) {
+ File logFile = new File(logDir, "logs/geonetwork.log");
+ if (logFile.exists()) {
+ return logFile;
+ }
+ }
+ } else {
+ File logFile = new File("logs/geonetwork.log");
+ if (logFile.exists()) {
+ return logFile;
+ }
+ }
+ return null; // unavailable
+ }
}
diff --git a/common/src/main/java/org/fao/geonet/utils/Xml.java b/common/src/main/java/org/fao/geonet/utils/Xml.java
index 59636fc9c9..c796fbfe4e 100644
--- a/common/src/main/java/org/fao/geonet/utils/Xml.java
+++ b/common/src/main/java/org/fao/geonet/utils/Xml.java
@@ -31,14 +31,9 @@
import net.sf.saxon.Configuration;
import net.sf.saxon.Controller;
import net.sf.saxon.FeatureKeys;
-import org.apache.commons.io.IOUtils;
import org.apache.fop.apps.Fop;
import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.MimeConstants;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.HttpClient;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.xml.resolver.tools.CatalogResolver;
import org.fao.geonet.exceptions.XSDValidationErrorEx;
import org.fao.geonet.utils.nio.NioPathAwareEntityResolver;
@@ -100,7 +95,6 @@
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CharsetEncoder;
-import java.nio.charset.StandardCharsets;
import java.nio.file.FileSystemNotFoundException;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
@@ -135,6 +129,7 @@ public final class Xml {
+ "\uE000-\uFFFD"
+ "\ud800\udc00-\udbff\udfff"
+ "]";
+ public static final String XML_VERSION_HEADER = "<\\?xml version=['\"]1.0['\"] encoding=['\"].*['\"]\\?>\\s*";
public static SAXBuilder getSAXBuilder(boolean validate) {
SAXBuilder builder = getSAXBuilderWithPathXMLResolver(validate, null);
@@ -398,6 +393,9 @@ public static Object unmarshall(Element xml, Class clazz) throws Exception {
public static Element transform(Element xml, Path styleSheetPath, Map params) throws Exception {
JDOMResult resXml = new JDOMResult();
transform(xml, styleSheetPath, resXml, params);
+ if (resXml.getDocument() == null) {
+ throw new NullPointerException("Failed to create a Document for " + resXml.getResult());
+ }
return (Element) resXml.getDocument().getRootElement().detach();
}
//--------------------------------------------------------------------------
@@ -1118,6 +1116,10 @@ private static void doCreateAttributesXpathExpr(StringBuilder builder, List"));
+ assertEquals(true,
+ Xml.isXMLLike(""));
+ assertEquals(true,
+ Xml.isXMLLike("\n"));
+ assertEquals(true,
+ Xml.isRDFLike("\n"));
+ assertEquals(true,
+ Xml.isRDFLike("\n"));
+ }
}
diff --git a/core/pom.xml b/core/pom.xml
index 0ba137fc72..737a015171 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -27,13 +27,13 @@
geonetwork
org.geonetwork-opensource
- 4.2.2-georchestra
+ 4.2.6-georchestra
4.0.0
gn-core
GeoNetwork core
- 4.2.2-georchestra
+ 4.2.6-georchestra
@@ -386,26 +386,20 @@
${project.groupId}
gn-domain
- ${project.parent.version}
+ ${project.version}
tests
test
${project.groupId}
gn-events
- ${project.parent.version}
+ ${project.version}
org.apache.jclouds
jclouds-all
- 2.2.1
-
-
- javax.annotation
- jsr250-api
-
-
+ 2.3.0
@@ -501,27 +495,27 @@
${project.groupId}
gn-oaipmh
- ${project.parent.version}
+ ${project.version}
${project.groupId}
gn-domain
- ${project.parent.version}
+ ${project.version}
${project.groupId}
gn-cachingxslt
- ${project.parent.version}
+ ${project.version}
org.geonetwork-opensource.schemas
gn-schema-iso19139
- ${project.parent.version}
+ ${project.version}
${project.groupId}
gn-dummy-api
- ${project.parent.version}
+ ${project.version}
@@ -593,7 +587,7 @@
${project.groupId}
gn-index
- ${project.parent.version}
+ ${project.version}
org.springframework
@@ -607,7 +601,7 @@
com.amazonaws
aws-java-sdk-s3
- 1.11.618
+ 1.12.261
org.jasypt
diff --git a/core/src/main/java/jeeves/config/springutil/JeevesNodeAwareLogoutSuccessHandler.java b/core/src/main/java/jeeves/config/springutil/JeevesNodeAwareLogoutSuccessHandler.java
index e1c0aec969..8442c90959 100644
--- a/core/src/main/java/jeeves/config/springutil/JeevesNodeAwareLogoutSuccessHandler.java
+++ b/core/src/main/java/jeeves/config/springutil/JeevesNodeAwareLogoutSuccessHandler.java
@@ -26,11 +26,15 @@
import org.fao.geonet.NodeInfo;
import org.fao.geonet.kernel.setting.SettingManager;
import org.fao.geonet.kernel.setting.Settings;
+import org.fao.geonet.constants.Geonet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AbstractAuthenticationTargetUrlRequestHandler;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
+import org.apache.commons.lang3.StringUtils;
+import org.fao.geonet.kernel.setting.SettingInfo;
+
import java.io.IOException;
import java.net.MalformedURLException;
@@ -84,8 +88,10 @@ protected String determineTargetUrl(HttpServletRequest request, HttpServletRespo
String siteHost = settingManager.getValue(Settings.SYSTEM_SERVER_HOST);
String siteProtocol = settingManager.getValue(Settings.SYSTEM_SERVER_PROTOCOL);
- int sitePort = settingManager.getValueAsInt(Settings.SYSTEM_SERVER_PORT);
-
+
+ // some conditional logic to handle the case where there's no port in the settings
+ SettingInfo si = new SettingInfo();
+ int sitePort = si.getSitePort();
if (!hostName.equalsIgnoreCase(siteHost) ||
!protocol.equalsIgnoreCase(siteProtocol) ||
diff --git a/core/src/main/java/jeeves/server/dispatchers/ServiceManager.java b/core/src/main/java/jeeves/server/dispatchers/ServiceManager.java
index b742d7f00d..c99f6b92b4 100644
--- a/core/src/main/java/jeeves/server/dispatchers/ServiceManager.java
+++ b/core/src/main/java/jeeves/server/dispatchers/ServiceManager.java
@@ -356,17 +356,26 @@ public ServiceContext createServiceContext(String name, ConfigurableApplicationC
return context;
}
+ /**
+ * If we do have the optional x-forwarded-for request header then
+ * use whatever is in it to record ip address of client
+ */
+ public static String getRequestIpAddress(HttpServletRequest request) {
+ String xForwardedForHeader = request.getHeader("x-forwarded-for");
+ return StringUtils.isNotEmpty(xForwardedForHeader)
+ ? xForwardedForHeader : request.getRemoteAddr();
+ }
+
+
public ServiceContext createServiceContext(String name, String lang, HttpServletRequest request) {
ServiceContext context = new ServiceContext(name, ApplicationContextHolder.get(), htContexts, entityManager);
context.setBaseUrl(baseUrl);
context.setLanguage(lang);
- context.setIpAddress(request.getRemoteAddr());
+ context.setIpAddress(getRequestIpAddress(request));
context.setMaxUploadSize(maxUploadSize);
context.setServlet(servlet);
- String ip = request.getRemoteAddr();
-
// Session is created by ApiInterceptor when needed
// Save the session here in the ServiceContext (not used in the API package).
final HttpSession httpSession = request.getSession(false);
diff --git a/core/src/main/java/jeeves/server/sources/ServiceRequestFactory.java b/core/src/main/java/jeeves/server/sources/ServiceRequestFactory.java
index 8310e69764..5e89a7d534 100644
--- a/core/src/main/java/jeeves/server/sources/ServiceRequestFactory.java
+++ b/core/src/main/java/jeeves/server/sources/ServiceRequestFactory.java
@@ -24,6 +24,7 @@
package jeeves.server.sources;
import jeeves.constants.Jeeves;
+import jeeves.server.dispatchers.ServiceManager;
import jeeves.server.sources.ServiceRequest.InputMethod;
import jeeves.server.sources.ServiceRequest.OutputMethod;
import jeeves.server.sources.http.HttpServiceRequest;
@@ -102,9 +103,7 @@ public static ServiceRequest create(HttpServletRequest req,
srvReq.setLanguage(lang);
srvReq.setService(service);
srvReq.setJSONOutput(extractJSONFlag(req.getQueryString()));
- String ip = req.getRemoteAddr();
- String forwardedFor = req.getHeader("x-forwarded-for");
- if (forwardedFor != null) ip = forwardedFor;
+ String ip = ServiceManager.getRequestIpAddress(req);
srvReq.setAddress(ip);
srvReq.setOutputStream(res.getOutputStream());
diff --git a/core/src/main/java/jeeves/server/sources/http/JeevesServlet.java b/core/src/main/java/jeeves/server/sources/http/JeevesServlet.java
index 154a268212..17ef9e745b 100644
--- a/core/src/main/java/jeeves/server/sources/http/JeevesServlet.java
+++ b/core/src/main/java/jeeves/server/sources/http/JeevesServlet.java
@@ -29,6 +29,7 @@
import jeeves.constants.Jeeves;
import jeeves.server.JeevesEngine;
import jeeves.server.UserSession;
+import jeeves.server.dispatchers.ServiceManager;
import jeeves.server.sources.ServiceRequest;
import jeeves.server.sources.ServiceRequestFactory;
@@ -113,13 +114,7 @@ public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOExc
//---------------------------------------------------------------------------
private void execute(HttpServletRequest req, HttpServletResponse res) throws IOException {
- String ip = req.getRemoteAddr();
- // if we do have the optional x-forwarded-for request header then
- // use whatever is in it to record ip address of client
- String forwardedFor = req.getHeader("x-forwarded-for");
- if (forwardedFor != null) {
- ip = forwardedFor;
- }
+ String ip = ServiceManager.getRequestIpAddress(req);
Log.info(Log.REQUEST, "==========================================================");
Log.info(Log.REQUEST, "HTML Request (from " + ip + ") : " + req.getRequestURI());
diff --git a/core/src/main/java/jeeves/services/RegExpReplace.java b/core/src/main/java/jeeves/services/RegExpReplace.java
index 9a6dc18149..a172f82c4e 100644
--- a/core/src/main/java/jeeves/services/RegExpReplace.java
+++ b/core/src/main/java/jeeves/services/RegExpReplace.java
@@ -42,7 +42,7 @@
//=============================================================================
/**
- * This service reads a configuration xml file containint containing pattern-replacement pairs and
+ * This service reads a configuration xml file containing pattern-replacement pairs and
* applies all the pairs to each text element of the output. The configuration is read from
* xml/regexp.xml and is formatted:
*/
diff --git a/core/src/main/java/org/fao/geonet/MetadataResourceDatabaseMigration.java b/core/src/main/java/org/fao/geonet/MetadataResourceDatabaseMigration.java
index 7cf4be53b1..ff9e62cc6b 100644
--- a/core/src/main/java/org/fao/geonet/MetadataResourceDatabaseMigration.java
+++ b/core/src/main/java/org/fao/geonet/MetadataResourceDatabaseMigration.java
@@ -78,7 +78,7 @@ public class MetadataResourceDatabaseMigration extends DatabaseMigrationTask {
"gmd:fileDescription/gco:CharacterString = 'large_thumbnail']/gmd:fileName/" +
"gco:CharacterString[not(starts-with(normalize-space(text()), 'http'))]";
private static final String XPATH_THUMBNAIL_WITH_URL =
- "*//gmd:graphicOverview/gmd:MD_BrowseGraphic[gmd:fileDescription/gco:CharacterString]/gmd:fileName/gco:CharacterString[starts-with(normalize-space(text()), 'http')]";
+ "*//gmd:graphicOverview/gmd:MD_BrowseGraphic/gmd:fileName/gco:CharacterString[starts-with(normalize-space(text()), 'http')]";
private static final String XPATH_ATTACHMENTS_WITH_URL =
"*//gmd:CI_OnlineResource/gmd:linkage/gmd:URL";
diff --git a/core/src/main/java/org/fao/geonet/api/records/attachments/CMISStore.java b/core/src/main/java/org/fao/geonet/api/records/attachments/CMISStore.java
index 3aea91d393..87f74ab998 100644
--- a/core/src/main/java/org/fao/geonet/api/records/attachments/CMISStore.java
+++ b/core/src/main/java/org/fao/geonet/api/records/attachments/CMISStore.java
@@ -65,6 +65,8 @@ public class CMISStore extends AbstractStore {
private Path baseMetadataDir = null;
+ private static final String CMIS_PROPERTY_PREFIX = "cmis:";
+
@Autowired
CMISConfiguration cmisConfiguration;
@@ -214,75 +216,64 @@ protected MetadataResource putResource(final ServiceContext context, final Strin
// Reset Filter from the default operationalContext to include all fields because we may need secondary properties.
oc.setFilter(null);
- CmisObject cmisObject;
+ Map properties = new HashMap();
+ Document doc;
try {
- cmisObject = cmisConfiguration.getClient().getObjectByPath(key, oc);
- } catch (Exception e) {
- cmisObject = null;
- }
+ doc = (Document) cmisConfiguration.getClient().getObjectByPath(key, oc);
- Map properties = new HashMap();
- if (!StringUtils.isEmpty(cmisConfiguration.getCmisMetadataUUIDPropertyName()) && !cmisConfiguration.existMetadataUUIDSecondaryProperty()) {
- setCmisMetadataUUIDPrimary(properties, metadataUuid);
+ // Update existing document
+ setCmisProperties(metadataUuid, properties, doc, additionalProperties);
+ doc = cmisUtils.saveDocument(key, doc, properties, is, changeDate);
+ } catch (CmisObjectNotFoundException e) {
+ // add new document
+ setCmisProperties(metadataUuid, properties, null, additionalProperties);
+ doc = cmisUtils.saveDocument(key, null, properties, is, changeDate);
}
- // If cmisObject is empty then it is a new record. With new records, we need to set the default value for the status.
- MetadataResourceExternalManagementProperties.ValidationStatus defaultStatus = null;
- // We only need to set the default if there is a status property supplied.
- if (!StringUtils.isEmpty(cmisConfiguration.getExternalResourceManagementValidationStatusPropertyName())) {
- if (cmisConfiguration.getExternalResourceManagementValidationStatusDefaultValue() != null) {
- // If a default property name does exist then use it
- defaultStatus = MetadataResourceExternalManagementProperties.ValidationStatus.valueOf(cmisConfiguration.getExternalResourceManagementValidationStatusDefaultValue());
- } else {
- // Otherwise lets default to incomplete.
- // Reason - as the administrator decided to use the status, it most likely means that there are extra properties that need to be set after a file is uploaded so defaulting it to
- // incomplete seems reasonable.
- defaultStatus = MetadataResourceExternalManagementProperties.ValidationStatus.INCOMPLETE;
- }
- if (cmisObject==null &&
- !cmisConfiguration.existExternalResourceManagementValidationStatusSecondaryProperty() &&
- !properties.containsKey(cmisConfiguration.getExternalResourceManagementValidationStatusPropertyName())
- ) {
- setCmisExternalManagementResourceStatusPrimary(properties, defaultStatus);
- }
+ return createResourceDescription(context, metadataUuid, visibility, filename,
+ doc, metadataId, approved);
+ }
+
+ protected void setCmisProperties(String metadataUuid, Map properties, Document doc, Map additionalProperties) {
+
+ // Add additional properties if exists.
+ if (MapUtils.isNotEmpty(additionalProperties)) {
+ properties.putAll(additionalProperties);
}
- Document doc = cmisUtils.saveDocument(key, cmisObject, properties, is, changeDate);
+ // now update metadata uuid and status within primary cmis fields if needed.
- // The optional metadata UUID is assigned to a user-defined property in the content management system.
- // In some content management systems, custom properties appear as CMIS Secondary properties.
- // CMIS Secondary properties cannot be set in the same call that creates the document and sets it's properties,
- // so this is done in the following call after the document is created
+ // Don't allow users metadata uuid to be supplied as a property so let's overwrite any value that may exist.
+ if (!StringUtils.isEmpty(cmisConfiguration.getCmisMetadataUUIDPropertyName())) {
+ setCmisMetadataUUIDPrimary(properties, metadataUuid);
+ }
+ // If document is empty it is a new record so set the default status value property if it does not already exist as an additional property.
+ if (doc == null &&
+ !StringUtils.isEmpty(cmisConfiguration.getExternalResourceManagementValidationStatusPropertyName()) &&
+ !properties.containsKey(cmisConfiguration.getExternalResourceManagementValidationStatusPropertyName())) {
+ setCmisExternalManagementResourceStatusPrimary(properties, cmisConfiguration.getValidationStatusDefaultValue());
+ }
+
+ // If we have secondary properties then lets apply those changes as well.
if (cmisConfiguration.existSecondaryProperty()) {
- Map secondaryProperties = new HashMap<>();
- if (MapUtils.isNotEmpty(additionalProperties)) {
- secondaryProperties.putAll(additionalProperties);
+ Property secondaryProperties = null;
+ if (doc != null) {
+ secondaryProperties = doc.getProperty(PropertyIds.SECONDARY_OBJECT_TYPE_IDS);
}
+
+ // Don't allow users metadata uuid to be supplied as a property so let's overwrite any value that may exist.
if (cmisConfiguration.existMetadataUUIDSecondaryProperty()) {
- setCmisMetadataUUIDSecondary(doc, secondaryProperties, metadataUuid);
+ setCmisMetadataUUIDSecondary(secondaryProperties, properties, metadataUuid);
}
-
- // If cmisObject is empty and the property does not already exist as an additional secondary property then it is a new record.
- // With new records, we need to set the default value for the status.
- if (cmisObject==null &&
+ // If document is empty it is a new record so set the default status value property if it does not already exist as an additional secondary property.
+ if (doc == null &&
cmisConfiguration.existExternalResourceManagementValidationStatusSecondaryProperty() &&
- !secondaryProperties.containsKey(cmisConfiguration.getExternalResourceManagementValidationStatusPropertyName().split(CMISConfiguration.CMIS_SECONDARY_PROPERTY_SEPARATOR)[1])) {
- setCmisExternalManagementResourceStatusSecondary(doc, secondaryProperties, defaultStatus);
- }
-
- try {
- doc.updateProperties(secondaryProperties);
- } catch (Exception e) {
- Log.error(Geonet.RESOURCES,
- String.format("Unable to update CMIS secondary property on metadata resource '%s' for metadata '%s'.", key, metadataUuid), e);
- throw e;
+ !properties.containsKey(cmisConfiguration.getExternalResourceManagementValidationStatusPropertyName().split(CMISConfiguration.CMIS_SECONDARY_PROPERTY_SEPARATOR)[1])) {
+ setCmisExternalManagementResourceStatusSecondary(secondaryProperties, properties, cmisConfiguration.getValidationStatusDefaultValue());
}
}
- return createResourceDescription(context, metadataUuid, visibility, filename,
- doc, metadataId, approved);
}
-
protected void setCmisMetadataUUIDPrimary(Map properties, String metadataUuid) {
setCmisPrimaryProperty(properties, cmisConfiguration.getCmisMetadataUUIDPropertyName(), metadataUuid);
}
@@ -298,22 +289,21 @@ protected void setCmisPrimaryProperty(Map properties, String pro
}
}
- protected void setCmisExternalManagementResourceStatusSecondary(Document doc, Map properties, MetadataResourceExternalManagementProperties.ValidationStatus status) {
- setCmisSecondaryProperty(doc, properties, cmisConfiguration.getExternalResourceManagementValidationStatusPropertyName(), status.getValue());
+ protected void setCmisExternalManagementResourceStatusSecondary(Property secondaryProperty, Map properties, MetadataResourceExternalManagementProperties.ValidationStatus status) {
+ setCmisSecondaryProperty(secondaryProperty, properties, cmisConfiguration.getExternalResourceManagementValidationStatusPropertyName(), status.getValue());
}
- protected void setCmisMetadataUUIDSecondary(Document doc, Map properties, String metadataUuid) {
- setCmisSecondaryProperty(doc, properties, cmisConfiguration.getCmisMetadataUUIDPropertyName(), metadataUuid);
+ protected void setCmisMetadataUUIDSecondary(Property secondaryProperty, Map properties, String metadataUuid) {
+ setCmisSecondaryProperty(secondaryProperty, properties, cmisConfiguration.getCmisMetadataUUIDPropertyName(), metadataUuid);
}
- protected void setCmisSecondaryProperty(Document doc, Map properties, String propertyName, Object value) {
+ protected void setCmisSecondaryProperty(Property secondaryProperty, Map properties, String propertyName, Object value) {
if (!StringUtils.isEmpty(propertyName) &&
propertyName.contains(cmisConfiguration.getSecondaryPropertySeparator())) {
String[] splitPropertyNames = propertyName.split(Pattern.quote(cmisConfiguration.getSecondaryPropertySeparator()));
String aspectName = splitPropertyNames[0];
String secondaryPropertyName = splitPropertyNames[1];
List