Skip to content

Commit

Permalink
Add support for 3 new properties in jcloud
Browse files Browse the repository at this point in the history
- jcloud.external.resource.management.created.date.property.name - to support identifying the property name to store the creation date.
- jcloud.external.resource.management.version.property.name - to identify the property name to store the version number.
- jcloud.metadata.property.exclude.list - to identify properties to exclude when creating new versions
  • Loading branch information
ianwallen committed Oct 15, 2024
1 parent eb1a2e9 commit e83d308
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,25 @@ private MetadataResource createResourceDescription(final ServiceContext context,
StorageMetadata storageMetadata, int metadataId, boolean approved) {
String filename = getFilename(metadataUuid, resourceId);

Date changedDate;
String changedDatePropertyName = jCloudConfiguration.getExternalResourceManagementChangedDatePropertyName();
if (storageMetadata.getUserMetadata().containsKey(changedDatePropertyName)) {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
String changedDateValue = storageMetadata.getUserMetadata().get(changedDatePropertyName);
changedDate = formatter.parse(changedDateValue);
} else {
changedDate = storageMetadata.getLastModified();
}
}

String versionValue = null;
if (jCloudConfiguration.isVersioningEnabled()) {
versionValue = storageMetadata.getETag(); // ETAG is cryptic may need some other value?
String versionPropertyName = jCloudConfiguration.getExternalResourceManagementVersionPropertyName();
if (storageMetadata.getUserMetadata().containsKey(versionPropertyName)) {
versionValue = storageMetadata.getUserMetadata().get(versionPropertyName);
} else {
versionValue = storageMetadata.getETag();
}
}

MetadataResourceExternalManagementProperties.ValidationStatus validationStatus = MetadataResourceExternalManagementProperties.ValidationStatus.UNKNOWN;
Expand All @@ -157,7 +173,7 @@ private MetadataResource createResourceDescription(final ServiceContext context,
getMetadataResourceExternalManagementProperties(context, metadataId, metadataUuid, visibility, resourceId, filename, storageMetadata.getETag(), storageMetadata.getType(), validationStatus);

return new FilesystemStoreResource(metadataUuid, metadataId, filename,
settingManager.getNodeURL() + "api/records/", visibility, storageMetadata.getSize(), storageMetadata.getLastModified(), versionValue, metadataResourceExternalManagementProperties, approved);
settingManager.getNodeURL() + "api/records/", visibility, storageMetadata.getSize(), changedDate, versionValue, metadataResourceExternalManagementProperties, approved);
}

