Defined a custom pattern for DateTimeFormat to support timezone. The value is also changed on DB configuration when the database is created.
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@148327 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
ed6f906c7e
commit
8951681d06
|
@ -5,6 +5,7 @@ package org.gcube.informationsystem.resourceregistry.dbinitialization;
|
||||||
|
|
||||||
import org.gcube.informationsystem.impl.utils.ISMapper;
|
import org.gcube.informationsystem.impl.utils.ISMapper;
|
||||||
import org.gcube.informationsystem.impl.utils.discovery.ERDiscovery;
|
import org.gcube.informationsystem.impl.utils.discovery.ERDiscovery;
|
||||||
|
import org.gcube.informationsystem.model.ISConstants;
|
||||||
import org.gcube.informationsystem.model.embedded.Embedded;
|
import org.gcube.informationsystem.model.embedded.Embedded;
|
||||||
import org.gcube.informationsystem.model.embedded.ValueSchema;
|
import org.gcube.informationsystem.model.embedded.ValueSchema;
|
||||||
import org.gcube.informationsystem.resourceregistry.context.SecurityContextMapper.PermissionMode;
|
import org.gcube.informationsystem.resourceregistry.context.SecurityContextMapper.PermissionMode;
|
||||||
|
@ -20,6 +21,7 @@ import com.orientechnologies.orient.core.metadata.schema.OSchema;
|
||||||
import com.orientechnologies.orient.core.metadata.security.ORole;
|
import com.orientechnologies.orient.core.metadata.security.ORole;
|
||||||
import com.orientechnologies.orient.core.metadata.security.OSecurity;
|
import com.orientechnologies.orient.core.metadata.security.OSecurity;
|
||||||
import com.orientechnologies.orient.core.metadata.security.OUser;
|
import com.orientechnologies.orient.core.metadata.security.OUser;
|
||||||
|
import com.orientechnologies.orient.core.sql.OCommandSQL;
|
||||||
import com.tinkerpop.blueprints.impls.orient.OrientEdgeType;
|
import com.tinkerpop.blueprints.impls.orient.OrientEdgeType;
|
||||||
import com.tinkerpop.blueprints.impls.orient.OrientGraphFactory;
|
import com.tinkerpop.blueprints.impls.orient.OrientGraphFactory;
|
||||||
import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
|
import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
|
||||||
|
@ -40,6 +42,9 @@ public class DatabaseIntializator {
|
||||||
|
|
||||||
public static final CONNECTION_STRATEGY CONNECTION_STRATEGY_PARAMETER = CONNECTION_STRATEGY.ROUND_ROBIN_CONNECT;
|
public static final CONNECTION_STRATEGY CONNECTION_STRATEGY_PARAMETER = CONNECTION_STRATEGY.ROUND_ROBIN_CONNECT;
|
||||||
|
|
||||||
|
private static final String ALTER_DATETIME_FORMAT_QUERY_TEMPLATE = "ALTER DATABASE DATETIMEFORMAT \"%s\"";
|
||||||
|
|
||||||
|
|
||||||
public static boolean initGraphDB() throws Exception {
|
public static boolean initGraphDB() throws Exception {
|
||||||
|
|
||||||
OLogManager.instance().setWarnEnabled(false);
|
OLogManager.instance().setWarnEnabled(false);
|
||||||
|
@ -72,6 +77,18 @@ public class DatabaseIntializator {
|
||||||
|
|
||||||
OrientGraphNoTx orientGraphNoTx = factory.getNoTx();
|
OrientGraphNoTx orientGraphNoTx = factory.getNoTx();
|
||||||
|
|
||||||
|
/* Updating DateTimeFormat to be aligned with IS model definition */
|
||||||
|
/*
|
||||||
|
* This solution does not work
|
||||||
|
* OStorageConfiguration configuration = orientGraphNoTx.getRawGraph().getStorage().getConfiguration();
|
||||||
|
* configuration.dateTimeFormat = ISConstants.DATETIME_PATTERN;
|
||||||
|
* configuration.update();
|
||||||
|
*/
|
||||||
|
String query = String.format(ALTER_DATETIME_FORMAT_QUERY_TEMPLATE, ISConstants.DATETIME_PATTERN);
|
||||||
|
OCommandSQL preparedQuery = new OCommandSQL( query );
|
||||||
|
orientGraphNoTx.getRawGraph().command( preparedQuery ).execute();
|
||||||
|
|
||||||
|
|
||||||
OMetadata oMetadata = orientGraphNoTx.getRawGraph().getMetadata();
|
OMetadata oMetadata = orientGraphNoTx.getRawGraph().getMetadata();
|
||||||
OSecurity oSecurity = oMetadata.getSecurity();
|
OSecurity oSecurity = oMetadata.getSecurity();
|
||||||
|
|
||||||
|
@ -91,6 +108,8 @@ public class DatabaseIntializator {
|
||||||
DatabaseEnvironment.CHANGED_ADMIN_PASSWORD, adminRole);
|
DatabaseEnvironment.CHANGED_ADMIN_PASSWORD, adminRole);
|
||||||
newAdminUser.save();
|
newAdminUser.save();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for (PermissionMode permissionMode : DatabaseEnvironment.DEFAULT_PASSWORDS
|
for (PermissionMode permissionMode : DatabaseEnvironment.DEFAULT_PASSWORDS
|
||||||
.keySet()) {
|
.keySet()) {
|
||||||
OUser oUser = oSecurity.getUser(permissionMode.toString());
|
OUser oUser = oSecurity.getUser(permissionMode.toString());
|
||||||
|
@ -119,9 +138,14 @@ public class DatabaseIntializator {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
serverAdmin.close();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static void createEntitiesAndRelations() throws Exception {
|
public static void createEntitiesAndRelations() throws Exception {
|
||||||
ERDiscovery erDiscovery = ISMapper.getErdiscovery();
|
ERDiscovery erDiscovery = ISMapper.getErdiscovery();
|
||||||
SchemaActionImpl entityRegistrationAction = new SchemaActionImpl();
|
SchemaActionImpl entityRegistrationAction = new SchemaActionImpl();
|
||||||
|
|
|
@ -194,7 +194,7 @@ public class ContextManagementImplTest {
|
||||||
logger.debug("The DB should be now clean");
|
logger.debug("The DB should be now clean");
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Test
|
//@Test
|
||||||
public void createDevContext() throws Exception {
|
public void createDevContext() throws Exception {
|
||||||
String gcubeJson = contextManagementImpl.create(null, "gcube");
|
String gcubeJson = contextManagementImpl.create(null, "gcube");
|
||||||
Context gcubeContext = ISMapper.unmarshal(Context.class, gcubeJson);
|
Context gcubeContext = ISMapper.unmarshal(Context.class, gcubeJson);
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
package org.gcube.informationsystem.resourceregistry.dbinitialization;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.orientechnologies.orient.core.config.OStorageConfiguration;
|
||||||
|
import com.tinkerpop.blueprints.impls.orient.OrientGraphFactory;
|
||||||
|
import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
|
||||||
|
|
||||||
|
public class DatabaseIntializatorTest {
|
||||||
|
|
||||||
|
private static Logger logger = LoggerFactory.getLogger(DatabaseIntializatorTest.class);
|
||||||
|
|
||||||
|
//@Test
|
||||||
|
public void testInitDB() throws Exception{
|
||||||
|
|
||||||
|
DatabaseIntializator.initGraphDB();
|
||||||
|
|
||||||
|
OrientGraphFactory factory = new OrientGraphFactory(
|
||||||
|
DatabaseEnvironment.DB_URI,
|
||||||
|
DatabaseEnvironment.CHANGED_ADMIN_USERNAME,
|
||||||
|
DatabaseEnvironment.CHANGED_ADMIN_PASSWORD)
|
||||||
|
.setupPool(1, 10);
|
||||||
|
|
||||||
|
OrientGraphNoTx orientGraphNoTx = factory.getNoTx();
|
||||||
|
|
||||||
|
/* Updating Datetime Format to be aligned with IS model definition */
|
||||||
|
OStorageConfiguration configuration = orientGraphNoTx.getRawGraph().getStorage().getConfiguration();
|
||||||
|
logger.debug("Got DateTimeFormat {}", configuration.getDateTimeFormat());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue