Search in sources :

Example 21 with RepositoryElementMetaInterface

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

the class GetRepositoryNames method processRow.

@Override
public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {
    if (first) {
        first = false;
        data.outputRowMeta = new RowMeta();
        meta.getFields(data.outputRowMeta, getStepname(), null, null, this, repository, metaStore);
    }
    if (data.filenr >= data.list.size()) {
        setOutputDone();
        return false;
    }
    // Get the next repository object from the list...
    // 
    RepositoryElementMetaInterface repositoryObject = data.list.get(data.filenr++);
    Object[] outputRow = buildEmptyRow();
    int outputIndex = 0;
    String directory = repositoryObject.getRepositoryDirectory().getPath();
    String name = repositoryObject.getName();
    String path = directory.endsWith("/") ? directory + name : directory + "/" + name;
    // the directory and name of the object
    outputRow[outputIndex++] = path;
    // the directory
    outputRow[outputIndex++] = directory;
    // the name
    outputRow[outputIndex++] = name;
    // the object type
    outputRow[outputIndex++] = repositoryObject.getObjectType().getTypeDescription();
    // the object ID
    outputRow[outputIndex++] = repositoryObject.getObjectId().toString();
    // modified user
    outputRow[outputIndex++] = repositoryObject.getModifiedUser();
    // modified date
    outputRow[outputIndex++] = repositoryObject.getModifiedDate();
    // description
    outputRow[outputIndex++] = repositoryObject.getDescription();
    if (meta.isIncludeRowNumber()) {
        outputRow[outputIndex++] = Long.valueOf(data.rownr++);
    }
    // Finally, let's give this row of data to the next steps...
    // 
    putRow(data.outputRowMeta, outputRow);
    if (checkFeedback(getLinesInput())) {
        if (log.isBasic()) {
            logBasic(BaseMessages.getString(PKG, "GetRepositoryNames.Log.NrLine", "" + getLinesInput()));
        }
    }
    return true;
}
Also used : RowMeta(org.pentaho.di.core.row.RowMeta) RepositoryElementMetaInterface(org.pentaho.di.repository.RepositoryElementMetaInterface)

Example 22 with RepositoryElementMetaInterface

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

the class GetRepositoryNames method getRepositoryObjects.

private List<RepositoryElementMetaInterface> getRepositoryObjects(Repository repository, RepositoryDirectoryInterface directory, boolean subdirs, String nameMask, String excludeNameMask) throws KettleException {
    List<RepositoryElementMetaInterface> list = new ArrayList<RepositoryElementMetaInterface>();
    List<RepositoryElementMetaInterface> objects = new ArrayList<RepositoryElementMetaInterface>();
    if (meta.getObjectTypeSelection().areTransformationsSelected()) {
        objects.addAll(repository.getTransformationObjects(directory.getObjectId(), false));
    }
    if (meta.getObjectTypeSelection().areJobsSelected()) {
        objects.addAll(repository.getJobObjects(directory.getObjectId(), false));
    }
    for (RepositoryElementMetaInterface object : objects) {
        boolean add = false;
        if (Utils.isEmpty(nameMask) || object.getName().matches(nameMask)) {
            add = true;
        }
        if (!Utils.isEmpty(excludeNameMask) && object.getName().matches(excludeNameMask)) {
            add = false;
        }
        if (add) {
            list.add(object);
        }
    }
    if (subdirs) {
        for (RepositoryDirectoryInterface child : directory.getChildren()) {
            list.addAll(getRepositoryObjects(repository, child, subdirs, nameMask, excludeNameMask));
        }
    }
    return list;
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) ArrayList(java.util.ArrayList) RepositoryElementMetaInterface(org.pentaho.di.repository.RepositoryElementMetaInterface)

Example 23 with RepositoryElementMetaInterface

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

the class KettleDatabaseRepositoryConnectionDelegate method getRepositoryObjects.

/**
 * @param id_directory
 * @return A list of RepositoryObjects
 *
 * @throws KettleException
 */
