From 0d89b1493293f83e9096615f653a6094519d59f2 Mon Sep 17 00:00:00 2001 From: Rainer Killinger Date: Tue, 6 Aug 2019 13:02:07 +0200 Subject: [PATCH] feat: make SCContactPoint extend SCThing Refactor SCPerson and SCOrganization --- src/meta.ts | 85 +++++------ src/things/abstract/thing.ts | 1 + src/things/contact-point.ts | 136 ++++++++++++++++++ src/things/organization.ts | 8 ++ src/things/person.ts | 53 +------ test/resources/ContactPoint.1.json | 39 +++++ ...{Organization.json => Organization.1.json} | 0 test/resources/Organization.2.json | 26 ++++ test/resources/Person.3.json | 60 ++------ test/type.spec.ts | 12 ++ 10 files changed, 279 insertions(+), 141 deletions(-) create mode 100644 src/things/contact-point.ts create mode 100644 test/resources/ContactPoint.1.json rename test/resources/{Organization.json => Organization.1.json} (100%) create mode 100644 test/resources/Organization.2.json diff --git a/src/meta.ts b/src/meta.ts index 8b7ba031..1258dcd4 100644 --- a/src/meta.ts +++ b/src/meta.ts @@ -18,6 +18,7 @@ import {SCArticle, SCArticleMeta, SCArticleWithoutReferences} from './things/art import {SCBook, SCBookMeta, SCBookWithoutReferences} from './things/book'; import {SCBuilding, SCBuildingMeta, SCBuildingWithoutReferences} from './things/building'; import {SCCatalog, SCCatalogMeta, SCCatalogWithoutReferences} from './things/catalog'; +import {SCContactPoint, SCContactPointMeta, SCContactPointWithoutReferences} from './things/contact-point'; import {SCCourseOfStudies, SCCourseOfStudiesMeta, SCCourseOfStudiesWithoutReferences} from './things/course-of-studies'; import {SCDateSeries, SCDateSeriesMeta, SCDateSeriesWithoutReferences} from './things/date-series'; import {SCDiff, SCDiffMeta, SCDiffWithoutReferences} from './things/diff'; @@ -49,6 +50,7 @@ export const SCClasses: { [K in SCThingType]: object } = { 'book': SCBookMeta, 'building': SCBuildingMeta, 'catalog': SCCatalogMeta, + 'contact point': SCContactPointMeta, 'course of studies': SCCourseOfStudiesMeta, 'date series': SCDateSeriesMeta, 'diff': SCDiffMeta, @@ -76,6 +78,7 @@ export type SCThingsWithoutDiff = | SCBook | SCBuilding | SCCatalog + | SCContactPoint | SCCourseOfStudies | SCDateSeries | SCDish @@ -116,26 +119,27 @@ export type SCAssociatedThingWithoutReferences = THING extends SCBook ? SCBookWithoutReferences : THING extends SCBuilding ? SCBuildingWithoutReferences : THING extends SCCatalog ? SCCatalogWithoutReferences : - THING extends SCCourseOfStudies ? SCCourseOfStudiesWithoutReferences : - THING extends SCDateSeries ? SCDateSeriesWithoutReferences : - THING extends SCDiff ? SCDiffWithoutReferences : - THING extends SCDish ? SCDishWithoutReferences : - THING extends SCFavorite ? SCFavoriteWithoutReferences : - THING extends SCFloor ? SCFloorWithoutReferences : - THING extends SCMessage ? SCMessageWithoutReferences : - THING extends SCOrganization ? SCOrganizationWithoutReferences : - THING extends SCPerson ? SCPersonWithoutReferences : - THING extends SCPointOfInterest ? SCPointOfInterestWithoutReferences : - THING extends SCRoom ? SCRoomWithoutReferences : - THING extends SCSemester ? SCSemesterWithoutReferences : - THING extends SCSetting ? SCSettingWithoutReferences : - THING extends SCSportCourse ? SCSportCourseWithoutReferences : - THING extends SCStudyModule ? SCStudyModuleWithoutReferences : - THING extends SCTicket ? SCTicketWithoutReferences : - THING extends SCToDo ? SCToDoWithoutReferences : - THING extends SCTour ? SCTourWithoutReferences : - THING extends SCVideo ? SCVideoWithoutReferences : - never; + THING extends SCContactPoint ? SCContactPointWithoutReferences : + THING extends SCCourseOfStudies ? SCCourseOfStudiesWithoutReferences : + THING extends SCDateSeries ? SCDateSeriesWithoutReferences : + THING extends SCDiff ? SCDiffWithoutReferences : + THING extends SCDish ? SCDishWithoutReferences : + THING extends SCFavorite ? SCFavoriteWithoutReferences : + THING extends SCFloor ? SCFloorWithoutReferences : + THING extends SCMessage ? SCMessageWithoutReferences : + THING extends SCOrganization ? SCOrganizationWithoutReferences : + THING extends SCPerson ? SCPersonWithoutReferences : + THING extends SCPointOfInterest ? SCPointOfInterestWithoutReferences : + THING extends SCRoom ? SCRoomWithoutReferences : + THING extends SCSemester ? SCSemesterWithoutReferences : + THING extends SCSetting ? SCSettingWithoutReferences : + THING extends SCSportCourse ? SCSportCourseWithoutReferences : + THING extends SCStudyModule ? SCStudyModuleWithoutReferences : + THING extends SCTicket ? SCTicketWithoutReferences : + THING extends SCToDo ? SCToDoWithoutReferences : + THING extends SCTour ? SCTourWithoutReferences : + THING extends SCVideo ? SCVideoWithoutReferences : + never; /** * Thing for a thing without references @@ -146,23 +150,24 @@ export type SCAssociatedThing = THING extends SCBookWithoutReferences ? SCBook : THING extends SCBuildingWithoutReferences ? SCBuilding : THING extends SCCatalogWithoutReferences ? SCCatalog : - THING extends SCCourseOfStudiesWithoutReferences ? SCCourseOfStudies : - THING extends SCDateSeriesWithoutReferences ? SCDateSeries : - THING extends SCDiffWithoutReferences ? SCDiff : - THING extends SCDishWithoutReferences ? SCDish : - THING extends SCFavoriteWithoutReferences ? SCFavorite : - THING extends SCFloorWithoutReferences ? SCFloor : - THING extends SCMessageWithoutReferences ? SCMessage : - THING extends SCOrganizationWithoutReferences ? SCOrganization : - THING extends SCPersonWithoutReferences ? SCPerson : - THING extends SCPointOfInterestWithoutReferences ? SCPointOfInterest : - THING extends SCRoomWithoutReferences ? SCRoom : - THING extends SCSemesterWithoutReferences ? SCSemester : - THING extends SCSettingWithoutReferences ? SCSetting : - THING extends SCSportCourseWithoutReferences ? SCSportCourse : - THING extends SCStudyModuleWithoutReferences ? SCStudyModule : - THING extends SCTicketWithoutReferences ? SCTicket : - THING extends SCToDoWithoutReferences ? SCToDo : - THING extends SCTourWithoutReferences ? SCTour : - THING extends SCVideoWithoutReferences ? SCVideo : - never; + THING extends SCContactPointWithoutReferences ? SCContactPoint : + THING extends SCCourseOfStudiesWithoutReferences ? SCCourseOfStudies : + THING extends SCDateSeriesWithoutReferences ? SCDateSeries : + THING extends SCDiffWithoutReferences ? SCDiff : + THING extends SCDishWithoutReferences ? SCDish : + THING extends SCFavoriteWithoutReferences ? SCFavorite : + THING extends SCFloorWithoutReferences ? SCFloor : + THING extends SCMessageWithoutReferences ? SCMessage : + THING extends SCOrganizationWithoutReferences ? SCOrganization : + THING extends SCPersonWithoutReferences ? SCPerson : + THING extends SCPointOfInterestWithoutReferences ? SCPointOfInterest : + THING extends SCRoomWithoutReferences ? SCRoom : + THING extends SCSemesterWithoutReferences ? SCSemester : + THING extends SCSettingWithoutReferences ? SCSetting : + THING extends SCSportCourseWithoutReferences ? SCSportCourse : + THING extends SCStudyModuleWithoutReferences ? SCStudyModule : + THING extends SCTicketWithoutReferences ? SCTicket : + THING extends SCToDoWithoutReferences ? SCToDo : + THING extends SCTourWithoutReferences ? SCTour : + THING extends SCVideoWithoutReferences ? SCVideo : + never; diff --git a/src/things/abstract/thing.ts b/src/things/abstract/thing.ts index 75bd3594..793aee14 100644 --- a/src/things/abstract/thing.ts +++ b/src/things/abstract/thing.ts @@ -27,6 +27,7 @@ export enum SCThingType { Book = 'book', Building = 'building', Catalog = 'catalog', + ContactPoint = 'contact point', CourseOfStudies = 'course of studies', DateSeries = 'date series', Diff = 'diff', diff --git a/src/things/contact-point.ts b/src/things/contact-point.ts new file mode 100644 index 00000000..ec4b0275 --- /dev/null +++ b/src/things/contact-point.ts @@ -0,0 +1,136 @@ +/* + * Copyright (C) 2019 StApps + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +import {SCMetaTranslations} from '../general/i18n'; +import { + SCThing, + SCThingMeta, + SCThingType, + SCThingWithoutReferences, + } from './abstract/thing'; +import {SCRoomWithoutReferences} from './room'; + +/** + * A contact point without references + */ +export interface SCContactPointWithoutReferences + extends SCThingWithoutReferences { + /** + * E-mail at the work location + * + * @keyword + */ + email?: string; + + /** + * Fax number at the work location + * + * @keyword + */ + faxNumber?: string; + + /** + * Office hours for contacting someone at the work location + * + * @see http://wiki.openstreetmap.org/wiki/Key:opening_hours/specification + * @keyword + */ + officeHours?: string; + + /** + * Contact number at the work location + * + * @keyword + */ + telephone?: string; + + /** + * Type of a contact point + */ + type: SCThingType.ContactPoint; + + /** + * URL at the work location + * + * @keyword + */ + url?: string; +} + +/** + * A contact point + * + * @see http://schema.org/ContactPoint + * + * @validatable + * @indexable + */ +export interface SCContactPoint + extends SCContactPointWithoutReferences, SCThing { + /** + * Exact place where work is performed + */ + areaServed?: SCRoomWithoutReferences; + + /** + * Type of a contact point + */ + type: SCThingType.ContactPoint; +} + +/** + * Meta information about a contact point + */ +export class SCContactPointMeta + extends SCThingMeta + implements SCMetaTranslations { + /** + * Translations of fields + */ + fieldTranslations = { + de: { + ...SCThingMeta.getInstance().fieldTranslations.de, + areaServed: 'Arbeitsraum', + email: 'E-Mail-Addresse', + faxNumber: 'Faxnummer', + officeHours: 'Sprechzeiten', + telephone: 'Telefonnummer', + url: 'Link', + }, + en: { + ...SCThingMeta.getInstance().fieldTranslations.en, + areaServed: 'location', + email: 'email address', + faxNumber: 'fax number', + officeHours: 'office hours', + telephone: 'telephone number', + url: 'link', + }, + }; + + /** + * Translations of values of fields + */ + fieldValueTranslations = { + de: { + ...SCThingMeta.getInstance().fieldValueTranslations.de, + type: 'Kontaktinformation', + }, + en: { + ...SCThingMeta.getInstance().fieldValueTranslations.en, + type: SCThingType.ContactPoint, + }, + }; +} diff --git a/src/things/organization.ts b/src/things/organization.ts index d1718a51..a45cb094 100644 --- a/src/things/organization.ts +++ b/src/things/organization.ts @@ -15,6 +15,7 @@ import {SCMetaTranslations} from '../general/i18n'; import {SCThingMeta, SCThingType, SCThingWithoutReferences} from './abstract/thing'; import {SCThingInPlace, SCThingInPlaceMeta} from './abstract/thing-in-place'; +import {SCContactPointWithoutReferences} from './contact-point'; /** * An organization without references @@ -35,6 +36,11 @@ export interface SCOrganizationWithoutReferences */ export interface SCOrganization extends SCOrganizationWithoutReferences, SCThingInPlace { + /** + * A list of contact points concerning the organization + */ + contactPoints?: SCContactPointWithoutReferences[]; + /** * Type of an organization */ @@ -52,9 +58,11 @@ export class SCOrganizationMeta fieldTranslations = { de: { ...SCThingInPlaceMeta.getInstance().fieldTranslations.de, + contactPoints: 'Kontaktinformationen', }, en: { ...SCThingInPlaceMeta.getInstance().fieldTranslations.en, + contactPoints: 'contact details', }, }; diff --git a/src/things/person.ts b/src/things/person.ts index 1515f967..4543cdcb 100644 --- a/src/things/person.ts +++ b/src/things/person.ts @@ -16,6 +16,7 @@ import {SCMetaTranslations, SCNationality} from '../general/i18n'; import {SCISO8601Date} from '../general/time'; import {SCThing, SCThingMeta, SCThingType, SCThingWithoutReferences} from './abstract/thing'; import {SCBuildingWithoutReferences} from './building'; +import {SCContactPointWithoutReferences} from './contact-point'; import {SCOrganizationWithoutReferences} from './organization'; import {SCPointOfInterestWithoutReferences} from './point-of-interest'; import {SCRoomWithoutReferences} from './room'; @@ -159,7 +160,7 @@ export interface SCPerson /** * Locations where the person performs her/his work */ - workLocations?: SCContactPoint[]; + workLocations?: SCContactPointWithoutReferences[]; } /** @@ -188,13 +189,14 @@ export class SCPersonMeta jobTitles: 'Berufsbezeichnungen', nationality: 'Staatsangehörigkeit', telephone: 'Telefonnummer', - workLocations: 'Arbeitsorte', + workLocations: 'Arbeitsstandorte', }, en: { ...SCThingMeta.getInstance().fieldTranslations.en, additionalName: 'additional name', affiliations: 'affiliations', birthDate: 'birth date', + contactDetails: 'contact details', email: 'email', familyName: 'family name', faxNumber: 'fax', @@ -231,53 +233,6 @@ export class SCPersonMeta }; } -/** - * A contact point - * - * @see http://schema.org/ContactPoint - */ -export interface SCContactPoint { - /** - * Exact place where work is performed - */ - areaServed?: SCRoomWithoutReferences; - - /** - * E-mail at the work location - * - * @keyword - */ - email?: string; - - /** - * Fax number at the work location - * - * @keyword - */ - faxNumber?: string; - - /** - * Times available for contacting at the work location - * - * @keyword - */ - hoursAvailable?: string; - - /** - * Contact number at the work location - * - * @keyword - */ - telephone?: string; - - /** - * URL at the work location - * - * @keyword - */ - url?: string; -} - /** * Gender of a person */ diff --git a/test/resources/ContactPoint.1.json b/test/resources/ContactPoint.1.json new file mode 100644 index 00000000..938874e9 --- /dev/null +++ b/test/resources/ContactPoint.1.json @@ -0,0 +1,39 @@ +{ + "errorNames": [], + "instance": { + "type": "contact point", + "name": "Dienstadresse", + "areaServed": { + "type": "room", + "categories": [ + "education" + ], + "uid": "39c1a574-04ef-5157-9c6f-e271d93eb273", + "name": "3.G 121", + "alternateNames": [ + "Dienstzimmer" + ], + "geo": { + "point": { + "coordinates": [ + 8.66919, + 50.12834 + ], + "type": "Point" + } + } + }, + "email": "info@example.com", + "faxNumber": "069 / 123450", + "officeHours": "Mo, Mi 8:00-13:00", + "telephone": "069 / 12345", + "url": "https://example.com", + "uid": "be34a419-e9e8-5de0-b998-dd1b19e7beef", + "origin": { + "indexed": "2018-09-11T12:30:00Z", + "name": "Dummy", + "type": "remote" + } + }, + "schema": "SCContactPoint" +} diff --git a/test/resources/Organization.json b/test/resources/Organization.1.json similarity index 100% rename from test/resources/Organization.json rename to test/resources/Organization.1.json diff --git a/test/resources/Organization.2.json b/test/resources/Organization.2.json new file mode 100644 index 00000000..55fa8f11 --- /dev/null +++ b/test/resources/Organization.2.json @@ -0,0 +1,26 @@ +{ + "errorNames": [], + "instance": { + "type": "organization", + "uid": "20e48393-0d2b-5bdc-9d92-5e0dc1e2860f", + "contactPoints": [ + { + "type": "contact point", + "name": "Dienstadresse", + "email": "info@example.com", + "faxNumber": "069 / 123450", + "officeHours": "Mo, Mi 8:00-13:00", + "telephone": "069 / 12345", + "url": "https://example.com", + "uid": "be34a419-e9e8-5de0-b998-dd1b19e7beef" + } + ], + "name": "Technische Universität Berlin", + "origin": { + "indexed": "2018-09-11T12:30:00Z", + "name": "Dummy", + "type": "remote" + } + }, + "schema": "SCOrganization" +} diff --git a/test/resources/Person.3.json b/test/resources/Person.3.json index ed3f6093..f55a2dde 100644 --- a/test/resources/Person.3.json +++ b/test/resources/Person.3.json @@ -17,58 +17,14 @@ "uid": "be34a419-e9e8-5de0-b998-dd1b19e7f451", "workLocations": [ { - "url": "http://www.fb03.uni-frankfurt.de/1234567", - "email": "mustermann@soz.uni-frankfurt.de", - "faxNumber": "", - "telephone": "069/123-36232; -1324325", - "hoursAvailable": "siehe Homepage", - "areaServed": { - "type": "room", - "categories": [ - "education" - ], - "uid": "39c1a574-04ef-5157-9c6f-e271d93eb273", - "name": "3.G 121", - "alternateNames": [ - "Dienstzimmer" - ], - "geo": { - "point": { - "coordinates": [ - 8.66919, - 50.12834 - ], - "type": "Point" - } - } - } - }, - { - "url": "http://www2.uni-frankfurt.de/12345/vizepraesidenten", - "email": "", - "faxNumber": "", - "telephone": "069/123-1235", - "hoursAvailable": "siehe Homepage", - "areaServed": { - "type": "room", - "categories": [ - "education" - ], - "uid": "5e54aefd-078b-5007-bca1-53dc60f79d37", - "name": "4.P 22", - "alternateNames": [ - "Dienstzimmer" - ], - "geo": { - "point": { - "coordinates": [ - 8.66898, - 50.12772 - ], - "type": "Point" - } - } - } + "type": "contact point", + "name": "Dienstadresse", + "email": "info@example.com", + "faxNumber": "069 / 123450", + "officeHours": "Mo, Mi 8:00-13:00", + "telephone": "069 / 12345", + "url": "https://example.com", + "uid": "be34a419-e9e8-5de0-b998-dd1b19e7beef" } ], "origin": { diff --git a/test/type.spec.ts b/test/type.spec.ts index 97d381e5..090823e2 100644 --- a/test/type.spec.ts +++ b/test/type.spec.ts @@ -19,6 +19,7 @@ import {SCArticle, SCArticleWithoutReferences} from '../src/things/article'; import {SCBook, SCBookWithoutReferences} from '../src/things/book'; import {SCBuilding, SCBuildingWithoutReferences} from '../src/things/building'; import {SCCatalog, SCCatalogWithoutReferences} from '../src/things/catalog'; +import {SCContactPoint, SCContactPointWithoutReferences} from '../src/things/contact-point'; import {SCCourseOfStudies, SCCourseOfStudiesWithoutReferences} from '../src/things/course-of-studies'; import {SCDateSeries, SCDateSeriesWithoutReferences} from '../src/things/date-series'; import {SCDiff, SCDiffWithoutReferences} from '../src/things/diff'; @@ -126,6 +127,17 @@ assert>(false); assert>(false); assert>(true); +/** + * Types of properties of SCContactPoint + */ +type SCContactPointPropertyTypes = PropertyTypesNested; +assert>(false); +assert>(true); +assert>(true); +assert>(false); +assert>(false); +assert>(true); + /** * Types of properties of SCCatalog */