From 30067cb953234144643407265618d5681edf1a48 Mon Sep 17 00:00:00 2001 From: dilanSachi Date: Fri, 27 Oct 2023 21:08:01 +0530 Subject: [PATCH] Fix suggestions --- ballerina/queue_manager.bal | 2 +- ballerina/types.bal | 2 +- .../ballerina/lib/ibm.ibmmq/CommonUtils.java | 39 +++++++++---------- .../io/ballerina/lib/ibm.ibmmq/Constants.java | 2 + .../lib/ibm.ibmmq/MQThreadFactory.java | 1 - .../ballerina/lib/ibm.ibmmq/QueueManager.java | 12 +++--- .../io/ballerina/lib/ibm.ibmmq/Topic.java | 4 +- 7 files changed, 30 insertions(+), 32 deletions(-) diff --git a/ballerina/queue_manager.bal b/ballerina/queue_manager.bal index adab5e2..65a03d8 100644 --- a/ballerina/queue_manager.bal +++ b/ballerina/queue_manager.bal @@ -31,7 +31,7 @@ public isolated class QueueManager { return error Error("Not implemented"); } - public isolated function accessTopic(string topicName, string topicString, OPEN_AS_OPTION openAs, AccessTopicOptions options) returns Topic|Error = + public isolated function accessTopic(string topicName, string topicString, OPEN_TOPIC_OPTION openTopicOption, AccessTopicOptions options) returns Topic|Error = @java:Method { 'class: "io.ballerina.lib.ibm.ibmmq.QueueManager" } external; diff --git a/ballerina/types.bal b/ballerina/types.bal index b9a8dba..669ccd9 100644 --- a/ballerina/types.bal +++ b/ballerina/types.bal @@ -16,7 +16,7 @@ public type GM_OPTIONS MQGMO_WAIT|MQGMO_NO_WAIT|MQGMO_SYNCPOINT|MQGMO_NO_SYNCPOINT|MQGMO_BROWSE_FIRST|MQGMO_BROWSE_MSG_UNDER_CURSOR|MQGMO_MSG_UNDER_CURSOR|MQGMO_LOCK|MQGMO_UNLOCK|MQGMO_ACCEPT_TRUNCATED_MSG|MQGMO_BROWSE_NEXT|MQGMO_ACCEPT_TRUNCATED_MSG|MQGMO_FAIL_IF_QUIESCING|MQGMO_CONVERT; -public type OPEN_AS_OPTION OPEN_AS_SUBSCRIPTION|OPEN_AS_PUBLICATION; +public type OPEN_TOPIC_OPTION OPEN_AS_SUBSCRIPTION|OPEN_AS_PUBLICATION; public type QueueManagerConfiguration record {| string name; diff --git a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/CommonUtils.java b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/CommonUtils.java index 1b4a567..8401733 100644 --- a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/CommonUtils.java +++ b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/CommonUtils.java @@ -43,9 +43,6 @@ */ public class CommonUtils { - public static final String BTOPIC = "TOPIC"; - public static final String TOPIC_OBJECT = "TOPIC_OBJECT"; - private static final String ERROR_DETAILS = "ErrorDetails"; private static final BString ERROR_REASON_CODE = StringUtils.fromString("reasonCode"); private static final BString ERROR_ERROR_CODE = StringUtils.fromString("errorCode"); @@ -101,10 +98,10 @@ private static BMap getBProperties(MQMessage mqMessage) throws BMap property = ValueCreator.createRecordValue(getModule(), BPROPERTY); MQPropertyDescriptor propertyDescriptor = new MQPropertyDescriptor(); Object propertyObject = mqMessage.getObjectProperty(propertyName, propertyDescriptor); - if (propertyObject instanceof Integer) { - property.put(PROPERTY_VALUE, ((Integer) propertyObject).longValue()); - } else if (propertyObject instanceof String) { - property.put(PROPERTY_VALUE, StringUtils.fromString((String) propertyObject)); + if (propertyObject instanceof Integer intProperty) { + property.put(PROPERTY_VALUE, intProperty.longValue()); + } else if (propertyObject instanceof String stringProperty) { + property.put(PROPERTY_VALUE, StringUtils.fromString(stringProperty)); } else { property.put(PROPERTY_VALUE, propertyObject); } @@ -134,20 +131,20 @@ private static void handlePropertyValue(BMap properties, MQMess propertyDescriptor = getMQPropertyDescriptor(properties.getMapValue(PROPERTY_DESCRIPTOR)); } Object value = property.get(PROPERTY_VALUE); - if (value instanceof Long) { - mqMessage.setIntProperty(key.getValue(), propertyDescriptor, ((Long) properties.get(key)).intValue()); - } else if (value instanceof Boolean) { - mqMessage.setBooleanProperty(key.getValue(), propertyDescriptor, ((Boolean) properties.get(key))); - } else if (value instanceof Byte) { - mqMessage.setByteProperty(key.getValue(), propertyDescriptor, (Byte) properties.get(key)); - } else if (value instanceof byte[]) { - mqMessage.setBytesProperty(key.getValue(), propertyDescriptor, ((byte[]) properties.get(key))); - } else if (value instanceof Float) { - mqMessage.setFloatProperty(key.getValue(), propertyDescriptor, (Float) properties.get(key)); - } else if (value instanceof Double) { - mqMessage.setDoubleProperty(key.getValue(), propertyDescriptor, (Double) properties.get(key)); - } else if (value instanceof BString) { - mqMessage.setStringProperty(key.getValue(), propertyDescriptor, ((BString) properties.get(key)).getValue()); + if (value instanceof Long longValue) { + mqMessage.setIntProperty(key.getValue(), propertyDescriptor, longValue.intValue()); + } else if (value instanceof Boolean booleanValue) { + mqMessage.setBooleanProperty(key.getValue(), propertyDescriptor, booleanValue); + } else if (value instanceof Byte byteValue) { + mqMessage.setByteProperty(key.getValue(), propertyDescriptor, byteValue); + } else if (value instanceof byte[] bytesValue) { + mqMessage.setBytesProperty(key.getValue(), propertyDescriptor, bytesValue); + } else if (value instanceof Float floatValue) { + mqMessage.setFloatProperty(key.getValue(), propertyDescriptor, floatValue); + } else if (value instanceof Double doubleValue) { + mqMessage.setDoubleProperty(key.getValue(), propertyDescriptor, doubleValue); + } else if (value instanceof BString stringValue) { + mqMessage.setStringProperty(key.getValue(), propertyDescriptor, stringValue.getValue()); } } diff --git a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/Constants.java b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/Constants.java index d9ad77b..2145199 100644 --- a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/Constants.java +++ b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/Constants.java @@ -24,4 +24,6 @@ public interface Constants { // Native properties in respective ballerina objects public static final String NATIVE_QUEUE_MANAGER = "queueManager"; + + public static final String NATIVE_TOPIC = "topic"; } diff --git a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/MQThreadFactory.java b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/MQThreadFactory.java index ab95b27..1f7ab82 100644 --- a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/MQThreadFactory.java +++ b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/MQThreadFactory.java @@ -34,5 +34,4 @@ public Thread newThread(Runnable runnable) { ibmMqClientThread.setName(threadGroupName); return ibmMqClientThread; } - } diff --git a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/QueueManager.java b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/QueueManager.java index b468651..d51f9c8 100644 --- a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/QueueManager.java +++ b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/QueueManager.java @@ -22,7 +22,6 @@ import com.ibm.mq.MQQueueManager; import com.ibm.mq.MQTopic; import com.ibm.mq.constants.MQConstants; -import io.ballerina.runtime.api.Environment; import io.ballerina.runtime.api.creators.ValueCreator; import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.values.BMap; @@ -46,6 +45,7 @@ public class QueueManager { private static final BString CHANNEL = StringUtils.fromString("channel"); private static final BString USER_ID = StringUtils.fromString("userID"); private static final BString PASSWORD = StringUtils.fromString("password"); + private static final String BTOPIC = "Topic"; /** * Creates a JMS connection with the provided configurations. @@ -67,14 +67,14 @@ public static Object init(BObject queueManager, BMap configurat return null; } - public static Object accessTopic(Environment env, BObject queueManagerObject, BString topicName, - BString topicString, Long openAs, Long options) { + public static Object accessTopic(BObject queueManagerObject, BString topicName, + BString topicString, Long openTopicOption, Long options) { MQQueueManager queueManager = (MQQueueManager) queueManagerObject.getNativeData(NATIVE_QUEUE_MANAGER); try { MQTopic mqTopic = queueManager.accessTopic(topicName.getValue(), topicString.getValue(), - openAs.intValue(), options.intValue()); - BObject bTopic = ValueCreator.createObjectValue(ModuleUtils.getModule(), CommonUtils.BTOPIC); - bTopic.addNativeData(CommonUtils.TOPIC_OBJECT, mqTopic); + openTopicOption.intValue(), options.intValue()); + BObject bTopic = ValueCreator.createObjectValue(ModuleUtils.getModule(), BTOPIC); + bTopic.addNativeData(Constants.NATIVE_TOPIC, mqTopic); return bTopic; } catch (MQException e) { return createError(IBMMQ_ERROR, diff --git a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/Topic.java b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/Topic.java index decba79..f960775 100644 --- a/native/src/main/java/io/ballerina/lib/ibm.ibmmq/Topic.java +++ b/native/src/main/java/io/ballerina/lib/ibm.ibmmq/Topic.java @@ -39,7 +39,7 @@ public class Topic { private static final BString OPTIONS = StringUtils.fromString("options"); public static Object put(Environment environment, BObject topicObject, BMap message) { - MQTopic topic = (MQTopic) topicObject.getNativeData(CommonUtils.TOPIC_OBJECT); + MQTopic topic = (MQTopic) topicObject.getNativeData(Constants.NATIVE_TOPIC); MQMessage mqMessage = CommonUtils.getMqMessageFromBMessage(message); Future future = environment.markAsync(); topicExecutorService.execute(() -> { @@ -54,7 +54,7 @@ public static Object put(Environment environment, BObject topicObject, BMap mess } public static Object get(Environment environment, BObject topicObject, BMap options) { - MQTopic topic = (MQTopic) topicObject.getNativeData(CommonUtils.TOPIC_OBJECT); + MQTopic topic = (MQTopic) topicObject.getNativeData(Constants.NATIVE_TOPIC); MQGetMessageOptions getMessageOptions = getGetMessageOptions(options); Future future = environment.markAsync(); topicExecutorService.execute(() -> {