Example usage for javax.xml.datatype XMLGregorianCalendar getMonth

List of usage examples for javax.xml.datatype XMLGregorianCalendar getMonth

Introduction

In this page you can find the example usage for javax.xml.datatype XMLGregorianCalendar getMonth.

Prototype

public abstract int getMonth();

Source Link

Document

Returns the month of this calendar or DatatypeConstants#FIELD_UNDEFINED .

Usage

From source file:ca.phon.session.io.xml.v12.XMLSessionReader_v12.java

private Participant copyParticipant(SessionFactory factory, ParticipantType pt, LocalDate sessionDate) {
    final Participant retVal = factory.createParticipant();

    retVal.setId(pt.getId());/*from  www . j  a  v a2s .  com*/
    retVal.setName(pt.getName());

    final XMLGregorianCalendar bday = pt.getBirthday();
    if (bday != null) {
        final LocalDate bdt = LocalDate.of(bday.getYear(), bday.getMonth(), bday.getDay());
        retVal.setBirthDate(bdt);

        // calculate age up to the session date
        final Period period = Period.between(bdt, sessionDate);
        retVal.setAgeTo(period);
    }

    final Duration ageDuration = pt.getAge();
    if (ageDuration != null) {
        // convert to period
        final Period age = Period.of(ageDuration.getYears(), ageDuration.getMonths(), ageDuration.getDays());
        retVal.setAge(age);
    }

    retVal.setEducation(pt.getEducation());
    retVal.setGroup(pt.getGroup());

    String langs = "";
    for (String lang : pt.getLanguage())
        langs += (langs.length() > 0 ? ", " : "") + lang;
    retVal.setLanguage(langs);

    if (pt.getSex() == SexType.MALE)
        retVal.setSex(Sex.MALE);
    else if (pt.getSex() == SexType.FEMALE)
        retVal.setSex(Sex.FEMALE);
    else
        retVal.setSex(Sex.UNSPECIFIED);

    ParticipantRole prole = ParticipantRole.fromString(pt.getRole());
    if (prole == null)
        prole = ParticipantRole.TARGET_CHILD;
    retVal.setRole(prole);

    retVal.setSES(pt.getSES());

    return retVal;
}

From source file:ca.phon.session.io.xml.v12.XMLSessionReader_v12.java

/**
 * Read session in from given xml {@link SessionType} object.
 * /* w  w  w  . j  ava  2 s  . c  o m*/
 * @param sessionType
 * 
 * @return session
 */
