Search in sources :

Example 16 with RepositoryObjectType

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

the class RepositoryBrowserController method hasDupeFile.

/**
 * Checks if there is a duplicate file in a given directory (i.e. hidden file)
 * @param path - Path to directory in which we are saving
 * @param name - Name of file to save
 * @param fileName - Possible duplicate file name
 * @param override - True is user wants override file, false otherwise
 * @return - true if a duplicate file is found, false otherwise
 */
private boolean hasDupeFile(String path, String name, String fileName, boolean override) {
    try {
        RepositoryDirectoryInterface repositoryDirectoryInterface = getRepository().findDirectory(path);
        EngineMetaInterface meta = getSpoon().getActiveMeta();
        RepositoryObjectType type = "Trans".equals(meta.getFileType()) ? RepositoryObjectType.TRANSFORMATION : RepositoryObjectType.JOB;
        if (getRepository().exists(name, repositoryDirectoryInterface, type)) {
            return !override || !name.equals(fileName);
        }
    } catch (Exception e) {
        System.out.println(e);
    }
    return false;
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) EngineMetaInterface(org.pentaho.di.core.EngineMetaInterface) RepositoryObjectType(org.pentaho.di.repository.RepositoryObjectType) 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 17 with RepositoryObjectType

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

the class AutoDoc method processRow.

