apache / hop

Hop Orchestration Platform
https://hop.apache.org/
Apache License 2.0
982 stars 351 forks source link

[Task]: Cleanup XML of transform `WriteToLog` #4145

Open nadment opened 3 months ago

nadment commented 3 months ago

What needs to happen?

Cleanup XML of transform WriteToLog

Issue Priority

Priority: 3

Issue Component

Component: Metadata, Component: Transforms

nadment commented 3 months ago

Duplicate #1949

hansva commented 3 months ago

Something has gone wrong with this

java.lang.NullPointerException: Cannot invoke "org.apache.hop.core.logging.LogLevel.ordinal()" because "loglevel" is null
    at org.apache.hop.pipeline.transforms.writetolog.WriteToLog.setLog(WriteToLog.java:130)
    at org.apache.hop.pipeline.transforms.writetolog.WriteToLog.processRow(WriteToLog.java:116)
    at org.apache.hop.pipeline.transform.RunThread.run(RunThread.java:54)
    at java.base/java.lang.Thread.run(Thread.java:840)
nadment commented 3 months ago

Sorry, I trusted the Junit tests blindly !

The transform Log level property in XML:

The WriteToLog action also uses <loglevel>Basic</loglevel>

I think we should keep the current form of storage.

We can renforce code, if it's null we use Basic as default. We can also add a patch to deserialize Hop's value from 1.0 to 2.9 or agree to reset it to Basic by default ?

hansva commented 3 months ago

Yes I did I think something like that in the past accept all of the values but only save the correct ones

nadment commented 3 months ago

I have a fix for the NPE but for the moment it's not backwards compatible and I haven't found a way in LogLevel or XmlMetadataUtil to use an alias.

public static LogLevel lookupCode(final String code) {

// Try alias for WriteToLog transform compatibility version before 2.10
LogLevel alias = IEnumHasCode.lookupCode(LogLevel.class, "log_level_" + code, null);
if (alias != null) {
  return alias;
}

return IEnumHasCode.lookupCode(LogLevel.class, code, LogLevel.BASIC);

}

nadment commented 3 months ago

I can't find a way except to add a method to the IEnumHasCode interface and use it in XmlMetadataUtil.

public interface IEnumHasCode {
  String getCode();
  /** Returns a list of code aliases, useful for backward compatibility. */
  default List<String> getAlias() {
    return List.of();
  }
}

Someone might have a better idea?