Skip to content

Commit

Permalink
FUSETOOLS-1778 - Insert valid xml respecting extension point (#16)
Browse files Browse the repository at this point in the history
- Use extension point and don't insert on our own the element
- Generate xsd valid node
- Add an integration tests
- use latest Fuse Tooling Snapshot build
  • Loading branch information
apupier committed May 11, 2016
1 parent 788e0bc commit 8508566
Show file tree
Hide file tree
Showing 21 changed files with 418 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ Bundle-ActivationPolicy: lazy
Bundle-Vendor: %Bundle-Vendor
Bundle-ClassPath: .
Bundle-Localization: OSGI-INF/l10n/bundle
Export-Package: org.fusesource.ide.sap.ui.export;x-friends:="org.fusesource.ide.sap.ui.tests.integration"
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.fusesource.ide.camel.model.service.core.catalog.Dependency;
import org.fusesource.ide.camel.model.service.core.model.CamelFile;
import org.fusesource.ide.sap.ui.export.SapGlobalConnectionConfigurationWizard;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

Expand All @@ -44,16 +43,16 @@ public class SAPServerContribution implements ICustomGlobalConfigElementContribu
*/
@Override
public GlobalConfigurationTypeWizard createGlobalElement(CamelFile camelFile) {
return createWizard(camelFile.getDocument());
return createWizard(camelFile);
}

/*
* (non-Javadoc)
* @see org.fusesource.ide.camel.editor.provider.ext.ICustomGlobalConfigElementContribution#modifyGlobalElement(org.w3c.dom.Document, org.w3c.dom.Node)
*/
@Override
public GlobalConfigurationTypeWizard modifyGlobalElement(Document document) {
return createWizard(document);
public GlobalConfigurationTypeWizard modifyGlobalElement(CamelFile camelFile) {
return createWizard(camelFile);
}

/* (non-Javadoc)
Expand Down Expand Up @@ -101,8 +100,8 @@ public List<Dependency> getElementDependencies() {
* @param document - document edited by wizard
* @return SAP Global Connection Configuration Wizard
*/
private GlobalConfigurationTypeWizard createWizard(Document document) {
SapGlobalConnectionConfigurationWizard wizard = new SapGlobalConnectionConfigurationWizard(document);
private GlobalConfigurationTypeWizard createWizard(CamelFile camelFile) {
SapGlobalConnectionConfigurationWizard wizard = new SapGlobalConnectionConfigurationWizard(camelFile);
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
ISelection selection = window.getSelectionService().getSelection();
if (!(selection instanceof IStructuredSelection)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
package org.fusesource.ide.sap.ui.export;

import static org.fusesource.ide.sap.ui.util.ModelUtil.getSapConnectionConfigurationModelFromDocument;
import static org.fusesource.ide.sap.ui.util.ModelUtil.setSapConnectionConfigurationModelIntoDocument;

import java.util.HashMap;

import javax.xml.bind.JAXBException;
import javax.xml.transform.dom.DOMResult;

import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.emf.common.command.BasicCommandStack;
import org.eclipse.emf.ecore.resource.Resource;
Expand All @@ -30,11 +32,13 @@
import org.fusesource.camel.component.sap.util.ComponentDestinationDataProvider;
import org.fusesource.camel.component.sap.util.ComponentServerDataProvider;
import org.fusesource.ide.camel.editor.provider.ext.GlobalConfigurationTypeWizard;
import org.fusesource.ide.camel.model.service.core.model.CamelFile;
import org.fusesource.ide.sap.ui.Messages;
import org.fusesource.ide.sap.ui.edit.command.TransactionalCommandStack;
import org.fusesource.ide.sap.ui.edit.idoc.IdocItemProviderAdapterFactory;
import org.fusesource.ide.sap.ui.edit.rfc.RfcItemProviderAdapterFactory;
import org.w3c.dom.Document;
import org.fusesource.ide.sap.ui.jaxb.SapConnectionConfiguration;
import org.fusesource.ide.sap.ui.jaxb.SapConnectionConfigurationBuilder;
import org.w3c.dom.Element;

/**
Expand All @@ -61,13 +65,15 @@ public class SapGlobalConnectionConfigurationWizard extends Wizard implements IE
private DataBindingContext context;
private SapGlobalConnectionConfigurationPage exportPage;

private Document document;
private CamelFile camelFile;
private org.fusesource.camel.component.sap.model.rfc.SapConnectionConfiguration sapConnectionConfigurationModel;

private Element globalConfigurationElementNode;

public SapGlobalConnectionConfigurationWizard(Document document) {
this.document = document;
public SapGlobalConnectionConfigurationWizard(CamelFile camelFile) {
this.camelFile = camelFile;
initializeEditingDomain();
this.sapConnectionConfigurationModel = getSapConnectionConfigurationModelFromDocument(this.document, editingDomain);
this.sapConnectionConfigurationModel = getSapConnectionConfigurationModelFromDocument(camelFile.getDocument(), editingDomain);
}

@Override
Expand All @@ -90,7 +96,17 @@ public void addPages() {

@Override
public boolean performFinish() {
setSapConnectionConfigurationModelIntoDocument(this.document, this.sapConnectionConfigurationModel);
SapConnectionConfiguration sapConnectionConfiguration = new SapConnectionConfiguration();
SapConnectionConfigurationBuilder.populateSapConnectionConfiguration(sapConnectionConfigurationModel, sapConnectionConfiguration);
try {
DOMResult result = sapConnectionConfiguration.marshal();
final Element beanNode = (Element) result.getNode().getFirstChild();
final Element importedBeanNode = (Element) camelFile.getDocument().importNode(beanNode, true);
setGlobalConfigurationElementNode(importedBeanNode);
} catch (JAXBException e) {
e.printStackTrace();
return false;
}
return true;
}

Expand Down Expand Up @@ -128,12 +144,22 @@ private void unregisterDataStores() {

@Override
public Element getGlobalConfigurationElementNode() {
return null;
return globalConfigurationElementNode;
}

@Override
public void setGlobalConfigurationElementNode(Element node) {
// NOOP
this.globalConfigurationElementNode = node;
}

/**
* /!\ Public for test purpose only
*
* @param sapConnectionConfigurationModel
* the sapConnectionConfigurationModel to set
*/
public void setSapConnectionConfigurationModel(org.fusesource.camel.component.sap.model.rfc.SapConnectionConfiguration sapConnectionConfigurationModel) {
this.sapConnectionConfigurationModel = sapConnectionConfigurationModel;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@
******************************************************************************/
package org.fusesource.ide.sap.ui.jaxb;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.PropertyException;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.transform.dom.DOMResult;

@XmlRootElement(name="bean")
@XmlAccessorType(XmlAccessType.FIELD)
Expand All @@ -41,4 +46,18 @@ public ServerDataStore getServerDataStore() {
return serverDataStore;
}

public DOMResult marshal() throws JAXBException, PropertyException {
Marshaller m = prepareMarshaller();
DOMResult result = new DOMResult();
m.marshal(this, result);
return result;
}

private Marshaller prepareMarshaller() throws JAXBException, PropertyException {
JAXBContext context = JAXBContext.newInstance(SapConnectionConfiguration.class);
Marshaller m = context.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
return m;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
import java.io.OutputStream;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.PropertyException;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
Expand All @@ -37,15 +39,20 @@ public void setSapConnectionConfiguration(SapConnectionConfiguration sapConnecti
this.sapConnectionConfiguration = sapConnectionConfiguration;
}

public void marshal(OutputStream os) throws Exception {
public void marshal(OutputStream os) throws JAXBException, PropertyException {
if (sapConnectionConfiguration != null) {
JAXBContext context = JAXBContext.newInstance(BlueprintFile.class);
Marshaller m = context.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION,
"http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd");
Marshaller m = prepareMarshaller();
m.marshal(this, os);
}
}

private Marshaller prepareMarshaller() throws JAXBException, PropertyException {
JAXBContext context = JAXBContext.newInstance(BlueprintFile.class);
Marshaller m = context.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION,
"http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd");
return m;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
import java.io.OutputStream;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.PropertyException;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
Expand All @@ -40,12 +42,23 @@ public void setSapConnectionConfiguration(

public void marshal(OutputStream os) throws Exception {
if (sapConnectionConfiguration != null) {
JAXBContext context = JAXBContext.newInstance(SpringFile.class);
Marshaller m = context.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd");
Marshaller m = prepareMarshaller();
m.marshal(this, os);
}
}

/**
* @return
* @throws JAXBException
* @throws PropertyException
*/
private Marshaller prepareMarshaller() throws JAXBException, PropertyException {
JAXBContext context = JAXBContext.newInstance(SpringFile.class);
Marshaller m = context.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION,
"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd");
return m;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -146,44 +146,6 @@ public static SapConnectionConfiguration getSapConnectionConfigurationModelFromD
return sapConnectionConfigurationModel;
}

public static void setSapConnectionConfigurationModelIntoDocument(Document document, SapConnectionConfiguration sapConnectionConfigurationModel) {
if (document == null || sapConnectionConfigurationModel == null) {
return;
}


Element sapConfigurationConfig = getSapConfiguration(document);
Element destinationDataStoreConfig = getDestinationDataStore(sapConfigurationConfig);
Element serverDataStoreConfig = getServerDataStore(sapConfigurationConfig);

DestinationDataStore destinationDataStoreModel = sapConnectionConfigurationModel.getDestinationDataStore();
populateDestinationDataStoreModelIntoConfig(destinationDataStoreModel, destinationDataStoreConfig);

ServerDataStore serverDataStoreModel = sapConnectionConfigurationModel.getServerDataStore();
populateServerDataStoreModelIntoConfig(serverDataStoreModel, serverDataStoreConfig);
}

public static void populateDestinationDataStoreModelIntoConfig(DestinationDataStore destinationDataStoreModel, Element destinationDataStoreConfig) {
if (destinationDataStoreModel == null || destinationDataStoreConfig == null) {
return;
}

Element map = getFirstChildElementWithName(destinationDataStoreConfig, MAP_TAG);
if (map == null) {
map = destinationDataStoreConfig.getOwnerDocument().createElement(MAP_TAG);
destinationDataStoreConfig.appendChild(map);
}

removeChildNodes(map);
for (Map.Entry<String,DestinationData> entry: destinationDataStoreModel.getEntries()) {
Element entryConfig = destinationDataStoreConfig.getOwnerDocument().createElement(ENTRY_TAG);
entryConfig.setAttribute(KEY_ATTRIBUTE, entry.getKey());
entryConfig.setAttribute(CLASS_ATTRIBUTE, DESTINATION_DATA_CLASS);
map.appendChild(entryConfig);
populateDestinationDataModelIntoConfig(entry.getValue(), entryConfig);
}
}

public static void populateDestinationDataConfigIntoModel(DestinationData destinationDataModel, Element destinationDataConfig) {
if (destinationDataModel == null || destinationDataConfig == null) {
return;
Expand All @@ -201,43 +163,6 @@ public static void populateDestinationDataConfigIntoModel(DestinationData destin
}
}

public static void populateDestinationDataModelIntoConfig(DestinationData destinationDataModel, Element destinationDataConfig) {
if (destinationDataModel == null || destinationDataConfig == null) {
return;
}

// Check if configuration entry is a reference to global bean config
String beanName = getAttributeValue(destinationDataConfig, "value-ref"); //$NON-NLS-1$
if (beanName != null) {
destinationDataConfig = getGlobalConfigurationById(destinationDataConfig.getOwnerDocument(), beanName);
}

Map<String,String> destinationDataProperties = extractDestinationDataProperties(destinationDataModel);

setPropertyValues(destinationDataConfig, destinationDataProperties);
}

public static void populateServerDataStoreModelIntoConfig(ServerDataStore serverDataStoreModel, Element serverDataStoreConfig) {
if (serverDataStoreModel == null || serverDataStoreConfig == null) {
return;
}

Element map = getFirstChildElementWithName(serverDataStoreConfig, MAP_TAG);
if (map == null) {
map = serverDataStoreConfig.getOwnerDocument().createElement(MAP_TAG);
serverDataStoreConfig.appendChild(map);
}

removeChildNodes(map);
for (Map.Entry<String,ServerData> entry: serverDataStoreModel.getEntries()) {
Element entryConfig = serverDataStoreConfig.getOwnerDocument().createElement(ENTRY_TAG);
entryConfig.setAttribute(KEY_ATTRIBUTE, entry.getKey());
entryConfig.setAttribute(CLASS_ATTRIBUTE, SERVER_DATA_CLASS);
map.appendChild(entryConfig);
populateServerDataModelIntoConfig(entry.getValue(), entryConfig);
}
}

public static void populateServerDataConfigIntoModel(ServerData serverDataModel, Element serverDataConfig) {
if (serverDataModel == null || serverDataConfig == null) {
return;
Expand Down Expand Up @@ -607,7 +532,6 @@ public static Element getSapConfiguration(Document document) {
sapConfigurationElement = document.createElement(BEAN_TAG);
sapConfigurationElement.setAttribute(ID_ATTRIBUTE, SAP_CONNECTION_CONFIGURATION_ID);
sapConfigurationElement.setAttribute(CLASS_ATTRIBUTE, SAP_CONNECTION_CONFIGURATION_CLASS);
document.getDocumentElement().appendChild(sapConfigurationElement);
}

return sapConfigurationElement;
Expand Down
2 changes: 1 addition & 1 deletion jboss-fuse-sap-tool-suite/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<tycho.scmUrl>scm:git:https://github.com/fusesource/fuseide.git</tycho.scmUrl>
<forge-project-id>ide</forge-project-id>
<ide-version>${project.version}</ide-version>
<fuse-tooling-url>http://download.jboss.org/jbosstools/mars/development/updates/integration-stack/fuse-tooling/8.0.0.Beta2/all/repo/</fuse-tooling-url>
<fuse-tooling-url>http://download.jboss.org/jbosstools/snapshots/builds/Fuse-Tooling/all/repo/</fuse-tooling-url>

<!-- camel version -->
<camel.version>2.15.1.redhat-620133</camel.version>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" path="src/main/resources"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.fusesource.ide.sap.ui.tests.integration</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

0 comments on commit 8508566

Please sign in to comment.