public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {
    meta = (AutoDocMeta) smi;
    data = (AutoDocData) sdi;
    Object[] row = getRow();
    if (row == null) {
        if (data.filenames.isEmpty()) {
            // Nothing to see here, move along!
            // 
            setOutputDone();
            return false;
        }
        // End of the line, create the documentation...
        // 
        FileObject targetFile = KettleVFS.getFileObject(environmentSubstitute(meta.getTargetFilename()));
        String targetFilename = KettleVFS.getFilename(targetFile);
        // Create the report builder
        // 
        KettleReportBuilder kettleReportBuilder = new KettleReportBuilder(this, data.filenames, KettleVFS.getFilename(targetFile), meta);
        try {
            // 
            if (ClassicEngineBoot.getInstance().isBootDone() == false) {
                ObjectUtilities.setClassLoader(getClass().getClassLoader());
                ObjectUtilities.setClassLoaderSource(ObjectUtilities.CLASS_CONTEXT);
                LibLoaderBoot.getInstance().start();
                LibFontBoot.getInstance().start();
                ClassicEngineBoot.getInstance().start();
            }
            // Do the reporting thing...
            // 
            kettleReportBuilder.createReport();
            kettleReportBuilder.render();
            Object[] outputRowData = RowDataUtil.allocateRowData(data.outputRowMeta.size());
            int outputIndex = 0;
            outputRowData[outputIndex++] = targetFilename;
            // Pass along the data to the next steps...
            // 
            putRow(data.outputRowMeta, outputRowData);
            // Add the target file to the result file list
            // 
            ResultFile resultFile = new ResultFile(ResultFile.FILE_TYPE_GENERAL, targetFile, getTransMeta().getName(), toString());
            resultFile.setComment("This file was generated by the 'Auto Documentation Output' step");
            addResultFile(resultFile);
        } catch (Exception e) {
            throw new KettleException(BaseMessages.getString(PKG, "AutoDoc.Exception.UnableToRenderReport"), e);
        }
        setOutputDone();
        return false;
    }
    if (first) {
        first = false;
        data.outputRowMeta = getInputRowMeta().clone();
        meta.getFields(data.outputRowMeta, getStepname(), null, null, this, repository, metaStore);
        // Get the filename field index...
        // 
        String filenameField = environmentSubstitute(meta.getFilenameField());
        data.fileNameFieldIndex = getInputRowMeta().indexOfValue(filenameField);
        if (data.fileNameFieldIndex < 0) {
            throw new KettleException(BaseMessages.getString(PKG, "AutoDoc.Exception.FilenameFieldNotFound", filenameField));
        }
        // Get the file type field index...
        // 
        String fileTypeField = environmentSubstitute(meta.getFileTypeField());
        data.fileTypeFieldIndex = getInputRowMeta().indexOfValue(fileTypeField);
        if (data.fileTypeFieldIndex < 0) {
            throw new KettleException(BaseMessages.getString(PKG, "AutoDoc.Exception.FileTypeFieldNotFound", fileTypeField));
        }
        data.repository = getTrans().getRepository();
        if (data.repository != null) {
            data.tree = data.repository.loadRepositoryDirectoryTree();
        }
        // Initialize the repository information handlers (images, metadata, loading, etc)
        // 
        TransformationInformation.init(getTrans().getRepository());
        JobInformation.init(getTrans().getRepository());
    }
    // One more transformation or job to place in the documentation.
    // 
    String fileName = getInputRowMeta().getString(row, data.fileNameFieldIndex);
    String fileType = getInputRowMeta().getString(row, data.fileTypeFieldIndex);
    RepositoryObjectType objectType;
    if ("Transformation".equalsIgnoreCase(fileType)) {
        objectType = RepositoryObjectType.TRANSFORMATION;
    } else if ("Job".equalsIgnoreCase(fileType)) {
        objectType = RepositoryObjectType.JOB;
    } else {
        throw new KettleException(BaseMessages.getString(PKG, "AutoDoc.Exception.UnknownFileTypeValue", fileType));
    }
    ReportSubjectLocation location = null;
    if (getTrans().getRepository() == null) {
        switch(objectType) {
            case TRANSFORMATION:
                location = new ReportSubjectLocation(fileName, null, null, objectType);
                break;
            case JOB:
                location = new ReportSubjectLocation(fileName, null, null, objectType);
                break;
            default:
                break;
        }
    } else {
        int lastSlashIndex = fileName.lastIndexOf(RepositoryDirectory.DIRECTORY_SEPARATOR);
        if (lastSlashIndex < 0) {
            fileName = RepositoryDirectory.DIRECTORY_SEPARATOR + fileName;
            lastSlashIndex = 0;
        }
        String directoryName = fileName.substring(0, lastSlashIndex + 1);
        String objectName = fileName.substring(lastSlashIndex + 1);
        RepositoryDirectoryInterface directory = data.tree.findDirectory(directoryName);
        if (directory == null) {
            throw new KettleException(BaseMessages.getString(PKG, "AutoDoc.Exception.RepositoryDirectoryNotFound", directoryName));
        }
        location = new ReportSubjectLocation(null, directory, objectName, objectType);
    }
    if (location == null) {
        throw new KettleException(BaseMessages.getString(PKG, "AutoDoc.Exception.UnableToDetermineLocation", fileName, fileType));
    }
    if (meta.getOutputType() != OutputType.METADATA) {
        // Add the file location to the list for later processing in one output report
        // 
        data.filenames.add(location);
    } else {
        // Load the metadata from the transformation / job...
        // Output it in one row for each input row
        // 
        Object[] outputRow = RowDataUtil.resizeArray(row, data.outputRowMeta.size());
        int outputIndex = getInputRowMeta().size();
        List<AreaOwner> imageAreaList = null;
        switch(location.getObjectType()) {
            case TRANSFORMATION:
                TransformationInformation ti = TransformationInformation.getInstance();
                TransMeta transMeta = ti.getTransMeta(location);
                imageAreaList = ti.getImageAreaList(location);
                // TransMeta
                outputRow[outputIndex++] = transMeta;
                break;
            case JOB:
                JobInformation ji = JobInformation.getInstance();
                JobMeta jobMeta = ji.getJobMeta(location);
                imageAreaList = ji.getImageAreaList(location);
                // TransMeta
                outputRow[outputIndex++] = jobMeta;
                break;
            default:
                break;
        }
        // Name
        if (meta.isIncludingName()) {
            outputRow[outputIndex++] = KettleFileTableModel.getName(location);
        }
        // Description
        if (meta.isIncludingDescription()) {
            outputRow[outputIndex++] = KettleFileTableModel.getDescription(location);
        }
        // Extended Description
        if (meta.isIncludingExtendedDescription()) {
            outputRow[outputIndex++] = KettleFileTableModel.getExtendedDescription(location);
        }
        // created
        if (meta.isIncludingCreated()) {
            outputRow[outputIndex++] = KettleFileTableModel.getCreation(location);
        }
        // modified
        if (meta.isIncludingModified()) {
            outputRow[outputIndex++] = KettleFileTableModel.getModification(location);
        }
        // image
        if (meta.isIncludingImage()) {
            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
            try {
                BufferedImage image = KettleFileTableModel.getImage(location);
                ImageIO.write(image, "png", outputStream);
                outputRow[outputIndex++] = outputStream.toByteArray();
            } catch (Exception e) {
                throw new KettleException("Unable to serialize image to PNG", e);
            } finally {
                try {
                    outputStream.close();
                } catch (IOException e) {
                    throw new KettleException("Unable to serialize image to PNG", e);
                }
            }
        }
        if (meta.isIncludingLoggingConfiguration()) {
            outputRow[outputIndex++] = KettleFileTableModel.getLogging(location);
        }
        if (meta.isIncludingLastExecutionResult()) {
            outputRow[outputIndex++] = KettleFileTableModel.getLogging(location);
        }
        if (meta.isIncludingImageAreaList()) {
            outputRow[outputIndex++] = imageAreaList;
        }
        putRow(data.outputRowMeta, outputRow);
    }
    return true;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) JobMeta(org.pentaho.di.job.JobMeta) TransMeta(org.pentaho.di.trans.TransMeta) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ResultFile(org.pentaho.di.core.ResultFile) KettleException(org.pentaho.di.core.exception.KettleException) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage) AreaOwner(org.pentaho.di.core.gui.AreaOwner) RepositoryObjectType(org.pentaho.di.repository.RepositoryObjectType) FileObject(org.apache.commons.vfs2.FileObject) FileObject(org.apache.commons.vfs2.FileObject)

