diff options
author | Fiete Ostkamp <Fiete.Ostkamp@telekom.de> | 2023-08-11 09:59:18 +0000 |
---|---|---|
committer | Fiete Ostkamp <fiete.ostkamp@telekom.de> | 2023-08-11 10:07:36 +0000 |
commit | f80d389842613bc961ae3f785580ab58f61b740a (patch) | |
tree | ea4cbfe524c18d507244167f3ba230206b1c6c1b /aai-core/src/main/java | |
parent | 1c1f0dc110177a190c67e3a8b924542ce4d75ff8 (diff) |
Refactor DBSerializer verifyResourceVersion method
- assign variables closer to where they are used
- have a less complex validation logic
- rename related test cases to better understand what they are doing
- add further test cases (this would actually be better covered via a parameterized test)
- rename DBSerializer variable in test cases to better match whith the name of the type it's representing
Issue-ID: AAI-3657
Signed-off-by: Fiete Ostkamp <Fiete.Ostkamp@telekom.de>
Change-Id: Id7976b0123c17178845db115c09b5c00d2361e6d
Diffstat (limited to 'aai-core/src/main/java')
-rw-r--r-- | aai-core/src/main/java/org/onap/aai/serialization/db/DBSerializer.java | 31 |
1 files changed, 12 insertions, 19 deletions
diff --git a/aai-core/src/main/java/org/onap/aai/serialization/db/DBSerializer.java b/aai-core/src/main/java/org/onap/aai/serialization/db/DBSerializer.java index 2192ff5e..3a694759 100644 --- a/aai-core/src/main/java/org/onap/aai/serialization/db/DBSerializer.java +++ b/aai-core/src/main/java/org/onap/aai/serialization/db/DBSerializer.java @@ -321,7 +321,7 @@ public class DBSerializer { /** * Touch standard vertex properties. - * + * * @param v the v * @param isNewVertex the is new vertex */ @@ -2213,29 +2213,24 @@ public class DBSerializer { */ public boolean verifyResourceVersion(String action, String nodeType, String currentResourceVersion, String resourceVersion, String uri) throws AAIException { - String enabled = ""; - String errorDetail = ""; - String aaiExceptionCode = ""; - boolean isDeleteResourceVersionOk = true; - if (currentResourceVersion == null) { - currentResourceVersion = ""; - } - if (resourceVersion == null) { - resourceVersion = ""; - } + currentResourceVersion = currentResourceVersion != null ? currentResourceVersion : ""; + resourceVersion = resourceVersion != null ? resourceVersion : ""; + + String enabled = ""; try { enabled = AAIConfig.get(AAIConstants.AAI_RESVERSION_ENABLEFLAG); - } catch (AAIException e) { ErrorLogHelper.logException(e); } - if (enabled.equals("true")) { - if ("delete".equals(action)) { - isDeleteResourceVersionOk = verifyResourceVersionForDelete(currentResourceVersion, resourceVersion); + + if ("true".equals(enabled)) { + if ("delete".equals(action) && verifyResourceVersionForDelete(currentResourceVersion, resourceVersion)) { + return true; } - if ((!isDeleteResourceVersionOk) - || ((!"delete".equals(action)) && (!currentResourceVersion.equals(resourceVersion)))) { + if (!currentResourceVersion.equals(resourceVersion)) { + String errorDetail; + String aaiExceptionCode; if ("create".equals(action) && !resourceVersion.equals("")) { errorDetail = "resource-version passed for " + action + " of " + uri; aaiExceptionCode = "AAI_6135"; @@ -2246,9 +2241,7 @@ public class DBSerializer { errorDetail = "resource-version MISMATCH for " + action + " of " + uri; aaiExceptionCode = "AAI_6131"; } - throw new AAIException(aaiExceptionCode, errorDetail); - } } return true; |