From 8951681d063bc1e12525452fe47701d23c925185 Mon Sep 17 00:00:00 2001 From: "luca.frosini" Date: Fri, 5 May 2017 13:51:40 +0000 Subject: [PATCH] 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 --- .../DatabaseIntializator.java | 26 ++++++++++++++- .../context/ContextManagementImplTest.java | 2 +- .../DatabaseIntializatorTest.java | 32 +++++++++++++++++++ 3 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 src/test/java/org/gcube/informationsystem/resourceregistry/dbinitialization/DatabaseIntializatorTest.java diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/dbinitialization/DatabaseIntializator.java b/src/main/java/org/gcube/informationsystem/resourceregistry/dbinitialization/DatabaseIntializator.java index ab7eea3..082c48a 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/dbinitialization/DatabaseIntializator.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/dbinitialization/DatabaseIntializator.java @@ -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,9 +77,21 @@ 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(); - + logger.trace("Changing {} password", DatabaseEnvironment.DEFAULT_ADMIN_USERNAME); @@ -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,8 +138,13 @@ public class DatabaseIntializator { return true; } + serverAdmin.close(); + return false; } + + + public static void createEntitiesAndRelations() throws Exception { ERDiscovery erDiscovery = ISMapper.getErdiscovery(); diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/context/ContextManagementImplTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/context/ContextManagementImplTest.java index 008fb8b..9e4086d 100644 --- a/src/test/java/org/gcube/informationsystem/resourceregistry/context/ContextManagementImplTest.java +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/context/ContextManagementImplTest.java @@ -194,7 +194,7 @@ public class ContextManagementImplTest { logger.debug("The DB should be now clean"); } - // @Test + //@Test public void createDevContext() throws Exception { String gcubeJson = contextManagementImpl.create(null, "gcube"); Context gcubeContext = ISMapper.unmarshal(Context.class, gcubeJson); diff --git a/src/test/java/org/gcube/informationsystem/resourceregistry/dbinitialization/DatabaseIntializatorTest.java b/src/test/java/org/gcube/informationsystem/resourceregistry/dbinitialization/DatabaseIntializatorTest.java new file mode 100644 index 0000000..c632380 --- /dev/null +++ b/src/test/java/org/gcube/informationsystem/resourceregistry/dbinitialization/DatabaseIntializatorTest.java @@ -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()); + + } +}