Example 18 with RepositoryObjectType

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

the class Spoon method loadLastUsedFile.

private void loadLastUsedFile(LastUsedFile lastUsedFile, String repositoryName, boolean trackIt, boolean isStartup) throws KettleException {
    boolean useRepository = repositoryName != null;
    // 
    if (lastUsedFile.isSourceRepository()) {
        if (!Utils.isEmpty(lastUsedFile.getRepositoryName())) {
            if (useRepository && !lastUsedFile.getRepositoryName().equalsIgnoreCase(repositoryName)) {
                // We just asked...
                useRepository = false;
            }
        }
    }
    if (useRepository && lastUsedFile.isSourceRepository()) {
        if (rep != null) {
            // load from this repository...
            if (rep.getName().equalsIgnoreCase(lastUsedFile.getRepositoryName())) {
                RepositoryDirectoryInterface rdi = rep.findDirectory(lastUsedFile.getDirectory());
                if (rdi != null) {
                    // does the file exist in the repo?
                    final RepositoryObjectType fileType = lastUsedFile.isJob() ? RepositoryObjectType.JOB : RepositoryObjectType.TRANSFORMATION;
                    if (!rep.exists(lastUsedFile.getFilename(), rdi, fileType)) {
                        // opening this file
                        if (isStartup) {
                            if (log.isDetailed()) {
                                log.logDetailed(BaseMessages.getString(PKG, "Spoon.log.openingMissingFile"));
                            }
                        } else {
                            final Dialog dlg = new SimpleMessageDialog(shell, BaseMessages.getString(PKG, "Spoon.Dialog.MissingRecentFile.Title"), BaseMessages.getString(PKG, "Spoon.Dialog.MissingRecentFile.Message", lastUsedFile.getLongFileType().toLowerCase()), MessageDialog.ERROR, BaseMessages.getString(PKG, "System.Button.Close"), MISSING_RECENT_DLG_WIDTH, SimpleMessageDialog.BUTTON_WIDTH);
                            dlg.open();
                        }
                    } else {
                        // Are we loading a transformation or a job?
                        if (lastUsedFile.isTransformation()) {
                            if (log.isDetailed()) {
                                // "Auto loading transformation ["+lastfiles[0]+"] from repository directory ["+lastdirs[0]+"]"
                                log.logDetailed(BaseMessages.getString(PKG, "Spoon.Log.AutoLoadingTransformation", lastUsedFile.getFilename(), lastUsedFile.getDirectory()));
                            }
                            TransLoadProgressDialog tlpd = new TransLoadProgressDialog(shell, rep, lastUsedFile.getFilename(), rdi, null);
                            TransMeta transMeta = tlpd.open();
                            if (transMeta != null) {
                                if (trackIt) {
                                    props.addLastFile(LastUsedFile.FILE_TYPE_TRANSFORMATION, lastUsedFile.getFilename(), rdi.getPath(), true, rep.getName(), getUsername(), null);
                                }
                                // transMeta.setFilename(lastUsedFile.getFilename());
                                transMeta.clearChanged();
                                addTransGraph(transMeta);
                                refreshTree();
                            }
                        } else if (lastUsedFile.isJob()) {
                            JobLoadProgressDialog progressDialog = new JobLoadProgressDialog(shell, rep, lastUsedFile.getFilename(), rdi, null);
                            JobMeta jobMeta = progressDialog.open();
                            if (jobMeta != null) {
                                if (trackIt) {
                                    props.addLastFile(LastUsedFile.FILE_TYPE_JOB, lastUsedFile.getFilename(), rdi.getPath(), true, rep.getName(), getUsername(), null);
                                }
                                jobMeta.clearChanged();
                                addJobGraph(jobMeta);
                            }
                        }
                        refreshTree();
                    }
                }
            }
        }
    }
    // open files stored locally, not in the repository
    if (!lastUsedFile.isSourceRepository() && !Utils.isEmpty(lastUsedFile.getFilename())) {
        if (lastUsedFile.isTransformation()) {
            openFile(lastUsedFile.getFilename(), rep != null);
        }
        if (lastUsedFile.isJob()) {
            openFile(lastUsedFile.getFilename(), false);
        }
        refreshTree();
    }
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) JobMeta(org.pentaho.di.job.JobMeta) SimpleMessageDialog(org.pentaho.di.ui.core.dialog.SimpleMessageDialog) TransLoadProgressDialog(org.pentaho.di.ui.trans.dialog.TransLoadProgressDialog) LogSettingsDialog(org.pentaho.di.ui.spoon.dialog.LogSettingsDialog) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) SubjectDataBrowserDialog(org.pentaho.di.ui.core.dialog.SubjectDataBrowserDialog) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) ImportRulesDialog(org.pentaho.di.ui.imp.ImportRulesDialog) RepositoriesDialog(org.pentaho.di.ui.repository.RepositoriesDialog) KettlePropertiesFileDialog(org.pentaho.di.ui.core.dialog.KettlePropertiesFileDialog) EnterMappingDialog(org.pentaho.di.ui.core.dialog.EnterMappingDialog) Dialog(org.eclipse.jface.dialogs.Dialog) CheckTransProgressDialog(org.pentaho.di.ui.spoon.dialog.CheckTransProgressDialog) PreviewRowsDialog(org.pentaho.di.ui.core.dialog.PreviewRowsDialog) ShowMessageDialog(org.pentaho.di.ui.core.dialog.ShowMessageDialog) CapabilityManagerDialog(org.pentaho.di.ui.spoon.dialog.CapabilityManagerDialog) TransHopDialog(org.pentaho.di.ui.trans.dialog.TransHopDialog) TransLoadProgressDialog(org.pentaho.di.ui.trans.dialog.TransLoadProgressDialog) EnterOptionsDialog(org.pentaho.di.ui.core.dialog.EnterOptionsDialog) BrowserEnvironmentWarningDialog(org.pentaho.di.ui.core.dialog.BrowserEnvironmentWarningDialog) AuthProviderDialog(org.pentaho.di.ui.core.auth.AuthProviderDialog) EnterSearchDialog(org.pentaho.di.ui.core.dialog.EnterSearchDialog) EnterStringsDialog(org.pentaho.di.ui.core.dialog.EnterStringsDialog) VfsFileChooserDialog(org.pentaho.vfs.ui.VfsFileChooserDialog) EnterTextDialog(org.pentaho.di.ui.core.dialog.EnterTextDialog) EnterSelectionDialog(org.pentaho.di.ui.core.dialog.EnterSelectionDialog) SelectDirectoryDialog(org.pentaho.di.ui.repository.dialog.SelectDirectoryDialog) MetaStoreExplorerDialog(org.pentaho.di.ui.spoon.dialog.MetaStoreExplorerDialog) RepositoryImportProgressDialog(org.pentaho.di.ui.repository.dialog.RepositoryImportProgressDialog) SaveProgressDialog(org.pentaho.di.ui.spoon.dialog.SaveProgressDialog) AnalyseImpactProgressDialog(org.pentaho.di.ui.spoon.dialog.AnalyseImpactProgressDialog) RepositoryExportProgressDialog(org.pentaho.di.ui.repository.dialog.RepositoryExportProgressDialog) AboutDialog(org.pentaho.di.ui.core.dialog.AboutDialog) JobLoadProgressDialog(org.pentaho.di.ui.job.dialog.JobLoadProgressDialog) WizardDialog(org.eclipse.jface.wizard.WizardDialog) SimpleMessageDialog(org.pentaho.di.ui.core.dialog.SimpleMessageDialog) CheckResultDialog(org.pentaho.di.ui.core.dialog.CheckResultDialog) ShowBrowserDialog(org.pentaho.di.ui.core.dialog.ShowBrowserDialog) FileDialog(org.eclipse.swt.widgets.FileDialog) TransMeta(org.pentaho.di.trans.TransMeta) RepositoryObjectType(org.pentaho.di.repository.RepositoryObjectType) JobLoadProgressDialog(org.pentaho.di.ui.job.dialog.JobLoadProgressDialog)

