Skip to content

Commit

Permalink
XINX parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
larshp committed May 17, 2024
1 parent c911afa commit 480b04c
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 2 deletions.
40 changes: 38 additions & 2 deletions packages/core/src/objects/extension_index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import {AbstractObject} from "./_abstract_object";

export class ExtensionIndex extends AbstractObject {
private parsedXML: {
sqltab?: string,
ddtext?: string,
} | undefined = undefined;

public getType(): string {
return "XINX";
Expand All @@ -13,8 +17,40 @@ export class ExtensionIndex extends AbstractObject {
};
}

public setDirty(): void {
this.parsedXML = undefined;
super.setDirty();
}

public getDescription(): string | undefined {
// todo
return undefined;
this.parse();
return this.parsedXML?.ddtext;
}

public getTableName(): string | undefined {
this.parse();
return this.parsedXML?.sqltab;
}

public parse() {
if (this.parsedXML !== undefined) {
return {updated: false, runtime: 0};
}

const start = Date.now();
this.parsedXML = {};
const parsed = super.parseRaw2();
if (parsed === undefined) {
return {updated: false, runtime: 0};
}

const xinx = parsed.abapGit?.["asx:abap"]?.["asx:values"]?.XINX;
this.parsedXML = {
sqltab: xinx?.DD12V?.SQLTAB,
ddtext: xinx?.DD12V?.DDTEXT,
};

const end = Date.now();
return {updated: true, runtime: end - start};
}
}
44 changes: 44 additions & 0 deletions packages/core/test/objects/extension_index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import {expect} from "chai";
import {Registry} from "../../src/registry";
import {MemoryFile} from "../../src/files/memory_file";
import {ExtensionIndex} from "../../src/objects";

describe("Extension index, parse main xml", () => {

it("test", async () => {
const xml = `
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_XINX" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<XINX>
<DD12V>
<SQLTAB>T005</SQLTAB>
<INDEXNAME>Z00</INDEXNAME>
<AS4LOCAL>A</AS4LOCAL>
<DDLANGUAGE>E</DDLANGUAGE>
<DBINDEX>T005~Z00</DBINDEX>
<DDTEXT>Test</DDTEXT>
<ISEXTIND>X</ISEXTIND>
</DD12V>
<T_DD17V>
<DD17V>
<SQLTAB>T005</SQLTAB>
<INDEXNAME>Z00</INDEXNAME>
<POSITION>0001</POSITION>
<AS4LOCAL>A</AS4LOCAL>
<FIELDNAME>NMFMT</FIELDNAME>
</DD17V>
</T_DD17V>
</XINX>
</asx:values>
</asx:abap>
</abapGit>`;
const reg = new Registry().addFile(new MemoryFile("t005 z00.xinx.xml", xml));
await reg.parseAsync();
const xinx = reg.getFirstObject()! as ExtensionIndex;
expect(xinx.getDescription()).to.equal("Test");
expect(xinx.getTableName()).to.equal("T005");
});

});

0 comments on commit 480b04c

Please sign in to comment.