./ct_report/coverage/node_dag.COVER.html

1 %%% ====================================================================
2 %%% ``The contents of this file are subject to the Erlang Public License,
3 %%% Version 1.1, (the "License"); you may not use this file except in
4 %%% compliance with the License. You should have received a copy of the
5 %%% Erlang Public License along with this software. If not, it can be
6 %%% retrieved via the world wide web at http://www.erlang.org/.
7 %%%
8 %%%
9 %%% Software distributed under the License is distributed on an "AS IS"
10 %%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11 %%% the License for the specific language governing rights and limitations
12 %%% under the License.
13 %%%
14 %%%
15 %%% @author Brian Cully <bjc@kublai.com>
16 %%% @end
17 %%% ====================================================================
18
19 -module(node_dag).
20 -behaviour(gen_pubsub_node).
21 -author('bjc@kublai.com').
22
23 -include("pubsub.hrl").
24 -include("jlib.hrl").
25
26 -export([based_on/0, init/3, terminate/2, options/0, features/0,
27 create_node_permission/6, publish_item/9, node_to_path/1,
28 path_to_node/1]).
29
30 1155 based_on() -> node_hometree.
31
32 init(Host, ServerHost, Opts) ->
33 22 node_flat:init(Host, ServerHost, Opts).
34
35 terminate(Host, ServerHost) ->
36 22 node_flat:terminate(Host, ServerHost).
37
38 options() ->
39 88 [{node_type, leaf} | node_hometree:options()].
40
41 features() ->
42 449 [<<"multi-collection">> | node_hometree:features()].
43
44 create_node_permission(_Host, _ServerHost, _Node, _ParentNode, _Owner, _Access) ->
45 91 {result, true}.
46
47 publish_item(ServerHost, Nidx, Publisher, Model, MaxItems, ItemId, ItemPublisher, Payload,
48 PublishOptions) ->
49 55 case nodetree_dag:get_node(Nidx) of
50 #pubsub_node{options = Options} ->
51 55 case find_opt(node_type, Options) of
52 collection ->
53
:-(
{error,
54 ?ERR_EXTENDED((mongoose_xmpp_errors:not_allowed()), <<"publish">>)};
55 _ ->
56 55 node_flat:publish_item(ServerHost, Nidx, Publisher, Model, MaxItems,
57 ItemId, ItemPublisher, Payload, PublishOptions)
58 end;
59
:-(
Err -> Err
60 end.
61
62
:-(
find_opt(_, []) -> false;
63 55 find_opt(Option, [{Option, Value} | _]) -> Value;
64 305 find_opt(Option, [_ | T]) -> find_opt(Option, T).
65
66 node_to_path(Node) ->
67 91 node_hometree:node_to_path(Node).
68
69 path_to_node(Path) ->
70 5 node_hometree:path_to_node(Path).
Line Hits Source