Search in sources :

Example 6 with RepositoryExtended

use of org.pentaho.di.repository.RepositoryExtended 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 7 with RepositoryExtended

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

the class RepositoryBrowserController method loadDirectoryTree.

public RepositoryTree loadDirectoryTree(String filter) {
    if (getRepository() != null) {
        try {
            if (getRepository() instanceof RepositoryExtended) {
                rootDirectory = ((RepositoryExtended) getRepository()).loadRepositoryDirectoryTree(false);
            } else {
                rootDirectory = getRepository().loadRepositoryDirectoryTree();
            }
            RepositoryTree repositoryTree = new RepositoryTree();
            RepositoryDirectory repositoryDirectory = RepositoryDirectory.build(null, rootDirectory);
            populateFolders(repositoryDirectory, rootDirectory);
            boolean isPentahoRepository = getRepository().getRepositoryMeta().getId().equals(PENTAHO_ENTERPRISE_REPOSITORY);
            repositoryTree.setIncludeRoot(!isPentahoRepository);
            repositoryTree.addChild(repositoryDirectory);
            return repositoryTree;
        } catch (Exception e) {
            return null;
        }
    }
    return null;
}
Also used : RepositoryDirectory(org.pentaho.repo.model.RepositoryDirectory) RepositoryExtended(org.pentaho.di.repository.RepositoryExtended) RepositoryTree(org.pentaho.repo.model.RepositoryTree) 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 8 with RepositoryExtended

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

the class GetRepositoryNames method getRepositoryObjects.

@SuppressWarnings("deprecation")
private List<RepositoryElementMetaInterface> getRepositoryObjects() throws KettleException {
    try {
        // The repository is available in the parent transformation metadata
        // 
        Repository repository = getTransMeta().getRepository();
        // Now populate the list...
        // 
        List<RepositoryElementMetaInterface> list = new ArrayList<RepositoryElementMetaInterface>();
        if (repository instanceof RepositoryExtended) {
            RepositoryExtended extendedRep = (RepositoryExtended) repository;
            for (int i = 0; i < meta.getDirectory().length; i++) {
                String directoryPath = environmentSubstitute(meta.getDirectory()[i]);
                String filter = null;
                // by default we look for current level
                int depth = 0;
                if (meta.getObjectTypeSelection().areTransformationsSelected()) {
                    filter = "*.ktr";
                }
                if (meta.getObjectTypeSelection().areJobsSelected()) {
                    // if we have selected the job and transformation than we have applied filter with both condition
                    filter = Utils.isEmpty(filter) ? "*.kjb" : filter + "|*.kjb";
                }
                // should include unlimited subfolder
                if (meta.getIncludeSubFolders()[i]) {
                    depth = -1;
                }
                RepositoryDirectoryInterface directory = extendedRep.loadRepositoryDirectoryTree(directoryPath, filter, depth, BooleanUtils.isTrue(repository.getUserInfo().isAdmin()), false, false);
                list.addAll(getRepositoryObjects(directory, environmentSubstitute(meta.getNameMask()[i]), environmentSubstitute(meta.getExcludeNameMask()[i])));
            }
        } else {
            // Get the repository directory tree.
            // 
            RepositoryDirectoryInterface tree = repository.loadRepositoryDirectoryTree();
            // 
            for (int i = 0; i < meta.getDirectory().length; i++) {
                RepositoryDirectoryInterface dir = tree.findDirectory(environmentSubstitute(meta.getDirectory()[i]));
                if (dir != null) {
                    List<RepositoryElementMetaInterface> objects = getRepositoryObjects(repository, dir, meta.getIncludeSubFolders()[i], environmentSubstitute(meta.getNameMask()[i]), environmentSubstitute(meta.getExcludeNameMask()[i]));
                    list.addAll(objects);
                }
            }
        }
        return list;
    } catch (Exception e) {
        throw new KettleException("Unable to get the list of repository objects from the repository", e);
    }
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) KettleException(org.pentaho.di.core.exception.KettleException) Repository(org.pentaho.di.repository.Repository) ArrayList(java.util.ArrayList) RepositoryExtended(org.pentaho.di.repository.RepositoryExtended) KettleException(org.pentaho.di.core.exception.KettleException) RepositoryElementMetaInterface(org.pentaho.di.repository.RepositoryElementMetaInterface)

