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

refactor: update constants (DSP-1187) #263

Merged
merged 3 commits into from
Jan 21, 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
2 changes: 1 addition & 1 deletion projects/dsp-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@angular/core": "^9.0.0",
"@angular/material": "^9.0.0",
"@angular/cdk": "^9.0.0",
"@dasch-swiss/dsp-js": "^1.0.1",
"@dasch-swiss/dsp-js": "^1.1.0",
"jdnconvertiblecalendar": "^0.0.5",
"jdnconvertiblecalendardateadapter": "^0.0.13",
"ngx-color-picker": "^10.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import { MatTooltipModule } from '@angular/material/tooltip';
import { By } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import {
ApiResponseError, Constants,
ApiResponseError,
Constants,
DeleteValue,
DeleteValueResponse,
MockResource,
Expand Down Expand Up @@ -303,13 +304,13 @@ class TestHostDisplayValueComponent implements OnInit {
standoffLinkVal.linkedResourceIri = 'testIri';

const propDefinition = this.readResource.entityInfo.properties['http://0.0.0.0:3333/ontology/0001/anything/v2#hasOtherThingValue'];
propDefinition.id = 'http://api.knora.org/ontology/knora-api/v2#hasStandoffLinkToValue';
propDefinition.id = Constants.HasStandoffLinkToValue;

const guiDefinition = this.readResource.entityInfo.classes['http://0.0.0.0:3333/ontology/0001/anything/v2#Thing'].propertiesList.filter(
propDefForGui => propDefForGui.propertyIndex === 'http://0.0.0.0:3333/ontology/0001/anything/v2#hasOtherThingValue'
);

guiDefinition[0].propertyIndex = 'http://api.knora.org/ontology/knora-api/v2#hasStandoffLinkToValue';
guiDefinition[0].propertyIndex = Constants.HasStandoffLinkToValue;

const propInfo: PropertyInfoValues = {
values: [standoffLinkVal],
Expand Down Expand Up @@ -706,15 +707,15 @@ describe('DisplayEditComponent', () => {
it('should choose the apt component for a link value (standoff link) in the template', () => {

testHostComponent.assignValue('http://0.0.0.0:3333/ontology/0001/anything/v2#hasOtherThingValue');
testHostComponent.readValue.property = Constants.KnoraApiV2 + Constants.HashDelimiter + 'hasStandoffLinkToValue';
testHostComponent.readValue.property = Constants.HasStandoffLinkToValue;
testHostComponent.readValue.attachedToUser = 'http://www.knora.org/ontology/knora-admin#SystemUser'; // sstandoff links are managed by the system
testHostFixture.detectChanges();

expect(testHostComponent.displayEditValueComponent.displayValueComponent instanceof TestLinkValueComponent).toBe(true);
expect(testHostComponent.displayEditValueComponent.displayValueComponent.displayValue instanceof ReadLinkValue).toBe(true);
expect(testHostComponent.displayEditValueComponent.displayValueComponent.mode).toEqual('read');
expect((testHostComponent.displayEditValueComponent.displayValueComponent as unknown as TestLinkValueComponent).parentResource instanceof ReadResource).toBe(true);
expect((testHostComponent.displayEditValueComponent.displayValueComponent as unknown as TestLinkValueComponent).propIri).toEqual('http://api.knora.org/ontology/knora-api/v2#hasStandoffLinkToValue');
expect((testHostComponent.displayEditValueComponent.displayValueComponent as unknown as TestLinkValueComponent).propIri).toEqual(Constants.HasStandoffLinkToValue);

const userServiceSpy = TestBed.inject(UserService);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export class DisplayEditComponent implements OnInit {
// find the PropertyInfoValues for the standoff link value
const standoffLinkPropInfoVals: PropertyInfoValues[] = this.propArray.filter(
resPropInfoVal => {
return resPropInfoVal.propDef.id === "http://api.knora.org/ontology/knora-api/v2#hasStandoffLinkToValue";
return resPropInfoVal.propDef.id === Constants.HasStandoffLinkToValue;
}
);

Expand Down
5 changes: 3 additions & 2 deletions projects/dsp-ui/src/lib/viewer/services/value.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { TestBed } from '@angular/core/testing';

import {
Constants,
KnoraDate, KnoraPeriod,
MockResource, ReadDateValue,
ReadIntValue, ReadLinkValue,
Expand Down Expand Up @@ -44,7 +45,7 @@ describe('ValueService', () => {

const readTextValueAsXml = new ReadTextValueAsXml();
readTextValueAsXml.type = 'http://api.knora.org/ontology/knora-api/v2#TextValue';
readTextValueAsXml.mapping = 'http://rdfh.ch/standoff/mappings/StandardMapping';
readTextValueAsXml.mapping = Constants.StandardMapping;
expect(service.isTextEditable(readTextValueAsXml)).toBeTruthy();

});
Expand Down Expand Up @@ -153,7 +154,7 @@ describe('ValueService', () => {
it('should not mark ReadTextValueAsXml with standard mapping as ReadOnly', () => {
const readTextValueAsXml = new ReadTextValueAsXml();
readTextValueAsXml.type = 'http://api.knora.org/ontology/knora-api/v2#TextValue';
readTextValueAsXml.mapping = 'http://rdfh.ch/standoff/mappings/StandardMapping';
readTextValueAsXml.mapping = Constants.StandardMapping;

const resPropDef = new ResourcePropertyDefinition();
resPropDef.isEditable = true;
Expand Down
2 changes: 1 addition & 1 deletion projects/dsp-ui/src/lib/viewer/services/value.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export class ValueService {
* @param textValue the text value to be checked.
*/
isTextEditable(textValue: ReadTextValueAsXml): boolean {
return textValue.mapping === 'http://rdfh.ch/standoff/mappings/StandardMapping';
return textValue.mapping === Constants.StandardMapping;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { ControlValueAccessor, NG_VALUE_ACCESSOR, ReactiveFormsModule } from '@a
import { MatInputModule } from '@angular/material/input';
import { By } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { CreateTextValueAsXml, MockResource, ReadTextValueAsXml, UpdateTextValueAsXml } from '@dasch-swiss/dsp-js';
import { Constants, CreateTextValueAsXml, MockResource, ReadTextValueAsXml, UpdateTextValueAsXml } from '@dasch-swiss/dsp-js';
import { TextValueAsXMLComponent } from './text-value-as-xml.component';

/**
Expand Down Expand Up @@ -361,7 +361,7 @@ describe('TextValueAsXMLComponent', () => {
const newXml = new ReadTextValueAsXml();

newXml.xml = '<?xml version="1.0" encoding="UTF-8"?><text><p>my updated text</p></text>';
newXml.mapping = 'http://rdfh.ch/standoff/mappings/StandardMapping';
newXml.mapping = Constants.StandardMapping;

newXml.id = 'updatedId';

Expand Down Expand Up @@ -514,7 +514,7 @@ describe('TextValueAsXMLComponent', () => {
expect(newValue instanceof CreateTextValueAsXml).toBeTruthy();

expect((newValue as CreateTextValueAsXml).xml).toEqual('<?xml version="1.0" encoding="UTF-8"?><text><p>created text<p></p></text>');
expect((newValue as CreateTextValueAsXml).mapping).toEqual('http://rdfh.ch/standoff/mappings/StandardMapping');
expect((newValue as CreateTextValueAsXml).mapping).toEqual(Constants.StandardMapping);
});

it('should reset form after cancellation', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const resolvedPromise = Promise.resolve(null);
})
export class TextValueAsXMLComponent extends BaseValueComponent implements OnInit, OnChanges, OnDestroy {

readonly standardMapping = 'http://rdfh.ch/standoff/mappings/StandardMapping'; // TODO: define this somewhere else
readonly standardMapping = Constants.StandardMapping; // TODO: define this somewhere else

@Input() displayValue?: ReadTextValueAsXml;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { MatTooltipModule } from '@angular/material/tooltip';
import { By } from '@angular/platform-browser';
import {
ApiResponseError,
Constants,
IHasPropertyWithPropertyDefinition,
MockResource,
ReadLinkValue,
Expand Down Expand Up @@ -321,7 +322,7 @@ describe('PropertyViewComponent', () => {
it('should determine that adding a standoff link value is not allowed', () => {

const standoffLinkVal = testHostComponent.propArray.filter(
propVal => propVal.propDef.id === 'http://api.knora.org/ontology/knora-api/v2#hasStandoffLinkToValue'
propVal => propVal.propDef.id === Constants.HasStandoffLinkToValue
);

expect(testHostComponent.propertyViewComponent.addValueIsAllowed(standoffLinkVal[0])).toBeFalsy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { MatIconModule } from '@angular/material/icon';
import { MatSnackBarModule } from '@angular/material/snack-bar';
import { By } from '@angular/platform-browser';
import {
Constants,
DeleteValue,
MockResource,
PropertyDefinition,
Expand Down Expand Up @@ -263,10 +264,10 @@ describe('ResourceViewComponent', () => {

const linkVal = res.getValuesAs('http://0.0.0.0:3333/ontology/0001/anything/v2#hasOtherThingValue', ReadLinkValue);

linkVal[0].property = 'http://api.knora.org/ontology/knora-api/v2#hasStandoffLinkToValue';
linkVal[0].property = Constants.HasStandoffLinkToValue;
linkVal[0].linkedResourceIri = 'testId';

res.properties['http://api.knora.org/ontology/knora-api/v2#hasStandoffLinkToValue'] = linkVal;
res.properties[Constants.HasStandoffLinkToValue] = linkVal;

return new ReadResourceSequence([res]);
}
Expand All @@ -286,7 +287,7 @@ describe('ResourceViewComponent', () => {
);

const propArrStandoffLinkValues = testHostComponent.resourceViewComponent.resPropInfoVals.filter(
propInfoValueArray => propInfoValueArray.propDef.id === 'http://api.knora.org/ontology/knora-api/v2#hasStandoffLinkToValue'
propInfoValueArray => propInfoValueArray.propDef.id === Constants.HasStandoffLinkToValue
);

expect(propArrayXmlValues[0].values.length).toEqual(1);
Expand Down Expand Up @@ -408,7 +409,7 @@ describe('ResourceViewComponent', () => {
);

const existingStandoffLinkVal = testHostComponent.resourceViewComponent.resPropInfoVals.filter(
propInfo => propInfo.propDef.id === 'http://api.knora.org/ontology/knora-api/v2#hasStandoffLinkToValue'
propInfo => propInfo.propDef.id === Constants.HasStandoffLinkToValue
);

// add value
Expand All @@ -417,7 +418,7 @@ describe('ResourceViewComponent', () => {
const standoffLinkVal = new ReadLinkValue();

standoffLinkVal.linkedResourceIri = 'testId';
standoffLinkVal.property = 'http://api.knora.org/ontology/knora-api/v2#hasStandoffLinkToValue';
standoffLinkVal.property = Constants.HasStandoffLinkToValue;

// add corresponding link val
existingStandoffLinkVal[0].values.push(standoffLinkVal);
Expand Down Expand Up @@ -507,9 +508,9 @@ describe('ResourceViewComponent', () => {
const linkVal = res.getValuesAs('http://0.0.0.0:3333/ontology/0001/anything/v2#hasOtherThingValue', ReadLinkValue);

linkVal[0].linkedResourceIri = 'testId';
linkVal[0].property = 'http://api.knora.org/ontology/knora-api/v2#hasStandoffLinkToValue';
linkVal[0].property = Constants.HasStandoffLinkToValue;

res.properties['http://api.knora.org/ontology/knora-api/v2#hasStandoffLinkToValue'] = linkVal;
res.properties[Constants.HasStandoffLinkToValue] = linkVal;

return new ReadResourceSequence([res]);
}
Expand All @@ -530,7 +531,7 @@ describe('ResourceViewComponent', () => {
);

const propArrStandoffLinkValues = testHostComponent.resourceViewComponent.resPropInfoVals.filter(
propInfoValueArray => propInfoValueArray.propDef.id === 'http://api.knora.org/ontology/knora-api/v2#hasStandoffLinkToValue'
propInfoValueArray => propInfoValueArray.propDef.id === Constants.HasStandoffLinkToValue
);

propArrayXmlValues[0].values.push(newReadXmlValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,11 @@ export class ResourceViewComponent implements OnInit, OnChanges, OnDestroy {
return;
}

const newStandoffLinkVals = res.resources[0].getValuesAs('http://api.knora.org/ontology/knora-api/v2#hasStandoffLinkToValue', ReadLinkValue);
const newStandoffLinkVals = res.resources[0].getValuesAs(Constants.HasStandoffLinkToValue, ReadLinkValue);

this.resPropInfoVals.filter(
resPropInfoVal => {
return resPropInfoVal.propDef.id === 'http://api.knora.org/ontology/knora-api/v2#hasStandoffLinkToValue';
return resPropInfoVal.propDef.id === Constants.HasStandoffLinkToValue;
}
).forEach(
standoffLinkResPropInfoVal => {
Expand Down