diff --git a/.github/workflows/build-java-app-workflow.yml b/.github/workflows/build-java-app-workflow.yml index 20769177..002c72f0 100644 --- a/.github/workflows/build-java-app-workflow.yml +++ b/.github/workflows/build-java-app-workflow.yml @@ -44,5 +44,6 @@ jobs: with: token: ${{ secrets.GITHUB_TOKEN }} file-to-check: pom.xml + only-return-version: true - name: test-version-from-check run: echo "Project version is " ${{ steps.get_project_version.outputs.version }} diff --git a/.github/workflows/deploy-docker-hub-workflow.yml b/.github/workflows/deploy-docker-hub-workflow.yml index 2922d7e1..75592693 100644 --- a/.github/workflows/deploy-docker-hub-workflow.yml +++ b/.github/workflows/deploy-docker-hub-workflow.yml @@ -21,7 +21,7 @@ jobs: name: build-folder path: build - name: Chmod - run: chmod +x build/bin/*sh + run: "find build -regex '.*sh' | while read file ; do chmod u+x $file ; done" - uses: docker/login-action@v1 if: ${{ inputs.cli }} with: diff --git a/commons-datastore/commons-datastore-core/pom.xml b/commons-datastore/commons-datastore-core/pom.xml index 89cd1780..2a7e5bca 100644 --- a/commons-datastore/commons-datastore-core/pom.xml +++ b/commons-datastore/commons-datastore-core/pom.xml @@ -6,7 +6,7 @@ org.opencb.commons commons-datastore - 4.4.0 + 4.4.1 ../pom.xml diff --git a/commons-datastore/commons-datastore-mongodb/pom.xml b/commons-datastore/commons-datastore-mongodb/pom.xml index eff14676..359656be 100644 --- a/commons-datastore/commons-datastore-mongodb/pom.xml +++ b/commons-datastore/commons-datastore-mongodb/pom.xml @@ -6,7 +6,7 @@ org.opencb.commons commons-datastore - 4.4.0 + 4.4.1 ../pom.xml diff --git a/commons-datastore/commons-datastore-solr/pom.xml b/commons-datastore/commons-datastore-solr/pom.xml index 8ed539b9..9a0d9400 100644 --- a/commons-datastore/commons-datastore-solr/pom.xml +++ b/commons-datastore/commons-datastore-solr/pom.xml @@ -22,7 +22,7 @@ org.opencb.commons commons-datastore - 4.4.0 + 4.4.1 ../pom.xml diff --git a/commons-datastore/pom.xml b/commons-datastore/pom.xml index ef509578..839b7cf4 100644 --- a/commons-datastore/pom.xml +++ b/commons-datastore/pom.xml @@ -6,7 +6,7 @@ org.opencb.commons commons - 4.4.0 + 4.4.1 ../pom.xml diff --git a/commons-lib/pom.xml b/commons-lib/pom.xml index 08738a42..b0587dda 100644 --- a/commons-lib/pom.xml +++ b/commons-lib/pom.xml @@ -6,7 +6,7 @@ org.opencb.commons commons - 4.4.0 + 4.4.1 ../pom.xml diff --git a/commons-lib/src/main/java/org/opencb/commons/utils/DataModelsUtils.java b/commons-lib/src/main/java/org/opencb/commons/utils/DataModelsUtils.java index 3b4f631b..3972738e 100644 --- a/commons-lib/src/main/java/org/opencb/commons/utils/DataModelsUtils.java +++ b/commons-lib/src/main/java/org/opencb/commons/utils/DataModelsUtils.java @@ -7,15 +7,12 @@ import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.util.*; +import java.util.stream.Collectors; public class DataModelsUtils { static final Map, String> PRIMITIVE_VALUES; - public static Map dataModelToMap(Class clazz) { - return dataModelToMap(clazz, ""); - } - static { PRIMITIVE_VALUES = new HashMap, String>(); PRIMITIVE_VALUES.put(boolean.class, "false"); @@ -28,6 +25,10 @@ public static Map dataModelToMap(Class clazz) { PRIMITIVE_VALUES.put(short.class, "0"); } + public static Map dataModelToMap(Class clazz) { + return dataModelToMap(clazz, ""); + } + public static Map dataModelToMap(Class clazz, String field) { return dataModelToMap(clazz, field, new HashMap()); } @@ -128,6 +129,22 @@ public static String dataModelToJsonString(Class clazz, boolean formatted) { return getClassAsJSON(clazz, 0, formatted, true); } + public static String dataModelToJsonString(String clazz, boolean formatted) { + return getClassAsJSON(clazz, 0, formatted, true); + } + + private static String getClassAsJSON(String sclazz, int margin, boolean formatted, boolean deep) { + if (StringUtils.isEmpty(sclazz)) { + return "No model found. The model parameter is required"; + } + Class clazz = null; + try { + clazz = Class.forName(sclazz); + } catch (ClassNotFoundException e) { + return e.getMessage() + " Invalid model parameter."; + } + return getClassAsJSON(clazz, 0, formatted, true); + } private static String getClassAsJSON(Class clazz, int margin, boolean formatted, boolean deep) { List declaredFields = getAllUnderlyingDeclaredFields(clazz); @@ -137,14 +154,14 @@ private static String getClassAsJSON(Class clazz, int margin, boolean formatt if (!declaredField.getType().equals(clazz)) { res += getTypeAsJSON(declaredField, clazz, margin, formatted, deep); } else { - res += (formatted ? addMargin(margin + 4) : "") + "\"" + declaredField.getName() + "\" : \"" + res += (formatted ? addMargin(margin + 4) : "") + "\"" + declaredField.getName() + "\": \"" + declaredField.getType().getName() + "\"," + (formatted ? "\n" : ""); } } if (res.trim().endsWith(",")) { res = res.trim().substring(0, res.trim().length() - 1); } - res += (addMargin(margin) + "}"); + res += "\n" + (addMargin(margin) + "}"); return res; } catch (Exception e) { return ""; @@ -175,13 +192,14 @@ private static String getTypeAsJSON(Field field, Class clazz, int margin, boo value = "0"; break; case "java.util.List": - value = getListRepresentation(field, clazz); + value = getListRepresentation(field, clazz, margin, formatted); break; case "java.util.Date": value = "\"dd/mm/yyyy\""; break; + case "org.opencb.commons.datastore.core.ObjectMap": case "java.util.Map": - value = "{\"key\":\"value\"}"; + value = "{\"key\": \"value\"}"; break; case "java.lang.Class": value = "\"java.lang.Class\""; @@ -190,12 +208,14 @@ private static String getTypeAsJSON(Field field, Class clazz, int margin, boo value = "\"java.lang.Object\""; break; default: - if (deep) { + if (field.getType().isEnum()) { + value = "\"" + printEnum(field.getType()) + "\""; + } else if (deep) { if (!Class.forName(field.getType().getName()).equals(clazz)) { value += getClassAsJSON(Class.forName(field.getType().getName()), (formatted ? margin + 4 : 0), formatted, true); } else { - return (formatted ? addMargin(margin + 4) : "") + "\"" + field.getName() + "\" : \"" + return (formatted ? addMargin(margin + 4) : "") + "\"" + field.getName() + "\": \"" + field.getType().getName() + "\"," + (formatted ? "\n" : ""); } } else { @@ -205,12 +225,20 @@ private static String getTypeAsJSON(Field field, Class clazz, int margin, boo break; } - return (formatted ? addMargin(margin + 4) : "") + "\"" + field.getName() + "\" : " + value + "," + (formatted ? "\n" : ""); + return (formatted ? addMargin(margin + 4) : "") + "\"" + field.getName() + "\": " + value + "," + (formatted ? "\n" : ""); + } + return ""; + } + + private static String printEnum(Class type) { + if (type.isEnum()) { + return Arrays.stream(type.getEnumConstants()).map(Object::toString) + .collect(Collectors.joining("|")); } return ""; } - private static String getListRepresentation(Field field, Class clazz) { + private static String getListRepresentation(Field field, Class clazz, int margin, boolean formatted) { String res = "[]"; Class collectionGenericType = DocUtils.getCollectionGenericType(field); if (collectionGenericType.equals(clazz)) { @@ -223,8 +251,8 @@ private static String getListRepresentation(Field field, Class clazz) { } else if (collectionGenericType.getCanonicalName().equals("java.lang.Class")) { res = "[\"java.lang.Class\"]"; } else { - System.out.println(collectionGenericType.getCanonicalName()); - res = "[" + getClassAsJSON(collectionGenericType, 0, false, false) + "]"; + // System.out.println(collectionGenericType.getCanonicalName()); + res = "[" + getClassAsJSON(collectionGenericType, (formatted ? margin + 4 : 0), true, false) + "]"; // res = "[" + collectionGenericType.getCanonicalName() + "]"; } return res; diff --git a/pom.xml b/pom.xml index abe370c4..4d2043de 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.opencb.commons commons - 4.4.0 + 4.4.1 pom OpenCB commons project