Search in sources :

Example 41 with Result

use of org.pentaho.di.core.Result in project pentaho-kettle by pentaho.

the class HL7MLLPInput method execute.

public Result execute(Result previousResult, int nr) {
    Result result = previousResult;
    try {
        String serverName = environmentSubstitute(server);
        int portNumber = Integer.parseInt(environmentSubstitute(port));
        String messageVariable = environmentSubstitute(messageVariableName);
        String messageTypeVariable = environmentSubstitute(messageTypeVariableName);
        String versionVariable = environmentSubstitute(versionVariableName);
        MLLPSocketCacheEntry entry = MLLPSocketCache.getInstance().getServerSocketStreamSource(serverName, portNumber);
        if (entry.getJobListener() != null) {
            parentJob.addJobListener(entry.getJobListener());
        }
        MLLPTransport transport = entry.getTransport();
        // 
        synchronized (transport) {
            Transportable transportable = transport.doReceive();
            String message = transportable.getMessage();
            logDetailed("Received message: " + message);
            parentJob.setVariable(messageVariable, message);
            // Parse the message and extract the control ID.
            // 
            Parser parser = new GenericParser();
            ValidationContext validationContext = new NoValidation();
            parser.setValidationContext(validationContext);
            Message msg = parser.parse(message);
            Structure structure = msg.get("MSH");
            String messageType = null;
            String version = msg.getVersion();
            if (structure instanceof ca.uhn.hl7v2.model.v21.segment.MSH) {
                messageType = ((ca.uhn.hl7v2.model.v21.segment.MSH) structure).getMESSAGETYPE().encode();
            } else if (structure instanceof ca.uhn.hl7v2.model.v22.segment.MSH) {
                messageType = ((ca.uhn.hl7v2.model.v22.segment.MSH) structure).getMessageType().encode();
            } else if (structure instanceof ca.uhn.hl7v2.model.v23.segment.MSH) {
                messageType = ((ca.uhn.hl7v2.model.v23.segment.MSH) structure).getMessageType().encode();
            } else if (structure instanceof ca.uhn.hl7v2.model.v231.segment.MSH) {
                messageType = ((ca.uhn.hl7v2.model.v231.segment.MSH) structure).getMessageType().getMessageStructure().getValue();
            } else if (structure instanceof ca.uhn.hl7v2.model.v24.segment.MSH) {
                messageType = ((ca.uhn.hl7v2.model.v24.segment.MSH) structure).getMessageType().getMessageStructure().getValue();
            } else if (structure instanceof ca.uhn.hl7v2.model.v25.segment.MSH) {
                messageType = ((ca.uhn.hl7v2.model.v25.segment.MSH) structure).getMessageType().getMessageStructure().getValue();
            } else if (structure instanceof ca.uhn.hl7v2.model.v251.segment.MSH) {
                messageType = ((ca.uhn.hl7v2.model.v251.segment.MSH) structure).getMessageType().getMessageStructure().getValue();
            } else if (structure instanceof ca.uhn.hl7v2.model.v26.segment.MSH) {
                messageType = ((ca.uhn.hl7v2.model.v26.segment.MSH) structure).getMessageType().getMessageStructure().getValue();
            } else {
                logError("This job entry does not support the HL7 dialect used. Found MSH class: " + structure.getClass().getName());
            }
            if (!Utils.isEmpty(messageTypeVariable)) {
                parentJob.setVariable(messageTypeVariable, messageType);
            }
            if (!Utils.isEmpty(versionVariable)) {
                parentJob.setVariable(versionVariable, version);
            }
        }
        // All went well..
        // 
        result.setNrErrors(0);
        result.setResult(true);
    } catch (Exception e) {
        log.logError(BaseMessages.getString(PKG, "HL7MLLPInput.Exception.UnexpectedError"), e);
        result.setNrErrors(1);
        result.setResult(false);
    }
    return result;
}
Also used : Message(ca.uhn.hl7v2.model.Message) Result(org.pentaho.di.core.Result) MLLPSocketCacheEntry(org.pentaho.di.trans.steps.hl7input.common.MLLPSocketCacheEntry) Structure(ca.uhn.hl7v2.model.Structure) Transportable(ca.uhn.hl7v2.protocol.Transportable) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) Parser(ca.uhn.hl7v2.parser.Parser) GenericParser(ca.uhn.hl7v2.parser.GenericParser) GenericParser(ca.uhn.hl7v2.parser.GenericParser) ValidationContext(ca.uhn.hl7v2.validation.ValidationContext) MLLPTransport(ca.uhn.hl7v2.protocol.impl.MLLPTransport) NoValidation(ca.uhn.hl7v2.validation.impl.NoValidation)

Example 42 with Result

use of org.pentaho.di.core.Result in project pentaho-kettle by pentaho.

the class PaloCubeCreate method execute.