Example 19 with RepositoryObjectType

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

the class PurRepositoryUnitTest method testEtcIsNotThereInGetChildren.

@Test
public void testEtcIsNotThereInGetChildren() throws KettleException {
    PurRepository purRepository = new PurRepository();
    IUnifiedRepository mockRepo = mock(IUnifiedRepository.class);
    RepositoryConnectResult result = mock(RepositoryConnectResult.class);
    when(result.getUnifiedRepository()).thenReturn(mockRepo);
    IRepositoryConnector connector = mock(IRepositoryConnector.class);
    when(connector.connect(anyString(), anyString())).thenReturn(result);
    PurRepositoryMeta mockMeta = mock(PurRepositoryMeta.class);
    purRepository.init(mockMeta);
    purRepository.setPurRepositoryConnector(connector);
    // purRepository.setTest( mockRepo );
    ObjectId objectId = mock(ObjectId.class);
    RepositoryFile mockFile = mock(RepositoryFile.class);
    RepositoryFile mockRootFolder = mock(RepositoryFile.class);
    RepositoryObjectType repositoryObjectType = RepositoryObjectType.TRANSFORMATION;
    RepositoryFileTree mockRepositoryTree = mock(RepositoryFileTree.class);
    String testId = "TEST_ID";
    String testFileId = "TEST_FILE_ID";
    when(objectId.getId()).thenReturn(testId);
    when(mockRepo.getFileById(testId)).thenReturn(mockFile);
    when(mockFile.getPath()).thenReturn("/etc");
    when(mockFile.getId()).thenReturn(testFileId);
    when(mockRepositoryTree.getFile()).thenReturn(mockRootFolder);
    when(mockRootFolder.getId()).thenReturn("/");
    when(mockRootFolder.getPath()).thenReturn("/");
    List<RepositoryFile> rootChildren = new ArrayList<>(Collections.singletonList(mockFile));
    when(mockRepo.getChildren(argThat(IsInstanceOf.<RepositoryRequest>instanceOf(RepositoryRequest.class)))).thenReturn(rootChildren);
    // for Lazy Repo
    when(mockRepo.getFile("/")).thenReturn(mockRootFolder);
    // for Eager Repo
    RepositoryFileTree repositoryFileTree = mock(RepositoryFileTree.class);
    when(mockRepo.getTree("/", -1, null, true)).thenReturn(repositoryFileTree);
    when(repositoryFileTree.getFile()).thenReturn(mockRootFolder);
    purRepository.connect("TEST_USER", "TEST_PASSWORD");
    List<RepositoryDirectoryInterface> children = purRepository.getRootDir().getChildren();
    assertThat(children, empty());
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) StringObjectId(org.pentaho.di.repository.StringObjectId) ObjectId(org.pentaho.di.repository.ObjectId) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree) RepositoryObjectType(org.pentaho.di.repository.RepositoryObjectType) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Test(org.junit.Test)

