Browse Source

full BPE schema

Namdak Tonpa 5 years ago
parent
commit
a930b5e1c7

+ 34 - 7
index.html

@@ -92,12 +92,17 @@
         <p>Automatiс chain-oriented API service implementation. Plug your Erlang HRL schema to
         <p>Automatiс chain-oriented API service implementation. Plug your Erlang HRL schema to
            <b>mix.exs</b></p>
            <b>mix.exs</b></p>
         <figure><code>
         <figure><code>
+ {:bpe, "~> 4.9.17"},
  {:erp, "~> 0.10.2"},
  {:erp, "~> 0.10.2"},
         </code></figure>
         </code></figure>
         <p>or <b>rebar.config</b>:</p>
         <p>or <b>rebar.config</b>:</p>
         <figure><code>
         <figure><code>
+ {bpe, ".*", {git, "git://github.com/synrc/bpe", {tag,"master"}}},
  {erp, ".*", {git, "git://github.com/erpuno/erp", {tag,"master"}}},
  {erp, ".*", {git, "git://github.com/erpuno/erp", {tag,"master"}}},
         </code></figure>
         </code></figure>
+    </section>
+    <section>
+        <a name="kvs"></a><h3>ERP JSON</h3>
         <p>Retrieve ERP organizational structure:</p>
         <p>Retrieve ERP organizational structure:</p>
         <figure><code>
         <figure><code>
  $ curl -X GET http://localhost:8005/rest/kvs/0/erp/group
  $ curl -X GET http://localhost:8005/rest/kvs/0/erp/group
@@ -106,13 +111,7 @@
         </code></figure>
         </code></figure>
         <p>Retrive all invoice payments for Stamp project of FinaTech company:</p>
         <p>Retrive all invoice payments for Stamp project of FinaTech company:</p>
         <figure><code>
         <figure><code>
- $ curl -i -X GET http://localhost:8005/rest/kvs/0/plm/FinaTech-Stamps/income
- HTTP/1.1 200 OK
- content-length: 1718
- content-type: application/json
- date: Fri, 04 Oct 2019 15:58:16 GMT
- server: Cowboy
-
+ $ curl -X GET http://localhost:8005/rest/kvs/0/plm/FinaTech-Stamps/income
  {"\/plm\/FinaTech-Stamps\/income":[{"invoice":"APR-2018-PAY-FTST","account":[],
  {"\/plm\/FinaTech-Stamps\/income":[{"invoice":"APR-2018-PAY-FTST","account":[],
  "subaccount":[],"volume":{"fraction":0,"digits":12000},"price":{"fraction":0,
  "subaccount":[],"volume":{"fraction":0,"digits":12000},"price":{"fraction":0,
  "digits":1},"instrument":"USD","type":"crypto","from":[],"to":[]},{"invoice":
  "digits":1},"instrument":"USD","type":"crypto","from":[],"to":[]},{"invoice":
@@ -137,6 +136,34 @@
  [],"volume":{"fraction":0,"digits":15000},"price":{"fraction":0,"digits":1},
  [],"volume":{"fraction":0,"digits":15000},"price":{"fraction":0,"digits":1},
  "instrument":"USD","type":"crypto","from":[],"to":[]}]}
  "instrument":"USD","type":"crypto","from":[],"to":[]}]}
         </code></figure>
         </code></figure>
+
+    </section>
+    <section>
+        <a name="kvs"></a><h3>BPE JSON</h3>
+
+        <p>Retrieve All History from Process 288117946539000:</p>
+        <figure><code>
+ curl -X GET http://localhost:8005/rest/kvs/0/bpe/hist/288117946539000
+ {"\/bpe\/hist\/288117946539000":[{"id":{"id":0,"proc":"288117946539000"},
+ "container":"feed","feed_id":[],"prev":[],"next":[],"name":[],"task":"Created",
+ "docs":[],"time":{"time":"{{2019,10,5},{21,21,44}}"}},{"id":{"id":1,"proc":
+ "288117946539000"},"container":"feed","feed_id":[],"prev":[],"next":[],
+ "name":[],"task":"Init","docs":[],"time":{"time":"{{2019,10,5},{21,21,50}}"}},
+ {"id":{"id":2,"proc":"288117946539000"},"container":"feed","feed_id":[],
+ "prev":[],"next":[],"name":[],"task":"Upload","docs":[],"time":{"time":
+ "{{2019,10,5},{21,21,51}}"}},{"id":{"id":3,"proc":"288117946539000"},
+ "container":"feed","feed_id":[],"prev":[],"next":[],"name":[],"task":
+ "Payment","docs":[],"time":{"time":"{{2019,10,5},{21,21,51}}"}}]}
+        </code></figure>
+
+        <p>Retrieve Step 2 from Process 288117946539000:</p>
+        <figure><code>
+ curl -X GET localhost:8005/rest/kvs/1/step,0,288117946539000/bpe/hist/288117946539000
+ {"id":{"id":2,"proc":"288117946539000"},"container":"feed","feed_id":[],
+ "prev":[],"next":[],"name":[],"task":"Upload","docs":[],"time":
+ {"time":"{{2019,10,5},{21,21,51}}"}}
+        </code></figure>
+
     </section>
     </section>
     <section>
     <section>
         <h3>MODULES</h3>
         <h3>MODULES</h3>

