Search in sources :

Example 1 with HttpMethod

use of com.robotoworks.mechanoid.net.netModel.HttpMethod in project mechanoid by robotoworks.

the class NetModelGenerator method _generate.

protected void _generate(final Client client, final Model model, final IFileSystemAccess fsa) {
    String _packageName = model.getPackageName();
    String _name = client.getName();
    String _plus = ("Abstract" + _name);
    String _resolveFileName = Strings.resolveFileName(_packageName, _plus);
    ClientGenerator _get = this.mClientGenerator.get();
    CharSequence _generate = _get.generate(client, model);
    fsa.generateFile(_resolveFileName, _generate);
    String _packageName_1 = model.getPackageName();
    String _name_1 = client.getName();
    String _resolveFileName_1 = Strings.resolveFileName(_packageName_1, _name_1);
    ClientGenerator _get_1 = this.mClientGenerator.get();
    CharSequence _generateStub = _get_1.generateStub(client, model);
    fsa.generateFile(_resolveFileName_1, MechanoidOutputConfigurationProvider.DEFAULT_STUB_OUTPUT, _generateStub);
    String _packageName_2 = model.getPackageName();
    String _name_2 = client.getName();
    String _pascalize = Strings.pascalize(_name_2);
    String _concat = _pascalize.concat("ReaderProvider");
    String _plus_1 = ("Default" + _concat);
    String _resolveFileName_2 = Strings.resolveFileName(_packageName_2, _plus_1);
    EntityReaderProviderGenerator _get_2 = this.mEntityReaderProviderGenerator.get();
    CharSequence _generate_1 = _get_2.generate(client, model);
    fsa.generateFile(_resolveFileName_2, _generate_1);
    String _packageName_3 = model.getPackageName();
    String _name_3 = client.getName();
    String _pascalize_1 = Strings.pascalize(_name_3);
    String _concat_1 = _pascalize_1.concat("WriterProvider");
    String _plus_2 = ("Default" + _concat_1);
    String _resolveFileName_3 = Strings.resolveFileName(_packageName_3, _plus_2);
    EntityWriterProviderGenerator _get_3 = this.mEntityWriterProviderGenerator.get();
    CharSequence _generate_2 = _get_3.generate(client, model);
    fsa.generateFile(_resolveFileName_3, _generate_2);
    EList<ClientBlock> _blocks = client.getBlocks();
    Iterable<HttpMethod> _filter = Iterables.<HttpMethod>filter(_blocks, HttpMethod.class);
    final Consumer<HttpMethod> _function = new Consumer<HttpMethod>() {

        public void accept(final HttpMethod method) {
            String _packageName = model.getPackageName();
            String _name = method.getName();
            String _pascalize = Strings.pascalize(_name);
            String _concat = _pascalize.concat("Request");
            String _resolveFileName = Strings.resolveFileName(_packageName, _concat);
            RequestGenerator _get = NetModelGenerator.this.mRequestGenerator.get();
            CharSequence _generate = _get.generate(method, model, client);
            fsa.generateFile(_resolveFileName, _generate);
            String _packageName_1 = model.getPackageName();
            String _name_1 = method.getName();
            String _pascalize_1 = Strings.pascalize(_name_1);
            String _concat_1 = _pascalize_1.concat("Result");
            String _resolveFileName_1 = Strings.resolveFileName(_packageName_1, _concat_1);
            ResultGenerator _get_1 = NetModelGenerator.this.mResultGenerator.get();
            CharSequence _generate_1 = _get_1.generate(method, model, client);
            fsa.generateFile(_resolveFileName_1, _generate_1);
        }
    };
    _filter.forEach(_function);
}
Also used : ClientGenerator(com.robotoworks.mechanoid.net.generator.ClientGenerator) EntityReaderProviderGenerator(com.robotoworks.mechanoid.net.generator.EntityReaderProviderGenerator) EntityWriterProviderGenerator(com.robotoworks.mechanoid.net.generator.EntityWriterProviderGenerator) ClientBlock(com.robotoworks.mechanoid.net.netModel.ClientBlock) ResultGenerator(com.robotoworks.mechanoid.net.generator.ResultGenerator) Consumer(java.util.function.Consumer) RequestGenerator(com.robotoworks.mechanoid.net.generator.RequestGenerator) HttpMethod(com.robotoworks.mechanoid.net.netModel.HttpMethod)