private Session readSessionType(SessionType sessionType) {
    final SessionFactory factory = SessionFactory.newFactory();
    final Session retVal = factory.createSession();

    // copy header info
    retVal.setName(sessionType.getId());
    retVal.setCorpus(sessionType.getCorpus());

    final HeaderType headerData = sessionType.getHeader();
    if (headerData != null) {
        if (headerData.getMedia() != null && headerData.getMedia().length() > 0) {
            retVal.setMediaLocation(headerData.getMedia());
        }
        if (headerData.getDate() != null) {
            final XMLGregorianCalendar xmlDate = headerData.getDate();
            final LocalDate dateTime = LocalDate.of(xmlDate.getYear(), xmlDate.getMonth(), xmlDate.getDay());
            retVal.setDate(dateTime);
        }
        if (headerData.getLanguage().size() > 0) {
            String langs = "";
            for (String lang : headerData.getLanguage()) {
                langs += (langs.length() > 0 ? " " : "") + lang;
            }
            retVal.setLanguage(langs);
        }
    }

    // copy participant information
    final ParticipantsType participants = sessionType.getParticipants();
    if (participants != null) {
        for (ParticipantType pt : participants.getParticipant()) {
            final Participant p = copyParticipant(factory, pt, retVal.getDate());
            retVal.addParticipant(p);
        }
    }

    // copy transcriber information
    final TranscribersType transcribers = sessionType.getTranscribers();
    if (transcribers != null) {
        for (TranscriberType tt : transcribers.getTranscriber()) {
            final Transcriber t = copyTranscriber(factory, tt);
            retVal.addTranscriber(t);
        }
    }

    // copy tier information
    final UserTiersType userTiers = sessionType.getUserTiers();
    if (userTiers != null) {
        for (UserTierType utt : userTiers.getUserTier()) {
            final TierDescription td = copyTierDescription(factory, utt);
            retVal.addUserTier(td);
        }
    }

    final List<TierViewItem> tierOrder = new ArrayList<TierViewItem>();
    for (TvType tot : sessionType.getTierOrder().getTier()) {
        final TierViewItem toi = copyTierViewItem(factory, tot);
        tierOrder.add(toi);
    }
    retVal.setTierView(tierOrder);

    // copy transcript data
    final List<Comment> recordComments = new ArrayList<Comment>();
    boolean foundFirstRecord = false;
    if (sessionType.getTranscript() != null) {
        for (Object uOrComment : sessionType.getTranscript().getUOrComment()) {
            if (uOrComment instanceof CommentType) {
                final CommentType ct = (CommentType) uOrComment;
                final Comment comment = copyComment(factory, ct);
                recordComments.add(comment);
            } else {
                if (!foundFirstRecord && recordComments.size() > 0) {
                    // add record comments to session metadata
                    for (Comment c : recordComments) {
                        retVal.getMetadata().addComment(c);
                    }
                    recordComments.clear();
                }
                final RecordType rt = (RecordType) uOrComment;

                Record record = null;
                try {
                    record = new LazyRecord(factory, retVal, rt);
                } catch (Exception e) {
                    LOGGER.info(rt.getId());
                    LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e);

                }

                retVal.addRecord(record);

                for (Comment comment : recordComments) {
                    record.addComment(comment);
                }
                recordComments.clear();
                foundFirstRecord = true;
            }
        }
    }

    return retVal;
}

From source file:org.apache.cxf.cwiki.SiteExporter.java

public String breadcrumbs(BlogEntrySummary page) {
    StringBuffer buffer = new StringBuffer();
    if (breadCrumbRoot != null) {
        buffer.append("<a href=\"");
        buffer.append("../../../index.html");
        buffer.append("\">");
        buffer.append(breadCrumbRoot);/*w w  w  .ja  v  a2s  . c om*/
        buffer.append("</a>");
        buffer.append(SEPARATOR);
    } else {
        buffer.append("<a href=\"../../../index.html\">Index</a>");
        buffer.append(SEPARATOR);
    }
    XMLGregorianCalendar published = page.getPublished();
    buffer.append(String.valueOf(published.getYear()));
    buffer.append(SEPARATOR);
    if (published.getMonth() < 10) {
        buffer.append("0");
    }
    buffer.append(String.valueOf(published.getMonth()));
    buffer.append(SEPARATOR);
    if (published.getDay() < 10) {
        buffer.append("0");
    }
    buffer.append(String.valueOf(published.getDay()));
    buffer.append(SEPARATOR);
    buffer.append("<a href=\"");
    buffer.append(page.createFileName());
    buffer.append("\">");
    buffer.append(page.getTitle());
    buffer.append("</a>");
    return buffer.toString();
}

From source file:edu.harvard.i2b2.previousquery.QueryPreviousRunsPanel.java

