Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to parse secondary properties names from a more human readable name #6687

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 70 additions & 2 deletions core/src/main/java/org/fao/geonet/resources/CMISConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@

package org.fao.geonet.resources;

import org.apache.chemistry.opencmis.client.api.Folder;
import org.apache.chemistry.opencmis.client.api.Repository;
import org.apache.chemistry.opencmis.client.api.SecondaryType;
import org.apache.chemistry.opencmis.client.api.Session;
import org.apache.chemistry.opencmis.client.api.SessionFactory;
import org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl;
import org.apache.chemistry.opencmis.commons.PropertyIds;
import org.apache.chemistry.opencmis.commons.SessionParameter;
import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
import org.apache.chemistry.opencmis.commons.enums.BindingType;
import org.apache.chemistry.opencmis.commons.enums.IncludeRelationships;
import org.apache.chemistry.opencmis.commons.enums.VersioningState;
Expand Down Expand Up @@ -90,6 +93,7 @@ public class CMISConfiguration {
* {property_name} - for primary properties - i.e. cmis:description
*/
private String cmisMetadataUUIDPropertyName;
private String parsedCmisMetadataUUIDPropertyName = null;
private boolean cmisMetadataUUIDSecondaryProperty = false;

/**
Expand All @@ -109,6 +113,7 @@ public class CMISConfiguration {
* If null then validation status will default to UNKNOWN.
*/
private String externalResourceManagementValidationStatusPropertyName;
private String parsedExternalResourceManagementValidationStatusPropertyName = null;
/**
* Default value to be used for the validation status.
* If null then it will use INCOMPLETE as the default.
Expand Down Expand Up @@ -455,7 +460,12 @@ public void setAtompubUrl(String atompubUrl) {
}

public String getCmisMetadataUUIDPropertyName() {
return cmisMetadataUUIDPropertyName;
// If we were able to parse the field on startup then return the parsed version.
if (parsedCmisMetadataUUIDPropertyName != null) {
return parsedCmisMetadataUUIDPropertyName;
} else {
return cmisMetadataUUIDPropertyName;
}
}

public void setCmisMetadataUUIDPropertyName(String cmisMetadataUUIDPropertyName) {
Expand All @@ -475,7 +485,12 @@ public void setCmisMetadataUUIDPropertyName(String cmisMetadataUUIDPropertyName)
}

public String getExternalResourceManagementValidationStatusPropertyName() {
return externalResourceManagementValidationStatusPropertyName;
// If we were able to parse the field on startup then return the parsed version.
if (parsedExternalResourceManagementValidationStatusPropertyName != null) {
return parsedExternalResourceManagementValidationStatusPropertyName;
} else {
return externalResourceManagementValidationStatusPropertyName;
}
}

public void setExternalResourceManagementValidationStatusPropertyName(String externalResourceManagementValidationStatusPropertyName) {
Expand Down Expand Up @@ -600,6 +615,10 @@ public void init() {
repositoryUrl + "' using product '" + client.getRepositoryInfo().getProductName() + "' version '" +
client.getRepositoryInfo().getProductVersion() + "'.");

// Check if we can parse the secondary parameters from human readable to secondary ids.
parsedCmisMetadataUUIDPropertyName = parseSecondaryProperty(client, cmisMetadataUUIDPropertyName);
parsedExternalResourceManagementValidationStatusPropertyName = parseSecondaryProperty(client, externalResourceManagementValidationStatusPropertyName);

// Setup default options
// Ensure caching is on.
if (!client.getDefaultContext().isCacheEnabled()) {
Expand Down Expand Up @@ -720,4 +739,53 @@ private String getServiceUrl(String baseUrl, String serviceUrl, String defaultSe
return serviceUrl;
}
}

/**
* On certain cmis system the secondary property name/id is a bunch of codes that get changed each time the application is deployed.
* Example from Open Text CMIS - otCat:43102->otCat:43102:43102_5
* This can cause issues for system that are re-deployed and the new codes need to be entered.
* This function help convert a human-readable entry like
* Catalogue->GeoNetwork Catalogue ID
* to
* otCat:43102->otCat:43102:43102_5
* The parsing is done by using the property display name.
*
* Note that using the display name means that it will stop on the next restart if the display name for the property is changed.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if there is documentation in the GeoNetwork manual for configuring CMIS, if so it would be nice to add this kind of information.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing that it could go on this page?

https://github.com/geonetwork/doc/blob/fada79d9cb875e80de1441e48b609d08e0285a97/source/install-guide/customizing-data-directory.rst

I think we should also add a section for jcloud (old pr geonetwork/doc#133) and cmis for external storage section. I will try to revisit this in the new year.

* so care should be taken in changing the display names if using this option.
*
* @param client connection to use to access CMIS server.
* @param propertyName to be parsed
* @return null if the property name cannot be parsed otherwise it will return the parsed value.
*/
private String parseSecondaryProperty(Session client, String propertyName) {
if (!StringUtils.isEmpty(propertyName) && propertyName.contains(CMIS_SECONDARY_PROPERTY_SEPARATOR)) {
String[] splitPropertyNames = propertyName.split(Pattern.quote(CMIS_SECONDARY_PROPERTY_SEPARATOR));
if (splitPropertyNames.length == 2) {
Folder baseFolder = (Folder) client.getObjectByPath(this.baseRepositoryPath);

for (SecondaryType secondaryType : baseFolder.getSecondaryTypes()) {
if (secondaryType.getId().equals(splitPropertyNames[0]) || secondaryType.getDisplayName().equals(splitPropertyNames[0])) {
for (Map.Entry<String, PropertyDefinition<?>> entry : secondaryType.getPropertyDefinitions().entrySet()) {
if (entry.getValue().getId().equals(splitPropertyNames[1]) || entry.getValue().getDisplayName().equals(splitPropertyNames[1])) {
String parsedPropertyName = secondaryType.getId() + CMIS_SECONDARY_PROPERTY_SEPARATOR + entry.getKey();
// The parsed property equals to the original property then we can simply return null as there were no changes.
if (parsedPropertyName.equals(propertyName)) {
return null;
} else {
Log.info(Geonet.RESOURCES,
String.format("Parsed CMIS secondary properties from '%s' to '%s'", propertyName, parsedPropertyName));
return parsedPropertyName;
}
}
}
}
}

// If we make it here then it means that we were not able to parse the value, so it is most likely invalid.
Log.error(Geonet.RESOURCES,
String.format("Unable to locate secondary property name '%s'", propertyName));
}
}
return null;
}
}