use of org.talend.mdm.repository.model.mdmserverobject.WSTransformerV2E in project tmdm-studio-se by Talend.
the class GenerateJobTransformerAction method createTransformer.
/**
* @param jobVersion
*/
private WSTransformerV2E createTransformer(String jobName, String jobVersion, JobOptionsDialog dialog) {
// $NON-NLS-1$
String server = "http://localhost:8180";
Execution execution = dialog.getExecution();
Parameter executionParameter = dialog.getParameter();
// $NON-NLS-1$
final String TRANSFORMER_PLUGIN = "amalto/local/transformer/plugin/xslt";
WSTransformerV2E transformer = MdmserverobjectFactory.eINSTANCE.createWSTransformerV2E();
// $NON-NLS-1$
String url = "";
switch(execution) {
case EMBEDDED:
// $NON-NLS-1$//$NON-NLS-2$
url = "ltj://" + jobName + "/" + jobVersion;
break;
case WEB_SERVICE:
url = Messages.bind(Messages.GenerateJobXX_UrlString, server, jobName, jobVersion, jobName);
break;
}
// Generate the job call
List<WSTransformerProcessStepE> steps = new ArrayList<WSTransformerProcessStepE>();
WSTransformerVariablesMapping[] input;
WSTransformerVariablesMapping[] output;
try {
List<WSTransformerVariablesMappingE> inItems;
List<WSTransformerVariablesMappingE> outItems;
switch(executionParameter) {
case CONTEXT_VARIABLE:
String itemstr = // $NON-NLS-1$
"<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" xmlns:mdm=\"java:com.amalto.core.plugin.base.xslt.MdmExtension\" version=\"1.0\"> <xsl:output method=\"xml\" indent=\"yes\" omit-xml-declaration=\"yes\" /> <xsl:template match=\"/\" priority=\"1\">\n" + // $NON-NLS-1$
"<exchange> <report>\n <xsl:copy-of select=\"Update\"/> </report> <item><xsl:copy-of select='mdm:getItemProjection(Update/RevisionID,Update/DataCluster,Update/Concept,Update/Key)'/></item></exchange> " + // $NON-NLS-1$
"</xsl:template> </xsl:stylesheet>\n";
WSTransformerProcessStepE steps1 = MdmserverobjectFactory.eINSTANCE.createWSTransformerProcessStepE();
inItems = new ArrayList<WSTransformerVariablesMappingE>();
WSTransformerVariablesMappingE inputLine = MdmserverobjectFactory.eINSTANCE.createWSTransformerVariablesMappingE();
// $NON-NLS-1$
inputLine.setPipelineVariable("_DEFAULT_");
// $NON-NLS-1$
inputLine.setPluginVariable("xml");
inItems.add(inputLine);
outItems = new ArrayList<WSTransformerVariablesMappingE>();
WSTransformerVariablesMappingE outputLine = MdmserverobjectFactory.eINSTANCE.createWSTransformerVariablesMappingE();
// $NON-NLS-1$
outputLine.setPipelineVariable("item_xml");
// $NON-NLS-1$
outputLine.setPluginVariable("text");
outItems.add(outputLine);
steps1.setPluginJNDI(TRANSFORMER_PLUGIN);
// $NON-NLS-1$
steps1.setDescription("Stylesheet");
steps1.setParameters(itemstr);
steps1.getInputMappings().addAll(inItems);
steps1.getOutputMappings().addAll(outItems);
steps1.setDisabled(false);
// Generate the XSLT step to retrieve the item from an update report
// step 2
WSTransformerProcessStepE steps2 = MdmserverobjectFactory.eINSTANCE.createWSTransformerProcessStepE();
List<WSTransformerVariablesMappingE> inItems2 = new ArrayList<WSTransformerVariablesMappingE>();
WSTransformerVariablesMappingE inputLine2 = MdmserverobjectFactory.eINSTANCE.createWSTransformerVariablesMappingE();
// $NON-NLS-1$
inputLine2.setPipelineVariable("item_xml");
// $NON-NLS-1$
inputLine2.setPluginVariable("law_text");
inItems2.add(inputLine2);
List<WSTransformerVariablesMappingE> outItems2 = new ArrayList<WSTransformerVariablesMappingE>();
WSTransformerVariablesMappingE outputLine2 = MdmserverobjectFactory.eINSTANCE.createWSTransformerVariablesMappingE();
// $NON-NLS-1$
outputLine2.setPipelineVariable("decode_xml");
// $NON-NLS-1$
outputLine2.setPluginVariable("codec_text");
outItems2.add(outputLine2);
// $NON-NLS-1$
steps2.setPluginJNDI("amalto/local/transformer/plugin/codec");
// $NON-NLS-1$
steps2.setDescription("Escape the item XML");
String parameter = // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"<parameters>\n" + "<method>DECODE</method>\n" + "<algorithm>XMLESCAPE</algorithm>\n" + // $NON-NLS-1$
"</parameters>\n";
steps2.setParameters(parameter);
steps2.getInputMappings().addAll(inItems2);
steps2.getOutputMappings().addAll(outItems2);
steps2.setDisabled(false);
// step 3
WSTransformerProcessStepE steps3 = MdmserverobjectFactory.eINSTANCE.createWSTransformerProcessStepE();
List<WSTransformerVariablesMappingE> inItems3 = new ArrayList<WSTransformerVariablesMappingE>();
WSTransformerVariablesMappingE inputLine3 = MdmserverobjectFactory.eINSTANCE.createWSTransformerVariablesMappingE();
// $NON-NLS-1$
inputLine3.setPipelineVariable("decode_xml");
// $NON-NLS-1$
inputLine3.setPluginVariable("text");
inItems3.add(inputLine3);
List<WSTransformerVariablesMappingE> outItems3 = new ArrayList<WSTransformerVariablesMappingE>();
WSTransformerVariablesMappingE outputLine3 = MdmserverobjectFactory.eINSTANCE.createWSTransformerVariablesMappingE();
// $NON-NLS-1$
outputLine3.setPipelineVariable("output");
// $NON-NLS-1$
outputLine3.setPluginVariable("result");
outItems3.add(outputLine3);
// $NON-NLS-1$
steps3.setPluginJNDI("amalto/local/transformer/plugin/callJob");
// $NON-NLS-1$
steps3.setDescription("Invoke the job");
input = new WSTransformerVariablesMapping[1];
// $NON-NLS-1$ //$NON-NLS-2$
input[0] = new WSTransformerVariablesMapping(null, "_DEFAULT_", "xml");
output = new WSTransformerVariablesMapping[1];
// $NON-NLS-1$ //$NON-NLS-2$
output[0] = new WSTransformerVariablesMapping(null, "item_xml", "text");
steps3.setParameters(parameter);
steps3.getInputMappings().addAll(inItems3);
steps3.getOutputMappings().addAll(outItems3);
steps3.setDisabled(false);
parameter = // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
"<configuration>\n" + "<url>" + url + "</url>\n" + "<contextParam>\n" + "<name>xmlInput</name>\n" + "<value>{decode_xml}</value>\n" + // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"</contextParam>\n" + // $NON-NLS-1$
"</configuration>\n";
steps3.setParameters(parameter);
steps.add(steps1);
steps.add(steps2);
steps.add(steps3);
break;
case INTEGRATED:
WSTransformerProcessStepE step1 = MdmserverobjectFactory.eINSTANCE.createWSTransformerProcessStepE();
inItems = new ArrayList<WSTransformerVariablesMappingE>();
inputLine = MdmserverobjectFactory.eINSTANCE.createWSTransformerVariablesMappingE();
// $NON-NLS-1$
inputLine.setPipelineVariable("_DEFAULT_");
// $NON-NLS-1$
inputLine.setPluginVariable("text");
inItems.add(inputLine);
outItems = new ArrayList<WSTransformerVariablesMappingE>();
outputLine = MdmserverobjectFactory.eINSTANCE.createWSTransformerVariablesMappingE();
// $NON-NLS-1$
outputLine.setPipelineVariable("item_xml");
// $NON-NLS-1$
outputLine.setPluginVariable("result");
outItems.add(outputLine);
// $NON-NLS-1$
step1.setPluginJNDI("amalto/local/transformer/plugin/callJob");
// $NON-NLS-1$
step1.setDescription("Invoke the job");
step1.setParameters(// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"<configuration>\n" + "<url>" + url + "</url>\n" + // $NON-NLS-1$
"</configuration>\n");
step1.getInputMappings().addAll(inItems);
step1.getOutputMappings().addAll(outItems);
step1.setDisabled(false);
steps.add(step1);
break;
default:
log.warn(Messages.bind(Messages.GenerateJobXX_UNSupportedType, executionParameter));
steps = Collections.emptyList();
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
try {
// Generate the job call
transformer.setName(getNewProcessName(jobName));
transformer.setDescription(Messages.bind(Messages.GenerateJobXX_ProcessCallJob, jobName));
transformer.getProcessSteps().addAll(steps);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return transformer;
}
use of org.talend.mdm.repository.model.mdmserverobject.WSTransformerV2E in project tmdm-studio-se by Talend.
the class GenerateJobTransformerAction method doRun.
@Override
protected void doRun() {
selectObj = getSelectedObject().get(0);
JobOptionsDialog dialog = new JobOptionsDialog(getShell(), Messages.JobProcesssOptionsDialogTitle_title, Execution.EMBEDDED);
dialog.setBlockOnOpen(true);
int ret = dialog.open();
if (ret == Dialog.CANCEL) {
return;
}
// $NON-NLS-1$
String jobName = "";
// $NON-NLS-1$
String jobVersion = "";
// $NON-NLS-1$
String path = "/other";
if (selectObj instanceof IRepositoryViewObject) {
Property property = ((IRepositoryViewObject) selectObj).getProperty();
if (property != null) {
jobName = property.getLabel();
jobVersion = property.getVersion();
}
}
// check exist
IValidateService validateService = (IValidateService) GlobalServiceRegister.getDefault().getService(IValidateService.class);
if (validateService != null) {
boolean result = validateService.validateAndAlertObjectExistence(IServerObjectRepositoryType.TYPE_TRANSFORMERV2, getNewProcessName(jobName), null);
if (!result) {
return;
}
}
WSTransformerV2E transformer = createTransformer(jobName, jobVersion, dialog);
// if the new objectect is opened ,than close it before regenerating
IRepositoryViewObject toDelete = RepositoryResourceUtil.findViewObjectByName(IServerObjectRepositoryType.TYPE_TRANSFORMERV2, PREFIX + jobName);
if (toDelete != null) {
IEditorPart openedEditor = UIUtil.findOpenedEditor(toDelete);
if (openedEditor != null) {
UIUtil.closeEditor(openedEditor, false);
}
// delete directly
RepositoryResourceUtil.removeViewObjectPhysically(toDelete, jobVersion);
}
AttachToProcessView(jobName, transformer);
}
Aggregations