Search in sources :

Example 51 with StepInjectionMetaEntry

use of org.pentaho.di.trans.step.StepInjectionMetaEntry in project pentaho-kettle by pentaho.

the class AccessInputMetaInjection method getStepInjectionMetadataEntries.

@Override
public List<StepInjectionMetaEntry> getStepInjectionMetadataEntries() throws KettleException {
    List<StepInjectionMetaEntry> all = new ArrayList<StepInjectionMetaEntry>();
    for (Entry entry : Entry.values()) {
        if (entry.getParent() == null && entry.getValueType() != ValueMetaInterface.TYPE_NONE) {
            all.add(new StepInjectionMetaEntry(entry.name(), entry.getValueType(), entry.getDescription()));
        }
    }
    // The file name lines
    // 
    StepInjectionMetaEntry filesEntry = new StepInjectionMetaEntry(Entry.FILENAME_LINES.name(), ValueMetaInterface.TYPE_NONE, Entry.FILENAME_LINES.description);
    all.add(filesEntry);
    StepInjectionMetaEntry fileEntry = new StepInjectionMetaEntry(Entry.FILENAME_LINE.name(), ValueMetaInterface.TYPE_NONE, Entry.FILENAME_LINE.description);
    filesEntry.getDetails().add(fileEntry);
    for (Entry entry : Entry.values()) {
        if (entry.getParent() == Entry.FILENAME_LINE) {
            StepInjectionMetaEntry metaEntry = new StepInjectionMetaEntry(entry.name(), entry.getValueType(), entry.getDescription());
            fileEntry.getDetails().add(metaEntry);
        }
    }
    // Add the fields...
    // 
    StepInjectionMetaEntry fieldsEntry = new StepInjectionMetaEntry(Entry.FIELDS.name(), Entry.FIELDS.getValueType(), Entry.FIELDS.getDescription());
    all.add(fieldsEntry);
    StepInjectionMetaEntry fieldEntry = new StepInjectionMetaEntry(Entry.FIELD.name(), Entry.FIELD.getValueType(), Entry.FIELD.getDescription());
    fieldsEntry.getDetails().add(fieldEntry);
    for (Entry entry : Entry.values()) {
        if (entry.getParent() == Entry.FIELD) {
            StepInjectionMetaEntry metaEntry = new StepInjectionMetaEntry(entry.name(), entry.getValueType(), entry.getDescription());
            fieldEntry.getDetails().add(metaEntry);
        }
    }
    return all;
}
Also used : StepInjectionMetaEntry(org.pentaho.di.trans.step.StepInjectionMetaEntry) StepInjectionMetaEntry(org.pentaho.di.trans.step.StepInjectionMetaEntry) ArrayList(java.util.ArrayList)

Example 52 with StepInjectionMetaEntry

use of org.pentaho.di.trans.step.StepInjectionMetaEntry in project pentaho-kettle by pentaho.

the class JsonOutputMetaInjection method injectStepMetadataEntries.

