Skip to content

Commit

Permalink
Merge pull request #310 from 0xPolygonID/feature/remove-get-vocabs
Browse files Browse the repository at this point in the history
removed get Vocab method
  • Loading branch information
rauljareno authored May 22, 2023
2 parents 8f6631b + c4bca38 commit c0b00ed
Show file tree
Hide file tree
Showing 19 changed files with 1,701 additions and 1,581 deletions.
2,089 changes: 1,310 additions & 779 deletions coverage/lcov.info

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion example/lib/src/common/env.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ part 'env.g.dart';
@Envied()
abstract class Env {
@EnviedField(varName: 'ENV_POLYGON_MUMBAI')
static const polygonMumbai = _Env.polygonMumbai;
static const String polygonMumbai = _Env.polygonMumbai;
}
102 changes: 0 additions & 102 deletions example/lib/src/presentation/ui/claims/mappers/claim_model_mapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,108 +65,6 @@ class ClaimModelMapper implements FromMapper<ClaimEntity, ClaimModel> {
if (key != "id" && key != "type") {
String claimTitle = key;
String claimValue = value.toString();
if (from.vocab != null &&
from.vocab!.containsKey("properties") &&
(from.vocab!['properties'] as Map<String, dynamic>)
.containsKey(key)) {
Map<String, dynamic> vocabProperty =
(from.vocab!['properties'] as Map<String, dynamic>)[key];
if (vocabProperty.containsKey("display")) {
claimTitle = vocabProperty["display"];
}
if (vocabProperty.containsKey("anyOf")) {
List vocabValues = vocabProperty["anyOf"] as List;
for (Map<String, String> vocabValue in vocabValues) {
if (vocabValue["const"] == value.toString()) {
claimValue = '${vocabValue["const"]} - ${vocabValue["title"]}';
value = claimValue;
break;
}
}
} else if (vocabProperty.containsKey("format")) {
if (vocabProperty["format"] == "bool") {
claimValue = value == 0 ? "no" : "yes";
value = claimValue;
} else if (vocabProperty["format"] == "yyyymmdd") {
try {
claimValue = DateFormat("d MMM yyyy")
.format(DateTime.parse(value.toString()));
value = claimValue;
} catch (e, s) {
logger().d(s);
}
} else {
if (key.toLowerCase().contains("date") ||
key.toLowerCase().contains("day") ||
key.toLowerCase().contains("birth") ||
key.toLowerCase().contains("age")) {
try {
claimValue = DateFormat("d MMM yyyy")
.format(DateTime.parse(value.toString()));
value = claimValue;
} catch (e, s) {
logger().d(s);
}
}
if (key.toLowerCase().contains("country")) {
try {
CountryCode code = CountryCode.ofNumeric(value as int);
Country country = Country.isoCode(code.alpha2);
claimValue = country.name;
value = claimValue;
} catch (e, s) {
logger().d(s);
}
}
}
} else {
if (key.toLowerCase().contains("date") ||
key.toLowerCase().contains("day") ||
key.toLowerCase().contains("birth") ||
key.toLowerCase().contains("age")) {
try {
claimValue = DateFormat("d MMM yyyy")
.format(DateTime.parse(value.toString()));
value = claimValue;
} catch (e, s) {
logger().d(s);
}
}
if (key.toLowerCase().contains("country")) {
try {
CountryCode code = CountryCode.ofNumeric(value as int);
Country country = Country.isoCode(code.alpha2);
claimValue = country.name;
value = claimValue;
} catch (e, s) {
logger().d(s);
}
}
}
} else {
if (key.toLowerCase().contains("date") ||
key.toLowerCase().contains("day") ||
key.toLowerCase().contains("birth") ||
key.toLowerCase().contains("age")) {
try {
claimValue = DateFormat("d MMM yyyy")
.format(DateTime.parse(value.toString()));
value = claimValue;
} catch (e, s) {
logger().d(s);
}
}
if (key.toLowerCase().contains("country")) {
try {
CountryCode code = CountryCode.ofNumeric(value as int);
Country country = Country.isoCode(code.alpha2);
claimValue = country.name;
value = claimValue;
} catch (e, s) {
logger().d(s);
}
}
}

details.add(
ClaimDetailModel(
Expand Down
4 changes: 1 addition & 3 deletions lib/credential/data/dtos/claim_dto.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class ClaimDTO extends Equatable {
final String? expiration;
final String type;
Map<String, dynamic>? schema;
Map<String, dynamic>? vocab;

ClaimDTO(
{required this.id,
Expand All @@ -26,8 +25,7 @@ class ClaimDTO extends Equatable {
this.state = '',
this.expiration,
required this.info,
this.schema,
this.vocab});
this.schema});

factory ClaimDTO.fromJson(Map<String, dynamic> json) =>
_$ClaimDTOFromJson(json);
Expand Down
2 changes: 0 additions & 2 deletions lib/credential/data/dtos/claim_dto.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions lib/credential/data/mappers/claim_mapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class ClaimMapper extends Mapper<ClaimDTO, ClaimEntity> {
state: _claimStateMapper.mapFrom(from.state),
expiration: from.expiration,
schema: from.schema,
vocab: from.vocab,
type: from.type,
info: _claimInfoMapper.mapFrom(from.info));
}
Expand All @@ -35,7 +34,6 @@ class ClaimMapper extends Mapper<ClaimDTO, ClaimEntity> {
type: to.type,
expiration: to.expiration,
schema: to.schema,
vocab: to.vocab,
info: _claimInfoMapper.mapTo(to.info));
}
}
7 changes: 1 addition & 6 deletions lib/credential/domain/entities/claim_entity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class ClaimEntity {
final ClaimState state;
final String? expiration;
final Map<String, dynamic>? schema;
final Map<String, dynamic>? vocab;
final String type;
final Map<String, dynamic> info;

Expand All @@ -18,7 +17,6 @@ class ClaimEntity {
required this.state,
this.expiration,
this.schema,
this.vocab,
required this.type,
required this.info});

Expand All @@ -30,7 +28,6 @@ class ClaimEntity {
state: ClaimState.values.firstWhere((e) => e.name == json['state']),
expiration: json['expiration'],
schema: json['schema'],
vocab: json['vocab'],
type: json['type'],
info: json['info'],
);
Expand All @@ -44,15 +41,14 @@ class ClaimEntity {
'state': state.name,
'expiration': expiration,
'schema': schema,
'vocab': vocab,
'type': type,
'info': info,
};

@override
String toString() => "[ClaimEntity] {id: $id, "
"issuer: $issuer, did: $did, state: $state, "
"expiration: $expiration, schema: $schema, vocab: $vocab, type: $type, info: $info}";
"expiration: $expiration, schema: $schema, type: $type, info: $info}";

@override
bool operator ==(Object other) =>
Expand All @@ -65,7 +61,6 @@ class ClaimEntity {
state == other.state &&
expiration == other.expiration &&
schema == other.schema &&
vocab == other.vocab &&
type == other.type &&
info.toString() == other.info.toString();

Expand Down
40 changes: 0 additions & 40 deletions lib/iden3comm/data/data_sources/remote_iden3comm_data_source.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,44 +98,4 @@ class RemoteIden3commDataSource {
throw FetchSchemaException(error);
}
}

Future<Map<String, dynamic>> fetchVocab(
{required Map<String, dynamic> schema, required String type}) async {
try {
Map<String, dynamic>? schemaContext;
if (schema['@context'] is List) {
schemaContext = schema['@context'].first;
} else if (schema['@context'] is Map) {
schemaContext = schema['@context'];
}

if (schemaContext != null &&
schemaContext[type]["@context"]["poly-vocab"] != null) {
String vocabId = schemaContext[type]["@context"]["poly-vocab"];
String vocabUrl = vocabId;
if (vocabId.toLowerCase().startsWith("ipfs://")) {
String vocabHash = vocabId.toLowerCase().replaceFirst("ipfs://", "");
vocabUrl = "https://ipfs.io/ipfs/$vocabHash";
}
var vocabUri = Uri.parse(vocabUrl);
var vocabResponse = await client.get(vocabUri, headers: {
HttpHeaders.acceptHeader: '*/*',
HttpHeaders.contentTypeHeader: 'application/json',
});
if (vocabResponse.statusCode == 200) {
Map<String, dynamic> vocab = json.decode(vocabResponse.body);
logger().d('vocab: $vocab');

return vocab;
} else {
throw NetworkException(vocabResponse);
}
} else {
throw UnsupportedSchemaFetchVocabException(schema);
}
} catch (error) {
logger().e('vocab error: $error');
throw FetchVocabException(error);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,12 @@ class Iden3commCredentialRepositoryImpl extends Iden3commCredentialRepository {
return _remoteIden3commDataSource
.fetchClaim(authToken: authToken, url: url, did: did)
.then((dto) {
/// Error in fetching schema and vocab are not blocking
/// Error in fetching schema is not blocking
return _remoteIden3commDataSource
.fetchSchema(url: dto.info.credentialSchema.id)
.then((schema) {
dto.schema = schema;

return _remoteIden3commDataSource
.fetchVocab(schema: schema, type: dto.info.context[2])
.then((vocab) {
dto.vocab = vocab;

return dto;
});
return dto;
})
.catchError((_) => dto)
.then((value) => _claimMapper.mapFrom(dto));
Expand All @@ -58,12 +51,4 @@ class Iden3commCredentialRepositoryImpl extends Iden3commCredentialRepository {
.fetchSchema(url: url)
.catchError((error) => throw FetchSchemaException(error));
}

@override
Future<Map<String, dynamic>> fetchVocab(
{required Map<String, dynamic> schema, required String type}) {
return _remoteIden3commDataSource
.fetchVocab(schema: schema, type: type)
.catchError((error) => throw FetchVocabException(error));
}
}
8 changes: 0 additions & 8 deletions lib/iden3comm/domain/exceptions/iden3comm_exceptions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,10 @@ class FetchSchemaException extends ErrorException {
FetchSchemaException(error) : super(error);
}

class FetchVocabException extends ErrorException {
FetchVocabException(error) : super(error);
}

class UnsupportedFetchClaimTypeException extends ErrorException {
UnsupportedFetchClaimTypeException(error) : super(error);
}

class UnsupportedSchemaFetchVocabException extends ErrorException {
UnsupportedSchemaFetchVocabException(error) : super(error);
}

class GetConnectionsException extends ErrorException {
GetConnectionsException(error) : super(error);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,4 @@ abstract class Iden3commCredentialRepository {
});

Future<Map<String, dynamic>> fetchSchema({required String url});

Future<Map<String, dynamic>> fetchVocab(
{required Map<String, dynamic> schema, required String type});
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ class FetchAndSaveClaimsUseCase
state: ClaimState.revoked,
expiration: claim.expiration,
schema: claim.schema,
vocab: claim.vocab,
type: claim.type,
info: claim.info,
);
Expand Down
45 changes: 0 additions & 45 deletions lib/iden3comm/domain/use_cases/get_vocabs_use_case.dart

This file was deleted.

Loading

0 comments on commit c0b00ed

Please sign in to comment.