[
https://issues.apache.org/jira/browse/AIRAVATA-2719?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16420706#comment-16420706
]
ASF GitHub Bot commented on AIRAVATA-2719:
------------------------------------------
machristie closed pull request #187: [AIRAVATA-2719] Refactoring Replica
Catalog Implementation
URL: https://github.com/apache/airavata/pull/187
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/replicacatalog/ConfigurationEntity.java
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/replicacatalog/ConfigurationEntity.java
new file mode 100644
index 0000000000..9b4f0c69fa
--- /dev/null
+++
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/replicacatalog/ConfigurationEntity.java
@@ -0,0 +1,59 @@
+/*
+ *
+ * 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.entities.replicacatalog;
+
+import javax.persistence.*;
+import java.io.Serializable;
+
+/**
+ * The persistent class for the configuration database table.
+ */
+@Entity
+@Table(name = "CONFIGURATION")
+@IdClass(ConfigurationPK.class)
+public class ConfigurationEntity implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ @Id
+ @Column(name = "CONFIG_KEY")
+ private String configKey;
+
+ @Id
+ @Column(name = "CONFIG_VAL")
+ private String configVal;
+
+ public String getConfigKey() {
+ return configKey;
+ }
+
+ public void setConfigKey(String configKey) {
+ this.configKey = configKey;
+ }
+
+ public String getConfigVal() {
+ return configVal;
+ }
+
+ public void setConfigVal(String configVal) {
+ this.configVal = configVal;
+ }
+
+}
diff --git
a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/replicacatalog/ConfigurationPK.java
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/replicacatalog/ConfigurationPK.java
new file mode 100644
index 0000000000..374e5b6e1e
--- /dev/null
+++
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/replicacatalog/ConfigurationPK.java
@@ -0,0 +1,75 @@
+/*
+ *
+ * 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.entities.replicacatalog;
+
+import javax.persistence.Column;
+import javax.persistence.Id;
+import java.io.Serializable;
+
+/**
+ * The primary key class for the configuration database table.
+ */
+public class ConfigurationPK implements Serializable {
+ //default serial version id, required for serializable classes.
+ private static final long serialVersionUID = 1L;
+
+ private String configKey;
+ private String configVal;
+
+ public String getConfigKey() {
+ return configKey;
+ }
+
+ public void setConfigKey(String configKey) {
+ this.configKey = configKey;
+ }
+
+ public String getConfigVal() {
+ return configVal;
+ }
+
+ public void setConfigVal(String configVal) {
+ this.configVal = configVal;
+ }
+
+ public boolean equals(Object other) {
+ if (this == other) {
+ return true;
+ }
+ if (!(other instanceof ConfigurationPK)) {
+ return false;
+ }
+ ConfigurationPK castOther = (ConfigurationPK) other;
+ return
+ this.configKey.equals(castOther.configKey)
+ && this.configVal.equals(castOther.configVal);
+ }
+
+ public int hashCode() {
+ final int prime = 31;
+ int hash = 17;
+ hash = hash * prime + this.configKey.hashCode();
+ hash = hash * prime + this.configVal.hashCode();
+
+ return hash;
+ }
+
+}
diff --git
a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/replicacatalog/DataProductEntity.java
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/replicacatalog/DataProductEntity.java
index 4abe9b567a..7df4307521 100644
---
a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/replicacatalog/DataProductEntity.java
+++
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/replicacatalog/DataProductEntity.java
@@ -20,24 +20,62 @@
*/
package org.apache.airavata.registry.core.entities.replicacatalog;
+import org.apache.airavata.model.data.replica.DataProductType;
+
+import java.util.*;
import javax.persistence.*;
+import java.io.Serializable;
import java.sql.Timestamp;
+/**
+ * The persistent class for the data_product database table.
+ */
@Entity
-@Table(name = "data_product", schema = "airavata_catalog", catalog = "")
-public class DataProductEntity {
+@Table(name = "DATA_PRODUCT")
+public class DataProductEntity implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ @Id
+ @Column(name = "PRODUCT_URI")
private String productUri;
+
+ @Column(name = "GATEWAY_ID")
private String gatewayId;
+
+ @Column(name = "PRODUCT_NAME")
private String productName;
+
+ @Column(name = "PRODUCT_DESCRIPTION")
private String productDescription;
+
+ @Column(name = "OWNER_NAME")
private String ownerName;
+
+ @Column(name = "PARENT_PRODUCT_URI")
private String parentProductUri;
- private Integer productSize;
+
+ @Column(name = "PRODUCT_SIZE")
+ private int productSize;
+
+ @Column(name = "CREATION_TIME")
private Timestamp creationTime;
+
+ @Column(name = "LAST_MODIFIED_TIME")
private Timestamp lastModifiedTime;
- @Id
- @Column(name = "PRODUCT_URI")
+ @Column(name = "PRODUCT_TYPE")
+ private DataProductType dataProductType;
+
+ @ElementCollection(fetch = FetchType.EAGER)
+ @CollectionTable(name="DATA_PRODUCT_METADATA", joinColumns =
@JoinColumn(name="PRODUCT_URI"))
+ @MapKeyColumn(name = "METADATA_KEY")
+ @Column(name = "METADATA_VALUE")
+ private Map<String, String> productMetadata;
+
+ @OneToMany(targetEntity = DataReplicaLocationEntity.class, cascade =
CascadeType.ALL,
+ mappedBy = "dataProduct", fetch = FetchType.EAGER)
+ private List<DataReplicaLocationEntity> replicaLocations;
+
public String getProductUri() {
return productUri;
}
@@ -46,8 +84,6 @@ public void setProductUri(String productUri) {
this.productUri = productUri;
}
- @Basic
- @Column(name = "GATEWAY_ID")
public String getGatewayId() {
return gatewayId;
}
@@ -56,8 +92,6 @@ public void setGatewayId(String gatewayId) {
this.gatewayId = gatewayId;
}
- @Basic
- @Column(name = "PRODUCT_NAME")
public String getProductName() {
return productName;
}
@@ -66,8 +100,6 @@ public void setProductName(String productName) {
this.productName = productName;
}
- @Basic
- @Column(name = "PRODUCT_DESCRIPTION")
public String getProductDescription() {
return productDescription;
}
@@ -76,8 +108,6 @@ public void setProductDescription(String productDescription)
{
this.productDescription = productDescription;
}
- @Basic
- @Column(name = "OWNER_NAME")
public String getOwnerName() {
return ownerName;
}
@@ -86,8 +116,6 @@ public void setOwnerName(String ownerName) {
this.ownerName = ownerName;
}
- @Basic
- @Column(name = "PARENT_PRODUCT_URI")
public String getParentProductUri() {
return parentProductUri;
}
@@ -96,18 +124,14 @@ public void setParentProductUri(String parentProductUri) {
this.parentProductUri = parentProductUri;
}
- @Basic
- @Column(name = "PRODUCT_SIZE")
- public Integer getProductSize() {
+ public int getProductSize() {
return productSize;
}
- public void setProductSize(Integer productSize) {
+ public void setProductSize(int productSize) {
this.productSize = productSize;
}
- @Basic
- @Column(name = "CREATION_TIME")
public Timestamp getCreationTime() {
return creationTime;
}
@@ -116,8 +140,6 @@ public void setCreationTime(Timestamp creationTime) {
this.creationTime = creationTime;
}
- @Basic
- @Column(name = "LAST_MODIFIED_TIME")
public Timestamp getLastModifiedTime() {
return lastModifiedTime;
}
@@ -126,40 +148,24 @@ public void setLastModifiedTime(Timestamp
lastModifiedTime) {
this.lastModifiedTime = lastModifiedTime;
}
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
-
- DataProductEntity that = (DataProductEntity) o;
-
- if (productUri != null ? !productUri.equals(that.productUri) :
that.productUri != null) return false;
- if (gatewayId != null ? !gatewayId.equals(that.gatewayId) :
that.gatewayId != null) return false;
- if (productName != null ? !productName.equals(that.productName) :
that.productName != null) return false;
- if (productDescription != null ?
!productDescription.equals(that.productDescription) : that.productDescription
!= null)
- return false;
- if (ownerName != null ? !ownerName.equals(that.ownerName) :
that.ownerName != null) return false;
- if (parentProductUri != null ?
!parentProductUri.equals(that.parentProductUri) : that.parentProductUri != null)
- return false;
- if (productSize != null ? !productSize.equals(that.productSize) :
that.productSize != null) return false;
- if (creationTime != null ? !creationTime.equals(that.creationTime) :
that.creationTime != null) return false;
- if (lastModifiedTime != null ?
!lastModifiedTime.equals(that.lastModifiedTime) : that.lastModifiedTime != null)
- return false;
-
- return true;
- }
-
- @Override
- public int hashCode() {
- int result = productUri != null ? productUri.hashCode() : 0;
- result = 31 * result + (gatewayId != null ? gatewayId.hashCode() : 0);
- result = 31 * result + (productName != null ? productName.hashCode() :
0);
- result = 31 * result + (productDescription != null ?
productDescription.hashCode() : 0);
- result = 31 * result + (ownerName != null ? ownerName.hashCode() : 0);
- result = 31 * result + (parentProductUri != null ?
parentProductUri.hashCode() : 0);
- result = 31 * result + (productSize != null ? productSize.hashCode() :
0);
- result = 31 * result + (creationTime != null ? creationTime.hashCode()
: 0);
- result = 31 * result + (lastModifiedTime != null ?
lastModifiedTime.hashCode() : 0);
- return result;
+ public DataProductType getDataProductType() {
+ return dataProductType;
+ }
+
+ public void setDataProductType(DataProductType dataProductType) {
+ this.dataProductType = dataProductType;
+ }
+
+ public Map<String, String> getProductMetadata() { return productMetadata; }
+
+ public void setProductMetadata(Map<String, String> productMetadata) {
this.productMetadata = productMetadata; }
+
+ public List<DataReplicaLocationEntity> getReplicaLocations() {
+ return replicaLocations;
}
+
+ public void setReplicaLocations(List<DataReplicaLocationEntity>
replicaLocations) {
+ this.replicaLocations = replicaLocations;
+ }
+
}
diff --git
a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/replicacatalog/DataProductMetadataEntity.java
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/replicacatalog/DataProductMetadataEntity.java
index 841a46d885..82f40b8223 100644
---
a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/replicacatalog/DataProductMetadataEntity.java
+++
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/replicacatalog/DataProductMetadataEntity.java
@@ -21,17 +21,28 @@
package org.apache.airavata.registry.core.entities.replicacatalog;
import javax.persistence.*;
+import java.io.Serializable;
+/**
+ * The persistent class for the data_product_metadata database table.
+ */
@Entity
-@Table(name = "data_product_metadata", schema = "airavata_catalog", catalog =
"")
-@IdClass(DataProductMetadataEntityPK.class)
-public class DataProductMetadataEntity {
+@Table(name = "DATA_PRODUCT_METADATA")
+@IdClass(DataProductMetadataPK.class)
+public class DataProductMetadataEntity implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ @Id
+ @Column(name = "PRODUCT_URI")
private String productUri;
+
+ @Id
+ @Column(name = "METADATA_KEY")
private String metadataKey;
+
+ @Column(name = "METADATA_VALUE")
private String metadataValue;
- @Id
- @Column(name = "PRODUCT_URI")
public String getProductUri() {
return productUri;
}
@@ -40,8 +51,6 @@ public void setProductUri(String productUri) {
this.productUri = productUri;
}
- @Id
- @Column(name = "METADATA_KEY")
public String getMetadataKey() {
return metadataKey;
}
@@ -50,8 +59,6 @@ public void setMetadataKey(String metadataKey) {
this.metadataKey = metadataKey;
}
- @Basic
- @Column(name = "METADATA_VALUE")
public String getMetadataValue() {
return metadataValue;
}
@@ -60,26 +67,4 @@ public void setMetadataValue(String metadataValue) {
this.metadataValue = metadataValue;
}
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
-
- DataProductMetadataEntity that = (DataProductMetadataEntity) o;
-
- if (productUri != null ? !productUri.equals(that.productUri) :
that.productUri != null) return false;
- if (metadataKey != null ? !metadataKey.equals(that.metadataKey) :
that.metadataKey != null) return false;
- if (metadataValue != null ? !metadataValue.equals(that.metadataValue)
: that.metadataValue != null)
- return false;
-
- return true;
- }
-
- @Override
- public int hashCode() {
- int result = productUri != null ? productUri.hashCode() : 0;
- result = 31 * result + (metadataKey != null ? metadataKey.hashCode() :
0);
- result = 31 * result + (metadataValue != null ?
metadataValue.hashCode() : 0);
- return result;
- }
}
diff --git
a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/replicacatalog/DataProductMetadataEntityPK.java
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/replicacatalog/DataProductMetadataPK.java
similarity index 61%
rename from
modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/replicacatalog/DataProductMetadataEntityPK.java
rename to
modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/replicacatalog/DataProductMetadataPK.java
index 569cf9f711..9837f11b0e 100644
---
a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/replicacatalog/DataProductMetadataEntityPK.java
+++
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/replicacatalog/DataProductMetadataPK.java
@@ -24,12 +24,16 @@
import javax.persistence.Id;
import java.io.Serializable;
-public class DataProductMetadataEntityPK implements Serializable {
+/**
+ * The primary key class for the data_product_metadata database table.
+ */
+public class DataProductMetadataPK implements Serializable {
+ //default serial version id, required for serializable classes.
+ private static final long serialVersionUID = 1L;
+
private String productUri;
private String metadataKey;
- @Column(name = "PRODUCT_URI")
- @Id
public String getProductUri() {
return productUri;
}
@@ -38,8 +42,6 @@ public void setProductUri(String productUri) {
this.productUri = productUri;
}
- @Column(name = "METADATA_KEY")
- @Id
public String getMetadataKey() {
return metadataKey;
}
@@ -48,23 +50,26 @@ public void setMetadataKey(String metadataKey) {
this.metadataKey = metadataKey;
}
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
-
- DataProductMetadataEntityPK that = (DataProductMetadataEntityPK) o;
-
- if (productUri != null ? !productUri.equals(that.productUri) :
that.productUri != null) return false;
- if (metadataKey != null ? !metadataKey.equals(that.metadataKey) :
that.metadataKey != null) return false;
-
- return true;
+ public boolean equals(Object other) {
+ if (this == other) {
+ return true;
+ }
+ if (!(other instanceof DataProductMetadataPK)) {
+ return false;
+ }
+ DataProductMetadataPK castOther = (DataProductMetadataPK) other;
+ return
+ this.productUri.equals(castOther.productUri)
+ && this.metadataKey.equals(castOther.metadataKey);
}
- @Override
public int hashCode() {
- int result = productUri != null ? productUri.hashCode() : 0;
- result = 31 * result + (metadataKey != null ? metadataKey.hashCode() :
0);
- return result;
+ final int prime = 31;
+ int hash = 17;
+ hash = hash * prime + this.productUri.hashCode();
+ hash = hash * prime + this.metadataKey.hashCode();
+
+ return hash;
}
+
}
diff --git
a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/replicacatalog/DataReplicaLocationEntity.java
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/replicacatalog/DataReplicaLocationEntity.java
index 1499320358..831ec8dfff 100644
---
a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/replicacatalog/DataReplicaLocationEntity.java
+++
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/replicacatalog/DataReplicaLocationEntity.java
@@ -20,23 +20,66 @@
*/
package org.apache.airavata.registry.core.entities.replicacatalog;
+import org.apache.airavata.model.data.replica.ReplicaLocationCategory;
+import org.apache.airavata.model.data.replica.ReplicaPersistentType;
+
+import java.io.Serializable;
+import java.util.*;
import javax.persistence.*;
import java.sql.Timestamp;
+/**
+ * The persistent class for the data_replica_location database table.
+ */
@Entity
-@Table(name = "data_replica_location", schema = "airavata_catalog", catalog =
"")
-public class DataReplicaLocationEntity {
+@Table(name = "DATA_REPLICA_LOCATION")
+public class DataReplicaLocationEntity implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ @Id
+ @Column(name = "REPLICA_ID")
private String replicaId;
+
+ @Column(name = "PRODUCT_URI")
+ private String productUri;
+
+ @Column(name = "REPLICA_NAME")
private String replicaName;
+
+ @Column(name = "REPLICA_DESCRIPTION")
private String replicaDescription;
+
+ @Column(name = "STORAGE_RESOURCE_ID")
private String storageResourceId;
+
+ @Column(name = "FILE_PATH")
private String filePath;
+
+ @Column(name = "CREATION_TIME")
private Timestamp creationTime;
+
+ @Column(name = "LAST_MODIFIED_TIME")
private Timestamp lastModifiedTime;
+
+ @Column(name = "VALID_UNTIL_TIME")
private Timestamp validUntilTime;
- @Id
- @Column(name = "REPLICA_ID")
+ @Column(name = "REPLICA_LOCATION_CATEGORY")
+ private ReplicaLocationCategory replicaLocationCategory;
+
+ @Column(name = "REPLICA_PERSISTENT_TYPE")
+ private ReplicaPersistentType replicaPersistentType;
+
+ @ElementCollection(fetch = FetchType.EAGER)
+ @CollectionTable(name="DATA_REPLICA_METADATA", joinColumns =
@JoinColumn(name="REPLICA_ID"))
+ @MapKeyColumn(name = "METADATA_KEY")
+ @Column(name = "METADATA_VALUE")
+ private Map<String, String> replicaMetadata;
+
+ @ManyToOne(targetEntity = DataProductEntity.class, cascade =
CascadeType.MERGE)
+ @JoinColumn(name = "PRODUCT_URI")
+ private DataProductEntity dataProduct;
+
public String getReplicaId() {
return replicaId;
}
@@ -45,8 +88,14 @@ public void setReplicaId(String replicaId) {
this.replicaId = replicaId;
}
- @Basic
- @Column(name = "REPLICA_NAME")
+ public String getProductUri() {
+ return productUri;
+ }
+
+ public void setProductUri(String productUri) {
+ this.productUri = productUri;
+ }
+
public String getReplicaName() {
return replicaName;
}
@@ -55,8 +104,6 @@ public void setReplicaName(String replicaName) {
this.replicaName = replicaName;
}
- @Basic
- @Column(name = "REPLICA_DESCRIPTION")
public String getReplicaDescription() {
return replicaDescription;
}
@@ -65,8 +112,6 @@ public void setReplicaDescription(String replicaDescription)
{
this.replicaDescription = replicaDescription;
}
- @Basic
- @Column(name = "STORAGE_RESOURCE_ID")
public String getStorageResourceId() {
return storageResourceId;
}
@@ -75,8 +120,6 @@ public void setStorageResourceId(String storageResourceId) {
this.storageResourceId = storageResourceId;
}
- @Basic
- @Column(name = "FILE_PATH")
public String getFilePath() {
return filePath;
}
@@ -85,8 +128,6 @@ public void setFilePath(String filePath) {
this.filePath = filePath;
}
- @Basic
- @Column(name = "CREATION_TIME")
public Timestamp getCreationTime() {
return creationTime;
}
@@ -95,8 +136,6 @@ public void setCreationTime(Timestamp creationTime) {
this.creationTime = creationTime;
}
- @Basic
- @Column(name = "LAST_MODIFIED_TIME")
public Timestamp getLastModifiedTime() {
return lastModifiedTime;
}
@@ -105,8 +144,6 @@ public void setLastModifiedTime(Timestamp lastModifiedTime)
{
this.lastModifiedTime = lastModifiedTime;
}
- @Basic
- @Column(name = "VALID_UNTIL_TIME")
public Timestamp getValidUntilTime() {
return validUntilTime;
}
@@ -115,39 +152,35 @@ public void setValidUntilTime(Timestamp validUntilTime) {
this.validUntilTime = validUntilTime;
}
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
-
- DataReplicaLocationEntity that = (DataReplicaLocationEntity) o;
-
- if (replicaId != null ? !replicaId.equals(that.replicaId) :
that.replicaId != null) return false;
- if (replicaName != null ? !replicaName.equals(that.replicaName) :
that.replicaName != null) return false;
- if (replicaDescription != null ?
!replicaDescription.equals(that.replicaDescription) : that.replicaDescription
!= null)
- return false;
- if (storageResourceId != null ?
!storageResourceId.equals(that.storageResourceId) : that.storageResourceId !=
null)
- return false;
- if (filePath != null ? !filePath.equals(that.filePath) : that.filePath
!= null) return false;
- if (creationTime != null ? !creationTime.equals(that.creationTime) :
that.creationTime != null) return false;
- if (lastModifiedTime != null ?
!lastModifiedTime.equals(that.lastModifiedTime) : that.lastModifiedTime != null)
- return false;
- if (validUntilTime != null ?
!validUntilTime.equals(that.validUntilTime) : that.validUntilTime != null)
- return false;
-
- return true;
- }
-
- @Override
- public int hashCode() {
- int result = replicaId != null ? replicaId.hashCode() : 0;
- result = 31 * result + (replicaName != null ? replicaName.hashCode() :
0);
- result = 31 * result + (replicaDescription != null ?
replicaDescription.hashCode() : 0);
- result = 31 * result + (storageResourceId != null ?
storageResourceId.hashCode() : 0);
- result = 31 * result + (filePath != null ? filePath.hashCode() : 0);
- result = 31 * result + (creationTime != null ? creationTime.hashCode()
: 0);
- result = 31 * result + (lastModifiedTime != null ?
lastModifiedTime.hashCode() : 0);
- result = 31 * result + (validUntilTime != null ?
validUntilTime.hashCode() : 0);
- return result;
+ public ReplicaLocationCategory getReplicaLocationCategory() {
+ return replicaLocationCategory;
+ }
+
+ public void setReplicaLocationCategory(ReplicaLocationCategory
replicaLocationCategory) {
+ this.replicaLocationCategory = replicaLocationCategory;
+ }
+
+ public ReplicaPersistentType getReplicaPersistentType() {
+ return replicaPersistentType;
+ }
+
+ public void setReplicaPersistentType(ReplicaPersistentType
replicaPersistentType) {
+ this.replicaPersistentType = replicaPersistentType;
+ }
+
+ public Map<String, String> getReplicaMetadata() {
+ return replicaMetadata;
+ }
+
+ public void setReplicaMetadata(Map<String, String> replicaMetadata) {
+ this.replicaMetadata = replicaMetadata;
+ }
+
+ public DataProductEntity getDataProduct() {
+ return dataProduct;
+ }
+
+ public void setDataProduct(DataProductEntity dataProduct) {
+ this.dataProduct = dataProduct;
}
}
diff --git
a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/replicacatalog/DataReplicaMetadataEntity.java
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/replicacatalog/DataReplicaMetadataEntity.java
index 26ff15c586..b4b8c987bb 100644
---
a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/replicacatalog/DataReplicaMetadataEntity.java
+++
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/replicacatalog/DataReplicaMetadataEntity.java
@@ -21,17 +21,28 @@
package org.apache.airavata.registry.core.entities.replicacatalog;
import javax.persistence.*;
+import java.io.Serializable;
+/**
+ * The persistent class for the data_replica_metadata database table.
+ */
@Entity
-@Table(name = "data_replica_metadata", schema = "airavata_catalog", catalog =
"")
-@IdClass(DataReplicaMetadataEntityPK.class)
-public class DataReplicaMetadataEntity {
+@Table(name = "DATA_REPLICA_METADATA")
+@IdClass(DataReplicaMetadataPK.class)
+public class DataReplicaMetadataEntity implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ @Id
+ @Column(name = "REPLICA_ID")
private String replicaId;
+
+ @Id
+ @Column(name = "METADATA_KEY")
private String metadataKey;
+
+ @Column(name = "METADATA_VALUE")
private String metadataValue;
- @Id
- @Column(name = "REPLICA_ID")
public String getReplicaId() {
return replicaId;
}
@@ -40,8 +51,6 @@ public void setReplicaId(String replicaId) {
this.replicaId = replicaId;
}
- @Id
- @Column(name = "METADATA_KEY")
public String getMetadataKey() {
return metadataKey;
}
@@ -50,8 +59,6 @@ public void setMetadataKey(String metadataKey) {
this.metadataKey = metadataKey;
}
- @Basic
- @Column(name = "METADATA_VALUE")
public String getMetadataValue() {
return metadataValue;
}
@@ -60,26 +67,4 @@ public void setMetadataValue(String metadataValue) {
this.metadataValue = metadataValue;
}
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
-
- DataReplicaMetadataEntity that = (DataReplicaMetadataEntity) o;
-
- if (replicaId != null ? !replicaId.equals(that.replicaId) :
that.replicaId != null) return false;
- if (metadataKey != null ? !metadataKey.equals(that.metadataKey) :
that.metadataKey != null) return false;
- if (metadataValue != null ? !metadataValue.equals(that.metadataValue)
: that.metadataValue != null)
- return false;
-
- return true;
- }
-
- @Override
- public int hashCode() {
- int result = replicaId != null ? replicaId.hashCode() : 0;
- result = 31 * result + (metadataKey != null ? metadataKey.hashCode() :
0);
- result = 31 * result + (metadataValue != null ?
metadataValue.hashCode() : 0);
- return result;
- }
}
diff --git
a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/replicacatalog/DataReplicaMetadataEntityPK.java
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/replicacatalog/DataReplicaMetadataPK.java
similarity index 63%
rename from
modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/replicacatalog/DataReplicaMetadataEntityPK.java
rename to
modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/replicacatalog/DataReplicaMetadataPK.java
index 317edfd19f..4a3f5354ea 100644
---
a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/replicacatalog/DataReplicaMetadataEntityPK.java
+++
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/entities/replicacatalog/DataReplicaMetadataPK.java
@@ -24,12 +24,15 @@
import javax.persistence.Id;
import java.io.Serializable;
-public class DataReplicaMetadataEntityPK implements Serializable {
+/**
+ * The primary key class for the data_replica_metadata database table.
+ */
+public class DataReplicaMetadataPK implements Serializable {
+ private static final long serialVersionUID = 1L;
+
private String replicaId;
private String metadataKey;
- @Column(name = "REPLICA_ID")
- @Id
public String getReplicaId() {
return replicaId;
}
@@ -38,8 +41,6 @@ public void setReplicaId(String replicaId) {
this.replicaId = replicaId;
}
- @Column(name = "METADATA_KEY")
- @Id
public String getMetadataKey() {
return metadataKey;
}
@@ -48,23 +49,25 @@ public void setMetadataKey(String metadataKey) {
this.metadataKey = metadataKey;
}
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
-
- DataReplicaMetadataEntityPK that = (DataReplicaMetadataEntityPK) o;
-
- if (replicaId != null ? !replicaId.equals(that.replicaId) :
that.replicaId != null) return false;
- if (metadataKey != null ? !metadataKey.equals(that.metadataKey) :
that.metadataKey != null) return false;
-
- return true;
+ public boolean equals(Object other) {
+ if (this == other) {
+ return true;
+ }
+ if (!(other instanceof DataReplicaMetadataPK)) {
+ return false;
+ }
+ DataReplicaMetadataPK castOther = (DataReplicaMetadataPK) other;
+ return
+ this.replicaId.equals(castOther.replicaId)
+ && this.metadataKey.equals(castOther.metadataKey);
}
- @Override
public int hashCode() {
- int result = replicaId != null ? replicaId.hashCode() : 0;
- result = 31 * result + (metadataKey != null ? metadataKey.hashCode() :
0);
- return result;
+ final int prime = 31;
+ int hash = 17;
+ hash = hash * prime + this.replicaId.hashCode();
+ hash = hash * prime + this.metadataKey.hashCode();
+
+ return hash;
}
}
diff --git
a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/replicacatalog/DataProductRepository.java
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/replicacatalog/DataProductRepository.java
index 68f94b54d9..606bb69425 100644
---
a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/replicacatalog/DataProductRepository.java
+++
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/replicacatalog/DataProductRepository.java
@@ -21,11 +21,110 @@
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.entities.replicacatalog.DataProductEntity;
-import org.apache.airavata.registry.core.repositories.AbstractRepository;
+import org.apache.airavata.registry.core.utils.DBConstants;
+import org.apache.airavata.registry.core.utils.QueryConstants;
+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;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
-public class DataProductRepository extends
AbstractRepository<DataProductModel, DataProductEntity, String> {
- public DataProductRepository(Class<DataProductModel> thriftGenericClass,
Class<DataProductEntity> dbEntityGenericClass) {
- super(thriftGenericClass, dbEntityGenericClass);
+import java.sql.Timestamp;
+import java.util.*;
+
+public class DataProductRepository extends
RepCatAbstractRepository<DataProductModel, DataProductEntity, String>
implements DataProductInterface {
+ private final static Logger logger =
LoggerFactory.getLogger(DataProductRepository.class);
+
+ public DataProductRepository() {
+ super(DataProductModel.class, DataProductEntity.class);
+ }
+
+ protected String saveDataProductModelData(DataProductModel
dataProductModel) throws ReplicaCatalogException {
+ DataProductEntity dataProductEntity =
saveDataProduct(dataProductModel);
+ return dataProductEntity.getProductUri();
+ }
+
+ protected DataProductEntity saveDataProduct(DataProductModel
dataProductModel) throws ReplicaCatalogException {
+
+ 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);
+
+ if (dataProductEntity.getOwnerName() == null ||
dataProductEntity.getGatewayId() == null) {
+ logger.error("Owner name and/or gateway ID is empty");
+ throw new ReplicaCatalogException("Owner name and gateway ID
should not be empty");
+ }
+
+ if (dataProductEntity.getParentProductUri() != null &&
(!isExists(dataProductEntity.getParentProductUri())
+ ||
!getDataProduct(dataProductEntity.getParentProductUri()).getDataProductType().equals(DataProductType.COLLECTION)))
{
+ logger.error("Parent product does not exist and/or parent type is
not Collection");
+ throw new ReplicaCatalogException("Parent product does not exist
or parent type is not Collection");
+ }
+
+ if (dataProductEntity.getReplicaLocations() != null) {
+ logger.debug("Populating the product URI for ReplicaLocations
objects for the Data Product");
+
dataProductEntity.getReplicaLocations().forEach(dataReplicaLocationEntity ->
dataReplicaLocationEntity.setProductUri(productUri));
+ }
+
+ if (!isDataProductExists(productUri)) {
+ logger.debug("Checking if the Data Product already exists");
+ dataProductEntity.setCreationTime(new
Timestamp(System.currentTimeMillis()));
+ }
+
+ dataProductEntity.setLastModifiedTime(new
Timestamp(System.currentTimeMillis()));
+
+ return execute(entityManager ->
entityManager.merge(dataProductEntity));
+
+ }
+
+ public String registerDataProduct(DataProductModel dataProductModel)
throws ReplicaCatalogException {
+ return saveDataProductModelData(dataProductModel);
+ }
+
+ public boolean updateDataProduct(DataProductModel updatedDataProductModel)
throws ReplicaCatalogException {
+ return (saveDataProductModelData(updatedDataProductModel) != null);
+ }
+
+ public DataProductModel getDataProduct(String productUri) throws
ReplicaCatalogException {
+ return get(productUri);
+ }
+
+ public DataProductModel getParentDataProduct(String productUri) throws
ReplicaCatalogException {
+ DataProductModel dataProductModel = getDataProduct(productUri);
+ return get(dataProductModel.getParentProductUri());
+ }
+
+ public List<DataProductModel> getChildDataProducts(String
parentProductUri) throws ReplicaCatalogException {
+ Map<String, Object> queryParameters = new HashMap<>();
+ queryParameters.put(DBConstants.DataProduct.PARENT_PRODUCT_URI,
parentProductUri);
+ List<DataProductModel> dataProductModelList =
select(QueryConstants.FIND_ALL_CHILD_DATA_PRODUCTS, -1, 0, queryParameters);
+ return dataProductModelList;
+ }
+
+ public List<DataProductModel> searchDataProductsByName(String gatewayId,
String userId, String productName,
+ int limit, int offset)
throws ReplicaCatalogException {
+ Map<String, Object> queryParameters = new HashMap<>();
+ queryParameters.put(DBConstants.DataProduct.GATEWAY_ID, gatewayId);
+ queryParameters.put(DBConstants.DataProduct.OWNER_NAME, userId);
+ queryParameters.put(DBConstants.DataProduct.PRODUCT_NAME, productName);
+ List<DataProductModel> dataProductModelList =
select(QueryConstants.FIND_DATA_PRODUCT_BY_NAME, limit, offset,
queryParameters);
+ return dataProductModelList;
+ }
+
+ public boolean isDataProductExists(String productUri) throws
ReplicaCatalogException {
+ return isExists(productUri);
+ }
+
+ public boolean removeDataProduct(String productUri) throws
ReplicaCatalogException {
+ return delete(productUri);
}
+
}
diff --git
a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/replicacatalog/DataReplicaLocationRepository.java
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/replicacatalog/DataReplicaLocationRepository.java
index 0731d03537..8cfb7dc57c 100644
---
a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/replicacatalog/DataReplicaLocationRepository.java
+++
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/replicacatalog/DataReplicaLocationRepository.java
@@ -20,12 +20,73 @@
*/
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.DataReplicaLocationEntity;
-import org.apache.airavata.registry.core.repositories.AbstractRepository;
+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;
+import org.slf4j.LoggerFactory;
-public class DataReplicaLocationRepository extends
AbstractRepository<DataReplicaLocationModel, DataReplicaLocationEntity, String>
{
- public DataReplicaLocationRepository(Class<DataReplicaLocationModel>
thriftGenericClass, Class<DataReplicaLocationEntity> dbEntityGenericClass) {
- super(thriftGenericClass, dbEntityGenericClass);
+import java.sql.Timestamp;
+import java.util.List;
+import java.util.UUID;
+
+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.getReplicaId();
}
+
+ private DataReplicaLocationEntity
saveDataReplicaLocation(DataReplicaLocationModel dataReplicaLocationModel)
throws ReplicaCatalogException {
+
+ 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 (!isExists(replicaId)) {
+ logger.debug("Checking if the Data Replica Location already
exists");
+ dataReplicaLocationEntity.setCreationTime(new
Timestamp(System.currentTimeMillis()));
+ }
+
+ dataReplicaLocationEntity.setLastModifiedTime(new
Timestamp(System.currentTimeMillis()));
+
+ return execute(entityManager ->
entityManager.merge(dataReplicaLocationEntity));
+ }
+
+ public String registerReplicaLocation(DataReplicaLocationModel
dataReplicaLocationModel) throws ReplicaCatalogException {
+ return saveDataReplicaLocationModelData(dataReplicaLocationModel);
+ }
+
+ public boolean updateReplicaLocation(DataReplicaLocationModel
dataReplicaLocationModel) throws ReplicaCatalogException {
+ return (saveDataReplicaLocationModelData(dataReplicaLocationModel) !=
null);
+ }
+
+ public DataReplicaLocationModel getReplicaLocation(String replicaId)
throws ReplicaCatalogException {
+ return get(replicaId);
+ }
+
+ 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 removeReplicaLocation(String replicaId) throws
ReplicaCatalogException {
+ return delete(replicaId);
+ }
+
}
diff --git
a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/replicacatalog/RepCatAbstractRepository.java
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/replicacatalog/RepCatAbstractRepository.java
new file mode 100644
index 0000000000..c8b603c38a
--- /dev/null
+++
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/replicacatalog/RepCatAbstractRepository.java
@@ -0,0 +1,132 @@
+/*
+ *
+ * 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;
+
+import org.apache.airavata.registry.core.utils.Committer;
+import org.apache.airavata.registry.core.utils.DBConstants;
+import org.apache.airavata.registry.core.utils.JPAUtil.RepCatalogJPAUtils;
+import org.apache.airavata.registry.core.utils.ObjectMapperSingleton;
+import org.dozer.Mapper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+public abstract class RepCatAbstractRepository<T, E, Id> {
+ private final static Logger logger =
LoggerFactory.getLogger(RepCatAbstractRepository.class);
+
+ private Class<T> thriftGenericClass;
+ private Class<E> dbEntityGenericClass;
+
+ public RepCatAbstractRepository(Class<T> thriftGenericClass, Class<E>
dbEntityGenericClass) {
+ this.thriftGenericClass = thriftGenericClass;
+ this.dbEntityGenericClass = dbEntityGenericClass;
+ }
+
+ public T create(T t) {
+ return update(t);
+ }
+
+ public T update(T t) {
+ Mapper mapper = ObjectMapperSingleton.getInstance();
+ E entity = mapper.map(t, dbEntityGenericClass);
+ E persistedCopy = execute(entityManager ->
entityManager.merge(entity));
+ return mapper.map(persistedCopy, thriftGenericClass);
+ }
+
+ public boolean delete(Id id) {
+ execute(entityManager -> {
+ E entity = entityManager.find(dbEntityGenericClass, id);
+ entityManager.remove(entity);
+ return entity;
+ });
+ return true;
+ }
+
+ public T get(Id id) {
+ E entity = execute(entityManager -> entityManager
+ .find(dbEntityGenericClass, id));
+ if(entity == null)
+ return null;
+ Mapper mapper = ObjectMapperSingleton.getInstance();
+ return mapper.map(entity, thriftGenericClass);
+ }
+
+ public List<T> select(String query, int offset) {
+ List resultSet = (List) execute(entityManager ->
entityManager.createQuery(query).setFirstResult(offset)
+ .getResultList());
+ Mapper mapper = ObjectMapperSingleton.getInstance();
+ List<T> gatewayList = new ArrayList<>();
+ resultSet.stream().forEach(rs -> gatewayList.add(mapper.map(rs,
thriftGenericClass)));
+ return gatewayList;
+ }
+
+ public List<T> select(String query, int limit, int offset, Map<String,
Object> queryParams) {
+ int newLimit = limit < 0 ? DBConstants.SELECT_MAX_ROWS: limit;
+
+ List resultSet = (List) execute(entityManager -> {
+ Query jpaQuery = entityManager.createQuery(query);
+
+ for (Map.Entry<String, Object> entry : queryParams.entrySet()) {
+
+ jpaQuery.setParameter(entry.getKey(), entry.getValue());
+ }
+
+ return
jpaQuery.setFirstResult(offset).setMaxResults(newLimit).getResultList();
+
+ });
+ Mapper mapper = ObjectMapperSingleton.getInstance();
+ List<T> gatewayList = new ArrayList<>();
+ resultSet.stream().forEach(rs -> gatewayList.add(mapper.map(rs,
thriftGenericClass)));
+ return gatewayList;
+ }
+
+ public boolean isExists(Id id) {
+ return get(id) != null;
+ }
+
+ public <R> R execute(Committer<EntityManager, R> committer){
+ EntityManager entityManager = null;
+ try {
+ entityManager = RepCatalogJPAUtils.getEntityManager();
+ } catch (Exception e) {
+ throw new RuntimeException("Failed to get Replica Catalog
EntityManager", e);
+ }
+ try {
+ entityManager.getTransaction().begin();
+ R r = committer.commit(entityManager);
+ entityManager.getTransaction().commit();
+ return r;
+ }finally {
+ if (entityManager != null && entityManager.isOpen()) {
+ if (entityManager.getTransaction().isActive()) {
+ entityManager.getTransaction().rollback();
+ }
+ entityManager.close();
+ }
+ }
+ }
+
+}
diff --git
a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/DBConstants.java
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/DBConstants.java
index e6bd0fc2ef..0a0553259f 100644
---
a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/DBConstants.java
+++
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/DBConstants.java
@@ -22,6 +22,7 @@
public class DBConstants {
public static int SELECT_MAX_ROWS = 1000;
+ public static final String CONFIGURATION = "Configuration";
public static class ApplicationDeployment {
public static final String APPLICATION_MODULE_ID = "appModuleId";
@@ -125,4 +126,11 @@
public static final String STORAGE_RESOURCE_ID = "storageResourceId";
}
+ public static class DataProduct {
+ public static final String GATEWAY_ID = "gatewayId";
+ public static final String OWNER_NAME = "ownerName";
+ public static final String PRODUCT_NAME = "productName";
+ public static final String PARENT_PRODUCT_URI = "parentProductUri";
+ }
+
}
diff --git
a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/JPAUtil/RepCatalogJPAUtils.java
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/JPAUtil/RepCatalogJPAUtils.java
new file mode 100644
index 0000000000..b523f09236
--- /dev/null
+++
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/JPAUtil/RepCatalogJPAUtils.java
@@ -0,0 +1,79 @@
+/**
+ *
+ * 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.utils.JPAUtil;
+
+import org.apache.airavata.common.exception.ApplicationSettingsException;
+import org.apache.airavata.common.utils.ServerSettings;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.persistence.*;
+import java.util.HashMap;
+import java.util.Map;
+
+public class RepCatalogJPAUtils {
+ private final static Logger logger =
LoggerFactory.getLogger(RepCatalogJPAUtils.class);
+
+ private static final String PERSISTENCE_UNIT_NAME = "replicacatalog_data";
+ private static final String REPLICACATALOG_JDBC_DRIVER =
"replicacatalog.jdbc.driver";
+ private static final String REPLICACATALOG_JDBC_URL =
"replicacatalog.jdbc.url";
+ private static final String REPLICACATALOG_JDBC_USER =
"replicacatalog.jdbc.user";
+ private static final String REPLICACATALOG_JDBC_PWD =
"replicacatalog.jdbc.password";
+ private static final String REPLICACATALOG_VALIDATION_QUERY =
"replicacatalog.validationQuery";
+ @PersistenceUnit(unitName=PERSISTENCE_UNIT_NAME)
+ protected static EntityManagerFactory factory;
+ @PersistenceContext(unitName=PERSISTENCE_UNIT_NAME)
+ private static EntityManager dataCatEntityManager;
+
+ public static EntityManager getEntityManager() throws
ApplicationSettingsException {
+ if (factory == null) {
+ String connectionProperties = "DriverClassName=" +
readServerProperties(REPLICACATALOG_JDBC_DRIVER) + "," +
+ "Url=" + readServerProperties(REPLICACATALOG_JDBC_URL) +
"?autoReconnect=true," +
+ "Username=" +
readServerProperties(REPLICACATALOG_JDBC_USER) + "," +
+ "Password=" +
readServerProperties(REPLICACATALOG_JDBC_PWD) +
+ ",validationQuery=" +
readServerProperties(REPLICACATALOG_VALIDATION_QUERY);
+ System.out.println(connectionProperties);
+ Map<String, String> properties = new HashMap<>();
+ properties.put("openjpa.ConnectionDriverName",
"org.apache.commons.dbcp.BasicDataSource");
+ properties.put("openjpa.ConnectionProperties",
connectionProperties);
+ 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.jdbc.SynchronizeMappings",
"buildSchema(ForeignKeys=true)");
+ properties.put("openjpa.jdbc.QuerySQLCache", "false");
+ properties.put("openjpa.ConnectionFactoryProperties",
"PrettyPrint=true, PrettyPrintLineLength=72," +
+ " PrintParameters=true, MaxActive=10, MaxIdle=5,
MinIdle=2, MaxWait=31536000, autoReconnect=true");
+ factory =
Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME, properties);
+ }
+ dataCatEntityManager = factory.createEntityManager();
+ return dataCatEntityManager;
+ }
+
+ private static String readServerProperties (String propertyName) throws
ApplicationSettingsException {
+ try {
+ return ServerSettings.getSetting(propertyName);
+ } catch (ApplicationSettingsException e) {
+ logger.error("Unable to read airavata-server.properties...", e);
+ throw new ApplicationSettingsException("Unable to read
airavata-server.properties...");
+ }
+ }
+
+}
diff --git
a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/QueryConstants.java
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/QueryConstants.java
index 274473d49c..fb79c73882 100644
---
a/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/QueryConstants.java
+++
b/modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/utils/QueryConstants.java
@@ -21,6 +21,7 @@
import org.apache.airavata.model.user.UserProfile;
import org.apache.airavata.registry.core.entities.appcatalog.*;
+import
org.apache.airavata.registry.core.entities.replicacatalog.DataProductEntity;
public interface QueryConstants {
@@ -106,4 +107,10 @@
"WHERE USP.userId LIKE :" +
DBConstants.UserStoragePreference.USER_ID + " AND USP.gatewayId LIKE :" +
DBConstants.UserStoragePreference.GATEWAY_ID;
+ String FIND_ALL_CHILD_DATA_PRODUCTS = "SELECT DP FROM " +
DataProductEntity.class.getSimpleName() + " DP " +
+ "WHERE DP.parentProductUri LIKE :" +
DBConstants.DataProduct.PARENT_PRODUCT_URI;
+ String FIND_DATA_PRODUCT_BY_NAME = "SELECT DP FROM " +
DataProductEntity.class.getSimpleName() + " DP " +
+ "WHERE DP.gatewayId LIKE :" + DBConstants.DataProduct.GATEWAY_ID +
" AND DP.ownerName LIKE :" +
+ DBConstants.DataProduct.OWNER_NAME + " AND dp.productName LIKE :"
+ DBConstants.DataProduct.PRODUCT_NAME;
+
}
diff --git
a/modules/registry-refactoring/src/main/resources/META-INF/persistence.xml
b/modules/registry-refactoring/src/main/resources/META-INF/persistence.xml
index 6d4384fbbf..78567057c1 100644
--- a/modules/registry-refactoring/src/main/resources/META-INF/persistence.xml
+++ b/modules/registry-refactoring/src/main/resources/META-INF/persistence.xml
@@ -22,42 +22,6 @@
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
<persistence-unit name="appcatalog_data_new">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
-
<class>org.apache.airavata.registry.core.entities.workspacecatalog.GatewayEntity</class>
-
<class>org.apache.airavata.registry.core.entities.workspacecatalog.UserProfileEntity</class>
-
<class>org.apache.airavata.registry.core.entities.workspacecatalog.NSFDemographicsEntity</class>
-
<class>org.apache.airavata.registry.core.entities.workspacecatalog.NotificationEntity</class>
-
<class>org.apache.airavata.registry.core.entities.workspacecatalog.ProjectEntity</class>
-
<class>org.apache.airavata.registry.core.entities.expcatalog.ComputeResourceSchedulingEntity</class>
-
<class>org.apache.airavata.registry.core.entities.expcatalog.ExperimentEntity</class>
-
<class>org.apache.airavata.registry.core.entities.expcatalog.ExperimentErrorEntity</class>
-
<class>org.apache.airavata.registry.core.entities.expcatalog.ExperimentInputEntity</class>
-
<class>org.apache.airavata.registry.core.entities.expcatalog.ExperimentOutputEntity</class>
-
<class>org.apache.airavata.registry.core.entities.expcatalog.ExperimentStatusEntity</class>
-
<class>org.apache.airavata.registry.core.entities.expcatalog.UserConfigurationEntity</class>
-
<class>org.apache.airavata.registry.core.entities.expcatalog.ProcessEntity</class>
-
<class>org.apache.airavata.registry.core.entities.expcatalog.ProcessErrorEntity</class>
-
<class>org.apache.airavata.registry.core.entities.expcatalog.ProcessInputEntity</class>
-
<class>org.apache.airavata.registry.core.entities.expcatalog.ProcessOutputEntity</class>
-
<class>org.apache.airavata.registry.core.entities.expcatalog.ProcessResourceSchedulingEntity</class>
-
<class>org.apache.airavata.registry.core.entities.expcatalog.ProcessStatusEntity</class>
-
<class>org.apache.airavata.registry.core.entities.expcatalog.TaskEntity</class>
-
<class>org.apache.airavata.registry.core.entities.expcatalog.TaskErrorEntity</class>
-
<class>org.apache.airavata.registry.core.entities.expcatalog.TaskStatusEntity</class>
-
<class>org.apache.airavata.registry.core.entities.expcatalog.JobEntity</class>
-
<class>org.apache.airavata.registry.core.entities.expcatalog.JobStatusEntity</class>
-
-
<!--<class>org.apache.airavata.registry.core.entities.workflowcatalog.WorkflowEntity</class>-->
-
<!--<class>org.apache.airavata.registry.core.entities.workflowcatalog.EdgeEntity</class>-->
-
<!--<class>org.apache.airavata.registry.core.entities.workflowcatalog.ComponentStatusEntity</class>-->
-
<!--<class>org.apache.airavata.registry.core.entities.workflowcatalog.NodeEntity</class>-->
-
<!--<class>org.apache.airavata.registry.core.entities.workflowcatalog.PortEntity</class>-->
-
<!--<class>org.apache.airavata.registry.core.entities.workflowcatalog.WorkflowInputEntity</class>-->
-
<!--<class>org.apache.airavata.registry.core.entities.workflowcatalog.WorkflowOutputEntity</class>-->
-
<!--<class>org.apache.airavata.registry.core.entities.workflowcatalog.WorkflowStatusEntity</class>-->
-
<!--<class>org.apache.airavata.registry.core.entities.replicacatalog.DataProductEntity</class>-->
-
<!--<class>org.apache.airavata.registry.core.entities.replicacatalog.DataProductMetadataEntity</class>-->
-
<!--<class>org.apache.airavata.registry.core.entities.replicacatalog.DataReplicaLocationEntity</class>-->
-
<!--<class>org.apache.airavata.registry.core.entities.replicacatalog.DataReplicaMetadataEntity</class>-->
<class>org.apache.airavata.registry.core.entities.appcatalog.GridftpDataMovementEntity</class>
<class>org.apache.airavata.registry.core.entities.appcatalog.ResourceJobManagerEntity</class>
<class>org.apache.airavata.registry.core.entities.appcatalog.ComputeResourceEntity</class>
@@ -107,12 +71,6 @@
<class>org.apache.airavata.registry.core.entities.appcatalog.GroupComputeResourcePrefEntity</class>
<class>org.apache.airavata.registry.core.entities.appcatalog.GroupSSHAccountProvisionerConfig</class>
<class>org.apache.airavata.registry.core.entities.appcatalog.GroupResourceProfileEntity</class>
-
<!--<class>org.apache.airavata.registry.core.entities.workflowcatalog.WorkflowInputPK</class>-->
-
<!--<class>org.apache.airavata.registry.core.entities.workflowcatalog.WorkflowOutputPK</class>-->
-
<!--<class>org.apache.airavata.registry.core.entities.workflowcatalog.WorkflowStatusPK</class>-->
-
<!--<class>org.apache.airavata.registry.core.entities.workflowcatalog.EdgePK</class>-->
-
<!--<class>org.apache.airavata.registry.core.entities.workflowcatalog.PortPK</class>-->
-
<!--<class>org.apache.airavata.registry.core.entities.workflowcatalog.NodePK</class>-->
<class>org.apache.airavata.registry.core.entities.appcatalog.GridftpEndpointPK</class>
<class>org.apache.airavata.registry.core.entities.appcatalog.StorageInterfacePK</class>
<class>org.apache.airavata.registry.core.entities.appcatalog.JobManagerCommandPK</class>
@@ -123,4 +81,49 @@
<class>org.apache.airavata.registry.core.entities.appcatalog.UserStoragePreferenceEntity</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
</persistence-unit>
+ <persistence-unit name="replicacatalog_data">
+
<class>org.apache.airavata.registry.core.entities.replicacatalog.ConfigurationEntity</class>
+
<class>org.apache.airavata.registry.core.entities.replicacatalog.DataProductEntity</class>
+
<class>org.apache.airavata.registry.core.entities.replicacatalog.DataProductMetadataEntity</class>
+
<class>org.apache.airavata.registry.core.entities.replicacatalog.DataReplicaLocationEntity</class>
+
<class>org.apache.airavata.registry.core.entities.replicacatalog.DataReplicaMetadataEntity</class>
+ <exclude-unlisted-classes>true</exclude-unlisted-classes>
+ </persistence-unit>
+ <persistence-unit name="workspacecatalog_data">
+
<class>org.apache.airavata.registry.core.entities.workspacecatalog.GatewayEntity</class>
+
<class>org.apache.airavata.registry.core.entities.workspacecatalog.UserProfileEntity</class>
+
<class>org.apache.airavata.registry.core.entities.workspacecatalog.NSFDemographicsEntity</class>
+
<class>org.apache.airavata.registry.core.entities.workspacecatalog.NotificationEntity</class>
+
<class>org.apache.airavata.registry.core.entities.workspacecatalog.ProjectEntity</class>
+ </persistence-unit>
+ <persistence-unit name="workflowcatalog_data">
+
<class>org.apache.airavata.registry.core.entities.workflowcatalog.WorkflowEntity</class>
+
<class>org.apache.airavata.registry.core.entities.workflowcatalog.EdgeEntity</class>
+
<class>org.apache.airavata.registry.core.entities.workflowcatalog.ComponentStatusEntity</class>
+
<class>org.apache.airavata.registry.core.entities.workflowcatalog.NodeEntity</class>
+
<class>org.apache.airavata.registry.core.entities.workflowcatalog.PortEntity</class>
+
<class>org.apache.airavata.registry.core.entities.workflowcatalog.WorkflowInputEntity</class>
+
<class>org.apache.airavata.registry.core.entities.workflowcatalog.WorkflowOutputEntity</class>
+
<class>org.apache.airavata.registry.core.entities.workflowcatalog.WorkflowStatusEntity</class>
+ </persistence-unit>
+ <persistence-unit name="experiment_data">
+
<class>org.apache.airavata.registry.core.entities.expcatalog.ComputeResourceSchedulingEntity</class>
+
<class>org.apache.airavata.registry.core.entities.expcatalog.ExperimentEntity</class>
+
<class>org.apache.airavata.registry.core.entities.expcatalog.ExperimentErrorEntity</class>
+
<class>org.apache.airavata.registry.core.entities.expcatalog.ExperimentInputEntity</class>
+
<class>org.apache.airavata.registry.core.entities.expcatalog.ExperimentOutputEntity</class>
+
<class>org.apache.airavata.registry.core.entities.expcatalog.ExperimentStatusEntity</class>
+
<class>org.apache.airavata.registry.core.entities.expcatalog.UserConfigurationEntity</class>
+
<class>org.apache.airavata.registry.core.entities.expcatalog.ProcessEntity</class>
+
<class>org.apache.airavata.registry.core.entities.expcatalog.ProcessErrorEntity</class>
+
<class>org.apache.airavata.registry.core.entities.expcatalog.ProcessInputEntity</class>
+
<class>org.apache.airavata.registry.core.entities.expcatalog.ProcessOutputEntity</class>
+
<class>org.apache.airavata.registry.core.entities.expcatalog.ProcessResourceSchedulingEntity</class>
+
<class>org.apache.airavata.registry.core.entities.expcatalog.ProcessStatusEntity</class>
+
<class>org.apache.airavata.registry.core.entities.expcatalog.TaskEntity</class>
+
<class>org.apache.airavata.registry.core.entities.expcatalog.TaskErrorEntity</class>
+
<class>org.apache.airavata.registry.core.entities.expcatalog.TaskStatusEntity</class>
+
<class>org.apache.airavata.registry.core.entities.expcatalog.JobEntity</class>
+
<class>org.apache.airavata.registry.core.entities.expcatalog.JobStatusEntity</class>
+ </persistence-unit>
</persistence>
diff --git
a/modules/registry-refactoring/src/main/resources/replicacatalog-derby.sql
b/modules/registry-refactoring/src/main/resources/replicacatalog-derby.sql
new file mode 100644
index 0000000000..f510f36357
--- /dev/null
+++ b/modules/registry-refactoring/src/main/resources/replicacatalog-derby.sql
@@ -0,0 +1,77 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+CREATE TABLE DATA_PRODUCT
+(
+ PRODUCT_URI VARCHAR (255),
+ GATEWAY_ID VARCHAR (255),
+ PRODUCT_NAME VARCHAR (255),
+ PRODUCT_DESCRIPTION VARCHAR (1024),
+ PARENT_PRODUCT_URI VARCHAR (255),
+ OWNER_NAME VARCHAR (255),
+ PRODUCT_SIZE INTEGER ,
+ CREATION_TIME TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
+ LAST_MODIFIED_TIME TIMESTAMP DEFAULT '0000-00-00 00:00:00',
+ PRIMARY KEY (PRODUCT_URI)
+);
+
+CREATE TABLE DATA_REPLICA_LOCATION
+(
+ REPLICA_ID VARCHAR (255),
+ PRODUCT_URI VARCHAR (255) NOT NULL,
+ REPLICA_NAME VARCHAR (255),
+ REPLICA_DESCRIPTION VARCHAR (1024),
+ STORAGE_RESOURCE_ID VARCHAR (255),
+ FILE_PATH VARCHAR (4096),
+ CREATION_TIME TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
+ LAST_MODIFIED_TIME TIMESTAMP DEFAULT '0000-00-00 00:00:00',
+ VALID_UNTIL_TIME TIMESTAMP DEFAULT '0000-00-00 00:00:00',
+ PRIMARY KEY (REPLICA_ID),
+ FOREIGN KEY (PRODUCT_URI) REFERENCES DATA_PRODUCT(PRODUCT_URI) ON
DELETE CASCADE
+);
+
+CREATE TABLE DATA_PRODUCT_METADATA
+(
+ PRODUCT_URI VARCHAR(255),
+ METADATA_KEY VARCHAR(255),
+ METADATA_VALUE VARCHAR(2048),
+ PRIMARY KEY(PRODUCT_URI, METADATA_KEY),
+ FOREIGN KEY (PRODUCT_URI) REFERENCES DATA_PRODUCT(PRODUCT_URI) ON
DELETE CASCADE
+);
+
+CREATE TABLE DATA_REPLICA_METADATA
+(
+ REPLICA_ID VARCHAR(255),
+ METADATA_KEY VARCHAR(255),
+ METADATA_VALUE VARCHAR(2048),
+ PRIMARY KEY(REPLICA_ID, METADATA_KEY),
+ FOREIGN KEY (REPLICA_ID) REFERENCES DATA_REPLICA_LOCATION(REPLICA_ID)
ON DELETE CASCADE
+);
+
+
+CREATE TABLE CONFIGURATION
+(
+ CONFIG_KEY VARCHAR(255),
+ CONFIG_VAL VARCHAR(255),
+ PRIMARY KEY(CONFIG_KEY, CONFIG_VAL)
+);
+
+INSERT INTO CONFIGURATION (CONFIG_KEY, CONFIG_VAL)
VALUES('data_catalog_version', '0.16');
\ No newline at end of file
diff --git
a/modules/registry-refactoring/src/main/resources/replicacatalog-mysql.sql
b/modules/registry-refactoring/src/main/resources/replicacatalog-mysql.sql
new file mode 100644
index 0000000000..bb9bbfcef4
--- /dev/null
+++ b/modules/registry-refactoring/src/main/resources/replicacatalog-mysql.sql
@@ -0,0 +1,76 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+CREATE TABLE DATA_PRODUCT
+(
+ PRODUCT_URI VARCHAR (255),
+ GATEWAY_ID VARCHAR (255),
+ PRODUCT_NAME VARCHAR (255),
+ PRODUCT_DESCRIPTION VARCHAR (255),
+ OWNER_NAME VARCHAR (255),
+ PARENT_PRODUCT_URI VARCHAR (255),
+ PRODUCT_SIZE INT,
+ CREATION_TIME TIMESTAMP NULL DEFAULT '0000-00-00 00:00:00',
+ LAST_MODIFIED_TIME TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE
CURRENT_TIMESTAMP,
+ PRIMARY KEY (PRODUCT_URI)
+);
+
+CREATE TABLE DATA_REPLICA_LOCATION
+(
+ REPLICA_ID VARCHAR (255),
+ PRODUCT_URI VARCHAR (255) NOT NULL,
+ REPLICA_NAME VARCHAR (255),
+ REPLICA_DESCRIPTION VARCHAR (255),
+ STORAGE_RESOURCE_ID VARCHAR (255),
+ FILE_PATH VARCHAR (255),
+ CREATION_TIME TIMESTAMP NULL DEFAULT '0000-00-00 00:00:00',
+ LAST_MODIFIED_TIME TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE
CURRENT_TIMESTAMP,
+ VALID_UNTIL_TIME TIMESTAMP NULL DEFAULT '0000-00-00 00:00:00',
+ PRIMARY KEY (REPLICA_ID),
+ FOREIGN KEY (PRODUCT_URI) REFERENCES DATA_PRODUCT(PRODUCT_URI) ON
DELETE CASCADE
+);
+
+CREATE TABLE DATA_PRODUCT_METADATA
+(
+ PRODUCT_URI VARCHAR(255),
+ METADATA_KEY VARCHAR(255),
+ METADATA_VALUE VARCHAR(255),
+ PRIMARY KEY(PRODUCT_URI, METADATA_KEY),
+ FOREIGN KEY (PRODUCT_URI) REFERENCES DATA_PRODUCT(PRODUCT_URI) ON
DELETE CASCADE
+);
+
+CREATE TABLE DATA_REPLICA_METADATA
+(
+ REPLICA_ID VARCHAR(255),
+ METADATA_KEY VARCHAR(255),
+ METADATA_VALUE VARCHAR(255),
+ PRIMARY KEY(REPLICA_ID, METADATA_KEY),
+ FOREIGN KEY (REPLICA_ID) REFERENCES DATA_REPLICA_LOCATION(REPLICA_ID)
ON DELETE CASCADE
+);
+
+CREATE TABLE CONFIGURATION
+(
+ CONFIG_KEY VARCHAR(255),
+ CONFIG_VAL VARCHAR(255),
+ PRIMARY KEY(CONFIG_KEY, CONFIG_VAL)
+);
+
+INSERT INTO CONFIGURATION (CONFIG_KEY, CONFIG_VAL)
VALUES('data_catalog_version', '0.16');
\ No newline at end of file
diff --git
a/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/ReplicaCatalogRepositoryTest.java
b/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/ReplicaCatalogRepositoryTest.java
deleted file mode 100644
index b8c8dc44e9..0000000000
---
a/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/ReplicaCatalogRepositoryTest.java
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- *
- * 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;
-
-import org.apache.airavata.model.data.replica.DataProductModel;
-import org.apache.airavata.model.user.UserProfile;
-import org.apache.airavata.model.workspace.Gateway;
-import org.apache.airavata.model.workspace.GatewayApprovalStatus;
-import
org.apache.airavata.registry.core.entities.replicacatalog.DataProductEntity;
-import
org.apache.airavata.registry.core.entities.workspacecatalog.GatewayEntity;
-import
org.apache.airavata.registry.core.entities.workspacecatalog.UserProfileEntity;
-import
org.apache.airavata.registry.core.repositories.replicacatalog.DataProductRepository;
-import
org.apache.airavata.registry.core.repositories.workspacecatalog.GatewayRepository;
-import
org.apache.airavata.registry.core.repositories.workspacecatalog.UserProfileRepository;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-public class ReplicaCatalogRepositoryTest {
-
- private GatewayRepository gatewayRepository;
- private UserProfileRepository userProfileRepository;
- private String gatewayId;
- private String userId;
- private String dataProductUri;
-
- private final String GATEWAY_DOMAIN = "test1.com";
- private final String DATA_PRODUCT_DESCRIPTION = "testDesc";
-
-
- @Before
- public void setupRepository() {
-
- gatewayRepository = new GatewayRepository(Gateway.class,
GatewayEntity.class);
- userProfileRepository = new UserProfileRepository(UserProfile.class,
UserProfileEntity.class);
-
-
- gatewayId = "test.com" + System.currentTimeMillis();
- userId = "testuser" + System.currentTimeMillis();
- dataProductUri = "uri" + System.currentTimeMillis();
-
- }
- @Test
- public void dataProductRepositoryTest() {
-
-// DataProductRepository dataProductRepository = new
DataProductRepository(DataProductModel.class, DataProductEntity.class);
-
- /*
- * Creating Gateway required for UserProfile & Project creation
- */
-// Gateway gateway = new Gateway();
-// gateway.setGatewayApprovalStatus(GatewayApprovalStatus.ACTIVE);
-// gateway.setGatewayId(gatewayId);
-// gateway.setDomain(GATEWAY_DOMAIN);
-// gateway = gatewayRepository.create(gateway);
-// Assert.assertTrue(!gateway.getGatewayId().isEmpty());
-
- /*
- * UserProfile Instance creation required for Project Creation
- */
-// UserProfile userProfile = new UserProfile();
-// userProfile.setAiravataInternalUserId(userId);
-// userProfile.setGatewayId(gateway.getGatewayId());
-// userProfile = userProfileRepository.create(userProfile);
-//
Assert.assertTrue(!userProfile.getAiravataInternalUserId().isEmpty());
-
- /*
- * DataProduct Instance creation
- */
-// DataProductModel dataProduct = new DataProductModel();
-// dataProduct.setProductUri(dataProductUri);
-// dataProduct.setGatewayId(gatewayId);
-// dataProduct.setOwnerName(gatewayId);
-// dataProduct.setProductName("Product1234");
-
-
- /*
- * Data Product Repository Insert Operation Test
- */
-// dataProduct = dataProductRepository.create(dataProduct);
-// Assert.assertTrue(!dataProduct.getProductUri().isEmpty());
-
-
-
- /*
- * DataProduct Repository Update Operation Test
- */
-// dataProduct.setProductDescription(DATA_PRODUCT_DESCRIPTION);
-// dataProductRepository.update(dataProduct);
-// dataProduct = dataProductRepository.get(dataProduct.getProductUri());
-// Assert.assertEquals(dataProduct.getProductDescription(),
DATA_PRODUCT_DESCRIPTION);
-
- /*
- * Data Product Repository Select Operation Test
- */
-// dataProduct = dataProductRepository.get(dataProductUri);
-// Assert.assertNotNull(dataProduct);
-
- /*
- * Workspace Project Repository Delete Operation
- */
-// boolean deleteResult = dataProductRepository.delete(dataProductUri);
-// Assert.assertTrue(deleteResult);
-//
-// deleteResult = userProfileRepository.delete(userId);
-// Assert.assertTrue(deleteResult);
-//
-// deleteResult = gatewayRepository.delete(gatewayId);
-// Assert.assertTrue(deleteResult);
-
- }
-}
diff --git
a/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/replicacatalog/DataProductRepositoryTest.java
b/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/replicacatalog/DataProductRepositoryTest.java
new file mode 100644
index 0000000000..9281fbe179
--- /dev/null
+++
b/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/replicacatalog/DataProductRepositoryTest.java
@@ -0,0 +1,116 @@
+/**
+ *
+ * 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;
+
+import org.apache.airavata.model.data.replica.DataProductModel;
+import org.apache.airavata.model.data.replica.DataProductType;
+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;
+import org.junit.Test;
+import org.slf4j.Logger;
+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 DataProductRepositoryTest {
+
+ private static Initialize initialize;
+ private DataProductRepository dataProductRepository;
+ private String gatewayId = "testGateway";
+ private String userId = "testUser";
+ private String productName = "testProduct";
+ private static final Logger logger =
LoggerFactory.getLogger(DataProductRepositoryTest.class);
+
+ @Before
+ public void setUp() {
+ try {
+ initialize = new Initialize("replicacatalog-derby.sql");
+ initialize.initializeDB();
+ dataProductRepository = new DataProductRepository();
+ } catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ }
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ System.out.println("********** TEAR DOWN ************");
+ initialize.stopDerbyServer();
+ }
+
+ @Test
+ public void DataProductRepositoryTest() throws ReplicaCatalogException {
+ DataProductModel testDataProductModel1 = new DataProductModel();
+ testDataProductModel1.setGatewayId(gatewayId);
+ testDataProductModel1.setOwnerName(userId);
+ testDataProductModel1.setDataProductType(DataProductType.COLLECTION);
+ testDataProductModel1.setProductName(productName);
+
+ String productUri1 =
dataProductRepository.registerDataProduct(testDataProductModel1);
+ assertTrue(dataProductRepository.isDataProductExists(productUri1));
+
+ DataProductModel retrievedDataProductModel1 =
dataProductRepository.getDataProduct(productUri1);
+ assertEquals(retrievedDataProductModel1.getProductUri(), productUri1);
+
+ DataProductModel testDataProductModel2 = new DataProductModel();
+ testDataProductModel2.setGatewayId(gatewayId);
+ testDataProductModel2.setOwnerName(userId);
+ testDataProductModel2.setDataProductType(DataProductType.FILE);
+ testDataProductModel2.setProductName(productName);
+
+ 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);
+
assertTrue(dataProductRepository.updateDataProduct(testDataProductModel2));
+
+ DataProductModel retrievedDataProductModel2 =
dataProductRepository.getDataProduct(productUri2);
+ assertTrue(retrievedDataProductModel2.getProductMetadata().size() ==
1);
+
+ DataProductModel retrievedParentDataProductModel =
dataProductRepository.getParentDataProduct(productUri2);
+ assertEquals(retrievedParentDataProductModel.getProductUri(),
productUri1);
+
+ List<DataProductModel> childDataProductList =
dataProductRepository.getChildDataProducts(productUri1);
+ assertTrue(childDataProductList.size() == 1);
+
+ List<DataProductModel> dataProductModelList =
dataProductRepository.searchDataProductsByName(gatewayId, userId, productName,
-1, 0);
+ assertTrue(dataProductModelList.size() == 2);
+
+ dataProductRepository.removeDataProduct(productUri1);
+ assertFalse(dataProductRepository.isDataProductExists(productUri1));
+
+ dataProductRepository.removeDataProduct(productUri2);
+ }
+
+}
diff --git
a/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/replicacatalog/DataReplicaLocationRepositoryTest.java
b/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/replicacatalog/DataReplicaLocationRepositoryTest.java
new file mode 100644
index 0000000000..1578585872
--- /dev/null
+++
b/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/replicacatalog/DataReplicaLocationRepositoryTest.java
@@ -0,0 +1,118 @@
+/**
+ *
+ * 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;
+
+import org.apache.airavata.model.data.replica.DataProductModel;
+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.replicacatalog.util.Initialize;
+import org.apache.airavata.registry.cpi.ReplicaCatalogException;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class DataReplicaLocationRepositoryTest {
+
+ private static Initialize initialize;
+ private DataProductRepository dataProductRepository;
+ private DataReplicaLocationRepository dataReplicaLocationRepository;
+ private String gatewayId = "testGateway";
+ private static final Logger logger =
LoggerFactory.getLogger(DataReplicaLocationRepositoryTest.class);
+
+ @Before
+ public void setUp() {
+ try {
+ initialize = new Initialize("replicacatalog-derby.sql");
+ initialize.initializeDB();
+ dataProductRepository = new DataProductRepository();
+ dataReplicaLocationRepository = new
DataReplicaLocationRepository();
+ } catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ }
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ System.out.println("********** TEAR DOWN ************");
+ initialize.stopDerbyServer();
+ }
+
+ @Test
+ public void DataReplicaLocationRepositoryTest() throws
ReplicaCatalogException {
+ DataProductModel testDataProductModel = new DataProductModel();
+ testDataProductModel.setGatewayId(gatewayId);
+ testDataProductModel.setOwnerName("testUser");
+ testDataProductModel.setDataProductType(DataProductType.COLLECTION);
+ testDataProductModel.setProductName("productName");
+ String productUri =
dataProductRepository.registerDataProduct(testDataProductModel);
+ assertTrue(dataProductRepository.isDataProductExists(productUri));
+
+ DataReplicaLocationModel testDataReplicaLocationModel1 = new
DataReplicaLocationModel();
+ testDataReplicaLocationModel1.setReplicaName("replicaName1");
+ testDataReplicaLocationModel1.setProductUri(productUri);
+ String replicaId1 =
dataReplicaLocationRepository.registerReplicaLocation(testDataReplicaLocationModel1);
+
+ DataReplicaLocationModel testDataReplicaLocationModel2 = new
DataReplicaLocationModel();
+ testDataReplicaLocationModel2.setReplicaName("replicaName2");
+ testDataReplicaLocationModel2.setProductUri(productUri);
+ String replicaId2 =
dataReplicaLocationRepository.registerReplicaLocation(testDataReplicaLocationModel2);
+
+ DataReplicaMetadataEntity dataReplicaMetadataEntity1 = new
DataReplicaMetadataEntity();
+ dataReplicaMetadataEntity1.setReplicaId(replicaId1);
+ dataReplicaMetadataEntity1.setMetadataKey("dataKey1");
+ dataReplicaMetadataEntity1.setMetadataValue("dataValue1");
+
+ DataReplicaMetadataEntity dataReplicaMetadataEntity2 = new
DataReplicaMetadataEntity();
+ dataReplicaMetadataEntity2.setReplicaId(replicaId1);
+ 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);
+
assertTrue(dataReplicaLocationRepository.updateReplicaLocation(testDataReplicaLocationModel1));
+
+ DataReplicaLocationModel retrievedDataReplicaLocationModel =
dataReplicaLocationRepository.getReplicaLocation(replicaId1);
+
assertTrue(retrievedDataReplicaLocationModel.getReplicaMetadata().size() == 2);
+
assertEquals(retrievedDataReplicaLocationModel.getReplicaPersistentType(),
testDataReplicaLocationModel1.getReplicaPersistentType());
+
+
testDataProductModel.setReplicaLocations(Arrays.asList(testDataReplicaLocationModel1,
testDataReplicaLocationModel2));
+ dataProductRepository.updateDataProduct(testDataProductModel);
+
assertTrue(dataProductRepository.getDataProduct(productUri).getReplicaLocations().size()
== 2);
+
+ List<DataReplicaLocationModel> dataReplicaLocationModelList =
dataReplicaLocationRepository.getAllReplicaLocations(productUri);
+ assertTrue(dataReplicaLocationModelList.size() == 2);
+
+ dataReplicaLocationRepository.removeReplicaLocation(replicaId1);
+ dataReplicaLocationRepository.removeReplicaLocation(replicaId2);
+ dataProductRepository.removeDataProduct(productUri);
+ }
+
+}
diff --git
a/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/replicacatalog/util/Initialize.java
b/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/replicacatalog/util/Initialize.java
new file mode 100644
index 0000000000..940d2e6e58
--- /dev/null
+++
b/modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/replicacatalog/util/Initialize.java
@@ -0,0 +1,313 @@
+/**
+ *
+ * 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);
+ }
+ }
+}
diff --git
a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/impl/ReplicaCatalogImpl.java
b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/impl/ReplicaCatalogImpl.java
index 078d85c78c..443ea85db3 100644
---
a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/impl/ReplicaCatalogImpl.java
+++
b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/impl/ReplicaCatalogImpl.java
@@ -48,7 +48,7 @@ public String registerDataProduct(DataProductModel
productModel) throws ReplicaC
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 DataProductModel getDataProduct(String productUri)
throws ReplicaCatalogE
}
@Override
- public boolean isExists(String productUri) throws ReplicaCatalogException {
+ public boolean isDataProductExists(String productUri) throws
ReplicaCatalogException {
EntityManager em = null;
try {
em = ReplicaCatalogJPAUtils.getEntityManager();
diff --git
a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/utils/ReplicaCatalogConstants.java
b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/utils/ReplicaCatalogConstants.java
index eaff647536..518fb229f1 100644
---
a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/utils/ReplicaCatalogConstants.java
+++
b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/replica/catalog/utils/ReplicaCatalogConstants.java
@@ -21,11 +21,11 @@
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";
diff --git
a/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/DataProductInterface.java
b/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/DataProductInterface.java
new file mode 100644
index 0000000000..3657c107e3
--- /dev/null
+++
b/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/DataProductInterface.java
@@ -0,0 +1,28 @@
+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;
+
+}
diff --git
a/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/DataReplicaLocationInterface.java
b/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/DataReplicaLocationInterface.java
new file mode 100644
index 0000000000..c006955361
--- /dev/null
+++
b/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/DataReplicaLocationInterface.java
@@ -0,0 +1,19 @@
+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;
+
+}
diff --git
a/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/ReplicaCatalog.java
b/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/ReplicaCatalog.java
index 1b27c967dd..324649a239 100644
---
a/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/ReplicaCatalog.java
+++
b/modules/registry/registry-cpi/src/main/java/org/apache/airavata/registry/cpi/ReplicaCatalog.java
@@ -20,13 +20,12 @@
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 @@
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 @@
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;*/
}
diff --git
a/modules/registry/registry-server/registry-api-service/src/main/java/org/apache/airavata/registry/api/service/handler/RegistryServerHandler.java
b/modules/registry/registry-server/registry-api-service/src/main/java/org/apache/airavata/registry/api/service/handler/RegistryServerHandler.java
index cf101fba30..8ccfa57ea0 100644
---
a/modules/registry/registry-server/registry-api-service/src/main/java/org/apache/airavata/registry/api/service/handler/RegistryServerHandler.java
+++
b/modules/registry/registry-server/registry-api-service/src/main/java/org/apache/airavata/registry/api/service/handler/RegistryServerHandler.java
@@ -60,7 +60,6 @@
import org.apache.airavata.registry.api.exception.RegistryServiceException;
import org.apache.airavata.registry.api.registry_apiConstants;
import org.apache.airavata.registry.core.app.catalog.resources.*;
-import org.apache.airavata.registry.core.app.catalog.util.AppCatalogJPAUtils;
import
org.apache.airavata.registry.core.app.catalog.util.AppCatalogThriftConversion;
import
org.apache.airavata.registry.core.experiment.catalog.ExpCatResourceUtils;
import
org.apache.airavata.registry.core.experiment.catalog.impl.RegistryFactory;
@@ -72,6 +71,8 @@
import
org.apache.airavata.registry.core.repositories.appcatalog.ApplicationDeploymentRepository;
import
org.apache.airavata.registry.core.repositories.appcatalog.ApplicationInterfaceRepository;
import
org.apache.airavata.registry.core.repositories.appcatalog.GwyResourceProfileRepository;
+import
org.apache.airavata.registry.core.repositories.replicacatalog.DataProductRepository;
+import
org.apache.airavata.registry.core.repositories.replicacatalog.DataReplicaLocationRepository;
import
org.apache.airavata.registry.core.repositories.appcatalog.UserResourceProfileRepository;
import org.apache.airavata.registry.cpi.*;
import org.apache.airavata.registry.cpi.utils.Constants;
@@ -86,11 +87,12 @@
private ExperimentCatalog experimentCatalog;
private AppCatalog appCatalog;
- private ReplicaCatalog dataCatalog;
private WorkflowCatalog workflowCatalog;
private ApplicationDeploymentRepository applicationDeploymentRepository =
new ApplicationDeploymentRepository();
private ApplicationInterfaceRepository applicationInterfaceRepository =
new ApplicationInterfaceRepository();
private UserResourceProfileRepository userResourceProfileRepository = new
UserResourceProfileRepository();
+ private DataProductRepository dataProductRepository = new
DataProductRepository();
+ private DataReplicaLocationRepository dataReplicaLocationRepository = new
DataReplicaLocationRepository();
/**
* Fetch Apache Registry API version
@@ -2294,8 +2296,7 @@ public boolean isWorkflowExistWithName(String
workflowName) throws RegistryServi
@Override
public DataProductModel getDataProduct(String productUri) throws
RegistryServiceException, TException {
try {
- dataCatalog = RegistryFactory.getReplicaCatalog();
- DataProductModel dataProductModel =
dataCatalog.getDataProduct(productUri);
+ DataProductModel dataProductModel =
dataProductRepository.getDataProduct(productUri);
return dataProductModel;
} catch (RegistryException e) {
String msg = "Error in retreiving the data product
"+productUri+".";
@@ -2309,8 +2310,7 @@ public DataProductModel getDataProduct(String productUri)
throws RegistryService
@Override
public DataProductModel getParentDataProduct(String productUri) throws
RegistryServiceException, TException {
try {
- dataCatalog = RegistryFactory.getReplicaCatalog();
- DataProductModel dataProductModel =
dataCatalog.getParentDataProduct(productUri);
+ DataProductModel dataProductModel =
dataProductRepository.getParentDataProduct(productUri);
return dataProductModel;
} catch (RegistryException e) {
String msg = "Error in retreiving the parent data product for "+
productUri+".";
@@ -2324,8 +2324,7 @@ public DataProductModel getParentDataProduct(String
productUri) throws RegistryS
@Override
public List<DataProductModel> getChildDataProducts(String productUri)
throws RegistryServiceException, TException {
try {
- dataCatalog = RegistryFactory.getReplicaCatalog();
- List<DataProductModel> dataProductModels =
dataCatalog.getChildDataProducts(productUri);
+ List<DataProductModel> dataProductModels =
dataProductRepository.getChildDataProducts(productUri);
return dataProductModels;
} catch (RegistryException e) {
String msg = "Error in retreiving the child products for
"+productUri+".";
@@ -2339,8 +2338,7 @@ public DataProductModel getParentDataProduct(String
productUri) throws RegistryS
@Override
public List<DataProductModel> searchDataProductsByName(String gatewayId,
String userId, String productName, int limit, int offset) throws
RegistryServiceException, TException {
try {
- dataCatalog = RegistryFactory.getReplicaCatalog();
- List<DataProductModel> dataProductModels =
dataCatalog.searchDataProductsByName(gatewayId, userId, productName, limit,
offset);
+ List<DataProductModel> dataProductModels =
dataProductRepository.searchDataProductsByName(gatewayId, userId, productName,
limit, offset);
return dataProductModels;
} catch (RegistryException e) {
String msg = "Error in searching the data products for name " +
productName + ".";
@@ -2596,8 +2594,7 @@ public BatchQueueResourcePolicy
getBatchQueueResourcePolicy(String resourcePolic
@Override
public String registerReplicaLocation(DataReplicaLocationModel
replicaLocationModel) throws RegistryServiceException, TException {
try {
- dataCatalog = RegistryFactory.getReplicaCatalog();
- String replicaId =
dataCatalog.registerReplicaLocation(replicaLocationModel);
+ String replicaId =
dataReplicaLocationRepository.registerReplicaLocation(replicaLocationModel);
return replicaId;
} catch (RegistryException e) {
String msg = "Error in retreiving the replica
"+replicaLocationModel.getReplicaName()+".";
@@ -2616,8 +2613,7 @@ public String
registerReplicaLocation(DataReplicaLocationModel replicaLocationMo
@Override
public String registerDataProduct(DataProductModel dataProductModel)
throws RegistryServiceException, TException {
try {
- dataCatalog = RegistryFactory.getReplicaCatalog();
- String productUrl =
dataCatalog.registerDataProduct(dataProductModel);
+ String productUrl =
dataProductRepository.registerDataProduct(dataProductModel);
return productUrl;
} catch (RegistryException e) {
String msg = "Error in registering the data
resource"+dataProductModel.getProductName()+".";
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> Refactoring Replica Catalog Implementation
> ------------------------------------------
>
> Key: AIRAVATA-2719
> URL: https://issues.apache.org/jira/browse/AIRAVATA-2719
> Project: Airavata
> Issue Type: Improvement
> Components: Registry API
> Reporter: Sneha Tilak
> Assignee: Sneha Tilak
> Priority: Major
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)