@Override
public void injectStepMetadataEntries(List<StepInjectionMetaEntry> all) throws KettleException {
    List<String> jsonFields = new ArrayList<String>();
    List<String> jsonElements = new ArrayList<String>();
    // 
    for (StepInjectionMetaEntry lookFields : all) {
        Entry fieldsEntry = Entry.findEntry(lookFields.getKey());
        if (fieldsEntry == null) {
            continue;
        }
        String lookValue = (String) lookFields.getValue();
        switch(fieldsEntry) {
            case JSON_FIELDS:
                for (StepInjectionMetaEntry lookField : lookFields.getDetails()) {
                    Entry fieldEntry = Entry.findEntry(lookField.getKey());
                    if (fieldEntry == Entry.JSON_FIELD) {
                        String jsonFieldname = null;
                        String jsonElement = null;
                        List<StepInjectionMetaEntry> entries = lookField.getDetails();
                        for (StepInjectionMetaEntry entry : entries) {
                            Entry metaEntry = Entry.findEntry(entry.getKey());
                            if (metaEntry != null) {
                                String value = (String) entry.getValue();
                                switch(metaEntry) {
                                    case JSON_FIELDNAME:
                                        jsonFieldname = value;
                                        break;
                                    case JSON_ELEMENTNAME:
                                        jsonElement = value;
                                        break;
                                    default:
                                        break;
                                }
                            }
                        }
                        jsonFields.add(jsonFieldname);
                        jsonElements.add(jsonElement);
                    }
                }
                break;
            case OPERATION:
                meta.setOperationType(JsonOutputMeta.getOperationTypeByDesc(lookValue));
                break;
            case JSON_BLOC_NAME:
                meta.setJsonBloc(lookValue);
                break;
            case NR_ROWS_IN_BLOC:
                meta.setNrRowsInBloc(lookValue);
                break;
            case OUTPUT_VALUE:
                meta.setOutputValue(lookValue);
                break;
            case COMPATIBILITY_MODE:
                meta.setCompatibilityMode("Y".equalsIgnoreCase(lookValue));
                break;
            case FILE_NAME:
                meta.setFileName(lookValue);
                break;
            case APPEND:
                meta.setFileAppended("Y".equalsIgnoreCase(lookValue));
                break;
            case CREATE_PARENT_FOLDER:
                meta.setCreateParentFolder("Y".equalsIgnoreCase(lookValue));
                break;
            case DONT_CREATE_AT_START:
                meta.setDoNotOpenNewFileInit("Y".equalsIgnoreCase(lookValue));
                break;
            case EXTENSION:
                meta.setExtension(lookValue);
                break;
            case ENCODING:
                meta.setEncoding(lookValue);
                break;
            case PASS_TO_SERVLET:
                meta.setServletOutput("Y".equalsIgnoreCase(lookValue));
                break;
            case INC_DATE_IN_FILENAME:
                meta.setDateInFilename("Y".equalsIgnoreCase(lookValue));
                break;
            case INC_TIME_IN_FILENAME:
                meta.setTimeInFilename("Y".equalsIgnoreCase(lookValue));
                break;
            case ADD_TO_RESULT:
                meta.setAddToResult("Y".equalsIgnoreCase(lookValue));
                break;
            default:
                break;
        }
    }
    // 
    if (jsonFields.size() > 0) {
        JsonOutputField[] jof = new JsonOutputField[jsonFields.size()];
        Iterator<String> iJsonFields = jsonFields.iterator();
        Iterator<String> iJsonElements = jsonElements.iterator();
        int i = 0;
        while (iJsonFields.hasNext()) {
            JsonOutputField field = new JsonOutputField();
            field.setFieldName(iJsonFields.next());
            field.setElementName(iJsonElements.next());
            jof[i] = field;
            i++;
        }
        meta.setOutputFields(jof);
    }
}
Also used : StepInjectionMetaEntry(org.pentaho.di.trans.step.StepInjectionMetaEntry) ArrayList(java.util.ArrayList) StepInjectionMetaEntry(org.pentaho.di.trans.step.StepInjectionMetaEntry)

Example 53 with StepInjectionMetaEntry

use of org.pentaho.di.trans.step.StepInjectionMetaEntry in project pentaho-kettle by pentaho.

the class TextFileInputMetaInjectionTest method extractingAll.

@Test
public void extractingAll() throws Exception {
    TextFileInputMetaInjection injection = new TextFileInputMetaInjection(new TextFileInputMeta());
    List<StepInjectionMetaEntry> metadata = injection.getStepInjectionMetadataEntries();
    List<StepInjectionMetaEntry> extracted = injection.extractStepMetadataEntries();
    assertEquals(metadata.size(), extracted.size());
    for (StepInjectionMetaEntry metaEntry : metadata) {
        assertNotNull(metaEntry.getKey(), StepInjectionUtil.findEntry(extracted, metaEntry.getKey()));
    }
}
Also used : StepInjectionMetaEntry(org.pentaho.di.trans.step.StepInjectionMetaEntry) Test(org.junit.Test)

Example 54 with StepInjectionMetaEntry

use of org.pentaho.di.trans.step.StepInjectionMetaEntry in project pentaho-kettle by pentaho.

the class TextFileInputMetaInjectionTest method assertInjected.

private static void assertInjected(List<StepInjectionMetaEntry> fields, List<StepInjectionMetaEntry> toBeInjected) {
    Map<String, StepInjectionMetaEntry> map = new HashMap<String, StepInjectionMetaEntry>(fields.size());
    for (StepInjectionMetaEntry field : fields) {
        map.put(field.getKey(), field);
    }
    for (StepInjectionMetaEntry entry : toBeInjected) {
        StepInjectionMetaEntry field = map.get(entry.getKey());
        assertNotNull(entry.getKey(), field);
        Object value = field.getValue();
        if (value == null) {
            assertNull(entry.getKey(), entry.getValue());
        } else {
            assertEquals(entry.getKey(), entry.getValue(), value);
        }
    }
}
Also used : HashMap(java.util.HashMap) StepInjectionMetaEntry(org.pentaho.di.trans.step.StepInjectionMetaEntry)

Aggregations

StepInjectionMetaEntry (org.pentaho.di.trans.step.StepInjectionMetaEntry)54 ArrayList (java.util.ArrayList)31 Test (org.junit.Test)17 KettleException (org.pentaho.di.core.exception.KettleException)10 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)6 KettleAttributeInterface (org.pentaho.di.core.KettleAttributeInterface)3 TextFileInputField (org.pentaho.di.trans.steps.textfileinput.TextFileInputField)2 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Locale (java.util.Locale)1 FocusEvent (org.eclipse.swt.events.FocusEvent)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 ShellEvent (org.eclipse.swt.events.ShellEvent)1