use of org.talend.repository.services.model.services.ServiceConnection in project tesb-studio-se by Talend.
the class AssignJobAction method assign.
public boolean assign(IRepositoryNode jobNode) {
if (jobNode == null) {
return false;
}
IRepositoryViewObject repositoryObject = jobNode.getObject();
final Item item = repositoryObject.getProperty().getItem();
// judge the job whether had T_ESB_PROVIDER_REQUEST
ProcessItem processItem = (ProcessItem) item;
NodeType providerNode = null;
for (Object obj : processItem.getProcess().getNode()) {
NodeType node = (NodeType) obj;
if (CreateNewJobAction.T_ESB_PROVIDER_REQUEST.equals(node.getComponentName())) {
providerNode = node;
break;
}
}
if (null == providerNode) {
MessageDialog.openWarning(Display.getCurrent().getActiveShell(), Messages.AssignJobAction_WarningTitle, Messages.AssignJobAction_WarningMessage);
return false;
}
try {
String jobID = item.getProperty().getId();
String jobName = item.getProperty().getLabel();
String operationName = repositoryNode.getObject().getLabel();
String portName = repositoryNode.getParent().getObject().getLabel();
ServiceItem serviceItem = (ServiceItem) repositoryNode.getParent().getParent().getObject().getProperty().getItem();
List<ServicePort> listPort = ((ServiceConnection) serviceItem.getConnection()).getServicePort();
for (ServicePort port : listPort) {
if (port.getName().equals(portName)) {
List<ServiceOperation> listOperation = port.getServiceOperation();
for (ServiceOperation operation : listOperation) {
if (operation.getLabel().equals(operationName)) {
// should not change the job name
// String jobNewName = port.getName() + "_" + operation.getName();
// if (resetJobname(item, jobNewName)) {
// jobName = jobNewName;
// }
operation.setReferenceJobId(jobID);
operation.setLabel(operation.getName() + "-" + jobName);
break;
}
}
break;
}
}
IFile wsdlPath = WSDLUtils.getWsdlFile(serviceItem);
Map<String, String> serviceParameters = WSDLUtils.getServiceOperationParameters(wsdlPath, ((OperationRepositoryObject) repositoryNode.getObject()).getName(), portName);
for (Object paramObj : providerNode.getElementParameter()) {
ElementParameterType param = (ElementParameterType) paramObj;
String name = param.getName();
if (serviceParameters.containsKey(name)) {
param.setValue(serviceParameters.get(name));
}
}
IProcess2 process = null;
IEditorReference[] reference = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
List<IProcess2> processes = RepositoryPlugin.getDefault().getDesignerCoreService().getOpenedProcess(reference);
for (IProcess2 processOpen : processes) {
if (processOpen.getProperty().getItem() == processItem) {
process = processOpen;
break;
}
}
if (process == null) {
IDesignerCoreService service = CorePlugin.getDefault().getDesignerCoreService();
IProcess proc = service.getProcessFromProcessItem(processItem);
if (proc instanceof IProcess2) {
process = (IProcess2) proc;
}
}
if (process != null) {
List<? extends INode> nodelist = process.getGraphicalNodes();
for (INode node : nodelist) {
if (node.getComponent().getName().equals("tESBProviderRequest")) {
repositoryChange(repositoryNode, node);
}
}
processItem.setProcess(process.saveXmlFile());
}
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
factory.save(processItem);
factory.save(serviceItem);
return true;
} catch (Exception e) {
ExceptionHandler.process(e);
}
return false;
}
use of org.talend.repository.services.model.services.ServiceConnection in project tesb-studio-se by Talend.
the class AssignJobAction method getAllReferenceJobId.
private List<String> getAllReferenceJobId(RepositoryNode repositoryNode) {
repositoryNode = getTopParent(repositoryNode);
List<IRepositoryNode> nodeList = repositoryNode.getChildren();
List<ServiceOperation> operaList = new ArrayList<ServiceOperation>();
List<String> jobIDList = new ArrayList<String>();
for (IRepositoryNode node : nodeList) {
if (node.getObject().getProperty().getItem() instanceof ServiceItem) {
ServiceItem item = (ServiceItem) node.getObject().getProperty().getItem();
ServiceConnection conn = (ServiceConnection) item.getConnection();
EList<ServicePort> portList = conn.getServicePort();
for (ServicePort port : portList) {
operaList.addAll(port.getServiceOperation());
}
}
}
for (ServiceOperation operation : operaList) {
String jobID = operation.getReferenceJobId();
if (jobID != null) {
jobIDList.add(jobID);
}
}
return jobIDList;
}
use of org.talend.repository.services.model.services.ServiceConnection in project tesb-studio-se by Talend.
the class CreateNewJobAction method init.
@Override
protected void init(RepositoryNode node) {
ERepositoryObjectType nodeType = (ERepositoryObjectType) node.getProperties(EProperties.CONTENT_TYPE);
if (!ERepositoryObjectType.SERVICESOPERATION.equals(nodeType)) {
return;
}
boolean flag = true;
ServiceItem serviceItem = (ServiceItem) node.getParent().getParent().getObject().getProperty().getItem();
for (ServicePort port : ((ServiceConnection) serviceItem.getConnection()).getServicePort()) {
for (ServiceOperation operation : port.getServiceOperation()) {
if (operation.getLabel().equals(node.getLabel()) && operation.getReferenceJobId() != null && !operation.getReferenceJobId().equals("")) {
flag = false;
}
}
}
setEnabled(flag);
}
use of org.talend.repository.services.model.services.ServiceConnection in project tesb-studio-se by Talend.
the class CreateNewJobAction method createNewProcess.
private boolean createNewProcess(RepositoryNode nodeOperation, final ProcessItem process) {
if (process == null) {
return false;
}
final RepositoryNode portNode = nodeOperation.getParent();
ServiceItem serviceItem = (ServiceItem) portNode.getParent().getObject().getProperty().getItem();
addToMergeRelationship(process, serviceItem);
try {
// Set readonly to false since created job will always be editable.
ProcessEditorInput fileEditorInput = new ProcessEditorInput(process, false, true, false);
IRepositoryNode repositoryNode = RepositorySeekerManager.getInstance().searchRepoViewNode(fileEditorInput.getItem().getProperty().getId());
fileEditorInput.setRepositoryNode(repositoryNode);
IEditorPart openEditor = getActivePage().openEditor(fileEditorInput, MultiPageTalendEditor.ID, true);
CommandStack commandStack = (CommandStack) openEditor.getAdapter(CommandStack.class);
final Node nodeProviderRequest = new Node(ComponentsFactoryProvider.getInstance().get(T_ESB_PROVIDER_REQUEST, ComponentCategory.CATEGORY_4_DI.getName()), fileEditorInput.getLoadedProcess());
IFile wsdlPath = WSDLUtils.getWsdlFile(serviceItem);
Map<String, String> serviceParameters = WSDLUtils.getServiceOperationParameters(wsdlPath, ((OperationRepositoryObject) nodeOperation.getObject()).getName(), portNode.getObject().getLabel());
setProviderRequestComponentConfiguration(nodeProviderRequest, serviceParameters);
CreateNodeContainerCommand cNcc = new CreateNodeContainerCommand(fileEditorInput.getLoadedProcess(), new NodeContainer(nodeProviderRequest), new Point(3 * Node.DEFAULT_SIZE, 4 * Node.DEFAULT_SIZE));
commandStack.execute(cNcc);
if (!WSDLUtils.ONE_WAY.equals(serviceParameters.get(WSDLUtils.COMMUNICATION_STYLE))) {
Node node = new Node(ComponentsFactoryProvider.getInstance().get(T_ESB_PROVIDER_RESPONSE, ComponentCategory.CATEGORY_4_DI.getName()), fileEditorInput.getLoadedProcess());
cNcc = new CreateNodeContainerCommand(fileEditorInput.getLoadedProcess(), new NodeContainer(node), new Point(9 * Node.DEFAULT_SIZE, 4 * Node.DEFAULT_SIZE));
commandStack.execute(cNcc);
}
String faults = serviceParameters.get(WSDLUtils.FAULTS);
if (null != faults) {
int horMultiplier = 15;
for (String fault : faults.split(",")) {
Node node = new Node(ComponentsFactoryProvider.getInstance().get(T_ESB_PROVIDER_FAULT, ComponentCategory.CATEGORY_4_DI.getName()), fileEditorInput.getLoadedProcess());
cNcc = new CreateNodeContainerCommand(fileEditorInput.getLoadedProcess(), new NodeContainer(node), new Point(horMultiplier * Node.DEFAULT_SIZE, 4 * Node.DEFAULT_SIZE));
commandStack.execute(cNcc);
// $NON-NLS-1$
node.getElementParameter("ESB_FAULT_TITLE").setValue('\"' + fault + '\"');
horMultiplier += 6;
}
}
ServiceConnection serviceConnection = (ServiceConnection) serviceItem.getConnection();
final String parentPortName = portNode.getObject().getLabel();
for (ServicePort port : serviceConnection.getServicePort()) {
if (port.getName().equals(parentPortName)) {
for (ServiceOperation operation : port.getServiceOperation()) {
if (operation.getLabel().equals(nodeOperation.getObject().getLabel())) {
String jobName = process.getProperty().getLabel();
String jobID = process.getProperty().getId();
operation.setReferenceJobId(jobID);
operation.setLabel(operation.getName() + "-" + jobName);
break;
}
}
break;
}
}
repositoryChange(nodeOperation, nodeProviderRequest);
ProxyRepositoryFactory.getInstance().save(serviceItem);
return true;
} catch (PartInitException e) {
ExceptionHandler.process(e);
} catch (PersistenceException e) {
MessageBoxExceptionHandler.process(e);
} catch (Exception e) {
ExceptionHandler.process(e);
}
return false;
}
use of org.talend.repository.services.model.services.ServiceConnection in project tesb-studio-se by Talend.
the class CreateMavenDataServicePom method create.
@Override
public void create(IProgressMonitor monitor) throws Exception {
IFile pom = getPomFile();
if (pom == null) {
return;
}
Model tmpModel = createModel();
// createModel();
this.model = new Model();
// config model
configModel(model);
// new Model();
Model pomModel = model;
pomModel.setModelVersion(MAVEN_VERSION);
// pom.setParent(model.getParent());
// @ProjectName@ @JobName@-@JobVersion@ (@TalendJobVersion@,@JobType@)
String groupId = PomIdsHelper.getJobGroupId(getJobProcessor().getProperty());
String projectName = ProjectManager.getInstance().getProject(getJobProcessor().getProperty()).getTechnicalLabel();
String artifactId = PomIdsHelper.getJobArtifactId(getJobProcessor().getProperty());
String jobVersion = PomIdsHelper.getJobVersion(getJobProcessor().getProperty());
String talendJobVersion = getJobProcessor().getProperty().getVersion();
String JobType = "Services";
String displayName = projectName + " " + artifactId + "-" + "${project.version}" + " (" + talendJobVersion + "," + JobType + ")";
pomModel.setGroupId(groupId);
pomModel.setArtifactId(artifactId);
pomModel.setVersion(jobVersion);
pomModel.setPackaging("pom");
pomModel.setParent(tmpModel.getParent());
pomModel.setName(displayName + " Kar");
// add dynamic ds job modules
String tmpJobId = "";
String upperPath = "../";
ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
ServiceConnection connection = (ServiceConnection) serviceItem.getConnection();
EList<ServicePort> listPort = connection.getServicePort();
// In case the service in under sub folder
int depth = ItemResourceUtil.getItemRelativePath(serviceItem.getProperty()).segmentCount();
String relativePath = upperPath.concat(upperPath);
for (int level = 0; level < depth; level++) {
relativePath += upperPath;
}
for (ServicePort port : listPort) {
List<ServiceOperation> listOperation = port.getServiceOperation();
for (ServiceOperation operation : listOperation) {
if (StringUtils.isNotEmpty(operation.getReferenceJobId())) {
IRepositoryViewObject node = factory.getLastVersion(operation.getReferenceJobId());
if (node != null) {
String jobName = node.getLabel();
if (jobName != null && !pomModel.getModules().contains(jobName)) {
String module = relativePath + TalendJavaProjectConstants.DIR_PROCESS + "/" + node.getPath() + "/" + AggregatorPomsHelper.getJobProjectFolderName(node.getProperty());
pomModel.addModule(module);
}
}
tmpJobId = operation.getReferenceJobId();
}
}
}
pomModel.addProperty("cloud.publisher.skip", "true");
// add control bundle module
pomModel.addModule(POM_CONTROL_BUNDLE_XML);
// add feature module
pomModel.addModule(POM_FEATURE_XML);
pomModel.addProfile(addProfileForCloud());
pomModel.setBuild(new Build());
pomModel.getBuild().addPlugin(addSkipDockerMavenPlugin());
PomUtil.savePom(monitor, pomModel, pom);
Parent parentPom = new Parent();
parentPom.setGroupId(pomModel.getGroupId());
parentPom.setArtifactId(pomModel.getArtifactId());
parentPom.setVersion(pomModel.getVersion());
parentPom.setRelativePath("/");
org.talend.designer.core.ui.editor.process.Process process = (org.talend.designer.core.ui.editor.process.Process) getJobProcessor().getProcess();
boolean publishAsSnapshot = BooleanUtils.toBoolean((String) process.getAdditionalProperties().get(MavenConstants.NAME_PUBLISH_AS_SNAPSHOT));
IFile feature = pom.getParent().getFile(new Path(POM_FEATURE_XML));
Model featureModel = new Model();
featureModel.setModelVersion(MAVEN_VERSION);
featureModel.setGroupId(PomIdsHelper.getJobGroupId(getJobProcessor().getProperty()));
featureModel.setArtifactId(PomIdsHelper.getJobArtifactId(getJobProcessor().getProperty()) + "-feature");
featureModel.setVersion(PomIdsHelper.getJobVersion(getJobProcessor().getProperty()));
featureModel.setPackaging("pom");
Build featureModelBuild = new Build();
featureModelBuild.addPlugin(addFeaturesMavenPlugin());
featureModelBuild.addPlugin(addSkipDockerMavenPlugin());
// featureModelBuild.addPlugin(
// addDeployFeatureMavenPlugin(featureModel.getArtifactId(), featureModel.getVersion(), publishAsSnapshot));
// featureModelBuild.addPlugin(addSkipDeployFeatureMavenPlugin());
featureModelBuild.addPlugin(addSkipMavenCleanPlugin());
// maven versioning
featureModelBuild.addPlugin(addOsgiHelperMavenPlugin());
featureModel.setBuild(featureModelBuild);
featureModel.setParent(parentPom);
featureModel.setName(displayName + " Feature");
featureModel.addProperty("cloud.publisher.skip", "false");
featureModel.addProperty("talend.job.id", model.getProperties().getProperty("talend.job.id"));
featureModel.addProperty("talend.job.name", artifactId);
featureModel.addProperty("talend.job.version", model.getProperties().getProperty("talend.job.version"));
featureModel.addProperty("talend.product.version", VersionUtils.getVersion());
// DemoService-feature-0.1.0
featureModel.addProperty("talend.job.finalName", featureModel.getArtifactId() + "-" + featureModel.getVersion());
PomUtil.savePom(monitor, featureModel, feature);
IFile controlBundle = pom.getParent().getFile(new Path(POM_CONTROL_BUNDLE_XML));
Model controlBundleModel = new Model();
controlBundleModel.setParent(model.getParent());
controlBundleModel.setModelVersion(MAVEN_VERSION);
controlBundleModel.setGroupId(PomIdsHelper.getJobGroupId(getJobProcessor().getProperty()));
controlBundleModel.setArtifactId(PomIdsHelper.getJobArtifactId(getJobProcessor().getProperty()) + "-control-bundle");
controlBundleModel.setVersion(PomIdsHelper.getJobVersion(getJobProcessor().getProperty()));
controlBundleModel.setPackaging("jar");
controlBundleModel.setName(displayName + " Control Bundle");
Build controlBundleModelBuild = new Build();
controlBundleModelBuild.addPlugin(addControlBundleMavenPlugin());
controlBundleModelBuild.addPlugin(addSkipDockerMavenPlugin());
controlBundleModelBuild.addResource(addControlBundleMavenResource());
controlBundleModel.setBuild(controlBundleModelBuild);
controlBundleModel.setParent(parentPom);
controlBundleModel.addProperty("cloud.publisher.skip", "true");
PomUtil.savePom(monitor, controlBundleModel, controlBundle);
afterCreate(monitor);
}
Aggregations