public String loadPreviousQueries(boolean getAllInGroup) {
    System.out.println("Loading previous queries for: " + System.getProperty("user"));
    String xmlStr = writeContentQueryXML(getAllInGroup);
    lastRequestMessage = xmlStr;/* w  ww.j  av a  2 s  .  c  om*/
    //System.out.println(xmlStr);

    String responseStr = QueryListNamesClient.sendQueryRequestREST(xmlStr);
    if (responseStr.equalsIgnoreCase("CellDown")) {
        cellStatus = new String("CellDown");
        return "CellDown";
    }
    lastResponseMessage = responseStr;

    try {
        JAXBUtil jaxbUtil = PreviousQueryJAXBUtil.getJAXBUtil();
        JAXBElement jaxbElement = jaxbUtil.unMashallFromString(responseStr);
        ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();
        BodyType bt = messageType.getMessageBody();
        MasterResponseType masterResponseType = (MasterResponseType) new JAXBUnWrapHelper().getObjectByClass(
                bt.getAny(), edu.harvard.i2b2.crcxmljaxb.datavo.psm.query.MasterResponseType.class);
        previousQueries = new ArrayList<QueryMasterData>();
        for (QueryMasterType queryMasterType : masterResponseType.getQueryMaster()) {
            QueryMasterData tmpData;
            tmpData = new QueryMasterData();
            XMLGregorianCalendar cldr = queryMasterType.getCreateDate();
            tmpData.name(
                    queryMasterType.getName() + " [" + addZero(cldr.getMonth()) + "-" + addZero(cldr.getDay())
                            + "-" + addZero(cldr.getYear()) + " ]" + " [" + queryMasterType.getUserId() + "]");
            tmpData.tooltip("A query run by " + queryMasterType.getUserId());//System.getProperty("user"));
            tmpData.visualAttribute("CA");
            tmpData.xmlContent(null);
            tmpData.id(new Integer(queryMasterType.getQueryMasterId()).toString());
            tmpData.userId(queryMasterType.getUserId()); //System.getProperty("user"));
            previousQueries.add(tmpData);
        }
        return "";
    } catch (Exception e) {
        e.printStackTrace();
        return "error";
    }
}

From source file:edu.harvard.i2b2.previousquery.QueryPreviousRunsPanel.java

