content: /*
   * Copyright 2017-2025 Hyland Software, Inc. and its affiliates.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.activiti.cloud.services.audit.jpa.repository;
  
  public class SpecSearchCriteria {
  
      private String key;
      private SearchOperation operation;
      private Object value;
      private boolean orPredicate;
  
      public SpecSearchCriteria() {}
  
      public SpecSearchCriteria(final String key, final SearchOperation operation, final Object value) {
          super();
          this.key = key;
          this.operation = operation;
          this.value = value;
      }
  
      public SpecSearchCriteria(
          final String orPredicate,
          final String key,
          final SearchOperation operation,
          final Object value
      ) {
          super();
          this.orPredicate = orPredicate != null && orPredicate.equals(SearchOperation.OR_PREDICATE_FLAG);
          this.key = key;
          this.operation = operation;
          this.value = value;
      }
  
      public SpecSearchCriteria(String key, String operation, String prefix, String value, String suffix) {
          SearchOperation op = SearchOperation.getSimpleOperation(operation);
          if (op != null) {
              if (op == SearchOperation.EQUALITY) { // the operation may be complex operation
                  final boolean startWithAsterisk = prefix != null && prefix.contains(SearchOperation.ZERO_OR_MORE_REGEX);
                  final boolean endWithAsterisk = suffix != null && suffix.contains(SearchOperation.ZERO_OR_MORE_REGEX);
  
                  if (startWithAsterisk && endWithAsterisk) {
                      op = SearchOperation.CONTAINS;
                  } else if (startWithAsterisk) {
                      op = SearchOperation.ENDS_WITH;
                  } else if (endWithAsterisk) {
                      op = SearchOperation.STARTS_WITH;
                  }
              }
          }
          this.key = key;
          this.operation = op;
          this.value = value;
      }
  
      public String getKey() {
          return key;
      }
  
      public void setKey(final String key) {
          this.key = key;
      }
  
      public SearchOperation getOperation() {
          return operation;
      }
  
      public void setOperation(final SearchOperation operation) {
          this.operation = operation;
      }
  
      public Object getValue() {
          return value;
      }
  
      public void setValue(final Object value) {
          this.value = value;
      }
  
      public boolean isOrPredicate() {
          return orPredicate;
      }
  
      public void setOrPredicate(boolean orPredicate) {
          this.orPredicate = orPredicate;
      }
  }
  