@JsonDeserialize(builder = CreateNewCycleDto.Builder.class)
public class CreateNewCycleDto extends AbstractDTO<CreateNewCycleDto> {
  @JsonUnwrapped
  public CycleLightDto cycleLightDto;
  public String cloneCycleId;
  public String sprintId;

  private CreateNewCycleDto(final Builder builder) {
    cycleLightDto = builder.cycleLightDto;
    cloneCycleId = builder.cloneCycleId;
    sprintId = builder.sprintId;
  }

  public static Builder newBuilder() {
    return new Builder();
  }

  @JsonPOJOBuilder(withPrefix = "")
  public static final class Builder {
    @JsonUnwrapped
    private CycleLightDto cycleLightDto;
    private String cloneCycleId;
    private String sprintId;

    private Builder() {
    }

    public Builder cycleLightDto(final CycleLightDto cycleLightDto) {
      this.cycleLightDto = cycleLightDto;
      return this;
    }

    public Builder cloneCycleId(final String cloneCycleId) {
      this.cloneCycleId = cloneCycleId;
      return this;
    }

    public Builder sprintId(final String sprintId) {
      this.sprintId = sprintId;
      return this;
    }

    public CreateNewCycleDto build() {
      return new CreateNewCycleDto(this);
    }
  }
} @JsonDeserialize(builder = CycleDto.Builder.class)
public class CycleDto extends AbstractDTO<CycleDto> {
  @JsonUnwrapped
  public CycleLightDto cycleLightDto;
  public String createdBy;
  public String createdByDisplay;
  public String createdDate;
  public String ended;
  public String expand;
  public Boolean isExecutionWorkflowEnabledForProject;
  public Boolean isTimeTrackingEnabled;
  public String modifiedBy;
  public String projectKey;
  public String started;
  public Long totalCycleExecutions;
  public Long totalDefects;
  public Long totalExecuted;
  public Long totalExecutions;
  public Long totalFolders;
  public String versionName;
  public Long recordsCount;

  private CycleDto(final Builder builder) {
    cycleLightDto = builder.cycleLightDto;
    createdBy = builder.createdBy;
    createdByDisplay = builder.createdByDisplay;
    createdDate = builder.createdDate;
    ended = builder.ended;
    expand = builder.expand;
    isExecutionWorkflowEnabledForProject = builder.isExecutionWorkflowEnabledForProject;
    isTimeTrackingEnabled = builder.isTimeTrackingEnabled;
    modifiedBy = builder.modifiedBy;
    projectKey = builder.projectKey;
    started = builder.started;
    totalCycleExecutions = builder.totalCycleExecutions;
    totalDefects = builder.totalDefects;
    totalExecuted = builder.totalExecuted;
    totalExecutions = builder.totalExecutions;
    totalFolders = builder.totalFolders;
    versionName = builder.versionName;
    recordsCount = builder.recordsCount;
  }

  public static Builder newBuilder() {
    return new Builder();
  }

  @JsonPOJOBuilder(withPrefix = "")
  public static final class Builder {
    @JsonUnwrapped
    private CycleLightDto cycleLightDto;
    private String createdBy;
    private String createdByDisplay;
    private String createdDate;
    private String ended;
    private String expand;
    private Boolean isExecutionWorkflowEnabledForProject;
    private Boolean isTimeTrackingEnabled;
    private String modifiedBy;
    private String projectKey;
    private String started;
    private Long totalCycleExecutions;
    private Long totalDefects;
    private Long totalExecuted;
    private Long totalExecutions;
    private Long totalFolders;
    private String versionName;
    private Long recordsCount;

    private Builder() {
    }

    public Builder cycleLightDto(final CycleLightDto cycleLightDto) {
      this.cycleLightDto = cycleLightDto;
      return this;
    }

    public Builder createdBy(final String createdBy) {
      this.createdBy = createdBy;
      return this;
    }

    public Builder createdByDisplay(final String createdByDisplay) {
      this.createdByDisplay = createdByDisplay;
      return this;
    }

    public Builder createdDate(final String createdDate) {
      this.createdDate = createdDate;
      return this;
    }

    public Builder ended(final String ended) {
      this.ended = ended;
      return this;
    }

    public Builder expand(final String expand) {
      this.expand = expand;
      return this;
    }

