get method Null safety

  1. @override
Future<AtValue> get(
  1. AtKey atKey,
  2. {bool isDedicated = false,
  3. GetRequestOptions? getRequestOptions}
)
override

Get the value of AtKey.key from user's cloud secondary if AtKey.sharedBy is set. Otherwise looks up the key from local secondary. If the key was stored with public access, set AtKey.metadata.isPublic to true. If the key was shared with another atSign set AtKey.sharedWith

e.g alice is current atsign
llookup:phone@alice
  var atKey = AtKey()..key='phone'
  get(atKey);
llookup:public:phone@alice
  var metaData = Metadata()..isPublic=true;
  var atKey = AtKey()..key='phone'
            ..metadata=metaData
  get(atKey);
lookup:phone@bob
  var metaData = Metadata()..sharedWith='@bob';
  var key = AtKey()..key='phone'
                  ..metadata=metaData
  get(key);
llookup:@alice:phone.persona@alice
  var key = AtKey()..key='phone'
            ..sharedWith='@alice'
  get(key);
llookup:@alice:phone@alice
  var metaData = Metadata()..namespaceAware=false
  var key = AtKey()..key='phone'
            ..sharedWith='@alice'
  get(key);

plookup public phone number of @bob
plookup:phone@bob
var metadata = Metadata()..isPublic=true;
var publicPhoneKey = AtKey()..key = 'phone'
                            ..sharedBy = '@bob'
                            ..metadata = metadata;
 get(publicPhoneKey);

@alice : update:@bob:phone.personal@alice
@bob   : lookup:phone.persona@alice
  var key = AtKey()..key='phone'
            ..sharedBy='@bob';
  get(key);

lookup:public:phone@alice
  var metaData = Metadata()..isPublic=true
                  ..namespaceAware='false'
  var key = AtKey()..key='phone'
            ..metadata=metaData
  get(key);

Throws AtKeyException for the invalid key formed

Throws AtDecryptionException if fails to decrypt the value

Throws AtPrivateKeyNotFoundException if the encryption private key is not found to decrypt the value

Throws AtPublicKeyChangeException if the encryption public key used encrypt the value is different from the current encryption public key(at the time of decryption)

Throws SharedKeyNotFoundException if the shared key to decrypt the value is not found

Throws SelfKeyNotFoundException if the self encryption key is not found.

Throws AtClientException if the cloud secondary is invalid or not reachable

Implementation

@override
Future<AtValue> get(AtKey atKey,
    {bool isDedicated = false, GetRequestOptions? getRequestOptions}) async {
  Secondary? secondary;
  try {
    // validate the get request.
    await AtClientValidation.validateAtKey(atKey);
    // Get the verb builder for the atKey
    var verbBuilder = GetRequestTransformer(this)
        .transform(atKey, requestOptions: getRequestOptions);
    // Execute the verb.
    secondary = SecondaryManager.getSecondary(verbBuilder);
    var getResponse = await secondary.executeVerb(verbBuilder);
    // Return empty value if getResponse is null.
    if (getResponse == null ||
        getResponse.isEmpty ||
        getResponse == 'data:null') {
      return AtValue();
    }
    // Send AtKey and AtResponse to transform the response to AtValue.
    var getResponseTuple = Tuple<AtKey, String>()
      ..one = atKey
      ..two = (getResponse);
    // Transform the response and return
    var atValue = await GetResponseTransformer().transform(getResponseTuple);
    return atValue;
  } on AtException catch (e) {
    var exceptionScenario = (secondary is LocalSecondary)
        ? ExceptionScenario.localVerbExecutionFailed
        : ExceptionScenario.remoteVerbExecutionFailed;
    e.stack(
        AtChainedException(Intent.fetchData, exceptionScenario, e.message));
    throw AtExceptionManager.createException(e);
  }
}