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

org.joinedworkz.common.info.MergedResourceOperationInfo Maven / Gradle / Ivy

There is a newer version: 1.3.51
Show newest version
package org.joinedworkz.common.info;

import java.util.List;
import java.util.Map;
import java.util.Set;
import org.eclipse.xtend.lib.annotations.Accessors;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
import org.eclipse.xtext.xbase.lib.Conversions;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.Pure;
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.CmnResponse;
import org.joinedworkz.core.model.Verb;

@Accessors
@SuppressWarnings("all")
public class MergedResourceOperationInfo {
  private final String parentPath;

  private final String path;

  private final String idPrefix;

  private final Verb verb;

  private final String operationType;

  private final boolean instanceOperation;

  private final Set consumes = CollectionLiterals.newLinkedHashSet();

  private final CmnResource operationResource;

  private final CmnProvidedResource providedResource;

  private Set operations;

  private CmnResource resource;

  private List parentParameters;

  private List queryParameters;

  private Map properties = CollectionLiterals.newLinkedHashMap();

  private boolean vendorSpecificMimeType;

  private CmnNamedObject filter;

  private boolean filteredByExpression;

  private boolean sorted;

  private boolean paginated;

  private CmnComplexType errorResponse;

  private final List operationParts = CollectionLiterals.newArrayList();

  public MergedResourceOperationInfo(final ResourceOperationInfo firstOperationInfo, final boolean vendorSpecificMimeType) {
    this.parentPath = firstOperationInfo.getParentPath();
    this.path = firstOperationInfo.getPath();
    this.verb = firstOperationInfo.getVerb();
    this.operationType = firstOperationInfo.getOperation().getOperationType();
    this.operationResource = firstOperationInfo.getOperationResource();
    this.idPrefix = firstOperationInfo.getIdPrefix();
    this.instanceOperation = (firstOperationInfo.getOperation().getInstanceOperation()).booleanValue();
    this.resource = firstOperationInfo.getResource();
    this.vendorSpecificMimeType = vendorSpecificMimeType;
    this.providedResource = firstOperationInfo.getProvidedResource();
    List _queryParameters = firstOperationInfo.getOperation().getQueryParameters();
    boolean _tripleNotEquals = (_queryParameters != null);
    if (_tripleNotEquals) {
      this.queryParameters = CollectionLiterals.newArrayList();
      this.queryParameters.addAll(firstOperationInfo.getOperation().getQueryParameters());
    }
    Set> _properties = firstOperationInfo.getOperation().getProperties();
    boolean _tripleNotEquals_1 = (_properties != null);
    if (_tripleNotEquals_1) {
      Set> _properties_1 = firstOperationInfo.getOperation().getProperties();
      for (final Map.Entry propertyEntry : _properties_1) {
        this.properties.put(propertyEntry.getKey(), propertyEntry.getValue());
      }
    }
    this.filter = this.getFilter(firstOperationInfo.getOperation());
    this.errorResponse = this.getErrorResponse(firstOperationInfo.getOperation());
  }

  public boolean setup() {
    boolean _xblockexpression = false;
    {
      this.operations = this.operations;
      if ((this.operations != null)) {
        for (final CmnResourceOperation operation : this.operations) {
          Set> _properties = operation.getProperties();
          for (final Map.Entry property : _properties) {
            this.properties.putIfAbsent(property.getKey(), property.getValue());
          }
        }
      }
      this.sorted = (this.isTrue(this.getProperty("sorting")) || this.isTrue(this.getProperty("sort")));
      this.paginated = (this.isTrue(this.getProperty("paging")) || this.isTrue(this.getProperty("pagination")));
      _xblockexpression = this.filteredByExpression = this.isTrue(this.getProperty("filter"));
    }
    return _xblockexpression;
  }

  public CmnNamedObject getFilter(final CmnResourceOperation operation) {
    final CmnProperty filter = operation.getProperty("filter");
    if ((filter != null)) {
      final Object value = filter.getValue();
      if ((value instanceof CmnNamedObject)) {
        return ((CmnNamedObject)value);
      }
    }
    return null;
  }

  public boolean isSorted(final CmnResourceOperation it) {
    return (this.isTrue(it.getProperty("sorting")) || this.isTrue(it.getProperty("sort")));
  }

  public boolean isFiltered(final CmnResourceOperation it) {
    return this.isTrue(it.getProperty("filter"));
  }

  public String getOperationName() {
    if (((this.operations != null) && (this.operations.size() == 1))) {
      return (((CmnResourceOperation[])Conversions.unwrapArray(this.operations, CmnResourceOperation.class))[0]).getName();
    }
    return null;
  }

  public CmnComplexType getErrorResponse(final CmnResourceOperation operation) {
    final CmnProperty fieldFilters = operation.getProperty("errorResponse");
    if ((fieldFilters != null)) {
      final Object value = fieldFilters.getValue();
      if ((value instanceof CmnComplexType)) {
        return ((CmnComplexType)value);
      }
    }
    return null;
  }

