Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ontology): class and property name has to be unique (DEV-183) #569

Merged
merged 2 commits into from Oct 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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