This repository has been archived by the owner on Jul 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
325 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright (c) TIKI Inc. | ||
* MIT license. See LICENSE file in root directory. | ||
*/ | ||
|
||
import 'package:uuid/uuid.dart'; | ||
|
||
import '../api_email_msg/model/api_email_msg_model.dart'; | ||
import 'model/data_push_model.dart'; | ||
|
||
class DataPushConvert { | ||
static List<DataPushModel> message(ApiEmailMsgModel message) => [ | ||
DataPushModel( | ||
fromType: "company", | ||
fromValue: message.sender?.company?.domain, | ||
toType: "content", | ||
toValue: "email", | ||
fingerprint: Uuid().v4()), | ||
DataPushModel( | ||
fromType: "content", | ||
fromValue: "email", | ||
toType: "action", | ||
toValue: "received", | ||
fingerprint: Uuid().v4()), | ||
DataPushModel( | ||
fromType: "action", | ||
fromValue: "received", | ||
toType: "day", | ||
toValue: message.receivedDate?.day.toString(), | ||
fingerprint: Uuid().v4()), | ||
DataPushModel( | ||
fromType: "day", | ||
fromValue: message.receivedDate?.day.toString(), | ||
toType: "month", | ||
toValue: message.receivedDate?.month.toString(), | ||
fingerprint: Uuid().v4()), | ||
DataPushModel( | ||
fromType: "month", | ||
fromValue: message.receivedDate?.month.toString(), | ||
toType: "year", | ||
toValue: message.receivedDate?.year.toString(), | ||
fingerprint: Uuid().v4()), | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright (c) TIKI Inc. | ||
* MIT license. See LICENSE file in root directory. | ||
*/ | ||
|
||
import 'package:app/src/utils/api/helper_api_rsp.dart'; | ||
import 'package:app/src/utils/api/helper_api_utils.dart'; | ||
import 'package:logging/logging.dart'; | ||
import 'package:sqflite_sqlcipher/sqlite_api.dart'; | ||
|
||
import '../api_knowledge/api_knowledge_service.dart'; | ||
import 'model/data_push_model.dart'; | ||
import 'repository/data_push_repository.dart'; | ||
|
||
class DataPushService { | ||
final _log = Logger('DataPushService'); | ||
static final int _pushOn = 250; | ||
final DataPushRepository _repository; | ||
final ApiKnowledgeService _apiKnowledgeService; | ||
|
||
DataPushService( | ||
{required ApiKnowledgeService apiKnowledgeService, | ||
required Database database}) | ||
: this._apiKnowledgeService = apiKnowledgeService, | ||
this._repository = DataPushRepository(database); | ||
|
||
Future<void> write(List<DataPushModel> edges, {bool force = false}) async { | ||
await _repository.insert(edges); | ||
int size = await _repository.getSize(); | ||
if (size >= _pushOn) { | ||
List<DataPushModel> edgesToPush = | ||
await _repository.getAll(limit: _pushOn); | ||
HelperApiRsp rsp = await _apiKnowledgeService | ||
.addEdges(edgesToPush.map((e) => e.toEdge()).toList()); | ||
if (HelperApiUtils.is2xx(rsp.code)) { | ||
List<int> ids = edgesToPush | ||
.where((e) => e.queueId != null) | ||
.map((e) => e.queueId!) | ||
.toList(); | ||
await _repository.deleteByIds(ids); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright (c) TIKI Inc. | ||
* MIT license. See LICENSE file in root directory. | ||
*/ | ||
|
||
import '../../api_knowledge/model/edge/api_knowledge_model_edge.dart'; | ||
import '../../api_knowledge/model/edge/api_knowledge_model_edge_vertex.dart'; | ||
|
||
class DataPushModel { | ||
int? queueId; | ||
String? fromType; | ||
String? fromValue; | ||
String? toType; | ||
String? toValue; | ||
String? fingerprint; | ||
DateTime? created; | ||
|
||
DataPushModel( | ||
{this.queueId, | ||
this.fromType, | ||
this.fromValue, | ||
this.toType, | ||
this.toValue, | ||
this.fingerprint, | ||
this.created}); | ||
|
||
DataPushModel.fromMap(Map<String, dynamic> map) | ||
: this.queueId = map['queue_id'], | ||
this.fromType = map['from_type'], | ||
this.fromValue = map['from_value'], | ||
this.toType = map['to_type'], | ||
this.toValue = map['to_value'], | ||
this.fingerprint = map['fingerprint'] { | ||
int? createdEpoch = map['created_epoch']; | ||
if (createdEpoch != null) | ||
this.created = DateTime.fromMillisecondsSinceEpoch(createdEpoch); | ||
} | ||
|
||
DataPushModel.fromEdge(ApiKnowledgeModelEdge edge) | ||
: this.fromValue = edge.from?.value, | ||
this.fromType = edge.from?.type, | ||
this.toValue = edge.to?.value, | ||
this.toType = edge.to?.type, | ||
this.fingerprint = edge.fingerprint; | ||
|
||
Map<String, dynamic> toMap() { | ||
return { | ||
'queue_id': this.queueId, | ||
'from_type': this.fromType, | ||
'from_value': this.fromValue, | ||
'to_type': this.toType, | ||
'to_value': this.toValue, | ||
'fingerprint': this.fingerprint, | ||
'created_epoch': created?.millisecondsSinceEpoch, | ||
}; | ||
} | ||
|
||
ApiKnowledgeModelEdge toEdge() { | ||
return ApiKnowledgeModelEdge( | ||
from: ApiKnowledgeModelEdgeVertex( | ||
type: this.fromType, | ||
value: this.fromValue, | ||
), | ||
to: ApiKnowledgeModelEdgeVertex( | ||
type: this.toType, | ||
value: this.toValue, | ||
), | ||
fingerprint: this.fingerprint); | ||
} | ||
} |
Oops, something went wrong.