Improved Metadata management
This commit is contained in:
parent
f4600172e2
commit
a424844dce
|
@ -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.contexts.ContextCacheRenewal;
|
||||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
import org.gcube.informationsystem.resourceregistry.contexts.entities.ContextManagement;
|
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.RequestUtility;
|
||||||
import org.gcube.informationsystem.resourceregistry.requests.ServerRequestInfo;
|
import org.gcube.informationsystem.resourceregistry.requests.ServerRequestInfo;
|
||||||
import org.gcube.informationsystem.serialization.ElementMapper;
|
import org.gcube.informationsystem.serialization.ElementMapper;
|
||||||
|
@ -98,8 +99,7 @@ public class ServerContextCache extends ContextCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isUserAllowedToGetPrivacyMeta() {
|
protected boolean isUserAllowedToGetPrivacyMeta() {
|
||||||
// TODO
|
return ElementManagement.isUserAllowedToGetPrivacyMeta();
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized List<Context> getContexts() throws ResourceRegistryException {
|
public synchronized List<Context> getContexts() throws ResourceRegistryException {
|
||||||
|
@ -117,8 +117,8 @@ public class ServerContextCache extends ContextCache {
|
||||||
|
|
||||||
protected Metadata getMetadataForPrivacy(ObjectMapper objectMapper, Metadata metadata) {
|
protected Metadata getMetadataForPrivacy(ObjectMapper objectMapper, Metadata metadata) {
|
||||||
ObjectNode objectNode = objectMapper.valueToTree(metadata);
|
ObjectNode objectNode = objectMapper.valueToTree(metadata);
|
||||||
objectNode.set(Metadata.CREATED_BY_PROPERTY, new TextNode(Metadata.HIDDEN_FOR_PRIVACY_USER));
|
objectNode.replace(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.LAST_UPDATE_BY_PROPERTY, new TextNode(Metadata.HIDDEN_FOR_PRIVACY_USER));
|
||||||
try {
|
try {
|
||||||
Metadata metadataWithPrivacy = objectMapper.treeToValue(objectNode, Metadata.class);
|
Metadata metadataWithPrivacy = objectMapper.treeToValue(objectNode, Metadata.class);
|
||||||
return metadataWithPrivacy;
|
return metadataWithPrivacy;
|
||||||
|
|
|
@ -1215,6 +1215,11 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isUserAllowedToGetPrivacyMeta() {
|
||||||
|
// TODO
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
protected JsonNode getPropertyForJson(String key, Object object) throws ResourceRegistryException {
|
protected JsonNode getPropertyForJson(String key, Object object) throws ResourceRegistryException {
|
||||||
try {
|
try {
|
||||||
if(object == null) {
|
if(object == null) {
|
||||||
|
@ -1228,7 +1233,12 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
||||||
if(key.compareTo(IdentifiableElement.METADATA_PROPERTY) == 0) {
|
if(key.compareTo(IdentifiableElement.METADATA_PROPERTY) == 0) {
|
||||||
// Keeping the metadata
|
// Keeping the metadata
|
||||||
MetadataOrient metadataOrient = MetadataUtility.getMetadataOrient((ODocument) object);
|
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
|
// TODO check a solution for supertypes
|
||||||
TypesCache typesCache = TypesCache.getInstance();
|
TypesCache typesCache = TypesCache.getInstance();
|
||||||
|
@ -1237,7 +1247,7 @@ public abstract class ElementManagement<El extends OElement, T extends Type> {
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
Collection<String> superClasses = metadataType.getSuperTypes();
|
Collection<String> superClasses = metadataType.getSuperTypes();
|
||||||
ArrayNode arrayNode = objectMapper.valueToTree(superClasses);
|
ArrayNode arrayNode = objectMapper.valueToTree(superClasses);
|
||||||
((ObjectNode) metadataJson).replace(Element.SUPERTYPES_PROPERTY, arrayNode);
|
metadataJson.replace(Element.SUPERTYPES_PROPERTY, arrayNode);
|
||||||
|
|
||||||
return metadataJson;
|
return metadataJson;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue