aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorThomas Nelson <nelson24@att.com>2019-07-09 14:49:05 +0000
committerGerrit Code Review <gerrit@onap.org>2019-07-09 14:49:05 +0000
commita83c036d46be00d1ca0b6bbff27382aa847240e1 (patch)
tree5ae5e356aee826195d3f2f825f7aa6fcc999182c /src/main
parent85e7c6bb431ee849eab28b3fa6e9de9b40b7863a (diff)
parentf9f7fa56adf725801a789ed6c3f5503bb5d243a2 (diff)
Merge "Sonar reduce method parameter"
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/onap/music/conductor/conditionals/MusicConditional.java40
-rw-r--r--src/main/java/org/onap/music/conductor/conditionals/RestMusicConditionalAPI.java10
-rw-r--r--src/main/java/org/onap/music/conductor/conditionals/UpdateDataObject.java119
3 files changed, 150 insertions, 19 deletions
diff --git a/src/main/java/org/onap/music/conductor/conditionals/MusicConditional.java b/src/main/java/org/onap/music/conductor/conditionals/MusicConditional.java
index 29740d83..18fa8a18 100644
--- a/src/main/java/org/onap/music/conductor/conditionals/MusicConditional.java
+++ b/src/main/java/org/onap/music/conductor/conditionals/MusicConditional.java
@@ -165,12 +165,10 @@ public class MusicConditional {
}
- public static ReturnType update(Map<String, PreparedQueryObject> queryBank, String keyspace, String tableName,
- String primaryKey, String primaryKeyValue, String planId, String cascadeColumnName,
- Map<String, String> cascadeColumnValues)
- throws MusicLockingException, MusicQueryException, MusicServiceException {
+ public static ReturnType update(UpdateDataObject dataObj)
+ throws MusicLockingException, MusicQueryException, MusicServiceException {
- String key = keyspace + "." + tableName + "." + primaryKeyValue;
+ String key = dataObj.getKeyspace() + "." + dataObj.getTableName() + "." + dataObj.getPrimaryKeyValue();
String lockId = MusicCore.createLockReference(key);
long leasePeriod = MusicUtil.getDefaultLockLeasePeriod();
ReturnType lockAcqResult = MusicCore.acquireLockWithLease(key, lockId, leasePeriod);
@@ -178,7 +176,16 @@ public class MusicConditional {
try {
if (lockAcqResult.getResult().equals(ResultType.SUCCESS)) {
- ReturnType criticalPutResult = updateAtomic(lockId, keyspace, tableName, primaryKey,primaryKeyValue, queryBank,planId,cascadeColumnValues,cascadeColumnName);
+ ReturnType criticalPutResult = updateAtomic(new UpdateDataObject().setLockId(lockId)
+ .setKeyspace(dataObj.getKeyspace())
+ .setTableName( dataObj.getTableName())
+ .setPrimaryKey(dataObj.getPrimaryKey())
+ .setPrimaryKeyValue(dataObj.getPrimaryKeyValue())
+ .setQueryBank(dataObj.getQueryBank())
+ .setPlanId(dataObj.getPlanId())
+ .setCascadeColumnValues(dataObj.getCascadeColumnValues())
+ .setCascadeColumnName(dataObj.getCascadeColumnName()));
+
MusicCore.destroyLockRef(lockId);
return criticalPutResult;
} else {
@@ -194,25 +201,24 @@ public class MusicConditional {
}
}
- public static ReturnType updateAtomic(String lockId, String keyspace, String tableName, String primaryKey,String primaryKeyValue,
- Map<String,PreparedQueryObject> queryBank,String planId,Map<String,String> cascadeColumnValues,String casscadeColumnName) {
+ public static ReturnType updateAtomic(UpdateDataObject dataObj) {
try {
- String fullyQualifiedKey = keyspace + "." + tableName + "." + primaryKeyValue;
- ReturnType lockAcqResult = MusicCore.acquireLock(fullyQualifiedKey, lockId);
+ String fullyQualifiedKey = dataObj.getKeyspace() + "." + dataObj.getTableName() + "." + dataObj.getPrimaryKeyValue();
+ ReturnType lockAcqResult = MusicCore.acquireLock(fullyQualifiedKey, dataObj.getLockId());
if (lockAcqResult.getResult().equals(ResultType.SUCCESS)) {
- Row row = MusicDataStoreHandle.getDSHandle().executeQuorumConsistencyGet(queryBank.get(MusicUtil.SELECT)).one();
+ Row row = MusicDataStoreHandle.getDSHandle().executeQuorumConsistencyGet(dataObj.getQueryBank().get(MusicUtil.SELECT)).one();
if(row != null) {
- Map<String, String> updatedValues = cascadeColumnUpdateSpecific(row, cascadeColumnValues, casscadeColumnName, planId);
+ Map<String, String> updatedValues = cascadeColumnUpdateSpecific(row, dataObj.getCascadeColumnValues(), dataObj.getCascadeColumnName(), dataObj.getPlanId());
JSONObject json = new JSONObject(updatedValues);
PreparedQueryObject update = new PreparedQueryObject();
String vector_ts = String.valueOf(Thread.currentThread().getId() + System.currentTimeMillis());
- update.appendQueryString("UPDATE " + keyspace + "." + tableName + " SET " + casscadeColumnName + "['" + planId
- + "'] = ?, vector_ts = ? WHERE " + primaryKey + " = ?");
+ update.appendQueryString("UPDATE " + dataObj.getKeyspace() + "." + dataObj.getTableName() + " SET " + dataObj.getCascadeColumnName() + "['" + dataObj.getPlanId()
+ + "'] = ?, vector_ts = ? WHERE " + dataObj.getPrimaryKey() + " = ?");
update.addValue(MusicUtil.convertToActualDataType(DataType.text(), json.toString()));
update.addValue(MusicUtil.convertToActualDataType(DataType.text(), vector_ts));
- update.addValue(MusicUtil.convertToActualDataType(DataType.text(), primaryKeyValue));
+ update.addValue(MusicUtil.convertToActualDataType(DataType.text(), dataObj.getPrimaryKeyValue()));
try {
MusicDataStoreHandle.getDSHandle().executePut(update, "critical");
} catch (Exception ex) {
@@ -220,9 +226,9 @@ public class MusicConditional {
return new ReturnType(ResultType.FAILURE, ex.getMessage());
}
}else {
- return new ReturnType(ResultType.FAILURE,"Cannot find data related to key: "+primaryKey);
+ return new ReturnType(ResultType.FAILURE,"Cannot find data related to key: "+dataObj.getPrimaryKey());
}
- MusicDataStoreHandle.getDSHandle().executePut(queryBank.get(MusicUtil.UPSERT), "critical");
+ MusicDataStoreHandle.getDSHandle().executePut(dataObj.getQueryBank().get(MusicUtil.UPSERT), "critical");
return new ReturnType(ResultType.SUCCESS, "update success");
} else {
diff --git a/src/main/java/org/onap/music/conductor/conditionals/RestMusicConditionalAPI.java b/src/main/java/org/onap/music/conductor/conditionals/RestMusicConditionalAPI.java
index 7372fc46..584a9e47 100644
--- a/src/main/java/org/onap/music/conductor/conditionals/RestMusicConditionalAPI.java
+++ b/src/main/java/org/onap/music/conductor/conditionals/RestMusicConditionalAPI.java
@@ -183,8 +183,14 @@ public class RestMusicConditionalAPI {
queryBank.put(MusicUtil.SELECT, select);
queryBank.put(MusicUtil.UPSERT, upsert);
String planId = casscadeColumnData.get("key").toString();
- ReturnType result = MusicConditional.update(queryBank, keyspace, tablename,
- primaryKey,primaryKeyValue,planId,casscadeColumnName,casscadeColumnValueMap);
+ ReturnType result = MusicConditional.update(new UpdateDataObject().setQueryBank(queryBank)
+ .setKeyspace(keyspace)
+ .setTableName(tablename)
+ .setPrimaryKey(primaryKey)
+ .setPrimaryKeyValue(primaryKeyValue)
+ .setPlanId(planId)
+ .setCascadeColumnName(casscadeColumnName)
+ .setCascadeColumnValues(casscadeColumnValueMap));
if (result.getResult() == ResultType.SUCCESS) {
return response.status(Status.OK)
.entity(new JsonResponse(result.getResult())
diff --git a/src/main/java/org/onap/music/conductor/conditionals/UpdateDataObject.java b/src/main/java/org/onap/music/conductor/conditionals/UpdateDataObject.java
new file mode 100644
index 00000000..1ea8994e
--- /dev/null
+++ b/src/main/java/org/onap/music/conductor/conditionals/UpdateDataObject.java
@@ -0,0 +1,119 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Samsung Electronics Co., Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.music.conductor.conditionals;
+
+import java.util.Map;
+import org.onap.music.datastore.PreparedQueryObject;
+
+public class UpdateDataObject {
+
+ Map<String, PreparedQueryObject> queryBank;
+ String keyspace;
+ String tableName;
+ String primaryKey;
+ String primaryKeyValue;
+ String planId;
+ String cascadeColumnName;
+ Map<String, String> cascadeColumnValues;
+ String lockId;
+
+ public Map<String, PreparedQueryObject> getQueryBank() {
+ return queryBank;
+ }
+
+ public UpdateDataObject setQueryBank(Map<String, PreparedQueryObject> queryBank) {
+ this.queryBank = queryBank;
+ return this;
+ }
+
+ public String getKeyspace() {
+ return keyspace;
+ }
+
+ public UpdateDataObject setKeyspace(String keyspace) {
+ this.keyspace = keyspace;
+ return this;
+ }
+
+ public String getTableName() {
+ return tableName;
+ }
+
+ public UpdateDataObject setTableName(String tableName) {
+ this.tableName = tableName;
+ return this;
+ }
+
+ public String getPrimaryKey() {
+ return primaryKey;
+ }
+
+ public UpdateDataObject setPrimaryKey(String primaryKey) {
+ this.primaryKey = primaryKey;
+ return this;
+ }
+
+ public String getPrimaryKeyValue() {
+ return primaryKeyValue;
+ }
+
+ public UpdateDataObject setPrimaryKeyValue(String primaryKeyValue) {
+ this.primaryKeyValue = primaryKeyValue;
+ return this;
+ }
+
+ public String getPlanId() {
+ return planId;
+ }
+
+ public UpdateDataObject setPlanId(String planId) {
+ this.planId = planId;
+ return this;
+ }
+
+ public String getCascadeColumnName() {
+ return cascadeColumnName;
+ }
+
+ public UpdateDataObject setCascadeColumnName(String cascadeColumnName) {
+ this.cascadeColumnName = cascadeColumnName;
+ return this;
+ }
+
+ public Map<String, String> getCascadeColumnValues() {
+ return cascadeColumnValues;
+ }
+
+ public UpdateDataObject setLockId(String lockId) {
+ this.lockId=lockId;
+ return this;
+ }
+
+ public String getLockId() {
+ return lockId;
+ }
+
+ public UpdateDataObject setCascadeColumnValues(Map<String, String> cascadeColumnValues) {
+ this.cascadeColumnValues = cascadeColumnValues;
+ return this;
+ }
+
+
+}