Esempio n. 1
0
  public void udtSerDeserTest(int version) throws Exception {
    ListType<?> lt = ListType.getInstance(Int32Type.instance, true);
    SetType<?> st = SetType.getInstance(UTF8Type.instance, true);
    MapType<?, ?> mt = MapType.getInstance(UTF8Type.instance, LongType.instance, true);

    UserType udt =
        new UserType(
            "ks",
            bb("myType"),
            Arrays.asList(bb("f1"), bb("f2"), bb("f3"), bb("f4")),
            Arrays.asList(LongType.instance, lt, st, mt));

    Map<ColumnIdentifier, Term.Raw> value = new HashMap<>();
    value.put(ci("f1"), lit(42));
    value.put(ci("f2"), new Lists.Literal(Arrays.<Term.Raw>asList(lit(3), lit(1))));
    value.put(ci("f3"), new Sets.Literal(Arrays.<Term.Raw>asList(lit("foo"), lit("bar"))));
    value.put(
        ci("f4"),
        new Maps.Literal(
            Arrays.<Pair<Term.Raw, Term.Raw>>asList(
                Pair.<Term.Raw, Term.Raw>create(lit("foo"), lit(24)),
                Pair.<Term.Raw, Term.Raw>create(lit("bar"), lit(12)))));

    UserTypes.Literal u = new UserTypes.Literal(value);
    Term t = u.prepare("ks", columnSpec("myValue", udt));

    QueryOptions options = QueryOptions.DEFAULT;
    if (version == 2)
      options =
          QueryOptions.fromProtocolV2(ConsistencyLevel.ONE, Collections.<ByteBuffer>emptyList());
    else if (version != 3) throw new AssertionError("Invalid protocol version for test");

    ByteBuffer serialized = t.bindAndGet(options);

    ByteBuffer[] fields = udt.split(serialized);

    assertEquals(4, fields.length);

    assertEquals(bytes(42L), fields[0]);

    // Note that no matter what the protocol version has been used in bindAndGet above, the
    // collections inside
    // a UDT should alway be serialized with version 3 of the protocol. Which is why we don't use
    // 'version'
    // on purpose below.

    assertEquals(
        Arrays.asList(3, 1), lt.getSerializer().deserializeForNativeProtocol(fields[1], 3));

    LinkedHashSet<String> s = new LinkedHashSet<>();
    s.addAll(Arrays.asList("bar", "foo"));
    assertEquals(s, st.getSerializer().deserializeForNativeProtocol(fields[2], 3));

    LinkedHashMap<String, Long> m = new LinkedHashMap<>();
    m.put("bar", 12L);
    m.put("foo", 24L);
    assertEquals(m, mt.getSerializer().deserializeForNativeProtocol(fields[3], 3));
  }
Esempio n. 2
0
  public String writeContentQueryXML(String queryName, String userId) {
    // DTOFactory dtoFactory = new DTOFactory();

    // QueryType queryType = new QueryType();

    // create header
    PsmQryHeaderType headerType = new PsmQryHeaderType();
    UserType userType = new UserType();
    userType.setLogin(userId);
    userType.setValue(userId);
    headerType.setUser(userType);
    headerType.setRequestType(PsmRequestTypeType.CRC_QRY_RUN_QUERY_INSTANCE_FROM_QUERY_DEFINITION);

    // QuerySetType querySetType = new QuerySetType();
    // querySetType.getQuery().add(queryType);

    RequestHeaderType requestHeader = new RequestHeaderType();
    requestHeader.setResultWaittimeMs(180000);
    BodyType bodyType = new BodyType();
    edu.harvard.i2b2.crcxmljaxb.datavo.psm.query.ObjectFactory psmOf =
        new edu.harvard.i2b2.crcxmljaxb.datavo.psm.query.ObjectFactory();
    bodyType.getAny().add(psmOf.createPsmheader(headerType));

    MessageHeaderType messageHeader = getMessageHeader();
    RequestMessageType requestMessageType = new RequestMessageType();
    requestMessageType.setMessageBody(bodyType);
    requestMessageType.setMessageHeader(messageHeader);
    requestMessageType.setRequestHeader(requestHeader);
    // dtoFactory.getRequestMessageType(messageHeader, requestHeader,
    // bodyType);

    JAXBUtil jaxbUtil = PreviousQueryJAXBUtil.getJAXBUtil();
    StringWriter strWriter = new StringWriter();
    try {
      edu.harvard.i2b2.crcxmljaxb.datavo.i2b2message.ObjectFactory of =
          new edu.harvard.i2b2.crcxmljaxb.datavo.i2b2message.ObjectFactory();
      jaxbUtil.marshaller(of.createRequest(requestMessageType), strWriter);
    } catch (Exception e) {
      e.printStackTrace();
    }

    System.out.println("Generated content XML request: " + strWriter.toString());
    return strWriter.toString();
  }
  public void updateView() {
    User user = Application.getCurrentUser();
    UserType userType = user.getNewUserType();
    if (userType != null) {
      Set<UserPermission> permissions = userType.getPermissions();
      if (permissions != null) {
        btnNewTicket.setEnabled(false);
        btnBackOffice.setEnabled(false);
        btnEditTicket.setEnabled(false);

        if (!"false".equalsIgnoreCase(AppConfig.getFeatureGroupTicketFlag())) {
          btnGroupSettle.setEnabled(false);
        }

        if (!"false".equalsIgnoreCase(AppConfig.getManagerMenuFlag())) {
          btnManager.setEnabled(false);
        }

        if (!"false".equalsIgnoreCase(AppConfig.getFeaturePenarikanFlag())) {
          btnPayout.setEnabled(false);
        }

        btnReopenTicket.setEnabled(false);
        btnSettleTicket.setEnabled(false);

        if (!"false".equalsIgnoreCase(AppConfig.getFeatureSplitTicketFlag())) {
          btnSplitTicket.setEnabled(false);
        }

        btnTakeout.setEnabled(false);
        btnVoidTicket.setEnabled(false);

        for (UserPermission permission : permissions) {
          if (permission.equals(UserPermission.VOID_TICKET)) {
            btnVoidTicket.setEnabled(true);
          } else if (permission.equals(UserPermission.PAY_OUT)) {
            if (!"false".equalsIgnoreCase(AppConfig.getFeaturePenarikanFlag())) {
              btnPayout.setEnabled(true);
            }
          } else if (permission.equals(UserPermission.SETTLE_TICKET)) {
            btnSettleTicket.setEnabled(true);
            if (!"false".equalsIgnoreCase(AppConfig.getFeatureGroupTicketFlag())) {
              btnGroupSettle.setEnabled(true);
            }
          } else if (permission.equals(UserPermission.REOPEN_TICKET)) {
            btnReopenTicket.setEnabled(true);
          } else if (permission.equals(UserPermission.PERFORM_MANAGER_TASK)) {
            if (!"false".equalsIgnoreCase(AppConfig.getManagerMenuFlag())) {
              btnManager.setEnabled(true);
            }
          } else if (permission.equals(UserPermission.SPLIT_TICKET)) {
            if (!"false".equalsIgnoreCase(AppConfig.getFeatureSplitTicketFlag())) {
              btnSplitTicket.setEnabled(true);
            }
          } else if (permission.equals(UserPermission.TAKE_OUT)) {
            btnTakeout.setEnabled(true);
          } else if (permission.equals(UserPermission.VIEW_BACK_OFFICE)) {
            btnBackOffice.setEnabled(true);
          }
          //                    else if (permission.equals(UserPermission.PAY_OUT)) {
          //                        btnPayout.setEnabled(true);
          //                    }
          else if (permission.equals(UserPermission.EDIT_TICKET)) {
            btnEditTicket.setEnabled(true);
          } else if (permission.equals(UserPermission.CREATE_NEW_TICKET)) {
            btnNewTicket.setEnabled(true);
          }
        }
      }
    }

    updateTicketList();
  }
