Example usage for java.util Date getMinutes

List of usage examples for java.util Date getMinutes

Introduction

In this page you can find the example usage for java.util Date getMinutes.

Prototype

@Deprecated
public int getMinutes() 

Source Link

Document

Returns the number of minutes past the hour represented by this date, as interpreted in the local time zone.

Usage

From source file:pa_SymposiumPlanner.ECAI2012LiaisonChair.java

public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    try {//  ww w  .  ja  v  a 2  s . c  o m
        address = PAConfiguration.getAddress();
        port = PAConfiguration.getPort(instantiation);
        poslAddress = PAConfiguration.getPOSL(instantiation, topic);
        rdfAddress = PAConfiguration.getRDFTaxonomy(instantiation);
        messageEndpoint = PAConfiguration.getEndpointName(instantiation, topic);
    } catch (BadConfigurationException e) {
        System.out.println(e.getMessage());
        e.printStackTrace();
        System.exit(0);
    }

    response.setContentType("text/html; charset=UTF-8");
    PrintWriter out = response.getWriter();

    try {

        System.out.println("Liaison Chair Servlet 123");
        System.out.println(response.toString());

        BufferedReader brd = request.getReader();

        String input = "";
        String message = "";

        while (!input.equals("</RuleML>")) {

            input = brd.readLine();

            message = message + input;
        }
        String[] varOrder = getVariableOrder(message);
        System.out.println("Received Message: " + message);

        //   BackwardReasoner br = new BackwardReasoner();
        //   Iterator solit =null;
        //   DefiniteClause dc = null;
        //   SymbolTable.reset();

        POSLParser pp = new POSLParser();
        // String contents = "c(a).\nc(b).\nc(c).";

        Date t1 = new GregorianCalendar().getTime();
        System.out.println(t1.getHours() + ":" + t1.getMinutes());
        //append time to contents

        System.out.println("day: " + t1.getDay());
        System.out.println("day: " + t1.getYear());
        System.out.println("day: " + t1.getMonth());

        //time
        String time = "time(" + t1.getHours() + ":integer).";
        System.out.println(time);

        String url = poslAddress;

        //String url = "http://www.jdrew.org/oojdrew/test.posl";
        String contents = "";

        //day of the week
        int day = t1.getDay();
        boolean weekday = true;

        if (day == 0 || day == 6) {
            weekday = false;
        }

        String dayOfWeek;

        if (weekday) {
            dayOfWeek = "day(weekday).";
        } else {
            dayOfWeek = "day(weekend).";
        }
        //full date 
        Calendar cal = new GregorianCalendar();

        int year = cal.get(Calendar.YEAR);
        int month = cal.get(Calendar.MONTH) + 1;
        int day2 = cal.get(Calendar.DAY_OF_MONTH);

        String date;

        String day3 = "" + day2;

        if (day2 == 1 || day2 == 2 || day2 == 3 || day2 == 4 || day2 == 5 || day2 == 6 || day2 == 7 || day2 == 8
                || day2 == 9) {

            day3 = "0" + day2;
        }

        if (month == 10 || month == 11 || month == 12)
            date = "" + year + month + day3;
        else
            date = "" + year + "0" + month + day3;

        date = "date(" + date + ":integer).";

        System.out.println(date);

        String url2 = rdfAddress;
        HttpClient client2 = new HttpClient();
        GetMethod method2 = new GetMethod(url2);
        method2.setFollowRedirects(true);
        String typestr = "";
        // Execute the GET method
        int statusCode2 = client2.executeMethod(method2);
        if (statusCode2 != -1) {
            typestr = method2.getResponseBodyAsString();
        }
        System.out.println("Types: " + typestr);
        Types.reset();
        RDFSParser.parseRDFSString(typestr);

        try {
            HttpClient client = new HttpClient();
            GetMethod method = new GetMethod(url);
            method.setFollowRedirects(true);

            // Execute the GET method
            int statusCode = client.executeMethod(method);
            if (statusCode != -1) {
                contents = method.getResponseBodyAsString();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        contents = contents + "\n" + time;
        contents = contents + "\n" + dayOfWeek;
        contents = contents + "\n" + date;

        BackwardReasoner br = new BackwardReasoner();
        Iterator solit = null;
        DefiniteClause dc = null;
        SymbolTable.reset();

        pp.parseDefiniteClauses(contents);

        br.loadClauses(pp.iterator());

        Iterator it = pp.iterator();
        while (it.hasNext()) {
            DefiniteClause d = (DefiniteClause) it.next();
            System.out.println("Loaded clause: " + d.toPOSLString());
        }

        br = new BackwardReasoner(br.clauses, br.oids);

        MessageParser m = new MessageParser(message);
        Element atom = null;

        try {

            atom = m.parseForContent();

        } catch (Exception e) {

            System.out.println("Invalid Message");
            //out.flush();

        }

        QueryBuilder q = new QueryBuilder(atom);
        String query = q.generateDoc();
        System.out.println("ABOUT TO INPUT THIS QUERY:" + query);
        RuleMLParser qp = new RuleMLParser();

        try {

            dc = qp.parseRuleMLQuery(query);

        }

        catch (Exception e) {
            System.out.println("Invalid Query");
            //out.flush();
        }

        //solit = br.iterativeDepthFirstSolutionIterator(dc);

        solit = br.iterativeDepthFirstSolutionIterator(dc);

        int varSize = 0;
        System.out.println("1");
        while (solit.hasNext()) {

            Vector data = new Vector();

            BackwardReasoner.GoalList gl = (BackwardReasoner.GoalList) solit.next();

            Hashtable varbind = gl.varBindings;
            javax.swing.tree.DefaultMutableTreeNode root = br.toTree();
            root.setAllowsChildren(true);

            javax.swing.tree.DefaultTreeModel dtm = new DefaultTreeModel(root);

            int i = 0;
            Object[][] rowdata = new Object[varbind.size()][2];
            varSize = varbind.size();

            Enumeration e = varbind.keys();
            while (e.hasMoreElements()) {
                Object k = e.nextElement();
                Object val = varbind.get(k);
                String ks = (String) k;
                rowdata[i][0] = ks;
                rowdata[i][1] = val;

                i++;
            }

            data.addElement(rowdata);
            String[] messages = new String[data.size()];
            MessageGenerator g = new MessageGenerator(data, varSize, messageEndpoint, m.getId(),
                    m.getProtocol(), m.getRel(), varOrder);
            messages = g.Messages2();

            String appender = "";

            URL sender = new URL(address + ":" + port);
            HttpMessage msg = new HttpMessage(sender);
            Properties props = new Properties();

            for (int i1 = 0; i1 < data.size(); i1++) {
                System.out.println(i1 + ")" + messages[i1].toString());
                props.put("text", messages[i1].toString());
                InputStream in = msg.sendGetMessage(props);
            }
            System.out.println("NEXT MESSAGE");
        }
        System.out.println("2");
        MessageGenerator g = new MessageGenerator(null, varSize, messageEndpoint, m.getId(), m.getProtocol(),
                m.getRel());

        URL sender = new URL(address + ":" + port);
        HttpMessage msg = new HttpMessage(sender);
        Properties props = new Properties();

        String finalMessage = g.finalMessage(query);

        System.out.println(finalMessage);

        props.put("text", finalMessage);
        InputStream in = msg.sendGetMessage(props);

        System.out.println("Stop_Communication");

    } catch (Exception e) {
        System.out.println("ERROR has occured : " + e.toString());

    }
    out.close();
}

From source file:pa_SymposiumPlanner.RuleML2009PanelChair.java

public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    try {//from   w w w. j av  a  2  s . c  o  m
        address = PAConfiguration.getAddress();
        port = PAConfiguration.getPort(instantiation);
        poslAddress = PAConfiguration.getPOSL(instantiation, topic);
        rdfAddress = PAConfiguration.getRDFTaxonomy(instantiation);
        messageEndpoint = PAConfiguration.getEndpointName(instantiation, topic);
    } catch (BadConfigurationException e) {
        System.out.println(e.getMessage());
        e.printStackTrace();
        System.exit(0);
    }

    response.setContentType("text/html; charset=UTF-8");
    PrintWriter out = response.getWriter();

    try {
        System.out.println("Panel Chair Servlet");
        System.out.println(response.toString());

        BufferedReader brd = request.getReader();

        String input = "";
        String message = "";

        while (!input.equals("</RuleML>")) {

            input = brd.readLine();

            message = message + input;
        }
        String[] varOrder = getVariableOrder(message);
        System.out.println("Received Message: " + message);

        //   BackwardReasoner br = new BackwardReasoner();
        //   Iterator solit =null;
        //   DefiniteClause dc = null;
        //   SymbolTable.reset();

        POSLParser pp = new POSLParser();
        // String contents = "c(a).\nc(b).\nc(c).";

        Date t1 = new GregorianCalendar().getTime();
        System.out.println(t1.getHours() + ":" + t1.getMinutes());
        //append time to contents

        System.out.println("day: " + t1.getDay());
        System.out.println("day: " + t1.getYear());
        System.out.println("day: " + t1.getMonth());

        //time
        String time = "time(" + t1.getHours() + ":integer).";
        System.out.println(time);

        String url = poslAddress;

        //String url = "http://www.jdrew.org/oojdrew/test.posl";
        String contents = "";

        //day of the week
        int day = t1.getDay();
        boolean weekday = true;

        if (day == 0 || day == 6) {
            weekday = false;
        }

        String dayOfWeek;

        if (weekday) {
            dayOfWeek = "day(weekday).";
        } else {
            dayOfWeek = "day(weekend).";
        }
        //full date 
        Calendar cal = new GregorianCalendar();

        int year = cal.get(Calendar.YEAR);
        int month = cal.get(Calendar.MONTH) + 1;
        int day2 = cal.get(Calendar.DAY_OF_MONTH);

        String date;

        String day3 = "" + day2;

        if (day2 == 1 || day2 == 2 || day2 == 3 || day2 == 4 || day2 == 5 || day2 == 6 || day2 == 7 || day2 == 8
                || day2 == 9) {

            day3 = "0" + day2;
        }

        if (month == 10 || month == 11 || month == 12)
            date = "" + year + month + day3;
        else
            date = "" + year + "0" + month + day3;

        date = "date(" + date + ":integer).";

        System.out.println(date);

        String url2 = rdfAddress;
        HttpClient client2 = new HttpClient();
        GetMethod method2 = new GetMethod(url2);
        method2.setFollowRedirects(true);
        String typestr = "";
        // Execute the GET method
        int statusCode2 = client2.executeMethod(method2);
        if (statusCode2 != -1) {
            typestr = method2.getResponseBodyAsString();
        }
        System.out.println("Types: " + typestr);
        Types.reset();
        RDFSParser.parseRDFSString(typestr);

        try {
            HttpClient client = new HttpClient();
            GetMethod method = new GetMethod(url);
            method.setFollowRedirects(true);

            // Execute the GET method
            int statusCode = client.executeMethod(method);
            if (statusCode != -1) {
                contents = method.getResponseBodyAsString();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        contents = contents + "\n" + time;
        contents = contents + "\n" + dayOfWeek;
        contents = contents + "\n" + date;

        BackwardReasoner br = new BackwardReasoner();
        Iterator solit = null;
        DefiniteClause dc = null;
        SymbolTable.reset();

        pp.parseDefiniteClauses(contents);

        br.loadClauses(pp.iterator());

        Iterator it = pp.iterator();
        while (it.hasNext()) {
            DefiniteClause d = (DefiniteClause) it.next();
            System.out.println("Loaded clause: " + d.toPOSLString());
        }

        br = new BackwardReasoner(br.clauses, br.oids);

        MessageParser m = new MessageParser(message);
        Element atom = null;

        try {

            atom = m.parseForContent();

        } catch (Exception e) {

            System.out.println("Invalid Message");
            //out.flush();

        }

        QueryBuilder q = new QueryBuilder(atom);
        String query = q.generateDoc();
        System.out.println("ABOUT TO INPUT THIS QUERY:" + query);
        RuleMLParser qp = new RuleMLParser();

        try {

            dc = qp.parseRuleMLQuery(query);

        }

        catch (Exception e) {
            System.out.println("Invalid Query");
            //out.flush();
        }

        //solit = br.iterativeDepthFirstSolutionIterator(dc);

        solit = br.iterativeDepthFirstSolutionIterator(dc);

        int varSize = 0;

        while (solit.hasNext()) {

            Vector data = new Vector();

            BackwardReasoner.GoalList gl = (BackwardReasoner.GoalList) solit.next();

            Hashtable varbind = gl.varBindings;
            javax.swing.tree.DefaultMutableTreeNode root = br.toTree();
            root.setAllowsChildren(true);

            javax.swing.tree.DefaultTreeModel dtm = new DefaultTreeModel(root);

            int i = 0;
            Object[][] rowdata = new Object[varbind.size()][2];
            varSize = varbind.size();

            Enumeration e = varbind.keys();
            while (e.hasMoreElements()) {
                Object k = e.nextElement();
                Object val = varbind.get(k);
                String ks = (String) k;
                rowdata[i][0] = ks;
                rowdata[i][1] = val;

                i++;
            }

            data.addElement(rowdata);
            String[] messages = new String[data.size()];
            MessageGenerator g = new MessageGenerator(data, varSize, messageEndpoint, m.getId(),
                    m.getProtocol(), m.getRel(), varOrder);
            messages = g.Messages2();

            String appender = "";

            URL sender = new URL(address + ":" + port);
            HttpMessage msg = new HttpMessage(sender);
            Properties props = new Properties();

            for (int i1 = 0; i1 < data.size(); i1++) {
                System.out.println(i1 + ")" + messages[i1].toString());
                props.put("text", messages[i1].toString());
                InputStream in = msg.sendGetMessage(props);
            }
            System.out.println("NEXT MESSAGE");
        }

        MessageGenerator g = new MessageGenerator(null, varSize, messageEndpoint, m.getId(), m.getProtocol(),
                m.getRel());

        URL sender = new URL(address + ":" + port);
        HttpMessage msg = new HttpMessage(sender);
        Properties props = new Properties();

        String finalMessage = g.finalMessage(query);

        System.out.println(finalMessage);

        props.put("text", finalMessage);
        InputStream in = msg.sendGetMessage(props);

        System.out.println("Stop_Communication");

    } catch (Exception e) {
        System.out.println("ERROR has occured : " + e.toString());

    }
    out.close();
}

From source file:org.openmrs.module.kenyaemr.fragment.controller.NextAppointmentCountFragmentController.java

public JSONObject saveAppointment(@RequestParam("patient") Patient patient, @RequestParam("date") String date,
        UiUtils ui) {/*from w w  w .  java 2  s. c  om*/

    Visit activeVisit = null;
    Encounter enounterAvailable = null;

    SimpleDateFormat mysqlDateTimeFormatter = new SimpleDateFormat("dd-MMM-yy");
    Date dateEntered = null;
    try {
        dateEntered = mysqlDateTimeFormatter.parse(date);
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    List<Visit> activeVisitList = Context.getVisitService().getActiveVisitsByPatient(patient);
    for (Visit v : activeVisitList) {
        activeVisit = v;
    }

    List<Obs> obsAllList = Context.getObsService().getObservationsByPersonAndConcept(patient,
            Context.getConceptService().getConceptByUuid(Dictionary.RETURN_VISIT_DATE));

    List<Obs> currentVisitObs = new ArrayList<Obs>();
    for (Obs o : obsAllList) {
        if (o.getEncounter().getVisit().equals(activeVisit)) {
            currentVisitObs.add(o);
        }
    }

    for (Obs o : currentVisitObs) {
        enounterAvailable = o.getEncounter();
    }

    if (enounterAvailable != null) {
        Date curDate = new Date();
        SimpleDateFormat mysqlDateTimeFormatter1 = new SimpleDateFormat("dd-MMM-yy HH:mm:ss");
        Date obsDateTime = null;

        String modifiedDate = new SimpleDateFormat("dd-MMM-yyyy")
                .format(enounterAvailable.getEncounterDatetime());
        try {
            obsDateTime = mysqlDateTimeFormatter1.parse(modifiedDate + " " + curDate.getHours() + ":"
                    + curDate.getMinutes() + ":" + curDate.getSeconds());
        } catch (ParseException e) {
            obsDateTime = curDate;
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        List<Obs> obsList = Context.getObsService().getObservationsByPersonAndConcept(patient,
                Context.getConceptService().getConceptByUuid(Dictionary.RETURN_VISIT_DATE));

        for (Obs o : obsList) {
            if (o.getEncounter().equals(enounterAvailable)) {
                o.setVoided(true);
                o.setVoidReason("updated");
                o.setDateVoided(new Date());
                o.setVoidedBy(Context.getAuthenticatedUser());
            }
        }

        Obs obs = new Obs();
        obs.setEncounter(enounterAvailable);
        obs.setObsDatetime(obsDateTime);
        obs.setPerson(patient);
        obs.setLocation(Context.getService(KenyaEmrService.class).getDefaultLocation());
        obs.setDateCreated(new Date());
        obs.setCreator(Context.getAuthenticatedUser());
        obs.setValueDatetime(dateEntered);
        obs.setConcept(Context.getConceptService().getConceptByUuid(Dictionary.RETURN_VISIT_DATE));
        obs.setComment("next apointment");
        Context.getObsService().saveObs(obs, null);

    } else {
        Date curDate = new Date();
        SimpleDateFormat mysqlDateTimeFormatter1 = new SimpleDateFormat("dd-MMM-yy HH:mm:ss");
        Date encounterDateTime = null;
        if (activeVisit != null) {
            String modifiedDate = new SimpleDateFormat("dd-MMM-yyyy").format(activeVisit.getStartDatetime());
            try {
                encounterDateTime = mysqlDateTimeFormatter1.parse(modifiedDate + " " + curDate.getHours() + ":"
                        + curDate.getMinutes() + ":" + curDate.getSeconds());
            } catch (ParseException e) {
                encounterDateTime = curDate;
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        Encounter newEncounter = new Encounter();
        newEncounter.setEncounterType(
                Context.getEncounterService().getEncounterTypeByUuid("465a92f2-baf8-42e9-9612-53064be868e8"));
        newEncounter.setPatient(patient);
        newEncounter.setLocation(Context.getService(KenyaEmrService.class).getDefaultLocation());
        newEncounter.setDateCreated(new Date());
        newEncounter.setEncounterDatetime(encounterDateTime);
        newEncounter.setVisit(activeVisit);
        newEncounter.setCreator(Context.getAuthenticatedUser());
        newEncounter.setVoided(false);
        enounterAvailable = Context.getEncounterService().saveEncounter(newEncounter);

        List<Obs> obsList = Context.getObsService().getObservationsByPersonAndConcept(patient,
                Context.getConceptService().getConceptByUuid(Dictionary.RETURN_VISIT_DATE));
        for (Obs o : obsList) {
            if (o.getEncounter().equals(enounterAvailable)) {
                o.setVoided(true);
                o.setVoidReason("updated");
                o.setDateVoided(new Date());
                o.setVoidedBy(Context.getAuthenticatedUser());
            }
        }

        Obs obs = new Obs();
        obs.setEncounter(enounterAvailable);
        obs.setObsDatetime(encounterDateTime);
        obs.setPerson(patient);
        obs.setDateCreated(new Date());
        obs.setLocation(Context.getService(KenyaEmrService.class).getDefaultLocation());
        obs.setCreator(Context.getAuthenticatedUser());
        obs.setValueDatetime(dateEntered);
        obs.setConcept(Context.getConceptService().getConceptByUuid(Dictionary.RETURN_VISIT_DATE));
        obs.setComment("next apointment");
        Context.getObsService().saveObs(obs, null);
    }

    int totalPatient = 0;
    JSONObject drugsInfoDetailsJson = new JSONObject();
    drugsInfoDetailsJson.put("count", totalPatient);
    return drugsInfoDetailsJson;
}

From source file:org.opencastproject.capture.impl.SchedulerImpl.java

/**
 * Parses an date to build a cron-like time string.
 * /*from w  w  w . j ava  2s . com*/
 * @param date
 *          The {@code Date} you want returned in a cronstring.
 * @return A cron-like scheduling string in a {@code CronExpression} object.
 * @throws ParseException
 */
public static CronExpression getCronString(Date date) throws ParseException {
    // TODO: Remove the deprecated calls here.
    StringBuilder sb = new StringBuilder();
    sb.append(date.getSeconds() + " ");
    sb.append(date.getMinutes() + " ");
    sb.append(date.getHours() + " ");
    sb.append(date.getDate() + " ");
    sb.append(date.getMonth() + 1 + " "); // Note: Java numbers months from 0-11, Quartz uses 1-12. Sigh.
    sb.append("? ");
    sb.append(date.getYear() + 1900); // Yay java.
    return new CronExpression(sb.toString());
}

From source file:org.mythdroid.activities.Guide.java

/**
 * Round the given Date to the nearest column time
 * @param time/*  ww  w .j av  a2s  .  com*/
 */
private void roundTime(Date time) {
    final int mins = time.getMinutes();
    final int off = mins % colMins;
    if (off == 0)
        return;
    int half = colMins / 2;
    if (half * 2 < colMins)
        half++;
    if (off < half)
        time.setMinutes(mins - off);
    else
        time.setMinutes(mins + (colMins - off));
}

From source file:net.cit.tetrad.dao.management.impl.SubDaoImpl.java

/**
 *  ?    ?//from   w  w  w.  j  a  v a 2  s  .  c  o  m
 * @param dto
 * @return gdInfo
 * @throws Exception
 */
public GraphDefInfo getGraphDefInfoForSubGraph(CommonDto dto) {
    GraphDefInfo gdInfo = new GraphDefInfo();

    try {
        String graphPeriod = StringUtils.getDefaultValueIfNull(dto.getGraph_period(), "1");
        dto.setGraph_period(graphPeriod);
        String startDate = dto.getSdate();
        int deviceCode = dto.getDeviceCode();
        String dsname = dto.getDsname();

        Query query = setIdx(deviceCode);
        Device ddto = (Device) monadService.getFind(query, Device.class);
        dto.setUid(ddto.getUid());

        Date stDate = DateUtil.plusHour(-2);
        Date edDate = new Date();

        long startTime = mainDao.getSubGraphSearchTime(graphPeriod,
                DateUtil.getCurrentDate(stDate, "yyyy-MM-dd"), stDate.getHours() + "",
                stDate.getMinutes() + "");
        long endTime = mainDao.getSubGraphSearchTime(graphPeriod, DateUtil.getCurrentDate(edDate, "yyyy-MM-dd"),
                edDate.getHours() + "", edDate.getMinutes() + "");

        if (!StringUtils.isNull(startDate)) {
            startTime = mainDao.getSubGraphSearchTime(graphPeriod, startDate, dto.getGraph_shour(),
                    dto.getGraph_smin());
            endTime = mainDao.getSubGraphSearchTime(graphPeriod, dto.getEdate(), dto.getGraph_ehour(),
                    dto.getGraph_emin());
        } else {
            String stFullDate = DateUtil.getCurrentDate(stDate, "yyyy-MM-dd HH:mm");
            String edFullDate = DateUtil.getCurrentDate(edDate, "yyyy-MM-dd HH:mm");

            String[] stSplitDate = stFullDate.split(" ");
            String[] edSplitDate = edFullDate.split(" ");
            dto.setSdate(stSplitDate[0]);
            dto.setEdate(edSplitDate[0]);

            String[] stSplitTime = stSplitDate[1].split(":");
            String[] edSplitTime = edSplitDate[1].split(":");

            dto.setGraph_shour(stSplitTime[0]);
            dto.setGraph_smin(stSplitTime[1]);
            dto.setGraph_ehour(edSplitTime[0]);
            dto.setGraph_emin(edSplitTime[1]);
        }

        String[] filters = mainDao.setFilters(dsname, graphPeriod, "");
        String[] graphLegend = mainDao.setGraphLegend(dsname);

        gdInfo.setFileName(dsname);
        gdInfo.setDevice(ddto);
        gdInfo.setStartTime(startTime);
        gdInfo.setEndTime(endTime);
        gdInfo.setFilters(filters);
        gdInfo.setGraphLegend(graphLegend);
        gdInfo.setWidth(SUB_SMALL_GRAPH_WIDTH);
        gdInfo.setHeight(SUB_SMALL_GRAPH_HEIGHT);
        gdInfo.setAxisTimeUnitDiv(graphPeriod);
    } catch (Exception e) {
        log.error(e, e);
    }

    return gdInfo;
}

From source file:ca.oson.json.gson.functional.DefaultTypeAdaptersTest.java

@SuppressWarnings("deprecation")
private void assertEqualsTime(Date date, int hours, int minutes, int seconds) {
    assertEquals(hours, date.getHours());
    assertEquals(minutes, date.getMinutes());
    assertEquals(seconds, date.getSeconds());
}

From source file:org.wso2.carbon.connector.integration.test.tsheets.TSheetsConnectorIntegrationTest.java

/**
 * Set up the environment./*from  w w w .  j av a 2s .  c  o  m*/
 */
@BeforeClass(alwaysRun = true)
public void setEnvironment() throws Exception {

    init("tsheets-connector-1.0.2-SNAPSHOT");

    esbRequestHeadersMap.put("Accept-Charset", "UTF-8");
    esbRequestHeadersMap.put("Content-Type", "application/json");

    apiRequestHeadersMap.putAll(esbRequestHeadersMap);
    apiRequestHeadersMap.put("Authorization", "Bearer " + connectorProperties.getProperty("accessToken"));

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    Date date = new Date();
    SimpleDateFormat sdf01 = new SimpleDateFormat("yyyy-MM-dd");

    date.setDate(date.getDate() - 1);
    String timeSheetTwoEnd = sdf.format(date) + "-07:00";
    date.setMinutes(date.getMinutes() - 1);
    String timeSheetTwoStart = sdf.format(date) + "-07:00";
    date.setDate(date.getDate() - 1);
    String timeSheetOneEnd = sdf.format(date) + "-07:00";
    String listTimeSheetOneEnd = sdf01.format(date);
    date.setMinutes(date.getMinutes() - 1);
    String timeSheetOneStart = sdf.format(date) + "-07:00";
    String listTimeSheetOneStart = sdf01.format(date);
    connectorProperties.setProperty("timeSheetOneStart", timeSheetOneStart);
    connectorProperties.setProperty("timeSheetOneEnd", timeSheetOneEnd);
    connectorProperties.setProperty("timeSheetTwoStart", timeSheetTwoStart);
    connectorProperties.setProperty("timeSheetTwoEnd", timeSheetTwoEnd);
    connectorProperties.setProperty("listTimeSheetOneStart", listTimeSheetOneStart);
    connectorProperties.setProperty("listTimeSheetOneEnd", listTimeSheetOneEnd);
}

From source file:pa_SymposiumPlanner.ECAI2012ProgramChair.java

private void answerQuery() {
    try {//from  w  w w .  j a  v  a2 s  .  c om
        address = PAConfiguration.getAddress();
        port = PAConfiguration.getPort(instantiation);
        poslAddress = PAConfiguration.getPOSL(instantiation, topic);
        rdfAddress = PAConfiguration.getRDFTaxonomy(instantiation);
        messageEndpoint = PAConfiguration.getEndpointName(instantiation, topic);
    } catch (BadConfigurationException e) {
        System.out.println(e.getMessage());
        e.printStackTrace();
        System.exit(0);
    }

    try {
        System.out.println("Programming Chair Servlet");
        String message = "";

        SAXReader reader = new SAXReader();
        message = reader.read(new File("D:\\RuleMLMessage.xml")).asXML();

        String[] varOrder = getVariableOrder(message);
        System.out.println("Received Message: " + message);

        POSLParser pp = new POSLParser();
        // String contents = "c(a).\nc(b).\nc(c).";

        Date t1 = new GregorianCalendar().getTime();
        System.out.println(t1.getHours() + ":" + t1.getMinutes());
        // append time to contents

        System.out.println("day: " + t1.getDay());
        System.out.println("day: " + t1.getYear());
        System.out.println("day: " + t1.getMonth());

        // time
        String time = "time(" + t1.getHours() + ":integer).";
        System.out.println(time);

        String url = poslAddress;

        // String url = "http://www.jdrew.org/oojdrew/test.posl";
        String contents = "";

        // day of the week
        int day = t1.getDay();
        boolean weekday = true;

        if (day == 0 || day == 6) {
            weekday = false;
        }

        String dayOfWeek;

        if (weekday) {
            dayOfWeek = "day(weekday).";
        } else {
            dayOfWeek = "day(weekend).";
        }
        // full date
        Calendar cal = new GregorianCalendar();

        int year = cal.get(Calendar.YEAR);
        int month = cal.get(Calendar.MONTH) + 1;
        int day2 = cal.get(Calendar.DAY_OF_MONTH);

        String date;

        String day3 = "" + day2;

        if (day2 == 1 || day2 == 2 || day2 == 3 || day2 == 4 || day2 == 5 || day2 == 6 || day2 == 7 || day2 == 8
                || day2 == 9) {

            day3 = "0" + day2;
        }

        if (month == 10 || month == 11 || month == 12)
            date = "" + year + month + day3;
        else
            date = "" + year + "0" + month + day3;

        date = "date(" + date + ":integer).";

        System.out.println(date);

        String url2 = rdfAddress;
        HttpClient client2 = new HttpClient();
        GetMethod method2 = new GetMethod(url2);
        method2.setFollowRedirects(true);
        String typestr = "";
        // Execute the GET method
        int statusCode2 = client2.executeMethod(method2);
        if (statusCode2 != -1) {
            typestr = method2.getResponseBodyAsString();
        }
        System.out.println("Types: " + typestr);
        Types.reset();
        RDFSParser.parseRDFSString(typestr);

        try {
            HttpClient client = new HttpClient();
            GetMethod method = new GetMethod(url);
            method.setFollowRedirects(true);

            // Execute the GET method
            int statusCode = client.executeMethod(method);
            if (statusCode != -1) {
                contents = method.getResponseBodyAsString();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        contents = contents + "\n" + time;
        contents = contents + "\n" + dayOfWeek;
        contents = contents + "\n" + date;

        BackwardReasoner br = new BackwardReasoner();
        Iterator solit = null;
        DefiniteClause dc = null;
        SymbolTable.reset();

        pp.parseDefiniteClauses(contents);

        br.loadClauses(pp.iterator());

        Iterator it = pp.iterator();
        while (it.hasNext()) {
            DefiniteClause d = (DefiniteClause) it.next();
            System.out.println("Loaded clause: " + d.toPOSLString());
        }

        br = new BackwardReasoner(br.clauses, br.oids);

        MessageParser m = new MessageParser(message);
        Element atom = null;

        try {

            atom = m.parseForContent();

        } catch (Exception e) {

            System.out.println("Invalid Message");
            // out.flush();

        }

        QueryBuilder q = new QueryBuilder(atom);
        String query = q.generateDoc();
        System.out.println("ABOUT TO INPUT THIS QUERY:" + query);
        RuleMLParser qp = new RuleMLParser();

        try {

            dc = qp.parseRuleMLQuery(query);

        }

        catch (Exception e) {
            System.out.println("Invalid Query");
            // out.flush();
        }

        // solit = br.iterativeDepthFirstSolutionIterator(dc);

        solit = br.iterativeDepthFirstSolutionIterator(dc);

        int varSize = 0;

        int i11 = 0;
        while (solit.hasNext()) {
            System.out.println("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA:" + (i11++));

            Vector data = new Vector();

            BackwardReasoner.GoalList gl = (BackwardReasoner.GoalList) solit.next();

            Hashtable varbind = gl.varBindings;
            javax.swing.tree.DefaultMutableTreeNode root = br.toTree();
            root.setAllowsChildren(true);

            javax.swing.tree.DefaultTreeModel dtm = new DefaultTreeModel(root);

            int i = 0;
            Object[][] rowdata = new Object[varbind.size()][2];
            varSize = varbind.size();

            Enumeration e = varbind.keys();
            while (e.hasMoreElements()) {
                Object k = e.nextElement();
                Object val = varbind.get(k);
                String ks = (String) k;
                rowdata[i][0] = ks;
                rowdata[i][1] = val;

                i++;
            }

            data.addElement(rowdata);
            String[] messages = new String[data.size()];
            MessageGenerator g = new MessageGenerator(data, varSize, messageEndpoint, m.getId(),
                    m.getProtocol(), m.getRel(), varOrder);
            messages = g.Messages2();

            String appender = "";

            URL sender = new URL(address + ":" + port);
            HttpMessage msg = new HttpMessage(sender);
            Properties props = new Properties();

            for (int i1 = 0; i1 < data.size(); i1++) {
                System.out.println(i1 + ")" + messages[i1].toString());
                props.put("text", messages[i1].toString());
                //               InputStream in = msg.sendGetMessage(props);
            }
            System.out.println("NEXT MESSAGE");
        }

        MessageGenerator g = new MessageGenerator(null, varSize, messageEndpoint, m.getId(), m.getProtocol(),
                m.getRel());

        URL sender = new URL(address + ":" + port);
        HttpMessage msg = new HttpMessage(sender);
        Properties props = new Properties();

        String finalMessage = g.finalMessage(query);

        System.out.println(finalMessage);

        props.put("text", finalMessage);
        //         InputStream in = msg.sendGetMessage(props);

        System.out.println("Stop_Communication");

    } catch (Exception e) {
        System.out.println("ERROR has occured : " + e.toString());

    }

}

From source file:pa_SymposiumPlanner.ECAI2012ProgramChair.java

public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    try {/*ww  w .  j av  a2s  .c o m*/
        address = PAConfiguration.getAddress();
        port = PAConfiguration.getPort(instantiation);
        poslAddress = PAConfiguration.getPOSL(instantiation, topic);
        rdfAddress = PAConfiguration.getRDFTaxonomy(instantiation);
        messageEndpoint = PAConfiguration.getEndpointName(instantiation, topic);
    } catch (BadConfigurationException e) {
        System.out.println(e.getMessage());
        e.printStackTrace();
        System.exit(0);
    }

    response.setContentType("text/html; charset=UTF-8");
    PrintWriter out = response.getWriter();

    try {
        System.out.println("Programming Chair Servlet");
        System.out.println(response.toString());

        BufferedReader brd = request.getReader();

        String input = "";
        String message = "";

        while (!input.equals("</RuleML>")) {

            input = brd.readLine();

            message = message + input;
        }
        String[] varOrder = getVariableOrder(message);
        System.out.println("Received Message: " + message);

        POSLParser pp = new POSLParser();
        // String contents = "c(a).\nc(b).\nc(c).";

        Date t1 = new GregorianCalendar().getTime();
        System.out.println(t1.getHours() + ":" + t1.getMinutes());
        // append time to contents

        System.out.println("day: " + t1.getDay());
        System.out.println("day: " + t1.getYear());
        System.out.println("day: " + t1.getMonth());

        // time
        String time = "time(" + t1.getHours() + ":integer).";
        System.out.println(time);

        String url = poslAddress;

        // String url = "http://www.jdrew.org/oojdrew/test.posl";
        String contents = "";

        // day of the week
        int day = t1.getDay();
        boolean weekday = true;

        if (day == 0 || day == 6) {
            weekday = false;
        }

        String dayOfWeek;

        if (weekday) {
            dayOfWeek = "day(weekday).";
        } else {
            dayOfWeek = "day(weekend).";
        }
        // full date
        Calendar cal = new GregorianCalendar();

        int year = cal.get(Calendar.YEAR);
        int month = cal.get(Calendar.MONTH) + 1;
        int day2 = cal.get(Calendar.DAY_OF_MONTH);

        String date;

        String day3 = "" + day2;

        if (day2 == 1 || day2 == 2 || day2 == 3 || day2 == 4 || day2 == 5 || day2 == 6 || day2 == 7 || day2 == 8
                || day2 == 9) {

            day3 = "0" + day2;
        }

        if (month == 10 || month == 11 || month == 12)
            date = "" + year + month + day3;
        else
            date = "" + year + "0" + month + day3;

        date = "date(" + date + ":integer).";

        System.out.println(date);

        String url2 = rdfAddress;
        HttpClient client2 = new HttpClient();
        GetMethod method2 = new GetMethod(url2);
        method2.setFollowRedirects(true);
        String typestr = "";
        // Execute the GET method
        int statusCode2 = client2.executeMethod(method2);
        if (statusCode2 != -1) {
            typestr = method2.getResponseBodyAsString();
        }
        System.out.println("Types: " + typestr);
        Types.reset();
        RDFSParser.parseRDFSString(typestr);

        try {
            HttpClient client = new HttpClient();
            GetMethod method = new GetMethod(url);
            method.setFollowRedirects(true);

            // Execute the GET method
            int statusCode = client.executeMethod(method);
            if (statusCode != -1) {
                contents = method.getResponseBodyAsString();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        contents = contents + "\n" + time;
        contents = contents + "\n" + dayOfWeek;
        contents = contents + "\n" + date;

        BackwardReasoner br = new BackwardReasoner();
        Iterator solit = null;
        DefiniteClause dc = null;
        SymbolTable.reset();

        pp.parseDefiniteClauses(contents);

        br.loadClauses(pp.iterator());

        Iterator it = pp.iterator();
        while (it.hasNext()) {
            DefiniteClause d = (DefiniteClause) it.next();
            System.out.println("Loaded clause: " + d.toPOSLString());
        }

        br = new BackwardReasoner(br.clauses, br.oids);

        MessageParser m = new MessageParser(message);
        Element atom = null;

        try {

            atom = m.parseForContent();

        } catch (Exception e) {

            System.out.println("Invalid Message");
            // out.flush();

        }

        QueryBuilder q = new QueryBuilder(atom);
        String query = q.generateDoc();
        System.out.println("ABOUT TO INPUT THIS QUERY:" + query);
        RuleMLParser qp = new RuleMLParser();

        try {

            dc = qp.parseRuleMLQuery(query);

        }

        catch (Exception e) {
            System.out.println("Invalid Query");
            // out.flush();
        }

        // solit = br.iterativeDepthFirstSolutionIterator(dc);

        solit = br.iterativeDepthFirstSolutionIterator(dc);

        int varSize = 0;

        while (solit.hasNext()) {

            Vector data = new Vector();

            BackwardReasoner.GoalList gl = (BackwardReasoner.GoalList) solit.next();

            Hashtable varbind = gl.varBindings;
            javax.swing.tree.DefaultMutableTreeNode root = br.toTree();
            root.setAllowsChildren(true);

            javax.swing.tree.DefaultTreeModel dtm = new DefaultTreeModel(root);

            int i = 0;
            Object[][] rowdata = new Object[varbind.size()][2];
            varSize = varbind.size();

            Enumeration e = varbind.keys();
            while (e.hasMoreElements()) {
                Object k = e.nextElement();
                Object val = varbind.get(k);
                String ks = (String) k;
                rowdata[i][0] = ks;
                rowdata[i][1] = val;

                i++;
            }

            data.addElement(rowdata);
            String[] messages = new String[data.size()];
            MessageGenerator g = new MessageGenerator(data, varSize, messageEndpoint, m.getId(),
                    m.getProtocol(), m.getRel(), varOrder);
            messages = g.Messages2();

            String appender = "";

            URL sender = new URL(address + ":" + port);
            HttpMessage msg = new HttpMessage(sender);
            Properties props = new Properties();

            for (int i1 = 0; i1 < data.size(); i1++) {
                System.out.println(i1 + ")" + messages[i1].toString());
                props.put("text", messages[i1].toString());
                InputStream in = msg.sendGetMessage(props);
            }
            System.out.println("NEXT MESSAGE");
        }

        MessageGenerator g = new MessageGenerator(null, varSize, messageEndpoint, m.getId(), m.getProtocol(),
                m.getRel());

        URL sender = new URL(address + ":" + port);
        HttpMessage msg = new HttpMessage(sender);
        Properties props = new Properties();

        String finalMessage = g.finalMessage(query);

        System.out.println(finalMessage);

        props.put("text", finalMessage);
        InputStream in = msg.sendGetMessage(props);

        System.out.println("Stop_Communication");

    } catch (Exception e) {
        System.out.println("ERROR has occured : " + e.toString());

    }
    out.close();
}