Project

General

Profile

Bug #9411

Implement SESSION:STREAM

Added by Alexandru Lungu over 1 year ago. Updated about 1 year ago.

Status:
Closed
Priority:
Normal
Assignee:
Eduard Marcu
Target version:
-
Start date:
Due date:
% Done:

100%

billable:
No
vendor_id:
GCD
case_num:
version_reported:
version_resolved:
production:
No
env_name:
topics:

1.png (8.09 KB) Eduard Marcu, 12/10/2024 08:25 AM

2.png (6.88 KB) Eduard Marcu, 12/10/2024 08:25 AM

3.png (8.09 KB) Eduard Marcu, 12/10/2024 08:25 AM

4.png (7.34 KB) Eduard Marcu, 12/10/2024 08:25 AM

5.png (7.34 KB) Eduard Marcu, 12/10/2024 08:25 AM

6.png (7.42 KB) Eduard Marcu, 12/10/2024 08:50 AM


Related issues

Related to Base Language - Bug #8294: SESSION attributes access statements produce uncompilable Java code New

History

#1 Updated by Alexandru Lungu over 1 year ago

This task is created to cover the implementation details of SESSION:STREAM.

#2 Updated by Alexandru Lungu over 1 year ago

  • Related to Bug #8294: SESSION attributes access statements produce uncompilable Java code added

#3 Updated by Eduard Marcu over 1 year ago

  • Status changed from New to WIP

#4 Updated by Eduard Marcu over 1 year ago

In method_attributes.rules:

               <!-- SESSION -->
               <rule>methodText.length() == 0 and
                     (htype == prog.kw_session or ref.type == prog.var_handle)

                  <rule> ftype == prog.kw_stream
                     <action>methodText = "SessionUtils.stream"</action>
                  </rule>
               ...

In SessionUtils:

    /**
    * Returns a value that specifies the character set used for operating system file I/O — "ibm850" or
    * "iso8859-1".
    *
    * @return   See above.
    */
   public static character stream()
   {
      String streamCP = I18nOps.convmap2JavaDefault
                               .get(I18nOps._getCPInternal()).equals("IBM850")  ? "IBM850" : "ISO8859-1";
      return new character(streamCP);
   }

I'm not sure if this can be considered a solution yet. I'll need to look further to make sure that SESSION:STREAM does indeed only return "IBM850" or "ISO8859-1".

#5 Updated by Eduard Marcu over 1 year ago

I tested the OE application and introduced other encoding formats in startup. SESSION:STREAM can also output other encodings such as UTF-8.

#6 Updated by Eduard Marcu over 1 year ago

    /**
    * Returns a value that specifies the character set used for operating system file I/O, such as"ibm850" or
    * "iso8859-1".
    *
    * @return   See above.
    */
   public static character stream()
   {
      String streamCP = I18nOps.convmap2JavaDefault.get(I18nOps._getCPInternal());
      return new character(streamCP);
   }

#7 Updated by Greg Shah over 1 year ago

  • reviewer Greg Shah added

That seems reasonable. Please put the changes in a branch.

#8 Updated by Eduard Marcu over 1 year ago

Committed 9411a revision 15609.

#9 Updated by Greg Shah over 1 year ago

Code Review Task Branch 9411a Revision 15609

1. Instead of SessionUtils, the getter should be in I18nOps.

2. The code should probably be reporting the same value as getCPStream() (SESSION:CPSTREAM) instead of _getCPInternal() (SESSION:CPINTERNAL). In other words, in OE does the SESSION:STREAM return value match the same value as SESSION:CPSTREAM or SESSION:CPINTERNAL? Please check. You will have to set the two values differently on the command line when starting the session.

3. The getter needs to be added to CommonSession with the proper annotations.

#10 Updated by Eduard Marcu over 1 year ago

  • % Done changed from 0 to 100
  • Status changed from WIP to Review

Greg Shah wrote:

Code Review Task Branch 9411a Revision 15609

1. Instead of SessionUtils, the getter should be in I18nOps.