Esempio n. 4
0
  public String wirteQueryXML() {
    DTOFactory dtoFactory = new DTOFactory();
    // TimeZone pdt = TimeZone.getTimeZone("EST");
    // DatatypeFactory dataTypeFactory = null;
    // try {
    // dataTypeFactory = DatatypeFactory.newInstance();
    // XMLGregorianCalendar xmlCalendar =
    // dataTypeFactory.newXMLGregorianCalendarDate(2006, 9, 21, -5*60);
    // TimeZone pdt = xmlCalendar.getgetTimezone();
    // }
    // catch (DatatypeConfigurationException e) {
    // e.printStackTrace();
    // }

    // RequestType requestType = new RequestType();
    // requestType.setSpecificityScale(specificity());
    QueryDefinitionType queryDefinitionType = new QueryDefinitionType();
    QueryDefinitionRequestType queryDefinitionRequestType = new QueryDefinitionRequestType();
    for (int i = 0; i < panelCount; i++) {
      ConceptTreePanel panel = getTreePanel(i);
      ArrayList<QueryConceptTreeNodeData> nodelist = panel.data().getItems();
      if ((nodelist != null) && (nodelist.size() > 0)) {
        System.out.println(
            "Panel: "
                + panel.getGroupName()
                + " Excluded: "
                + ((panel.data().exclude()) ? "yes" : "no"));
        PanelType panelType = new PanelType();
        panelType.setInvert((panel.data().exclude()) ? 1 : 0);
        PanelType.TotalItemOccurrences totalItemOccurrences = new PanelType.TotalItemOccurrences();
        totalItemOccurrences.setValue(panel.getOccurrenceTimes());

        panelType.setTotalItemOccurrences(totalItemOccurrences);
        panelType.setPanelNumber(i + 1);

        // if(panel.data().startTime() != -1) {
        // panelType.setPanelDateFrom(//dataTypeFactory.
        // newXMLGregorianCalendarDate(
        // dtoFactory.getXMLGregorianCalendarDate(panel.data().startYear(
        // ),
        // panel.data().startMonth(), panel.data().startDay()));
        // }

        // if(panel.data().endTime() != -1) {
        // panelType.setPanelDateTo(//dataTypeFactory.
        // newXMLGregorianCalendarDate(
        // dtoFactory.getXMLGregorianCalendarDate(panel.data().endYear(),
        // panel.data().endMonth(), panel.data().endDay()));
        // }

        for (int j = 0; j < nodelist.size(); j++) {
          QueryConceptTreeNodeData node = nodelist.get(j);
          System.out.println("\tItem: " + node.fullname());

          // create item
          ItemType itemType = new ItemType();
          // itemType.setConstrainByDate(.setDateFrom(dtoFactory.
          // getXMLGregorianCalendarDate(2006,
          // 10, 4)));
          itemType.setItemKey(node.fullname());
          itemType.setItemName(node.name());
          // mm removed
          // itemType.setItemTable(node.lookuptable());
          itemType.setTooltip(node.tooltip());
          itemType.setHlevel(Integer.parseInt(node.hlevel()));
          itemType.setClazz("ENC");
          ConstrainByDate cDate = new ConstrainByDate();
          ConstrainDateType constrinDataType = new ConstrainDateType();
          constrinDataType.setValue(
              dtoFactory.getXMLGregorianCalendarDate(
                  node.startYear(), node.startMonth(), node.startDay()));
          if (node.startTime() != -1) {
            cDate.setDateFrom(constrinDataType);
          }
          if (node.endTime() != -1) {
            cDate.setDateTo(constrinDataType);
          }
          itemType.getConstrainByDate().add(cDate);
          panelType.getItem().add(itemType);
        }
        queryDefinitionType.getPanel().add(panelType);
      }
    }

    // create infotype
    InfoType infoType = new InfoType();
    infoType.setValue("INFO");
    infoType.setUrl("http://www.ibm.com");

    // create header
    PsmQryHeaderType headerType = new PsmQryHeaderType();
    UserType userType = new UserType();
    userType.setLogin(UserInfoBean.getInstance().getUserName());
    userType.setValue(UserInfoBean.getInstance().getUserName());
    headerType.setUser(userType);
    headerType.setRequestType(PsmRequestTypeType.CRC_QRY_RUN_QUERY_INSTANCE_FROM_QUERY_DEFINITION);
    if (queryName == null) {
      queryName =
          getTreePanel(0).data().getItems().get(0).name()
              + "_"
              + generateMessageId().substring(0, 4);
    }

    queryDefinitionType.setQueryName(queryName);
    queryDefinitionRequestType.setQueryDefinition(queryDefinitionType);

    RequestHeaderType requestHeader = new RequestHeaderType();
    requestHeader.setResultWaittimeMs(180000);

    BodyType bodyType = new BodyType();
    edu.harvard.i2b2.crcxmljaxb.datavo.psm.query.ObjectFactory psmOf =
        new edu.harvard.i2b2.crcxmljaxb.datavo.psm.query.ObjectFactory();
    bodyType.getAny().add(psmOf.createPsmheader(headerType));
    bodyType.getAny().add(psmOf.createRequest(queryDefinitionRequestType));
    // new QueryToolDTOFactory().buildBodyType(headerType,
    // queryDefinitionRequestType, null);
    MessageHeaderType messageHeader = getMessageHeader();
    RequestMessageType requestMessageType = new RequestMessageType();
    requestMessageType.setMessageBody(bodyType);
    requestMessageType.setMessageHeader(messageHeader);
    requestMessageType.setRequestHeader(requestHeader);
    // dtoFactory.getRequestMessageType(messageHeader, requestHeader,
    // bodyType);

    JAXBUtil jaxbUtil = PreviousQueryJAXBUtil.getJAXBUtil();
    StringWriter strWriter = new StringWriter();
    try {
      edu.harvard.i2b2.crcxmljaxb.datavo.i2b2message.ObjectFactory of =
          new edu.harvard.i2b2.crcxmljaxb.datavo.i2b2message.ObjectFactory();
      jaxbUtil.marshaller(of.createRequest(requestMessageType), strWriter);
    } catch (Exception e) {
      e.printStackTrace();
    }

    return strWriter.toString();
  }