Search in sources :

Example 61 with RepositoryDirectoryInterface

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

the class RepositoryBrowserController method loadFolders.

public RepositoryDirectory loadFolders(String path) {
    RepositoryDirectoryInterface repositoryDirectoryInterface = findDirectory(path);
    RepositoryDirectory repositoryDirectory = RepositoryDirectory.build(null, repositoryDirectoryInterface);
    populateFolders(repositoryDirectory, repositoryDirectoryInterface);
    return repositoryDirectory;
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) RepositoryDirectory(org.pentaho.repo.model.RepositoryDirectory)

Example 62 with RepositoryDirectoryInterface

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

the class RepositoryBrowserController method create.

public RepositoryDirectory create(String parent, String name) {
    if (hasDupeFolder(parent, name)) {
        return null;
    }
    try {
        RepositoryDirectoryInterface repositoryDirectoryInterface = getRepository().createRepositoryDirectory(findDirectory(parent), name);
        RepositoryDirectory repositoryDirectory = new RepositoryDirectory();
        repositoryDirectory.setName(repositoryDirectoryInterface.getName());
        repositoryDirectory.setPath(repositoryDirectoryInterface.getPath());
        repositoryDirectory.setObjectId(repositoryDirectoryInterface.getObjectId());
        repositoryDirectory.setParent(parent);
        return repositoryDirectory;
    } catch (Exception e) {
        return null;
    }
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) RepositoryDirectory(org.pentaho.repo.model.RepositoryDirectory) KettleException(org.pentaho.di.core.exception.KettleException) KettleObjectExistsException(org.pentaho.di.core.exception.KettleObjectExistsException) KettleTransException(org.pentaho.di.core.exception.KettleTransException) KettleJobException(org.pentaho.di.core.exception.KettleJobException)

Example 63 with RepositoryDirectoryInterface

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

the class RepositoryBrowserController method remove.

public boolean remove(String id, String name, String path, String type) throws KettleException {
    try {
        switch(type) {
            case JOB:
                if (isJobOpened(id, path, name)) {
                    throw new KettleJobException();
                }
                getRepository().deleteJob(() -> id);
                break;
            case TRANSFORMATION:
                if (isTransOpened(id, path, name)) {
                    throw new KettleTransException();
                }
                getRepository().deleteTransformation(() -> id);
                break;
            case FOLDER:
                isFileOpenedInFolder(path);
                removeRecentsUsingPath(path);
                RepositoryDirectoryInterface repositoryDirectoryInterface = findDirectory(path);
                if (getRepository() instanceof RepositoryExtended) {
                    ((RepositoryExtended) getRepository()).deleteRepositoryDirectory(repositoryDirectoryInterface, true);
                } else {
                    getRepository().deleteRepositoryDirectory(repositoryDirectoryInterface);
                }
                break;
        }
        return true;
    } catch (KettleTransException | KettleJobException ke) {
        throw ke;
    } catch (Exception e) {
        return false;
    }
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) KettleTransException(org.pentaho.di.core.exception.KettleTransException) RepositoryExtended(org.pentaho.di.repository.RepositoryExtended) KettleJobException(org.pentaho.di.core.exception.KettleJobException) KettleException(org.pentaho.di.core.exception.KettleException) KettleObjectExistsException(org.pentaho.di.core.exception.KettleObjectExistsException) KettleTransException(org.pentaho.di.core.exception.KettleTransException) KettleJobException(org.pentaho.di.core.exception.KettleJobException)

Example 64 with RepositoryDirectoryInterface

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

the class RepositoryBrowserController method search.

public List<org.pentaho.repo.model.RepositoryObject> search(String path, String filter) {
    RepositoryDirectoryInterface repositoryDirectoryInterface = findDirectory(path);
    List<org.pentaho.repo.model.RepositoryObject> repositoryObjects = new ArrayList<>();
    List<RepositoryObjectInterface> repositoryObjects1 = ((RepositoryExtended) getRepository()).getChildren(repositoryDirectoryInterface.getObjectId().getId(), filter);
    for (RepositoryObjectInterface repositoryObject : repositoryObjects1) {
        if (repositoryObject instanceof RepositoryDirectoryInterface) {
            RepositoryDirectory repositoryDirectory = new RepositoryDirectory();
            repositoryDirectory.setPath(path + "/" + repositoryObject.getName());
            repositoryDirectory.setName(repositoryObject.getName());
            repositoryDirectory.setObjectId(repositoryObject.getObjectId());
            repositoryObjects.add(repositoryDirectory);
        } else {
            RepositoryFile repositoryFile = new RepositoryFile();
            repositoryFile.setPath(path + "/" + repositoryObject.getName());
            repositoryFile.setName(repositoryObject.getName());
            repositoryFile.setType(((RepositoryObject) repositoryObject).getObjectType() == RepositoryObjectType.TRANSFORMATION ? TRANSFORMATION : JOB);
            repositoryFile.setObjectId(repositoryObject.getObjectId());
            repositoryObjects.add(repositoryFile);
        }
    }
    return repositoryObjects;
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) RepositoryDirectory(org.pentaho.repo.model.RepositoryDirectory) RepositoryObject(org.pentaho.di.repository.RepositoryObject) ArrayList(java.util.ArrayList) RepositoryExtended(org.pentaho.di.repository.RepositoryExtended) RepositoryFile(org.pentaho.repo.model.RepositoryFile) RepositoryObjectInterface(org.pentaho.di.repository.RepositoryObjectInterface)

