All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.joinedworkz.common.helper.CmnModelHelper Maven / Gradle / Ivy

There is a newer version: 1.3.46
Show newest version
package org.joinedworkz.common.helper;

import com.google.common.base.Objects;
import com.google.common.collect.Iterables;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
import org.eclipse.xtext.xbase.lib.Extension;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.joinedworkz.common.adapter.KeyAdapter;
import org.joinedworkz.common.strategies.ColumnNameStrategy;
import org.joinedworkz.common.strategies.TableNameStrategy;
import org.joinedworkz.core.model.CmnComplexType;
import org.joinedworkz.core.model.CmnElement;
import org.joinedworkz.core.model.CmnEnumeration;
import org.joinedworkz.core.model.CmnField;
import org.joinedworkz.core.model.CmnFieldContainer;
import org.joinedworkz.core.model.CmnFieldSet;
import org.joinedworkz.core.model.CmnModel;
import org.joinedworkz.core.model.CmnNamedObject;
import org.joinedworkz.core.model.CmnObject;
import org.joinedworkz.core.model.CmnOperation;
import org.joinedworkz.core.model.CmnOperationParameter;
import org.joinedworkz.core.model.CmnProperty;
import org.joinedworkz.core.model.CmnType;

@Singleton
@SuppressWarnings("all")
public class CmnModelHelper {
  @Inject
  private TableNameStrategy tableNameStrategy;

  @Inject
  private ColumnNameStrategy columnNameStrategy;

  @Inject
  private Inflector inflector;

  private static final char BRACKET = '(';

  private static final char DOT = '.';

  @Extension
  protected NameHelper nameHelper = new NameHelper();

  protected static final String JAVA_NAME = "javaName";

  protected static final String JAVA_TYPE = "javaType";

  protected static final String TABLE_NAME = "tableName";

  protected static final String COLUMN_NAME = "columnName";

  protected static final String COLUMN_TYPE = "columnType";

  public String lastSegment(final String type) {
    if ((type != null)) {
      final int bracketIndex = type.indexOf(CmnModelHelper.BRACKET);
      int relevantDotIndex = (-1);
      if ((bracketIndex > 0)) {
        final String beforeBracket = type.substring(0, bracketIndex);
        relevantDotIndex = beforeBracket.lastIndexOf(CmnModelHelper.DOT);
      } else {
        relevantDotIndex = type.lastIndexOf(CmnModelHelper.DOT);
      }
      if ((relevantDotIndex > 0)) {
        return type.substring((relevantDotIndex + 1));
      }
    }
    return type;
  }

  public String packageSegments(final String type) {
    if ((type != null)) {
      final int lastDotIndex = type.lastIndexOf(".");
      if ((lastDotIndex > 0)) {
        return type.substring(0, lastDotIndex);
      }
    }
    return type;
  }

  public CmnModel getModel(final CmnElement cmnObject) {
    if ((cmnObject instanceof CmnModel)) {
      return ((CmnModel)cmnObject);
    } else {
      CmnObject _container = cmnObject.getContainer();
      boolean _tripleNotEquals = (_container != null);
      if (_tripleNotEquals) {
        return this.getModel(cmnObject.getContainer());
      } else {
        Class _class = null;
        if (cmnObject!=null) {
          _class=cmnObject.getClass();
        }
        String _canonicalName = _class.getCanonicalName();
        String _plus = ("Model not found for element of type " + _canonicalName);
        throw new RuntimeException(_plus);
      }
    }
  }

  public Iterable concreteFieldContainers(final CmnModel model) {
    final Function1 _function = (CmnObject e) -> {
      return Boolean.valueOf(this.isDtoObject(e));
    };
    final Function1 _function_1 = (CmnFieldContainer it) -> {
      return Boolean.valueOf(this.isConcrete(it));
    };
    return IterableExtensions.filter(Iterables.filter(IterableExtensions.filter(model.getModelElements(), _function), CmnFieldContainer.class), _function_1);
  }

  public boolean isDtoObject(final CmnObject it) {
    return ((it instanceof CmnFieldContainer) && (!(it instanceof CmnFieldSet)));
  }

  public boolean isConcrete(final CmnFieldContainer it) {
    return ((it.getAbstract() == null) || (!(it.getAbstract()).booleanValue()));
  }