Example 2 with HttpMethod

use of com.robotoworks.mechanoid.net.netModel.HttpMethod in project mechanoid by robotoworks.

the class ClientGenerator method generateClientMethods.

public CharSequence generateClientMethods(final Client client, final Model model) {
    StringConcatenation _builder = new StringConcatenation();
    {
        EList<ClientBlock> _blocks = client.getBlocks();
        Iterable<HttpMethod> _filter = Iterables.<HttpMethod>filter(_blocks, HttpMethod.class);
        for (final HttpMethod method : _filter) {
            {
                boolean _and = false;
                boolean _hasBody = ModelExtensions.hasBody(method);
                boolean _not = (!_hasBody);
                if (!_not) {
                    _and = false;
                } else {
                    boolean _or = false;
                    Path _path = method.getPath();
                    boolean _equals = Objects.equal(_path, null);
                    if (_equals) {
                        _or = true;
                    } else {
                        Path _path_1 = method.getPath();
                        EList<SimpleMemberAssignment> _params = _path_1.getParams();
                        int _size = _params.size();
                        boolean _equals_1 = (_size == 0);
                        _or = _equals_1;
                    }
                    _and = _or;
                }
                if (_and) {
                    _builder.append("public Response<");
                    String _name = method.getName();
                    String _pascalize = Strings.pascalize(_name);
                    _builder.append(_pascalize, "");
                    _builder.append("Result> ");
                    String _name_1 = method.getName();
                    String _camelize = Strings.camelize(_name_1);
                    _builder.append(_camelize, "");
                    _builder.append("()");
                    _builder.newLineIfNotEmpty();
                    _builder.append("  ");
                    _builder.append("throws ServiceException {");
                    _builder.newLine();
                    _builder.append("  \t");
                    _builder.append("return ");
                    String _name_2 = method.getName();
                    String _camelize_1 = Strings.camelize(_name_2);
                    _builder.append(_camelize_1, "  \t");
                    _builder.append("(new ");
                    String _name_3 = method.getName();
                    String _pascalize_1 = Strings.pascalize(_name_3);
                    _builder.append(_pascalize_1, "  \t");
                    _builder.append("Request());");
                    _builder.newLineIfNotEmpty();
                    _builder.append("}");
                    _builder.newLine();
                    _builder.newLine();
                }
            }
            _builder.append("public Response<");
            String _name_4 = method.getName();
            String _pascalize_2 = Strings.pascalize(_name_4);
            _builder.append(_pascalize_2, "");
            _builder.append("Result> ");
            String _name_5 = method.getName();
            String _camelize_2 = Strings.camelize(_name_5);
            _builder.append(_camelize_2, "");
            _builder.append("(");
            String _name_6 = method.getName();
            String _pascalize_3 = Strings.pascalize(_name_6);
            _builder.append(_pascalize_3, "");
            _builder.append("Request request)");
            _builder.newLineIfNotEmpty();
            _builder.append("  ");
            _builder.append("throws ServiceException {");
            _builder.newLine();
            _builder.append("  \t");
            ParamsBlock params = ModelExtensions.getParamsBlock(client);
            _builder.newLineIfNotEmpty();
            {
                boolean _notEquals = (!Objects.equal(params, null));
                if (_notEquals) {
                    {
                        EList<SimpleMemberAssignment> _params_1 = params.getParams();
                        for (final SimpleMemberAssignment param : _params_1) {
                            _builder.append("\t");
                            _builder.append("if(this.");
                            SimpleMember _member = param.getMember();
                            String _name_7 = _member.getName();
                            String _camelize_3 = Strings.camelize(_name_7);
                            _builder.append(_camelize_3, "\t");
                            _builder.append("ParamSet && !request.is");
                            SimpleMember _member_1 = param.getMember();
                            String _name_8 = _member_1.getName();
                            String _pascalize_4 = Strings.pascalize(_name_8);
                            _builder.append(_pascalize_4, "\t");
                            _builder.append("ParamSet()){");
                            _builder.newLineIfNotEmpty();
                            _builder.append("\t");
                            _builder.append("\t");
                            _builder.append("request.set");
                            SimpleMember _member_2 = param.getMember();
                            String _name_9 = _member_2.getName();
                            String _pascalize_5 = Strings.pascalize(_name_9);
                            _builder.append(_pascalize_5, "\t\t");
                            _builder.append("Param(this.");
                            SimpleMember _member_3 = param.getMember();
                            String _name_10 = _member_3.getName();
                            String _camelize_4 = Strings.camelize(_name_10);
                            _builder.append(_camelize_4, "\t\t");
                            _builder.append("Param);");
                            _builder.newLineIfNotEmpty();
                            _builder.append("\t");
                            _builder.append("}");
                            _builder.newLine();
                        }
                    }
                    _builder.append("\t");
                    _builder.newLine();
                }
            }
            _builder.append("\t");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("Parser<");
            String _name_11 = method.getName();
            String _pascalize_6 = Strings.pascalize(_name_11);
            _builder.append(_pascalize_6, "\t");
            _builder.append("Result> parser = new Parser<");
            String _name_12 = method.getName();
            String _pascalize_7 = Strings.pascalize(_name_12);
            _builder.append(_pascalize_7, "\t");
            _builder.append("Result>() {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("public ");
            String _name_13 = method.getName();
            String _pascalize_8 = Strings.pascalize(_name_13);
            _builder.append(_pascalize_8, "\t\t");
            _builder.append("Result parse(InputStream inStream) throws IOException {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t\t");
            _builder.append("return new ");
            String _name_14 = method.getName();
            String _pascalize_9 = Strings.pascalize(_name_14);
            _builder.append(_pascalize_9, "\t\t\t");
            _builder.append("Result(getReaderProvider(), inStream);");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("};");
            _builder.newLine();
            _builder.append("\t");
            _builder.newLine();
            _builder.append("\t");
            CharSequence _generateServiceMethod = this.generateServiceMethod(method);
            _builder.append(_generateServiceMethod, "\t");
            _builder.newLineIfNotEmpty();
            _builder.append("}");
            _builder.newLine();
            _builder.newLine();
        }
    }
    return _builder;
}
Also used : Path(com.robotoworks.mechanoid.net.netModel.Path) EList(org.eclipse.emf.common.util.EList) SimpleMemberAssignment(com.robotoworks.mechanoid.net.netModel.SimpleMemberAssignment) ParamsBlock(com.robotoworks.mechanoid.net.netModel.ParamsBlock) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) SimpleMember(com.robotoworks.mechanoid.net.netModel.SimpleMember) HttpMethod(com.robotoworks.mechanoid.net.netModel.HttpMethod)

Aggregations

HttpMethod (com.robotoworks.mechanoid.net.netModel.HttpMethod)2 ClientGenerator (com.robotoworks.mechanoid.net.generator.ClientGenerator)1 EntityReaderProviderGenerator (com.robotoworks.mechanoid.net.generator.EntityReaderProviderGenerator)1 EntityWriterProviderGenerator (com.robotoworks.mechanoid.net.generator.EntityWriterProviderGenerator)1 RequestGenerator (com.robotoworks.mechanoid.net.generator.RequestGenerator)1 ResultGenerator (com.robotoworks.mechanoid.net.generator.ResultGenerator)1 ClientBlock (com.robotoworks.mechanoid.net.netModel.ClientBlock)1 ParamsBlock (com.robotoworks.mechanoid.net.netModel.ParamsBlock)1 Path (com.robotoworks.mechanoid.net.netModel.Path)1 SimpleMember (com.robotoworks.mechanoid.net.netModel.SimpleMember)1 SimpleMemberAssignment (com.robotoworks.mechanoid.net.netModel.SimpleMemberAssignment)1 Consumer (java.util.function.Consumer)1 EList (org.eclipse.emf.common.util.EList)1 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)1