public synchronized List<RepositoryElementMetaInterface> getRepositoryObjects(String tableName, RepositoryObjectType objectType, ObjectId id_directory) throws KettleException {
    try {
        String idField;
        if (RepositoryObjectType.TRANSFORMATION.equals(objectType)) {
            idField = KettleDatabaseRepository.FIELD_TRANSFORMATION_ID_TRANSFORMATION;
        } else {
            idField = KettleDatabaseRepository.FIELD_JOB_ID_JOB;
        }
        if (id_directory == null) {
            // root!
            id_directory = new LongObjectId(0L);
        }
        RepositoryDirectoryInterface repositoryDirectory = repository.directoryDelegate.loadPathToRoot(id_directory);
        // RepositoryDirectoryInterface repositoryDirectory =
        // repository.loadRepositoryDirectoryTree().findDirectory(id_directory);
        String sql = "SELECT " + quote(KettleDatabaseRepository.FIELD_TRANSFORMATION_NAME) + ", " + quote(KettleDatabaseRepository.FIELD_TRANSFORMATION_MODIFIED_USER) + ", " + quote(KettleDatabaseRepository.FIELD_TRANSFORMATION_MODIFIED_DATE) + ", " + quote(KettleDatabaseRepository.FIELD_TRANSFORMATION_DESCRIPTION) + ", " + quote(idField) + " " + "FROM " + tableName + " " + "WHERE " + quote(KettleDatabaseRepository.FIELD_TRANSFORMATION_ID_DIRECTORY) + " = ? ";
        RowMetaAndData directoryIdRow = getParameterMetaData(id_directory);
        return callRead(new Callable<List<RepositoryElementMetaInterface>>() {

            @Override
            public List<RepositoryElementMetaInterface> call() throws Exception {
                List<RepositoryElementMetaInterface> repositoryObjects = new ArrayList<RepositoryElementMetaInterface>();
                ResultSet rs = database.openQuery(sql, directoryIdRow.getRowMeta(), directoryIdRow.getData());
                if (rs != null) {
                    List<Object[]> rows = database.getRows(rs, -1, null);
                    if (rs != null) {
                        database.closeQuery(rs);
                    }
                    RowMetaInterface rowMeta = database.getReturnRowMeta();
                    for (Object[] r : rows) {
                        ObjectId id = new LongObjectId(rowMeta.getInteger(r, 4));
                        repositoryObjects.add(new RepositoryObject(id, rowMeta.getString(r, 0), repositoryDirectory, rowMeta.getString(r, 1), rowMeta.getDate(r, 2), objectType, rowMeta.getString(r, 3), false));
                    }
                }
                return repositoryObjects;
            }
        });
    } catch (Exception e) {
        throw new KettleException("Unable to get list of repository objects", e);
    }
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) KettleException(org.pentaho.di.core.exception.KettleException) RepositoryObject(org.pentaho.di.repository.RepositoryObject) LongObjectId(org.pentaho.di.repository.LongObjectId) ObjectId(org.pentaho.di.repository.ObjectId) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) LongObjectId(org.pentaho.di.repository.LongObjectId) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) SQLException(java.sql.SQLException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) List(java.util.List) SimpleLoggingObject(org.pentaho.di.core.logging.SimpleLoggingObject) RepositoryObject(org.pentaho.di.repository.RepositoryObject) RepositoryElementMetaInterface(org.pentaho.di.repository.RepositoryElementMetaInterface)

Example 24 with RepositoryElementMetaInterface

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

the class GetRepositoryNamesTest method prepareExtendedRepository.

