Skip to content
Permalink
Browse files
fix(ontology): class and property name has to be unique (DEV-183) (#569)
* 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 059dd2a48a8346b0f8835223c5d9fb86e05cefed
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 29 deletions.
@@ -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>
@@ -8,6 +8,7 @@ import {
IHasProperty,
KnoraApiConnection,
ListNodeInfo,
PropertyDefinition,
ReadOntology,
ResourceClassDefinitionWithAllLanguages,
ResourcePropertyDefinitionWithAllLanguages,
@@ -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[]) => {
@@ -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,
@@ -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);

0 comments on commit 059dd2a

Please sign in to comment.