Fixed ContextCache management
This commit is contained in:
parent
723bb8dff2
commit
a026f9ecda
|
@ -1,9 +1,7 @@
|
|||
package org.gcube.informationsystem.resourceregistry.contexts.entities;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
|
@ -19,7 +17,6 @@ import org.gcube.informationsystem.contexts.reference.relations.IsParentOf;
|
|||
import org.gcube.informationsystem.model.reference.properties.Header;
|
||||
import org.gcube.informationsystem.model.reference.relations.Relation;
|
||||
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache;
|
||||
import org.gcube.informationsystem.resourceregistry.api.contexts.ContextCacheRenewal;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.AlreadyPresentException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
||||
|
@ -63,26 +60,9 @@ public class ContextManagement extends EntityElementManagement<Context, EntityTy
|
|||
this.typeName = Context.NAME;
|
||||
}
|
||||
|
||||
protected ContextCacheRenewal contextCacheRenewal = new ContextCacheRenewal() {
|
||||
|
||||
@Override
|
||||
public List<Context> renew() throws ResourceRegistryException {
|
||||
String contextsJsonString = allFromServer(false);
|
||||
List<Context> contexts = null;
|
||||
try {
|
||||
contexts = ElementMapper.unmarshalList(contextsJsonString);
|
||||
} catch (IOException e) {
|
||||
logger.error("Unable to read contexts from DB", e);
|
||||
}
|
||||
return contexts;
|
||||
}
|
||||
};
|
||||
|
||||
public ContextManagement() {
|
||||
super(AccessType.CONTEXT);
|
||||
init();
|
||||
ContextCache contextCache = ContextCache.getInstance();
|
||||
contextCache.setContextCacheRenewal(contextCacheRenewal);
|
||||
}
|
||||
|
||||
public ContextManagement(ODatabaseDocument oDatabaseDocument) throws ResourceRegistryException {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.gcube.informationsystem.resourceregistry.dbinitialization;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.security.Key;
|
||||
|
@ -17,13 +18,18 @@ import org.gcube.informationsystem.base.reference.Element;
|
|||
import org.gcube.informationsystem.base.reference.entities.EntityElement;
|
||||
import org.gcube.informationsystem.base.reference.properties.PropertyElement;
|
||||
import org.gcube.informationsystem.base.reference.relations.RelationElement;
|
||||
import org.gcube.informationsystem.contexts.reference.entities.Context;
|
||||
import org.gcube.informationsystem.model.reference.properties.Header;
|
||||
import org.gcube.informationsystem.model.reference.properties.Property;
|
||||
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.contexts.security.AdminSecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.contexts.security.ContextSecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.contexts.security.QueryTemplatesSecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.contexts.security.TypeSecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext.PermissionMode;
|
||||
import org.gcube.informationsystem.resourceregistry.contexts.security.TypeSecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagement;
|
||||
import org.gcube.informationsystem.resourceregistry.types.properties.PropertyTypeDefinitionManagement;
|
||||
import org.gcube.informationsystem.types.TypeMapper;
|
||||
|
@ -37,6 +43,7 @@ import org.gcube.informationsystem.types.reference.properties.PropertyType;
|
|||
import org.gcube.informationsystem.types.reference.relations.ConsistsOfType;
|
||||
import org.gcube.informationsystem.types.reference.relations.IsRelatedToType;
|
||||
import org.gcube.informationsystem.types.reference.relations.RelationType;
|
||||
import org.gcube.informationsystem.utils.ElementMapper;
|
||||
import org.gcube.informationsystem.utils.discovery.ElementSpecilizationDiscovery;
|
||||
import org.gcube.informationsystem.utils.discovery.RegistrationProvider;
|
||||
import org.gcube.informationsystem.utils.discovery.SchemaAction;
|
||||
|
@ -253,6 +260,8 @@ public class DatabaseEnvironment {
|
|||
|
||||
KEY = initDbKey(properties);
|
||||
|
||||
initContextCacheRenewal();
|
||||
|
||||
}
|
||||
|
||||
protected static Key initDbKey(Properties properties) {
|
||||
|
@ -338,6 +347,26 @@ public class DatabaseEnvironment {
|
|||
}
|
||||
}
|
||||
|
||||
public static void initContextCacheRenewal() {
|
||||
ContextCacheRenewal contextCacheRenewal = new ContextCacheRenewal() {
|
||||
|
||||
@Override
|
||||
public List<Context> renew() throws ResourceRegistryException {
|
||||
ContextManagement contextManagement = new ContextManagement();
|
||||
String contextsJsonString = contextManagement.allFromServer(false);
|
||||
List<Context> contexts = null;
|
||||
try {
|
||||
contexts = ElementMapper.unmarshalList(contextsJsonString);
|
||||
} catch (IOException e) {
|
||||
logger.error("Unable to read contexts from DB", e);
|
||||
}
|
||||
return contexts;
|
||||
}
|
||||
};
|
||||
ContextCache.getInstance().setContextCacheRenewal(contextCacheRenewal);
|
||||
}
|
||||
|
||||
|
||||
public static Key getDatabaseKey() {
|
||||
return KEY;
|
||||
}
|
||||
|
|
|
@ -303,4 +303,17 @@ public class AddToContextTest extends MultiContextTest {
|
|||
|
||||
}
|
||||
}
|
||||
|
||||
// @Test
|
||||
// public void testAddToContext() throws Exception {
|
||||
// ContextCache contextCache = ContextCache.getInstance();
|
||||
// HostingNode hostingNode = new HostingNodeImpl();
|
||||
// Header header = new HeaderImpl(UUID.fromString("a87bb07e-5320-4fd8-a48d-bf3cc55756c4"));
|
||||
// hostingNode.setHeader(header);
|
||||
// ResourceManagement resourceManagement = ERManagementTest.getResourceManagement(hostingNode);
|
||||
// resourceManagement.setDryRun(false);
|
||||
// UUID contextUUID = ContextUtility.getInstance().getSecurityContextByFullName("/gcube/devsec").getUUID();
|
||||
// resourceManagement.addToContext(contextUUID);
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue