From 14952bc04524337b8de7f7366806bfe431c234fe Mon Sep 17 00:00:00 2001 From: Stoyan Tzenkov Date: Tue, 16 Oct 2018 13:57:30 +0300 Subject: [PATCH 1/9] NY_XXXX: Search by username implemented Signed-off-by: Stoyan Tzenkov --- .../account/services/SearchServiceImpl.java | 76 + .../biz/nynja/search/grpc/ErrorResponse.java | 760 +++++++++ .../search/grpc/ErrorResponseOrBuilder.java | 28 + .../java/biz/nynja/search/grpc/Search.java | 108 ++ .../search/grpc/SearchByUsernameRequest.java | 516 ++++++ .../SearchByUsernameRequestOrBuilder.java | 19 + .../biz/nynja/search/grpc/SearchResponse.java | 924 +++++++++++ .../search/grpc/SearchResponseOrBuilder.java | 42 + .../search/grpc/SearchResultDetails.java | 1405 +++++++++++++++++ .../grpc/SearchResultDetailsOrBuilder.java | 89 ++ .../biz/nynja/search/grpc/SearchService.java | 237 +++ .../nynja/search/grpc/SearchServiceGrpc.java | 286 ++++ 12 files changed, 4490 insertions(+) create mode 100644 src/main/java/biz/nynja/account/services/SearchServiceImpl.java create mode 100644 src/main/java/biz/nynja/search/grpc/ErrorResponse.java create mode 100644 src/main/java/biz/nynja/search/grpc/ErrorResponseOrBuilder.java create mode 100644 src/main/java/biz/nynja/search/grpc/Search.java create mode 100644 src/main/java/biz/nynja/search/grpc/SearchByUsernameRequest.java create mode 100644 src/main/java/biz/nynja/search/grpc/SearchByUsernameRequestOrBuilder.java create mode 100644 src/main/java/biz/nynja/search/grpc/SearchResponse.java create mode 100644 src/main/java/biz/nynja/search/grpc/SearchResponseOrBuilder.java create mode 100644 src/main/java/biz/nynja/search/grpc/SearchResultDetails.java create mode 100644 src/main/java/biz/nynja/search/grpc/SearchResultDetailsOrBuilder.java create mode 100644 src/main/java/biz/nynja/search/grpc/SearchService.java create mode 100644 src/main/java/biz/nynja/search/grpc/SearchServiceGrpc.java diff --git a/src/main/java/biz/nynja/account/services/SearchServiceImpl.java b/src/main/java/biz/nynja/account/services/SearchServiceImpl.java new file mode 100644 index 0000000..7fe16ab --- /dev/null +++ b/src/main/java/biz/nynja/account/services/SearchServiceImpl.java @@ -0,0 +1,76 @@ +package biz.nynja.account.services; + +import org.lognet.springboot.grpc.GRpcService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; + +import biz.nynja.account.grpc.AccountByAuthenticationProviderRequest; +import biz.nynja.account.grpc.AccountResponse; +import biz.nynja.account.grpc.AuthenticationType; +import biz.nynja.search.grpc.ErrorResponse; +import biz.nynja.search.grpc.ErrorResponse.Cause; +import biz.nynja.account.models.Account; +import biz.nynja.account.models.AccountByUsername; +import biz.nynja.account.repositories.AccountByUsernameRepository; +import biz.nynja.search.grpc.SearchByUsernameRequest; +import biz.nynja.search.grpc.SearchResponse; +import biz.nynja.search.grpc.SearchResultDetails; +import biz.nynja.search.grpc.SearchServiceGrpc; +import io.grpc.stub.StreamObserver; + +@GRpcService +public class SearchServiceImpl extends SearchServiceGrpc.SearchServiceImplBase { + + private static final Logger logger = LoggerFactory.getLogger(SearchServiceImpl.class); + + @Autowired + AccountByUsernameRepository accountByUsernameRepository; + + + @Override + public void searchByUsername(SearchByUsernameRequest request, + StreamObserver responseObserver) { + + logger.info("Getting account by username: {}", request.getUsername()); + if (request.getUsername().isEmpty()) { + responseObserver.onNext(SearchResponse.newBuilder() + .setError(ErrorResponse.newBuilder().setCause(Cause.MISSING_USERNAME)).build()); + responseObserver.onCompleted(); + return; + } + + AccountByUsername account = accountByUsernameRepository.findByUsername(request.getUsername()); + if (account == null) { + + logger.debug("No matching accounts found for usernamer: {}", request.getUsername()); + responseObserver.onNext(SearchResponse.newBuilder() + .setError(ErrorResponse.newBuilder().setCause(Cause.USERNAME_NOT_FOUND)).build()); + responseObserver.onCompleted(); + return; + } + + SearchResultDetails searchResultDetails = SearchResultDetails.newBuilder() + .setAccountId(account.getAccountId().toString()) + .setAuthenticationProvider(account.getAuthenticationProvider()) + .setAuthenticationType(account.getAuthenticationProviderType()) + .setFirstName(account.getFirstName()) + .setLastName(account.getLastName()) + .setProfileId(account.getAccountId().toString()) + .setQrCode(account.getQrCode()) + .setUsername(account.getUsername()) + .build(); + + SearchResponse response = SearchResponse.newBuilder() + .setSearchResultDetails(searchResultDetails).build(); + logger.debug("Found result for account by username {}: \"{}\"", + request.getUsername(), response); + responseObserver.onNext(response); + responseObserver.onCompleted(); + + return; + } + + + +} diff --git a/src/main/java/biz/nynja/search/grpc/ErrorResponse.java b/src/main/java/biz/nynja/search/grpc/ErrorResponse.java new file mode 100644 index 0000000..e2889a7 --- /dev/null +++ b/src/main/java/biz/nynja/search/grpc/ErrorResponse.java @@ -0,0 +1,760 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: search.proto + +package biz.nynja.search.grpc; + +/** + * Protobuf type {@code account.ErrorResponse} + */ +public final class ErrorResponse extends + com.google.protobuf.GeneratedMessageV3 implements + // @@protoc_insertion_point(message_implements:account.ErrorResponse) + ErrorResponseOrBuilder { +private static final long serialVersionUID = 0L; + // Use ErrorResponse.newBuilder() to construct. + private ErrorResponse(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + private ErrorResponse() { + cause_ = 0; + message_ = ""; + } + + @java.lang.Override + public final com.google.protobuf.UnknownFieldSet + getUnknownFields() { + return this.unknownFields; + } + private ErrorResponse( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + this(); + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + int mutable_bitField0_ = 0; + com.google.protobuf.UnknownFieldSet.Builder unknownFields = + com.google.protobuf.UnknownFieldSet.newBuilder(); + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + default: { + if (!parseUnknownFieldProto3( + input, unknownFields, extensionRegistry, tag)) { + done = true; + } + break; + } + case 8: { + int rawValue = input.readEnum(); + + cause_ = rawValue; + break; + } + case 18: { + java.lang.String s = input.readStringRequireUtf8(); + + message_ = s; + break; + } + } + } + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(this); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException( + e).setUnfinishedMessage(this); + } finally { + this.unknownFields = unknownFields.build(); + makeExtensionsImmutable(); + } + } + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return biz.nynja.search.grpc.Search.internal_static_account_ErrorResponse_descriptor; + } + + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return biz.nynja.search.grpc.Search.internal_static_account_ErrorResponse_fieldAccessorTable + .ensureFieldAccessorsInitialized( + biz.nynja.search.grpc.ErrorResponse.class, biz.nynja.search.grpc.ErrorResponse.Builder.class); + } + + /** + * Protobuf enum {@code account.ErrorResponse.Cause} + */ + public enum Cause + implements com.google.protobuf.ProtocolMessageEnum { + /** + * INTERNAL_SERVER_ERROR = 0; + */ + INTERNAL_SERVER_ERROR(0), + /** + * MISSING_USERNAME = 1; + */ + MISSING_USERNAME(1), + /** + * MISSING_EMAIL = 2; + */ + MISSING_EMAIL(2), + /** + * MISSING_PHONENUMBER = 3; + */ + MISSING_PHONENUMBER(3), + /** + * MISSING_QR_CODE = 4; + */ + MISSING_QR_CODE(4), + /** + * USERNAME_NOT_FOUND = 5; + */ + USERNAME_NOT_FOUND(5), + /** + * EMAIL_NOT_FOUND = 6; + */ + EMAIL_NOT_FOUND(6), + /** + * PHONENUMBER_NOT_FOUND = 7; + */ + PHONENUMBER_NOT_FOUND(7), + /** + * QR_CODE_NOT_FOUND = 8; + */ + QR_CODE_NOT_FOUND(8), + UNRECOGNIZED(-1), + ; + + /** + * INTERNAL_SERVER_ERROR = 0; + */ + public static final int INTERNAL_SERVER_ERROR_VALUE = 0; + /** + * MISSING_USERNAME = 1; + */ + public static final int MISSING_USERNAME_VALUE = 1; + /** + * MISSING_EMAIL = 2; + */ + public static final int MISSING_EMAIL_VALUE = 2; + /** + * MISSING_PHONENUMBER = 3; + */ + public static final int MISSING_PHONENUMBER_VALUE = 3; + /** + * MISSING_QR_CODE = 4; + */ + public static final int MISSING_QR_CODE_VALUE = 4; + /** + * USERNAME_NOT_FOUND = 5; + */ + public static final int USERNAME_NOT_FOUND_VALUE = 5; + /** + * EMAIL_NOT_FOUND = 6; + */ + public static final int EMAIL_NOT_FOUND_VALUE = 6; + /** + * PHONENUMBER_NOT_FOUND = 7; + */ + public static final int PHONENUMBER_NOT_FOUND_VALUE = 7; + /** + * QR_CODE_NOT_FOUND = 8; + */ + public static final int QR_CODE_NOT_FOUND_VALUE = 8; + + + public final int getNumber() { + if (this == UNRECOGNIZED) { + throw new java.lang.IllegalArgumentException( + "Can't get the number of an unknown enum value."); + } + return value; + } + + /** + * @deprecated Use {@link #forNumber(int)} instead. + */ + @java.lang.Deprecated + public static Cause valueOf(int value) { + return forNumber(value); + } + + public static Cause forNumber(int value) { + switch (value) { + case 0: return INTERNAL_SERVER_ERROR; + case 1: return MISSING_USERNAME; + case 2: return MISSING_EMAIL; + case 3: return MISSING_PHONENUMBER; + case 4: return MISSING_QR_CODE; + case 5: return USERNAME_NOT_FOUND; + case 6: return EMAIL_NOT_FOUND; + case 7: return PHONENUMBER_NOT_FOUND; + case 8: return QR_CODE_NOT_FOUND; + default: return null; + } + } + + public static com.google.protobuf.Internal.EnumLiteMap + internalGetValueMap() { + return internalValueMap; + } + private static final com.google.protobuf.Internal.EnumLiteMap< + Cause> internalValueMap = + new com.google.protobuf.Internal.EnumLiteMap() { + public Cause findValueByNumber(int number) { + return Cause.forNumber(number); + } + }; + + public final com.google.protobuf.Descriptors.EnumValueDescriptor + getValueDescriptor() { + return getDescriptor().getValues().get(ordinal()); + } + public final com.google.protobuf.Descriptors.EnumDescriptor + getDescriptorForType() { + return getDescriptor(); + } + public static final com.google.protobuf.Descriptors.EnumDescriptor + getDescriptor() { + return biz.nynja.search.grpc.ErrorResponse.getDescriptor().getEnumTypes().get(0); + } + + private static final Cause[] VALUES = values(); + + public static Cause valueOf( + com.google.protobuf.Descriptors.EnumValueDescriptor desc) { + if (desc.getType() != getDescriptor()) { + throw new java.lang.IllegalArgumentException( + "EnumValueDescriptor is not for this type."); + } + if (desc.getIndex() == -1) { + return UNRECOGNIZED; + } + return VALUES[desc.getIndex()]; + } + + private final int value; + + private Cause(int value) { + this.value = value; + } + + // @@protoc_insertion_point(enum_scope:account.ErrorResponse.Cause) + } + + public static final int CAUSE_FIELD_NUMBER = 1; + private int cause_; + /** + * .account.ErrorResponse.Cause cause = 1; + */ + public int getCauseValue() { + return cause_; + } + /** + * .account.ErrorResponse.Cause cause = 1; + */ + public biz.nynja.search.grpc.ErrorResponse.Cause getCause() { + biz.nynja.search.grpc.ErrorResponse.Cause result = biz.nynja.search.grpc.ErrorResponse.Cause.valueOf(cause_); + return result == null ? biz.nynja.search.grpc.ErrorResponse.Cause.UNRECOGNIZED : result; + } + + public static final int MESSAGE_FIELD_NUMBER = 2; + private volatile java.lang.Object message_; + /** + * string message = 2; + */ + public java.lang.String getMessage() { + java.lang.Object ref = message_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + message_ = s; + return s; + } + } + /** + * string message = 2; + */ + public com.google.protobuf.ByteString + getMessageBytes() { + java.lang.Object ref = message_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + message_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + private byte memoizedIsInitialized = -1; + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + if (cause_ != biz.nynja.search.grpc.ErrorResponse.Cause.INTERNAL_SERVER_ERROR.getNumber()) { + output.writeEnum(1, cause_); + } + if (!getMessageBytes().isEmpty()) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 2, message_); + } + unknownFields.writeTo(output); + } + + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (cause_ != biz.nynja.search.grpc.ErrorResponse.Cause.INTERNAL_SERVER_ERROR.getNumber()) { + size += com.google.protobuf.CodedOutputStream + .computeEnumSize(1, cause_); + } + if (!getMessageBytes().isEmpty()) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, message_); + } + size += unknownFields.getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof biz.nynja.search.grpc.ErrorResponse)) { + return super.equals(obj); + } + biz.nynja.search.grpc.ErrorResponse other = (biz.nynja.search.grpc.ErrorResponse) obj; + + boolean result = true; + result = result && cause_ == other.cause_; + result = result && getMessage() + .equals(other.getMessage()); + result = result && unknownFields.equals(other.unknownFields); + return result; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + hash = (37 * hash) + CAUSE_FIELD_NUMBER; + hash = (53 * hash) + cause_; + hash = (37 * hash) + MESSAGE_FIELD_NUMBER; + hash = (53 * hash) + getMessage().hashCode(); + hash = (29 * hash) + unknownFields.hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static biz.nynja.search.grpc.ErrorResponse parseFrom( + java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static biz.nynja.search.grpc.ErrorResponse parseFrom( + java.nio.ByteBuffer data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static biz.nynja.search.grpc.ErrorResponse parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static biz.nynja.search.grpc.ErrorResponse parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static biz.nynja.search.grpc.ErrorResponse parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static biz.nynja.search.grpc.ErrorResponse parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static biz.nynja.search.grpc.ErrorResponse parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); + } + public static biz.nynja.search.grpc.ErrorResponse parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); + } + public static biz.nynja.search.grpc.ErrorResponse parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input); + } + public static biz.nynja.search.grpc.ErrorResponse parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input, extensionRegistry); + } + public static biz.nynja.search.grpc.ErrorResponse parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); + } + public static biz.nynja.search.grpc.ErrorResponse parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); + } + + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + public static Builder newBuilder(biz.nynja.search.grpc.ErrorResponse prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + public Builder toBuilder() { + return this == DEFAULT_INSTANCE + ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * Protobuf type {@code account.ErrorResponse} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessageV3.Builder implements + // @@protoc_insertion_point(builder_implements:account.ErrorResponse) + biz.nynja.search.grpc.ErrorResponseOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return biz.nynja.search.grpc.Search.internal_static_account_ErrorResponse_descriptor; + } + + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return biz.nynja.search.grpc.Search.internal_static_account_ErrorResponse_fieldAccessorTable + .ensureFieldAccessorsInitialized( + biz.nynja.search.grpc.ErrorResponse.class, biz.nynja.search.grpc.ErrorResponse.Builder.class); + } + + // Construct using biz.nynja.search.grpc.ErrorResponse.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder( + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessageV3 + .alwaysUseFieldBuilders) { + } + } + public Builder clear() { + super.clear(); + cause_ = 0; + + message_ = ""; + + return this; + } + + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return biz.nynja.search.grpc.Search.internal_static_account_ErrorResponse_descriptor; + } + + public biz.nynja.search.grpc.ErrorResponse getDefaultInstanceForType() { + return biz.nynja.search.grpc.ErrorResponse.getDefaultInstance(); + } + + public biz.nynja.search.grpc.ErrorResponse build() { + biz.nynja.search.grpc.ErrorResponse result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + public biz.nynja.search.grpc.ErrorResponse buildPartial() { + biz.nynja.search.grpc.ErrorResponse result = new biz.nynja.search.grpc.ErrorResponse(this); + result.cause_ = cause_; + result.message_ = message_; + onBuilt(); + return result; + } + + public Builder clone() { + return (Builder) super.clone(); + } + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, + java.lang.Object value) { + return (Builder) super.setField(field, value); + } + public Builder clearField( + com.google.protobuf.Descriptors.FieldDescriptor field) { + return (Builder) super.clearField(field); + } + public Builder clearOneof( + com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return (Builder) super.clearOneof(oneof); + } + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + int index, java.lang.Object value) { + return (Builder) super.setRepeatedField(field, index, value); + } + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + java.lang.Object value) { + return (Builder) super.addRepeatedField(field, value); + } + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof biz.nynja.search.grpc.ErrorResponse) { + return mergeFrom((biz.nynja.search.grpc.ErrorResponse)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(biz.nynja.search.grpc.ErrorResponse other) { + if (other == biz.nynja.search.grpc.ErrorResponse.getDefaultInstance()) return this; + if (other.cause_ != 0) { + setCauseValue(other.getCauseValue()); + } + if (!other.getMessage().isEmpty()) { + message_ = other.message_; + onChanged(); + } + this.mergeUnknownFields(other.unknownFields); + onChanged(); + return this; + } + + public final boolean isInitialized() { + return true; + } + + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + biz.nynja.search.grpc.ErrorResponse parsedMessage = null; + try { + parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + parsedMessage = (biz.nynja.search.grpc.ErrorResponse) e.getUnfinishedMessage(); + throw e.unwrapIOException(); + } finally { + if (parsedMessage != null) { + mergeFrom(parsedMessage); + } + } + return this; + } + + private int cause_ = 0; + /** + * .account.ErrorResponse.Cause cause = 1; + */ + public int getCauseValue() { + return cause_; + } + /** + * .account.ErrorResponse.Cause cause = 1; + */ + public Builder setCauseValue(int value) { + cause_ = value; + onChanged(); + return this; + } + /** + * .account.ErrorResponse.Cause cause = 1; + */ + public biz.nynja.search.grpc.ErrorResponse.Cause getCause() { + biz.nynja.search.grpc.ErrorResponse.Cause result = biz.nynja.search.grpc.ErrorResponse.Cause.valueOf(cause_); + return result == null ? biz.nynja.search.grpc.ErrorResponse.Cause.UNRECOGNIZED : result; + } + /** + * .account.ErrorResponse.Cause cause = 1; + */ + public Builder setCause(biz.nynja.search.grpc.ErrorResponse.Cause value) { + if (value == null) { + throw new NullPointerException(); + } + + cause_ = value.getNumber(); + onChanged(); + return this; + } + /** + * .account.ErrorResponse.Cause cause = 1; + */ + public Builder clearCause() { + + cause_ = 0; + onChanged(); + return this; + } + + private java.lang.Object message_ = ""; + /** + * string message = 2; + */ + public java.lang.String getMessage() { + java.lang.Object ref = message_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + message_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * string message = 2; + */ + public com.google.protobuf.ByteString + getMessageBytes() { + java.lang.Object ref = message_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + message_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * string message = 2; + */ + public Builder setMessage( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + + message_ = value; + onChanged(); + return this; + } + /** + * string message = 2; + */ + public Builder clearMessage() { + + message_ = getDefaultInstance().getMessage(); + onChanged(); + return this; + } + /** + * string message = 2; + */ + public Builder setMessageBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + + message_ = value; + onChanged(); + return this; + } + public final Builder setUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFieldsProto3(unknownFields); + } + + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + + // @@protoc_insertion_point(builder_scope:account.ErrorResponse) + } + + // @@protoc_insertion_point(class_scope:account.ErrorResponse) + private static final biz.nynja.search.grpc.ErrorResponse DEFAULT_INSTANCE; + static { + DEFAULT_INSTANCE = new biz.nynja.search.grpc.ErrorResponse(); + } + + public static biz.nynja.search.grpc.ErrorResponse getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser + PARSER = new com.google.protobuf.AbstractParser() { + public ErrorResponse parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return new ErrorResponse(input, extensionRegistry); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + public biz.nynja.search.grpc.ErrorResponse getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } + +} + diff --git a/src/main/java/biz/nynja/search/grpc/ErrorResponseOrBuilder.java b/src/main/java/biz/nynja/search/grpc/ErrorResponseOrBuilder.java new file mode 100644 index 0000000..016d8bc --- /dev/null +++ b/src/main/java/biz/nynja/search/grpc/ErrorResponseOrBuilder.java @@ -0,0 +1,28 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: search.proto + +package biz.nynja.search.grpc; + +public interface ErrorResponseOrBuilder extends + // @@protoc_insertion_point(interface_extends:account.ErrorResponse) + com.google.protobuf.MessageOrBuilder { + + /** + * .account.ErrorResponse.Cause cause = 1; + */ + int getCauseValue(); + /** + * .account.ErrorResponse.Cause cause = 1; + */ + biz.nynja.search.grpc.ErrorResponse.Cause getCause(); + + /** + * string message = 2; + */ + java.lang.String getMessage(); + /** + * string message = 2; + */ + com.google.protobuf.ByteString + getMessageBytes(); +} diff --git a/src/main/java/biz/nynja/search/grpc/Search.java b/src/main/java/biz/nynja/search/grpc/Search.java new file mode 100644 index 0000000..efca238 --- /dev/null +++ b/src/main/java/biz/nynja/search/grpc/Search.java @@ -0,0 +1,108 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: search.proto + +package biz.nynja.search.grpc; + +public final class Search { + private Search() {} + public static void registerAllExtensions( + com.google.protobuf.ExtensionRegistryLite registry) { + } + + public static void registerAllExtensions( + com.google.protobuf.ExtensionRegistry registry) { + registerAllExtensions( + (com.google.protobuf.ExtensionRegistryLite) registry); + } + static final com.google.protobuf.Descriptors.Descriptor + internal_static_account_SearchByUsernameRequest_descriptor; + static final + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_account_SearchByUsernameRequest_fieldAccessorTable; + static final com.google.protobuf.Descriptors.Descriptor + internal_static_account_SearchResponse_descriptor; + static final + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_account_SearchResponse_fieldAccessorTable; + static final com.google.protobuf.Descriptors.Descriptor + internal_static_account_SearchResultDetails_descriptor; + static final + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_account_SearchResultDetails_fieldAccessorTable; + static final com.google.protobuf.Descriptors.Descriptor + internal_static_account_ErrorResponse_descriptor; + static final + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internal_static_account_ErrorResponse_fieldAccessorTable; + + public static com.google.protobuf.Descriptors.FileDescriptor + getDescriptor() { + return descriptor; + } + private static com.google.protobuf.Descriptors.FileDescriptor + descriptor; + static { + java.lang.String[] descriptorData = { + "\n\014search.proto\022\007account\"+\n\027SearchByUsern" + + "ameRequest\022\020\n\010username\030\001 \001(\t\"\223\001\n\016SearchR" + + "esponse\022\021\n\trequestId\030\001 \001(\004\022\'\n\005error\030\002 \001(" + + "\0132\026.account.ErrorResponseH\000\022;\n\023searchRes" + + "ultDetails\030\003 \001(\0132\034.account.SearchResultD" + + "etailsH\000B\010\n\006result\"\276\001\n\023SearchResultDetai" + + "ls\022\021\n\taccountId\030\001 \001(\t\022\021\n\tprofileId\030\002 \001(\t" + + "\022\036\n\026authenticationProvider\030\003 \001(\t\022\032\n\022auth" + + "enticationType\030\004 \001(\t\022\021\n\tfirstName\030\005 \001(\t\022" + + "\020\n\010lastName\030\006 \001(\t\022\020\n\010username\030\007 \001(\t\022\016\n\006q" + + "rCode\030\010 \001(\t\"\250\002\n\rErrorResponse\022+\n\005cause\030\001" + + " \001(\0162\034.account.ErrorResponse.Cause\022\017\n\007me" + + "ssage\030\002 \001(\t\"\330\001\n\005Cause\022\031\n\025INTERNAL_SERVER" + + "_ERROR\020\000\022\024\n\020MISSING_USERNAME\020\001\022\021\n\rMISSIN" + + "G_EMAIL\020\002\022\027\n\023MISSING_PHONENUMBER\020\003\022\023\n\017MI" + + "SSING_QR_CODE\020\004\022\026\n\022USERNAME_NOT_FOUND\020\005\022" + + "\023\n\017EMAIL_NOT_FOUND\020\006\022\031\n\025PHONENUMBER_NOT_" + + "FOUND\020\007\022\025\n\021QR_CODE_NOT_FOUND\020\0102^\n\rSearch" + + "Service\022M\n\020searchByUsername\022 .account.Se" + + "archByUsernameRequest\032\027.account.SearchRe" + + "sponseB$\n\025biz.nynja.search.grpcB\006SearchP" + + "\001\210\001\001b\006proto3" + }; + com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = + new com.google.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() { + public com.google.protobuf.ExtensionRegistry assignDescriptors( + com.google.protobuf.Descriptors.FileDescriptor root) { + descriptor = root; + return null; + } + }; + com.google.protobuf.Descriptors.FileDescriptor + .internalBuildGeneratedFileFrom(descriptorData, + new com.google.protobuf.Descriptors.FileDescriptor[] { + }, assigner); + internal_static_account_SearchByUsernameRequest_descriptor = + getDescriptor().getMessageTypes().get(0); + internal_static_account_SearchByUsernameRequest_fieldAccessorTable = new + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_account_SearchByUsernameRequest_descriptor, + new java.lang.String[] { "Username", }); + internal_static_account_SearchResponse_descriptor = + getDescriptor().getMessageTypes().get(1); + internal_static_account_SearchResponse_fieldAccessorTable = new + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_account_SearchResponse_descriptor, + new java.lang.String[] { "RequestId", "Error", "SearchResultDetails", "Result", }); + internal_static_account_SearchResultDetails_descriptor = + getDescriptor().getMessageTypes().get(2); + internal_static_account_SearchResultDetails_fieldAccessorTable = new + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_account_SearchResultDetails_descriptor, + new java.lang.String[] { "AccountId", "ProfileId", "AuthenticationProvider", "AuthenticationType", "FirstName", "LastName", "Username", "QrCode", }); + internal_static_account_ErrorResponse_descriptor = + getDescriptor().getMessageTypes().get(3); + internal_static_account_ErrorResponse_fieldAccessorTable = new + com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( + internal_static_account_ErrorResponse_descriptor, + new java.lang.String[] { "Cause", "Message", }); + } + + // @@protoc_insertion_point(outer_class_scope) +} diff --git a/src/main/java/biz/nynja/search/grpc/SearchByUsernameRequest.java b/src/main/java/biz/nynja/search/grpc/SearchByUsernameRequest.java new file mode 100644 index 0000000..98d0d9d --- /dev/null +++ b/src/main/java/biz/nynja/search/grpc/SearchByUsernameRequest.java @@ -0,0 +1,516 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: search.proto + +package biz.nynja.search.grpc; + +/** + * Protobuf type {@code account.SearchByUsernameRequest} + */ +public final class SearchByUsernameRequest extends + com.google.protobuf.GeneratedMessageV3 implements + // @@protoc_insertion_point(message_implements:account.SearchByUsernameRequest) + SearchByUsernameRequestOrBuilder { +private static final long serialVersionUID = 0L; + // Use SearchByUsernameRequest.newBuilder() to construct. + private SearchByUsernameRequest(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + private SearchByUsernameRequest() { + username_ = ""; + } + + @java.lang.Override + public final com.google.protobuf.UnknownFieldSet + getUnknownFields() { + return this.unknownFields; + } + private SearchByUsernameRequest( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + this(); + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + int mutable_bitField0_ = 0; + com.google.protobuf.UnknownFieldSet.Builder unknownFields = + com.google.protobuf.UnknownFieldSet.newBuilder(); + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + default: { + if (!parseUnknownFieldProto3( + input, unknownFields, extensionRegistry, tag)) { + done = true; + } + break; + } + case 10: { + java.lang.String s = input.readStringRequireUtf8(); + + username_ = s; + break; + } + } + } + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(this); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException( + e).setUnfinishedMessage(this); + } finally { + this.unknownFields = unknownFields.build(); + makeExtensionsImmutable(); + } + } + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return biz.nynja.search.grpc.Search.internal_static_account_SearchByUsernameRequest_descriptor; + } + + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return biz.nynja.search.grpc.Search.internal_static_account_SearchByUsernameRequest_fieldAccessorTable + .ensureFieldAccessorsInitialized( + biz.nynja.search.grpc.SearchByUsernameRequest.class, biz.nynja.search.grpc.SearchByUsernameRequest.Builder.class); + } + + public static final int USERNAME_FIELD_NUMBER = 1; + private volatile java.lang.Object username_; + /** + * string username = 1; + */ + public java.lang.String getUsername() { + java.lang.Object ref = username_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + username_ = s; + return s; + } + } + /** + * string username = 1; + */ + public com.google.protobuf.ByteString + getUsernameBytes() { + java.lang.Object ref = username_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + username_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + private byte memoizedIsInitialized = -1; + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + if (!getUsernameBytes().isEmpty()) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 1, username_); + } + unknownFields.writeTo(output); + } + + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (!getUsernameBytes().isEmpty()) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, username_); + } + size += unknownFields.getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof biz.nynja.search.grpc.SearchByUsernameRequest)) { + return super.equals(obj); + } + biz.nynja.search.grpc.SearchByUsernameRequest other = (biz.nynja.search.grpc.SearchByUsernameRequest) obj; + + boolean result = true; + result = result && getUsername() + .equals(other.getUsername()); + result = result && unknownFields.equals(other.unknownFields); + return result; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + hash = (37 * hash) + USERNAME_FIELD_NUMBER; + hash = (53 * hash) + getUsername().hashCode(); + hash = (29 * hash) + unknownFields.hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static biz.nynja.search.grpc.SearchByUsernameRequest parseFrom( + java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static biz.nynja.search.grpc.SearchByUsernameRequest parseFrom( + java.nio.ByteBuffer data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static biz.nynja.search.grpc.SearchByUsernameRequest parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static biz.nynja.search.grpc.SearchByUsernameRequest parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static biz.nynja.search.grpc.SearchByUsernameRequest parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static biz.nynja.search.grpc.SearchByUsernameRequest parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static biz.nynja.search.grpc.SearchByUsernameRequest parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); + } + public static biz.nynja.search.grpc.SearchByUsernameRequest parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); + } + public static biz.nynja.search.grpc.SearchByUsernameRequest parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input); + } + public static biz.nynja.search.grpc.SearchByUsernameRequest parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input, extensionRegistry); + } + public static biz.nynja.search.grpc.SearchByUsernameRequest parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); + } + public static biz.nynja.search.grpc.SearchByUsernameRequest parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); + } + + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + public static Builder newBuilder(biz.nynja.search.grpc.SearchByUsernameRequest prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + public Builder toBuilder() { + return this == DEFAULT_INSTANCE + ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * Protobuf type {@code account.SearchByUsernameRequest} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessageV3.Builder implements + // @@protoc_insertion_point(builder_implements:account.SearchByUsernameRequest) + biz.nynja.search.grpc.SearchByUsernameRequestOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return biz.nynja.search.grpc.Search.internal_static_account_SearchByUsernameRequest_descriptor; + } + + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return biz.nynja.search.grpc.Search.internal_static_account_SearchByUsernameRequest_fieldAccessorTable + .ensureFieldAccessorsInitialized( + biz.nynja.search.grpc.SearchByUsernameRequest.class, biz.nynja.search.grpc.SearchByUsernameRequest.Builder.class); + } + + // Construct using biz.nynja.search.grpc.SearchByUsernameRequest.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder( + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessageV3 + .alwaysUseFieldBuilders) { + } + } + public Builder clear() { + super.clear(); + username_ = ""; + + return this; + } + + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return biz.nynja.search.grpc.Search.internal_static_account_SearchByUsernameRequest_descriptor; + } + + public biz.nynja.search.grpc.SearchByUsernameRequest getDefaultInstanceForType() { + return biz.nynja.search.grpc.SearchByUsernameRequest.getDefaultInstance(); + } + + public biz.nynja.search.grpc.SearchByUsernameRequest build() { + biz.nynja.search.grpc.SearchByUsernameRequest result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + public biz.nynja.search.grpc.SearchByUsernameRequest buildPartial() { + biz.nynja.search.grpc.SearchByUsernameRequest result = new biz.nynja.search.grpc.SearchByUsernameRequest(this); + result.username_ = username_; + onBuilt(); + return result; + } + + public Builder clone() { + return (Builder) super.clone(); + } + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, + java.lang.Object value) { + return (Builder) super.setField(field, value); + } + public Builder clearField( + com.google.protobuf.Descriptors.FieldDescriptor field) { + return (Builder) super.clearField(field); + } + public Builder clearOneof( + com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return (Builder) super.clearOneof(oneof); + } + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + int index, java.lang.Object value) { + return (Builder) super.setRepeatedField(field, index, value); + } + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + java.lang.Object value) { + return (Builder) super.addRepeatedField(field, value); + } + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof biz.nynja.search.grpc.SearchByUsernameRequest) { + return mergeFrom((biz.nynja.search.grpc.SearchByUsernameRequest)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(biz.nynja.search.grpc.SearchByUsernameRequest other) { + if (other == biz.nynja.search.grpc.SearchByUsernameRequest.getDefaultInstance()) return this; + if (!other.getUsername().isEmpty()) { + username_ = other.username_; + onChanged(); + } + this.mergeUnknownFields(other.unknownFields); + onChanged(); + return this; + } + + public final boolean isInitialized() { + return true; + } + + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + biz.nynja.search.grpc.SearchByUsernameRequest parsedMessage = null; + try { + parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + parsedMessage = (biz.nynja.search.grpc.SearchByUsernameRequest) e.getUnfinishedMessage(); + throw e.unwrapIOException(); + } finally { + if (parsedMessage != null) { + mergeFrom(parsedMessage); + } + } + return this; + } + + private java.lang.Object username_ = ""; + /** + * string username = 1; + */ + public java.lang.String getUsername() { + java.lang.Object ref = username_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + username_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * string username = 1; + */ + public com.google.protobuf.ByteString + getUsernameBytes() { + java.lang.Object ref = username_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + username_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * string username = 1; + */ + public Builder setUsername( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + + username_ = value; + onChanged(); + return this; + } + /** + * string username = 1; + */ + public Builder clearUsername() { + + username_ = getDefaultInstance().getUsername(); + onChanged(); + return this; + } + /** + * string username = 1; + */ + public Builder setUsernameBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + + username_ = value; + onChanged(); + return this; + } + public final Builder setUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFieldsProto3(unknownFields); + } + + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + + // @@protoc_insertion_point(builder_scope:account.SearchByUsernameRequest) + } + + // @@protoc_insertion_point(class_scope:account.SearchByUsernameRequest) + private static final biz.nynja.search.grpc.SearchByUsernameRequest DEFAULT_INSTANCE; + static { + DEFAULT_INSTANCE = new biz.nynja.search.grpc.SearchByUsernameRequest(); + } + + public static biz.nynja.search.grpc.SearchByUsernameRequest getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser + PARSER = new com.google.protobuf.AbstractParser() { + public SearchByUsernameRequest parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return new SearchByUsernameRequest(input, extensionRegistry); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + public biz.nynja.search.grpc.SearchByUsernameRequest getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } + +} + diff --git a/src/main/java/biz/nynja/search/grpc/SearchByUsernameRequestOrBuilder.java b/src/main/java/biz/nynja/search/grpc/SearchByUsernameRequestOrBuilder.java new file mode 100644 index 0000000..afba29e --- /dev/null +++ b/src/main/java/biz/nynja/search/grpc/SearchByUsernameRequestOrBuilder.java @@ -0,0 +1,19 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: search.proto + +package biz.nynja.search.grpc; + +public interface SearchByUsernameRequestOrBuilder extends + // @@protoc_insertion_point(interface_extends:account.SearchByUsernameRequest) + com.google.protobuf.MessageOrBuilder { + + /** + * string username = 1; + */ + java.lang.String getUsername(); + /** + * string username = 1; + */ + com.google.protobuf.ByteString + getUsernameBytes(); +} diff --git a/src/main/java/biz/nynja/search/grpc/SearchResponse.java b/src/main/java/biz/nynja/search/grpc/SearchResponse.java new file mode 100644 index 0000000..7efeef4 --- /dev/null +++ b/src/main/java/biz/nynja/search/grpc/SearchResponse.java @@ -0,0 +1,924 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: search.proto + +package biz.nynja.search.grpc; + +/** + * Protobuf type {@code account.SearchResponse} + */ +public final class SearchResponse extends + com.google.protobuf.GeneratedMessageV3 implements + // @@protoc_insertion_point(message_implements:account.SearchResponse) + SearchResponseOrBuilder { +private static final long serialVersionUID = 0L; + // Use SearchResponse.newBuilder() to construct. + private SearchResponse(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + private SearchResponse() { + requestId_ = 0L; + } + + @java.lang.Override + public final com.google.protobuf.UnknownFieldSet + getUnknownFields() { + return this.unknownFields; + } + private SearchResponse( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + this(); + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + int mutable_bitField0_ = 0; + com.google.protobuf.UnknownFieldSet.Builder unknownFields = + com.google.protobuf.UnknownFieldSet.newBuilder(); + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + default: { + if (!parseUnknownFieldProto3( + input, unknownFields, extensionRegistry, tag)) { + done = true; + } + break; + } + case 8: { + + requestId_ = input.readUInt64(); + break; + } + case 18: { + biz.nynja.search.grpc.ErrorResponse.Builder subBuilder = null; + if (resultCase_ == 2) { + subBuilder = ((biz.nynja.search.grpc.ErrorResponse) result_).toBuilder(); + } + result_ = + input.readMessage(biz.nynja.search.grpc.ErrorResponse.parser(), extensionRegistry); + if (subBuilder != null) { + subBuilder.mergeFrom((biz.nynja.search.grpc.ErrorResponse) result_); + result_ = subBuilder.buildPartial(); + } + resultCase_ = 2; + break; + } + case 26: { + biz.nynja.search.grpc.SearchResultDetails.Builder subBuilder = null; + if (resultCase_ == 3) { + subBuilder = ((biz.nynja.search.grpc.SearchResultDetails) result_).toBuilder(); + } + result_ = + input.readMessage(biz.nynja.search.grpc.SearchResultDetails.parser(), extensionRegistry); + if (subBuilder != null) { + subBuilder.mergeFrom((biz.nynja.search.grpc.SearchResultDetails) result_); + result_ = subBuilder.buildPartial(); + } + resultCase_ = 3; + break; + } + } + } + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(this); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException( + e).setUnfinishedMessage(this); + } finally { + this.unknownFields = unknownFields.build(); + makeExtensionsImmutable(); + } + } + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return biz.nynja.search.grpc.Search.internal_static_account_SearchResponse_descriptor; + } + + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return biz.nynja.search.grpc.Search.internal_static_account_SearchResponse_fieldAccessorTable + .ensureFieldAccessorsInitialized( + biz.nynja.search.grpc.SearchResponse.class, biz.nynja.search.grpc.SearchResponse.Builder.class); + } + + private int resultCase_ = 0; + private java.lang.Object result_; + public enum ResultCase + implements com.google.protobuf.Internal.EnumLite { + ERROR(2), + SEARCHRESULTDETAILS(3), + RESULT_NOT_SET(0); + private final int value; + private ResultCase(int value) { + this.value = value; + } + /** + * @deprecated Use {@link #forNumber(int)} instead. + */ + @java.lang.Deprecated + public static ResultCase valueOf(int value) { + return forNumber(value); + } + + public static ResultCase forNumber(int value) { + switch (value) { + case 2: return ERROR; + case 3: return SEARCHRESULTDETAILS; + case 0: return RESULT_NOT_SET; + default: return null; + } + } + public int getNumber() { + return this.value; + } + }; + + public ResultCase + getResultCase() { + return ResultCase.forNumber( + resultCase_); + } + + public static final int REQUESTID_FIELD_NUMBER = 1; + private long requestId_; + /** + * uint64 requestId = 1; + */ + public long getRequestId() { + return requestId_; + } + + public static final int ERROR_FIELD_NUMBER = 2; + /** + * .account.ErrorResponse error = 2; + */ + public boolean hasError() { + return resultCase_ == 2; + } + /** + * .account.ErrorResponse error = 2; + */ + public biz.nynja.search.grpc.ErrorResponse getError() { + if (resultCase_ == 2) { + return (biz.nynja.search.grpc.ErrorResponse) result_; + } + return biz.nynja.search.grpc.ErrorResponse.getDefaultInstance(); + } + /** + * .account.ErrorResponse error = 2; + */ + public biz.nynja.search.grpc.ErrorResponseOrBuilder getErrorOrBuilder() { + if (resultCase_ == 2) { + return (biz.nynja.search.grpc.ErrorResponse) result_; + } + return biz.nynja.search.grpc.ErrorResponse.getDefaultInstance(); + } + + public static final int SEARCHRESULTDETAILS_FIELD_NUMBER = 3; + /** + * .account.SearchResultDetails searchResultDetails = 3; + */ + public boolean hasSearchResultDetails() { + return resultCase_ == 3; + } + /** + * .account.SearchResultDetails searchResultDetails = 3; + */ + public biz.nynja.search.grpc.SearchResultDetails getSearchResultDetails() { + if (resultCase_ == 3) { + return (biz.nynja.search.grpc.SearchResultDetails) result_; + } + return biz.nynja.search.grpc.SearchResultDetails.getDefaultInstance(); + } + /** + * .account.SearchResultDetails searchResultDetails = 3; + */ + public biz.nynja.search.grpc.SearchResultDetailsOrBuilder getSearchResultDetailsOrBuilder() { + if (resultCase_ == 3) { + return (biz.nynja.search.grpc.SearchResultDetails) result_; + } + return biz.nynja.search.grpc.SearchResultDetails.getDefaultInstance(); + } + + private byte memoizedIsInitialized = -1; + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + if (requestId_ != 0L) { + output.writeUInt64(1, requestId_); + } + if (resultCase_ == 2) { + output.writeMessage(2, (biz.nynja.search.grpc.ErrorResponse) result_); + } + if (resultCase_ == 3) { + output.writeMessage(3, (biz.nynja.search.grpc.SearchResultDetails) result_); + } + unknownFields.writeTo(output); + } + + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (requestId_ != 0L) { + size += com.google.protobuf.CodedOutputStream + .computeUInt64Size(1, requestId_); + } + if (resultCase_ == 2) { + size += com.google.protobuf.CodedOutputStream + .computeMessageSize(2, (biz.nynja.search.grpc.ErrorResponse) result_); + } + if (resultCase_ == 3) { + size += com.google.protobuf.CodedOutputStream + .computeMessageSize(3, (biz.nynja.search.grpc.SearchResultDetails) result_); + } + size += unknownFields.getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof biz.nynja.search.grpc.SearchResponse)) { + return super.equals(obj); + } + biz.nynja.search.grpc.SearchResponse other = (biz.nynja.search.grpc.SearchResponse) obj; + + boolean result = true; + result = result && (getRequestId() + == other.getRequestId()); + result = result && getResultCase().equals( + other.getResultCase()); + if (!result) return false; + switch (resultCase_) { + case 2: + result = result && getError() + .equals(other.getError()); + break; + case 3: + result = result && getSearchResultDetails() + .equals(other.getSearchResultDetails()); + break; + case 0: + default: + } + result = result && unknownFields.equals(other.unknownFields); + return result; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + hash = (37 * hash) + REQUESTID_FIELD_NUMBER; + hash = (53 * hash) + com.google.protobuf.Internal.hashLong( + getRequestId()); + switch (resultCase_) { + case 2: + hash = (37 * hash) + ERROR_FIELD_NUMBER; + hash = (53 * hash) + getError().hashCode(); + break; + case 3: + hash = (37 * hash) + SEARCHRESULTDETAILS_FIELD_NUMBER; + hash = (53 * hash) + getSearchResultDetails().hashCode(); + break; + case 0: + default: + } + hash = (29 * hash) + unknownFields.hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static biz.nynja.search.grpc.SearchResponse parseFrom( + java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static biz.nynja.search.grpc.SearchResponse parseFrom( + java.nio.ByteBuffer data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static biz.nynja.search.grpc.SearchResponse parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static biz.nynja.search.grpc.SearchResponse parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static biz.nynja.search.grpc.SearchResponse parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static biz.nynja.search.grpc.SearchResponse parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static biz.nynja.search.grpc.SearchResponse parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); + } + public static biz.nynja.search.grpc.SearchResponse parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); + } + public static biz.nynja.search.grpc.SearchResponse parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input); + } + public static biz.nynja.search.grpc.SearchResponse parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input, extensionRegistry); + } + public static biz.nynja.search.grpc.SearchResponse parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); + } + public static biz.nynja.search.grpc.SearchResponse parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); + } + + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + public static Builder newBuilder(biz.nynja.search.grpc.SearchResponse prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + public Builder toBuilder() { + return this == DEFAULT_INSTANCE + ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * Protobuf type {@code account.SearchResponse} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessageV3.Builder implements + // @@protoc_insertion_point(builder_implements:account.SearchResponse) + biz.nynja.search.grpc.SearchResponseOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return biz.nynja.search.grpc.Search.internal_static_account_SearchResponse_descriptor; + } + + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return biz.nynja.search.grpc.Search.internal_static_account_SearchResponse_fieldAccessorTable + .ensureFieldAccessorsInitialized( + biz.nynja.search.grpc.SearchResponse.class, biz.nynja.search.grpc.SearchResponse.Builder.class); + } + + // Construct using biz.nynja.search.grpc.SearchResponse.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder( + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessageV3 + .alwaysUseFieldBuilders) { + } + } + public Builder clear() { + super.clear(); + requestId_ = 0L; + + resultCase_ = 0; + result_ = null; + return this; + } + + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return biz.nynja.search.grpc.Search.internal_static_account_SearchResponse_descriptor; + } + + public biz.nynja.search.grpc.SearchResponse getDefaultInstanceForType() { + return biz.nynja.search.grpc.SearchResponse.getDefaultInstance(); + } + + public biz.nynja.search.grpc.SearchResponse build() { + biz.nynja.search.grpc.SearchResponse result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + public biz.nynja.search.grpc.SearchResponse buildPartial() { + biz.nynja.search.grpc.SearchResponse result = new biz.nynja.search.grpc.SearchResponse(this); + result.requestId_ = requestId_; + if (resultCase_ == 2) { + if (errorBuilder_ == null) { + result.result_ = result_; + } else { + result.result_ = errorBuilder_.build(); + } + } + if (resultCase_ == 3) { + if (searchResultDetailsBuilder_ == null) { + result.result_ = result_; + } else { + result.result_ = searchResultDetailsBuilder_.build(); + } + } + result.resultCase_ = resultCase_; + onBuilt(); + return result; + } + + public Builder clone() { + return (Builder) super.clone(); + } + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, + java.lang.Object value) { + return (Builder) super.setField(field, value); + } + public Builder clearField( + com.google.protobuf.Descriptors.FieldDescriptor field) { + return (Builder) super.clearField(field); + } + public Builder clearOneof( + com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return (Builder) super.clearOneof(oneof); + } + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + int index, java.lang.Object value) { + return (Builder) super.setRepeatedField(field, index, value); + } + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + java.lang.Object value) { + return (Builder) super.addRepeatedField(field, value); + } + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof biz.nynja.search.grpc.SearchResponse) { + return mergeFrom((biz.nynja.search.grpc.SearchResponse)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(biz.nynja.search.grpc.SearchResponse other) { + if (other == biz.nynja.search.grpc.SearchResponse.getDefaultInstance()) return this; + if (other.getRequestId() != 0L) { + setRequestId(other.getRequestId()); + } + switch (other.getResultCase()) { + case ERROR: { + mergeError(other.getError()); + break; + } + case SEARCHRESULTDETAILS: { + mergeSearchResultDetails(other.getSearchResultDetails()); + break; + } + case RESULT_NOT_SET: { + break; + } + } + this.mergeUnknownFields(other.unknownFields); + onChanged(); + return this; + } + + public final boolean isInitialized() { + return true; + } + + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + biz.nynja.search.grpc.SearchResponse parsedMessage = null; + try { + parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + parsedMessage = (biz.nynja.search.grpc.SearchResponse) e.getUnfinishedMessage(); + throw e.unwrapIOException(); + } finally { + if (parsedMessage != null) { + mergeFrom(parsedMessage); + } + } + return this; + } + private int resultCase_ = 0; + private java.lang.Object result_; + public ResultCase + getResultCase() { + return ResultCase.forNumber( + resultCase_); + } + + public Builder clearResult() { + resultCase_ = 0; + result_ = null; + onChanged(); + return this; + } + + + private long requestId_ ; + /** + * uint64 requestId = 1; + */ + public long getRequestId() { + return requestId_; + } + /** + * uint64 requestId = 1; + */ + public Builder setRequestId(long value) { + + requestId_ = value; + onChanged(); + return this; + } + /** + * uint64 requestId = 1; + */ + public Builder clearRequestId() { + + requestId_ = 0L; + onChanged(); + return this; + } + + private com.google.protobuf.SingleFieldBuilderV3< + biz.nynja.search.grpc.ErrorResponse, biz.nynja.search.grpc.ErrorResponse.Builder, biz.nynja.search.grpc.ErrorResponseOrBuilder> errorBuilder_; + /** + * .account.ErrorResponse error = 2; + */ + public boolean hasError() { + return resultCase_ == 2; + } + /** + * .account.ErrorResponse error = 2; + */ + public biz.nynja.search.grpc.ErrorResponse getError() { + if (errorBuilder_ == null) { + if (resultCase_ == 2) { + return (biz.nynja.search.grpc.ErrorResponse) result_; + } + return biz.nynja.search.grpc.ErrorResponse.getDefaultInstance(); + } else { + if (resultCase_ == 2) { + return errorBuilder_.getMessage(); + } + return biz.nynja.search.grpc.ErrorResponse.getDefaultInstance(); + } + } + /** + * .account.ErrorResponse error = 2; + */ + public Builder setError(biz.nynja.search.grpc.ErrorResponse value) { + if (errorBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + result_ = value; + onChanged(); + } else { + errorBuilder_.setMessage(value); + } + resultCase_ = 2; + return this; + } + /** + * .account.ErrorResponse error = 2; + */ + public Builder setError( + biz.nynja.search.grpc.ErrorResponse.Builder builderForValue) { + if (errorBuilder_ == null) { + result_ = builderForValue.build(); + onChanged(); + } else { + errorBuilder_.setMessage(builderForValue.build()); + } + resultCase_ = 2; + return this; + } + /** + * .account.ErrorResponse error = 2; + */ + public Builder mergeError(biz.nynja.search.grpc.ErrorResponse value) { + if (errorBuilder_ == null) { + if (resultCase_ == 2 && + result_ != biz.nynja.search.grpc.ErrorResponse.getDefaultInstance()) { + result_ = biz.nynja.search.grpc.ErrorResponse.newBuilder((biz.nynja.search.grpc.ErrorResponse) result_) + .mergeFrom(value).buildPartial(); + } else { + result_ = value; + } + onChanged(); + } else { + if (resultCase_ == 2) { + errorBuilder_.mergeFrom(value); + } + errorBuilder_.setMessage(value); + } + resultCase_ = 2; + return this; + } + /** + * .account.ErrorResponse error = 2; + */ + public Builder clearError() { + if (errorBuilder_ == null) { + if (resultCase_ == 2) { + resultCase_ = 0; + result_ = null; + onChanged(); + } + } else { + if (resultCase_ == 2) { + resultCase_ = 0; + result_ = null; + } + errorBuilder_.clear(); + } + return this; + } + /** + * .account.ErrorResponse error = 2; + */ + public biz.nynja.search.grpc.ErrorResponse.Builder getErrorBuilder() { + return getErrorFieldBuilder().getBuilder(); + } + /** + * .account.ErrorResponse error = 2; + */ + public biz.nynja.search.grpc.ErrorResponseOrBuilder getErrorOrBuilder() { + if ((resultCase_ == 2) && (errorBuilder_ != null)) { + return errorBuilder_.getMessageOrBuilder(); + } else { + if (resultCase_ == 2) { + return (biz.nynja.search.grpc.ErrorResponse) result_; + } + return biz.nynja.search.grpc.ErrorResponse.getDefaultInstance(); + } + } + /** + * .account.ErrorResponse error = 2; + */ + private com.google.protobuf.SingleFieldBuilderV3< + biz.nynja.search.grpc.ErrorResponse, biz.nynja.search.grpc.ErrorResponse.Builder, biz.nynja.search.grpc.ErrorResponseOrBuilder> + getErrorFieldBuilder() { + if (errorBuilder_ == null) { + if (!(resultCase_ == 2)) { + result_ = biz.nynja.search.grpc.ErrorResponse.getDefaultInstance(); + } + errorBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< + biz.nynja.search.grpc.ErrorResponse, biz.nynja.search.grpc.ErrorResponse.Builder, biz.nynja.search.grpc.ErrorResponseOrBuilder>( + (biz.nynja.search.grpc.ErrorResponse) result_, + getParentForChildren(), + isClean()); + result_ = null; + } + resultCase_ = 2; + onChanged();; + return errorBuilder_; + } + + private com.google.protobuf.SingleFieldBuilderV3< + biz.nynja.search.grpc.SearchResultDetails, biz.nynja.search.grpc.SearchResultDetails.Builder, biz.nynja.search.grpc.SearchResultDetailsOrBuilder> searchResultDetailsBuilder_; + /** + * .account.SearchResultDetails searchResultDetails = 3; + */ + public boolean hasSearchResultDetails() { + return resultCase_ == 3; + } + /** + * .account.SearchResultDetails searchResultDetails = 3; + */ + public biz.nynja.search.grpc.SearchResultDetails getSearchResultDetails() { + if (searchResultDetailsBuilder_ == null) { + if (resultCase_ == 3) { + return (biz.nynja.search.grpc.SearchResultDetails) result_; + } + return biz.nynja.search.grpc.SearchResultDetails.getDefaultInstance(); + } else { + if (resultCase_ == 3) { + return searchResultDetailsBuilder_.getMessage(); + } + return biz.nynja.search.grpc.SearchResultDetails.getDefaultInstance(); + } + } + /** + * .account.SearchResultDetails searchResultDetails = 3; + */ + public Builder setSearchResultDetails(biz.nynja.search.grpc.SearchResultDetails value) { + if (searchResultDetailsBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + result_ = value; + onChanged(); + } else { + searchResultDetailsBuilder_.setMessage(value); + } + resultCase_ = 3; + return this; + } + /** + * .account.SearchResultDetails searchResultDetails = 3; + */ + public Builder setSearchResultDetails( + biz.nynja.search.grpc.SearchResultDetails.Builder builderForValue) { + if (searchResultDetailsBuilder_ == null) { + result_ = builderForValue.build(); + onChanged(); + } else { + searchResultDetailsBuilder_.setMessage(builderForValue.build()); + } + resultCase_ = 3; + return this; + } + /** + * .account.SearchResultDetails searchResultDetails = 3; + */ + public Builder mergeSearchResultDetails(biz.nynja.search.grpc.SearchResultDetails value) { + if (searchResultDetailsBuilder_ == null) { + if (resultCase_ == 3 && + result_ != biz.nynja.search.grpc.SearchResultDetails.getDefaultInstance()) { + result_ = biz.nynja.search.grpc.SearchResultDetails.newBuilder((biz.nynja.search.grpc.SearchResultDetails) result_) + .mergeFrom(value).buildPartial(); + } else { + result_ = value; + } + onChanged(); + } else { + if (resultCase_ == 3) { + searchResultDetailsBuilder_.mergeFrom(value); + } + searchResultDetailsBuilder_.setMessage(value); + } + resultCase_ = 3; + return this; + } + /** + * .account.SearchResultDetails searchResultDetails = 3; + */ + public Builder clearSearchResultDetails() { + if (searchResultDetailsBuilder_ == null) { + if (resultCase_ == 3) { + resultCase_ = 0; + result_ = null; + onChanged(); + } + } else { + if (resultCase_ == 3) { + resultCase_ = 0; + result_ = null; + } + searchResultDetailsBuilder_.clear(); + } + return this; + } + /** + * .account.SearchResultDetails searchResultDetails = 3; + */ + public biz.nynja.search.grpc.SearchResultDetails.Builder getSearchResultDetailsBuilder() { + return getSearchResultDetailsFieldBuilder().getBuilder(); + } + /** + * .account.SearchResultDetails searchResultDetails = 3; + */ + public biz.nynja.search.grpc.SearchResultDetailsOrBuilder getSearchResultDetailsOrBuilder() { + if ((resultCase_ == 3) && (searchResultDetailsBuilder_ != null)) { + return searchResultDetailsBuilder_.getMessageOrBuilder(); + } else { + if (resultCase_ == 3) { + return (biz.nynja.search.grpc.SearchResultDetails) result_; + } + return biz.nynja.search.grpc.SearchResultDetails.getDefaultInstance(); + } + } + /** + * .account.SearchResultDetails searchResultDetails = 3; + */ + private com.google.protobuf.SingleFieldBuilderV3< + biz.nynja.search.grpc.SearchResultDetails, biz.nynja.search.grpc.SearchResultDetails.Builder, biz.nynja.search.grpc.SearchResultDetailsOrBuilder> + getSearchResultDetailsFieldBuilder() { + if (searchResultDetailsBuilder_ == null) { + if (!(resultCase_ == 3)) { + result_ = biz.nynja.search.grpc.SearchResultDetails.getDefaultInstance(); + } + searchResultDetailsBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< + biz.nynja.search.grpc.SearchResultDetails, biz.nynja.search.grpc.SearchResultDetails.Builder, biz.nynja.search.grpc.SearchResultDetailsOrBuilder>( + (biz.nynja.search.grpc.SearchResultDetails) result_, + getParentForChildren(), + isClean()); + result_ = null; + } + resultCase_ = 3; + onChanged();; + return searchResultDetailsBuilder_; + } + public final Builder setUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFieldsProto3(unknownFields); + } + + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + + // @@protoc_insertion_point(builder_scope:account.SearchResponse) + } + + // @@protoc_insertion_point(class_scope:account.SearchResponse) + private static final biz.nynja.search.grpc.SearchResponse DEFAULT_INSTANCE; + static { + DEFAULT_INSTANCE = new biz.nynja.search.grpc.SearchResponse(); + } + + public static biz.nynja.search.grpc.SearchResponse getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser + PARSER = new com.google.protobuf.AbstractParser() { + public SearchResponse parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return new SearchResponse(input, extensionRegistry); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + public biz.nynja.search.grpc.SearchResponse getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } + +} + diff --git a/src/main/java/biz/nynja/search/grpc/SearchResponseOrBuilder.java b/src/main/java/biz/nynja/search/grpc/SearchResponseOrBuilder.java new file mode 100644 index 0000000..1249eaa --- /dev/null +++ b/src/main/java/biz/nynja/search/grpc/SearchResponseOrBuilder.java @@ -0,0 +1,42 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: search.proto + +package biz.nynja.search.grpc; + +public interface SearchResponseOrBuilder extends + // @@protoc_insertion_point(interface_extends:account.SearchResponse) + com.google.protobuf.MessageOrBuilder { + + /** + * uint64 requestId = 1; + */ + long getRequestId(); + + /** + * .account.ErrorResponse error = 2; + */ + boolean hasError(); + /** + * .account.ErrorResponse error = 2; + */ + biz.nynja.search.grpc.ErrorResponse getError(); + /** + * .account.ErrorResponse error = 2; + */ + biz.nynja.search.grpc.ErrorResponseOrBuilder getErrorOrBuilder(); + + /** + * .account.SearchResultDetails searchResultDetails = 3; + */ + boolean hasSearchResultDetails(); + /** + * .account.SearchResultDetails searchResultDetails = 3; + */ + biz.nynja.search.grpc.SearchResultDetails getSearchResultDetails(); + /** + * .account.SearchResultDetails searchResultDetails = 3; + */ + biz.nynja.search.grpc.SearchResultDetailsOrBuilder getSearchResultDetailsOrBuilder(); + + public biz.nynja.search.grpc.SearchResponse.ResultCase getResultCase(); +} diff --git a/src/main/java/biz/nynja/search/grpc/SearchResultDetails.java b/src/main/java/biz/nynja/search/grpc/SearchResultDetails.java new file mode 100644 index 0000000..5191524 --- /dev/null +++ b/src/main/java/biz/nynja/search/grpc/SearchResultDetails.java @@ -0,0 +1,1405 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: search.proto + +package biz.nynja.search.grpc; + +/** + * Protobuf type {@code account.SearchResultDetails} + */ +public final class SearchResultDetails extends + com.google.protobuf.GeneratedMessageV3 implements + // @@protoc_insertion_point(message_implements:account.SearchResultDetails) + SearchResultDetailsOrBuilder { +private static final long serialVersionUID = 0L; + // Use SearchResultDetails.newBuilder() to construct. + private SearchResultDetails(com.google.protobuf.GeneratedMessageV3.Builder builder) { + super(builder); + } + private SearchResultDetails() { + accountId_ = ""; + profileId_ = ""; + authenticationProvider_ = ""; + authenticationType_ = ""; + firstName_ = ""; + lastName_ = ""; + username_ = ""; + qrCode_ = ""; + } + + @java.lang.Override + public final com.google.protobuf.UnknownFieldSet + getUnknownFields() { + return this.unknownFields; + } + private SearchResultDetails( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + this(); + if (extensionRegistry == null) { + throw new java.lang.NullPointerException(); + } + int mutable_bitField0_ = 0; + com.google.protobuf.UnknownFieldSet.Builder unknownFields = + com.google.protobuf.UnknownFieldSet.newBuilder(); + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + default: { + if (!parseUnknownFieldProto3( + input, unknownFields, extensionRegistry, tag)) { + done = true; + } + break; + } + case 10: { + java.lang.String s = input.readStringRequireUtf8(); + + accountId_ = s; + break; + } + case 18: { + java.lang.String s = input.readStringRequireUtf8(); + + profileId_ = s; + break; + } + case 26: { + java.lang.String s = input.readStringRequireUtf8(); + + authenticationProvider_ = s; + break; + } + case 34: { + java.lang.String s = input.readStringRequireUtf8(); + + authenticationType_ = s; + break; + } + case 42: { + java.lang.String s = input.readStringRequireUtf8(); + + firstName_ = s; + break; + } + case 50: { + java.lang.String s = input.readStringRequireUtf8(); + + lastName_ = s; + break; + } + case 58: { + java.lang.String s = input.readStringRequireUtf8(); + + username_ = s; + break; + } + case 66: { + java.lang.String s = input.readStringRequireUtf8(); + + qrCode_ = s; + break; + } + } + } + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(this); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException( + e).setUnfinishedMessage(this); + } finally { + this.unknownFields = unknownFields.build(); + makeExtensionsImmutable(); + } + } + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return biz.nynja.search.grpc.Search.internal_static_account_SearchResultDetails_descriptor; + } + + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return biz.nynja.search.grpc.Search.internal_static_account_SearchResultDetails_fieldAccessorTable + .ensureFieldAccessorsInitialized( + biz.nynja.search.grpc.SearchResultDetails.class, biz.nynja.search.grpc.SearchResultDetails.Builder.class); + } + + public static final int ACCOUNTID_FIELD_NUMBER = 1; + private volatile java.lang.Object accountId_; + /** + * string accountId = 1; + */ + public java.lang.String getAccountId() { + java.lang.Object ref = accountId_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + accountId_ = s; + return s; + } + } + /** + * string accountId = 1; + */ + public com.google.protobuf.ByteString + getAccountIdBytes() { + java.lang.Object ref = accountId_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + accountId_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int PROFILEID_FIELD_NUMBER = 2; + private volatile java.lang.Object profileId_; + /** + * string profileId = 2; + */ + public java.lang.String getProfileId() { + java.lang.Object ref = profileId_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + profileId_ = s; + return s; + } + } + /** + * string profileId = 2; + */ + public com.google.protobuf.ByteString + getProfileIdBytes() { + java.lang.Object ref = profileId_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + profileId_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int AUTHENTICATIONPROVIDER_FIELD_NUMBER = 3; + private volatile java.lang.Object authenticationProvider_; + /** + * string authenticationProvider = 3; + */ + public java.lang.String getAuthenticationProvider() { + java.lang.Object ref = authenticationProvider_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + authenticationProvider_ = s; + return s; + } + } + /** + * string authenticationProvider = 3; + */ + public com.google.protobuf.ByteString + getAuthenticationProviderBytes() { + java.lang.Object ref = authenticationProvider_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + authenticationProvider_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int AUTHENTICATIONTYPE_FIELD_NUMBER = 4; + private volatile java.lang.Object authenticationType_; + /** + * string authenticationType = 4; + */ + public java.lang.String getAuthenticationType() { + java.lang.Object ref = authenticationType_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + authenticationType_ = s; + return s; + } + } + /** + * string authenticationType = 4; + */ + public com.google.protobuf.ByteString + getAuthenticationTypeBytes() { + java.lang.Object ref = authenticationType_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + authenticationType_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int FIRSTNAME_FIELD_NUMBER = 5; + private volatile java.lang.Object firstName_; + /** + * string firstName = 5; + */ + public java.lang.String getFirstName() { + java.lang.Object ref = firstName_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + firstName_ = s; + return s; + } + } + /** + * string firstName = 5; + */ + public com.google.protobuf.ByteString + getFirstNameBytes() { + java.lang.Object ref = firstName_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + firstName_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int LASTNAME_FIELD_NUMBER = 6; + private volatile java.lang.Object lastName_; + /** + * string lastName = 6; + */ + public java.lang.String getLastName() { + java.lang.Object ref = lastName_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + lastName_ = s; + return s; + } + } + /** + * string lastName = 6; + */ + public com.google.protobuf.ByteString + getLastNameBytes() { + java.lang.Object ref = lastName_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + lastName_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int USERNAME_FIELD_NUMBER = 7; + private volatile java.lang.Object username_; + /** + * string username = 7; + */ + public java.lang.String getUsername() { + java.lang.Object ref = username_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + username_ = s; + return s; + } + } + /** + * string username = 7; + */ + public com.google.protobuf.ByteString + getUsernameBytes() { + java.lang.Object ref = username_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + username_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int QRCODE_FIELD_NUMBER = 8; + private volatile java.lang.Object qrCode_; + /** + * string qrCode = 8; + */ + public java.lang.String getQrCode() { + java.lang.Object ref = qrCode_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + qrCode_ = s; + return s; + } + } + /** + * string qrCode = 8; + */ + public com.google.protobuf.ByteString + getQrCodeBytes() { + java.lang.Object ref = qrCode_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + qrCode_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + private byte memoizedIsInitialized = -1; + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + if (!getAccountIdBytes().isEmpty()) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 1, accountId_); + } + if (!getProfileIdBytes().isEmpty()) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 2, profileId_); + } + if (!getAuthenticationProviderBytes().isEmpty()) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 3, authenticationProvider_); + } + if (!getAuthenticationTypeBytes().isEmpty()) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 4, authenticationType_); + } + if (!getFirstNameBytes().isEmpty()) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 5, firstName_); + } + if (!getLastNameBytes().isEmpty()) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 6, lastName_); + } + if (!getUsernameBytes().isEmpty()) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 7, username_); + } + if (!getQrCodeBytes().isEmpty()) { + com.google.protobuf.GeneratedMessageV3.writeString(output, 8, qrCode_); + } + unknownFields.writeTo(output); + } + + public int getSerializedSize() { + int size = memoizedSize; + if (size != -1) return size; + + size = 0; + if (!getAccountIdBytes().isEmpty()) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, accountId_); + } + if (!getProfileIdBytes().isEmpty()) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, profileId_); + } + if (!getAuthenticationProviderBytes().isEmpty()) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(3, authenticationProvider_); + } + if (!getAuthenticationTypeBytes().isEmpty()) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(4, authenticationType_); + } + if (!getFirstNameBytes().isEmpty()) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(5, firstName_); + } + if (!getLastNameBytes().isEmpty()) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(6, lastName_); + } + if (!getUsernameBytes().isEmpty()) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(7, username_); + } + if (!getQrCodeBytes().isEmpty()) { + size += com.google.protobuf.GeneratedMessageV3.computeStringSize(8, qrCode_); + } + size += unknownFields.getSerializedSize(); + memoizedSize = size; + return size; + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof biz.nynja.search.grpc.SearchResultDetails)) { + return super.equals(obj); + } + biz.nynja.search.grpc.SearchResultDetails other = (biz.nynja.search.grpc.SearchResultDetails) obj; + + boolean result = true; + result = result && getAccountId() + .equals(other.getAccountId()); + result = result && getProfileId() + .equals(other.getProfileId()); + result = result && getAuthenticationProvider() + .equals(other.getAuthenticationProvider()); + result = result && getAuthenticationType() + .equals(other.getAuthenticationType()); + result = result && getFirstName() + .equals(other.getFirstName()); + result = result && getLastName() + .equals(other.getLastName()); + result = result && getUsername() + .equals(other.getUsername()); + result = result && getQrCode() + .equals(other.getQrCode()); + result = result && unknownFields.equals(other.unknownFields); + return result; + } + + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptor().hashCode(); + hash = (37 * hash) + ACCOUNTID_FIELD_NUMBER; + hash = (53 * hash) + getAccountId().hashCode(); + hash = (37 * hash) + PROFILEID_FIELD_NUMBER; + hash = (53 * hash) + getProfileId().hashCode(); + hash = (37 * hash) + AUTHENTICATIONPROVIDER_FIELD_NUMBER; + hash = (53 * hash) + getAuthenticationProvider().hashCode(); + hash = (37 * hash) + AUTHENTICATIONTYPE_FIELD_NUMBER; + hash = (53 * hash) + getAuthenticationType().hashCode(); + hash = (37 * hash) + FIRSTNAME_FIELD_NUMBER; + hash = (53 * hash) + getFirstName().hashCode(); + hash = (37 * hash) + LASTNAME_FIELD_NUMBER; + hash = (53 * hash) + getLastName().hashCode(); + hash = (37 * hash) + USERNAME_FIELD_NUMBER; + hash = (53 * hash) + getUsername().hashCode(); + hash = (37 * hash) + QRCODE_FIELD_NUMBER; + hash = (53 * hash) + getQrCode().hashCode(); + hash = (29 * hash) + unknownFields.hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static biz.nynja.search.grpc.SearchResultDetails parseFrom( + java.nio.ByteBuffer data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static biz.nynja.search.grpc.SearchResultDetails parseFrom( + java.nio.ByteBuffer data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static biz.nynja.search.grpc.SearchResultDetails parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static biz.nynja.search.grpc.SearchResultDetails parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static biz.nynja.search.grpc.SearchResultDetails parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static biz.nynja.search.grpc.SearchResultDetails parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static biz.nynja.search.grpc.SearchResultDetails parseFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); + } + public static biz.nynja.search.grpc.SearchResultDetails parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); + } + public static biz.nynja.search.grpc.SearchResultDetails parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input); + } + public static biz.nynja.search.grpc.SearchResultDetails parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseDelimitedWithIOException(PARSER, input, extensionRegistry); + } + public static biz.nynja.search.grpc.SearchResultDetails parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input); + } + public static biz.nynja.search.grpc.SearchResultDetails parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return com.google.protobuf.GeneratedMessageV3 + .parseWithIOException(PARSER, input, extensionRegistry); + } + + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder() { + return DEFAULT_INSTANCE.toBuilder(); + } + public static Builder newBuilder(biz.nynja.search.grpc.SearchResultDetails prototype) { + return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); + } + public Builder toBuilder() { + return this == DEFAULT_INSTANCE + ? new Builder() : new Builder().mergeFrom(this); + } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * Protobuf type {@code account.SearchResultDetails} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessageV3.Builder implements + // @@protoc_insertion_point(builder_implements:account.SearchResultDetails) + biz.nynja.search.grpc.SearchResultDetailsOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return biz.nynja.search.grpc.Search.internal_static_account_SearchResultDetails_descriptor; + } + + protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable + internalGetFieldAccessorTable() { + return biz.nynja.search.grpc.Search.internal_static_account_SearchResultDetails_fieldAccessorTable + .ensureFieldAccessorsInitialized( + biz.nynja.search.grpc.SearchResultDetails.class, biz.nynja.search.grpc.SearchResultDetails.Builder.class); + } + + // Construct using biz.nynja.search.grpc.SearchResultDetails.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder( + com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessageV3 + .alwaysUseFieldBuilders) { + } + } + public Builder clear() { + super.clear(); + accountId_ = ""; + + profileId_ = ""; + + authenticationProvider_ = ""; + + authenticationType_ = ""; + + firstName_ = ""; + + lastName_ = ""; + + username_ = ""; + + qrCode_ = ""; + + return this; + } + + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return biz.nynja.search.grpc.Search.internal_static_account_SearchResultDetails_descriptor; + } + + public biz.nynja.search.grpc.SearchResultDetails getDefaultInstanceForType() { + return biz.nynja.search.grpc.SearchResultDetails.getDefaultInstance(); + } + + public biz.nynja.search.grpc.SearchResultDetails build() { + biz.nynja.search.grpc.SearchResultDetails result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + public biz.nynja.search.grpc.SearchResultDetails buildPartial() { + biz.nynja.search.grpc.SearchResultDetails result = new biz.nynja.search.grpc.SearchResultDetails(this); + result.accountId_ = accountId_; + result.profileId_ = profileId_; + result.authenticationProvider_ = authenticationProvider_; + result.authenticationType_ = authenticationType_; + result.firstName_ = firstName_; + result.lastName_ = lastName_; + result.username_ = username_; + result.qrCode_ = qrCode_; + onBuilt(); + return result; + } + + public Builder clone() { + return (Builder) super.clone(); + } + public Builder setField( + com.google.protobuf.Descriptors.FieldDescriptor field, + java.lang.Object value) { + return (Builder) super.setField(field, value); + } + public Builder clearField( + com.google.protobuf.Descriptors.FieldDescriptor field) { + return (Builder) super.clearField(field); + } + public Builder clearOneof( + com.google.protobuf.Descriptors.OneofDescriptor oneof) { + return (Builder) super.clearOneof(oneof); + } + public Builder setRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + int index, java.lang.Object value) { + return (Builder) super.setRepeatedField(field, index, value); + } + public Builder addRepeatedField( + com.google.protobuf.Descriptors.FieldDescriptor field, + java.lang.Object value) { + return (Builder) super.addRepeatedField(field, value); + } + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof biz.nynja.search.grpc.SearchResultDetails) { + return mergeFrom((biz.nynja.search.grpc.SearchResultDetails)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(biz.nynja.search.grpc.SearchResultDetails other) { + if (other == biz.nynja.search.grpc.SearchResultDetails.getDefaultInstance()) return this; + if (!other.getAccountId().isEmpty()) { + accountId_ = other.accountId_; + onChanged(); + } + if (!other.getProfileId().isEmpty()) { + profileId_ = other.profileId_; + onChanged(); + } + if (!other.getAuthenticationProvider().isEmpty()) { + authenticationProvider_ = other.authenticationProvider_; + onChanged(); + } + if (!other.getAuthenticationType().isEmpty()) { + authenticationType_ = other.authenticationType_; + onChanged(); + } + if (!other.getFirstName().isEmpty()) { + firstName_ = other.firstName_; + onChanged(); + } + if (!other.getLastName().isEmpty()) { + lastName_ = other.lastName_; + onChanged(); + } + if (!other.getUsername().isEmpty()) { + username_ = other.username_; + onChanged(); + } + if (!other.getQrCode().isEmpty()) { + qrCode_ = other.qrCode_; + onChanged(); + } + this.mergeUnknownFields(other.unknownFields); + onChanged(); + return this; + } + + public final boolean isInitialized() { + return true; + } + + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + biz.nynja.search.grpc.SearchResultDetails parsedMessage = null; + try { + parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + parsedMessage = (biz.nynja.search.grpc.SearchResultDetails) e.getUnfinishedMessage(); + throw e.unwrapIOException(); + } finally { + if (parsedMessage != null) { + mergeFrom(parsedMessage); + } + } + return this; + } + + private java.lang.Object accountId_ = ""; + /** + * string accountId = 1; + */ + public java.lang.String getAccountId() { + java.lang.Object ref = accountId_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + accountId_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * string accountId = 1; + */ + public com.google.protobuf.ByteString + getAccountIdBytes() { + java.lang.Object ref = accountId_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + accountId_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * string accountId = 1; + */ + public Builder setAccountId( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + + accountId_ = value; + onChanged(); + return this; + } + /** + * string accountId = 1; + */ + public Builder clearAccountId() { + + accountId_ = getDefaultInstance().getAccountId(); + onChanged(); + return this; + } + /** + * string accountId = 1; + */ + public Builder setAccountIdBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + + accountId_ = value; + onChanged(); + return this; + } + + private java.lang.Object profileId_ = ""; + /** + * string profileId = 2; + */ + public java.lang.String getProfileId() { + java.lang.Object ref = profileId_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + profileId_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * string profileId = 2; + */ + public com.google.protobuf.ByteString + getProfileIdBytes() { + java.lang.Object ref = profileId_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + profileId_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * string profileId = 2; + */ + public Builder setProfileId( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + + profileId_ = value; + onChanged(); + return this; + } + /** + * string profileId = 2; + */ + public Builder clearProfileId() { + + profileId_ = getDefaultInstance().getProfileId(); + onChanged(); + return this; + } + /** + * string profileId = 2; + */ + public Builder setProfileIdBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + + profileId_ = value; + onChanged(); + return this; + } + + private java.lang.Object authenticationProvider_ = ""; + /** + * string authenticationProvider = 3; + */ + public java.lang.String getAuthenticationProvider() { + java.lang.Object ref = authenticationProvider_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + authenticationProvider_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * string authenticationProvider = 3; + */ + public com.google.protobuf.ByteString + getAuthenticationProviderBytes() { + java.lang.Object ref = authenticationProvider_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + authenticationProvider_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * string authenticationProvider = 3; + */ + public Builder setAuthenticationProvider( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + + authenticationProvider_ = value; + onChanged(); + return this; + } + /** + * string authenticationProvider = 3; + */ + public Builder clearAuthenticationProvider() { + + authenticationProvider_ = getDefaultInstance().getAuthenticationProvider(); + onChanged(); + return this; + } + /** + * string authenticationProvider = 3; + */ + public Builder setAuthenticationProviderBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + + authenticationProvider_ = value; + onChanged(); + return this; + } + + private java.lang.Object authenticationType_ = ""; + /** + * string authenticationType = 4; + */ + public java.lang.String getAuthenticationType() { + java.lang.Object ref = authenticationType_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + authenticationType_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * string authenticationType = 4; + */ + public com.google.protobuf.ByteString + getAuthenticationTypeBytes() { + java.lang.Object ref = authenticationType_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + authenticationType_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * string authenticationType = 4; + */ + public Builder setAuthenticationType( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + + authenticationType_ = value; + onChanged(); + return this; + } + /** + * string authenticationType = 4; + */ + public Builder clearAuthenticationType() { + + authenticationType_ = getDefaultInstance().getAuthenticationType(); + onChanged(); + return this; + } + /** + * string authenticationType = 4; + */ + public Builder setAuthenticationTypeBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + + authenticationType_ = value; + onChanged(); + return this; + } + + private java.lang.Object firstName_ = ""; + /** + * string firstName = 5; + */ + public java.lang.String getFirstName() { + java.lang.Object ref = firstName_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + firstName_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * string firstName = 5; + */ + public com.google.protobuf.ByteString + getFirstNameBytes() { + java.lang.Object ref = firstName_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + firstName_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * string firstName = 5; + */ + public Builder setFirstName( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + + firstName_ = value; + onChanged(); + return this; + } + /** + * string firstName = 5; + */ + public Builder clearFirstName() { + + firstName_ = getDefaultInstance().getFirstName(); + onChanged(); + return this; + } + /** + * string firstName = 5; + */ + public Builder setFirstNameBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + + firstName_ = value; + onChanged(); + return this; + } + + private java.lang.Object lastName_ = ""; + /** + * string lastName = 6; + */ + public java.lang.String getLastName() { + java.lang.Object ref = lastName_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + lastName_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * string lastName = 6; + */ + public com.google.protobuf.ByteString + getLastNameBytes() { + java.lang.Object ref = lastName_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + lastName_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * string lastName = 6; + */ + public Builder setLastName( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + + lastName_ = value; + onChanged(); + return this; + } + /** + * string lastName = 6; + */ + public Builder clearLastName() { + + lastName_ = getDefaultInstance().getLastName(); + onChanged(); + return this; + } + /** + * string lastName = 6; + */ + public Builder setLastNameBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + + lastName_ = value; + onChanged(); + return this; + } + + private java.lang.Object username_ = ""; + /** + * string username = 7; + */ + public java.lang.String getUsername() { + java.lang.Object ref = username_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + username_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * string username = 7; + */ + public com.google.protobuf.ByteString + getUsernameBytes() { + java.lang.Object ref = username_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + username_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * string username = 7; + */ + public Builder setUsername( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + + username_ = value; + onChanged(); + return this; + } + /** + * string username = 7; + */ + public Builder clearUsername() { + + username_ = getDefaultInstance().getUsername(); + onChanged(); + return this; + } + /** + * string username = 7; + */ + public Builder setUsernameBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + + username_ = value; + onChanged(); + return this; + } + + private java.lang.Object qrCode_ = ""; + /** + * string qrCode = 8; + */ + public java.lang.String getQrCode() { + java.lang.Object ref = qrCode_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + qrCode_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * string qrCode = 8; + */ + public com.google.protobuf.ByteString + getQrCodeBytes() { + java.lang.Object ref = qrCode_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + qrCode_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * string qrCode = 8; + */ + public Builder setQrCode( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + + qrCode_ = value; + onChanged(); + return this; + } + /** + * string qrCode = 8; + */ + public Builder clearQrCode() { + + qrCode_ = getDefaultInstance().getQrCode(); + onChanged(); + return this; + } + /** + * string qrCode = 8; + */ + public Builder setQrCodeBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + checkByteStringIsUtf8(value); + + qrCode_ = value; + onChanged(); + return this; + } + public final Builder setUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.setUnknownFieldsProto3(unknownFields); + } + + public final Builder mergeUnknownFields( + final com.google.protobuf.UnknownFieldSet unknownFields) { + return super.mergeUnknownFields(unknownFields); + } + + + // @@protoc_insertion_point(builder_scope:account.SearchResultDetails) + } + + // @@protoc_insertion_point(class_scope:account.SearchResultDetails) + private static final biz.nynja.search.grpc.SearchResultDetails DEFAULT_INSTANCE; + static { + DEFAULT_INSTANCE = new biz.nynja.search.grpc.SearchResultDetails(); + } + + public static biz.nynja.search.grpc.SearchResultDetails getDefaultInstance() { + return DEFAULT_INSTANCE; + } + + private static final com.google.protobuf.Parser + PARSER = new com.google.protobuf.AbstractParser() { + public SearchResultDetails parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return new SearchResultDetails(input, extensionRegistry); + } + }; + + public static com.google.protobuf.Parser parser() { + return PARSER; + } + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + public biz.nynja.search.grpc.SearchResultDetails getDefaultInstanceForType() { + return DEFAULT_INSTANCE; + } + +} + diff --git a/src/main/java/biz/nynja/search/grpc/SearchResultDetailsOrBuilder.java b/src/main/java/biz/nynja/search/grpc/SearchResultDetailsOrBuilder.java new file mode 100644 index 0000000..1541d2d --- /dev/null +++ b/src/main/java/biz/nynja/search/grpc/SearchResultDetailsOrBuilder.java @@ -0,0 +1,89 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: search.proto + +package biz.nynja.search.grpc; + +public interface SearchResultDetailsOrBuilder extends + // @@protoc_insertion_point(interface_extends:account.SearchResultDetails) + com.google.protobuf.MessageOrBuilder { + + /** + * string accountId = 1; + */ + java.lang.String getAccountId(); + /** + * string accountId = 1; + */ + com.google.protobuf.ByteString + getAccountIdBytes(); + + /** + * string profileId = 2; + */ + java.lang.String getProfileId(); + /** + * string profileId = 2; + */ + com.google.protobuf.ByteString + getProfileIdBytes(); + + /** + * string authenticationProvider = 3; + */ + java.lang.String getAuthenticationProvider(); + /** + * string authenticationProvider = 3; + */ + com.google.protobuf.ByteString + getAuthenticationProviderBytes(); + + /** + * string authenticationType = 4; + */ + java.lang.String getAuthenticationType(); + /** + * string authenticationType = 4; + */ + com.google.protobuf.ByteString + getAuthenticationTypeBytes(); + + /** + * string firstName = 5; + */ + java.lang.String getFirstName(); + /** + * string firstName = 5; + */ + com.google.protobuf.ByteString + getFirstNameBytes(); + + /** + * string lastName = 6; + */ + java.lang.String getLastName(); + /** + * string lastName = 6; + */ + com.google.protobuf.ByteString + getLastNameBytes(); + + /** + * string username = 7; + */ + java.lang.String getUsername(); + /** + * string username = 7; + */ + com.google.protobuf.ByteString + getUsernameBytes(); + + /** + * string qrCode = 8; + */ + java.lang.String getQrCode(); + /** + * string qrCode = 8; + */ + com.google.protobuf.ByteString + getQrCodeBytes(); +} diff --git a/src/main/java/biz/nynja/search/grpc/SearchService.java b/src/main/java/biz/nynja/search/grpc/SearchService.java new file mode 100644 index 0000000..6fdbe5c --- /dev/null +++ b/src/main/java/biz/nynja/search/grpc/SearchService.java @@ -0,0 +1,237 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: search.proto + +package biz.nynja.search.grpc; + +/** + * Protobuf service {@code account.SearchService} + */ +public abstract class SearchService + implements com.google.protobuf.Service { + protected SearchService() {} + + public interface Interface { + /** + * rpc searchByUsername(.account.SearchByUsernameRequest) returns (.account.SearchResponse); + */ + public abstract void searchByUsername( + com.google.protobuf.RpcController controller, + biz.nynja.search.grpc.SearchByUsernameRequest request, + com.google.protobuf.RpcCallback done); + + } + + public static com.google.protobuf.Service newReflectiveService( + final Interface impl) { + return new SearchService() { + @java.lang.Override + public void searchByUsername( + com.google.protobuf.RpcController controller, + biz.nynja.search.grpc.SearchByUsernameRequest request, + com.google.protobuf.RpcCallback done) { + impl.searchByUsername(controller, request, done); + } + + }; + } + + public static com.google.protobuf.BlockingService + newReflectiveBlockingService(final BlockingInterface impl) { + return new com.google.protobuf.BlockingService() { + public final com.google.protobuf.Descriptors.ServiceDescriptor + getDescriptorForType() { + return getDescriptor(); + } + + public final com.google.protobuf.Message callBlockingMethod( + com.google.protobuf.Descriptors.MethodDescriptor method, + com.google.protobuf.RpcController controller, + com.google.protobuf.Message request) + throws com.google.protobuf.ServiceException { + if (method.getService() != getDescriptor()) { + throw new java.lang.IllegalArgumentException( + "Service.callBlockingMethod() given method descriptor for " + + "wrong service type."); + } + switch(method.getIndex()) { + case 0: + return impl.searchByUsername(controller, (biz.nynja.search.grpc.SearchByUsernameRequest)request); + default: + throw new java.lang.AssertionError("Can't get here."); + } + } + + public final com.google.protobuf.Message + getRequestPrototype( + com.google.protobuf.Descriptors.MethodDescriptor method) { + if (method.getService() != getDescriptor()) { + throw new java.lang.IllegalArgumentException( + "Service.getRequestPrototype() given method " + + "descriptor for wrong service type."); + } + switch(method.getIndex()) { + case 0: + return biz.nynja.search.grpc.SearchByUsernameRequest.getDefaultInstance(); + default: + throw new java.lang.AssertionError("Can't get here."); + } + } + + public final com.google.protobuf.Message + getResponsePrototype( + com.google.protobuf.Descriptors.MethodDescriptor method) { + if (method.getService() != getDescriptor()) { + throw new java.lang.IllegalArgumentException( + "Service.getResponsePrototype() given method " + + "descriptor for wrong service type."); + } + switch(method.getIndex()) { + case 0: + return biz.nynja.search.grpc.SearchResponse.getDefaultInstance(); + default: + throw new java.lang.AssertionError("Can't get here."); + } + } + + }; + } + + /** + * rpc searchByUsername(.account.SearchByUsernameRequest) returns (.account.SearchResponse); + */ + public abstract void searchByUsername( + com.google.protobuf.RpcController controller, + biz.nynja.search.grpc.SearchByUsernameRequest request, + com.google.protobuf.RpcCallback done); + + public static final + com.google.protobuf.Descriptors.ServiceDescriptor + getDescriptor() { + return biz.nynja.search.grpc.Search.getDescriptor().getServices().get(0); + } + public final com.google.protobuf.Descriptors.ServiceDescriptor + getDescriptorForType() { + return getDescriptor(); + } + + public final void callMethod( + com.google.protobuf.Descriptors.MethodDescriptor method, + com.google.protobuf.RpcController controller, + com.google.protobuf.Message request, + com.google.protobuf.RpcCallback< + com.google.protobuf.Message> done) { + if (method.getService() != getDescriptor()) { + throw new java.lang.IllegalArgumentException( + "Service.callMethod() given method descriptor for wrong " + + "service type."); + } + switch(method.getIndex()) { + case 0: + this.searchByUsername(controller, (biz.nynja.search.grpc.SearchByUsernameRequest)request, + com.google.protobuf.RpcUtil.specializeCallback( + done)); + return; + default: + throw new java.lang.AssertionError("Can't get here."); + } + } + + public final com.google.protobuf.Message + getRequestPrototype( + com.google.protobuf.Descriptors.MethodDescriptor method) { + if (method.getService() != getDescriptor()) { + throw new java.lang.IllegalArgumentException( + "Service.getRequestPrototype() given method " + + "descriptor for wrong service type."); + } + switch(method.getIndex()) { + case 0: + return biz.nynja.search.grpc.SearchByUsernameRequest.getDefaultInstance(); + default: + throw new java.lang.AssertionError("Can't get here."); + } + } + + public final com.google.protobuf.Message + getResponsePrototype( + com.google.protobuf.Descriptors.MethodDescriptor method) { + if (method.getService() != getDescriptor()) { + throw new java.lang.IllegalArgumentException( + "Service.getResponsePrototype() given method " + + "descriptor for wrong service type."); + } + switch(method.getIndex()) { + case 0: + return biz.nynja.search.grpc.SearchResponse.getDefaultInstance(); + default: + throw new java.lang.AssertionError("Can't get here."); + } + } + + public static Stub newStub( + com.google.protobuf.RpcChannel channel) { + return new Stub(channel); + } + + public static final class Stub extends biz.nynja.search.grpc.SearchService implements Interface { + private Stub(com.google.protobuf.RpcChannel channel) { + this.channel = channel; + } + + private final com.google.protobuf.RpcChannel channel; + + public com.google.protobuf.RpcChannel getChannel() { + return channel; + } + + public void searchByUsername( + com.google.protobuf.RpcController controller, + biz.nynja.search.grpc.SearchByUsernameRequest request, + com.google.protobuf.RpcCallback done) { + channel.callMethod( + getDescriptor().getMethods().get(0), + controller, + request, + biz.nynja.search.grpc.SearchResponse.getDefaultInstance(), + com.google.protobuf.RpcUtil.generalizeCallback( + done, + biz.nynja.search.grpc.SearchResponse.class, + biz.nynja.search.grpc.SearchResponse.getDefaultInstance())); + } + } + + public static BlockingInterface newBlockingStub( + com.google.protobuf.BlockingRpcChannel channel) { + return new BlockingStub(channel); + } + + public interface BlockingInterface { + public biz.nynja.search.grpc.SearchResponse searchByUsername( + com.google.protobuf.RpcController controller, + biz.nynja.search.grpc.SearchByUsernameRequest request) + throws com.google.protobuf.ServiceException; + } + + private static final class BlockingStub implements BlockingInterface { + private BlockingStub(com.google.protobuf.BlockingRpcChannel channel) { + this.channel = channel; + } + + private final com.google.protobuf.BlockingRpcChannel channel; + + public biz.nynja.search.grpc.SearchResponse searchByUsername( + com.google.protobuf.RpcController controller, + biz.nynja.search.grpc.SearchByUsernameRequest request) + throws com.google.protobuf.ServiceException { + return (biz.nynja.search.grpc.SearchResponse) channel.callBlockingMethod( + getDescriptor().getMethods().get(0), + controller, + request, + biz.nynja.search.grpc.SearchResponse.getDefaultInstance()); + } + + } + + // @@protoc_insertion_point(class_scope:account.SearchService) +} + diff --git a/src/main/java/biz/nynja/search/grpc/SearchServiceGrpc.java b/src/main/java/biz/nynja/search/grpc/SearchServiceGrpc.java new file mode 100644 index 0000000..b7654c8 --- /dev/null +++ b/src/main/java/biz/nynja/search/grpc/SearchServiceGrpc.java @@ -0,0 +1,286 @@ +package biz.nynja.search.grpc; + +import static io.grpc.MethodDescriptor.generateFullMethodName; +import static io.grpc.stub.ClientCalls.asyncBidiStreamingCall; +import static io.grpc.stub.ClientCalls.asyncClientStreamingCall; +import static io.grpc.stub.ClientCalls.asyncServerStreamingCall; +import static io.grpc.stub.ClientCalls.asyncUnaryCall; +import static io.grpc.stub.ClientCalls.blockingServerStreamingCall; +import static io.grpc.stub.ClientCalls.blockingUnaryCall; +import static io.grpc.stub.ClientCalls.futureUnaryCall; +import static io.grpc.stub.ServerCalls.asyncBidiStreamingCall; +import static io.grpc.stub.ServerCalls.asyncClientStreamingCall; +import static io.grpc.stub.ServerCalls.asyncServerStreamingCall; +import static io.grpc.stub.ServerCalls.asyncUnaryCall; +import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall; +import static io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall; + +/** + */ +@javax.annotation.Generated( + value = "by gRPC proto compiler (version 1.11.0)", + comments = "Source: search.proto") +public final class SearchServiceGrpc { + + private SearchServiceGrpc() {} + + public static final String SERVICE_NAME = "account.SearchService"; + + // Static method descriptors that strictly reflect the proto. + @io.grpc.ExperimentalApi("https://github.com/grpc/grpc-java/issues/1901") + @java.lang.Deprecated // Use {@link #getSearchByUsernameMethod()} instead. + public static final io.grpc.MethodDescriptor METHOD_SEARCH_BY_USERNAME = getSearchByUsernameMethodHelper(); + + private static volatile io.grpc.MethodDescriptor getSearchByUsernameMethod; + + @io.grpc.ExperimentalApi("https://github.com/grpc/grpc-java/issues/1901") + public static io.grpc.MethodDescriptor getSearchByUsernameMethod() { + return getSearchByUsernameMethodHelper(); + } + + private static io.grpc.MethodDescriptor getSearchByUsernameMethodHelper() { + io.grpc.MethodDescriptor getSearchByUsernameMethod; + if ((getSearchByUsernameMethod = SearchServiceGrpc.getSearchByUsernameMethod) == null) { + synchronized (SearchServiceGrpc.class) { + if ((getSearchByUsernameMethod = SearchServiceGrpc.getSearchByUsernameMethod) == null) { + SearchServiceGrpc.getSearchByUsernameMethod = getSearchByUsernameMethod = + io.grpc.MethodDescriptor.newBuilder() + .setType(io.grpc.MethodDescriptor.MethodType.UNARY) + .setFullMethodName(generateFullMethodName( + "account.SearchService", "searchByUsername")) + .setSampledToLocalTracing(true) + .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( + biz.nynja.search.grpc.SearchByUsernameRequest.getDefaultInstance())) + .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( + biz.nynja.search.grpc.SearchResponse.getDefaultInstance())) + .setSchemaDescriptor(new SearchServiceMethodDescriptorSupplier("searchByUsername")) + .build(); + } + } + } + return getSearchByUsernameMethod; + } + + /** + * Creates a new async stub that supports all call types for the service + */ + public static SearchServiceStub newStub(io.grpc.Channel channel) { + return new SearchServiceStub(channel); + } + + /** + * Creates a new blocking-style stub that supports unary and streaming output calls on the service + */ + public static SearchServiceBlockingStub newBlockingStub( + io.grpc.Channel channel) { + return new SearchServiceBlockingStub(channel); + } + + /** + * Creates a new ListenableFuture-style stub that supports unary calls on the service + */ + public static SearchServiceFutureStub newFutureStub( + io.grpc.Channel channel) { + return new SearchServiceFutureStub(channel); + } + + /** + */ + public static abstract class SearchServiceImplBase implements io.grpc.BindableService { + + /** + */ + public void searchByUsername(biz.nynja.search.grpc.SearchByUsernameRequest request, + io.grpc.stub.StreamObserver responseObserver) { + asyncUnimplementedUnaryCall(getSearchByUsernameMethodHelper(), responseObserver); + } + + @java.lang.Override public final io.grpc.ServerServiceDefinition bindService() { + return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor()) + .addMethod( + getSearchByUsernameMethodHelper(), + asyncUnaryCall( + new MethodHandlers< + biz.nynja.search.grpc.SearchByUsernameRequest, + biz.nynja.search.grpc.SearchResponse>( + this, METHODID_SEARCH_BY_USERNAME))) + .build(); + } + } + + /** + */ + public static final class SearchServiceStub extends io.grpc.stub.AbstractStub { + private SearchServiceStub(io.grpc.Channel channel) { + super(channel); + } + + private SearchServiceStub(io.grpc.Channel channel, + io.grpc.CallOptions callOptions) { + super(channel, callOptions); + } + + @java.lang.Override + protected SearchServiceStub build(io.grpc.Channel channel, + io.grpc.CallOptions callOptions) { + return new SearchServiceStub(channel, callOptions); + } + + /** + */ + public void searchByUsername(biz.nynja.search.grpc.SearchByUsernameRequest request, + io.grpc.stub.StreamObserver responseObserver) { + asyncUnaryCall( + getChannel().newCall(getSearchByUsernameMethodHelper(), getCallOptions()), request, responseObserver); + } + } + + /** + */ + public static final class SearchServiceBlockingStub extends io.grpc.stub.AbstractStub { + private SearchServiceBlockingStub(io.grpc.Channel channel) { + super(channel); + } + + private SearchServiceBlockingStub(io.grpc.Channel channel, + io.grpc.CallOptions callOptions) { + super(channel, callOptions); + } + + @java.lang.Override + protected SearchServiceBlockingStub build(io.grpc.Channel channel, + io.grpc.CallOptions callOptions) { + return new SearchServiceBlockingStub(channel, callOptions); + } + + /** + */ + public biz.nynja.search.grpc.SearchResponse searchByUsername(biz.nynja.search.grpc.SearchByUsernameRequest request) { + return blockingUnaryCall( + getChannel(), getSearchByUsernameMethodHelper(), getCallOptions(), request); + } + } + + /** + */ + public static final class SearchServiceFutureStub extends io.grpc.stub.AbstractStub { + private SearchServiceFutureStub(io.grpc.Channel channel) { + super(channel); + } + + private SearchServiceFutureStub(io.grpc.Channel channel, + io.grpc.CallOptions callOptions) { + super(channel, callOptions); + } + + @java.lang.Override + protected SearchServiceFutureStub build(io.grpc.Channel channel, + io.grpc.CallOptions callOptions) { + return new SearchServiceFutureStub(channel, callOptions); + } + + /** + */ + public com.google.common.util.concurrent.ListenableFuture searchByUsername( + biz.nynja.search.grpc.SearchByUsernameRequest request) { + return futureUnaryCall( + getChannel().newCall(getSearchByUsernameMethodHelper(), getCallOptions()), request); + } + } + + private static final int METHODID_SEARCH_BY_USERNAME = 0; + + private static final class MethodHandlers implements + io.grpc.stub.ServerCalls.UnaryMethod, + io.grpc.stub.ServerCalls.ServerStreamingMethod, + io.grpc.stub.ServerCalls.ClientStreamingMethod, + io.grpc.stub.ServerCalls.BidiStreamingMethod { + private final SearchServiceImplBase serviceImpl; + private final int methodId; + + MethodHandlers(SearchServiceImplBase serviceImpl, int methodId) { + this.serviceImpl = serviceImpl; + this.methodId = methodId; + } + + @java.lang.Override + @java.lang.SuppressWarnings("unchecked") + public void invoke(Req request, io.grpc.stub.StreamObserver responseObserver) { + switch (methodId) { + case METHODID_SEARCH_BY_USERNAME: + serviceImpl.searchByUsername((biz.nynja.search.grpc.SearchByUsernameRequest) request, + (io.grpc.stub.StreamObserver) responseObserver); + break; + default: + throw new AssertionError(); + } + } + + @java.lang.Override + @java.lang.SuppressWarnings("unchecked") + public io.grpc.stub.StreamObserver invoke( + io.grpc.stub.StreamObserver responseObserver) { + switch (methodId) { + default: + throw new AssertionError(); + } + } + } + + private static abstract class SearchServiceBaseDescriptorSupplier + implements io.grpc.protobuf.ProtoFileDescriptorSupplier, io.grpc.protobuf.ProtoServiceDescriptorSupplier { + SearchServiceBaseDescriptorSupplier() {} + + @java.lang.Override + public com.google.protobuf.Descriptors.FileDescriptor getFileDescriptor() { + return biz.nynja.search.grpc.Search.getDescriptor(); + } + + @java.lang.Override + public com.google.protobuf.Descriptors.ServiceDescriptor getServiceDescriptor() { + return getFileDescriptor().findServiceByName("SearchService"); + } + } + + private static final class SearchServiceFileDescriptorSupplier + extends SearchServiceBaseDescriptorSupplier { + SearchServiceFileDescriptorSupplier() {} + } + + private static final class SearchServiceMethodDescriptorSupplier + extends SearchServiceBaseDescriptorSupplier + implements io.grpc.protobuf.ProtoMethodDescriptorSupplier { + private final String methodName; + + SearchServiceMethodDescriptorSupplier(String methodName) { + this.methodName = methodName; + } + + @java.lang.Override + public com.google.protobuf.Descriptors.MethodDescriptor getMethodDescriptor() { + return getServiceDescriptor().findMethodByName(methodName); + } + } + + private static volatile io.grpc.ServiceDescriptor serviceDescriptor; + + public static io.grpc.ServiceDescriptor getServiceDescriptor() { + io.grpc.ServiceDescriptor result = serviceDescriptor; + if (result == null) { + synchronized (SearchServiceGrpc.class) { + result = serviceDescriptor; + if (result == null) { + serviceDescriptor = result = io.grpc.ServiceDescriptor.newBuilder(SERVICE_NAME) + .setSchemaDescriptor(new SearchServiceFileDescriptorSupplier()) + .addMethod(getSearchByUsernameMethodHelper()) + .build(); + } + } + } + return result; + } +} -- GitLab From 21859ac03545ef75cd83437b318134170f28758d Mon Sep 17 00:00:00 2001 From: Stoyan Tzenkov Date: Wed, 17 Oct 2018 16:18:05 +0300 Subject: [PATCH 2/9] NY_3810: Implement search user by attributes Signed-off-by: Stoyan Tzenkov --- pom.xml | 12 + .../nynja/account/StartupScriptsListener.java | 7 +- .../nynja/account/models/AccountByQrCode.java | 275 ++++ .../AccountByQrCodeRepository.java | 17 + .../account/services/SearchServiceImpl.java | 149 +- .../biz/nynja/search/grpc/ErrorResponse.java | 760 --------- .../search/grpc/ErrorResponseOrBuilder.java | 28 - .../java/biz/nynja/search/grpc/Search.java | 108 -- .../search/grpc/SearchByUsernameRequest.java | 516 ------ .../SearchByUsernameRequestOrBuilder.java | 19 - .../biz/nynja/search/grpc/SearchResponse.java | 924 ----------- .../search/grpc/SearchResponseOrBuilder.java | 42 - .../search/grpc/SearchResultDetails.java | 1405 ----------------- .../grpc/SearchResultDetailsOrBuilder.java | 89 -- .../biz/nynja/search/grpc/SearchService.java | 237 --- .../nynja/search/grpc/SearchServiceGrpc.java | 286 ---- 16 files changed, 455 insertions(+), 4419 deletions(-) create mode 100644 src/main/java/biz/nynja/account/models/AccountByQrCode.java create mode 100644 src/main/java/biz/nynja/account/repositories/AccountByQrCodeRepository.java delete mode 100644 src/main/java/biz/nynja/search/grpc/ErrorResponse.java delete mode 100644 src/main/java/biz/nynja/search/grpc/ErrorResponseOrBuilder.java delete mode 100644 src/main/java/biz/nynja/search/grpc/Search.java delete mode 100644 src/main/java/biz/nynja/search/grpc/SearchByUsernameRequest.java delete mode 100644 src/main/java/biz/nynja/search/grpc/SearchByUsernameRequestOrBuilder.java delete mode 100644 src/main/java/biz/nynja/search/grpc/SearchResponse.java delete mode 100644 src/main/java/biz/nynja/search/grpc/SearchResponseOrBuilder.java delete mode 100644 src/main/java/biz/nynja/search/grpc/SearchResultDetails.java delete mode 100644 src/main/java/biz/nynja/search/grpc/SearchResultDetailsOrBuilder.java delete mode 100644 src/main/java/biz/nynja/search/grpc/SearchService.java delete mode 100644 src/main/java/biz/nynja/search/grpc/SearchServiceGrpc.java diff --git a/pom.xml b/pom.xml index ad665e6..4d47ff7 100644 --- a/pom.xml +++ b/pom.xml @@ -111,6 +111,18 @@ + + libs-snapshot-local.biz.nynja.protos + search-service-intracoldev + 1.0-SNAPSHOT + + + com.google.protobuf + protobuf-java + + + + com.googlecode.libphonenumber libphonenumber diff --git a/src/main/java/biz/nynja/account/StartupScriptsListener.java b/src/main/java/biz/nynja/account/StartupScriptsListener.java index 08acd3a..ac797ab 100644 --- a/src/main/java/biz/nynja/account/StartupScriptsListener.java +++ b/src/main/java/biz/nynja/account/StartupScriptsListener.java @@ -56,7 +56,12 @@ public class StartupScriptsListener { + ".pendingaccountbyauthenticationprovider AS SELECT * FROM pendingaccount " + "WHERE authenticationprovider IS NOT NULL " + "PRIMARY KEY (authenticationprovider, accountid);"; + String scriptAccountViewByQrCode = "CREATE MATERIALIZED VIEW IF NOT EXISTS " + keyspace + + ".accountbyqrcode AS SELECT * FROM account " + "WHERE qrcode IS NOT NULL " + + "PRIMARY KEY (qrcode, accountid);"; + return Arrays.asList(scriptAccountViewByProfileId, scriptAccountViewByAuthProvider, - scriptAccountViewByAccountName, scriptAccountViewByUsername, scriptPendingAccountViewByAuthenticationProvider); + scriptAccountViewByAccountName, scriptAccountViewByUsername, + scriptPendingAccountViewByAuthenticationProvider, scriptAccountViewByQrCode); } } \ No newline at end of file diff --git a/src/main/java/biz/nynja/account/models/AccountByQrCode.java b/src/main/java/biz/nynja/account/models/AccountByQrCode.java new file mode 100644 index 0000000..479a12a --- /dev/null +++ b/src/main/java/biz/nynja/account/models/AccountByQrCode.java @@ -0,0 +1,275 @@ +/** + * Copyright (C) 2018 Nynja Inc. All rights reserved. + */ +package biz.nynja.account.models; + +import java.nio.ByteBuffer; +import java.util.Set; +import java.util.UUID; + +import biz.nynja.account.grpc.AccountDetails; +import biz.nynja.account.grpc.AccountDetails.Builder; + +public class AccountByQrCode { + + private UUID profileId; + private UUID accountId; + private String accountMark; + private String authenticationProvider; + private String authenticationProviderType; + private String firstName; + private String lastName; + private ByteBuffer avatar; + private String accountName; + private String username; + private String accountStatus; + private Long creationTimestamp; + private Long lastUpdateTimestamp; + private Set contactsInfo; + private String qrCode; + + public UUID getProfileId() { + return profileId; + } + + public void setProfileId(UUID profileId) { + this.profileId = profileId; + } + + public UUID getAccountId() { + return accountId; + } + + public void setAccountId(UUID accountId) { + this.accountId = accountId; + } + + public String getAccountMark() { + return accountMark; + } + + public void setAccountMark(String accountMark) { + this.accountMark = accountMark; + } + + public String getAuthenticationProvider() { + return authenticationProvider; + } + + public void setAuthenticationProvider(String authenticationProvider) { + this.authenticationProvider = authenticationProvider; + } + + public String getAuthenticationProviderType() { + return authenticationProviderType; + } + + public void setAuthenticationProviderType(String authenticationProviderType) { + this.authenticationProviderType = authenticationProviderType; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public ByteBuffer getAvatar() { + return avatar; + } + + public void setAvatar(ByteBuffer avatar) { + this.avatar = avatar; + } + + public String getAccountName() { + return accountName; + } + + public void setAccountName(String accountName) { + this.accountName = accountName; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getAccountStatus() { + return accountStatus; + } + + public void setAccountStatus(String accountStatus) { + this.accountStatus = accountStatus; + } + + public Long getCreationTimestamp() { + return creationTimestamp; + } + + public void setCreationTimestamp(Long creationTimestamp) { + this.creationTimestamp = creationTimestamp; + } + + public Long getLastUpdateTimestamp() { + return lastUpdateTimestamp; + } + + public void setLastUpdateTimestamp(Long lastUpdateTimestamp) { + this.lastUpdateTimestamp = lastUpdateTimestamp; + } + + public Set getContactsInfo() { + return contactsInfo; + } + + public void setContactsInfo(Set contactsInfo) { + this.contactsInfo = contactsInfo; + } + + public String getQrCode() { + return qrCode; + } + + public void setQrCode(String qrCode) { + this.qrCode = qrCode; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((accountId == null) ? 0 : accountId.hashCode()); + result = prime * result + ((accountMark == null) ? 0 : accountMark.hashCode()); + result = prime * result + ((accountName == null) ? 0 : accountName.hashCode()); + result = prime * result + ((accountStatus == null) ? 0 : accountStatus.hashCode()); + result = prime * result + ((authenticationProvider == null) ? 0 : authenticationProvider.hashCode()); + result = prime * result + ((authenticationProviderType == null) ? 0 : authenticationProviderType.hashCode()); + result = prime * result + ((avatar == null) ? 0 : avatar.hashCode()); + result = prime * result + ((contactsInfo == null) ? 0 : contactsInfo.hashCode()); + result = prime * result + ((creationTimestamp == null) ? 0 : creationTimestamp.hashCode()); + result = prime * result + ((firstName == null) ? 0 : firstName.hashCode()); + result = prime * result + ((lastName == null) ? 0 : lastName.hashCode()); + result = prime * result + ((lastUpdateTimestamp == null) ? 0 : lastUpdateTimestamp.hashCode()); + result = prime * result + ((profileId == null) ? 0 : profileId.hashCode()); + result = prime * result + ((qrCode == null) ? 0 : qrCode.hashCode()); + result = prime * result + ((username == null) ? 0 : username.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + AccountByQrCode other = (AccountByQrCode) obj; + if (accountId == null) { + if (other.accountId != null) + return false; + } else if (!accountId.equals(other.accountId)) + return false; + if (accountMark == null) { + if (other.accountMark != null) + return false; + } else if (!accountMark.equals(other.accountMark)) + return false; + if (accountName == null) { + if (other.accountName != null) + return false; + } else if (!accountName.equals(other.accountName)) + return false; + if (accountStatus == null) { + if (other.accountStatus != null) + return false; + } else if (!accountStatus.equals(other.accountStatus)) + return false; + if (authenticationProvider == null) { + if (other.authenticationProvider != null) + return false; + } else if (!authenticationProvider.equals(other.authenticationProvider)) + return false; + if (authenticationProviderType == null) { + if (other.authenticationProviderType != null) + return false; + } else if (!authenticationProviderType.equals(other.authenticationProviderType)) + return false; + if (avatar == null) { + if (other.avatar != null) + return false; + } else if (!avatar.equals(other.avatar)) + return false; + if (contactsInfo == null) { + if (other.contactsInfo != null) + return false; + } else if (!contactsInfo.equals(other.contactsInfo)) + return false; + if (creationTimestamp == null) { + if (other.creationTimestamp != null) + return false; + } else if (!creationTimestamp.equals(other.creationTimestamp)) + return false; + if (firstName == null) { + if (other.firstName != null) + return false; + } else if (!firstName.equals(other.firstName)) + return false; + if (lastName == null) { + if (other.lastName != null) + return false; + } else if (!lastName.equals(other.lastName)) + return false; + if (lastUpdateTimestamp == null) { + if (other.lastUpdateTimestamp != null) + return false; + } else if (!lastUpdateTimestamp.equals(other.lastUpdateTimestamp)) + return false; + if (profileId == null) { + if (other.profileId != null) + return false; + } else if (!profileId.equals(other.profileId)) + return false; + if (qrCode == null) { + if (other.qrCode != null) + return false; + } else if (!qrCode.equals(other.qrCode)) + return false; + if (username == null) { + if (other.username != null) + return false; + } else if (!username.equals(other.username)) + return false; + return true; + } + + @Override + public String toString() { + return new StringBuilder("Account [accountId=").append(accountId).append(", profileId=").append(profileId) + .append(", accountMark=").append(accountMark).append(", authenticationProvider=") + .append(authenticationProvider).append(", authenticationProviderType=") + .append(authenticationProviderType).append(", firstName=").append(firstName).append(", lastName=") + .append(lastName).append(", avatar=").append(avatar).append(", accountName=").append(accountName) + .append(", username=").append(username).append(", accountStatus=").append(accountStatus) + .append(", creationTimestamp=").append(creationTimestamp) + .append(", lastUpdateTimestamp=").append(lastUpdateTimestamp) + .append(", qrCode=").append(qrCode) + .append(", contactsInfo=").append(contactsInfo) + .append("]").toString(); + } + +} diff --git a/src/main/java/biz/nynja/account/repositories/AccountByQrCodeRepository.java b/src/main/java/biz/nynja/account/repositories/AccountByQrCodeRepository.java new file mode 100644 index 0000000..0d893fb --- /dev/null +++ b/src/main/java/biz/nynja/account/repositories/AccountByQrCodeRepository.java @@ -0,0 +1,17 @@ +/** + * Copyright (C) 2018 Nynja Inc. All rights reserved. + */ +package biz.nynja.account.repositories; + +import org.springframework.data.cassandra.repository.CassandraRepository; +import org.springframework.stereotype.Repository; + +import biz.nynja.account.models.AccountByQrCode; +import biz.nynja.account.models.AccountByUsername; + +@Repository +public interface AccountByQrCodeRepository extends CassandraRepository { + + AccountByQrCode findByQrCode(String qrCode); + +} diff --git a/src/main/java/biz/nynja/account/services/SearchServiceImpl.java b/src/main/java/biz/nynja/account/services/SearchServiceImpl.java index 7fe16ab..c072d79 100644 --- a/src/main/java/biz/nynja/account/services/SearchServiceImpl.java +++ b/src/main/java/biz/nynja/account/services/SearchServiceImpl.java @@ -1,18 +1,23 @@ package biz.nynja.account.services; +import java.util.List; + import org.lognet.springboot.grpc.GRpcService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import biz.nynja.account.grpc.AccountByAuthenticationProviderRequest; -import biz.nynja.account.grpc.AccountResponse; -import biz.nynja.account.grpc.AuthenticationType; import biz.nynja.search.grpc.ErrorResponse; import biz.nynja.search.grpc.ErrorResponse.Cause; -import biz.nynja.account.models.Account; +import biz.nynja.search.grpc.SearchByEmailRequest; +import biz.nynja.search.grpc.SearchByPhoneNumberRequest; +import biz.nynja.search.grpc.SearchByQrCodeRequest; +import biz.nynja.account.models.AccountByAuthenticationProvider; +import biz.nynja.account.models.AccountByQrCode; import biz.nynja.account.models.AccountByUsername; +import biz.nynja.account.repositories.AccountByAuthenticationProviderRepository; import biz.nynja.account.repositories.AccountByUsernameRepository; +import biz.nynja.account.repositories.AccountByQrCodeRepository; import biz.nynja.search.grpc.SearchByUsernameRequest; import biz.nynja.search.grpc.SearchResponse; import biz.nynja.search.grpc.SearchResultDetails; @@ -27,7 +32,12 @@ public class SearchServiceImpl extends SearchServiceGrpc.SearchServiceImplBase { @Autowired AccountByUsernameRepository accountByUsernameRepository; + @Autowired + AccountByAuthenticationProviderRepository accountByAuthenticationProviderRepository; + @Autowired + AccountByQrCodeRepository accountByQrCodeRepository; + @Override public void searchByUsername(SearchByUsernameRequest request, StreamObserver responseObserver) { @@ -71,6 +81,137 @@ public class SearchServiceImpl extends SearchServiceGrpc.SearchServiceImplBase { return; } + @Override + public void searchByPhoneNumber(SearchByPhoneNumberRequest request, + StreamObserver responseObserver) { + + logger.info("Getting account by phone number: {}", request.getPhoneNumber()); + if (request.getPhoneNumber().isEmpty()) { + responseObserver.onNext(SearchResponse.newBuilder() + .setError(ErrorResponse.newBuilder().setCause(Cause.MISSING_PHONENUMBER)).build()); + responseObserver.onCompleted(); + return; + } + + List accounts = accountByAuthenticationProviderRepository + .findAllByAuthenticationProvider(request.getPhoneNumber()); + + if (accounts.isEmpty()) { + logger.debug("No matching accounts found for phone number: {}", request.getPhoneNumber()); + responseObserver.onNext(SearchResponse.newBuilder() + .setError(ErrorResponse.newBuilder().setCause(Cause.PHONENUMBER_NOT_FOUND)).build()); + responseObserver.onCompleted(); + return; + } + + AccountByAuthenticationProvider account = accounts.get(0); + SearchResultDetails searchResultDetails = SearchResultDetails.newBuilder() + .setAccountId(account.getAccountId().toString()) + .setAuthenticationProvider(account.getAuthenticationProvider()) + .setAuthenticationType(account.getAuthenticationProviderType()) + .setFirstName(account.getFirstName()) + .setLastName(account.getLastName()) + .setProfileId(account.getAccountId().toString()) + .setQrCode(account.getQrCode()) + .setUsername(account.getUsername()) + .build(); + + SearchResponse response = SearchResponse.newBuilder() + .setSearchResultDetails(searchResultDetails).build(); + logger.debug("Found result for account by phone number {}: \"{}\"", + request.getPhoneNumber(), response); + responseObserver.onNext(response); + responseObserver.onCompleted(); + + return; + } + + @Override + public void searchByEmail(SearchByEmailRequest request, + StreamObserver responseObserver) { + + logger.info("Getting account by e-mail: {}", request.getEmail()); + if (request.getEmail().isEmpty()) { + responseObserver.onNext(SearchResponse.newBuilder() + .setError(ErrorResponse.newBuilder().setCause(Cause.MISSING_EMAIL)).build()); + responseObserver.onCompleted(); + return; + } + + List accounts = accountByAuthenticationProviderRepository + .findAllByAuthenticationProvider(request.getEmail()); + + if (accounts.isEmpty()) { + logger.debug("No matching accounts found for e-mail: {}", request.getEmail()); + responseObserver.onNext(SearchResponse.newBuilder() + .setError(ErrorResponse.newBuilder().setCause(Cause.EMAIL_NOT_FOUND)).build()); + responseObserver.onCompleted(); + return; + } + + AccountByAuthenticationProvider account = accounts.get(0); + SearchResultDetails searchResultDetails = SearchResultDetails.newBuilder() + .setAccountId(account.getAccountId().toString()) + .setAuthenticationProvider(account.getAuthenticationProvider()) + .setAuthenticationType(account.getAuthenticationProviderType()) + .setFirstName(account.getFirstName()) + .setLastName(account.getLastName()) + .setProfileId(account.getAccountId().toString()) + .setQrCode(account.getQrCode()) + .setUsername(account.getUsername()) + .build(); + + SearchResponse response = SearchResponse.newBuilder() + .setSearchResultDetails(searchResultDetails).build(); + logger.debug("Found result for account by e-mail {}: \"{}\"", + request.getEmail(), response); + responseObserver.onNext(response); + responseObserver.onCompleted(); + + return; + } + + @Override + public void searchByQrCode(SearchByQrCodeRequest request, + StreamObserver responseObserver) { + + logger.info("Getting account by QR code: {}", request.getQrCode()); + if (request.getQrCode().isEmpty()) { + responseObserver.onNext(SearchResponse.newBuilder() + .setError(ErrorResponse.newBuilder().setCause(Cause.MISSING_QR_CODE)).build()); + responseObserver.onCompleted(); + return; + } + AccountByQrCode account = accountByQrCodeRepository.findByQrCode(request.getQrCode()); + if (account == null) { + + logger.debug("No matching accounts found for QR code: {}", request.getQrCode()); + responseObserver.onNext(SearchResponse.newBuilder() + .setError(ErrorResponse.newBuilder().setCause(Cause.QR_CODE_NOT_FOUND)).build()); + responseObserver.onCompleted(); + return; + } + + SearchResultDetails searchResultDetails = SearchResultDetails.newBuilder() + .setAccountId(account.getAccountId().toString()) + .setAuthenticationProvider(account.getAuthenticationProvider()) + .setAuthenticationType(account.getAuthenticationProviderType()) + .setFirstName(account.getFirstName()) + .setLastName(account.getLastName()) + .setProfileId(account.getAccountId().toString()) + .setQrCode(account.getQrCode()) + .setUsername(account.getUsername()) + .build(); + + SearchResponse response = SearchResponse.newBuilder() + .setSearchResultDetails(searchResultDetails).build(); + logger.debug("Found result for account by QR code {}: \"{}\"", + request.getQrCode(), response); + responseObserver.onNext(response); + responseObserver.onCompleted(); + + return; + } } diff --git a/src/main/java/biz/nynja/search/grpc/ErrorResponse.java b/src/main/java/biz/nynja/search/grpc/ErrorResponse.java deleted file mode 100644 index e2889a7..0000000 --- a/src/main/java/biz/nynja/search/grpc/ErrorResponse.java +++ /dev/null @@ -1,760 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: search.proto - -package biz.nynja.search.grpc; - -/** - * Protobuf type {@code account.ErrorResponse} - */ -public final class ErrorResponse extends - com.google.protobuf.GeneratedMessageV3 implements - // @@protoc_insertion_point(message_implements:account.ErrorResponse) - ErrorResponseOrBuilder { -private static final long serialVersionUID = 0L; - // Use ErrorResponse.newBuilder() to construct. - private ErrorResponse(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - private ErrorResponse() { - cause_ = 0; - message_ = ""; - } - - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private ErrorResponse( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - if (extensionRegistry == null) { - throw new java.lang.NullPointerException(); - } - int mutable_bitField0_ = 0; - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - default: { - if (!parseUnknownFieldProto3( - input, unknownFields, extensionRegistry, tag)) { - done = true; - } - break; - } - case 8: { - int rawValue = input.readEnum(); - - cause_ = rawValue; - break; - } - case 18: { - java.lang.String s = input.readStringRequireUtf8(); - - message_ = s; - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return biz.nynja.search.grpc.Search.internal_static_account_ErrorResponse_descriptor; - } - - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return biz.nynja.search.grpc.Search.internal_static_account_ErrorResponse_fieldAccessorTable - .ensureFieldAccessorsInitialized( - biz.nynja.search.grpc.ErrorResponse.class, biz.nynja.search.grpc.ErrorResponse.Builder.class); - } - - /** - * Protobuf enum {@code account.ErrorResponse.Cause} - */ - public enum Cause - implements com.google.protobuf.ProtocolMessageEnum { - /** - * INTERNAL_SERVER_ERROR = 0; - */ - INTERNAL_SERVER_ERROR(0), - /** - * MISSING_USERNAME = 1; - */ - MISSING_USERNAME(1), - /** - * MISSING_EMAIL = 2; - */ - MISSING_EMAIL(2), - /** - * MISSING_PHONENUMBER = 3; - */ - MISSING_PHONENUMBER(3), - /** - * MISSING_QR_CODE = 4; - */ - MISSING_QR_CODE(4), - /** - * USERNAME_NOT_FOUND = 5; - */ - USERNAME_NOT_FOUND(5), - /** - * EMAIL_NOT_FOUND = 6; - */ - EMAIL_NOT_FOUND(6), - /** - * PHONENUMBER_NOT_FOUND = 7; - */ - PHONENUMBER_NOT_FOUND(7), - /** - * QR_CODE_NOT_FOUND = 8; - */ - QR_CODE_NOT_FOUND(8), - UNRECOGNIZED(-1), - ; - - /** - * INTERNAL_SERVER_ERROR = 0; - */ - public static final int INTERNAL_SERVER_ERROR_VALUE = 0; - /** - * MISSING_USERNAME = 1; - */ - public static final int MISSING_USERNAME_VALUE = 1; - /** - * MISSING_EMAIL = 2; - */ - public static final int MISSING_EMAIL_VALUE = 2; - /** - * MISSING_PHONENUMBER = 3; - */ - public static final int MISSING_PHONENUMBER_VALUE = 3; - /** - * MISSING_QR_CODE = 4; - */ - public static final int MISSING_QR_CODE_VALUE = 4; - /** - * USERNAME_NOT_FOUND = 5; - */ - public static final int USERNAME_NOT_FOUND_VALUE = 5; - /** - * EMAIL_NOT_FOUND = 6; - */ - public static final int EMAIL_NOT_FOUND_VALUE = 6; - /** - * PHONENUMBER_NOT_FOUND = 7; - */ - public static final int PHONENUMBER_NOT_FOUND_VALUE = 7; - /** - * QR_CODE_NOT_FOUND = 8; - */ - public static final int QR_CODE_NOT_FOUND_VALUE = 8; - - - public final int getNumber() { - if (this == UNRECOGNIZED) { - throw new java.lang.IllegalArgumentException( - "Can't get the number of an unknown enum value."); - } - return value; - } - - /** - * @deprecated Use {@link #forNumber(int)} instead. - */ - @java.lang.Deprecated - public static Cause valueOf(int value) { - return forNumber(value); - } - - public static Cause forNumber(int value) { - switch (value) { - case 0: return INTERNAL_SERVER_ERROR; - case 1: return MISSING_USERNAME; - case 2: return MISSING_EMAIL; - case 3: return MISSING_PHONENUMBER; - case 4: return MISSING_QR_CODE; - case 5: return USERNAME_NOT_FOUND; - case 6: return EMAIL_NOT_FOUND; - case 7: return PHONENUMBER_NOT_FOUND; - case 8: return QR_CODE_NOT_FOUND; - default: return null; - } - } - - public static com.google.protobuf.Internal.EnumLiteMap - internalGetValueMap() { - return internalValueMap; - } - private static final com.google.protobuf.Internal.EnumLiteMap< - Cause> internalValueMap = - new com.google.protobuf.Internal.EnumLiteMap() { - public Cause findValueByNumber(int number) { - return Cause.forNumber(number); - } - }; - - public final com.google.protobuf.Descriptors.EnumValueDescriptor - getValueDescriptor() { - return getDescriptor().getValues().get(ordinal()); - } - public final com.google.protobuf.Descriptors.EnumDescriptor - getDescriptorForType() { - return getDescriptor(); - } - public static final com.google.protobuf.Descriptors.EnumDescriptor - getDescriptor() { - return biz.nynja.search.grpc.ErrorResponse.getDescriptor().getEnumTypes().get(0); - } - - private static final Cause[] VALUES = values(); - - public static Cause valueOf( - com.google.protobuf.Descriptors.EnumValueDescriptor desc) { - if (desc.getType() != getDescriptor()) { - throw new java.lang.IllegalArgumentException( - "EnumValueDescriptor is not for this type."); - } - if (desc.getIndex() == -1) { - return UNRECOGNIZED; - } - return VALUES[desc.getIndex()]; - } - - private final int value; - - private Cause(int value) { - this.value = value; - } - - // @@protoc_insertion_point(enum_scope:account.ErrorResponse.Cause) - } - - public static final int CAUSE_FIELD_NUMBER = 1; - private int cause_; - /** - * .account.ErrorResponse.Cause cause = 1; - */ - public int getCauseValue() { - return cause_; - } - /** - * .account.ErrorResponse.Cause cause = 1; - */ - public biz.nynja.search.grpc.ErrorResponse.Cause getCause() { - biz.nynja.search.grpc.ErrorResponse.Cause result = biz.nynja.search.grpc.ErrorResponse.Cause.valueOf(cause_); - return result == null ? biz.nynja.search.grpc.ErrorResponse.Cause.UNRECOGNIZED : result; - } - - public static final int MESSAGE_FIELD_NUMBER = 2; - private volatile java.lang.Object message_; - /** - * string message = 2; - */ - public java.lang.String getMessage() { - java.lang.Object ref = message_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - message_ = s; - return s; - } - } - /** - * string message = 2; - */ - public com.google.protobuf.ByteString - getMessageBytes() { - java.lang.Object ref = message_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - message_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - private byte memoizedIsInitialized = -1; - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - if (cause_ != biz.nynja.search.grpc.ErrorResponse.Cause.INTERNAL_SERVER_ERROR.getNumber()) { - output.writeEnum(1, cause_); - } - if (!getMessageBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 2, message_); - } - unknownFields.writeTo(output); - } - - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - if (cause_ != biz.nynja.search.grpc.ErrorResponse.Cause.INTERNAL_SERVER_ERROR.getNumber()) { - size += com.google.protobuf.CodedOutputStream - .computeEnumSize(1, cause_); - } - if (!getMessageBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, message_); - } - size += unknownFields.getSerializedSize(); - memoizedSize = size; - return size; - } - - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof biz.nynja.search.grpc.ErrorResponse)) { - return super.equals(obj); - } - biz.nynja.search.grpc.ErrorResponse other = (biz.nynja.search.grpc.ErrorResponse) obj; - - boolean result = true; - result = result && cause_ == other.cause_; - result = result && getMessage() - .equals(other.getMessage()); - result = result && unknownFields.equals(other.unknownFields); - return result; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptor().hashCode(); - hash = (37 * hash) + CAUSE_FIELD_NUMBER; - hash = (53 * hash) + cause_; - hash = (37 * hash) + MESSAGE_FIELD_NUMBER; - hash = (53 * hash) + getMessage().hashCode(); - hash = (29 * hash) + unknownFields.hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static biz.nynja.search.grpc.ErrorResponse parseFrom( - java.nio.ByteBuffer data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static biz.nynja.search.grpc.ErrorResponse parseFrom( - java.nio.ByteBuffer data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static biz.nynja.search.grpc.ErrorResponse parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static biz.nynja.search.grpc.ErrorResponse parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static biz.nynja.search.grpc.ErrorResponse parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static biz.nynja.search.grpc.ErrorResponse parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static biz.nynja.search.grpc.ErrorResponse parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static biz.nynja.search.grpc.ErrorResponse parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - public static biz.nynja.search.grpc.ErrorResponse parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input); - } - public static biz.nynja.search.grpc.ErrorResponse parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static biz.nynja.search.grpc.ErrorResponse parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static biz.nynja.search.grpc.ErrorResponse parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(biz.nynja.search.grpc.ErrorResponse prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code account.ErrorResponse} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements - // @@protoc_insertion_point(builder_implements:account.ErrorResponse) - biz.nynja.search.grpc.ErrorResponseOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return biz.nynja.search.grpc.Search.internal_static_account_ErrorResponse_descriptor; - } - - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return biz.nynja.search.grpc.Search.internal_static_account_ErrorResponse_fieldAccessorTable - .ensureFieldAccessorsInitialized( - biz.nynja.search.grpc.ErrorResponse.class, biz.nynja.search.grpc.ErrorResponse.Builder.class); - } - - // Construct using biz.nynja.search.grpc.ErrorResponse.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 - .alwaysUseFieldBuilders) { - } - } - public Builder clear() { - super.clear(); - cause_ = 0; - - message_ = ""; - - return this; - } - - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return biz.nynja.search.grpc.Search.internal_static_account_ErrorResponse_descriptor; - } - - public biz.nynja.search.grpc.ErrorResponse getDefaultInstanceForType() { - return biz.nynja.search.grpc.ErrorResponse.getDefaultInstance(); - } - - public biz.nynja.search.grpc.ErrorResponse build() { - biz.nynja.search.grpc.ErrorResponse result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - public biz.nynja.search.grpc.ErrorResponse buildPartial() { - biz.nynja.search.grpc.ErrorResponse result = new biz.nynja.search.grpc.ErrorResponse(this); - result.cause_ = cause_; - result.message_ = message_; - onBuilt(); - return result; - } - - public Builder clone() { - return (Builder) super.clone(); - } - public Builder setField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return (Builder) super.setField(field, value); - } - public Builder clearField( - com.google.protobuf.Descriptors.FieldDescriptor field) { - return (Builder) super.clearField(field); - } - public Builder clearOneof( - com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return (Builder) super.clearOneof(oneof); - } - public Builder setRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - int index, java.lang.Object value) { - return (Builder) super.setRepeatedField(field, index, value); - } - public Builder addRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return (Builder) super.addRepeatedField(field, value); - } - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof biz.nynja.search.grpc.ErrorResponse) { - return mergeFrom((biz.nynja.search.grpc.ErrorResponse)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(biz.nynja.search.grpc.ErrorResponse other) { - if (other == biz.nynja.search.grpc.ErrorResponse.getDefaultInstance()) return this; - if (other.cause_ != 0) { - setCauseValue(other.getCauseValue()); - } - if (!other.getMessage().isEmpty()) { - message_ = other.message_; - onChanged(); - } - this.mergeUnknownFields(other.unknownFields); - onChanged(); - return this; - } - - public final boolean isInitialized() { - return true; - } - - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - biz.nynja.search.grpc.ErrorResponse parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (biz.nynja.search.grpc.ErrorResponse) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - - private int cause_ = 0; - /** - * .account.ErrorResponse.Cause cause = 1; - */ - public int getCauseValue() { - return cause_; - } - /** - * .account.ErrorResponse.Cause cause = 1; - */ - public Builder setCauseValue(int value) { - cause_ = value; - onChanged(); - return this; - } - /** - * .account.ErrorResponse.Cause cause = 1; - */ - public biz.nynja.search.grpc.ErrorResponse.Cause getCause() { - biz.nynja.search.grpc.ErrorResponse.Cause result = biz.nynja.search.grpc.ErrorResponse.Cause.valueOf(cause_); - return result == null ? biz.nynja.search.grpc.ErrorResponse.Cause.UNRECOGNIZED : result; - } - /** - * .account.ErrorResponse.Cause cause = 1; - */ - public Builder setCause(biz.nynja.search.grpc.ErrorResponse.Cause value) { - if (value == null) { - throw new NullPointerException(); - } - - cause_ = value.getNumber(); - onChanged(); - return this; - } - /** - * .account.ErrorResponse.Cause cause = 1; - */ - public Builder clearCause() { - - cause_ = 0; - onChanged(); - return this; - } - - private java.lang.Object message_ = ""; - /** - * string message = 2; - */ - public java.lang.String getMessage() { - java.lang.Object ref = message_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - message_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * string message = 2; - */ - public com.google.protobuf.ByteString - getMessageBytes() { - java.lang.Object ref = message_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - message_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string message = 2; - */ - public Builder setMessage( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - message_ = value; - onChanged(); - return this; - } - /** - * string message = 2; - */ - public Builder clearMessage() { - - message_ = getDefaultInstance().getMessage(); - onChanged(); - return this; - } - /** - * string message = 2; - */ - public Builder setMessageBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - message_ = value; - onChanged(); - return this; - } - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFieldsProto3(unknownFields); - } - - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } - - - // @@protoc_insertion_point(builder_scope:account.ErrorResponse) - } - - // @@protoc_insertion_point(class_scope:account.ErrorResponse) - private static final biz.nynja.search.grpc.ErrorResponse DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new biz.nynja.search.grpc.ErrorResponse(); - } - - public static biz.nynja.search.grpc.ErrorResponse getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - public ErrorResponse parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new ErrorResponse(input, extensionRegistry); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - public biz.nynja.search.grpc.ErrorResponse getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - -} - diff --git a/src/main/java/biz/nynja/search/grpc/ErrorResponseOrBuilder.java b/src/main/java/biz/nynja/search/grpc/ErrorResponseOrBuilder.java deleted file mode 100644 index 016d8bc..0000000 --- a/src/main/java/biz/nynja/search/grpc/ErrorResponseOrBuilder.java +++ /dev/null @@ -1,28 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: search.proto - -package biz.nynja.search.grpc; - -public interface ErrorResponseOrBuilder extends - // @@protoc_insertion_point(interface_extends:account.ErrorResponse) - com.google.protobuf.MessageOrBuilder { - - /** - * .account.ErrorResponse.Cause cause = 1; - */ - int getCauseValue(); - /** - * .account.ErrorResponse.Cause cause = 1; - */ - biz.nynja.search.grpc.ErrorResponse.Cause getCause(); - - /** - * string message = 2; - */ - java.lang.String getMessage(); - /** - * string message = 2; - */ - com.google.protobuf.ByteString - getMessageBytes(); -} diff --git a/src/main/java/biz/nynja/search/grpc/Search.java b/src/main/java/biz/nynja/search/grpc/Search.java deleted file mode 100644 index efca238..0000000 --- a/src/main/java/biz/nynja/search/grpc/Search.java +++ /dev/null @@ -1,108 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: search.proto - -package biz.nynja.search.grpc; - -public final class Search { - private Search() {} - public static void registerAllExtensions( - com.google.protobuf.ExtensionRegistryLite registry) { - } - - public static void registerAllExtensions( - com.google.protobuf.ExtensionRegistry registry) { - registerAllExtensions( - (com.google.protobuf.ExtensionRegistryLite) registry); - } - static final com.google.protobuf.Descriptors.Descriptor - internal_static_account_SearchByUsernameRequest_descriptor; - static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_account_SearchByUsernameRequest_fieldAccessorTable; - static final com.google.protobuf.Descriptors.Descriptor - internal_static_account_SearchResponse_descriptor; - static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_account_SearchResponse_fieldAccessorTable; - static final com.google.protobuf.Descriptors.Descriptor - internal_static_account_SearchResultDetails_descriptor; - static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_account_SearchResultDetails_fieldAccessorTable; - static final com.google.protobuf.Descriptors.Descriptor - internal_static_account_ErrorResponse_descriptor; - static final - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internal_static_account_ErrorResponse_fieldAccessorTable; - - public static com.google.protobuf.Descriptors.FileDescriptor - getDescriptor() { - return descriptor; - } - private static com.google.protobuf.Descriptors.FileDescriptor - descriptor; - static { - java.lang.String[] descriptorData = { - "\n\014search.proto\022\007account\"+\n\027SearchByUsern" + - "ameRequest\022\020\n\010username\030\001 \001(\t\"\223\001\n\016SearchR" + - "esponse\022\021\n\trequestId\030\001 \001(\004\022\'\n\005error\030\002 \001(" + - "\0132\026.account.ErrorResponseH\000\022;\n\023searchRes" + - "ultDetails\030\003 \001(\0132\034.account.SearchResultD" + - "etailsH\000B\010\n\006result\"\276\001\n\023SearchResultDetai" + - "ls\022\021\n\taccountId\030\001 \001(\t\022\021\n\tprofileId\030\002 \001(\t" + - "\022\036\n\026authenticationProvider\030\003 \001(\t\022\032\n\022auth" + - "enticationType\030\004 \001(\t\022\021\n\tfirstName\030\005 \001(\t\022" + - "\020\n\010lastName\030\006 \001(\t\022\020\n\010username\030\007 \001(\t\022\016\n\006q" + - "rCode\030\010 \001(\t\"\250\002\n\rErrorResponse\022+\n\005cause\030\001" + - " \001(\0162\034.account.ErrorResponse.Cause\022\017\n\007me" + - "ssage\030\002 \001(\t\"\330\001\n\005Cause\022\031\n\025INTERNAL_SERVER" + - "_ERROR\020\000\022\024\n\020MISSING_USERNAME\020\001\022\021\n\rMISSIN" + - "G_EMAIL\020\002\022\027\n\023MISSING_PHONENUMBER\020\003\022\023\n\017MI" + - "SSING_QR_CODE\020\004\022\026\n\022USERNAME_NOT_FOUND\020\005\022" + - "\023\n\017EMAIL_NOT_FOUND\020\006\022\031\n\025PHONENUMBER_NOT_" + - "FOUND\020\007\022\025\n\021QR_CODE_NOT_FOUND\020\0102^\n\rSearch" + - "Service\022M\n\020searchByUsername\022 .account.Se" + - "archByUsernameRequest\032\027.account.SearchRe" + - "sponseB$\n\025biz.nynja.search.grpcB\006SearchP" + - "\001\210\001\001b\006proto3" - }; - com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = - new com.google.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() { - public com.google.protobuf.ExtensionRegistry assignDescriptors( - com.google.protobuf.Descriptors.FileDescriptor root) { - descriptor = root; - return null; - } - }; - com.google.protobuf.Descriptors.FileDescriptor - .internalBuildGeneratedFileFrom(descriptorData, - new com.google.protobuf.Descriptors.FileDescriptor[] { - }, assigner); - internal_static_account_SearchByUsernameRequest_descriptor = - getDescriptor().getMessageTypes().get(0); - internal_static_account_SearchByUsernameRequest_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_account_SearchByUsernameRequest_descriptor, - new java.lang.String[] { "Username", }); - internal_static_account_SearchResponse_descriptor = - getDescriptor().getMessageTypes().get(1); - internal_static_account_SearchResponse_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_account_SearchResponse_descriptor, - new java.lang.String[] { "RequestId", "Error", "SearchResultDetails", "Result", }); - internal_static_account_SearchResultDetails_descriptor = - getDescriptor().getMessageTypes().get(2); - internal_static_account_SearchResultDetails_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_account_SearchResultDetails_descriptor, - new java.lang.String[] { "AccountId", "ProfileId", "AuthenticationProvider", "AuthenticationType", "FirstName", "LastName", "Username", "QrCode", }); - internal_static_account_ErrorResponse_descriptor = - getDescriptor().getMessageTypes().get(3); - internal_static_account_ErrorResponse_fieldAccessorTable = new - com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( - internal_static_account_ErrorResponse_descriptor, - new java.lang.String[] { "Cause", "Message", }); - } - - // @@protoc_insertion_point(outer_class_scope) -} diff --git a/src/main/java/biz/nynja/search/grpc/SearchByUsernameRequest.java b/src/main/java/biz/nynja/search/grpc/SearchByUsernameRequest.java deleted file mode 100644 index 98d0d9d..0000000 --- a/src/main/java/biz/nynja/search/grpc/SearchByUsernameRequest.java +++ /dev/null @@ -1,516 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: search.proto - -package biz.nynja.search.grpc; - -/** - * Protobuf type {@code account.SearchByUsernameRequest} - */ -public final class SearchByUsernameRequest extends - com.google.protobuf.GeneratedMessageV3 implements - // @@protoc_insertion_point(message_implements:account.SearchByUsernameRequest) - SearchByUsernameRequestOrBuilder { -private static final long serialVersionUID = 0L; - // Use SearchByUsernameRequest.newBuilder() to construct. - private SearchByUsernameRequest(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - private SearchByUsernameRequest() { - username_ = ""; - } - - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private SearchByUsernameRequest( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - if (extensionRegistry == null) { - throw new java.lang.NullPointerException(); - } - int mutable_bitField0_ = 0; - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - default: { - if (!parseUnknownFieldProto3( - input, unknownFields, extensionRegistry, tag)) { - done = true; - } - break; - } - case 10: { - java.lang.String s = input.readStringRequireUtf8(); - - username_ = s; - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return biz.nynja.search.grpc.Search.internal_static_account_SearchByUsernameRequest_descriptor; - } - - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return biz.nynja.search.grpc.Search.internal_static_account_SearchByUsernameRequest_fieldAccessorTable - .ensureFieldAccessorsInitialized( - biz.nynja.search.grpc.SearchByUsernameRequest.class, biz.nynja.search.grpc.SearchByUsernameRequest.Builder.class); - } - - public static final int USERNAME_FIELD_NUMBER = 1; - private volatile java.lang.Object username_; - /** - * string username = 1; - */ - public java.lang.String getUsername() { - java.lang.Object ref = username_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - username_ = s; - return s; - } - } - /** - * string username = 1; - */ - public com.google.protobuf.ByteString - getUsernameBytes() { - java.lang.Object ref = username_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - username_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - private byte memoizedIsInitialized = -1; - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - if (!getUsernameBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 1, username_); - } - unknownFields.writeTo(output); - } - - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - if (!getUsernameBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, username_); - } - size += unknownFields.getSerializedSize(); - memoizedSize = size; - return size; - } - - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof biz.nynja.search.grpc.SearchByUsernameRequest)) { - return super.equals(obj); - } - biz.nynja.search.grpc.SearchByUsernameRequest other = (biz.nynja.search.grpc.SearchByUsernameRequest) obj; - - boolean result = true; - result = result && getUsername() - .equals(other.getUsername()); - result = result && unknownFields.equals(other.unknownFields); - return result; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptor().hashCode(); - hash = (37 * hash) + USERNAME_FIELD_NUMBER; - hash = (53 * hash) + getUsername().hashCode(); - hash = (29 * hash) + unknownFields.hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static biz.nynja.search.grpc.SearchByUsernameRequest parseFrom( - java.nio.ByteBuffer data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static biz.nynja.search.grpc.SearchByUsernameRequest parseFrom( - java.nio.ByteBuffer data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static biz.nynja.search.grpc.SearchByUsernameRequest parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static biz.nynja.search.grpc.SearchByUsernameRequest parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static biz.nynja.search.grpc.SearchByUsernameRequest parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static biz.nynja.search.grpc.SearchByUsernameRequest parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static biz.nynja.search.grpc.SearchByUsernameRequest parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static biz.nynja.search.grpc.SearchByUsernameRequest parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - public static biz.nynja.search.grpc.SearchByUsernameRequest parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input); - } - public static biz.nynja.search.grpc.SearchByUsernameRequest parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static biz.nynja.search.grpc.SearchByUsernameRequest parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static biz.nynja.search.grpc.SearchByUsernameRequest parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(biz.nynja.search.grpc.SearchByUsernameRequest prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code account.SearchByUsernameRequest} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements - // @@protoc_insertion_point(builder_implements:account.SearchByUsernameRequest) - biz.nynja.search.grpc.SearchByUsernameRequestOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return biz.nynja.search.grpc.Search.internal_static_account_SearchByUsernameRequest_descriptor; - } - - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return biz.nynja.search.grpc.Search.internal_static_account_SearchByUsernameRequest_fieldAccessorTable - .ensureFieldAccessorsInitialized( - biz.nynja.search.grpc.SearchByUsernameRequest.class, biz.nynja.search.grpc.SearchByUsernameRequest.Builder.class); - } - - // Construct using biz.nynja.search.grpc.SearchByUsernameRequest.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 - .alwaysUseFieldBuilders) { - } - } - public Builder clear() { - super.clear(); - username_ = ""; - - return this; - } - - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return biz.nynja.search.grpc.Search.internal_static_account_SearchByUsernameRequest_descriptor; - } - - public biz.nynja.search.grpc.SearchByUsernameRequest getDefaultInstanceForType() { - return biz.nynja.search.grpc.SearchByUsernameRequest.getDefaultInstance(); - } - - public biz.nynja.search.grpc.SearchByUsernameRequest build() { - biz.nynja.search.grpc.SearchByUsernameRequest result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - public biz.nynja.search.grpc.SearchByUsernameRequest buildPartial() { - biz.nynja.search.grpc.SearchByUsernameRequest result = new biz.nynja.search.grpc.SearchByUsernameRequest(this); - result.username_ = username_; - onBuilt(); - return result; - } - - public Builder clone() { - return (Builder) super.clone(); - } - public Builder setField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return (Builder) super.setField(field, value); - } - public Builder clearField( - com.google.protobuf.Descriptors.FieldDescriptor field) { - return (Builder) super.clearField(field); - } - public Builder clearOneof( - com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return (Builder) super.clearOneof(oneof); - } - public Builder setRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - int index, java.lang.Object value) { - return (Builder) super.setRepeatedField(field, index, value); - } - public Builder addRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return (Builder) super.addRepeatedField(field, value); - } - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof biz.nynja.search.grpc.SearchByUsernameRequest) { - return mergeFrom((biz.nynja.search.grpc.SearchByUsernameRequest)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(biz.nynja.search.grpc.SearchByUsernameRequest other) { - if (other == biz.nynja.search.grpc.SearchByUsernameRequest.getDefaultInstance()) return this; - if (!other.getUsername().isEmpty()) { - username_ = other.username_; - onChanged(); - } - this.mergeUnknownFields(other.unknownFields); - onChanged(); - return this; - } - - public final boolean isInitialized() { - return true; - } - - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - biz.nynja.search.grpc.SearchByUsernameRequest parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (biz.nynja.search.grpc.SearchByUsernameRequest) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - - private java.lang.Object username_ = ""; - /** - * string username = 1; - */ - public java.lang.String getUsername() { - java.lang.Object ref = username_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - username_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * string username = 1; - */ - public com.google.protobuf.ByteString - getUsernameBytes() { - java.lang.Object ref = username_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - username_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string username = 1; - */ - public Builder setUsername( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - username_ = value; - onChanged(); - return this; - } - /** - * string username = 1; - */ - public Builder clearUsername() { - - username_ = getDefaultInstance().getUsername(); - onChanged(); - return this; - } - /** - * string username = 1; - */ - public Builder setUsernameBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - username_ = value; - onChanged(); - return this; - } - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFieldsProto3(unknownFields); - } - - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } - - - // @@protoc_insertion_point(builder_scope:account.SearchByUsernameRequest) - } - - // @@protoc_insertion_point(class_scope:account.SearchByUsernameRequest) - private static final biz.nynja.search.grpc.SearchByUsernameRequest DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new biz.nynja.search.grpc.SearchByUsernameRequest(); - } - - public static biz.nynja.search.grpc.SearchByUsernameRequest getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - public SearchByUsernameRequest parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new SearchByUsernameRequest(input, extensionRegistry); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - public biz.nynja.search.grpc.SearchByUsernameRequest getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - -} - diff --git a/src/main/java/biz/nynja/search/grpc/SearchByUsernameRequestOrBuilder.java b/src/main/java/biz/nynja/search/grpc/SearchByUsernameRequestOrBuilder.java deleted file mode 100644 index afba29e..0000000 --- a/src/main/java/biz/nynja/search/grpc/SearchByUsernameRequestOrBuilder.java +++ /dev/null @@ -1,19 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: search.proto - -package biz.nynja.search.grpc; - -public interface SearchByUsernameRequestOrBuilder extends - // @@protoc_insertion_point(interface_extends:account.SearchByUsernameRequest) - com.google.protobuf.MessageOrBuilder { - - /** - * string username = 1; - */ - java.lang.String getUsername(); - /** - * string username = 1; - */ - com.google.protobuf.ByteString - getUsernameBytes(); -} diff --git a/src/main/java/biz/nynja/search/grpc/SearchResponse.java b/src/main/java/biz/nynja/search/grpc/SearchResponse.java deleted file mode 100644 index 7efeef4..0000000 --- a/src/main/java/biz/nynja/search/grpc/SearchResponse.java +++ /dev/null @@ -1,924 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: search.proto - -package biz.nynja.search.grpc; - -/** - * Protobuf type {@code account.SearchResponse} - */ -public final class SearchResponse extends - com.google.protobuf.GeneratedMessageV3 implements - // @@protoc_insertion_point(message_implements:account.SearchResponse) - SearchResponseOrBuilder { -private static final long serialVersionUID = 0L; - // Use SearchResponse.newBuilder() to construct. - private SearchResponse(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - private SearchResponse() { - requestId_ = 0L; - } - - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private SearchResponse( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - if (extensionRegistry == null) { - throw new java.lang.NullPointerException(); - } - int mutable_bitField0_ = 0; - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - default: { - if (!parseUnknownFieldProto3( - input, unknownFields, extensionRegistry, tag)) { - done = true; - } - break; - } - case 8: { - - requestId_ = input.readUInt64(); - break; - } - case 18: { - biz.nynja.search.grpc.ErrorResponse.Builder subBuilder = null; - if (resultCase_ == 2) { - subBuilder = ((biz.nynja.search.grpc.ErrorResponse) result_).toBuilder(); - } - result_ = - input.readMessage(biz.nynja.search.grpc.ErrorResponse.parser(), extensionRegistry); - if (subBuilder != null) { - subBuilder.mergeFrom((biz.nynja.search.grpc.ErrorResponse) result_); - result_ = subBuilder.buildPartial(); - } - resultCase_ = 2; - break; - } - case 26: { - biz.nynja.search.grpc.SearchResultDetails.Builder subBuilder = null; - if (resultCase_ == 3) { - subBuilder = ((biz.nynja.search.grpc.SearchResultDetails) result_).toBuilder(); - } - result_ = - input.readMessage(biz.nynja.search.grpc.SearchResultDetails.parser(), extensionRegistry); - if (subBuilder != null) { - subBuilder.mergeFrom((biz.nynja.search.grpc.SearchResultDetails) result_); - result_ = subBuilder.buildPartial(); - } - resultCase_ = 3; - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return biz.nynja.search.grpc.Search.internal_static_account_SearchResponse_descriptor; - } - - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return biz.nynja.search.grpc.Search.internal_static_account_SearchResponse_fieldAccessorTable - .ensureFieldAccessorsInitialized( - biz.nynja.search.grpc.SearchResponse.class, biz.nynja.search.grpc.SearchResponse.Builder.class); - } - - private int resultCase_ = 0; - private java.lang.Object result_; - public enum ResultCase - implements com.google.protobuf.Internal.EnumLite { - ERROR(2), - SEARCHRESULTDETAILS(3), - RESULT_NOT_SET(0); - private final int value; - private ResultCase(int value) { - this.value = value; - } - /** - * @deprecated Use {@link #forNumber(int)} instead. - */ - @java.lang.Deprecated - public static ResultCase valueOf(int value) { - return forNumber(value); - } - - public static ResultCase forNumber(int value) { - switch (value) { - case 2: return ERROR; - case 3: return SEARCHRESULTDETAILS; - case 0: return RESULT_NOT_SET; - default: return null; - } - } - public int getNumber() { - return this.value; - } - }; - - public ResultCase - getResultCase() { - return ResultCase.forNumber( - resultCase_); - } - - public static final int REQUESTID_FIELD_NUMBER = 1; - private long requestId_; - /** - * uint64 requestId = 1; - */ - public long getRequestId() { - return requestId_; - } - - public static final int ERROR_FIELD_NUMBER = 2; - /** - * .account.ErrorResponse error = 2; - */ - public boolean hasError() { - return resultCase_ == 2; - } - /** - * .account.ErrorResponse error = 2; - */ - public biz.nynja.search.grpc.ErrorResponse getError() { - if (resultCase_ == 2) { - return (biz.nynja.search.grpc.ErrorResponse) result_; - } - return biz.nynja.search.grpc.ErrorResponse.getDefaultInstance(); - } - /** - * .account.ErrorResponse error = 2; - */ - public biz.nynja.search.grpc.ErrorResponseOrBuilder getErrorOrBuilder() { - if (resultCase_ == 2) { - return (biz.nynja.search.grpc.ErrorResponse) result_; - } - return biz.nynja.search.grpc.ErrorResponse.getDefaultInstance(); - } - - public static final int SEARCHRESULTDETAILS_FIELD_NUMBER = 3; - /** - * .account.SearchResultDetails searchResultDetails = 3; - */ - public boolean hasSearchResultDetails() { - return resultCase_ == 3; - } - /** - * .account.SearchResultDetails searchResultDetails = 3; - */ - public biz.nynja.search.grpc.SearchResultDetails getSearchResultDetails() { - if (resultCase_ == 3) { - return (biz.nynja.search.grpc.SearchResultDetails) result_; - } - return biz.nynja.search.grpc.SearchResultDetails.getDefaultInstance(); - } - /** - * .account.SearchResultDetails searchResultDetails = 3; - */ - public biz.nynja.search.grpc.SearchResultDetailsOrBuilder getSearchResultDetailsOrBuilder() { - if (resultCase_ == 3) { - return (biz.nynja.search.grpc.SearchResultDetails) result_; - } - return biz.nynja.search.grpc.SearchResultDetails.getDefaultInstance(); - } - - private byte memoizedIsInitialized = -1; - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - if (requestId_ != 0L) { - output.writeUInt64(1, requestId_); - } - if (resultCase_ == 2) { - output.writeMessage(2, (biz.nynja.search.grpc.ErrorResponse) result_); - } - if (resultCase_ == 3) { - output.writeMessage(3, (biz.nynja.search.grpc.SearchResultDetails) result_); - } - unknownFields.writeTo(output); - } - - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - if (requestId_ != 0L) { - size += com.google.protobuf.CodedOutputStream - .computeUInt64Size(1, requestId_); - } - if (resultCase_ == 2) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(2, (biz.nynja.search.grpc.ErrorResponse) result_); - } - if (resultCase_ == 3) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(3, (biz.nynja.search.grpc.SearchResultDetails) result_); - } - size += unknownFields.getSerializedSize(); - memoizedSize = size; - return size; - } - - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof biz.nynja.search.grpc.SearchResponse)) { - return super.equals(obj); - } - biz.nynja.search.grpc.SearchResponse other = (biz.nynja.search.grpc.SearchResponse) obj; - - boolean result = true; - result = result && (getRequestId() - == other.getRequestId()); - result = result && getResultCase().equals( - other.getResultCase()); - if (!result) return false; - switch (resultCase_) { - case 2: - result = result && getError() - .equals(other.getError()); - break; - case 3: - result = result && getSearchResultDetails() - .equals(other.getSearchResultDetails()); - break; - case 0: - default: - } - result = result && unknownFields.equals(other.unknownFields); - return result; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptor().hashCode(); - hash = (37 * hash) + REQUESTID_FIELD_NUMBER; - hash = (53 * hash) + com.google.protobuf.Internal.hashLong( - getRequestId()); - switch (resultCase_) { - case 2: - hash = (37 * hash) + ERROR_FIELD_NUMBER; - hash = (53 * hash) + getError().hashCode(); - break; - case 3: - hash = (37 * hash) + SEARCHRESULTDETAILS_FIELD_NUMBER; - hash = (53 * hash) + getSearchResultDetails().hashCode(); - break; - case 0: - default: - } - hash = (29 * hash) + unknownFields.hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static biz.nynja.search.grpc.SearchResponse parseFrom( - java.nio.ByteBuffer data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static biz.nynja.search.grpc.SearchResponse parseFrom( - java.nio.ByteBuffer data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static biz.nynja.search.grpc.SearchResponse parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static biz.nynja.search.grpc.SearchResponse parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static biz.nynja.search.grpc.SearchResponse parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static biz.nynja.search.grpc.SearchResponse parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static biz.nynja.search.grpc.SearchResponse parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static biz.nynja.search.grpc.SearchResponse parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - public static biz.nynja.search.grpc.SearchResponse parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input); - } - public static biz.nynja.search.grpc.SearchResponse parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static biz.nynja.search.grpc.SearchResponse parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static biz.nynja.search.grpc.SearchResponse parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(biz.nynja.search.grpc.SearchResponse prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code account.SearchResponse} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements - // @@protoc_insertion_point(builder_implements:account.SearchResponse) - biz.nynja.search.grpc.SearchResponseOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return biz.nynja.search.grpc.Search.internal_static_account_SearchResponse_descriptor; - } - - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return biz.nynja.search.grpc.Search.internal_static_account_SearchResponse_fieldAccessorTable - .ensureFieldAccessorsInitialized( - biz.nynja.search.grpc.SearchResponse.class, biz.nynja.search.grpc.SearchResponse.Builder.class); - } - - // Construct using biz.nynja.search.grpc.SearchResponse.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 - .alwaysUseFieldBuilders) { - } - } - public Builder clear() { - super.clear(); - requestId_ = 0L; - - resultCase_ = 0; - result_ = null; - return this; - } - - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return biz.nynja.search.grpc.Search.internal_static_account_SearchResponse_descriptor; - } - - public biz.nynja.search.grpc.SearchResponse getDefaultInstanceForType() { - return biz.nynja.search.grpc.SearchResponse.getDefaultInstance(); - } - - public biz.nynja.search.grpc.SearchResponse build() { - biz.nynja.search.grpc.SearchResponse result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - public biz.nynja.search.grpc.SearchResponse buildPartial() { - biz.nynja.search.grpc.SearchResponse result = new biz.nynja.search.grpc.SearchResponse(this); - result.requestId_ = requestId_; - if (resultCase_ == 2) { - if (errorBuilder_ == null) { - result.result_ = result_; - } else { - result.result_ = errorBuilder_.build(); - } - } - if (resultCase_ == 3) { - if (searchResultDetailsBuilder_ == null) { - result.result_ = result_; - } else { - result.result_ = searchResultDetailsBuilder_.build(); - } - } - result.resultCase_ = resultCase_; - onBuilt(); - return result; - } - - public Builder clone() { - return (Builder) super.clone(); - } - public Builder setField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return (Builder) super.setField(field, value); - } - public Builder clearField( - com.google.protobuf.Descriptors.FieldDescriptor field) { - return (Builder) super.clearField(field); - } - public Builder clearOneof( - com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return (Builder) super.clearOneof(oneof); - } - public Builder setRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - int index, java.lang.Object value) { - return (Builder) super.setRepeatedField(field, index, value); - } - public Builder addRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return (Builder) super.addRepeatedField(field, value); - } - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof biz.nynja.search.grpc.SearchResponse) { - return mergeFrom((biz.nynja.search.grpc.SearchResponse)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(biz.nynja.search.grpc.SearchResponse other) { - if (other == biz.nynja.search.grpc.SearchResponse.getDefaultInstance()) return this; - if (other.getRequestId() != 0L) { - setRequestId(other.getRequestId()); - } - switch (other.getResultCase()) { - case ERROR: { - mergeError(other.getError()); - break; - } - case SEARCHRESULTDETAILS: { - mergeSearchResultDetails(other.getSearchResultDetails()); - break; - } - case RESULT_NOT_SET: { - break; - } - } - this.mergeUnknownFields(other.unknownFields); - onChanged(); - return this; - } - - public final boolean isInitialized() { - return true; - } - - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - biz.nynja.search.grpc.SearchResponse parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (biz.nynja.search.grpc.SearchResponse) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - private int resultCase_ = 0; - private java.lang.Object result_; - public ResultCase - getResultCase() { - return ResultCase.forNumber( - resultCase_); - } - - public Builder clearResult() { - resultCase_ = 0; - result_ = null; - onChanged(); - return this; - } - - - private long requestId_ ; - /** - * uint64 requestId = 1; - */ - public long getRequestId() { - return requestId_; - } - /** - * uint64 requestId = 1; - */ - public Builder setRequestId(long value) { - - requestId_ = value; - onChanged(); - return this; - } - /** - * uint64 requestId = 1; - */ - public Builder clearRequestId() { - - requestId_ = 0L; - onChanged(); - return this; - } - - private com.google.protobuf.SingleFieldBuilderV3< - biz.nynja.search.grpc.ErrorResponse, biz.nynja.search.grpc.ErrorResponse.Builder, biz.nynja.search.grpc.ErrorResponseOrBuilder> errorBuilder_; - /** - * .account.ErrorResponse error = 2; - */ - public boolean hasError() { - return resultCase_ == 2; - } - /** - * .account.ErrorResponse error = 2; - */ - public biz.nynja.search.grpc.ErrorResponse getError() { - if (errorBuilder_ == null) { - if (resultCase_ == 2) { - return (biz.nynja.search.grpc.ErrorResponse) result_; - } - return biz.nynja.search.grpc.ErrorResponse.getDefaultInstance(); - } else { - if (resultCase_ == 2) { - return errorBuilder_.getMessage(); - } - return biz.nynja.search.grpc.ErrorResponse.getDefaultInstance(); - } - } - /** - * .account.ErrorResponse error = 2; - */ - public Builder setError(biz.nynja.search.grpc.ErrorResponse value) { - if (errorBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - result_ = value; - onChanged(); - } else { - errorBuilder_.setMessage(value); - } - resultCase_ = 2; - return this; - } - /** - * .account.ErrorResponse error = 2; - */ - public Builder setError( - biz.nynja.search.grpc.ErrorResponse.Builder builderForValue) { - if (errorBuilder_ == null) { - result_ = builderForValue.build(); - onChanged(); - } else { - errorBuilder_.setMessage(builderForValue.build()); - } - resultCase_ = 2; - return this; - } - /** - * .account.ErrorResponse error = 2; - */ - public Builder mergeError(biz.nynja.search.grpc.ErrorResponse value) { - if (errorBuilder_ == null) { - if (resultCase_ == 2 && - result_ != biz.nynja.search.grpc.ErrorResponse.getDefaultInstance()) { - result_ = biz.nynja.search.grpc.ErrorResponse.newBuilder((biz.nynja.search.grpc.ErrorResponse) result_) - .mergeFrom(value).buildPartial(); - } else { - result_ = value; - } - onChanged(); - } else { - if (resultCase_ == 2) { - errorBuilder_.mergeFrom(value); - } - errorBuilder_.setMessage(value); - } - resultCase_ = 2; - return this; - } - /** - * .account.ErrorResponse error = 2; - */ - public Builder clearError() { - if (errorBuilder_ == null) { - if (resultCase_ == 2) { - resultCase_ = 0; - result_ = null; - onChanged(); - } - } else { - if (resultCase_ == 2) { - resultCase_ = 0; - result_ = null; - } - errorBuilder_.clear(); - } - return this; - } - /** - * .account.ErrorResponse error = 2; - */ - public biz.nynja.search.grpc.ErrorResponse.Builder getErrorBuilder() { - return getErrorFieldBuilder().getBuilder(); - } - /** - * .account.ErrorResponse error = 2; - */ - public biz.nynja.search.grpc.ErrorResponseOrBuilder getErrorOrBuilder() { - if ((resultCase_ == 2) && (errorBuilder_ != null)) { - return errorBuilder_.getMessageOrBuilder(); - } else { - if (resultCase_ == 2) { - return (biz.nynja.search.grpc.ErrorResponse) result_; - } - return biz.nynja.search.grpc.ErrorResponse.getDefaultInstance(); - } - } - /** - * .account.ErrorResponse error = 2; - */ - private com.google.protobuf.SingleFieldBuilderV3< - biz.nynja.search.grpc.ErrorResponse, biz.nynja.search.grpc.ErrorResponse.Builder, biz.nynja.search.grpc.ErrorResponseOrBuilder> - getErrorFieldBuilder() { - if (errorBuilder_ == null) { - if (!(resultCase_ == 2)) { - result_ = biz.nynja.search.grpc.ErrorResponse.getDefaultInstance(); - } - errorBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< - biz.nynja.search.grpc.ErrorResponse, biz.nynja.search.grpc.ErrorResponse.Builder, biz.nynja.search.grpc.ErrorResponseOrBuilder>( - (biz.nynja.search.grpc.ErrorResponse) result_, - getParentForChildren(), - isClean()); - result_ = null; - } - resultCase_ = 2; - onChanged();; - return errorBuilder_; - } - - private com.google.protobuf.SingleFieldBuilderV3< - biz.nynja.search.grpc.SearchResultDetails, biz.nynja.search.grpc.SearchResultDetails.Builder, biz.nynja.search.grpc.SearchResultDetailsOrBuilder> searchResultDetailsBuilder_; - /** - * .account.SearchResultDetails searchResultDetails = 3; - */ - public boolean hasSearchResultDetails() { - return resultCase_ == 3; - } - /** - * .account.SearchResultDetails searchResultDetails = 3; - */ - public biz.nynja.search.grpc.SearchResultDetails getSearchResultDetails() { - if (searchResultDetailsBuilder_ == null) { - if (resultCase_ == 3) { - return (biz.nynja.search.grpc.SearchResultDetails) result_; - } - return biz.nynja.search.grpc.SearchResultDetails.getDefaultInstance(); - } else { - if (resultCase_ == 3) { - return searchResultDetailsBuilder_.getMessage(); - } - return biz.nynja.search.grpc.SearchResultDetails.getDefaultInstance(); - } - } - /** - * .account.SearchResultDetails searchResultDetails = 3; - */ - public Builder setSearchResultDetails(biz.nynja.search.grpc.SearchResultDetails value) { - if (searchResultDetailsBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - result_ = value; - onChanged(); - } else { - searchResultDetailsBuilder_.setMessage(value); - } - resultCase_ = 3; - return this; - } - /** - * .account.SearchResultDetails searchResultDetails = 3; - */ - public Builder setSearchResultDetails( - biz.nynja.search.grpc.SearchResultDetails.Builder builderForValue) { - if (searchResultDetailsBuilder_ == null) { - result_ = builderForValue.build(); - onChanged(); - } else { - searchResultDetailsBuilder_.setMessage(builderForValue.build()); - } - resultCase_ = 3; - return this; - } - /** - * .account.SearchResultDetails searchResultDetails = 3; - */ - public Builder mergeSearchResultDetails(biz.nynja.search.grpc.SearchResultDetails value) { - if (searchResultDetailsBuilder_ == null) { - if (resultCase_ == 3 && - result_ != biz.nynja.search.grpc.SearchResultDetails.getDefaultInstance()) { - result_ = biz.nynja.search.grpc.SearchResultDetails.newBuilder((biz.nynja.search.grpc.SearchResultDetails) result_) - .mergeFrom(value).buildPartial(); - } else { - result_ = value; - } - onChanged(); - } else { - if (resultCase_ == 3) { - searchResultDetailsBuilder_.mergeFrom(value); - } - searchResultDetailsBuilder_.setMessage(value); - } - resultCase_ = 3; - return this; - } - /** - * .account.SearchResultDetails searchResultDetails = 3; - */ - public Builder clearSearchResultDetails() { - if (searchResultDetailsBuilder_ == null) { - if (resultCase_ == 3) { - resultCase_ = 0; - result_ = null; - onChanged(); - } - } else { - if (resultCase_ == 3) { - resultCase_ = 0; - result_ = null; - } - searchResultDetailsBuilder_.clear(); - } - return this; - } - /** - * .account.SearchResultDetails searchResultDetails = 3; - */ - public biz.nynja.search.grpc.SearchResultDetails.Builder getSearchResultDetailsBuilder() { - return getSearchResultDetailsFieldBuilder().getBuilder(); - } - /** - * .account.SearchResultDetails searchResultDetails = 3; - */ - public biz.nynja.search.grpc.SearchResultDetailsOrBuilder getSearchResultDetailsOrBuilder() { - if ((resultCase_ == 3) && (searchResultDetailsBuilder_ != null)) { - return searchResultDetailsBuilder_.getMessageOrBuilder(); - } else { - if (resultCase_ == 3) { - return (biz.nynja.search.grpc.SearchResultDetails) result_; - } - return biz.nynja.search.grpc.SearchResultDetails.getDefaultInstance(); - } - } - /** - * .account.SearchResultDetails searchResultDetails = 3; - */ - private com.google.protobuf.SingleFieldBuilderV3< - biz.nynja.search.grpc.SearchResultDetails, biz.nynja.search.grpc.SearchResultDetails.Builder, biz.nynja.search.grpc.SearchResultDetailsOrBuilder> - getSearchResultDetailsFieldBuilder() { - if (searchResultDetailsBuilder_ == null) { - if (!(resultCase_ == 3)) { - result_ = biz.nynja.search.grpc.SearchResultDetails.getDefaultInstance(); - } - searchResultDetailsBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< - biz.nynja.search.grpc.SearchResultDetails, biz.nynja.search.grpc.SearchResultDetails.Builder, biz.nynja.search.grpc.SearchResultDetailsOrBuilder>( - (biz.nynja.search.grpc.SearchResultDetails) result_, - getParentForChildren(), - isClean()); - result_ = null; - } - resultCase_ = 3; - onChanged();; - return searchResultDetailsBuilder_; - } - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFieldsProto3(unknownFields); - } - - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } - - - // @@protoc_insertion_point(builder_scope:account.SearchResponse) - } - - // @@protoc_insertion_point(class_scope:account.SearchResponse) - private static final biz.nynja.search.grpc.SearchResponse DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new biz.nynja.search.grpc.SearchResponse(); - } - - public static biz.nynja.search.grpc.SearchResponse getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - public SearchResponse parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new SearchResponse(input, extensionRegistry); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - public biz.nynja.search.grpc.SearchResponse getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - -} - diff --git a/src/main/java/biz/nynja/search/grpc/SearchResponseOrBuilder.java b/src/main/java/biz/nynja/search/grpc/SearchResponseOrBuilder.java deleted file mode 100644 index 1249eaa..0000000 --- a/src/main/java/biz/nynja/search/grpc/SearchResponseOrBuilder.java +++ /dev/null @@ -1,42 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: search.proto - -package biz.nynja.search.grpc; - -public interface SearchResponseOrBuilder extends - // @@protoc_insertion_point(interface_extends:account.SearchResponse) - com.google.protobuf.MessageOrBuilder { - - /** - * uint64 requestId = 1; - */ - long getRequestId(); - - /** - * .account.ErrorResponse error = 2; - */ - boolean hasError(); - /** - * .account.ErrorResponse error = 2; - */ - biz.nynja.search.grpc.ErrorResponse getError(); - /** - * .account.ErrorResponse error = 2; - */ - biz.nynja.search.grpc.ErrorResponseOrBuilder getErrorOrBuilder(); - - /** - * .account.SearchResultDetails searchResultDetails = 3; - */ - boolean hasSearchResultDetails(); - /** - * .account.SearchResultDetails searchResultDetails = 3; - */ - biz.nynja.search.grpc.SearchResultDetails getSearchResultDetails(); - /** - * .account.SearchResultDetails searchResultDetails = 3; - */ - biz.nynja.search.grpc.SearchResultDetailsOrBuilder getSearchResultDetailsOrBuilder(); - - public biz.nynja.search.grpc.SearchResponse.ResultCase getResultCase(); -} diff --git a/src/main/java/biz/nynja/search/grpc/SearchResultDetails.java b/src/main/java/biz/nynja/search/grpc/SearchResultDetails.java deleted file mode 100644 index 5191524..0000000 --- a/src/main/java/biz/nynja/search/grpc/SearchResultDetails.java +++ /dev/null @@ -1,1405 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: search.proto - -package biz.nynja.search.grpc; - -/** - * Protobuf type {@code account.SearchResultDetails} - */ -public final class SearchResultDetails extends - com.google.protobuf.GeneratedMessageV3 implements - // @@protoc_insertion_point(message_implements:account.SearchResultDetails) - SearchResultDetailsOrBuilder { -private static final long serialVersionUID = 0L; - // Use SearchResultDetails.newBuilder() to construct. - private SearchResultDetails(com.google.protobuf.GeneratedMessageV3.Builder builder) { - super(builder); - } - private SearchResultDetails() { - accountId_ = ""; - profileId_ = ""; - authenticationProvider_ = ""; - authenticationType_ = ""; - firstName_ = ""; - lastName_ = ""; - username_ = ""; - qrCode_ = ""; - } - - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private SearchResultDetails( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - if (extensionRegistry == null) { - throw new java.lang.NullPointerException(); - } - int mutable_bitField0_ = 0; - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - default: { - if (!parseUnknownFieldProto3( - input, unknownFields, extensionRegistry, tag)) { - done = true; - } - break; - } - case 10: { - java.lang.String s = input.readStringRequireUtf8(); - - accountId_ = s; - break; - } - case 18: { - java.lang.String s = input.readStringRequireUtf8(); - - profileId_ = s; - break; - } - case 26: { - java.lang.String s = input.readStringRequireUtf8(); - - authenticationProvider_ = s; - break; - } - case 34: { - java.lang.String s = input.readStringRequireUtf8(); - - authenticationType_ = s; - break; - } - case 42: { - java.lang.String s = input.readStringRequireUtf8(); - - firstName_ = s; - break; - } - case 50: { - java.lang.String s = input.readStringRequireUtf8(); - - lastName_ = s; - break; - } - case 58: { - java.lang.String s = input.readStringRequireUtf8(); - - username_ = s; - break; - } - case 66: { - java.lang.String s = input.readStringRequireUtf8(); - - qrCode_ = s; - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return biz.nynja.search.grpc.Search.internal_static_account_SearchResultDetails_descriptor; - } - - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return biz.nynja.search.grpc.Search.internal_static_account_SearchResultDetails_fieldAccessorTable - .ensureFieldAccessorsInitialized( - biz.nynja.search.grpc.SearchResultDetails.class, biz.nynja.search.grpc.SearchResultDetails.Builder.class); - } - - public static final int ACCOUNTID_FIELD_NUMBER = 1; - private volatile java.lang.Object accountId_; - /** - * string accountId = 1; - */ - public java.lang.String getAccountId() { - java.lang.Object ref = accountId_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - accountId_ = s; - return s; - } - } - /** - * string accountId = 1; - */ - public com.google.protobuf.ByteString - getAccountIdBytes() { - java.lang.Object ref = accountId_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - accountId_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int PROFILEID_FIELD_NUMBER = 2; - private volatile java.lang.Object profileId_; - /** - * string profileId = 2; - */ - public java.lang.String getProfileId() { - java.lang.Object ref = profileId_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - profileId_ = s; - return s; - } - } - /** - * string profileId = 2; - */ - public com.google.protobuf.ByteString - getProfileIdBytes() { - java.lang.Object ref = profileId_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - profileId_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int AUTHENTICATIONPROVIDER_FIELD_NUMBER = 3; - private volatile java.lang.Object authenticationProvider_; - /** - * string authenticationProvider = 3; - */ - public java.lang.String getAuthenticationProvider() { - java.lang.Object ref = authenticationProvider_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - authenticationProvider_ = s; - return s; - } - } - /** - * string authenticationProvider = 3; - */ - public com.google.protobuf.ByteString - getAuthenticationProviderBytes() { - java.lang.Object ref = authenticationProvider_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - authenticationProvider_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int AUTHENTICATIONTYPE_FIELD_NUMBER = 4; - private volatile java.lang.Object authenticationType_; - /** - * string authenticationType = 4; - */ - public java.lang.String getAuthenticationType() { - java.lang.Object ref = authenticationType_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - authenticationType_ = s; - return s; - } - } - /** - * string authenticationType = 4; - */ - public com.google.protobuf.ByteString - getAuthenticationTypeBytes() { - java.lang.Object ref = authenticationType_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - authenticationType_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int FIRSTNAME_FIELD_NUMBER = 5; - private volatile java.lang.Object firstName_; - /** - * string firstName = 5; - */ - public java.lang.String getFirstName() { - java.lang.Object ref = firstName_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - firstName_ = s; - return s; - } - } - /** - * string firstName = 5; - */ - public com.google.protobuf.ByteString - getFirstNameBytes() { - java.lang.Object ref = firstName_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - firstName_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int LASTNAME_FIELD_NUMBER = 6; - private volatile java.lang.Object lastName_; - /** - * string lastName = 6; - */ - public java.lang.String getLastName() { - java.lang.Object ref = lastName_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - lastName_ = s; - return s; - } - } - /** - * string lastName = 6; - */ - public com.google.protobuf.ByteString - getLastNameBytes() { - java.lang.Object ref = lastName_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - lastName_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int USERNAME_FIELD_NUMBER = 7; - private volatile java.lang.Object username_; - /** - * string username = 7; - */ - public java.lang.String getUsername() { - java.lang.Object ref = username_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - username_ = s; - return s; - } - } - /** - * string username = 7; - */ - public com.google.protobuf.ByteString - getUsernameBytes() { - java.lang.Object ref = username_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - username_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int QRCODE_FIELD_NUMBER = 8; - private volatile java.lang.Object qrCode_; - /** - * string qrCode = 8; - */ - public java.lang.String getQrCode() { - java.lang.Object ref = qrCode_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - qrCode_ = s; - return s; - } - } - /** - * string qrCode = 8; - */ - public com.google.protobuf.ByteString - getQrCodeBytes() { - java.lang.Object ref = qrCode_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - qrCode_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - private byte memoizedIsInitialized = -1; - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - if (!getAccountIdBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 1, accountId_); - } - if (!getProfileIdBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 2, profileId_); - } - if (!getAuthenticationProviderBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 3, authenticationProvider_); - } - if (!getAuthenticationTypeBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 4, authenticationType_); - } - if (!getFirstNameBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 5, firstName_); - } - if (!getLastNameBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 6, lastName_); - } - if (!getUsernameBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 7, username_); - } - if (!getQrCodeBytes().isEmpty()) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 8, qrCode_); - } - unknownFields.writeTo(output); - } - - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - if (!getAccountIdBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, accountId_); - } - if (!getProfileIdBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, profileId_); - } - if (!getAuthenticationProviderBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(3, authenticationProvider_); - } - if (!getAuthenticationTypeBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(4, authenticationType_); - } - if (!getFirstNameBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(5, firstName_); - } - if (!getLastNameBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(6, lastName_); - } - if (!getUsernameBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(7, username_); - } - if (!getQrCodeBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(8, qrCode_); - } - size += unknownFields.getSerializedSize(); - memoizedSize = size; - return size; - } - - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof biz.nynja.search.grpc.SearchResultDetails)) { - return super.equals(obj); - } - biz.nynja.search.grpc.SearchResultDetails other = (biz.nynja.search.grpc.SearchResultDetails) obj; - - boolean result = true; - result = result && getAccountId() - .equals(other.getAccountId()); - result = result && getProfileId() - .equals(other.getProfileId()); - result = result && getAuthenticationProvider() - .equals(other.getAuthenticationProvider()); - result = result && getAuthenticationType() - .equals(other.getAuthenticationType()); - result = result && getFirstName() - .equals(other.getFirstName()); - result = result && getLastName() - .equals(other.getLastName()); - result = result && getUsername() - .equals(other.getUsername()); - result = result && getQrCode() - .equals(other.getQrCode()); - result = result && unknownFields.equals(other.unknownFields); - return result; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptor().hashCode(); - hash = (37 * hash) + ACCOUNTID_FIELD_NUMBER; - hash = (53 * hash) + getAccountId().hashCode(); - hash = (37 * hash) + PROFILEID_FIELD_NUMBER; - hash = (53 * hash) + getProfileId().hashCode(); - hash = (37 * hash) + AUTHENTICATIONPROVIDER_FIELD_NUMBER; - hash = (53 * hash) + getAuthenticationProvider().hashCode(); - hash = (37 * hash) + AUTHENTICATIONTYPE_FIELD_NUMBER; - hash = (53 * hash) + getAuthenticationType().hashCode(); - hash = (37 * hash) + FIRSTNAME_FIELD_NUMBER; - hash = (53 * hash) + getFirstName().hashCode(); - hash = (37 * hash) + LASTNAME_FIELD_NUMBER; - hash = (53 * hash) + getLastName().hashCode(); - hash = (37 * hash) + USERNAME_FIELD_NUMBER; - hash = (53 * hash) + getUsername().hashCode(); - hash = (37 * hash) + QRCODE_FIELD_NUMBER; - hash = (53 * hash) + getQrCode().hashCode(); - hash = (29 * hash) + unknownFields.hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static biz.nynja.search.grpc.SearchResultDetails parseFrom( - java.nio.ByteBuffer data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static biz.nynja.search.grpc.SearchResultDetails parseFrom( - java.nio.ByteBuffer data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static biz.nynja.search.grpc.SearchResultDetails parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static biz.nynja.search.grpc.SearchResultDetails parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static biz.nynja.search.grpc.SearchResultDetails parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static biz.nynja.search.grpc.SearchResultDetails parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static biz.nynja.search.grpc.SearchResultDetails parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static biz.nynja.search.grpc.SearchResultDetails parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - public static biz.nynja.search.grpc.SearchResultDetails parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input); - } - public static biz.nynja.search.grpc.SearchResultDetails parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static biz.nynja.search.grpc.SearchResultDetails parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input); - } - public static biz.nynja.search.grpc.SearchResultDetails parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessageV3 - .parseWithIOException(PARSER, input, extensionRegistry); - } - - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(biz.nynja.search.grpc.SearchResultDetails prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code account.SearchResultDetails} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessageV3.Builder implements - // @@protoc_insertion_point(builder_implements:account.SearchResultDetails) - biz.nynja.search.grpc.SearchResultDetailsOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return biz.nynja.search.grpc.Search.internal_static_account_SearchResultDetails_descriptor; - } - - protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable - internalGetFieldAccessorTable() { - return biz.nynja.search.grpc.Search.internal_static_account_SearchResultDetails_fieldAccessorTable - .ensureFieldAccessorsInitialized( - biz.nynja.search.grpc.SearchResultDetails.class, biz.nynja.search.grpc.SearchResultDetails.Builder.class); - } - - // Construct using biz.nynja.search.grpc.SearchResultDetails.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessageV3 - .alwaysUseFieldBuilders) { - } - } - public Builder clear() { - super.clear(); - accountId_ = ""; - - profileId_ = ""; - - authenticationProvider_ = ""; - - authenticationType_ = ""; - - firstName_ = ""; - - lastName_ = ""; - - username_ = ""; - - qrCode_ = ""; - - return this; - } - - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return biz.nynja.search.grpc.Search.internal_static_account_SearchResultDetails_descriptor; - } - - public biz.nynja.search.grpc.SearchResultDetails getDefaultInstanceForType() { - return biz.nynja.search.grpc.SearchResultDetails.getDefaultInstance(); - } - - public biz.nynja.search.grpc.SearchResultDetails build() { - biz.nynja.search.grpc.SearchResultDetails result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - public biz.nynja.search.grpc.SearchResultDetails buildPartial() { - biz.nynja.search.grpc.SearchResultDetails result = new biz.nynja.search.grpc.SearchResultDetails(this); - result.accountId_ = accountId_; - result.profileId_ = profileId_; - result.authenticationProvider_ = authenticationProvider_; - result.authenticationType_ = authenticationType_; - result.firstName_ = firstName_; - result.lastName_ = lastName_; - result.username_ = username_; - result.qrCode_ = qrCode_; - onBuilt(); - return result; - } - - public Builder clone() { - return (Builder) super.clone(); - } - public Builder setField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return (Builder) super.setField(field, value); - } - public Builder clearField( - com.google.protobuf.Descriptors.FieldDescriptor field) { - return (Builder) super.clearField(field); - } - public Builder clearOneof( - com.google.protobuf.Descriptors.OneofDescriptor oneof) { - return (Builder) super.clearOneof(oneof); - } - public Builder setRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - int index, java.lang.Object value) { - return (Builder) super.setRepeatedField(field, index, value); - } - public Builder addRepeatedField( - com.google.protobuf.Descriptors.FieldDescriptor field, - java.lang.Object value) { - return (Builder) super.addRepeatedField(field, value); - } - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof biz.nynja.search.grpc.SearchResultDetails) { - return mergeFrom((biz.nynja.search.grpc.SearchResultDetails)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(biz.nynja.search.grpc.SearchResultDetails other) { - if (other == biz.nynja.search.grpc.SearchResultDetails.getDefaultInstance()) return this; - if (!other.getAccountId().isEmpty()) { - accountId_ = other.accountId_; - onChanged(); - } - if (!other.getProfileId().isEmpty()) { - profileId_ = other.profileId_; - onChanged(); - } - if (!other.getAuthenticationProvider().isEmpty()) { - authenticationProvider_ = other.authenticationProvider_; - onChanged(); - } - if (!other.getAuthenticationType().isEmpty()) { - authenticationType_ = other.authenticationType_; - onChanged(); - } - if (!other.getFirstName().isEmpty()) { - firstName_ = other.firstName_; - onChanged(); - } - if (!other.getLastName().isEmpty()) { - lastName_ = other.lastName_; - onChanged(); - } - if (!other.getUsername().isEmpty()) { - username_ = other.username_; - onChanged(); - } - if (!other.getQrCode().isEmpty()) { - qrCode_ = other.qrCode_; - onChanged(); - } - this.mergeUnknownFields(other.unknownFields); - onChanged(); - return this; - } - - public final boolean isInitialized() { - return true; - } - - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - biz.nynja.search.grpc.SearchResultDetails parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (biz.nynja.search.grpc.SearchResultDetails) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - - private java.lang.Object accountId_ = ""; - /** - * string accountId = 1; - */ - public java.lang.String getAccountId() { - java.lang.Object ref = accountId_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - accountId_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * string accountId = 1; - */ - public com.google.protobuf.ByteString - getAccountIdBytes() { - java.lang.Object ref = accountId_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - accountId_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string accountId = 1; - */ - public Builder setAccountId( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - accountId_ = value; - onChanged(); - return this; - } - /** - * string accountId = 1; - */ - public Builder clearAccountId() { - - accountId_ = getDefaultInstance().getAccountId(); - onChanged(); - return this; - } - /** - * string accountId = 1; - */ - public Builder setAccountIdBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - accountId_ = value; - onChanged(); - return this; - } - - private java.lang.Object profileId_ = ""; - /** - * string profileId = 2; - */ - public java.lang.String getProfileId() { - java.lang.Object ref = profileId_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - profileId_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * string profileId = 2; - */ - public com.google.protobuf.ByteString - getProfileIdBytes() { - java.lang.Object ref = profileId_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - profileId_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string profileId = 2; - */ - public Builder setProfileId( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - profileId_ = value; - onChanged(); - return this; - } - /** - * string profileId = 2; - */ - public Builder clearProfileId() { - - profileId_ = getDefaultInstance().getProfileId(); - onChanged(); - return this; - } - /** - * string profileId = 2; - */ - public Builder setProfileIdBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - profileId_ = value; - onChanged(); - return this; - } - - private java.lang.Object authenticationProvider_ = ""; - /** - * string authenticationProvider = 3; - */ - public java.lang.String getAuthenticationProvider() { - java.lang.Object ref = authenticationProvider_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - authenticationProvider_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * string authenticationProvider = 3; - */ - public com.google.protobuf.ByteString - getAuthenticationProviderBytes() { - java.lang.Object ref = authenticationProvider_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - authenticationProvider_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string authenticationProvider = 3; - */ - public Builder setAuthenticationProvider( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - authenticationProvider_ = value; - onChanged(); - return this; - } - /** - * string authenticationProvider = 3; - */ - public Builder clearAuthenticationProvider() { - - authenticationProvider_ = getDefaultInstance().getAuthenticationProvider(); - onChanged(); - return this; - } - /** - * string authenticationProvider = 3; - */ - public Builder setAuthenticationProviderBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - authenticationProvider_ = value; - onChanged(); - return this; - } - - private java.lang.Object authenticationType_ = ""; - /** - * string authenticationType = 4; - */ - public java.lang.String getAuthenticationType() { - java.lang.Object ref = authenticationType_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - authenticationType_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * string authenticationType = 4; - */ - public com.google.protobuf.ByteString - getAuthenticationTypeBytes() { - java.lang.Object ref = authenticationType_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - authenticationType_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string authenticationType = 4; - */ - public Builder setAuthenticationType( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - authenticationType_ = value; - onChanged(); - return this; - } - /** - * string authenticationType = 4; - */ - public Builder clearAuthenticationType() { - - authenticationType_ = getDefaultInstance().getAuthenticationType(); - onChanged(); - return this; - } - /** - * string authenticationType = 4; - */ - public Builder setAuthenticationTypeBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - authenticationType_ = value; - onChanged(); - return this; - } - - private java.lang.Object firstName_ = ""; - /** - * string firstName = 5; - */ - public java.lang.String getFirstName() { - java.lang.Object ref = firstName_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - firstName_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * string firstName = 5; - */ - public com.google.protobuf.ByteString - getFirstNameBytes() { - java.lang.Object ref = firstName_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - firstName_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string firstName = 5; - */ - public Builder setFirstName( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - firstName_ = value; - onChanged(); - return this; - } - /** - * string firstName = 5; - */ - public Builder clearFirstName() { - - firstName_ = getDefaultInstance().getFirstName(); - onChanged(); - return this; - } - /** - * string firstName = 5; - */ - public Builder setFirstNameBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - firstName_ = value; - onChanged(); - return this; - } - - private java.lang.Object lastName_ = ""; - /** - * string lastName = 6; - */ - public java.lang.String getLastName() { - java.lang.Object ref = lastName_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - lastName_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * string lastName = 6; - */ - public com.google.protobuf.ByteString - getLastNameBytes() { - java.lang.Object ref = lastName_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - lastName_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string lastName = 6; - */ - public Builder setLastName( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - lastName_ = value; - onChanged(); - return this; - } - /** - * string lastName = 6; - */ - public Builder clearLastName() { - - lastName_ = getDefaultInstance().getLastName(); - onChanged(); - return this; - } - /** - * string lastName = 6; - */ - public Builder setLastNameBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - lastName_ = value; - onChanged(); - return this; - } - - private java.lang.Object username_ = ""; - /** - * string username = 7; - */ - public java.lang.String getUsername() { - java.lang.Object ref = username_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - username_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * string username = 7; - */ - public com.google.protobuf.ByteString - getUsernameBytes() { - java.lang.Object ref = username_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - username_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string username = 7; - */ - public Builder setUsername( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - username_ = value; - onChanged(); - return this; - } - /** - * string username = 7; - */ - public Builder clearUsername() { - - username_ = getDefaultInstance().getUsername(); - onChanged(); - return this; - } - /** - * string username = 7; - */ - public Builder setUsernameBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - username_ = value; - onChanged(); - return this; - } - - private java.lang.Object qrCode_ = ""; - /** - * string qrCode = 8; - */ - public java.lang.String getQrCode() { - java.lang.Object ref = qrCode_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - qrCode_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * string qrCode = 8; - */ - public com.google.protobuf.ByteString - getQrCodeBytes() { - java.lang.Object ref = qrCode_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - qrCode_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string qrCode = 8; - */ - public Builder setQrCode( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - qrCode_ = value; - onChanged(); - return this; - } - /** - * string qrCode = 8; - */ - public Builder clearQrCode() { - - qrCode_ = getDefaultInstance().getQrCode(); - onChanged(); - return this; - } - /** - * string qrCode = 8; - */ - public Builder setQrCodeBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - qrCode_ = value; - onChanged(); - return this; - } - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.setUnknownFieldsProto3(unknownFields); - } - - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return super.mergeUnknownFields(unknownFields); - } - - - // @@protoc_insertion_point(builder_scope:account.SearchResultDetails) - } - - // @@protoc_insertion_point(class_scope:account.SearchResultDetails) - private static final biz.nynja.search.grpc.SearchResultDetails DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new biz.nynja.search.grpc.SearchResultDetails(); - } - - public static biz.nynja.search.grpc.SearchResultDetails getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - public SearchResultDetails parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new SearchResultDetails(input, extensionRegistry); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - public biz.nynja.search.grpc.SearchResultDetails getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - -} - diff --git a/src/main/java/biz/nynja/search/grpc/SearchResultDetailsOrBuilder.java b/src/main/java/biz/nynja/search/grpc/SearchResultDetailsOrBuilder.java deleted file mode 100644 index 1541d2d..0000000 --- a/src/main/java/biz/nynja/search/grpc/SearchResultDetailsOrBuilder.java +++ /dev/null @@ -1,89 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: search.proto - -package biz.nynja.search.grpc; - -public interface SearchResultDetailsOrBuilder extends - // @@protoc_insertion_point(interface_extends:account.SearchResultDetails) - com.google.protobuf.MessageOrBuilder { - - /** - * string accountId = 1; - */ - java.lang.String getAccountId(); - /** - * string accountId = 1; - */ - com.google.protobuf.ByteString - getAccountIdBytes(); - - /** - * string profileId = 2; - */ - java.lang.String getProfileId(); - /** - * string profileId = 2; - */ - com.google.protobuf.ByteString - getProfileIdBytes(); - - /** - * string authenticationProvider = 3; - */ - java.lang.String getAuthenticationProvider(); - /** - * string authenticationProvider = 3; - */ - com.google.protobuf.ByteString - getAuthenticationProviderBytes(); - - /** - * string authenticationType = 4; - */ - java.lang.String getAuthenticationType(); - /** - * string authenticationType = 4; - */ - com.google.protobuf.ByteString - getAuthenticationTypeBytes(); - - /** - * string firstName = 5; - */ - java.lang.String getFirstName(); - /** - * string firstName = 5; - */ - com.google.protobuf.ByteString - getFirstNameBytes(); - - /** - * string lastName = 6; - */ - java.lang.String getLastName(); - /** - * string lastName = 6; - */ - com.google.protobuf.ByteString - getLastNameBytes(); - - /** - * string username = 7; - */ - java.lang.String getUsername(); - /** - * string username = 7; - */ - com.google.protobuf.ByteString - getUsernameBytes(); - - /** - * string qrCode = 8; - */ - java.lang.String getQrCode(); - /** - * string qrCode = 8; - */ - com.google.protobuf.ByteString - getQrCodeBytes(); -} diff --git a/src/main/java/biz/nynja/search/grpc/SearchService.java b/src/main/java/biz/nynja/search/grpc/SearchService.java deleted file mode 100644 index 6fdbe5c..0000000 --- a/src/main/java/biz/nynja/search/grpc/SearchService.java +++ /dev/null @@ -1,237 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: search.proto - -package biz.nynja.search.grpc; - -/** - * Protobuf service {@code account.SearchService} - */ -public abstract class SearchService - implements com.google.protobuf.Service { - protected SearchService() {} - - public interface Interface { - /** - * rpc searchByUsername(.account.SearchByUsernameRequest) returns (.account.SearchResponse); - */ - public abstract void searchByUsername( - com.google.protobuf.RpcController controller, - biz.nynja.search.grpc.SearchByUsernameRequest request, - com.google.protobuf.RpcCallback done); - - } - - public static com.google.protobuf.Service newReflectiveService( - final Interface impl) { - return new SearchService() { - @java.lang.Override - public void searchByUsername( - com.google.protobuf.RpcController controller, - biz.nynja.search.grpc.SearchByUsernameRequest request, - com.google.protobuf.RpcCallback done) { - impl.searchByUsername(controller, request, done); - } - - }; - } - - public static com.google.protobuf.BlockingService - newReflectiveBlockingService(final BlockingInterface impl) { - return new com.google.protobuf.BlockingService() { - public final com.google.protobuf.Descriptors.ServiceDescriptor - getDescriptorForType() { - return getDescriptor(); - } - - public final com.google.protobuf.Message callBlockingMethod( - com.google.protobuf.Descriptors.MethodDescriptor method, - com.google.protobuf.RpcController controller, - com.google.protobuf.Message request) - throws com.google.protobuf.ServiceException { - if (method.getService() != getDescriptor()) { - throw new java.lang.IllegalArgumentException( - "Service.callBlockingMethod() given method descriptor for " + - "wrong service type."); - } - switch(method.getIndex()) { - case 0: - return impl.searchByUsername(controller, (biz.nynja.search.grpc.SearchByUsernameRequest)request); - default: - throw new java.lang.AssertionError("Can't get here."); - } - } - - public final com.google.protobuf.Message - getRequestPrototype( - com.google.protobuf.Descriptors.MethodDescriptor method) { - if (method.getService() != getDescriptor()) { - throw new java.lang.IllegalArgumentException( - "Service.getRequestPrototype() given method " + - "descriptor for wrong service type."); - } - switch(method.getIndex()) { - case 0: - return biz.nynja.search.grpc.SearchByUsernameRequest.getDefaultInstance(); - default: - throw new java.lang.AssertionError("Can't get here."); - } - } - - public final com.google.protobuf.Message - getResponsePrototype( - com.google.protobuf.Descriptors.MethodDescriptor method) { - if (method.getService() != getDescriptor()) { - throw new java.lang.IllegalArgumentException( - "Service.getResponsePrototype() given method " + - "descriptor for wrong service type."); - } - switch(method.getIndex()) { - case 0: - return biz.nynja.search.grpc.SearchResponse.getDefaultInstance(); - default: - throw new java.lang.AssertionError("Can't get here."); - } - } - - }; - } - - /** - * rpc searchByUsername(.account.SearchByUsernameRequest) returns (.account.SearchResponse); - */ - public abstract void searchByUsername( - com.google.protobuf.RpcController controller, - biz.nynja.search.grpc.SearchByUsernameRequest request, - com.google.protobuf.RpcCallback done); - - public static final - com.google.protobuf.Descriptors.ServiceDescriptor - getDescriptor() { - return biz.nynja.search.grpc.Search.getDescriptor().getServices().get(0); - } - public final com.google.protobuf.Descriptors.ServiceDescriptor - getDescriptorForType() { - return getDescriptor(); - } - - public final void callMethod( - com.google.protobuf.Descriptors.MethodDescriptor method, - com.google.protobuf.RpcController controller, - com.google.protobuf.Message request, - com.google.protobuf.RpcCallback< - com.google.protobuf.Message> done) { - if (method.getService() != getDescriptor()) { - throw new java.lang.IllegalArgumentException( - "Service.callMethod() given method descriptor for wrong " + - "service type."); - } - switch(method.getIndex()) { - case 0: - this.searchByUsername(controller, (biz.nynja.search.grpc.SearchByUsernameRequest)request, - com.google.protobuf.RpcUtil.specializeCallback( - done)); - return; - default: - throw new java.lang.AssertionError("Can't get here."); - } - } - - public final com.google.protobuf.Message - getRequestPrototype( - com.google.protobuf.Descriptors.MethodDescriptor method) { - if (method.getService() != getDescriptor()) { - throw new java.lang.IllegalArgumentException( - "Service.getRequestPrototype() given method " + - "descriptor for wrong service type."); - } - switch(method.getIndex()) { - case 0: - return biz.nynja.search.grpc.SearchByUsernameRequest.getDefaultInstance(); - default: - throw new java.lang.AssertionError("Can't get here."); - } - } - - public final com.google.protobuf.Message - getResponsePrototype( - com.google.protobuf.Descriptors.MethodDescriptor method) { - if (method.getService() != getDescriptor()) { - throw new java.lang.IllegalArgumentException( - "Service.getResponsePrototype() given method " + - "descriptor for wrong service type."); - } - switch(method.getIndex()) { - case 0: - return biz.nynja.search.grpc.SearchResponse.getDefaultInstance(); - default: - throw new java.lang.AssertionError("Can't get here."); - } - } - - public static Stub newStub( - com.google.protobuf.RpcChannel channel) { - return new Stub(channel); - } - - public static final class Stub extends biz.nynja.search.grpc.SearchService implements Interface { - private Stub(com.google.protobuf.RpcChannel channel) { - this.channel = channel; - } - - private final com.google.protobuf.RpcChannel channel; - - public com.google.protobuf.RpcChannel getChannel() { - return channel; - } - - public void searchByUsername( - com.google.protobuf.RpcController controller, - biz.nynja.search.grpc.SearchByUsernameRequest request, - com.google.protobuf.RpcCallback done) { - channel.callMethod( - getDescriptor().getMethods().get(0), - controller, - request, - biz.nynja.search.grpc.SearchResponse.getDefaultInstance(), - com.google.protobuf.RpcUtil.generalizeCallback( - done, - biz.nynja.search.grpc.SearchResponse.class, - biz.nynja.search.grpc.SearchResponse.getDefaultInstance())); - } - } - - public static BlockingInterface newBlockingStub( - com.google.protobuf.BlockingRpcChannel channel) { - return new BlockingStub(channel); - } - - public interface BlockingInterface { - public biz.nynja.search.grpc.SearchResponse searchByUsername( - com.google.protobuf.RpcController controller, - biz.nynja.search.grpc.SearchByUsernameRequest request) - throws com.google.protobuf.ServiceException; - } - - private static final class BlockingStub implements BlockingInterface { - private BlockingStub(com.google.protobuf.BlockingRpcChannel channel) { - this.channel = channel; - } - - private final com.google.protobuf.BlockingRpcChannel channel; - - public biz.nynja.search.grpc.SearchResponse searchByUsername( - com.google.protobuf.RpcController controller, - biz.nynja.search.grpc.SearchByUsernameRequest request) - throws com.google.protobuf.ServiceException { - return (biz.nynja.search.grpc.SearchResponse) channel.callBlockingMethod( - getDescriptor().getMethods().get(0), - controller, - request, - biz.nynja.search.grpc.SearchResponse.getDefaultInstance()); - } - - } - - // @@protoc_insertion_point(class_scope:account.SearchService) -} - diff --git a/src/main/java/biz/nynja/search/grpc/SearchServiceGrpc.java b/src/main/java/biz/nynja/search/grpc/SearchServiceGrpc.java deleted file mode 100644 index b7654c8..0000000 --- a/src/main/java/biz/nynja/search/grpc/SearchServiceGrpc.java +++ /dev/null @@ -1,286 +0,0 @@ -package biz.nynja.search.grpc; - -import static io.grpc.MethodDescriptor.generateFullMethodName; -import static io.grpc.stub.ClientCalls.asyncBidiStreamingCall; -import static io.grpc.stub.ClientCalls.asyncClientStreamingCall; -import static io.grpc.stub.ClientCalls.asyncServerStreamingCall; -import static io.grpc.stub.ClientCalls.asyncUnaryCall; -import static io.grpc.stub.ClientCalls.blockingServerStreamingCall; -import static io.grpc.stub.ClientCalls.blockingUnaryCall; -import static io.grpc.stub.ClientCalls.futureUnaryCall; -import static io.grpc.stub.ServerCalls.asyncBidiStreamingCall; -import static io.grpc.stub.ServerCalls.asyncClientStreamingCall; -import static io.grpc.stub.ServerCalls.asyncServerStreamingCall; -import static io.grpc.stub.ServerCalls.asyncUnaryCall; -import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall; -import static io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall; - -/** - */ -@javax.annotation.Generated( - value = "by gRPC proto compiler (version 1.11.0)", - comments = "Source: search.proto") -public final class SearchServiceGrpc { - - private SearchServiceGrpc() {} - - public static final String SERVICE_NAME = "account.SearchService"; - - // Static method descriptors that strictly reflect the proto. - @io.grpc.ExperimentalApi("https://github.com/grpc/grpc-java/issues/1901") - @java.lang.Deprecated // Use {@link #getSearchByUsernameMethod()} instead. - public static final io.grpc.MethodDescriptor METHOD_SEARCH_BY_USERNAME = getSearchByUsernameMethodHelper(); - - private static volatile io.grpc.MethodDescriptor getSearchByUsernameMethod; - - @io.grpc.ExperimentalApi("https://github.com/grpc/grpc-java/issues/1901") - public static io.grpc.MethodDescriptor getSearchByUsernameMethod() { - return getSearchByUsernameMethodHelper(); - } - - private static io.grpc.MethodDescriptor getSearchByUsernameMethodHelper() { - io.grpc.MethodDescriptor getSearchByUsernameMethod; - if ((getSearchByUsernameMethod = SearchServiceGrpc.getSearchByUsernameMethod) == null) { - synchronized (SearchServiceGrpc.class) { - if ((getSearchByUsernameMethod = SearchServiceGrpc.getSearchByUsernameMethod) == null) { - SearchServiceGrpc.getSearchByUsernameMethod = getSearchByUsernameMethod = - io.grpc.MethodDescriptor.newBuilder() - .setType(io.grpc.MethodDescriptor.MethodType.UNARY) - .setFullMethodName(generateFullMethodName( - "account.SearchService", "searchByUsername")) - .setSampledToLocalTracing(true) - .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( - biz.nynja.search.grpc.SearchByUsernameRequest.getDefaultInstance())) - .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( - biz.nynja.search.grpc.SearchResponse.getDefaultInstance())) - .setSchemaDescriptor(new SearchServiceMethodDescriptorSupplier("searchByUsername")) - .build(); - } - } - } - return getSearchByUsernameMethod; - } - - /** - * Creates a new async stub that supports all call types for the service - */ - public static SearchServiceStub newStub(io.grpc.Channel channel) { - return new SearchServiceStub(channel); - } - - /** - * Creates a new blocking-style stub that supports unary and streaming output calls on the service - */ - public static SearchServiceBlockingStub newBlockingStub( - io.grpc.Channel channel) { - return new SearchServiceBlockingStub(channel); - } - - /** - * Creates a new ListenableFuture-style stub that supports unary calls on the service - */ - public static SearchServiceFutureStub newFutureStub( - io.grpc.Channel channel) { - return new SearchServiceFutureStub(channel); - } - - /** - */ - public static abstract class SearchServiceImplBase implements io.grpc.BindableService { - - /** - */ - public void searchByUsername(biz.nynja.search.grpc.SearchByUsernameRequest request, - io.grpc.stub.StreamObserver responseObserver) { - asyncUnimplementedUnaryCall(getSearchByUsernameMethodHelper(), responseObserver); - } - - @java.lang.Override public final io.grpc.ServerServiceDefinition bindService() { - return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor()) - .addMethod( - getSearchByUsernameMethodHelper(), - asyncUnaryCall( - new MethodHandlers< - biz.nynja.search.grpc.SearchByUsernameRequest, - biz.nynja.search.grpc.SearchResponse>( - this, METHODID_SEARCH_BY_USERNAME))) - .build(); - } - } - - /** - */ - public static final class SearchServiceStub extends io.grpc.stub.AbstractStub { - private SearchServiceStub(io.grpc.Channel channel) { - super(channel); - } - - private SearchServiceStub(io.grpc.Channel channel, - io.grpc.CallOptions callOptions) { - super(channel, callOptions); - } - - @java.lang.Override - protected SearchServiceStub build(io.grpc.Channel channel, - io.grpc.CallOptions callOptions) { - return new SearchServiceStub(channel, callOptions); - } - - /** - */ - public void searchByUsername(biz.nynja.search.grpc.SearchByUsernameRequest request, - io.grpc.stub.StreamObserver responseObserver) { - asyncUnaryCall( - getChannel().newCall(getSearchByUsernameMethodHelper(), getCallOptions()), request, responseObserver); - } - } - - /** - */ - public static final class SearchServiceBlockingStub extends io.grpc.stub.AbstractStub { - private SearchServiceBlockingStub(io.grpc.Channel channel) { - super(channel); - } - - private SearchServiceBlockingStub(io.grpc.Channel channel, - io.grpc.CallOptions callOptions) { - super(channel, callOptions); - } - - @java.lang.Override - protected SearchServiceBlockingStub build(io.grpc.Channel channel, - io.grpc.CallOptions callOptions) { - return new SearchServiceBlockingStub(channel, callOptions); - } - - /** - */ - public biz.nynja.search.grpc.SearchResponse searchByUsername(biz.nynja.search.grpc.SearchByUsernameRequest request) { - return blockingUnaryCall( - getChannel(), getSearchByUsernameMethodHelper(), getCallOptions(), request); - } - } - - /** - */ - public static final class SearchServiceFutureStub extends io.grpc.stub.AbstractStub { - private SearchServiceFutureStub(io.grpc.Channel channel) { - super(channel); - } - - private SearchServiceFutureStub(io.grpc.Channel channel, - io.grpc.CallOptions callOptions) { - super(channel, callOptions); - } - - @java.lang.Override - protected SearchServiceFutureStub build(io.grpc.Channel channel, - io.grpc.CallOptions callOptions) { - return new SearchServiceFutureStub(channel, callOptions); - } - - /** - */ - public com.google.common.util.concurrent.ListenableFuture searchByUsername( - biz.nynja.search.grpc.SearchByUsernameRequest request) { - return futureUnaryCall( - getChannel().newCall(getSearchByUsernameMethodHelper(), getCallOptions()), request); - } - } - - private static final int METHODID_SEARCH_BY_USERNAME = 0; - - private static final class MethodHandlers implements - io.grpc.stub.ServerCalls.UnaryMethod, - io.grpc.stub.ServerCalls.ServerStreamingMethod, - io.grpc.stub.ServerCalls.ClientStreamingMethod, - io.grpc.stub.ServerCalls.BidiStreamingMethod { - private final SearchServiceImplBase serviceImpl; - private final int methodId; - - MethodHandlers(SearchServiceImplBase serviceImpl, int methodId) { - this.serviceImpl = serviceImpl; - this.methodId = methodId; - } - - @java.lang.Override - @java.lang.SuppressWarnings("unchecked") - public void invoke(Req request, io.grpc.stub.StreamObserver responseObserver) { - switch (methodId) { - case METHODID_SEARCH_BY_USERNAME: - serviceImpl.searchByUsername((biz.nynja.search.grpc.SearchByUsernameRequest) request, - (io.grpc.stub.StreamObserver) responseObserver); - break; - default: - throw new AssertionError(); - } - } - - @java.lang.Override - @java.lang.SuppressWarnings("unchecked") - public io.grpc.stub.StreamObserver invoke( - io.grpc.stub.StreamObserver responseObserver) { - switch (methodId) { - default: - throw new AssertionError(); - } - } - } - - private static abstract class SearchServiceBaseDescriptorSupplier - implements io.grpc.protobuf.ProtoFileDescriptorSupplier, io.grpc.protobuf.ProtoServiceDescriptorSupplier { - SearchServiceBaseDescriptorSupplier() {} - - @java.lang.Override - public com.google.protobuf.Descriptors.FileDescriptor getFileDescriptor() { - return biz.nynja.search.grpc.Search.getDescriptor(); - } - - @java.lang.Override - public com.google.protobuf.Descriptors.ServiceDescriptor getServiceDescriptor() { - return getFileDescriptor().findServiceByName("SearchService"); - } - } - - private static final class SearchServiceFileDescriptorSupplier - extends SearchServiceBaseDescriptorSupplier { - SearchServiceFileDescriptorSupplier() {} - } - - private static final class SearchServiceMethodDescriptorSupplier - extends SearchServiceBaseDescriptorSupplier - implements io.grpc.protobuf.ProtoMethodDescriptorSupplier { - private final String methodName; - - SearchServiceMethodDescriptorSupplier(String methodName) { - this.methodName = methodName; - } - - @java.lang.Override - public com.google.protobuf.Descriptors.MethodDescriptor getMethodDescriptor() { - return getServiceDescriptor().findMethodByName(methodName); - } - } - - private static volatile io.grpc.ServiceDescriptor serviceDescriptor; - - public static io.grpc.ServiceDescriptor getServiceDescriptor() { - io.grpc.ServiceDescriptor result = serviceDescriptor; - if (result == null) { - synchronized (SearchServiceGrpc.class) { - result = serviceDescriptor; - if (result == null) { - serviceDescriptor = result = io.grpc.ServiceDescriptor.newBuilder(SERVICE_NAME) - .setSchemaDescriptor(new SearchServiceFileDescriptorSupplier()) - .addMethod(getSearchByUsernameMethodHelper()) - .build(); - } - } - } - return result; - } -} -- GitLab From 203a9d18bd40fc7003236131be2ff9ca3e345fbf Mon Sep 17 00:00:00 2001 From: Stoyan Tzenkov Date: Fri, 19 Oct 2018 10:11:16 +0300 Subject: [PATCH 3/9] NY_3810: Validation implemented --- .../nynja/account/components/Validator.java | 3 + .../account/services/SearchServiceImpl.java | 200 ++++++++---------- 2 files changed, 95 insertions(+), 108 deletions(-) diff --git a/src/main/java/biz/nynja/account/components/Validator.java b/src/main/java/biz/nynja/account/components/Validator.java index a27e8a6..272dc81 100644 --- a/src/main/java/biz/nynja/account/components/Validator.java +++ b/src/main/java/biz/nynja/account/components/Validator.java @@ -204,6 +204,9 @@ public class Validator { return isValid; } + public boolean isValidUsername(String username) { + return username.matches("[a-zA-Z0-9_]{1,32}"); + } boolean isAccountNameValid(String accountName) { logger.debug("Checking Account Name: {}", accountName); diff --git a/src/main/java/biz/nynja/account/services/SearchServiceImpl.java b/src/main/java/biz/nynja/account/services/SearchServiceImpl.java index c072d79..5776602 100644 --- a/src/main/java/biz/nynja/account/services/SearchServiceImpl.java +++ b/src/main/java/biz/nynja/account/services/SearchServiceImpl.java @@ -1,23 +1,25 @@ package biz.nynja.account.services; import java.util.List; +import java.nio.ByteBuffer; import org.lognet.springboot.grpc.GRpcService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import biz.nynja.search.grpc.ErrorResponse; -import biz.nynja.search.grpc.ErrorResponse.Cause; -import biz.nynja.search.grpc.SearchByEmailRequest; -import biz.nynja.search.grpc.SearchByPhoneNumberRequest; -import biz.nynja.search.grpc.SearchByQrCodeRequest; +import biz.nynja.account.components.Validator; import biz.nynja.account.models.AccountByAuthenticationProvider; import biz.nynja.account.models.AccountByQrCode; import biz.nynja.account.models.AccountByUsername; import biz.nynja.account.repositories.AccountByAuthenticationProviderRepository; import biz.nynja.account.repositories.AccountByUsernameRepository; import biz.nynja.account.repositories.AccountByQrCodeRepository; +import biz.nynja.search.grpc.ErrorResponse; +import biz.nynja.search.grpc.ErrorResponse.Cause; +import biz.nynja.search.grpc.SearchByEmailRequest; +import biz.nynja.search.grpc.SearchByPhoneNumberRequest; +import biz.nynja.search.grpc.SearchByQrCodeRequest; import biz.nynja.search.grpc.SearchByUsernameRequest; import biz.nynja.search.grpc.SearchResponse; import biz.nynja.search.grpc.SearchResultDetails; @@ -28,53 +30,44 @@ import io.grpc.stub.StreamObserver; public class SearchServiceImpl extends SearchServiceGrpc.SearchServiceImplBase { private static final Logger logger = LoggerFactory.getLogger(SearchServiceImpl.class); - + @Autowired AccountByUsernameRepository accountByUsernameRepository; @Autowired AccountByAuthenticationProviderRepository accountByAuthenticationProviderRepository; - + @Autowired AccountByQrCodeRepository accountByQrCodeRepository; + @Autowired + Validator validator; + @Override - public void searchByUsername(SearchByUsernameRequest request, - StreamObserver responseObserver) { + public void searchByUsername(SearchByUsernameRequest request, StreamObserver responseObserver) { logger.info("Getting account by username: {}", request.getUsername()); - if (request.getUsername().isEmpty()) { - responseObserver.onNext(SearchResponse.newBuilder() - .setError(ErrorResponse.newBuilder().setCause(Cause.MISSING_USERNAME)).build()); - responseObserver.onCompleted(); + if ((request.getUsername() == null) || request.getUsername().isEmpty()) { + logAndBuildGrpcResponse(responseObserver, "Missing username.", "", Cause.MISSING_USERNAME); + return; + } + if (!validator.isValidUsername(request.getUsername())) { + logAndBuildGrpcResponse(responseObserver, "Invalid username {}: ", request.getUsername(), Cause.INVALID_USERNAME); return; } AccountByUsername account = accountByUsernameRepository.findByUsername(request.getUsername()); if (account == null) { - - logger.debug("No matching accounts found for usernamer: {}", request.getUsername()); - responseObserver.onNext(SearchResponse.newBuilder() - .setError(ErrorResponse.newBuilder().setCause(Cause.USERNAME_NOT_FOUND)).build()); - responseObserver.onCompleted(); + logAndBuildGrpcResponse(responseObserver, "No matching accounts found for usernamer: {}", + request.getUsername(), Cause.USERNAME_NOT_FOUND); return; - } + } - SearchResultDetails searchResultDetails = SearchResultDetails.newBuilder() - .setAccountId(account.getAccountId().toString()) - .setAuthenticationProvider(account.getAuthenticationProvider()) - .setAuthenticationType(account.getAuthenticationProviderType()) - .setFirstName(account.getFirstName()) - .setLastName(account.getLastName()) - .setProfileId(account.getAccountId().toString()) - .setQrCode(account.getQrCode()) - .setUsername(account.getUsername()) - .build(); - - SearchResponse response = SearchResponse.newBuilder() - .setSearchResultDetails(searchResultDetails).build(); - logger.debug("Found result for account by username {}: \"{}\"", - request.getUsername(), response); + SearchResultDetails searchResultDetails = buildSearchResultDetails(account.getAvatar(), account.getFirstName(), + account.getLastName()); + + SearchResponse response = SearchResponse.newBuilder().setSearchResultDetails(searchResultDetails).build(); + logger.debug("Found result for account by username {}: \"{}\"", request.getUsername(), response); responseObserver.onNext(response); responseObserver.onCompleted(); @@ -86,10 +79,12 @@ public class SearchServiceImpl extends SearchServiceGrpc.SearchServiceImplBase { StreamObserver responseObserver) { logger.info("Getting account by phone number: {}", request.getPhoneNumber()); - if (request.getPhoneNumber().isEmpty()) { - responseObserver.onNext(SearchResponse.newBuilder() - .setError(ErrorResponse.newBuilder().setCause(Cause.MISSING_PHONENUMBER)).build()); - responseObserver.onCompleted(); + if ((request.getPhoneNumber() == null) || request.getPhoneNumber().isEmpty()) { + logAndBuildGrpcResponse(responseObserver, "Missing phone number.", "", Cause.MISSING_PHONENUMBER); + return; + } + if (!isValidPhoneNumber(request.getPhoneNumber())) { + logAndBuildGrpcResponse(responseObserver, "Invalid phone number {}: ", request.getPhoneNumber(), Cause.INVALID_PHONENUMBER); return; } @@ -97,29 +92,17 @@ public class SearchServiceImpl extends SearchServiceGrpc.SearchServiceImplBase { .findAllByAuthenticationProvider(request.getPhoneNumber()); if (accounts.isEmpty()) { - logger.debug("No matching accounts found for phone number: {}", request.getPhoneNumber()); - responseObserver.onNext(SearchResponse.newBuilder() - .setError(ErrorResponse.newBuilder().setCause(Cause.PHONENUMBER_NOT_FOUND)).build()); - responseObserver.onCompleted(); + logAndBuildGrpcResponse(responseObserver, "No matching accounts found for phone number: {}", + request.getPhoneNumber(), Cause.PHONENUMBER_NOT_FOUND); return; } AccountByAuthenticationProvider account = accounts.get(0); - SearchResultDetails searchResultDetails = SearchResultDetails.newBuilder() - .setAccountId(account.getAccountId().toString()) - .setAuthenticationProvider(account.getAuthenticationProvider()) - .setAuthenticationType(account.getAuthenticationProviderType()) - .setFirstName(account.getFirstName()) - .setLastName(account.getLastName()) - .setProfileId(account.getAccountId().toString()) - .setQrCode(account.getQrCode()) - .setUsername(account.getUsername()) - .build(); - - SearchResponse response = SearchResponse.newBuilder() - .setSearchResultDetails(searchResultDetails).build(); - logger.debug("Found result for account by phone number {}: \"{}\"", - request.getPhoneNumber(), response); + SearchResultDetails searchResultDetails = buildSearchResultDetails(account.getAvatar(), account.getFirstName(), + account.getLastName()); + + SearchResponse response = SearchResponse.newBuilder().setSearchResultDetails(searchResultDetails).build(); + logger.debug("Found result for account by phone number {}: \"{}\"", request.getPhoneNumber(), response); responseObserver.onNext(response); responseObserver.onCompleted(); @@ -127,14 +110,15 @@ public class SearchServiceImpl extends SearchServiceGrpc.SearchServiceImplBase { } @Override - public void searchByEmail(SearchByEmailRequest request, - StreamObserver responseObserver) { + public void searchByEmail(SearchByEmailRequest request, StreamObserver responseObserver) { logger.info("Getting account by e-mail: {}", request.getEmail()); - if (request.getEmail().isEmpty()) { - responseObserver.onNext(SearchResponse.newBuilder() - .setError(ErrorResponse.newBuilder().setCause(Cause.MISSING_EMAIL)).build()); - responseObserver.onCompleted(); + if ((request.getEmail() == null) || request.getEmail().isEmpty()) { + logAndBuildGrpcResponse(responseObserver, "Missing e-mail.", "", Cause.MISSING_EMAIL); + return; + } + if (!validator.isEmailValid(request.getEmail())) { + logAndBuildGrpcResponse(responseObserver, "Invalid e-mail {}: ", request.getEmail(), Cause.INVALID_EMAIL); return; } @@ -142,29 +126,17 @@ public class SearchServiceImpl extends SearchServiceGrpc.SearchServiceImplBase { .findAllByAuthenticationProvider(request.getEmail()); if (accounts.isEmpty()) { - logger.debug("No matching accounts found for e-mail: {}", request.getEmail()); - responseObserver.onNext(SearchResponse.newBuilder() - .setError(ErrorResponse.newBuilder().setCause(Cause.EMAIL_NOT_FOUND)).build()); - responseObserver.onCompleted(); + logAndBuildGrpcResponse(responseObserver, "No matching accounts found for e-mail: {}", request.getEmail(), + Cause.EMAIL_NOT_FOUND); return; } AccountByAuthenticationProvider account = accounts.get(0); - SearchResultDetails searchResultDetails = SearchResultDetails.newBuilder() - .setAccountId(account.getAccountId().toString()) - .setAuthenticationProvider(account.getAuthenticationProvider()) - .setAuthenticationType(account.getAuthenticationProviderType()) - .setFirstName(account.getFirstName()) - .setLastName(account.getLastName()) - .setProfileId(account.getAccountId().toString()) - .setQrCode(account.getQrCode()) - .setUsername(account.getUsername()) - .build(); - - SearchResponse response = SearchResponse.newBuilder() - .setSearchResultDetails(searchResultDetails).build(); - logger.debug("Found result for account by e-mail {}: \"{}\"", - request.getEmail(), response); + SearchResultDetails searchResultDetails = buildSearchResultDetails(account.getAvatar(), account.getFirstName(), + account.getLastName()); + + SearchResponse response = SearchResponse.newBuilder().setSearchResultDetails(searchResultDetails).build(); + logger.debug("Found result for account by e-mail {}: \"{}\"", request.getEmail(), response); responseObserver.onNext(response); responseObserver.onCompleted(); @@ -172,46 +144,58 @@ public class SearchServiceImpl extends SearchServiceGrpc.SearchServiceImplBase { } @Override - public void searchByQrCode(SearchByQrCodeRequest request, - StreamObserver responseObserver) { + public void searchByQrCode(SearchByQrCodeRequest request, StreamObserver responseObserver) { logger.info("Getting account by QR code: {}", request.getQrCode()); - if (request.getQrCode().isEmpty()) { - responseObserver.onNext(SearchResponse.newBuilder() - .setError(ErrorResponse.newBuilder().setCause(Cause.MISSING_QR_CODE)).build()); - responseObserver.onCompleted(); + if ((request.getQrCode() == null) || request.getQrCode().isEmpty()) { + logAndBuildGrpcResponse(responseObserver, "Missing QR code.", "", Cause.MISSING_QR_CODE); return; } AccountByQrCode account = accountByQrCodeRepository.findByQrCode(request.getQrCode()); if (account == null) { - - logger.debug("No matching accounts found for QR code: {}", request.getQrCode()); - responseObserver.onNext(SearchResponse.newBuilder() - .setError(ErrorResponse.newBuilder().setCause(Cause.QR_CODE_NOT_FOUND)).build()); - responseObserver.onCompleted(); + logAndBuildGrpcResponse(responseObserver, "No matching accounts found for QR code: {}", request.getQrCode(), + Cause.QR_CODE_NOT_FOUND); return; } - SearchResultDetails searchResultDetails = SearchResultDetails.newBuilder() - .setAccountId(account.getAccountId().toString()) - .setAuthenticationProvider(account.getAuthenticationProvider()) - .setAuthenticationType(account.getAuthenticationProviderType()) - .setFirstName(account.getFirstName()) - .setLastName(account.getLastName()) - .setProfileId(account.getAccountId().toString()) - .setQrCode(account.getQrCode()) - .setUsername(account.getUsername()) - .build(); - - SearchResponse response = SearchResponse.newBuilder() - .setSearchResultDetails(searchResultDetails).build(); - logger.debug("Found result for account by QR code {}: \"{}\"", - request.getQrCode(), response); + SearchResultDetails searchResultDetails = buildSearchResultDetails(account.getAvatar(), account.getFirstName(), + account.getLastName()); + + SearchResponse response = SearchResponse.newBuilder().setSearchResultDetails(searchResultDetails).build(); + logger.debug("Found result for account by QR code {}: \"{}\"", request.getQrCode(), response); responseObserver.onNext(response); responseObserver.onCompleted(); return; } + private SearchResultDetails buildSearchResultDetails(ByteBuffer avatar, String firstName, String lastName) { + SearchResultDetails searchResultDetails = SearchResultDetails.newBuilder() + .setAvatar(com.google.protobuf.ByteString.copyFrom(avatar)).setFirstName(firstName) + .setLastName(lastName).build(); + return searchResultDetails; + } + + private static void logAndBuildGrpcResponse(StreamObserver responseObserver, String logMessage, + String logValue, Cause cause) { + logger.debug(logMessage, logValue); + responseObserver + .onNext(SearchResponse.newBuilder().setError(ErrorResponse.newBuilder().setCause(cause)).build()); + responseObserver.onCompleted(); + } + + private boolean isValidPhoneNumber(String phoneNumber) { + // We expect the phone number in the format : ":" + + String[] provider = phoneNumber.split(":"); + if (provider == null || provider.length != 2) { + return false; + } + if (!validator.isPhoneNumberValid(provider[1], provider[0])) { + return false; + } + return true; + } + } -- GitLab From f98001798755f5818fbaec1c8fa1820fe61698cb Mon Sep 17 00:00:00 2001 From: Stoyan Tzenkov Date: Wed, 24 Oct 2018 11:59:31 +0300 Subject: [PATCH 4/9] NY_3706: Logic implemented to allow search without country selector Signed-off-by: Stoyan Tzenkov --- .../nynja/account/components/Validator.java | 77 +++++++++++++++++-- .../account/services/SearchServiceImpl.java | 24 ++---- .../components/AccountServiceHelperTests.java | 4 + .../account/services/AccountServiceTests.java | 3 + 4 files changed, 84 insertions(+), 24 deletions(-) diff --git a/src/main/java/biz/nynja/account/components/Validator.java b/src/main/java/biz/nynja/account/components/Validator.java index 272dc81..0dfb271 100644 --- a/src/main/java/biz/nynja/account/components/Validator.java +++ b/src/main/java/biz/nynja/account/components/Validator.java @@ -26,6 +26,7 @@ import biz.nynja.account.grpc.AddAuthenticationProviderRequest; import biz.nynja.account.grpc.AddContactInfoRequest; import com.google.i18n.phonenumbers.NumberParseException; import com.google.i18n.phonenumbers.PhoneNumberUtil; +import com.google.i18n.phonenumbers.Phonenumber; import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber; import biz.nynja.account.grpc.AuthProviderDetails; import biz.nynja.account.grpc.AuthenticationType; @@ -60,6 +61,7 @@ public class Validator { private static final int MAX_LAST_NAME_LENGTH = 32; private HashMap countryInfoMap; + private HashMap countryMapByCountryCode; @PostConstruct public void loadPhonesBook() { @@ -67,6 +69,7 @@ public class Validator { CountryInfo countryInfo = null; BufferedReader reader = null; countryInfoMap = new HashMap<>(); + countryMapByCountryCode = new HashMap<>(); logger.debug("Loading phones information from file."); try { @@ -85,6 +88,7 @@ public class Validator { countryInfo.setPhoneFormat(args[3]); } countryInfoMap.put(args[1], countryInfo); + countryMapByCountryCode.put(args[0], countryInfo); } } catch (IOException e) { logger.error("Error during load phones information: {}", e.getMessage()); @@ -98,6 +102,17 @@ public class Validator { } + public String getCountrySelector(String countryCode) { + CountryInfo countryInfo = countryMapByCountryCode.get(countryCode); + if (countryInfo != null) { + return countryInfo.getCountryCode(); + } else { + logger.debug("Country selector not found in'countries.txt' for country code: {}", countryCode); + throw new InternalError(biz.nynja.search.grpc.ErrorResponse.Cause.INVALID_PHONENUMBER.getValueDescriptor().toString(), + new InternalError("No country selector found in 'countries.txt' for country code: " + countryCode)); + } + } + public boolean isPhoneNumberValid(String phoneNumber, String countryCode) { logger.debug("Checking phoneNumber: {} for country: {}", phoneNumber, countryCode); @@ -135,18 +150,17 @@ public class Validator { } public String getNormalizedPhoneNumber(String authenticationProvider) { - String[] provider = authenticationProvider.split(":"); - String country = provider[0]; - String phoneNumber = provider[1]; - logger.info("libphone: New phone number normalization request received - phone number: {}, country code: {}", phoneNumber, - country); + String[] provider = authenticationProvider.split(":"); + String country = provider[0]; + String phoneNumber = provider[1]; + logger.info("libphone: New phone number normalization request received - phone number: {}, country code: {}", + phoneNumber, country); PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance(); String normalizedPhoneNumber = ""; try { - PhoneNumber pn = phoneUtil.parse(phoneNumber, country); - normalizedPhoneNumber = Integer.toString(pn.getCountryCode()) + - Long.toString(pn.getNationalNumber()); + PhoneNumber pn = phoneUtil.parse(phoneNumber, country); + normalizedPhoneNumber = Integer.toString(pn.getCountryCode()) + Long.toString(pn.getNationalNumber()); logger.info("libphone: Normalized phone number: " + normalizedPhoneNumber); } catch (NumberParseException e) { logger.error("libphone: NumberParseException was thrown: {}", e.toString()); @@ -207,6 +221,7 @@ public class Validator { public boolean isValidUsername(String username) { return username.matches("[a-zA-Z0-9_]{1,32}"); } + boolean isAccountNameValid(String accountName) { logger.debug("Checking Account Name: {}", accountName); @@ -402,4 +417,50 @@ public class Validator { } return null; } + + public String validatePhone(String phoneString) throws InternalError { + String phoneNumber = ""; + + String[] provider = phoneString.split(":"); + if (provider.length == 1) { // no country selector + phoneNumber = provider[0]; + } else { + phoneNumber = provider[1]; + } + if (!phoneNumber.matches("^\\+?[\\d- ]+$")) { + throw new InternalError(biz.nynja.search.grpc.ErrorResponse.Cause.INVALID_PHONENUMBER.getValueDescriptor().toString(), + new InternalError("Invalid phone number: " + phoneNumber)); // invalid phone number + } + phoneNumber = phoneNumber.replaceAll("^0*", "").replaceAll("[^\\d]", ""); + + String countryCode = getCountryCode(phoneNumber); + + String countrySelector = getCountrySelector(countryCode); + + if (!isPhoneNumberValid(phoneNumber, countrySelector)) { + throw new InternalError(biz.nynja.search.grpc.ErrorResponse.Cause.INVALID_PHONENUMBER.getValueDescriptor().toString(), + new InternalError("Invalid phone number: " + phoneNumber)); // invalid phone number + } + + if ((provider.length == 2) && (!countrySelector.equals(provider[0]))) { + throw new InternalError(biz.nynja.search.grpc.ErrorResponse.Cause.INVALID_PHONENUMBER.getValueDescriptor().toString(), + new InternalError("Request country selector = " + provider[0] + + " while derived country selector = " + countrySelector)); + } + return phoneNumber; + } + + private String getCountryCode(String phoneNumber) { + + PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance(); + try { + Phonenumber.PhoneNumber numberProto = phoneUtil.parse("+" + phoneNumber, ""); + logger.debug("Country code found: {}", numberProto.getCountryCode()); + return Integer.toString(numberProto.getCountryCode()); + } catch (NumberParseException e) { + throw new InternalError(biz.nynja.search.grpc.ErrorResponse.Cause.INVALID_PHONENUMBER.getValueDescriptor().toString(), + new InternalError("No country code found for phone number: " + phoneNumber)); + } + } + } diff --git a/src/main/java/biz/nynja/account/services/SearchServiceImpl.java b/src/main/java/biz/nynja/account/services/SearchServiceImpl.java index 5776602..5e2ad40 100644 --- a/src/main/java/biz/nynja/account/services/SearchServiceImpl.java +++ b/src/main/java/biz/nynja/account/services/SearchServiceImpl.java @@ -52,7 +52,8 @@ public class SearchServiceImpl extends SearchServiceGrpc.SearchServiceImplBase { return; } if (!validator.isValidUsername(request.getUsername())) { - logAndBuildGrpcResponse(responseObserver, "Invalid username {}: ", request.getUsername(), Cause.INVALID_USERNAME); + logAndBuildGrpcResponse(responseObserver, "Invalid username {}: ", request.getUsername(), + Cause.INVALID_USERNAME); return; } @@ -83,8 +84,12 @@ public class SearchServiceImpl extends SearchServiceGrpc.SearchServiceImplBase { logAndBuildGrpcResponse(responseObserver, "Missing phone number.", "", Cause.MISSING_PHONENUMBER); return; } - if (!isValidPhoneNumber(request.getPhoneNumber())) { - logAndBuildGrpcResponse(responseObserver, "Invalid phone number {}: ", request.getPhoneNumber(), Cause.INVALID_PHONENUMBER); + try { + request = SearchByPhoneNumberRequest.newBuilder().setPhoneNumber(validator.validatePhone(request.getPhoneNumber())) + .build(); + } catch (InternalError err) { + logAndBuildGrpcResponse(responseObserver, "Invalid phone number {}: ", request.getPhoneNumber(), + Cause.INVALID_PHONENUMBER); return; } @@ -184,18 +189,5 @@ public class SearchServiceImpl extends SearchServiceGrpc.SearchServiceImplBase { .onNext(SearchResponse.newBuilder().setError(ErrorResponse.newBuilder().setCause(cause)).build()); responseObserver.onCompleted(); } - - private boolean isValidPhoneNumber(String phoneNumber) { - // We expect the phone number in the format : ":" - - String[] provider = phoneNumber.split(":"); - if (provider == null || provider.length != 2) { - return false; - } - if (!validator.isPhoneNumberValid(provider[1], provider[0])) { - return false; - } - return true; - } } diff --git a/src/test/java/biz/nynja/account/components/AccountServiceHelperTests.java b/src/test/java/biz/nynja/account/components/AccountServiceHelperTests.java index ef41016..9615064 100644 --- a/src/test/java/biz/nynja/account/components/AccountServiceHelperTests.java +++ b/src/test/java/biz/nynja/account/components/AccountServiceHelperTests.java @@ -32,6 +32,10 @@ import biz.nynja.account.utils.Util; "spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration" }) @ActiveProfiles("dev") public class AccountServiceHelperTests { + + @MockBean + private PreparedStatementsCache preparedStatementsCache; + @MockBean private AccountByAuthenticationProviderRepository accountByAuthenticationProviderRepository; diff --git a/src/test/java/biz/nynja/account/services/AccountServiceTests.java b/src/test/java/biz/nynja/account/services/AccountServiceTests.java index 1a3991b..a1a45c5 100644 --- a/src/test/java/biz/nynja/account/services/AccountServiceTests.java +++ b/src/test/java/biz/nynja/account/services/AccountServiceTests.java @@ -152,6 +152,9 @@ public class AccountServiceTests extends GrpcServerTestBase { @Qualifier("profileByAuthenticationProvider") private ProfileByAuthenticationProvider profileByAuthenticationProvider; + @MockBean + private PreparedStatementsCache preparedStatementsCache; + @MockBean private AccountRepository accountRepository; -- GitLab From c17f9419d89f059a110963e8290c551d19fa6b9a Mon Sep 17 00:00:00 2001 From: Stoyan Tzenkov Date: Mon, 29 Oct 2018 13:34:49 +0200 Subject: [PATCH 5/9] NY_3607: Search service solely/entirely implemented in account-service Signed-off-by: Stoyan Tzenkov --- pom.xml | 12 - .../nynja/account/components/Validator.java | 15 +- .../account/services/AccountServiceImpl.java | 329 +++++++++++++----- .../account/services/SearchServiceImpl.java | 193 ---------- .../decomposition/AccountsProvider.java | 2 +- .../account/services/AccountServiceTests.java | 288 ++++++++++++++- .../java/biz/nynja/account/utils/Util.java | 47 ++- 7 files changed, 579 insertions(+), 307 deletions(-) delete mode 100644 src/main/java/biz/nynja/account/services/SearchServiceImpl.java diff --git a/pom.xml b/pom.xml index 4d47ff7..ad665e6 100644 --- a/pom.xml +++ b/pom.xml @@ -111,18 +111,6 @@ - - libs-snapshot-local.biz.nynja.protos - search-service-intracoldev - 1.0-SNAPSHOT - - - com.google.protobuf - protobuf-java - - - - com.googlecode.libphonenumber libphonenumber diff --git a/src/main/java/biz/nynja/account/components/Validator.java b/src/main/java/biz/nynja/account/components/Validator.java index 0dfb271..c468aa4 100644 --- a/src/main/java/biz/nynja/account/components/Validator.java +++ b/src/main/java/biz/nynja/account/components/Validator.java @@ -22,8 +22,6 @@ import org.slf4j.LoggerFactory; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import org.springframework.stereotype.Component; -import biz.nynja.account.grpc.AddAuthenticationProviderRequest; -import biz.nynja.account.grpc.AddContactInfoRequest; import com.google.i18n.phonenumbers.NumberParseException; import com.google.i18n.phonenumbers.PhoneNumberUtil; import com.google.i18n.phonenumbers.Phonenumber; @@ -44,6 +42,9 @@ import biz.nynja.account.models.CountryInfo; import javax.mail.internet.AddressException; import javax.mail.internet.InternetAddress; +import biz.nynja.account.grpc.AddAuthenticationProviderRequest; +import biz.nynja.account.grpc.AddContactInfoRequest; + /** * Component which contains all validation methods. */ @@ -108,7 +109,7 @@ public class Validator { return countryInfo.getCountryCode(); } else { logger.debug("Country selector not found in'countries.txt' for country code: {}", countryCode); - throw new InternalError(biz.nynja.search.grpc.ErrorResponse.Cause.INVALID_PHONENUMBER.getValueDescriptor().toString(), + throw new InternalError(Cause.INVALID_PHONENUMBER.getValueDescriptor().toString(), new InternalError("No country selector found in 'countries.txt' for country code: " + countryCode)); } } @@ -428,7 +429,7 @@ public class Validator { phoneNumber = provider[1]; } if (!phoneNumber.matches("^\\+?[\\d- ]+$")) { - throw new InternalError(biz.nynja.search.grpc.ErrorResponse.Cause.INVALID_PHONENUMBER.getValueDescriptor().toString(), + throw new InternalError(Cause.INVALID_PHONENUMBER.getValueDescriptor().toString(), new InternalError("Invalid phone number: " + phoneNumber)); // invalid phone number } phoneNumber = phoneNumber.replaceAll("^0*", "").replaceAll("[^\\d]", ""); @@ -438,12 +439,12 @@ public class Validator { String countrySelector = getCountrySelector(countryCode); if (!isPhoneNumberValid(phoneNumber, countrySelector)) { - throw new InternalError(biz.nynja.search.grpc.ErrorResponse.Cause.INVALID_PHONENUMBER.getValueDescriptor().toString(), + throw new InternalError(Cause.INVALID_PHONENUMBER.getValueDescriptor().toString(), new InternalError("Invalid phone number: " + phoneNumber)); // invalid phone number } if ((provider.length == 2) && (!countrySelector.equals(provider[0]))) { - throw new InternalError(biz.nynja.search.grpc.ErrorResponse.Cause.INVALID_PHONENUMBER.getValueDescriptor().toString(), + throw new InternalError(Cause.INVALID_PHONENUMBER.getValueDescriptor().toString(), new InternalError("Request country selector = " + provider[0] + " while derived country selector = " + countrySelector)); } @@ -458,7 +459,7 @@ public class Validator { logger.debug("Country code found: {}", numberProto.getCountryCode()); return Integer.toString(numberProto.getCountryCode()); } catch (NumberParseException e) { - throw new InternalError(biz.nynja.search.grpc.ErrorResponse.Cause.INVALID_PHONENUMBER.getValueDescriptor().toString(), + throw new InternalError(Cause.INVALID_PHONENUMBER.getValueDescriptor().toString(), new InternalError("No country code found for phone number: " + phoneNumber)); } } diff --git a/src/main/java/biz/nynja/account/services/AccountServiceImpl.java b/src/main/java/biz/nynja/account/services/AccountServiceImpl.java index 1909e98..4fba79f 100644 --- a/src/main/java/biz/nynja/account/services/AccountServiceImpl.java +++ b/src/main/java/biz/nynja/account/services/AccountServiceImpl.java @@ -16,39 +16,14 @@ import org.slf4j.LoggerFactory; import biz.nynja.account.components.PhoneNumberNormalizer; import biz.nynja.account.components.Validator; -import biz.nynja.account.grpc.AccountByAccountIdRequest; -import biz.nynja.account.grpc.AccountByAuthenticationProviderRequest; -import biz.nynja.account.grpc.AccountResponse; -import biz.nynja.account.grpc.AccountServiceGrpc; -import biz.nynja.account.grpc.AccountsByProfileIdRequest; -import biz.nynja.account.grpc.AccountsResponse; -import biz.nynja.account.grpc.AddAuthenticationProviderRequest; -import biz.nynja.account.grpc.AddContactInfoRequest; -import biz.nynja.account.grpc.AuthProviderDetails; -import biz.nynja.account.grpc.AuthenticationType; -import biz.nynja.account.grpc.CompletePendingAccountCreationRequest; -import biz.nynja.account.grpc.ContactType; -import biz.nynja.account.grpc.CreateAccountRequest; -import biz.nynja.account.grpc.CreatePendingAccountRequest; -import biz.nynja.account.grpc.CreatePendingAccountResponse; -import biz.nynja.account.grpc.DeleteAccountRequest; -import biz.nynja.account.grpc.DeleteAuthenticationProviderRequest; -import biz.nynja.account.grpc.DeleteContactInfoRequest; -import biz.nynja.account.grpc.DeleteProfileRequest; -import biz.nynja.account.grpc.EditContactInfoRequest; + +import biz.nynja.account.grpc.*; import biz.nynja.account.grpc.ErrorResponse.Cause; -import biz.nynja.account.grpc.ProfileResponse; -import biz.nynja.account.grpc.Role; -import biz.nynja.account.grpc.StatusResponse; -import biz.nynja.account.grpc.UpdateAccountRequest; -import biz.nynja.account.grpc.UpdateProfileRequest; import biz.nynja.account.models.Account; -import biz.nynja.account.models.AuthenticationProvider; -import biz.nynja.account.models.ContactInfo; -import biz.nynja.account.models.PendingAccount; -import biz.nynja.account.models.PendingAccountByAuthenticationProvider; -import biz.nynja.account.models.Profile; -import biz.nynja.account.models.ProfileByAuthenticationProvider; +import biz.nynja.account.models.*; +import biz.nynja.account.repositories.AccountByAuthenticationProviderRepository; +import biz.nynja.account.repositories.AccountByQrCodeRepository; +import biz.nynja.account.repositories.AccountByUsernameRepository; import biz.nynja.account.repositories.AccountRepositoryAdditional; import biz.nynja.account.repositories.PendingAccountRepository; import biz.nynja.account.repositories.ProfileByAuthenticationProviderRepository; @@ -56,6 +31,19 @@ import biz.nynja.account.repositories.ProfileRepository; import biz.nynja.account.services.decomposition.AccountsProvider; import io.grpc.stub.StreamObserver; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.lognet.springboot.grpc.GRpcService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.nio.ByteBuffer; +import java.time.Instant; +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +//import static biz.nynja.account.grpc.ErrorResponse.Cause; +//import static biz.nynja.account.grpc.ErrorResponse.newBuilder; /** * gRPC Account service implementation.
* The service extends the protobuf generated class and overrides the needed methods. It also saves/retrieves the @@ -71,18 +59,30 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas private final AccountRepositoryAdditional accountRepositoryAdditional; private final ProfileRepository profileRepository; private final ProfileByAuthenticationProviderRepository profileByAutheticationProviderRepository; + private final AccountByQrCodeRepository accountByQrCodeRepository; + private final AccountByAuthenticationProviderRepository accountByAuthenticationProviderRepository; + private final AccountByUsernameRepository accountByUsernameRepository; private final Validator validator; private final AccountsProvider accountsProvider; private final PhoneNumberNormalizer phoneNumberNormalizer; public AccountServiceImpl(PendingAccountRepository pendingAccountRepository, - AccountRepositoryAdditional accountRepositoryAdditional, ProfileRepository profileRepository, - ProfileByAuthenticationProviderRepository profileByAutheticationProviderRepository, Validator validator, - AccountsProvider accountsProvider, PhoneNumberNormalizer phoneNumberNormalizer) { + AccountRepositoryAdditional accountRepositoryAdditional, + ProfileRepository profileRepository, + ProfileByAuthenticationProviderRepository profileByAutheticationProviderRepository, + AccountByQrCodeRepository accountByQrCodeRepository, + AccountByAuthenticationProviderRepository accountByAuthenticationProviderRepository, + AccountByUsernameRepository accountByUsernameRepository, + Validator validator, + AccountsProvider accountsProvider, + PhoneNumberNormalizer phoneNumberNormalizer) { this.pendingAccountRepository = pendingAccountRepository; this.accountRepositoryAdditional = accountRepositoryAdditional; this.profileRepository = profileRepository; this.profileByAutheticationProviderRepository = profileByAutheticationProviderRepository; + this.accountByQrCodeRepository = accountByQrCodeRepository; + this.accountByAuthenticationProviderRepository = accountByAuthenticationProviderRepository; + this.accountByUsernameRepository = accountByUsernameRepository; this.validator = validator; this.accountsProvider = accountsProvider; this.phoneNumberNormalizer = phoneNumberNormalizer; @@ -177,8 +177,8 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas Cause cause = validator.validateCreatePendingAccountRequest(request); if (cause != null) { - responseObserver - .onNext(CreatePendingAccountResponse.newBuilder().setError(newBuilder().setCause(cause)).build()); + responseObserver.onNext(CreatePendingAccountResponse.newBuilder() + .setError(ErrorResponse.newBuilder().setCause(cause)).build()); responseObserver.onCompleted(); return; } @@ -219,7 +219,7 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas AuthenticationProvider.createAuthenticationProviderFromStrings(request.getAuthenticationType().name(), request.getAuthenticationProvider()))) { responseObserver.onNext(CreatePendingAccountResponse.newBuilder() - .setError(newBuilder().setCause(Cause.ACCOUNT_ALREADY_CREATED)).build()); + .setError(ErrorResponse.newBuilder().setCause(Cause.ACCOUNT_ALREADY_CREATED)).build()); responseObserver.onCompleted(); return; } @@ -252,15 +252,16 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas Cause cause = validator.validateCompletePendingAccountCreationRequest(request); if (cause != null) { - responseObserver.onNext(AccountResponse.newBuilder().setError(newBuilder().setCause(cause)).build()); + responseObserver + .onNext(AccountResponse.newBuilder().setError(ErrorResponse.newBuilder().setCause(cause)).build()); responseObserver.onCompleted(); return; } if (request.getUsername() != null && !request.getUsername().trim().isEmpty() && accountRepositoryAdditional .foundExistingNotOwnUsername(UUID.fromString(request.getAccountId()), request.getUsername())) { - responseObserver.onNext( - AccountResponse.newBuilder().setError(newBuilder().setCause(Cause.USERNAME_ALREADY_USED)).build()); + responseObserver.onNext(AccountResponse.newBuilder() + .setError(ErrorResponse.newBuilder().setCause(Cause.USERNAME_ALREADY_USED)).build()); responseObserver.onCompleted(); return; } @@ -272,8 +273,8 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas Account createdAccount = accountRepositoryAdditional.completePendingAccountCreation(request); if (createdAccount == null) { - responseObserver.onNext( - AccountResponse.newBuilder().setError(newBuilder().setCause(Cause.ERROR_CREATING_ACCOUNT)).build()); + responseObserver.onNext(AccountResponse.newBuilder() + .setError(ErrorResponse.newBuilder().setCause(Cause.ERROR_CREATING_ACCOUNT)).build()); responseObserver.onCompleted(); return; } else { @@ -294,15 +295,16 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas logger.debug("Updating profile...: {}", request); if ((request.getProfileId() == null) || (request.getProfileId().isEmpty())) { - responseObserver.onNext( - ProfileResponse.newBuilder().setError(newBuilder().setCause(Cause.MISSING_PROFILE_ID)).build()); + responseObserver.onNext(ProfileResponse.newBuilder() + .setError(ErrorResponse.newBuilder().setCause(Cause.MISSING_PROFILE_ID)).build()); responseObserver.onCompleted(); return; } Cause cause = validator.validateUpdateProfileRequest(request); if (cause != null) { - responseObserver.onNext(ProfileResponse.newBuilder().setError(newBuilder().setCause(cause)).build()); + responseObserver.onNext(ProfileResponse.newBuilder() + .setError(ErrorResponse.newBuilder().setCause(cause)).build()); responseObserver.onCompleted(); return; } @@ -310,8 +312,8 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas Profile updatedProfile = accountRepositoryAdditional.updateProfile(request); if (updatedProfile == null) { - responseObserver.onNext( - ProfileResponse.newBuilder().setError(newBuilder().setCause(Cause.ERROR_UPDATING_PROFILE)).build()); + responseObserver.onNext(ProfileResponse.newBuilder() + .setError(ErrorResponse.newBuilder().setCause(Cause.ERROR_UPDATING_PROFILE)).build()); responseObserver.onCompleted(); return; } @@ -330,23 +332,23 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas logger.debug("Updating account...: {}", request); if ((request.getAccountId() == null) || (request.getAccountId().isEmpty())) { - responseObserver.onNext( - AccountResponse.newBuilder().setError(newBuilder().setCause(Cause.MISSING_ACCOUNT_ID)).build()); + responseObserver.onNext(AccountResponse.newBuilder() + .setError(ErrorResponse.newBuilder().setCause(Cause.MISSING_ACCOUNT_ID)).build()); responseObserver.onCompleted(); return; } Cause validationCause = validator.validateUpdateAccountRequest(request); if (validationCause != null) { - responseObserver - .onNext(AccountResponse.newBuilder().setError(newBuilder().setCause(validationCause)).build()); + responseObserver.onNext(AccountResponse.newBuilder() + .setError(ErrorResponse.newBuilder().setCause(validationCause)).build()); responseObserver.onCompleted(); return; } if (request.getUsername() != null && !request.getUsername().trim().isEmpty() && accountRepositoryAdditional .foundExistingNotOwnUsername(UUID.fromString(request.getAccountId()), request.getUsername())) { - responseObserver.onNext( - AccountResponse.newBuilder().setError(newBuilder().setCause(Cause.USERNAME_ALREADY_USED)).build()); + responseObserver.onNext(AccountResponse.newBuilder() + .setError(ErrorResponse.newBuilder().setCause(Cause.USERNAME_ALREADY_USED)).build()); responseObserver.onCompleted(); return; } @@ -354,8 +356,8 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas Account updatedAccount = accountRepositoryAdditional.updateAccount(request); if (updatedAccount == null) { - responseObserver.onNext( - AccountResponse.newBuilder().setError(newBuilder().setCause(Cause.ERROR_UPDATING_ACCOUNT)).build()); + responseObserver.onNext(AccountResponse.newBuilder() + .setError(ErrorResponse.newBuilder().setCause(Cause.ERROR_UPDATING_ACCOUNT)).build()); responseObserver.onCompleted(); return; } @@ -373,8 +375,8 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas logger.debug("Deleting account...: {}", request); if ((request.getAccountId() == null) || (request.getAccountId().isEmpty())) { - responseObserver.onNext( - StatusResponse.newBuilder().setError(newBuilder().setCause(Cause.MISSING_ACCOUNT_ID)).build()); + responseObserver.onNext(StatusResponse.newBuilder() + .setError(ErrorResponse.newBuilder().setCause(Cause.MISSING_ACCOUNT_ID)).build()); responseObserver.onCompleted(); return; } @@ -386,8 +388,8 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas return; } - responseObserver.onNext( - StatusResponse.newBuilder().setError(newBuilder().setCause(Cause.ERROR_DELETING_ACCOUNT)).build()); + responseObserver.onNext(StatusResponse.newBuilder() + .setError(ErrorResponse.newBuilder().setCause(Cause.ERROR_DELETING_ACCOUNT)).build()); responseObserver.onCompleted(); return; } @@ -396,8 +398,8 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas public void deleteProfile(DeleteProfileRequest request, StreamObserver responseObserver) { logger.debug("Deleting profile: {}", request); if ((request.getProfileId() == null) || (request.getProfileId().isEmpty())) { - responseObserver.onNext( - StatusResponse.newBuilder().setError(newBuilder().setCause(Cause.MISSING_PROFILE_ID)).build()); + responseObserver.onNext(StatusResponse.newBuilder() + .setError(ErrorResponse.newBuilder().setCause(Cause.MISSING_PROFILE_ID)).build()); responseObserver.onCompleted(); return; } @@ -411,8 +413,8 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas } logger.info("Error deleting profile."); - responseObserver.onNext( - StatusResponse.newBuilder().setError(newBuilder().setCause(Cause.ERROR_DELETING_PROFILE)).build()); + responseObserver.onNext(StatusResponse.newBuilder() + .setError(ErrorResponse.newBuilder().setCause(Cause.ERROR_DELETING_PROFILE)).build()); responseObserver.onCompleted(); return; } @@ -422,28 +424,29 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas StreamObserver responseObserver) { logger.info("Adding authentication provider to profile requested."); logger.debug("Adding authentication provider to profile requested: {}", request); - if ((request.getProfileId() == null) || (request.getProfileId().isEmpty())) { - responseObserver.onNext( - StatusResponse.newBuilder().setError(newBuilder().setCause(Cause.MISSING_PROFILE_ID)).build()); + if ((request.getProfileId() == null) || (request.getProfileId().isEmpty())) { + responseObserver.onNext(StatusResponse.newBuilder() + .setError(ErrorResponse.newBuilder().setCause(Cause.MISSING_PROFILE_ID)).build()); responseObserver.onCompleted(); return; } if (request.getAuthenticationProvider().getAuthenticationTypeValue() == 0) { responseObserver.onNext(StatusResponse.newBuilder() - .setError(newBuilder().setCause(Cause.MISSING_AUTH_PROVIDER_TYPE)).build()); + .setError(ErrorResponse.newBuilder().setCause(Cause.MISSING_AUTH_PROVIDER_TYPE)).build()); responseObserver.onCompleted(); return; } if (request.getAuthenticationProvider().getAuthenticationProvider() == null || request.getAuthenticationProvider().getAuthenticationProvider().isEmpty()) { responseObserver.onNext(StatusResponse.newBuilder() - .setError(newBuilder().setCause(Cause.MISSING_AUTH_PROVIDER_IDENTIFIER)).build()); + .setError(ErrorResponse.newBuilder().setCause(Cause.MISSING_AUTH_PROVIDER_IDENTIFIER)).build()); responseObserver.onCompleted(); return; } Cause cause = validator.validateAddAuthenticationProviderRequest(request); if (cause != null) { - responseObserver.onNext(StatusResponse.newBuilder().setError(newBuilder().setCause(cause)).build()); + responseObserver + .onNext(StatusResponse.newBuilder().setError(ErrorResponse.newBuilder().setCause(cause)).build()); responseObserver.onCompleted(); return; } @@ -464,8 +467,8 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas Profile profile = profileRepository.findByProfileId(UUID.fromString(request.getProfileId())); if (profile == null) { logger.error("Profile id {} missing in DB.", request.getProfileId()); - responseObserver.onNext( - StatusResponse.newBuilder().setError(newBuilder().setCause(Cause.PROFILE_NOT_FOUND)).build()); + responseObserver.onNext(StatusResponse.newBuilder() + .setError(ErrorResponse.newBuilder().setCause(Cause.PROFILE_NOT_FOUND)).build()); responseObserver.onCompleted(); return; } @@ -479,7 +482,7 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas request.getAuthenticationProvider().getAuthenticationType().name(), request.getAuthenticationProvider().getAuthenticationProvider()); responseObserver.onNext(StatusResponse.newBuilder() - .setError(newBuilder().setCause(Cause.AUTH_PROVIDER_ALREADY_USED)).build()); + .setError(ErrorResponse.newBuilder().setCause(Cause.AUTH_PROVIDER_ALREADY_USED)).build()); responseObserver.onCompleted(); return; } @@ -496,8 +499,8 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas logger.error("Authentication provider {}:{} was not successfuly added for profile id {}.", request.getAuthenticationProvider().getAuthenticationType().name(), request.getAuthenticationProvider().getAuthenticationProvider(), request.getProfileId()); - responseObserver.onNext( - StatusResponse.newBuilder().setError(newBuilder().setCause(Cause.INTERNAL_SERVER_ERROR)).build()); + responseObserver.onNext(StatusResponse.newBuilder() + .setError(ErrorResponse.newBuilder().setCause(Cause.INTERNAL_SERVER_ERROR)).build()); responseObserver.onCompleted(); return; } @@ -568,28 +571,29 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas logger.info("Deleting Authentication Provider from profile: {}", request); if ((request.getProfileId() == null) || (request.getProfileId().isEmpty())) { - responseObserver.onNext( - StatusResponse.newBuilder().setError(newBuilder().setCause(Cause.MISSING_PROFILE_ID)).build()); + responseObserver.onNext(StatusResponse.newBuilder() + .setError(ErrorResponse.newBuilder().setCause(Cause.MISSING_PROFILE_ID)).build()); responseObserver.onCompleted(); return; } if (request.getAuthenticationProvider().getAuthenticationTypeValue() == 0) { responseObserver.onNext(StatusResponse.newBuilder() - .setError(newBuilder().setCause(Cause.MISSING_AUTH_PROVIDER_TYPE)).build()); + .setError(ErrorResponse.newBuilder().setCause(Cause.MISSING_AUTH_PROVIDER_TYPE)).build()); responseObserver.onCompleted(); return; } if (request.getAuthenticationProvider().getAuthenticationProvider() == null || request.getAuthenticationProvider().getAuthenticationProvider().isEmpty()) { responseObserver.onNext(StatusResponse.newBuilder() - .setError(newBuilder().setCause(Cause.MISSING_AUTH_PROVIDER_IDENTIFIER)).build()); + .setError(ErrorResponse.newBuilder().setCause(Cause.MISSING_AUTH_PROVIDER_IDENTIFIER)).build()); responseObserver.onCompleted(); return; } Cause cause = validator.validateDeleteAuthenticationProviderRequest(request); if (cause != null) { - responseObserver.onNext(StatusResponse.newBuilder().setError(newBuilder().setCause(cause)).build()); + responseObserver + .onNext(StatusResponse.newBuilder().setError(ErrorResponse.newBuilder().setCause(cause)).build()); responseObserver.onCompleted(); return; } @@ -598,8 +602,8 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas Profile profile = profileRepository.findByProfileId(UUID.fromString(request.getProfileId())); if (profile == null) { logger.error("Profile id {} missing in DB.", request.getProfileId()); - responseObserver.onNext( - StatusResponse.newBuilder().setError(newBuilder().setCause(Cause.PROFILE_NOT_FOUND)).build()); + responseObserver.onNext(StatusResponse.newBuilder() + .setError(ErrorResponse.newBuilder().setCause(Cause.PROFILE_NOT_FOUND)).build()); responseObserver.onCompleted(); return; } @@ -613,7 +617,7 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas "Error deleting authentication provider {} from profile with id {}. Check the number of authentication providers.", request.getAuthenticationProvider(), request.getProfileId()); responseObserver.onNext(StatusResponse.newBuilder() - .setError(newBuilder().setCause(Cause.ERROR_DELETING_AUTH_PROVIDER)).build()); + .setError(ErrorResponse.newBuilder().setCause(Cause.ERROR_DELETING_AUTH_PROVIDER)).build()); responseObserver.onCompleted(); return; } @@ -632,8 +636,8 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas logger.error("Authentication provider {}:{} was not successfuly deleted from profile id {}.", request.getAuthenticationProvider().getAuthenticationType().name(), request.getAuthenticationProvider().getAuthenticationProvider(), request.getProfileId()); - responseObserver.onNext( - StatusResponse.newBuilder().setError(newBuilder().setCause(Cause.INTERNAL_SERVER_ERROR)).build()); + responseObserver.onNext(StatusResponse.newBuilder() + .setError(ErrorResponse.newBuilder().setCause(Cause.INTERNAL_SERVER_ERROR)).build()); responseObserver.onCompleted(); return; } @@ -682,20 +686,169 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas return; } + @Override + public void searchByUsername(SearchByUsernameRequest request, StreamObserver responseObserver) { + + logger.info("Getting account by username: {}", request.getUsername()); + if ((request.getUsername() == null) || request.getUsername().isEmpty()) { + logAndBuildGrpcResponse(responseObserver, "Missing username.", "", Cause.MISSING_USERNAME); + return; + } + if (!validator.isValidUsername(request.getUsername())) { + logAndBuildGrpcResponse(responseObserver, "Invalid username {}: ", request.getUsername(), + Cause.INVALID_USERNAME); + return; + } + + AccountByUsername account = accountByUsernameRepository.findByUsername(request.getUsername()); + if (account == null) { + logAndBuildGrpcResponse(responseObserver, "No matching accounts found for usernamer: {}", + request.getUsername(), Cause.USERNAME_NOT_FOUND); + return; + } + + SearchResultDetails searchResultDetails = buildSearchResultDetails(account.getAvatar(), account.getFirstName(), + account.getLastName()); + + SearchResponse response = SearchResponse.newBuilder().setSearchResultDetails(searchResultDetails).build(); + logger.debug("Found result for account by username {}: \"{}\"", request.getUsername(), response); + responseObserver.onNext(response); + responseObserver.onCompleted(); + + return; + } + + @Override + public void searchByPhoneNumber(SearchByPhoneNumberRequest request, + StreamObserver responseObserver) { + + logger.info("Getting account by phone number: {}", request.getPhoneNumber()); + if ((request.getPhoneNumber() == null) || request.getPhoneNumber().isEmpty()) { + logAndBuildGrpcResponse(responseObserver, "Missing phone number.", "", Cause.MISSING_PHONENUMBER); + return; + } + try { + request = SearchByPhoneNumberRequest.newBuilder().setPhoneNumber(validator.validatePhone(request.getPhoneNumber())) + .build(); + } catch (InternalError err) { + logAndBuildGrpcResponse(responseObserver, "Invalid phone number {}: ", request.getPhoneNumber(), + Cause.INVALID_PHONENUMBER); + return; + } + + List accounts = accountByAuthenticationProviderRepository + .findAllByAuthenticationProvider(request.getPhoneNumber()); + + if (accounts.isEmpty()) { + logAndBuildGrpcResponse(responseObserver, "No matching accounts found for phone number: {}", + request.getPhoneNumber(), Cause.PHONENUMBER_NOT_FOUND); + return; + } + + AccountByAuthenticationProvider account = accounts.get(0); + SearchResultDetails searchResultDetails = buildSearchResultDetails(account.getAvatar(), account.getFirstName(), + account.getLastName()); + + SearchResponse response = SearchResponse.newBuilder().setSearchResultDetails(searchResultDetails).build(); + logger.debug("Found result for account by phone number {}: \"{}\"", request.getPhoneNumber(), response); + responseObserver.onNext(response); + responseObserver.onCompleted(); + + return; + } + + @Override + public void searchByEmail(SearchByEmailRequest request, StreamObserver responseObserver) { + + logger.info("Getting account by e-mail: {}", request.getEmail()); + if ((request.getEmail() == null) || request.getEmail().isEmpty()) { + logAndBuildGrpcResponse(responseObserver, "Missing e-mail.", "", Cause.MISSING_EMAIL); + return; + } + if (!validator.isEmailValid(request.getEmail())) { + logAndBuildGrpcResponse(responseObserver, "Invalid e-mail {}: ", request.getEmail(), Cause.INVALID_EMAIL); + return; + } + + List accounts = accountByAuthenticationProviderRepository + .findAllByAuthenticationProvider(request.getEmail()); + + if (accounts.isEmpty()) { + logAndBuildGrpcResponse(responseObserver, "No matching accounts found for e-mail: {}", request.getEmail(), + Cause.EMAIL_NOT_FOUND); + return; + } + + AccountByAuthenticationProvider account = accounts.get(0); + SearchResultDetails searchResultDetails = buildSearchResultDetails(account.getAvatar(), account.getFirstName(), + account.getLastName()); + + SearchResponse response = SearchResponse.newBuilder().setSearchResultDetails(searchResultDetails).build(); + logger.debug("Found result for account by e-mail {}: \"{}\"", request.getEmail(), response); + responseObserver.onNext(response); + responseObserver.onCompleted(); + + return; + } + + @Override + public void searchByQrCode(SearchByQrCodeRequest request, StreamObserver responseObserver) { + + logger.info("Getting account by QR code: {}", request.getQrCode()); + if ((request.getQrCode() == null) || request.getQrCode().isEmpty()) { + logAndBuildGrpcResponse(responseObserver, "Missing QR code.", "", Cause.MISSING_QR_CODE); + return; + } + + AccountByQrCode account = accountByQrCodeRepository.findByQrCode(request.getQrCode()); + if (account == null) { + logAndBuildGrpcResponse(responseObserver, "No matching accounts found for QR code: {}", request.getQrCode(), + Cause.QR_CODE_NOT_FOUND); + return; + } + + SearchResultDetails searchResultDetails = buildSearchResultDetails(account.getAvatar(), account.getFirstName(), + account.getLastName()); + + SearchResponse response = SearchResponse.newBuilder().setSearchResultDetails(searchResultDetails).build(); + logger.debug("Found result for account by QR code {}: \"{}\"", request.getQrCode(), response); + responseObserver.onNext(response); + responseObserver.onCompleted(); + + return; + } + + private static void logAndBuildGrpcResponse(StreamObserver responseObserver, String logMessage, + String logValue, Cause cause) { + logger.debug(logMessage, logValue); + responseObserver + .onNext(SearchResponse.newBuilder().setError(ErrorResponse.newBuilder().setCause(cause)).build()); + responseObserver.onCompleted(); + } + + private SearchResultDetails buildSearchResultDetails(ByteBuffer avatar, String firstName, String lastName) { + SearchResultDetails searchResultDetails = SearchResultDetails.newBuilder() + .setAvatar(com.google.protobuf.ByteString.copyFrom(avatar)).setFirstName(firstName) + .setLastName(lastName).build(); + return searchResultDetails; + } + private void sendErrorMessageForAccountsResponse(StreamObserver responseObserver, Cause cause) { - responseObserver.onNext(AccountsResponse.newBuilder().setError(newBuilder().setCause(cause)).build()); + responseObserver.onNext(AccountsResponse.newBuilder() + .setError(ErrorResponse.newBuilder().setCause(cause)).build()); responseObserver.onCompleted(); } private void sendErrorMessageForAccountResponse(StreamObserver responseObserver, Cause cause) { - responseObserver.onNext(AccountResponse.newBuilder().setError(newBuilder().setCause(cause)).build()); + responseObserver.onNext(AccountResponse.newBuilder() + .setError(ErrorResponse.newBuilder().setCause(cause)).build()); responseObserver.onCompleted(); } public void prepareErrorStatusResponse(StreamObserver responseObserver, Cause error, String message) { - responseObserver - .onNext(StatusResponse.newBuilder().setError(newBuilder().setCause(error).setMessage(message)).build()); + responseObserver.onNext(StatusResponse.newBuilder() + .setError(ErrorResponse.newBuilder().setCause(error).setMessage(message)).build()); responseObserver.onCompleted(); } diff --git a/src/main/java/biz/nynja/account/services/SearchServiceImpl.java b/src/main/java/biz/nynja/account/services/SearchServiceImpl.java deleted file mode 100644 index 5e2ad40..0000000 --- a/src/main/java/biz/nynja/account/services/SearchServiceImpl.java +++ /dev/null @@ -1,193 +0,0 @@ -package biz.nynja.account.services; - -import java.util.List; -import java.nio.ByteBuffer; - -import org.lognet.springboot.grpc.GRpcService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; - -import biz.nynja.account.components.Validator; -import biz.nynja.account.models.AccountByAuthenticationProvider; -import biz.nynja.account.models.AccountByQrCode; -import biz.nynja.account.models.AccountByUsername; -import biz.nynja.account.repositories.AccountByAuthenticationProviderRepository; -import biz.nynja.account.repositories.AccountByUsernameRepository; -import biz.nynja.account.repositories.AccountByQrCodeRepository; -import biz.nynja.search.grpc.ErrorResponse; -import biz.nynja.search.grpc.ErrorResponse.Cause; -import biz.nynja.search.grpc.SearchByEmailRequest; -import biz.nynja.search.grpc.SearchByPhoneNumberRequest; -import biz.nynja.search.grpc.SearchByQrCodeRequest; -import biz.nynja.search.grpc.SearchByUsernameRequest; -import biz.nynja.search.grpc.SearchResponse; -import biz.nynja.search.grpc.SearchResultDetails; -import biz.nynja.search.grpc.SearchServiceGrpc; -import io.grpc.stub.StreamObserver; - -@GRpcService -public class SearchServiceImpl extends SearchServiceGrpc.SearchServiceImplBase { - - private static final Logger logger = LoggerFactory.getLogger(SearchServiceImpl.class); - - @Autowired - AccountByUsernameRepository accountByUsernameRepository; - - @Autowired - AccountByAuthenticationProviderRepository accountByAuthenticationProviderRepository; - - @Autowired - AccountByQrCodeRepository accountByQrCodeRepository; - - @Autowired - Validator validator; - - @Override - public void searchByUsername(SearchByUsernameRequest request, StreamObserver responseObserver) { - - logger.info("Getting account by username: {}", request.getUsername()); - if ((request.getUsername() == null) || request.getUsername().isEmpty()) { - logAndBuildGrpcResponse(responseObserver, "Missing username.", "", Cause.MISSING_USERNAME); - return; - } - if (!validator.isValidUsername(request.getUsername())) { - logAndBuildGrpcResponse(responseObserver, "Invalid username {}: ", request.getUsername(), - Cause.INVALID_USERNAME); - return; - } - - AccountByUsername account = accountByUsernameRepository.findByUsername(request.getUsername()); - if (account == null) { - logAndBuildGrpcResponse(responseObserver, "No matching accounts found for usernamer: {}", - request.getUsername(), Cause.USERNAME_NOT_FOUND); - return; - } - - SearchResultDetails searchResultDetails = buildSearchResultDetails(account.getAvatar(), account.getFirstName(), - account.getLastName()); - - SearchResponse response = SearchResponse.newBuilder().setSearchResultDetails(searchResultDetails).build(); - logger.debug("Found result for account by username {}: \"{}\"", request.getUsername(), response); - responseObserver.onNext(response); - responseObserver.onCompleted(); - - return; - } - - @Override - public void searchByPhoneNumber(SearchByPhoneNumberRequest request, - StreamObserver responseObserver) { - - logger.info("Getting account by phone number: {}", request.getPhoneNumber()); - if ((request.getPhoneNumber() == null) || request.getPhoneNumber().isEmpty()) { - logAndBuildGrpcResponse(responseObserver, "Missing phone number.", "", Cause.MISSING_PHONENUMBER); - return; - } - try { - request = SearchByPhoneNumberRequest.newBuilder().setPhoneNumber(validator.validatePhone(request.getPhoneNumber())) - .build(); - } catch (InternalError err) { - logAndBuildGrpcResponse(responseObserver, "Invalid phone number {}: ", request.getPhoneNumber(), - Cause.INVALID_PHONENUMBER); - return; - } - - List accounts = accountByAuthenticationProviderRepository - .findAllByAuthenticationProvider(request.getPhoneNumber()); - - if (accounts.isEmpty()) { - logAndBuildGrpcResponse(responseObserver, "No matching accounts found for phone number: {}", - request.getPhoneNumber(), Cause.PHONENUMBER_NOT_FOUND); - return; - } - - AccountByAuthenticationProvider account = accounts.get(0); - SearchResultDetails searchResultDetails = buildSearchResultDetails(account.getAvatar(), account.getFirstName(), - account.getLastName()); - - SearchResponse response = SearchResponse.newBuilder().setSearchResultDetails(searchResultDetails).build(); - logger.debug("Found result for account by phone number {}: \"{}\"", request.getPhoneNumber(), response); - responseObserver.onNext(response); - responseObserver.onCompleted(); - - return; - } - - @Override - public void searchByEmail(SearchByEmailRequest request, StreamObserver responseObserver) { - - logger.info("Getting account by e-mail: {}", request.getEmail()); - if ((request.getEmail() == null) || request.getEmail().isEmpty()) { - logAndBuildGrpcResponse(responseObserver, "Missing e-mail.", "", Cause.MISSING_EMAIL); - return; - } - if (!validator.isEmailValid(request.getEmail())) { - logAndBuildGrpcResponse(responseObserver, "Invalid e-mail {}: ", request.getEmail(), Cause.INVALID_EMAIL); - return; - } - - List accounts = accountByAuthenticationProviderRepository - .findAllByAuthenticationProvider(request.getEmail()); - - if (accounts.isEmpty()) { - logAndBuildGrpcResponse(responseObserver, "No matching accounts found for e-mail: {}", request.getEmail(), - Cause.EMAIL_NOT_FOUND); - return; - } - - AccountByAuthenticationProvider account = accounts.get(0); - SearchResultDetails searchResultDetails = buildSearchResultDetails(account.getAvatar(), account.getFirstName(), - account.getLastName()); - - SearchResponse response = SearchResponse.newBuilder().setSearchResultDetails(searchResultDetails).build(); - logger.debug("Found result for account by e-mail {}: \"{}\"", request.getEmail(), response); - responseObserver.onNext(response); - responseObserver.onCompleted(); - - return; - } - - @Override - public void searchByQrCode(SearchByQrCodeRequest request, StreamObserver responseObserver) { - - logger.info("Getting account by QR code: {}", request.getQrCode()); - if ((request.getQrCode() == null) || request.getQrCode().isEmpty()) { - logAndBuildGrpcResponse(responseObserver, "Missing QR code.", "", Cause.MISSING_QR_CODE); - return; - } - - AccountByQrCode account = accountByQrCodeRepository.findByQrCode(request.getQrCode()); - if (account == null) { - logAndBuildGrpcResponse(responseObserver, "No matching accounts found for QR code: {}", request.getQrCode(), - Cause.QR_CODE_NOT_FOUND); - return; - } - - SearchResultDetails searchResultDetails = buildSearchResultDetails(account.getAvatar(), account.getFirstName(), - account.getLastName()); - - SearchResponse response = SearchResponse.newBuilder().setSearchResultDetails(searchResultDetails).build(); - logger.debug("Found result for account by QR code {}: \"{}\"", request.getQrCode(), response); - responseObserver.onNext(response); - responseObserver.onCompleted(); - - return; - } - - private SearchResultDetails buildSearchResultDetails(ByteBuffer avatar, String firstName, String lastName) { - SearchResultDetails searchResultDetails = SearchResultDetails.newBuilder() - .setAvatar(com.google.protobuf.ByteString.copyFrom(avatar)).setFirstName(firstName) - .setLastName(lastName).build(); - return searchResultDetails; - } - - private static void logAndBuildGrpcResponse(StreamObserver responseObserver, String logMessage, - String logValue, Cause cause) { - logger.debug(logMessage, logValue); - responseObserver - .onNext(SearchResponse.newBuilder().setError(ErrorResponse.newBuilder().setCause(cause)).build()); - responseObserver.onCompleted(); - } - -} diff --git a/src/main/java/biz/nynja/account/services/decomposition/AccountsProvider.java b/src/main/java/biz/nynja/account/services/decomposition/AccountsProvider.java index 07dae8d..23bb7c4 100644 --- a/src/main/java/biz/nynja/account/services/decomposition/AccountsProvider.java +++ b/src/main/java/biz/nynja/account/services/decomposition/AccountsProvider.java @@ -71,7 +71,7 @@ public class AccountsProvider { public Optional getAccountByAccountId(AccountByAccountIdRequest request) { logger.info("Getting accounts by account id: {}", request.getAccountId()); Account account = accountRepository.findByAccountId(UUID.fromString(request.getAccountId())); - if (account == null) { + if (account.getAccountId() == null) { return Optional.empty(); } AccountResponse response = AccountResponse.newBuilder().setAccountDetails(account.toProto()).build(); diff --git a/src/test/java/biz/nynja/account/services/AccountServiceTests.java b/src/test/java/biz/nynja/account/services/AccountServiceTests.java index a1a45c5..47e0132 100644 --- a/src/test/java/biz/nynja/account/services/AccountServiceTests.java +++ b/src/test/java/biz/nynja/account/services/AccountServiceTests.java @@ -10,6 +10,7 @@ import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.verify; import java.util.ArrayList; +import java.util.LinkedList; import java.util.List; import java.util.Optional; import java.util.UUID; @@ -60,6 +61,8 @@ import biz.nynja.account.grpc.UpdateProfileRequest; import biz.nynja.account.models.Account; import biz.nynja.account.models.AccountByAuthenticationProvider; import biz.nynja.account.models.AccountByProfileId; +import biz.nynja.account.models.AccountByQrCode; +import biz.nynja.account.models.AccountByUsername; import biz.nynja.account.models.AuthenticationProvider; import biz.nynja.account.models.ContactInfo; import biz.nynja.account.models.PendingAccount; @@ -68,6 +71,8 @@ import biz.nynja.account.models.Profile; import biz.nynja.account.models.ProfileByAuthenticationProvider; import biz.nynja.account.repositories.AccountByAuthenticationProviderRepository; import biz.nynja.account.repositories.AccountByProfileIdRepository; +import biz.nynja.account.repositories.AccountByQrCodeRepository; +import biz.nynja.account.repositories.AccountByUsernameRepository; import biz.nynja.account.repositories.AccountRepository; import biz.nynja.account.repositories.AccountRepositoryAdditional; import biz.nynja.account.repositories.PendingAccountRepository; @@ -75,6 +80,11 @@ import biz.nynja.account.repositories.ProfileByAuthenticationProviderRepository; import biz.nynja.account.repositories.ProfileRepository; import biz.nynja.account.utils.GrpcServerTestBase; import biz.nynja.account.utils.Util; +import biz.nynja.account.grpc.SearchByQrCodeRequest; +import biz.nynja.account.grpc.SearchByEmailRequest; +import biz.nynja.account.grpc.SearchByPhoneNumberRequest; +import biz.nynja.account.grpc.SearchByUsernameRequest; +import biz.nynja.account.grpc.SearchResponse; /** * AccountService unit tests. @@ -89,9 +99,6 @@ import biz.nynja.account.utils.Util; @ActiveProfiles("dev") public class AccountServiceTests extends GrpcServerTestBase { - @MockBean - private AccountByAuthenticationProviderRepository accountByAuthenticationProviderRepository; - @Autowired @Qualifier("accountByPhone") private AccountByAuthenticationProvider accountByPhone; @@ -152,6 +159,21 @@ public class AccountServiceTests extends GrpcServerTestBase { @Qualifier("profileByAuthenticationProvider") private ProfileByAuthenticationProvider profileByAuthenticationProvider; + @Autowired + @Qualifier("savedResponse") + private AccountByUsername savedResponse; + + @Autowired + @Qualifier("savedResponseProvider") + private AccountByAuthenticationProvider savedResponseProvider; + + @Autowired + @Qualifier("savedResponseQrCode") + private AccountByQrCode savedResponseQrCode; + + @MockBean + private AccountByAuthenticationProviderRepository accountByAuthenticationProviderRepository; + @MockBean private PreparedStatementsCache preparedStatementsCache; @@ -173,11 +195,14 @@ public class AccountServiceTests extends GrpcServerTestBase { @MockBean private ProfileByAuthenticationProviderRepository profileByAutheticationProviderRepository; + @MockBean + private AccountByQrCodeRepository accountByQrCodeRepository; + @MockBean private AccountServiceHelper util; @MockBean - private PreparedStatementsCache preparedStatementsCache; + private AccountByUsernameRepository accountByUsernameRepository; @Test public void testGetAccountByAccountId() throws ExecutionException, InterruptedException { @@ -1428,4 +1453,259 @@ public class AccountServiceTests extends GrpcServerTestBase { assertTrue(String.format("Reply should contain cause '%s'", Cause.INVALID_BIRTHDAY_DATE), reply.getError().getCause().equals(Cause.INVALID_BIRTHDAY_DATE)); } + + public void testSearchByUsername() throws ExecutionException, InterruptedException { + final SearchByUsernameRequest request = SearchByUsernameRequest.newBuilder() + .setUsername(Util.S_USERNAME).build(); + + AccountByUsername response = savedResponse; + + given(accountByUsernameRepository.findByUsername(request.getUsername())).willReturn(response); + + final AccountServiceGrpc.AccountServiceBlockingStub searchServiceBlockingStub = AccountServiceGrpc + .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + + final SearchResponse reply = searchServiceBlockingStub.searchByUsername(request); + + assertNotNull("Reply should not be null", reply); + assertTrue(String.format("Reply should contain last name '%s'", Util.S_LAST_NAME.toString()), + reply.getSearchResultDetails().getLastName().equals(Util.S_LAST_NAME.toString())); + } + + @Test + public void testSearchByUsernameNotFound() throws ExecutionException, InterruptedException { + final SearchByUsernameRequest request = SearchByUsernameRequest.newBuilder() + .setUsername(Util.S_USERNAME).build(); + + AccountByUsername response = null; + + given(accountByUsernameRepository.findByUsername(request.getUsername())).willReturn(response); + + final AccountServiceGrpc.AccountServiceBlockingStub searchServiceBlockingStub = AccountServiceGrpc + .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + + final SearchResponse reply = searchServiceBlockingStub.searchByUsername(request); + + assertNotNull("Reply should not be null", reply); + assertTrue(String.format("Reply should contain cause '%s'", Cause.USERNAME_NOT_FOUND), + reply.getError().getCause().equals(Cause.USERNAME_NOT_FOUND)); + } + + @Test + public void testSearchByUsernameBadRequest() throws ExecutionException, InterruptedException { + final SearchByUsernameRequest request = SearchByUsernameRequest.newBuilder().build(); + + final AccountServiceGrpc.AccountServiceBlockingStub searchServiceBlockingStub = AccountServiceGrpc + .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + + final SearchResponse reply = searchServiceBlockingStub.searchByUsername(request); + + assertNotNull("Reply should not be null", reply); + assertTrue(String.format("Reply should contain cause '%s'", Cause.MISSING_USERNAME), + reply.getError().getCause().equals(Cause.MISSING_USERNAME)); + } + + @Test + public void testSearchByUsernameInvalid() { + final SearchByUsernameRequest request = SearchByUsernameRequest.newBuilder() + .setUsername(Util.S_INVALID_USERNAME).build(); + + final AccountServiceGrpc.AccountServiceBlockingStub searchServiceBlockingStub = AccountServiceGrpc + .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + + final SearchResponse reply = searchServiceBlockingStub.searchByUsername(request); + + assertNotNull("Reply should not be null", reply); + assertTrue(String.format("Reply should contain cause '%s'", Cause.INVALID_USERNAME), + reply.getError().getCause().equals(Cause.INVALID_USERNAME)); + } + + @Test + public void testSearchByPhoneNumber() throws ExecutionException, InterruptedException { + final SearchByPhoneNumberRequest request = SearchByPhoneNumberRequest.newBuilder() + .setPhoneNumber(Util.S_PHONE_NUMBER).build(); + + List response = new LinkedList<>(); + response.add(savedResponseProvider); + + given(accountByAuthenticationProviderRepository.findAllByAuthenticationProvider(request.getPhoneNumber())).willReturn(response); + + final AccountServiceGrpc.AccountServiceBlockingStub searchServiceBlockingStub = AccountServiceGrpc + .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + + final SearchResponse reply = searchServiceBlockingStub.searchByPhoneNumber(request); + + assertNotNull("Reply should not be null", reply); + assertTrue(String.format("Reply should contain last name '%s'", Util.S_LAST_NAME.toString()), + reply.getSearchResultDetails().getLastName().equals(Util.S_LAST_NAME.toString())); + } + + @Test + public void testSearchByPhoneNumberNotFound() throws ExecutionException, InterruptedException { + final SearchByPhoneNumberRequest request = SearchByPhoneNumberRequest.newBuilder() + .setPhoneNumber(Util.S_PHONE_NUMBER).build(); + + List response = new LinkedList<>(); + + given(accountByAuthenticationProviderRepository.findAllByAuthenticationProvider(request.getPhoneNumber())).willReturn(response); + + final AccountServiceGrpc.AccountServiceBlockingStub searchServiceBlockingStub = AccountServiceGrpc + .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + + final SearchResponse reply = searchServiceBlockingStub.searchByPhoneNumber(request); + + assertNotNull("Reply should not be null", reply); + assertTrue(String.format("Reply should contain cause '%s'", Cause.PHONENUMBER_NOT_FOUND), + reply.getError().getCause().equals(Cause.PHONENUMBER_NOT_FOUND)); + } + + @Test + public void testSearchByPhoneNumberBadRequest() throws ExecutionException, InterruptedException { + final SearchByPhoneNumberRequest request = SearchByPhoneNumberRequest.newBuilder().build(); + + final AccountServiceGrpc.AccountServiceBlockingStub searchServiceBlockingStub = AccountServiceGrpc + .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + + final SearchResponse reply = searchServiceBlockingStub.searchByPhoneNumber(request); + + assertNotNull("Reply should not be null", reply); + assertTrue(String.format("Reply should contain cause '%s'", Cause.MISSING_PHONENUMBER), + reply.getError().getCause().equals(Cause.MISSING_PHONENUMBER)); + } + + @Test + public void testSearchByPhoneNumberInvalid() { + final SearchByPhoneNumberRequest request = SearchByPhoneNumberRequest.newBuilder() + .setPhoneNumber(Util.S_INVALID_PHONENUMBER).build(); + + final AccountServiceGrpc.AccountServiceBlockingStub searchServiceBlockingStub = AccountServiceGrpc + .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + + final SearchResponse reply = searchServiceBlockingStub.searchByPhoneNumber(request); + + assertNotNull("Reply should not be null", reply); + assertTrue(String.format("Reply should contain cause '%s'", Cause.INVALID_PHONENUMBER), + reply.getError().getCause().equals(Cause.INVALID_PHONENUMBER)); + } + + @Test + public void testSearchByEmail() throws ExecutionException, InterruptedException { + final SearchByEmailRequest request = SearchByEmailRequest.newBuilder() + .setEmail(Util.S_EMAIL).build(); + + List response = new LinkedList<>(); + response.add(savedResponseProvider); + + given(accountByAuthenticationProviderRepository.findAllByAuthenticationProvider(request.getEmail())).willReturn(response); + + final AccountServiceGrpc.AccountServiceBlockingStub searchServiceBlockingStub = AccountServiceGrpc + .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + + final SearchResponse reply = searchServiceBlockingStub.searchByEmail(request); + + assertNotNull("Reply should not be null", reply); + assertTrue(String.format("Reply should contain last name '%s'", Util.S_LAST_NAME.toString()), + reply.getSearchResultDetails().getLastName().equals(Util.S_LAST_NAME.toString())); + } + + @Test + public void testSearchByEmailNotFound() throws ExecutionException, InterruptedException { + final SearchByEmailRequest request = SearchByEmailRequest.newBuilder() + .setEmail(Util.S_EMAIL).build(); + + List response = new LinkedList<>(); + + given(accountByAuthenticationProviderRepository.findAllByAuthenticationProvider(request.getEmail())).willReturn(response); + + final AccountServiceGrpc.AccountServiceBlockingStub searchServiceBlockingStub = AccountServiceGrpc + .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + + final SearchResponse reply = searchServiceBlockingStub.searchByEmail(request); + + assertNotNull("Reply should not be null", reply); + assertTrue(String.format("Reply should contain cause '%s'", Cause.EMAIL_NOT_FOUND), + reply.getError().getCause().equals(Cause.EMAIL_NOT_FOUND)); + } + + @Test + public void testSearchByEmailBadRequest() throws ExecutionException, InterruptedException { + final SearchByEmailRequest request = SearchByEmailRequest.newBuilder().build(); + + final AccountServiceGrpc.AccountServiceBlockingStub searchServiceBlockingStub = AccountServiceGrpc + .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + + final SearchResponse reply = searchServiceBlockingStub.searchByEmail(request); + + assertNotNull("Reply should not be null", reply); + assertTrue(String.format("Reply should contain cause '%s'", Cause.MISSING_EMAIL), + reply.getError().getCause().equals(Cause.MISSING_EMAIL)); + } + + @Test + public void testSearchByEmailInvalid() { + final SearchByEmailRequest request = SearchByEmailRequest.newBuilder() + .setEmail(Util.S_INVALID_EMAIL).build(); + + final AccountServiceGrpc.AccountServiceBlockingStub searchServiceBlockingStub = AccountServiceGrpc + .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + + final SearchResponse reply = searchServiceBlockingStub.searchByEmail(request); + + assertNotNull("Reply should not be null", reply); + assertTrue(String.format("Reply should contain cause '%s'", Cause.INVALID_EMAIL), + reply.getError().getCause().equals(Cause.INVALID_EMAIL)); + } + + @Test + public void testSearchByQrCode() throws ExecutionException, InterruptedException { + final SearchByQrCodeRequest request = SearchByQrCodeRequest.newBuilder() + .setQrCode(Util.S_QR_CODE).build(); + + AccountByQrCode response = savedResponseQrCode; + + given(accountByQrCodeRepository.findByQrCode(request.getQrCode())).willReturn(response); + + final AccountServiceGrpc.AccountServiceBlockingStub searchServiceBlockingStub = AccountServiceGrpc + .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + + final SearchResponse reply = searchServiceBlockingStub.searchByQrCode(request); + + assertNotNull("Reply should not be null", reply); + assertTrue(String.format("Reply should contain last name '%s'", Util.S_LAST_NAME.toString()), + reply.getSearchResultDetails().getLastName().equals(Util.S_LAST_NAME.toString())); + } + + @Test + public void testSearchByQrCodeNotFound() throws ExecutionException, InterruptedException { + final SearchByQrCodeRequest request = SearchByQrCodeRequest.newBuilder() + .setQrCode(Util.S_QR_CODE).build(); + + AccountByQrCode response = null; + + given(accountByQrCodeRepository.findByQrCode(request.getQrCode())).willReturn(response); + + final AccountServiceGrpc.AccountServiceBlockingStub searchServiceBlockingStub = AccountServiceGrpc + .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + + final SearchResponse reply = searchServiceBlockingStub.searchByQrCode(request); + + assertNotNull("Reply should not be null", reply); + assertTrue(String.format("Reply should contain cause '%s'", Cause.QR_CODE_NOT_FOUND), + reply.getError().getCause().equals(Cause.QR_CODE_NOT_FOUND)); + } + + @Test + public void testSearchByQrCodeBadRequest() throws ExecutionException, InterruptedException { + final SearchByQrCodeRequest request = SearchByQrCodeRequest.newBuilder().build(); + + final AccountServiceGrpc.AccountServiceBlockingStub searchServiceBlockingStub = AccountServiceGrpc + .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); + + final SearchResponse reply = searchServiceBlockingStub.searchByQrCode(request); + + assertNotNull("Reply should not be null", reply); + assertTrue(String.format("Reply should contain cause '%s'", Cause.MISSING_QR_CODE), + reply.getError().getCause().equals(Cause.MISSING_QR_CODE)); + } + } diff --git a/src/test/java/biz/nynja/account/utils/Util.java b/src/test/java/biz/nynja/account/utils/Util.java index 08f4aa2..1fc500e 100644 --- a/src/test/java/biz/nynja/account/utils/Util.java +++ b/src/test/java/biz/nynja/account/utils/Util.java @@ -13,17 +13,20 @@ import java.util.UUID; import org.springframework.boot.test.context.TestConfiguration; import org.springframework.context.annotation.Bean; + import biz.nynja.account.grpc.AccessStatus; import biz.nynja.account.grpc.Role; import biz.nynja.account.models.Account; import biz.nynja.account.models.AccountByAuthenticationProvider; import biz.nynja.account.models.AccountByProfileId; +import biz.nynja.account.models.AccountByQrCode; +import biz.nynja.account.models.AccountByUsername; import biz.nynja.account.models.AuthenticationProvider; import biz.nynja.account.models.ContactInfo; -import biz.nynja.account.models.PendingAccount; -import biz.nynja.account.models.PendingAccountByAuthenticationProvider; import biz.nynja.account.models.Profile; import biz.nynja.account.models.ProfileByAuthenticationProvider; +import biz.nynja.account.models.PendingAccount; +import biz.nynja.account.models.PendingAccountByAuthenticationProvider; /** * Unit tests variables, beans and help methods. @@ -67,6 +70,18 @@ public class Util { public static final String FACBOOK_TYPE = "FACEBOOK"; public static final String GOOGLEPLUS_TYPE = "GOOGLEPLUS"; + public static final String S_USERNAME = "TomJohns"; + public static final String S_PHONE_NUMBER = "448873598834"; + public static final String S_EMAIL = "p_petrov@abv.bg"; + public static final String S_QR_CODE = "QRcoded"; + public static final String S_INVALID_USERNAME = "Tom-Johns"; + public static final String S_INVALID_PHONENUMBER = "GB:44887359883"; // one DTMF less + public static final String S_INVALID_EMAIL = "p_petrov.@abv.bg"; + public static final String S_AVATAR_STRING = "avatar-TomJohns"; + public static final String S_FIRST_NAME = "Tom"; + public static final String S_LAST_NAME = "Johns"; + + @Bean public ProfileByAuthenticationProvider profileByAuthenticationProvider() { ProfileByAuthenticationProvider profile = new ProfileByAuthenticationProvider(); @@ -262,4 +277,32 @@ public class Util { pendingAccount.setCreationTimestamp(EXISTING_PENDING_ACCOUNT_TIMESTAMP_UPDATED); return pendingAccount; } + + @Bean + public AccountByUsername savedResponse() { + AccountByUsername response = new AccountByUsername(); + response.setAvatar(ByteBuffer.wrap(S_AVATAR_STRING.getBytes())); + response.setFirstName(Util.S_FIRST_NAME); + response.setLastName(Util.S_LAST_NAME); + return response; + } + + @Bean + public AccountByAuthenticationProvider savedResponseProvider() { + AccountByAuthenticationProvider response = new AccountByAuthenticationProvider(); + response.setAvatar(ByteBuffer.wrap(S_AVATAR_STRING.getBytes())); + response.setFirstName(Util.S_FIRST_NAME); + response.setLastName(Util.S_LAST_NAME); + return response; + } + + @Bean + public AccountByQrCode savedResponseQrCode() { + AccountByQrCode response = new AccountByQrCode(); + response.setAvatar(ByteBuffer.wrap(S_AVATAR_STRING.getBytes())); + response.setFirstName(Util.S_FIRST_NAME); + response.setLastName(Util.S_LAST_NAME); + return response; + } + } -- GitLab From 6f7482a77684a2f7f11d6a6c64e33baca19c1533 Mon Sep 17 00:00:00 2001 From: Stoyan Hristov Date: Fri, 2 Nov 2018 16:31:01 +0200 Subject: [PATCH 6/9] NY-3607: restructored --- pom.xml | 2 +- .../nynja/account/components/Validator.java | 167 +-------- .../nynja/account/models/AccountByQrCode.java | 96 ++++- .../account/models/AccountByUsername.java | 62 +++- .../PhoneNumberNormalizer.java | 5 +- .../account/phone/PhoneNumberValidator.java | 195 ++++++++++ .../account/services/AccountServiceImpl.java | 349 ++++++++++-------- .../decomposition/AccountsProvider.java | 59 ++- .../nynja/account/validation/Validation.java | 59 +++ .../account/validation/ValidationError.java | 33 ++ ...ibphoneNormalizationParameterizedTest.java | 3 +- .../components/PhoneNumberValidatorTests.java | 126 +++++++ .../account/components/ValidatorTests.java | 89 +---- .../account/services/AccountServiceTests.java | 102 ++--- .../java/biz/nynja/account/utils/Util.java | 3 +- 15 files changed, 896 insertions(+), 454 deletions(-) rename src/main/java/biz/nynja/account/{components => phone}/PhoneNumberNormalizer.java (96%) create mode 100644 src/main/java/biz/nynja/account/phone/PhoneNumberValidator.java create mode 100644 src/main/java/biz/nynja/account/validation/Validation.java create mode 100644 src/main/java/biz/nynja/account/validation/ValidationError.java create mode 100644 src/test/java/biz/nynja/account/components/PhoneNumberValidatorTests.java diff --git a/pom.xml b/pom.xml index ad665e6..9ac7f5c 100644 --- a/pom.xml +++ b/pom.xml @@ -101,7 +101,7 @@ libs-snapshot-local.biz.nynja.protos - account-service-intracoldev + account-service-ny-3607-search-users-by-attributes 1.0-SNAPSHOT diff --git a/src/main/java/biz/nynja/account/components/Validator.java b/src/main/java/biz/nynja/account/components/Validator.java index c468aa4..9f7adf6 100644 --- a/src/main/java/biz/nynja/account/components/Validator.java +++ b/src/main/java/biz/nynja/account/components/Validator.java @@ -42,6 +42,9 @@ import biz.nynja.account.models.CountryInfo; import javax.mail.internet.AddressException; import javax.mail.internet.InternetAddress; +import biz.nynja.account.phone.PhoneNumberValidator; +import biz.nynja.account.validation.Validation; +import biz.nynja.account.validation.ValidationError; import biz.nynja.account.grpc.AddAuthenticationProviderRequest; import biz.nynja.account.grpc.AddContactInfoRequest; @@ -61,114 +64,13 @@ public class Validator { private static final int MIN_LAST_NAME_LENGTH = 0; private static final int MAX_LAST_NAME_LENGTH = 32; - private HashMap countryInfoMap; - private HashMap countryMapByCountryCode; - - @PostConstruct - public void loadPhonesBook() { - - CountryInfo countryInfo = null; - BufferedReader reader = null; - countryInfoMap = new HashMap<>(); - countryMapByCountryCode = new HashMap<>(); - - logger.debug("Loading phones information from file."); - try { - Resource resource = new ClassPathResource("countries.txt"); - InputStream resourceInputStream = resource.getInputStream(); - logger.debug("Phones information loaded."); - reader = new BufferedReader(new InputStreamReader(resourceInputStream)); - String line; - while ((line = reader.readLine()) != null) { - String[] args = line.split(";"); - countryInfo = new CountryInfo(); - countryInfo.setCountryCode(args[1]); - countryInfo.setCountryPhoneCode(args[0]); - countryInfo.setCountryName(args[2]); - if (args.length > 3) { - countryInfo.setPhoneFormat(args[3]); - } - countryInfoMap.put(args[1], countryInfo); - countryMapByCountryCode.put(args[0], countryInfo); - } - } catch (IOException e) { - logger.error("Error during load phones information: {}", e.getMessage()); - } finally { - try { - reader.close(); - } catch (IOException e) { - logger.error("Close reader error: {}", e.getMessage()); - } - } - - } - - public String getCountrySelector(String countryCode) { - CountryInfo countryInfo = countryMapByCountryCode.get(countryCode); - if (countryInfo != null) { - return countryInfo.getCountryCode(); - } else { - logger.debug("Country selector not found in'countries.txt' for country code: {}", countryCode); - throw new InternalError(Cause.INVALID_PHONENUMBER.getValueDescriptor().toString(), - new InternalError("No country selector found in 'countries.txt' for country code: " + countryCode)); - } + private PhoneNumberValidator phoneValidator; + + public Validator(PhoneNumberValidator phoneValidator) { + this.phoneValidator = phoneValidator; + } - public boolean isPhoneNumberValid(String phoneNumber, String countryCode) { - - logger.debug("Checking phoneNumber: {} for country: {}", phoneNumber, countryCode); - CountryInfo countryInfo = countryInfoMap.get(countryCode); - if (countryInfo == null) { - logger.debug("Country: {} not found!", countryCode); - return false; - } - - char[] digits = countryInfo.getCountryPhoneCode().toCharArray(); - StringBuilder builder = new StringBuilder(); - for (char digit : digits) { - builder.append("[" + digit + "]"); - } - String codePattern = builder.toString(); - - String phoneLength = null; - if (countryInfo.getPhoneFormat() != null) { - phoneLength = "{" + countryInfo.getPhoneFormat().replaceAll("\\s", "").length() + "}"; - } else { - phoneLength = "+"; - } - - final String PHONE_PATTERN = "((?:\\+?([0][0])?" + codePattern + ")?||([0][0]" + codePattern + ")?)(\\d" - + phoneLength + ")$"; - logger.debug("Generated phone pattern for country: {}, {}", countryCode, PHONE_PATTERN); - - Pattern pattern = Pattern.compile(PHONE_PATTERN); - Matcher matcher = pattern.matcher(phoneNumber); - - boolean isValid = matcher.matches(); - logger.debug("PhoneNumber: {} for country: {} is valid: {}", phoneNumber, countryCode, isValid); - - return isValid; - } - - public String getNormalizedPhoneNumber(String authenticationProvider) { - String[] provider = authenticationProvider.split(":"); - String country = provider[0]; - String phoneNumber = provider[1]; - logger.info("libphone: New phone number normalization request received - phone number: {}, country code: {}", - phoneNumber, country); - - PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance(); - String normalizedPhoneNumber = ""; - try { - PhoneNumber pn = phoneUtil.parse(phoneNumber, country); - normalizedPhoneNumber = Integer.toString(pn.getCountryCode()) + Long.toString(pn.getNationalNumber()); - logger.info("libphone: Normalized phone number: " + normalizedPhoneNumber); - } catch (NumberParseException e) { - logger.error("libphone: NumberParseException was thrown: {}", e.toString()); - logger.debug("libphone: NumberParseException was thrown: {}", e.getCause()); - } - return normalizedPhoneNumber; - } public boolean isUsernameValid(String username) { @@ -220,6 +122,9 @@ public class Validator { } public boolean isValidUsername(String username) { + if(username == null) { + return false; + } return username.matches("[a-zA-Z0-9_]{1,32}"); } @@ -250,7 +155,7 @@ public class Validator { if (provider == null || provider.length != 2) { return Cause.PHONE_NUMBER_INVALID; } - if (!isPhoneNumberValid(provider[1], provider[0])) { + if (!phoneValidator.isPhoneNumberValid(provider[1], provider[0])) { return Cause.PHONE_NUMBER_INVALID; } break; @@ -278,7 +183,7 @@ public class Validator { if (provider == null || provider.length != 2) { return Optional.of(new ImmutablePair<>(Cause.PHONE_NUMBER_INVALID, "Invalid phone number")); } - if (!isPhoneNumberValid(provider[1], provider[0])) { + if (!phoneValidator.isPhoneNumberValid(provider[1], provider[0])) { return Optional.of(new ImmutablePair<>(Cause.PHONE_NUMBER_INVALID, "Invalid phone number")); } break; @@ -418,50 +323,4 @@ public class Validator { } return null; } - - public String validatePhone(String phoneString) throws InternalError { - String phoneNumber = ""; - - String[] provider = phoneString.split(":"); - if (provider.length == 1) { // no country selector - phoneNumber = provider[0]; - } else { - phoneNumber = provider[1]; - } - if (!phoneNumber.matches("^\\+?[\\d- ]+$")) { - throw new InternalError(Cause.INVALID_PHONENUMBER.getValueDescriptor().toString(), - new InternalError("Invalid phone number: " + phoneNumber)); // invalid phone number - } - phoneNumber = phoneNumber.replaceAll("^0*", "").replaceAll("[^\\d]", ""); - - String countryCode = getCountryCode(phoneNumber); - - String countrySelector = getCountrySelector(countryCode); - - if (!isPhoneNumberValid(phoneNumber, countrySelector)) { - throw new InternalError(Cause.INVALID_PHONENUMBER.getValueDescriptor().toString(), - new InternalError("Invalid phone number: " + phoneNumber)); // invalid phone number - } - - if ((provider.length == 2) && (!countrySelector.equals(provider[0]))) { - throw new InternalError(Cause.INVALID_PHONENUMBER.getValueDescriptor().toString(), - new InternalError("Request country selector = " + provider[0] - + " while derived country selector = " + countrySelector)); - } - return phoneNumber; - } - - private String getCountryCode(String phoneNumber) { - - PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance(); - try { - Phonenumber.PhoneNumber numberProto = phoneUtil.parse("+" + phoneNumber, ""); - logger.debug("Country code found: {}", numberProto.getCountryCode()); - return Integer.toString(numberProto.getCountryCode()); - } catch (NumberParseException e) { - throw new InternalError(Cause.INVALID_PHONENUMBER.getValueDescriptor().toString(), - new InternalError("No country code found for phone number: " + phoneNumber)); - } - } - } diff --git a/src/main/java/biz/nynja/account/models/AccountByQrCode.java b/src/main/java/biz/nynja/account/models/AccountByQrCode.java index 479a12a..0100f4d 100644 --- a/src/main/java/biz/nynja/account/models/AccountByQrCode.java +++ b/src/main/java/biz/nynja/account/models/AccountByQrCode.java @@ -7,7 +7,9 @@ import java.nio.ByteBuffer; import java.util.Set; import java.util.UUID; +import biz.nynja.account.grpc.AccessStatus; import biz.nynja.account.grpc.AccountDetails; +import biz.nynja.account.grpc.Role; import biz.nynja.account.grpc.AccountDetails.Builder; public class AccountByQrCode { @@ -22,11 +24,12 @@ public class AccountByQrCode { private ByteBuffer avatar; private String accountName; private String username; - private String accountStatus; private Long creationTimestamp; private Long lastUpdateTimestamp; private Set contactsInfo; private String qrCode; + private String accessStatus; + private Set roles; public UUID getProfileId() { return profileId; @@ -108,12 +111,12 @@ public class AccountByQrCode { this.username = username; } - public String getAccountStatus() { - return accountStatus; + public String getAccessStatus() { + return accessStatus; } - public void setAccountStatus(String accountStatus) { - this.accountStatus = accountStatus; + public void setAccessStatus(String accesstStatus) { + this.accessStatus = accesstStatus; } public Long getCreationTimestamp() { @@ -147,6 +150,15 @@ public class AccountByQrCode { public void setQrCode(String qrCode) { this.qrCode = qrCode; } + + + public Set getRoles() { + return roles; + } + + public void setRoles(Set roles) { + this.roles = roles; + } @Override public int hashCode() { @@ -155,7 +167,7 @@ public class AccountByQrCode { result = prime * result + ((accountId == null) ? 0 : accountId.hashCode()); result = prime * result + ((accountMark == null) ? 0 : accountMark.hashCode()); result = prime * result + ((accountName == null) ? 0 : accountName.hashCode()); - result = prime * result + ((accountStatus == null) ? 0 : accountStatus.hashCode()); + result = prime * result + ((accessStatus == null) ? 0 : accessStatus.hashCode()); result = prime * result + ((authenticationProvider == null) ? 0 : authenticationProvider.hashCode()); result = prime * result + ((authenticationProviderType == null) ? 0 : authenticationProviderType.hashCode()); result = prime * result + ((avatar == null) ? 0 : avatar.hashCode()); @@ -166,6 +178,7 @@ public class AccountByQrCode { result = prime * result + ((lastUpdateTimestamp == null) ? 0 : lastUpdateTimestamp.hashCode()); result = prime * result + ((profileId == null) ? 0 : profileId.hashCode()); result = prime * result + ((qrCode == null) ? 0 : qrCode.hashCode()); + result = prime * result + ((roles == null) ? 0 : roles.hashCode()); result = prime * result + ((username == null) ? 0 : username.hashCode()); return result; } @@ -194,10 +207,10 @@ public class AccountByQrCode { return false; } else if (!accountName.equals(other.accountName)) return false; - if (accountStatus == null) { - if (other.accountStatus != null) + if (accessStatus == null) { + if (other.accessStatus != null) return false; - } else if (!accountStatus.equals(other.accountStatus)) + } else if (!accessStatus.equals(other.accessStatus)) return false; if (authenticationProvider == null) { if (other.authenticationProvider != null) @@ -249,6 +262,11 @@ public class AccountByQrCode { return false; } else if (!qrCode.equals(other.qrCode)) return false; + if (roles == null) { + if (other.roles != null) + return false; + } else if (!roles.equals(other.roles)) + return false; if (username == null) { if (other.username != null) return false; @@ -264,12 +282,70 @@ public class AccountByQrCode { .append(authenticationProvider).append(", authenticationProviderType=") .append(authenticationProviderType).append(", firstName=").append(firstName).append(", lastName=") .append(lastName).append(", avatar=").append(avatar).append(", accountName=").append(accountName) - .append(", username=").append(username).append(", accountStatus=").append(accountStatus) + .append(", username=").append(username).append(", accountStatus=").append(accessStatus) .append(", creationTimestamp=").append(creationTimestamp) .append(", lastUpdateTimestamp=").append(lastUpdateTimestamp) .append(", qrCode=").append(qrCode) .append(", contactsInfo=").append(contactsInfo) + .append(", roles=").append(roles) .append("]").toString(); } + + + + public AccountDetails toProto() { + + Builder builder = AccountDetails.newBuilder(); + + if (getAccountId() != null) { + builder.setAccountId(getAccountId().toString()); + } + if (getProfileId() != null) { + builder.setProfileId(getProfileId().toString()); + } + if (getAuthenticationProvider() != null) { + builder.setAuthenticationIdentifier(getAuthenticationProvider()); + } + if (getAuthenticationProviderType() != null) { + builder.setAuthenticationType(getAuthenticationProviderType()); + } + if (getAccountMark() != null) { + builder.setAccountMark(getAccountMark()); + } + if (getAccountName() != null) { + builder.setAccountName(getAccountName()); + } + if (getFirstName() != null) { + builder.setFirstName(getFirstName()); + } + if (getLastName() != null) { + builder.setLastName(getLastName()); + } + if (getUsername() != null) { + builder.setUsername(getUsername()); + } + if (getQrCode() != null) { + builder.setQrCode(getQrCode()); + } + if (getAvatar() != null) { + builder.setAvatar(com.google.protobuf.ByteString.copyFrom(avatar)); + } + if (getRoles() != null) { + for (String role : getRoles()) { + builder.addRoles(Role.valueOf(role)); + } + } + if (getAccessStatus() != null) { + builder.setAccessStatus(AccessStatus.valueOf(getAccessStatus())); + } + if (getContactsInfo() != null) { + for (ContactInfo c : contactsInfo) { + builder.addContactsInfo(c.toProto()); + } + } + + return builder.build(); + + } } diff --git a/src/main/java/biz/nynja/account/models/AccountByUsername.java b/src/main/java/biz/nynja/account/models/AccountByUsername.java index ebe01dc..ed40828 100644 --- a/src/main/java/biz/nynja/account/models/AccountByUsername.java +++ b/src/main/java/biz/nynja/account/models/AccountByUsername.java @@ -8,6 +8,11 @@ import java.time.LocalDate; import java.util.Set; import java.util.UUID; +import biz.nynja.account.grpc.AccessStatus; +import biz.nynja.account.grpc.AccountDetails; +import biz.nynja.account.grpc.Role; +import biz.nynja.account.grpc.AccountDetails.Builder; + public class AccountByUsername { private UUID profileId; @@ -299,5 +304,60 @@ public class AccountByUsername { .append(", accessStatus=").append(accessStatus).append(", birthday=").append(birthday).append("]"); return builder.toString(); } - + + public AccountDetails toProto() { + + Builder builder = AccountDetails.newBuilder(); + + if (getAccountId() != null) { + builder.setAccountId(getAccountId().toString()); + } + if (getProfileId() != null) { + builder.setProfileId(getProfileId().toString()); + } + if (getAuthenticationProvider() != null) { + builder.setAuthenticationIdentifier(getAuthenticationProvider()); + } + if (getAuthenticationProviderType() != null) { + builder.setAuthenticationType(getAuthenticationProviderType()); + } + if (getAccountMark() != null) { + builder.setAccountMark(getAccountMark()); + } + if (getAccountName() != null) { + builder.setAccountName(getAccountName()); + } + if (getFirstName() != null) { + builder.setFirstName(getFirstName()); + } + if (getLastName() != null) { + builder.setLastName(getLastName()); + } + if (getUsername() != null) { + builder.setUsername(getUsername()); + } + if (getQrCode() != null) { + builder.setQrCode(getQrCode()); + } + if (getAvatar() != null) { + builder.setAvatar(com.google.protobuf.ByteString.copyFrom(avatar)); + } + if (getRoles() != null) { + for (String role : getRoles()) { + builder.addRoles(Role.valueOf(role)); + } + } + if (getAccessStatus() != null) { + builder.setAccessStatus(AccessStatus.valueOf(getAccessStatus())); + } + if (getContactsInfo() != null) { + for (ContactInfo c : contactsInfo) { + builder.addContactsInfo(c.toProto()); + } + } + + return builder.build(); + + } + } diff --git a/src/main/java/biz/nynja/account/components/PhoneNumberNormalizer.java b/src/main/java/biz/nynja/account/phone/PhoneNumberNormalizer.java similarity index 96% rename from src/main/java/biz/nynja/account/components/PhoneNumberNormalizer.java rename to src/main/java/biz/nynja/account/phone/PhoneNumberNormalizer.java index 1ed7fc9..e9b434f 100644 --- a/src/main/java/biz/nynja/account/components/PhoneNumberNormalizer.java +++ b/src/main/java/biz/nynja/account/phone/PhoneNumberNormalizer.java @@ -1,11 +1,12 @@ /** * Copyright (C) 2018 Nynja Inc. All rights reserved. */ -package biz.nynja.account.components; +package biz.nynja.account.phone; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import biz.nynja.account.components.Validator; import biz.nynja.account.grpc.AddContactInfoRequest; import biz.nynja.account.grpc.ContactDetails; import biz.nynja.account.grpc.DeleteContactInfoRequest; @@ -15,7 +16,7 @@ import biz.nynja.account.grpc.EditContactInfoRequest; public class PhoneNumberNormalizer { @Autowired - private Validator validator; + private PhoneNumberValidator validator; public AddContactInfoRequest normalizePhoneNumber(AddContactInfoRequest request) { // Get the normalized phone number from libphone diff --git a/src/main/java/biz/nynja/account/phone/PhoneNumberValidator.java b/src/main/java/biz/nynja/account/phone/PhoneNumberValidator.java new file mode 100644 index 0000000..8069be8 --- /dev/null +++ b/src/main/java/biz/nynja/account/phone/PhoneNumberValidator.java @@ -0,0 +1,195 @@ +package biz.nynja.account.phone; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.HashMap; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.annotation.PostConstruct; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.Resource; +import org.springframework.stereotype.Component; + +import com.google.i18n.phonenumbers.NumberParseException; +import com.google.i18n.phonenumbers.PhoneNumberUtil; +import com.google.i18n.phonenumbers.Phonenumber; +import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber; + +import biz.nynja.account.grpc.ErrorResponse.Cause; +import biz.nynja.account.models.CountryInfo; +import biz.nynja.account.validation.ValidationError; + +@Component +public class PhoneNumberValidator { + private static final Logger logger = LoggerFactory.getLogger(PhoneNumberValidator.class); + private HashMap countryInfoMap; + private HashMap countryMapByCountryCode; + + @PostConstruct + public void loadPhonesBook() { + + CountryInfo countryInfo = null; + BufferedReader reader = null; + countryInfoMap = new HashMap<>(); + countryMapByCountryCode = new HashMap<>(); + + logger.debug("Loading phones information from file."); + try { + Resource resource = new ClassPathResource("countries.txt"); + InputStream resourceInputStream = resource.getInputStream(); + logger.debug("Phones information loaded."); + reader = new BufferedReader(new InputStreamReader(resourceInputStream)); + String line; + while ((line = reader.readLine()) != null) { + String[] args = line.split(";"); + countryInfo = new CountryInfo(); + countryInfo.setCountryCode(args[1]); + countryInfo.setCountryPhoneCode(args[0]); + countryInfo.setCountryName(args[2]); + if (args.length > 3) { + countryInfo.setPhoneFormat(args[3]); + } + countryInfoMap.put(args[1], countryInfo); + countryMapByCountryCode.put(args[0], countryInfo); + } + } catch (IOException e) { + logger.error("Error during load phones information: {}", e.getMessage()); + } finally { + try { + reader.close(); + } catch (IOException e) { + logger.error("Close reader error: {}", e.getMessage()); + } + } + + } + + public boolean isPhoneNumberValid(String phoneNumber, String countryCode) { + + logger.debug("Checking phoneNumber: {} for country: {}", phoneNumber, countryCode); + CountryInfo countryInfo = countryInfoMap.get(countryCode); + if (countryInfo == null) { + logger.debug("Country: {} not found!", countryCode); + return false; + } + + char[] digits = countryInfo.getCountryPhoneCode().toCharArray(); + StringBuilder builder = new StringBuilder(); + for (char digit : digits) { + builder.append("[" + digit + "]"); + } + String codePattern = builder.toString(); + + String phoneLength = null; + if (countryInfo.getPhoneFormat() != null) { + phoneLength = "{" + countryInfo.getPhoneFormat().replaceAll("\\s", "").length() + "}"; + } else { + phoneLength = "+"; + } + + final String PHONE_PATTERN = "((?:\\+?([0][0])?" + codePattern + ")?||([0][0]" + codePattern + ")?)(\\d" + + phoneLength + ")$"; + logger.debug("Generated phone pattern for country: {}, {}", countryCode, PHONE_PATTERN); + + Pattern pattern = Pattern.compile(PHONE_PATTERN); + Matcher matcher = pattern.matcher(phoneNumber); + + boolean isValid = matcher.matches(); + logger.debug("PhoneNumber: {} for country: {} is valid: {}", phoneNumber, countryCode, isValid); + + return isValid; + } + + + + /** + * + * @param rawPhoneNumber + * it could be in format + i.e +359878123456 or 00 i.e + * 00359878123456 or : i.e :359878225840 + */ + public boolean isPhoneNumberValid(String rawPhoneNumber) { + String phoneNumber; + + String[] provider = rawPhoneNumber.split(":"); + if (provider.length == 1) { // no country selector + phoneNumber = provider[0]; + } else { + phoneNumber = provider[1]; + } + if (!phoneNumber.matches("^\\+?[\\d- ]+$")) { + return false; + } + phoneNumber = phoneNumber.replaceAll("^0*", "").replaceAll("[^\\d]", ""); + + String countryCode = getCountryCode(phoneNumber); + + String countrySelector = getCountrySelector(countryCode); + + if (!isPhoneNumberValid(phoneNumber, countrySelector)) { + return false; + } + + if ((provider.length == 2) && (!countrySelector.equals(provider[0]))) { + return false; + } + + return true; + } + + public String getCountryCode(String phoneNumber) { + + PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance(); + try { + Phonenumber.PhoneNumber numberProto = phoneUtil.parse("+" + phoneNumber, ""); + logger.debug("Country code found: {}", numberProto.getCountryCode()); + return Integer.toString(numberProto.getCountryCode()); + } catch (NumberParseException e) { + throw new InternalError(Cause.INVALID_PHONENUMBER.getValueDescriptor().toString(), + new InternalError("No country code found for phone number: " + phoneNumber)); + } + } + + + public String getNormalizedPhoneNumber(String rawPhoneNumber) { + String[] provider = rawPhoneNumber.split(":"); + if (provider == null || provider.length < 2) { + throw new InternalError("Phone number with wrong format: " + rawPhoneNumber); + } + + String country = provider[0]; + String phoneNumber = provider[1]; + logger.info("libphone: New phone number normalization request received - phone number: {}, country code: {}", + phoneNumber, country); + + PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance(); + String normalizedPhoneNumber = ""; + try { + PhoneNumber pn = phoneUtil.parse(phoneNumber, country); + normalizedPhoneNumber = Integer.toString(pn.getCountryCode()) + Long.toString(pn.getNationalNumber()); + logger.info("libphone: Normalized phone number: " + normalizedPhoneNumber); + } catch (NumberParseException e) { + logger.error("libphone: NumberParseException was thrown: {}", e.toString()); + logger.debug("libphone: NumberParseException was thrown: {}", e.getCause()); + } + return normalizedPhoneNumber; + } + + public String getCountrySelector(String countryCode) { + CountryInfo countryInfo = countryMapByCountryCode.get(countryCode); + if (countryInfo != null) { + return countryInfo.getCountryCode(); + } else { + logger.debug("Country selector not found in'countries.txt' for country code: {}", countryCode); + throw new InternalError(Cause.INVALID_PHONENUMBER.getValueDescriptor().toString(), + new InternalError("No country selector found in 'countries.txt' for country code: " + countryCode)); + } + } + +} diff --git a/src/main/java/biz/nynja/account/services/AccountServiceImpl.java b/src/main/java/biz/nynja/account/services/AccountServiceImpl.java index 4fba79f..ac61087 100644 --- a/src/main/java/biz/nynja/account/services/AccountServiceImpl.java +++ b/src/main/java/biz/nynja/account/services/AccountServiceImpl.java @@ -3,8 +3,6 @@ */ package biz.nynja.account.services; -import static biz.nynja.account.grpc.ErrorResponse.newBuilder; - import java.time.Instant; import java.util.Optional; import java.util.UUID; @@ -14,12 +12,13 @@ import org.lognet.springboot.grpc.GRpcService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import biz.nynja.account.components.PhoneNumberNormalizer; import biz.nynja.account.components.Validator; import biz.nynja.account.grpc.*; import biz.nynja.account.grpc.ErrorResponse.Cause; import biz.nynja.account.models.Account; +import biz.nynja.account.phone.PhoneNumberNormalizer; +import biz.nynja.account.phone.PhoneNumberValidator; import biz.nynja.account.models.*; import biz.nynja.account.repositories.AccountByAuthenticationProviderRepository; import biz.nynja.account.repositories.AccountByQrCodeRepository; @@ -29,6 +28,8 @@ import biz.nynja.account.repositories.PendingAccountRepository; import biz.nynja.account.repositories.ProfileByAuthenticationProviderRepository; import biz.nynja.account.repositories.ProfileRepository; import biz.nynja.account.services.decomposition.AccountsProvider; +import biz.nynja.account.validation.ValidationError; +import biz.nynja.account.validation.Validation; import io.grpc.stub.StreamObserver; import org.apache.commons.lang3.tuple.ImmutablePair; @@ -63,6 +64,7 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas private final AccountByAuthenticationProviderRepository accountByAuthenticationProviderRepository; private final AccountByUsernameRepository accountByUsernameRepository; private final Validator validator; + private final PhoneNumberValidator phoneNumberValidator; private final AccountsProvider accountsProvider; private final PhoneNumberNormalizer phoneNumberNormalizer; @@ -74,6 +76,7 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas AccountByAuthenticationProviderRepository accountByAuthenticationProviderRepository, AccountByUsernameRepository accountByUsernameRepository, Validator validator, + PhoneNumberValidator phoneNumbervalidator, AccountsProvider accountsProvider, PhoneNumberNormalizer phoneNumberNormalizer) { this.pendingAccountRepository = pendingAccountRepository; @@ -84,6 +87,7 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas this.accountByAuthenticationProviderRepository = accountByAuthenticationProviderRepository; this.accountByUsernameRepository = accountByUsernameRepository; this.validator = validator; + this.phoneNumberValidator = phoneNumbervalidator; this.accountsProvider = accountsProvider; this.phoneNumberNormalizer = phoneNumberNormalizer; } @@ -108,7 +112,8 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas sendErrorMessageForAccountResponse(responseObserver, Cause.MISSING_AUTH_PROVIDER_IDENTIFIER); return; } - Optional account = accountsProvider.getAccountByAuthenticationProvider(request); + Optional account = accountsProvider.getAccountResponseByAuthenticationProvider( + request.getAuthenticationType(), request.getAuthenticationIdentifier()); if (!account.isPresent()) { sendErrorMessageForAccountResponse(responseObserver, Cause.ACCOUNT_NOT_FOUND); @@ -117,8 +122,186 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas responseObserver.onCompleted(); } + } + + @Override + public void searchByEmail(GetByEmailRequest request, StreamObserver responseObserver) { + logger.info("Search account by e-mail: {}", request.getEmail()); + if ((request.getEmail() == null) || request.getEmail().isEmpty()) { + logAndBuildGrpcResponse(responseObserver, new ValidationError("Missing e-mail.", Cause.MISSING_EMAIL)); + return; + } + if (!validator.isEmailValid(request.getEmail())) { + logAndBuildGrpcResponse(responseObserver, new ValidationError("Invalid e-mail!. Value : " + request.getEmail(), Cause.INVALID_EMAIL)); + return; + } + + Optional account = accountsProvider.getAccountByAuthenticationProvider(AuthenticationType.EMAIL, + request.getEmail()); + + if (!account.isPresent()) { + logAndBuildGrpcResponse(responseObserver, new ValidationError("No matching accounts found for e-mail: " + request.getEmail(), + Cause.EMAIL_NOT_FOUND)); + return; + } else { + SearchResultDetails searchResultDetails = buildSearchResultDetails(account.get().getAvatar(), + account.get().getFirstName(), account.get().getLastName()); + + SearchResponse response = SearchResponse.newBuilder().setSearchResultDetails(searchResultDetails).build(); + logger.debug("Found result for account by e-mail {}: \"{}\"", request.getEmail(), response); + responseObserver.onNext(response); + responseObserver.onCompleted(); + } + } + + @Override + public void searchByPhoneNumber(GetByPhoneNumberRequest request, StreamObserver responseObserver) { + + logger.info("Search account by phone: {}", request.getPhoneNumber()); + if ((request.getPhoneNumber() == null) || request.getPhoneNumber().isEmpty()) { + logAndBuildGrpcResponse(responseObserver, new ValidationError("Missing phone number.", Cause.MISSING_PHONENUMBER)); + return; + } + + if (!phoneNumberValidator.isPhoneNumberValid(request.getPhoneNumber())) { + logAndBuildGrpcResponse(responseObserver, new ValidationError("Invalid phone number.", Cause.INVALID_PHONENUMBER)); + return; + } + + Optional account = accountsProvider.getAccountByAuthenticationProvider(AuthenticationType.PHONE, + request.getPhoneNumber()); + + if (!account.isPresent()) { + logAndBuildGrpcResponse(responseObserver, new ValidationError( + "No matching accounts found for phone:" + request.getPhoneNumber(), Cause.PHONENUMBER_NOT_FOUND)); + return; + } else { + SearchResultDetails searchResultDetails = buildSearchResultDetails(account.get().getAvatar(), + account.get().getFirstName(), account.get().getLastName()); + + SearchResponse response = SearchResponse.newBuilder().setSearchResultDetails(searchResultDetails).build(); + logger.debug("Found result for account by phone {}: \"{}\"", request.getPhoneNumber(), response); + responseObserver.onNext(response); + responseObserver.onCompleted(); + } + } + + @Override + public void getAccountByUsername(GetByUsernameRequest request, StreamObserver responseObserver) { + logger.info("Getting account by username: {}", request.getUsername()); + Validation validation = validateGetByUsernameRequest(request); + if(validation.hasErrors()) { + logger.debug(validation.getErrorMessage()); + responseObserver.onNext(AccountResponse.newBuilder() + .setError(ErrorResponse.newBuilder().setMessage(validation.getErrorMessage()) + .setCause(validation.getCause().get())).build()); + responseObserver.onCompleted(); + } + + Optional accountResonse = + accountsProvider.getAccountResponseByUsername(request.getUsername()); + + if (!accountResonse.isPresent()) { + sendErrorMessageForAccountResponse(responseObserver, Cause.ACCOUNT_NOT_FOUND); + } else { + responseObserver.onNext(accountResonse.get()); + responseObserver.onCompleted(); + } + } + + @Override + public void searchByUsername(GetByUsernameRequest request, StreamObserver responseObserver) { + logger.info("Searching account by username: {}", request.getUsername()); + Validation validation = validateGetByUsernameRequest(request); + if(validation.hasErrors()) { + logAndBuildGrpcResponse(responseObserver, validation); + } + + AccountByUsername account = accountByUsernameRepository.findByUsername(request.getUsername()); + if (account == null) { + logAndBuildGrpcResponse(responseObserver, new ValidationError("No matching accounts found for username: "+ + request.getUsername(), Cause.USERNAME_NOT_FOUND)); + return; + } + + SearchResultDetails searchResultDetails = buildSearchResultDetails(account.getAvatar(), account.getFirstName(), + account.getLastName()); + + SearchResponse response = SearchResponse.newBuilder().setSearchResultDetails(searchResultDetails).build(); + logger.debug("Found result for account by username {}: \"{}\"", request.getUsername(), response); + responseObserver.onNext(response); + responseObserver.onCompleted(); + + return; + } + + private Validation validateGetByUsernameRequest(GetByUsernameRequest request) { + Validation validation = new Validation(); + + if ((request.getUsername() == null) || request.getUsername().isEmpty()) { + validation.addError(new ValidationError("Missing username.", Cause.MISSING_USERNAME)); + } + if (!validator.isValidUsername(request.getUsername())) { + validation.addError(new ValidationError("Invalid username. Value: " + request.getUsername(), Cause.INVALID_USERNAME)); + } + + return validation; + } + + @Override + public void getAccountByQrCode(GetByQrCodeRequest request, StreamObserver responseObserver) { + logger.info("Search account by QR code: {}", request.getQrCode()); + if ((request.getQrCode() == null) || request.getQrCode().isEmpty()) { + logger.debug("Missing QR code."); + responseObserver.onNext(AccountResponse.newBuilder() + .setError(ErrorResponse.newBuilder().setMessage("Missing QR code.") + .setCause(Cause.MISSING_QR_CODE)).build()); + responseObserver.onCompleted(); + return; + } + + Optional accountResonse = + accountsProvider.getAccountResponseByQrCode(request.getQrCode()); + + if (!accountResonse.isPresent()) { + sendErrorMessageForAccountResponse(responseObserver, Cause.ACCOUNT_NOT_FOUND); + } else { + responseObserver.onNext(accountResonse.get()); + responseObserver.onCompleted(); + } + + } + + + + + @Override + public void searchByQrCode(GetByQrCodeRequest request, StreamObserver responseObserver) { + logger.info("Search account by QR code: {}", request.getQrCode()); + if ((request.getQrCode() == null) || request.getQrCode().isEmpty()) { + logAndBuildGrpcResponse(responseObserver, new ValidationError("Missing QR code.", Cause.MISSING_QR_CODE)); + return; + } + + AccountByQrCode account = accountByQrCodeRepository.findByQrCode(request.getQrCode()); + if (account == null) { + logAndBuildGrpcResponse(responseObserver, new ValidationError("No matching accounts found for QR code! Value: " + request.getQrCode(), + Cause.QR_CODE_NOT_FOUND)); + return; + } + + SearchResultDetails searchResultDetails = buildSearchResultDetails(account.getAvatar(), account.getFirstName(), + account.getLastName()); + + SearchResponse response = SearchResponse.newBuilder().setSearchResultDetails(searchResultDetails).build(); + logger.debug("Found result for account by QR code {}: \"{}\"", request.getQrCode(), response); + responseObserver.onNext(response); + responseObserver.onCompleted(); + + return; } + @Override public void getAllAccountsByProfileId(AccountsByProfileIdRequest request, StreamObserver responseObserver) { @@ -186,8 +369,8 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas if (request.getAuthenticationType() == AuthenticationType.PHONE) { // Get the normalized phone number from libphone CreatePendingAccountRequest newRequest = CreatePendingAccountRequest.newBuilder() - .setAuthenticationType(request.getAuthenticationType()) - .setAuthenticationProvider(validator.getNormalizedPhoneNumber(request.getAuthenticationProvider())) + .setAuthenticationType(request.getAuthenticationType()).setAuthenticationProvider( + phoneNumberValidator.getNormalizedPhoneNumber(request.getAuthenticationProvider())) .build(); request = newRequest; } @@ -455,7 +638,7 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas // Get the normalized phone number from libphone AuthProviderDetails newAuthProviderDetails = AuthProviderDetails.newBuilder() .setAuthenticationType(request.getAuthenticationProvider().getAuthenticationType()) - .setAuthenticationProvider(validator + .setAuthenticationProvider(phoneNumberValidator .getNormalizedPhoneNumber(request.getAuthenticationProvider().getAuthenticationProvider())) .build(); AddAuthenticationProviderRequest newRequest = AddAuthenticationProviderRequest.newBuilder() @@ -686,151 +869,29 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas return; } - @Override - public void searchByUsername(SearchByUsernameRequest request, StreamObserver responseObserver) { - - logger.info("Getting account by username: {}", request.getUsername()); - if ((request.getUsername() == null) || request.getUsername().isEmpty()) { - logAndBuildGrpcResponse(responseObserver, "Missing username.", "", Cause.MISSING_USERNAME); - return; - } - if (!validator.isValidUsername(request.getUsername())) { - logAndBuildGrpcResponse(responseObserver, "Invalid username {}: ", request.getUsername(), - Cause.INVALID_USERNAME); - return; - } - - AccountByUsername account = accountByUsernameRepository.findByUsername(request.getUsername()); - if (account == null) { - logAndBuildGrpcResponse(responseObserver, "No matching accounts found for usernamer: {}", - request.getUsername(), Cause.USERNAME_NOT_FOUND); - return; - } - - SearchResultDetails searchResultDetails = buildSearchResultDetails(account.getAvatar(), account.getFirstName(), - account.getLastName()); - - SearchResponse response = SearchResponse.newBuilder().setSearchResultDetails(searchResultDetails).build(); - logger.debug("Found result for account by username {}: \"{}\"", request.getUsername(), response); - responseObserver.onNext(response); - responseObserver.onCompleted(); - - return; - } - - @Override - public void searchByPhoneNumber(SearchByPhoneNumberRequest request, - StreamObserver responseObserver) { - - logger.info("Getting account by phone number: {}", request.getPhoneNumber()); - if ((request.getPhoneNumber() == null) || request.getPhoneNumber().isEmpty()) { - logAndBuildGrpcResponse(responseObserver, "Missing phone number.", "", Cause.MISSING_PHONENUMBER); - return; - } - try { - request = SearchByPhoneNumberRequest.newBuilder().setPhoneNumber(validator.validatePhone(request.getPhoneNumber())) - .build(); - } catch (InternalError err) { - logAndBuildGrpcResponse(responseObserver, "Invalid phone number {}: ", request.getPhoneNumber(), - Cause.INVALID_PHONENUMBER); - return; - } - - List accounts = accountByAuthenticationProviderRepository - .findAllByAuthenticationProvider(request.getPhoneNumber()); - - if (accounts.isEmpty()) { - logAndBuildGrpcResponse(responseObserver, "No matching accounts found for phone number: {}", - request.getPhoneNumber(), Cause.PHONENUMBER_NOT_FOUND); - return; - } - - AccountByAuthenticationProvider account = accounts.get(0); - SearchResultDetails searchResultDetails = buildSearchResultDetails(account.getAvatar(), account.getFirstName(), - account.getLastName()); - - SearchResponse response = SearchResponse.newBuilder().setSearchResultDetails(searchResultDetails).build(); - logger.debug("Found result for account by phone number {}: \"{}\"", request.getPhoneNumber(), response); - responseObserver.onNext(response); + private static void logAndBuildGrpcResponse(StreamObserver responseObserver, Validation validation) { + logger.debug(validation.getErrorMessage()); + responseObserver + .onNext(SearchResponse.newBuilder().setError(ErrorResponse.newBuilder().setCause(validation.getCause().get())).build()); responseObserver.onCompleted(); - - return; } - - @Override - public void searchByEmail(SearchByEmailRequest request, StreamObserver responseObserver) { - - logger.info("Getting account by e-mail: {}", request.getEmail()); - if ((request.getEmail() == null) || request.getEmail().isEmpty()) { - logAndBuildGrpcResponse(responseObserver, "Missing e-mail.", "", Cause.MISSING_EMAIL); - return; - } - if (!validator.isEmailValid(request.getEmail())) { - logAndBuildGrpcResponse(responseObserver, "Invalid e-mail {}: ", request.getEmail(), Cause.INVALID_EMAIL); - return; - } - - List accounts = accountByAuthenticationProviderRepository - .findAllByAuthenticationProvider(request.getEmail()); - - if (accounts.isEmpty()) { - logAndBuildGrpcResponse(responseObserver, "No matching accounts found for e-mail: {}", request.getEmail(), - Cause.EMAIL_NOT_FOUND); - return; - } - - AccountByAuthenticationProvider account = accounts.get(0); - SearchResultDetails searchResultDetails = buildSearchResultDetails(account.getAvatar(), account.getFirstName(), - account.getLastName()); - - SearchResponse response = SearchResponse.newBuilder().setSearchResultDetails(searchResultDetails).build(); - logger.debug("Found result for account by e-mail {}: \"{}\"", request.getEmail(), response); - responseObserver.onNext(response); + + private static void logAndBuildGrpcResponse(StreamObserver responseObserver, ValidationError error) { + logger.debug(error.getMessage()); + responseObserver + .onNext(SearchResponse.newBuilder().setError(ErrorResponse.newBuilder().setCause(error.getCause())).build()); responseObserver.onCompleted(); - - return; } - @Override - public void searchByQrCode(SearchByQrCodeRequest request, StreamObserver responseObserver) { - - logger.info("Getting account by QR code: {}", request.getQrCode()); - if ((request.getQrCode() == null) || request.getQrCode().isEmpty()) { - logAndBuildGrpcResponse(responseObserver, "Missing QR code.", "", Cause.MISSING_QR_CODE); - return; - } + private SearchResultDetails buildSearchResultDetails(ByteBuffer avatar, String firstName, String lastName) { + SearchResultDetails.Builder searchResultDetails = SearchResultDetails.newBuilder(); - AccountByQrCode account = accountByQrCodeRepository.findByQrCode(request.getQrCode()); - if (account == null) { - logAndBuildGrpcResponse(responseObserver, "No matching accounts found for QR code: {}", request.getQrCode(), - Cause.QR_CODE_NOT_FOUND); - return; + searchResultDetails.setFirstName(firstName).setLastName(lastName); + if (avatar != null) { + searchResultDetails.setAvatar(com.google.protobuf.ByteString.copyFrom(avatar)); } - SearchResultDetails searchResultDetails = buildSearchResultDetails(account.getAvatar(), account.getFirstName(), - account.getLastName()); - - SearchResponse response = SearchResponse.newBuilder().setSearchResultDetails(searchResultDetails).build(); - logger.debug("Found result for account by QR code {}: \"{}\"", request.getQrCode(), response); - responseObserver.onNext(response); - responseObserver.onCompleted(); - - return; - } - - private static void logAndBuildGrpcResponse(StreamObserver responseObserver, String logMessage, - String logValue, Cause cause) { - logger.debug(logMessage, logValue); - responseObserver - .onNext(SearchResponse.newBuilder().setError(ErrorResponse.newBuilder().setCause(cause)).build()); - responseObserver.onCompleted(); - } - - private SearchResultDetails buildSearchResultDetails(ByteBuffer avatar, String firstName, String lastName) { - SearchResultDetails searchResultDetails = SearchResultDetails.newBuilder() - .setAvatar(com.google.protobuf.ByteString.copyFrom(avatar)).setFirstName(firstName) - .setLastName(lastName).build(); - return searchResultDetails; + return searchResultDetails.build(); } private void sendErrorMessageForAccountsResponse(StreamObserver responseObserver, Cause cause) { diff --git a/src/main/java/biz/nynja/account/services/decomposition/AccountsProvider.java b/src/main/java/biz/nynja/account/services/decomposition/AccountsProvider.java index 23bb7c4..5bff256 100644 --- a/src/main/java/biz/nynja/account/services/decomposition/AccountsProvider.java +++ b/src/main/java/biz/nynja/account/services/decomposition/AccountsProvider.java @@ -5,7 +5,12 @@ import biz.nynja.account.components.Validator; import biz.nynja.account.grpc.*; import biz.nynja.account.models.Account; import biz.nynja.account.models.AccountByProfileId; +import biz.nynja.account.models.AccountByQrCode; +import biz.nynja.account.models.AccountByUsername; +import biz.nynja.account.phone.PhoneNumberValidator; import biz.nynja.account.repositories.AccountByProfileIdRepository; +import biz.nynja.account.repositories.AccountByQrCodeRepository; +import biz.nynja.account.repositories.AccountByUsernameRepository; import biz.nynja.account.repositories.AccountRepository; import biz.nynja.account.services.AccountServiceImpl; import org.slf4j.Logger; @@ -24,34 +29,70 @@ public class AccountsProvider { private final AccountRepository accountRepository; private final AccountByProfileIdRepository accountByProfileIdRepository; - private final Validator validator; + private final AccountByUsernameRepository accountByUsernameRepository; + private final AccountByQrCodeRepository accountByQrCodeRepository; + private final PhoneNumberValidator validator; private final AccountServiceHelper accountServiceHelper; public AccountsProvider(AccountRepository accountRepository, AccountByProfileIdRepository accountByProfileIdRepository, - Validator validator, + AccountByUsernameRepository accountByUsernameRepository, + AccountByQrCodeRepository accountByQrCodeRepository, + PhoneNumberValidator validator, AccountServiceHelper accountServiceHelper) { this.accountRepository = accountRepository; this.accountByProfileIdRepository = accountByProfileIdRepository; this.validator = validator; this.accountServiceHelper = accountServiceHelper; + this.accountByUsernameRepository = accountByUsernameRepository; + this.accountByQrCodeRepository = accountByQrCodeRepository; } - public Optional getAccountByAuthenticationProvider(AccountByAuthenticationProviderRequest request) { + public Optional getAccountByAuthenticationProvider(AuthenticationType type, String authenticationIdentifier) { - if (request.getAuthenticationType() == AuthenticationType.PHONE) { - request = normalizedPhoneNumber(request); + if (type == AuthenticationType.PHONE) { + authenticationIdentifier = validator.getNormalizedPhoneNumber(authenticationIdentifier); } Account account = accountServiceHelper.getAccountByAuthenticationProviderHelper( - request.getAuthenticationIdentifier(), request.getAuthenticationType().toString()); + authenticationIdentifier, type.toString()); if (account == null) { logger.debug("No matching accounts found for authetntication provider {}: {}", - request.getAuthenticationType(), request.getAuthenticationIdentifier()); + type, authenticationIdentifier); return Optional.empty(); } - AccountResponse response = AccountResponse.newBuilder().setAccountDetails(account.toProto()).build(); + + return Optional.of(account); + } + + public Optional getAccountResponseByUsername(String username){ + AccountByUsername account = accountByUsernameRepository.findByUsername(username); + if(account == null) { + return Optional.empty(); + } + AccountResponse response = AccountResponse.newBuilder().setAccountDetails(account.toProto()).build(); + logger.debug("Found result for account by username {}:", username, response); + return Optional.of(response); + } + + public Optional getAccountResponseByQrCode(String qrCode){ + AccountByQrCode account = accountByQrCodeRepository.findByQrCode(qrCode); + if(account == null) { + return Optional.empty(); + } + AccountResponse response = AccountResponse.newBuilder().setAccountDetails(account.toProto()).build(); + logger.debug("Found result for account by username {}:", qrCode, response); + return Optional.of(response); + } + + public Optional getAccountResponseByAuthenticationProvider(AuthenticationType type, String authenticationIdentifier) { + Optional account = getAccountByAuthenticationProvider(type, authenticationIdentifier); + if(!account.isPresent()) { + return Optional.empty(); + } + + AccountResponse response = AccountResponse.newBuilder().setAccountDetails(account.get().toProto()).build(); logger.debug("Found result for account by authentication provider {}: {}: \"{}\"", - request.getAuthenticationType(), request.getAuthenticationIdentifier(), response); + type, authenticationIdentifier, response); return Optional.of(response); } diff --git a/src/main/java/biz/nynja/account/validation/Validation.java b/src/main/java/biz/nynja/account/validation/Validation.java new file mode 100644 index 0000000..4c57db1 --- /dev/null +++ b/src/main/java/biz/nynja/account/validation/Validation.java @@ -0,0 +1,59 @@ +package biz.nynja.account.validation; + +import java.util.LinkedList; +import java.util.List; +import java.util.Optional; + +import biz.nynja.account.grpc.ErrorResponse.Cause; + +public class Validation { + List errors = new LinkedList<>(); + + public Validation() { + } + + public Validation(ValidationError e) { + errors.add(e); + } + + public void addError(ValidationError e) { + errors.add(e); + } + + public boolean hasErrors() { + return errors.size() > 0; + } + + public List getErrors() { + return errors; + } + + public String getErrorMessage() { + if (!hasErrors()) { + return ""; + } + StringBuilder builder = new StringBuilder(); + for (ValidationError error : errors) { + builder.append("Message: ").append(error.getMessage()).append(". "); + if (error.getCause() != null) { + builder.append("Cause: ").append(error.getCause()); + } + } + + return builder.toString(); + } + + public Optional getCause() { + if (!hasErrors()) { + return Optional.empty(); + } + + if (errors.size() == 1) { + return Optional.of(errors.get(0).getCause()); + } else { + return Optional.of(Cause.MULTIPLE_INVALID_PARAMETERS); + } + + } + +} diff --git a/src/main/java/biz/nynja/account/validation/ValidationError.java b/src/main/java/biz/nynja/account/validation/ValidationError.java new file mode 100644 index 0000000..9ed8012 --- /dev/null +++ b/src/main/java/biz/nynja/account/validation/ValidationError.java @@ -0,0 +1,33 @@ +package biz.nynja.account.validation; + +import biz.nynja.account.grpc.ErrorResponse.Cause; + +public class ValidationError { + private String message; + private Cause cause; + + public ValidationError(String message, Cause cause) { + this.setMessage(message); + this.setCause(cause); + } + + public ValidationError(String message) { + this.setMessage(message); + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Cause getCause() { + return cause; + } + + public void setCause(Cause cause) { + this.cause = cause; + } +} diff --git a/src/test/java/biz/nynja/account/components/LibphoneNormalizationParameterizedTest.java b/src/test/java/biz/nynja/account/components/LibphoneNormalizationParameterizedTest.java index 71e74d3..79a0e6f 100644 --- a/src/test/java/biz/nynja/account/components/LibphoneNormalizationParameterizedTest.java +++ b/src/test/java/biz/nynja/account/components/LibphoneNormalizationParameterizedTest.java @@ -21,6 +21,7 @@ import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.rules.SpringClassRule; import org.springframework.test.context.junit4.rules.SpringMethodRule; +import biz.nynja.account.phone.PhoneNumberValidator; import biz.nynja.account.repositories.AccountRepository; import biz.nynja.account.services.AccountServiceImpl; @@ -34,7 +35,7 @@ import biz.nynja.account.services.AccountServiceImpl; @ContextConfiguration(classes = { Validator.class }) public class LibphoneNormalizationParameterizedTest { - private Validator validator = new Validator(); + private PhoneNumberValidator validator = new PhoneNumberValidator(); private String expectedPhoneNumber; private String inputPhoneNumber; diff --git a/src/test/java/biz/nynja/account/components/PhoneNumberValidatorTests.java b/src/test/java/biz/nynja/account/components/PhoneNumberValidatorTests.java new file mode 100644 index 0000000..1536aae --- /dev/null +++ b/src/test/java/biz/nynja/account/components/PhoneNumberValidatorTests.java @@ -0,0 +1,126 @@ +/** + * Copyright (C) 2018 Nynja Inc. All rights reserved. + */ + +package biz.nynja.account.components; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +import biz.nynja.account.phone.PhoneNumberValidator; +import biz.nynja.account.repositories.AccountRepositoryAdditional; + +/** + * Components unit tests. + */ + +@RunWith(SpringRunner.class) +@ContextConfiguration(classes = { PhoneNumberValidator.class }) +public class PhoneNumberValidatorTests { + + @Autowired + @Qualifier("phoneNumberValidator") + private PhoneNumberValidator phoneNumberValidator; + + @MockBean + private AccountRepositoryAdditional accountRepositoryAdditional; + + @Test + public void validPhoneNumberTest() { + + String phoneNumber = "+359887434646"; + String countryCode = "BG"; + boolean isValid = phoneNumberValidator.isPhoneNumberValid(phoneNumber, countryCode); + assertTrue(String.format("Phone number: '%s' should be valid for country '%s'", phoneNumber, countryCode), + isValid == true); + + } + + @Test + public void invalidPhoneNumberTest() { + + String phoneNumber = "+357887434646"; + String countryCode = "BG"; + boolean isValid = phoneNumberValidator.isPhoneNumberValid(phoneNumber, countryCode); + assertFalse(String.format("Phone number: '%s' should be invalid for country '%s'", phoneNumber, countryCode), + isValid == true); + + } + + @Test + public void validNormalizedPhoneNumberTest1() { + + String expectedPhoneNumber = "359887345234"; + String inputPhoneNumber = "BG:+359887345234"; + String normalizedPhoneNumber = phoneNumberValidator.getNormalizedPhoneNumber(inputPhoneNumber); + assertEquals( + String.format("Phone number: '%s' should be normalized to '%s'", inputPhoneNumber, expectedPhoneNumber), + expectedPhoneNumber, normalizedPhoneNumber); + } + + @Test + public void validNormalizedPhoneNumberTest2() { + + String expectedPhoneNumber = "359887345234"; + String inputPhoneNumber = "BG:00359887345234"; + String normalizedPhoneNumber = phoneNumberValidator.getNormalizedPhoneNumber(inputPhoneNumber); + assertEquals( + String.format("Phone number: '%s' should be normalized to '%s'", inputPhoneNumber, expectedPhoneNumber), + expectedPhoneNumber, normalizedPhoneNumber); + } + + @Test + public void validNormalizedPhoneNumberTest3() { + + String expectedPhoneNumber = "359887345234"; + String inputPhoneNumber = "BG:359-887-345-234"; + String normalizedPhoneNumber = phoneNumberValidator.getNormalizedPhoneNumber(inputPhoneNumber); + assertEquals( + String.format("Phone number: '%s' should be normalized to '%s'", inputPhoneNumber, expectedPhoneNumber), + expectedPhoneNumber, normalizedPhoneNumber); + } + + @Test + public void validNormalizedPhoneNumberTest4() { + + String expectedPhoneNumber = "359887345234"; + String inputPhoneNumber = "BG:359 887 345 234"; + String normalizedPhoneNumber = phoneNumberValidator.getNormalizedPhoneNumber(inputPhoneNumber); + assertEquals( + String.format("Phone number: '%s' should be normalized to '%s'", inputPhoneNumber, expectedPhoneNumber), + expectedPhoneNumber, normalizedPhoneNumber); + } + + @Test + public void invalidNormalizedPhoneNumberTest1() { + + String expectedPhoneNumber = "359887345234"; + String inputPhoneNumber = "BG:359887345234567"; + String normalizedPhoneNumber = phoneNumberValidator.getNormalizedPhoneNumber(inputPhoneNumber); + assertNotEquals( + String.format("Phone number: '%s' should be normalized to '%s'", inputPhoneNumber, expectedPhoneNumber), + expectedPhoneNumber, normalizedPhoneNumber); + } + + @Test + public void invalidNormalizedPhoneNumberTest2() { + + String expectedPhoneNumber = "359887345234"; + String inputPhoneNumber = "BG:35988734523"; + String normalizedPhoneNumber = phoneNumberValidator.getNormalizedPhoneNumber(inputPhoneNumber); + assertNotEquals( + String.format("Phone number: '%s' should be normalized to '%s'", inputPhoneNumber, expectedPhoneNumber), + expectedPhoneNumber, normalizedPhoneNumber); + } +} diff --git a/src/test/java/biz/nynja/account/components/ValidatorTests.java b/src/test/java/biz/nynja/account/components/ValidatorTests.java index 008f3b1..932b69e 100644 --- a/src/test/java/biz/nynja/account/components/ValidatorTests.java +++ b/src/test/java/biz/nynja/account/components/ValidatorTests.java @@ -13,6 +13,7 @@ import static org.junit.Assert.assertTrue; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; @@ -22,6 +23,7 @@ import biz.nynja.account.grpc.AuthenticationType; import biz.nynja.account.grpc.CompletePendingAccountCreationRequest; import biz.nynja.account.grpc.CreatePendingAccountRequest; import biz.nynja.account.grpc.ErrorResponse.Cause; +import biz.nynja.account.phone.PhoneNumberValidator; import biz.nynja.account.repositories.AccountRepositoryAdditional; import biz.nynja.account.utils.Util; @@ -30,98 +32,15 @@ import biz.nynja.account.utils.Util; */ @RunWith(SpringRunner.class) -@ContextConfiguration(classes = { Validator.class }) +@ContextConfiguration(classes = { Validator.class, PhoneNumberValidator.class }) public class ValidatorTests { @Autowired + @Qualifier("validator") private Validator validator; @MockBean private AccountRepositoryAdditional accountRepositoryAdditional; - - @Test - public void validPhoneNumberTest() { - - String phoneNumber = "+359887434646"; - String countryCode = "BG"; - boolean isValid = validator.isPhoneNumberValid(phoneNumber, countryCode); - assertTrue(String.format("Phone number: '%s' should be valid for country '%s'", phoneNumber, countryCode), - isValid == true); - - } - - @Test - public void invalidPhoneNumberTest() { - - String phoneNumber = "+357887434646"; - String countryCode = "BG"; - boolean isValid = validator.isPhoneNumberValid(phoneNumber, countryCode); - assertFalse(String.format("Phone number: '%s' should be invalid for country '%s'", phoneNumber, countryCode), - isValid == true); - - } - - @Test - public void validNormalizedPhoneNumberTest1() { - - String expectedPhoneNumber = "359887345234"; - String inputPhoneNumber = "BG:+359887345234"; - String normalizedPhoneNumber = validator.getNormalizedPhoneNumber(inputPhoneNumber); - assertEquals(String.format("Phone number: '%s' should be normalized to '%s'", inputPhoneNumber, expectedPhoneNumber), - expectedPhoneNumber, normalizedPhoneNumber); - } - - @Test - public void validNormalizedPhoneNumberTest2() { - - String expectedPhoneNumber = "359887345234"; - String inputPhoneNumber = "BG:00359887345234"; - String normalizedPhoneNumber = validator.getNormalizedPhoneNumber(inputPhoneNumber); - assertEquals(String.format("Phone number: '%s' should be normalized to '%s'", inputPhoneNumber, expectedPhoneNumber), - expectedPhoneNumber, normalizedPhoneNumber); - } - - @Test - public void validNormalizedPhoneNumberTest3() { - - String expectedPhoneNumber = "359887345234"; - String inputPhoneNumber = "BG:359-887-345-234"; - String normalizedPhoneNumber = validator.getNormalizedPhoneNumber(inputPhoneNumber); - assertEquals(String.format("Phone number: '%s' should be normalized to '%s'", inputPhoneNumber, expectedPhoneNumber), - expectedPhoneNumber, normalizedPhoneNumber); - } - - @Test - public void validNormalizedPhoneNumberTest4() { - - String expectedPhoneNumber = "359887345234"; - String inputPhoneNumber = "BG:359 887 345 234"; - String normalizedPhoneNumber = validator.getNormalizedPhoneNumber(inputPhoneNumber); - assertEquals(String.format("Phone number: '%s' should be normalized to '%s'", inputPhoneNumber, expectedPhoneNumber), - expectedPhoneNumber, normalizedPhoneNumber); - } - - @Test - public void invalidNormalizedPhoneNumberTest1() { - - String expectedPhoneNumber = "359887345234"; - String inputPhoneNumber = "BG:359887345234567"; - String normalizedPhoneNumber = validator.getNormalizedPhoneNumber(inputPhoneNumber); - assertNotEquals(String.format("Phone number: '%s' should be normalized to '%s'", inputPhoneNumber, expectedPhoneNumber), - expectedPhoneNumber, normalizedPhoneNumber); - } - - @Test - public void invalidNormalizedPhoneNumberTest2() { - - String expectedPhoneNumber = "359887345234"; - String inputPhoneNumber = "BG:35988734523"; - String normalizedPhoneNumber = validator.getNormalizedPhoneNumber(inputPhoneNumber); - assertNotEquals(String.format("Phone number: '%s' should be normalized to '%s'", inputPhoneNumber, expectedPhoneNumber), - expectedPhoneNumber, normalizedPhoneNumber); - } - - @Test public void validUsernameTest() { diff --git a/src/test/java/biz/nynja/account/services/AccountServiceTests.java b/src/test/java/biz/nynja/account/services/AccountServiceTests.java index 47e0132..10466dc 100644 --- a/src/test/java/biz/nynja/account/services/AccountServiceTests.java +++ b/src/test/java/biz/nynja/account/services/AccountServiceTests.java @@ -15,6 +15,7 @@ import java.util.List; import java.util.Optional; import java.util.UUID; import java.util.concurrent.ExecutionException; +import java.util.stream.Collectors; import org.junit.Test; import org.junit.runner.RunWith; @@ -33,9 +34,11 @@ import biz.nynja.account.components.PreparedStatementsCache; import biz.nynja.account.configurations.CassandraTestsConfig; import biz.nynja.account.grpc.AccountByAccountIdRequest; import biz.nynja.account.grpc.AccountByAuthenticationProviderRequest; +import biz.nynja.account.grpc.AccountDetails; import biz.nynja.account.grpc.AccountResponse; import biz.nynja.account.grpc.AccountServiceGrpc; import biz.nynja.account.grpc.AccountsByProfileIdRequest; +import biz.nynja.account.grpc.AccountsList; import biz.nynja.account.grpc.AccountsResponse; import biz.nynja.account.grpc.AddAuthenticationProviderRequest; import biz.nynja.account.grpc.AddContactInfoRequest; @@ -55,6 +58,7 @@ import biz.nynja.account.grpc.EditContactInfoRequest; import biz.nynja.account.grpc.ErrorResponse.Cause; import biz.nynja.account.grpc.ProfileResponse; import biz.nynja.account.grpc.Role; +import biz.nynja.account.grpc.GetByUsernameRequest; import biz.nynja.account.grpc.StatusResponse; import biz.nynja.account.grpc.UpdateAccountRequest; import biz.nynja.account.grpc.UpdateProfileRequest; @@ -78,12 +82,12 @@ import biz.nynja.account.repositories.AccountRepositoryAdditional; import biz.nynja.account.repositories.PendingAccountRepository; import biz.nynja.account.repositories.ProfileByAuthenticationProviderRepository; import biz.nynja.account.repositories.ProfileRepository; +import biz.nynja.account.services.decomposition.AccountsProvider; import biz.nynja.account.utils.GrpcServerTestBase; import biz.nynja.account.utils.Util; -import biz.nynja.account.grpc.SearchByQrCodeRequest; -import biz.nynja.account.grpc.SearchByEmailRequest; -import biz.nynja.account.grpc.SearchByPhoneNumberRequest; -import biz.nynja.account.grpc.SearchByUsernameRequest; +import biz.nynja.account.grpc.GetByQrCodeRequest; +import biz.nynja.account.grpc.GetByEmailRequest; +import biz.nynja.account.grpc.GetByPhoneNumberRequest; import biz.nynja.account.grpc.SearchResponse; /** @@ -203,6 +207,9 @@ public class AccountServiceTests extends GrpcServerTestBase { @MockBean private AccountByUsernameRepository accountByUsernameRepository; + + @MockBean + private AccountsProvider accountsProvider; @Test public void testGetAccountByAccountId() throws ExecutionException, InterruptedException { @@ -210,8 +217,9 @@ public class AccountServiceTests extends GrpcServerTestBase { .setAccountId(Util.ACCOUNT_ID.toString()).build(); Account account = savedAccount; - - given(accountRepository.findByAccountId(UUID.fromString(request.getAccountId()))).willReturn(account); + AccountResponse response = AccountResponse.newBuilder().setAccountDetails(account.toProto()).build(); + Optional accountResponse = Optional.of(response); + given(accountsProvider.getAccountByAccountId(request)).willReturn(accountResponse); final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); @@ -264,9 +272,14 @@ public class AccountServiceTests extends GrpcServerTestBase { List accountByProfileId = new ArrayList<>(); accountByProfileId.add(savedAccountByProfileId); + + List responseList = accountByProfileId.stream().map(AccountByProfileId::toProto).collect(Collectors.toList()); - given(accountByProffileIdRepository.findAllByProfileId(UUID.fromString(request.getProfileId()))) - .willReturn(accountByProfileId); + AccountsResponse aResponse = AccountsResponse.newBuilder() + .setAccountsResponse(AccountsList.newBuilder().addAllAccountDetails(responseList)).build(); + Optional response = Optional.of(aResponse); + given(accountsProvider.getAllAccountsByProfileId(request)) + .willReturn(response); final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); @@ -317,12 +330,11 @@ public class AccountServiceTests extends GrpcServerTestBase { .setAuthenticationIdentifier(Util.PHONE_PROVIDER).setAuthenticationType(AuthenticationType.PHONE) .build(); - List accList = new ArrayList<>(); - accList.add(accountByPhone); - - given(accountByAuthenticationProviderRepository.findAllByAuthenticationProvider(Util.PHONE_PROVIDER)) - .willReturn(accList); - given(util.getAccountByAuthenticationProviderHelper(Util.PHONE_PROVIDER, "PHONE")).willReturn(phoneAccount); + AccountResponse response = AccountResponse.newBuilder().setAccountDetails(accountByPhone.toProto()).build(); + Optional accountResponse = Optional.of(response); + + given(accountsProvider.getAccountResponseByAuthenticationProvider(AuthenticationType.PHONE, + Util.PHONE_PROVIDER)).willReturn(accountResponse); final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); @@ -331,7 +343,7 @@ public class AccountServiceTests extends GrpcServerTestBase { assertTrue( String.format("Reply should contain authentication provider '%s'", request.getAuthenticationIdentifier()), - reply.getAccountDetails().getAuthenticationIdentifier().equals(Util.PHONE_PROVIDER)); + reply.getAccountDetails().getAuthenticationIdentifier().equals(Util.PHONE_NUMBER)); assertTrue(String.format("Reply should contain authentication type '%s'", AuthenticationType.PHONE.name()), reply.getAccountDetails().getAuthenticationType().equals(AuthenticationType.PHONE.name())); } @@ -773,8 +785,8 @@ public class AccountServiceTests extends GrpcServerTestBase { given(profileRepository.findByProfileId(Util.PROFILE_ID)).willReturn(profile2AuthProviders); - given(profileByAutheticationProviderRepository - .findByAuthenticationProviderAndAuthenticationProviderType(Util.PHONE_PROVIDER, "PHONE")) + given(profileByAutheticationProviderRepository.findByAuthenticationProviderAndAuthenticationProviderType( + Util.PHONE_NUMBER_STRIAGHT, AuthenticationType.PHONE.name())) .willReturn(profileByAuthenticationProvider); final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc @@ -1455,7 +1467,7 @@ public class AccountServiceTests extends GrpcServerTestBase { } public void testSearchByUsername() throws ExecutionException, InterruptedException { - final SearchByUsernameRequest request = SearchByUsernameRequest.newBuilder() + final GetByUsernameRequest request = GetByUsernameRequest.newBuilder() .setUsername(Util.S_USERNAME).build(); AccountByUsername response = savedResponse; @@ -1474,7 +1486,7 @@ public class AccountServiceTests extends GrpcServerTestBase { @Test public void testSearchByUsernameNotFound() throws ExecutionException, InterruptedException { - final SearchByUsernameRequest request = SearchByUsernameRequest.newBuilder() + final GetByUsernameRequest request = GetByUsernameRequest.newBuilder() .setUsername(Util.S_USERNAME).build(); AccountByUsername response = null; @@ -1493,7 +1505,7 @@ public class AccountServiceTests extends GrpcServerTestBase { @Test public void testSearchByUsernameBadRequest() throws ExecutionException, InterruptedException { - final SearchByUsernameRequest request = SearchByUsernameRequest.newBuilder().build(); + final GetByUsernameRequest request = GetByUsernameRequest.newBuilder().build(); final AccountServiceGrpc.AccountServiceBlockingStub searchServiceBlockingStub = AccountServiceGrpc .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); @@ -1501,13 +1513,13 @@ public class AccountServiceTests extends GrpcServerTestBase { final SearchResponse reply = searchServiceBlockingStub.searchByUsername(request); assertNotNull("Reply should not be null", reply); - assertTrue(String.format("Reply should contain cause '%s'", Cause.MISSING_USERNAME), - reply.getError().getCause().equals(Cause.MISSING_USERNAME)); + assertTrue(String.format("Reply should contain cause '%s'", Cause.MULTIPLE_INVALID_PARAMETERS), + reply.getError().getCause().equals(Cause.MULTIPLE_INVALID_PARAMETERS)); } @Test public void testSearchByUsernameInvalid() { - final SearchByUsernameRequest request = SearchByUsernameRequest.newBuilder() + final GetByUsernameRequest request = GetByUsernameRequest.newBuilder() .setUsername(Util.S_INVALID_USERNAME).build(); final AccountServiceGrpc.AccountServiceBlockingStub searchServiceBlockingStub = AccountServiceGrpc @@ -1522,13 +1534,12 @@ public class AccountServiceTests extends GrpcServerTestBase { @Test public void testSearchByPhoneNumber() throws ExecutionException, InterruptedException { - final SearchByPhoneNumberRequest request = SearchByPhoneNumberRequest.newBuilder() + final GetByPhoneNumberRequest request = GetByPhoneNumberRequest.newBuilder() .setPhoneNumber(Util.S_PHONE_NUMBER).build(); - List response = new LinkedList<>(); - response.add(savedResponseProvider); - - given(accountByAuthenticationProviderRepository.findAllByAuthenticationProvider(request.getPhoneNumber())).willReturn(response); + Optional response = Optional.of(savedAccount); + + given(accountsProvider.getAccountByAuthenticationProvider(AuthenticationType.PHONE, request.getPhoneNumber())).willReturn(response); final AccountServiceGrpc.AccountServiceBlockingStub searchServiceBlockingStub = AccountServiceGrpc .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); @@ -1536,13 +1547,13 @@ public class AccountServiceTests extends GrpcServerTestBase { final SearchResponse reply = searchServiceBlockingStub.searchByPhoneNumber(request); assertNotNull("Reply should not be null", reply); - assertTrue(String.format("Reply should contain last name '%s'", Util.S_LAST_NAME.toString()), - reply.getSearchResultDetails().getLastName().equals(Util.S_LAST_NAME.toString())); + assertTrue(String.format("Reply should contain last name '%s'", savedAccount.getFirstName()), + reply.getSearchResultDetails().getLastName().equals(savedAccount.getLastName())); } @Test public void testSearchByPhoneNumberNotFound() throws ExecutionException, InterruptedException { - final SearchByPhoneNumberRequest request = SearchByPhoneNumberRequest.newBuilder() + final GetByPhoneNumberRequest request = GetByPhoneNumberRequest.newBuilder() .setPhoneNumber(Util.S_PHONE_NUMBER).build(); List response = new LinkedList<>(); @@ -1561,7 +1572,7 @@ public class AccountServiceTests extends GrpcServerTestBase { @Test public void testSearchByPhoneNumberBadRequest() throws ExecutionException, InterruptedException { - final SearchByPhoneNumberRequest request = SearchByPhoneNumberRequest.newBuilder().build(); + final GetByPhoneNumberRequest request = GetByPhoneNumberRequest.newBuilder().build(); final AccountServiceGrpc.AccountServiceBlockingStub searchServiceBlockingStub = AccountServiceGrpc .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); @@ -1575,7 +1586,7 @@ public class AccountServiceTests extends GrpcServerTestBase { @Test public void testSearchByPhoneNumberInvalid() { - final SearchByPhoneNumberRequest request = SearchByPhoneNumberRequest.newBuilder() + final GetByPhoneNumberRequest request = GetByPhoneNumberRequest.newBuilder() .setPhoneNumber(Util.S_INVALID_PHONENUMBER).build(); final AccountServiceGrpc.AccountServiceBlockingStub searchServiceBlockingStub = AccountServiceGrpc @@ -1590,13 +1601,12 @@ public class AccountServiceTests extends GrpcServerTestBase { @Test public void testSearchByEmail() throws ExecutionException, InterruptedException { - final SearchByEmailRequest request = SearchByEmailRequest.newBuilder() + final GetByEmailRequest request = GetByEmailRequest.newBuilder() .setEmail(Util.S_EMAIL).build(); - List response = new LinkedList<>(); - response.add(savedResponseProvider); - - given(accountByAuthenticationProviderRepository.findAllByAuthenticationProvider(request.getEmail())).willReturn(response); + Optional response = Optional.of(savedAccount); + + given(accountsProvider.getAccountByAuthenticationProvider(AuthenticationType.EMAIL, request.getEmail())).willReturn(response); final AccountServiceGrpc.AccountServiceBlockingStub searchServiceBlockingStub = AccountServiceGrpc .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); @@ -1604,13 +1614,13 @@ public class AccountServiceTests extends GrpcServerTestBase { final SearchResponse reply = searchServiceBlockingStub.searchByEmail(request); assertNotNull("Reply should not be null", reply); - assertTrue(String.format("Reply should contain last name '%s'", Util.S_LAST_NAME.toString()), - reply.getSearchResultDetails().getLastName().equals(Util.S_LAST_NAME.toString())); + assertTrue(String.format("Reply should contain last name '%s'", savedAccount.getFirstName()), + reply.getSearchResultDetails().getLastName().equals(savedAccount.getLastName())); } @Test public void testSearchByEmailNotFound() throws ExecutionException, InterruptedException { - final SearchByEmailRequest request = SearchByEmailRequest.newBuilder() + final GetByEmailRequest request = GetByEmailRequest.newBuilder() .setEmail(Util.S_EMAIL).build(); List response = new LinkedList<>(); @@ -1629,7 +1639,7 @@ public class AccountServiceTests extends GrpcServerTestBase { @Test public void testSearchByEmailBadRequest() throws ExecutionException, InterruptedException { - final SearchByEmailRequest request = SearchByEmailRequest.newBuilder().build(); + final GetByEmailRequest request = GetByEmailRequest.newBuilder().build(); final AccountServiceGrpc.AccountServiceBlockingStub searchServiceBlockingStub = AccountServiceGrpc .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); @@ -1643,7 +1653,7 @@ public class AccountServiceTests extends GrpcServerTestBase { @Test public void testSearchByEmailInvalid() { - final SearchByEmailRequest request = SearchByEmailRequest.newBuilder() + final GetByEmailRequest request = GetByEmailRequest.newBuilder() .setEmail(Util.S_INVALID_EMAIL).build(); final AccountServiceGrpc.AccountServiceBlockingStub searchServiceBlockingStub = AccountServiceGrpc @@ -1658,7 +1668,7 @@ public class AccountServiceTests extends GrpcServerTestBase { @Test public void testSearchByQrCode() throws ExecutionException, InterruptedException { - final SearchByQrCodeRequest request = SearchByQrCodeRequest.newBuilder() + final GetByQrCodeRequest request = GetByQrCodeRequest.newBuilder() .setQrCode(Util.S_QR_CODE).build(); AccountByQrCode response = savedResponseQrCode; @@ -1677,7 +1687,7 @@ public class AccountServiceTests extends GrpcServerTestBase { @Test public void testSearchByQrCodeNotFound() throws ExecutionException, InterruptedException { - final SearchByQrCodeRequest request = SearchByQrCodeRequest.newBuilder() + final GetByQrCodeRequest request = GetByQrCodeRequest.newBuilder() .setQrCode(Util.S_QR_CODE).build(); AccountByQrCode response = null; @@ -1696,7 +1706,7 @@ public class AccountServiceTests extends GrpcServerTestBase { @Test public void testSearchByQrCodeBadRequest() throws ExecutionException, InterruptedException { - final SearchByQrCodeRequest request = SearchByQrCodeRequest.newBuilder().build(); + final GetByQrCodeRequest request = GetByQrCodeRequest.newBuilder().build(); final AccountServiceGrpc.AccountServiceBlockingStub searchServiceBlockingStub = AccountServiceGrpc .newBlockingStub(Optional.ofNullable(channel).orElse(inProcChannel)); diff --git a/src/test/java/biz/nynja/account/utils/Util.java b/src/test/java/biz/nynja/account/utils/Util.java index 1fc500e..655dd02 100644 --- a/src/test/java/biz/nynja/account/utils/Util.java +++ b/src/test/java/biz/nynja/account/utils/Util.java @@ -62,6 +62,7 @@ public class Util { public static final LocalDate BIRTHDAY = LocalDate.of(1990, 9, 16); public static final String MIDDLE_NAME = "Kass"; public static final String PHONE_NUMBER = "+359887123456"; + public static final String PHONE_NUMBER_STRIAGHT = "359887123456"; public static final String PHONE_PROVIDER = "BG:+359887123456"; public static final String PHONE_PROVIDER_EDITED = "BG:+359887111111"; public static final String INVALID_PHONE_PROVIDER = "BG:+3"; @@ -71,7 +72,7 @@ public class Util { public static final String GOOGLEPLUS_TYPE = "GOOGLEPLUS"; public static final String S_USERNAME = "TomJohns"; - public static final String S_PHONE_NUMBER = "448873598834"; + public static final String S_PHONE_NUMBER = "359878123456"; public static final String S_EMAIL = "p_petrov@abv.bg"; public static final String S_QR_CODE = "QRcoded"; public static final String S_INVALID_USERNAME = "Tom-Johns"; -- GitLab From fb50d75c46e1eb1ce4334c335b8fa4a9e9a17b97 Mon Sep 17 00:00:00 2001 From: Stoyan Hristov Date: Mon, 5 Nov 2018 18:03:01 +0200 Subject: [PATCH 7/9] NY-3608 : add copyright message --- .../java/biz/nynja/account/phone/PhoneNumberValidator.java | 4 ++++ src/main/java/biz/nynja/account/validation/Validation.java | 3 +++ .../java/biz/nynja/account/validation/ValidationError.java | 3 +++ 3 files changed, 10 insertions(+) diff --git a/src/main/java/biz/nynja/account/phone/PhoneNumberValidator.java b/src/main/java/biz/nynja/account/phone/PhoneNumberValidator.java index 8069be8..5c535a9 100644 --- a/src/main/java/biz/nynja/account/phone/PhoneNumberValidator.java +++ b/src/main/java/biz/nynja/account/phone/PhoneNumberValidator.java @@ -1,3 +1,7 @@ +/** + * Copyright (C) 2018 Nynja Inc. All rights reserved. + */ + package biz.nynja.account.phone; import java.io.BufferedReader; diff --git a/src/main/java/biz/nynja/account/validation/Validation.java b/src/main/java/biz/nynja/account/validation/Validation.java index 4c57db1..9ae0982 100644 --- a/src/main/java/biz/nynja/account/validation/Validation.java +++ b/src/main/java/biz/nynja/account/validation/Validation.java @@ -1,3 +1,6 @@ +/** + * Copyright (C) 2018 Nynja Inc. All rights reserved. + */ package biz.nynja.account.validation; import java.util.LinkedList; diff --git a/src/main/java/biz/nynja/account/validation/ValidationError.java b/src/main/java/biz/nynja/account/validation/ValidationError.java index 9ed8012..f9bcaae 100644 --- a/src/main/java/biz/nynja/account/validation/ValidationError.java +++ b/src/main/java/biz/nynja/account/validation/ValidationError.java @@ -1,3 +1,6 @@ +/** + * Copyright (C) 2018 Nynja Inc. All rights reserved. + */ package biz.nynja.account.validation; import biz.nynja.account.grpc.ErrorResponse.Cause; -- GitLab From 842615717883e1db8e1228857e2e655808de8500 Mon Sep 17 00:00:00 2001 From: Stoyan Hristov Date: Tue, 6 Nov 2018 12:01:48 +0200 Subject: [PATCH 8/9] NY 3607 : code review feedback --- pom.xml | 2 +- .../nynja/account/models/AccountByQrCode.java | 36 +++++------ .../account/services/AccountServiceImpl.java | 62 +++++++++---------- .../decomposition/AccountsProvider.java | 2 +- .../account/services/AccountServiceTests.java | 10 +-- .../java/biz/nynja/account/utils/Util.java | 2 +- 6 files changed, 54 insertions(+), 60 deletions(-) diff --git a/pom.xml b/pom.xml index 9ac7f5c..ad665e6 100644 --- a/pom.xml +++ b/pom.xml @@ -101,7 +101,7 @@ libs-snapshot-local.biz.nynja.protos - account-service-ny-3607-search-users-by-attributes + account-service-intracoldev 1.0-SNAPSHOT diff --git a/src/main/java/biz/nynja/account/models/AccountByQrCode.java b/src/main/java/biz/nynja/account/models/AccountByQrCode.java index 0100f4d..f80d84f 100644 --- a/src/main/java/biz/nynja/account/models/AccountByQrCode.java +++ b/src/main/java/biz/nynja/account/models/AccountByQrCode.java @@ -28,7 +28,7 @@ public class AccountByQrCode { private Long lastUpdateTimestamp; private Set contactsInfo; private String qrCode; - private String accessStatus; + private String accessStatus; private Set roles; public UUID getProfileId() { @@ -150,15 +150,14 @@ public class AccountByQrCode { public void setQrCode(String qrCode) { this.qrCode = qrCode; } - - public Set getRoles() { - return roles; - } + public Set getRoles() { + return roles; + } - public void setRoles(Set roles) { - this.roles = roles; - } + public void setRoles(Set roles) { + this.roles = roles; + } @Override public int hashCode() { @@ -277,22 +276,17 @@ public class AccountByQrCode { @Override public String toString() { - return new StringBuilder("Account [accountId=").append(accountId).append(", profileId=").append(profileId) - .append(", accountMark=").append(accountMark).append(", authenticationProvider=") + return new StringBuilder("AccountByQrCode [accountId=").append(accountId).append(", profileId=") + .append(profileId).append(", accountMark=").append(accountMark).append(", authenticationProvider=") .append(authenticationProvider).append(", authenticationProviderType=") .append(authenticationProviderType).append(", firstName=").append(firstName).append(", lastName=") .append(lastName).append(", avatar=").append(avatar).append(", accountName=").append(accountName) - .append(", username=").append(username).append(", accountStatus=").append(accessStatus) - .append(", creationTimestamp=").append(creationTimestamp) - .append(", lastUpdateTimestamp=").append(lastUpdateTimestamp) - .append(", qrCode=").append(qrCode) - .append(", contactsInfo=").append(contactsInfo) - .append(", roles=").append(roles) - .append("]").toString(); - } - - - + .append(", username=").append(username).append(", accessStatus=").append(accessStatus) + .append(", creationTimestamp=").append(creationTimestamp).append(", lastUpdateTimestamp=") + .append(lastUpdateTimestamp).append(", qrCode=").append(qrCode).append(", contactsInfo=") + .append(contactsInfo).append(", roles=").append(roles).append("]").toString(); + } + public AccountDetails toProto() { Builder builder = AccountDetails.newBuilder(); diff --git a/src/main/java/biz/nynja/account/services/AccountServiceImpl.java b/src/main/java/biz/nynja/account/services/AccountServiceImpl.java index ac61087..9f6ea47 100644 --- a/src/main/java/biz/nynja/account/services/AccountServiceImpl.java +++ b/src/main/java/biz/nynja/account/services/AccountServiceImpl.java @@ -32,19 +32,8 @@ import biz.nynja.account.validation.ValidationError; import biz.nynja.account.validation.Validation; import io.grpc.stub.StreamObserver; -import org.apache.commons.lang3.tuple.ImmutablePair; -import org.lognet.springboot.grpc.GRpcService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.nio.ByteBuffer; -import java.time.Instant; -import java.util.List; -import java.util.Optional; -import java.util.UUID; -//import static biz.nynja.account.grpc.ErrorResponse.Cause; -//import static biz.nynja.account.grpc.ErrorResponse.newBuilder; /** * gRPC Account service implementation.
* The service extends the protobuf generated class and overrides the needed methods. It also saves/retrieves the @@ -117,9 +106,11 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas if (!account.isPresent()) { sendErrorMessageForAccountResponse(responseObserver, Cause.ACCOUNT_NOT_FOUND); + return; } else { responseObserver.onNext(account.get()); responseObserver.onCompleted(); + return; } } @@ -132,7 +123,7 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas return; } if (!validator.isEmailValid(request.getEmail())) { - logAndBuildGrpcResponse(responseObserver, new ValidationError("Invalid e-mail!. Value : " + request.getEmail(), Cause.INVALID_EMAIL)); + logAndBuildGrpcResponse(responseObserver, new ValidationError("Invalid e-mail!. Value : " + request.getEmail(), Cause.EMAIL_INVALID)); return; } @@ -144,13 +135,14 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas Cause.EMAIL_NOT_FOUND)); return; } else { - SearchResultDetails searchResultDetails = buildSearchResultDetails(account.get().getAvatar(), - account.get().getFirstName(), account.get().getLastName()); + SearchResultDetails searchResultDetails = buildSearchResultDetails(account.get().getAccountId().toString(), + account.get().getAvatar(), account.get().getFirstName(), account.get().getLastName()); SearchResponse response = SearchResponse.newBuilder().setSearchResultDetails(searchResultDetails).build(); logger.debug("Found result for account by e-mail {}: \"{}\"", request.getEmail(), response); responseObserver.onNext(response); responseObserver.onCompleted(); + return; } } @@ -176,13 +168,14 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas "No matching accounts found for phone:" + request.getPhoneNumber(), Cause.PHONENUMBER_NOT_FOUND)); return; } else { - SearchResultDetails searchResultDetails = buildSearchResultDetails(account.get().getAvatar(), - account.get().getFirstName(), account.get().getLastName()); + SearchResultDetails searchResultDetails = buildSearchResultDetails(account.get().getAccountId().toString(), + account.get().getAvatar(), account.get().getFirstName(), account.get().getLastName()); SearchResponse response = SearchResponse.newBuilder().setSearchResultDetails(searchResultDetails).build(); logger.debug("Found result for account by phone {}: \"{}\"", request.getPhoneNumber(), response); responseObserver.onNext(response); responseObserver.onCompleted(); + return; } } @@ -196,6 +189,7 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas .setError(ErrorResponse.newBuilder().setMessage(validation.getErrorMessage()) .setCause(validation.getCause().get())).build()); responseObserver.onCompleted(); + return; } Optional accountResonse = @@ -203,9 +197,11 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas if (!accountResonse.isPresent()) { sendErrorMessageForAccountResponse(responseObserver, Cause.ACCOUNT_NOT_FOUND); + return; } else { responseObserver.onNext(accountResonse.get()); responseObserver.onCompleted(); + return; } } @@ -215,6 +211,7 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas Validation validation = validateGetByUsernameRequest(request); if(validation.hasErrors()) { logAndBuildGrpcResponse(responseObserver, validation); + return; } AccountByUsername account = accountByUsernameRepository.findByUsername(request.getUsername()); @@ -224,8 +221,8 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas return; } - SearchResultDetails searchResultDetails = buildSearchResultDetails(account.getAvatar(), account.getFirstName(), - account.getLastName()); + SearchResultDetails searchResultDetails = buildSearchResultDetails(account.getAccountId().toString(), + account.getAvatar(), account.getFirstName(), account.getLastName()); SearchResponse response = SearchResponse.newBuilder().setSearchResultDetails(searchResultDetails).build(); logger.debug("Found result for account by username {}: \"{}\"", request.getUsername(), response); @@ -235,18 +232,19 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas return; } - private Validation validateGetByUsernameRequest(GetByUsernameRequest request) { - Validation validation = new Validation(); - + private Validation validateGetByUsernameRequest(GetByUsernameRequest request) { + Validation validation = new Validation(); + if ((request.getUsername() == null) || request.getUsername().isEmpty()) { - validation.addError(new ValidationError("Missing username.", Cause.MISSING_USERNAME)); + validation.addError(new ValidationError("Missing username.", Cause.MISSING_USERNAME)); } if (!validator.isValidUsername(request.getUsername())) { - validation.addError(new ValidationError("Invalid username. Value: " + request.getUsername(), Cause.INVALID_USERNAME)); + validation.addError( + new ValidationError("Invalid username. Value: " + request.getUsername(), Cause.USERNAME_INVALID)); } - + return validation; - } + } @Override public void getAccountByQrCode(GetByQrCodeRequest request, StreamObserver responseObserver) { @@ -265,16 +263,15 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas if (!accountResonse.isPresent()) { sendErrorMessageForAccountResponse(responseObserver, Cause.ACCOUNT_NOT_FOUND); + return; } else { responseObserver.onNext(accountResonse.get()); responseObserver.onCompleted(); + return; } } - - - @Override public void searchByQrCode(GetByQrCodeRequest request, StreamObserver responseObserver) { logger.info("Search account by QR code: {}", request.getQrCode()); @@ -290,8 +287,8 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas return; } - SearchResultDetails searchResultDetails = buildSearchResultDetails(account.getAvatar(), account.getFirstName(), - account.getLastName()); + SearchResultDetails searchResultDetails = buildSearchResultDetails(account.getAccountId().toString(), + account.getAvatar(), account.getFirstName(), account.getLastName()); SearchResponse response = SearchResponse.newBuilder().setSearchResultDetails(searchResultDetails).build(); logger.debug("Found result for account by QR code {}: \"{}\"", request.getQrCode(), response); @@ -322,6 +319,7 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas } else { responseObserver.onNext(accounts.get()); responseObserver.onCompleted(); + return; } } @@ -345,9 +343,11 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas if (!account.isPresent()) { sendErrorMessageForAccountResponse(responseObserver, Cause.ACCOUNT_NOT_FOUND); + return; } else { responseObserver.onNext(account.get()); responseObserver.onCompleted(); + return; } } @@ -883,7 +883,7 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas responseObserver.onCompleted(); } - private SearchResultDetails buildSearchResultDetails(ByteBuffer avatar, String firstName, String lastName) { + private SearchResultDetails buildSearchResultDetails(String id, ByteBuffer avatar, String firstName, String lastName) { SearchResultDetails.Builder searchResultDetails = SearchResultDetails.newBuilder(); searchResultDetails.setFirstName(firstName).setLastName(lastName); diff --git a/src/main/java/biz/nynja/account/services/decomposition/AccountsProvider.java b/src/main/java/biz/nynja/account/services/decomposition/AccountsProvider.java index 5bff256..66c1c67 100644 --- a/src/main/java/biz/nynja/account/services/decomposition/AccountsProvider.java +++ b/src/main/java/biz/nynja/account/services/decomposition/AccountsProvider.java @@ -112,7 +112,7 @@ public class AccountsProvider { public Optional getAccountByAccountId(AccountByAccountIdRequest request) { logger.info("Getting accounts by account id: {}", request.getAccountId()); Account account = accountRepository.findByAccountId(UUID.fromString(request.getAccountId())); - if (account.getAccountId() == null) { + if (account == null || account.getAccountId() == null) { return Optional.empty(); } AccountResponse response = AccountResponse.newBuilder().setAccountDetails(account.toProto()).build(); diff --git a/src/test/java/biz/nynja/account/services/AccountServiceTests.java b/src/test/java/biz/nynja/account/services/AccountServiceTests.java index 10466dc..7da8739 100644 --- a/src/test/java/biz/nynja/account/services/AccountServiceTests.java +++ b/src/test/java/biz/nynja/account/services/AccountServiceTests.java @@ -786,7 +786,7 @@ public class AccountServiceTests extends GrpcServerTestBase { given(profileRepository.findByProfileId(Util.PROFILE_ID)).willReturn(profile2AuthProviders); given(profileByAutheticationProviderRepository.findByAuthenticationProviderAndAuthenticationProviderType( - Util.PHONE_NUMBER_STRIAGHT, AuthenticationType.PHONE.name())) + Util.PHONE_NUMBER_STREIGHT, AuthenticationType.PHONE.name())) .willReturn(profileByAuthenticationProvider); final AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc @@ -1528,8 +1528,8 @@ public class AccountServiceTests extends GrpcServerTestBase { final SearchResponse reply = searchServiceBlockingStub.searchByUsername(request); assertNotNull("Reply should not be null", reply); - assertTrue(String.format("Reply should contain cause '%s'", Cause.INVALID_USERNAME), - reply.getError().getCause().equals(Cause.INVALID_USERNAME)); + assertTrue(String.format("Reply should contain cause '%s'", Cause.USERNAME_INVALID), + reply.getError().getCause().equals(Cause.USERNAME_INVALID)); } @Test @@ -1662,8 +1662,8 @@ public class AccountServiceTests extends GrpcServerTestBase { final SearchResponse reply = searchServiceBlockingStub.searchByEmail(request); assertNotNull("Reply should not be null", reply); - assertTrue(String.format("Reply should contain cause '%s'", Cause.INVALID_EMAIL), - reply.getError().getCause().equals(Cause.INVALID_EMAIL)); + assertTrue(String.format("Reply should contain cause '%s'", Cause.EMAIL_INVALID), + reply.getError().getCause().equals(Cause.EMAIL_INVALID)); } @Test diff --git a/src/test/java/biz/nynja/account/utils/Util.java b/src/test/java/biz/nynja/account/utils/Util.java index 655dd02..215476d 100644 --- a/src/test/java/biz/nynja/account/utils/Util.java +++ b/src/test/java/biz/nynja/account/utils/Util.java @@ -62,7 +62,7 @@ public class Util { public static final LocalDate BIRTHDAY = LocalDate.of(1990, 9, 16); public static final String MIDDLE_NAME = "Kass"; public static final String PHONE_NUMBER = "+359887123456"; - public static final String PHONE_NUMBER_STRIAGHT = "359887123456"; + public static final String PHONE_NUMBER_STREIGHT = "359887123456"; public static final String PHONE_PROVIDER = "BG:+359887123456"; public static final String PHONE_PROVIDER_EDITED = "BG:+359887111111"; public static final String INVALID_PHONE_PROVIDER = "BG:+3"; -- GitLab From 8c47baa0f46b073a2655312288b36d238b8505c2 Mon Sep 17 00:00:00 2001 From: Stoyan Hristov Date: Wed, 7 Nov 2018 15:07:33 +0200 Subject: [PATCH 9/9] NY3607: coordinate phone number validation --- .../phone/InvalidPhoneNumberException.java | 8 ++++ .../account/phone/PhoneNumberValidator.java | 43 +++++++++++-------- .../java/biz/nynja/account/utils/Util.java | 4 ++ 3 files changed, 38 insertions(+), 17 deletions(-) create mode 100644 src/main/java/biz/nynja/account/phone/InvalidPhoneNumberException.java diff --git a/src/main/java/biz/nynja/account/phone/InvalidPhoneNumberException.java b/src/main/java/biz/nynja/account/phone/InvalidPhoneNumberException.java new file mode 100644 index 0000000..51efe73 --- /dev/null +++ b/src/main/java/biz/nynja/account/phone/InvalidPhoneNumberException.java @@ -0,0 +1,8 @@ +package biz.nynja.account.phone; + +public class InvalidPhoneNumberException extends RuntimeException{ + + public InvalidPhoneNumberException(String msg) { + super(msg); + } +} diff --git a/src/main/java/biz/nynja/account/phone/PhoneNumberValidator.java b/src/main/java/biz/nynja/account/phone/PhoneNumberValidator.java index 5c535a9..125928a 100644 --- a/src/main/java/biz/nynja/account/phone/PhoneNumberValidator.java +++ b/src/main/java/biz/nynja/account/phone/PhoneNumberValidator.java @@ -132,9 +132,12 @@ public class PhoneNumberValidator { } phoneNumber = phoneNumber.replaceAll("^0*", "").replaceAll("[^\\d]", ""); - String countryCode = getCountryCode(phoneNumber); - - String countrySelector = getCountrySelector(countryCode); + String countrySelector; + try { + countrySelector = getCountrySelector(phoneNumber); + } catch (InvalidPhoneNumberException e) { + return false; + } if (!isPhoneNumberValid(phoneNumber, countrySelector)) { return false; @@ -147,7 +150,7 @@ public class PhoneNumberValidator { return true; } - public String getCountryCode(String phoneNumber) { + private String getCountryCode(String phoneNumber) { PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance(); try { @@ -155,20 +158,24 @@ public class PhoneNumberValidator { logger.debug("Country code found: {}", numberProto.getCountryCode()); return Integer.toString(numberProto.getCountryCode()); } catch (NumberParseException e) { - throw new InternalError(Cause.INVALID_PHONENUMBER.getValueDescriptor().toString(), - new InternalError("No country code found for phone number: " + phoneNumber)); + throw new InvalidPhoneNumberException("No country code found for phone number: " + phoneNumber); } - } - + } - public String getNormalizedPhoneNumber(String rawPhoneNumber) { + public String getNormalizedPhoneNumber(String rawPhoneNumber) throws InvalidPhoneNumberException { String[] provider = rawPhoneNumber.split(":"); - if (provider == null || provider.length < 2) { - throw new InternalError("Phone number with wrong format: " + rawPhoneNumber); + if (provider == null || provider.length > 2) { + throw new InvalidPhoneNumberException("Phone number with wrong format: " + rawPhoneNumber); + } + String country; + String phoneNumber; + if(provider.length == 1) { + country = getCountrySelector(provider[0]); + phoneNumber = provider[0]; + } else { + country = provider[0]; + phoneNumber = provider[1]; } - - String country = provider[0]; - String phoneNumber = provider[1]; logger.info("libphone: New phone number normalization request received - phone number: {}, country code: {}", phoneNumber, country); @@ -185,14 +192,16 @@ public class PhoneNumberValidator { return normalizedPhoneNumber; } - public String getCountrySelector(String countryCode) { + private String getCountrySelector(String phoneNumber) throws InvalidPhoneNumberException{ + String countryCode; + countryCode = getCountryCode(phoneNumber); + CountryInfo countryInfo = countryMapByCountryCode.get(countryCode); if (countryInfo != null) { return countryInfo.getCountryCode(); } else { logger.debug("Country selector not found in'countries.txt' for country code: {}", countryCode); - throw new InternalError(Cause.INVALID_PHONENUMBER.getValueDescriptor().toString(), - new InternalError("No country selector found in 'countries.txt' for country code: " + countryCode)); + throw new InvalidPhoneNumberException("No country found for code: " + countryCode); } } diff --git a/src/test/java/biz/nynja/account/utils/Util.java b/src/test/java/biz/nynja/account/utils/Util.java index 215476d..11d213e 100644 --- a/src/test/java/biz/nynja/account/utils/Util.java +++ b/src/test/java/biz/nynja/account/utils/Util.java @@ -282,6 +282,7 @@ public class Util { @Bean public AccountByUsername savedResponse() { AccountByUsername response = new AccountByUsername(); + response.setAccountId(Util.ACCOUNT_ID); response.setAvatar(ByteBuffer.wrap(S_AVATAR_STRING.getBytes())); response.setFirstName(Util.S_FIRST_NAME); response.setLastName(Util.S_LAST_NAME); @@ -291,6 +292,7 @@ public class Util { @Bean public AccountByAuthenticationProvider savedResponseProvider() { AccountByAuthenticationProvider response = new AccountByAuthenticationProvider(); + response.setAccountId(Util.ACCOUNT_ID); response.setAvatar(ByteBuffer.wrap(S_AVATAR_STRING.getBytes())); response.setFirstName(Util.S_FIRST_NAME); response.setLastName(Util.S_LAST_NAME); @@ -300,9 +302,11 @@ public class Util { @Bean public AccountByQrCode savedResponseQrCode() { AccountByQrCode response = new AccountByQrCode(); + response.setAccountId(Util.ACCOUNT_ID); response.setAvatar(ByteBuffer.wrap(S_AVATAR_STRING.getBytes())); response.setFirstName(Util.S_FIRST_NAME); response.setLastName(Util.S_LAST_NAME); + response.setQrCode(Util.S_QR_CODE); return response; } -- GitLab