2. The code should probably be reporting the same value as getCPStream() (SESSION:CPSTREAM) instead of _getCPInternal() (SESSION:CPINTERNAL). In other words, in OE does the SESSION:STREAM return value match the same value as SESSION:CPSTREAM or SESSION:CPINTERNAL? Please check. You will have to set the two values differently on the command line when starting the session.

3. The getter needs to be added to CommonSession with the proper annotations.

2. You are right. SESSION:STREAM should match SESSION:CPSTREAM:

output to text.tst.

message 
        session:stream
        session:cpstream
        session:CPINTERNAL
        .

output close.

Output:

ibm850 ibm850 ISO8859-1

=== modified file 'rules/convert/methods_attributes.rules'
--- old/rules/convert/methods_attributes.rules    2024-12-09 15:05:14 +0000
+++ new/rules/convert/methods_attributes.rules    2024-12-10 08:48:48 +0000
@@ -2438,7 +2438,7 @@
                      (htype == prog.kw_session or ref.type == prog.var_handle)

                   <rule> ftype == prog.kw_stream
-                     <action>methodText = "SessionUtils.stream"</action>
+                     <action>methodText = "I18nOps.stream"</action>
                   </rule>

                   <rule>ftype == prog.kw_supw_lst

=== modified file 'src/com/goldencode/p2j/util/CommonSession.java'
--- old/src/com/goldencode/p2j/util/CommonSession.java    2024-07-01 08:01:37 +0000
+++ new/src/com/goldencode/p2j/util/CommonSession.java    2024-12-10 08:52:09 +0000
@@ -59,6 +59,7 @@
 ** 035 GBB 20240301 Added multiple custom session attributes.
 ** 036 GBB 20240515 Added GET-LOGIN-PARAMETER method.
 ** 037 HC  20240630 Implemented support for WEB-FILE-UPLOAD statement.
+** 038 EM  20241210 Implemented support for SESSION:STREAM.
 */
 /*
 ** This program is free software: you can redistribute it and/or modify
@@ -401,7 +402,15 @@
     */
    @LegacyAttribute(name = "CPLOG")
    public character getCPLog();
