private boolean isRequestTokenParam(MethodConfig methodConfig, FieldModel field) { return methodConfig.isPageStreaming() && field.equals(methodConfig.getPageStreaming().getRequestTokenField()); }
/** Returns true if this method has batching configured. */ public boolean isBatching() { return getBatching() != null; }
private List<SingleResourceNameConfig> getSingleResourceNameConfigsUsedByInterface( InterfaceContext context) { InterfaceConfig interfaceConfig = context.getInterfaceConfig(); Set<String> foundSet = new HashSet<>(); ImmutableList.Builder<SingleResourceNameConfig> resourceNameConfigsBuilder = ImmutableList.builder(); for (SingleResourceNameConfig config : interfaceConfig.getSingleResourceNameConfigs()) { resourceNameConfigsBuilder.add(config); foundSet.add(config.getEntityId()); } for (MethodConfig methodConfig : interfaceConfig.getMethodConfigs()) { MethodContext methodContext = context.asRequestMethodContext(methodConfig.getMethodModel()); for (String fieldNamePattern : methodConfig.getFieldNamePatterns().values()) { SingleResourceNameConfig resourceNameConfig = methodContext.getSingleResourceNameConfig(fieldNamePattern); if (resourceNameConfig != null && !foundSet.contains(resourceNameConfig.getEntityId())) { resourceNameConfigsBuilder.add(resourceNameConfig); foundSet.add(resourceNameConfig.getEntityId()); } } } return resourceNameConfigsBuilder.build(); }
private boolean hasParams(MethodConfig methodConfig) { if (!Iterables.isEmpty(methodConfig.getRequiredFieldConfigs())) { return true; } int optionalParamCount = Iterables.size(methodConfig.getOptionalFieldConfigs()); // Must have at least one parameter that is not the page token parameter. return optionalParamCount > (methodConfig.getPageStreaming() == null ? 0 : 1); }
/** Returns the grpc streaming configuration of the method. */ public GrpcStreamingType getGrpcStreamingType() { if (isGrpcStreaming()) { return getGrpcStreaming().getType(); } else { return GrpcStreamingType.NonStreaming; } }
private List<FieldModel> removePageTokenFromFields(MethodConfig methodConfig) { ImmutableList.Builder<FieldModel> newFields = ImmutableList.builder(); for (FieldModel field : methodConfig.getOptionalFields()) { if (methodConfig.isPageStreaming() && field.equals(methodConfig.getPageStreaming().getRequestTokenField())) { continue; } newFields.add(field); } return newFields.build(); }
for (MethodModel method : context.getSupportedMethods()) { MethodConfig methodConfig = context.getMethodConfig(method); if (methodConfig.isGrpcStreaming()) { } else if (methodConfig.isFlattening()) { ClientMethodType clientMethodTypeSync; ClientMethodType clientMethodTypeAsync; if (methodConfig.isPageStreaming()) { } else if (methodConfig.isLongRunningOperation()) { clientMethodTypeAsync = ClientMethodType.FlattenedAsyncCallSettingsMethod; if (methodConfig.getRerouteToGrpcInterface() != null) { for (FlatteningConfig flatteningGroup : methodConfig.getFlatteningConfigs()) { GapicMethodContext methodContext = context.asFlattenedMethodContext(method, flatteningGroup); requestContext, methodConfig, testNameTable, Synchronicity.Async)); } else { if (methodConfig.isPageStreaming() || methodConfig.isLongRunningOperation() || methodConfig.getRerouteToGrpcInterface() != null) {
if (methodConfig.isPageStreaming()) { clientMethodName = namer.getApiMethodName(method, methodConfig.getVisibility()); responseTypeName = namer.getAndSavePagedResponseTypeName( methodContext, methodConfig.getPageStreaming().getResourcesFieldConfig()); callerResponseTypeName = namer.getAndSaveCallerPagedResponseTypeName( methodContext, methodConfig.getPageStreaming().getResourcesFieldConfig()); } else if (methodConfig.isLongRunningOperation()) { clientMethodName = namer.getLroApiMethodName(method, methodConfig.getVisibility()); responseTypeName = methodContext .getTypeTable() .getAndSaveNicknameFor(methodConfig.getLongRunningConfig().getReturnType()); callerResponseTypeName = responseTypeName; fullyQualifiedResponseTypeName = methodContext .getTypeTable() .getFullNameFor(methodConfig.getLongRunningConfig().getReturnType()); } else if (clientMethodType == ClientMethodType.CallableMethod) { clientMethodName = namer.getCallableMethodName(method); clientMethodName = synchronicity == Synchronicity.Sync ? namer.getApiMethodName(method, methodConfig.getVisibility()) : namer.getAsyncApiMethodName(method, methodConfig.getVisibility()); responseTypeName = method.getAndSaveResponseTypeName(typeTable, namer); callerResponseTypeName = responseTypeName;
/** Returns true if this method has page streaming configured. */ public boolean isPageStreaming() { return getPageStreaming() != null; }
private List<InitCodeNode> createMockResponseAdditionalSubTrees(MethodContext context) { List<InitCodeNode> additionalSubTrees = new ArrayList<>(); if (context.getMethodConfig().isPageStreaming()) { PageStreamingConfig config = context.getMethodConfig().getPageStreaming(); FieldModel field = config.getResourcesField(); InitCodeNode initCodeNode; responseTokenName, InitValueConfig.createWithValue(InitValue.createLiteral("")))); if (context.getMethodConfig().isBatching()) { BatchingConfig config = context.getMethodConfig().getBatching(); if (config.getSubresponseField() != null) { String subResponseFieldName = config.getSubresponseField().getSimpleName(); if (context.getMethodConfig().isGrpcStreaming()) { GrpcStreamingConfig streamingConfig = context.getMethodConfig().getGrpcStreaming(); if (streamingConfig.hasResourceField()) { String resourceFieldName = streamingConfig.getResourcesField().getSimpleName();
settings.retryCodesName(methodConfig.getRetryCodesConfigName()); settings.retryCodesView(retryCodesByKey.get(methodConfig.getRetryCodesConfigName())); settings.retryParamsName(methodConfig.getRetrySettingsConfigName()); settings.retryParamsView(retryParamsByKey.get(methodConfig.getRetrySettingsConfigName())); settings.visibility(namer.getVisiblityKeyword(methodConfig.getVisibility())); case ClientStreamingApiCallable: case ServerStreamingApiCallable: settings.type(ApiCallableImplType.of(methodConfig.getGrpcStreamingType())); if (methodConfig.getGrpcStreaming().hasResourceField()) { FieldModel resourceType = methodConfig.getGrpcStreaming().getResourcesField(); settings.resourceTypeName(typeTable.getAndSaveNicknameForElementType(resourceType)); settings.grpcStreamingType(methodConfig.getGrpcStreaming().getType()); break; case PagedApiCallable: settings.type(ApiCallableImplType.PagedApiCallable); FieldModel resourceField = methodConfig.getPageStreaming().getResourcesField(); settings.resourceTypeName(typeTable.getAndSaveNicknameForElementType(resourceField)); settings.pagedListResponseTypeName( namer.getAndSavePagedResponseTypeName( context, methodConfig.getPageStreaming().getResourcesFieldConfig())); settings.pagedListResponseFactoryName(namer.getPagedListResponseFactoryConstName(method)); break;
TransformationContext context, MethodContext methodContext, Synchronicity synchronicity) { MethodConfig methodConfig = methodContext.getMethodConfig(); if (methodConfig.isPageStreaming()) { FieldModel resourceType = methodConfig.getPageStreaming().getResourcesField(); String resourceTypeName = context.getImportTypeTable().getAndSaveNicknameForElementType(resourceType); + "\"/> resources."); } else if (methodConfig.isGrpcStreaming()) { switch (methodConfig.getGrpcStreamingType()) { case ServerStreaming: return ImmutableList.of("The server stream."); default: throw new IllegalStateException( "Invalid streaming: " + methodConfig.getGrpcStreamingType()); boolean hasReturn = !methodConfig.getMethodModel().isOutputTypeEmpty(); switch (synchronicity) { case Sync:
@Override public String getDynamicLangReturnTypeName(MethodContext methodContext) { MethodModel method = methodContext.getMethodModel(); MethodConfig methodConfig = methodContext.getMethodConfig(); if (method.isOutputTypeEmpty()) { return ""; } String classInfo = method.getOutputTypeName(methodContext.getTypeTable()).getFullName(); if (method.getResponseStreaming()) { return "Enumerable<" + classInfo + ">"; } if (methodConfig.isPageStreaming()) { String resourceTypeName = getModelTypeFormatter() .getFullNameForElementType(methodConfig.getPageStreaming().getResourcesField()); return "Google::Gax::PagedEnumerable<" + resourceTypeName + ">"; } if (methodConfig.isLongRunningOperation()) { return "Google::Gax::Operation"; } return classInfo; }
public List<ApiCallSettingsView> generateApiCallableSettings(MethodContext context) { List<ApiCallSettingsView> settings = new ArrayList<>(); MethodConfig methodConfig = context.getMethodConfig(); if (methodConfig.isGrpcStreaming()) { settings.add( generateApiCallableSettings( context, ApiCallableImplType.of(methodConfig.getGrpcStreamingType()))); } else if (methodConfig.isPageStreaming()) { settings.add(generateApiCallableSettings(context, ApiCallableImplType.PagedApiCallable)); } else if (methodConfig.isBatching()) { settings.add(generateApiCallableSettings(context, ApiCallableImplType.BatchingApiCallable)); } else if (methodConfig.isLongRunningOperation()) { if (context.getFeatureConfig().enableRawOperationCallSettings()) { settings.add(generateApiCallableSettings(context, ApiCallableImplType.SimpleApiCallable)); } settings.add(generateApiCallableSettings(context, ApiCallableImplType.OperationApiCallable)); } else { settings.add(generateApiCallableSettings(context, ApiCallableImplType.SimpleApiCallable)); } return settings; }
methodViewBuilder.callableName(context.getNamer().getCallableName(method)); methodViewBuilder.modifyMethodName(namer.getModifyMethodName(context)); methodViewBuilder.grpcStreamingType(context.getMethodConfig().getGrpcStreamingType()); methodViewBuilder.visibility( namer.getVisiblityKeyword(context.getMethodConfig().getVisibility())); methodViewBuilder.releaseLevelAnnotation( namer.getReleaseAnnotation(context.getMethodConfig().getReleaseLevel())); if (context.getMethodConfig().isLongRunningOperation()) { methodViewBuilder.hasReturnValue( !context.getMethodConfig().getLongRunningConfig().getReturnType().isEmptyType()); } else { methodViewBuilder.hasReturnValue(!method.isOutputTypeEmpty());
private StaticLangApiMethodSnippetView generatePagedRequestMethod(MethodContext methodContext) { StaticLangApiMethodView method = generateInitCode( apiMethodTransformer.generatePagedRequestObjectMethod( methodContext, csharpCommonTransformer.pagedMethodAdditionalParams()), methodContext, methodContext.getMethodConfig().getRequiredFieldConfigs(), InitCodeOutputType.SingleObject, CallingForm.RequestPaged); SurfaceNamer namer = methodContext.getNamer(); PageStreamingConfig pageStreaming = methodContext.getMethodConfig().getPageStreaming(); FieldConfig resourceFieldConfig = pageStreaming.getResourcesFieldConfig(); String callerResponseTypeName = namer.getAndSaveCallerPagedResponseTypeName(methodContext, resourceFieldConfig); return StaticLangApiMethodSnippetView.newBuilder() .method(method) .snippetMethodName(method.name() + "_RequestObject") .callerResponseTypeName(callerResponseTypeName) .apiClassName(namer.getApiWrapperClassName(methodContext.getInterfaceConfig())) .apiVariableName(method.apiVariableName()) .build(); }
apiCallableBuilder.name(namer.getCallableName(method)); apiCallableBuilder.methodName( namer.getApiMethodName(method, context.getMethodConfig().getVisibility())); apiCallableBuilder.asyncMethodName( namer.getAsyncApiMethodName(method, VisibilityConfig.PUBLIC)); if (methodConfig.isGrpcStreaming()) { callableImplType = ApiCallableImplType.of(methodConfig.getGrpcStreamingType()); apiCallableBuilder.grpcStreamingType(methodConfig.getGrpcStreamingType()); } else if (methodConfig.isBatching()) { callableImplType = ApiCallableImplType.BatchingApiCallable;
methodViewBuilder, context, context.getMethodConfig().getRequiredFieldConfigs(), InitCodeOutputType.SingleObject, initCodeContext -> if (methodConfig.isGrpcStreaming()) { callableImplType = ApiCallableImplType.of(methodConfig.getGrpcStreamingType()); } else if (methodConfig.isBatching()) { callableImplType = ApiCallableImplType.BatchingApiCallable;
if (baseIdentifier.equals(RESPONSE_PLACEHOLDER)) { view.variable(context.getNamer().getSampleResponseVarName(context)); boolean pageStreaming = context.getMethodConfig().getPageStreaming() != null; boolean pageStreamingAndUseResourceName = pageStreaming .getFeatureConfig() .useResourceNameFormatOption( context.getMethodConfig().getPageStreaming().getResourcesFieldConfig()); .getAndSaveElementResourceTypeName( context.getTypeTable(), context.getMethodConfig().getPageStreaming().getResourcesFieldConfig()); } else if (pageStreaming) { type = context .getMethodConfig() .getPageStreaming() .getResourcesFieldConfig() .getField() .getType() .makeOptional(); } else if (context.getMethodConfig().isLongRunningOperation()) { type = context.getMethodConfig().getLongRunningConfig().getReturnType(); } else { type = context.getMethodModel().getOutputType();
public String getSampleResponseVarName(MethodContext context) { MethodConfig config = context.getMethodConfig(); if (config.getPageStreaming() != null) { return "responseItem"; } if (config.getGrpcStreaming() != null) { GrpcStreamingConfig.GrpcStreamingType type = config.getGrpcStreaming().getType(); if (type == GrpcStreamingConfig.GrpcStreamingType.ServerStreaming || type == GrpcStreamingConfig.GrpcStreamingType.BidiStreaming) { return "responseItem"; } } return "response"; }