use of org.talend.core.model.properties.JobletProcessItem in project tdi-studio-se by Talend.
the class ComponentChooseDialog method createNewComponent.
public void createNewComponent(DropTargetEvent event1) {
boolean quickCreateInput = event1.detail == DND.DROP_LINK;
boolean quickCreateOutput = event1.detail == DND.DROP_COPY;
Iterator iterator = getSelection().iterator();
List<TempStore> list = new ArrayList<TempStore>();
List<IComponent> components = new ArrayList<IComponent>();
while (iterator.hasNext()) {
Object obj = iterator.next();
if (obj instanceof RepositoryNode) {
RepositoryNode sourceNode = (RepositoryNode) obj;
if (equalsJobInCurrentEditor(sourceNode)) {
continue;
}
Item item = sourceNode.getObject().getProperty().getItem();
if (GlobalServiceRegister.getDefault().isServiceRegistered(ITestContainerProviderService.class)) {
ITestContainerProviderService testContainerService = (ITestContainerProviderService) GlobalServiceRegister.getDefault().getService(ITestContainerProviderService.class);
if (testContainerService != null && testContainerService.isTestContainerItem(item)) {
continue;
}
}
ERepositoryObjectType type = sourceNode.getObjectType();
if (!(item instanceof ConnectionItem) && !(item instanceof ProcessItem) && !(item instanceof JobletProcessItem) && !(item instanceof RulesItem) && !(item instanceof LinkRulesItem)) {
// RulesItem
return;
}
{
/**
* Remove this limitation for feature: TDI-32362, I think it should be ok, don't know why adding
* this limitation to forbid to d&d salseforce connection, I keep those code in case this behavior
* will cause some bugs when d&d salseforce connection, then maybe need to review
*/
// if (item instanceof SalesforceSchemaConnectionItem && type ==
// ERepositoryObjectType.METADATA_SALESFORCE_SCHEMA) {
// return;
// }
}
TempStore store = new TempStore();
store.seletetedNode = sourceNode;
getAppropriateComponent(item, quickCreateInput, quickCreateOutput, store, type);
if (store.component != null) {
list.add(store);
} else {
MessageDialog.openInformation(editor.getEditorSite().getShell(), //$NON-NLS-1$
Messages.getString("TalendEditorDropTargetListener.dngsupportdialog.title"), //$NON-NLS-1$
Messages.getString("TalendEditorDropTargetListener.dngsupportdialog.content"));
}
}
org.eclipse.swt.graphics.Point swtLocation = new org.eclipse.swt.graphics.Point(event1.x, event1.y);
Canvas canvas = (Canvas) editor.getViewer().getControl();
/*
* translate to Canvas coordinate
*/
swtLocation = canvas.toControl(swtLocation);
org.eclipse.swt.graphics.Point size = canvas.getSize();
/*
* translate to Viewport coordinate with zoom
*/
org.eclipse.draw2d.geometry.Point draw2dPosition = new org.eclipse.draw2d.geometry.Point(swtLocation.x, swtLocation.y);
/*
* calcule the view port position. Take into acounte the scroll position
*/
ProcessPart part = (ProcessPart) editor.getViewer().getRootEditPart().getRoot().getChildren().get(0);
IFigure targetFigure = part.getFigure();
translateAbsolateToRelative(targetFigure, draw2dPosition);
//$NON-NLS-1$
String lastUniqname = "";
// creates every node
for (TempStore store : list) {
RepositoryNode selectedNode = store.seletetedNode;
IComponent element = store.component;
if (!components.contains(element)) {
components.add(element);
}
Node node = new Node(element);
// for bug4564(metadata label format)
// IPreferenceStore preferenceStore = DesignerPlugin.getDefault().getPreferenceStore();
// if (preferenceStore.getBoolean(TalendDesignerPrefConstants.USE_REPOSITORY_NAME)) {
// node.setPropertyValue(EParameterName.LABEL.getName(), selectedNode.getObject().getLabel());
// }
IPreferenceStore preferenceStore = DesignerPlugin.getDefault().getPreferenceStore();
if (preferenceStore.getBoolean(TalendDesignerPrefConstants.USE_REPOSITORY_NAME)) {
String LabelValue = null;
RepositoryNode repositoryNode = null;
repositoryNode = (RepositoryNode) getSelection().getFirstElement();
// dnd a table
IElementParameter dbTableParam = node.getElementParameterFromField(EParameterFieldType.DBTABLE);
boolean hasDbTableField = dbTableParam != null;
if (repositoryNode.getObjectType() == ERepositoryObjectType.METADATA_CON_TABLE && repositoryNode.getObject() != null && repositoryNode.getObject().getProperty().getItem() instanceof DatabaseConnectionItem && hasDbTableField) {
LabelValue = DesignerUtilities.getParameterVar(dbTableParam.getName());
} else if (repositoryNode.getObjectType() == ERepositoryObjectType.PROCESS || repositoryNode.getObjectType() == ERepositoryObjectType.PROCESS_MR || repositoryNode.getObjectType() == ERepositoryObjectType.PROCESS_STORM) {
// dnd a job
LabelValue = DesignerUtilities.getParameterVar(EParameterName.PROCESS);
} else if (repositoryNode.getObjectType() == ERepositoryObjectType.JOBLET || repositoryNode.getObjectType() == ERepositoryObjectType.SPARK_JOBLET || repositoryNode.getObjectType() == ERepositoryObjectType.SPARK_STREAMING_JOBLET) {
LabelValue = element.getName();
} else if (CorePlugin.getDefault().getDesignerCoreService().getPreferenceStore(TalendDesignerPrefConstants.DEFAULT_LABEL).equals(node.getPropertyValue(EParameterName.LABEL.getName()))) {
// dnd a default
LabelValue = selectedNode.getObject().getLabel();
}
if (LabelValue != null) {
node.setPropertyValue(EParameterName.LABEL.getName(), LabelValue);
}
}
processSpecificDBTypeIfSameProduct(store.componentName, node);
NodeContainer nc = ((Process) node.getProcess()).loadNodeContainer(node, false);
;
// create component on link
boolean executed = false;
if (getSelection().size() == 1 && getTargetEditPart() instanceof SubjobContainerPart) {
executed = createComponentOnLink(node, draw2dPosition);
}
if (!executed) {
// create the node on the design sheet
execCommandStack(new CreateNodeContainerCommand((Process) editor.getProcess(), nc, draw2dPosition));
}
// initialize the propertiesView
CompoundCommand cc = new CompoundCommand();
createRefreshingPropertiesCommand(cc, selectedNode, node);
execCommandStack(cc);
// for (Command command : commands) {
// }
propaHadoopCfgChanges(selectedNode);
draw2dPosition = draw2dPosition.getCopy();
draw2dPosition.x += TalendEditor.GRID_SIZE;
draw2dPosition.y += TalendEditor.GRID_SIZE;
node.checkNode();
lastUniqname = node.getUniqueName();
}
// setselecte(part, lastUniqname);
}
// Shell shell = Display.getCurrent().getActiveShell();
// ModulesInstallerUtil.installModules(new Shell(shell), components);
}
use of org.talend.core.model.properties.JobletProcessItem in project tdi-studio-se by Talend.
the class HTMLDocGenerator method generateContextInfo.
/**
* DOC YeXiaowei Comment method "generateContextInfo".
*
* @return
*/
private void generateContextInfo(final Item item, final Element element) {
EList contexts = null;
if (item instanceof ProcessItem) {
contexts = ((ProcessItem) item).getProcess().getContext();
} else if (item instanceof JobletProcessItem) {
contexts = ((JobletProcessItem) item).getJobletProcess().getContext();
}
if (contexts == null || contexts.isEmpty()) {
return;
}
// Context root //$NON-NLS-1$
Element contextListElement = DocumentHelper.createElement("contextList");
for (int i = 0, n = contexts.size(); i < n; i++) {
// export single context infomation
//$NON-NLS-1$
Element contextElement = DocumentHelper.createElement("context");
ContextType context = (ContextType) contexts.get(i);
// Attributes
//$NON-NLS-1$
contextElement.addAttribute("name", HTMLDocUtils.checkString(context.getName()));
IProxyRepositoryFactory repositoryFactory = CorePlugin.getDefault().getProxyRepositoryFactory();
// Context parameters as children
EList params = context.getContextParameter();
if (params != null && !params.isEmpty()) {
for (int j = 0, k = params.size(); j < k; j++) {
/*
* <contextParameter comment="Give server name" name="server" prompt="Default Server "
* promptNeeded="false" repositoryContextId="_crJMkCCQEd2Oweh7yRMWjQ" type=""
* value="'192.168.0.109'"/>
*/
ContextParameterType param = (ContextParameterType) params.get(j);
//$NON-NLS-1$
Element contextParamElement = DocumentHelper.createElement("contextParameter");
//$NON-NLS-1$
contextParamElement.addAttribute("name", HTMLDocUtils.checkString(param.getName()));
//$NON-NLS-1$
contextParamElement.addAttribute("prompt", HTMLDocUtils.checkString(param.getPrompt()));
contextParamElement.addAttribute("promptNeeded", HTMLDocUtils.checkString(Boolean.toString(//$NON-NLS-1$
param.isPromptNeeded())));
//$NON-NLS-1$
contextParamElement.addAttribute("type", HTMLDocUtils.checkString(param.getType()));
//$NON-NLS-1$
contextParamElement.addAttribute("value", ParameterValueUtil.getValue4Doc(param));
// replace repository id with context label
if (param.getRepositoryContextId() != null) {
ContextItem contextItem = ContextUtils.getContextItemById2(param.getRepositoryContextId());
if (contextItem != null) {
// bug 5978: repository link to context item might be lost.
String label = contextItem.getProperty().getLabel();
//$NON-NLS-1$
contextParamElement.addAttribute("source", HTMLDocUtils.checkString(label));
}
}
contextElement.add(contextParamElement);
}
}
contextListElement.add(contextElement);
}
element.add(contextListElement);
}
use of org.talend.core.model.properties.JobletProcessItem in project tdi-studio-se by Talend.
the class HTMLDocGenerator method handleXMLFile.
/**
* Generates the xml file base on an instance of <code>ExportFileResource</code> and the temporary folder path.
*
* @param resource
* @param tempFolderPath
* @param version
*/
private void handleXMLFile(ExportFileResource resource, String tempFolderPath, String... version) throws Exception {
Item item = resource.getItem();
// Check if generate Job Extra / Stats&Logs Setting Info
if (item instanceof ProcessItem) {
if (GlobalServiceRegister.getDefault().isServiceRegistered(IMRProcessService.class)) {
IMRProcessService mrProcessService = (IMRProcessService) GlobalServiceRegister.getDefault().getService(IMRProcessService.class);
generateExtraSetting = !mrProcessService.isMapReduceItem(item);
generateStatsLogsSetting = generateExtraSetting;
} else if (isRouteProcess(item)) {
generateStatsLogsSetting = generateExtraSetting = !isRouteProcess(item);
}
} else if (item instanceof JobletProcessItem) {
generateStatsLogsSetting = false;
}
targetConnectionMap = new HashMap<String, List>();
sourceConnectionMap = new HashMap<String, List>();
getSourceAndTargetConnection(item);
Document document = DocumentHelper.createDocument();
Element projectElement = generateProjectInfo(document);
Element jobElement = generateJobInfo(item, projectElement, version);
// This two element see feature 4162
generateContextInfo(item, jobElement);
generateJobSettingInfo(item, jobElement);
List<List> allList = seperateNodes(item);
if (allList == null || allList.size() != 3) {
return;
}
List<INode> allComponentsList = allList.get(0);
List<INode> internalNodeComponentsList = allList.get(1);
List<INode> externalNodeComponentsList = allList.get(2);
if (allComponentsList.size() > 0) {
// Generates information for 'Component List' part in exported HTML file.
generateAllComponentsSummaryInfo(item, jobElement, allComponentsList);
}
//$NON-NLS-1$
Element internalNodeElement = jobElement.addElement("internalNodeComponents");
//$NON-NLS-1$
Element externalNodeElement = jobElement.addElement("externalNodeComponents");
if (internalNodeComponentsList.size() > 0) {
InternalNodeComponentHandler internalNodeComponentHandler = new InternalNodeComponentHandler(this.picFilePathMap, internalNodeElement, internalNodeComponentsList, this.sourceConnectionMap, this.targetConnectionMap, this.designerCoreService, this.repositoryConnectionItemMap, this.repositoryDBIdAndNameMap, externalNodeHTMLMap);
// Generates internal node components information.
internalNodeComponentHandler.generateComponentInfo();
}
if (externalNodeComponentsList.size() > 0) {
ExternalNodeComponentHandler externalNodeComponentHandler = new ExternalNodeComponentHandler(this.picFilePathMap, externalNodeElement, externalNodeComponentsList, this.sourceConnectionMap, this.targetConnectionMap, this.designerCoreService, this.repositoryConnectionItemMap, this.repositoryDBIdAndNameMap, externalNodeHTMLMap);
// Generates external node components(tMap etc.) information.
externalNodeComponentHandler.generateComponentInfo();
}
// Generates all connection information(include internal node and external node).
EList connectionList = null;
if (item instanceof ProcessItem) {
connectionList = ((ProcessItem) item).getProcess().getConnection();
} else if (item instanceof JobletProcessItem) {
connectionList = (((JobletProcessItem) item).getJobletProcess().getConnection());
}
if (connectionList != null && connectionList.size() != 0) {
generateConnectionsInfo(jobElement, connectionList);
}
//$NON-NLS-1$
String versionPath = "_";
if (version != null && version.length == 1) {
versionPath = versionPath + version[0];
} else {
versionPath = versionPath + item.getProperty().getVersion();
}
String filePath = tempFolderPath + File.separatorChar + item.getProperty().getLabel() + versionPath + IHTMLDocConstants.XML_FILE_SUFFIX;
// This element see feature 4382
if (item instanceof ProcessItem) {
generateSourceCodeInfo((ProcessItem) item, jobElement);
}
XMLHandler.generateXMLFile(tempFolderPath, filePath, document);
}
use of org.talend.core.model.properties.JobletProcessItem in project tdi-studio-se by Talend.
the class HTMLDocGenerator method generateDocumentation.
/*
* This method is used for generating HTML file base on an instance of <code>ExportFileResource</code> (non-Javadoc)
*
* @see
* org.talend.repository.documentation.generation.IDocumentationGenerator#generateDocumentation(org.talend.repository
* .documentation.ExportFileResource, java.lang.String, java.lang.String[])
*/
@Override
public void generateDocumentation(ExportFileResource resource, String targetPath, String... jobVersion) throws Exception {
// Store all pictures' path.
List<URL> picList = new ArrayList<URL>(5);
String jobName = resource.getItem().getProperty().getLabel();
String jobPath = resource.getItem().getProperty().getItem().getState().getPath();
// Used for generating/updating all jobs' documentaiton only.
String typePath = new Path(this.repositoryObjectType.getFolder()).lastSegment();
if (jobName != null && !(jobName).equals(typePath.toLowerCase()) && targetPath.endsWith(typePath.toLowerCase())) {
targetPath = targetPath + IPath.SEPARATOR + jobPath + IPath.SEPARATOR + jobName;
}
//$NON-NLS-1$
String version = "";
// Checks if the job's version is specified, see it on "Export documentation" Dialog:
if (jobVersion != null && jobVersion.length == 1) {
version = jobVersion[0];
} else {
version = resource.getItem().getProperty().getVersion();
}
//$NON-NLS-1$
targetPath = targetPath + "_" + version;
File file = new File(targetPath);
// Delete if folde is existing.
if (file.exists()) {
FilesUtils.removeFolder(file, true);
}
file.mkdirs();
handleXMLFile(resource, targetPath, jobVersion);
String picFolderPath = checkPicDirIsExists(resource, targetPath);
// Gets the "org.talend.repository" plug-in:
//$NON-NLS-1$
final Bundle b = Platform.getBundle("org.talend.repository");
final URL xslFileUrl = FileLocator.toFileURL(FileLocator.find(b, new Path(IHTMLDocConstants.MAIN_XSL_FILE_PATH), null));
// final URL logoFileUrl = FileLocator.toFileURL(FileLocator.find(b,
// new Path(IHTMLDocConstants.LOGO_FILE_PATH), null));
File logoFile = new File(picFolderPath + File.separatorChar + IHTMLDocConstants.TALEND_LOGO_FILE_NAME);
saveLogoImage(SWT.IMAGE_JPEG, logoFile);
String xslFilePath = xslFileUrl.getPath();
// String logoFilePath = logoFileUrl.getPath();
// FileCopyUtils.copy(logoFilePath, picFolderPath + File.separatorChar
// + IHTMLDocConstants.TALEND_LOGO_FILE_NAME);
// if set css file in preference.
boolean isCheck = CorePlugin.getDefault().getPreferenceStore().getBoolean(ITalendCorePrefConstants.USE_CSS_TEMPLATE);
String cssFile = CorePlugin.getDefault().getPreferenceStore().getString(ITalendCorePrefConstants.CSS_FILE_PATH);
String temXslPath = null;
if (isCheck && cssFile != null && !cssFile.equals("")) {
//$NON-NLS-1$
String tempFolderPath = checkTempDirIsExists(resource);
temXslPath = tempFolderPath + File.separator + (new File(xslFilePath)).getName();
File temXslFile = new File(temXslPath);
if (temXslFile.exists()) {
temXslFile.delete();
}
generateXslFile(xslFilePath, temXslPath, cssFile, null);
}
// if no new xls generated, use default xsl
if (temXslPath != null) {
File temFile = new File(temXslPath);
if (!temFile.exists()) {
temXslPath = xslFilePath;
}
} else {
temXslPath = xslFilePath;
}
picList.add(logoFile.toURL());
// Property property = item.getProperty();
// String jobName = property.getLabel();
// String jobVersion = property.getVersion();
byte[] innerContent = null;
ProcessType processType = null;
if (resource.getItem() instanceof ProcessItem) {
processType = ((ProcessItem) resource.getItem()).getProcess();
//$NON-NLS-1$
innerContent = (byte[]) processType.getScreenshots().get("process");
} else if (resource.getItem() instanceof JobletProcessItem) {
processType = ((JobletProcessItem) resource.getItem()).getJobletProcess();
//$NON-NLS-1$
innerContent = (byte[]) processType.getScreenshots().get("process");
;
}
if (innerContent != null) {
//$NON-NLS-1$
String picName = jobName + "_" + version + IHTMLDocConstants.JOB_PREVIEW_PIC_SUFFIX;
ImageUtils.save(innerContent, picFolderPath + File.separatorChar + picName, SWT.IMAGE_PNG);
picList.add(new File(picFolderPath + File.separatorChar + picName).toURL());
// need to generate another pic for pdf
ByteArrayInputStream bais = new ByteArrayInputStream(innerContent);
Image pdfImage = new Image(null, bais);
int width = pdfImage.getImageData().width;
int percent = 22 * 32 * 100 / width;
//$NON-NLS-1$
ImageUtils.save(//$NON-NLS-1$
ImageUtils.scale(pdfImage, percent), //$NON-NLS-1$
picFolderPath + File.separatorChar + "pdf_" + picName, SWT.IMAGE_PNG);
//$NON-NLS-1$
picList.add(new File(picFolderPath + File.separatorChar + "pdf_" + picName).toURL());
pdfImage.dispose();
}
if (processType != null) {
for (NodeType node : (List<NodeType>) processType.getNode()) {
//$NON-NLS-1$
String uniqueName = "";
for (Object o : node.getElementParameter()) {
if (o instanceof ElementParameterType) {
if ("UNIQUE_NAME".equals(((ElementParameterType) o).getName())) {
//$NON-NLS-1$
uniqueName = ((ElementParameterType) o).getValue();
break;
}
}
}
byte[] screenshot = (byte[]) processType.getScreenshots().get(uniqueName);
if (screenshot != null && screenshot.length != 0) {
String picName = IHTMLDocConstants.EXTERNAL_NODE_PREVIEW + uniqueName + IHTMLDocConstants.JOB_PREVIEW_PIC_SUFFIX;
ImageUtils.save(screenshot, picFolderPath + File.separatorChar + picName, SWT.IMAGE_PNG);
picList.add(new File(picFolderPath + File.separatorChar + picName).toURL());
// need to generate externalNode pic for pdf
ByteArrayInputStream bais = new ByteArrayInputStream(screenshot);
Image pdfImage = new Image(null, bais);
int width = pdfImage.getImageData().width;
int percent = 22 * 32 * 100 / width;
//$NON-NLS-1$
ImageUtils.save(//$NON-NLS-1$
ImageUtils.scale(pdfImage, percent), //$NON-NLS-1$
picFolderPath + File.separatorChar + "pdf_" + picName, SWT.IMAGE_PNG);
picList.add(new File(picFolderPath + File.separatorChar + picName).toURL());
pdfImage.dispose();
}
}
}
Set keySet = picFilePathMap.keySet();
for (Object key : keySet) {
String value = picFilePathMap.get(key);
FileCopyUtils.copy(value, picFolderPath + File.separatorChar + key);
picList.add(new File(picFolderPath + File.separatorChar + key).toURL());
}
//$NON-NLS-1$
List<URL> resultFiles = parseXml2HtmlPdf(targetPath, jobName + "_" + version, temXslPath);
resource.addResources(resultFiles);
resource.addResources(IHTMLDocConstants.PIC_FOLDER_NAME, picList);
HTMLDocUtils.deleteTempFiles();
// List<URL> externalList = getExternalHtmlPath();
// resource.addResources(IHTMLDocConstants.EXTERNAL_FOLDER_NAME, externalList);
targetConnectionMap = null;
sourceConnectionMap = null;
}
use of org.talend.core.model.properties.JobletProcessItem in project tdi-studio-se by Talend.
the class AddContextCommentValueMigrationTask method execute.
@SuppressWarnings("unchecked")
@Override
public ExecutionResult execute(Item item) {
EList<ContextType> contexts = null;
if (item instanceof ProcessItem) {
// process, process_mr, process_storm, route, routelet.
ProcessItem processItem = (ProcessItem) item;
contexts = processItem.getProcess().getContext();
} else if (item instanceof JobletProcessItem) {
JobletProcessItem jobletItem = (JobletProcessItem) item;
contexts = jobletItem.getJobletProcess().getContext();
} else if (item instanceof ContextItem) {
ContextItem contextItem = (ContextItem) item;
contexts = contextItem.getContext();
}
// 2 kinds of situation should be excluded before doing migration to the old context:
// 1.has null, 2.all same comment values;
// 1 is from 6.1.0 release and 5.6.2 patched TPS-1109, all null comment value will set to "".
// for repository context in job, won't change anything because the repository context has been fixed
// the update action will execute when opening job.
boolean hasNull = false, isSame = true;
if (contexts != null && contexts.size() > 1) {
List<String> firstComments = new ArrayList<String>();
for (int x = 0; x < contexts.size(); x++) {
List<ContextParameterType> contextParams = contexts.get(x).getContextParameter();
for (int y = 0; y < contextParams.size(); y++) {
ContextParameterType param = contextParams.get(y);
boolean isBuiltin = param.getRepositoryContextId() == null;
String comment = param.getComment();
if (comment == null) {
if (isBuiltin) {
//$NON-NLS-1$
param.setComment("");
hasNull = true;
}
continue;
}
// comments to show in old item before 5.6.1 are always in the first group.
if (x == 0) {
if (!isBuiltin) {
//$NON-NLS-1$
firstComments.add("NOT_BUILTIN");
} else {
firstComments.add(comment);
}
continue;
}
if (isBuiltin && !comment.equals(firstComments.get(y))) {
isSame = false;
}
}
}
try {
if (hasNull) {
ProxyRepositoryFactory.getInstance().save(item, true);
return ExecutionResult.SUCCESS_NO_ALERT;
}
if (!isSame) {
for (int x = 1; x < contexts.size(); x++) {
List<ContextParameterType> contextParams = contexts.get(x).getContextParameter();
for (int y = 0; y < contextParams.size(); y++) {
ContextParameterType param = contextParams.get(y);
String comment = param.getComment();
if (param.getRepositoryContextId() == null && !firstComments.get(y).equals(comment)) {
if (!firstComments.get(y).equals("NOT_BUILTIN")) {
//$NON-NLS-1$
param.setComment(firstComments.get(y));
}
}
}
}
ProxyRepositoryFactory.getInstance().save(item, true);
return ExecutionResult.SUCCESS_NO_ALERT;
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
return ExecutionResult.NOTHING_TO_DO;
}
Aggregations