Skip to content

Commit

Permalink
Merge pull request #36 from qcri-social/dev
Browse files Browse the repository at this point in the history
Merging dev to staging (Release 1.6) minor commits
  • Loading branch information
kushalkantgoyal committed Jul 13, 2015
2 parents 29ae5cf + dfcc0ba commit 8e4d412
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -417,45 +417,6 @@ public Map<String, Integer> findTotalCount(final String collectionCode) throws E
}


/**
* This method is a duplicate of the actual one in TaggerController.java and has been placed here ONLY for testing purpose.
* Please remove once testing is successful!
* @param queryString
* @param crisisCode
* @param count
* @param fileType
* @param contentType
* @return
* @throws Exception
*/
@RequestMapping(value = "/downloadHumanLabeledDocuments.action", method = RequestMethod.POST)
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ResponseBody
public Map<String,Object> downloadHumanLabeledDocuments(@RequestBody String queryString,
@RequestParam(value = "crisisCode", required = true) String crisisCode,
@RequestParam(value = "count", defaultValue = "-1") Integer count,
@RequestParam(value = "fileType", defaultValue = DownloadType.TEXT_JSON) String fileType,
@RequestParam(value = "contentType", defaultValue = DownloadType.FULL_TWEETS) String contentType) throws Exception {
logger.info("Received request: crisisCode = " + crisisCode + ", count = " + count + ", fileType = " + fileType
+ ", contentType = " + contentType + "\nquery String = " + queryString);
try {
String userName = "SinhaKoushik"; // a hard-coded placeholder, TODO: change to something more meaningful
if (null == count) {
count = -1;
}
Map<String, Object> downloadLink = taggerService.downloadHumanLabeledDocumentsByCrisisUserName(queryString, crisisCode, userName, count, fileType, contentType);
if (downloadLink.get("fileName") != null && downloadLink.get("total") != null) {
return getUIWrapper(downloadLink, true, new Long((Integer)downloadLink.get("total")), null);
} else {
return getUIWrapper(downloadLink, false);
}
} catch (Exception e) {
e.printStackTrace();
return getUIWrapper(false, "Error in getting dlownload link for human labeled documents");
}
}

private AidrCollectionTotalDTO convertAidrCollectionToDTO(AidrCollection collection, boolean hasTaggerOutput){
if (collection == null){
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ public Map<String,Object> getHumanLabeledDocumentsByCrisisIDUserName(Long crisis
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ResponseBody
public Map<String,Object> downloadHumanLabeledDocuments(@RequestBody String queryString,
public Map<String,Object> downloadHumanLabeledDocuments(String queryString,
@RequestParam(value = "crisisCode", required = true) String crisisCode,
@RequestParam(value = "count", defaultValue = "-1") Integer count,
@RequestParam(value = "fileType", defaultValue = DownloadType.TEXT_JSON) String fileType,
Expand All @@ -940,7 +940,7 @@ public Map<String,Object> downloadHumanLabeledDocuments(@RequestBody String quer
}
} catch (Exception e) {
e.printStackTrace();
return getUIWrapper(false, "Error in getting dlownload link for human labeled documents");
return getUIWrapper(false, "Error in getting download link for human labeled documents");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,20 @@ Ext.define('TAGGUI.training-data.controller.TrainingDataController', {
},
'button[action=deleteTrainingExample]': {
click: this.deleteTrainingExample
}

},
"#downloadButton": {
click: function (btn, e, eOpts) {
this.downloadButtonHandler(btn);
}
}
});

},

beforeRenderView: function (component, eOpts) {
AIDRFMFunctions.initMessageContainer();
this.mainComponent = component;
this.mainComponent.constraintsString = '{"constraints":[]}';
taggerCollectionDetailsController = this;

this.loadModelData();
Expand Down Expand Up @@ -177,6 +182,61 @@ Ext.define('TAGGUI.training-data.controller.TrainingDataController', {
}
}
});
}
},
downloadButtonHandler: function(btn){
var me = this;
var format = me.mainComponent.downloadFormat.getValue().format;
// var contents = 'full';

var url = '';
var params = {
crisisCode: CRISIS_CODE,
//count: 1000,
//queryString: me.mainComponent.constraintsString
queryString: me.mainComponent.constraintsString
};

if(format == 'csv'){
url = '/protected/tagger/downloadHumanLabeledDocuments.action';
} else {
params.jsonType = format;
url = '/protected/tagger/downloadHumanLabeledDocuments.action';
}

btn.setDisabled(true);
me.mainComponent.downloadLink.setText('<div class="loading-block"></div>', false);

Ext.Ajax.timeout = 900000;
Ext.override(Ext.form.Basic, {timeout: Ext.Ajax.timeout/1000});
Ext.override(Ext.data.proxy.Server, {timeout: Ext.Ajax.timeout});
Ext.override(Ext.data.Connection, {timeout: Ext.Ajax.timeout});
Ext.Ajax.request({
url: BASE_URL + url,
timeout: 900000,
method: 'POST',
params: params,
headers: {
'Accept': 'application/json'
},
success: function (response) {
btn.setDisabled(false);
var resp = Ext.decode(response.responseText);
if (resp.success) {
if (resp.data && resp.data != '') {
me.mainComponent.downloadLink.setText('<div class="styled-text download-link"><a target="_blank" href="' + resp.data.fileName + '">' + resp.data.fileName + '</a></div>', false);
} else {
me.mainComponent.downloadLink.setText('', false);
AIDRFMFunctions.setAlert("Error", "Generate Tweet Ids service returned empty url. For further inquiries please contact admin.");
}
} else {
me.mainComponent.downloadLink.setText('', false);
AIDRFMFunctions.setAlert("Error", resp.message);
}
},
failure: function () {
btn.setDisabled(false);
}
});
}

});
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,74 @@ Ext.define('TAGGUI.training-data.view.TrainingDataPanel', {
displayMsg:'Human-tagged '+ COLLECTION_TYPES[TYPE]["plural"] + ' {0} - {1} of {2}',
emptyMsg:'No human-tagged '+ COLLECTION_TYPES[TYPE]["plural"] + ' to display'
});
//
this.downloadTweetsL = Ext.create('Ext.form.Label', {
text: 'Download',
padding: '15 0 0 0',
cls: 'header-h2'
});

