From 3c2facde3eb6ab98b0abfbdba612b3743822c14d Mon Sep 17 00:00:00 2001 From: Sangamesh Vijaykumar Date: Fri, 10 Apr 2026 13:57:48 +0530 Subject: [PATCH] fix: Refactor FoD attribute default value resolution to use server-provided defaults with fallback logic --- .../helper/FoDAttributeDescriptor.java | 1 + .../attribute/helper/FoDAttributeHelper.java | 35 +++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/fcli-core/fcli-fod/src/main/java/com/fortify/cli/fod/attribute/helper/FoDAttributeDescriptor.java b/fcli-core/fcli-fod/src/main/java/com/fortify/cli/fod/attribute/helper/FoDAttributeDescriptor.java index 83d54ea3d8..450140c0b9 100644 --- a/fcli-core/fcli-fod/src/main/java/com/fortify/cli/fod/attribute/helper/FoDAttributeDescriptor.java +++ b/fcli-core/fcli-fod/src/main/java/com/fortify/cli/fod/attribute/helper/FoDAttributeDescriptor.java @@ -36,4 +36,5 @@ public class FoDAttributeDescriptor extends JsonNodeHolder { private Boolean isRestricted; private ArrayList picklistValues; private String value; + private String defaultValue; } diff --git a/fcli-core/fcli-fod/src/main/java/com/fortify/cli/fod/attribute/helper/FoDAttributeHelper.java b/fcli-core/fcli-fod/src/main/java/com/fortify/cli/fod/attribute/helper/FoDAttributeHelper.java index 501c416565..5204883417 100644 --- a/fcli-core/fcli-fod/src/main/java/com/fortify/cli/fod/attribute/helper/FoDAttributeHelper.java +++ b/fcli-core/fcli-fod/src/main/java/com/fortify/cli/fod/attribute/helper/FoDAttributeHelper.java @@ -14,6 +14,7 @@ import java.util.*; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -68,23 +69,9 @@ public static final Map getRequiredAttributesDefaultValues(Unire FoDAttributeDescriptor currentLookup = lookupIterator.next(); // currentLookup.getAttributeTypeId() == 1 if "Application", 4 if "Release" - filter above does not support querying on this yet! if (currentLookup.getIsRequired() && (attrType.getValue() == 0 || currentLookup.getAttributeTypeId() == attrType.getValue())) { - switch (currentLookup.getAttributeDataType()) { - case "Text": - reqAttrs.put(currentLookup.getName(), "autofilled by fcli"); - break; - case "Boolean": - reqAttrs.put(currentLookup.getName(), String.valueOf(false)); - break; - case "User": - // use the first user in the list - reqAttrs.put(currentLookup.getName(), currentLookup.getPicklistValues().get(0).getName()); - break; - case "Picklist": - // use the first value in the picklist - reqAttrs.put(currentLookup.getName(), currentLookup.getPicklistValues().get(0).getName()); - break; - default: - break; + var defaultValue = getDefaultValue(currentLookup); + if (defaultValue != null) { + reqAttrs.put(currentLookup.getName(), defaultValue); } } } @@ -204,4 +191,16 @@ public static FoDAttributeDescriptor updateAttribute(UnirestInstance unirest, St } -} + private static String getDefaultValue(FoDAttributeDescriptor attribute) { + if (StringUtils.isNotBlank(attribute.getDefaultValue())) { + return attribute.getDefaultValue(); + } + return switch (attribute.getAttributeDataType()) { + case "Text" -> "autofilled by fcli"; + case "Boolean" -> String.valueOf(false); + case "User", "Picklist" -> attribute.getPicklistValues() != null && !attribute.getPicklistValues().isEmpty() + ? attribute.getPicklistValues().get(0).getName() : null; + default -> null; + }; + } +} \ No newline at end of file