use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-kettle by pentaho.
the class JobDelegateTest method testElementToDataNodeSavesCopyAttributes.
@Test
public void testElementToDataNodeSavesCopyAttributes() throws KettleException {
JobMeta mockJobMeta = mock(JobMeta.class);
IUnifiedRepository mockUnifiedRepository = mock(IUnifiedRepository.class);
JobDelegate jobDelegate = new JobDelegate(mockPurRepository, mockUnifiedRepository);
JobLogTable mockJobLogTable = mock(JobLogTable.class);
JobEntryCopy mockJobEntryCopy = mock(JobEntryCopy.class);
Map<String, Map<String, String>> attributes = new HashMap<String, Map<String, String>>();
Map<String, String> group = new HashMap<String, String>();
final String mockGroup = "MOCK_GROUP";
final String mockProperty = "MOCK_PROPERTY";
final String mockValue = "MOCK_VALUE";
group.put(mockProperty, mockValue);
attributes.put(mockGroup, group);
when(mockJobEntryCopy.getAttributesMap()).thenReturn(attributes);
JobEntryBaseAndInterface mockJobEntry = mock(JobEntryBaseAndInterface.class);
when(mockJobMeta.listParameters()).thenReturn(new String[] {});
when(mockJobMeta.getJobLogTable()).thenReturn(mockJobLogTable);
when(mockJobMeta.nrJobEntries()).thenReturn(1);
when(mockJobMeta.getJobEntry(0)).thenReturn(mockJobEntryCopy);
when(mockJobEntryCopy.getName()).thenReturn("MOCK_NAME");
when(mockJobEntryCopy.getLocation()).thenReturn(new Point(0, 0));
when(mockJobEntryCopy.getEntry()).thenReturn(mockJobEntry);
DataNode dataNode = jobDelegate.elementToDataNode(mockJobMeta);
DataNode groups = dataNode.getNode("entries").getNodes().iterator().next().getNode(AttributesMapUtil.NODE_ATTRIBUTE_GROUPS);
DataNode mockGroupNode = groups.getNode(mockGroup);
assertEquals(mockValue, mockGroupNode.getProperty(mockProperty).getString());
}
use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-kettle by pentaho.
the class PurRepositoryUnitTest method testGetObjectInformationGetsAclByFileId.
@Test
public void testGetObjectInformationGetsAclByFileId() throws KettleException {
PurRepository purRepository = new PurRepository();
IUnifiedRepository mockRepo = mock(IUnifiedRepository.class);
RepositoryConnectResult result = mock(RepositoryConnectResult.class);
when(result.getUnifiedRepository()).thenReturn(mockRepo);
RepositoryServiceRegistry registry = mock(RepositoryServiceRegistry.class);
UnifiedRepositoryLockService lockService = new UnifiedRepositoryLockService(mockRepo);
when(registry.getService(ILockService.class)).thenReturn(lockService);
when(result.repositoryServiceRegistry()).thenReturn(registry);
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("/home/testuser/path.ktr");
when(mockFile.isLocked()).thenReturn(false);
when(mockFile.getId()).thenReturn(testFileId);
when(mockRepo.getTree(anyString(), anyInt(), anyString(), anyBoolean())).thenReturn(mockRepositoryTree);
when(mockRepositoryTree.getFile()).thenReturn(mockRootFolder);
when(mockRootFolder.getId()).thenReturn("/");
when(mockRootFolder.getPath()).thenReturn("/");
when(mockRepo.getFile("/")).thenReturn(mockRootFolder);
purRepository.connect("TEST_USER", "TEST_PASSWORD");
purRepository.getObjectInformation(objectId, repositoryObjectType);
verify(mockRepo).getAcl(testFileId);
}
use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-kettle by pentaho.
the class PurRepositoryUnitTest method testEtcIsNotThereInGetNrDirectories.
@Test
public void testEtcIsNotThereInGetNrDirectories() 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);
ObjectId objectId = mock(ObjectId.class);
RepositoryFile mockEtcFolder = mock(RepositoryFile.class);
RepositoryFile mockFolderVisible = mock(RepositoryFile.class);
RepositoryFile mockRootFolder = mock(RepositoryFile.class);
RepositoryFileTree mockRepositoryTree = mock(RepositoryFileTree.class);
String testId = "TEST_ID";
String visibleFolderId = testId + "2";
when(objectId.getId()).thenReturn(testId);
when(mockRepo.getFileById(testId)).thenReturn(mockEtcFolder);
when(mockRepo.getFile(ClientRepositoryPaths.getEtcFolderPath())).thenReturn(mockEtcFolder);
when(mockRepo.getFileById(visibleFolderId)).thenReturn(mockFolderVisible);
when(mockEtcFolder.getPath()).thenReturn("/etc");
when(mockEtcFolder.getName()).thenReturn("etc");
when(mockEtcFolder.isFolder()).thenReturn(true);
when(mockEtcFolder.getId()).thenReturn(testId);
when(mockFolderVisible.getPath()).thenReturn("/visible");
when(mockFolderVisible.getName()).thenReturn("visible");
when(mockFolderVisible.isFolder()).thenReturn(true);
when(mockFolderVisible.getId()).thenReturn(visibleFolderId);
when(mockRepositoryTree.getFile()).thenReturn(mockRootFolder);
when(mockRootFolder.getId()).thenReturn("/");
when(mockRootFolder.getPath()).thenReturn("/");
List<RepositoryFile> rootChildren = new ArrayList<>(Arrays.asList(mockEtcFolder, mockFolderVisible));
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);
RepositoryFileTree mockEtcFolderTree = mock(RepositoryFileTree.class);
when(mockEtcFolderTree.getFile()).thenReturn(mockEtcFolder);
RepositoryFileTree mockFolderVisibleTree = mock(RepositoryFileTree.class);
when(mockFolderVisibleTree.getFile()).thenReturn(mockFolderVisible);
when(repositoryFileTree.getChildren()).thenReturn(new ArrayList<RepositoryFileTree>(Arrays.asList(mockEtcFolderTree, mockFolderVisibleTree)));
purRepository.connect("TEST_USER", "TEST_PASSWORD");
int children = purRepository.getRootDir().getNrSubdirectories();
assertThat(children, equalTo(1));
}
use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-kettle by pentaho.
the class PurRepositoryConnector method connect.
public synchronized RepositoryConnectResult connect(final String username, final String password) throws KettleException {
if (serviceManager != null) {
disconnect();
}
serviceManager = new WebServiceManager(repositoryMeta.getRepositoryLocation().getUrl(), username);
RepositoryServiceRegistry purRepositoryServiceRegistry = new RepositoryServiceRegistry();
IUser user1 = new EEUserInfo();
final String decryptedPassword = Encr.decryptPasswordOptionallyEncrypted(password);
final RepositoryConnectResult result = new RepositoryConnectResult(purRepositoryServiceRegistry);
try {
/*
* Three scenarios: 1. Connect in process: username fetched using PentahoSessionHolder; no authentication occurs
* 2. Connect externally with trust: username specified is assumed authenticated if IP of calling code is trusted
* 3. Connect externally: authentication occurs normally (i.e. password is checked)
*/
user1.setLogin(username);
user1.setPassword(decryptedPassword);
user1.setName(username);
result.setUser(user1);
// We need to have the application context and the session available in order for us to skip authentication
if (PentahoSystem.getApplicationContext() != null && PentahoSessionHolder.getSession() != null && PentahoSessionHolder.getSession().isAuthenticated()) {
if (inProcess()) {
// connect to the IUnifiedRepository through PentahoSystem
// this assumes we're running in a BI Platform
result.setUnifiedRepository(PentahoSystem.get(IUnifiedRepository.class));
if (result.getUnifiedRepository() != null) {
if (log.isDebug()) {
log.logDebug(BaseMessages.getString(PKG, "PurRepositoryConnector.ConnectInProgress.Begin"));
}
String name = PentahoSessionHolder.getSession().getName();
user1 = new EEUserInfo();
user1.setLogin(name);
user1.setName(name);
user1.setPassword(decryptedPassword);
result.setUser(user1);
result.setSuccess(true);
if (log.isDebug()) {
log.logDebug(BaseMessages.getString(PKG, "PurRepositoryConnector.ConnectInProgress", name, result.getUnifiedRepository()));
}
// what about security provider?
return result;
}
}
}
ExecutorService executor = getExecutor();
Future<Boolean> authorizationWebserviceFuture = executor.submit(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
// IRoleSupportSecurityManager depends RepositorySecurityManager to be present
if (log.isBasic()) {
log.logBasic(BaseMessages.getString(PKG, "PurRepositoryConnector.CreateServiceProvider.Start"));
}
result.setSecurityProvider(new AbsSecurityProvider(purRepository, repositoryMeta, result.getUser(), serviceManager));
if (log.isBasic()) {
// $NON-NLS-1$
log.logBasic(BaseMessages.getString(PKG, "PurRepositoryConnector.CreateServiceProvider.End"));
}
// need to added them to the service list
if (allowedActionsContains((AbsSecurityProvider) result.getSecurityProvider(), IAbsSecurityProvider.ADMINISTER_SECURITY_ACTION)) {
result.setSecurityManager(new AbsSecurityManager(purRepository, repositoryMeta, result.getUser(), serviceManager));
// Set the reference of the security manager to security provider for user role list change event
((PurRepositorySecurityProvider) result.getSecurityProvider()).setUserRoleDelegate(((PurRepositorySecurityManager) result.getSecurityManager()).getUserRoleDelegate());
return true;
}
return false;
}
});
Future<WebServiceException> repoWebServiceFuture = executor.submit(new Callable<WebServiceException>() {
@Override
public WebServiceException call() throws Exception {
try {
IUnifiedRepositoryJaxwsWebService repoWebService = null;
if (log.isBasic()) {
// $NON-NLS-1$
log.logBasic(BaseMessages.getString(PKG, "PurRepositoryConnector.CreateRepositoryWebService.Start"));
}
repoWebService = // $NON-NLS-1$
serviceManager.createService(username, decryptedPassword, IUnifiedRepositoryJaxwsWebService.class);
if (log.isBasic()) {
// $NON-NLS-1$
log.logBasic(BaseMessages.getString(PKG, "PurRepositoryConnector.CreateRepositoryWebService.End"));
}
if (log.isBasic()) {
// $NON-NLS-1$
log.logBasic(BaseMessages.getString(PKG, "PurRepositoryConnector.CreateUnifiedRepositoryToWebServiceAdapter.Start"));
}
result.setUnifiedRepository(new UnifiedRepositoryToWebServiceAdapter(repoWebService));
} catch (WebServiceException wse) {
return wse;
}
return null;
}
});
Future<Exception> syncWebserviceFuture = executor.submit(new Callable<Exception>() {
@Override
public Exception call() throws Exception {
try {
if (log.isBasic()) {
log.logBasic(BaseMessages.getString(PKG, "PurRepositoryConnector.CreateRepositorySyncWebService.Start"));
}
IRepositorySyncWebService syncWebService = // $NON-NLS-1$
serviceManager.createService(username, decryptedPassword, IRepositorySyncWebService.class);
if (log.isBasic()) {
// $NON-NLS-1$
log.logBasic(BaseMessages.getString(PKG, "PurRepositoryConnector.CreateRepositorySyncWebService.Sync"));
}
syncWebService.sync(repositoryMeta.getName(), repositoryMeta.getRepositoryLocation().getUrl());
} catch (RepositorySyncException e) {
log.logError(e.getMessage(), e);
// this message will be presented to the user in spoon
result.setConnectMessage(e.getMessage());
return null;
} catch (ClientTransportException e) {
// caused by authentication errors, etc
return e;
} catch (WebServiceException e) {
// if we can speak to the repository okay but not the sync service, assume we're talking to a BA Server
log.logError(e.getMessage(), e);
return new Exception(BaseMessages.getString(PKG, "PurRepository.BAServerLogin.Message"), e);
}
return null;
}
});
Future<String> sessionServiceFuture = executor.submit(new Callable<String>() {
@Override
public String call() throws Exception {
try {
if (log.isBasic()) {
log.logBasic(BaseMessages.getString(PKG, "PurRepositoryConnector.SessionService.Start"));
}
CredentialsProvider provider = new BasicCredentialsProvider();
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password);
provider.setCredentials(AuthScope.ANY, credentials);
HttpClient client = HttpClientBuilder.create().setDefaultCredentialsProvider(provider).build();
HttpResponse response = client.execute(new HttpGet(repositoryMeta.getRepositoryLocation().getUrl() + "/api/session/userName"));
if (log.isBasic()) {
// $NON-NLS-1$
log.logBasic(BaseMessages.getString(PKG, "PurRepositoryConnector.SessionService.Sync"));
}
return EntityUtils.toString(response.getEntity());
} catch (Exception e) {
if (log.isError()) {
log.logError(BaseMessages.getString(PKG, "PurRepositoryConnector.Error.EnableToGetUser"), e);
}
return null;
}
}
});
WebServiceException repoException = repoWebServiceFuture.get();
if (repoException != null) {
log.logError(repoException.getMessage());
throw new Exception(BaseMessages.getString(PKG, "PurRepository.FailedLogin.Message"), repoException);
}
Exception syncException = syncWebserviceFuture.get();
if (syncException != null) {
throw syncException;
}
Boolean isAdmin = authorizationWebserviceFuture.get();
result.getUser().setAdmin(isAdmin);
String userName = sessionServiceFuture.get();
if (userName != null) {
result.getUser().setLogin(userName);
}
if (log.isBasic()) {
log.logBasic(BaseMessages.getString(PKG, "PurRepositoryConnector.RegisterSecurityProvider.Start"));
}
purRepositoryServiceRegistry.registerService(RepositorySecurityProvider.class, result.getSecurityProvider());
purRepositoryServiceRegistry.registerService(IAbsSecurityProvider.class, result.getSecurityProvider());
if (isAdmin) {
purRepositoryServiceRegistry.registerService(RepositorySecurityManager.class, result.getSecurityManager());
purRepositoryServiceRegistry.registerService(IRoleSupportSecurityManager.class, result.getSecurityManager());
purRepositoryServiceRegistry.registerService(IAbsSecurityManager.class, result.getSecurityManager());
}
purRepositoryServiceRegistry.registerService(PurRepositoryRestService.PurRepositoryPluginApiRevision.class, serviceManager.createService(username, decryptedPassword, PurRepositoryRestService.PurRepositoryPluginApiRevision.class));
purRepositoryServiceRegistry.registerService(IRevisionService.class, new UnifiedRepositoryRevisionService(result.getUnifiedRepository(), rootRef));
purRepositoryServiceRegistry.registerService(IAclService.class, new UnifiedRepositoryConnectionAclService(result.getUnifiedRepository()));
purRepositoryServiceRegistry.registerService(IConnectionAclService.class, new UnifiedRepositoryConnectionAclService(result.getUnifiedRepository()));
purRepositoryServiceRegistry.registerService(ITrashService.class, new UnifiedRepositoryTrashService(result.getUnifiedRepository(), rootRef));
purRepositoryServiceRegistry.registerService(ILockService.class, new UnifiedRepositoryLockService(result.getUnifiedRepository()));
if (log.isBasic()) {
log.logBasic(BaseMessages.getString(PKG, "PurRepositoryConnector.RepositoryServicesRegistered.End"));
}
result.setSuccess(true);
} catch (NullPointerException npe) {
result.setSuccess(false);
throw new KettleException(BaseMessages.getString(PKG, "PurRepository.LoginException.Message"));
} catch (Throwable e) {
result.setSuccess(false);
serviceManager.close();
throw new KettleException(e);
}
return result;
}
use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-metaverse by pentaho.
the class RepositoryLocatorTest method setUp.
@Before
public void setUp() throws Exception {
RepositoryLocator loc = new RepositoryLocator() {
@Override
protected IUnifiedRepository getUnifiedRepository(IPentahoSession session) throws Exception {
return null;
}
@Override
protected Object getContents(RepositoryFile locatedItem) throws Exception {
return null;
}
/**
* Returns the locator node for this locator. The locator node is the node in the metaverse
* that represents this locator. It is used to create a link from this locator to the documents
* that are found by/within it.
*
* @return The locator node in the metaverse
*/
@Override
public IMetaverseNode getLocatorNode() {
return new MetaverseNode(mock(Vertex.class));
}
@Override
public URI getRootUri() {
return null;
}
};
loc.setMetaverseBuilder(metaverseBuilder);
baseLocator = spy(loc);
when(baseLocator.getMetaverseBuilder()).thenReturn(metaverseBuilder);
when(metaverseBuilder.getMetaverseObjectFactory()).thenReturn(metaverseObjectFactory);
when(metaverseObjectFactory.createDocumentObject()).thenReturn(new MetaverseDocument());
}
Aggregations