class Blufin::YmlJavaSdkWriter

Constants

PLACEHOLDER_BASE_IMPORT
PLACEHOLDER_CONTENT
PLACEHOLDER_END_POINT
PLACEHOLDER_ENUM
PLACEHOLDER_OVERRIDE
PLACEHOLDER_OVERRIDE_TOP
PLACEHOLDER_SERVICE
PLACEHOLDER_SERVICE_GETTERS
PLACEHOLDER_SITE_DOMAIN
PLACEHOLDER_SITE_NAME
PLACEHOLDER_SITE_NAME_CAMEL_CASED
SERVICE_INTERNAL

Public Class Methods

new(site, schema_data, schema_resources) click to toggle source

Initialize the class. @return void

# File lib/core/yml_writers/yml_java_sdk_writer.rb, line 21
        def initialize(site, schema_data, schema_resources)

            @schema_data      = schema_data
            @schema_resources = schema_resources

            raise RuntimeError, 'Could not find valid @schema_data.' if @schema_data.nil? || !@schema_data.is_a?(Hash)
            raise RuntimeError, 'Could not find valid @schema_resources.' if @schema_resources.nil? || !@schema_resources.is_a?(Hash)

            @site                  = Blufin::SiteResolver::validate_site(site)
            @site_name             = Blufin::SiteResolver::get_site_name(@site)
            @site_name_camel_cased = Blufin::SiteResolver::get_site_name_camel_cased(@site)
            @site_domain           = Blufin::SiteResolver::get_site_domain(@site)
            @site_domain_gsub      = @site_domain.strip == '' ? '' : "#{@site_domain}."
            @site_location         = "#{Blufin::SiteResolver::get_site_location(@site)}/"

            @path_base    = "#{get_java_path(@site, nil, SERVICE_INTERNAL, 'base')}"
            @path_service = "#{get_java_path(@site, nil, SERVICE_INTERNAL, 'service')}"

            @embedded_data    = Blufin::SiteEmbedded::get_data
            @embedded_path    = "#{Blufin::Config::get_path('Paths', 'BlufinJava')}/#{Blufin::ScannerJavaEmbeddedObjects::PATH_TO_EMBEDDED}"
            @embedded_package = 'org.blufin.sdk.embedded'
            @embedded_objects = Blufin::SiteAuth::AUTHENTICATION_LEVELS[Blufin::SiteAuth::get_auth_level]

            @base_import_schemas = []

            @auth_level       = Blufin::SiteAuth::get_auth_level

            # Wipe out all previous sdk.base files.
            paths_to_wipe_out = [@path_base]
            paths_to_wipe_out.each do |path_to_wipe_out|
                if Blufin::Files::path_exists(path_to_wipe_out)
                    if Blufin::Files::get_files_in_dir(path_to_wipe_out).any?
                        Blufin::Terminal::command('rm *', path_to_wipe_out, false, false)
                    end
                end
            end

            # Wipe out all previous sdk.service.{schema} files.
            Blufin::YmlSchemaValidator::VALID_SCHEMAS_GENERATE.each do |schema|
                paths_to_wipe_out = %W(
                #{get_java_path(@site, schema, SERVICE_INTERNAL, 'client')}
                #{get_java_path(@site, schema, SERVICE_INTERNAL, 'field')}
                #{get_java_path(@site, schema, SERVICE_INTERNAL, 'filter')}
                #{get_java_path(@site, schema, SERVICE_INTERNAL, 'refiner')}
                #{get_java_path(@site, schema, SERVICE_INTERNAL, 'service')}
                #{get_java_path(@site, schema, SERVICE_INTERNAL, 'sort')}
                )
                paths_to_wipe_out.each do |path_to_wipe_out|
                    if Blufin::Files::path_exists(path_to_wipe_out)
                        if Blufin::Files::get_files_in_dir(path_to_wipe_out).any?
                            Blufin::Terminal::command('rm *', path_to_wipe_out, false, false)
                        end
                    end
                end
            end

            @template_base = <<TEMPLATE
package #{PLACEHOLDER_PACKAGE};

import org.blufin.sdk.base.ResourceData;
import org.blufin.sdk.service.BlufinApiService;
import org.blufin.sdk.service.credentials.ApiCredentialsHttp;
import org.blufin.sdk.service.credentials.ApiCredentialsInternal;
import org.springframework.stereotype.Service;
#{PLACEHOLDER_BASE_IMPORT}
@Service
public class #{PLACEHOLDER_CLASS} extends BlufinApiService {

    public void initialize(ResourceData resourceLocator) {

        initializeParent(new ApiCredentialsInternal(resourceLocator));
    }

    public void initialize(String authorizationHeader, String apiUri) {

        initializeParent(new ApiCredentialsHttp(authorizationHeader, apiUri));
    }
