org.joinedworkz.common.helper.ScenarioHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of common-base Show documentation
Show all versions of common-base Show documentation
DSL based modeling framework - facilities common base
package org.joinedworkz.common.helper;
import java.util.List;
import javax.inject.Singleton;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.ListExtensions;
import org.joinedworkz.core.model.CmnComponent;
import org.joinedworkz.core.model.CmnComponentFeature;
import org.joinedworkz.core.model.CmnImplementedFeature;
import org.joinedworkz.core.model.CmnObject;
import org.joinedworkz.core.model.CmnOperation;
import org.joinedworkz.core.model.CmnOperationContainer;
import org.joinedworkz.core.model.CmnOperationParameter;
import org.joinedworkz.core.model.CmnProvidedAction;
import org.joinedworkz.core.model.CmnProvidedFeature;
import org.joinedworkz.core.model.CmnProvidedFeatureImplementation;
import org.joinedworkz.core.model.CmnProvidedOperation;
import org.joinedworkz.core.model.CmnProvidedResource;
import org.joinedworkz.core.model.CmnProvidedService;
import org.joinedworkz.core.model.CmnResource;
import org.joinedworkz.core.model.CmnResourceOperation;
import org.joinedworkz.core.model.CmnService;
import org.joinedworkz.core.model.ux.CmnPage;
import org.joinedworkz.core.model.ux.CmnPageContentElement;
@Singleton
@SuppressWarnings("all")
public class ScenarioHelper {
public CharSequence stringRepresentation(final CmnProvidedFeatureImplementation it) {
if ((it instanceof CmnImplementedFeature)) {
CmnResourceOperation _resourceOperation = ((CmnImplementedFeature)it).getResourceOperation();
boolean _tripleNotEquals = (_resourceOperation != null);
if (_tripleNotEquals) {
CharSequence _stringRepresentation = this.stringRepresentation(((CmnImplementedFeature)it).getTargetFeature());
String _plus = (_stringRepresentation + ".");
String _operationType = ((CmnImplementedFeature)it).getResourceOperation().getOperationType();
return (_plus + _operationType);
} else {
CmnOperation _operation = ((CmnImplementedFeature)it).getOperation();
boolean _tripleNotEquals_1 = (_operation != null);
if (_tripleNotEquals_1) {
CharSequence _stringRepresentation_1 = this.stringRepresentation(((CmnImplementedFeature)it).getTargetFeature());
String _plus_1 = (_stringRepresentation_1 + ".");
String _operationTitle = this.operationTitle(((CmnImplementedFeature)it).getOperation());
return (_plus_1 + _operationTitle);
} else {
return this.stringRepresentation(((CmnImplementedFeature)it).getTargetFeature());
}
}
} else {
if ((it instanceof CmnProvidedFeature)) {
return this.stringRepresentation(((CmnProvidedFeature) it));
}
}
return null;
}
public CharSequence stringRepresentation(final CmnOperation it) {
CmnObject _container = it.getContainer();
String _name = ((CmnService) _container).getName();
String _plus = (_name + ".");
String _name_1 = it.getName();
return (_plus + _name_1);
}
public CharSequence stringRepresentation(final CmnComponentFeature it) {
CharSequence _xifexpression = null;
if ((it instanceof CmnProvidedFeature)) {
_xifexpression = this.stringRepresentation(((CmnProvidedFeature)it));
} else {
if ((it instanceof CmnPage)) {
return ((CmnPage)it).getName();
}
}
return _xifexpression;
}
public CharSequence stringRepresentation(final CmnProvidedFeature it) {
if ((it instanceof CmnProvidedService)) {
return ((CmnProvidedService)it).getOperationContainer().getName();
} else {
if ((it instanceof CmnProvidedResource)) {
final Function1 _function = (CmnResource it_1) -> {
return this.stringRepresentation(it_1);
};
String _join = IterableExtensions.join(ListExtensions.map(((CmnProvidedResource)it).getResourcePath(), _function), "/");
return ("/" + _join);
} else {
if ((it instanceof CmnProvidedOperation)) {
CmnOperationContainer _xifexpression = null;
CmnOperationContainer _operationContainer = ((CmnProvidedOperation)it).getOperationContainer();
boolean _tripleNotEquals = (_operationContainer != null);
if (_tripleNotEquals) {
_xifexpression = ((CmnProvidedOperation)it).getOperationContainer();
} else {
CmnObject _container = ((CmnProvidedOperation)it).getOperation().getContainer();
_xifexpression = ((CmnOperationContainer) _container);
}
final CmnOperationContainer operationContainer = _xifexpression;
String _name = operationContainer.getName();
String _plus = (_name + ".");
String _operationTitle = this.operationTitle(((CmnProvidedOperation)it).getOperation());
return (_plus + _operationTitle);
} else {
if ((it instanceof CmnPageContentElement)) {
CmnPage _containingPage = this.containingPage(((CmnObject)it));
String _name_1 = null;
if (_containingPage!=null) {
_name_1=_containingPage.getName();
}
String _plus_1 = (_name_1 + ".");
String _name_2 = ((CmnPageContentElement)it).getName();
return (_plus_1 + _name_2);
} else {
if ((it instanceof CmnProvidedAction)) {
CmnPage _containingPage_1 = this.containingPage(((CmnObject)it));
String _name_3 = null;
if (_containingPage_1!=null) {
_name_3=_containingPage_1.getName();
}
String _plus_2 = (_name_3 + ".");
String _operationName = ((CmnProvidedAction)it).getOperationName();
return (_plus_2 + _operationName);
}
}
}
}
}
return null;
}
public CharSequence stringRepresentation(final CmnResource it) {
String _name = it.getName();
boolean _tripleNotEquals = (_name != null);
if (_tripleNotEquals) {
return it.getName();
}
if (((it.getIdentifiers() != null) && (!it.getIdentifiers().isEmpty()))) {
return this.stringRepresentationOfIdentifiers(it);
}
return null;
}
public CharSequence stringRepresentationIncludingIdentifiers(final CmnResource it) {
String _name = it.getName();
boolean _tripleNotEquals = (_name != null);
if (_tripleNotEquals) {
if (((it.getIdentifiers() != null) && (!it.getIdentifiers().isEmpty()))) {
String _name_1 = it.getName();
String _plus = (_name_1 + "/");
CharSequence _stringRepresentationOfIdentifiers = this.stringRepresentationOfIdentifiers(it);
return (_plus + _stringRepresentationOfIdentifiers);
} else {
return it.getName();
}
}
if (((it.getIdentifiers() != null) && (!it.getIdentifiers().isEmpty()))) {
return this.stringRepresentationOfIdentifiers(it);
}
return null;
}
public CharSequence stringRepresentationOfIdentifiers(final CmnResource it) {
final int size = it.getIdentifiers().size();
if ((size == 1)) {
String _name = IterableExtensions.head(it.getIdentifiers()).getName();
String _plus = ("{" + _name);
return (_plus + "}");
} else {
if ((size > 1)) {
final StringBuilder buffer = new StringBuilder();
boolean first = true;
List _identifiers = it.getIdentifiers();
for (final CmnOperationParameter identifier : _identifiers) {
{
if (first) {
first = false;
} else {
buffer.append("/");
}
buffer.append("{");
buffer.append(identifier.getName());
buffer.append("}");
}
}
return buffer.toString();
}
}
return null;
}
public String operationTitle(final CmnOperation it) {
String _description = it.getDescription();
boolean _tripleNotEquals = (_description != null);
if (_tripleNotEquals) {
return it.getDescription();
} else {
return it.getName();
}
}
public CmnPage containingPage(final CmnObject obj) {
final CmnObject container = obj.getContainer();
if ((container instanceof CmnPage)) {
return ((CmnPage)container);
} else {
if ((container != null)) {
return this.containingPage(container);
}
}
return null;
}
public CmnComponent containingComponent(final CmnProvidedFeatureImplementation it) {
if ((it instanceof CmnProvidedFeature)) {
return this.containingComponent(((CmnProvidedFeature) it));
} else {
if ((it instanceof CmnObject)) {
return this.containingComponent(((CmnObject) it));
}
}
return null;
}
public CmnComponent containingComponent(final CmnProvidedFeature providedFeature) {
if ((providedFeature instanceof CmnProvidedOperation)) {
CmnComponent _component = ((CmnProvidedOperation)providedFeature).getComponent();
boolean _tripleEquals = (_component == null);
if (_tripleEquals) {
String _name = ((CmnProvidedOperation)providedFeature).getOperation().getName();
String _plus = ("CmnProvidedOperation.component, component undefined, operation: " + _name);
throw new RuntimeException(_plus);
}
return ((CmnProvidedOperation)providedFeature).getComponent();
}
if ((providedFeature instanceof CmnObject)) {
return this.containingComponent(((CmnObject) providedFeature));
}
return null;
}
public CmnComponent containingComponent(final CmnObject obj) {
final CmnObject container = obj.getContainer();
if ((container instanceof CmnComponent)) {
return ((CmnComponent)container);
} else {
if ((container != null)) {
return this.containingComponent(container);
}
}
return null;
}
}