Skip to content

Commit

Permalink
fix: Revision history is not showing the timestamp of the revision (b…
Browse files Browse the repository at this point in the history
…ackport #1142) (#1146)

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: armory-abedonik <106548537+armory-abedonik@users.noreply.github.com>
Co-authored-by: mattgogerly <matthewgogerly@gmail.com>
  • Loading branch information
3 people committed Aug 2, 2022
1 parent c36b905 commit 19566df
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 25 deletions.
Expand Up @@ -16,6 +16,7 @@
*/
package com.netflix.spinnaker.front50.api.model.pipeline;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.netflix.spinnaker.front50.api.model.Timestamped;
import java.util.*;
import lombok.Getter;
Expand All @@ -36,10 +37,10 @@ public class Pipeline implements Timestamped {
@Getter @Setter private List<Trigger> triggers = new ArrayList<>();
@Getter @Setter private Integer index;

private String updateTs;
private String createTs;
@JsonIgnore private String updateTs;
private String lastModifiedBy;
private String lastModified;
@Getter @Setter private Long lastModified;

@Getter @Setter private String email;
@Getter @Setter private Boolean disabled;
Expand All @@ -56,6 +57,12 @@ public class Pipeline implements Timestamped {
@Getter @Setter private List<Map<String, Object>> parameterConfig;
@Getter @Setter private String spelEvaluator;

public String getUpdateTs() {
var lastModified = getLastModified();

return lastModified != null ? lastModified.toString() : null;
}

public void setAny(String key, Object value) {
anyMap.put(key, value);
}
Expand All @@ -69,22 +76,6 @@ public String getId() {
return this.id;
}

@Override
public Long getLastModified() {
String updateTs = this.updateTs;
if (updateTs == null || updateTs == "") {
return null;
}
return Long.valueOf(updateTs);
}

@Override
public void setLastModified(Long lastModified) {
if (lastModified != null) {
this.updateTs = lastModified.toString();
}
}

@Override
public String getLastModifiedBy() {
return this.lastModifiedBy;
Expand Down
Expand Up @@ -81,6 +81,9 @@ class SqlStorageService(
PLUGIN_INFO to DefaultTableDefinition(PLUGIN_INFO, "plugin_info", false),
PLUGIN_VERSIONS to DefaultTableDefinition(PLUGIN_VERSIONS, "plugin_versions", false)
)

private val bodyField = field("body", String::class.java)
private val lastModifiedField = field("last_modified_at", Long::class.java)
}

override fun supportsVersioning(): Boolean {
Expand Down Expand Up @@ -330,30 +333,30 @@ class SqlStorageService(
return mutableListOf(loadObject(objectType, objectKey))
}

val bodies = withPool(poolName) {
val result = withPool(poolName) {
jooq.withRetry(sqlRetryProperties.reads) { ctx ->
if (definitionsByType[objectType]!!.supportsHistory) {
ctx
.select(field("body", String::class.java))
.select(bodyField, lastModifiedField)
.from(definitionsByType[objectType]!!.historyTableName)
.where(DSL.field("id", String::class.java).eq(objectKey))
.orderBy(DSL.field("recorded_at").desc())
.limit(maxResults)
.fetch()
.getValues(field("body", String::class.java))
} else {
ctx
.select(field("body", String::class.java))
.select(bodyField, lastModifiedField)
.from(definitionsByType[objectType]!!.tableName)
.where(DSL.field("id", String::class.java).eq(objectKey))
.fetch()
.getValues(field("body", String::class.java))
}
}
}

return bodies.map {
objectMapper.readValue(it, objectType.clazz as Class<T>)
return result.map {
val record = objectMapper.readValue(it.get(bodyField), objectType.clazz as Class<T>)
record.lastModified = it.get(lastModifiedField)
record
}
}

Expand Down

0 comments on commit 19566df

Please sign in to comment.