import { AttributeType } from "../../../attribute"; import { BusinessObjectType } from "../../../businessObjectType"; import { IAttributeReadingAuthorizationJSON } from "./iAttributeReadingAuthorizationJSON"; import { IAttributeReadingAuthorizationModelFormat } from "./iAttributeReadingAuthorizationModelFormat"; /** * An `AttributeReadingTableAuthorization` defines whether or not an attribute type can be read by a given participant types * * @specfield attributeType: attribute type over which the authorization is defined * @specfield participantType: participant type for which the authorization is defined * @specfield allowed: defines whether or not this.participantType has access ot this.attributeType */ export class AttributeReadingAuthorization { //================================ Representation ================================ private attributeType: AttributeType; private participantType: BusinessObjectType; private allowed: boolean; //================================= Constructor ================================== /** * Creates a new AttributeReadingAuthorization ara so that: * * ara.attribuetType = attributeType && * * ara.participantType = participantType && * * ara.allowed = allowed * @throws an error in case participantType is not actually a participant type * @param attributeType Type of attribute over which the authorization is defined * @param participantType Participant type for which the authorization is defined * @param allowed Whether or not participantType can read attributeType */ public constructor(attributeType: AttributeType, participantType: BusinessObjectType, allowed: boolean) { if(!participantType.isParticipant()) throw new Error(`[AtttributetReadingAuthorizatiton.constructor(...)]: provided business object type must be a participant type`); this.attributeType = attributeType; this.participantType = participantType; this.allowed = allowed; } //=================================== Getters ==================================== /** * @willreturn this.allowed */ public isAllowed(): boolean { return this.allowed; } //=================================== Other ==================================== public toJSON(): IAttributeReadingAuthorizationJSON { return { attributeType: this.attributeType.toJSON(), participantType: this.participantType.toJSON(), allowed: this.allowed }; } public toModelFormat(): IAttributeReadingAuthorizationModelFormat { return { attributeType: this.attributeType.getId(), participantType: this.participantType.getId(), allowed: this.allowed }; } }