org.joinedworkz.common.helper.ScenarioHelper.xtend 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 javax.inject.Singleton
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.CmnProvidedAction
import org.joinedworkz.core.model.CmnProvidedFeature
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.CmnService
import org.joinedworkz.core.model.ux.CmnPageContentElement
import org.joinedworkz.core.model.ux.CmnPage
import org.joinedworkz.core.model.CmnOperationContainer
import org.joinedworkz.core.model.CmnProvidedFeatureImplementation
@Singleton
class ScenarioHelper {
def CharSequence stringRepresentation(CmnProvidedFeatureImplementation it) {
if (it instanceof CmnImplementedFeature) {
if (resourceOperation !== null) {
return stringRepresentation(targetFeature) + "." + resourceOperation.operationType
} else if (operation !== null) {
return stringRepresentation(targetFeature) + "." + operation.operationTitle
} else {
return stringRepresentation(targetFeature)
}
} else if (it instanceof CmnProvidedFeature) {
return stringRepresentation(it as CmnProvidedFeature)
}
}
def CharSequence stringRepresentation(CmnOperation it) {
return (container as CmnService).name + '.' + name
}
def CharSequence stringRepresentation(CmnComponentFeature it) {
if (it instanceof CmnProvidedFeature) {
stringRepresentation
} else if (it instanceof CmnPage) {
return name
}
}
def CharSequence stringRepresentation(CmnProvidedFeature it) {
if (it instanceof CmnProvidedService) {
return it.operationContainer.name
} else if (it instanceof CmnProvidedResource) {
return '/' + resourcePath.map[stringRepresentation].join('/')
} else if (it instanceof CmnProvidedOperation) {
val operationContainer = it.operationContainer !== null ? it.operationContainer : it.operation.container as CmnOperationContainer
return operationContainer.name+"."+it.operation.operationTitle
} else if (it instanceof CmnPageContentElement) {
return containingPage?.name + "." + name
} else if (it instanceof CmnProvidedAction) {
return containingPage?.name + "." + operationName
}
}
def CharSequence stringRepresentation(CmnResource it) {
if (name !== null) {
return name
}
if (identifiers !==null && !identifiers.empty) {
return stringRepresentationOfIdentifiers
}
}
def CharSequence stringRepresentationIncludingIdentifiers(CmnResource it) {
if (name !== null) {
if (identifiers !==null && !identifiers.empty) {
return name + "/" + stringRepresentationOfIdentifiers
} else {
return name
}
}
if (identifiers !==null && !identifiers.empty) {
return stringRepresentationOfIdentifiers
}
}
def CharSequence stringRepresentationOfIdentifiers(CmnResource it) {
val size = identifiers.size
if (size === 1) {
return '{' + identifiers.head.name + '}'
} else if (size > 1) {
val buffer = new StringBuilder
var first = true
for (identifier : identifiers) {
if (first) {
first = false
} else {
buffer.append('/')
}
buffer.append('{')
buffer.append(identifier.name)
buffer.append('}')
}
return buffer.toString
}
}
def operationTitle(CmnOperation it) {
if (description !== null) {
return description
} else {
return name
}
}
def CmnPage containingPage(CmnObject obj) {
val container = obj.container
if (container instanceof CmnPage) {
return container
} else if (container !== null) {
return containingPage(container)
}
}
def CmnComponent containingComponent(CmnProvidedFeatureImplementation it) {
if (it instanceof CmnProvidedFeature) {
return containingComponent(it as CmnProvidedFeature)
} else if (it instanceof CmnObject) {
return containingComponent(it as CmnObject)
}
}
def CmnComponent containingComponent(CmnProvidedFeature providedFeature) {
if (providedFeature instanceof CmnProvidedOperation) {
if (providedFeature.component === null) {
throw new RuntimeException("CmnProvidedOperation.component, component undefined, operation: "+ providedFeature.operation.name)
}
return providedFeature.component
}
if (providedFeature instanceof CmnObject) {
return (providedFeature as CmnObject).containingComponent
}
}
def CmnComponent containingComponent(CmnObject obj) {
val container = obj.container
if (container instanceof CmnComponent) {
return container
} else if (container !== null) {
return containingComponent(container)
}
}
}