#{PLACEHOLDER_SERVICE_GETTERS}}
TEMPLATE

            @template_service_getter = <<TEMPLATE

    public #{PLACEHOLDER_SERVICE}Service get#{PLACEHOLDER_SERVICE}Service() {

        return new #{PLACEHOLDER_SERVICE}Service(getApiCredentials());
    }
TEMPLATE

            @template_service_outer = <<TEMPLATE
package #{PLACEHOLDER_PACKAGE};

import org.blufin.sdk.base.AbstractService;
import org.blufin.base.helper.IdSet;
import org.blufin.sdk.service.credentials.ApiCredentials;#{PLACEHOLDER_IMPORT}
import org.blufin.sdk.request.IdSetGetRequest;
import org.blufin.sdk.request.PaginatedGetRequest;
import #{PLACEHOLDER_SITE_DOMAIN}#{PLACEHOLDER_SITE_NAME}.sdk.dto.#{PLACEHOLDER_SERVICE};
import #{PLACEHOLDER_SITE_DOMAIN}#{PLACEHOLDER_SITE_NAME}.sdk.field.#{PLACEHOLDER_SERVICE}Field;
import #{PLACEHOLDER_SITE_DOMAIN}#{PLACEHOLDER_SITE_NAME}.sdk.metadata.#{PLACEHOLDER_SERVICE}MetaData;
import #{PLACEHOLDER_SITE_DOMAIN}#{PLACEHOLDER_SITE_NAME}.sdk.refiner.#{PLACEHOLDER_SERVICE}Refiner;
import #{PLACEHOLDER_SITE_DOMAIN}#{PLACEHOLDER_SITE_NAME}.sdk.sort.#{PLACEHOLDER_SERVICE}Sort;

public class #{PLACEHOLDER_CLASS} implements AbstractService {

    private final ApiCredentials apiCredentials;

    public #{PLACEHOLDER_CLASS}(ApiCredentials apiCredentials) {

        this.apiCredentials = apiCredentials;
    }

#{PLACEHOLDER_CONTENT}}
TEMPLATE

            @template_service = <<TEMPLATE
#{PLACEHOLDER_OVERRIDE_TOP}public PaginatedGetRequest<#{PLACEHOLDER_SERVICE}, #{PLACEHOLDER_SERVICE}Field, #{PLACEHOLDER_SERVICE}Sort, #{PLACEHOLDER_SERVICE}Refiner> get() {

        return new PaginatedGetRequest<>(apiCredentials, "#{PLACEHOLDER_END_POINT}", #{PLACEHOLDER_SERVICE}.class, #{PLACEHOLDER_SERVICE}MetaData.getInstance(), #{PLACEHOLDER_SERVICE}Refiner.class);
    }

    #{PLACEHOLDER_OVERRIDE}public IdSetGetRequest<#{PLACEHOLDER_SERVICE}, #{PLACEHOLDER_SERVICE}Field, #{PLACEHOLDER_SERVICE}Sort> get(IdSet idSet) {

        return new IdSetGetRequest<>(apiCredentials, "#{PLACEHOLDER_END_POINT}", #{PLACEHOLDER_SERVICE}.class, #{PLACEHOLDER_SERVICE}MetaData.getInstance(), idSet);
    }

    #{PLACEHOLDER_OVERRIDE}public IdSetGetRequest<#{PLACEHOLDER_SERVICE}, #{PLACEHOLDER_SERVICE}Field, #{PLACEHOLDER_SERVICE}Sort> get(int id) {

        return new IdSetGetRequest<>(apiCredentials, "#{PLACEHOLDER_END_POINT}", #{PLACEHOLDER_SERVICE}.class, #{PLACEHOLDER_SERVICE}MetaData.getInstance(), new IdSet(id));
    }
TEMPLATE

            @template_service_account = <<TEMPLATE
#{PLACEHOLDER_OVERRIDE_TOP}public AccountRequest<PaginatedGetRequest<#{PLACEHOLDER_SERVICE}, #{PLACEHOLDER_SERVICE}Field, #{PLACEHOLDER_SERVICE}Sort, #{PLACEHOLDER_SERVICE}Refiner>> get() {

        return new AccountRequest<>(apiCredentials, "#{PLACEHOLDER_END_POINT}", #{PLACEHOLDER_SERVICE}.class, #{PLACEHOLDER_SERVICE}MetaData.getInstance(), #{PLACEHOLDER_SERVICE}Refiner.class);
    }

    #{PLACEHOLDER_OVERRIDE}public AccountRequest<IdSetGetRequest<#{PLACEHOLDER_SERVICE}, #{PLACEHOLDER_SERVICE}Field, #{PLACEHOLDER_SERVICE}Sort>> get(IdSet idSet) {

        return new AccountRequest<>(apiCredentials, "#{PLACEHOLDER_END_POINT}", #{PLACEHOLDER_SERVICE}.class, #{PLACEHOLDER_SERVICE}MetaData.getInstance(), idSet);
    }

    #{PLACEHOLDER_OVERRIDE}public AccountRequest<IdSetGetRequest<#{PLACEHOLDER_SERVICE}, #{PLACEHOLDER_SERVICE}Field, #{PLACEHOLDER_SERVICE}Sort>> get(int id) {

        return new AccountRequest<>(apiCredentials, "#{PLACEHOLDER_END_POINT}", #{PLACEHOLDER_SERVICE}.class, #{PLACEHOLDER_SERVICE}MetaData.getInstance(), new IdSet(id));
    }
