ARTEMIS-5071 align naming for management option syntax

This commit aligns the naming for the management option syntax but also
retains support for the old naming.
This commit is contained in:
Justin Bertram 2024-09-26 14:14:34 -05:00 committed by Timothy Bish
parent a89c452ab7
commit 022ec167cf
16 changed files with 111 additions and 43 deletions

View File

@ -124,7 +124,7 @@ var Artemis;
operation: "",
value: "",
sortOrder: "asc",
sortColumn: "id"
sortField: "id"
},
text: {
fieldText: "Filter Field..",
@ -167,7 +167,7 @@ var Artemis;
ctrl.filter.values.operation = "";
ctrl.filter.values.value = "";
ctrl.filter.sortOrder = "asc";
ctrl.filter.sortColumn = "id";
ctrl.filter.sortField = "id";
ctrl.refreshed = true;
artemisAddress.address = null;
ctrl.pagination.load();
@ -220,7 +220,7 @@ var Artemis;
operation: ctrl.filter.values.operation,
value: ctrl.filter.values.value,
sortOrder: ctrl.filter.values.sortOrder,
sortColumn: ctrl.filter.values.sortColumn
sortField: ctrl.filter.values.sortField
};
if (ctrl.refreshed == true) {

View File

@ -146,7 +146,7 @@ var Artemis;
operation: "",
value: "",
sortOrder: "asc",
sortColumn: "connectionID"
sortField: "connectionID"
},
text: {
fieldText: "Filter Field..",
@ -204,7 +204,7 @@ var Artemis;
ctrl.filter.values.operation = "";
ctrl.filter.values.value = "";
ctrl.filter.sortOrder = "asc";
ctrl.filter.sortColumn = "connectionID";
ctrl.filter.sortField = "connectionID";
ctrl.filter.text.fieldText = "Filter Field..";
ctrl.filter.text.operationText = "Operation..";
ctrl.filter.text.sortOrderText = "ascending";
@ -222,7 +222,7 @@ var Artemis;
operation: ctrl.filter.values.operation,
value: ctrl.filter.values.value,
sortOrder: ctrl.filter.values.sortOrder,
sortColumn: ctrl.filter.values.sortColumn
sortField: ctrl.filter.values.sortField
};
if (ctrl.refreshed == true) {

View File

@ -164,7 +164,7 @@ var Artemis;
operation: "",
value: "",
sortOrder: "asc",
sortColumn: "id"
sortField: "id"
},
text: {
fieldText: "Filter Field..",
@ -218,7 +218,7 @@ var Artemis;
ctrl.filter.values.operation = "";
ctrl.filter.values.value = "";
ctrl.filter.sortOrder = "asc";
ctrl.filter.sortColumn = "id";
ctrl.filter.sortField = "id";
ctrl.filter.text.fieldText = "Filter Field..";
ctrl.filter.text.operationText = "Operation..";
ctrl.filter.text.sortOrderText = "ascending";
@ -291,7 +291,7 @@ var Artemis;
operation: ctrl.filter.values.operation,
value: ctrl.filter.values.value,
sortOrder: ctrl.filter.values.sortOrder,
sortColumn: ctrl.filter.values.sortColumn
sortField: ctrl.filter.values.sortField
};
if (ctrl.refreshed == true) {

View File

@ -130,7 +130,7 @@ var Artemis;
operation: "",
value: "",
sortOrder: "asc",
sortColumn: "id"
sortField: "id"
},
text: {
fieldText: "Filter Field..",
@ -168,7 +168,7 @@ var Artemis;
ctrl.filter.values.operation = "";
ctrl.filter.values.value = "";
ctrl.filter.sortOrder = "asc";
ctrl.filter.sortColumn = "id";
ctrl.filter.sortField = "id";
ctrl.filter.text.fieldText = "Filter Field..";
ctrl.filter.text.operationText = "Operation..";
ctrl.filter.text.sortOrderText = "ascending";
@ -208,7 +208,7 @@ var Artemis;
operation: ctrl.filter.values.operation,
value: ctrl.filter.values.value,
sortOrder: ctrl.filter.values.sortOrder,
sortColumn: ctrl.filter.values.sortColumn
sortField: ctrl.filter.values.sortField
};
if (ctrl.refreshed == true) {

View File

@ -162,7 +162,7 @@ var Artemis;
operation: "",
value: "",
sortOrder: "asc",
sortColumn: "id"
sortField: "id"
},
text: {
fieldText: "Filter Field..",
@ -233,7 +233,7 @@ var Artemis;
ctrl.filter.values.operation = "";
ctrl.filter.values.value = "";
ctrl.filter.sortOrder = "asc";
ctrl.filter.sortColumn = "id";
ctrl.filter.sortField = "id";
ctrl.filter.text.fieldText = "Filter Field..";
ctrl.filter.text.operationText = "Operation..";
ctrl.filter.text.sortOrderText = "ascending";
@ -321,7 +321,7 @@ var Artemis;
operation: ctrl.filter.values.operation,
value: ctrl.filter.values.value,
sortOrder: ctrl.filter.values.sortOrder,
sortColumn: ctrl.filter.values.sortColumn
sortField: ctrl.filter.values.sortField
};
if (ctrl.refreshed == true) {

View File

@ -143,7 +143,7 @@ var Artemis;
operation: "",
value: "",
sortOrder: "asc",
sortColumn: "id"
sortField: "id"
},
text: {
fieldText: "Filter Field..",
@ -182,7 +182,7 @@ var Artemis;
ctrl.filter.values.operation = "";
ctrl.filter.values.value = "";
ctrl.filter.sortOrder = "asc";
ctrl.filter.sortColumn = "id";
ctrl.filter.sortField = "id";
ctrl.filter.text.fieldText = "Filter Field..";
ctrl.filter.text.operationText = "Operation..";
ctrl.filter.text.sortOrderText = "ascending";
@ -257,7 +257,7 @@ var Artemis;
operation: ctrl.filter.values.operation,
value: ctrl.filter.values.value,
sortOrder: ctrl.filter.values.sortOrder,
sortColumn: ctrl.filter.values.sortColumn
sortField: ctrl.filter.values.sortField
};
if (ctrl.refreshed == true) {

View File

@ -51,7 +51,7 @@ var Artemis;
<button type="button" class="btn btn-default dropdown-toggle" id="filter" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">{{$ctrl.filter.text.sortByText}}<span class="caret"></span></button>
<ul class="dropdown-menu">
<li ng-repeat="option in $ctrl.filter.fieldOptions"
id="option.id" ng-click="$ctrl.filter.values.sortColumn = option.id;$ctrl.filter.text.sortByText = option.name">{{ option.name }}</ul>
id="option.id" ng-click="$ctrl.filter.values.sortField = option.id;$ctrl.filter.text.sortByText = option.name">{{ option.name }}</ul>
</ul>
</div>
<div class="input-group-btn">

View File

@ -42,23 +42,28 @@ public abstract class ActiveMQAbstractView<T> {
private static final String SORT_ORDER = "sortOrder";
private static final String ASCENDING = "asc";
private static final String DESCENDING = "desc";
@Deprecated(forRemoval = true)
private static final String SORT_COLUMN = "sortColumn";
private static final String SORT_FIELD = "sortField";
private static final JsonObject DEFAULT_FILTER = JsonUtil.toJsonObject(Map.of(FILTER_FIELD, "", FILTER_OPERATION, "", FILTER_VALUE, ""));
protected Collection<T> collection;
protected ActiveMQFilterPredicate<T> predicate;
protected String sortColumn;
protected String sortField;
protected String sortOrder;
protected String options;
public ActiveMQAbstractView() {
this.sortColumn = getDefaultOrderColumn();
this.sortOrder = "asc";
this.sortField = getDefaultOrderColumn();
this.sortOrder = ASCENDING;
}
public void setCollection(Collection<T> collection) {
@ -102,10 +107,10 @@ public abstract class ActiveMQAbstractView<T> {
public Comparator<T> getComparator() {
return (left, right) -> {
try {
Object leftValue = getField(left, sortColumn);
Object rightValue = getField(right, sortColumn);
Object leftValue = getField(left, sortField);
Object rightValue = getField(right, sortField);
if (leftValue instanceof Comparable && rightValue instanceof Comparable) {
if (sortOrder.equals("desc")) {
if (sortOrder.equalsIgnoreCase(DESCENDING)) {
return ((Comparable) rightValue).compareTo(leftValue);
} else {
return ((Comparable) leftValue).compareTo(rightValue);
@ -132,8 +137,12 @@ public abstract class ActiveMQAbstractView<T> {
predicate.setField(json.getString(FILTER_FIELD));
predicate.setOperation(json.getString(FILTER_OPERATION));
predicate.setValue(json.getString(FILTER_VALUE));
if (json.containsKey(SORT_COLUMN) && json.containsKey(SORT_ORDER)) {
this.sortColumn = json.getString(SORT_COLUMN);
if ((json.containsKey(SORT_COLUMN) || json.containsKey(SORT_FIELD)) && json.containsKey(SORT_ORDER)) {
if (json.containsKey(SORT_COLUMN)) {
this.sortField = json.getString(SORT_COLUMN);
} else {
this.sortField = json.getString(SORT_FIELD);
}
this.sortOrder = json.getString(SORT_ORDER);
}
}
@ -145,6 +154,14 @@ public abstract class ActiveMQAbstractView<T> {
public abstract String getDefaultOrderColumn();
public String getSortField() {
return sortField;
}
public String getSortOrder() {
return sortOrder;
}
/**
* JsonObjectBuilder will throw an NPE if a null value is added. For this reason we check for null explicitly when
* adding objects.

View File

@ -24,7 +24,7 @@ import org.apache.activemq.artemis.utils.JsonLoader;
public class AddressView extends ActiveMQAbstractView<AddressInfo> {
private static final String defaultSortColumn = AddressField.ID.getName();
private static final String defaultSortField = AddressField.ID.getName();
private final ActiveMQServer server;
@ -90,6 +90,6 @@ public class AddressView extends ActiveMQAbstractView<AddressInfo> {
@Override
public String getDefaultOrderColumn() {
return defaultSortColumn;
return defaultSortField;
}
}

View File

@ -31,7 +31,7 @@ import org.apache.activemq.artemis.utils.StringUtil;
public class ConnectionView extends ActiveMQAbstractView<RemotingConnection> {
private static final String defaultSortColumn = ConnectionField.CONNECTION_ID.getName();
private static final String defaultSortField = ConnectionField.CONNECTION_ID.getName();
private final ActiveMQServer server;
@ -104,6 +104,6 @@ public class ConnectionView extends ActiveMQAbstractView<RemotingConnection> {
@Override
public String getDefaultOrderColumn() {
return defaultSortColumn;
return defaultSortField;
}
}

View File

@ -32,7 +32,7 @@ public class ConsumerView extends ActiveMQAbstractView<ServerConsumer> {
public static final String CONSUMER_STATUS_ORPHANED = "Orphaned";
private static final String defaultSortColumn = ConsumerField.ID.getName();
private static final String defaultSortField = ConsumerField.ID.getName();
private final ActiveMQServer server;
@ -153,6 +153,6 @@ public class ConsumerView extends ActiveMQAbstractView<ServerConsumer> {
@Override
public String getDefaultOrderColumn() {
return defaultSortColumn;
return defaultSortField;
}
}

View File

@ -25,7 +25,7 @@ import org.apache.activemq.artemis.utils.JsonLoader;
public class ProducerView extends ActiveMQAbstractView<ServerProducer> {
private static final String defaultSortColumn = ProducerField.CREATION_TIME.getName();
private static final String defaultSortField = ProducerField.CREATION_TIME.getName();
private final ActiveMQServer server;
@ -106,6 +106,6 @@ public class ProducerView extends ActiveMQAbstractView<ServerProducer> {
@Override
public String getDefaultOrderColumn() {
return defaultSortColumn;
return defaultSortField;
}
}

View File

@ -26,7 +26,7 @@ import org.apache.activemq.artemis.utils.JsonLoader;
public class QueueView extends ActiveMQAbstractView<QueueControl> {
private static final String defaultSortColumn = QueueField.NAME.getName();
private static final String defaultSortField = QueueField.NAME.getName();
private ActiveMQServer server;
@ -162,6 +162,6 @@ public class QueueView extends ActiveMQAbstractView<QueueControl> {
@Override
public String getDefaultOrderColumn() {
return defaultSortColumn;
return defaultSortField;
}
}

View File

@ -25,7 +25,7 @@ import org.apache.activemq.artemis.utils.JsonLoader;
public class SessionView extends ActiveMQAbstractView<ServerSession> {
private static final String defaultSortColumn = SessionField.ID.getName();
private static final String defaultSortField = SessionField.ID.getName();
public SessionView() {
super();
@ -79,6 +79,6 @@ public class SessionView extends ActiveMQAbstractView<ServerSession> {
@Override
public String getDefaultOrderColumn() {
return defaultSortColumn;
return defaultSortField;
}
}

View File

@ -20,6 +20,9 @@ import org.apache.activemq.artemis.core.server.ActiveMQServer;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
public class ViewTest {
@Test
@ -36,6 +39,14 @@ public class ViewTest {
connectionView.setOptions("");
}
@Test
public void testConnectionViewLegacySort() {
ConnectionView connectionView = new ConnectionView(Mockito.mock(ActiveMQServer.class));
assertNotEquals("protocol", connectionView.getDefaultOrderColumn());
connectionView.setOptions("{\"field\":\"protocol\",\"operation\":\"EQUALS\",\"value\":\"CORE\",\"sortColumn\":\"protocol\",\"sortOrder\":\"asc\"}");
assertEquals("protocol", connectionView.getSortField());
}
@Test
public void testDefaultSessionViewNullOptions() {
SessionView sessionView = new SessionView();
@ -50,6 +61,14 @@ public class ViewTest {
sessionView.setOptions("");
}
@Test
public void testSessionViewLegacySort() {
SessionView sessionView = new SessionView();
assertNotEquals("user", sessionView.getDefaultOrderColumn());
sessionView.setOptions("{\"field\":\"user\",\"operation\":\"EQUALS\",\"value\":\"123\",\"sortColumn\":\"user\",\"sortOrder\":\"asc\"}");
assertEquals("user", sessionView.getSortField());
}
@Test
public void testDefaultAddressViewNullOptions() {
AddressView addressView = new AddressView(Mockito.mock(ActiveMQServer.class));
@ -64,6 +83,14 @@ public class ViewTest {
addressView.setOptions("");
}
@Test
public void testAddressViewLegacySort() {
AddressView addressView = new AddressView(Mockito.mock(ActiveMQServer.class));
assertNotEquals("name", addressView.getDefaultOrderColumn());
addressView.setOptions("{\"field\":\"name\",\"operation\":\"EQUALS\",\"value\":\"123\",\"sortColumn\":\"name\",\"sortOrder\":\"asc\"}");
assertEquals("name", addressView.getSortField());
}
@Test
public void testDefaultQueueViewNullOptions() {
QueueView queueView = new QueueView(Mockito.mock(ActiveMQServer.class));
@ -78,6 +105,14 @@ public class ViewTest {
queueView.setOptions("");
}
@Test
public void testQueueViewLegacySort() {
QueueView view = new QueueView(Mockito.mock(ActiveMQServer.class));
assertNotEquals("id", view.getDefaultOrderColumn());
view.setOptions("{\"field\":\"id\",\"operation\":\"EQUALS\",\"value\":\"123\",\"sortColumn\":\"id\",\"sortOrder\":\"asc\"}");
assertEquals("id", view.getSortField());
}
@Test
public void testDefaultConsumerViewNullOptions() {
ConsumerView consumerView = new ConsumerView(Mockito.mock(ActiveMQServer.class));
@ -92,6 +127,14 @@ public class ViewTest {
consumerView.setOptions("");
}
@Test
public void testConsumerViewLegacySort() {
ConsumerView view = new ConsumerView(Mockito.mock(ActiveMQServer.class));
assertNotEquals("user", view.getDefaultOrderColumn());
view.setOptions("{\"field\":\"user\",\"operation\":\"EQUALS\",\"value\":\"123\",\"sortColumn\":\"user\",\"sortOrder\":\"asc\"}");
assertEquals("user", view.getSortField());
}
@Test
public void testDefaultProducerViewNullOptions() {
ProducerView producerView = new ProducerView(Mockito.mock(ActiveMQServer.class));
@ -105,4 +148,12 @@ public class ViewTest {
// sanity check to ensure this doesn't just blow up
producerView.setOptions("");
}
@Test
public void testProducerViewLegacySort() {
ProducerView view = new ProducerView(Mockito.mock(ActiveMQServer.class));
assertNotEquals("user", view.getDefaultOrderColumn());
view.setOptions("{\"field\":\"user\",\"operation\":\"EQUALS\",\"value\":\"123\",\"sortColumn\":\"user\",\"sortOrder\":\"asc\"}");
assertEquals("user", view.getSortField());
}
}

View File

@ -6317,12 +6317,12 @@ public class ActiveMQServerControlTest extends ManagementTestBase {
return ManagementControlHelper.createActiveMQServerControl(mbeanServer);
}
private String createJsonFilter(String fieldName, String operationName, String value,String sortColumn, String sortOrder) {
private String createJsonFilter(String fieldName, String operationName, String value, String sortField, String sortOrder) {
HashMap<String, Object> filterMap = new HashMap<>();
filterMap.put("field", fieldName);
filterMap.put("operation", operationName);
filterMap.put("value", value);
filterMap.put("sortColumn", sortColumn);
filterMap.put("sortField", sortField);
filterMap.put("sortOrder", sortOrder);
JsonObject jsonFilterObject = JsonUtil.toJsonObject(filterMap);
return jsonFilterObject.toString();