diff --git a/engine/src/main/java/org/pentaho/di/repository/kdr/KettleDatabaseRepository.java b/engine/src/main/java/org/pentaho/di/repository/kdr/KettleDatabaseRepository.java index d26e326819b7..e58a2bfca9c2 100644 --- a/engine/src/main/java/org/pentaho/di/repository/kdr/KettleDatabaseRepository.java +++ b/engine/src/main/java/org/pentaho/di/repository/kdr/KettleDatabaseRepository.java @@ -22,29 +22,17 @@ package org.pentaho.di.repository.kdr; -import java.io.BufferedOutputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.zip.GZIPOutputStream; - import org.apache.commons.codec.binary.Base64; import org.pentaho.di.cluster.ClusterSchema; import org.pentaho.di.cluster.SlaveServer; import org.pentaho.di.core.Condition; import org.pentaho.di.core.Const; -import org.pentaho.di.core.util.Utils; -import org.pentaho.di.i18n.BaseMessages; import org.pentaho.di.core.NotePadMeta; import org.pentaho.di.core.ProgressMonitorListener; import org.pentaho.di.core.RowMetaAndData; import org.pentaho.di.core.database.Database; import org.pentaho.di.core.database.DatabaseMeta; +import org.pentaho.di.core.exception.IdNotFoundException; import org.pentaho.di.core.exception.KettleDatabaseException; import org.pentaho.di.core.exception.KettleDependencyException; import org.pentaho.di.core.exception.KettleException; @@ -55,6 +43,8 @@ import org.pentaho.di.core.row.value.ValueMetaDate; import org.pentaho.di.core.row.value.ValueMetaInteger; import org.pentaho.di.core.row.value.ValueMetaString; +import org.pentaho.di.core.util.Utils; +import org.pentaho.di.i18n.BaseMessages; import org.pentaho.di.job.JobMeta; import org.pentaho.di.job.entry.JobEntryBase; import org.pentaho.di.partition.PartitionSchema; @@ -96,6 +86,17 @@ import org.pentaho.di.shared.SharedObjects; import org.pentaho.di.trans.TransMeta; +import java.io.BufferedOutputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.zip.GZIPOutputStream; + /** * * This class handles interactions with a Kettle repository. @@ -1826,6 +1827,9 @@ public ObjectId getDatabaseID( String name ) throws KettleException { } public ObjectId getJobId( String name, RepositoryDirectoryInterface repositoryDirectory ) throws KettleException { + if ( repositoryDirectory == null ) { + throw new IdNotFoundException( name, null, RepositoryObjectType.JOB ); + } return jobDelegate.getJobID( name, repositoryDirectory.getObjectId() ); } @@ -1838,6 +1842,9 @@ public ObjectId getSlaveID( String name ) throws KettleException { } public ObjectId getTransformationID( String name, RepositoryDirectoryInterface repositoryDirectory ) throws KettleException { + if ( repositoryDirectory == null ) { + throw new IdNotFoundException( name, null, RepositoryObjectType.TRANSFORMATION ); + } return transDelegate.getTransformationID( name, repositoryDirectory.getObjectId() ); } diff --git a/engine/src/test/java/org/pentaho/di/repository/kdr/KettleDatabaseRepositoryTest.java b/engine/src/test/java/org/pentaho/di/repository/kdr/KettleDatabaseRepositoryTest.java index 1bdc861514cf..83266c315818 100644 --- a/engine/src/test/java/org/pentaho/di/repository/kdr/KettleDatabaseRepositoryTest.java +++ b/engine/src/test/java/org/pentaho/di/repository/kdr/KettleDatabaseRepositoryTest.java @@ -22,18 +22,6 @@ package org.pentaho.di.repository.kdr; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.spy; - -import java.util.Arrays; -import java.util.Calendar; -import java.util.Date; - import org.junit.Before; import org.junit.BeforeClass; import org.junit.ClassRule; @@ -44,6 +32,7 @@ import org.pentaho.di.core.KettleEnvironment; import org.pentaho.di.core.RowMetaAndData; import org.pentaho.di.core.database.DatabaseMeta; +import org.pentaho.di.core.exception.IdNotFoundException; import org.pentaho.di.core.exception.KettleException; import org.pentaho.di.core.row.RowMeta; import org.pentaho.di.core.row.ValueMetaInterface; @@ -54,6 +43,18 @@ import org.pentaho.di.repository.UserInfo; import org.pentaho.di.repository.kdr.delegates.KettleDatabaseRepositoryConnectionDelegate; +import java.util.Arrays; +import java.util.Calendar; +import java.util.Date; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.spy; + public class KettleDatabaseRepositoryTest { @ClassRule public static RestorePDIEngineEnvironment env = new RestorePDIEngineEnvironment(); @@ -319,4 +320,20 @@ public void testInsertTransStepCondition() throws KettleException { assertEquals( KettleDatabaseRepository.FIELD_TRANS_STEP_CONDITION_ID_CONDITION, insertRecord.getValueMeta( 2 ).getName() ); assertEquals( Long.valueOf( 468 ), insertRecord.getInteger( 2 ) ); } + + /** + * Regression for PDI-19730. + */ + @Test(expected = IdNotFoundException.class ) + public void getJobId_nullDirectory() throws KettleException { + repo.getJobId( "job1", null ); + } + + /** + * Regression for PDI-19730. + */ + @Test(expected = IdNotFoundException.class) + public void getTransId_nullDirectory() throws KettleException { + repo.getTransformationID( "trans1", null ); + } }