  public boolean multipleOccurences(final Integer maxOccurs) {
    return ((maxOccurs != null) && (1 != (maxOccurs).intValue()));
  }

  public CmnFieldContainer getBaseFieldContainer(final CmnElement it) {
    if ((it instanceof CmnType)) {
      final CmnType baseType = ((CmnType)it).getBaseType();
      if ((baseType instanceof CmnComplexType)) {
        return ((CmnFieldContainer)baseType);
      }
    }
    return null;
  }

  public Set collectBaseTypes(final Set types) {
    LinkedHashSet collectedTypes = CollectionLiterals.newLinkedHashSet();
    for (final CmnType type : types) {
      this.addBaseTypeRecursive(collectedTypes, type);
    }
    return collectedTypes;
  }

  public void addBaseTypeRecursive(final Set collectedTypes, final CmnType type) {
    final CmnType baseType = type.getBaseType();
    if ((baseType != null)) {
      collectedTypes.add(baseType);
      this.addBaseTypeRecursive(collectedTypes, baseType);
    }
  }

  public String getName(final CmnElement cmnObject) {
    if ((cmnObject instanceof CmnNamedObject)) {
      return ((CmnNamedObject)cmnObject).getName();
    }
    return null;
  }

  public Integer getInteger(final CmnObject object, final String propertyName) {
    final CmnProperty property = object.getProperty(propertyName);
    if ((property != null)) {
      final Object propertyValue = property.getValue();
      if ((propertyValue instanceof Integer)) {
        return ((Integer) propertyValue);
      }
    }
    return null;
  }

  public Boolean getBoolean(final CmnObject object, final String propertyName) {
    final CmnProperty property = object.getProperty(propertyName);
    if ((property != null)) {
      final Object propertyValue = property.getValue();
      if ((propertyValue instanceof Boolean)) {
        return ((Boolean) propertyValue);
      }
    }
    return null;
  }

  public boolean isTrue(final CmnObject object, final String propertyName) {
    final CmnProperty property = object.getProperty(propertyName);
    if ((property != null)) {
      final Object propertyValue = property.getValue();
      if ((propertyValue instanceof Boolean)) {
        return ((Boolean) propertyValue).booleanValue();
      }
    }
    return false;
  }

  public String determineEnumType(final CmnType type) {
    if ((type instanceof CmnEnumeration)) {
      String _xifexpression = null;
      boolean _hasStereoType = this.hasStereoType(type, "integer");
      if (_hasStereoType) {
        _xifexpression = "Integer";
      } else {
        _xifexpression = null;
      }
      return _xifexpression;
    }
    return null;
  }

  public String javaType(final CmnElement object) {
    final String javaType = this.javaTypeProperty(object);
    if ((javaType != null)) {
      return javaType;
    }
    if ((object instanceof CmnField)) {
      CmnType _type = ((CmnField)object).getType();
      String _name = null;
      if (_type!=null) {
        _name=_type.getName();
      }
      return _name;
    } else {
      if ((object instanceof CmnType)) {
        return ((CmnType)object).getName();
      }
    }
    return null;
  }

  public String javaTypeProperty(final CmnElement it) {
    return it.getString(CmnModelHelper.JAVA_TYPE);
  }

  public CmnType keyType(final CmnType it) {
    if ((it instanceof CmnFieldContainer)) {
      CmnField _keyFieldOfType = this.keyFieldOfType(it);
      CmnType _type = null;
      if (_keyFieldOfType!=null) {
        _type=_keyFieldOfType.getType();
      }
      return _type;
    }
    return null;
  }

  public String keyJavaName(final CmnType it) {
    if ((it instanceof CmnFieldContainer)) {
      CmnField _keyFieldOfType = this.keyFieldOfType(it);
      String _javaName = null;
      if (_keyFieldOfType!=null) {
        _javaName=this.javaName(_keyFieldOfType);
      }
      return _javaName;
    }
    return null;
  }

