message: Making the requested changes

diff:
@@ -75,7 +75,10 @@ public class UserComputeResourcePreferenceEntity {
private boolean validated;
@ManyToOne(targetEntity = UserResourceProfileEntity.class, cascade = CascadeType.MERGE)
- @JoinColumn(name = "USER_ID")
+ @JoinColumns({
+ @JoinColumn(name = "USER_ID"),
+ @JoinColumn(name="GATEWAY_ID")
+ })
private UserResourceProfileEntity userResourceProfile;
public UserComputeResourcePreferenceEntity() {

diff:
@@ -32,16 +32,8 @@ public class UserComputeResourcePreferencePK implements Serializable {
//default serial version id, required for serializable classes.
private static final long serialVersionUID = 1L;
- @Id
- @Column(name = "RESOURCE_ID")
private String computeResourceId;
-
- @Id
- @Column(name = "USER_ID")
private String userId;
-
- @Id
- @Column(name = "GATEWAY_ID")
private String gatewayId;
public UserComputeResourcePreferencePK() {

diff:
@@ -32,12 +32,7 @@ public class UserResourceProfilePK implements Serializable {
//default serial version id, required for serializable classes.
private static final long serialVersionUID = 1L;
- @Id
- @Column(name = "USER_ID")
private String userId;
-
- @Id
- @Column(name = "GATEWAY_ID")
private String gatewayId;
public UserResourceProfilePK() {

diff:
@@ -53,7 +53,10 @@ public class UserStoragePreferenceEntity {
private String loginUserName;
@ManyToOne(targetEntity = UserResourceProfileEntity.class, cascade = CascadeType.MERGE)
- @JoinColumn(name = "USER_ID")
+ @JoinColumns({
+ @JoinColumn(name = "USER_ID"),
+ @JoinColumn(name="GATEWAY_ID")
+ })
private UserResourceProfileEntity userResourceProfile;
public UserStoragePreferenceEntity() {

diff:
@@ -32,16 +32,8 @@ public class UserStoragePreferencePK implements Serializable {
//default serial version id, required for serializable classes.
private static final long serialVersionUID = 1L;
- @Id
- @Column(name = "STORAGE_RESOURCE_ID")
private String storageResourceId;
-
- @Id
- @Column(name = "USER_ID")
private String userId;
-
- @Id
- @Column(name = "GATEWAY_ID")
private String gatewayId;
public UserStoragePreferencePK() {

diff:
@@ -59,14 +59,14 @@ public class UserResourceProfileRepository extends AppCatAbstractRepository<User
if (userResourceProfileEntity.getUserComputeResourcePreferences() != null) {
logger.debug("Populating the Primary Key UserComputeResourcePreferences objects for the User Resource Profile");
- userResourceProfileEntity.getUserComputeResourcePreferences().forEach(userComputeResourcePreferenceEntity -> userComputeResourcePreferenceEntity.setUserId(userId));
- userResourceProfileEntity.getUserComputeResourcePreferences().forEach(userComputeResourcePreferenceEntity -> userComputeResourcePreferenceEntity.setGatewayId(gatewayId));
+ userResourceProfileEntity.getUserComputeResourcePreferences().forEach(userComputeResourcePreferenceEntity -> { userComputeResourcePreferenceEntity.setUserId(userId);
+ userComputeResourcePreferenceEntity.setGatewayId(gatewayId); });
}
if (userResourceProfileEntity.getUserStoragePreferences() != null) {
logger.debug("Populating the Primary Key UserStoragePreferences objects for the User Resource Profile");
- userResourceProfileEntity.getUserStoragePreferences().forEach(userStoragePreferenceEntity -> userStoragePreferenceEntity.setUserId(userId));
- userResourceProfileEntity.getUserStoragePreferences().forEach(userStoragePreferenceEntity -> userStoragePreferenceEntity.setGatewayId(gatewayId));
+ userResourceProfileEntity.getUserStoragePreferences().forEach(userStoragePreferenceEntity -> { userStoragePreferenceEntity.setUserId(userId);
+ userStoragePreferenceEntity.setGatewayId(gatewayId); });
}
if (!isUserResourceProfileExists(userId, gatewayId)) {
@@ -90,53 +90,33 @@ public class UserResourceProfileRepository extends AppCatAbstractRepository<User
@Override
public UserResourceProfile getUserResourceProfile(String userId, String gatewayId) throws AppCatalogException {
- Map<String, Object> queryParameters = new HashMap<>();
- queryParameters.put(DBConstants.UserResourceProfile.USER_ID, userId);
- queryParameters.put(DBConstants.UserResourceProfile.GATEWAY_ID, gatewayId);
- List<UserResourceProfile> userResourceProfileList = select(QueryConstants.GET_USER_RESOURCE_PROFILE, -1, 0, queryParameters);
-
- if(!userResourceProfileList.isEmpty() && userResourceProfileList != null) {
- logger.debug("Return the record (there is only one record)");
- return userResourceProfileList.get(0);
- }
-
- return null;
+ UserResourceProfilePK userResourceProfilePK = new UserResourceProfilePK();
+ userResourceProfilePK.setUserId(userId);
+ userResourceProfilePK.setGatewayId(gatewayId);
+ UserResourceProfile userResourceProfile = get(userResourceProfilePK);
+ return userResourceProfile;
}
@Override
public UserComputeResourcePreference getUserComputeResourcePreference(String userId, String gatewayId, String hostId) throws AppCatalogException {
UserComputeResourcePreferenceRepository userComputeResourcePreferenceRepository = new UserComputeResourcePreferenceRepository();
- Map<String, Object> queryParameters = new HashMap<>();
- queryParameters.put(DBConstants.UserComputeResourcePreference.USER_ID, userId);
- queryParameters.put(DBConstants.UserComputeResourcePreference.GATEWAY_ID, gatewayId);
- queryParameters.put(DBConstants.UserComputeResourcePreference.COMPUTE_RESOURCE_ID, hostId);
- List<UserComputeResourcePreference> userComputeResourcePreferenceList =
- userComputeResourcePreferenceRepository.select(QueryConstants.GET_USER_COMPUTE_RESOURCE_PREFERENCE, -1, 0, queryParameters);
-
- if(!userComputeResourcePreferenceList.isEmpty() && userComputeResourcePreferenceList != null) {
- logger.debug("Return the record (there is only one record)");
- return userComputeResourcePreferenceList.get(0);
- }
-
- return null;
+ UserComputeResourcePreferencePK userComputeResourcePreferencePK = new UserComputeResourcePreferencePK();
+ userComputeResourcePreferencePK.setUserId(userId);
+ userComputeResourcePreferencePK.setGatewayId(gatewayId);
+ userComputeResourcePreferencePK.setComputeResourceId(hostId);
+ UserComputeResourcePreference userComputeResourcePreference = userComputeResourcePreferenceRepository.get(userComputeResourcePreferencePK);
+ return userComputeResourcePreference;
}
@Override
public UserStoragePreference getUserStoragePreference(String userId, String gatewayId, String storageId) throws AppCatalogException {
UserStoragePreferenceRepository userStoragePreferenceRepository = new UserStoragePreferenceRepository();
- Map<String, Object> queryParameters = new HashMap<>();
- queryParameters.put(DBConstants.UserStoragePreference.USER_ID, userId);
- queryParameters.put(DBConstants.UserStoragePreference.GATEWAY_ID, gatewayId);
- queryParameters.put(DBConstants.UserStoragePreference.STORAGE_RESOURCE_ID, storageId);
- List<UserStoragePreference> userStoragePreferenceList =
- userStoragePreferenceRepository.select(QueryConstants.GET_USER_STORAGE_PREFERENCE, -1, 0, queryParameters);
-
- if(!userStoragePreferenceList.isEmpty() && userStoragePreferenceList != null) {
- logger.debug("Return the record (there is only one record)");
- return userStoragePreferenceList.get(0);
- }
-
- return null;
+ UserStoragePreferencePK userStoragePreferencePK = new UserStoragePreferencePK();
+ userStoragePreferencePK.setUserId(userId);
+ userStoragePreferencePK.setGatewayId(gatewayId);
+ userStoragePreferencePK.setStorageResourceId(storageId);
+ UserStoragePreference userStoragePreference = userStoragePreferenceRepository.get(userStoragePreferencePK);
+ return userStoragePreference;
}
@Override

diff:
@@ -38,23 +38,14 @@ public interface QueryConstants {
String FIND_ALL_GROUP_COMPUTE_RESOURCE_POLICY = "SELECT CR FROM "+ ComputeResourcePolicyEntity.class.getSimpleName() + " CR " +
"WHERE CR.groupResourceProfileId LIKE : " + DBConstants.GroupResourceProfile.GROUP_RESOURCE_PROFILE_ID;
- String GET_USER_RESOURCE_PROFILE = "SELECT DISTINCT URP FROM " + UserResourceProfileEntity.class.getSimpleName() + " URP " +
- "WHERE URP.userId LIKE :"+ DBConstants.UserResourceProfile.USER_ID + " AND URP.gatewayId LIKE :" +
- DBConstants.UserResourceProfile.GATEWAY_ID;
String GET_ALL_USER_RESOURCE_PROFILE = "SELECT URP FROM " + UserResourceProfileEntity.class.getSimpleName() + " URP";
String GET_ALL_GATEWAY_ID = "SELECT DISTINCT URP FROM " + UserResourceProfileEntity.class.getSimpleName() + " URP " +
"WHERE URP.gatewayId LIKE :" + DBConstants.UserResourceProfile.GATEWAY_ID;
- String GET_USER_COMPUTE_RESOURCE_PREFERENCE = "SELECT DISTINCT UCRP FROM " + UserComputeResourcePreferenceEntity.class.getSimpleName() + " UCRP " +
- "WHERE UCRP.userId LIKE :" + DBConstants.UserComputeResourcePreference.USER_ID + " AND UCRP.gatewayId LIKE :" + DBConstants.UserComputeResourcePreference.GATEWAY_ID +
- " AND UCRP.computeResourceId LIKE :" + DBConstants.UserComputeResourcePreference.COMPUTE_RESOURCE_ID;
String GET_ALL_USER_COMPUTE_RESOURCE_PREFERENCE = "SELECT UCRP FROM " + UserComputeResourcePreferenceEntity.class.getSimpleName() + " UCRP " +
"WHERE UCRP.userId LIKE :" + DBConstants.UserComputeResourcePreference.USER_ID + " AND UCRP.gatewayId LIKE :" +
DBConstants.UserComputeResourcePreference.GATEWAY_ID;
- String GET_USER_STORAGE_PREFERENCE = "SELECT DISTINCT USP FROM " + UserStoragePreferenceEntity.class.getSimpleName() + " USP " +
- "WHERE USP.userId LIKE :" + DBConstants.UserStoragePreference.USER_ID + " AND USP.gatewayId LIKE :" + DBConstants.UserStoragePreference.GATEWAY_ID +
- " AND USP.storageResourceId LIKE :" + DBConstants.UserStoragePreference.STORAGE_RESOURCE_ID;
String GET_ALL_USER_STORAGE_PREFERENCE = "SELECT USP FROM " + UserStoragePreferenceEntity.class.getSimpleName() + " USP " +
"WHERE USP.userId LIKE :" + DBConstants.UserStoragePreference.USER_ID + " AND USP.gatewayId LIKE :" +
DBConstants.UserStoragePreference.GATEWAY_ID;

original_message: Making the requested changes


message: Removing JPA annocations for Id classes

change_type: MODIFY

diff:
@@ -32,12 +32,7 @@ public class AppModuleMappingPK implements Serializable {
//default serial version id, required for serializable classes.
private static final long serialVersionUID = 1L;
- @Column(name="INTERFACE_ID", insertable=false, updatable=false)
- @Id
private String interfaceId;
-
- @Column(name="MODULE_ID", insertable=false, updatable=false)
- @Id
private String moduleId;
public AppModuleMappingPK() {

diff:
@@ -32,12 +32,7 @@ public class ApplicationInputPK implements Serializable {
//default serial version id, required for serializable classes.
private static final long serialVersionUID = 1L;
- @Column(name="INTERFACE_ID", insertable=false, updatable=false)
- @Id
private String interfaceId;
-
- @Column(name="INPUT_KEY")
- @Id
private String name;
public ApplicationInputPK() {

diff:
@@ -32,12 +32,7 @@ public class ApplicationOutputPK implements Serializable {
//default serial version id, required for serializable classes.
private static final long serialVersionUID = 1L;
- @Column(name="INTERFACE_ID", insertable=false, updatable=false)
- @Id
private String interfaceId;
-
- @Column(name="OUTPUT_KEY")
- @Id
private String name;
public ApplicationOutputPK() {

diff:
@@ -31,12 +31,7 @@ public class ModuleLoadCmdPK implements Serializable {
// default serial version id, required for serializable classes.
private static final long serialVersionUID = 1L;
- @Id
- @Column(name = "APP_DEPLOYMENT_ID", insertable = false, updatable = false)
private String appdeploymentId;
-
- @Id
- @Column(name = "CMD")
private String command;
public ModuleLoadCmdPK() {

diff:
@@ -31,12 +31,7 @@ public class PostjobCommandPK implements Serializable {
// default serial version id, required for serializable classes.
private static final long serialVersionUID = 1L;
- @Column(name = "APPDEPLOYMENT_ID", insertable = false, updatable = false)
- @Id
private String appdeploymentId;
-
- @Column(name = "COMMAND")
- @Id
private String command;
public PostjobCommandPK() {

diff:
@@ -32,12 +32,7 @@ public class PrejobCommandPK implements Serializable {
//default serial version id, required for serializable classes.
private static final long serialVersionUID = 1L;
- @Column(name="APPDEPLOYMENT_ID", insertable=false, updatable=false)
- @Id
private String appdeploymentId;
-
- @Column(name="COMMAND")
- @Id
private String command;
public PrejobCommandPK() {

license: Apache License 2.0

repo: apache/airavata

original_message: Removing JPA annocations for Id classes


message: Removing JPA annotations in Id classes

diff:
@@ -31,12 +31,7 @@ public class ConfigurationPK implements Serializable {
//default serial version id, required for serializable classes.
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() {

diff:
@@ -66,9 +66,9 @@ public class DataProductEntity implements Serializable {
@Column(name = "PRODUCT_TYPE")
private DataProductType dataProductType;
- //@ElementCollection(fetch = FetchType.EAGER)
- //@CollectionTable(name="DATA_PRODUCT_METADATA", joinColumns = @JoinColumn(name="PRODUCT_URI"))
- //@Column(name = "METADATA_KEY")
+ @ElementCollection(fetch = FetchType.EAGER)
+ @CollectionTable(name="DATA_PRODUCT_METADATA", joinColumns = @JoinColumn(name="PRODUCT_URI"))
+ @Column(name = "METADATA_KEY")
private Map<String, String> productMetadata;
@OneToMany(targetEntity = DataReplicaLocationEntity.class, cascade = CascadeType.ALL,

diff:
@@ -31,12 +31,7 @@ public class DataProductMetadataPK implements Serializable {
//default serial version id, required for serializable classes.
private static final long serialVersionUID = 1L;
- @Id
- @Column(name = "PRODUCT_URI")
private String productUri;
-
- @Id
- @Column(name = "METADATA_KEY")
private String metadataKey;
public String getProductUri() {

diff:
@@ -70,9 +70,9 @@ public class DataReplicaLocationEntity implements Serializable {
@Column(name = "REPLICA_PERSISTENT_TYPE")
private ReplicaPersistentType replicaPersistentType;
- //@ElementCollection(fetch = FetchType.EAGER)
- //@CollectionTable(name="DATA_REPLICA_METADATA", joinColumns = @JoinColumn(name="REPLICA_ID"))
- //@Column(name = "METADATA_KEY")
+ @ElementCollection(fetch = FetchType.EAGER)
+ @CollectionTable(name="DATA_REPLICA_METADATA", joinColumns = @JoinColumn(name="REPLICA_ID"))
+ @Column(name = "METADATA_KEY")
private Map<String, String> replicaMetadata;
@ManyToOne(targetEntity = DataProductEntity.class, cascade = CascadeType.MERGE)

diff:
@@ -30,12 +30,7 @@ import java.io.Serializable;
public class DataReplicaMetadataPK implements Serializable {
private static final long serialVersionUID = 1L;
- @Id
- @Column(name = "REPLICA_ID")
private String replicaId;
-
- @Id
- @Column(name = "METADATA_KEY")
private String metadataKey;
public String getReplicaId() {

original_message: Removing JPA annotations in Id classes


message: Adding Repository classes and tests

change_type: ADD

diff:
+/*
+ *
+ * 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.DataProductEntity;
+import org.apache.airavata.registry.core.utils.DBConstants;
+import org.apache.airavata.registry.core.utils.QueryConstants;
+import org.apache.airavata.registry.cpi.ReplicaCatalog;
+import org.apache.airavata.registry.cpi.ReplicaCatalogException;
+import org.apache.airavata.registry.core.utils.ObjectMapperSingleton;
+import org.dozer.Mapper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.sql.Timestamp;
+import java.util.*;
+
+public class DataProductRepository extends RepCatAbstractRepository<DataProductModel, DataProductEntity, String> {
+ 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 {
+ String productUri = ReplicaCatalog.schema + "://" + UUID.randomUUID().toString();
+ dataProductModel.setProductUri(productUri);
+ 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 Application Deployment");
+ 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 void updateDataProduct(DataProductModel updatedDataProductModel) throws ReplicaCatalogException {
+ saveDataProductModelData(updatedDataProductModel);
+ }
+
+ 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:
+/*
+ *
+ * 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.DataReplicaLocationModel;
+import org.apache.airavata.registry.core.entities.replicacatalog.DataProductEntity;
+import org.apache.airavata.registry.core.entities.replicacatalog.DataReplicaLocationEntity;
+import org.apache.airavata.registry.core.utils.ObjectMapperSingleton;
+import org.apache.airavata.registry.cpi.ReplicaCatalogException;
+import org.dozer.Mapper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.sql.Timestamp;
+import java.util.List;
+import java.util.UUID;
+
+public class DataReplicaLocationRepository extends RepCatAbstractRepository<DataReplicaLocationModel, DataReplicaLocationEntity, String> {
+ private final static Logger logger = LoggerFactory.getLogger(DataProductRepository.class);
+
+ public DataReplicaLocationRepository() { super(DataReplicaLocationModel.class, DataReplicaLocationEntity.class); }
+
+ private String saveDataReplicaLocationModelData(DataReplicaLocationModel dataReplicaLocationModel) throws ReplicaCatalogException {
+ DataReplicaLocationEntity dataReplicaLocationEntity = saveDataReplicaLocation(dataReplicaLocationModel);
+ return dataReplicaLocationEntity.getProductUri();
+ }
+
+ private DataReplicaLocationEntity saveDataReplicaLocation(DataReplicaLocationModel dataReplicaLocationModel) throws ReplicaCatalogException {
+ String replicaId = UUID.randomUUID().toString();
+ dataReplicaLocationModel.setReplicaId(replicaId);
+ Mapper mapper = ObjectMapperSingleton.getInstance();
+ DataReplicaLocationEntity dataReplicaLocationEntity = mapper.map(dataReplicaLocationModel, DataReplicaLocationEntity.class);
+
+ if (!isDataReplicaLocationExists(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 registerDataReplicaLocation(DataReplicaLocationModel dataReplicaLocationModel) throws ReplicaCatalogException {
+ return saveDataReplicaLocationModelData(dataReplicaLocationModel);
+ }
+
+ public void updateDataReplicaLocation(DataReplicaLocationModel dataReplicaLocationModel) throws ReplicaCatalogException {
+ saveDataReplicaLocationModelData(dataReplicaLocationModel);
+ }
+
+ public DataReplicaLocationModel getDataReplicaLocation(String replicaId) throws ReplicaCatalogException {
+ return get(replicaId);
+ }
+
+ public List<DataReplicaLocationModel> getAllDataReplicaLocations(String productUri) throws ReplicaCatalogException {
+ DataProductRepository dataProductRepository = new DataProductRepository();
+ DataProductModel dataProductModel = dataProductRepository.getDataProduct(productUri);
+ List<DataReplicaLocationModel> dataReplicaLocationModelList = dataProductModel.getReplicaLocations();
+ return dataReplicaLocationModelList;
+ }
+
+ public boolean isDataReplicaLocationExists(String replicaId) throws ReplicaCatalogException {
+ return isExists(replicaId);
+ }
+
+ public boolean removeDataReplicaLocation(String replicaId) throws ReplicaCatalogException {
+ return delete(replicaId);
+ }
+
+}

diff:
+/*
+ *
+ * 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:
@@ -26,4 +26,11 @@ public class DBConstants {
public static final String GROUP_RESOURCE_PROFILE_ID = "groupResourceProfileId";
}
+ 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:
+/**
+ *
+ * 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="replicacatalog_data")
+ protected static EntityManagerFactory factory;
+
+ @PersistenceContext(unitName="replicacatalog_data")
+ 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<String, String>();
+ 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:
@@ -3,6 +3,7 @@ package org.apache.airavata.registry.core.utils;
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 {
@@ -37,4 +38,10 @@ public interface QueryConstants {
"WHERE BQ.groupResourceProfileId LIKE : " + DBConstants.GroupResourceProfile.GROUP_RESOURCE_PROFILE_ID;
String FIND_ALL_GROUP_COMPUTE_RESOURCE_POLICY = "SELECT CR FROM "+ ComputeResourcePolicyEntity.class.getSimpleName() + " CR " +
"WHERE CR.groupResourceProfileId LIKE : " + DBConstants.GroupResourceProfile.GROUP_RESOURCE_PROFILE_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:
+/**
+ *
+ * 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.repositories.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 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 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 {
+
+ }
+
+}

diff:
+/**
+ *
+ * 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.repositories.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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
+
+public class DataReplicaLocationRepositoryTest {
+
+ private static Initialize initialize;
+ 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();
+ 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 DataProductRepositoryTest() throws ReplicaCatalogException {
+
+ }
+
+}

original_message: Adding Repository classes and tests


message: Replacing queries with AbstractRepository methods

diff:
@@ -111,16 +111,7 @@ public class ApplicationDeploymentRepository extends AppCatAbstractRepository<Ap
@Override
public ApplicationDeploymentDescription getApplicationDeployement(String deploymentId) throws AppCatalogException {
- Map<String, Object> queryParameters = new HashMap<>();
- queryParameters.put(DBConstants.ApplicationDeployment.APPLICATION_DEPLOYMENT_ID, deploymentId);
- List<ApplicationDeploymentDescription> applicationDeploymentDescriptionList = select(QueryConstants.FIND_APPLICATION_DEPLOYMENT, -1, 0, queryParameters);
-
- if(!applicationDeploymentDescriptionList.isEmpty() && applicationDeploymentDescriptionList != null) {
- logger.debug("Return the record (there is only one record)");
- return applicationDeploymentDescriptionList.get(0);
- }
-
- return null;
+ return get(deploymentId);
}
@Override

diff:
@@ -155,30 +155,12 @@ public class ApplicationInterfaceRepository extends AppCatAbstractRepository<App
@Override
public ApplicationModule getApplicationModule(String moduleId) throws AppCatalogException {
ApplicationModuleRepository applicationModuleRepository = new ApplicationModuleRepository();
- Map<String, Object> queryParameters = new HashMap<>();
- queryParameters.put(DBConstants.ApplicationModule.APPLICATION_MODULE_ID, moduleId);
- List<ApplicationModule> applicationModuleList = applicationModuleRepository.select(QueryConstants.FIND_APPLICATION_MODULE, -1, 0, queryParameters);
-
- if(!applicationModuleList.isEmpty() && applicationModuleList != null) {
- logger.debug("Return the record (there is only one record)");
- return applicationModuleList.get(0);
- }
-
- return null;
+ return applicationModuleRepository.get(moduleId);
}
@Override
public ApplicationInterfaceDescription getApplicationInterface(String interfaceId) throws AppCatalogException {
- Map<String, Object> queryParameters = new HashMap<>();
- queryParameters.put(DBConstants.ApplicationInterface.APPLICATION_INTERFACE_ID, interfaceId);
- List<ApplicationInterfaceDescription> applicationInterfaceDescriptionList = select(QueryConstants.FIND_APPLICATION_INTERFACE, -1, 0, queryParameters);
-
- if(!applicationInterfaceDescriptionList.isEmpty() && applicationInterfaceDescriptionList != null) {
- logger.debug("Return the record (there is only one record)");
- return applicationInterfaceDescriptionList.get(0);
- }
-
- return null;
+ return get(interfaceId);
}
@Override

diff:
@@ -24,7 +24,6 @@ public class DBConstants {
public static int SELECT_MAX_ROWS = 1000;
public static class ApplicationDeployment {
- public static final String APPLICATION_DEPLOYMENT_ID = "appDeploymentId";
public static final String APPLICATION_MODULE_ID = "appModuleId";
public static final String COMPUTE_HOST_ID = "computeHostId";
public static final String GATEWAY_ID = "gatewayId";
@@ -33,13 +32,11 @@ public class DBConstants {
}
public static class ApplicationModule {
- public static final String APPLICATION_MODULE_ID = "appModuleId";
public static final String APPLICATION_MODULE_NAME = "appModuleName";
public static final String GATEWAY_ID = "gatewayId";
}
public static class ApplicationInterface {
- public static final String APPLICATION_INTERFACE_ID = "applicationInterfaceId";
public static final String APPLICATION_NAME = "applicationName";
public static final String GATEWAY_ID = "gatewayId";
}

diff:
@@ -38,8 +38,6 @@ public interface QueryConstants {
"WHERE AD.appModuleId LIKE : " + DBConstants.ApplicationDeployment.APPLICATION_MODULE_ID;
String FIND_APPLICATION_DEPLOYMENTS_FOR_COMPUTE_HOST_ID = "SELECT AD FROM " + ApplicationDeploymentEntity.class.getSimpleName() + " AD " +
"WHERE AD.computeHostId LIKE : " + DBConstants.ApplicationDeployment.COMPUTE_HOST_ID;
- String FIND_APPLICATION_DEPLOYMENT = "SELECT AD FROM " + ApplicationDeploymentEntity.class.getSimpleName() + " AD " +
- "WHERE AD.appDeploymentId LIKE : " + DBConstants.ApplicationDeployment.APPLICATION_DEPLOYMENT_ID;
String GET_ALL_APPLICATION_DEPLOYMENTS = "SELECT AD FROM " + ApplicationDeploymentEntity.class.getSimpleName() + " AD";
String FIND_ACCESSIBLE_APPLICATION_DEPLOYMENTS = "SELECT AD FROM " + ApplicationDeploymentEntity.class.getSimpleName() + " AD " +
"WHERE AD.gatewayId LIKE : " + DBConstants.ApplicationDeployment.GATEWAY_ID + " AND AD.appDeploymentId IN :" +
@@ -51,8 +49,6 @@ public interface QueryConstants {
"WHERE AM.gatewayId LIKE : " + DBConstants.ApplicationModule.GATEWAY_ID;
String FIND_APPLICATION_MODULES_FOR_APPLICATION_MODULE_NAME = "SELECT AM FROM " + ApplicationModuleEntity.class.getSimpleName() + " AM " +
"WHERE AM.appModuleName LIKE : " + DBConstants.ApplicationModule.APPLICATION_MODULE_NAME;
- String FIND_APPLICATION_MODULE = "SELECT AM FROM " + ApplicationModuleEntity.class.getSimpleName() + " AM " +
- "WHERE AM.appModuleId LIKE : " + DBConstants.ApplicationModule.APPLICATION_MODULE_ID;
String FIND_ACCESSIBLE_APPLICATION_MODULES = "SELECT AM FROM " + ApplicationModuleEntity.class.getSimpleName() + " AM " +
", " + ApplicationDeploymentEntity.class.getSimpleName() + " AD WHERE AM.appModuleId = AD.appModuleId AND AM.gatewayId LIKE : " +
DBConstants.ApplicationModule.GATEWAY_ID + " AND AD.appDeploymentId IN :" + DBConstants.ApplicationDeployment.ACCESSIBLE_APPLICATION_DEPLOYMENT_IDS +
@@ -63,8 +59,6 @@ public interface QueryConstants {
"WHERE AI.gatewayId LIKE : " + DBConstants.ApplicationInterface.GATEWAY_ID;
String FIND_APPLICATION_INTERFACES_FOR_APPLICATION_NAME = "SELECT AI FROM " + ApplicationInterfaceEntity.class.getSimpleName() + " AI " +
"WHERE AI.applicationName LIKE : " + DBConstants.ApplicationInterface.APPLICATION_NAME;
- String FIND_APPLICATION_INTERFACE = "SELECT AI FROM " + ApplicationInterfaceEntity.class.getSimpleName() + " AI " +
- "WHERE AI.applicationInterfaceId LIKE : " + DBConstants.ApplicationInterface.APPLICATION_INTERFACE_ID;
String GET_ALL_APPLICATION_INTERFACES = "SELECT AI FROM " + ApplicationInterfaceEntity.class.getSimpleName() + " AI";
// Application Inputs Queries


message: Modifying the tests for Replica Catalog repositories

diff:
@@ -29,6 +29,7 @@ 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;
@@ -38,6 +39,8 @@ 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
@@ -60,14 +63,43 @@ public class DataProductRepositoryTest {
@Test
public void DataProductRepositoryTest() throws ReplicaCatalogException {
- DataProductModel dataProductModel = new DataProductModel();
- dataProductModel.setGatewayId(gatewayId);
- dataProductModel.setOwnerName("testUser");
- dataProductModel.setDataProductType(DataProductType.COLLECTION);
- dataProductModel.setProductSize(1);
- dataProductModel.setProductName("testProduct");
- String productUri = dataProductRepository.registerDataProduct(dataProductModel);
- assertTrue(productUri != null);
+ 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 retrievedDataProductModel = dataProductRepository.getDataProduct(productUri1);
+ assertEquals(retrievedDataProductModel.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));
+
+ testDataProductModel2.setParentProductUri(productUri1);
+ dataProductRepository.updateDataProduct(testDataProductModel2);
+
+ 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:
*/
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.util.Initialize;
import org.apache.airavata.registry.cpi.ReplicaCatalogException;
import org.junit.After;
@@ -27,6 +32,7 @@ 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;
@@ -34,6 +40,7 @@ import static org.junit.Assert.assertFalse;
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);
@@ -43,6 +50,7 @@ public class DataReplicaLocationRepositoryTest {
try {
initialize = new Initialize("replicacatalog-derby.sql");
initialize.initializeDB();
+ dataProductRepository = new DataProductRepository();
dataReplicaLocationRepository = new DataReplicaLocationRepository();
} catch (Exception e) {
logger.error(e.getMessage(), e);
@@ -56,8 +64,61 @@ public class DataReplicaLocationRepositoryTest {
}
@Test
- public void DataProductRepositoryTest() throws ReplicaCatalogException {
+ 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.registerDataReplicaLocation(testDataReplicaLocationModel1);
+ assertTrue(dataReplicaLocationRepository.isExists(replicaId1));
+
+ DataReplicaLocationModel testDataReplicaLocationModel2 = new DataReplicaLocationModel();
+ testDataReplicaLocationModel2.setReplicaName("replicaName2");
+ testDataReplicaLocationModel2.setProductUri(productUri);
+ String replicaId2 = dataReplicaLocationRepository.registerDataReplicaLocation(testDataReplicaLocationModel2);
+ assertTrue(dataReplicaLocationRepository.isExists(replicaId2));
+
+ DataReplicaMetadataEntity dataReplicaMetadataEntity1 = new DataReplicaMetadataEntity();
+ dataReplicaMetadataEntity1.setReplicaId(replicaId1);
+ dataReplicaMetadataEntity1.setMetadataKey("dataKey1");
+ dataReplicaMetadataEntity1.setMetadataValue("dataValue1");
+
+ DataReplicaMetadataEntity dataReplicaMetadataEntity2 = new DataReplicaMetadataEntity();
+ dataReplicaMetadataEntity2.setReplicaId(replicaId1);
+ dataReplicaMetadataEntity1.setMetadataKey("dataKey2");
+ dataReplicaMetadataEntity1.setMetadataValue("dataValue2");
+
+ Map<String, String> dataReplicaMetadataEntityMap = new HashMap<>();
+ dataReplicaMetadataEntityMap.put(dataReplicaMetadataEntity1.getMetadataKey(), dataReplicaMetadataEntity1.getMetadataValue());
+ dataReplicaMetadataEntityMap.put(dataReplicaMetadataEntity2.getMetadataKey(), dataReplicaMetadataEntity2.getMetadataValue());
+ testDataReplicaLocationModel1.setReplicaMetadata(dataReplicaMetadataEntityMap);
+ testDataReplicaLocationModel1.setReplicaPersistentType(ReplicaPersistentType.TRANSIENT);
+ dataReplicaLocationRepository.updateDataReplicaLocation(testDataReplicaLocationModel1);
+
+ DataReplicaLocationModel retrievedDataReplicaLocationModel = dataReplicaLocationRepository.getDataReplicaLocation(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.getAllDataReplicaLocations(productUri);
+ assertTrue(dataReplicaLocationModelList.size() == 2);
+
+ dataReplicaLocationRepository.removeDataReplicaLocation(replicaId1);
+ assertFalse(dataReplicaLocationRepository.isDataReplicaLocationExists(replicaId1));
+
+ dataReplicaLocationRepository.removeDataReplicaLocation(replicaId2);
+ dataProductRepository.removeDataProduct(productUri);
}
}


message: Modifying method calls in RegistryServerHandler

diff:
@@ -60,7 +60,6 @@ import org.apache.airavata.registry.api.RegistryService;
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;
@@ -68,6 +67,8 @@ import org.apache.airavata.registry.core.experiment.catalog.resources.AbstractEx
import org.apache.airavata.registry.core.repositories.appcatalog.ComputeResourceRepository;
import org.apache.airavata.registry.core.repositories.appcatalog.GroupResourceProfileRepository;
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.cpi.*;
import org.apache.airavata.registry.cpi.utils.Constants;
import org.apache.thrift.TException;
@@ -81,8 +82,9 @@ public class RegistryServerHandler implements RegistryService.Iface {
private ExperimentCatalog experimentCatalog;
private AppCatalog appCatalog;
- private ReplicaCatalog dataCatalog;
private WorkflowCatalog workflowCatalog;
+ private DataProductRepository dataProductRepository = new DataProductRepository();
+ private DataReplicaLocationRepository dataReplicaLocationRepository = new DataReplicaLocationRepository();
/**
* Fetch Apache Registry API version
@@ -2304,8 +2306,7 @@ public class RegistryServerHandler implements RegistryService.Iface {
@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+".";
@@ -2319,8 +2320,7 @@ public class RegistryServerHandler implements RegistryService.Iface {
@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+".";
@@ -2334,8 +2334,7 @@ public class RegistryServerHandler implements RegistryService.Iface {
@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+".";
@@ -2349,8 +2348,7 @@ public class RegistryServerHandler implements RegistryService.Iface {
@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 + ".";
@@ -2606,8 +2604,7 @@ public class RegistryServerHandler implements RegistryService.Iface {
@Override
public String registerReplicaLocation(DataReplicaLocationModel replicaLocationModel) throws RegistryServiceException, TException {
try {
- dataCatalog = RegistryFactory.getReplicaCatalog();
- String replicaId = dataCatalog.registerReplicaLocation(replicaLocationModel);
+ String replicaId = dataReplicaLocationRepository.registerDataReplicaLocation(replicaLocationModel);
return replicaId;
} catch (RegistryException e) {
String msg = "Error in retreiving the replica "+replicaLocationModel.getReplicaName()+".";
@@ -2626,8 +2623,7 @@ public class RegistryServerHandler implements RegistryService.Iface {
@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()+".";


message: Making changes to interface, repository, tests

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

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

diff:
@@ -3,6 +3,7 @@ package org.apache.airavata.registry.core.utils;
public class DBConstants {
public static int SELECT_MAX_ROWS = 1000;
+ public static final String CONFIGURATION = "Configuration";
public static class ComputeResourcePreference {
public static final String GATEWAY_ID = "gatewayId";

diff:
@@ -56,7 +56,7 @@ public class RepCatalogJPAUtils {
properties.put("openjpa.DynamicEnhancementAgent", "true");
properties.put("openjpa.RuntimeUnenhancedClasses", "unsupported");
properties.put("openjpa.RemoteCommitProvider","sjvm");
- properties.put("openjpa.Log","DefaultLevel=INFO, Runtime=INFO, Tool=INFO, SQL=INFO");
+ properties.put("openjpa.Log","DefaultLevel=TRACE, Runtime=TRACE, Tool=TRACE, SQL=TRACE");
properties.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)");
properties.put("openjpa.jdbc.QuerySQLCache", "false");
properties.put("openjpa.ConnectionFactoryProperties", "PrettyPrint=true, PrettyPrintLineLength=72," +

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

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

diff:
+/**
+ *
+ * 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:
@@ -48,7 +48,7 @@ public class ReplicaCatalogImpl implements ReplicaCatalog {
throw new ReplicaCatalogException("owner name and gateway id should be non empty");
}
- if(productModel.getParentProductUri() != null && (!isExists(productModel.getParentProductUri())
+ if(productModel.getParentProductUri() != null && (!isDataProductExists(productModel.getParentProductUri())
|| !getDataProduct(productModel.getParentProductUri()).getDataProductType().equals(DataProductType.COLLECTION))){
throw new ReplicaCatalogException("Parent Product does not exists or parent type is not Collection");
}
@@ -169,7 +169,7 @@ public class ReplicaCatalogImpl implements ReplicaCatalog {
}
@Override
- public boolean isExists(String productUri) throws ReplicaCatalogException {
+ public boolean isDataProductExists(String productUri) throws ReplicaCatalogException {
EntityManager em = null;
try {
em = ReplicaCatalogJPAUtils.getEntityManager();

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

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

diff:
@@ -2604,7 +2604,7 @@ public class RegistryServerHandler implements RegistryService.Iface {
@Override
public String registerReplicaLocation(DataReplicaLocationModel replicaLocationModel) throws RegistryServiceException, TException {
try {
- String replicaId = dataReplicaLocationRepository.registerDataReplicaLocation(replicaLocationModel);
+ String replicaId = dataReplicaLocationRepository.registerReplicaLocation(replicaLocationModel);
return replicaId;
} catch (RegistryException e) {
String msg = "Error in retreiving the replica "+replicaLocationModel.getReplicaName()+".";


message: Removing unused logger

diff:
@@ -26,7 +26,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class UserComputeResourcePreferenceRepository extends AppCatAbstractRepository<UserComputeResourcePreference, UserComputeResourcePreferenceEntity, UserComputeResourcePreferencePK> {
- private final static Logger logger = LoggerFactory.getLogger(UserComputeResourcePreferenceRepository.class);
public UserComputeResourcePreferenceRepository() {
super(UserComputeResourcePreference.class, UserComputeResourcePreferenceEntity.class);

diff:
@@ -26,7 +26,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class UserStoragePreferenceRepository extends AppCatAbstractRepository<UserStoragePreference, UserStoragePreferenceEntity, UserStoragePreferencePK> {
- private final static Logger logger = LoggerFactory.getLogger(UserStoragePreferenceRepository.class);
public UserStoragePreferenceRepository() {
super(UserStoragePreference.class, UserStoragePreferenceEntity.class);

original_message: Removing unused logger


message: Changing logging to INFO

diff:
@@ -56,7 +56,7 @@ public class RepCatalogJPAUtils {
properties.put("openjpa.DynamicEnhancementAgent", "true");
properties.put("openjpa.RuntimeUnenhancedClasses", "unsupported");
properties.put("openjpa.RemoteCommitProvider","sjvm");
- properties.put("openjpa.Log","DefaultLevel=TRACE, Runtime=TRACE, Tool=TRACE, SQL=TRACE");
+ 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," +

original_message: Changing logging to INFO


message: Adding replicacatalog-mysql.sql to resources

diff:
+/*
+ *
+ * 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


message: Adding default constructor

diff:
@@ -34,6 +34,9 @@ public class ConfigurationPK implements Serializable {
private String configKey;
private String configVal;
+ public ConfigurationPK() {
+ }
+
public String getConfigKey() {
return configKey;
}

diff:
@@ -34,6 +34,9 @@ public class DataProductMetadataPK implements Serializable {
private String productUri;
private String metadataKey;
+ public DataProductMetadataPK() {
+ }
+
public String getProductUri() {
return productUri;
}

diff:
@@ -33,6 +33,9 @@ public class DataReplicaMetadataPK implements Serializable {
private String replicaId;
private String metadataKey;
+ public DataReplicaMetadataPK() {
+ }
+
public String getReplicaId() {
return replicaId;
}

original_message: Adding default constructor