use of org.talend.core.model.properties.FolderItem in project tdi-studio-se by Talend.
the class JobScriptsExportWizardPage method getProcessItem.
protected ProcessItem getProcessItem() {
if ((processItem == null) && (nodes != null) && (nodes.length >= 1)) {
IRepositoryViewObject repositoryObject = nodes[0].getObject();
// add for bug TDI-20132
List<IRepositoryNode> nodesChildren = nodes[0].getChildren();
IRepositoryViewObject childObject = null;
if ((nodesChildren != null) && (nodesChildren.size() >= 1)) {
childObject = nodesChildren.get(0).getObject();
}
if (repositoryObject == null && childObject != null && childObject.getProperty().getItem() instanceof ProcessItem) {
processItem = (ProcessItem) childObject.getProperty().getItem();
}
if (repositoryObject != null && repositoryObject.getProperty().getItem() instanceof ProcessItem) {
processItem = (ProcessItem) repositoryObject.getProperty().getItem();
} else if (repositoryObject != null && repositoryObject.getProperty().getItem() instanceof FolderItem) {
processItem = getProcessItemIfSelectFolder(repositoryObject);
}
}
return processItem;
}
use of org.talend.core.model.properties.FolderItem in project tdi-studio-se by Talend.
the class RepositoryTypeProcessor method selectRepositoryNode.
@Override
protected boolean selectRepositoryNode(Viewer viewer, RepositoryNode parentNode, RepositoryNode node) {
final String repositoryType = getRepositoryType();
if (node == null) {
return false;
}
if (node.getContentType() == ERepositoryObjectType.REFERENCED_PROJECTS) {
return true;
}
// for sub folders
if (node.getType() == ENodeType.STABLE_SYSTEM_FOLDER) {
return false;
}
// for Db Connections
if (node.getType() == ENodeType.SYSTEM_FOLDER) {
return true;
}
// }
IRepositoryViewObject object = node.getObject();
if (object == null || object.getProperty().getItem() == null) {
return false;
}
if (object instanceof MetadataTable) {
return false;
}
Item item = object.getProperty().getItem();
if (item instanceof FolderItem) {
return true;
}
if (item instanceof ConnectionItem) {
ConnectionItem connectionItem = (ConnectionItem) item;
Connection connection = connectionItem.getConnection();
// tAdvancedFileOutputXML
if (repositoryType != null && repositoryType.equals(ERepositoryCategoryType.XMLOUTPUT.getName())) {
if (connection instanceof XmlFileConnection && ((XmlFileConnection) connection).isInputModel()) {
return false;
}
}
if (repositoryType.startsWith(ERepositoryCategoryType.DATABASE.getName())) {
//$NON-NLS-1$
String currentDbType = (String) RepositoryToComponentProperty.getValue(connection, "TYPE", null);
if (repositoryType.contains(":")) {
// database //$NON-NLS-1$
// is
// specified
// //$NON-NLS-1$
//$NON-NLS-1$
String neededDbType = repositoryType.substring(repositoryType.indexOf(":") + 1);
if (hidenTypeSelection) {
return true;
}
if (!MetadataTalendType.sameDBProductType(neededDbType, currentDbType)) {
return false;
}
}
}
}
if (repositoryType.startsWith(ERepositoryCategoryType.HEADERFOOTER.getName())) {
if (item instanceof HeaderFooterConnectionItem) {
HeaderFooterConnectionItem connectionItem = (HeaderFooterConnectionItem) item;
HeaderFooterConnection connection = (HeaderFooterConnection) connectionItem.getConnection();
boolean isHeader = connection.isIsHeader();
if ((isHeader && isHeaderButton) || (!isHeader && !isHeaderButton)) {
return true;
} else {
return false;
}
}
}
return true;
}
use of org.talend.core.model.properties.FolderItem in project tdi-studio-se by Talend.
the class ValidationRuleTypeProcessor method selectRepositoryNode.
@Override
protected boolean selectRepositoryNode(Viewer viewer, RepositoryNode parentNode, RepositoryNode node) {
if (node.getContentType() == ERepositoryObjectType.REFERENCED_PROJECTS) {
return true;
}
ProjectManager pManager = ProjectManager.getInstance();
if (!pManager.isInCurrentMainProject(node)) {
if (node.getType() == ENodeType.STABLE_SYSTEM_FOLDER) {
return false;
}
if (node.getType() == ENodeType.SYSTEM_FOLDER) {
return true;
}
}
if (node.getType() == ENodeType.SYSTEM_FOLDER) {
return true;
}
if (node.getObject() == null || node.getObject().getProperty().getItem() == null) {
return false;
}
if (node.getObject() instanceof MetadataTable) {
return false;
}
Item item = node.getObject().getProperty().getItem();
if (item instanceof FolderItem) {
return true;
}
if (node.getObjectType() == getType()) {
return true;
}
return false;
}
use of org.talend.core.model.properties.FolderItem in project tdi-studio-se by Talend.
the class TosTokenCollector method collectJobDetails.
/**
* DOC nrousseau Comment method "collectJobDetails".
*
* @param all
* @param jobDetails
* @throws JSONException
*/
private void collectJobDetails(List<IRepositoryViewObject> allRvo, JSONObject jobDetails) throws JSONException {
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
IWorkbenchWindow ww = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IEditorReference[] reference = new IEditorReference[0];
if (ww != null) {
IWorkbenchPage page = ww.getActivePage();
reference = page.getEditorReferences();
}
List<IProcess2> processes = RepositoryPlugin.getDefault().getDesignerCoreService().getOpenedProcess(reference);
Set<String> idsOpened = new HashSet<String>();
for (IProcess2 process : processes) {
idsOpened.add(process.getId());
}
JSONArray components = new JSONArray();
int contextVarsNum = 0;
int nbComponentsUsed = 0;
for (IRepositoryViewObject rvo : allRvo) {
Item item = rvo.getProperty().getItem();
if (item instanceof ProcessItem) {
ProcessType processType = ((ProcessItem) item).getProcess();
for (NodeType node : (List<NodeType>) processType.getNode()) {
JSONObject component_names = null;
String componentName = node.getComponentName();
int nbComp = 0;
for (int i = 0; i < components.length(); i++) {
JSONObject temp = components.getJSONObject(i);
if (temp.get("component_name").equals(componentName)) {
//$NON-NLS-1$
//$NON-NLS-1$
nbComp = temp.getInt("count");
component_names = temp;
break;
}
}
if (component_names == null) {
component_names = new JSONObject();
components.put(component_names);
}
component_names.put("component_name", componentName);
component_names.put("count", nbComp + 1);
nbComponentsUsed++;
}
// context variable per job
EList contexts = processType.getContext();
if (contexts.size() > 0) {
ContextType contextType = (ContextType) contexts.get(0);
contextVarsNum += contextType.getContextParameter().size();
}
}
if (factory.getStatus(item) != ERepositoryStatus.LOCK_BY_USER && !idsOpened.contains(item.getProperty().getId())) {
// job is not locked and not opened by editor, so we can unload.
if (item.getParent() instanceof FolderItem) {
((FolderItem) item.getParent()).getChildren().remove(item);
item.setParent(null);
}
item.eResource().unload();
}
}
jobDetails.put("components", components);
jobDetails.put("nb.contextVars", contextVarsNum);
jobDetails.put("nb.components", nbComponentsUsed);
}
use of org.talend.core.model.properties.FolderItem in project tmdm-studio-se by Talend.
the class RemoveFromRepositoryActionTest method doRunTest.
@Test
public void doRunTest() throws Exception {
PowerMockito.mockStatic(MDMWorbenchPlugin.class);
when(MDMWorbenchPlugin.getImageDescriptor(anyString())).thenReturn(mock(ImageDescriptor.class));
RemoveFromRepositoryAction removeAction = new RemoveFromRepositoryAction();
RemoveFromRepositoryAction removeActionM = PowerMockito.spy(removeAction);
CommonViewer commonViewerM = mock(CommonViewer.class);
// $NON-NLS-1$
Whitebox.setInternalState(removeActionM, "commonViewer", commonViewerM);
// $NON-NLS-1$
PowerMockito.doReturn(true).when(removeActionM, "confirm", 2);
// $NON-NLS-1$
PowerMockito.doNothing().when(removeActionM, "warn");
// mock a mdm repositoryViewObject
IRepositoryViewObject objectRVO = mock(IRepositoryViewObject.class);
MDMServerObjectItem mdmItemM = mock(MDMServerObjectItem.class);
Property propertyM = mock(Property.class);
when(objectRVO.getProperty()).thenReturn(propertyM);
when(propertyM.getItem()).thenReturn(mdmItemM);
// mock a FolderRepositoryObject
FolderRepositoryObject folderRO = mock(FolderRepositoryObject.class);
Property foldePropertyM = mock(Property.class);
ContainerItem containerItem = mock(ContainerItem.class);
when(folderRO.getProperty()).thenReturn(foldePropertyM);
when(foldePropertyM.getItem()).thenReturn(containerItem);
ItemState itemState = mock(ItemState.class);
when(containerItem.getState()).thenReturn(itemState);
// $NON-NLS-1$
when(itemState.getPath()).thenReturn("");
PowerMockito.mockStatic(RepositoryNodeProviderRegistryReader.class);
RepositoryNodeProviderRegistryReader reader = mock(RepositoryNodeProviderRegistryReader.class);
PowerMockito.when(RepositoryNodeProviderRegistryReader.getInstance()).thenReturn(reader);
ERepositoryObjectType typeM = ERepositoryObjectType.PROCESS;
when(containerItem.getRepObjType()).thenReturn(typeM);
MDMServerObject mdmServerObjectM = mock(MDMServerObject.class);
when(mdmItemM.getMDMServerObject()).thenReturn(mdmServerObjectM);
Shell shellM = mock(Shell.class);
Control controlM = mock(Control.class);
when(commonViewerM.getControl()).thenReturn(controlM);
when(controlM.getShell()).thenReturn(shellM);
List<Object> selectedObjects = new ArrayList<Object>();
selectedObjects.add(objectRVO);
selectedObjects.add(folderRO);
when(removeActionM.getSelectedObject()).thenReturn(selectedObjects);
// $NON-NLS-1$
Whitebox.setInternalState(removeActionM, "lockedObjs", Collections.EMPTY_LIST);
PowerMockito.mockStatic(MessageDialog.class);
when(MessageDialog.openConfirm((Shell) anyObject(), anyString(), anyString())).thenReturn(true);
PowerMockito.mockStatic(RepositoryResourceUtil.class);
when(RepositoryResourceUtil.isOpenedInEditor((IRepositoryViewObject) anyObject())).thenReturn(null);
when(RepositoryResourceUtil.hasContainerItem(anyObject(), eq(FolderType.FOLDER_LITERAL))).thenReturn(true);
PowerMockito.mockStatic(ContainerCacheService.class);
FolderItem folderItemM = mock(FolderItem.class);
when(repositoryFactory.getFolderItem(eq(projectM), eq(typeM), (IPath) anyObject())).thenReturn(folderItemM);
when(folderItemM.getState()).thenReturn(itemState);
removeActionM.doRun();
}
Aggregations