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 org.eclipse.xtend.lib.annotations.Accessors
import org.joinedworkz.core.model.CmnOperationParameter
import org.joinedworkz.core.model.CmnResource
import org.joinedworkz.core.model.CmnResourceOperation
import java.util.List
import org.joinedworkz.core.model.Verb
import org.joinedworkz.core.model.CmnContent
import org.joinedworkz.core.model.CmnProperty
import java.util.Map
import org.joinedworkz.core.model.CmnFieldSet
import org.joinedworkz.core.model.CmnComplexType
import org.joinedworkz.core.model.CmnNamedObject
@Accessors
class MergedResourceOperationInfo {
final String parentPath
final String idPrefix
final Verb verb;
final String operationType
final boolean instanceOperation
final CmnContent consumes
final CmnResource operationResource
List operations
String path;
CmnResource resource
List parentParameters
List queryParameters
Map properties = newLinkedHashMap
CmnNamedObject filter
boolean sorted
CmnComplexType errorResponse
new (ResourceOperationInfo firstOperationInfo) {
this.parentPath = firstOperationInfo.parentPath
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
if (firstOperationInfo.operation.queryParameters !== null) {
queryParameters = newArrayList
queryParameters.addAll(firstOperationInfo.operation.queryParameters)
}
filter = firstOperationInfo.operation.getFilter
sorted = firstOperationInfo.operation.isSorted
errorResponse = firstOperationInfo.operation.getErrorResponse
consumes = firstOperationInfo.operation.consumes
if (firstOperationInfo.operation.properties !== null) {
for (propertyEntry : firstOperationInfo.operation.properties) {
properties.put(propertyEntry.key, propertyEntry.value)
}
}
}
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 operation) {
val fieldFilters = operation.getProperty("sorting")
if (fieldFilters !== null) {
val value = fieldFilters.value
return value instanceof Boolean && value as Boolean
} else {
return false
}
}
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 = newArrayList
}
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
}
}