/*
 * Copyright 2017 flow.ci
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.flow.platform.plugin.domain.envs;

/**
 * @author yh@firim
 */
public enum PluginEnvType {

    STRING("string"),

    INTEGER("integer"),

    BOOLEAN("boolean"),

    LIST("list");

    private String value;

    PluginEnvType(String value) {
        this.value = value;
    }

    public String getValue() {
        return value;
    }
}

@@ -631,16 +631,56 @@
 .envs;%0A%0A
+import com.google.common.base.Strings;%0A%0A
 /**%0A * @
@@ -747,16 +747,37 @@
 %22string%22
+, new StringHandler()
 ),%0A%0A    
@@ -793,16 +793,38 @@
 integer%22
+, new IntegerHandler()
 ),%0A%0A    
@@ -844,31 +844,73 @@
 ean%22
-),%0A%0A    LIST(%22list%22
+, new BooleanHandler()),%0A%0A    LIST(%22list%22, new ListHandler()
 );%0A%0A
+%0A
     
@@ -932,16 +932,46 @@
 value;%0A%0A
+    private Handler handler;%0A%0A
     Plug
@@ -992,16 +992,33 @@
 ng value
+, Handler handler
 ) %7B%0A    
@@ -1037,24 +1037,56 @@
 ue = value;%0A
+        this.handler = handler;%0A
     %7D%0A%0A    p
@@ -1139,10 +1139,2074 @@
 ;%0A    %7D%0A
+%0A    public Handler getHandler() %7B%0A        return handler;%0A    %7D%0A%0A    private interface Handler%3CT%3E %7B%0A%0A        Boolean isValidated(String value);%0A%0A        T converter(String value);%0A    %7D%0A%0A    private static class StringHandler implements Handler%3CString%3E %7B%0A%0A        @Override%0A        public Boolean isValidated(String value) %7B%0A            return true;%0A        %7D%0A%0A        @Override%0A        public String converter(String value) %7B%0A            return value;%0A        %7D%0A    %7D%0A%0A    private static class IntegerHandler implements Handler%3CInteger%3E %7B%0A%0A        @Override%0A        public Boolean isValidated(String value) %7B%0A            try %7B%0A                integerOfString(value);%0A            %7D catch (Throwable throwable) %7B%0A                return false;%0A            %7D%0A%0A            return true;%0A        %7D%0A%0A        @Override%0A        public Integer converter(String value) %7B%0A            return integerOfString(value);%0A        %7D%0A    %7D%0A%0A    private static class BooleanHandler implements Handler%3CBoolean%3E %7B%0A%0A        @Override%0A        public Boolean isValidated(String value) %7B%0A            try %7B%0A                booleanOfString(value);%0A            %7D catch (Throwable throwable) %7B%0A                return false;%0A            %7D%0A%0A            return true;%0A        %7D%0A%0A        @Override%0A        public Boolean converter(String value) %7B%0A            return booleanOfString(value);%0A        %7D%0A    %7D%0A%0A    private static class ListHandler implements Handler%3CString%3E %7B%0A%0A        @Override%0A        public Boolean isValidated(String value) %7B%0A            return true;%0A        %7D%0A%0A        @Override%0A        public String converter(String value) %7B%0A            return value;%0A        %7D%0A    %7D%0A%0A    private static boolean booleanOfString(String value) %7B%0A        if (Strings.isNullOrEmpty(value)) %7B%0A            return false;%0A        %7D else %7B%0A            return Boolean.valueOf(value);%0A        %7D%0A    %7D%0A%0A%0A    private static Integer integerOfString(String value) %7B%0A        if (Strings.isNullOrEmpty(value)) %7B%0A            return null;%0A        %7D else %7B%0A            return Integer.valueOf(value);%0A        %7D%0A    %7D%0A%0A
 %7D%0A

add pluginEnvType Handler