All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.daml.ledger.test.java.package_management.packagemanagementtest.PackageManagementTestTemplate Maven / Gradle / Ivy

The newest version!
package com.daml.ledger.test.java.package_management.packagemanagementtest;

import static com.daml.ledger.javaapi.data.codegen.json.JsonLfEncoders.apply;

import com.daml.ledger.javaapi.data.ContractFilter;
import com.daml.ledger.javaapi.data.CreateAndExerciseCommand;
import com.daml.ledger.javaapi.data.CreateCommand;
import com.daml.ledger.javaapi.data.CreatedEvent;
import com.daml.ledger.javaapi.data.DamlRecord;
import com.daml.ledger.javaapi.data.ExerciseCommand;
import com.daml.ledger.javaapi.data.Identifier;
import com.daml.ledger.javaapi.data.Party;
import com.daml.ledger.javaapi.data.Template;
import com.daml.ledger.javaapi.data.Unit;
import com.daml.ledger.javaapi.data.Value;
import com.daml.ledger.javaapi.data.codegen.Choice;
import com.daml.ledger.javaapi.data.codegen.ContractCompanion;
import com.daml.ledger.javaapi.data.codegen.ContractTypeCompanion;
import com.daml.ledger.javaapi.data.codegen.Created;
import com.daml.ledger.javaapi.data.codegen.Exercised;
import com.daml.ledger.javaapi.data.codegen.PrimitiveValueDecoders;
import com.daml.ledger.javaapi.data.codegen.Update;
import com.daml.ledger.javaapi.data.codegen.ValueDecoder;
import com.daml.ledger.javaapi.data.codegen.json.JsonLfDecoder;
import com.daml.ledger.javaapi.data.codegen.json.JsonLfDecoders;
import com.daml.ledger.javaapi.data.codegen.json.JsonLfEncoder;
import com.daml.ledger.javaapi.data.codegen.json.JsonLfEncoders;
import com.daml.ledger.javaapi.data.codegen.json.JsonLfReader;
import java.lang.Deprecated;
import java.lang.IllegalArgumentException;
import java.lang.Object;
import java.lang.Override;
import java.lang.String;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Set;

public final class PackageManagementTestTemplate extends Template {
  public static final Identifier TEMPLATE_ID = new Identifier("5f87825d0f165e34afa118b148a07bf40a2ddf4778597c669869829553188c13", "PackageManagementTest", "PackageManagementTestTemplate");

  public static final Choice CHOICE_Archive = 
      Choice.create("Archive", value$ -> value$.toValue(), value$ ->
        com.daml.ledger.test.java.package_management.da.internal.template.Archive.valueDecoder()
        .decode(value$), value$ -> PrimitiveValueDecoders.fromUnit.decode(value$));

  public static final Choice CHOICE_TestChoice = 
      Choice.create("TestChoice", value$ -> value$.toValue(), value$ -> TestChoice.valueDecoder()
        .decode(value$), value$ -> PrimitiveValueDecoders.fromUnit.decode(value$));

  public static final ContractCompanion.WithoutKey COMPANION = 
      new ContractCompanion.WithoutKey<>(
        "com.daml.ledger.test.java.package_management.packagemanagementtest.PackageManagementTestTemplate",
        TEMPLATE_ID, ContractId::new,
        v -> PackageManagementTestTemplate.templateValueDecoder().decode(v),
        PackageManagementTestTemplate::fromJson, Contract::new, List.of(CHOICE_Archive,
        CHOICE_TestChoice));

  public final String owner;

  public PackageManagementTestTemplate(String owner) {
    this.owner = owner;
  }

  @Override
  public Update> create() {
    return new Update.CreateUpdate>(new CreateCommand(PackageManagementTestTemplate.TEMPLATE_ID, this.toValue()), x -> x, ContractId::new);
  }

  /**
   * @deprecated since Daml 2.3.0; use {@code createAnd().exerciseArchive} instead
   */
  @Deprecated
  public Update> createAndExerciseArchive(
      com.daml.ledger.test.java.package_management.da.internal.template.Archive arg) {
    return createAnd().exerciseArchive(arg);
  }

  /**
   * @deprecated since Daml 2.3.0; use {@code createAnd().exerciseArchive} instead
   */
  @Deprecated
  public Update> createAndExerciseArchive() {
    return createAndExerciseArchive(new com.daml.ledger.test.java.package_management.da.internal.template.Archive());
  }

  /**
   * @deprecated since Daml 2.3.0; use {@code createAnd().exerciseTestChoice} instead
   */
  @Deprecated
  public Update> createAndExerciseTestChoice(TestChoice arg) {
    return createAnd().exerciseTestChoice(arg);
  }

  /**
   * @deprecated since Daml 2.3.0; use {@code createAnd().exerciseTestChoice} instead
   */
  @Deprecated
  public Update> createAndExerciseTestChoice() {
    return createAndExerciseTestChoice(new TestChoice());
  }

  public static Update> create(String owner) {
    return new PackageManagementTestTemplate(owner).create();
  }

