Skip to content

Commit

Permalink
Removed deprecated methods in Message class, that were used only in u… (
Browse files Browse the repository at this point in the history
  • Loading branch information
luk-kaminski committed Dec 5, 2023
1 parent 2d4b321 commit 801bd45
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 109 deletions.
10 changes: 7 additions & 3 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ Any existing Active Directory User Asset import configurations will be automatic

The following Java Code API changes have been made.

| File/method | Description |
|--------------------------------|--------------------------|
| `ExampleClass#exampleFunction` | TODO placeholder comment |
| File/method | Description |
|--------------------------------|---------------------------|
| `org.graylog2.plugin.Message#addStringFields` | Deprecated method removed |
| `org.graylog2.plugin.Message#addLongFields` | Deprecated method removed |
| `org.graylog2.plugin.Message#addDoubleFields` | Deprecated method removed |
| `org.graylog2.plugin.Message#getValidationErrors` | Deprecated method removed |


## REST API Endpoint Changes

Expand Down
5 changes: 5 additions & 0 deletions changelog/unreleased/pr-17585.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type = "r"
message = "Removed deprecated methods in org.graylog2.plugin.Message class : addStringFields, addLongFields, addDoubleFields, getValidationErrors"

issues = [""]
pulls = ["17585"]
48 changes: 0 additions & 48 deletions graylog2-server/src/main/java/org/graylog2/plugin/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -375,21 +375,6 @@ public boolean isComplete() {
return true;
}

@Deprecated
public String getValidationErrors() {
final StringBuilder sb = new StringBuilder();

for (String key : REQUIRED_FIELDS) {
final Object field = getField(key);
if (field == null) {
sb.append(key).append(" is missing, ");
} else if (field instanceof String && ((String) field).isEmpty()) {
sb.append(key).append(" is empty, ");
}
}
return sb.toString();
}

@Override
public String getId() {
return getFieldAs(String.class, FIELD_ID);
Expand Down Expand Up @@ -656,39 +641,6 @@ public void addFields(final Map<String, Object> fields) {
}
}

@Deprecated
public void addStringFields(final Map<String, String> fields) {
if (fields == null) {
return;
}

for (Map.Entry<String, String> field : fields.entrySet()) {
addField(field.getKey(), field.getValue());
}
}

@Deprecated
public void addLongFields(final Map<String, Long> fields) {
if (fields == null) {
return;
}

for (Map.Entry<String, Long> field : fields.entrySet()) {
addField(field.getKey(), field.getValue());
}
}

@Deprecated
public void addDoubleFields(final Map<String, Double> fields) {
if (fields == null) {
return;
}

for (Map.Entry<String, Double> field : fields.entrySet()) {
addField(field.getKey(), field.getValue());
}
}

public void removeField(final String key) {
if (!RESERVED_FIELDS.contains(key)) {
final Object removedValue = fields.remove(key);
Expand Down
58 changes: 0 additions & 58 deletions graylog2-server/src/test/java/org/graylog2/plugin/MessageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,48 +170,6 @@ public void testAddFields() throws Exception {
assertEquals(1, message.getField("field2"));
}

@Test
@SuppressWarnings("deprecation")
public void testAddStringFields() throws Exception {
final Map<String, String> map = Maps.newHashMap();

map.put("field1", "Foo");
map.put("field2", "Bar");

message.addStringFields(map);

assertEquals("Foo", message.getField("field1"));
assertEquals("Bar", message.getField("field2"));
}

@Test
@SuppressWarnings("deprecation")
public void testAddLongFields() throws Exception {
final Map<String, Long> map = Maps.newHashMap();

map.put("field1", 10L);
map.put("field2", 230L);

message.addLongFields(map);

assertEquals(10L, message.getField("field1"));
assertEquals(230L, message.getField("field2"));
}

@Test
@SuppressWarnings("deprecation")
public void testAddDoubleFields() throws Exception {
final Map<String, Double> map = Maps.newHashMap();

map.put("field1", 10.0d);
map.put("field2", 230.2d);

message.addDoubleFields(map);

assertEquals(10.0d, message.getField("field1"));
assertEquals(230.2d, message.getField("field2"));
}

@Test
public void testRemoveField() throws Exception {
message.addField("foo", "bar");
Expand Down Expand Up @@ -529,22 +487,6 @@ public void testIsComplete() throws Exception {
assertFalse(message.isComplete());
}

@Test
@SuppressWarnings("deprecation")
public void testGetValidationErrorsWithEmptyMessage() throws Exception {
final Message message = new Message("", "source", Tools.nowUTC());

assertEquals("message is empty, ", message.getValidationErrors());
}

@Test
@SuppressWarnings("deprecation")
public void testGetValidationErrorsWithNullMessage() throws Exception {
final Message message = new Message(null, "source", Tools.nowUTC());

assertEquals("message is missing, ", message.getValidationErrors());
}

@Test
public void testGetFields() throws Exception {
final Map<String, Object> fields = message.getFields();
Expand Down

0 comments on commit 801bd45

Please sign in to comment.