Example 20 with RepositoryObjectType

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

the class PurRepositoryUnitTest method testRevisionsEnabled.

@Test
public void testRevisionsEnabled() throws KettleException {
    PurRepository purRepository = new PurRepository();
    IUnifiedRepository mockRepo = mock(IUnifiedRepository.class);
    RepositoryConnectResult result = mock(RepositoryConnectResult.class);
    when(result.getUnifiedRepository()).thenReturn(mockRepo);
    IRepositoryConnector connector = mock(IRepositoryConnector.class);
    when(connector.connect(anyString(), anyString())).thenReturn(result);
    RepositoryServiceRegistry registry = mock(RepositoryServiceRegistry.class);
    UnifiedRepositoryLockService lockService = new UnifiedRepositoryLockService(mockRepo);
    when(registry.getService(ILockService.class)).thenReturn(lockService);
    when(result.repositoryServiceRegistry()).thenReturn(registry);
    PurRepositoryMeta mockMeta = mock(PurRepositoryMeta.class);
    purRepository.init(mockMeta);
    purRepository.setPurRepositoryConnector(connector);
    // purRepository.setTest( mockRepo );
    ObjectId objectId = mock(ObjectId.class);
    RepositoryFile mockFileVersioningEnabled = mock(RepositoryFile.class);
    RepositoryFile mockFileVersioningNotEnabled = mock(RepositoryFile.class);
    RepositoryFileTree mockRepositoryTreeChildVersioningEnabled = mock(RepositoryFileTree.class);
    RepositoryFileTree mockRepositoryTreeChildVersioningNotEnabled = mock(RepositoryFileTree.class);
    RepositoryFile publicFolder = mock(RepositoryFile.class);
    RepositoryFileTree publicFolderTree = mock(RepositoryFileTree.class);
    RepositoryFile mockRootFolder = mock(RepositoryFile.class);
    RepositoryObjectType repositoryObjectType = RepositoryObjectType.TRANSFORMATION;
    RepositoryFileTree mockRepositoryTree = mock(RepositoryFileTree.class);
    String testId = "TEST_ID";
    String testFileId = "TEST_FILE_ID";
    List<RepositoryFileTree> children = Arrays.asList(mockRepositoryTreeChildVersioningEnabled, mockRepositoryTreeChildVersioningNotEnabled);
    when(objectId.getId()).thenReturn(testId);
    when(mockRepo.getFileById(testId)).thenReturn(mockFileVersioningEnabled);
    when(mockFileVersioningEnabled.getPath()).thenReturn("/public/path.ktr");
    when(mockFileVersioningEnabled.getId()).thenReturn(testFileId);
    when(mockFileVersioningEnabled.getName()).thenReturn("path.ktr");
    when(mockFileVersioningNotEnabled.getPath()).thenReturn("/public/path2.ktr");
    when(mockFileVersioningNotEnabled.getId()).thenReturn(testFileId + "2");
    when(mockFileVersioningNotEnabled.getName()).thenReturn("path2.ktr");
    when(publicFolder.getPath()).thenReturn("/public");
    when(publicFolder.getName()).thenReturn("public");
    when(publicFolder.getId()).thenReturn(testFileId + "3");
    when(publicFolder.isFolder()).thenReturn(true);
    when(publicFolderTree.getFile()).thenReturn(publicFolder);
    when(mockRepositoryTreeChildVersioningEnabled.getFile()).thenReturn(mockFileVersioningEnabled);
    when(mockRepositoryTreeChildVersioningEnabled.getVersionCommentEnabled()).thenReturn(true);
    when(mockRepositoryTreeChildVersioningEnabled.getVersioningEnabled()).thenReturn(true);
    when(mockRepositoryTreeChildVersioningNotEnabled.getFile()).thenReturn(mockFileVersioningNotEnabled);
    when(mockRepositoryTreeChildVersioningNotEnabled.getVersionCommentEnabled()).thenReturn(false);
    when(mockRepositoryTreeChildVersioningNotEnabled.getVersioningEnabled()).thenReturn(false);
    when(mockRepo.getTree(anyString(), anyInt(), anyString(), anyBoolean())).thenReturn(mockRepositoryTree);
    when(mockRepo.getTree(any(RepositoryRequest.class))).thenReturn(mockRepositoryTree);
    when(mockRepo.getTree(argThat(new ArgumentMatcher<RepositoryRequest>() {

        @Override
        public boolean matches(Object argument) {
            return ((RepositoryRequest) argument).getPath().equals("/public");
        }
    }))).thenReturn(publicFolderTree);
    when(mockRepositoryTree.getFile()).thenReturn(mockRootFolder);
    when(mockRepositoryTree.getChildren()).thenReturn(new ArrayList<>(Arrays.asList(publicFolderTree)));
    when(publicFolderTree.getChildren()).thenReturn(children);
    when(mockRootFolder.getId()).thenReturn("/");
    when(mockRootFolder.getPath()).thenReturn("/");
    when(mockRepo.getFile("/")).thenReturn(mockRootFolder);
    when(mockRepo.getFile("/public")).thenReturn(publicFolder);
    purRepository.connect("TEST_USER", "TEST_PASSWORD");
    List<RepositoryElementMetaInterface> repositoryObjects = purRepository.findDirectory("/public").getRepositoryObjects();
    assertThat(repositoryObjects.size(), is(2));
    // Test Enabled
    RepositoryElementMetaInterface element = repositoryObjects.get(0);
    assertThat(element, is(instanceOf(EERepositoryObject.class)));
    EERepositoryObject eeElement = (EERepositoryObject) element;
    assertThat(eeElement.getVersioningEnabled(), is(true));
    assertThat(eeElement.getVersionCommentEnabled(), is(true));
    // Test Not Enabled
    RepositoryElementMetaInterface element2 = repositoryObjects.get(1);
    assertThat(element2, is(instanceOf(EERepositoryObject.class)));
    EERepositoryObject eeElement2 = (EERepositoryObject) element;
    assertThat(eeElement2.getVersioningEnabled(), is(true));
    assertThat(eeElement2.getVersionCommentEnabled(), is(true));
}
Also used : EERepositoryObject(org.pentaho.di.repository.pur.model.EERepositoryObject) StringObjectId(org.pentaho.di.repository.StringObjectId) ObjectId(org.pentaho.di.repository.ObjectId) Matchers.anyString(org.mockito.Matchers.anyString) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree) ArgumentMatcher(org.mockito.ArgumentMatcher) RepositoryObjectType(org.pentaho.di.repository.RepositoryObjectType) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest) EERepositoryObject(org.pentaho.di.repository.pur.model.EERepositoryObject) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) RepositoryElementMetaInterface(org.pentaho.di.repository.RepositoryElementMetaInterface) Test(org.junit.Test)

Aggregations

RepositoryObjectType (org.pentaho.di.repository.RepositoryObjectType)25 ArrayList (java.util.ArrayList)13 KettleException (org.pentaho.di.core.exception.KettleException)13 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)10 List (java.util.List)7 SharedObjectInterface (org.pentaho.di.shared.SharedObjectInterface)7 IdNotFoundException (org.pentaho.di.core.exception.IdNotFoundException)6 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)6 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)5 Test (org.junit.Test)5 KettleFileException (org.pentaho.di.core.exception.KettleFileException)5 KettleSecurityException (org.pentaho.di.core.exception.KettleSecurityException)5 RepositoryElementMetaInterface (org.pentaho.di.repository.RepositoryElementMetaInterface)5 StringObjectId (org.pentaho.di.repository.StringObjectId)5 EERepositoryObject (org.pentaho.di.repository.pur.model.EERepositoryObject)5 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)5 MetaStoreNamespaceExistsException (org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException)5 RepositoryFileTree (org.pentaho.platform.api.repository2.unified.RepositoryFileTree)5 UnifiedRepositoryCreateFileException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryCreateFileException)5 UnifiedRepositoryUpdateFileException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryUpdateFileException)5