+ 1 - 1
mix.exs

@@ -20,7 +20,7 @@ defmodule REST.Mixfile do
                   {:rocksdb, "~> 1.3.2"},
                   {:rocksdb, "~> 1.3.2"},
                   {:kvs, "~> 6.9.2"},
                   {:kvs, "~> 6.9.2"},
                   {:erp, "~> 0.10.3"},
                   {:erp, "~> 0.10.3"},
-                  {:bpe, "~> 4.9.17"},
+                  {:bpe, "~> 4.9.18"},
                   {:jsone, "~> 1.5.0"},
                   {:jsone, "~> 1.5.0"},
                   {:cowboy, "~> 2.5.0"} ]
                   {:cowboy, "~> 2.5.0"} ]
 
 

+ 0 - 6
src/Organization.erl

@@ -1,6 +0,0 @@
--module('Organization').
--include_lib("erp/include/organization.hrl").
--compile({parse_transform, rest}).
--compile(export_all).
--rest_record('Organization').
-new() -> #'Organization'{}.

+ 0 - 6
src/Payment.erl

@@ -1,6 +0,0 @@
--module('Payment').
--include_lib("erp/include/payment.hrl").
--compile({parse_transform, rest}).
--compile(export_all).
--rest_record('Payment').
-new() -> #'Payment'{}.

+ 6 - 0
src/bpe/beginEvent.erl

@@ -0,0 +1,6 @@
+-module(beginEvent).
+-include_lib("bpe/include/bpe.hrl").
+-compile({parse_transform, rest}).
+-compile(export_all).
+-rest_record(beginEvent).
+new() -> #beginEvent{}.

+ 6 - 0
src/bpe/boundaryEvent.erl

@@ -0,0 +1,6 @@
+-module(boundaryEvent).
+-include_lib("bpe/include/bpe.hrl").
+-compile({parse_transform, rest}).
+-compile(export_all).
+-rest_record(boundaryEvent).
+new() -> #boundaryEvent{}.

+ 6 - 0
src/bpe/endEvent.erl

@@ -0,0 +1,6 @@
+-module(endEvent).
+-include_lib("bpe/include/bpe.hrl").
+-compile({parse_transform, rest}).
+-compile(export_all).
+-rest_record(endEvent).
+new() -> #endEvent{}.

+ 0 - 0
src/hist.erl → src/bpe/hist.erl


+ 6 - 0
src/bpe/messageEvent.erl

@@ -0,0 +1,6 @@
+-module(messageEvent).
+-include_lib("bpe/include/bpe.hrl").
+-compile({parse_transform, rest}).
+-compile(export_all).
+-rest_record(messageEvent).
+new() -> #messageEvent{}.

+ 6 - 0
src/bpe/process.erl

@@ -0,0 +1,6 @@
+-module(process).
+-include_lib("bpe/include/bpe.hrl").
+-compile({parse_transform, rest}).
+-compile(export_all).
+-rest_record(process).
+new() -> #process{}.

+ 6 - 0
src/bpe/sequenceFlow.erl

@@ -0,0 +1,6 @@
+-module(sequenceFlow).
+-include_lib("bpe/include/bpe.hrl").
+-compile({parse_transform, rest}).
+-compile(export_all).
+-rest_record(sequenceFlow).
+new() -> #sequenceFlow{}.

+ 6 - 0
src/bpe/serviceTask.erl

@@ -0,0 +1,6 @@
+-module(serviceTask).
+-include_lib("bpe/include/bpe.hrl").
+-compile({parse_transform, rest}).
+-compile(export_all).
+-rest_record(serviceTask).
+new() -> #serviceTask{}.

+ 0 - 0
src/step.erl → src/bpe/step.erl


+ 7 - 0
src/bpe/timeout.erl

