Github user apiri commented on a diff in the pull request:

    https://github.com/apache/nifi-minifi/pull/17#discussion_r66997854
  
    --- Diff: 
minifi-bootstrap/src/main/java/org/apache/nifi/minifi/bootstrap/util/schema/common/BaseSchema.java
 ---
    @@ -51,18 +55,80 @@ public void addValidationIssue(String keyName, String 
wrapperName, String reason
             validationIssues.add("'" + keyName + "' in section '" + 
wrapperName + "' because " + reason);
         }
     
    -    public <T> T getRequiredKey(Map map, String keyName, String 
wrapperName) {
    -        if (map.get(keyName) != null) {
    -            return (T) map.get(keyName);
    +    public void addIssuesIfNotNull(BaseSchema baseSchema) {
    +        if (baseSchema != null) {
    +            validationIssues.addAll(baseSchema.getValidationIssues());
    +        }
    +    }
    +
    +    /******* Value Access/Interpretation helper methods *******/
    +    public <T> T getOptionalKeyAsType(Map valueMap, String key, Class 
targetClass, String wrapperName, T defaultValue) {
    +        return getKeyAsType(valueMap, key, targetClass, wrapperName, 
false, defaultValue);
    +    }
    +
    +    public <T> T getRequiredKeyAsType(Map valueMap, String key, Class 
targetClass, String wrapperName) {
    +        return getKeyAsType(valueMap, key, targetClass, wrapperName, true, 
null);
    +    }
    +
    +    <T> T getKeyAsType(Map valueMap, String key, Class targetClass, String 
wrapperName, boolean required, T defaultValue) {
    +        Object value = valueMap.get(key);
    +        if (value == null) {
    +            if (defaultValue != null) {
    +                return defaultValue;
    +            } else if(required) {
    +                addValidationIssue(key, wrapperName, "it was not found and 
it is required");
    +            }
             } else {
    -            addValidationIssue(keyName, wrapperName, "it was not found and 
it is required");
    -            return null;
    +            if (targetClass.isInstance(value)) {
    +                return (T) value;
    +            } else {
    +                addValidationIssue(key, wrapperName, "it is found but 
could not be parsed as a " + targetClass.getSimpleName());
    +            }
             }
    +        return null;
         }
     
    -    public void addIssuesIfNotNull(BaseSchema baseSchema) {
    -        if (baseSchema != null) {
    -            validationIssues.addAll(baseSchema.getValidationIssues());
    +
    +    public <T> T getMapAsType(Map valueMap, String key, Class targetClass, 
String wrapperName, boolean required) {
    +        Object obj = valueMap.get(key);
    +        return interpretValueAsType(obj, key, targetClass, wrapperName, 
required);
    +    }
    +
    +    public void instantiateList(List list, String simpleListType, Class 
targetClass, String wrapperName){
    --- End diff --
    
    Is it fair to say that this is more of a transform/mapping to type for the 
already existing list?  


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to