Exemplo n.º 1
0
 public static final String getDominantSortAttributeValueAsString(
     CommonFieldsBase cb, DataField dominantAttr) {
   String value;
   switch (dominantAttr.getDataType()) {
     case BINARY:
       throw new IllegalStateException("cannot sort on a binary field");
     case LONG_STRING:
       throw new IllegalStateException("cannot sort on a long text field");
     case URI:
     case STRING:
       {
         value = cb.getStringField(dominantAttr);
         break;
       }
     case INTEGER:
       {
         Long l = cb.getLongField(dominantAttr);
         if (l == null) {
           value = null;
         } else {
           value = Long.toString(l);
         }
         break;
       }
     case DECIMAL:
       {
         BigDecimal bd = cb.getNumericField(dominantAttr);
         if (bd == null) {
           value = null;
         } else {
           value = bd.toString();
         }
         break;
       }
     case BOOLEAN:
       {
         Boolean b = cb.getBooleanField(dominantAttr);
         if (b == null) {
           value = null;
         } else {
           value = b.toString();
         }
         break;
       }
     case DATETIME:
       {
         Date d = cb.getDateField(dominantAttr);
         if (d == null) {
           value = null;
         } else {
           value = WebUtils.iso8601Date(d);
         }
         break;
       }
     default:
       throw new IllegalStateException("datatype not handled");
   }
   return value;
 }
Exemplo n.º 2
0
 public static final String getAttributeValueAsString(Object o, DataField dominantAttr) {
   String value;
   switch (dominantAttr.getDataType()) {
     case BINARY:
       throw new IllegalStateException("cannot sort on a binary field");
     case LONG_STRING:
       throw new IllegalStateException("cannot sort on a long text field");
     case URI:
     case STRING:
       {
         value = (String) o;
         break;
       }
     case INTEGER:
       {
         Long l = (Long) o;
         if (l == null) {
           value = null;
         } else {
           value = Long.toString(l);
         }
         break;
       }
     case DECIMAL:
       {
         BigDecimal bd;
         if (o == null) {
           bd = null;
         } else if (o instanceof Double) {
           bd = new BigDecimal(((Double) o).toString());
         } else {
           bd = new BigDecimal(o.toString());
         }
         if (bd == null) {
           value = null;
         } else {
           value = bd.toString();
         }
         break;
       }
     case BOOLEAN:
       {
         Boolean b = (Boolean) o;
         if (b == null) {
           value = null;
         } else {
           value = b.toString();
         }
         break;
       }
     case DATETIME:
       {
         Date d = (Date) o;
         if (d == null) {
           value = null;
         } else {
           value = WebUtils.iso8601Date(d);
         }
         break;
       }
     default:
       throw new IllegalStateException("datatype not handled");
   }
   return value;
 }