  public CmnField keyFieldOfType(final CmnType it) {
    if ((it instanceof CmnFieldContainer)) {
      KeyAdapter keyAdapter = it.getAdapter(KeyAdapter.class);
      if ((keyAdapter == null)) {
        List _keyFields = ((CmnFieldContainer)it).getKeyFields();
        CmnField _head = null;
        if (_keyFields!=null) {
          _head=IterableExtensions.head(_keyFields);
        }
        CmnField keyField = _head;
        if ((keyField == null)) {
          CmnType _baseType = it.getBaseType();
          CmnField _keyFieldOfType = null;
          if (_baseType!=null) {
            _keyFieldOfType=this.keyFieldOfType(_baseType);
          }
          keyField = _keyFieldOfType;
        }
        if ((keyField == null)) {
          String _name = it.getName();
          String _plus = ("Key field not found of type: " + _name);
          System.err.println(_plus);
          int _size = ((CmnFieldContainer)it).getKeyFields().size();
          String _plus_1 = ("Key fields size: " + Integer.valueOf(_size));
          System.err.println(_plus_1);
          String _name_1 = it.getName();
          String _plus_2 = ("No key fields found for type: " + _name_1);
          throw new IllegalStateException(_plus_2);
        }
        KeyAdapter _keyAdapter = new KeyAdapter(keyField);
        keyAdapter = _keyAdapter;
        it.putAdapter(keyAdapter);
      }
      return keyAdapter.getKeyField();
    }
    return null;
  }

  public boolean isKey(final CmnField it) {
    boolean _xifexpression = false;
    CmnObject _container = it.getContainer();
    if ((_container instanceof CmnFieldContainer)) {
      CmnObject _container_1 = it.getContainer();
      return this.containsKeyField(((CmnFieldContainer) _container_1), it);
    } else {
      _xifexpression = this.hasStereoType(it, "key");
    }
    return _xifexpression;
  }

  public boolean containsKeyField(final CmnFieldContainer container, final CmnField field) {
    List _keyFields = container.getKeyFields();
    boolean _contains = false;
    if (_keyFields!=null) {
      _contains=_keyFields.contains(field);
    }
    final boolean containsKey = _contains;
    if (containsKey) {
      return true;
    } else {
      CmnObject _container = container.getContainer();
      if ((_container instanceof CmnFieldContainer)) {
        CmnObject _container_1 = container.getContainer();
        final boolean containerContainsKey = this.containsKeyField(((CmnFieldContainer) _container_1), field);
        if (containsKey) {
          return true;
        }
      }
    }
    return this.hasStereoType(field, "key");
  }

  public String javaType(final CmnOperationParameter object) {
    CmnType _type = object.getType();
    boolean _tripleNotEquals = (_type != null);
    if (_tripleNotEquals) {
      return this.javaType(object.getType());
    } else {
      CmnField _referencedField = object.getReferencedField();
      boolean _tripleNotEquals_1 = (_referencedField != null);
      if (_tripleNotEquals_1) {
        return this.javaDtoFieldType(object.getReferencedField());
      }
    }
    return null;
  }

  public CmnType dtoFieldType(final CmnField field) {
    boolean _isReferenceField = this.isReferenceField(field);
    if (_isReferenceField) {
      final CmnType keyFieldType = this.keyType(this.referencedRootField(field).getType());
      if ((keyFieldType == null)) {
        String _name = field.getName();
        String _plus = ("Error: key type not found for field " + _name);
        String _plus_1 = (_plus + " of type ");
        String _name_1 = field.getType().getName();
        String _plus_2 = (_plus_1 + _name_1);
        System.err.println(_plus_2);
      }
      return keyFieldType;
    } else {
      return field.getType();
    }
  }

  public CmnField referencedRootField(final CmnField field) {
    if (((field.getSourceField() != null) && (!this.isRelationField(field)))) {
      String _name = this.getName(field.getContainer());
      String _plus = ("Get root of: " + _name);
      String _plus_1 = (_plus + ".");
      String _name_1 = field.getName();
      String _plus_2 = (_plus_1 + _name_1);
      System.out.println(_plus_2);
      return this.referencedRootField(field.getSourceField());
    } else {
      return field;
    }
  }

  public Iterable collectAllReferences(final CmnFieldContainer it, final List references) {
    final Function1 _function = (CmnField it_1) -> {
      return Boolean.valueOf(this.isReferenceField(it_1));
    };
    Iterables.addAll(references, IterableExtensions.filter(it.getFields(), _function));
    final CmnFieldContainer base = this.getBaseFieldContainer(it);
    if ((base != null)) {
      this.collectAllReferences(base, references);
    }
    return references;
  }

