use of org.talend.core.model.process.IContext in project tdi-studio-se by Talend.
the class JavaProcessor method generateCode.
/*
* Append the generated java code form context into java file wihtin the project. If the file not existed new one
* will be created.
*
* @see org.talend.designer.runprocess.IProcessor#generateCode(org.talend.core .model.process.IContext, boolean,
* boolean, boolean)
*/
@Override
public void generateCode(boolean statistics, boolean trace, boolean javaProperties, int option) throws ProcessorException {
super.generateCode(statistics, trace, javaProperties, option);
try {
// hywang modified for 6484
String currentJavaProject = ProjectManager.getInstance().getProject(property).getTechnicalLabel();
ICodeGenerator codeGen;
ICodeGeneratorService service = RunProcessPlugin.getDefault().getCodeGeneratorService();
if (javaProperties) {
//$NON-NLS-1$
String javaInterpreter = "";
//$NON-NLS-1$
String javaLib = "";
String javaContext = getContextPath().toPortableString();
codeGen = service.createCodeGenerator(process, statistics, trace, javaInterpreter, javaLib, javaContext, currentJavaProject);
} else {
codeGen = service.createCodeGenerator(process, statistics, trace);
}
// set the selected context. if don't find, will keep default
if (!process.getContextManager().getDefaultContext().getName().equals(context.getName())) {
boolean found = false;
for (IContext c : process.getContextManager().getListContext()) {
if (c.getName().equals(context.getName())) {
found = true;
}
}
if (found) {
codeGen.setContextName(context.getName());
}
}
//$NON-NLS-1$
String processCode = "";
try {
// must before codegen for job to set the rule flag.
if (PluginChecker.isRulesPluginLoaded()) {
IRulesProviderService rulesService = (IRulesProviderService) GlobalServiceRegister.getDefault().getService(IRulesProviderService.class);
if (rulesService != null) {
boolean useGenerateRuleFiles = false;
List<? extends INode> allNodes = this.process.getGeneratingNodes();
for (int i = 0; i < allNodes.size(); i++) {
if (allNodes.get(i) instanceof INode) {
INode node = allNodes.get(i);
if (rulesService.isRuleComponent(node) && !node.getElementParameter(EParameterName.PROPERTY_TYPE.getName()).getValue().toString().equals("BUILT_IN")) {
//$NON-NLS-1$
useGenerateRuleFiles = true;
break;
}
}
}
if (useGenerateRuleFiles && rulesService != null && currentJavaProject != null) {
rulesService.generateFinalRuleFiles(currentJavaProject, this.process);
LastGenerationInfo.getInstance().setUseRules(this.process.getId(), this.process.getVersion(), true);
}
}
}
processCode = codeGen.generateProcessCode();
} catch (SystemException e) {
//$NON-NLS-1$
throw new ProcessorException(Messages.getString("Processor.generationFailed"), e);
} catch (IOException e) {
ExceptionHandler.process(e);
}
if (!BitwiseOptionUtils.containOption(option, TalendProcessOptionConstants.GENERATE_WITHOUT_FORMAT)) {
processCode = doFormat(processCode);
}
// see feature 4610:option to see byte length of each code method
processCode = computeMethodSizeIfNeeded(processCode);
InputStream codeStream = new ByteArrayInputStream(processCode.getBytes());
// Generating files
IFile codeFile = this.getCodeProject().getFile(this.getSrcCodePath());
if (!codeFile.exists()) {
// in win.
try {
org.talend.commons.utils.io.FilesUtils.removeExistedResources(null, codeFile, true, true);
} catch (Exception e) {
throw new ProcessorException(e);
}
IFolder parentFolder = (IFolder) codeFile.getParent();
if (!parentFolder.exists()) {
parentFolder.create(true, true, null);
}
codeFile.create(codeStream, true, null);
} else {
codeFile.setContents(codeStream, true, false, null);
}
// codeFile.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
processCode = null;
// updateContextCode(codeGen);
//$NON-NLS-1$
codeFile.getProject().deleteMarkers("org.eclipse.jdt.debug.javaLineBreakpointMarker", true, IResource.DEPTH_INFINITE);
List<INode> breakpointNodes = CorePlugin.getContext().getBreakpointNodes(process);
if (!breakpointNodes.isEmpty()) {
String[] nodeNames = new String[breakpointNodes.size()];
int pos = 0;
String nodeName;
for (INode node : breakpointNodes) {
nodeName = node.getUniqueName();
if (node.getComponent().getMultipleComponentManagers().size() > 0) {
//$NON-NLS-1$
nodeName += "_" + node.getComponent().getMultipleComponentManagers().get(0).getInput().getName();
}
//$NON-NLS-1$ //$NON-NLS-2$
nodeNames[pos++] = "[" + nodeName + " main ] start";
}
int[] lineNumbers = getLineNumbers(codeFile, nodeNames);
setBreakpoints(codeFile, getMainClass(), lineNumbers);
}
} catch (CoreException e1) {
if (e1.getStatus() != null && e1.getStatus().getException() != null) {
ExceptionHandler.process(e1.getStatus().getException());
}
//$NON-NLS-1$
throw new ProcessorException(Messages.getString("Processor.tempFailed"), e1);
}
}
use of org.talend.core.model.process.IContext in project tdi-studio-se by Talend.
the class UpdateCheckResult method getName.
@Override
@SuppressWarnings("unchecked")
public String getName() {
IUpdateItemType updateType = getUpdateType();
String displayName = updateType.getDisplayLabel();
if (updateType instanceof EUpdateItemType) {
switch((EUpdateItemType) updateType) {
case NODE_SCHEMA:
if (getResultType() == EUpdateResult.RENAME) {
List<Object> param = (List<Object>) getParameter();
String[] oldSourceIdAndChildName = UpdateManagerUtils.getSourceIdAndChildName((String) param.get(1));
String[] newSourceIdAndChildName = UpdateManagerUtils.getSourceIdAndChildName((String) param.get(2));
String display = UpdateManagerHelper.getRenamedDisplay(oldSourceIdAndChildName[1], newSourceIdAndChildName[1]);
if (display != null) {
displayName = display;
}
} else if (getResultType() == EUpdateResult.DELETE) {
// table delete by deselect
List<Object> param = (List<Object>) getParameter();
String tableDeleted = (String) param.get(0);
EUpdateResult status = (EUpdateResult) param.get(1);
String display = getDeleteOrReloadDisplay(tableDeleted, status);
if (display != null) {
displayName = display;
}
} else if (getResultType() == EUpdateResult.RELOAD) {
// table reload by deselect and reselect
List<Object> param = (List<Object>) getParameter();
String tableReload = (String) param.get(0);
EUpdateResult status = (EUpdateResult) param.get(1);
String display = getDeleteOrReloadDisplay(tableReload, status);
if (display != null) {
displayName = display;
}
} else {
if (getUpdateObject() instanceof INode && getParameter() instanceof List && PluginChecker.isEBCDICPluginLoaded()) {
IEBCDICProviderService service = (IEBCDICProviderService) GlobalServiceRegister.getDefault().getService(IEBCDICProviderService.class);
if (service != null && service.isEbcdicNode((INode) getUpdateObject())) {
List<Object> paramObjs = (List<Object>) getParameter();
if (paramObjs.size() >= 2) {
Object schemaName = paramObjs.get(1);
if (schemaName instanceof String) {
displayName = displayName + UpdateManagerUtils.addBrackets((String) schemaName);
}
}
}
}
}
break;
case NODE_PROPERTY:
case NODE_QUERY:
case JOBLET_SCHEMA:
case NODE_VALIDATION_RULE:
break;
case JOB_PROPERTY_EXTRA:
displayName = displayName + UpdateManagerUtils.addBrackets(EComponentCategory.EXTRA.getTitle());
break;
case JOB_PROPERTY_STATS_LOGS:
displayName = displayName + UpdateManagerUtils.addBrackets(EComponentCategory.STATSANDLOGS.getTitle());
break;
case JOB_PROPERTY_HEADERFOOTER:
displayName = displayName + UpdateManagerUtils.addBrackets(EComponentCategory.HEADERFOOTER.getTitle());
break;
case CONTEXT_GROUP:
if (getUpdateObject() != null && getUpdateObject() instanceof IContext) {
displayName = ((IContext) getUpdateObject()).getName();
}
break;
case CONTEXT:
// case JOBLET_CONTEXT:
{
String display = null;
switch(getResultType()) {
case RENAME:
List<Object> param = (List<Object>) getParameter();
display = UpdateManagerHelper.getRenamedDisplay((String) param.get(1), (String) param.get(2));
break;
default:
if (getUpdateObject() instanceof Collection) {
display = UpdateManagerHelper.getCollectionsDisplay(getUpdateObject(), false);
}
break;
}
if (display != null) {
displayName = display;
}
break;
}
case JOBLET_RENAMED:
{
List<Object> param = (List<Object>) getParameter();
String display = UpdateManagerHelper.getRenamedDisplay((String) param.get(1), (String) param.get(2));
if (display != null) {
displayName = display;
}
break;
}
case RELOAD:
case JUNIT_RELOAD:
if (getParameter() != null && getParameter() instanceof PropertyChangeEvent) {
PropertyChangeEvent event = (PropertyChangeEvent) getParameter();
// reload all compoennts.
if (event.getSource() != null && !(event.getSource() instanceof IProcess)) {
displayName = updateType.getDisplayLabel();
break;
}
}
break;
default:
}
return displayName;
} else {
return UpdateManagerProviderDetector.INSTANCE.getResultName(this);
}
}
use of org.talend.core.model.process.IContext in project tdi-studio-se by Talend.
the class RepositoryService method exportPigudf.
/*
* (non-Javadoc)
*
* @see org.talend.repository.model.IRepositoryService#exportPigudf(org.talend.designer.runprocess.IProcessor,
* org.talend.core.model.properties.Property, int, int)
*/
@Override
public String exportPigudf(IProcessor processor, Property property, boolean isExport) throws ProcessorException {
// build java project
CorePlugin.getDefault().getRunProcessService().buildJavaProject();
Map<ExportChoice, Object> exportChoiceMap = new EnumMap<ExportChoice, Object>(ExportChoice.class);
exportChoiceMap.put(ExportChoice.needPigudf, true);
ProcessItem processItem = (ProcessItem) property.getItem();
ExportFileResource fileResource = new ExportFileResource(processItem, property.getLabel());
ExportFileResource[] exportFileResources = new ExportFileResource[] { fileResource };
IContext context = processor.getContext();
//$NON-NLS-1$
String contextName = "Default";
if (context != null) {
contextName = context.getName();
}
JobScriptsManager jobScriptsManager = JobScriptsManagerFactory.createManagerInstance(exportChoiceMap, contextName, JobScriptsManager.ALL_ENVIRONMENTS, -1, -1, JobExportType.POJO);
URL url = jobScriptsManager.getExportPigudfResources(exportFileResources);
if (url == null) {
return null;
}
File file = new File(url.getFile());
// String librariesPath = LibrariesManagerUtils.getLibrariesPath(ECodeLanguage.JAVA) + "/";
//$NON-NLS-1$
String librariesPath = processor.getCodeProject().getLocation() + "/lib/";
String targetFileName = JobJavaScriptsManager.USERPIGUDF_JAR;
if (!isExport) {
targetFileName = property.getLabel() + '_' + property.getVersion() + '_' + JobJavaScriptsManager.USERPIGUDF_JAR;
}
File target = new File(librariesPath + targetFileName);
try {
FilesUtils.copyFile(file, target);
} catch (IOException e) {
throw new ProcessorException(e.getMessage());
}
return targetFileName;
}
use of org.talend.core.model.process.IContext in project tdi-studio-se by Talend.
the class ProcessContextComposite method checkIsSameContextParameter.
/*
* check same ContextParameter or not.
*/
private boolean checkIsSameContextParameter() {
List<ContextItem> allContextItem = ContextUtils.getAllContextItem();
for (IContext context : process.getContextManager().getListContext()) {
for (IContextParameter param : context.getContextParameterList()) {
if (allContextItem != null) {
ContextItem contextItem = ContextUtils.getContextItemById(allContextItem, param.getSource());
ContextType contextType = ContextUtils.getContextTypeByName(contextItem, context.getName(), true);
ContextParameterType contextParameterType = ContextUtils.getContextParameterTypeByName(contextType, param.getName());
if (!ContextUtils.samePropertiesForContextParameter(param, contextParameterType)) {
return false;
}
// if don't open the job to run it(not use the "Detect and update all jobs"), will show
// UpdateDetectionDialog to update the context ,after updated the item, the contextComboViewer still
// set the old one , so need refresh.
IContext runJobViewContext = getSelectedContext();
if (runJobViewContext != null) {
for (IContextParameter tempContext : runJobViewContext.getContextParameterList()) {
if (tempContext.getName().equals(contextParameterType.getName()) && !ContextUtils.samePropertiesForContextParameter(tempContext, contextParameterType)) {
return false;
}
}
}
}
}
}
return true;
}
use of org.talend.core.model.process.IContext in project tdi-studio-se by Talend.
the class ProcessContextComposite method promptConfirmLauch.
public static boolean promptConfirmLauch(Shell shell, IContext context, IProcess process) {
boolean continueLaunch = true;
int nbValues = 0;
if (context == null) {
//$NON-NLS-1$
throw new IllegalArgumentException("Context is null");
}
// Prompt for context values ?
for (IContextParameter parameter : context.getContextParameterList()) {
if (parameter.isPromptNeeded()) {
nbValues++;
}
}
if (nbValues > 0) {
IContext contextCopy = context.clone();
PromptDialog promptDialog = new PromptDialog(shell, contextCopy);
if (promptDialog.open() == PromptDialog.OK) {
for (IContextParameter param : context.getContextParameterList()) {
boolean found = false;
IContextParameter paramCopy = null;
for (int i = 0; i < contextCopy.getContextParameterList().size() & !found; i++) {
paramCopy = contextCopy.getContextParameterList().get(i);
if (param.getName().equals(paramCopy.getName())) {
// param.setValueList(paramCopy.getValueList());
param.setInternalValue(paramCopy.getValue());
found = true;
}
}
}
contextComboViewer.refresh();
contextTableViewer.refresh();
processNeedGenCode(process);
} else {
continueLaunch = false;
}
} else {
if (context.isConfirmationNeeded()) {
continueLaunch = //$NON-NLS-1$
MessageDialog.openQuestion(//$NON-NLS-1$
shell, //$NON-NLS-1$
Messages.getString("ProcessComposite.confirmTitle"), //$NON-NLS-1$
Messages.getString("ProcessComposite.confirmText", context.getName()));
}
updateDefaultValueForListTypeParameter(context.getContextParameterList());
}
return continueLaunch;
}
Aggregations