All files / output zcl_abapgit_repo_cs_migration.clas.mjs

24.27% Statements 25/103
100% Branches 2/2
7.14% Functions 1/14
24.27% Lines 25/103

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 97 98 99 100 101 102 1031x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x             1x       1x     1x               1x     1x                                                     1x     1x                                       1x     1x                   1x 1x 1x 1x
const {cx_root} = await import("./cx_root.clas.mjs");
// zcl_abapgit_repo_cs_migration.clas.abap
class zcl_abapgit_repo_cs_migration {
  static INTERNAL_TYPE = 'CLAS';
  static INTERNAL_NAME = 'ZCL_ABAPGIT_REPO_CS_MIGRATION';
  static IMPLEMENTED_INTERFACES = [];
  static ATTRIBUTES = {};
  static METHODS = {"GET_UNCONVERTED_REPO_IDS": {"visibility": "I", "parameters": {"RT_REPO_IDS": {"type": () => {return abap.types.TableFactory.construct(new abap.types.Character(12, {"qualifiedName":"zif_abapgit_persistence=>ty_value"}), {"withHeader":false,"keyType":"USER","primaryKey":{"name":"primary_key","type":"SORTED","isUnique":true,"keyFields":["TABLE_LINE"]},"secondary":[]}, "zcl_abapgit_repo_cs_migration=>ty_repo_ids");}, "is_optional": " "}}},
  "CLEAR_REPO_METADATA": {"visibility": "I", "parameters": {"IV_REPO_KEY": {"type": () => {return new abap.types.Character(12, {"qualifiedName":"zif_abapgit_persistence=>ty_value"});}, "is_optional": " "}}},
  "CONVERT_CHECKSUMS": {"visibility": "I", "parameters": {"IV_REPO_KEY": {"type": () => {return new abap.types.Character(12, {"qualifiedName":"zif_abapgit_persistence=>ty_value"});}, "is_optional": " "}}},
  "RUN": {"visibility": "U", "parameters": {}}};
  constructor() {
    this.me = new abap.types.ABAPObject();
    this.me.set(this);
    this.INTERNAL_ID = abap.internalIdCounter++;
    this.FRIENDS_ACCESS_INSTANCE = {
    };
  }
  async constructor_(INPUT) {
    if (super.constructor_) { await super.constructor_(INPUT); }
    return this;
  }
  async clear_repo_metadata(INPUT) {
    return zcl_abapgit_repo_cs_migration.clear_repo_metadata(INPUT);
  }
  static async clear_repo_metadata(INPUT) {
    let iv_repo_key = INPUT?.iv_repo_key;
    if (iv_repo_key?.getQualifiedName === undefined || iv_repo_key.getQualifiedName() !== "ZIF_ABAPGIT_PERSISTENCE=>TY_VALUE") { iv_repo_key = undefined; }
    if (iv_repo_key === undefined) { iv_repo_key = new abap.types.Character(12, {"qualifiedName":"zif_abapgit_persistence=>ty_value"}).set(INPUT.iv_repo_key); }
    let lo_repo_persistence = new abap.types.ABAPObject({qualifiedName: "ZCL_ABAPGIT_PERSISTENCE_REPO", RTTIName: "\\CLASS=ZCL_ABAPGIT_PERSISTENCE_REPO"});
    await abap.statements.cast(lo_repo_persistence, (await abap.Classes['ZCL_ABAPGIT_PERSIST_FACTORY'].get_repo()));
    await lo_repo_persistence.get().rewrite_repo_meta({iv_repo_key: iv_repo_key});
  }
  async convert_checksums(INPUT) {
    return zcl_abapgit_repo_cs_migration.convert_checksums(INPUT);
  }
  static async convert_checksums(INPUT) {
    let iv_repo_key = INPUT?.iv_repo_key;
    if (iv_repo_key?.getQualifiedName === undefined || iv_repo_key.getQualifiedName() !== "ZIF_ABAPGIT_PERSISTENCE=>TY_VALUE") { iv_repo_key = undefined; }
    if (iv_repo_key === undefined) { iv_repo_key = new abap.types.Character(12, {"qualifiedName":"zif_abapgit_persistence=>ty_value"}).set(INPUT.iv_repo_key); }
    let lo_cs = new abap.types.ABAPObject({qualifiedName: "ZCL_ABAPGIT_REPO_CHECKSUMS", RTTIName: "\\CLASS=ZCL_ABAPGIT_REPO_CHECKSUMS"});
    let lv_xml = new abap.types.String({qualifiedName: "ZIF_ABAPGIT_PERSISTENCE=>TY_CONTENT-DATA_STR"});
    let ls_repo_extract = new abap.types.Structure({
    "local_checksums": abap.types.TableFactory.construct(new abap.types.Structure({
    "item": new abap.types.Structure({
    "obj_type": new abap.types.Character(4, {}),
    "obj_name": new abap.types.Character(40, {}),
    "devclass": new abap.types.Character(30, {"qualifiedName":"DEVCLASS","ddicName":"DEVCLASS","description":"DEVCLASS"})}, "zif_abapgit_definitions=>ty_item_signature", undefined, {}, {}),
    "files": abap.types.TableFactory.construct(new abap.types.Structure({
    "path": new abap.types.String({qualifiedName: "ZIF_ABAPGIT_GIT_DEFINITIONS=>TY_FILE_SIGNATURE-PATH"}),
    "filename": new abap.types.String({qualifiedName: "ZIF_ABAPGIT_GIT_DEFINITIONS=>TY_FILE_SIGNATURE-FILENAME"}),
    "sha1": new abap.types.Character(40, {"qualifiedName":"zif_abapgit_git_definitions=>ty_sha1"})}, "zif_abapgit_git_definitions=>ty_file_signature", undefined, {}, {}), {"withHeader":false,"keyType":"DEFAULT","primaryKey":{"name":"primary_key","type":"STANDARD","isUnique":false,"keyFields":[]},"secondary":[]}, "zif_abapgit_git_definitions=>ty_file_signatures_tt")}, "zif_abapgit_persistence=>ty_local_checksum", undefined, {}, {}), {"withHeader":false,"keyType":"DEFAULT","primaryKey":{"name":"primary_key","type":"STANDARD","isUnique":false,"keyFields":[]},"secondary":[]}, "zif_abapgit_persistence=>ty_local_checksum_tt")}, undefined, undefined, {}, {});
    lv_xml.set((await (await abap.Classes['ZCL_ABAPGIT_PERSISTENCE_DB'].get_instance()).get().read({iv_type: abap.Classes['ZCL_ABAPGIT_PERSISTENCE_DB'].c_type_repo, iv_value: iv_repo_key})));
    abap.statements.replace({target: lv_xml, all: true, with: abap.CharacterFactory.get(6, '<REPO>'), of: abap.CharacterFactory.get(23, '<_--28C_TYPE_REPO_--29>')});
    abap.statements.replace({target: lv_xml, all: true, with: abap.CharacterFactory.get(7, '</REPO>'), of: abap.CharacterFactory.get(24, '</_--28C_TYPE_REPO_--29>')});
    if (abap.Classes['KERNEL_CALL_TRANSFORMATION'] === undefined) throw new Error("CallTransformation, kernel class missing");
    await abap.Classes['KERNEL_CALL_TRANSFORMATION'].call({name: "id",sourceXML: lv_xml,options: {value_handling:abap.CharacterFactory.get(16, 'accept_data_loss')},result: {repo:ls_repo_extract}});
    if (abap.compare.eq(abap.builtin.lines({val: ls_repo_extract.get().local_checksums}), abap.IntegerFactory.get(0))) {
      return;
    }
    lo_cs.set(await (new abap.Classes['ZCL_ABAPGIT_REPO_CHECKSUMS']()).constructor_({iv_repo_key: iv_repo_key}));
    await lo_cs.get().force_write({it_checksums: ls_repo_extract.get().local_checksums});
  }
  async get_unconverted_repo_ids() {
    return zcl_abapgit_repo_cs_migration.get_unconverted_repo_ids();
  }
  static async get_unconverted_repo_ids() {
    let rt_repo_ids = abap.types.TableFactory.construct(new abap.types.Character(12, {"qualifiedName":"zif_abapgit_persistence=>ty_value"}), {"withHeader":false,"keyType":"USER","primaryKey":{"name":"primary_key","type":"SORTED","isUnique":true,"keyFields":["TABLE_LINE"]},"secondary":[]}, "zcl_abapgit_repo_cs_migration=>ty_repo_ids");
    let lt_cs_ids = abap.types.TableFactory.construct(new abap.types.Character(12, {"qualifiedName":"zif_abapgit_persistence=>ty_value"}), {"withHeader":false,"keyType":"USER","primaryKey":{"name":"primary_key","type":"SORTED","isUnique":true,"keyFields":["TABLE_LINE"]},"secondary":[]}, "zcl_abapgit_repo_cs_migration=>ty_repo_ids");
    let lv_repo_id = new abap.types.Character(12, {"qualifiedName":"zif_abapgit_persistence=>ty_value"});
    let lv_index = new abap.types.Integer({qualifiedName: "I"});
    await abap.statements.select(rt_repo_ids, {select: "SELECT value FROM " + abap.buildDbTableName(abap.Classes['ZCL_ABAPGIT_PERSISTENCE_DB'].c_tabname.get().trimEnd().toLowerCase()) + " WHERE \"type\" = '" + abap.Classes['ZCL_ABAPGIT_PERSISTENCE_DB'].c_type_repo.get() + "'"});
    await abap.statements.select(lt_cs_ids, {select: "SELECT value FROM " + abap.buildDbTableName(abap.Classes['ZCL_ABAPGIT_PERSISTENCE_DB'].c_tabname.get().trimEnd().toLowerCase()) + " WHERE \"type\" = '" + abap.Classes['ZCL_ABAPGIT_PERSISTENCE_DB'].c_type_repo_csum.get() + "'"});
    for await (const unique614 of abap.statements.loop(rt_repo_ids)) {
      lv_repo_id.set(unique614);
      lv_index.set(abap.builtin.sy.get().tabix);
      abap.statements.readTable(lt_cs_ids,{withKey: (i) => {return abap.compare.eq(i.table_line, lv_repo_id);},
        withKeyValue: [{key: (i) => {return i.table_line}, value: lv_repo_id}],
        usesTableLine: true,
        withKeySimple: {"table_line": lv_repo_id}});
      if (abap.compare.eq(abap.builtin.sy.get().subrc, abap.IntegerFactory.get(0))) {
        await abap.statements.deleteInternal(rt_repo_ids,{index: lv_index});
      }
    }
    return rt_repo_ids;
  }
  async run() {
    return zcl_abapgit_repo_cs_migration.run();
  }
  static async run() {
    let lt_repo_ids = abap.types.TableFactory.construct(new abap.types.Character(12, {"qualifiedName":"zif_abapgit_persistence=>ty_value"}), {"withHeader":false,"keyType":"USER","primaryKey":{"name":"primary_key","type":"SORTED","isUnique":true,"keyFields":["TABLE_LINE"]},"secondary":[]}, "zcl_abapgit_repo_cs_migration=>ty_repo_ids");
    let lv_repo_id = new abap.types.Character(12, {"qualifiedName":"zif_abapgit_persistence=>ty_value"});
    lt_repo_ids.set((await this.get_unconverted_repo_ids()));
    for await (const unique615 of abap.statements.loop(lt_repo_ids)) {
      lv_repo_id.set(unique615);
      await this.convert_checksums({iv_repo_key: lv_repo_id});
      await this.clear_repo_metadata({iv_repo_key: lv_repo_id});
    }
  }
}
abap.Classes['ZCL_ABAPGIT_REPO_CS_MIGRATION'] = zcl_abapgit_repo_cs_migration;
zcl_abapgit_repo_cs_migration.ty_repo_ids = abap.types.TableFactory.construct(new abap.types.Character(12, {"qualifiedName":"zif_abapgit_persistence=>ty_value"}), {"withHeader":false,"keyType":"USER","primaryKey":{"name":"primary_key","type":"SORTED","isUnique":true,"keyFields":["TABLE_LINE"]},"secondary":[]}, "zcl_abapgit_repo_cs_migration=>ty_repo_ids");
export {zcl_abapgit_repo_cs_migration};