    public Builder isExecutionWorkflowEnabledForProject(
        final Boolean isExecutionWorkflowEnabledForProject) {
      this.isExecutionWorkflowEnabledForProject = isExecutionWorkflowEnabledForProject;
      return this;
    }

    public Builder isTimeTrackingEnabled(final Boolean isTimeTrackingEnabled) {
      this.isTimeTrackingEnabled = isTimeTrackingEnabled;
      return this;
    }

    public Builder modifiedBy(final String modifiedBy) {
      this.modifiedBy = modifiedBy;
      return this;
    }

    public Builder projectKey(final String projectKey) {
      this.projectKey = projectKey;
      return this;
    }

    public Builder started(final String started) {
      this.started = started;
      return this;
    }

    public Builder totalCycleExecutions(final Long totalCycleExecutions) {
      this.totalCycleExecutions = totalCycleExecutions;
      return this;
    }

    public Builder totalDefects(final Long totalDefects) {
      this.totalDefects = totalDefects;
      return this;
    }

    public Builder totalExecuted(final Long totalExecuted) {
      this.totalExecuted = totalExecuted;
      return this;
    }

    public Builder totalExecutions(final Long totalExecutions) {
      this.totalExecutions = totalExecutions;
      return this;
    }

    public Builder totalFolders(final Long totalFolders) {
      this.totalFolders = totalFolders;
      return this;
    }

    public Builder versionName(final String versionName) {
      this.versionName = versionName;
      return this;
    }

    public Builder recordsCount(final Long recordsCount) {
      this.recordsCount = recordsCount;
      return this;
    }

    public CycleDto build() {
      return new CycleDto(this);
    }
  }
} @JsonDeserialize(builder = CycleLightDto.Builder.class)
public class CycleLightDto extends AbstractDTO<CycleLightDto> {
  public String name;
  public String build;
  public String environment;
  public String description;
  public LocalDate startDate;
  public LocalDate endDate;
  public Long projectId;
  public Long versionId;

  private CycleLightDto(final Builder builder) {
    name = builder.name;
    build = builder.build;
    environment = builder.environment;
    description = builder.description;
    startDate = builder.startDate;
    endDate = builder.endDate;
    projectId = builder.projectId;
    versionId = builder.versionId;
  }

  public static Builder newBuilder() {
    return new Builder();
  }

  @JsonPOJOBuilder(withPrefix = "")
  public static final class Builder {
    private String name;
    private String build;
    private String environment;
    private String description;
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "d/MMM/yy",
        with = JsonFormat.Feature.ACCEPT_CASE_INSENSITIVE_VALUES)
    private LocalDate startDate;
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "d/MMM/yy",
        with = JsonFormat.Feature.ACCEPT_CASE_INSENSITIVE_VALUES)
    private LocalDate endDate;
    private Long projectId;
    private Long versionId;

    private Builder() {
    }

    public Builder name(final String name) {
      this.name = name;
      return this;
    }

    public Builder environment(final String environment) {
      this.environment = environment;
      return this;
    }

    public Builder description(final String description) {
      this.description = description;
      return this;
    }

    public Builder startDate(final LocalDate startDate) {
      this.startDate = startDate;
      return this;
    }

    public Builder endDate(final LocalDate endDate) {
      this.endDate = endDate;
      return this;
    }

    public Builder projectId(final Long projectId) {
      this.projectId = projectId;
      return this;
    }

    public Builder versionId(final Long versionId) {
      this.versionId = versionId;
      return this;
    }

    public CycleLightDto build() {
      return new CycleLightDto(this);
    }
  }
} @JsonDeserialize(builder = AddTestToCycleOperationDto.Builder.class)
public class AddTestToCycleOperationDto extends AbstractDTO<AddTestToCycleOperationDto> {
  public String cycleId;
  public List<String> issues;
  public String searchId;
  public String method;
  @JsonSerialize(using = ToStringSerializer.class)
  public Long projectId;
  @JsonSerialize(using = ToStringSerializer.class)
  public Long versionId;


  private AddTestToCycleOperationDto(final Builder builder) {
    cycleId = builder.cycleId;
    issues = builder.issues;
    searchId = builder.searchId;
    method = builder.method;
    projectId = builder.projectId;
    versionId = builder.versionId;
  }

  public static Builder newBuilder() {
    return new Builder();
  }