protected static String getFilename(final String key) {
Expand Down Expand Up @@ -215,21 +231,31 @@ protected MetadataResource putResource(final ServiceContext context, final Strin
Map<String, String> properties = null;
try {
try {
StorageMetadata storageMetadata = jCloudConfiguration.getClient().getBlobStore().blobMetadata(jCloudConfiguration.getContainerName(), key);
if (storageMetadata != null) {
properties = storageMetadata.getUserMetadata();
Set<String> excludeList = jCloudConfiguration.getPropertyExculudeList();
// Copy existing properties except for items from the exclude list.
properties = storageMetadata.getUserMetadata().entrySet().stream()
.filter(entry -> !excludeList.contains(entry.getKey()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}
} catch (ContainerNotFoundException ignored) {
// ignored
}

if (properties == null) {
properties = new HashMap<>();
}
addProperties(metadataUuid, properties, changeDate, additionalProperties);
// If changeDate not supplied then default to now.
addProperties(metadataUuid, properties, (changeDate == null ? new Date() : changeDate), additionalProperties);
// Update/set version
setPropertiesVersion(properties);
Blob blob = jCloudConfiguration.getClient().getBlobStore().blobBuilder(key)
.payload(is)
Expand All @@ -245,6 +271,40 @@ protected MetadataResource putResource(final ServiceContext context, final Strin
}
protected void setPropertiesVersion(Map<String, String> properties) {
//Todo: add logic to set the vresion
//Todo: add logic to set the vresion
//Todo: add logic to set the vresion
//Todo: add logic to set the vresion
//Todo: add logic to set the vresion
if(!StringUtils.isEmpty(jCloudConfiguration.getExternalResourceManagementVersionPropertyName())) {
// Parse the current version label
currentVersionLabel = properties.containskey(jCloudConfiguration.getExternalResourceManagementVersionPropertyName()))
String[] versionParts = currentVersionLabel.split("\\.");
int majorVersion = Integer.parseInt(versionParts[0]);
int minorVersion = Integer.parseInt(versionParts[1]);
// Increment the major version and reset the minor version
majorVersion++;
minorVersion = 0;
// Create the new version label
String newVersionLabel = majorVersion + "." + minorVersion;
// Create a new blob with the updated payload and version metadata
Blob newBlob = blobStore.blobBuilder(blobName)
.payload(newPayload)
.userMetadata(Map.of("versionLabel", newVersionLabel))
.build();
// Upload the new version
blobStore.putBlob(containerName, newBlob);
// Return the new version label
return newVersionLabel;
}
}
protected void addProperties(String metadataUuid, Map<String, String> properties, Date changeDate, Map<String, String> additionalProperties) {
// Add additional properties if exists.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ public class JCloudConfiguration {
*/
private String externalResourceManagementChangedDatePropertyName;

/**
* Property name for storing the creation date of the record.
*/
private String externalResourceManagementCreatedDatePropertyName;

/**
* Property name for validation status that is expected to be an integer with values of null, 0, 1, 2
* (See MetadataResourceExternalManagementProperties.ValidationStatus for code meaning)
Expand All @@ -86,7 +91,18 @@ public class JCloudConfiguration {
* Enable option to add versioning in the link to the resource.
*/
private Boolean versioningEnabled;
/**
* Property name for storing the version information JCloud does not support versioning.
*/
private String externalResourceManagementVersionPropertyName;

/**
* Property name for identifying fields that should not be carried over to the next version when updating field.
* i.e. assume a migration was performed and a new migration_source_id was added. It when creating a new version,
* you may not want migration_source_id carried over to the next version.
*/
private String metadataPropertyExculudeList;
private Set<String> propertyExculudeList = null;

public void setProvider(String provider) {
this.provider = provider;
Expand Down Expand Up @@ -225,6 +241,14 @@ public void setVersioningEnabled(String versioningEnabled) {
this.versioningEnabled = BooleanUtils.toBooleanObject(versioningEnabled);
}

public String getExternalResourceManagementVersionPropertyName() {
return externalResourceManagementVersionPropertyName;
}

public void setExternalResourceManagementVersionPropertyName(String externalResourceManagementVersionPropertyName) {
this.externalResourceManagementVersionPropertyName = externalResourceManagementVersionPropertyName;
}

public String getMetadataUUIDPropertyName() {
return metadataUUIDPropertyName;
}
Expand All @@ -240,6 +264,15 @@ public String getExternalResourceManagementChangedDatePropertyName() {
public void setExternalResourceManagementChangedDatePropertyName(String externalResourceManagementChangedDatePropertyName) {
this.externalResourceManagementChangedDatePropertyName = externalResourceManagementChangedDatePropertyName;
}

public String getExternalResourceManagementCreatedDatePropertyName() {
return externalResourceManagementCreatedDatePropertyName;
}

public void setExternalResourceManagementCreatedDatePropertyName(String externalResourceManagementCreatedDatePropertyName) {
this.externalResourceManagementCreatedDatePropertyName = externalResourceManagementCreatedDatePropertyName;
}

public String getExternalResourceManagementValidationStatusPropertyName() {
return externalResourceManagementValidationStatusPropertyName;
}
Expand All @@ -264,6 +297,24 @@ public MetadataResourceExternalManagementProperties.ValidationStatus getValidati
return this.defaultStatus;
}

public String getMetadataPropertyExculudeList() {
return metadataPropertyExculudeList;
}

public void setMetadataPropertyExculudeList(String metadataPropertyExculudeList) {
this.metadataPropertyExculudeList = metadataPropertyExculudeList;
}

public Set<String> getPropertyExculudeList() {
if (propertyExculudeList == null) {
propertyExculudeList = Arrays.stream(metadataPropertyExculudeList.split(","))
.map(String::trim)
.filter(field -> !field.isEmpty())
.collect(Collectors.toSet());
}
return propertyExculudeList;
}

@PostConstruct
public void init() {
if (folderDelimiter == null) {
Expand Down Expand Up @@ -311,7 +362,8 @@ private void validateMetadataPropertyNames() throws IllegalArgumentException {
String[] names = {
getMetadataUUIDPropertyName(),
getExternalResourceManagementChangedDatePropertyName(),
getExternalResourceManagementValidationStatusPropertyName()
getExternalResourceManagementValidationStatusPropertyName(),
getExternalResourceManagementCreatedDatePropertyName()
};

JCloudMetadataNameValidator.validateMetadataNamesForProvider(provider, names);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ jcloud.external.resource.management.validation.status.property.name=${JCLOUD_EXT
jcloud.external.resource.management.validation.status.default.value=${JCLOUD_EXTERNAL_RESOURCE_MANAGEMENT_VALIDATION_STATUS_DEFAULT_VALUE:#{null}}

jcloud.external.resource.management.changed.date.property.name=${JCLOUD_EXTERNAL_RESOURCE_MANAGEMENT_CHANGE_DATE_PROPERTY_NAME:#{null}}
jcloud.external.resource.management.created.date.property.name=${JCLOUD_EXTERNAL_RESOURCE_MANAGEMENT_CREATED_DATE_PROPERTY_NAME:#{null}}

jcloud.versioning.enabled=${JCLOUD_VERSIONING_ENABLED:#{null}}
jcloud.external.resource.management.version.property.name=${JCLOUD_EXTERNAL_RESOURCE_MANAGEMENT_VERSION_PROPERTY_NAME:#{null}}

jcloud.metadata.uuid.property.name=${JCLOUD_METADATA_UUID_PROPERTY_NAME:#{null}}
jcloud.metadata.property.exclude.list=${JCLOUD_METADATA_PROPERTY_EXCLUDE_LIST:#{null}}

Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,13 @@
<property name="externalResourceManagementValidationStatusPropertyName" value="${jcloud.external.resource.management.validation.status.property.name}"/>
<property name="externalResourceManagementValidationStatusDefaultValue" value="${jcloud.external.resource.management.validation.status.default.value}"/>
<property name="externalResourceManagementChangedDatePropertyName" value="${jcloud.external.resource.management.changed.date.property.name}"/>
<property name="externalResourceManagementCreatedDatePropertyName" value="${jcloud.external.resource.management.created.date.property.name}"/>

<property name="versioningEnabled" value="${jcloud.versioning.enabled}"/>
<property name="externalResourceManagementVersionPropertyName" value="${jcloud.external.resource.management.version.property.name}"/>

<property name="metadataUUIDPropertyName" value="${jcloud.metadata.uuid.property.name}"/>
<property name="metadataPropertyExculudeList" value="${jcloud.metadata.property.exclude.list}"/>
</bean>
<bean id="filesystemStore" class="org.fao.geonet.api.records.attachments.JCloudStore" />
<bean id="resourceStore"
Expand Down

0 comments on commit e83d308

Please sign in to comment.