Skip to content

Commit

Permalink
Merge pull request #21 from musale/update/add-references-node
Browse files Browse the repository at this point in the history
Adds TLC Elements
  • Loading branch information
SmoDav authored Sep 24, 2018
2 parents 1b0fd06 + 607476b commit f946112
Show file tree
Hide file tree
Showing 25 changed files with 615 additions and 5 deletions.
46 changes: 41 additions & 5 deletions __tests__/level_1_act_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import { Body } from '../src/Elements/RootContainers/Body';
import { Conclusions } from '../src/Elements/RootContainers/Conclusions';
import { Attachments } from '../src/Elements/RootContainers/Attachments';
import { Components } from '../src/Elements/RootContainers/Components';
import { References } from '../src/Elements/Core/References';
import { Identification } from '../src/Elements/Core/Identification';
import { TLCConcept } from '../src/Elements/Core/TLCConcept';
import { SourceAttribute, HrefAttribute } from '../src/Attributes';

const doc = new AKNDocument();
let act = new Act();
Expand All @@ -23,7 +27,7 @@ const components = new Components();
/**
* Act test
*/
describe("Level 1 Act test", () => {
describe('Level 1 Act test', () => {
// it('validates the maximum element count', () => {
// expect(() => {
// act = new Act();
Expand All @@ -44,25 +48,31 @@ describe("Level 1 Act test", () => {
act = new Act();
act.appendChild(meta);
act.appendChild(conclusions);
}).toThrow('The child node conclusions is unexpected. Expected is one of coverPage, preface, preamble, body');
}).toThrow(
'The child node conclusions is unexpected. Expected is one of coverPage, preface, preamble, body'
);

expect(() => {
act = new Act();
act.appendChild(meta);
act.appendChild(body);
act.appendChild(preamble);
}).toThrow('The child node preamble is expected before the current last child(body). Expected is one of conclusions, attachments, components');
}).toThrow(
'The child node preamble is expected before the current last child(body). Expected is one of conclusions, attachments, components'
);

expect(() => {
act = new Act();
act.appendChild(meta);
act.appendChild(body);
act.appendChild(conclusions);
act.appendChild(preamble);
}).toThrow('The child node preamble is expected before the current last child(conclusions). Expected is one of attachments, components');
}).toThrow(
'The child node preamble is expected before the current last child(conclusions). Expected is one of attachments, components'
);
});

