Skip to content

Commit

Permalink
fix: Value from Object with empty display type. (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwinBetanc0urt authored Feb 9, 2024
1 parent b6b31bd commit 5df4455
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 5 deletions.
45 changes: 41 additions & 4 deletions src/main/java/org/spin/service/grpc/util/value/TimeManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,13 @@ public static Timestamp getTimestampFromString(String stringValue) {

// Convert
if(validDate != null) {
return new Timestamp(
return getTimestampFromLong(
validDate.getTime()
);
}
return null;
}


/**
* Convert Timestamp to String
* @param date
Expand All @@ -119,7 +118,37 @@ public static String getTimestampToString(Timestamp date) {
if(date == null) {
return null;
}
return new SimpleDateFormat(TIME_FORMAT).format(date);
return getTimestampToString(date, TIME_FORMAT);
}

/**
* Convert Timestamp to String
* @param date
* @param pattern default `yyyy-MM-dd hh:mm:ss`
* @return
*/
public static String getTimestampToString(Timestamp date, String pattern) {
if(date == null) {
return null;
}
if (Util.isEmpty(pattern, true)) {
pattern = TIME_FORMAT;
}
return new SimpleDateFormat(pattern).format(date);
}

/**
* Convert Timestamp to String
* @param date
* @return
*/
public static Timestamp getTimestampFromDate(Date value) {
if(value == null) {
return null;
}
return new Timestamp(
value.getTime()
);
}

public static Timestamp getTimestampFromLong(long value) {
Expand Down Expand Up @@ -157,7 +186,15 @@ public static long getLongFromTimestamp(Timestamp value) {
}
return value.getTime();
}



/**
* @link ValueManager.getDateFromTimestampDate
* @param value
* @return
* @see {@link ValueManager.getDateFromTimestampDate(com.google.protobuf.Timestamp)}
*/
@Deprecated
public static Timestamp convertValueToDate(com.google.protobuf.Timestamp value) {
return ValueManager.getDateFromTimestampDate(value);
}
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/org/spin/service/grpc/util/value/ValueManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ public static Value.Builder getValueFromNull() {
* @return
*/
public static Value.Builder getEmptyValueByReference(int referenceId) {
if (referenceId <= 0) {
return getValueFromNull();
}
if (DisplayType.isID(referenceId) || DisplayType.Integer == referenceId) {
int emptyId = 0;
return getValueFromInteger(emptyId);
Expand Down Expand Up @@ -458,6 +461,9 @@ public static Value.Builder getValueFromReference(Object value, int referenceId)
// getEmptyValueByReference(referenceId);
return getValueFromNull();
}
if (referenceId <= 0) {
return getValueFromObject(value);
}
// Validate values
if (DisplayType.isID(referenceId) || DisplayType.Integer == referenceId) {
Integer integerValue = NumberManager.getIntegerFromObject(
Expand Down Expand Up @@ -504,17 +510,21 @@ public static Value.Builder getValueFromReference(Object value, int referenceId)
);
}
return getValueFromObject(value);
} else {
builderValue = getValueFromObject(value);
}
//
return builderValue;
}

public static String getDisplayedValueFromReference(Object value, String columnName, int displayTypeId, int referenceValueId) {
String displayedValue = null;

if (value == null) {
return displayedValue;
}
if (displayTypeId <= 0) {
return displayedValue;
}
if (DisplayType.isText (displayTypeId)) {
;
} else if (displayTypeId == DisplayType.YesNo) {
Expand Down Expand Up @@ -756,6 +766,9 @@ public static Object getObjectFromReference(Value value, int referenceId) {
if(value == null) {
return null;
}
if (referenceId <= 0) {
return getObjectFromValue(value);
}
// Validate values
if(isLookup(referenceId)
|| DisplayType.isID(referenceId)) {
Expand All @@ -772,6 +785,7 @@ public static Object getObjectFromReference(Value value, int referenceId) {
return getStringFromValue(value);
}
//
// TODO: return getObjectFromValue(value);
return null;
}

Expand Down

0 comments on commit 5df4455

Please sign in to comment.