  @Override
  public CreateAnd createAnd() {
    return new CreateAnd(this);
  }

  @Override
  protected ContractCompanion.WithoutKey getCompanion(
      ) {
    return COMPANION;
  }

  /**
   * @deprecated since Daml 2.5.0; use {@code valueDecoder} instead
   */
  @Deprecated
  public static PackageManagementTestTemplate fromValue(Value value$) throws
      IllegalArgumentException {
    return valueDecoder().decode(value$);
  }

  public static ValueDecoder valueDecoder() throws
      IllegalArgumentException {
    return ContractCompanion.valueDecoder(COMPANION);
  }

  public DamlRecord toValue() {
    ArrayList fields = new ArrayList(1);
    fields.add(new DamlRecord.Field("owner", new Party(this.owner)));
    return new DamlRecord(fields);
  }

  private static ValueDecoder templateValueDecoder() throws
      IllegalArgumentException {
    return value$ -> {
      Value recordValue$ = value$;
      List fields$ = PrimitiveValueDecoders.recordCheck(1,0, recordValue$);
      String owner = PrimitiveValueDecoders.fromParty.decode(fields$.get(0).getValue());
      return new PackageManagementTestTemplate(owner);
    } ;
  }

  public static JsonLfDecoder jsonDecoder() {
    return JsonLfDecoders.record(Arrays.asList("owner"), name -> {
          switch (name) {
            case "owner": return com.daml.ledger.javaapi.data.codegen.json.JsonLfDecoders.JavaArg.at(0, com.daml.ledger.javaapi.data.codegen.json.JsonLfDecoders.party);
            default: return null;
          }
        }
        , (Object[] args) -> new PackageManagementTestTemplate(JsonLfDecoders.cast(args[0])));
  }

  public static PackageManagementTestTemplate fromJson(String json) throws JsonLfDecoder.Error {
    return jsonDecoder().decode(new JsonLfReader(json));
  }

  public JsonLfEncoder jsonEncoder() {
    return JsonLfEncoders.record(
        JsonLfEncoders.Field.of("owner", apply(JsonLfEncoders::party, owner)));
  }

  public static ContractFilter contractFilter() {
    return ContractFilter.of(COMPANION);
  }

  @Override
  public boolean equals(Object object) {
    if (this == object) {
      return true;
    }
    if (object == null) {
      return false;
    }
    if (!(object instanceof PackageManagementTestTemplate)) {
      return false;
    }
    PackageManagementTestTemplate other = (PackageManagementTestTemplate) object;
    return Objects.equals(this.owner, other.owner);
  }

  @Override
  public int hashCode() {
    return Objects.hash(this.owner);
  }

  @Override
  public String toString() {
    return String.format("com.daml.ledger.test.java.package_management.packagemanagementtest.PackageManagementTestTemplate(%s)",
        this.owner);
  }

  public static final class ContractId extends com.daml.ledger.javaapi.data.codegen.ContractId implements Exercises {
    public ContractId(String contractId) {
      super(contractId);
    }

    @Override
    protected ContractTypeCompanion, ContractId, PackageManagementTestTemplate, ?> getCompanion(
        ) {
      return COMPANION;
    }

    public static ContractId fromContractId(
        com.daml.ledger.javaapi.data.codegen.ContractId contractId) {
      return COMPANION.toContractId(contractId);
    }
  }

  public static class Contract extends com.daml.ledger.javaapi.data.codegen.Contract {
    public Contract(ContractId id, PackageManagementTestTemplate data, Set signatories,
        Set observers) {
      super(id, data, signatories, observers);
    }

    @Override
    protected ContractCompanion getCompanion(
        ) {
      return COMPANION;
    }

    public static Contract fromIdAndRecord(String contractId, DamlRecord record$,
        Set signatories, Set observers) {
      return COMPANION.fromIdAndRecord(contractId, record$, signatories, observers);
    }

    public static Contract fromCreatedEvent(CreatedEvent event) {
      return COMPANION.fromCreatedEvent(event);
    }
  }

  public interface Exercises extends com.daml.ledger.javaapi.data.codegen.Exercises.Archive {
    default Update> exerciseArchive(
        com.daml.ledger.test.java.package_management.da.internal.template.Archive arg) {
      return makeExerciseCmd(CHOICE_Archive, arg);
    }

    default Update> exerciseArchive() {
      return exerciseArchive(new com.daml.ledger.test.java.package_management.da.internal.template.Archive());
    }

    default Update> exerciseTestChoice(TestChoice arg) {
      return makeExerciseCmd(CHOICE_TestChoice, arg);
    }

    default Update> exerciseTestChoice() {
      return exerciseTestChoice(new TestChoice());
    }
  }

  public static final class CreateAnd extends com.daml.ledger.javaapi.data.codegen.CreateAnd implements Exercises {
    CreateAnd(Template createArguments) {
      super(createArguments);
    }

    @Override
    protected ContractTypeCompanion, ContractId, PackageManagementTestTemplate, ?> getCompanion(
        ) {
      return COMPANION;
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy