コード例 #1
0
  private XMLGregorianCalendar populateDate(OpaAttribute input) {

    DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    Date date = null;
    XMLGregorianCalendar xmlDate = null;
    try {
      date = df.parse(input.getValue());
      GregorianCalendar cal = new GregorianCalendar();

      cal.setTime(date);
      xmlDate =
          DatatypeFactory.newInstance()
              .newXMLGregorianCalendarDate(
                  cal.get(Calendar.YEAR),
                  cal.get(Calendar.MONTH) + 1,
                  cal.get(Calendar.DAY_OF_MONTH),
                  cal.getTimeZone().LONG);
    } catch (ParseException e) {
      throw new RuntimeException("Cannot convert inputValue to Date : " + input.getValue());
    } catch (DatatypeConfigurationException e) {
      throw new RuntimeException("Cannot convert inputValue to Date : " + input.getValue());
    }

    return xmlDate;
  }
コード例 #2
0
 private void populateAttributeTypeValue(AttributeType attributeType, OpaAttribute input) {
   switch (input.getValueType()) {
     case _NUMBER:
     case _CURRENCY:
       attributeType.setNumberVal(new BigDecimal(input.getValue()));
       break;
     case _BOOLEAN:
       attributeType.setBooleanVal(new Boolean(input.getValue()));
       break;
     case _DATE:
       attributeType.setDateVal(populateDate(input));
       break;
     case _TEXT:
       break;
     default:
       throw new RuntimeException("Unsupported AttributeType :" + input.getValueType());
   }
 }
コード例 #3
0
  /**
   * constructs an assess-request like the following example:
   *
   * <p><typ:assess-request> <typ:global-instance> <typ:attribute id="base_premium"
   * outcome-style="value-only" /> <typ:attribute id="deductible">
   * <typ:number-val>100</typ:number-val> </typ:attribute> <typ:attribute id="insured_value">
   * <typ:number-val>1100</typ:number-val> </typ:attribute> <typ:attribute id="premium_rate">
   * <typ:number-val>0.05</typ:number-val> </typ:attribute> </typ:global-instance>
   * </typ:assess-request>
   *
   * @return
   * @param unknown
   * @param inputValues
   */
  public AssessRequest constructOpaAssessRequest(
      OpaAttribute unknown, List<OpaAttribute> inputValues) {

    AssessRequest request = new AssessRequest();
    GlobalInstanceType globalInstance = new GlobalInstanceType();
    request.setGlobalInstance(globalInstance);

    AttributeType unknown_Attribute = new AttributeType();
    unknown_Attribute.setOutcomeStyle(OutcomeStyleEnum.VALUE_ONLY);
    unknown_Attribute.setId(unknown.getName());
    globalInstance.getAttribute().add(unknown_Attribute);

    for (OpaAttribute input : inputValues) {
      AttributeType attributeType = new AttributeType();
      attributeType.setId(input.getName());
      populateAttributeTypeValue(attributeType, input);
      globalInstance.getAttribute().add(attributeType);
    }

    return request;
  }