andy před 1 rokem
rodič
revize
e55dd258e5
1 změnil soubory, kde provedl 105 přidání a 0 odebrání
  1. 105 0
      src/main/java/com/scbfkj/uni/dtos/Expression.java

+ 105 - 0
src/main/java/com/scbfkj/uni/dtos/Expression.java

@@ -0,0 +1,105 @@
+package com.scbfkj.uni.dtos;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
+import java.util.Objects;
+import java.util.UUID;
+
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class Expression {
+
+    private String valuekey;
+    private String expression;
+    private String opt;
+
+    private Object comparevalue;
+    private Object returnvalue;
+    private Object elsevalue;
+    private Long algorithmlibraryid;
+
+    public Long getAlgorithmlibraryid() {
+        return algorithmlibraryid;
+    }
+
+    public void setAlgorithmlibraryid(Long algorithmlibraryid) {
+        this.algorithmlibraryid = algorithmlibraryid;
+    }
+
+    public String getExpression() {
+        return expression;
+    }
+
+    public void setExpression(String expression) {
+        this.expression = expression;
+    }
+
+    public String getOpt() {
+        return opt;
+    }
+
+    public void setOpt(String opt) {
+        this.opt = opt;
+    }
+
+    public Object getComparevalue() {
+        return comparevalue;
+    }
+
+    public void setComparevalue(Object comparevalue) {
+        this.comparevalue = comparevalue;
+    }
+
+    public Object getReturnvalue() {
+        return returnvalue;
+    }
+
+    public void setReturnvalue(Object returnvalue) {
+        this.returnvalue = returnvalue;
+    }
+
+    public Object getElsevalue() {
+        return elsevalue;
+    }
+
+    public void setElsevalue(Object elsevalue) {
+        this.elsevalue = elsevalue;
+    }
+
+    public String getValuekey() {
+        return valuekey;
+    }
+
+    public void setValuekey(String valuekey) {
+        this.valuekey = valuekey;
+    }
+
+    public String toScript() {
+        String randKey = (Objects.isNull(valuekey) || valuekey.trim().isEmpty()) ? ("a" + UUID.randomUUID().toString().replaceAll("-", "")) : valuekey;
+        if (Objects.nonNull(expression) && Objects.nonNull(opt) && (Objects.nonNull(returnvalue) || Objects.nonNull(elsevalue))) {
+            return """
+                    var %s = ( %s %s %s ) ? %s : %s;
+                    %s;
+                    """.formatted(randKey, expression, opt, Objects.isNull(comparevalue) ? "null" : comparevalue, Objects.isNull(returnvalue) ? "null" : returnvalue, Objects.isNull(elsevalue) ? "null" : elsevalue, randKey);
+        } else if (Objects.nonNull(expression) && Objects.isNull(opt) && (Objects.nonNull(returnvalue) || Objects.nonNull(elsevalue))) {
+            return """
+                    var %s = ( %s ) ? %s : %s;
+                    %s;
+                    """.formatted(randKey, expression, Objects.isNull(returnvalue) ? "null" : returnvalue, Objects.isNull(elsevalue) ? "null" : elsevalue, randKey);
+
+        } else if (Objects.isNull(opt) && Objects.nonNull(expression)) {
+            return """
+                    var %s = %s;
+                    """.formatted(randKey, expression);
+        } else if (Objects.isNull(opt) && Objects.nonNull(returnvalue)) {
+            return """
+                    var %s = %s;
+                    """.formatted(randKey, returnvalue);
+        } else {
+            return """
+                    var %s = null;
+                    %s;
+                    """.formatted(randKey, randKey);
+
+        }
+    }
+}