From 0ead00f88407453d3276b3af5531ebb5f9e18c4e Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Tue, 5 Nov 2024 18:32:57 +0100 Subject: [PATCH] Fixing issues --- .../base/ElementManagement.java | 2 +- .../contexts/ServerContextCache.java | 62 +++++++++++++------ 2 files changed, 44 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/base/ElementManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/base/ElementManagement.java index be97af5..420c98a 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/base/ElementManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/base/ElementManagement.java @@ -259,7 +259,7 @@ public abstract class ElementManagement { protected Environment getWorkingEnvironment() throws ResourceRegistryException { if(workingEnvironment == null) { workingEnvironment = ContextUtility.getCurrentRequestEnvironment(); - Context context = ServerContextCache.getInstance().getContextByUUID(workingEnvironment.getUUID()); + Context context = ServerContextCache.getInstance().getFullInfoContextByUUID(workingEnvironment.getUUID()); String state = context.getState(); if(state.compareTo(ContextState.ACTIVE.getState())!=0) { Set allowedRoles = workingEnvironment.getAllowedRoles(); diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/ServerContextCache.java b/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/ServerContextCache.java index cde308f..fe189f3 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/ServerContextCache.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/contexts/ServerContextCache.java @@ -10,6 +10,8 @@ import java.util.SortedSet; import java.util.TreeSet; import java.util.UUID; +import javax.ws.rs.InternalServerErrorException; + import org.gcube.com.fasterxml.jackson.core.JsonProcessingException; import org.gcube.com.fasterxml.jackson.databind.ObjectMapper; import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode; @@ -117,6 +119,11 @@ public class ServerContextCache extends ContextCache { } } + public synchronized Context getFullInfoContextByUUID(UUID uuid) throws ResourceRegistryException { + refreshContextsIfNeeded(); + return uuidToContext.get(uuid); + } + @Override public synchronized Context getContextByUUID(UUID uuid) throws ResourceRegistryException { refreshContextsIfNeeded(); @@ -171,25 +178,42 @@ public class ServerContextCache extends ContextCache { for(Context c : contexts) { UUID uuid = c.getID(); - Context contextWithMeta = new ContextImpl(c.getName()); - contextWithMeta.setMetadata(c.getMetadata()); - contextWithMeta.setID(uuid); - this.contexts.add(contextWithMeta); - this.uuidToContext.put(uuid, contextWithMeta); - - Context contextMetaPrivacy = new ContextImpl(c.getName()); - Metadata metadataWithPrivacy = getMetadataForPrivacy(objectMapper, c.getMetadata()); - contextMetaPrivacy.setMetadata(metadataWithPrivacy); - contextMetaPrivacy.setID(uuid); - this.contextsMetaPrivacy.add(contextMetaPrivacy); - this.uuidToContextMetaPrivacy.put(uuid, contextMetaPrivacy); - - Context contextNoMeta = new ContextImpl(c.getName()); - contextNoMeta.setMetadata(null); - contextNoMeta.setID(uuid); - this.contextsBasicInfo.add(contextNoMeta); - this.uuidToContextBasicInfo.put(uuid, contextNoMeta); - + try { + String contextString = ElementMapper.marshal(c); + + Context contextWithMeta = ElementMapper.unmarshal(Context.class, contextString); + this.contexts.add(contextWithMeta); + this.uuidToContext.put(uuid, contextWithMeta); + + Context contextMetaPrivacy = new ContextImpl(c.getName()); + Metadata metadataWithPrivacy = getMetadataForPrivacy(objectMapper, c.getMetadata()); + contextMetaPrivacy.setMetadata(metadataWithPrivacy); + contextMetaPrivacy.setID(uuid); + this.contextsMetaPrivacy.add(contextMetaPrivacy); + this.uuidToContextMetaPrivacy.put(uuid, contextMetaPrivacy); + + Context contextNoMeta = new ContextImpl(c.getName()); + contextNoMeta.setMetadata(null); + contextNoMeta.setID(uuid); + this.contextsBasicInfo.add(contextNoMeta); + this.uuidToContextBasicInfo.put(uuid, contextNoMeta); + + /* + Context contextMetaPrivacy = ElementMapper.unmarshal(Context.class, contextString); + Metadata metadataWithPrivacy = getMetadataForPrivacy(objectMapper, c.getMetadata()); + contextMetaPrivacy.setMetadata(metadataWithPrivacy); + this.contextsMetaPrivacy.add(contextMetaPrivacy); + this.uuidToContextMetaPrivacy.put(uuid, contextMetaPrivacy); + + Context contextNoMeta = ElementMapper.unmarshal(Context.class, contextString); + contextNoMeta.setMetadata(null); + this.contextsBasicInfo.add(contextNoMeta); + this.uuidToContextBasicInfo.put(uuid, contextNoMeta); + */ + + }catch (Exception e) { + throw new InternalServerErrorException("Error while creating context Cache", e); + } } for(Context c : contexts) {