All files / src/objects domain.ts

95.88% Statements 93/97
85.19% Branches 46/54
100% Functions 7/7
95.88% Lines 93/97

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 971x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 92x 92x 1x 1x 5x 5x 1x 1x 2x 2x 2x 2x 2x 1x 1x 23x 23x 23x 23x 1x 1x 10x 4x 10x     6x 6x 6x 6x 1x 1x 25x 2x 2x 23x 23x 23x 23x 25x     23x 25x 25x 25x 25x 13x 52x 52x 52x 52x 52x 52x 52x 13x 23x 23x 25x 25x 25x 25x 25x 25x 25x 25x 25x 1x 1x 23x 23x 1x 1x
import {AbstractObject} from "./_abstract_object";
import {AbstractType} from "../abap/types/basic/_abstract_type";
import * as Types from "../abap/types/basic";
import {IRegistry} from "../_iregistry";
import {DDIC} from "../ddic";
 
export interface DomainValue {
  language: string,
  value: string,
  description: string
}
 
export class Domain extends AbstractObject {
 
  private parsedXML: {
    description?: string,
    datatype?: string,
    length?: string,
    decimals?: string,
    values?: DomainValue[],
  } | undefined;
  private parsedType: AbstractType | undefined;
 
  public getType(): string {
    return "DOMA";
  }
 
  public getDescription(): string | undefined {
    return this.parsedXML?.description;
  }
 
  public getAllowedNaming() {
    return {
      maxLength: 30,
      allowNamespace: true,
    };
  }
 
  public setDirty(): void {
    this.parsedXML = undefined;
    this.parsedType = undefined;
    super.setDirty();
  }
 
  public parseType(reg: IRegistry): AbstractType {
    if (this.parsedType) {
      return this.parsedType;
    } else if (this.parsedXML === undefined) {
      return new Types.UnknownType("Domain " + this.getName() + " parser error", this.getName());
    }
    const ddic = new DDIC(reg);
    this.parsedType = ddic.textToType(this.parsedXML.datatype, this.parsedXML.length, this.parsedXML.decimals, this.getName());
    return this.parsedType;
  }
 
  public parse() {
    if (this.parsedXML) {
      return {updated: false, runtime: 0};
    }
 
    const start = Date.now();
    this.parsedXML = {};
    const parsed = super.parseRaw2();
    if (parsed === undefined) {
      return {updated: false, runtime: 0};
    }
 
    const dd01v = parsed.abapGit?.["asx:abap"]?.["asx:values"]?.DD01V;
    const dd07v_tab = parsed.abapGit?.["asx:abap"]?.["asx:values"]?.DD07V_TAB?.DD07V;
    const values: DomainValue[] = [];
    if (dd07v_tab) {
      for (const ddo7v of dd07v_tab) {
        const value: DomainValue = {
          description: ddo7v?.DDTEXT,
          value: ddo7v?.DOMVALUE_L,
          language: ddo7v?.DDLANGUAGE,
        };
        values.push(value);
      }
    }
 
    this.parsedXML = {
      description: dd01v?.DDTEXT,
      datatype: dd01v?.DATATYPE,
      length: dd01v?.LENG,
      decimals: dd01v?.DECIMALS,
      values: values,
    };
    const end = Date.now();
    return {updated: true, runtime: end - start};
  }
 
  public getFixedValues() {
    return this.parsedXML?.values ?? [];
  }
 
}