  public Iterable collectReferencesToBeImplemented(final CmnFieldContainer it, final List references) {
    final Function1 _function = (CmnField it_1) -> {
      return Boolean.valueOf(this.isReferenceField(it_1));
    };
    Iterables.addAll(references, IterableExtensions.filter(it.getFields(), _function));
    final CmnFieldContainer base = this.getBaseFieldContainer(it);
    if (((base != null) && (base.getAbstract()).booleanValue())) {
      this.collectReferencesToBeImplemented(base, references);
    }
    return references;
  }

  public boolean isReferenceField(final CmnField field) {
    Boolean _isReference = field.getIsReference();
    boolean _tripleEquals = (Boolean.TRUE == _isReference);
    if (_tripleEquals) {
      return true;
    } else {
      if (((field.getSourceField() != null) && (!this.isRelationField(field)))) {
        final HashSet processedFields = CollectionLiterals.newHashSet();
        processedFields.add(field);
        return this.isReferenceFieldRecursive(field.getSourceField(), processedFields);
      }
    }
    return false;
  }

  public boolean isReferenceFieldRecursive(final CmnField field, final Set processedFields) {
    boolean _contains = processedFields.contains(field);
    if (_contains) {
      String _name = field.getName();
      String _plus = ("Field already processed: " + _name);
      System.out.println(_plus);
      return false;
    }
    processedFields.add(field);
    Boolean _isReference = field.getIsReference();
    boolean _tripleEquals = (Boolean.TRUE == _isReference);
    if (_tripleEquals) {
      return true;
    } else {
      CmnField _sourceField = field.getSourceField();
      boolean _tripleNotEquals = (_sourceField != null);
      if (_tripleNotEquals) {
        boolean _contains_1 = processedFields.contains(field.getSourceField());
        if (_contains_1) {
          String _name_1 = field.getSourceField().getName();
          String _plus_1 = ("Source field already processed: " + _name_1);
          System.out.println(_plus_1);
          return false;
        }
        return this.isReferenceFieldRecursive(field.getSourceField(), processedFields);
      }
    }
    return false;
  }

  public String javaDtoFieldType(final CmnField field) {
    if ((field != null)) {
      boolean _isReferenceField = this.isReferenceField(field);
      boolean _not = (!_isReferenceField);
      if (_not) {
        final String typeFromProperty = this.javaTypeProperty(field);
        if ((typeFromProperty != null)) {
          return typeFromProperty;
        }
      }
      final CmnType dtoType = this.dtoFieldType(field);
      if ((dtoType != null)) {
        return this.javaType(dtoType);
      } else {
        return "String";
      }
    } else {
      return null;
    }
  }

  public String javaDtoFieldName(final CmnField field) {
    final String fieldName = this.javaName(field);
    boolean _isReferenceField = this.isReferenceField(field);
    if (_isReferenceField) {
      CmnField _sourceField = field.getSourceField();
      boolean _tripleNotEquals = (_sourceField != null);
      if (_tripleNotEquals) {
        final String sourceFieldJavaName = this.sourceFieldJavaNameRecursive(field);
        boolean _notEquals = (!Objects.equal(fieldName, sourceFieldJavaName));
        if (_notEquals) {
          return fieldName;
        }
      }
      final String keyName = this.keyJavaName(field.getType());
      boolean _isCollection = this.isCollection(field);
      if (_isCollection) {
        final String singularFieldName = this.inflector.singularize(fieldName);
        String _xifexpression = null;
        if ((keyName != null)) {
          _xifexpression = this.inflector.pluralize(keyName);
        } else {
          _xifexpression = null;
        }
        final String pluralKeyName = _xifexpression;
        String _firstUpper = null;
        if (pluralKeyName!=null) {
          _firstUpper=this.nameHelper.toFirstUpper(pluralKeyName);
        }
        return (singularFieldName + _firstUpper);
      } else {
        String _firstUpper_1 = null;
        if (keyName!=null) {
          _firstUpper_1=this.nameHelper.toFirstUpper(keyName);
        }
        return (fieldName + _firstUpper_1);
      }
    } else {
      return fieldName;
    }
  }