-   
+
+   /**
+    * Returns a value that specifies the character set used for operating system file I/O using the Stream Code Page (-cpstream) startup parameter.
+    *
+    * @return   The SESSION:STREAM attribute.
+    */
+   @LegacyAttribute(name = "STREAM")
+   public character stream();
+
    /**
     * Reports the the value set using the Stream Code Page (-cpstream) startup parameter.
     * 

=== modified file 'src/com/goldencode/p2j/util/I18nOps.java'
--- old/src/com/goldencode/p2j/util/I18nOps.java    2024-07-03 14:06:51 +0000
+++ new/src/com/goldencode/p2j/util/I18nOps.java    2024-12-10 09:01:15 +0000
@@ -35,6 +35,7 @@
 ** 012 SB  20240411 Added getJavaCPInternal to get the JVM charset for the CP defined in
 **                  SESSION:CPINTERNAL.
 ** 013 SP  20240619 Added getWordDelimiters to get a regex list of delimiters based on codepage used.
+** 014 EM  20241210 Implemented support for SESSION:STREAM.
 */

 /*
@@ -993,7 +994,18 @@
    {
       return proCharset == null ? null : convmap2Java.get(proCharset);
    }
-   
+
+   /**
+    * Returns a value that specifies the character set used for operating system file I/O, such as"ibm850" or
+    * "iso8859-1".
+    *
+    * @return   See above.
+    */
+   public static character stream()
+   {
+      return new character(I18nOps.convmap2JavaDefault.get(I18nOps.getCPStream().value));
+   }
+
    /**
     * Reports the codepage used for streams (the equivalent of the CPSTREAM 4GL attribute), which
     * reports the value set using the &lt;code&gt;-cpstream&lt;/code&gt; startup parameter.

=== modified file 'src/com/goldencode/p2j/util/SessionUtils.java'
--- old/src/com/goldencode/p2j/util/SessionUtils.java    2024-12-09 15:05:14 +0000
+++ new/src/com/goldencode/p2j/util/SessionUtils.java    2024-12-10 08:47:32 +0000
@@ -106,7 +106,6 @@
 ** 056 GBB 20240709 Fixing getLoginParam javadoc.
 ** 057 GBB 20240826 Storing and retrieving SSO storageId.
 ** 058 GBB 20240912 Don't call the client with date updates if ALL OS resources are enabled server-side.
-** 059 EM  20241209 Implemented support for SESSION:STREAM.
 */

 /*
@@ -745,17 +744,6 @@
    }

    /**
-    * Returns a value that specifies the character set used for operating system file I/O, such as"ibm850" or
-    * "iso8859-1".
-    *
-    * @return   See above.
-    */
-   public static character stream()
-   {
-      String streamCP = I18nOps.convmap2JavaDefault.get(I18nOps._getCPInternal());
-      return new character(streamCP);
-   }
-   /**
     * Returns the handle for the last window in the session.
     * 
     * @return   The last window in the session's list of windows.


#11 Updated by Eduard Marcu over 1 year ago

Committed 9411a revision 15610.

#12 Updated by Eduard Marcu over 1 year ago

Since we moved the stream() method we should also do the following changes:

=== modified file 'src/com/goldencode/p2j/util/I18nOps.java'
--- old/src/com/goldencode/p2j/util/I18nOps.java    2024-12-10 09:06:10 +0000
+++ new/src/com/goldencode/p2j/util/I18nOps.java    2024-12-10 09:21:53 +0000
@@ -1003,7 +1003,7 @@
     */
    public static character stream()
    {
-      return new character(I18nOps.convmap2JavaDefault.get(I18nOps.getCPStream().value));
+      return new character(convmap2JavaDefault.get(getCPStream().value));
    }

    /**

Committed 9411a revision 15611.

#13 Updated by Alexandru Lungu over 1 year ago

Review of 9411a:

  • please keep the naming consistent with the rest of CommonSession API (aka use get prefix)
  • honor the 110 characters per line limitation.
  • the javadoc of CommonSession.stream is wrong
  • use _getCPStream instead of getCPStream to retrieve the actual String instead of character.
  • the javadoc of I18nOps.stream can be improved
    • there can be other streams return apparently, beside ibm850 and iso8859-1, right?
    • please rephrase and use an appropriate return description.
  • keep spacing consistent in: <rule> ftype == prog.kw_stream (remove leading space).

Functional: I might not properly understand the use of convmap2JavaDefault. What is the goal of converting to the Java CP equivalent to provide legacy support of STREAM?

#14 Updated by Eduard Marcu over 1 year ago

Alexandru Lungu wrote:

Functional: I might not properly understand the use of convmap2JavaDefault. What is the goal of converting to the Java CP equivalent to provide legacy support of STREAM?

This is not something that I can test on OE, but if we look at convmap2JavaDefault.put("1256", "windows-1256"); isn't the actual encoder "windows-1256" and not "1256"? Looking at convmap2JavaDefault I see that some keys look like they are shorter versions of the value they hold.

If convmap2JavaDefault is not needed then we can either change the rules to call getCPStream directly:

                   <rule> ftype == prog.kw_stream
                     <action>methodText = "I18nOps.getCPStream"</action>
                   </rule>

Or modify getStream as such:

   public static character getStream()
   {
      return getCPStream();
   }

#15 Updated by Greg Shah over 1 year ago

Eugenie: Please review and comment on #9411-14.

is not needed then we can either change the rules to call getCPStream directly

Does STREAM always report the same value as CPSTREAM in OE? If so, then you are right that we should consider just making STREAM a synonym for CPSTREAM instead of a separate getter. In other words, we could make STREAM convert to I18NOps.getCPStream() at conversion.

#16 Updated by Eduard Marcu over 1 year ago

I tested with every encoder and I found the following:
  • the encoder is the key of convmap2JavaDefault
  • SESSION:STREAM and SESSION:CPSTREAM always had the same value.

As such I think we can go ahead and make SESSION:STREAM be SESSION:CPSTREAM at conversion.

#17 Updated by Alexandru Lungu over 1 year ago

As such I think we can go ahead and make SESSION:STREAM be SESSION:CPSTREAM in conversion.

Running a 4GL application with -cpstream option at CLI is also changing STREAM? Also, using -stream option at CLI, does the CPSTREAM change?
Also, what happens if you specific an invalid -cpstream / -stream at CLI? Are their respective attribute unknown? Maybe they are different from the POV of error handling.

#18 Updated by Eduard Marcu over 1 year ago

Alexandru Lungu wrote:

Running a 4GL application with -cpstream option at CLI is also changing STREAM?

Yes.

Also, using -stream option at CLI, does the CPSTREAM change?

Yes.

Also, what happens if you specific an invalid -cpstream / -stream at CLI? Are their respective attribute unknown? Maybe they are different from the POV of error handling.

I've run these different snippets: message session:cpstream and message session:stream with -cpstream "IBM857" and they threw the same errors in the same order.

#19 Updated by Eduard Marcu over 1 year ago

I think it's worth mentioning that even if I set -stream "someEncoder" the error message contains -cpstream not -stream.

#20 Updated by Greg Shah over 1 year ago

Perfect. OE treats these as synonyms too. Go ahead with that idea.

#21 Updated by Eduard Marcu over 1 year ago

Committed 9411a revision 15609.

=== modified file 'rules/convert/methods_attributes.rules'
--- old/rules/convert/methods_attributes.rules    2024-07-01 08:01:37 +0000
+++ new/rules/convert/methods_attributes.rules    2024-12-10 14:18:50 +0000
@@ -566,6 +566,7 @@
 ** 235 GBB 20240515          Added conversion for SESSION:GET-LOGIN-PARAMETER.
 ** 236 GBB 20240610          Move getClientType from LogicalTerminal to SessionUtils.
 ** 237 HC  20240630          Implemented support for WEB-FILE-UPLOAD statement.
+** 238 EM  20241210          Implemented support for SESSION:STREAM.
 */
  -->