  @JsonPOJOBuilder(withPrefix = "")
  public static final class Builder {
    private String cycleId;
    private List<String> issues;
    private String searchId;
    private String method;
    private Long projectId;
    private Long versionId;

    private Builder() {
    }

    public Builder cycleId(final String cycleId) {
      this.cycleId = cycleId;
      return this;
    }

    public Builder issues(final List<String> issues) {
      this.issues = issues;
      return this;
    }

    public Builder searchId(final String searchId) {
      this.searchId = searchId;
      return this;
    }

    public Builder method(final String method) {
      this.method = method;
      return this;
    }

    public Builder projectId(final Long projectId) {
      this.projectId = projectId;
      return this;
    }

    public Builder versionId(final Long versionId) {
      this.versionId = versionId;
      return this;
    }

    public AddTestToCycleOperationDto build() {
      return new AddTestToCycleOperationDto(this);
    }
  }
} public class ProjectDto extends AbstractDTO<ProjectDto> {
  @JsonSerialize(using = ToStringSerializer.class)
  public Long id;
  public String key;
} @JsonDeserialize(builder = VersionDto.Builder.class)
public class VersionDto extends AbstractDTO<VersionDto> {
  public final String self;
  public final Long id;
  public final String description;
  public final String name;
  public final Boolean archived;
  @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
  public final LocalDate releaseDate;
  public final Boolean released;
  public final Boolean overdue;
  public final LocalDate userReleaseDate;
  public final String project;
  public final Long projectId;

  private VersionDto(final Builder builder) {
    self = builder.self;
    id = builder.id;
    description = builder.description;
    name = builder.name;
    archived = builder.archived;
    released = builder.released;
    releaseDate = builder.releaseDate;
    overdue = builder.overdue;
    userReleaseDate = builder.userReleaseDate;
    project = builder.project;
    projectId = builder.projectId;
  }

  public static Builder newBuilder() {
    return new Builder();
  }

  @JsonPOJOBuilder(withPrefix = "")
  public static final class Builder {
    private String self;
    @JsonSerialize(as = String.class)
    private Long id;
    private String description;
    private String name;
    private Boolean archived;
    private Boolean released;
    private LocalDate releaseDate;
    private Boolean overdue;
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd/MMM/yy",
        with = JsonFormat.Feature.ACCEPT_CASE_INSENSITIVE_VALUES)
    private LocalDate userReleaseDate;
    private String project;
    private Long projectId;

    private Builder() {
    }

    public Builder self(final String self) {
      this.self = self;
      return this;
    }

    public Builder id(final Long id) {
      this.id = id;
      return this;
    }

    public Builder description(final String description) {
      this.description = description;
      return this;
    }

    public Builder name(final String name) {
      this.name = name;
      return this;
    }

    public Builder archived(final Boolean archived) {
      this.archived = archived;
      return this;
    }

    public Builder released(final Boolean released) {
      this.released = released;
      return this;
    }

    public Builder releaseDate(final LocalDate releaseDate) {
      this.releaseDate = releaseDate;
      return this;
    }

    public Builder overdue(final Boolean overdue) {
      this.overdue = overdue;
      return this;
    }

    public Builder userReleaseDate(final LocalDate userReleaseDate) {
      this.userReleaseDate = userReleaseDate;
      return this;
    }

    public Builder project(final String project) {
      this.project = project;
      return this;
    }

    public Builder projectId(final Long projectId) {
      this.projectId = projectId;
      return this;
    }