  public String sourceFieldJavaNameRecursive(final CmnField field) {
    CmnField _sourceField = field.getSourceField();
    boolean _tripleNotEquals = (_sourceField != null);
    if (_tripleNotEquals) {
      return this.sourceFieldJavaNameRecursive(field.getSourceField());
    } else {
      return this.javaName(field);
    }
  }

  public String javaName(final CmnField field) {
    final String javaName = field.getString(CmnModelHelper.JAVA_NAME);
    if ((javaName != null)) {
      return javaName;
    } else {
      return field.getName();
    }
  }

  public String javaName(final CmnOperationParameter it) {
    String _name = it.getName();
    boolean _tripleNotEquals = (_name != null);
    if (_tripleNotEquals) {
      return it.getName();
    } else {
      CmnField _referencedField = it.getReferencedField();
      boolean _tripleNotEquals_1 = (_referencedField != null);
      if (_tripleNotEquals_1) {
        return this.javaDtoFieldName(it.getReferencedField());
      }
    }
    return null;
  }

  public String parameterName(final CmnOperationParameter it) {
    String _name = it.getName();
    boolean _tripleNotEquals = (_name != null);
    if (_tripleNotEquals) {
      return it.getName();
    } else {
      CmnField _referencedField = it.getReferencedField();
      boolean _tripleNotEquals_1 = (_referencedField != null);
      if (_tripleNotEquals_1) {
        return this.javaName(it.getReferencedField());
      }
    }
    return null;
  }

  public String tableName(final CmnElement object) {
    if ((object instanceof CmnFieldContainer)) {
      final String tableName = ((CmnFieldContainer)object).getString(CmnModelHelper.TABLE_NAME);
      if ((tableName != null)) {
        return tableName;
      }
      return this.tableNameStrategy.defaultTableName(((CmnFieldContainer)object));
    }
    return "UNDEFINED_TABLE_NAME";
  }

  public String columnName(final CmnField field) {
    if ((field != null)) {
      final String javaName = field.getString(CmnModelHelper.COLUMN_NAME);
      if ((javaName != null)) {
        return javaName;
      }
      return this.columnNameStrategy.defaultColumnName(field);
    }
    return null;
  }

  public String columnType(final CmnField field) {
    final String columnType = field.getString(CmnModelHelper.COLUMN_TYPE);
    final String javaType = this.javaDtoFieldType(field);
    if ((columnType != null)) {
      return columnType;
    } else {
      if ((javaType != null)) {
        boolean _endsWith = javaType.endsWith("UUID");
        if (_endsWith) {
          return "UUID";
        } else {
          boolean _endsWith_1 = javaType.endsWith("Integer");
          if (_endsWith_1) {
            final Integer precision = this.getInteger(field, "precision");
            if (((precision != null) && ((precision).intValue() < 5))) {
              return "SMALLINT";
            } else {
              return "INTEGER";
            }
          } else {
            boolean _endsWith_2 = javaType.endsWith("Long");
            if (_endsWith_2) {
              return "BIGINT";
            }
          }
        }
      }
    }
    CmnType _type = field.getType();
    if ((_type instanceof CmnEnumeration)) {
      final String enumType = this.determineEnumType(field.getType());
      boolean _equals = Objects.equal(enumType, "Integer");
      if (_equals) {
        return "INTEGER";
      } else {
        return "VARCHAR";
      }
    }
    CmnType _type_1 = field.getType();
    String _name = null;
    if (_type_1!=null) {
      _name=_type_1.getName();
    }
    String _upperCase = null;
    if (_name!=null) {
      _upperCase=_name.toUpperCase();
    }
    final String typeName = _upperCase;
    boolean _hasStereoTypeString = this.hasStereoTypeString(field.getType());
    if (_hasStereoTypeString) {
      boolean _notEquals = (!Objects.equal("TEXT", typeName));
      if (_notEquals) {
        return "VARCHAR";
      }
    }
    return typeName;
  }

  public boolean hasStereoType(final CmnObject it, final String stereoTypeName) {
    return ((it.getStereoTypes() != null) && it.getStereoTypes().contains(stereoTypeName));
  }

