Search in sources :

Example 1 with LookupReferencesException

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

the class JobMeta method lookupRepositoryReferences.

/**
 * Look up the references after import
 *
 * @param repository the repository to reference.
 */
public void lookupRepositoryReferences(Repository repository) throws KettleException {
    KettleException lastThrownException = null;
    Map<String, RepositoryObjectType> notFoundedReferences = new HashMap<>();
    for (JobEntryCopy copy : jobcopies) {
        if (copy.getEntry().hasRepositoryReferences()) {
            try {
                copy.getEntry().lookupRepositoryReferences(repository);
            } catch (IdNotFoundException e) {
                lastThrownException = e;
                String path = e.getPathToObject();
                String name = e.getObjectName();
                String key = StringUtils.isEmpty(path) || path.equals("null") ? name : path + "/" + name;
                notFoundedReferences.put(key, e.getObjectType());
            }
        }
    }
    if (lastThrownException != null && !notFoundedReferences.isEmpty()) {
        throw new LookupReferencesException(lastThrownException, notFoundedReferences);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) LookupReferencesException(org.pentaho.di.core.exception.LookupReferencesException) JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) HashMap(java.util.HashMap) RepositoryObjectType(org.pentaho.di.repository.RepositoryObjectType) IdNotFoundException(org.pentaho.di.core.exception.IdNotFoundException)

Example 2 with LookupReferencesException

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

the class JobMetaTest method testLookupRepositoryReferences.

@Test
public void testLookupRepositoryReferences() throws Exception {
    jobMeta.clear();
    JobEntryTrans jobEntryMock = mock(JobEntryTrans.class);
    when(jobEntryMock.hasRepositoryReferences()).thenReturn(true);
    JobEntryTrans brokenJobEntryMock = mock(JobEntryTrans.class);
    when(brokenJobEntryMock.hasRepositoryReferences()).thenReturn(true);
    doThrow(mock(IdNotFoundException.class)).when(brokenJobEntryMock).lookupRepositoryReferences(any(Repository.class));
    JobEntryCopy jobEntryCopy1 = mock(JobEntryCopy.class);
    when(jobEntryCopy1.getEntry()).thenReturn(jobEntryMock);
    jobMeta.addJobEntry(0, jobEntryCopy1);
    JobEntryCopy jobEntryCopy2 = mock(JobEntryCopy.class);
    when(jobEntryCopy2.getEntry()).thenReturn(brokenJobEntryMock);
    jobMeta.addJobEntry(1, jobEntryCopy2);
    JobEntryCopy jobEntryCopy3 = mock(JobEntryCopy.class);
    when(jobEntryCopy3.getEntry()).thenReturn(jobEntryMock);
    jobMeta.addJobEntry(2, jobEntryCopy3);
    try {
        jobMeta.lookupRepositoryReferences(mock(Repository.class));
        fail("no exception for broken entry");
    } catch (LookupReferencesException e) {
    // ok
    }
    verify(jobEntryMock, times(2)).lookupRepositoryReferences(any(Repository.class));
}
Also used : LookupReferencesException(org.pentaho.di.core.exception.LookupReferencesException) Repository(org.pentaho.di.repository.Repository) JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) JobEntryTrans(org.pentaho.di.job.entries.trans.JobEntryTrans) IdNotFoundException(org.pentaho.di.core.exception.IdNotFoundException) Test(org.junit.Test)

Aggregations

IdNotFoundException (org.pentaho.di.core.exception.IdNotFoundException)2 LookupReferencesException (org.pentaho.di.core.exception.LookupReferencesException)2 JobEntryCopy (org.pentaho.di.job.entry.JobEntryCopy)2 HashMap (java.util.HashMap)1 Test (org.junit.Test)1 KettleException (org.pentaho.di.core.exception.KettleException)1 JobEntryTrans (org.pentaho.di.job.entries.trans.JobEntryTrans)1 Repository (org.pentaho.di.repository.Repository)1 RepositoryObjectType (org.pentaho.di.repository.RepositoryObjectType)1