    public VersionDto build() {
      return new VersionDto(this);
    }
  }
} public class Project extends AbstractJiraService {
  public ProjectDto getProject(String projectIdOrKey) {
    return getRequestSpec()
        .basePath(JiraEndpoint.PROJECT.getUrl())
        .pathParam("projectIdOrKey", projectIdOrKey)
        .contentType(ContentType.JSON)
        .get("/{projectIdOrKey}")
        .then()
        .log().ifValidationFails()
        .statusCode(SC_OK)
        .extract()
        .as(ProjectDto.class);
  }

  public List<VersionDto> getProjectVersions(String projectIdOrKey) {
    return getRequestSpec()
        .basePath(JiraEndpoint.PROJECT.getUrl())
        .pathParam("projectIdOrKey", projectIdOrKey)
        .get("/{projectIdOrKey}/versions")
        .then()
        .log().ifValidationFails()
        .statusCode(SC_OK)
        .extract()
        .body().jsonPath()
        .getList("", VersionDto.class);
  }
} public class Version extends AbstractJiraService {
  public VersionDto getVersion(String versionId) {
    return getRequestSpec()
        .basePath(JiraEndpoint.VERSION.getUrl())
        .pathParam("id", versionId)
        .get("/{id}")
        .then()
        .log().ifValidationFails()
        .statusCode(SC_OK)
        .extract()
        .as(VersionDto.class);
  }

  public VersionDto createVersion(VersionDto versionDto) {
    return getRequestSpec()
        .basePath(JiraEndpoint.VERSION.getUrl())
        .body(versionDto)
        .post()
        .then()
        .log().ifValidationFails()
        .statusCode(SC_CREATED)
        .extract()
        .as(VersionDto.class);
  }
} public class Cycle extends AbstractJiraService {
  public CycleListDto getListOfCycle(Long projectId, Long versionId) {
    return getRequestSpec()
        .basePath(ZephyrEndpoint.CYCLE.getUrl())
        .queryParam("projectId", projectId)
        .queryParam("versionId", versionId)
        .get()
        .then()
        .log().ifValidationFails()
        .statusCode(SC_OK)
        .extract().body()
        .as(CycleListDto.class);
  }

  public CreateCycleSuccessDto createNewCycle(CreateNewCycleDto createNewCycleDto) {
    return getRequestSpec()
        .basePath(ZephyrEndpoint.CYCLE.getUrl())
        .body(createNewCycleDto)
        .post()
        .then()
        .log().ifValidationFails()
        .extract()
        .as(CreateCycleSuccessDto.class);
  }
} public class Execution extends AbstractJiraService {
  public String addTestsToCycle(AddTestToCycleOperationDto addTestToCycleOperationDto) {
    return getRequestSpec()
        .basePath(ZephyrEndpoint.ADD_TEST_TO_EXECUTION.getUrl())
        .body(addTestToCycleOperationDto)
        .post()
        .then()
        .log().ifValidationFails()
        .statusCode(SC_OK)
        .extract()
        .asString(); //gets a jobprogresstoken
  }

  public String updateExecutionDetails(UpdateExecutionOperationDto updateExecutionOperationDto,
                                       Integer id) {
    return getRequestSpec()
        .basePath(ZephyrEndpoint.EXECUTION.getUrl())
        .pathParam("id", id)
        .body(updateExecutionOperationDto)
        .put("/{id}/execute")
        .then()
        .log().ifValidationFails()
        .statusCode(SC_OK)
        .extract()
        .asString(); // get a success token
  }
}
import static java.lang.String.format;
import com.beust.jcommander.ParameterException;
import com.frameworkium.core.common.properties.Property;
import com.frameworkium.core.common.reporting.jira.dto.cycle.CreateNewCycleDto;
import com.frameworkium.core.common.reporting.jira.dto.cycle.CycleDto;
import com.frameworkium.core.common.reporting.jira.dto.cycle.CycleLightDto;
import com.frameworkium.core.common.reporting.jira.dto.execution.AddTestToCycleOperationDto;
import com.frameworkium.core.common.reporting.jira.dto.project.ProjectDto;
import com.frameworkium.core.common.reporting.jira.dto.version.VersionDto;
import com.frameworkium.core.common.reporting.jira.service.Project;
import com.frameworkium.core.common.reporting.jira.service.Version;
import com.frameworkium.core.common.reporting.jira.zapi.Cycle;
import com.frameworkium.core.common.reporting.jira.zapi.Execution;
import io.qameta.allure.TmsLink;
import java.util.Arrays;
import java.util.List;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.openqa.selenium.NotFoundException;
import org.testng.ISuite;
import org.testng.ISuiteListener;
import org.testng.ITestNGMethod;
import org.testng.internal.ConstructorOrMethod;
package com.frameworkium.core.common.listeners;




public class CreateJiraCycleListener implements ISuiteListener {
  private final Logger logger = LogManager.getLogger(CreateJiraCycleListener.class);
  private final Project project = new Project();
  private final Version version = new Version();
  private final Cycle cycle = new Cycle();
  private final Execution execution = new Execution();