Skip to content

Commit

Permalink
#1410 Use Query API to fetch observable jobs in observables list
Browse files Browse the repository at this point in the history
  • Loading branch information
nadouani committed Jul 24, 2020
1 parent c55e1ce commit cb93cc0
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 27 deletions.
9 changes: 5 additions & 4 deletions frontend/app/scripts/controllers/case/CaseObservablesCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,11 +366,12 @@

$scope.showReport = function(observable, analyzerId) {
CortexSrv.getJobs($scope.caseId, observable._id, analyzerId, 1)
.then(function(response) {
return CortexSrv.getJob(response.data[0].id);
})
.then(function(response){
var job = response.data;
if(!response.data || response.data.length !== 1) {
return;
}

var job = response.data[0];
var report = {
job: job,
template: job.analyzerName || job.analyzerId,
Expand Down
59 changes: 36 additions & 23 deletions frontend/app/scripts/services/api/CortexSrv.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(function() {
'use strict';
angular.module('theHiveServices').service('CortexSrv', function($q, $http, $rootScope, $uibModal, StatSrv, StreamSrv, AnalyzerSrv, PSearchSrv, ModalUtilsSrv) {
angular.module('theHiveServices').service('CortexSrv', function($q, $http, $rootScope, $uibModal, QuerySrv, StatSrv, StreamSrv, AnalyzerSrv, PSearchSrv, ModalUtilsSrv) {
var self = this;
var baseUrl = './api/connector/cortex';

Expand All @@ -24,32 +24,45 @@
};

this.getJobs = function(caseId, observableId, analyzerId, limit) {
return $http.post(baseUrl + '/job/_search', {
sort: ['-startDate'],
range: '0-' + (
limit || 10),
query: {
_and: [

return QuerySrv.query('v1', [
{
'_name': 'getObservable',
'idOrName': observableId
},
{
'_name': 'jobs'
},
{
'_name': 'filter',
'_or': [
{
_parent: {
_type: 'case_artifact',
_query: {
_id: observableId
}
'analyzerId': analyzerId
},
{
'_like': {
'_field': 'analyzerDefinition',
'_value': analyzerId
}
}, {
_or: [
{
analyzerId: analyzerId
}, {
_like: {
_field: 'analyzerDefinition',
_value: analyzerId
}
}
]
}
]
},
{
'_name': 'sort',
'_fields': [
{
'startDate': 'desc'
}
]
},
{
'_name': 'page',
'from': 0,
'to': limit || 10
}
], {
params: {
name: 'observable-jobs-' + observableId
}
});
};
Expand Down

0 comments on commit cb93cc0

Please sign in to comment.