Skip to content

Commit

Permalink
feat(ontology): select link class from all ontologies (DEV-688) (#737)
Browse files Browse the repository at this point in the history
* refactor(ontology): remove unused interface

* feat(ontology): select link class from all ontologies (DEV-688)

* test(ontolgy): fix broken test
  • Loading branch information
kilchenmann committed May 13, 2022
1 parent b9f56a8 commit 8dcdd8f
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 22 deletions.
5 changes: 0 additions & 5 deletions src/app/project/ontology/ontology.component.ts
Expand Up @@ -31,11 +31,6 @@ import { DefaultProperties, PropertyCategory, PropertyInfoObject } from './defau
import { DefaultClass, DefaultResourceClasses } from './default-data/default-resource-classes';
import { OntologyService } from './ontology.service';

export interface OntologyInfo {
id: string;
label: string;
}

export interface CardinalityInfo {
resClass: ClassDefinition;
property: PropertyInfoObject;
Expand Down
Expand Up @@ -75,6 +75,7 @@

<!-- depending on type: display gui attribute -->
<div *ngIf="showGuiAttr" [ngSwitch]="propertyInfo.propType.objectType">
<!-- list property -->
<mat-form-field class="large-field property-type ontology-form-field" *ngSwitchCase="dspConstants.ListValue">
<span matPrefix class="ontology-prefix-icon">
<mat-icon>{{guiAttrIcon}}</mat-icon>&nbsp;
Expand All @@ -90,15 +91,18 @@
</mat-hint>
</mat-form-field>

<!-- link property -->
<mat-form-field class="large-field property-type ontology-form-field" *ngSwitchCase="dspConstants.LinkValue">
<span matPrefix class="ontology-prefix-icon">
<mat-icon>{{guiAttrIcon}}</mat-icon>&nbsp;
</span>
<mat-label>Select resource class</mat-label>
<mat-select formControlName="guiAttr">
<mat-option *ngFor="let item of resourceClasses" [value]="item.id">
{{item.label}}
</mat-option>
<mat-optgroup *ngFor="let onto of ontologyClasses" [label]="onto.ontologyLabel">
<mat-option *ngFor="let class of onto.classes" [value]="class.id">
{{class.label}}
</mat-option>
</mat-optgroup>
</mat-select>
<mat-hint *ngIf="formErrors.guiAttr">
{{formErrors.guiAttr}}
Expand Down
Expand Up @@ -200,8 +200,7 @@ describe('PropertyFormComponent', () => {

beforeEach(waitForAsync(() => {

const cacheServiceSpyOnto = jasmine.createSpyObj('CacheServiceOnto', ['get']);
const cacheServiceSpyLists = jasmine.createSpyObj('CacheServiceLists', ['get']);
const cacheServiceSpy = jasmine.createSpyObj('CacheService', ['get']);

const ontologyEndpointSpyObj = {
v2: {
Expand Down Expand Up @@ -239,11 +238,7 @@ describe('PropertyFormComponent', () => {
},
{
provide: CacheService,
useValue: cacheServiceSpyOnto
},
{
provide: CacheService,
useValue: cacheServiceSpyLists
useValue: cacheServiceSpy
}
]
})
Expand All @@ -261,6 +256,18 @@ describe('PropertyFormComponent', () => {
}
);

// mock cache service for currentProjectOntologies
const cacheSpyProjOnto = TestBed.inject(CacheService);
(cacheSpyProjOnto as jasmine.SpyObj<CacheService>).get.withArgs('currentProjectOntologies').and.callFake (
() => {
const ontologies: ReadOntology[] = [];
ontologies.push(MockOntology.mockReadOntology('http://0.0.0.0:3333/ontology/0001/anything/v2'));
ontologies.push(MockOntology.mockReadOntology('http://0.0.0.0:3333/ontology/0001/minimal/v2'));
const response: ReadOntology[] = ontologies;
return of(response);
}
);

// mock cache service for currentOntologyLists
const cacheSpyLists = TestBed.inject(CacheService);
(cacheSpyLists as jasmine.SpyObj<CacheService>).get.withArgs('currentOntologyLists').and.callFake(
Expand Down
34 changes: 27 additions & 7 deletions src/app/project/ontology/property-form/property-form.component.ts
Expand Up @@ -29,6 +29,12 @@ import { AutocompleteItem } from 'src/app/workspace/search/advanced-search/resou
import { DefaultProperties, DefaultProperty, PropertyCategory, PropertyInfoObject } from '../default-data/default-properties';
import { OntologyService } from '../ontology.service';

export interface ClassToSelect {
ontologyId: string;
ontologyLabel: string;
classes: ClassDefinition[];
}

@Component({
selector: 'app-property-form',
templateUrl: './property-form.component.html',
Expand Down Expand Up @@ -106,7 +112,7 @@ export class PropertyFormComponent implements OnInit {
lists: ListNodeInfo[];

// resource classes in this ontology
resourceClasses: ClassDefinition[] = [];
ontologyClasses: ClassToSelect[] = [];

loading = false;

Expand Down Expand Up @@ -136,15 +142,12 @@ export class PropertyFormComponent implements OnInit {

this.loading = true;

// set various lists to select from
this._cache.get('currentOntology').subscribe(
(response: ReadOntology) => {
this.ontology = response;
this.lastModificationDate = response.lastModificationDate;

// set various lists to select from
// a) in case of link value:
// set list of resource classes from response; needed for linkValue
this.resourceClasses = response.getAllClassDefinitions();
const resourceProperties = response.getAllPropertyDefinitions();

// set list of all existing resource property names to avoid same name twice
Expand All @@ -156,7 +159,7 @@ export class PropertyFormComponent implements OnInit {
});

// add all resource classes to the same list
this.resourceClasses.forEach((resClass: ClassDefinition) => {
response.getAllClassDefinitions().forEach((resClass: ClassDefinition) => {
const name = this._os.getNameFromIri(resClass.id);
this.existingNames.push(
new RegExp('(?:^|W)' + name.toLowerCase() + '(?:$|W)')
Expand All @@ -169,8 +172,25 @@ export class PropertyFormComponent implements OnInit {
}
);

// b) in case of list value:s
// a) in case of link value:
// set list of resource classes from response; needed for linkValue
this._cache.get('currentProjectOntologies').subscribe(
(response: ReadOntology[]) => {
// reset list of ontology classes
this.ontologyClasses = [];
response.forEach(onto => {
const ontoClasses: ClassToSelect = {
ontologyId: onto.id,
ontologyLabel: onto.label,
classes: onto.getAllClassDefinitions()
};
this.ontologyClasses.push(ontoClasses);
});

}
);

// b) in case of list value:
// set list of lists; needed for listValue
this._cache.get('currentOntologyLists').subscribe(
(response: ListNodeInfo[]) => {
Expand Down

0 comments on commit 8dcdd8f

Please sign in to comment.