T nz(T val, T def){
return val!=null?val:def;
}
@@ -219,7 +261,7 @@ public final class Handy {
return bufs.toString();
}
/** Attempts to take a user string and compact it to camel case.
- * @param str nicely formatted string
+ * @param value more or less presentable string
* @return nicely compact string
*/
public static String toCamelCase(String value) {
diff --git a/src/main/java/com/reliancy/util/Path.java b/src/main/java/com/reliancy/util/Path.java
index a58dde7..5c71891 100644
--- a/src/main/java/com/reliancy/util/Path.java
+++ b/src/main/java/com/reliancy/util/Path.java
@@ -1,7 +1,11 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
+/*
+Copyright (c) 2011-2022 Reliancy LLC
+
+Licensed under the GNU LESSER GENERAL PUBLIC LICENSE Version 3.
+You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html.
+You may not use this file except in compliance with the License.
+*/
+
package com.reliancy.util;
import java.io.File;
import java.net.MalformedURLException;
@@ -13,7 +17,7 @@ import java.net.URLDecoder;
* It might but should not hold any handles. It holds the address and
* possibly takes care of looking up addresses.
* The richest syntax is:
- * PROTOCOL://USER:PWD@MACHINE:PORT/DATABASE?key=val&...
+ * {@code PROTOCOL://USER:PWD@MACHINE:PORT/DATABASE?key=val&... }
* Properties are held in their own string and need to be decoded.
*
* We use forward slash for path delimitation of database portion. For the rest we preserve other slashes to allow windows domain\\user or server\\instance.
@@ -380,7 +384,7 @@ public class Path {
* method will split paths used in linux and windows.
* in particular for windows it checks if a single letter precedes a colon in which case it considers it a volume
* and does not split there.
- * @param paths paths joined with colon or semi-colon
+ * @param _paths paths joined with colon or semi-colon
* @return array of paths
*/
public static String[] splitPaths(String _paths){
diff --git a/src/main/java/com/reliancy/util/Resources.java b/src/main/java/com/reliancy/util/Resources.java
index 3a747e3..fbe08a8 100644
--- a/src/main/java/com/reliancy/util/Resources.java
+++ b/src/main/java/com/reliancy/util/Resources.java
@@ -1,3 +1,11 @@
+/*
+Copyright (c) 2011-2022 Reliancy LLC
+
+Licensed under the GNU LESSER GENERAL PUBLIC LICENSE Version 3.
+You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html.
+You may not use this file except in compliance with the License.
+*/
+
package com.reliancy.util;
import java.io.BufferedReader;
diff --git a/src/main/java/com/reliancy/util/ResultCode.java b/src/main/java/com/reliancy/util/ResultCode.java
new file mode 100644
index 0000000..3b6fe72
--- /dev/null
+++ b/src/main/java/com/reliancy/util/ResultCode.java
@@ -0,0 +1,131 @@
+/*
+Copyright (c) 2011-2022 Reliancy LLC
+
+Licensed under the GNU LESSER GENERAL PUBLIC LICENSE Version 3.
+You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html.
+You may not use this file except in compliance with the License.
+*/
+package com.reliancy.util;
+
+import java.util.HashMap;
+
+/** Utility class to handle error codes and error messages.
+ * Error codes are integers that describe outcome of an operation.
+ *
+ * In cases when return codes are used and not exceptions thrown it is a mess to keep track of what they mean.
+ * With this class we define a uniform way of managing return codes and allow for additional information.
+ * This additional information can be text that could be localized and give better user information about what happened.
+ *
+ * First we distinguish between success and failure. Any code that is negative is failure.
+ * Default success code is 0 and provides no additional info. Any positive code is a warning or info and possibly carries extra meaning and
+ * or description.
+ *
+ * success,failure,pending
+ * source
+ * parametric
+ */
+public class ResultCode {
+ public static final byte TYPE_SUCCESS=0x0;
+ public static final byte TYPE_PENDING=0x1;
+ public static final byte TYPE_FAILURE=0xF;
+ final int code;
+ final String message;
+ final String source;
+ public ResultCode(byte type,short value,String src,String message) {
+ this.message=message;
+ this.source=src;
+ this.code=ResultCode.getCode(type,value,source!=null?source.hashCode():0);
+ }
+ public int getCode() {
+ return code;
+ }
+
+ public byte getType() {
+ return getType(code);
+ }
+
+ public int getValue() {
+ return getValue(code);
+ }
+
+ public String getSource() {
+ return source;
+ }
+ public String getMessage() {
+ return message;
+ }
+ @Override
+ public String toString() {
+ int code=getCode();
+ String context=getSource();
+ String message=getMessage();
+ if(context!=null){
+ return context+"("+String.format("%08X", code)+"):"+message;
+ }else{
+ return "("+String.format("%08X", code)+"):"+message;
+ }
+ }
+ protected static final HashMap codes=new HashMap<>();
+ public static final int getCode(byte type,int value,int source){
+ int st=(type <<28) & 0xF0000000;
+ int sc=(source <<8) & 0x0FFFFF00;
+ int vl=(value) & 0x000000FF;
+ return (int) (st | sc | vl);
+ }
+ public static final byte getType(int code){
+ return (byte)((code>>28) & 0x0F);
+ }
+ public static final boolean testType(int code,byte st){
+ return getType(code)==st;
+ }
+ public static final boolean isSuccess(int code){
+ return testType(code,TYPE_SUCCESS);
+ }
+ public static final boolean isFailure(int code,int st){
+ return testType(code,TYPE_FAILURE);
+ }
+ public static final boolean isPending(int code,int st){
+ return testType(code,TYPE_PENDING);
+ }
+ public static final int getValue(int code){
+ return (int)(code & 0x000000FF);
+ }
+ public static final int getSource(int code){
+ return (int)((code & 0x0FFFFF00)>>8);
+ }
+ public static final synchronized ResultCode get(int code){
+ if(codes==null) return null;
+ return (ResultCode)codes.get(code);
+ }
+ public static final synchronized ResultCode put(ResultCode c){
+ ResultCode old=(ResultCode) codes.get(c.getCode());
+ codes.put(c.getCode(),c);
+ return old;
+ }
+ public static final int define(byte type,int value,Class> source,String message){
+ return define(type,value,source!=null?source.getSimpleName():null,message);
+ }
+ public static final int define(byte type,int value,String source,String message){
+ int code=getCode(type,value,source!=null?source.hashCode():0);
+ ResultCode c=get(code);
+ if(c!=null){
+ System.err.println("Result code redefinition(consider different value or source):"+c);
+ return code;
+ }
+ c=new ResultCode(type, (short) value,source,message);
+ put(c);
+ return code;
+ }
+ public static final int defineSuccess(int value,Class> source,String message){
+ return define(TYPE_SUCCESS,value,source,message);
+ }
+ public static final int defineFailure(int value,Class> source,String message){
+ return define(TYPE_FAILURE,value,source,message);
+ }
+ public static final int definePending(int value,Class> source,String message){
+ return define(TYPE_PENDING,value,source,message);
+ }
+ public static final int SUCCESS=ResultCode.defineSuccess(0,null,"Success");
+ public static final int FAILURE=ResultCode.defineFailure(0,null,"Failure");
+ public static final int PENDING=ResultCode.definePending(0,null,"Pending");
+}
diff --git a/src/main/java/com/reliancy/util/Tokenizer.java b/src/main/java/com/reliancy/util/Tokenizer.java
index bd60852..123eecd 100644
--- a/src/main/java/com/reliancy/util/Tokenizer.java
+++ b/src/main/java/com/reliancy/util/Tokenizer.java
@@ -1,5 +1,12 @@
-package com.reliancy.util;
+/*
+Copyright (c) 2011-2022 Reliancy LLC
+Licensed under the GNU LESSER GENERAL PUBLIC LICENSE Version 3.
+You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html.
+You may not use this file except in compliance with the License.
+*/
+
+package com.reliancy.util;
import java.util.ArrayList;
import java.util.Iterator;
diff --git a/src/main/resources/templates/error.hbs b/src/main/resources/templates/error.hbs
new file mode 100644
index 0000000..5d13383
--- /dev/null
+++ b/src/main/resources/templates/error.hbs
@@ -0,0 +1,18 @@
+{{#partial "MainSection"}}
+
+
+
+
+
+
+ {{error_message}}
+
+
+
+
+
+
+{{/partial}}
+{{> frame-1c}}
diff --git a/src/main/resources/templates/login.hbs b/src/main/resources/templates/login.hbs
index 784dec7..63130e4 100644
--- a/src/main/resources/templates/login.hbs
+++ b/src/main/resources/templates/login.hbs
@@ -1,4 +1,24 @@
-{{#partial "content"}}
-Calling base
+{{#partial "MainSection"}}
+
{{/partial}}
-{{> base}}
+{{> frame-1c}}
diff --git a/src/test/java/com/reliancy/dbo/TerminalTest.java b/src/test/java/com/reliancy/dbo/TerminalTest.java
index ca4e5ea..ba1e2c5 100644
--- a/src/test/java/com/reliancy/dbo/TerminalTest.java
+++ b/src/test/java/com/reliancy/dbo/TerminalTest.java
@@ -1,10 +1,16 @@
+/*
+Copyright (c) 2011-2022 Reliancy LLC
+
+Licensed under the GNU LESSER GENERAL PUBLIC LICENSE Version 3.
+You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html.
+You may not use this file except in compliance with the License.
+*/
package com.reliancy.dbo;
import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
-import java.sql.Timestamp;
import java.util.Date;
import com.reliancy.rec.JSON;
@@ -93,25 +99,38 @@ public class TerminalTest {
@Test
public void complexCRUD() throws IOException, SQLException{
System.out.println("ComplexCRUD");
+ // Reading
try(Action act=t.begin().load(Product.class).execute()){
for(DBO o:act){
System.out.println("DBO:"+o);
}
}
+ //Saving
Product p=new Product();
p.setStatus(DBO.Status.USED);
+ Product.id.set(p,35);
Product.kind.set(p,Product.class.getSimpleName());
Product.name.set(p,"myproduct");
Product.created.set(p,new Date());
- Product.short_info.set(p,"a sweet melody");
+ Product.short_info.set(p,"a sweet melody:"+new java.sql.Timestamp(System.currentTimeMillis()));
Product.display_name.set(p,"first entry");
- System.out.println("P0:"+JSON.toString(p));
+ System.out.println("Update P0:"+JSON.toString(p));
t.save(p);
- System.out.println("P1:"+JSON.toString(p));
- Product pp=t.load(Product.class, 35);
+ System.out.println("Update P1:"+JSON.toString(p));
+ // Creating
+ Product pp=new Product();
+ Product.kind.set(pp,Product.class.getSimpleName());
+ Product.name.set(pp,"myproduct");
+ Product.created.set(pp,new Date());
+ Product.short_info.set(pp,"a sweet melody:");
+ Product.display_name.set(pp,"created entry:"+new java.sql.Timestamp(System.currentTimeMillis()));
+ t.save(pp);
+ System.out.println("Create PP0:"+JSON.toString(pp));
+ pp=t.load(Product.class, Product.id.get(pp,null));
System.out.println("Returning:"+pp);
- //t.delete(pp);
- Entity.retract(Maps.class);
+ // Deleting
+ t.delete(pp);
+ //Entity.retract(Maps.class);
}
}
diff --git a/src/test/java/com/reliancy/jabba/RouterTest.java b/src/test/java/com/reliancy/jabba/RouterTest.java
index 3922b0e..aa7bcd2 100644
--- a/src/test/java/com/reliancy/jabba/RouterTest.java
+++ b/src/test/java/com/reliancy/jabba/RouterTest.java
@@ -1,3 +1,10 @@
+/*
+Copyright (c) 2011-2022 Reliancy LLC
+
+Licensed under the GNU LESSER GENERAL PUBLIC LICENSE Version 3.
+You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html.
+You may not use this file except in compliance with the License.
+*/
package com.reliancy.jabba;
import static org.junit.Assert.assertTrue;
@@ -31,8 +38,9 @@ public class RouterTest
{
//assertTrue( true );
System.out.println("Test router init...");
- Router r=new Router();
- RouterEndPoint rep=r.importEndPoints(r);
+ JettyApp r=new JettyApp();
+ RoutedEndPoint rep=new RoutedEndPoint();
+ rep.importMethods(r);
rep.compile();
//Matcher m=rep.match("GET","/helloPlain");
Matcher m=rep.match("GET","/hello3/45");
diff --git a/src/test/java/com/reliancy/rec/ObjTest.java b/src/test/java/com/reliancy/rec/ObjTest.java
index 7220270..6b5d3ef 100644
--- a/src/test/java/com/reliancy/rec/ObjTest.java
+++ b/src/test/java/com/reliancy/rec/ObjTest.java
@@ -1,10 +1,13 @@
-package com.reliancy.rec;
-import static org.junit.Assert.assertTrue;
+/*
+Copyright (c) 2011-2022 Reliancy LLC
+Licensed under the GNU LESSER GENERAL PUBLIC LICENSE Version 3.
+You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html.
+You may not use this file except in compliance with the License.
+*/
+
+package com.reliancy.rec;
import java.io.IOException;
-import java.util.HashMap;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import org.junit.Test;
diff --git a/var/favicon.ico b/var/favicon.ico
deleted file mode 100644
index 72b6083..0000000
Binary files a/var/favicon.ico and /dev/null differ