org.joinedworkz.common.info.MergedResourceOperationInfo.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.info
import java.util.List
import java.util.Map
import org.eclipse.xtend.lib.annotations.Accessors
import org.joinedworkz.core.model.CmnComplexType
import org.joinedworkz.core.model.CmnContent
import org.joinedworkz.core.model.CmnNamedObject
import org.joinedworkz.core.model.CmnOperationParameter
import org.joinedworkz.core.model.CmnProperty
import org.joinedworkz.core.model.CmnProvidedResource
import org.joinedworkz.core.model.CmnResource
import org.joinedworkz.core.model.CmnResourceOperation
import org.joinedworkz.core.model.Verb
import java.util.Set
@Accessors
class MergedResourceOperationInfo {
final String parentPath
final String path
final String idPrefix
final Verb verb;
final String operationType
final boolean instanceOperation
final Set consumes = newLinkedHashSet
final CmnResource operationResource
final CmnProvidedResource providedResource
Set operations
CmnResource resource
List parentParameters
List queryParameters
Map properties = newLinkedHashMap
boolean vendorSpecificMimeType
CmnNamedObject filter
boolean filteredByExpression
boolean sorted
boolean paginated
CmnComplexType errorResponse
final List operationParts = newArrayList
new (ResourceOperationInfo firstOperationInfo, boolean vendorSpecificMimeType) {
this.parentPath = firstOperationInfo.parentPath
this.path = firstOperationInfo.path
this.verb = firstOperationInfo.verb
this.operationType = firstOperationInfo.operation.operationType
this.operationResource = firstOperationInfo.operationResource;
this.idPrefix = firstOperationInfo.idPrefix
this.instanceOperation = firstOperationInfo.operation.instanceOperation
this.resource = firstOperationInfo.resource
this.vendorSpecificMimeType = vendorSpecificMimeType
this.providedResource = firstOperationInfo.providedResource
if (firstOperationInfo.operation.queryParameters !== null) {
queryParameters = newArrayList
queryParameters.addAll(firstOperationInfo.operation.queryParameters)
}
/* add properties of first operation */
if (firstOperationInfo.operation.properties !== null) {
for (propertyEntry : firstOperationInfo.operation.properties) {
properties.put(propertyEntry.key, propertyEntry.value)
}
}
filter = firstOperationInfo.operation.getFilter
errorResponse = firstOperationInfo.operation.getErrorResponse
}
def setup() {
/* add properties from other operations if not already present */
this.operations = operations
if (operations !== null) {
for (operation : operations) {
for (property : operation.properties) {
properties.putIfAbsent(property.key, property.value)
}
}
}
sorted = getProperty("sorting").isTrue || getProperty("sort").isTrue
paginated = getProperty("paging").isTrue() || getProperty("pagination").isTrue()
filteredByExpression = getProperty("filter").isTrue
}
def CmnNamedObject getFilter(CmnResourceOperation operation) {
val filter = operation.getProperty("filter")
if (filter !== null) {
val value = filter.value
if (value instanceof CmnNamedObject) {
return value
}
}
}
def boolean isSorted(CmnResourceOperation it) {
return getProperty("sorting").isTrue || getProperty("sort").isTrue
}
def boolean isFiltered(CmnResourceOperation it) {
return getProperty("filter").isTrue
}
def String getOperationName() {
if (operations !== null && operations.size === 1) {
return operations.get(0).name
}
}
def CmnComplexType getErrorResponse(CmnResourceOperation operation) {
val fieldFilters = operation.getProperty("errorResponse")
if (fieldFilters !== null) {
val value = fieldFilters.value
if (value instanceof CmnComplexType) {
return value
}
}
}
def addParentPathParameters(List parameters) {
if (parameters !== null) {
if (parentParameters === null) {
parentParameters = newArrayList
}
parentParameters.addAll(parameters)
}
}
def addOperation(CmnResourceOperation operation) {
if (operation !== null) {
if (operations === null) {
operations = newLinkedHashSet
}
operations.add(operation)
}
}
def boolean returnsMultiple() {
if (operations !== null && !operations.empty) {
val firstOperation = operations.head
val Integer maxOccurs = firstOperation.responses?.head?.content?.maxOccurs
return maxOccurs !== null && maxOccurs != 1
} else {
return false
}
}
def CmnProperty getProperty(String propertyName) {
if (properties !== null) {
return properties.get(propertyName)
}
return null
}
def boolean isTrue(String propertyName) {
val property = getProperty(propertyName)
return property.isTrue
}
def boolean isTrue(CmnProperty property) {
if (property !== null) {
val propertyValue = property.value
if (propertyValue instanceof Boolean) {
return (propertyValue as Boolean).booleanValue
}
}
return false
}
def getVerb() {
return verb
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy