aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrancis Toth <francis.toth@yoppworks.com>2020-05-01 11:45:41 -0400
committerOfir Sonsino <ofir.sonsino@intl.att.com>2020-05-05 08:15:12 +0000
commit908793f04e9a595734a6e0e189b846ed062bfc7d (patch)
tree26df434e33e2e5d54fc898cae1ddf3291966307f
parent06b84593bea8b963266f8d2a8a62dce9feeb2181 (diff)
Refactor CsarUtil::getLatestSchemaFilesFromCassandra
Signed-off-by: Francis Toth <francis.toth@yoppworks.com> Change-Id: I3f96d76a07fd32bdbd8b59beb5409eab0b0f3aa8 Issue-ID: SDC-2812
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java47
1 files changed, 31 insertions, 16 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java
index bb388fe311..80441103cf 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CsarUtils.java
@@ -39,6 +39,7 @@ import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
+import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -630,25 +631,39 @@ public class CsarUtils {
}
private Either<byte[], ResponseFormat> getLatestSchemaFilesFromCassandra() {
- Either<List<SdcSchemaFilesData>, CassandraOperationStatus> specificSchemaFiles = sdcSchemaFilesCassandraDao.getSpecificSchemaFiles(getVersionFirstThreeOctets(), CONFORMANCE_LEVEL);
-
- if(specificSchemaFiles.isRight()){
- log.debug("Failed to get the schema files SDC-Version: {} Conformance-Level {}. Please fix DB table accordingly.", getVersionFirstThreeOctets(), CONFORMANCE_LEVEL);
- StorageOperationStatus storageStatus = DaoStatusConverter.convertCassandraStatusToStorageStatus(specificSchemaFiles.right().value());
- ActionStatus convertedFromStorageResponse = componentsUtils.convertFromStorageResponse(storageStatus);
- return Either.right(componentsUtils.getResponseFormat(convertedFromStorageResponse));
- }
-
- List<SdcSchemaFilesData> listOfSchemas = specificSchemaFiles.left().value();
+ String fto = getVersionFirstThreeOctets();
+ return sdcSchemaFilesCassandraDao.getSpecificSchemaFiles(fto, CONFORMANCE_LEVEL)
+ .right().map(schemaFilesFetchDBError(fto))
+ .left().bind(iff(
+ List::isEmpty,
+ () -> schemaFileFetchError(fto),
+ s -> Either.left(s.iterator().next().getPayloadAsArray())
+ )
+ );
+ }
- if(listOfSchemas.isEmpty()){
- log.debug("Failed to get the schema files SDC-Version: {} Conformance-Level {}", getVersionFirstThreeOctets(), CONFORMANCE_LEVEL);
- return Either.right(componentsUtils.getResponseFormat(ActionStatus.TOSCA_SCHEMA_FILES_NOT_FOUND, getVersionFirstThreeOctets(), CONFORMANCE_LEVEL));
- }
+ private static <A, B> F<A, B> iff(Predicate<A> p, Supplier<B> s, Function<A, B> orElse) {
+ return a -> p.test(a) ? s.get() : orElse.apply(a);
+ }
- SdcSchemaFilesData schemaFile = listOfSchemas.iterator().next();
+ private F<CassandraOperationStatus, ResponseFormat> schemaFilesFetchDBError(String firstThreeOctets) {
+ return cos -> {
+ log.debug(
+ "Failed to get the schema files SDC-Version: {} Conformance-Level {}. Please fix DB table accordingly.",
+ firstThreeOctets, CONFORMANCE_LEVEL);
+ StorageOperationStatus sos = DaoStatusConverter.convertCassandraStatusToStorageStatus(cos);
+ return componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(sos));
+ };
+ }
- return Either.left(schemaFile.getPayloadAsArray());
+ private Either<byte[], ResponseFormat> schemaFileFetchError(String firstThreeOctets) {
+ log.debug("Failed to get the schema files SDC-Version: {} Conformance-Level {}",
+ firstThreeOctets, CONFORMANCE_LEVEL);
+ return Either.right(
+ componentsUtils.getResponseFormat(
+ ActionStatus.TOSCA_SCHEMA_FILES_NOT_FOUND, firstThreeOctets, CONFORMANCE_LEVEL
+ )
+ );
}
private Either<byte[], ActionStatus> getFromCassandra(String cassandraId) {