this.downloadTweetsDescription = Ext.create('Ext.form.Label', {
text: 'Download Human-tagged tweets',
padding: '0 0 10 0'
});

this.downloadFormat = Ext.create('Ext.form.RadioGroup', {
fieldLabel: 'Format',
labelWidth: 55,
columns: [150, 210, 240],
items: [
{
boxLabel: 'Spreadsheet (.csv)',
name: 'format',
inputValue: 'csv',
checked: true
},
{
boxLabel: 'Single JSON object (.json)',
name: 'format',
inputValue: 'JSON'
},
{
boxLabel: 'One JSON per line (.txt-json)',
name: 'format',
inputValue: 'TEXT_JSON'
}
]
});

this.downloadButton = Ext.create('Ext.Button', {
text: 'Generate Downloadable File',
cls:'btn btn-blue',
id: 'downloadButton',
margin: '10 0 0 0'
});

this.downloadLink = Ext.create('Ext.form.Label', {
flex: 1,
margin: '10 5 5 5',
html: ''
});

this.downloadPanel = Ext.create('Ext.container.Container', {
layout: {
type: 'vbox'
},
items: [
this.downloadTweetsL,
this.downloadTweetsDescription,
this.downloadFormat,
{
xtype: 'container',
layout: 'hbox',
items: [
this.downloadButton,
this.downloadLink
]
}
]
});
//