@@ -0,0 +1,7 @@
+-module(timeout).
+-include_lib("bpe/include/bpe.hrl").
+-compile(export_all).
+new() -> {timeout,{0,{0,0,0}}}.
+to_json(#timeout{spec=X}) -> [{<<"timeout">>,iolist_to_binary(lists:flatten(io_lib:format("~p",[X])))}].
+from_json([{<<"timeout">>,X}],_) -> #timeout{spec = rest:parse(X) };
+from_json([{timeout,X}],_) -> #timeout{spec = rest:parse(X) }.

+ 0 - 0
src/ts.erl → src/bpe/ts.erl


+ 6 - 0
src/bpe/userTask.erl

@@ -0,0 +1,6 @@
+-module(userTask).
+-include_lib("bpe/include/bpe.hrl").
+-compile({parse_transform, rest}).
+-compile(export_all).
+-rest_record(userTask).
+new() -> #userTask{}.

+ 0 - 6
src/money.erl

@@ -1,6 +0,0 @@
--module(money).
--include_lib("dec/include/dec.hrl").
--compile({parse_transform, rest}).
--compile(export_all).
--rest_record(money).
-new() -> #money{}.

+ 5 - 2
src/rest.erl

@@ -171,10 +171,13 @@ atomize([{Key,_}|_]=Props) when Key =/= struct ->
 atomize(X) -> X.
 atomize(X) -> X.
 
 
 binarize([{Key,_}|_]=Props) when Key =/= struct ->
 binarize([{Key,_}|_]=Props) when Key =/= struct ->
-  lists:map(fun ({K,V}) when is_atom(K) -> {list_to_binary(atom_to_list(K)),V};
-                ({K,V}) when is_binary(K) -> {K,V} end, Props);
+  lists:map(fun ({K,V}) when is_atom(K) -> {list_to_binary(atom_to_list(K)),allowed_value(V)};
+                ({K,V}) when is_binary(K) -> {K,allowed_value(V)} end, Props);
 binarize(X) -> X.
 binarize(X) -> X.
 
 
+allowed_value(X) when is_reference(X) -> [];
+allowed_value(X) -> X.
+
 to_json(X) when is_tuple(X) -> Module = hd(tuple_to_list(X)), Module:to_json(X);
 to_json(X) when is_tuple(X) -> Module = hd(tuple_to_list(X)), Module:to_json(X);
 to_json(Data) ->
 to_json(Data) ->
     case is_string(Data) of
     case is_string(Data) of

+ 3 - 2
src/rest_kvs.erl

@@ -73,9 +73,10 @@ default_html_layout(Body) -> [<<"<html><body>">>, Body, <<"</body></html>">>].
 to_json(#{bindings := #{resource := Module, id := Id}} = Req, State) ->
 to_json(#{bindings := #{resource := Module, id := Id}} = Req, State) ->
     {ok,Resource} = kvs:get(c(Module),c(parse_id(Id))),
     {ok,Resource} = kvs:get(c(Module),c(parse_id(Id))),
     Type = element(1,Resource),
     Type = element(1,Resource),
-    {iolist_to_binary([?REST_JSON:encode(Type:to_json(Resource)),"\n"]), Req, State};
+    {iolist_to_binary([?REST_JSON:encode(rest:binarize(Type:to_json(Resource))),"\n"]), Req, State};
 to_json(#{bindings := #{resource := Module}} = Req, State) ->
 to_json(#{bindings := #{resource := Module}} = Req, State) ->
-    Fold = [ begin M = element(1,Resource), M:to_json(Resource) end || Resource <- kvs:all(c(Module))],
+    Fold = [ begin M = element(1,Resource), rest:binarize(M:to_json(Resource)) end || Resource <- kvs:all(c(Module))],
+    io:format("Fold: ~p~n",[Fold]),
     {iolist_to_binary([?REST_JSON:encode([{Module,Fold}]),"\n"]), Req, State}.
     {iolist_to_binary([?REST_JSON:encode([{Module,Fold}]),"\n"]), Req, State}.
 
 
 content_types_accepted(Req, State) ->
 content_types_accepted(Req, State) ->

+ 0 - 15
src/users.erl

@@ -1,15 +0,0 @@
--module(users).
--compile({parse_transform, rest}).
--record(user, {id,cn,name,type}).
--export([init/0, populate/1, exists/1, get/0, get/1, post/1, delete/1]).
--rest_record(user).
-
-new() -> #user{}.
-init()               -> ets:new(users, [public, named_table, {keypos, #user.id}]).
-populate(Users)      -> ets:insert(users, Users).
-exists(Id)           -> X = ets:member(users, binary_to_list(Id)), io:format("Member: ~p~n",[X]), X.
-get()                -> ets:tab2list(users).
-get(Id)              -> #user{id=Id}.
-delete(Id)           -> ets:delete(users, binary_to_list(Id)).
-post(#user{} = User) -> ets:insert(users, User);
-post(Data)           -> post(from_json(Data, #user{})).