Skip to content

Commit

Permalink
Features/2828/tools project links (#782)
Browse files Browse the repository at this point in the history
* Displayed Quay.io link and other links

dockstore/dockstore#2828

Set up the ImageProviderService for search.service.ts allowing the
tools data to merge with the images (quay.io and other links) before
pushing the data into the Akita 'store' state.

Set up the imageProviderService in filterEntry after the method has
determined that hit['_type'] is a tool

Modified the filterEntry method in search.service.ts to return a tuple
in order to unit test without side effects.

* Defined an Interface of Hit and replaced
Array<Any> in filterEntry and all associated methods with Array<Hit>
  • Loading branch information
ByteMap authored Sep 10, 2019
1 parent 09a0640 commit 761b7ae
Show file tree
Hide file tree
Showing 4 changed files with 191 additions and 13 deletions.
7 changes: 4 additions & 3 deletions src/app/search/search.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { AdvancedSearchService } from './advancedsearch/advanced-search.service'
import { ELASTIC_SEARCH_CLIENT } from './elastic-search-client';
import { QueryBuilderService } from './query-builder.service';
import { SearchQuery } from './state/search.query';
import { SearchService } from './state/search.service';
import { Hit, SearchService } from './state/search.service';

/**
* There are a total of 5 calls per search.
Expand Down Expand Up @@ -61,7 +61,7 @@ export class SearchComponent implements OnInit, OnDestroy {
*/
/*TODO: Bad coding...change this up later (init)..*/
private setFilter = false;
public hits: Object[];
public hits: Hit[];

// Possibly 100 workflows and 100 tools (extra +1 is used to see if there are > 200 results)
public readonly query_size = 201;
Expand Down Expand Up @@ -383,7 +383,8 @@ export class SearchComponent implements OnInit, OnDestroy {
})
.then(hits => {
this.hits = hits.hits.hits;
this.searchService.filterEntry(this.hits, this.query_size);
const filteredHits: [Array<Hit>, Array<Hit>] = this.searchService.filterEntry(this.hits, this.query_size);
this.searchService.setHits(filteredHits[0], filteredHits[1]);
if (this.values.length > 0 && hits) {
this.searchTerm = true;
}
Expand Down
30 changes: 26 additions & 4 deletions src/app/search/state/search.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,30 @@
* limitations under the License.
*/
import { inject, TestBed } from '@angular/core/testing';
import { elasticSearchResponse } from '../../test/mocked-objects';
import { RouterTestingModule } from '@angular/router/testing';

import { ProviderService } from '../../shared/provider.service';
import { ProviderStubService } from '../../test/service-stubs';
import { SearchService } from './search.service';
import { Hit, SearchService } from './search.service';
import { SearchStore } from './search.store';
import { ImageProviderService } from '../../shared/image-provider.service';
import { HttpClientTestingModule } from '@angular/common/http/testing';

describe('SearchService', () => {
let searchStore: SearchStore;
let searchService: SearchService;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [RouterTestingModule],
providers: [SearchService, SearchStore, { provide: ProviderService, useClass: ProviderStubService }]
imports: [RouterTestingModule, HttpClientTestingModule],
providers: [
ImageProviderService,
SearchService,
SearchStore,
{
provide: ProviderService,
useClass: ProviderStubService
}
]
});
searchService = TestBed.get(SearchService);
searchStore = TestBed.get(SearchStore);
Expand All @@ -49,4 +59,16 @@ describe('SearchService', () => {
it('should not crash on null advancedSearchObject', inject([SearchService], (service: SearchService) => {
expect(service.hasSearchText(null, null, null)).toEqual(false);
}));

it('should create image provider', inject([SearchService], (service: SearchService) => {
const filtered: [Array<Hit>, Array<Hit>] = service.filterEntry(elasticSearchResponse, 201);
const tools = filtered[0];
const workflows = filtered[1];
const toolsSource = tools[0]._source;
const workflowSource = workflows[0]._source;
expect(toolsSource.imgProvider).toBe('Docker Hub');
expect(toolsSource.imgProviderUrl).toBe('https://hub.docker.com/r/weischenfeldt/pcawg_delly_workflow');
expect(workflowSource.imgProvider).toBe(undefined);
expect(workflowSource.imgProviderUrl).toBe(undefined);
}));
});
30 changes: 24 additions & 6 deletions src/app/search/state/search.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@ import { ProviderService } from '../../shared/provider.service';
import { ELASTIC_SEARCH_CLIENT } from '../elastic-search-client';
import { SearchQuery } from './search.query';
import { SearchStore } from './search.store';
import { ImageProviderService } from '../../shared/image-provider.service';
import { Explanation } from 'elasticsearch';

export interface Hit {
_index: string;
_type: string;
_id: string;
_score: number;
_source: any;
_version?: number;
_explanation?: Explanation;
fields?: any;
highlight?: any;
inner_hits?: any;
sort?: string[];
}

@Injectable()
export class SearchService {
Expand All @@ -44,7 +60,8 @@ export class SearchService {
private searchStore: SearchStore,
private searchQuery: SearchQuery,
private providerService: ProviderService,
private router: Router
private router: Router,
private imageProviderService: ImageProviderService
) {}

// Given a URL, will attempt to shorten it
Expand Down Expand Up @@ -108,28 +125,29 @@ export class SearchService {
* @param {number} query_size
* @memberof SearchService
*/
filterEntry(hits: Array<any>, query_size: number) {
filterEntry(hits: Array<Hit>, query_size: number): [Array<Hit>, Array<Hit>] {
const workflowHits = [];
const toolHits = [];
hits.forEach(hit => {
hit['_source'] = this.providerService.setUpProvider(hit['_source']);
if (workflowHits.length + toolHits.length < query_size - 1) {
if (hit['_type'] === 'tool') {
hit['_source'] = this.imageProviderService.setUpImageProvider(hit['_source']);
toolHits.push(hit);
} else if (hit['_type'] === 'workflow') {
workflowHits.push(hit);
}
}
});
this.setHits(toolHits, workflowHits);
return [toolHits, workflowHits];
}

setHits(toolHit: any, workflowHit: any) {
setHits(toolHits: Array<Hit>, workflowHits: Array<Hit>) {
this.searchStore.setState(state => {
return {
...state,
toolhit: toolHit,
workflowhit: workflowHit
toolhit: toolHits,
workflowhit: workflowHits
};
});
}
Expand Down
137 changes: 137 additions & 0 deletions src/app/test/mocked-objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { WorkflowVersion } from '../shared/swagger';
import { OrgToolObject } from '../mytools/my-tool/my-tool.component';
import { WebserviceDescriptorTypeEnum } from '../shared/descriptor-type-compat.service';
import DescriptorTypeEnum = Workflow.DescriptorTypeEnum;
import { Hit } from '../search/state/search.service';

export const updatedWorkflow: Workflow = {
descriptorType: DescriptorTypeEnum.CWL,
Expand Down Expand Up @@ -456,3 +457,139 @@ export const testSourceFiles: Array<SourceFile> = [
}
}
];

export const elasticSearchResponse: Hit[] = [
{
_index: 'entry',
_type: 'tool',
_id: '2313',
_score: 1,
_source: {
tool_maintainer_email: '',
aliases: {},
default_dockerfile_path: '/delly_docker/Dockerfile',
is_published: true,
toolname: null,
last_modified_date: null,
checker_id: null,
private_access: false,
descriptorType: ['CWL'],
mode: 'MANUAL_IMAGE_PATH',
lastBuild: null,
lastUpdated: 1513149095843,
path: 'registry.hub.docker.com/weischenfeldt/pcawg_delly_workflow',
defaultCWLTestParameterFile: '/test.json',
workflowVersions: [
{
doiURL: null,
dbUpdateDate: null,
versionEditor: null,
verifiedSource: null,
verified: false,
referenceType: 'UNSET',
frozen: false,
commitID: null,
dockerfile_path: '/delly_docker/Dockerfile',
last_built: null,
doiStatus: 'NOT_REQUESTED',
wdl_path: '/delly_docker/Dockstore.wdl',
automated: false,
size: 0,
cwl_path: '/delly_docker/Dockstore.cwl',
id: 8459,
image_id: ''
},
{
doiURL: null,
dbUpdateDate: null,
versionEditor: null,
verifiedSource: null,
verified: false,
referenceType: 'UNSET',
frozen: false,
commitID: null,
dockerfile_path: '/delly_docker/Dockerfile',
last_built: null,
doiStatus: 'NOT_REQUESTED',
wdl_path: '/delly_docker/Dockstore.wdl',
automated: false,
size: 0,
cwl_path: '/delly_docker/Dockstore.cwl',
id: 8458,
image_id: ''
}
],
has_checker: false,
id: 2313,
last_modified: null,
email: '[email protected]',
default_wdl_path: '/delly_docker/Dockstore.wdl',
tool_path: 'registry.hub.docker.com/weischenfeldt/pcawg_delly_workflow',
registry: 'DOCKER_HUB',
dbUpdateDate: null,
registry_string: 'registry.hub.docker.com',
tags: null,
dbCreateDate: null,
topicId: null,
custom_docker_registry_path: 'registry.hub.docker.com',
default_cwl_path: '/delly_docker/Dockstore.cwl',
name: 'pcawg_delly_workflow',
namespace: 'weischenfeldt',
gitUrl: '[email protected]:weischenfeldt/pcawg_delly_workflow.git',
defaultWDLTestParameterFile: '/test.json',
defaultVersion: 'DELLYlegacy'
}
},
{
_index: 'entry',
_type: 'workflow',
_id: '2210',
_score: 1,
_source: {
aliases: {},
is_published: true,
last_modified_date: null,
is_checker: false,
checker_id: null,
type: 'BioWorkflow',
repository: 'Ginny-9609498',
source_control_provider: 'GITHUB',
descriptorType: 'CWL',
full_workflow_path: 'github.com/smc-rna-challenge/Ginny-9609498/Ginny-9609498',
mode: 'FULL',
lastUpdated: 1496192152500,
path: 'github.com/smc-rna-challenge/Ginny-9609498',
workflowVersions: [
{
doiURL: null,
dbUpdateDate: null,
subClass: null,
versionEditor: null,
verifiedSource: null,
verified: false,
frozen: false,
referenceType: 'UNSET',
commitID: null,
id: 8288,
doiStatus: 'NOT_REQUESTED'
}
],
sourceControl: 'github.com',
has_checker: false,
id: 2210,
last_modified: null,
email: '[email protected]',
dbUpdateDate: null,
author: 'Ginny',
defaultTestParameterFilePath: '/test.json',
workflowName: 'Ginny-9609498',
workflow_path: '/main.cwl',
dbCreateDate: null,
topicId: null,
parent_id: null,
organization: 'smc-rna-challenge',
gitUrl: '[email protected]:smc-rna-challenge/Ginny-9609498.git',
defaultVersion: null
}
}
];

0 comments on commit 761b7ae

Please sign in to comment.