@@ -2610,7 +2611,7 @@
                      <action>methodText = "I18nOps.getCPRCodeOut"</action>
                   </rule>

-                  <rule>ftype == prog.kw_cpstream
+                  <rule>ftype == prog.kw_cpstream or ftype == prog.kw_stream
                      <action>methodText = "I18nOps.getCPStream"</action>
                   </rule>

#22 Updated by Greg Shah over 1 year ago

Please apply the changes to the branch.

#23 Updated by Eduard Marcu over 1 year ago

It is already committed!

#24 Updated by Eugenie Lyzenko over 1 year ago

Greg Shah wrote:

Eugenie: Please review and comment on #9411-14.

is not needed then we can either change the rules to call getCPStream directly

Does STREAM always report the same value as CPSTREAM in OE? If so, then you are right that we should consider just making STREAM a synonym for CPSTREAM instead of a separate getter. In other words, we could make STREAM convert to I18NOps.getCPStream() at conversion.

I agree, we can consider STREAM and CPSTREAM as synonyms, making same call in converted code.

For convmap2JavaDefault purpose. This is a map to make make relationship between encoding name used in 4GL and relative name used in Java. Because sometimes the names can be different for the same encoding to use. That's my understanding for the map usage (initially designed for).

#25 Updated by Alexandru Lungu over 1 year ago

  • reviewer Alexandru Lungu added

I am OK with the changes in 9411a.

#26 Updated by Alexandru Lungu over 1 year ago

  • Status changed from Review to Internal Test

#27 Updated by Greg Shah over 1 year ago

Please update the gap marking for this attribute (mark it full/partial the same way that cpstream is marked).

Then let's get this merged.

#28 Updated by Eduard Marcu over 1 year ago

Committed 9411a revision 15610.

#29 Updated by Greg Shah over 1 year ago

  • Status changed from Internal Test to Merge Pending

Code Review Task Branch 9411a Revision 15610

It is good.

You can merge to trunk now.

#30 Updated by Greg Shah over 1 year ago

  • Status changed from Merge Pending to Internal Test

I'm removing this from the merge queue so that the queue is not blocked. Let me know when you are ready to perform the merge.

#31 Updated by Alexandru Lungu over 1 year ago

  • Status changed from Internal Test to Test

Branch 9411a was merged in trunk revision 15631 and archived.

#33 Updated by Alexandru Lungu about 1 year ago

  • Status changed from Test to Closed

This can be closed.

Also available in: Atom PDF