Skip to content

Commit

Permalink
fix(ontology): class and property name has to be unique (DEV-183) (#569)
Browse files Browse the repository at this point in the history
* fix(ontology): class and property name has to be unique (DEV-183)

* chore(ontology): update comment
  • Loading branch information
kilchenmann committed Oct 29, 2021
1 parent 16f26ce commit 059dd2a
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 29 deletions.
Expand Up @@ -72,34 +72,40 @@

<!-- depending on type: display gui attribute -->
<div *ngIf="showGuiAttr" [ngSwitch]="propertyInfo.propType.objectType">
<mat-form-field class="large-field property-type" *ngSwitchCase="dspConstants.ListValue">
<span matPrefix class="property-type-icon">
<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;
</span>
<mat-label>Select list</mat-label>
<mat-label>Select list *</mat-label>
<mat-select formControlName="guiAttr">
<mat-option *ngFor="let item of lists" [value]="item.id">
{{item.labels[0].value}}
</mat-option>
</mat-select>
<mat-hint *ngIf="formErrors.guiAttr">
{{formErrors.guiAttr}}
</mat-hint>
</mat-form-field>

<mat-form-field class="large-field property-type" *ngSwitchCase="dspConstants.LinkValue">
<span matPrefix class="property-type-icon">
<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-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-select>
<mat-hint *ngIf="formErrors.guiAttr">
{{formErrors.guiAttr}}
</mat-hint>
</mat-form-field>

<!-- the gui-attribute for integer and decimal are not yet supported in the app -->
<mat-form-field class="large-field property-type"
<mat-form-field class="large-field property-type ontology-form-field"
*ngSwitchCase="propertyInfo.propType.objectType === dspConstants.IntValue || propertyInfo.propType.objectType === dspConstants.DecimalValue">
<span matPrefix class="property-type-icon">
<span matPrefix class="ontology-prefix-icon">
<mat-icon>{{guiAttrIcon}}</mat-icon>&nbsp;
</span>
<mat-label>Define range</mat-label>
Expand Down
30 changes: 20 additions & 10 deletions src/app/project/ontology/property-form/property-form.component.ts
Expand Up @@ -8,6 +8,7 @@ import {
IHasProperty,
KnoraApiConnection,
ListNodeInfo,
PropertyDefinition,
ReadOntology,
ResourceClassDefinitionWithAllLanguages,
ResourcePropertyDefinitionWithAllLanguages,
Expand Down Expand Up @@ -141,23 +142,32 @@ export class PropertyFormComponent implements OnInit {
// 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
resourceProperties.forEach((resProp: PropertyDefinition) => {
const name = this._os.getNameFromIri(resProp.id);
this.existingNames.push(
new RegExp('(?:^|W)' + name.toLowerCase() + '(?:$|W)')
);
});

// add all resource classes to the same list
this.resourceClasses.forEach((resClass: ClassDefinition) => {
const name = this._os.getNameFromIri(resClass.id);
this.existingNames.push(
new RegExp('(?:^|W)' + name.toLowerCase() + '(?:$|W)')
);
});

// set list of all existing property names to avoid same name twice
Object.entries(this.ontology.properties).forEach(
([key]) => {
const name = this._os.getNameFromIri(key);
this.existingNames.push(
new RegExp('(?:^|W)' + name.toLowerCase() + '(?:$|W)')
);
}
);
},
(error: ApiResponseError) => {
this._errorHandler.showMessage(error);
}
);

// b) in case of list value:
// b) in case of list value:s

// set list of lists; needed for listValue
this._cache.get('currentOntologyLists').subscribe(
(response: ListNodeInfo[]) => {
Expand Down
Expand Up @@ -2,8 +2,10 @@ import { AfterViewChecked, ChangeDetectorRef, Component, EventEmitter, Inject, I
import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
import {
ApiResponseError,
ClassDefinition,
CreateResourceClass,
KnoraApiConnection,
PropertyDefinition,
ReadOntology,
ResourceClassDefinitionWithAllLanguages,
StringLiteral,
Expand Down Expand Up @@ -146,17 +148,25 @@ export class ResourceClassFormComponent implements OnInit, AfterViewChecked {

this.lastModificationDate = this.ontology.lastModificationDate;

// get all ontology resource classes:
// can be used to select resource class as gui attribute in link property,
// but also to avoid same name which should be unique
Object.entries(this.ontology.classes).forEach(
([key]) => {
const name = this._os.getNameFromIri(key);
this.existingNames.push(
new RegExp('(?:^|W)' + name.toLowerCase() + '(?:$|W)')
);
}
);
const resourceClasses = response.getAllClassDefinitions();
const resourceProperties = response.getAllPropertyDefinitions();

// set list of all existing resource class names to avoid same name twice
resourceClasses.forEach((resClass: ClassDefinition) => {
const name = this._os.getNameFromIri(resClass.id);
this.existingNames.push(
new RegExp('(?:^|W)' + name.toLowerCase() + '(?:$|W)')
);
});

// add all resource properties to the same list
resourceProperties.forEach((resProp: PropertyDefinition) => {
const name = this._os.getNameFromIri(resProp.id);
this.existingNames.push(
new RegExp('(?:^|W)' + name.toLowerCase() + '(?:$|W)')
);
});

},
(error: ApiResponseError) => {
this._errorHandler.showMessage(error);
Expand Down

0 comments on commit 059dd2a

Please sign in to comment.