private void populateChildNodes(DefaultMutableTreeNode node) {
    if (node.getUserObject().getClass().getSimpleName().equalsIgnoreCase("QueryMasterData")) {
        QueryMasterData data = (QueryMasterData) node.getUserObject();
        try {/*  www  .j  av a2  s .c o m*/
            String xmlRequest = data.writeContentQueryXML();
            lastRequestMessage = xmlRequest;
            //System.out.println(xmlRequest);
            String xmlResponse = QueryListNamesClient.sendQueryRequestREST(xmlRequest);
            if (xmlResponse.equalsIgnoreCase("CellDown")) {
                final JPanel parent = this;
                java.awt.EventQueue.invokeLater(new Runnable() {
                    public void run() {
                        JOptionPane.showMessageDialog(parent,
                                "Trouble with connection to the remote server, "
                                        + "this is often a network error, please try again",
                                "Network Error", JOptionPane.INFORMATION_MESSAGE);
                    }
                });
                return;
            }
            lastResponseMessage = xmlResponse;

            try {
                JAXBUtil jaxbUtil = PreviousQueryJAXBUtil.getJAXBUtil();
                JAXBElement jaxbElement = jaxbUtil.unMashallFromString(xmlResponse);
                ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();

                BodyType bt = messageType.getMessageBody();
                InstanceResponseType instanceResponseType = (InstanceResponseType) new JAXBUnWrapHelper()
                        .getObjectByClass(bt.getAny(), InstanceResponseType.class);

                for (QueryInstanceType queryInstanceType : instanceResponseType.getQueryInstance()) {
                    //change later for working with new xml schema
                    //RunQuery runQuery = queryInstanceType.getResult().get(i).getRunQuery().get(0);

                    QueryInstanceData runData = new QueryInstanceData();

                    runData.visualAttribute("FA");
                    runData.tooltip("The results of the query run");
                    runData.id(new Integer(queryInstanceType.getQueryInstanceId()).toString());
                    //runData.patientRefId(new Integer(queryInstanceType.getRefId()).toString());
                    //runData.patientCount(new Long(queryInstanceType.getCount()).toString());
                    XMLGregorianCalendar cldr = queryInstanceType.getStartDate();
                    runData.name("Results of " + "[" + addZero(cldr.getMonth()) + "-" + addZero(cldr.getDay())
                            + "-" + addZero(cldr.getYear()) + " " + addZero(cldr.getHour()) + ":"
                            + addZero(cldr.getMinute()) + ":" + addZero(cldr.getSecond()) + "]");

                    data.runs.add(runData);
                    addNode(runData, node);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

            jTree1.scrollPathToVisible(new TreePath(node.getPath()));
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else if (node.getUserObject().getClass().getSimpleName().equalsIgnoreCase("QueryInstanceData")) {
        QueryInstanceData data = (QueryInstanceData) node.getUserObject();

        try {
            String xmlRequest = data.writeContentQueryXML();
            lastRequestMessage = xmlRequest;
            //System.out.println(xmlRequest);

            String xmlResponse = QueryListNamesClient.sendQueryRequestREST(xmlRequest);
            if (xmlResponse.equalsIgnoreCase("CellDown")) {
                final JPanel parent = this;
                java.awt.EventQueue.invokeLater(new Runnable() {
                    public void run() {
                        JOptionPane.showMessageDialog(parent,
                                "Trouble with connection to the remote server, "
                                        + "this is often a network error, please try again",
                                "Network Error", JOptionPane.INFORMATION_MESSAGE);
                    }
                });
                return;
            }
            lastResponseMessage = xmlResponse;

            JAXBUtil jaxbUtil = PreviousQueryJAXBUtil.getJAXBUtil();

            JAXBElement jaxbElement = jaxbUtil.unMashallFromString(xmlResponse);
            ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();
            BodyType bt = messageType.getMessageBody();
            ResultResponseType resultResponseType = (ResultResponseType) new JAXBUnWrapHelper()
                    .getObjectByClass(bt.getAny(), ResultResponseType.class);

            for (QueryResultInstanceType queryResultInstanceType : resultResponseType
                    .getQueryResultInstance()) {
                String status = queryResultInstanceType.getQueryStatusType().getName();

                QueryResultData resultData = new QueryResultData();
                resultData.visualAttribute("LAO");
                resultData.tooltip("A patient set of the query run");
                //resultData.queryId(data.queryId());
                resultData.patientRefId(new Integer(queryResultInstanceType.getResultInstanceId()).toString());//data.patientRefId());
                resultData.patientCount(new Integer(queryResultInstanceType.getSetSize()).toString());//data.patientCount());
                if (status.equalsIgnoreCase("FINISHED")) {
                    resultData.name("Patient Set - " + resultData.patientCount() + " Patients");
                } else {
                    resultData.name("Patient Set - " + status);
                }
                resultData.xmlContent(xmlResponse);

                addNode(resultData, node);
            }

            jTree1.scrollPathToVisible(new TreePath(node.getPath()));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    //implement for other type of nodes later!!!
}

From source file:com.microsoft.exchange.integration.TimeZoneIntegrationTest.java

@Test
public void createGetDeleteCalendarItem() throws DatatypeConfigurationException {

    TimeZone utcTimeZone = TimeZone.getTimeZone(RequestServerTimeZoneInterceptor.FALLBACK_TIMEZONE_ID);
    TimeZone.setDefault(utcTimeZone);

    ApplicationContext context = new ClassPathXmlApplicationContext(
            "classpath:test-contexts/exchangeContext.xml");
    RequestServerTimeZoneInterceptor timeZoneInterceptor = context
            .getBean(RequestServerTimeZoneInterceptor.class);
    ExchangeWebServices ews = context.getBean(ExchangeWebServices.class);
    BaseExchangeCalendarDataDao exchangeCalendarDao = context.getBean(BaseExchangeCalendarDataDao.class);
    exchangeCalendarDao.setWebServices(ews);

    assertEquals(TimeZone.getDefault(), utcTimeZone);

    //XMLGregorianCalendar is sortof backed by a gregorian calendar, date/times should reflect default jvm timezone
    XMLGregorianCalendar xmlStart = DateHelp.getXMLGregorianCalendarNow();

    CalendarItemType calendarItem = new CalendarItemType();
    calendarItem.setStart(xmlStart);//from   ww  w.  j  ava 2  s. co  m

    ItemIdType itemId = exchangeCalendarDao.createCalendarItem(upn, calendarItem);
    assertNotNull(itemId);
    Set<ItemIdType> itemIds = Collections.singleton(itemId);
    Set<CalendarItemType> calendarItems = exchangeCalendarDao.getCalendarItems(upn, itemIds);
    assertNotNull(calendarItems);
    CalendarItemType createdCalendarItem = DataAccessUtils.singleResult(calendarItems);
    assertNotNull(createdCalendarItem);
    XMLGregorianCalendar createdCalendarItemStart = createdCalendarItem.getStart();

    assertNotNull(createdCalendarItemStart);
    assertEquals(xmlStart.getTimezone(), createdCalendarItemStart.getTimezone());

    //nope! tzDisplayName = createdCalendarItem.getTimeZone()
    //assertEquals(RequestServerTimeZoneInterceptor.FALLBACK_TIMEZONE_ID, createdCalendarItem.getTimeZone());

    assertEquals(xmlStart.getEon(), createdCalendarItemStart.getEon());
    assertEquals(xmlStart.getEonAndYear(), createdCalendarItemStart.getEonAndYear());
    assertEquals(xmlStart.getYear(), createdCalendarItemStart.getYear());
    assertEquals(xmlStart.getMonth(), createdCalendarItemStart.getMonth());
    assertEquals(xmlStart.getDay(), createdCalendarItemStart.getDay());
    assertEquals(xmlStart.getHour(), createdCalendarItemStart.getHour());
    assertEquals(xmlStart.getMinute(), createdCalendarItemStart.getMinute());
    assertEquals(xmlStart.getSecond(), createdCalendarItemStart.getSecond());

    //nope!  always seems to be a slight variation
    //assertEquals(xmlStart.toGregorianCalendar().getTimeInMillis(), createdCalendarItemStart.toGregorianCalendar().getTimeInMillis());
    //assertEquals(xmlStart.getMillisecond(), createdCalendarItemStart.getMillisecond());   
    //assertEquals(xmlStart.getFractionalSecond(), createdCalendarItemStart.getFractionalSecond());

    assertTrue(DateHelp.withinOneSecond(xmlStart, createdCalendarItemStart));

    assertTrue(exchangeCalendarDao.deleteCalendarItems(upn, itemIds));
}

From source file:edu.harvard.i2b2.previousquery.ui.QueryPreviousRunsPanel.java

public String loadPreviousQueries(boolean getAllInGroup) {
    System.out.println("Loading previous queries for: " + System.getProperty("user"));
    String xmlStr = writeContentQueryXML(getAllInGroup);
    // System.out.println(xmlStr);

    String responseStr = null;/* ww  w . j a v a 2 s .co m*/
    if (System.getProperty("webServiceMethod").equals("SOAP")) {
        responseStr = QueryListNamesClient.sendQueryRequestSOAP(xmlStr);
    } else {
        responseStr = QueryListNamesClient.sendQueryRequestREST(xmlStr);
    }

    if (responseStr.equalsIgnoreCase("CellDown")) {
        cellStatus = new String("CellDown");
        return "CellDown";
    }

    try {
        JAXBUtil jaxbUtil = PreviousQueryJAXBUtil.getJAXBUtil();
        JAXBElement jaxbElement = jaxbUtil.unMashallFromString(responseStr);
        ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();
        BodyType bt = messageType.getMessageBody();
        MasterResponseType masterResponseType = (MasterResponseType) new JAXBUnWrapHelper().getObjectByClass(
                bt.getAny(), edu.harvard.i2b2.crcxmljaxb.datavo.psm.query.MasterResponseType.class);
        for (Condition status : masterResponseType.getStatus().getCondition()) {
            if (status.getType().equals("ERROR"))
                cellStatus = new String("CellDown");
        }
        previousQueries = new ArrayList<QueryMasterData>();
        for (QueryMasterType queryMasterType : masterResponseType.getQueryMaster()) {
            QueryMasterData tmpData;
            tmpData = new QueryMasterData();
            XMLGregorianCalendar cldr = queryMasterType.getCreateDate();
            tmpData.name(
                    queryMasterType.getName() + " [" + addZero(cldr.getMonth()) + "-" + addZero(cldr.getDay())
                            + "-" + addZero(cldr.getYear()) + " ]" + " [" + queryMasterType.getUserId() + "]");
            tmpData.tooltip("A query run by " + queryMasterType.getUserId());// System.
            // getProperty
            // ("user"));
            tmpData.visualAttribute("CA");
            tmpData.xmlContent(null);
            tmpData.id(queryMasterType.getQueryMasterId());
            tmpData.userId(queryMasterType.getUserId()); //System.getProperty
            // ("user"));
            previousQueries.add(tmpData);
        }
        return "";
    } catch (Exception e) {
        e.printStackTrace();
        return "error";
    }
}

From source file:edu.harvard.i2b2.previousquery.ui.PreviousQueryPanel.java

@SuppressWarnings("unchecked")
public String loadPreviousQueries(String user) {
    System.out.println("Loading previous queries for: " + System.getProperty("user"));
    String xmlStr = writeContentQueryXML(user);
    // System.out.println(xmlStr);

    String responseStr = null;/*from w w w .  j a  v a 2  s. com*/
    if (System.getProperty("webServiceMethod").equals("SOAP")) {
        responseStr = QueryListNamesClient.sendQueryRequestSOAP(xmlStr);
    } else {
        responseStr = QueryListNamesClient.sendQueryRequestREST(xmlStr);
    }

    if (responseStr.equalsIgnoreCase("CellDown")) {
        cellStatus = new String("CellDown");
        return "CellDown";
    }

    try {
        JAXBUtil jaxbUtil = PreviousQueryJAXBUtil.getJAXBUtil();
        JAXBElement jaxbElement = jaxbUtil.unMashallFromString(responseStr);
        ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();
        BodyType bt = messageType.getMessageBody();
        MasterResponseType masterResponseType = (MasterResponseType) new JAXBUnWrapHelper().getObjectByClass(
                bt.getAny(), edu.harvard.i2b2.crcxmljaxb.datavo.psm.query.MasterResponseType.class);
        for (Condition status : masterResponseType.getStatus().getCondition()) {
            if (status.getType().equals("ERROR"))
                cellStatus = new String("CellDown");
        }
        previousQueries = new ArrayList<QueryMasterData>();
        for (QueryMasterType queryMasterType : masterResponseType.getQueryMaster()) {
            QueryMasterData tmpData;
            tmpData = new QueryMasterData();
            XMLGregorianCalendar cldr = queryMasterType.getCreateDate();
            tmpData.name(
                    queryMasterType.getName() + " [" + addZero(cldr.getMonth()) + "-" + addZero(cldr.getDay())
                            + "-" + addZero(cldr.getYear()) + " ]" + " [" + queryMasterType.getUserId() + "]");
            tmpData.creationTime(cldr);//.clone());
            tmpData.creationTimeStr(
                    addZero(cldr.getMonth()) + "-" + addZero(cldr.getDay()) + "-" + addZero(cldr.getYear())
                            + " " + cldr.getHour() + ":" + cldr.getMinute() + ":" + cldr.getSecond());
            tmpData.tooltip("A query run by " + queryMasterType.getUserId());// System.
            // getProperty
            // ("user"));
            tmpData.visualAttribute("CA");
            tmpData.xmlContent(null);
            tmpData.id(queryMasterType.getQueryMasterId());
            tmpData.userId(queryMasterType.getUserId()); // System.getProperty
            // ("user"));
            if (queryMasterType.getMasterTypeCd() != null) {
                tmpData.queryType(queryMasterType.getMasterTypeCd());
            }
            previousQueries.add(tmpData);
        }
        return "";
    } catch (Exception e) {
        e.printStackTrace();
        return "error";
    }
}

From source file:edu.harvard.i2b2.previousquery.ui.PreviousQueryPanel.java

private void jFindButtonActionPerformed(java.awt.event.ActionEvent evt) {
    System.out.println("Loading previous queries for: " + System.getProperty("user"));

    cellStatus = "";
    String searchStr = this.jSearchStringTextField.getText();
    int category = this.jCategoryComboBox.getSelectedIndex();
    int strategy = this.jContainComboBox.getSelectedIndex();

    String xmlStr = writeFindQueryXML(searchStr, category, strategy);
    // System.out.println(xmlStr);

    String responseStr = null;//  w  w w.j av  a2 s.  com
    if (System.getProperty("webServiceMethod").equals("SOAP")) {
        responseStr = QueryListNamesClient.sendQueryRequestSOAP(xmlStr);
    } else {
        responseStr = QueryListNamesClient.sendFindQueryRequestREST(xmlStr);
    }

    if (responseStr.equalsIgnoreCase("CellDown")) {
        cellStatus = new String("CellDown");
        return; //"CellDown";
    }

    try {
        JAXBUtil jaxbUtil = PreviousQueryJAXBUtil.getJAXBUtil();
        JAXBElement jaxbElement = jaxbUtil.unMashallFromString(responseStr);
        ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();
        BodyType bt = messageType.getMessageBody();
        MasterResponseType masterResponseType = (MasterResponseType) new JAXBUnWrapHelper().getObjectByClass(
                bt.getAny(), edu.harvard.i2b2.crcxmljaxb.datavo.psm.query.MasterResponseType.class);
        for (Condition status : masterResponseType.getStatus().getCondition()) {
            if (status.getType().equals("ERROR"))
                cellStatus = new String("CellDown");
        }
        previousQueries = new ArrayList<QueryMasterData>();
        for (QueryMasterType queryMasterType : masterResponseType.getQueryMaster()) {
            QueryMasterData tmpData;
            tmpData = new QueryMasterData();
            XMLGregorianCalendar cldr = queryMasterType.getCreateDate();
            tmpData.name(
                    queryMasterType.getName() + " [" + addZero(cldr.getMonth()) + "-" + addZero(cldr.getDay())
                            + "-" + addZero(cldr.getYear()) + " ]" + " [" + queryMasterType.getUserId() + "]");
            tmpData.tooltip("A query run by " + queryMasterType.getUserId());// System.
            // getProperty
            // ("user"));
            tmpData.visualAttribute("CA");
            tmpData.xmlContent(null);
            tmpData.id(queryMasterType.getQueryMasterId());
            tmpData.userId(queryMasterType.getUserId()); // System.getProperty
            // ("user"));
            previousQueries.add(tmpData);
        }

        if (previousQueries.size() == 0) {
            final JPanel parent = this;
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    JOptionPane.showMessageDialog(parent, "No results were found.", "Not Found",
                            JOptionPane.INFORMATION_MESSAGE);
                }
            });
            return;
        }

        if (cellStatus.equalsIgnoreCase("")) {
            reset(200, false, false);
        } else if (cellStatus.equalsIgnoreCase("CellDown")) {
            final JPanel parent = this;
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    JOptionPane.showMessageDialog(parent,
                            "Trouble with connection to the remote server, "
                                    + "this is often a network error, please try again",
                            "Network Error", JOptionPane.INFORMATION_MESSAGE);
                }
            });
        }
        return;
    } catch (Exception e) {
        e.printStackTrace();
        return;
    }
}

