diff --git a/plugins/tech/neo4j/src/main/java/org/apache/hop/neo4j/transforms/loginfo/GetLoggingInfo.java b/plugins/tech/neo4j/src/main/java/org/apache/hop/neo4j/transforms/loginfo/GetLoggingInfo.java index d826c92a21..84a1a26055 100644 --- a/plugins/tech/neo4j/src/main/java/org/apache/hop/neo4j/transforms/loginfo/GetLoggingInfo.java +++ b/plugins/tech/neo4j/src/main/java/org/apache/hop/neo4j/transforms/loginfo/GetLoggingInfo.java @@ -63,19 +63,19 @@ private Object[] getLoggingInfo(IRowMeta inputRowMeta, Object[] inputRowData) th for (int i = 0; i < inputRowMeta.size(); i++) { row[i] = inputRowData[i]; // no data is changed, clone is not needed here. } - for (int i = 0, index = inputRowMeta.size(); i < meta.getFieldName().length; i++, index++) { + for (int i = 0, index = inputRowMeta.size(); i < meta.getFields().size(); i++, index++) { Calendar cal; int argnr = 0; - String argument = meta.getFieldArgument()[i]; + String argument = meta.getFields().get(i).getFieldArgument(); if (StringUtils.isEmpty(argument)) { argument = getPipeline().getPipelineMeta().getName(); } else { argument = resolve(argument); } - switch (meta.getFieldType()[i]) { + switch (meta.getFields().get(i).getFieldType()) { case TYPE_SYSTEM_INFO_PIPELINE_DATE_FROM: { Date previousSuccess = getPreviousPipelineSuccess(argument); diff --git a/plugins/tech/neo4j/src/main/java/org/apache/hop/neo4j/transforms/loginfo/GetLoggingInfoDialog.java b/plugins/tech/neo4j/src/main/java/org/apache/hop/neo4j/transforms/loginfo/GetLoggingInfoDialog.java index 3d7aafcef2..0a63b4fe67 100644 --- a/plugins/tech/neo4j/src/main/java/org/apache/hop/neo4j/transforms/loginfo/GetLoggingInfoDialog.java +++ b/plugins/tech/neo4j/src/main/java/org/apache/hop/neo4j/transforms/loginfo/GetLoggingInfoDialog.java @@ -54,7 +54,7 @@ public class GetLoggingInfoDialog extends BaseTransformDialog { private static final Class PKG = GetLoggingInfo.class; // for i18n purposes, needed by Translator2!! - private Text wTransformname; + private Text wTransformName; private TableView wFields; @@ -116,35 +116,35 @@ public void modifyText(ModifyEvent e) { isReceivingInput = !pipelineMeta.findPreviousTransforms(transformMeta).isEmpty(); // Transform name line - Label wlTransformname = new Label(shell, SWT.RIGHT); + Label wlTransformName = new Label(shell, SWT.RIGHT); wlTransformName.setText(BaseMessages.getString(PKG, "System.TransformName.Label")); wlTransformName.setToolTipText(BaseMessages.getString(PKG, "System.TransformName.Tooltip")); - PropsUi.setLook(wlTransformname); + PropsUi.setLook(wlTransformName); FormData fdlTransformname = new FormData(); fdlTransformname.left = new FormAttachment(0, 0); fdlTransformname.right = new FormAttachment(middle, -margin); fdlTransformname.top = new FormAttachment(0, margin); - wlTransformname.setLayoutData(fdlTransformname); - wTransformname = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); - wTransformname.setText(transformName); - PropsUi.setLook(wTransformname); - wTransformname.addModifyListener(lsMod); + wlTransformName.setLayoutData(fdlTransformname); + wTransformName = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); + wTransformName.setText(transformName); + PropsUi.setLook(wTransformName); + wTransformName.addModifyListener(lsMod); FormData fdTransformname = new FormData(); fdTransformname.left = new FormAttachment(middle, 0); fdTransformname.top = new FormAttachment(0, margin); fdTransformname.right = new FormAttachment(100, 0); - wTransformname.setLayoutData(fdTransformname); + wTransformName.setLayoutData(fdTransformname); Label wlFields = new Label(shell, SWT.NONE); wlFields.setText(BaseMessages.getString(PKG, "GetLoggingInfoDialog.Fields.Label")); PropsUi.setLook(wlFields); FormData fdlFields = new FormData(); fdlFields.left = new FormAttachment(0, 0); - fdlFields.top = new FormAttachment(wTransformname, margin); + fdlFields.top = new FormAttachment(wTransformName, margin); wlFields.setLayoutData(fdlFields); final int FieldsCols = 3; - final int FieldsRows = input.getFieldName().length; + final int FieldsRows = input.getFields().size(); final String[] functionDesc = new String[GetLoggingInfoTypes.values().length - 1]; for (int i = 1; i < GetLoggingInfoTypes.values().length; i++) { @@ -214,21 +214,22 @@ public void widgetSelected(SelectionEvent e) { /** Copy information from the meta-data input to the dialog fields. */ public void getData() { - wTransformname.setText(transformName); + wTransformName.setText(transformName); - for (int i = 0; i < input.getFieldName().length; i++) { + for (int i = 0; i < input.getFields().size(); i++) { TableItem item = wFields.table.getItem(i); - item.setText(1, Const.NVL(input.getFieldName()[i], "")); - item.setText(2, Const.NVL(input.getFieldType()[i].lookupDescription(), "")); - item.setText(3, Const.NVL(input.getFieldArgument()[i], "")); + item.setText(1, Const.NVL(input.getFields().get(i).getFieldName(), "")); + GetLoggingInfoTypes type = input.getFields().get(i).getFieldType(); + item.setText(2, Const.NVL(type.getDescription(), "")); + item.setText(3, Const.NVL(input.getFields().get(i).getFieldArgument(), "")); } wFields.setRowNums(); wFields.optWidth(true); - wTransformname.selectAll(); - wTransformname.setFocus(); + wTransformName.selectAll(); + wTransformName.setFocus(); } private void cancel() { @@ -238,7 +239,7 @@ private void cancel() { } private void ok() { - if (StringUtils.isEmpty(wTransformname.getText())) { + if (StringUtils.isEmpty(wTransformName.getText())) { return; } @@ -256,15 +257,19 @@ private void ok() { private void getInfo(GetLoggingInfoMeta in) throws HopException { - transformName = wTransformname.getText(); // return value + transformName = wTransformName.getText(); // return value int count = wFields.nrNonEmpty(); - in.allocate(count); + + in.getFields().clear(); for (int i = 0; i < count; i++) { TableItem item = wFields.getNonEmpty(i); - in.getFieldName()[i] = item.getText(1); - in.getFieldType()[i] = GetLoggingInfoTypes.getTypeFromString(item.getText(2)); - in.getFieldArgument()[i] = item.getText(3); + GetLoggingInfoField field = new GetLoggingInfoField(); + field.setFieldName(item.getText(1)); + GetLoggingInfoTypes type = GetLoggingInfoTypes.getTypeFromString(item.getText(2)); + field.setFieldType(type); + field.setFieldArgument(item.getText(3)); + in.getFields().add(field); } } @@ -276,7 +281,7 @@ private void preview() { PipelineMeta previewMeta = PipelinePreviewFactory.generatePreviewPipeline( - metadataProvider, oneMeta, wTransformname.getText()); + metadataProvider, oneMeta, wTransformName.getText()); EnterNumberDialog numberDialog = new EnterNumberDialog( @@ -292,7 +297,7 @@ private void preview() { shell, variables, previewMeta, - new String[] {wTransformname.getText()}, + new String[] {wTransformName.getText()}, new int[] {previewSize}); progressDialog.open(); @@ -317,9 +322,9 @@ private void preview() { shell, variables, SWT.NONE, - wTransformname.getText(), - progressDialog.getPreviewRowsMeta(wTransformname.getText()), - progressDialog.getPreviewRows(wTransformname.getText()), + wTransformName.getText(), + progressDialog.getPreviewRowsMeta(wTransformName.getText()), + progressDialog.getPreviewRows(wTransformName.getText()), loggingText); prd.open(); } diff --git a/plugins/tech/neo4j/src/main/java/org/apache/hop/neo4j/transforms/loginfo/GetLoggingInfoField.java b/plugins/tech/neo4j/src/main/java/org/apache/hop/neo4j/transforms/loginfo/GetLoggingInfoField.java new file mode 100644 index 0000000000..446f66b11b --- /dev/null +++ b/plugins/tech/neo4j/src/main/java/org/apache/hop/neo4j/transforms/loginfo/GetLoggingInfoField.java @@ -0,0 +1,61 @@ +package org.apache.hop.neo4j.transforms.loginfo; + +import java.util.Objects; +import lombok.Getter; +import lombok.Setter; +import org.apache.hop.metadata.api.HopMetadataProperty; + +@Getter +@Setter +public class GetLoggingInfoField { + + public GetLoggingInfoField() {} + + public GetLoggingInfoField( + String fieldName, GetLoggingInfoTypes fieldType, String fieldArgument) { + this.fieldName = fieldName; + this.fieldType = fieldType; + this.fieldArgument = fieldArgument; + } + + public GetLoggingInfoField(GetLoggingInfoField f) { + this.fieldName = f.getFieldName(); + this.fieldType = f.getFieldType(); + this.fieldArgument = f.getFieldArgument(); + } + + @HopMetadataProperty(key = "name", injectionKey = "FIELD_NAME") + private String fieldName; + + @HopMetadataProperty( + key = "type", + injectionKey = "FIELD_TYPE", + injectionConverter = GetLoggingInfoMetaInjectionTypeConverter.class) + private GetLoggingInfoTypes fieldType; + + @HopMetadataProperty(key = "argument", injectionKey = "FIELD_ARGUMENT") + private String fieldArgument; + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + GetLoggingInfoField that = (GetLoggingInfoField) obj; + return fieldType.equals(that.fieldType) + && fieldName.equals(that.fieldName) + && fieldArgument.equals(that.fieldArgument); + } + + @Override + public int hashCode() { + return Objects.hash(fieldName, fieldType, fieldArgument); + } + + public GetLoggingInfoTypes getFieldType() { + return fieldType; + } + + public void setFieldType(GetLoggingInfoTypes fieldType) { + this.fieldType = fieldType; + } +} diff --git a/plugins/tech/neo4j/src/main/java/org/apache/hop/neo4j/transforms/loginfo/GetLoggingInfoMeta.java b/plugins/tech/neo4j/src/main/java/org/apache/hop/neo4j/transforms/loginfo/GetLoggingInfoMeta.java index 364d83583c..3750dfe649 100644 --- a/plugins/tech/neo4j/src/main/java/org/apache/hop/neo4j/transforms/loginfo/GetLoggingInfoMeta.java +++ b/plugins/tech/neo4j/src/main/java/org/apache/hop/neo4j/transforms/loginfo/GetLoggingInfoMeta.java @@ -17,28 +17,26 @@ package org.apache.hop.neo4j.transforms.loginfo; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import lombok.Getter; +import lombok.Setter; import org.apache.hop.core.CheckResult; -import org.apache.hop.core.Const; import org.apache.hop.core.ICheckResult; import org.apache.hop.core.annotations.Transform; import org.apache.hop.core.exception.HopTransformException; -import org.apache.hop.core.exception.HopXmlException; -import org.apache.hop.core.injection.Injection; -import org.apache.hop.core.injection.InjectionSupported; import org.apache.hop.core.row.IRowMeta; import org.apache.hop.core.row.IValueMeta; import org.apache.hop.core.row.value.ValueMetaDate; import org.apache.hop.core.row.value.ValueMetaNone; import org.apache.hop.core.variables.IVariables; -import org.apache.hop.core.xml.XmlHandler; import org.apache.hop.i18n.BaseMessages; +import org.apache.hop.metadata.api.HopMetadataProperty; import org.apache.hop.metadata.api.IHopMetadataProvider; import org.apache.hop.pipeline.PipelineMeta; import org.apache.hop.pipeline.transform.BaseTransformMeta; import org.apache.hop.pipeline.transform.TransformMeta; -import org.w3c.dom.Node; @Transform( id = "GetLoggingInfo", @@ -48,125 +46,55 @@ image = "systeminfo.svg", keywords = "i18n::GetLoggingInfoMeta.keyword", documentationUrl = "/pipeline/transforms/neo4j-getloginfo.html") -@InjectionSupported(localizationPrefix = "GetLoggingInfoMeta.Injection.") +@Getter +@Setter public class GetLoggingInfoMeta extends BaseTransformMeta { private static final Class PKG = GetLoggingInfoMeta.class; // for i18n purposes, needed by Translator2!! public static final String CONST_SPACES = " "; - @Injection(name = "FIELD_NAME") - private String[] fieldName; - - @Injection(name = "FIELD_TYPE", converter = GetLoggingInfoMetaInjectionTypeConverter.class) - private GetLoggingInfoTypes[] fieldType; - - @Injection(name = "FIELD_ARGUMENT") - private String[] fieldArgument; + @HopMetadataProperty( + key = "field", + groupKey = "fields", + injectionKey = "FIELD", + injectionGroupKey = "FIELDS") + private List fields; public GetLoggingInfoMeta() { super(); // allocate BaseTransformMeta } - /** - * @return Returns the fieldName. - */ - public String[] getFieldName() { - return fieldName; - } - - /** - * @param fieldName The fieldName to set. - */ - public void setFieldName(String[] fieldName) { - this.fieldName = fieldName; - } - - /** - * @return Returns the fieldType. - */ - public GetLoggingInfoTypes[] getFieldType() { - return fieldType; - } - - /** - * @param fieldType The fieldType to set. - */ - public void setFieldType(GetLoggingInfoTypes[] fieldType) { - this.fieldType = fieldType; - } - - /** - * Gets fieldArgument - * - * @return value of fieldArgument - */ - public String[] getFieldArgument() { - return fieldArgument; - } - - /** - * @param fieldArgument The fieldArgument to set - */ - public void setFieldArgument(String[] fieldArgument) { - this.fieldArgument = fieldArgument; - } - - public void allocate(int count) { - fieldName = new String[count]; - fieldType = new GetLoggingInfoTypes[count]; - fieldArgument = new String[count]; - } - @Override public Object clone() { GetLoggingInfoMeta retval = (GetLoggingInfoMeta) super.clone(); - int count = fieldName.length; - - retval.allocate(count); - - System.arraycopy(fieldName, 0, retval.fieldName, 0, count); - System.arraycopy(fieldType, 0, retval.fieldType, 0, count); - System.arraycopy(fieldArgument, 0, retval.fieldArgument, 0, count); - return retval; } @Override - public void loadXml(Node transformNode, IHopMetadataProvider metadataProvider) - throws HopXmlException { - try { - Node fields = XmlHandler.getSubNode(transformNode, "fields"); - int count = XmlHandler.countNodes(fields, "field"); - String type; + public void setDefault() { - allocate(count); + fields = new ArrayList<>(); - for (int i = 0; i < count; i++) { - Node fnode = XmlHandler.getSubNodeByNr(fields, "field", i); + GetLoggingInfoField f1 = new GetLoggingInfoField(); + f1.setFieldName("startOfPipelineDelta"); + f1.setFieldType(GetLoggingInfoTypes.TYPE_SYSTEM_INFO_PIPELINE_DATE_FROM); + fields.add(f1); - fieldName[i] = XmlHandler.getTagValue(fnode, "name"); - type = XmlHandler.getTagValue(fnode, "type"); - fieldType[i] = GetLoggingInfoTypes.getTypeFromString(type); - fieldArgument[i] = XmlHandler.getTagValue(fnode, "argument"); - } - } catch (Exception e) { - throw new HopXmlException("Unable to read transform information from Xml", e); - } - } + GetLoggingInfoField f2 = new GetLoggingInfoField(); + f2.setFieldName(""); + f2.setFieldType(GetLoggingInfoTypes.TYPE_SYSTEM_INFO_PIPELINE_DATE_TO); + fields.add(f2); - @Override - public void setDefault() { - allocate(4); + GetLoggingInfoField f3 = new GetLoggingInfoField(); + f3.setFieldName("startOfWorkflowDelta"); + f3.setFieldType(GetLoggingInfoTypes.TYPE_SYSTEM_INFO_WORKFLOW_DATE_TO); + fields.add(f3); - fieldName[0] = "startOfPipelineDelta"; - fieldType[0] = GetLoggingInfoTypes.TYPE_SYSTEM_INFO_PIPELINE_DATE_FROM; - fieldName[1] = "endOfPipelineDelta"; - fieldType[1] = GetLoggingInfoTypes.TYPE_SYSTEM_INFO_PIPELINE_DATE_TO; - fieldName[2] = "startOfWorkflowDelta"; - fieldType[2] = GetLoggingInfoTypes.TYPE_SYSTEM_INFO_WORKFLOW_DATE_FROM; - fieldName[3] = "endOfWorkflowDelta"; - fieldType[3] = GetLoggingInfoTypes.TYPE_SYSTEM_INFO_WORKFLOW_DATE_TO; + GetLoggingInfoField f4 = new GetLoggingInfoField(); + f4.setFieldName("endOfWorkflowDelta"); + f4.setFieldType(GetLoggingInfoTypes.TYPE_SYSTEM_INFO_WORKFLOW_DATE_TO); + fields.add(f4); } @Override @@ -178,10 +106,10 @@ public void getFields( IVariables space, IHopMetadataProvider metadataProvider) throws HopTransformException { - for (int i = 0; i < fieldName.length; i++) { + for (int i = 0; i < fields.size(); i++) { IValueMeta v; - switch (fieldType[i]) { + switch (fields.get(i).getFieldType()) { case TYPE_SYSTEM_INFO_PIPELINE_DATE_FROM, TYPE_SYSTEM_INFO_PIPELINE_DATE_TO, TYPE_SYSTEM_INFO_WORKFLOW_DATE_FROM, @@ -190,10 +118,10 @@ public void getFields( TYPE_SYSTEM_INFO_PIPELINE_PREVIOUS_SUCCESS_DATE, TYPE_SYSTEM_INFO_WORKFLOW_PREVIOUS_EXECUTION_DATE, TYPE_SYSTEM_INFO_WORKFLOW_PREVIOUS_SUCCESS_DATE: - v = new ValueMetaDate(fieldName[i]); + v = new ValueMetaDate(fields.get(i).getFieldName()); break; default: - v = new ValueMetaNone(fieldName[i]); + v = new ValueMetaNone(fields.get(i).getFieldName()); break; } v.setOrigin(name); @@ -201,26 +129,6 @@ public void getFields( } } - @Override - public String getXml() { - StringBuilder retval = new StringBuilder(); - - retval.append(" " + Const.CR); - - for (int i = 0; i < fieldName.length; i++) { - retval.append(" " + Const.CR); - retval.append(CONST_SPACES + XmlHandler.addTagValue("name", fieldName[i])); - retval.append( - CONST_SPACES - + XmlHandler.addTagValue("type", fieldType[i] != null ? fieldType[i].getCode() : "")); - retval.append(CONST_SPACES + XmlHandler.addTagValue("argument", fieldArgument[i])); - retval.append(" " + Const.CR); - } - retval.append(" " + Const.CR); - - return retval.toString(); - } - @Override public void check( List remarks, @@ -234,13 +142,14 @@ public void check( IHopMetadataProvider metadataProvider) { // See if we have input streams leading to this transform! int nrRemarks = remarks.size(); - for (int i = 0; i < fieldName.length; i++) { - if (fieldType[i].ordinal() <= GetLoggingInfoTypes.TYPE_SYSTEM_INFO_NONE.ordinal()) { + for (int i = 0; i < fields.size(); i++) { + if (fields.get(i).getFieldType().ordinal() + <= GetLoggingInfoTypes.TYPE_SYSTEM_INFO_NONE.ordinal()) { CheckResult cr = new CheckResult( ICheckResult.TYPE_RESULT_ERROR, BaseMessages.getString( - PKG, "SystemDataMeta.CheckResult.FieldHasNoType", fieldName[i]), + PKG, "SystemDataMeta.CheckResult.FieldHasNoType", fields.get(i).getFieldName()), transformMeta); remarks.add(cr); } @@ -265,10 +174,7 @@ public boolean equals(Object o) { } GetLoggingInfoMeta that = (GetLoggingInfoMeta) o; - if (!Arrays.equals(fieldName, that.fieldName)) { - return false; - } - if (!Arrays.equals(fieldType, that.fieldType)) { + if (!fields.equals(that.fields)) { return false; } @@ -277,8 +183,8 @@ public boolean equals(Object o) { @Override public int hashCode() { - int result = Arrays.hashCode(fieldName); - result = 31 * result + Arrays.hashCode(fieldType); + int result = Arrays.asList(fields).hashCode(); + result = 31 * result + Arrays.asList().hashCode(); return result; } } diff --git a/plugins/tech/neo4j/src/main/java/org/apache/hop/neo4j/transforms/loginfo/GetLoggingInfoTypes.java b/plugins/tech/neo4j/src/main/java/org/apache/hop/neo4j/transforms/loginfo/GetLoggingInfoTypes.java index 65e265e493..2f5f0a6b78 100644 --- a/plugins/tech/neo4j/src/main/java/org/apache/hop/neo4j/transforms/loginfo/GetLoggingInfoTypes.java +++ b/plugins/tech/neo4j/src/main/java/org/apache/hop/neo4j/transforms/loginfo/GetLoggingInfoTypes.java @@ -18,8 +18,10 @@ package org.apache.hop.neo4j.transforms.loginfo; +import lombok.Getter; import org.apache.hop.i18n.BaseMessages; +@Getter public enum GetLoggingInfoTypes { TYPE_SYSTEM_INFO_NONE("", ""), @@ -42,16 +44,12 @@ public enum GetLoggingInfoTypes { "Specified workflow: Previous success date", "Types.Desc.WorkflowPreviousSuccessDate"), ; - private String code; - private String description; + private final String code; + private final String description; private static Class PKG = GetLoggingInfoMeta.class; // for i18n purposes, needed by Translator2!! - public String getCode() { - return code; - } - public String lookupDescription() { return description; } @@ -59,7 +57,7 @@ public String lookupDescription() { public static GetLoggingInfoTypes getTypeFromString(String typeStr) { for (GetLoggingInfoTypes type : GetLoggingInfoTypes.values()) { // attempting to purge this typo from KTRs - if ("previous result nr lines rejeted".equalsIgnoreCase(typeStr)) { + if ("previous result nr lines rejected".equalsIgnoreCase(typeStr)) { typeStr = "previous result nr lines rejected"; }