  public boolean hasStereoType(final CmnComplexType it, final String stereoTypeName) {
    return ((it.getStereoTypes() != null) && it.getStereoTypes().contains(stereoTypeName));
  }

  public boolean hasStereoType(final CmnFieldContainer it, final String stereoTypeName) {
    return ((it.getStereoTypes() != null) && it.getStereoTypes().contains(stereoTypeName));
  }

  public boolean hasStereoTypeContainedIn(final CmnObject it, final String... stereoTypeNames) {
    Set _stereoTypes = it.getStereoTypes();
    boolean _tripleNotEquals = (_stereoTypes != null);
    if (_tripleNotEquals) {
      for (final String stereoTypeName : stereoTypeNames) {
        boolean _contains = it.getStereoTypes().contains(stereoTypeName);
        if (_contains) {
          return true;
        }
      }
    }
    return false;
  }

  public boolean hasStereoTypeString(final CmnType it) {
    return this.hasStereoType(it, "string");
  }

  public Iterable allFields(final CmnFieldContainer fieldContainer, final boolean pullAllBaseFields) {
    if ((fieldContainer instanceof CmnComplexType)) {
      final Collection allFields = CollectionLiterals.newArrayList();
      this.collectFields(allFields, ((CmnType)fieldContainer), pullAllBaseFields);
      return allFields;
    } else {
      return fieldContainer.getFields();
    }
  }

  public void collectFields(final Collection collectedFields, final CmnType type, final boolean pullAllBaseFields) {
    if ((type instanceof CmnComplexType)) {
      if ((pullAllBaseFields || this.hasAbstractBaseType(((CmnComplexType)type)))) {
        this.collectFields(collectedFields, ((CmnComplexType)type).getBaseType(), pullAllBaseFields);
      }
      collectedFields.addAll(((CmnComplexType)type).getFields());
    }
  }

  public Iterable allDtoFields(final CmnFieldContainer fieldContainer, final boolean pullAllBaseFields) {
    if ((fieldContainer instanceof CmnComplexType)) {
      final Collection allFields = CollectionLiterals.newArrayList();
      this.collectDtoFields(allFields, ((CmnType)fieldContainer), pullAllBaseFields);
      return allFields;
    } else {
      return this.dtoFields(fieldContainer);
    }
  }

  public void collectDtoFields(final Collection collectedFields, final CmnType type, final boolean pullAllBaseFields) {
    if ((type instanceof CmnComplexType)) {
      if ((pullAllBaseFields || this.hasAbstractBaseType(((CmnComplexType)type)))) {
        this.collectFields(collectedFields, ((CmnComplexType)type).getBaseType(), pullAllBaseFields);
      }
      Iterables.addAll(collectedFields, this.dtoFields(((CmnFieldContainer)type)));
    }
  }

  public Iterable dtoFields(final CmnFieldContainer it) {
    final Function1 _function = (CmnField it_1) -> {
      boolean _isM2NRelation = this.isM2NRelation(it_1);
      return Boolean.valueOf((!_isM2NRelation));
    };
    return IterableExtensions.filter(it.getFields(), _function);
  }

  public boolean isM2NRelation(final CmnField it) {
    boolean _isRelationField = this.isRelationField(it);
    if (_isRelationField) {
      return ((this.isCollection(it) && (it.getSourceField() != null)) && this.isCollection(it.getSourceField()));
    } else {
      return false;
    }
  }

  public Collection allOperations(final CmnFieldContainer fieldContainer, final boolean pullAllBaseOperations) {
    final Collection allOperations = CollectionLiterals.newArrayList();
    this.collectOperations(allOperations, fieldContainer, pullAllBaseOperations);
    return allOperations;
  }

  public void collectOperations(final Collection collectedOperations, final CmnElement type, final boolean pullAllBaseOperations) {
    if ((type instanceof CmnComplexType)) {
      if ((pullAllBaseOperations || this.hasAbstractBaseType(((CmnComplexType)type)))) {
        this.collectOperations(collectedOperations, ((CmnComplexType)type).getBaseType(), pullAllBaseOperations);
      }
    }
    if ((type instanceof CmnFieldContainer)) {
      collectedOperations.addAll(((CmnFieldContainer)type).getOperations());
    }
  }

