Example #1
0
        public string PagingGroupedParameterTransformation(bool filterRequired = false)
        {
            var builder = new IndentedStringBuilder();

            if (IsPagingOperation)
            {
                string    invocation;
                MethodJva nextMethod = GetPagingNextMethodWithInvocation(out invocation);
                TransformPagingGroupedParameter(builder, nextMethod, filterRequired);
            }
            return(builder.ToString());
        }
Example #2
0
        public override string ResponseGeneration(bool filterRequired = false)
        {
            if (this.IsPagingOperation && !this.IsPagingNextOperation)
            {
                var builder = new IndentedStringBuilder();
                builder.AppendLine("{0} response = {1}Delegate(call.execute());",
                                   ReturnTypeJva.WireResponseTypeString, this.Name);

                string    invocation;
                MethodJva nextMethod = GetPagingNextMethodWithInvocation(out invocation);

                builder.AppendLine("PagedList<{0}> result = new PagedList<{0}>(response.body()) {{", ((SequenceType)ReturnType.Body).ElementType.Name)
                .Indent().AppendLine("@Override")
                .AppendLine("public Page<{0}> nextPage(String {1}) throws {2}, IOException {{",
                            ((SequenceType)ReturnType.Body).ElementType.Name,
                            nextMethod.Parameters.First(p => p.Name.ToString().StartsWith("next", StringComparison.OrdinalIgnoreCase)).Name,
                            OperationExceptionTypeString)
                .Indent();
                TransformPagingGroupedParameter(builder, nextMethod, filterRequired);
                builder.AppendLine("return {0}({1}).body();",
                                   invocation, filterRequired ? nextMethod.MethodDefaultParameterInvocation : nextMethod.MethodParameterInvocation)
                .Outdent().AppendLine("}")
                .Outdent().AppendLine("};");
                return(builder.ToString());
            }
            else if (this.IsPagingNonPollingOperation)
            {
                var returnTypeBody = ReturnType.Body as SequenceTypeJva;
                var builder        = new IndentedStringBuilder();
                builder.AppendLine("{0}<{1}<{2}>> response = {3}Delegate(call.execute());",
                                   ReturnTypeJva.ClientResponseType, returnTypeBody.PageImplType, returnTypeBody.ElementType.Name, this.Name.ToCamelCase());
                builder.AppendLine("{0} result = null;", this.ReturnType.Body.Name);
                builder.AppendLine("if (response.body() != null) {")
                .Indent()
                .AppendLine("result = response.body().items();", this.ReturnType.Body.Name)
                .Outdent().AppendLine("}");
                return(builder.ToString());
            }
            else
            {
                return(base.ResponseGeneration());
            }
        }
Example #3
0
        public string NextMethodParameterInvocation(bool filterRequired = false)
        {
            string    invocation;
            MethodJva nextMethod = GetPagingNextMethodWithInvocation(out invocation);

            if (filterRequired)
            {
                if (this.InputParameterTransformation.IsNullOrEmpty() || nextMethod.InputParameterTransformation.IsNullOrEmpty())
                {
                    return(nextMethod.MethodDefaultParameterInvocation);
                }
                var           groupedType   = this.InputParameterTransformation.First().ParameterMappings[0].InputParameter;
                var           nextGroupType = nextMethod.InputParameterTransformation.First().ParameterMappings[0].InputParameter;
                List <string> invocations   = new List <string>();
                foreach (var parameter in nextMethod.LocalParameters)
                {
                    if (parameter.IsRequired)
                    {
                        invocations.Add(parameter.Name);
                    }
                    else if (parameter.Name == nextGroupType.Name && groupedType.IsRequired)
                    {
                        invocations.Add(parameter.Name);
                    }
                    else
                    {
                        invocations.Add("null");
                    }
                }
                return(string.Join(", ", invocations));
            }
            else
            {
                return(nextMethod.MethodParameterInvocation);
            }
        }
Example #4
0
        protected virtual void TransformPagingGroupedParameter(IndentedStringBuilder builder, MethodJva nextMethod, bool filterRequired = false)
        {
            if (this.InputParameterTransformation.IsNullOrEmpty() || nextMethod.InputParameterTransformation.IsNullOrEmpty())
            {
                return;
            }
            var groupedType   = this.InputParameterTransformation.First().ParameterMappings[0].InputParameter;
            var nextGroupType = nextMethod.InputParameterTransformation.First().ParameterMappings[0].InputParameter;

            if (nextGroupType.Name == groupedType.Name)
            {
                return;
            }
            var nextGroupTypeName = CodeNamerJva.Instance.GetTypeName(nextGroupType.Name);

            if (filterRequired && !groupedType.IsRequired)
            {
                return;
            }
            if (!groupedType.IsRequired)
            {
                builder.AppendLine("{0} {1} = null;", nextGroupTypeName, nextGroupType.Name.ToCamelCase());
                builder.AppendLine("if ({0} != null) {{", groupedType.Name.ToCamelCase());
                builder.Indent();
                builder.AppendLine("{0} = new {1}();", nextGroupType.Name.ToCamelCase(), nextGroupTypeName);
            }
            else
            {
                builder.AppendLine("{1} {0} = new {1}();", nextGroupType.Name.ToCamelCase(), nextGroupTypeName);
            }
            foreach (var outParam in nextMethod.InputParameterTransformation.Select(t => t.OutputParameter))
            {
                builder.AppendLine("{0}.with{1}({2}.{3}());", nextGroupType.Name.ToCamelCase(), outParam.Name.ToPascalCase(), groupedType.Name.ToCamelCase(), outParam.Name.ToCamelCase());
            }
            if (!groupedType.IsRequired)
            {
                builder.Outdent().AppendLine(@"}");
            }
        }
Example #5
0
 public override string SuccessCallback(bool filterRequired = false)
 {
     if (this.IsPagingOperation)
     {
         var builder = new IndentedStringBuilder();
         builder.AppendLine("{0} result = {1}Delegate(response);",
                            ReturnTypeJva.WireResponseTypeString, this.Name);
         builder.AppendLine("if (serviceCallback != null) {").Indent();
         builder.AppendLine("serviceCallback.load(result.body().items());");
         builder.AppendLine("if (result.body().nextPageLink() != null").Indent().Indent()
         .AppendLine("&& serviceCallback.progress(result.body().items()) == ListOperationCallback.PagingBahavior.CONTINUE) {").Outdent();
         string    invocation;
         MethodJva nextMethod = GetPagingNextMethodWithInvocation(out invocation, true);
         TransformPagingGroupedParameter(builder, nextMethod, filterRequired);
         var nextCall = string.Format(CultureInfo.InvariantCulture, "{0}(result.body().nextPageLink(), {1});",
                                      invocation,
                                      filterRequired ? nextMethod.MethodRequiredParameterInvocationWithCallback : nextMethod.MethodParameterInvocationWithCallback);
         builder.AppendLine(nextCall.Replace(
                                string.Format(", {0}", nextMethod.Parameters.First(p => p.Name.ToString().StartsWith("next", StringComparison.OrdinalIgnoreCase)).Name),
                                "")).Outdent();
         builder.AppendLine("} else {").Indent();
         if (ReturnType.Headers == null)
         {
             builder.AppendLine("serviceCallback.success(new {0}<>(serviceCallback.get(), result.response()));", ReturnTypeJva.ClientResponseType);
         }
         else
         {
             builder.AppendLine("serviceCallback.success(new {0}<>(serviceCallback.get(), result.headers(), result.response()));", ReturnTypeJva.ClientResponseType);
         }
         builder.Outdent().AppendLine("}").Outdent().AppendLine("}");
         if (ReturnType.Headers == null)
         {
             builder.AppendLine("serviceFuture.success(new {0}<>(result.body().items(), response));", ReturnTypeJva.ClientResponseType);
         }
         else
         {
             builder.AppendLine("serviceFuture.success(new {0}<>(result.body().items(), result.headers(), result.response()));", ReturnTypeJva.ClientResponseType);
         }
         return(builder.ToString());
     }
     else if (this.IsPagingNextOperation)
     {
         var builder = new IndentedStringBuilder();
         builder.AppendLine("{0} result = {1}Delegate(response);", ReturnTypeJva.WireResponseTypeString, this.Name);
         builder.AppendLine("serviceCallback.load(result.body().items());");
         builder.AppendLine("if (result.body().nextPageLink() != null").Indent().Indent();
         builder.AppendLine("&& serviceCallback.progress(result.body().items()) == ListOperationCallback.PagingBahavior.CONTINUE) {").Outdent();
         var nextCall = string.Format(CultureInfo.InvariantCulture, "{0}Async(result.body().nextPageLink(), {1});",
                                      this.Name,
                                      filterRequired ? MethodRequiredParameterInvocationWithCallback : MethodParameterInvocationWithCallback);
         builder.AppendLine(nextCall.Replace(
                                string.Format(", {0}", Parameters.First(p => p.Name.ToString().StartsWith("next", StringComparison.OrdinalIgnoreCase)).Name),
                                "")).Outdent();
         builder.AppendLine("} else {").Indent();
         if (ReturnType.Headers == null)
         {
             builder.AppendLine("serviceCallback.success(new {0}<>(serviceCallback.get(), result.response()));", ReturnTypeJva.ClientResponseType);
         }
         else
         {
             builder.AppendLine("serviceCallback.success(new {0}<>(serviceCallback.get(), result.headers(), result.response()));", ReturnTypeJva.ClientResponseType);
         }
         builder.Outdent().AppendLine("}");
         return(builder.ToString());
     }
     else if (this.IsPagingNonPollingOperation)
     {
         var returnTypeBody = ReturnType.Body as SequenceTypeJva;
         var builder        = new IndentedStringBuilder();
         builder.AppendLine("{0}<{1}<{2}>> result = {3}Delegate(response);",
                            ReturnTypeJva.ClientResponseType, returnTypeBody.PageImplType, returnTypeBody.ElementType.Name, this.Name.ToCamelCase());
         if (ReturnType.Headers == null)
         {
             builder.AppendLine("serviceCallback.success(new {0}<>(result.body().items(), result.response()));", ReturnTypeJva.ClientResponseType);
         }
         else
         {
             builder.AppendLine("serviceCallback.success(new {0}<>(result.body().items(), result.headers(), result.response()));", ReturnTypeJva.ClientResponseType);
         }
         return(builder.ToString());
     }
     return(base.SuccessCallback());
 }