use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository 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());
}
use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository 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));
}
use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-kettle by pentaho.
the class PurRepository_GetObjectInformation_IT method getObjectInformation_InvalidRepositoryId_NullIsHandled.
@Test
public void getObjectInformation_InvalidRepositoryId_NullIsHandled() throws Exception {
IUnifiedRepository unifiedRepository = mock(IUnifiedRepository.class);
when(unifiedRepository.getFileById(any(Serializable.class))).thenReturn(null);
purRepository.setTest(unifiedRepository);
RepositoryObject information = purRepository.getObjectInformation(new StringObjectId("invalid id"), RepositoryObjectType.JOB);
assertNull("Should return null if file was not found", information);
}
use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-kettle by pentaho.
the class PurRepository method connect.
@Override
public void connect(final String username, final String password) throws KettleException {
connected = false;
if (isTest()) {
connected = true;
purRepositoryServiceRegistry.registerService(IRevisionService.class, new UnifiedRepositoryRevisionService(pur, getRootRef()));
purRepositoryServiceRegistry.registerService(ILockService.class, new UnifiedRepositoryLockService(pur));
purRepositoryServiceRegistry.registerService(IAclService.class, new UnifiedRepositoryConnectionAclService(pur));
metaStore = new PurRepositoryMetaStore(this);
try {
metaStore.createNamespace(PentahoDefaults.NAMESPACE);
} catch (MetaStoreException e) {
log.logError(BaseMessages.getString(PKG, "PurRepositoryMetastore.NamespaceCreateException.Message", PentahoDefaults.NAMESPACE), e);
}
this.user = new EEUserInfo(username, password, username, "test user", true);
this.jobDelegate = new JobDelegate(this, pur);
this.transDelegate = new TransDelegate(this, pur);
this.unifiedRepositoryLockService = new UnifiedRepositoryLockService(pur);
return;
}
try {
if (log != null && purRepositoryConnector != null && purRepositoryConnector.getLog() != null) {
purRepositoryConnector.getLog().setLogLevel(log.getLogLevel());
}
RepositoryConnectResult result = purRepositoryConnector.connect(username, password);
this.user = result.getUser();
this.connected = result.isSuccess();
this.securityProvider = result.getSecurityProvider();
this.securityManager = result.getSecurityManager();
IUnifiedRepository r = result.getUnifiedRepository();
try {
this.pur = (IUnifiedRepository) Proxy.newProxyInstance(r.getClass().getClassLoader(), new Class<?>[] { IUnifiedRepository.class }, new UnifiedRepositoryInvocationHandler<IUnifiedRepository>(r));
if (this.securityProvider != null) {
this.securityProvider = (RepositorySecurityProvider) Proxy.newProxyInstance(this.securityProvider.getClass().getClassLoader(), new Class<?>[] { RepositorySecurityProvider.class }, new UnifiedRepositoryInvocationHandler<RepositorySecurityProvider>(this.securityProvider));
}
} catch (Throwable th) {
if (log.isError()) {
log.logError("Failed to setup repository connection", th);
}
connected = false;
}
this.unifiedRepositoryLockService = new UnifiedRepositoryLockService(pur);
this.connectMessage = result.getConnectMessage();
this.purRepositoryServiceRegistry = result.repositoryServiceRegistry();
this.transDelegate = new TransDelegate(this, pur);
this.jobDelegate = new JobDelegate(this, pur);
} finally {
if (connected) {
if (log.isBasic()) {
log.logBasic(BaseMessages.getString(PKG, "PurRepositoryMetastore.Create.Message"));
}
metaStore = new PurRepositoryMetaStore(this);
// Create the default Pentaho namespace if it does not exist
try {
metaStore.createNamespace(PentahoDefaults.NAMESPACE);
if (log.isBasic()) {
log.logBasic(BaseMessages.getString(PKG, "PurRepositoryMetastore.NamespaceCreateSuccess.Message", PentahoDefaults.NAMESPACE));
}
} catch (MetaStoreNamespaceExistsException e) {
// Ignore this exception, we only use it to save a call to check if the namespace exists, as the
// createNamespace()
// call will do the check for us and throw this exception.
} catch (MetaStoreException e) {
log.logError(BaseMessages.getString(PKG, "PurRepositoryMetastore.NamespaceCreateException.Message", PentahoDefaults.NAMESPACE), e);
}
if (log.isBasic()) {
log.logBasic(BaseMessages.getString(PKG, "PurRepository.ConnectSuccess.Message"));
}
}
}
}
use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-platform by pentaho.
the class XactionUtil method deleteContentItem.
static void deleteContentItem(IContentItem contentItem, IUnifiedRepository unifiedRepository) {
if (contentItem instanceof RepositoryFileContentItem) {
String path = contentItem.getPath();
RepositoryFile repositoryFile = unifiedRepository.getFile(path);
// repositoryFile can be null if we have not access or file does not exist
if (repositoryFile != null) {
unifiedRepository.deleteFile(repositoryFile.getId(), true, null);
}
} else if (contentItem instanceof FileContentItem) {
// Files in the file system must not be deleted here
String path = ((FileContentItem) contentItem).getFile().getName();
logger.warn(Messages.getInstance().getString("XactionUtil.SKIP_REMOVING_OUTPUT_FILE", path));
}
}
Aggregations