Added class to create missing context

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/private/luca.frosini/resource-registry-database-creator@166941 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2018-04-12 13:04:25 +00:00
parent 717b603064
commit 4a3ba04384
5 changed files with 154 additions and 2 deletions

View File

@ -60,6 +60,12 @@
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>context-enumeration</artifactId>
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>

View File

@ -0,0 +1,77 @@
package org.gcube.informationsystem.resourceregistry.context;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.gcube.common.scope.impl.ScopeBean;
import org.gcube.context.ContextElaborator;
import org.gcube.informationsystem.impl.entity.ContextImpl;
import org.gcube.informationsystem.impl.utils.ISMapper;
import org.gcube.informationsystem.model.entity.Context;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.context.ContextException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ContextCreator extends ContextElaborator {
private static Logger logger = LoggerFactory.getLogger(ContextCreator.class);
protected Map<String, UUID> contexts;
protected ContextManagement contextManagement;
public ContextCreator() {
super();
contexts = new HashMap<>();
contextManagement = new ContextManagement();
}
protected Context create(Context context) throws ResourceRegistryException, IOException {
ContextManagement contextManagement = new ContextManagement();
contextManagement.setJSON(ISMapper.marshal(context));
String contextString = contextManagement.create();
logger.info("Created {}", contextString);
Context c = ISMapper.unmarshal(Context.class, contextString);
return c;
}
protected UUID getContextUUID(ScopeBean scopeBean) throws ResourceRegistryException, IOException {
if(scopeBean!=null) {
try {
UUID uuid = contexts.get(scopeBean.toString());
if(uuid==null) {
uuid = ContextUtility.getInstance().getContextUUIDFromFullName(scopeBean.toString());
if(uuid!=null) {
contexts.put(scopeBean.toString(), uuid);
}
}
return uuid;
}catch (ContextException e) {
logger.info("{} does not exists", scopeBean);
}
}
return null;
}
@Override
protected void elaborateContext(ScopeBean scopeBean) throws Exception {
UUID uuid = getContextUUID(scopeBean);
if(uuid==null) {
logger.info("Parent Context of {} is {}", scopeBean, scopeBean.enclosingScope());
UUID parentUUID = getContextUUID(scopeBean.enclosingScope());
Context context = new ContextImpl(scopeBean.name());
if(parentUUID!=null) {
context.setParent(parentUUID);
}
context = create(context);
contexts.put(scopeBean.toString(), context.getHeader().getUUID());
}else {
logger.info("Context {} is already present with UUID {}", scopeBean, uuid.toString());
}
}
}

View File

@ -1,5 +1,6 @@
package org.gcube.informationsystem.resourceregistry.context;
import java.io.File;
import java.io.IOException;
import java.util.UUID;
@ -7,6 +8,7 @@ import org.gcube.informationsystem.impl.entity.ContextImpl;
import org.gcube.informationsystem.impl.utils.ISMapper;
import org.gcube.informationsystem.model.entity.Context;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -46,4 +48,18 @@ public class ContextManagementTest {
}
@Test
public void createProductionContext() throws Exception {
File src = new File("src");
File test = new File(src, "test");
File resources = new File(test, "resources");
File voFile = new File(resources, "scopedata.xml");
ContextCreator contextCreator = new ContextCreator();
contextCreator.all(voFile);
}
}

View File

@ -9,8 +9,8 @@
</appender>
<logger name="org.gcube" level="INFO" />
<logger name="org.gcube.informationsystem" level="INFO" />
<logger name="org.gcube" level="ERROR" />
<logger name="org.gcube.informationsystem.resourceregistry.context" level="INFO" />
<root level="WARN">
<appender-ref ref="STDOUT" />

View File

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<infrastructures>
<infrastructure>
<name>d4science</name>
<vos>
<vo>
<name>d4science</name>
<src>ServiceMap_d4science.research-infrastructures.eu.xml</src>
<scope>/d4science.research-infrastructures.eu</scope>
</vo>
<vo>
<name>d4science/D4Research</name>
<src>ServiceMap_D4Research.xml</src>
<scope>/d4science.research-infrastructures.eu/D4Research</scope>
</vo>
<vo>
<name>d4science/Edison</name>
<src>ServiceMap_Edison.xml</src>
<scope>/d4science.research-infrastructures.eu/Edison</scope>
</vo>
<vo>
<name>d4science/FARM</name>
<src>ServiceMap_FARM.xml</src>
<scope>/d4science.research-infrastructures.eu/FARM</scope>
</vo>
<vo>
<name>d4science/gCubeApps</name>
<src>ServiceMap_gCubeApps.xml</src>
<scope>/d4science.research-infrastructures.eu/gCubeApps</scope>
</vo>
<vo>
<name>d4science/OpenAIRE</name>
<src>ServiceMap_OpenAIRE.xml</src>
<scope>/d4science.research-infrastructures.eu/OpenAIRE</scope>
</vo>
<vo>
<name>d4science/ParthenosVO</name>
<src>ServiceMap_ParthenosVO.xml</src>
<scope>/d4science.research-infrastructures.eu/ParthenosVO</scope>
</vo>
<vo>
<name>d4science/SmartArea</name>
<src>ServiceMap_SmartArea.xml</src>
<scope>/d4science.research-infrastructures.eu/SmartArea</scope>
</vo>
<vo>
<name>d4science/SoBigData</name>
<src>ServiceMap_SoBigData.xml</src>
<scope>/d4science.research-infrastructures.eu/SoBigData</scope>
</vo>
</vos>
</infrastructure>
</infrastructures>