Skip to content

Commit

Permalink
Add helper methods for numer and date
Browse files Browse the repository at this point in the history
  • Loading branch information
yamelsenih committed Nov 1, 2023
1 parent 46bb456 commit d48d472
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/org/spin/service/grpc/util/Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static String getUuidFromId(String tableName, int id, String transactionN
* @param value
* @param message
*/
public static java.sql.Timestamp validateDate(com.google.protobuf.Timestamp value, String message) {
public static java.sql.Timestamp validateDate(com.google.protobuf.Timestamp value, String message) {
if(value == null) {
throw new AdempiereException(message);
}
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/org/spin/service/grpc/util/value/NumberManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import org.compiere.util.Util;

import com.google.protobuf.Value;

/**
* Class for handle Number (BigDecimal, Integer, Double) values
* @author Edwin Betancourt, EdwinBetanc0urt@outlook.com, https://github.com/EdwinBetanc0urt
Expand Down Expand Up @@ -186,5 +188,19 @@ public static int getIntFromString(String stringValue) {
}
return integerValue;
}

public static BigDecimal convertFromValueToDecimal(Value value) {
if(value.hasStringValue()) {
return NumberManager.getBigDecimalFromString(value.getStringValue());
}
return null;
}

public static Value convertFromDecimalToValue(BigDecimal value) {
if(value != null) {
return Value.newBuilder().setStringValue(value.toPlainString()).build();
}
return Value.newBuilder().build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,12 @@ public static long getLongFromTimestamp(Timestamp value) {
}
return value.getTime();
}

public static Timestamp convertValueToDate(com.google.protobuf.Timestamp value) {
return ValueManager.getDateFromTimestampDate(value);
}

public static com.google.protobuf.Timestamp convertDateToValue(Timestamp value) {
return ValueManager.getTimestampFromDate(value);
}
}

0 comments on commit d48d472

Please sign in to comment.