74 lines
2.5 KiB
Java
74 lines
2.5 KiB
Java
package org.gcube.informationsystem.resourceregistry;
|
|
|
|
import java.io.IOException;
|
|
import java.util.ServiceLoader;
|
|
|
|
import org.gcube.informationsystem.model.impl.entities.ContextImpl;
|
|
import org.gcube.informationsystem.model.reference.entities.Context;
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
|
import org.gcube.informationsystem.resourceregistry.context.ContextManagement;
|
|
import org.gcube.informationsystem.resourceregistry.dbinitialization.SchemaActionImpl;
|
|
import org.gcube.informationsystem.utils.ISMapper;
|
|
import org.gcube.informationsystem.utils.discovery.ISMDiscovery;
|
|
import org.gcube.informationsystem.utils.discovery.RegistrationProvider;
|
|
import org.gcube.informationsystem.utils.discovery.SchemaAction;
|
|
import org.junit.Test;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
public class DataBaseCreator {
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(ISMDiscovery.class);
|
|
|
|
@Test
|
|
public void createDatabase() throws Exception {
|
|
SchemaAction schemaAction = new SchemaActionImpl();
|
|
ServiceLoader<? extends RegistrationProvider> regsitrationProviders = ServiceLoader
|
|
.load(RegistrationProvider.class);
|
|
for(RegistrationProvider registrationProvider : regsitrationProviders) {
|
|
ISMDiscovery.manageISM(schemaAction, registrationProvider.getPackagesToRegister());
|
|
}
|
|
}
|
|
|
|
|
|
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;
|
|
}
|
|
|
|
// @Test
|
|
public void createDevContext() throws Exception {
|
|
Context gcube = new ContextImpl("gcube");
|
|
gcube = create(gcube);
|
|
|
|
Context devsec = new ContextImpl("devsec");
|
|
devsec.setParent(gcube);
|
|
devsec = create(devsec);
|
|
|
|
Context devVRE = new ContextImpl("devVRE");
|
|
devVRE.setParent(devsec);
|
|
devVRE = create(devVRE);
|
|
|
|
Context devNext = new ContextImpl("devNext");
|
|
devNext.setParent(gcube);
|
|
devNext = create(devNext);
|
|
|
|
Context nextNext = new ContextImpl("NextNext");
|
|
nextNext.setParent(devNext);
|
|
nextNext = create(nextNext);
|
|
|
|
Context preprod = new ContextImpl("preprod");
|
|
preprod.setParent(gcube);
|
|
preprod = create(preprod);
|
|
|
|
Context preVRE = new ContextImpl("preVRE");
|
|
preVRE.setParent(preprod);
|
|
preVRE = create(preVRE);
|
|
}
|
|
|
|
}
|