Browse files

Bit more validation of empty documents and start of the queue page

  • Loading branch information...
1 parent 5a41b9c commit 4acca0ee7cabc174d52499b39a9efd24820122ec Donovan Hide committed Apr 3, 2012
View
2 public/app.js
@@ -17,7 +17,7 @@ Ext.Ajax.timeout = 60000; // 60 seconds
Ext.application({
name: 'Superfastmatch',
models: ['Fragment','Search','Document'],
- controllers: ['Searches','Documents','Compare'],
+ controllers: ['Searches','Documents','Compare','Queue'],
requires: ['Superfastmatch.view.MainViewPort'],
launch: function(){
Ext.QuickTips.init();
View
23 public/app/controller/Queue.js
@@ -0,0 +1,23 @@
+Ext.define('Superfastmatch.controller.Queue', {
+ extend: 'Ext.app.Controller',
+ stores: ['Queue'],
+ views: ['QueuePanel'],
+ refs: [
+ {
+ ref: 'queue',
+ selector: '#QueuePanel'
+ }
+ ],
+
+ init: function() {
+ this.control({
+ '#QueuePanel':{
+ activate: function(panel){panel.getStore().load({start:1});}
+ }
+ });
+ },
+
+ onLaunch: function(){
+ // this.getQueue().reconfigure(this.getQueueStore());
+ }
+});
View
16 public/app/model/Queue.js
@@ -0,0 +1,16 @@
+Ext.define('Superfastmatch.model.Queue', {
+ extend: 'Ext.data.Model',
+ requires: ['Ext.ux.data.PagedProxy','Ext.ux.data.TimedJsonReader'],
+ uses: ['Superfastmatch.model.Queue'],
+ fields: ['id','status','action','priority','doctype','docid','source','target'],
+
+ proxy: {
+ type: 'paged',
+ startParam: 'start',
+ url: '/queue/',
+ reader: {
+ type: 'timedjson',
+ root: 'rows'
+ }
+ }
+});
View
5 public/app/store/Queue.js
@@ -0,0 +1,5 @@
+Ext.define('Superfastmatch.store.Queue', {
+ extend: 'Ext.data.Store',
+ requires: ['Superfastmatch.model.Queue'],
+ model: 'Superfastmatch.model.Queue'
+});
View
7 public/app/view/MainViewPort.js
@@ -3,6 +3,7 @@ Ext.define('Superfastmatch.view.MainViewPort', {
requires: [
'Superfastmatch.view.SearchPanel',
'Superfastmatch.view.DocumentPanel',
+ 'Superfastmatch.view.QueuePanel',
'Ext.ux.panel.HTMLPanel',
'Ext.ux.panel.StatefulTabPanel'
],
@@ -33,11 +34,7 @@ Ext.define('Superfastmatch.view.MainViewPort', {
title: 'Index'
},
{
- xtype: 'HTMLPanel',
- loader: {
- url: '/queue/'
- },
- title: 'Queue'
+ xtype: 'queuepanel',
},
{
xtype: 'HTMLPanel',
View
35 public/app/view/QueuePanel.js
@@ -0,0 +1,35 @@
+Ext.define('Superfastmatch.view.QueuePanel', {
+ extend: 'Ext.grid.Panel',
+ alias: 'widget.queuepanel',
+ requires: ['Superfastmatch.store.Queue'],
+ itemId: 'QueuePanel',
+ title: 'Queue',
+ forceFit: true,
+ columns: [
+ {text:"ID",dataIndex:'id'},
+ {text:"Status",dataIndex:'status'},
+ {text:"Action",dataIndex:'action'},
+ {text:"Priority",dataIndex:'priority'},
+ {text:"Doc Type",dataIndex:'doctype'},
+ {text:"Doc ID",dataIndex:'docid'},
+ {text:"Source",dataIndex:'source'},
+ {text:"Target",dataIndex:'target'}
+ ],
+
+ buildToolBar: function(store){
+ return {
+ xtype: 'pagingtoolbar',
+ store: store,
+ dock: 'bottom',
+ displayInfo: true
+ }
+ },
+
+ initComponent: function() {
+ var me = this,
+ store=Ext.create('Superfastmatch.store.Queue');
+ me.callParent(arguments);
+ me.reconfigure(store);
+ me.addDocked(me.buildToolBar(store));
+ }
+});
View
27 src/api.cc
@@ -153,23 +153,24 @@ namespace superfastmatch{
void Api::MatchQuery(const ApiCall* call,const string& query,ApiParams& params){
vector<string> queries,parts;
+ map<string,string> temp;
kc::strsplit(query,"&",&queries);
for (vector<string>::const_iterator it=queries.begin();it!=queries.end();++it){
kc::strsplit(*it,"=",&parts);
if (parts.size()==2){
size_t ksiz,vsiz;
char* kbuf = kc::urldecode(parts[0].c_str(), &ksiz);
char* vbuf = kc::urldecode(parts[1].c_str(), &vsiz);
- set<string>::const_iterator q=call->queries.find(kbuf);
- if (q!=call->queries.end()){
- string value(vbuf,vsiz);
- queries_.find(kbuf)->second->validate(value);
- params.query[kbuf]=value;
- }
+ temp[kbuf]=vbuf;
delete[] kbuf;
delete[] vbuf;
}
- }
+ }
+ for(set<string>::const_iterator it=call->queries.begin(),ite=call->queries.end();it!=ite;++it){
+ string value=temp[*it];
+ queries_.find(*it)->second->validate(value);
+ params.query[*it]=value;
+ }
}
// --------------------
@@ -230,14 +231,14 @@ namespace superfastmatch{
create_map<response_t,string>(response_t(202,"application/json"),QUEUED_JSON)\
(response_t(400,"application/json"),FAILURE_JSON),
set<string>(),
- "Create a new document asynchronously. There must be a form field with name text, otherwise returns response code 400.",
+ "Create a new document asynchronously. There must be a form field with name text and a string of length greater than 0, otherwise returns response code 400.",
&Api::CreateDocument),
ApiCall(HTTPClient::MPUT,
"^/document/<doctype>/<docid>/?$",
create_map<response_t,string>(response_t(202,"application/json"),QUEUED_JSON)\
(response_t(400,"application/json"),FAILURE_JSON),
set<string>(),
- "Create and associate a new document asynchronously. There must be a form field with name text, otherwise returns response code 400.",
+ "Create and associate a new document asynchronously. There must be a form field with name text and a string of length greater than 0, otherwise returns response code 400.",
&Api::CreateAndAssociateDocument),
ApiCall(HTTPClient::MDELETE,
"^/document/<doctype>/<docid>/?$",
@@ -373,13 +374,13 @@ namespace superfastmatch{
uint32_t doctype = kc::atoi(params.resource.find("doctype")->second.c_str());
uint32_t docid = kc::atoi(params.resource.find("docid")->second.c_str());
map<string,string>::const_iterator text=params.form.find("text");
- if (text!=params.form.end()){
+ if (text!=params.form.end() && text->second.size()>0){
CommandPtr addCommand = registry_->getQueueManager()->createCommand(AddDocument,doctype,docid,"","",params.body);
addCommand->fillDictionary(&response.dict);
response.type=response_t(202,"application/json");
}else{
response.type=response_t(400,"application/json");
- response.dict.SetValue("MESSAGE","No text field specified");
+ response.dict.SetValue("MESSAGE","No text field specified or is empty");
}
}
@@ -432,7 +433,9 @@ namespace superfastmatch{
}
void Api::GetQueue(const ApiParams& params,ApiResponse& response){
- registry_->getQueueManager()->fillDictionary(&response.dict);
+ uint64_t start = kc::atoi(params.query.find("start")->second.c_str());
+ uint64_t limit = kc::atoi(params.query.find("limit")->second.c_str());
+ registry_->getQueueManager()->fillDictionary(&response.dict,start,limit);
response.type=response_t(200,"application/json");
}
View
3 src/document.cc
@@ -344,6 +344,9 @@ namespace superfastmatch
DocumentPtr doc(new Document(doctype,docid,permanent,registry_));
metadata_map content_map;
kt::wwwformtomap(content,&content_map);
+ if (content_map.find("text")==content_map.end()){
+ return DocumentPtr();
+ }
if (not doc->setText(content_map["text"])){
return DocumentPtr();
}
View
30 src/queue.cc
@@ -56,13 +56,13 @@ namespace superfastmatch{
return count;
}
- void QueueManager::fillDictionary(TemplateDictionary* dict,const uint64_t cursor){
+ void QueueManager::fillDictionary(TemplateDictionary* dict,const uint64_t start,const uint64_t limit){
TemplateDictionary* queueDict=dict->AddIncludeDictionary("DATA");
queueDict->SetFilename(QUEUE_JSON);
queueDict->SetIntValue("TOTAL",registry_->getQueueDB()->count());
kc::PolyDB::Cursor* queue_cursor=registry_->getQueueDB()->cursor();
size_t count;
- string start;
+ string cursor;
vector<string> keys;
string key;
string value;
@@ -72,36 +72,36 @@ namespace superfastmatch{
queueDict->SetIntValue("FIRST",command->getQueueId());
}
if(queue_cursor->jump_back()){
- count=registry_->getPageSize()-1;
+ count=limit-1;
while(count--){
queue_cursor->step_back();
}
if (queue_cursor->get(&key,&value)){
command = getCommand(key,value);
queueDict->SetIntValue("LAST",command->getQueueId());
- start=key;
+ cursor=key;
}
}
- if (cursor && (registry_->getQueueDB()->match_prefix(kc::strprintf("%u:%020lu",Queued,cursor),&keys,1)==1 ||\
- registry_->getQueueDB()->match_prefix(kc::strprintf("%u:%020lu",Active,cursor),&keys,1)==1 ||\
- registry_->getQueueDB()->match_prefix(kc::strprintf("%u:%020lu",Failed,cursor),&keys,1)==1 ||\
- registry_->getQueueDB()->match_prefix(kc::strprintf("%u:%020lu",Finished,cursor),&keys,1)==1 ||\
- registry_->getQueueDB()->match_prefix(kc::strprintf("%u",Active),&keys,1)==1 ||\
- registry_->getQueueDB()->match_prefix(kc::strprintf("%u",Queued),&keys,1)==1))
+ if (start && (registry_->getQueueDB()->match_prefix(kc::strprintf("%u|%020lu",Queued,start),&keys,1)==1 ||\
+ registry_->getQueueDB()->match_prefix(kc::strprintf("%u|%020lu",Active,start),&keys,1)==1 ||\
+ registry_->getQueueDB()->match_prefix(kc::strprintf("%u|%020lu",Failed,start),&keys,1)==1 ||\
+ registry_->getQueueDB()->match_prefix(kc::strprintf("%u|%020lu",Finished,start),&keys,1)==1 ||\
+ registry_->getQueueDB()->match_prefix(kc::strprintf("%u",Active),&keys,1)==1 ||\
+ registry_->getQueueDB()->match_prefix(kc::strprintf("%u",Queued),&keys,1)==1))
{
- start=keys[0];
+ cursor=keys[0];
}
- queue_cursor->jump(start);
- count=registry_->getPageSize();
+ queue_cursor->jump(cursor);
+ count=limit;
while(count--){
queue_cursor->step_back();
}
if(queue_cursor->get(&key,&value)){
command = getCommand(key,value);
queueDict->SetIntValue("PREVIOUS",command->getQueueId());
}
- queue_cursor->jump(start);
- count=registry_->getPageSize();
+ queue_cursor->jump(cursor);
+ count=limit;
while(count>0 && queue_cursor->get(&key,&value,true)){
command = getCommand(key,value);
command->fillDictionary(queueDict);
View
2 src/queue.h
@@ -20,7 +20,7 @@ namespace superfastmatch
CommandPtr createCommand(const CommandAction action,const uint32_t doc_type,const uint32_t doc_id,const string& source, const string& target,const string& payload);
CommandPtr getQueuedCommand();
size_t processQueue();
- void fillDictionary(TemplateDictionary* dict,const uint64_t cursor=0);
+ void fillDictionary(TemplateDictionary* dict,const uint64_t start,const uint64_t limit);
private:
CommandPtr getCommand(const string& key,const string& value);
View
6 tests/api-unittest.cc
@@ -27,6 +27,8 @@ TEST_F(BaseTest,DocumentApiTest){
TestAPI(api_,HTTPClient::MPOST,"/document/","","",-1);
TestAPI(api_,HTTPClient::MPOST,"/document/5/1","","",400);
TestAPI(api_,HTTPClient::MPOST,"/document/5/1/","","",400);
+ TestAPI(api_,HTTPClient::MPOST,"/document/5/1/","","text=",400);
+ TestAPI(api_,HTTPClient::MPUT,"/document/5/1/","","text=",400);
TestAPI(api_,HTTPClient::MPOST,"/document/5/1","","text=testing+123",202);
TestAPI(api_,HTTPClient::MPOST,"/document/5/1/","","text=testing+123",202);
TestAPI(api_,HTTPClient::MPUT,"/document/5/1","","text=testing+123",202);
@@ -108,6 +110,10 @@ TEST_F(BaseTest,QueueApiTest){
TestAPI(api_,HTTPClient::MGET,"/queue","","",200);
TestAPI(api_,HTTPClient::MGET,"/queue/","","",200);
TestAPI(api_,HTTPClient::MGET,"/QUEUE/","","",200);
+ TestAPI(api_,HTTPClient::MGET,"/queue/","start=0","",200);
+ TestAPI(api_,HTTPClient::MGET,"/queue/","start=0&limit=0","",200);
+ TestAPI(api_,HTTPClient::MGET,"/queue/","start=0&limit=10","",200);
+ TestAPI(api_,HTTPClient::MGET,"/queue/","limit=10","",200);
}
TEST_F(BaseTest,IndexApiTest){

0 comments on commit 4acca0e

Please sign in to comment.