Skip to content

Commit

Permalink
Trim operator
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerwowen committed Sep 30, 2024
1 parent e662ce1 commit e254cde
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;

public class AgentBean implements Updatable {
public class AgentBean extends BaseBean implements Updatable {

@JsonProperty("hostId")
private String host_id;
Expand Down Expand Up @@ -161,7 +161,7 @@ public String getLast_operator() {
}

public void setLast_operator(String last_operator) {
this.last_operator = last_operator;
this.last_operator = getStringWithSizeLimit(last_operator, 64);
}

public Boolean getFirst_deploy() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.pinterest.deployservice.bean;

public class BaseBean {

/**
* Trims the input string to the specified size limit. If the input string's length
* exceeds the limit, the method returns the substring from the end of the string
* with the specified limit. Otherwise returns the original string.
*
* @param value the input string to be trimmed
* @param limit the maximum length of the returned string
* @return the trimmed string if the input string's length exceeds the limit,
* otherwise the original string
*/
protected String getStringWithSizeLimit(String value, int limit) {
if (value != null && value.length() > limit) {
return value.substring(value.length() - limit, value.length());
}
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;

public class ConfigHistoryBean implements Updatable {
public class ConfigHistoryBean extends BaseBean implements Updatable {
@JsonProperty("id")
private String config_id;

Expand Down Expand Up @@ -62,7 +62,7 @@ public Long getCreation_time() {
}

public void setOperator(String operator) {
this.operator = operator;
this.operator = getStringWithSizeLimit(operator, 64);
}

public String getOperator() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import org.apache.commons.lang3.builder.ReflectionToStringBuilder;

public class DataBean implements Updatable {
public class DataBean extends BaseBean implements Updatable {
private String data_id;
// TODO deprecate data_kind, we should use json all the time
private String data_kind;
Expand Down Expand Up @@ -46,7 +46,7 @@ public String getOperator() {
}

public void setOperator(String operator) {
this.operator = operator;
this.operator = getStringWithSizeLimit(operator, 64);
}

public String getData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;

public class DeployBean implements Updatable {
public class DeployBean extends BaseBean implements Updatable {
@JsonProperty("id")
private String deploy_id;

Expand Down Expand Up @@ -107,7 +107,7 @@ public String getOperator() {
}

public void setOperator(String operator) {
this.operator = operator;
this.operator = getStringWithSizeLimit(operator, 64);
}

public Long getLast_update() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.apache.commons.text.StringEscapeUtils;
import org.hibernate.validator.constraints.Range;

public class EnvironBean implements Updatable, Serializable {
public class EnvironBean extends BaseBean implements Updatable, Serializable {
@JsonProperty("id")
private String env_id;

Expand Down Expand Up @@ -309,7 +309,7 @@ public String getLast_operator() {
}

public void setLast_operator(String last_operator) {
this.last_operator = last_operator;
this.last_operator = getStringWithSizeLimit(last_operator, 64);
}

public Long getLast_update() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import javax.validation.constraints.NotEmpty;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;

public class HotfixBean implements Updatable {
public class HotfixBean extends BaseBean implements Updatable {
private String id;

@NotEmpty
Expand Down Expand Up @@ -145,7 +145,7 @@ public String getOperator() {
}

public void setOperator(String operator) {
this.operator = operator;
this.operator = getStringWithSizeLimit(operator, 32);
}

public Long getStart_time() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.quartz.CronExpression;

public class PromoteBean implements Updatable, Serializable {
public class PromoteBean extends BaseBean implements Updatable, Serializable {
@JsonProperty("envId")
private String env_id;

Expand Down Expand Up @@ -71,7 +71,7 @@ public String getLast_operator() {
}

public void setLast_operator(String last_operator) {
this.last_operator = last_operator;
this.last_operator = getStringWithSizeLimit(last_operator, 64);
}

public Long getLast_update() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import java.beans.Transient;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;

public class TagBean implements Updatable {
public class TagBean extends BaseBean implements Updatable {

private static final ObjectMapper mapper = new ObjectMapper();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.pinterest.deployservice.bean;


import static org.junit.Assert.assertSame;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

import org.junit.jupiter.api.Test;

public class BaseBeanTest {
@Test
void testGetStringWithSizeLimitInputNull() {
BaseBean baseBean = new BaseBean();
String result = baseBean.getStringWithSizeLimit(null, 10);
assertNull(result);
}

@Test
void testGetStringWithSizeLimitInputWithinLimit() {
BaseBean baseBean = new BaseBean();
String input = "test";
String result = baseBean.getStringWithSizeLimit(input, 10);
assertSame(input, result);
}
@Test
void testGetStringWithSizeLimitInputExceedsLimit() {
BaseBean baseBean = new BaseBean();
String result = baseBean.getStringWithSizeLimit("0123456789", 5);
assertEquals("56789", result);
}
}

0 comments on commit e254cde

Please sign in to comment.