Skip to content

Commit

Permalink
Merge branch 'release-4.4.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
imedina committed Aug 19, 2022
2 parents 191961d + bf5612b commit 26f064f
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 21 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build-java-app-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
2 changes: 1 addition & 1 deletion .github/workflows/deploy-docker-hub-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion commons-datastore/commons-datastore-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.opencb.commons</groupId>
<artifactId>commons-datastore</artifactId>
<version>4.4.0</version>
<version>4.4.1</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion commons-datastore/commons-datastore-mongodb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.opencb.commons</groupId>
<artifactId>commons-datastore</artifactId>
<version>4.4.0</version>
<version>4.4.1</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion commons-datastore/commons-datastore-solr/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>org.opencb.commons</groupId>
<artifactId>commons-datastore</artifactId>
<version>4.4.0</version>
<version>4.4.1</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion commons-datastore/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.opencb.commons</groupId>
<artifactId>commons</artifactId>
<version>4.4.0</version>
<version>4.4.1</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion commons-lib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.opencb.commons</groupId>
<artifactId>commons</artifactId>
<version>4.4.0</version>
<version>4.4.1</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Class<?>, String> PRIMITIVE_VALUES;

public static Map<String, Type> dataModelToMap(Class<?> clazz) {
return dataModelToMap(clazz, "");
}

static {
PRIMITIVE_VALUES = new HashMap<Class<?>, String>();
PRIMITIVE_VALUES.put(boolean.class, "false");
Expand All @@ -28,6 +25,10 @@ public static Map<String, Type> dataModelToMap(Class<?> clazz) {
PRIMITIVE_VALUES.put(short.class, "0");
}

public static Map<String, Type> dataModelToMap(Class<?> clazz) {
return dataModelToMap(clazz, "");
}

public static Map<String, Type> dataModelToMap(Class<?> clazz, String field) {
return dataModelToMap(clazz, field, new HashMap<String, Type>());
}
Expand Down Expand Up @@ -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<Field> declaredFields = getAllUnderlyingDeclaredFields(clazz);
Expand All @@ -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 "";
Expand Down Expand Up @@ -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\"";
Expand All @@ -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 {
Expand All @@ -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)) {
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>org.opencb.commons</groupId>
<artifactId>commons</artifactId>
<version>4.4.0</version>
<version>4.4.1</version>
<packaging>pom</packaging>

<name>OpenCB commons project</name>
Expand Down

0 comments on commit 26f064f

Please sign in to comment.