TEMPLATE

            @template_service_account_user = <<TEMPLATE
#{PLACEHOLDER_OVERRIDE_TOP}public AccountUserRequest<PaginatedGetRequest<#{PLACEHOLDER_SERVICE}, #{PLACEHOLDER_SERVICE}Field, #{PLACEHOLDER_SERVICE}Sort, #{PLACEHOLDER_SERVICE}Refiner>> get() {

        return new AccountUserRequest<>(apiCredentials, "#{PLACEHOLDER_END_POINT}", #{PLACEHOLDER_SERVICE}.class, #{PLACEHOLDER_SERVICE}MetaData.getInstance(), #{PLACEHOLDER_SERVICE}Refiner.class);
    }

    #{PLACEHOLDER_OVERRIDE}public AccountUserRequest<IdSetGetRequest<#{PLACEHOLDER_SERVICE}, #{PLACEHOLDER_SERVICE}Field, #{PLACEHOLDER_SERVICE}Sort>> get(IdSet idSet) {

        return new AccountUserRequest<>(apiCredentials, "#{PLACEHOLDER_END_POINT}", #{PLACEHOLDER_SERVICE}.class, #{PLACEHOLDER_SERVICE}MetaData.getInstance(), idSet);
    }

    #{PLACEHOLDER_OVERRIDE}public AccountUserRequest<IdSetGetRequest<#{PLACEHOLDER_SERVICE}, #{PLACEHOLDER_SERVICE}Field, #{PLACEHOLDER_SERVICE}Sort>> get(int id) {

        return new AccountUserRequest<>(apiCredentials, "#{PLACEHOLDER_END_POINT}", #{PLACEHOLDER_SERVICE}.class, #{PLACEHOLDER_SERVICE}MetaData.getInstance(), new IdSet(id));
    }
TEMPLATE

            @template_field = <<TEMPLATE
package #{PLACEHOLDER_PACKAGE};

import org.blufin.sdk.base.AbstractField;

public enum #{PLACEHOLDER_CLASS} implements AbstractField {
#{PLACEHOLDER_CONTENT}

    private final String fieldName;

    #{PLACEHOLDER_CLASS}(String fieldName) {

        this.fieldName = fieldName;
    }

    @Override
    public String getFieldName() {

        return fieldName;
    }
}
TEMPLATE

            @template_filter = <<TEMPLATE
package #{PLACEHOLDER_PACKAGE};

import org.blufin.sdk.base.AbstractFilter;

public enum #{PLACEHOLDER_CLASS} implements AbstractFilter {
#{PLACEHOLDER_CONTENT}

    private final String fieldName;

    #{PLACEHOLDER_CLASS}(String fieldName) {

        this.fieldName = fieldName;
    }

    @Override
    public String getFieldName() {

        return fieldName;
    }
}
TEMPLATE

            @template_sort = <<TEMPLATE
package #{PLACEHOLDER_PACKAGE};

import org.blufin.sdk.base.AbstractSort;

public enum #{PLACEHOLDER_CLASS} implements AbstractSort {
#{PLACEHOLDER_CONTENT}

    private final String fieldName;

    #{PLACEHOLDER_CLASS}(String fieldName) {

        this.fieldName = fieldName;
    }

    @Override
    public String getFieldName() {

        return fieldName;
    }

    @Override
    public String toString() {

        return this.name();
    }
}
TEMPLATE

            @template_refiner = <<TEMPLATE
package #{PLACEHOLDER_PACKAGE};

import org.blufin.base.annotations.NestedRefiner;
import org.blufin.sdk.base.AbstractRefiner;
import org.blufin.sdk.base.Refiner;
import org.blufin.sdk.filters.dynamic.*;
import org.blufin.sdk.request.PaginatedGetRequest;
import org.blufin.sdk.filters.Filter;
import #{PLACEHOLDER_SITE_DOMAIN}#{PLACEHOLDER_SITE_NAME}.sdk.dto.#{PLACEHOLDER_SERVICE};
import #{PLACEHOLDER_SITE_DOMAIN}#{PLACEHOLDER_SITE_NAME}.sdk.field.#{PLACEHOLDER_SERVICE}Field;
import #{PLACEHOLDER_SITE_DOMAIN}#{PLACEHOLDER_SITE_NAME}.sdk.filter.#{PLACEHOLDER_SERVICE}Filter;
import #{PLACEHOLDER_SITE_DOMAIN}#{PLACEHOLDER_SITE_NAME}.sdk.sort.#{PLACEHOLDER_SERVICE}Sort;#{PLACEHOLDER_BASE_IMPORT}
import java.util.List;