it("validates the Act is generated successfully", () => {
it('validates the Act is generated successfully', () => {
act = new Act();
act.appendChild(meta);
act.appendChild(body);
Expand All @@ -71,3 +81,29 @@ describe("Level 1 Act test", () => {
expect(act.getNode().childNodes.length).toBe(3);
});
});

describe('Create act with references', () => {
it('creates a references node', () => {
const actTest = new Act();
const metaTest = new Meta();
const identificationTest = new Identification();
const tlcconcept = new TLCConcept();
const referencesTest = new References();

identificationTest.setAttribute(new SourceAttribute('#tester'));
referencesTest.setAttribute(new SourceAttribute('#tester'));

tlcconcept.setAttribute(new HrefAttribute('#testConcept'));
expect(()=>{tlcconcept.validate()}).toThrow(
'Element TLCConcept is missing required attributes: ShowAsAttribute'
);

actTest.appendChild(metaTest);
metaTest.appendChild(identificationTest);
metaTest.appendChild(referencesTest);

expect(actTest.getNode().childNodes.length).toBe(1);
expect(actTest.getNode().childNodes[0].childNodes.length).toBe(2);

});
});
37 changes: 37 additions & 0 deletions src/ComplexTypes/RefItems.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { AttributeGroupItem } from "../Interfaces/AttributeGroupItem";
import { HasChildrenMap } from "../Interfaces/HasChildrenMap";
import { NodeRules } from "../Interfaces/NodeRules";
import { TLCs } from "../ElementGroups/TLCs";
import { DocRefs } from "../ElementGroups/DocRefs";
import { ReferenceType } from "./ReferenceType";

/**
* The complex type refItems is a list of types of references
* used in the references section.
*/
export class RefItems implements HasChildrenMap {
readonly CHILDREN_MAP: NodeRules = {
refItemsChoices: {
choice: true,
minOccur: 1,
options: {
tlcsGroup: {
choice: true,
minOccur: 1,
maxOccur: 1,
options: { ...(new TLCs()).CHILDREN_MAP }
},
docrefGroup: {
choice: true,
minOccur: 1,
maxOccur: 1,
options: { ...(new DocRefs()).CHILDREN_MAP }
}
}
}
};

readonly ATTRIBUTE_GROUPS: AttributeGroupItem[] = [
...(new ReferenceType()).ATTRIBUTE_GROUPS
];
}
20 changes: 20 additions & 0 deletions src/ComplexTypes/ReferenceType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { AttributeGroupItem } from "../Interfaces/AttributeGroupItem";
import { HasChildrenMap } from "../Interfaces/HasChildrenMap";
import { NodeRules } from "../Interfaces/NodeRules";
import { Core, Idreq, Link, Show } from "../AttributeGroups";

/**
* The complex type referenceType defines the empty content model
* and the list of attributes for metadata elements in the
* references section
*/
export class ReferenceType implements HasChildrenMap {
readonly CHILDREN_MAP: NodeRules = {};

readonly ATTRIBUTE_GROUPS: AttributeGroupItem[] = [
...(new Core()).items,
...(new Idreq()).items,
...(new Link()).items,
...(new Show()).items
];
}
2 changes: 2 additions & 0 deletions src/ComplexTypes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export { ModType } from './ModType';
export { Preambleopt } from './Preambleopt';
export { Prefaceopt } from './Prefaceopt';
export { RecitalHierarchy } from './RecitalHierarchy';
export { RefItems } from './RefItems';
export { ReferenceType } from './ReferenceType';
export { SrcType } from './SrcType';
export { SubFlowStructure } from './SubFlowStructure';
export { ValueType } from './ValueType';
26 changes: 26 additions & 0 deletions src/ElementGroups/DocRefs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { AttributeGroupItem } from "../Interfaces/AttributeGroupItem";
import { HasChildrenMap } from "../Interfaces/HasChildrenMap";
import { NodeRules } from "../Interfaces/NodeRules";

/**
* The group docrefs is a list of types of legal references to documents.
*/
export class DocRefs implements HasChildrenMap {
readonly CHILDREN_MAP: NodeRules = {
docRefChoices: {
choice: true,
maxOccur: 1,
minOccur: 1,
options: {
original: { minOccur: 1, maxOccur: 1, options: {} },
passiveRef: { minOccur: 1, maxOccur: 1, options: {} },
activeRef: { minOccur: 1, maxOccur: 1, options: {} },
jurisprudence: { minOccur: 1, maxOccur: 1, options: {} },
hasAttachment: { minOccur: 1, maxOccur: 1, options: {} },
attachmentOf: { minOccur: 1, maxOccur: 1, options: {} }
}
}
};

readonly ATTRIBUTE_GROUPS: AttributeGroupItem[] = [];
}
39 changes: 39 additions & 0 deletions src/ElementGroups/TLCs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { AttributeGroupItem } from "../Interfaces/AttributeGroupItem";
import { HasChildrenMap } from "../Interfaces/HasChildrenMap";
import { NodeRules } from "../Interfaces/NodeRules";
import {
EIdAttribute,
ShowAsAttribute,
HrefAttribute,
ShortFormAttribute,
GUIDAttribute,
WIdAttribute
} from "../Attributes";

/**
* The group TLCs is a list of types of Top Level classes of
* the Akoma Ntoso ontology.
*/
export class TLCs implements HasChildrenMap {
readonly CHILDREN_MAP: NodeRules = {
TLCChoices: {
choice: true,
maxOccur: 1,
minOccur: 1,
options: {
TLCPerson: { minOccur: 1, maxOccur: 1, options: {} },
TLCOrganization: { minOccur: 1, maxOccur: 1, options: {} },
TLCConcept: { minOccur: 1, maxOccur: 1, options: {} },
TLCObject: { minOccur: 1, maxOccur: 1, options: {} },
TLCEvent: { minOccur: 1, maxOccur: 1, options: {} },
TLCLocation: { minOccur: 1, maxOccur: 1, options: {} },
TLCProcess: { minOccur: 1, maxOccur: 1, options: {} },
TLCRole: { minOccur: 1, maxOccur: 1, options: {} },
TLCTerm: { minOccur: 1, maxOccur: 1, options: {} },
TLCReference: { minOccur: 1, maxOccur: 1, options: {} }
}
}
};

readonly ATTRIBUTE_GROUPS: AttributeGroupItem[] = [];
}
24 changes: 24 additions & 0 deletions src/Elements/Core/ActiveRef.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { AbstractNode } from '../../Abstracts/AbstractNode';
import { AttributeGroupItem } from '../../Interfaces/AttributeGroupItem';
import { NodeRules } from '../../Interfaces/NodeRules';
import { ReferenceType } from '../../ComplexTypes/ReferenceType';

const type = new ReferenceType();
/**
* The element activeRef is a metadata reference to the
* Akoma Ntoso IRI of a document that is modified by this
* document (i.e., an active references)
*/
export class ActiveRef extends AbstractNode {
abbreviation = '';

getNodeName(): string {
return 'activeRef';
}

readonly CHILDREN_MAP: NodeRules = type.CHILDREN_MAP;

readonly SEQUENCE: string[] = [];

readonly ATTRIBUTE_GROUPS: AttributeGroupItem[] = type.ATTRIBUTE_GROUPS;
}
28 changes: 28 additions & 0 deletions src/Elements/Core/AttachmentOf.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { AbstractNode } from "../../Abstracts/AbstractNode";
import { AttributeGroupItem } from "../../Interfaces/AttributeGroupItem";
import { NodeRules } from "../../Interfaces/NodeRules";
import { ReferenceType } from "../../ComplexTypes/ReferenceType";
import { Type } from "../../AttributeGroups";

const type = new ReferenceType();
/**
* The element attachmentOf is a metadata reference to
* the Akoma Ntoso IRI of a document of which this
* document is an attachment
*/
export class AttachmentOf extends AbstractNode {
abbreviation = "";

getNodeName(): string {
return "attachmentOf";
}

readonly CHILDREN_MAP: NodeRules = type.CHILDREN_MAP;

readonly SEQUENCE: string[] = [];

readonly ATTRIBUTE_GROUPS: AttributeGroupItem[] = [
...type.ATTRIBUTE_GROUPS,
...(new Type()).items
];
}
28 changes: 28 additions & 0 deletions src/Elements/Core/HasAttachment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { AbstractNode } from "../../Abstracts/AbstractNode";
import { AttributeGroupItem } from "../../Interfaces/AttributeGroupItem";
import { NodeRules } from "../../Interfaces/NodeRules";
import { ReferenceType } from "../../ComplexTypes/ReferenceType";
import { Type } from "../../AttributeGroups";

const type = new ReferenceType();
/**
* The element hasAttachment is a metadata reference to
* the Akoma Ntoso IRI of a document of which this
* document is an attachment
*/
export class HasAttachment extends AbstractNode {
abbreviation = "";

getNodeName(): string {
return "hasAttachment";
}

readonly CHILDREN_MAP: NodeRules = type.CHILDREN_MAP;

readonly SEQUENCE: string[] = [];

readonly ATTRIBUTE_GROUPS: AttributeGroupItem[] = [
...type.ATTRIBUTE_GROUPS,
...(new Type()).items
];
}
24 changes: 24 additions & 0 deletions src/Elements/Core/Jurisprudence.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { AbstractNode } from "../../Abstracts/AbstractNode";
import { AttributeGroupItem } from "../../Interfaces/AttributeGroupItem";
import { NodeRules } from "../../Interfaces/NodeRules";
import { ReferenceType } from "../../ComplexTypes/ReferenceType";

const type = new ReferenceType();
/**
* The element jurisprudence is a metadata reference to
* the Akoma Ntoso IRI of a document of which this
* document is an attachment
*/
export class Jurisprudence extends AbstractNode {
abbreviation = "";

getNodeName(): string {
return "jurisprudence";
}

readonly CHILDREN_MAP: NodeRules = type.CHILDREN_MAP;

readonly SEQUENCE: string[] = [];

readonly ATTRIBUTE_GROUPS: AttributeGroupItem[] = type.ATTRIBUTE_GROUPS;
}
24 changes: 24 additions & 0 deletions src/Elements/Core/Original.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { AbstractNode } from '../../Abstracts/AbstractNode';
import { AttributeGroupItem } from '../../Interfaces/AttributeGroupItem';
import { NodeRules } from '../../Interfaces/NodeRules';
import { ReferenceType } from '../../ComplexTypes/ReferenceType';

const type = new ReferenceType();
/**
* The element original is a metadata reference to the
* Akoma Ntoso IRI of the original version of this
* document (i.e., the first expression)
*/
export class Original extends AbstractNode {
abbreviation = '';

getNodeName(): string {
return 'original';
}

readonly CHILDREN_MAP: NodeRules = type.CHILDREN_MAP;

readonly SEQUENCE: string[] = [];

readonly ATTRIBUTE_GROUPS: AttributeGroupItem[] = type.ATTRIBUTE_GROUPS;
}
24 changes: 24 additions & 0 deletions src/Elements/Core/PassiveRef.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { AbstractNode } from "../../Abstracts/AbstractNode";
import { AttributeGroupItem } from "../../Interfaces/AttributeGroupItem";
import { NodeRules } from "../../Interfaces/NodeRules";
import { ReferenceType } from "../../ComplexTypes/ReferenceType";

const type = new ReferenceType();
/**
* The element passiveRef is a metadata reference to the
* Akoma Ntoso IRI of a document providing modifications
* on this document (i.e., a passive references)
*/
export class PassiveRef extends AbstractNode {
abbreviation = "";

getNodeName(): string {
return "passiveRef";
}

readonly CHILDREN_MAP: NodeRules = type.CHILDREN_MAP;

readonly SEQUENCE: string[] = [];

readonly ATTRIBUTE_GROUPS: AttributeGroupItem[] = type.ATTRIBUTE_GROUPS;
}
Loading

0 comments on commit f946112

Please sign in to comment.