this.items = [
this.breadcrumbs,
Expand Down Expand Up @@ -158,9 +226,12 @@ Ext.define('TAGGUI.training-data.view.TrainingDataPanel', {
},
this.taggerDescription2line,
this.trainingDataGrid,
this.trainingDataPaging
this.trainingDataPaging,
this.downloadPanel
];



this.callParent(arguments);
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,17 @@ public Response generateTweetsIDSCSVFromListFiltered(HumanLabeledDocumentListWra
}

@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/filter/genJson")
public Response generateJSONFromListFiltered(HumanLabeledDocumentListWrapper postBody,
@QueryParam("collectionCode") String collectionCode,
@QueryParam("exportLimit") Integer exportLimit,
@DefaultValue(DownloadType.TEXT_JSON) @QueryParam("jsonType") String jsonType,
@QueryParam("userName") String userName) throws UnknownHostException {
logger.debug("In list-persister genJson");
logger.info("Received request for collection: " + collectionCode + " with jsonType = " + jsonType);

logger.info("Received request for collection: " + collectionCode + " with jsonType = " + jsonType + ", post body = " + postBody);
logger.info("Received query string: " + postBody.toJsonString());
try {
DeserializeFilters des = new DeserializeFilters();
JsonQueryList queryList = des.deserializeConstraints(postBody.getQueryString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,15 @@ public Response downloadHumanLabeledDocumentsByCrisisIDUserName(String queryStri
@DefaultValue("CSV") @QueryParam("fileType") String fileType,
@DefaultValue("full") @QueryParam("contentType") String contentType) {

System.out.println("Received request: crisisCode = " + crisisCode + ", userName = " + userName + ", count = " + count + ", fileType = " + fileType
logger.info("Received request: crisisCode = " + crisisCode + ", userName = " + userName + ", count = " + count + ", fileType = " + fileType
+ ", contentType = " + contentType + "\nquery String = " + queryString);
if (null == crisisCode || null == userName) {
return Response.ok(
new ResponseWrapper(TaggerAPIConfigurator.getInstance().getProperty(TaggerAPIConfigurationProperty.STATUS_CODE_FAILED), "crisisID or user name can't be null")).build();
}
try {
List<HumanLabeledDocumentDTO> dtoList = miscEJB.getHumanLabeledDocumentsByCrisisCode(crisisCode, count);
System.out.println("REST call will return dto List size = " + (dtoList != null ? dtoList.size() : "null"));
logger.info("REST call will return dto List size = " + (dtoList != null ? dtoList.size() : "null"));
if (dtoList != null) {
ResponseWrapper response = new ResponseWrapper(TaggerAPIConfigurator.getInstance().getProperty(TaggerAPIConfigurationProperty.STATUS_CODE_SUCCESS));
response.setTotal(dtoList.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,10 @@ public List<HumanLabeledDocumentDTO> getHumanLabeledDocumentsByCrisisCode(String
try {
return remoteTaskManager.getHumanLabeledDocumentsByCrisisCode(crisisCode, count);
} catch (Exception e) {
logger.error("exception for crisis code = " + crisisCode);
System.out.println("exception for crisis code = " + crisisCode);
e.printStackTrace();
logger.error("Exception for crisis code = " + crisisCode);
logger.error("Exception", e);
//System.out.println("exception for crisis code = " + crisisCode);
//e.printStackTrace();
return null;
}
}
Expand Down Expand Up @@ -153,17 +154,17 @@ public String downloadItems(HumanLabeledDocumentList dtoList, String queryString
HumanLabeledDocumentListWrapper postBody = new HumanLabeledDocumentListWrapper(dtoList, queryString);
//System.out.println("Request POST body: " + postBody.toJsonString());

System.out.println("Received request to create file for: " + dtoList.getTotal() + "items for crisis = " + crisisCode + "userName = " + userName);
logger.info("Received request to create file for: " + dtoList.getTotal() + "items for crisis = " + crisisCode + "userName = " + userName);
Client client = ClientBuilder.newBuilder().register(JacksonFeature.class).build();

String targetAPI = getPersisterTargetAPI(fileType, contentType, count);
WebTarget webResource = client.target(persisterMainUrl + targetAPI + "collectionCode=" + crisisCode + "&userName=" + userName);
System.out.println("Invoking REST call: " + persisterMainUrl + targetAPI + "collectionCode=" + crisisCode + "&userName=" + userName);
logger.info("Invoking REST call: " + persisterMainUrl + targetAPI + "collectionCode=" + crisisCode + "&userName=" + userName);
Response clientResponse = webResource.request(MediaType.APPLICATION_JSON)
.post(Entity.json(postBody), Response.class);
//System.out.println("received raw response from persister: " + clientResponse);
Map<String, Object> jsonResponse = clientResponse.readEntity(Map.class);
System.out.println("Received response from persister: " + jsonResponse);
logger.info("Received response from persister: " + jsonResponse);
if (jsonResponse.get("url") != null) {
return jsonResponse.get("url").toString();
} else {
Expand Down
1 change: 1 addition & 0 deletions update-db-r1.5-r1.6.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE `aidr_predict`.`crisis` ADD COLUMN `isMicromapperEnabled` BIT(1) NOT NULL AFTER `userID`;

0 comments on commit 8e4d412

Please sign in to comment.