public class #{PLACEHOLDER_CLASS} extends Refiner<PaginatedGetRequest<#{PLACEHOLDER_SERVICE}, #{PLACEHOLDER_SERVICE}Field, #{PLACEHOLDER_SERVICE}Sort, #{PLACEHOLDER_SERVICE}Refiner>> implements AbstractRefiner {

    public #{PLACEHOLDER_SERVICE}Refiner(List<Filter> filters, PaginatedGetRequest<#{PLACEHOLDER_SERVICE}, #{PLACEHOLDER_SERVICE}Field, #{PLACEHOLDER_SERVICE}Sort, #{PLACEHOLDER_SERVICE}Refiner> originalRequest) {

        super(filters, originalRequest);
    }
#{PLACEHOLDER_CONTENT}}
TEMPLATE

        end

Public Instance Methods

write() click to toggle source

Write the file(s). @return void

# File lib/core/yml_writers/yml_java_sdk_writer.rb, line 289
def write

    write_service
    write_meta
    write_base

end

Private Instance Methods

get_refiner_content(schema, table, nest_level = 1) click to toggle source

Gets refiner content as a Hash of Arrays. @return string

# File lib/core/yml_writers/yml_java_sdk_writer.rb, line 537
def get_refiner_content(schema, table, nest_level = 1)

    content_data   = []
    content_import = []

    field_data = @schema_data[schema][table]
    field_data.keys.each do |key|

        field_to_match   = key.include?('.') ? key.split('.')[1] : key
        filterable_extra = nil

        # If this is a LINK field, skip.
        # TODO - 12/15/18 - Probably need to make changes here when we need to support Linked objects.
        next if key =~ /\A(#{Blufin::YmlSchemaValidator::VALID_SCHEMAS_REGEX})\.[a-z_]+\[link\]\z/

        # If this is a nested SINGLE/MULTIPLE, handle it.
        if key =~ /\A(#{Blufin::YmlSchemaValidator::VALID_SCHEMAS_REGEX})\.[a-z_]+\z/ || key =~ /\A(#{Blufin::YmlSchemaValidator::VALID_SCHEMAS_REGEX})\.[a-z_]+\[\]\z/
            key_split = key.gsub(/\[\]$/, '').split('.')
            content_data << ["#{nest_level + 1}.#{schema}.#{key_split[1]}"]
            get_refiner_content(schema, key_split[1], nest_level + 1)
            next
        end

        # If this field is ENCRYPTED, skip.
        next if @schema_data[schema][table][key].has_key?(Blufin::YmlSchemaValidator::ENCRYPTED)

        @type = @schema_data[schema][table][key][Blufin::YmlSchemaValidator::TYPE]

        # Skip Transient Objects.
        next if [Blufin::ScannerJavaEmbeddedObjects::OBJECT].include?(@type)

        enum_class = nil

        begin
            overridden = @embedded_data[table][:data].keys.include?(key)
            @content_data_import << 'import org.blufin.base.annotations.Embedded;'
        rescue
            overridden = false
        end

        if @type == Blufin::YmlSchemaValidator::TYPE_BOOLEAN
            filter = 'FilterBoolean'
        elsif @type == Blufin::YmlSchemaValidator::TYPE_DATE
            # Must come BEFORE ..DATETIME_TYPES.include?(@type) because the latter included DATE as well.
            filter = 'FilterDate'
        elsif Blufin::YmlSchemaValidator::DATETIME_TYPES.include?(@type)
            filter = 'FilterDateTime'
        elsif @type =~ Blufin::YmlSchemaValidator::REGEX_DECIMAL
            filter = 'FilterDecimal'
        elsif @type == Blufin::YmlSchemaValidator::TYPE_INT_BIG
            filter = 'FilterIntegerBig'
        elsif @type == Blufin::YmlSchemaValidator::TYPE_INT_TINY
            filter = 'FilterIntegerTiny'
        elsif @type == Blufin::YmlSchemaValidator::TYPE_INT_SMALL
            filter = 'FilterIntegerSmall'
        elsif Blufin::YmlSchemaValidator::INT_TYPES.include?(@type)
            filter = 'FilterInteger'
        elsif @type == Blufin::YmlSchemaValidator::TYPE_TEXT
            filter = 'FilterText'
        elsif @type == Blufin::YmlSchemaValidator::TYPE_TEXT_LONG
            filter = 'FilterTextLong'
        elsif @type =~ Blufin::YmlSchemaValidator::REGEX_ENUM || @type =~ Blufin::YmlSchemaValidator::REGEX_ENUM_CUSTOM || @type =~ Blufin::YmlSchemaValidator::REGEX_ENUM_SYSTEM
            filter = 'FilterEnum'
            if @type =~ Blufin::YmlSchemaValidator::REGEX_ENUM
                enum_class  = "#{Blufin::Strings::snake_case_to_camel_case(table)}#{Blufin::Strings::snake_case_to_camel_case(key)}"
                enum_import = "import #{@site_domain_gsub}#{@site_name.gsub('-', '.')}.sdk.enums.#{PLACEHOLDER_ENUM};"
            elsif @type =~ Blufin::YmlSchemaValidator::REGEX_ENUM_CUSTOM

                # TODO - Need to fix this. Enums need to be handled in a way that they resolve to a package/path (not something hard-coded).

                enum_class  = Blufin::YmlCommon::enum_name_extractor(@type)
                enum_import = "import #{@site_domain_gsub}#{@site_name.gsub('-', '.')}.sdk.enums.#{PLACEHOLDER_ENUM};"
            elsif @type =~ Blufin::YmlSchemaValidator::REGEX_ENUM_SYSTEM
                enum_class  = Blufin::YmlCommon::enum_name_extractor(@type)
                enum_import = "import #{Blufin::SiteServices::PACKAGE_SYSTEM_ENUMS}.#{PLACEHOLDER_ENUM};"
            else
                raise RuntimeError, "'enum_string' doesn't match regex --> #{@type}"
            end
            enum_class       = enum_class.slice(0, 1).upcase + enum_class.slice(1..-1)
            filterable_extra = ", #{enum_class}"
            @content_data_import << enum_import.gsub(PLACEHOLDER_ENUM, enum_class)
            enum_class = ", #{enum_class}"
        elsif @type =~ Blufin::YmlSchemaValidator::REGEX_VARCHAR
            filter = 'FilterVarchar'
        else
            raise RuntimeError, "Unrecognized type in #{__FILE__} or field: #{key} \xe2\x86\x92 #{@type}"
        end

        key_cleaned = Blufin::YmlCommon::extract_field_name(key)

        content_data << [filter, Blufin::Strings::snake_case_to_camel_case_lower(key_cleaned), key_cleaned.upcase, filterable_extra, overridden]

    end

    @content_data_master["#{nest_level}.#{schema}.#{table}"] = content_data

end
write_base() click to toggle source

Writes the Base Service -> IE: SkyButlerService. @return void

# File lib/core/yml_writers/yml_java_sdk_writer.rb, line 688
def write_base

    class_name = "#{@site_name_camel_cased}SDK"

    contents = @template_base
    contents = contents.gsub(PLACEHOLDER_PACKAGE, get_package(@site, nil, 'base', SERVICE_INTERNAL))
    contents = contents.gsub(PLACEHOLDER_CLASS, class_name)
    contents = contents.gsub(PLACEHOLDER_SITE_NAME, @site_name.gsub('-', '.'))
    contents = contents.gsub(PLACEHOLDER_SITE_NAME_CAMEL_CASED, @site_name_camel_cased)
    contents = contents.gsub(PLACEHOLDER_SITE_DOMAIN, @site_domain_gsub)

    service_names   = []
    service_getters = ''

    @schema_resources.each do |data|

        # This filters out the "mock" schema used for testing.
        next if data[0].split('.')[0] == Blufin::YmlSchemaValidator::MOCK

        data            = data[1]
        service_name    = Blufin::Strings::snake_case_to_camel_case(data[:table])
        service_getters += @template_service_getter.gsub(PLACEHOLDER_SERVICE, service_name)

        # Technically this will never be reached, but if it does we know there's and issue where we have a service name conflict that needs to be validated for.
        # A conflict could be: app.sale_ebay.inventory AND common.sale.ebay_inventory.
        # This will probably never happen though so I won't waste time now (10/6/16) writing validation for this.
        raise RuntimeError, "Duplicated service name: #{service_name}" if service_names.include?(service_name)

        service_names << service_name
    end

    base_import_schemas = ''
    base_import_schemas += "import #{@site_domain_gsub}#{@site_name.gsub('-', '.')}.sdk.service.*;\n" if @base_import_schemas.any?

    contents = contents.gsub(PLACEHOLDER_BASE_IMPORT, base_import_schemas)
    contents = contents.gsub(PLACEHOLDER_SERVICE_GETTERS, service_getters)
    contents = contents.gsub(PLACEHOLDER_SITE_DOMAIN, @site_domain_gsub)

    write_file_java("#{@path_base}/#{class_name}.java", Blufin::YmlCommon::convert_string_to_line_array(contents))

end
write_field(data) click to toggle source

Write FIELD Classes. @return void

# File lib/core/yml_writers/yml_java_sdk_writer.rb, line 368
def write_field(data)

    content_data = []
    content      = "\n"
    package      = 'field'
    schema       = data[:schema]
    table        = data[:table]
    service      = Blufin::Strings::snake_case_to_camel_case(data[:table])
    class_name   = "#{service}Field"
    contents     = @template_field
    contents     = contents.gsub(PLACEHOLDER_PACKAGE, get_package(@site, schema, package, SERVICE_INTERNAL))
    contents     = contents.gsub(PLACEHOLDER_CLASS, class_name)
    field_data   = @schema_data[data[:schema]][data[:table]]

    field_data.keys.each do |key|
        next if key =~ /\A(#{Blufin::YmlSchemaValidator::VALID_SCHEMAS_REGEX})\.[a-z_]+\z/ || key =~ /\A(#{Blufin::YmlSchemaValidator::VALID_SCHEMAS_REGEX})\.[a-z_]+\[(link)?\]\z/
        content_data << [Blufin::YmlCommon::extract_field_name(key)]
    end

    content_data.each_with_index do |cd, idx|
        comma_or_not = (idx == (content_data.length - 1)) ? ';' : ",\n"
        content      += "    #{cd[0].upcase}(\"#{table}.#{cd[0]}\")#{comma_or_not}"
    end

    contents = contents.gsub(PLACEHOLDER_CONTENT, content)

    write_file_java("#{get_java_path(@site, schema, SERVICE_INTERNAL, package)}/#{class_name}.java", Blufin::YmlCommon::convert_string_to_line_array(contents), schema == Blufin::YmlSchemaValidator::MOCK)

end
write_filter(data) click to toggle source

Write FILTER Classes. @return void

# File lib/core/yml_writers/yml_java_sdk_writer.rb, line 400
def write_filter(data)

    content_data = []
    content      = "\n"
    package      = 'filter'
    schema       = data[:schema]
    table        = data[:table]
    service      = Blufin::Strings::snake_case_to_camel_case(data[:table])

    class_name = "#{service}Filter"

    contents = @template_filter
    contents = contents.gsub(PLACEHOLDER_PACKAGE, get_package(@site, schema, package, SERVICE_INTERNAL))
    contents = contents.gsub(PLACEHOLDER_CLASS, class_name)

    field_data = @schema_data[data[:schema]][data[:table]]
    field_data.each do |key, data|
        next if key =~ /\A(#{Blufin::YmlSchemaValidator::VALID_SCHEMAS_REGEX})\.[a-z_]+\z/ || key =~ /\A(#{Blufin::YmlSchemaValidator::VALID_SCHEMAS_REGEX})\.[a-z_]+\[(link)?\]\z/
        next if data.has_key?(Blufin::YmlSchemaValidator::ENCRYPTED)
        content_data << [Blufin::YmlCommon::extract_field_name(key)]
    end

    content_data.each_with_index do |cd, idx|
        comma_or_not = (idx == (content_data.length - 1)) ? ';' : ",\n"
        content      += "    #{cd[0].upcase}(\"#{table}.#{cd[0]}\")#{comma_or_not}"
    end

    contents = contents.gsub(PLACEHOLDER_CONTENT, content)

    write_file_java("#{get_java_path(@site, schema, SERVICE_INTERNAL, package)}/#{class_name}.java", Blufin::YmlCommon::convert_string_to_line_array(contents), schema == Blufin::YmlSchemaValidator::MOCK)

end
write_meta() click to toggle source

Writes all the Field, Refiner + Sort classes -> IE: SaleField, SaleRefiner, SaleSort @return void

# File lib/core/yml_writers/yml_java_sdk_writer.rb, line 351
def write_meta

    @schema_resources.each do |data|

        data = data[1]

        write_field(data)
        write_filter(data)
        write_sort(data)
        write_refiner(data)

    end

end
write_refiner(data) click to toggle source

Write REFINER Classes. @return void

# File lib/core/yml_writers/yml_java_sdk_writer.rb, line 473
        def write_refiner(data)

            @content             = "\n"
            @content_nested      = {}
            package              = 'refiner'
            schema               = data[:schema]
            table                = data[:table]
            service              = Blufin::Strings::snake_case_to_camel_case(data[:table])
            class_name           = "#{service}Refiner"
            full_file_path       = "#{get_java_path(@site, schema, SERVICE_INTERNAL, package)}/#{class_name}.java"
            @content_data_import = []
            @content_data_master = {}

            get_refiner_content(schema, table)

            # Sort Hash by keys (alphabetically).
            @content_data_master = Hash[@content_data_master.sort_by { |key, val| key }]
            @content_data_master.each do |first_key, content_data|
                write_refiner_content(first_key, content_data, service)
                break
            end

            contents = @template_refiner
            contents = contents.gsub(PLACEHOLDER_PACKAGE, get_package(@site, schema, package, SERVICE_INTERNAL))
            contents = contents.gsub(PLACEHOLDER_CLASS, class_name)

            base_import_statements = "\n"

            @content_data_import.uniq!
            @content_data_import.sort!
            @content_data_import.each { |content_import_statement| base_import_statements += "#{content_import_statement}\n" }

            @content_nested.each do |key, data|
                key_split  = key.split('.')
                nest_level = key_split[0]
                nc_cc      = Blufin::Strings::snake_case_to_camel_case(key_split[2])
                content    = <<CLASS
    @NestedRefiner
    public static class #{nc_cc}Refiner extends Refiner<PaginatedGetRequest<#{PLACEHOLDER_SERVICE}, #{PLACEHOLDER_SERVICE}Field, #{PLACEHOLDER_SERVICE}Sort, #{PLACEHOLDER_SERVICE}Refiner>> implements AbstractRefiner {

        public #{nc_cc}Refiner(List<Filter> filters, PaginatedGetRequest<#{PLACEHOLDER_SERVICE}, #{PLACEHOLDER_SERVICE}Field, #{PLACEHOLDER_SERVICE}Sort, #{PLACEHOLDER_SERVICE}Refiner> originalRequest) {

            super(filters, originalRequest);
        }

#{PLACEHOLDER_CONTENT}    }

CLASS
                content  = content.gsub(PLACEHOLDER_CONTENT, data.chomp)
                @content += content
            end

            contents = contents.gsub(PLACEHOLDER_CONTENT, @content.chomp)
            contents = contents.gsub(PLACEHOLDER_SERVICE, service)
            contents = contents.gsub(PLACEHOLDER_SITE_NAME, @site_name.gsub('-', '.'))
            contents = contents.gsub(PLACEHOLDER_SITE_DOMAIN, @site_domain_gsub)
            contents = contents.gsub(PLACEHOLDER_BASE_IMPORT, base_import_statements)

            write_file_java(full_file_path, Blufin::YmlCommon::convert_string_to_line_array(contents), schema == Blufin::YmlSchemaValidator::MOCK)

        end
write_refiner_content(content_key, content_data, service_inner, nest_level = 1) click to toggle source

Adds method data to @content & @content_nested Arrays. @return void

# File lib/core/yml_writers/yml_java_sdk_writer.rb, line 637
        def write_refiner_content(content_key, content_data, service_inner, nest_level = 1)

            nest_space = nest_level == 1 ? '    ' : '        '

            content_data.each do |cd|

                if cd.length == 1
                    cd_split = cd[0].split('.')
                    cd_cc    = Blufin::Strings::snake_case_to_camel_case(cd_split[2])
                    cd_ccl   = Blufin::Strings::snake_case_to_camel_case_lower(cd_split[2])
                    @content_data_import << "import #{@site_domain_gsub}#{@site_name.gsub('-', '.')}.sdk.filter.#{cd_cc}Filter;"
                    write_refiner_content(cd[0], @content_data_master[cd[0]], cd_cc, nest_level + 1)
                    content = <<METHOD
#{nest_space}public #{PLACEHOLDER_SERVICE}Refiner.#{cd_cc}Refiner #{cd_ccl}() {

#{nest_space}    return new #{PLACEHOLDER_SERVICE}Refiner.#{cd_cc}Refiner(getFilters(), getOriginalRequest());
#{nest_space}}

METHOD
                    if nest_level == 1
                        @content += content
                    else
                        @content_nested[content_key] = '' if @content_nested[cd].nil?
                        @content_nested[content_key] += content
                    end

                    next
                end

                content = ''
                content += "#{nest_space}#{Blufin::ScannerJavaEmbeddedObjects::EMBEDDED_ANNOTATION}\n" if cd[4]
                content += <<METHOD
#{nest_space}public #{cd[0]}<PaginatedGetRequest<#{PLACEHOLDER_SERVICE}, #{PLACEHOLDER_SERVICE}Field, #{PLACEHOLDER_SERVICE}Sort, #{PLACEHOLDER_SERVICE}Refiner>#{cd[3]}> #{cd[1]}() {

#{nest_space}    return new #{cd[0]}<>(#{service_inner}Filter.#{cd[2]}, getFilters(), getOriginalRequest());
#{nest_space}}

METHOD
                if nest_level == 1
                    @content += content
                else
                    @content_nested[content_key] = '' if @content_nested[content_key].nil?
                    @content_nested[content_key] += content
                end

            end

        end
write_service() click to toggle source

Writes all the Services -> IE: SaleService @return void

# File lib/core/yml_writers/yml_java_sdk_writer.rb, line 301
def write_service

    @schema_resources.each do |data|

        data              = data[1]
        schema            = data[:schema]
        table             = data[:table]
        service           = Blufin::Strings::snake_case_to_camel_case(data[:table])
        class_name        = "#{service}Service"
        class_auth        = Blufin::SiteAuth::get_auth_level_for_table(schema, table)
        import_statements = []
        contents          = @template_service_outer
        overridden        = @embedded_objects.include?(table)

        import_statements << 'import org.blufin.base.annotations.Embedded;' if overridden

        case class_auth
            when Blufin::SiteAuth::LEVEL_NONE
                contents_inner = @template_service
            when Blufin::SiteAuth::LEVEL_ACCOUNT
                import_statements << 'import org.blufin.sdk.request.type.AccountRequest;'
                contents_inner = @template_service_account
            when Blufin::SiteAuth::LEVEL_ACCOUNT_USER
                import_statements << 'import org.blufin.sdk.request.type.AccountUserRequest;'
                contents_inner = @template_service_account_user
            else
                raise RuntimeError, "Unrecognized AuthLevel for table: #{class_auth}"
        end

        contents = contents.gsub(PLACEHOLDER_CONTENT, contents_inner)
        contents = contents.gsub(PLACEHOLDER_PACKAGE, get_package(@site, nil, "service", SERVICE_INTERNAL))
        contents = contents.gsub(PLACEHOLDER_CLASS, class_name)
        contents = contents.gsub(PLACEHOLDER_SERVICE, service)
        contents = contents.gsub(PLACEHOLDER_END_POINT, data[:resource])
        contents = contents.gsub(PLACEHOLDER_OVERRIDE_TOP, overridden ? "    @Embedded\n    " : '    ')
        contents = contents.gsub(PLACEHOLDER_OVERRIDE, overridden ? "@Embedded\n    " : '')
        contents = contents.gsub(PLACEHOLDER_IMPORT, import_statements.any? ? "\n#{import_statements.join("\n")}" : '')
        contents = contents.gsub(PLACEHOLDER_SITE_NAME, @site_name.gsub('-', '.'))
        contents = contents.gsub(PLACEHOLDER_SITE_DOMAIN, @site_domain_gsub)

        write_file_java("#{@path_service}/#{class_name}.java", Blufin::YmlCommon::convert_string_to_line_array(contents), schema == Blufin::YmlSchemaValidator::MOCK)

        @base_import_schemas << schema unless @base_import_schemas.include?(schema) || schema == Blufin::YmlSchemaValidator::MOCK

    end

end
write_sort(data) click to toggle source

Write SORT Classes. @return void

# File lib/core/yml_writers/yml_java_sdk_writer.rb, line 435
def write_sort(data)

    content_data = []
    content      = "\n"
    package      = 'sort'
    table        = data[:table]
    schema       = data[:schema]
    service      = Blufin::Strings::snake_case_to_camel_case(data[:table])
    class_name   = "#{service}Sort"
    contents     = @template_sort
    contents     = contents.gsub(PLACEHOLDER_PACKAGE, get_package(@site, schema, package, SERVICE_INTERNAL))
    contents     = contents.gsub(PLACEHOLDER_CLASS, class_name)
    field_data   = @schema_data[data[:schema]][data[:table]]

    field_data.each_with_index do |(key, data_inner), idx|
        next if key =~ /\A(#{Blufin::YmlSchemaValidator::VALID_SCHEMAS_REGEX})\.[a-z_]+\z/ || key =~ /\A(#{Blufin::YmlSchemaValidator::VALID_SCHEMAS_REGEX})\.[a-z_]+\[(link)?\]\z/
        next if data_inner.has_key?(Blufin::YmlSchemaValidator::ENCRYPTED)
        next if [
            Blufin::YmlSchemaValidator::TYPE_BOOLEAN,
            Blufin::YmlSchemaValidator::TYPE_TEXT,
            Blufin::YmlSchemaValidator::TYPE_TEXT_LONG
        ].include?(data_inner['type'])
        content_data << [Blufin::YmlCommon::extract_field_name(key)]
    end

    content_data.each_with_index do |cd, idx|
        comma_or_not = (idx == (content_data.length - 1)) ? ';' : ",\n"
        content      += "    #{cd[0].upcase}(\"#{table}.#{cd[0]}\")#{comma_or_not}"
    end

    contents = contents.gsub(PLACEHOLDER_CONTENT, content)

    write_file_java("#{get_java_path(@site, schema, SERVICE_INTERNAL, package)}/#{class_name}.java", Blufin::YmlCommon::convert_string_to_line_array(contents), schema == Blufin::YmlSchemaValidator::MOCK)

end