Example 9 with RepositoryExtended

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

the class BrowseControllerTest method testInit.

// PDI-16258
@Test
public void testInit() throws Exception {
    RepositoryExtended repository = Mockito.mock(RepositoryExtended.class);
    UserInfo userInfo = new UserInfo("user", "password", "user", "test user", true);
    userInfo.setAdmin(true);
    Mockito.doReturn(userInfo).when(repository).getUserInfo();
    Mockito.doReturn(Mockito.mock(RepositoryDirectoryInterface.class)).when(repository).loadRepositoryDirectoryTree(anyString(), anyString(), anyInt(), anyBoolean(), anyBoolean(), anyBoolean());
    BrowseController browseController = Mockito.spy(controller);
    doNothing().when(browseController).createBindings();
    browseController.init(repository);
    Mockito.verify(repository).loadRepositoryDirectoryTree("/", "*.ktr|*.kjb", -1, true, true, true);
    userInfo.setAdmin(false);
    browseController.init(repository);
    Mockito.verify(repository).loadRepositoryDirectoryTree("/", "*.ktr|*.kjb", -1, false, true, true);
    userInfo.setAdmin(null);
    browseController.init(repository);
    Mockito.verify(repository, Mockito.times(2)).loadRepositoryDirectoryTree("/", "*.ktr|*.kjb", -1, false, true, true);
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) RepositoryExtended(org.pentaho.di.repository.RepositoryExtended) UserInfo(org.pentaho.di.repository.UserInfo) Test(org.junit.Test)

Example 10 with RepositoryExtended

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

the class UIRepositoryDirectoryTest method testRefresh.

@Test
public void testRefresh() throws Exception {
    RepositoryDirectory root = new RepositoryDirectory();
    LongObjectId rootObjectId = new LongObjectId(0L);
    root.setObjectId(rootObjectId);
    RepositoryDirectory dir = new RepositoryDirectory();
    dir.setObjectId(new LongObjectId(1L));
    root.addSubdirectory(dir);
    RepositoryExtended repo = mock(RepositoryExtended.class);
    UserInfo userInfo = new UserInfo();
    userInfo.setAdmin(true);
    Mockito.when(repo.getUserInfo()).thenReturn(userInfo);
    RepositoryDirectory rd = Mockito.mock(RepositoryDirectory.class);
    Mockito.when(rd.findDirectory(Mockito.eq(rootObjectId))).thenReturn(Mockito.mock(RepositoryDirectory.class));
    Mockito.when(repo.loadRepositoryDirectoryTree("/", "*.ktr|*.kjb", -1, true, true, true)).thenReturn(rd);
    UIRepositoryDirectory uiDir = new UIRepositoryDirectory(root, null, repo);
    uiDir.refresh();
    Mockito.verify(repo).loadRepositoryDirectoryTree("/", "*.ktr|*.kjb", -1, true, true, true);
}
Also used : RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) RepositoryExtended(org.pentaho.di.repository.RepositoryExtended) UserInfo(org.pentaho.di.repository.UserInfo) LongObjectId(org.pentaho.di.repository.LongObjectId) Test(org.junit.Test)

Aggregations

RepositoryExtended (org.pentaho.di.repository.RepositoryExtended)11 KettleException (org.pentaho.di.core.exception.KettleException)7 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)7 KettleJobException (org.pentaho.di.core.exception.KettleJobException)3 KettleObjectExistsException (org.pentaho.di.core.exception.KettleObjectExistsException)3 KettleTransException (org.pentaho.di.core.exception.KettleTransException)3 ArrayList (java.util.ArrayList)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 FormAttachment (org.eclipse.swt.layout.FormAttachment)2 FormData (org.eclipse.swt.layout.FormData)2 FormLayout (org.eclipse.swt.layout.FormLayout)2 Button (org.eclipse.swt.widgets.Button)2 Event (org.eclipse.swt.widgets.Event)2 Listener (org.eclipse.swt.widgets.Listener)2 Shell (org.eclipse.swt.widgets.Shell)2 Tree (org.eclipse.swt.widgets.Tree)2 Test (org.junit.Test)2 ObjectId (org.pentaho.di.repository.ObjectId)2 UserInfo (org.pentaho.di.repository.UserInfo)2