Making changes to interface, repository, tests
MODIFY
modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/replicacatalog/DataProductRepository.java
modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/replicacatalog/DataProductRepository.java
@@ -25,7 +25,7 @@ import org.apache.airavata.model.data.replica.DataProductType;
import org.apache.airavata.registry.core.entities.replicacatalog.DataProductEntity;
import org.apache.airavata.registry.core.utils.DBConstants;
import org.apache.airavata.registry.core.utils.QueryConstants;
-import org.apache.airavata.registry.cpi.ReplicaCatalog;
+import org.apache.airavata.registry.cpi.DataProductInterface;
import org.apache.airavata.registry.cpi.ReplicaCatalogException;
import org.apache.airavata.registry.core.utils.ObjectMapperSingleton;
import org.dozer.Mapper;
@@ -35,7 +35,7 @@ import org.slf4j.LoggerFactory;
import java.sql.Timestamp;
import java.util.*;
-public class DataProductRepository extends RepCatAbstractRepository<DataProductModel, DataProductEntity, String> {
+public class DataProductRepository extends RepCatAbstractRepository<DataProductModel, DataProductEntity, String> implements DataProductInterface {
private final static Logger logger = LoggerFactory.getLogger(DataProductRepository.class);
public DataProductRepository() {
@@ -48,8 +48,13 @@ public class DataProductRepository extends RepCatAbstractRepository<DataProductM
}
protected DataProductEntity saveDataProduct(DataProductModel dataProductModel) throws ReplicaCatalogException {
- String productUri = ReplicaCatalog.schema + "://" + UUID.randomUUID().toString();
- dataProductModel.setProductUri(productUri);
+
+ if (dataProductModel.getProductUri() == null) {
+ logger.debug("Setting the Product URI for the new Data Product");
+ dataProductModel.setProductUri(DataProductInterface.schema + "://" + UUID.randomUUID().toString());
+ }
+
+ String productUri = dataProductModel.getProductUri();
Mapper mapper = ObjectMapperSingleton.getInstance();
DataProductEntity dataProductEntity = mapper.map(dataProductModel, DataProductEntity.class);
@@ -65,7 +70,7 @@ public class DataProductRepository extends RepCatAbstractRepository<DataProductM
}
if (dataProductEntity.getReplicaLocations() != null) {
- logger.debug("Populating the product URI for ReplicaLocations objects for the Application Deployment");
+ logger.debug("Populating the product URI for ReplicaLocations objects for the Data Product");
dataProductEntity.getReplicaLocations().forEach(dataReplicaLocationEntity -> dataReplicaLocationEntity.setProductUri(productUri));
}
@@ -84,8 +89,8 @@ public class DataProductRepository extends RepCatAbstractRepository<DataProductM
return saveDataProductModelData(dataProductModel);
}
- public void updateDataProduct(DataProductModel updatedDataProductModel) throws ReplicaCatalogException {
- saveDataProductModelData(updatedDataProductModel);
+ public boolean updateDataProduct(DataProductModel updatedDataProductModel) throws ReplicaCatalogException {
+ return (saveDataProductModelData(updatedDataProductModel) != null);
}
public DataProductModel getDataProduct(String productUri) throws ReplicaCatalogException {

MODIFY
modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/replicacatalog/DataReplicaLocationRepository.java
modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/replicacatalog/DataReplicaLocationRepository.java
@@ -22,9 +22,9 @@ package org.apache.airavata.registry.core.repositories.replicacatalog;
import org.apache.airavata.model.data.replica.DataProductModel;
import org.apache.airavata.model.data.replica.DataReplicaLocationModel;
-import org.apache.airavata.registry.core.entities.replicacatalog.DataProductEntity;
import org.apache.airavata.registry.core.entities.replicacatalog.DataReplicaLocationEntity;
import org.apache.airavata.registry.core.utils.ObjectMapperSingleton;
+import org.apache.airavata.registry.cpi.DataReplicaLocationInterface;
import org.apache.airavata.registry.cpi.ReplicaCatalogException;
import org.dozer.Mapper;
import org.slf4j.Logger;
@@ -34,23 +34,29 @@ import java.sql.Timestamp;
import java.util.List;
import java.util.UUID;
-public class DataReplicaLocationRepository extends RepCatAbstractRepository<DataReplicaLocationModel, DataReplicaLocationEntity, String> {
- private final static Logger logger = LoggerFactory.getLogger(DataProductRepository.class);
+public class DataReplicaLocationRepository extends RepCatAbstractRepository<DataReplicaLocationModel, DataReplicaLocationEntity, String> implements DataReplicaLocationInterface {
+ private final static Logger logger = LoggerFactory.getLogger(DataReplicaLocationRepository.class);
public DataReplicaLocationRepository() { super(DataReplicaLocationModel.class, DataReplicaLocationEntity.class); }
private String saveDataReplicaLocationModelData(DataReplicaLocationModel dataReplicaLocationModel) throws ReplicaCatalogException {
DataReplicaLocationEntity dataReplicaLocationEntity = saveDataReplicaLocation(dataReplicaLocationModel);
- return dataReplicaLocationEntity.getProductUri();
+ return dataReplicaLocationEntity.getReplicaId();
}
private DataReplicaLocationEntity saveDataReplicaLocation(DataReplicaLocationModel dataReplicaLocationModel) throws ReplicaCatalogException {
- String replicaId = UUID.randomUUID().toString();
+
+ if (dataReplicaLocationModel.getReplicaId() == null) {
+ logger.debug("Setting the Replica ID for the new Data Replica Location");
+ dataReplicaLocationModel.setReplicaId(UUID.randomUUID().toString());
+ }
+
+ String replicaId = dataReplicaLocationModel.getReplicaId();
dataReplicaLocationModel.setReplicaId(replicaId);
Mapper mapper = ObjectMapperSingleton.getInstance();
DataReplicaLocationEntity dataReplicaLocationEntity = mapper.map(dataReplicaLocationModel, DataReplicaLocationEntity.class);
- if (!isDataReplicaLocationExists(replicaId)) {
+ if (!isExists(replicaId)) {
logger.debug("Checking if the Data Replica Location already exists");
dataReplicaLocationEntity.setCreationTime(new Timestamp(System.currentTimeMillis()));
}
@@ -60,30 +66,26 @@ public class DataReplicaLocationRepository extends RepCatAbstractRepository<Data
return execute(entityManager -> entityManager.merge(dataReplicaLocationEntity));
}
- public String registerDataReplicaLocation(DataReplicaLocationModel dataReplicaLocationModel) throws ReplicaCatalogException {
+ public String registerReplicaLocation(DataReplicaLocationModel dataReplicaLocationModel) throws ReplicaCatalogException {
return saveDataReplicaLocationModelData(dataReplicaLocationModel);
}
- public void updateDataReplicaLocation(DataReplicaLocationModel dataReplicaLocationModel) throws ReplicaCatalogException {
- saveDataReplicaLocationModelData(dataReplicaLocationModel);
+ public boolean updateReplicaLocation(DataReplicaLocationModel dataReplicaLocationModel) throws ReplicaCatalogException {
+ return (saveDataReplicaLocationModelData(dataReplicaLocationModel) != null);
}
- public DataReplicaLocationModel getDataReplicaLocation(String replicaId) throws ReplicaCatalogException {
+ public DataReplicaLocationModel getReplicaLocation(String replicaId) throws ReplicaCatalogException {
return get(replicaId);
}
- public List<DataReplicaLocationModel> getAllDataReplicaLocations(String productUri) throws ReplicaCatalogException {
+ public List<DataReplicaLocationModel> getAllReplicaLocations(String productUri) throws ReplicaCatalogException {
DataProductRepository dataProductRepository = new DataProductRepository();
DataProductModel dataProductModel = dataProductRepository.getDataProduct(productUri);
List<DataReplicaLocationModel> dataReplicaLocationModelList = dataProductModel.getReplicaLocations();
return dataReplicaLocationModelList;
}
- public boolean isDataReplicaLocationExists(String replicaId) throws ReplicaCatalogException {
- return isExists(replicaId);
- }
-
- public boolean removeDataReplicaLocation(String replicaId) throws ReplicaCatalogException {
+ public boolean removeReplicaLocation(String replicaId) throws ReplicaCatalogException {
return delete(replicaId);
}

MODIFY
modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/DBConstants.java
modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/DBConstants.java
@@ -3,6 +3,7 @@ package org.apache.airavata.registry.core.utils;
public class DBConstants {
public static int SELECT_MAX_ROWS = 1000;
+ public static final String CONFIGURATION = "Configuration";
public static class ComputeResourcePreference {
public static final String GATEWAY_ID = "gatewayId";

MODIFY
modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/JPAUtil/RepCatalogJPAUtils.java
modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/JPAUtil/RepCatalogJPAUtils.java
@@ -56,7 +56,7 @@ public class RepCatalogJPAUtils {
properties.put("openjpa.DynamicEnhancementAgent", "true");
properties.put("openjpa.RuntimeUnenhancedClasses", "unsupported");
properties.put("openjpa.RemoteCommitProvider","sjvm");
- properties.put("openjpa.Log","DefaultLevel=INFO, Runtime=INFO, Tool=INFO, SQL=INFO");
+ properties.put("openjpa.Log","DefaultLevel=TRACE, Runtime=TRACE, Tool=TRACE, SQL=TRACE");
properties.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)");
properties.put("openjpa.jdbc.QuerySQLCache", "false");
properties.put("openjpa.ConnectionFactoryProperties", "PrettyPrint=true, PrettyPrintLineLength=72," +

MODIFY
modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/replicacatalog/DataProductRepositoryTest.java
modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/replicacatalog/DataProductRepositoryTest.java
@@ -21,7 +21,8 @@ package org.apache.airavata.registry.core.repositories.replicacatalog;
import org.apache.airavata.model.data.replica.DataProductModel;
import org.apache.airavata.model.data.replica.DataProductType;
-import org.apache.airavata.registry.core.repositories.util.Initialize;
+import org.apache.airavata.registry.core.entities.replicacatalog.DataProductMetadataEntity;
+import org.apache.airavata.registry.core.repositories.replicacatalog.util.Initialize;
import org.apache.airavata.registry.cpi.ReplicaCatalogException;
import org.junit.After;
import org.junit.Before;
@@ -51,7 +52,6 @@ public class DataProductRepositoryTest {
dataProductRepository = new DataProductRepository();
} catch (Exception e) {
logger.error(e.getMessage(), e);
- throw e;
}
}
@@ -72,8 +72,8 @@ public class DataProductRepositoryTest {
String productUri1 = dataProductRepository.registerDataProduct(testDataProductModel1);
assertTrue(dataProductRepository.isDataProductExists(productUri1));
- DataProductModel retrievedDataProductModel = dataProductRepository.getDataProduct(productUri1);
- assertEquals(retrievedDataProductModel.getProductUri(), productUri1);
+ DataProductModel retrievedDataProductModel1 = dataProductRepository.getDataProduct(productUri1);
+ assertEquals(retrievedDataProductModel1.getProductUri(), productUri1);
DataProductModel testDataProductModel2 = new DataProductModel();
testDataProductModel2.setGatewayId(gatewayId);
@@ -84,8 +84,19 @@ public class DataProductRepositoryTest {
String productUri2 = dataProductRepository.registerDataProduct(testDataProductModel2);
assertTrue(dataProductRepository.isDataProductExists(productUri2));
+ DataProductMetadataEntity dataProductMetadataEntity = new DataProductMetadataEntity();
+ dataProductMetadataEntity.setProductUri(productUri2);
+ dataProductMetadataEntity.setMetadataKey("dataKey");
+ dataProductMetadataEntity.setMetadataValue("dataValue");
+
+ Map<String, String> dataProductMetadataEntityMap = new HashMap<>();
+ dataProductMetadataEntityMap.put(dataProductMetadataEntity.getMetadataKey(), dataProductMetadataEntity.getMetadataValue());
+ testDataProductModel2.setProductMetadata(dataProductMetadataEntityMap);
testDataProductModel2.setParentProductUri(productUri1);
- dataProductRepository.updateDataProduct(testDataProductModel2);
+ assertTrue(dataProductRepository.updateDataProduct(testDataProductModel2));
+
+ DataProductModel retrievedDataProductModel2 = dataProductRepository.getDataProduct(productUri2);
+ assertTrue(retrievedDataProductModel2.getProductMetadata().size() == 1);
DataProductModel retrievedParentDataProductModel = dataProductRepository.getParentDataProduct(productUri2);
assertEquals(retrievedParentDataProductModel.getProductUri(), productUri1);

MODIFY
modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/replicacatalog/DataReplicaLocationRepositoryTest.java
modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/replicacatalog/DataReplicaLocationRepositoryTest.java
@@ -24,7 +24,7 @@ import org.apache.airavata.model.data.replica.DataProductType;
import org.apache.airavata.model.data.replica.DataReplicaLocationModel;
import org.apache.airavata.model.data.replica.ReplicaPersistentType;
import org.apache.airavata.registry.core.entities.replicacatalog.DataReplicaMetadataEntity;
-import org.apache.airavata.registry.core.repositories.util.Initialize;
+import org.apache.airavata.registry.core.repositories.replicacatalog.util.Initialize;
import org.apache.airavata.registry.cpi.ReplicaCatalogException;
import org.junit.After;
import org.junit.Before;
@@ -35,7 +35,6 @@ import org.slf4j.LoggerFactory;
import java.util.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertFalse;
public class DataReplicaLocationRepositoryTest {
@@ -76,14 +75,12 @@ public class DataReplicaLocationRepositoryTest {
DataReplicaLocationModel testDataReplicaLocationModel1 = new DataReplicaLocationModel();
testDataReplicaLocationModel1.setReplicaName("replicaName1");
testDataReplicaLocationModel1.setProductUri(productUri);
- String replicaId1 = dataReplicaLocationRepository.registerDataReplicaLocation(testDataReplicaLocationModel1);
- assertTrue(dataReplicaLocationRepository.isExists(replicaId1));
+ String replicaId1 = dataReplicaLocationRepository.registerReplicaLocation(testDataReplicaLocationModel1);
DataReplicaLocationModel testDataReplicaLocationModel2 = new DataReplicaLocationModel();
testDataReplicaLocationModel2.setReplicaName("replicaName2");
testDataReplicaLocationModel2.setProductUri(productUri);
- String replicaId2 = dataReplicaLocationRepository.registerDataReplicaLocation(testDataReplicaLocationModel2);
- assertTrue(dataReplicaLocationRepository.isExists(replicaId2));
+ String replicaId2 = dataReplicaLocationRepository.registerReplicaLocation(testDataReplicaLocationModel2);
DataReplicaMetadataEntity dataReplicaMetadataEntity1 = new DataReplicaMetadataEntity();
dataReplicaMetadataEntity1.setReplicaId(replicaId1);
@@ -92,17 +89,17 @@ public class DataReplicaLocationRepositoryTest {
DataReplicaMetadataEntity dataReplicaMetadataEntity2 = new DataReplicaMetadataEntity();
dataReplicaMetadataEntity2.setReplicaId(replicaId1);
- dataReplicaMetadataEntity1.setMetadataKey("dataKey2");
- dataReplicaMetadataEntity1.setMetadataValue("dataValue2");
+ dataReplicaMetadataEntity2.setMetadataKey("dataKey2");
+ dataReplicaMetadataEntity2.setMetadataValue("dataValue2");
Map<String, String> dataReplicaMetadataEntityMap = new HashMap<>();
dataReplicaMetadataEntityMap.put(dataReplicaMetadataEntity1.getMetadataKey(), dataReplicaMetadataEntity1.getMetadataValue());
dataReplicaMetadataEntityMap.put(dataReplicaMetadataEntity2.getMetadataKey(), dataReplicaMetadataEntity2.getMetadataValue());
testDataReplicaLocationModel1.setReplicaMetadata(dataReplicaMetadataEntityMap);
testDataReplicaLocationModel1.setReplicaPersistentType(ReplicaPersistentType.TRANSIENT);
- dataReplicaLocationRepository.updateDataReplicaLocation(testDataReplicaLocationModel1);
+ assertTrue(dataReplicaLocationRepository.updateReplicaLocation(testDataReplicaLocationModel1));
- DataReplicaLocationModel retrievedDataReplicaLocationModel = dataReplicaLocationRepository.getDataReplicaLocation(replicaId1);
+ DataReplicaLocationModel retrievedDataReplicaLocationModel = dataReplicaLocationRepository.getReplicaLocation(replicaId1);
assertTrue(retrievedDataReplicaLocationModel.getReplicaMetadata().size() == 2);
assertEquals(retrievedDataReplicaLocationModel.getReplicaPersistentType(), testDataReplicaLocationModel1.getReplicaPersistentType());
@@ -110,14 +107,11 @@ public class DataReplicaLocationRepositoryTest {
dataProductRepository.updateDataProduct(testDataProductModel);
assertTrue(dataProductRepository.getDataProduct(productUri).getReplicaLocations().size() == 2);
-
- List<DataReplicaLocationModel> dataReplicaLocationModelList = dataReplicaLocationRepository.getAllDataReplicaLocations(productUri);
+ List<DataReplicaLocationModel> dataReplicaLocationModelList = dataReplicaLocationRepository.getAllReplicaLocations(productUri);
assertTrue(dataReplicaLocationModelList.size() == 2);
- dataReplicaLocationRepository.removeDataReplicaLocation(replicaId1);
- assertFalse(dataReplicaLocationRepository.isDataReplicaLocationExists(replicaId1));
-
- dataReplicaLocationRepository.removeDataReplicaLocation(replicaId2);
+ dataReplicaLocationRepository.removeReplicaLocation(replicaId1);
+ dataReplicaLocationRepository.removeReplicaLocation(replicaId2);
dataProductRepository.removeDataProduct(productUri);
}

ADD
modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/replicacatalog/util/Initialize.java
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.airavata.registry.core.repositories.replicacatalog.util;
+
+import org.apache.airavata.common.exception.ApplicationSettingsException;
+import org.apache.airavata.common.utils.ServerSettings;
+import org.apache.airavata.registry.core.utils.DBConstants;
+import org.apache.derby.drda.NetworkServerControl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.InetAddress;
+import java.net.URI;
+import java.sql.*;
+import java.util.StringTokenizer;
+
+public class Initialize {
+ private static final Logger logger = LoggerFactory.getLogger(Initialize.class);
+ public static final String DERBY_SERVER_MODE_SYS_PROPERTY = "derby.drda.startNetworkServer";
+ public String scriptName = "replicacatalog-derby.sql";
+ private NetworkServerControl server;
+ private static final String delimiter = ";";
+ private String jdbcUrl = null;
+ private String jdbcDriver = null;
+ private String jdbcUser = null;
+ private String jdbcPassword = null;
+
+ public Initialize(String scriptName) {
+ this.scriptName = scriptName;
+ }
+
+ public static boolean checkStringBufferEndsWith(StringBuffer buffer, String suffix) {
+ if (suffix.length() > buffer.length()) {
+ return false;
+ }
+ // this loop is done on purpose to avoid memory allocation performance
+ // problems on various JDKs
+ // StringBuffer.lastIndexOf() was introduced in jdk 1.4 and
+ // implementation is ok though does allocation/copying
+ // StringBuffer.toString().endsWith() does massive memory
+ // allocation/copying on JDK 1.5
+ // See http://issues.apache.org/bugzilla/show_bug.cgi?id=37169
+ int endIndex = suffix.length() - 1;
+ int bufferIndex = buffer.length() - 1;
+ while (endIndex >= 0) {
+ if (buffer.charAt(bufferIndex) != suffix.charAt(endIndex)) {
+ return false;
+ }
+ bufferIndex--;
+ endIndex--;
+ }
+ return true;
+ }
+
+ private static boolean isServerStarted(NetworkServerControl server, int ntries)
+ {
+ for (int i = 1; i <= ntries; i ++)
+ {
+ try {
+ Thread.sleep(500);
+ server.ping();
+ return true;
+ }
+ catch (Exception e) {
+ if (i == ntries)
+ return false;
+ }
+ }
+ return false;
+ }
+
+ public void initializeDB() {
+ try{
+ jdbcDriver = ServerSettings.getSetting("replicacatalog.jdbc.driver");
+ jdbcUrl = ServerSettings.getSetting("replicacatalog.jdbc.url");
+ jdbcUser = ServerSettings.getSetting("replicacatalog.jdbc.user");
+ jdbcPassword = ServerSettings.getSetting("replicacatalog.jdbc.password");
+ jdbcUrl = jdbcUrl + "?" + "user=" + jdbcUser + "&" + "password=" + jdbcPassword;
+ } catch (ApplicationSettingsException e) {
+ logger.error("Unable to read properties", e);
+ }
+
+ startDerbyInServerMode();
+ if(!isServerStarted(server, 20)){
+ throw new RuntimeException("Derby server could not started within five seconds...");
+ }
+ Connection conn = null;
+ try {
+ Class.forName(jdbcDriver).newInstance();
+ conn = DriverManager.getConnection(jdbcUrl, jdbcUser, jdbcPassword);
+ if (!isDatabaseStructureCreated(DBConstants.CONFIGURATION, conn)) {
+ executeSQLScript(conn);
+ logger.info("New Database created for Data Catalog !!!");
+ } else {
+ logger.debug("Database already created for Data Catalog!");
+ }
+ } catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ throw new RuntimeException("Database failure", e);
+ } finally {
+ try {
+ if (conn != null){
+ if (!conn.getAutoCommit()) {
+ conn.commit();
+ }
+ conn.close();
+ }
+ } catch (SQLException e) {
+ logger.error(e.getMessage(), e);
+ }
+ }
+ }
+
+ public static boolean isDatabaseStructureCreated(String tableName, Connection conn) {
+ try {
+ System.out.println("Running a query to test the database tables existence.");
+ // check whether the tables are already created with a query
+ Statement statement = null;
+ try {
+ statement = conn.createStatement();
+ ResultSet rs = statement.executeQuery("select * from " + tableName);
+ if (rs != null) {
+ rs.close();
+ }
+ } finally {
+ try {
+ if (statement != null) {
+ statement.close();
+ }
+ } catch (SQLException e) {
+ return false;
+ }
+ }
+ } catch (SQLException e) {
+ return false;
+ }
+
+ return true;
+ }
+
+ private void executeSQLScript(Connection conn) throws Exception {
+ StringBuffer sql = new StringBuffer();
+ BufferedReader reader = null;
+ try{
+
+ InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(scriptName);
+ reader = new BufferedReader(new InputStreamReader(inputStream));
+ String line;
+ while ((line = reader.readLine()) != null) {
+ line = line.trim();
+ if (line.startsWith("//")) {
+ continue;
+ }
+ if (line.startsWith("--")) {
+ continue;
+ }
+ StringTokenizer st = new StringTokenizer(line);
+ if (st.hasMoreTokens()) {
+ String token = st.nextToken();
+ if ("REM".equalsIgnoreCase(token)) {
+ continue;
+ }
+ }
+ sql.append(" ").append(line);
+
+ // SQL defines "--" as a comment to EOL
+ // and in Oracle it may contain a hint
+ // so we cannot just remove it, instead we must end it
+ if (line.indexOf("--") >= 0) {
+ sql.append("\n");
+ }
+ if ((checkStringBufferEndsWith(sql, delimiter))) {
+ executeSQL(sql.substring(0, sql.length() - delimiter.length()), conn);
+ sql.replace(0, sql.length(), "");
+ }
+ }
+ // Catch any statements not followed by ;
+ if (sql.length() > 0) {
+ executeSQL(sql.toString(), conn);
+ }
+ }catch (IOException e){
+ logger.error("Error occurred while executing SQL script for creating Airavata Data Catalog database", e);
+ throw new Exception("Error occurred while executing SQL script for creating Airavata Data Catalog database", e);
+ }finally {
+ if (reader != null) {
+ reader.close();
+ }
+ }
+ }
+
+ private static void executeSQL(String sql, Connection conn) throws Exception {
+ // Check and ignore empty statements
+ if ("".equals(sql.trim())) {
+ return;
+ }
+
+ Statement statement = null;
+ try {
+ logger.debug("SQL : " + sql);
+
+ boolean ret;
+ int updateCount = 0, updateCountTotal = 0;
+ statement = conn.createStatement();
+ ret = statement.execute(sql);
+ updateCount = statement.getUpdateCount();
+ do {
+ if (!ret) {
+ if (updateCount != -1) {
+ updateCountTotal += updateCount;
+ }
+ }
+ ret = statement.getMoreResults();
+ if (ret) {
+ updateCount = statement.getUpdateCount();
+ }
+ } while (ret);
+
+ logger.debug(sql + " : " + updateCountTotal + " rows affected");
+
+ SQLWarning warning = conn.getWarnings();
+ while (warning != null) {
+ logger.warn(warning + " sql warning");
+ warning = warning.getNextWarning();
+ }
+ conn.clearWarnings();
+ } catch (SQLException e) {
+ if (e.getSQLState().equals("X0Y32")) {
+ // eliminating the table already exception for the derby
+ // database
+ logger.info("Table Already Exists", e);
+ } else {
+ throw new Exception("Error occurred while executing : " + sql, e);
+ }
+ } finally {
+ if (statement != null) {
+ try {
+ statement.close();
+ } catch (SQLException e) {
+ logger.error("Error occurred while closing result set.", e);
+ }
+ }
+ }
+ }
+
+ private void startDerbyInServerMode() {
+ try {
+ System.setProperty(DERBY_SERVER_MODE_SYS_PROPERTY, "true");
+ server = new NetworkServerControl(InetAddress.getByName("0.0.0.0"),
+ 20000,
+ jdbcUser, jdbcPassword);
+ java.io.PrintWriter consoleWriter = new java.io.PrintWriter(System.out, true);
+ server.start(consoleWriter);
+ } catch (IOException e) {
+ logger.error("Unable to start Apache derby in the server mode! Check whether " +
+ "specified port is available");
+ } catch (Exception e) {
+ logger.error("Unable to start Apache derby in the server mode! Check whether " +
+ "specified port is available");
+ }
+
+ }
+
+ public static int getPort(String jdbcURL){
+ try{
+ String cleanURI = jdbcURL.substring(5);
+ URI uri = URI.create(cleanURI);
+ return uri.getPort();
+ } catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ return -1;
+ }
+ }
+
+ private void startDerbyInEmbeddedMode(){
+ try {
+ Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
+ DriverManager.getConnection("jdbc:derby:memory:unit-testing-jpa;create=true").close();
+ } catch (ClassNotFoundException e) {
+ logger.error(e.getMessage(), e);
+ } catch (SQLException e) {
+ logger.error(e.getMessage(), e);
+ }
+ }
+
+ public void stopDerbyServer() {
+ try {
+ server.shutdown();
+ } catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ }
+ }
+}

MODIFY
modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/impl/ReplicaCatalogImpl.java
modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/impl/ReplicaCatalogImpl.java
@@ -48,7 +48,7 @@ public class ReplicaCatalogImpl implements ReplicaCatalog {
throw new ReplicaCatalogException("owner name and gateway id should be non empty");
}
- if(productModel.getParentProductUri() != null && (!isExists(productModel.getParentProductUri())
+ if(productModel.getParentProductUri() != null && (!isDataProductExists(productModel.getParentProductUri())
|| !getDataProduct(productModel.getParentProductUri()).getDataProductType().equals(DataProductType.COLLECTION))){
throw new ReplicaCatalogException("Parent Product does not exists or parent type is not Collection");
}
@@ -169,7 +169,7 @@ public class ReplicaCatalogImpl implements ReplicaCatalog {
}
@Override
- public boolean isExists(String productUri) throws ReplicaCatalogException {
+ public boolean isDataProductExists(String productUri) throws ReplicaCatalogException {
EntityManager em = null;
try {
em = ReplicaCatalogJPAUtils.getEntityManager();

MODIFY
modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/utils/ReplicaCatalogConstants.java
modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/utils/ReplicaCatalogConstants.java
@@ -21,11 +21,11 @@ package org.apache.airavata.registry.core.replica.catalog.utils;
public class ReplicaCatalogConstants {
// table names
- public static final String DATA_RESOURCE = "DataProduct";
- public static final String DATA_REPLICA_LOCATION = "DataReplicaLocation";
+ public static final String DATA_RESOURCE = "DataProductInterface";
+ public static final String DATA_REPLICA_LOCATION = "DataReplicaLocationInterface";
public static final String CONFIGURATION = "Configuration";
- // DataProduct Table
+ // DataProductInterface Table
public final class DataResourceConstants {
public static final String RESOURCE_ID = "resourceId";
public static final String RESOURCE_NAME = "resourceName";

ADD
modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/DataProductInterface.java
+package org.apache.airavata.registry.cpi;
+
+import org.apache.airavata.model.data.replica.DataProductModel;
+
+import java.util.List;
+
+public interface DataProductInterface {
+
+ String schema = "airavata-dp";
+
+ String registerDataProduct(DataProductModel product) throws ReplicaCatalogException;
+
+ boolean updateDataProduct(DataProductModel product) throws ReplicaCatalogException;
+
+ DataProductModel getDataProduct(String productUri) throws ReplicaCatalogException;
+
+ DataProductModel getParentDataProduct(String productUri) throws ReplicaCatalogException;
+
+ List<DataProductModel> getChildDataProducts(String productUri) throws ReplicaCatalogException;
+
+ List<DataProductModel> searchDataProductsByName(String gatewayId, String userId, String productName,
+ int limit, int offset) throws ReplicaCatalogException;
+
+ boolean isDataProductExists(String productUri) throws ReplicaCatalogException;
+
+ boolean removeDataProduct(String productUri) throws ReplicaCatalogException;
+
+}

ADD
modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/DataReplicaLocationInterface.java
+package org.apache.airavata.registry.cpi;
+
+import org.apache.airavata.model.data.replica.DataReplicaLocationModel;
+
+import java.util.List;
+
+public interface DataReplicaLocationInterface {
+
+ String registerReplicaLocation(DataReplicaLocationModel dataReplicaLocationModel) throws ReplicaCatalogException;
+
+ boolean updateReplicaLocation(DataReplicaLocationModel dataReplicaLocationModel) throws ReplicaCatalogException;
+
+ DataReplicaLocationModel getReplicaLocation(String replicaId) throws ReplicaCatalogException;
+
+ List<DataReplicaLocationModel> getAllReplicaLocations(String productUri) throws ReplicaCatalogException;
+
+ boolean removeReplicaLocation(String replicaId) throws ReplicaCatalogException;
+
+}

MODIFY
modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/ReplicaCatalog.java
modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/ReplicaCatalog.java
package org.apache.airavata.registry.cpi;
-import org.apache.airavata.model.data.replica.DataProductModel;
-import org.apache.airavata.model.data.replica.DataReplicaLocationModel;
-
-import java.util.List;
-
-public interface ReplicaCatalog {
- String schema = "airavata-dp";
+/*
+Included for backwards compatibility
+TODO: Remove interface once registry refactoring is complete
+*/
+public interface ReplicaCatalog extends DataProductInterface, DataReplicaLocationInterface {
+ /*String schema = "airavata-dp";
String registerDataProduct(DataProductModel product) throws ReplicaCatalogException;
@@ -36,7 +35,7 @@ public interface ReplicaCatalog {
DataProductModel getDataProduct(String productUri) throws ReplicaCatalogException;
- boolean isExists(String productUri) throws ReplicaCatalogException;
+ boolean isDataProductExists(String productUri) throws ReplicaCatalogException;
String registerReplicaLocation(DataReplicaLocationModel dataReplicaLocationModel) throws ReplicaCatalogException;
@@ -53,5 +52,5 @@ public interface ReplicaCatalog {
List<DataProductModel> getChildDataProducts(String productUri) throws ReplicaCatalogException;
List<DataProductModel> searchDataProductsByName(String gatewayId, String userId, String productName,
- int limit, int offset) throws ReplicaCatalogException;
+ int limit, int offset) throws ReplicaCatalogException;*/
}

MODIFY
modules/registry/registry-server/registry-api-service/src/main/java/org/apache/airavata/registry/api/service/handler/RegistryServerHandler.java
modules/registry/registry-server/registry-api-service/src/main/java/org/apache/airavata/registry/api/service/handler/RegistryServerHandler.java
@@ -2604,7 +2604,7 @@ public class RegistryServerHandler implements RegistryService.Iface {
@Override
public String registerReplicaLocation(DataReplicaLocationModel replicaLocationModel) throws RegistryServiceException, TException {
try {
- String replicaId = dataReplicaLocationRepository.registerDataReplicaLocation(replicaLocationModel);
+ String replicaId = dataReplicaLocationRepository.registerReplicaLocation(replicaLocationModel);
return replicaId;
} catch (RegistryException e) {
String msg = "Error in retreiving the replica "+replicaLocationModel.getReplicaName()+".";

Making changes to interface, repository, tests