Example 65 with RepositoryDirectoryInterface

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

the class RunTransServletTest method testRunTransServletCheckParameter.

@Test
public void testRunTransServletCheckParameter() throws Exception {
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
    Mockito.when(request.getParameter("trans")).thenReturn("home/test.rtr");
    StringWriter out = new StringWriter();
    PrintWriter printWriter = new PrintWriter(out);
    Mockito.when(request.getContextPath()).thenReturn(RunTransServlet.CONTEXT_PATH);
    Mockito.when(response.getWriter()).thenReturn(printWriter);
    TransformationMap mockTransformationMap = Mockito.mock(TransformationMap.class);
    SlaveServerConfig slaveServerConfig = Mockito.mock(SlaveServerConfig.class);
    Mockito.when(mockTransformationMap.getSlaveServerConfig()).thenReturn(slaveServerConfig);
    Repository repository = Mockito.mock(Repository.class);
    Mockito.when(slaveServerConfig.getRepository()).thenReturn(repository);
    RepositoryDirectoryInterface repositoryDirectoryInterface = Mockito.mock(RepositoryDirectoryInterface.class);
    Mockito.when(repository.loadRepositoryDirectoryTree()).thenReturn(repositoryDirectoryInterface);
    Mockito.when(repositoryDirectoryInterface.findDirectory(Mockito.anyString())).thenReturn(repositoryDirectoryInterface);
    TransMeta transMeta = Mockito.mock(TransMeta.class);
    Mockito.when(repository.loadTransformation(Mockito.any(), Mockito.any())).thenReturn(transMeta);
    String testParameter = "testParameter";
    Mockito.when(transMeta.listVariables()).thenReturn(new String[] { testParameter });
    Mockito.when(transMeta.getVariable(Mockito.anyString())).thenReturn("default value");
    Mockito.when(transMeta.listParameters()).thenReturn(new String[] { testParameter });
    Mockito.when(request.getParameterNames()).thenReturn(new StringTokenizer(testParameter));
    String testValue = "testValue";
    Mockito.when(request.getParameterValues(testParameter)).thenReturn(new String[] { testValue });
    RunTransServlet runTransServlet = Mockito.mock(RunTransServlet.class);
    Mockito.doCallRealMethod().when(runTransServlet).doGet(Mockito.anyObject(), Mockito.anyObject());
    Trans trans = new Trans(transMeta, new SimpleLoggingObject(RunTransServlet.CONTEXT_PATH, LoggingObjectType.CARTE, null));
    Mockito.when(runTransServlet.createTrans(Mockito.anyObject(), Mockito.anyObject())).thenReturn(trans);
    Mockito.when(transMeta.getParameterValue(Mockito.eq(testParameter))).thenReturn(testValue);
    runTransServlet.log = new LogChannel("RunTransServlet");
    runTransServlet.transformationMap = mockTransformationMap;
    runTransServlet.doGet(request, response);
    Assert.assertEquals(testValue, trans.getParameterValue(testParameter));
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) TransMeta(org.pentaho.di.trans.TransMeta) HttpServletResponse(javax.servlet.http.HttpServletResponse) LogChannel(org.pentaho.di.core.logging.LogChannel) SimpleLoggingObject(org.pentaho.di.core.logging.SimpleLoggingObject) HttpServletRequest(javax.servlet.http.HttpServletRequest) Repository(org.pentaho.di.repository.Repository) StringTokenizer(java.util.StringTokenizer) StringWriter(java.io.StringWriter) Trans(org.pentaho.di.trans.Trans) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Aggregations

RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)163 KettleException (org.pentaho.di.core.exception.KettleException)68 Test (org.junit.Test)32 TransMeta (org.pentaho.di.trans.TransMeta)30 ObjectId (org.pentaho.di.repository.ObjectId)27 JobMeta (org.pentaho.di.job.JobMeta)23 Repository (org.pentaho.di.repository.Repository)22 ArrayList (java.util.ArrayList)17 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)17 RepositoryDirectory (org.pentaho.di.repository.RepositoryDirectory)15 IOException (java.io.IOException)14 RepositoryElementMetaInterface (org.pentaho.di.repository.RepositoryElementMetaInterface)13 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)11 RepositoryObject (org.pentaho.di.repository.RepositoryObject)11 FileObject (org.apache.commons.vfs2.FileObject)10 List (java.util.List)8 TreeItem (org.eclipse.swt.widgets.TreeItem)8 KettleFileException (org.pentaho.di.core.exception.KettleFileException)8 Date (java.util.Date)7 FileSystemException (org.apache.commons.vfs2.FileSystemException)7