Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Hardik Juneja
jio
Commits
9c0c1922
Commit
9c0c1922
authored
Nov 04, 2016
by
Vincent Bechu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mappingstorage: catch error properly in put
parent
6cd7c2ab
Changes
3
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
196 additions
and
143 deletions
+196
-143
src/jio.storage/mappingstorage.js
src/jio.storage/mappingstorage.js
+56
-73
test/jio.storage/mappingstorage.tests.js
test/jio.storage/mappingstorage.tests.js
+139
-70
test/tests.html
test/tests.html
+1
-0
No files found.
src/jio.storage/mappingstorage.js
View file @
9c0c1922
/*jslint indent:2, maxlen: 80, nomen: true */
/*jslint indent:2, maxlen: 80, nomen: true */
/*global jIO, RSVP, UriTemplate, SimpleQuery, ComplexQuery, QueryFactory,
/*global jIO, RSVP, UriTemplate, SimpleQuery, ComplexQuery, QueryFactory,
Query*/
Query*/
(
function
(
jIO
,
RSVP
)
{
(
function
(
jIO
,
RSVP
,
UriTemplate
,
SimpleQuery
,
ComplexQuery
,
QueryFactory
,
Query
)
{
"
use strict
"
;
"
use strict
"
;
function
MappingStorage
(
spec
)
{
function
MappingStorage
(
spec
)
{
...
@@ -52,8 +53,6 @@
...
@@ -52,8 +53,6 @@
function
getAttachmentId
(
storage
,
sub_id
,
attachment_id
,
method
)
{
function
getAttachmentId
(
storage
,
sub_id
,
attachment_id
,
method
)
{
var
mapping_dict
=
storage
.
_attachment_mapping_dict
;
var
mapping_dict
=
storage
.
_attachment_mapping_dict
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
if
(
mapping_dict
!==
undefined
if
(
mapping_dict
!==
undefined
&&
mapping_dict
[
attachment_id
]
!==
undefined
&&
mapping_dict
[
attachment_id
]
!==
undefined
&&
mapping_dict
[
attachment_id
][
method
]
!==
undefined
&&
mapping_dict
[
attachment_id
][
method
]
!==
undefined
...
@@ -63,7 +62,6 @@
...
@@ -63,7 +62,6 @@
).
expand
({
id
:
sub_id
});
).
expand
({
id
:
sub_id
});
}
}
return
attachment_id
;
return
attachment_id
;
});
}
}
function
getSubStorageId
(
storage
,
id
)
{
function
getSubStorageId
(
storage
,
id
)
{
...
@@ -95,7 +93,10 @@
...
@@ -95,7 +93,10 @@
})
})
.
push
(
function
(
data
)
{
.
push
(
function
(
data
)
{
if
(
data
.
data
.
rows
.
length
===
0
)
{
if
(
data
.
data
.
rows
.
length
===
0
)
{
return
undefined
;
throw
new
jIO
.
util
.
jIOError
(
"
Can not find id
"
,
404
);
}
}
if
(
data
.
data
.
rows
.
length
>
1
)
{
if
(
data
.
data
.
rows
.
length
>
1
)
{
throw
new
TypeError
(
"
id must be unique field:
"
+
id
throw
new
TypeError
(
"
id must be unique field:
"
+
id
...
@@ -194,6 +195,23 @@
...
@@ -194,6 +195,23 @@
return
sub_doc
;
return
sub_doc
;
}
}
function
handleAttachment
(
context
,
argument_list
,
method
)
{
return
getSubStorageId
(
context
,
argument_list
[
0
])
.
push
(
function
(
sub_id
)
{
argument_list
[
0
]
=
sub_id
;
argument_list
[
1
]
=
getAttachmentId
(
context
,
sub_id
,
argument_list
[
1
],
method
);
return
context
.
_sub_storage
[
method
+
"
Attachment
"
].
apply
(
context
.
_sub_storage
,
argument_list
);
});
}
MappingStorage
.
prototype
.
get
=
function
(
id
)
{
MappingStorage
.
prototype
.
get
=
function
(
id
)
{
var
context
=
this
;
var
context
=
this
;
return
getSubStorageId
(
this
,
id
)
return
getSubStorageId
(
this
,
id
)
...
@@ -202,10 +220,6 @@
...
@@ -202,10 +220,6 @@
})
})
.
push
(
function
(
sub_doc
)
{
.
push
(
function
(
sub_doc
)
{
return
mapToMainDocument
(
context
,
sub_doc
,
true
);
return
mapToMainDocument
(
context
,
sub_doc
,
true
);
})
.
push
(
undefined
,
function
(
error
)
{
throw
new
jIO
.
util
.
jIOError
(
"
Cannot find document
"
+
id
+
"
, cause:
"
+
error
.
message
,
404
);
});
});
};
};
...
@@ -220,20 +234,18 @@
...
@@ -220,20 +234,18 @@
};
};
MappingStorage
.
prototype
.
put
=
function
(
id
,
doc
)
{
MappingStorage
.
prototype
.
put
=
function
(
id
,
doc
)
{
doc
.
id
=
id
;
var
context
=
this
,
var
context
=
this
,
sub_doc
=
mapToSubstorageDocument
(
this
,
doc
);
sub_doc
=
mapToSubstorageDocument
(
this
,
doc
);
return
getSubStorageId
(
this
,
id
)
return
getSubStorageId
(
this
,
id
)
.
push
(
function
(
sub_id
)
{
.
push
(
function
(
sub_id
)
{
if
(
context
.
_id_is_mapped
)
{
sub_doc
[
context
.
_mapping_dict
.
id
.
equal
]
=
id
;
}
if
(
id
===
undefined
)
{
throw
new
Error
();
}
return
context
.
_sub_storage
.
put
(
sub_id
,
sub_doc
);
return
context
.
_sub_storage
.
put
(
sub_id
,
sub_doc
);
})
})
.
push
(
undefined
,
function
()
{
.
push
(
undefined
,
function
(
error
)
{
if
(
error
instanceof
jIO
.
util
.
jIOError
&&
error
.
status_code
===
404
)
{
return
context
.
_sub_storage
.
post
(
sub_doc
);
return
context
.
_sub_storage
.
post
(
sub_doc
);
}
throw
error
;
})
})
.
push
(
function
()
{
.
push
(
function
()
{
return
id
;
return
id
;
...
@@ -252,48 +264,18 @@
...
@@ -252,48 +264,18 @@
};
};
MappingStorage
.
prototype
.
putAttachment
=
function
(
id
,
attachment_id
)
{
MappingStorage
.
prototype
.
putAttachment
=
function
(
id
,
attachment_id
)
{
var
context
=
this
,
argument_list
=
arguments
;
return
handleAttachment
(
this
,
arguments
,
"
put
"
,
id
)
return
getSubStorageId
(
context
,
id
)
.
push
(
function
(
sub_id
)
{
argument_list
[
0
]
=
sub_id
;
return
getAttachmentId
(
context
,
sub_id
,
attachment_id
,
"
put
"
);
})
.
push
(
function
(
sub_attachment_id
)
{
argument_list
[
1
]
=
sub_attachment_id
;
return
context
.
_sub_storage
.
putAttachment
.
apply
(
context
.
_sub_storage
,
argument_list
);
})
.
push
(
function
()
{
.
push
(
function
()
{
return
attachment_id
;
return
attachment_id
;
});
});
};
};
MappingStorage
.
prototype
.
getAttachment
=
function
(
id
,
attachment_id
)
{
MappingStorage
.
prototype
.
getAttachment
=
function
()
{
var
context
=
this
,
argument_list
=
arguments
;
return
handleAttachment
(
this
,
arguments
,
"
get
"
);
return
getSubStorageId
(
context
,
id
)
.
push
(
function
(
sub_id
)
{
argument_list
[
0
]
=
sub_id
;
return
getAttachmentId
(
context
,
sub_id
,
attachment_id
,
"
get
"
);
})
.
push
(
function
(
sub_attachment_id
)
{
argument_list
[
1
]
=
sub_attachment_id
;
return
context
.
_sub_storage
.
getAttachment
.
apply
(
context
.
_sub_storage
,
argument_list
);
});
};
};
MappingStorage
.
prototype
.
removeAttachment
=
function
(
id
,
attachment_id
)
{
MappingStorage
.
prototype
.
removeAttachment
=
function
(
id
,
attachment_id
)
{
var
context
=
this
,
argument_list
=
arguments
;
return
handleAttachment
(
this
,
arguments
,
"
remove
"
,
id
)
return
getSubStorageId
(
context
,
id
)
.
push
(
function
(
sub_id
)
{
argument_list
[
0
]
=
sub_id
;
return
getAttachmentId
(
context
,
sub_id
,
attachment_id
,
"
remove
"
);
})
.
push
(
function
(
sub_attachment_id
)
{
argument_list
[
1
]
=
sub_attachment_id
;
return
context
.
_sub_storage
.
removeAttachment
.
apply
(
context
.
_sub_storage
,
argument_list
);
})
.
push
(
function
()
{
.
push
(
function
()
{
return
attachment_id
;
return
attachment_id
;
});
});
...
@@ -308,24 +290,25 @@
...
@@ -308,24 +290,25 @@
};
};
MappingStorage
.
prototype
.
bulk
=
function
(
id_list
)
{
MappingStorage
.
prototype
.
bulk
=
function
(
id_list
)
{
var
i
,
var
context
=
this
;
context
=
this
,
mapped_result
=
[],
function
mapId
(
parameter
)
{
promise_list
=
id_list
.
map
(
function
(
parameter
)
{
return
getSubStorageId
(
context
,
parameter
.
parameter_list
[
0
])
return
getSubStorageId
(
context
,
parameter
.
parameter_list
[
0
])
.
push
(
function
(
id
)
{
.
push
(
function
(
id
)
{
return
{
"
method
"
:
parameter
.
method
,
"
parameter_list
"
:
[
id
]};
return
{
"
method
"
:
parameter
.
method
,
"
parameter_list
"
:
[
id
]};
});
});
});
}
return
new
RSVP
.
Queue
()
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
.
push
(
function
()
{
var
promise_list
=
id_list
.
map
(
mapId
);
return
RSVP
.
all
(
promise_list
);
return
RSVP
.
all
(
promise_list
);
})
})
.
push
(
function
(
id_list_mapped
)
{
.
push
(
function
(
id_list_mapped
)
{
return
context
.
_sub_storage
.
bulk
(
id_list_mapped
);
return
context
.
_sub_storage
.
bulk
(
id_list_mapped
);
})
})
.
push
(
function
(
result
)
{
.
push
(
function
(
result
)
{
var
mapped_result
=
[],
i
;
for
(
i
=
0
;
i
<
result
.
length
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
result
.
length
;
i
+=
1
)
{
mapped_result
.
push
(
mapToMainDocument
(
context
,
result
[
i
],
false
));
mapped_result
.
push
(
mapToMainDocument
(
context
,
result
[
i
],
false
));
}
}
...
@@ -342,10 +325,10 @@
...
@@ -342,10 +325,10 @@
sort_on
=
[];
sort_on
=
[];
function
mapQuery
(
one_query
)
{
function
mapQuery
(
one_query
)
{
var
i
,
query_list
=
[];
var
j
,
query_list
=
[];
if
(
one_query
.
type
===
"
complex
"
)
{
if
(
one_query
.
type
===
"
complex
"
)
{
for
(
i
=
0
;
i
<
one_query
.
query_list
.
length
;
i
+=
1
)
{
for
(
j
=
0
;
j
<
one_query
.
query_list
.
length
;
j
+=
1
)
{
query_list
.
push
(
mapQuery
(
one_query
.
query_list
[
i
]));
query_list
.
push
(
mapQuery
(
one_query
.
query_list
[
j
]));
}
}
one_query
.
query_list
=
query_list
;
one_query
.
query_list
=
query_list
;
return
one_query
;
return
one_query
;
...
@@ -430,4 +413,4 @@
...
@@ -430,4 +413,4 @@
};
};
jIO
.
addStorage
(
'
mapping
'
,
MappingStorage
);
jIO
.
addStorage
(
'
mapping
'
,
MappingStorage
);
}(
jIO
,
RSVP
));
}(
jIO
,
RSVP
,
UriTemplate
,
SimpleQuery
,
ComplexQuery
,
QueryFactory
,
Query
));
\ No newline at end of file
\ No newline at end of file
test/jio.storage/mappingstorage.tests.js
View file @
9c0c1922
This diff is collapsed.
Click to expand it.
test/tests.html
View file @
9c0c1922
...
@@ -28,6 +28,7 @@
...
@@ -28,6 +28,7 @@
<script
src=
"queries/key-jiodate.tests.js"
></script>
<script
src=
"queries/key-jiodate.tests.js"
></script>
<!--script src="queries/key-localstorage.tests.js"></script-->
<!--script src="queries/key-localstorage.tests.js"></script-->
<script
src=
"jio.storage/memorystorage.tests.js"
></script>
<script
src=
"jio.storage/memorystorage.tests.js"
></script>
<script
src=
"jio.storage/querystorage.tests.js"
></script>
<script
src=
"jio.storage/querystorage.tests.js"
></script>
<script
src=
"jio.storage/localstorage.tests.js"
></script>
<script
src=
"jio.storage/localstorage.tests.js"
></script>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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