use of org.pentaho.di.repository.RepositoryDirectoryInterface in project pentaho-kettle by pentaho.
the class RepositoryBrowserController method loadFolders.
public RepositoryDirectory loadFolders(String path) {
RepositoryDirectoryInterface repositoryDirectoryInterface = findDirectory(path);
RepositoryDirectory repositoryDirectory = RepositoryDirectory.build(null, repositoryDirectoryInterface);
populateFolders(repositoryDirectory, repositoryDirectoryInterface);
return repositoryDirectory;
}
use of org.pentaho.di.repository.RepositoryDirectoryInterface in project pentaho-kettle by pentaho.
the class RepositoryBrowserController method create.
public RepositoryDirectory create(String parent, String name) {
if (hasDupeFolder(parent, name)) {
return null;
}
try {
RepositoryDirectoryInterface repositoryDirectoryInterface = getRepository().createRepositoryDirectory(findDirectory(parent), name);
RepositoryDirectory repositoryDirectory = new RepositoryDirectory();
repositoryDirectory.setName(repositoryDirectoryInterface.getName());
repositoryDirectory.setPath(repositoryDirectoryInterface.getPath());
repositoryDirectory.setObjectId(repositoryDirectoryInterface.getObjectId());
repositoryDirectory.setParent(parent);
return repositoryDirectory;
} catch (Exception e) {
return null;
}
}
use of org.pentaho.di.repository.RepositoryDirectoryInterface in project pentaho-kettle by pentaho.
the class RepositoryBrowserController method remove.
public boolean remove(String id, String name, String path, String type) throws KettleException {
try {
switch(type) {
case JOB:
if (isJobOpened(id, path, name)) {
throw new KettleJobException();
}
getRepository().deleteJob(() -> id);
break;
case TRANSFORMATION:
if (isTransOpened(id, path, name)) {
throw new KettleTransException();
}
getRepository().deleteTransformation(() -> id);
break;
case FOLDER:
isFileOpenedInFolder(path);
removeRecentsUsingPath(path);
RepositoryDirectoryInterface repositoryDirectoryInterface = findDirectory(path);
if (getRepository() instanceof RepositoryExtended) {
((RepositoryExtended) getRepository()).deleteRepositoryDirectory(repositoryDirectoryInterface, true);
} else {
getRepository().deleteRepositoryDirectory(repositoryDirectoryInterface);
}
break;
}
return true;
} catch (KettleTransException | KettleJobException ke) {
throw ke;
} catch (Exception e) {
return false;
}
}
use of org.pentaho.di.repository.RepositoryDirectoryInterface 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;
}
use of org.pentaho.di.repository.RepositoryDirectoryInterface in project pentaho-kettle by pentaho.
the class RunTransServletTest method testRunTransServletCheckParameter.
@Test
public void testRunTransServletCheckParameter() throws Exception {
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
Mockito.when(request.getParameter("trans")).thenReturn("home/test.rtr");
StringWriter out = new StringWriter();
PrintWriter printWriter = new PrintWriter(out);
Mockito.when(request.getContextPath()).thenReturn(RunTransServlet.CONTEXT_PATH);
Mockito.when(response.getWriter()).thenReturn(printWriter);
TransformationMap mockTransformationMap = Mockito.mock(TransformationMap.class);
SlaveServerConfig slaveServerConfig = Mockito.mock(SlaveServerConfig.class);
Mockito.when(mockTransformationMap.getSlaveServerConfig()).thenReturn(slaveServerConfig);
Repository repository = Mockito.mock(Repository.class);
Mockito.when(slaveServerConfig.getRepository()).thenReturn(repository);
RepositoryDirectoryInterface repositoryDirectoryInterface = Mockito.mock(RepositoryDirectoryInterface.class);
Mockito.when(repository.loadRepositoryDirectoryTree()).thenReturn(repositoryDirectoryInterface);
Mockito.when(repositoryDirectoryInterface.findDirectory(Mockito.anyString())).thenReturn(repositoryDirectoryInterface);
TransMeta transMeta = Mockito.mock(TransMeta.class);
Mockito.when(repository.loadTransformation(Mockito.any(), Mockito.any())).thenReturn(transMeta);
String testParameter = "testParameter";
Mockito.when(transMeta.listVariables()).thenReturn(new String[] { testParameter });
Mockito.when(transMeta.getVariable(Mockito.anyString())).thenReturn("default value");
Mockito.when(transMeta.listParameters()).thenReturn(new String[] { testParameter });
Mockito.when(request.getParameterNames()).thenReturn(new StringTokenizer(testParameter));
String testValue = "testValue";
Mockito.when(request.getParameterValues(testParameter)).thenReturn(new String[] { testValue });
RunTransServlet runTransServlet = Mockito.mock(RunTransServlet.class);
Mockito.doCallRealMethod().when(runTransServlet).doGet(Mockito.anyObject(), Mockito.anyObject());
Trans trans = new Trans(transMeta, new SimpleLoggingObject(RunTransServlet.CONTEXT_PATH, LoggingObjectType.CARTE, null));
Mockito.when(runTransServlet.createTrans(Mockito.anyObject(), Mockito.anyObject())).thenReturn(trans);
Mockito.when(transMeta.getParameterValue(Mockito.eq(testParameter))).thenReturn(testValue);
runTransServlet.log = new LogChannel("RunTransServlet");
runTransServlet.transformationMap = mockTransformationMap;
runTransServlet.doGet(request, response);
Assert.assertEquals(testValue, trans.getParameterValue(testParameter));
}
Aggregations