Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Memri
Flutter App for Memri
Commits
449ae34b
Commit
449ae34b
authored
3 years ago
by
Eelco van der Wel
Browse files
Options
Download
Email Patches
Plain Diff
update pod service with createSchema
parent
6bb90bf1
Pipeline
#8193
passed with stages
in 4 minutes and 56 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
lib/core/apis/pod_api.dart
+4
-6
lib/core/apis/pod_api.dart
lib/core/models/item.dart
+57
-6
lib/core/models/item.dart
lib/core/services/pod_service.dart
+94
-8
lib/core/services/pod_service.dart
lib/providers/pod_provider.dart
+2
-0
lib/providers/pod_provider.dart
with
157 additions
and
20 deletions
+157
-20
lib/core/apis/pod_api.dart
+
4
-
6
View file @
449ae34b
...
...
@@ -5,7 +5,6 @@ import 'package:memri/core/apis/base_api.dart';
import
'package:memri/core/models/pod/pod_config.dart'
;
import
'package:memri/core/apis/pod/pod_payloads.dart'
;
import
'package:memri/core/controllers/file_storage/file_storage_controller.dart'
;
import
'package:memri/core/models/item.dart'
;
import
'package:memri/core/services/settings.dart'
;
import
'package:moor/moor.dart'
;
...
...
@@ -47,13 +46,13 @@ class PodAPI extends BaseAPI {
return
response
.
data
;
}
Future
<
dynamic
>
createItem
(
Map
<
String
,
dynamic
>
syncDict
)
async
{
Future
<
String
>
createItem
(
Map
<
String
,
dynamic
>
item_map
)
async
{
String
endpoint
=
'
$_endpointUrl
/create_item'
;
var
response
=
await
dio
.
post
(
endpoint
,
data:
{
'auth'
:
{
'type'
:
'ClientAuth'
,
'databaseKey'
:
_podConfig
.
databaseKey
},
'payload'
:
syncDict
,
'payload'
:
item_map
,
},
);
checkResponseError
(
response
);
...
...
@@ -86,7 +85,7 @@ class PodAPI extends BaseAPI {
return
response
.
data
;
}
Future
<
Item
>
getItem
(
String
id
)
async
{
Future
<
Map
<
String
,
dynamic
>
>
getItem
(
String
id
)
async
{
String
endpoint
=
'
$_endpointUrl
/get_item'
;
var
response
=
await
dio
.
post
(
endpoint
,
...
...
@@ -96,8 +95,7 @@ class PodAPI extends BaseAPI {
},
);
checkResponseError
(
response
);
var
res_dict
=
jsonDecode
(
response
.
data
);
return
Item
.
fromJson
(
res_dict
[
0
]);
return
jsonDecode
(
response
.
data
);
}
Future
<
dynamic
>
getLogsForPluginRun
(
String
itemId
)
async
{
...
...
This diff is collapsed.
Click to expand it.
lib/core/models/item.dart
+
57
-
6
View file @
449ae34b
import
'package:collection/collection.dart'
;
import
'package:uuid/uuid.dart'
;
class
Item
{
String
type
;
String
?
type
;
Map
<
String
,
dynamic
>
properties
;
Map
<
String
,
EdgeList
>
edges
;
Item
({
required
String
this
.
type
,
String
?
this
.
type
=
null
,
Map
<
String
,
dynamic
>
?
properties
,
Map
<
String
,
EdgeList
>
?
edges
,
})
:
properties
=
properties
??
{},
edges
=
edges
??
{};
EdgeList
?
getEdges
(
String
edgeName
)
{
return
this
.
edges
[
edgeName
]
??
null
;
List
<
Edge
>
?
getEdges
(
String
edgeName
)
{
var
edgeList
=
this
.
edges
[
edgeName
];
if
(
edgeList
==
null
)
{
return
null
;
}
else
{
List
<
Edge
>
edges
=
[];
edgeList
.
targets
.
forEach
((
target
)
{
edges
.
add
(
Edge
(
source
:
this
,
target:
target
,
name:
edgeList
.
name
,
))
;
});
return
edges
;
}
}
List
<
Item
>
?
getEdgeTargets
(
String
edgeName
)
{
return
this
.
edges
[
edgeName
]
?.
targets
;
}
dynamic
get
(
String
propertyName
)
{
return
this
.
properties
[
propertyName
]
??
null
;
}
void
setIdIfNotExists
()
{
if
(
this
.
get
(
"id"
)
==
null
)
{
this
.
properties
[
"id"
]
=
Uuid
()
.
v4
();
}
}
static
Item
fromJson
(
Map
<
String
,
dynamic
>
itemMap
)
{
String
type
=
"Item"
;
String
?
type
;
Map
<
String
,
dynamic
>
properties
=
{};
Map
<
String
,
EdgeList
>
edges
=
{};
itemMap
.
forEach
((
key
,
value
)
{
...
...
@@ -43,6 +67,13 @@ class Item {
edges:
edges
,
);
}
Map
<
String
,
dynamic
>
toJson
()
{
Map
<
String
,
dynamic
>
result
=
{};
result
.
addAll
(
this
.
properties
);
result
[
"type"
]
=
this
.
type
;
return
result
;
}
}
class
EdgeList
{
...
...
@@ -52,10 +83,30 @@ class EdgeList {
EdgeList
({
required
this
.
name
,
List
<
Item
>
?
targets
,
required
List
<
Item
>
?
targets
,
})
:
targets
=
targets
??
[];
Item
?
first
()
{
return
this
.
targets
.
firstOrNull
;
}
}
class
Edge
{
Item
source
;
Item
target
;
String
name
;
Edge
({
required
this
.
source
,
required
this
.
target
,
required
this
.
name
,
});
Map
<
String
,
dynamic
>
toJson
()
{
return
{
"_source"
:
this
.
source
.
get
(
"id"
),
"_target"
:
this
.
target
.
get
(
"id"
),
"_name"
:
this
.
name
,
};
}
}
This diff is collapsed.
Click to expand it.
lib/core/services/pod_service.dart
+
94
-
8
View file @
449ae34b
import
'dart:convert'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/services.dart'
;
import
'package:memri/core/apis/pod/pod_payloads.dart'
;
import
'package:memri/core/apis/pod_api.dart'
;
import
'package:memri/core/models/item.dart'
;
...
...
@@ -22,6 +26,13 @@ class PodService extends ApiService<PodAPI> {
final
SharedPreferences
_prefs
;
late
PodConfig
podConfig
;
final
Map
<
String
,
String
>
_podPropertyTypes
=
{
"string"
:
"Text"
,
"int"
:
"Integer"
,
"double"
:
"Real"
,
"bool"
:
"Bool"
,
"datetime"
:
"DateTime"
,
};
/**
* Authentication
...
...
@@ -63,27 +74,102 @@ class PodService extends ApiService<PodAPI> {
/**
* POD
*/
Future
<
void
>
createSchema
()
async
{
Map
<
String
,
dynamic
>
schemaJson
=
jsonDecode
(
await
rootBundle
.
loadString
(
"assets/schema.json"
));
List
<
Map
<
String
,
dynamic
>>
schemaItems
=
[];
for
(
var
property
in
schemaJson
[
"properties"
])
{
schemaItems
.
add
({
"type"
:
"ItemPropertySchema"
,
"itemType"
:
property
[
"item_type"
],
"propertyName"
:
property
[
"property"
],
"valueType"
:
_podPropertyTypes
[
property
[
"value_type"
]],
});
}
for
(
var
edge
in
schemaJson
[
"edges"
])
{
schemaItems
.
add
({
"type"
:
"ItemEdgeSchema"
,
"sourceType"
:
edge
[
"source_type"
],
"targetType"
:
edge
[
"target_type"
],
"edgeName"
:
edge
[
"edge"
],
});
}
debugPrint
(
"[DEBUG] create schema:
${schemaItems.length}
items"
);
var
payload
=
PodPayloadBulkAction
(
createItems:
schemaItems
,
updateItems:
[],
deleteItems:
[],
createEdges:
[]);
api
.
bulkAction
(
payload
);
}
Future
<
String
>
podVersion
()
async
=
>
api
.
podVersion
()
.
catchError
((
error
)
=
>
''
);
Future
<
dynamic
>
bulkAction
({
required
PodConfig
connectionConfig
,
required
PodPayloadBulkAction
bulkPayload
,
})
async
=
>
api
.
bulkAction
(
bulkPayload
);
Future
<
void
>
bulkAction
({
List
<
Item
>
?
createItems
=
null
,
List
<
Item
>
?
updateItems
=
null
,
List
<
String
>
?
deleteItems
=
null
,
List
<
Edge
>
?
createEdges
=
null
,
})
async
{
List
<
Map
<
String
,
dynamic
>>
createPayload
=
[];
if
(
createItems
!=
null
)
{
createItems
.
forEach
((
item
)
{
item
.
setIdIfNotExists
();
createPayload
.
add
(
item
.
toJson
());
});
}
List
<
Map
<
String
,
dynamic
>>
updatePayload
=
[];
if
(
updateItems
!=
null
)
{
updateItems
.
forEach
((
item
)
{
updatePayload
.
add
(
item
.
toJson
());
});
}
List
<
Map
<
String
,
dynamic
>>
edgePayload
=
[];
if
(
createEdges
!=
null
)
{
createEdges
.
forEach
((
edge
)
{
edgePayload
.
add
(
edge
.
toJson
());
});
}
var
bulkPayload
=
PodPayloadBulkAction
(
createItems:
createPayload
,
updateItems:
updatePayload
,
deleteItems:
deleteItems
??
[],
createEdges:
edgePayload
);
await
api
.
bulkAction
(
bulkPayload
);
}
Future
<
Item
>
getItem
({
required
PodConfig
connectionConfig
,
required
String
id
,
})
async
=
>
api
.
getItem
(
id
);
Item
.
fromJson
(
await
api
.
getItem
(
id
)
)
;
Future
<
List
<
Item
>>
graphql
({
required
PodConfig
connectionConfig
,
required
String
query
,
})
async
=
>
_parseGQLResponse
(
await
api
.
queryGraphQL
(
query
));
Future
<
Item
>
createItem
({
required
Item
item
,
})
async
{
if
(
item
.
type
==
null
)
{
throw
new
Exception
(
"Attempted to create item without an item type."
);
}
var
itemMap
=
item
.
toJson
();
var
resultID
=
await
api
.
createItem
(
itemMap
);
item
.
properties
[
"id"
]
=
resultID
;
return
item
;
}
List
<
Item
>
_parseGQLResponse
(
Map
<
String
,
dynamic
>
jsonBody
)
{
List
<
Item
>
result
=
[];
List
<
dynamic
>
data
=
jsonBody
[
'data'
]
??
[];
...
...
This diff is collapsed.
Click to expand it.
lib/providers/pod_provider.dart
+
2
-
0
View file @
449ae34b
...
...
@@ -44,6 +44,8 @@ class PodProvider with ChangeNotifier {
try
{
await
_podService
.
authenticate
(
podAddress:
podUrl
,
ownerKey:
ownerKey
,
dbKey:
dbKey
);
// TODO move this once not required on signup
await
_podService
.
createSchema
();
_handleAuthenticated
(
context
);
RouteNavigator
.
navigateTo
(
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets