Skip to content

Commit

Permalink
Return logic into the model (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
ozonophore committed Jul 31, 2023
1 parent 258cdf5 commit b139305
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 180 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public String getBuildVersion(JiraComponent jiraComponent, String version) {
}

public String getLineVersion(JiraComponentVersion jiraComponentVersion) {
return getLineVersion(jiraComponentVersion.component, jiraComponentVersion.version);
return getLineVersion(jiraComponentVersion.getComponent(), jiraComponentVersion.getVersion());
}

public String getLineVersion(JiraComponent jiraComponent, String version) {
Expand All @@ -57,7 +57,7 @@ public boolean matchesReleaseVersionFormat(JiraComponent jiraComponent, String v
}

public boolean matchesReleaseVersionFormat(JiraComponentVersion jiraComponentVersion, String version) {
return matchesReleaseVersionFormat(jiraComponentVersion.component, version, true);
return matchesReleaseVersionFormat(jiraComponentVersion.getComponent(), version, true);
}

public boolean matchesReleaseVersionFormat(JiraComponent jiraComponent, String version) {
Expand All @@ -70,11 +70,11 @@ public boolean matchesMajorVersionFormat(JiraComponent jiraComponent, String ver
}

public boolean matchesMajorVersionFormat(JiraComponentVersion jiraComponentVersion, String version) {
return matchesMajorVersionFormat(jiraComponentVersion.component, version, true);
return matchesMajorVersionFormat(jiraComponentVersion.getComponent(), version, true);
}

public boolean matchesBuildVersionFormat(JiraComponentVersion jiraComponentVersion, String version) {
return matchesBuildVersionFormat(jiraComponentVersion.component, version, true);
return matchesBuildVersionFormat(jiraComponentVersion.getComponent(), version, true);
}

public boolean matchesBuildVersionFormat(JiraComponent jiraComponent, String version, boolean strict) {
Expand All @@ -92,12 +92,12 @@ public boolean matchesLineVersionFormat(JiraComponent jiraComponent, String vers
}

public boolean matchesAny(JiraComponentVersion jiraComponentVersion, String version) {
return matchesAny(jiraComponentVersion.component, version, true);
return matchesAny(jiraComponentVersion.getComponent(), version, true);
}


public boolean matchesAny(JiraComponentVersion jiraComponentVersion, String version, boolean strict) {
return matchesAny(jiraComponentVersion.component, version, strict);
return matchesAny(jiraComponentVersion.getComponent(), version, strict);
}

public boolean matchesAny(JiraComponent jiraComponent, String version, boolean strict) {
Expand All @@ -107,7 +107,7 @@ public boolean matchesAny(JiraComponent jiraComponent, String version, boolean s
}

public boolean matchesRCVersionFormat(JiraComponentVersion jiraComponentVersion, String version) {
return matchesRCVersionFormat(jiraComponentVersion.component, version, true);
return matchesRCVersionFormat(jiraComponentVersion.getComponent(), version, true);
}

public boolean matchesRCVersionFormat(JiraComponent jiraComponent, String version, boolean strict) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.type.CollectionType;
import org.apache.commons.lang3.Validate;
import org.octopusden.octopus.releng.dto.ComponentVersion;
import org.octopusden.octopus.releng.dto.JiraComponent;
import org.octopusden.octopus.releng.dto.JiraComponentVersion;
import org.octopusden.releng.versions.ComponentVersionFormat;
import org.octopusden.releng.versions.KotlinVersionFormatter;
import org.octopusden.releng.versions.VersionFormatter;
import org.apache.commons.lang3.Validate;
import org.octopusden.releng.versions.VersionNames;

import java.io.IOException;
Expand Down Expand Up @@ -125,10 +125,11 @@ private JiraComponentVersion deserializeFromRequestString(String component) {

JiraComponent jiraComponent = new JiraComponent(projectKey, "", versionFormat, null, false);
JiraComponentVersionFormatter jiraComponentVersionFormatter = new JiraComponentVersionFormatter(versionNames);
return JiraComponentVersion.builder(jiraComponentVersionFormatter)
.componentVersion(ComponentVersion.create(componentName, releaseVersion))
.component(jiraComponent)
.build();
return new JiraComponentVersion(
ComponentVersion.create(componentName, releaseVersion),
jiraComponent,
jiraComponentVersionFormatter
);
}

boolean isValidJSON(final String json) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,166 +1,52 @@
package org.octopusden.octopus.releng.dto;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
import org.octopusden.octopus.releng.JiraComponentVersionFormatter;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class JiraComponentVersion {

@JsonIgnore
public static final String RC_SUFFIX = "_RC";

@JsonProperty
public final ComponentVersion componentVersion;
private final ComponentVersion componentVersion;

@JsonProperty
public final JiraComponent component;

@JsonIgnore
public final String lineVersion;

@JsonIgnore
public final String minorVersion;

@JsonIgnore
public final String releaseVersion;

private final JiraComponent component;
@JsonIgnore
public final String buildVersion;
private final JiraComponentVersionFormatter jiraComponentVersionFormatter;

@JsonIgnore
public final ComponentVersion releaseComponentVersion;
private String lineVersion = null;

@JsonIgnore
public final ComponentVersion buildComponentVersion;
private String minorVersion = null;

@JsonIgnore
public final ComponentVersion rCComponentVersion;
private String releaseVersion = null;

@JsonIgnore
public final String version;
private String buildVersion = null;

@JsonIgnore
public final String rCversion;

@JsonIgnore
public final String majorVersion;

public static Builder builder(JiraComponentVersionFormatter jiraComponentVersionFormatter) {
return new Builder(jiraComponentVersionFormatter);
@JsonCreator
public JiraComponentVersion(@JsonProperty("componentVersion") ComponentVersion componentVersion,
@JsonProperty("component") JiraComponent component,
JiraComponentVersionFormatter jiraComponentVersionFormatter) {
this.componentVersion = componentVersion;
this.component = component;
this.jiraComponentVersionFormatter = jiraComponentVersionFormatter;
}

@JsonPOJOBuilder(withPrefix = "")
public static class Builder {

private final JiraComponentVersionFormatter jiraComponentVersionFormatter;
private ComponentVersion componentVersion;
private JiraComponent component;

private String version;

private String majorVersion;

private String releaseVersion;

private String rCversion;

private ComponentVersion releaseComponentVersion;

private String buildVersion;
private ComponentVersion buildComponentVersion;
private ComponentVersion rCComponentVersion;
private String minorVersion;
private String lineVersion;

public Builder(JiraComponentVersionFormatter jiraComponentVersionFormatter) {
this.jiraComponentVersionFormatter = jiraComponentVersionFormatter;
}

public Builder componentVersion(ComponentVersion componentVersion) {
this.componentVersion = componentVersion;
return this;
}

public Builder componentVersionByNameAndVersion(String componentName, String version) {
this.componentVersion = ComponentVersion.create(componentName, version);
return this;
}

public Builder component(JiraComponent component) {
this.component = component;
return this;
}


private String getReleaseVersion() {
return (componentVersionFormatIsNotSpecified() || component.getComponentVersionFormat().getReleaseVersionFormat() == null) ?
componentVersion.getVersion() : jiraComponentVersionFormatter.getReleaseVersion(component, version);
}

private ComponentVersion getComponentVersion(String version) {
return ComponentVersion.create(componentVersion.getComponentName(), version);
}

private String getBuildVersion() {
String buildVersionFormat = jiraComponentVersionFormatter.getBuildVersionFormat(component);
if (buildVersionFormat == null) {
return version;
}
return jiraComponentVersionFormatter.getBuildVersion(component, version);
}

private boolean componentVersionFormatIsNotSpecified() {
return component == null || component.getComponentVersionFormat() == null;
}

private String getMinorVersion() {
if (componentVersionFormatIsNotSpecified() || component.getComponentVersionFormat().getMajorVersionFormat() == null) {
return version;
}
return jiraComponentVersionFormatter.getMajorVersion(component, version);
}

private String getLineVersion() {
if (componentVersionFormatIsNotSpecified() || component.getComponentVersionFormat().getLineVersionFormat() == null) {
return majorVersion;
}
return jiraComponentVersionFormatter.getLineVersion(component, version);
}

public JiraComponentVersion build() {
version = componentVersion.getVersion();
releaseVersion = getReleaseVersion();
rCversion = releaseVersion + RC_SUFFIX;
releaseComponentVersion = getComponentVersion(releaseVersion);
buildVersion = getBuildVersion();
buildComponentVersion = getComponentVersion(buildVersion);
rCComponentVersion = getComponentVersion(rCversion);
minorVersion = getMinorVersion();
majorVersion = minorVersion;
lineVersion = getLineVersion();
return new JiraComponentVersion(this);
}
}

private JiraComponentVersion(Builder builder) {
this.componentVersion = builder.componentVersion;
this.component = builder.component;
this.version = builder.version;
this.releaseVersion = builder.releaseVersion;
this.rCversion = builder.rCversion;
this.releaseComponentVersion = builder.releaseComponentVersion;
this.buildVersion = builder.buildVersion;
this.buildComponentVersion = builder.buildComponentVersion;
this.rCComponentVersion = builder.rCComponentVersion;
this.minorVersion = builder.minorVersion;
this.majorVersion = builder.majorVersion;
this.lineVersion = builder.lineVersion;
public JiraComponent getComponent() {
return component;
}

@JsonIgnore
Expand All @@ -170,20 +56,29 @@ public ComponentVersion getComponentVersion() {

@JsonIgnore
public String getReleaseVersion() {
if (releaseVersion == null) {
if (componentVersionFormatIsNotSpecified() || component.getComponentVersionFormat().getReleaseVersionFormat() == null) {
releaseVersion = getVersion();
} else {
releaseVersion = jiraComponentVersionFormatter.getReleaseVersion(getComponent(), getVersion());
}
}
return releaseVersion;
}

@JsonIgnore
public ComponentVersion getReleaseComponentVersion() {
return releaseComponentVersion;
return getComponentVersion(getReleaseVersion());
}

@JsonIgnore
public ComponentVersion getBuildComponentVersion() {
return buildComponentVersion;
return getComponentVersion(getBuildVersion());
}

@JsonIgnore
public ComponentVersion getRCComponentVersion() {
return rCComponentVersion;
return getComponentVersion(getRCVersion());
}

@JsonIgnore
Expand All @@ -195,24 +90,52 @@ private boolean componentVersionFormatIsNotSpecified() {
return component == null || component.getComponentVersionFormat() == null;
}

@JsonIgnore
public String getMajorVersion() {
return majorVersion;
if (minorVersion == null) {
if (componentVersionFormatIsNotSpecified() || component.getComponentVersionFormat().getMajorVersionFormat() == null) {
minorVersion = getVersion();
} else {
minorVersion = jiraComponentVersionFormatter.getMajorVersion(getComponent(), getVersion());
}
}
return minorVersion;
}

@JsonIgnore
public String getLineVersion() {
if (lineVersion == null) {
if (componentVersionFormatIsNotSpecified() || component.getComponentVersionFormat().getLineVersionFormat() == null) {
lineVersion = getMajorVersion();
} else {
lineVersion = jiraComponentVersionFormatter.getLineVersion(this);
}
}
return lineVersion;
}

@JsonIgnore
public String getVersion() {
return version;
return componentVersion.getVersion();
}

@JsonIgnore
public String getBuildVersion() {
if (buildVersion == null) {
String buildVersionFormat = jiraComponentVersionFormatter.getBuildVersionFormat(getComponent());
if (buildVersionFormat == null) {
buildVersion = getVersion();
} else {
buildVersion = jiraComponentVersionFormatter.getBuildVersion(getComponent(), getVersion());
}
}
return buildVersion;
}


@JsonIgnore
public String getRCVersion() {
return rCversion;
return getReleaseVersion() + RC_SUFFIX;
}

@Override
Expand Down
Loading

0 comments on commit b139305

Please sign in to comment.