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:
Luca Frosini 2017-05-05 13:51:40 +00:00
parent ed6f906c7e
commit 8951681d06
3 changed files with 58 additions and 2 deletions

View File

@ -5,6 +5,7 @@ package org.gcube.informationsystem.resourceregistry.dbinitialization;
import org.gcube.informationsystem.impl.utils.ISMapper;
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.ValueSchema;
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.OSecurity;
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.OrientGraphFactory;
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;
private static final String ALTER_DATETIME_FORMAT_QUERY_TEMPLATE = "ALTER DATABASE DATETIMEFORMAT \"%s\"";
public static boolean initGraphDB() throws Exception {
OLogManager.instance().setWarnEnabled(false);
@ -72,6 +77,18 @@ public class DatabaseIntializator {
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();
OSecurity oSecurity = oMetadata.getSecurity();
@ -91,6 +108,8 @@ public class DatabaseIntializator {
DatabaseEnvironment.CHANGED_ADMIN_PASSWORD, adminRole);
newAdminUser.save();
for (PermissionMode permissionMode : DatabaseEnvironment.DEFAULT_PASSWORDS
.keySet()) {
OUser oUser = oSecurity.getUser(permissionMode.toString());
@ -119,9 +138,14 @@ public class DatabaseIntializator {
return true;
}
serverAdmin.close();
return false;
}
public static void createEntitiesAndRelations() throws Exception {
ERDiscovery erDiscovery = ISMapper.getErdiscovery();
SchemaActionImpl entityRegistrationAction = new SchemaActionImpl();

View File

@ -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());
}
}