@Override
public Result execute(Result prevResult, int nr) throws KettleException {
    Result result = new Result(nr);
    result.setResult(false);
    logDetailed(toString(), "Start of processing");
    // String substitution..
    String realCubeName = environmentSubstitute(getCubeName());
    PaloHelper database = new PaloHelper(this.getDatabaseMeta(), getLogLevel());
    try {
        database.connect();
        database.createCube(realCubeName, dimensionNames.toArray(new String[dimensionNames.size()]));
        result.setResult(true);
        result.setNrLinesOutput(1);
    } catch (Exception e) {
        result.setNrErrors(1);
        e.printStackTrace();
        logError(toString(), "Error processing Palo Cube Create : " + e.getMessage());
    } finally {
        database.disconnect();
    }
    return result;
}
Also used : PaloHelper(org.pentaho.di.palo.core.PaloHelper) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) Result(org.pentaho.di.core.Result)

Example 43 with Result

use of org.pentaho.di.core.Result in project pentaho-kettle by pentaho.

the class MetaInjectTest method testTransWaitsForListenersToFinish.

@Test
public void testTransWaitsForListenersToFinish() throws Exception {
    doReturn(new String[] {}).when(transMeta).getPrevStepNames(any(StepMeta.class));
    data.stepInjectionMetasMap = new HashMap<>();
    data.stepInjectionMap = new HashMap<>();
    data.transMeta = new TransMeta();
    meta.setNoExecution(false);
    Trans injectTrans = mock(Trans.class);
    doReturn(injectTrans).when(metaInject).createInjectTrans();
    when(injectTrans.isFinished()).thenReturn(true);
    Result result = mock(Result.class);
    when(injectTrans.getResult()).thenReturn(result);
    metaInject.processRow(meta, data);
    verify(injectTrans).waitUntilFinished();
}
Also used : TransMeta(org.pentaho.di.trans.TransMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) Trans(org.pentaho.di.trans.Trans) Result(org.pentaho.di.core.Result) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 44 with Result

use of org.pentaho.di.core.Result in project pentaho-kettle by pentaho.

the class TransExecutorUnitTest method setUp.

@Before
public void setUp() throws Exception {
    executor = StepMockUtil.getStep(TransExecutor.class, TransExecutorMeta.class, "TransExecutorUnitTest");
    executor = spy(executor);
    TransMeta internalTransMeta = mock(TransMeta.class);
    doReturn(internalTransMeta).when(executor).loadExecutorTransMeta();
    internalTrans = spy(new Trans());
    internalTrans.setLog(mock(LogChannelInterface.class));
    doNothing().when(internalTrans).prepareExecution(any(String[].class));
    doNothing().when(internalTrans).startThreads();
    doNothing().when(internalTrans).waitUntilFinished();
    doNothing().when(executor).discardLogLines(any(TransExecutorData.class));
    doReturn(internalTrans).when(executor).createInternalTrans();
    internalResult = new Result();
    doReturn(internalResult).when(internalTrans).getResult();
    meta = new TransExecutorMeta();
    data = new TransExecutorData();
}
Also used : TransMeta(org.pentaho.di.trans.TransMeta) Trans(org.pentaho.di.trans.Trans) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) Result(org.pentaho.di.core.Result) Before(org.junit.Before)

Example 45 with Result

use of org.pentaho.di.core.Result in project pentaho-kettle by pentaho.

the class TransExecutorUnitTest method testCollectTransResultsDisabledHop.

@Test
public void testCollectTransResultsDisabledHop() throws KettleException {
    StepMeta outputRowsSourceStepMeta = mock(StepMeta.class);
    meta.setOutputRowsSourceStepMeta(outputRowsSourceStepMeta);
    Result result = mock(Result.class);
    RowMetaAndData rowMetaAndData = mock(RowMetaAndData.class);
    when(result.getRows()).thenReturn(Arrays.asList(rowMetaAndData));
    doNothing().when(executor).putRowTo(any(), any(), any());
    executor.init(meta, data);
    executor.collectTransResults(result);
    verify(executor, never()).putRowTo(any(), any(), any());
}
Also used : RowMetaAndData(org.pentaho.di.core.RowMetaAndData) StepMeta(org.pentaho.di.trans.step.StepMeta) Result(org.pentaho.di.core.Result) Test(org.junit.Test)

Aggregations

Result (org.pentaho.di.core.Result)192 Test (org.junit.Test)75 KettleException (org.pentaho.di.core.exception.KettleException)75 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)64 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)57 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)40 FileObject (org.apache.commons.vfs2.FileObject)34 Job (org.pentaho.di.job.Job)32 IOException (java.io.IOException)24 ResultFile (org.pentaho.di.core.ResultFile)20 File (java.io.File)17 ArrayList (java.util.ArrayList)16 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)15 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)12 Pattern (java.util.regex.Pattern)10 KettleFileException (org.pentaho.di.core.exception.KettleFileException)10 Database (org.pentaho.di.core.database.Database)9 Date (java.util.Date)8 Trans (org.pentaho.di.trans.Trans)8 Matcher (java.util.regex.Matcher)7