  public CmnType determineReturnType(final CmnOperation operation) {
    CmnType _returnType = operation.getReturnType();
    boolean _tripleNotEquals = (_returnType != null);
    if (_tripleNotEquals) {
      return operation.getReturnType();
    } else {
      CmnOperation _baseOperation = operation.getBaseOperation();
      boolean _tripleNotEquals_1 = (_baseOperation != null);
      if (_tripleNotEquals_1) {
        return this.determineReturnType(operation.getBaseOperation());
      }
    }
    return null;
  }

  public boolean hasAbstractBaseType(final CmnComplexType it) {
    final CmnFieldContainer baseFieldContainer = this.getBaseFieldContainer(it);
    return this.isAbstract(baseFieldContainer);
  }

  public boolean isAbstract(final CmnFieldContainer it) {
    if ((it != null)) {
      final Boolean isAbstract = it.getAbstract();
      return ((isAbstract != null) && (isAbstract).booleanValue());
    } else {
      return false;
    }
  }

  public boolean isAbstract(final CmnOperation it) {
    if ((it != null)) {
      final Boolean isAbstract = it.getAbstract();
      return ((isAbstract != null) && (isAbstract).booleanValue());
    } else {
      return false;
    }
  }

  public boolean isCollection(final CmnField field) {
    return ((field.getMaxOccurs() != null) && (((field.getMaxOccurs()).intValue() < 0) || ((field.getMaxOccurs()).intValue() > 1)));
  }

  public boolean isRelationField(final CmnField it) {
    if (((it.getIsRelation() != null) && (it.getIsRelation()).booleanValue())) {
      return ((this.isCollection(it) && (it.getSourceField() != null)) && this.isCollection(it.getSourceField()));
    } else {
      return false;
    }
  }

  public List getImmutableFields(final CmnFieldContainer it, final boolean recursive) {
    if ((it != null)) {
      final boolean immutable = this.hasStereoType(it, "immutable");
      final ArrayList immutableFields = CollectionLiterals.newArrayList();
      if (recursive) {
        immutableFields.addAll(this.getImmutableFields(this.getBaseFieldContainer(it), true));
      }
      final Function1 _function = (CmnField it_1) -> {
        return Boolean.valueOf((immutable || this.hasStereoType(it_1, "immutable")));
      };
      Iterables.addAll(immutableFields, IterableExtensions.filter(it.getFields(), _function));
      return immutableFields;
    } else {
      return CollectionLiterals.emptyList();
    }
  }

  public boolean hasImmutableFields(final CmnFieldContainer it, final boolean recursive) {
    if ((((it != null) && (it.getFields() != null)) && (!it.getFields().isEmpty()))) {
      boolean _hasStereoType = this.hasStereoType(it, "immutable");
      if (_hasStereoType) {
        return true;
      }
      final Function1 _function = (CmnField it_1) -> {
        return Boolean.valueOf(this.hasStereoType(it_1, "immutable"));
      };
      boolean _exists = IterableExtensions.exists(it.getFields(), _function);
      if (_exists) {
        return true;
      }
      if (recursive) {
        return this.hasImmutableFields(this.getBaseFieldContainer(it), true);
      }
    }
    return false;
  }

  public Iterable allImmutableFields(final CmnFieldContainer complexType) {
    final Function1 _function = (CmnField it) -> {
      boolean _isCollection = this.isCollection(it);
      return Boolean.valueOf((!_isCollection));
    };
    final Iterable baseImmutableFields = IterableExtensions.filter(this.getImmutableFields(this.getBaseFieldContainer(complexType), true), _function);
    final Function1 _function_1 = (CmnField it) -> {
      boolean _isCollection = this.isCollection(it);
      return Boolean.valueOf((!_isCollection));
    };
    final Iterable immutableFields = IterableExtensions.filter(this.getImmutableFields(complexType, false), _function_1);
    if (((!IterableExtensions.isEmpty(immutableFields)) || (!IterableExtensions.isEmpty(baseImmutableFields)))) {
      final ArrayList allImmutableFields = CollectionLiterals.newArrayList();
      Iterables.addAll(allImmutableFields, baseImmutableFields);
      Iterables.addAll(allImmutableFields, immutableFields);
      return allImmutableFields;
    }
    return CollectionLiterals.emptyList();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy