Skip to content

Commit

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

* fix: Revision history is not showing the timestamp of the revision

* fix: recovery timestamp data

* fix: replace updateTs with lastModified

* fix: unit tests

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
armory-abedonik and mergify[bot] committed Aug 2, 2022
1 parent 8d03f16 commit 5c15d0c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 25 deletions.
Original file line number Diff line number Diff line change
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;

@Getter 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 @@ -57,6 +58,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 @@ -70,22 +77,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
Original file line number Diff line number Diff line change
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 5c15d0c

Please sign in to comment.