  public boolean addParentPathParameters(final List parameters) {
    boolean _xifexpression = false;
    if ((parameters != null)) {
      boolean _xblockexpression = false;
      {
        if ((this.parentParameters == null)) {
          this.parentParameters = CollectionLiterals.newArrayList();
        }
        _xblockexpression = this.parentParameters.addAll(parameters);
      }
      _xifexpression = _xblockexpression;
    }
    return _xifexpression;
  }

  public boolean addOperation(final CmnResourceOperation operation) {
    boolean _xifexpression = false;
    if ((operation != null)) {
      boolean _xblockexpression = false;
      {
        if ((this.operations == null)) {
          this.operations = CollectionLiterals.newLinkedHashSet();
        }
        _xblockexpression = this.operations.add(operation);
      }
      _xifexpression = _xblockexpression;
    }
    return _xifexpression;
  }

  public boolean returnsMultiple() {
    if (((this.operations != null) && (!this.operations.isEmpty()))) {
      final CmnResourceOperation firstOperation = IterableExtensions.head(this.operations);
      List _responses = firstOperation.getResponses();
      CmnResponse _head = null;
      if (_responses!=null) {
        _head=IterableExtensions.head(_responses);
      }
      CmnContent _content = null;
      if (_head!=null) {
        _content=_head.getContent();
      }
      Integer _maxOccurs = null;
      if (_content!=null) {
        _maxOccurs=_content.getMaxOccurs();
      }
      final Integer maxOccurs = _maxOccurs;
      return ((maxOccurs != null) && ((maxOccurs).intValue() != 1));
    } else {
      return false;
    }
  }

  public CmnProperty getProperty(final String propertyName) {
    if ((this.properties != null)) {
      return this.properties.get(propertyName);
    }
    return null;
  }

  public boolean isTrue(final String propertyName) {
    final CmnProperty property = this.getProperty(propertyName);
    return this.isTrue(property);
  }

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

  public Verb getVerb() {
    return this.verb;
  }

  @Pure
  public String getParentPath() {
    return this.parentPath;
  }

  @Pure
  public String getPath() {
    return this.path;
  }

  @Pure
  public String getIdPrefix() {
    return this.idPrefix;
  }

  @Pure
  public String getOperationType() {
    return this.operationType;
  }

  @Pure
  public boolean isInstanceOperation() {
    return this.instanceOperation;
  }

  @Pure
  public Set getConsumes() {
    return this.consumes;
  }

  @Pure
  public CmnResource getOperationResource() {
    return this.operationResource;
  }

  @Pure
  public CmnProvidedResource getProvidedResource() {
    return this.providedResource;
  }

  @Pure
  public Set getOperations() {
    return this.operations;
  }

  public void setOperations(final Set operations) {
    this.operations = operations;
  }

  @Pure
  public CmnResource getResource() {
    return this.resource;
  }

  public void setResource(final CmnResource resource) {
    this.resource = resource;
  }

  @Pure
  public List getParentParameters() {
    return this.parentParameters;
  }

  public void setParentParameters(final List parentParameters) {
    this.parentParameters = parentParameters;
  }

  @Pure
  public List getQueryParameters() {
    return this.queryParameters;
  }

  public void setQueryParameters(final List queryParameters) {
    this.queryParameters = queryParameters;
  }

  @Pure
  public Map getProperties() {
    return this.properties;
  }

  public void setProperties(final Map properties) {
    this.properties = properties;
  }

  @Pure
  public boolean isVendorSpecificMimeType() {
    return this.vendorSpecificMimeType;
  }

  public void setVendorSpecificMimeType(final boolean vendorSpecificMimeType) {
    this.vendorSpecificMimeType = vendorSpecificMimeType;
  }

  @Pure
  public CmnNamedObject getFilter() {
    return this.filter;
  }

  public void setFilter(final CmnNamedObject filter) {
    this.filter = filter;
  }

  @Pure
  public boolean isFilteredByExpression() {
    return this.filteredByExpression;
  }

  public void setFilteredByExpression(final boolean filteredByExpression) {
    this.filteredByExpression = filteredByExpression;
  }

  @Pure
  public boolean isSorted() {
    return this.sorted;
  }

  public void setSorted(final boolean sorted) {
    this.sorted = sorted;
  }

  @Pure
  public boolean isPaginated() {
    return this.paginated;
  }

  public void setPaginated(final boolean paginated) {
    this.paginated = paginated;
  }

  @Pure
  public CmnComplexType getErrorResponse() {
    return this.errorResponse;
  }

  public void setErrorResponse(final CmnComplexType errorResponse) {
    this.errorResponse = errorResponse;
  }

  @Pure
  public List getOperationParts() {
    return this.operationParts;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy