Search in sources :

Example 46 with RepositoryDirectory

use of org.pentaho.di.repository.RepositoryDirectory in project pentaho-kettle by pentaho.

the class UIEEJobTest method testRename.

@Test
public void testRename() throws Exception {
    final String newName = "newName";
    RepositoryDirectory repDir = mock(RepositoryDirectory.class);
    uiJob.renameJob(mockObjectId, repDir, newName);
    verify(mockRevisionService, times(1)).getRevisions(mockObjectId);
}
Also used : RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) UIRepositoryDirectory(org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryDirectory) Test(org.junit.Test)

Example 47 with RepositoryDirectory

use of org.pentaho.di.repository.RepositoryDirectory in project pentaho-kettle by pentaho.

the class Spoon method getDefaultSaveLocation.

public RepositoryDirectoryInterface getDefaultSaveLocation(RepositoryElementInterface repositoryElement) {
    try {
        if (getRepository() != defaultSaveLocationRepository) {
            // The repository has changed, reset the defaultSaveLocation
            defaultSaveLocation = null;
            defaultSaveLocationRepository = null;
        }
        if (defaultSaveLocation == null) {
            if (getRepository() != null) {
                defaultSaveLocation = getRepository().getDefaultSaveDirectory(repositoryElement);
                defaultSaveLocationRepository = getRepository();
            } else {
                defaultSaveLocation = new RepositoryDirectory();
            }
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return defaultSaveLocation;
}
Also used : RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) SWTException(org.eclipse.swt.SWTException) KettleRowException(org.pentaho.di.core.exception.KettleRowException) FileSystemException(org.apache.commons.vfs2.FileSystemException) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleAuthException(org.pentaho.di.core.exception.KettleAuthException) KettleRepositoryLostException(org.pentaho.di.repository.KettleRepositoryLostException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) LifecycleException(org.pentaho.di.core.lifecycle.LifecycleException) KettleMissingPluginsException(org.pentaho.di.core.exception.KettleMissingPluginsException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) KettleException(org.pentaho.di.core.exception.KettleException) MalformedURLException(java.net.MalformedURLException)

Example 48 with RepositoryDirectory

use of org.pentaho.di.repository.RepositoryDirectory in project pentaho-kettle by pentaho.

the class MetaInject method writeInjectedKtrToRepo.

/**
 * Writes the generated meta injection transformation to the repository. It is assumed that the repository
 * exists (user is connected).
 * @param targetFilePath the repo path to which to save the generated injection ktr
 * @throws KettleException
 */
private void writeInjectedKtrToRepo(final String targetFilePath) throws KettleException {
    // clone the transMeta associated with the data, this is the generated meta injection transformation
    final TransMeta generatedTrans = (TransMeta) data.transMeta.clone();
    // the targetFilePath holds the absolute repo path that is the requested destination of this generated
    // transformation, extract the file name (no extension) and the containing directory and adjust the generated
    // transformation properties accordingly
    List<String> targetPath = new ArrayList(Arrays.asList(Const.splitPath(targetFilePath, RepositoryDirectory.DIRECTORY_SEPARATOR)));
    final String fileName = targetPath.get(targetPath.size() - 1).replace(".ktr", "");
    generatedTrans.setName(fileName);
    // remove the last targetPath element, so we're left with the target directory path
    targetPath.remove(targetPath.size() - 1);
    if (targetPath.size() > 0) {
        final String dirPath = String.join(RepositoryDirectory.DIRECTORY_SEPARATOR, targetPath);
        RepositoryDirectoryInterface directory = getRepository().findDirectory(dirPath);
        // if the directory does not exist, try to create it
        if (directory == null) {
            directory = getRepository().createRepositoryDirectory(new RepositoryDirectory(null, "/"), dirPath);
        }
        generatedTrans.setRepositoryDirectory(directory);
    } else {
        // if the directory is null, set it to the directory of the cloned template ktr
        if (log.isDebug()) {
            log.logDebug("The target injection ktr file path provided by the user is not a valid fully qualified " + "repository path - will store the generated ktr in the same directory as the template ktr: ", data.transMeta.getRepositoryDirectory());
        }
        generatedTrans.setRepositoryDirectory(data.transMeta.getRepositoryDirectory());
    }
    // set the objectId, in case the injected transformation already exists in the repo, so that is is updated in
    // the repository - the objectId will remain null, if the transformation is begin generated for the first time,
    // in which a new ktr will be created in the repo
    generatedTrans.setObjectId(getRepository().getTransformationID(fileName, generatedTrans.getRepositoryDirectory()));
    getRepository().save(generatedTrans, null, null, true);
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) TransMeta(org.pentaho.di.trans.TransMeta) ArrayList(java.util.ArrayList)

Example 49 with RepositoryDirectory

use of org.pentaho.di.repository.RepositoryDirectory in project pentaho-kettle by pentaho.

the class MetaInjectTest method testWriteInjectedKtrToRepoSameDir.

@Test
public void testWriteInjectedKtrToRepoSameDir() throws Exception {
    RepositoryDirectory rootDir = PowerMockito.spy(new RepositoryDirectory(null, "/"));
    RepositoryDirectory adminDir = PowerMockito.spy(new RepositoryDirectory(new RepositoryDirectory(new RepositoryDirectory(null, "/"), "home"), "admin"));
    TransMeta cloneMeta = PowerMockito.spy((TransMeta) data.transMeta.clone());
    PowerMockito.doReturn(cloneMeta).when(data.transMeta).clone();
    PowerMockito.doReturn(adminDir).when(repository).createRepositoryDirectory(rootDir, "home/admin");
    PowerMockito.doReturn(adminDir).when(data.transMeta).getRepositoryDirectory();
    PowerMockito.whenNew(RepositoryDirectory.class).withArguments(null, "/").thenReturn(rootDir);
    metaInject.setRepository(repository);
    Whitebox.<String>invokeMethod(metaInject, "writeInjectedKtrToRepo", "/home/admin/injected_trans.ktr");
    verify(repository, times(1)).findDirectory("home/admin");
    verify(repository, times(1)).createRepositoryDirectory(rootDir, "home/admin");
    verify(cloneMeta, times(1)).setRepositoryDirectory(adminDir);
    verify(cloneMeta, times(1)).setObjectId(any(ObjectId.class));
    verify(repository, times(1)).save(cloneMeta, null, null, true);
}
Also used : RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) ObjectId(org.pentaho.di.repository.ObjectId) TransMeta(org.pentaho.di.trans.TransMeta) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Mockito.anyString(org.mockito.Mockito.anyString) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 50 with RepositoryDirectory

use of org.pentaho.di.repository.RepositoryDirectory in project pentaho-kettle by pentaho.

the class PurRepository method getPdiObjects.

protected List<RepositoryElementMetaInterface> getPdiObjects(ObjectId dirId, List<RepositoryObjectType> objectTypes, boolean includeDeleted) throws KettleException {
    try {
        // RepositoryDirectoryInterface repDir = getRootDir().findDirectory( dirId );
        RepositoryFile dirFile = pur.getFileById(dirId.getId());
        RepositoryDirectory repDir = new RepositoryDirectory();
        repDir.setObjectId(dirId);
        repDir.setName(dirFile.getName());
        List<RepositoryElementMetaInterface> list = new ArrayList<RepositoryElementMetaInterface>();
        List<RepositoryFile> nonDeletedChildren = getAllFilesOfType(dirId, objectTypes);
        for (RepositoryFile file : nonDeletedChildren) {
            RepositoryLock lock = unifiedRepositoryLockService.getLock(file);
            RepositoryObjectType objectType = getObjectType(file.getName());
            list.add(new EERepositoryObject(file, repDir, null, objectType, null, lock, false));
        }
        if (includeDeleted) {
            String dirPath = null;
            if (dirId != null) {
                // derive path using id
                dirPath = pur.getFileById(dirId.getId()).getPath();
            }
            List<RepositoryFile> deletedChildren = getAllDeletedFilesOfType(dirPath, objectTypes);
            for (RepositoryFile file : deletedChildren) {
                RepositoryLock lock = unifiedRepositoryLockService.getLock(file);
                RepositoryObjectType objectType = getObjectType(file.getName());
                list.add(new EERepositoryObject(file, repDir, null, objectType, null, lock, true));
            }
        }
        return list;
    } catch (Exception e) {
        throw new KettleException("Unable to get list of objects from directory [" + dirId + "]", e);
    }
}
Also used : EERepositoryObject(org.pentaho.di.repository.pur.model.EERepositoryObject) KettleException(org.pentaho.di.core.exception.KettleException) RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) ArrayList(java.util.ArrayList) RepositoryObjectType(org.pentaho.di.repository.RepositoryObjectType) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryLock(org.pentaho.di.repository.pur.model.RepositoryLock) MetaStoreNamespaceExistsException(org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) UnifiedRepositoryCreateFileException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryCreateFileException) UnifiedRepositoryUpdateFileException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryUpdateFileException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) KettleException(org.pentaho.di.core.exception.KettleException) IdNotFoundException(org.pentaho.di.core.exception.IdNotFoundException) KettleSecurityException(org.pentaho.di.core.exception.KettleSecurityException) RepositoryElementMetaInterface(org.pentaho.di.repository.RepositoryElementMetaInterface)

Aggregations

RepositoryDirectory (org.pentaho.di.repository.RepositoryDirectory)57 KettleException (org.pentaho.di.core.exception.KettleException)23 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)15 Test (org.junit.Test)14 TransMeta (org.pentaho.di.trans.TransMeta)11 LongObjectId (org.pentaho.di.repository.LongObjectId)10 ObjectId (org.pentaho.di.repository.ObjectId)9 KettleFileException (org.pentaho.di.core.exception.KettleFileException)8 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)8 Repository (org.pentaho.di.repository.Repository)8 RepositoryElementMetaInterface (org.pentaho.di.repository.RepositoryElementMetaInterface)8 ArrayList (java.util.ArrayList)7 StringObjectId (org.pentaho.di.repository.StringObjectId)7 FileSystemException (org.apache.commons.vfs2.FileSystemException)6 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)6 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)6 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)6 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)5 JobMeta (org.pentaho.di.job.JobMeta)5 TreeItem (org.eclipse.swt.widgets.TreeItem)4