use of com.google.cloud.OperationResponseMapping in project gapic-generator-java by googleapis.
the class Parser method parseMessages.
private static Map<String, Message> parseMessages(Descriptor messageDescriptor, Set<ResourceReference> outputResourceReferencesSeen, List<String> outerNestedTypes) {
Map<String, Message> messages = new HashMap<>();
String messageName = messageDescriptor.getName();
if (!messageDescriptor.getNestedTypes().isEmpty()) {
for (Descriptor nestedMessage : messageDescriptor.getNestedTypes()) {
if (isMapType(nestedMessage)) {
continue;
}
List<String> currentNestedTypes = new ArrayList<>(outerNestedTypes);
currentNestedTypes.add(messageName);
messages.putAll(parseMessages(nestedMessage, outputResourceReferencesSeen, currentNestedTypes));
}
}
TypeNode messageType = TypeParser.parseType(messageDescriptor);
List<FieldDescriptor> fields = messageDescriptor.getFields();
HashMap<String, String> operationRequestFields = new HashMap<String, String>();
BiMap<String, String> operationResponseFields = HashBiMap.create();
OperationResponse.Builder operationResponse = null;
for (FieldDescriptor fd : fields) {
if (fd.getOptions().hasExtension(ExtendedOperationsProto.operationRequestField)) {
String orf = fd.getOptions().getExtension(ExtendedOperationsProto.operationRequestField);
operationRequestFields.put(orf, fd.getName());
}
if (fd.getOptions().hasExtension(ExtendedOperationsProto.operationResponseField)) {
String orf = fd.getOptions().getExtension(ExtendedOperationsProto.operationResponseField);
operationResponseFields.put(orf, fd.getName());
}
if (fd.getOptions().hasExtension(ExtendedOperationsProto.operationField)) {
OperationResponseMapping orm = fd.getOptions().getExtension(ExtendedOperationsProto.operationField);
if (operationResponse == null) {
operationResponse = OperationResponse.builder();
}
if (orm.equals(OperationResponseMapping.NAME)) {
operationResponse.setNameFieldName(fd.getName());
} else if (orm.equals(OperationResponseMapping.STATUS)) {
operationResponse.setStatusFieldName(fd.getName());
operationResponse.setStatusFieldTypeName(fd.toProto().getTypeName());
} else if (orm.equals(OperationResponseMapping.ERROR_CODE)) {
operationResponse.setErrorCodeFieldName(fd.getName());
} else if (orm.equals(OperationResponseMapping.ERROR_MESSAGE)) {
operationResponse.setErrorMessageFieldName(fd.getName());
}
}
}
messages.put(messageType.reference().fullName(), Message.builder().setType(messageType).setName(messageName).setFullProtoName(messageDescriptor.getFullName()).setFields(parseFields(messageDescriptor, outputResourceReferencesSeen)).setOuterNestedTypes(outerNestedTypes).setOperationRequestFields(operationRequestFields).setOperationResponseFields(operationResponseFields).setOperationResponse(operationResponse != null ? operationResponse.build() : null).build());
return messages;
}
Aggregations