category: Tutorial
name: Shadow
persistence: false
api_generation: false
abstract: true
attributes:
  local_fields:
    - field_name: system
      field_type: string
      field_persistence: true
      field_nullable: true
      field_immutable: false
      field_unique: false
      field_enum:
        - A
        - B
      field_metadata:
        ignore: true
    - field_name: description
      field_type: string
      field_persistence: true
      field_nullable: true
      field_immutable: false
      field_unique: false
      field_metadata:
        ignore: false
    - field_name: origin
      field_type: string
      field_persistence: true
      field_nullable: true
      field_immutable: false
      field_unique: false
      field_metadata:
        ignore: true
  ref_fields: []
  identifier:
    field_name: name
    field_type: string
    field_persistence: true
    field_immutable: true
    field_metadata:
      ignore: false
methods:
  class_methods: []
  instance_methods:
    - method_body: |-
        async def create(self, *args, **kwargs):
            print("作成中...%s" % self.system)
            r = await callout(path="/apis/system{}s".format(self.system),
                              method=POST,
                              body={"System{}".format(self.system): self.localfields(ignore=False)})
            if r.error:
                print("作成失敗...%s" % self.system)
                raise Error(r.code, reason=r.error.__str__())
            self.origin = json.loads(r.body)["System{}".format(self.system)]["instance"]
            print("作成完了...%s" % self.system)
      propagation_mode: true
      topdown: true
      auto_rollback: true
      multiplexable_number: 1
      field_order: ascend
    - method_body: |-
        async def delete(self, *args, **kwargs):
            print("削除要否判定...%s" % self.system)
            if not self.origin:
                r = await callout(path="/apis/system{}s?name={}".format(self.system, self.name))
                if r.error:
                    print("削除要否判定失敗...%s" % self.system)
                    raise Error(r.code, reason=r.error.__str__())
                payload = json.loads(r.body)
                if len(payload)==0:
                    print("削除不要...%s" % self.system)
                    return
                self.origin = payload[0]["System{}".format(self.system)]["instance"]

            print("削除中...%s" % self.system)
            r = await callout(path="/apis/system{}s/{}".format(self.system, self.origin), method=DELETE)
            if r.error:
                print("削除失敗...%s" % self.system)
                raise Error(r.code, reason=r.error.__str__())
            print("削除完了...%s" % self.system)
      propagation_mode: true
      topdown: true
      auto_rollback: true
      multiplexable_number: 1
      field_order: ascend