fixed bug
This commit is contained in:
parent
39373982ed
commit
2ff9841de2
|
@ -3,6 +3,7 @@ package org.gcube.informationsystem.resourceregistry.contexts;
|
|||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -64,10 +65,12 @@ public class ServerContextCache extends ContextCache {
|
|||
@Override
|
||||
protected void cleanCache(Calendar now) {
|
||||
super.cleanCache(now);
|
||||
contextsMetaPrivacy = null;
|
||||
uuidToContextMetaPrivacy = null;
|
||||
contextsBasicInfo = null;
|
||||
uuidToContextBasicInfo = null;
|
||||
|
||||
this.contextsMetaPrivacy = new ArrayList<>();
|
||||
this.uuidToContextMetaPrivacy = new LinkedHashMap<>();
|
||||
|
||||
this.contextsBasicInfo = new ArrayList<>();
|
||||
this.uuidToContextBasicInfo = new LinkedHashMap<>();
|
||||
}
|
||||
|
||||
public ServerContextCache() {
|
||||
|
@ -108,7 +111,7 @@ public class ServerContextCache extends ContextCache {
|
|||
public synchronized List<Context> getContexts() throws ResourceRegistryException {
|
||||
refreshContextsIfNeeded();
|
||||
ServerRequestInfo requestInfo = RequestUtility.getRequestInfo().get();
|
||||
if(requestInfo.getUriInfo()!=null && !requestInfo.includeMeta()){
|
||||
if(requestInfo!=null && !requestInfo.includeMeta()){
|
||||
return contextsBasicInfo;
|
||||
}
|
||||
ContextManagement contextManagement = new ContextManagement();
|
||||
|
@ -119,9 +122,15 @@ public class ServerContextCache extends ContextCache {
|
|||
}
|
||||
}
|
||||
|
||||
public synchronized List<Context> getFullInfoContexts() throws ResourceRegistryException {
|
||||
refreshContextsIfNeeded();
|
||||
return contexts;
|
||||
}
|
||||
|
||||
public synchronized Context getFullInfoContextByUUID(UUID uuid) throws ResourceRegistryException {
|
||||
refreshContextsIfNeeded();
|
||||
return uuidToContext.get(uuid);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -163,15 +172,7 @@ public class ServerContextCache extends ContextCache {
|
|||
|
||||
@Override
|
||||
protected void setContexts(Calendar calendar, List<Context> contexts) {
|
||||
this.contexts = new ArrayList<>();
|
||||
this.uuidToContext = new LinkedHashMap<>();
|
||||
|
||||
this.contextsMetaPrivacy = new ArrayList<>();
|
||||
this.uuidToContextMetaPrivacy = new LinkedHashMap<>();
|
||||
|
||||
this.contextsBasicInfo = new ArrayList<>();
|
||||
this.uuidToContextBasicInfo = new LinkedHashMap<>();
|
||||
|
||||
cleanCache(calendar);
|
||||
|
||||
ObjectMapper objectMapper = ElementMapper.getObjectMapper();
|
||||
|
||||
|
@ -179,43 +180,57 @@ public class ServerContextCache extends ContextCache {
|
|||
UUID uuid = c.getID();
|
||||
|
||||
try {
|
||||
String contextString = ElementMapper.marshal(c);
|
||||
|
||||
Context contextWithMeta = ElementMapper.unmarshal(Context.class, contextString);
|
||||
/*
|
||||
* The user entitled to get all meta is also
|
||||
* entitled to get state as well as
|
||||
* additional properties
|
||||
*/
|
||||
Context contextWithMeta = new ContextImpl(c.getName());
|
||||
contextWithMeta.setMetadata(c.getMetadata());
|
||||
contextWithMeta.setID(uuid);
|
||||
contextWithMeta.setState(c.getState());
|
||||
contextWithMeta.setAdditionalProperties(c.getAdditionalProperties());
|
||||
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);
|
||||
/*
|
||||
* state and additional properties are not added because
|
||||
* the user which get this classes are non entitled to get this info
|
||||
*
|
||||
* contextMetaPrivacy.setState(c.getState());
|
||||
* contextMetaPrivacy.setAdditionalProperties(c.getAdditionalProperties());
|
||||
*/
|
||||
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);
|
||||
* state and additional properties are not added because
|
||||
* the user which get this classes are non entitled to get this info
|
||||
*
|
||||
* contextNoMeta.setState(c.getState());
|
||||
* contextNoMeta.setAdditionalProperties(c.getAdditionalProperties());
|
||||
*/
|
||||
this.contextsBasicInfo.add(contextNoMeta);
|
||||
this.uuidToContextBasicInfo.put(uuid, contextNoMeta);
|
||||
*/
|
||||
|
||||
}catch (Exception e) {
|
||||
throw new InternalServerErrorException("Error while creating context Cache", e);
|
||||
}
|
||||
}
|
||||
|
||||
Map<UUID, IsParentOf> parentOfWithMetaMap = new HashMap<>();
|
||||
Map<UUID, IsParentOf> parentOfMetaWithPrivacyMap = new HashMap<>();
|
||||
Map<UUID, IsParentOf> parentOfNoMetaMap = new HashMap<>();
|
||||
|
||||
for(Context c : contexts) {
|
||||
UUID uuid = c.getID();
|
||||
|
||||
|
@ -223,32 +238,45 @@ public class ServerContextCache extends ContextCache {
|
|||
Context contextMetaPrivacy = this.uuidToContextMetaPrivacy.get(uuid);
|
||||
Context contextNoMeta = this.uuidToContextBasicInfo.get(uuid);
|
||||
|
||||
|
||||
if(c.getParent()!=null) {
|
||||
IsParentOf ipo = c.getParent();
|
||||
UUID isParentOfParentUUID = ipo.getID();
|
||||
UUID contextParentUUID = ipo.getSource().getID();
|
||||
|
||||
Context parentWithMeta = this.uuidToContext.get(contextParentUUID);
|
||||
IsParentOf isParentOfWithMeta = new IsParentOfImpl(parentWithMeta, contextMeta);
|
||||
IsParentOf isParentOfWithMeta = parentOfWithMetaMap.get(isParentOfParentUUID);
|
||||
if(isParentOfWithMeta==null) {
|
||||
isParentOfWithMeta = new IsParentOfImpl(parentWithMeta, contextMeta);
|
||||
isParentOfWithMeta.setID(isParentOfParentUUID);
|
||||
isParentOfWithMeta.setMetadata(ipo.getMetadata());
|
||||
parentOfWithMetaMap.put(isParentOfParentUUID, isParentOfWithMeta);
|
||||
parentWithMeta.addChild(isParentOfWithMeta);
|
||||
}
|
||||
contextMeta.setParent(isParentOfWithMeta);
|
||||
|
||||
|
||||
Context parentWithMetaPrivacy = this.uuidToContextMetaPrivacy.get(contextParentUUID);
|
||||
IsParentOf isParentOfMetaPrivacy = new IsParentOfImpl(parentWithMetaPrivacy, contextMetaPrivacy);
|
||||
IsParentOf isParentOfMetaPrivacy = parentOfMetaWithPrivacyMap.get(isParentOfParentUUID);
|
||||
if(isParentOfMetaPrivacy==null) {
|
||||
isParentOfMetaPrivacy = new IsParentOfImpl(parentWithMetaPrivacy, contextMetaPrivacy);
|
||||
isParentOfMetaPrivacy.setID(isParentOfParentUUID);
|
||||
Metadata metadataWithPrivacy = getMetadataForPrivacy(objectMapper, ipo.getMetadata());
|
||||
isParentOfMetaPrivacy.setMetadata(metadataWithPrivacy);
|
||||
parentOfMetaWithPrivacyMap.put(isParentOfParentUUID, isParentOfMetaPrivacy);
|
||||
parentWithMetaPrivacy.addChild(isParentOfMetaPrivacy);
|
||||
}
|
||||
contextMetaPrivacy.setParent(isParentOfMetaPrivacy);
|
||||
|
||||
|
||||
Context parentNoMeta = this.uuidToContextBasicInfo.get(contextParentUUID);
|
||||
IsParentOf isParentOfNoMeta = new IsParentOfImpl(parentNoMeta, contextNoMeta);
|
||||
IsParentOf isParentOfNoMeta = parentOfNoMetaMap.get(isParentOfParentUUID);
|
||||
if(isParentOfNoMeta==null) {
|
||||
isParentOfNoMeta = new IsParentOfImpl(parentNoMeta, contextNoMeta);
|
||||
isParentOfNoMeta.setMetadata(null);
|
||||
isParentOfNoMeta.setID(isParentOfParentUUID);
|
||||
parentOfNoMetaMap.put(isParentOfParentUUID, isParentOfNoMeta);
|
||||
parentNoMeta.addChild(isParentOfNoMeta);
|
||||
}
|
||||
contextNoMeta.setParent(isParentOfNoMeta);
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue