Package com.dtolabs.rundeck.plugins.util

Examples of com.dtolabs.rundeck.plugins.util.PropertyBuilder


        }
        return null;
    }

    private static Property propertyFromField(final Field field, final PluginProperty annotation) {
        final PropertyBuilder pbuild = PropertyBuilder.builder();
        //determine type
        final Property.Type type = propertyTypeFromFieldType(field.getType());
        if (null == type) {
            return null;
        }
        pbuild.type(type);
        if (type == Property.Type.String) {
            StringRenderingConstants.DisplayType renderBehaviour = StringRenderingConstants.DisplayType.SINGLE_LINE;
            //set select/freeselect
            final SelectValues selectAnnotation = field.getAnnotation(SelectValues.class);
            if (null != selectAnnotation) {
                pbuild.type(selectAnnotation.freeSelect() ? Property.Type.FreeSelect : Property.Type.Select);
                pbuild.values(selectAnnotation.values());
            }
           
            if (field.getAnnotation(TextArea.class) != null) {
                renderBehaviour = StringRenderingConstants.DisplayType.MULTI_LINE;
            }

            if (field.getAnnotation(Password.class) != null) {
                renderBehaviour = StringRenderingConstants.DisplayType.PASSWORD;
            }

            pbuild.renderingOption(StringRenderingConstants.DISPLAY_TYPE_KEY, renderBehaviour);
        }

        String name = annotation.name();
        if (null == name || "".equals(name)) {
            name = field.getName();
        }
        pbuild.name(name);

        if (null != annotation.title() && !"".equals(annotation.title())) {
            pbuild.title(annotation.title());
        } else {
            pbuild.title(name);
        }

        pbuild.description(annotation.description());

        if (null != annotation.defaultValue() && !"".equals(annotation.defaultValue())) {
            pbuild.defaultValue(annotation.defaultValue());
        }
        pbuild.required(annotation.required());

        pbuild.scope(annotation.scope());

        return pbuild.build();
    }
View Full Code Here


        final Object config = metadata.get("config");
        if (config instanceof List) {
            final List configs = (List) config;
            for (final Object citem : configs) {
                if (citem instanceof Map) {
                    final PropertyBuilder pbuild = PropertyBuilder.builder();
                    final Map<String, Object> itemmeta = (Map<String, Object>) citem;
                    final String typestr = metaStringProp(itemmeta, CONFIG_TYPE);
                    try {
                        pbuild.type(Property.Type.valueOf(typestr));
                    } catch (IllegalArgumentException e) {
                        throw new ConfigurationException("Invalid property type: " + typestr);
                    }

                    String propName = metaStringProp(itemmeta, CONFIG_NAME);
                    pbuild
                        .name(propName)
                        .title(metaStringProp(itemmeta, CONFIG_TITLE))
                        .description(metaStringProp(itemmeta, CONFIG_DESCRIPTION));

                    final Object reqValue = itemmeta.get(CONFIG_REQUIRED);
                    final boolean required;
                    if (reqValue instanceof Boolean) {
                        required = (Boolean) reqValue;
                    } else {
                        required = reqValue instanceof String && Boolean.parseBoolean((String) reqValue);
                    }

                    pbuild.required(required);


                    final Object defObj = itemmeta.get(CONFIG_DEFAULT);

                    pbuild.defaultValue(null != defObj ? defObj.toString() : null);

                    final List<String> valueList;

                    final String valuesstr = metaStringProp(itemmeta, CONFIG_VALUES);
                    if (null != valuesstr) {
                        final String[] split = null != valuesstr ? valuesstr.split(",") : null;
                        valueList = Arrays.asList(split);
                    } else {
                        Object vlist = itemmeta.get(CONFIG_VALUES);
                        if (vlist instanceof List) {
                            valueList = (List<String>) vlist;
                        } else {
                            valueList = null;
                        }
                    }
                    final List<String> values;
                    if (null != valueList) {
                        final ArrayList<String> valuesA = new ArrayList<String>();
                        for (final String s : valueList) {
                            valuesA.add(s.trim());
                        }
                        values = valuesA;
                    } else {
                        values = null;
                    }
                    pbuild.values(values);

                    final String scopeString = metaStringProp(itemmeta, CONFIG_SCOPE);
                    if(null!=scopeString) {
                        try {
                            pbuild.scope(PropertyScope.valueOf(scopeString.trim()));
                        } catch (IllegalArgumentException e) {
                            throw new ConfigurationException("Invalid property scope: " + scopeString);
                        }
                    }
                    if(useConventionalPropertiesMapping) {
                        final String projectPropertyPrefix =
                                PropertyResolverFactory.projectPropertyPrefix
                                        (
                                                PropertyResolverFactory
                                                        .pluginPropertyPrefix(
                                                                provider.getService(),
                                                                provider.getName()
                                                        )
                                        ) ;
                        dbuilder.mapping(propName, projectPropertyPrefix + propName);

                        final String frameworkPropertyPrefix =
                                PropertyResolverFactory.frameworkPropertyPrefix
                                        (
                                                PropertyResolverFactory
                                                        .pluginPropertyPrefix(
                                                                provider.getService(),
                                                                provider.getName()
                                                        )
                                        );

                        dbuilder.frameworkMapping(propName, frameworkPropertyPrefix + propName);
                    }
                    //rendering options
                    final Object renderingOpts = itemmeta.get(CONFIG_RENDERING_OPTIONS);
                    if(null != renderingOpts && renderingOpts instanceof Map){
                        Map<String,Object> renderingOptsMap=(Map<String,Object>) renderingOpts;
                        pbuild.renderingOptions(renderingOptsMap);
                    }

                    try {
                        dbuilder.property(pbuild.build());
                    } catch (IllegalStateException e) {
                        throw new ConfigurationException(e.getMessage());
                    }

                }
View Full Code Here

TOP

Related Classes of com.dtolabs.rundeck.plugins.util.PropertyBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.