Skip to content

Commit

Permalink
[OPENENGSB-3776] better support for xlink switch
Browse files Browse the repository at this point in the history
  • Loading branch information
stfnsche committed Oct 8, 2014
1 parent d5d8bf1 commit 68f3ac2
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 27 deletions.
20 changes: 17 additions & 3 deletions api/core/src/main/java/org/openengsb/core/api/LinkingSupport.java
Expand Up @@ -17,7 +17,10 @@

package org.openengsb.core.api;

import org.openengsb.core.api.model.ModelDescription;
import org.openengsb.core.api.xlink.model.XLinkConnectorView;
import org.openengsb.core.api.xlink.model.XLinkObject;
import org.openengsb.core.api.xlink.service.XLinkConnectorManager;


/**
Expand All @@ -28,8 +31,19 @@
public interface LinkingSupport {

/**
* PushMethod to transfer a List of potential Matches, of modelObjects, to the Clienttool. Also defines the Id of
* View to open Matches in. The transfered modelObjects are instances of the Clienttools model.
* Callback method that is triggered as a response
* to {@link XLinkConnectorManager#requestXLinkSwitch(String, String, Object, boolean)}.
*
* @param xLinkObjects the list of {@link XLinkObject}s that can be opened.
*/
void openXLinks(XLinkObject[] xLinkObjects);
void showXLinks(XLinkObject[] xLinkObjects);

/**
* Implementors should open the requested view with the given object.
*
* @param modelDescription the model description
* @param modelObject the model object to display
* @param view the view to display the model object with
*/
void openXLink(ModelDescription modelDescription, Object modelObject, XLinkConnectorView view);
}
Expand Up @@ -25,6 +25,8 @@
public class XLinkObject implements Serializable {
private static final long serialVersionUID = 1L;

private String connectorId;
private String applicationName;
private Object modelObject;
private ModelDescription modelDescription;
private List<XLinkConnectorView> views;
Expand All @@ -33,12 +35,22 @@ public XLinkObject() {

}

public XLinkObject(Object modelObject, ModelDescription modelDescription, List<XLinkConnectorView> views) {
public XLinkObject(String connectorId, String applicationName, Object modelObject, ModelDescription modelDescription, List<XLinkConnectorView> views) {
this.connectorId = connectorId;
this.applicationName = applicationName;
this.modelObject = modelObject;
this.modelDescription = modelDescription;
this.views = views;
}

public String getConnectorId() {
return connectorId;
}

public String getApplicationName() {
return applicationName;
}

public Object getModelObject() {
return modelObject;
}
Expand Down
Expand Up @@ -55,20 +55,20 @@ void registerWithXLink(String connectorId, String remoteHostId, String toolName,

/**
*
* @param connectorId
* @param modelObject
* @param connectorId the requestor's connector id.
* @param context
* @param modelObject
* @param hostOnly
* @return
* @return the XLink-URL
*/
String publishXLink(String connectorId, String context, Object modelObject, boolean hostOnly);
String requestXLinkSwitch(String connectorId, String context, Object modelObject, boolean hostOnly);

/**
*
* @param connectorId
* @param connectorId the requestor's connector id.
* @param context
* @param modelObject
* @return
* @param modelObject the model object to generate an xlink for.
* @return the XLink-URL
*/
String generateXLink(String connectorId, String context, Object modelObject);
}
Expand Up @@ -94,27 +94,27 @@ public List<XLinkConnectorRegistration> getXLinkRegistrations(String hostId) {
}

@Override
public String publishXLink(String connectorId, String context, Object modelObject, boolean hostOnly) {
public String requestXLinkSwitch(String connectorId, String context, Object modelObject, boolean hostOnly) {
XLinkConnectorRegistration registration = xLinkRegistrations.get(connectorId);
Collection<XLinkConnectorRegistration> registrations = hostOnly
? getXLinkRegistrations(registration.getHostId())
: xLinkRegistrations.values();

ModelDescription modelDescription = ModelWrapper.wrap(modelObject).getModelDescription();
List<XLinkObject> xLinkObjects = new ArrayList<>();
for (XLinkConnectorRegistration r : registrations) {
List<XLinkObject> xLinkObjects = collectXLinkObjects(modelObject, modelDescription, r);
if (!xLinkObjects.isEmpty()) {
Object connector = getUtilsService().getService("(service.pid=" + r.getConnectorId() + ")", 100L);
if (connector == null) {
throw new IllegalStateException("registered connector not there");
}
try {
LinkingSupport service = (LinkingSupport) connector;

service.openXLinks(xLinkObjects.toArray(new XLinkObject[xLinkObjects.size()]));
} catch (ClassCastException e) {
throw new DomainNotLinkableException();
}
xLinkObjects.addAll(collectXLinkObjects(modelObject, modelDescription, r));
}
if (!xLinkObjects.isEmpty()) {
Object connector = getUtilsService().getService("(service.pid=" + connectorId + ")", 100L);
if (connector == null) {
throw new IllegalStateException("requestor connector not there");
}
try {
LinkingSupport service = (LinkingSupport) connector;
service.showXLinks(xLinkObjects.toArray(new XLinkObject[xLinkObjects.size()]));
} catch (ClassCastException e) {
throw new DomainNotLinkableException();
}
}

Expand All @@ -126,10 +126,10 @@ private List<XLinkObject> collectXLinkObjects(Object modelObject, ModelDescripti
List<XLinkObject> xLinkObjects = new ArrayList<>();
for (Entry<ModelDescription, XLinkConnectorView[]> entry : registration.getModelsToViews().entrySet()) {
if (modelDescription.equals(entry.getKey())) {
xLinkObjects.add(new XLinkObject(modelObject, modelDescription, Arrays.asList(entry.getValue())));
xLinkObjects.add(new XLinkObject(registration.getConnectorId(), registration.getToolName(), modelObject, modelDescription, Arrays.asList(entry.getValue())));
} else if (transformationEngine.isTransformationPossible(modelDescription, entry.getKey())) {
Object transformedObject = transformAndMerge(modelDescription, entry.getKey(), modelObject);
xLinkObjects.add(new XLinkObject(transformedObject, entry.getKey(), Arrays.asList(entry.getValue())));
xLinkObjects.add(new XLinkObject(registration.getConnectorId(), registration.getToolName(), transformedObject, entry.getKey(), Arrays.asList(entry.getValue())));
}
}

Expand Down

0 comments on commit 68f3ac2

Please sign in to comment.