@SuppressWarnings("deprecation")
private static void prepareExtendedRepository() throws KettleException {
    repoExtended = mock(RepositoryExtended.class);
    when(repoExtended.loadRepositoryDirectoryTree(anyString(), anyString(), anyInt(), anyBoolean(), anyBoolean(), anyBoolean())).then(new Answer<RepositoryDirectoryInterface>() {

        @Override
        public RepositoryDirectoryInterface answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            RepositoryDirectoryInterface root = new RepositoryDirectory();
            root.setName("/");
            RepositoryDirectoryInterface subdir1 = new RepositoryDirectory(root, "subdir1");
            RepositoryDirectoryInterface subdir2 = new RepositoryDirectory(subdir1, "subdir2");
            RepositoryElementMetaInterface trans1 = new RepositoryObject(null, "Trans1", subdir1, "user", null, RepositoryObjectType.TRANSFORMATION, "", false);
            RepositoryElementMetaInterface trans2 = new RepositoryObject(null, "Trans2", subdir2, "user", null, RepositoryObjectType.TRANSFORMATION, "", false);
            RepositoryElementMetaInterface job1 = new RepositoryObject(null, "Job1", subdir1, "user", null, RepositoryObjectType.JOB, "", false);
            RepositoryElementMetaInterface job2 = new RepositoryObject(null, "Job2", subdir2, "user", null, RepositoryObjectType.JOB, "", false);
            List<RepositoryElementMetaInterface> list1 = new ArrayList<RepositoryElementMetaInterface>();
            List<RepositoryElementMetaInterface> list2 = new ArrayList<RepositoryElementMetaInterface>();
            if (((String) args[1]).contains("ktr")) {
                list1.add(trans1);
                list2.add(trans2);
            }
            if (((String) args[1]).contains("kjb")) {
                list1.add(job1);
                list2.add(job2);
            }
            subdir1.setRepositoryObjects(list1);
            subdir2.setRepositoryObjects(list2);
            if (((Integer) args[2]) == -1) {
                subdir1.addSubdirectory(subdir2);
                root.addSubdirectory(subdir1);
            }
            String actualPath = ((String) args[0]);
            if (actualPath.equals("/")) {
                return root;
            } else if (actualPath.equals(subdir1.getPath())) {
                return subdir1;
            } else if (actualPath.equals(subdir2.getPath())) {
                return subdir2;
            } else {
                return null;
            }
        }
    });
    IUser user = Mockito.mock(IUser.class);
    Mockito.when(user.isAdmin()).thenReturn(true);
    Mockito.when(repoExtended.getUserInfo()).thenReturn(user);
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) RepositoryObject(org.pentaho.di.repository.RepositoryObject) Mockito.anyString(org.mockito.Mockito.anyString) InvocationOnMock(org.mockito.invocation.InvocationOnMock) IUser(org.pentaho.di.repository.IUser) RepositoryExtended(org.pentaho.di.repository.RepositoryExtended) ArrayList(java.util.ArrayList) List(java.util.List) RepositoryElementMetaInterface(org.pentaho.di.repository.RepositoryElementMetaInterface)

Example 25 with RepositoryElementMetaInterface

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

RepositoryElementMetaInterface (org.pentaho.di.repository.RepositoryElementMetaInterface)33 Test (org.junit.Test)13 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)13 ArrayList (java.util.ArrayList)11 KettleException (org.pentaho.di.core.exception.KettleException)11 RepositoryDirectory (org.pentaho.di.repository.RepositoryDirectory)8 ObjectId (org.pentaho.di.repository.ObjectId)7 LongObjectId (org.pentaho.di.repository.LongObjectId)5 Repository (org.pentaho.di.repository.Repository)5 RepositoryObject (org.pentaho.di.repository.RepositoryObject)5 RepositoryObjectType (org.pentaho.di.repository.RepositoryObjectType)5 StringObjectId (org.pentaho.di.repository.StringObjectId)5 IOException (java.io.IOException)4 List (java.util.List)4 TreeItem (org.eclipse.swt.widgets.TreeItem)4 KettleFileException (org.pentaho.di.core.exception.KettleFileException)4 EERepositoryObject (org.pentaho.di.repository.pur.model.EERepositoryObject)4 SimpleDateFormat (java.text.SimpleDateFormat)3 Date (java.util.Date)3 RepositoryLock (org.pentaho.di.repository.pur.model.RepositoryLock)3