From source file:edu.harvard.i2b2.previousquery.ui.PreviousQueryPanel.java

private void jForwardButtonActionPerformed(java.awt.event.ActionEvent evt) {
    System.out.println("Loading previous queries for: " + System.getProperty("user"));

    cellStatus = "";
    String searchStr = jSearchStringTextField.getText();
    int category = jCategoryComboBox.getSelectedIndex();
    int strategy = jContainComboBox.getSelectedIndex();

    curCreationDate = previousQueries.get(previousQueries.size() - 1).creationTime();
    ////////////////////////////////////////////////
    SimpleDateFormat df = new SimpleDateFormat("MM-dd-yyyy HH:mm:ss");//.getDateInstance();
    Date date = null;/*from  w w w  . ja  v a 2 s.  c o  m*/
    try {
        date = df.parse(this.jStartTimeTextField.getText());
    } catch (Exception e) {
        e.printStackTrace();
    }
    DTOFactory dtoFactory = new DTOFactory();

    TimeZone tz = Calendar.getInstance().getTimeZone();
    GregorianCalendar cal = new GregorianCalendar(tz);
    cal.setTime(date);
    //cal.get(Calendar.ZONE_OFFSET);
    int zt_offset = (cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET)) / 60000;
    //log.info("Timezone: "+tz.getID()+" : "+zt_offset);

    //if (startTime() != -1) {
    ConstrainDateType constraindateType = new ConstrainDateType();
    XMLGregorianCalendar xmlC = dtoFactory.getXMLGregorianCalendarDate(cal.get(GregorianCalendar.YEAR),
            cal.get(GregorianCalendar.MONTH) + 1, cal.get(GregorianCalendar.DAY_OF_MONTH));
    xmlC.setTimezone(zt_offset);//0);//-5*60);
    xmlC.setHour(cal.get(GregorianCalendar.HOUR_OF_DAY));
    xmlC.setMinute(cal.get(GregorianCalendar.MINUTE));
    xmlC.setSecond(cal.get(GregorianCalendar.SECOND));
    constraindateType.setValue(xmlC);
    //timeConstrain.setDateFrom(constraindateType);
    //}
    ////////////////////////////////////////////////
    String xmlStr = writePagingQueryXML("", category, strategy, false, xmlC);//curCreationDate);
    // System.out.println(xmlStr);

    String responseStr = null;
    if (System.getProperty("webServiceMethod").equals("SOAP")) {
        responseStr = QueryListNamesClient.sendQueryRequestSOAP(xmlStr);
    } else {
        responseStr = QueryListNamesClient.sendFindQueryRequestREST(xmlStr);
    }

    if (responseStr.equalsIgnoreCase("CellDown")) {
        cellStatus = new String("CellDown");
        return; //"CellDown";
    }

    try {
        JAXBUtil jaxbUtil = PreviousQueryJAXBUtil.getJAXBUtil();
        JAXBElement jaxbElement = jaxbUtil.unMashallFromString(responseStr);
        ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();
        BodyType bt = messageType.getMessageBody();
        MasterResponseType masterResponseType = (MasterResponseType) new JAXBUnWrapHelper().getObjectByClass(
                bt.getAny(), edu.harvard.i2b2.crcxmljaxb.datavo.psm.query.MasterResponseType.class);
        for (Condition status : masterResponseType.getStatus().getCondition()) {
            if (status.getType().equals("ERROR"))
                cellStatus = new String("CellDown");
        }
        previousQueries = new ArrayList<QueryMasterData>();
        for (QueryMasterType queryMasterType : masterResponseType.getQueryMaster()) {
            QueryMasterData tmpData;
            tmpData = new QueryMasterData();
            XMLGregorianCalendar cldr = queryMasterType.getCreateDate();
            tmpData.name(
                    queryMasterType.getName() + " [" + addZero(cldr.getMonth()) + "-" + addZero(cldr.getDay())
                            + "-" + addZero(cldr.getYear()) + " ]" + " [" + queryMasterType.getUserId() + "]");
            tmpData.creationTime(cldr);//.clone());
            tmpData.creationTimeStr(
                    addZero(cldr.getMonth()) + "-" + addZero(cldr.getDay()) + "-" + addZero(cldr.getYear())
                            + " " + cldr.getHour() + ":" + cldr.getMinute() + ":" + cldr.getSecond());
            tmpData.tooltip("A query run by " + queryMasterType.getUserId());// System.
            // getProperty
            // ("user"));
            tmpData.visualAttribute("CA");
            tmpData.xmlContent(null);
            tmpData.id(queryMasterType.getQueryMasterId());
            tmpData.userId(queryMasterType.getUserId()); // System.getProperty
            // ("user"));
            previousQueries.add(tmpData);
        }

        if (previousQueries.size() == 0) {
            final JPanel parent = this;
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    JOptionPane.showMessageDialog(parent, "No results were found.", "Not Found",
                            JOptionPane.INFORMATION_MESSAGE);
                }
            });
            return;
        }

        if (cellStatus.equalsIgnoreCase("")) {
            reset(200, false, false);
        } else if (cellStatus.equalsIgnoreCase("CellDown")) {
            final JPanel parent = this;
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    JOptionPane.showMessageDialog(parent,
                            "Trouble with connection to the remote server, "
                                    + "this is often a network error, please try again",
                            "Network Error", JOptionPane.INFORMATION_MESSAGE);
                }
            });
        }
        return;
    } catch (Exception e) {
        e.printStackTrace();
        return;
    }
}