Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 13CC8200AF7 for ; Tue, 14 Jun 2016 17:45:46 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 12839160A47; Tue, 14 Jun 2016 15:45:46 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 59E4C160A06 for ; Tue, 14 Jun 2016 17:45:45 +0200 (CEST) Received: (qmail 61641 invoked by uid 500); 14 Jun 2016 15:45:44 -0000 Mailing-List: contact dev-help@nifi.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@nifi.apache.org Delivered-To: mailing list dev@nifi.apache.org Received: (qmail 61626 invoked by uid 99); 14 Jun 2016 15:45:44 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 14 Jun 2016 15:45:44 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 17247DFDEF; Tue, 14 Jun 2016 15:45:44 +0000 (UTC) From: apiri To: dev@nifi.apache.org Reply-To: dev@nifi.apache.org References: In-Reply-To: Subject: [GitHub] nifi-minifi pull request #17: MINIFI-30 added changes to the config transfor... Content-Type: text/plain Message-Id: <20160614154544.17247DFDEF@git1-us-west.apache.org> Date: Tue, 14 Jun 2016 15:45:44 +0000 (UTC) archived-at: Tue, 14 Jun 2016 15:45:46 -0000 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 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 getOptionalKeyAsType(Map valueMap, String key, Class targetClass, String wrapperName, T defaultValue) { + return getKeyAsType(valueMap, key, targetClass, wrapperName, false, defaultValue); + } + + public T getRequiredKeyAsType(Map valueMap, String key, Class targetClass, String wrapperName) { + return getKeyAsType(valueMap, key, targetClass, wrapperName, true, null); + } + + 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 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 infrastructure@apache.org or file a JIRA ticket with INFRA. ---