Improved Metadata management

This commit is contained in:
Luca Frosini 2023-05-10 17:25:54 +02:00
parent f4600172e2
commit a424844dce
2 changed files with 16 additions and 6 deletions

View File

@ -21,6 +21,7 @@ import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache;
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCacheRenewal;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.contexts.entities.ContextManagement;
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagement;
import org.gcube.informationsystem.resourceregistry.requests.RequestUtility;
import org.gcube.informationsystem.resourceregistry.requests.ServerRequestInfo;
import org.gcube.informationsystem.serialization.ElementMapper;
@ -98,8 +99,7 @@ public class ServerContextCache extends ContextCache {
}
protected boolean isUserAllowedToGetPrivacyMeta() {
// TODO
return true;
return ElementManagement.isUserAllowedToGetPrivacyMeta();
}
public synchronized List<Context> getContexts() throws ResourceRegistryException {
@ -117,8 +117,8 @@ public class ServerContextCache extends ContextCache {
protected Metadata getMetadataForPrivacy(ObjectMapper objectMapper, Metadata metadata) {
ObjectNode objectNode = objectMapper.valueToTree(metadata);
objectNode.set(Metadata.CREATED_BY_PROPERTY, new TextNode(Metadata.HIDDEN_FOR_PRIVACY_USER));
objectNode.set(Metadata.LAST_UPDATE_BY_PROPERTY, new TextNode(Metadata.HIDDEN_FOR_PRIVACY_USER));
objectNode.replace(Metadata.CREATED_BY_PROPERTY, new TextNode(Metadata.HIDDEN_FOR_PRIVACY_USER));
objectNode.replace(Metadata.LAST_UPDATE_BY_PROPERTY, new TextNode(Metadata.HIDDEN_FOR_PRIVACY_USER));
try {
Metadata metadataWithPrivacy = objectMapper.treeToValue(objectNode, Metadata.class);
return metadataWithPrivacy;

View File

@ -1215,6 +1215,11 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
return element;
}
public static boolean isUserAllowedToGetPrivacyMeta() {
// TODO
return true;
}
protected JsonNode getPropertyForJson(String key, Object object) throws ResourceRegistryException {
try {
if(object == null) {
@ -1228,7 +1233,12 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
if(key.compareTo(IdentifiableElement.METADATA_PROPERTY) == 0) {
// Keeping the metadata
MetadataOrient metadataOrient = MetadataUtility.getMetadataOrient((ODocument) object);
JsonNode metadataJson = OrientDBUtility.toJsonNode(metadataOrient);
ObjectNode metadataJson = (ObjectNode) OrientDBUtility.toJsonNode(metadataOrient);
if(!isUserAllowedToGetPrivacyMeta()) {
metadataJson.replace(Metadata.CREATED_BY_PROPERTY, new TextNode(Metadata.HIDDEN_FOR_PRIVACY_USER));
metadataJson.replace(Metadata.LAST_UPDATE_BY_PROPERTY, new TextNode(Metadata.HIDDEN_FOR_PRIVACY_USER));
}
// TODO check a solution for supertypes
TypesCache typesCache = TypesCache.getInstance();
@ -1237,7 +1247,7 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
ObjectMapper objectMapper = new ObjectMapper();
Collection<String> superClasses = metadataType.getSuperTypes();
ArrayNode arrayNode = objectMapper.valueToTree(superClasses);
((ObjectNode) metadataJson).replace(Element.SUPERTYPES_PROPERTY, arrayNode);
metadataJson.replace(Element.SUPERTYPES_PROPERTY, arrayNode);
return metadataJson;
}