Example usage for org.joda.time DateMidnight DateMidnight

List of usage examples for org.joda.time DateMidnight DateMidnight

Introduction

In this page you can find the example usage for org.joda.time DateMidnight DateMidnight.

Prototype

public DateMidnight(Object instant) 

Source Link

Document

Constructs an instance from an Object that represents a datetime.

Usage

From source file:op.care.prescription.PnlScheduleDose.java

License:Open Source License

private void initPanel() {

    tabWdh.setTitleAt(0, SYSTools.xx("misc.msg.daily"));
    tabWdh.setTitleAt(1, SYSTools.xx("misc.msg.weekly"));
    tabWdh.setTitleAt(2, SYSTools.xx("misc.msg.monthly"));

    lblLDate.setText(SYSTools.xx(internalClassID + ".lblLDate") + " ");
    lblOnThe.setText(SYSTools.xx(internalClassID + ".lblOnThe"));
    lblMonth.setText(SYSTools.xx("misc.msg.months"));
    lblEach.setText(SYSTools.xx("misc.msg.every"));
    lblEvery1.setText(SYSTools.xx("misc.msg.every"));
    lblEvery2.setText(SYSTools.xx("misc.msg.every"));
    lblWeeksAt.setText(SYSTools.xx("misc.msg.weeks") + " " + SYSTools.xx("misc.msg.atchrono"));
    lblDays.setText(SYSTools.xx("misc.msg.Days2"));

    ArrayList<Date> timelist = SYSCalendar.getTimeList();
    cmbUhrzeit.setModel(new DefaultComboBoxModel(timelist.toArray()));
    cmbUhrzeit.setRenderer(SYSCalendar.getTimeRenderer());

    String[] wdaymodel = new String[] { SYSTools.xx("misc.msg.dayOfMonth"), SYSTools.xx("misc.msg.monday"),
            SYSTools.xx("misc.msg.tuesday"), SYSTools.xx("misc.msg.wednesday"),
            SYSTools.xx("misc.msg.thursday"), SYSTools.xx("misc.msg.friday"), SYSTools.xx("misc.msg.saturday"),
            SYSTools.xx("misc.msg.sunday") };
    cmbWDay.setModel(new DefaultComboBoxModel(wdaymodel));

    lblMon.setText(SYSTools.xx("misc.msg.monday"));
    lblTue.setText(SYSTools.xx("misc.msg.tuesday"));
    lblWed.setText(SYSTools.xx("misc.msg.wednesday"));
    lblThu.setText(SYSTools.xx("misc.msg.thursday"));
    lblFri.setText(SYSTools.xx("misc.msg.friday"));
    lblSat.setText(SYSTools.xx("misc.msg.saturday"));
    lblSun.setText(SYSTools.xx("misc.msg.sunday"));

    lblVeryEarly.setText(SYSTools.xx("misc.msg.earlyinthemorning.long"));
    lblMorning.setText(SYSTools.xx("misc.msg.morning.long"));
    lblNoon.setText(SYSTools.xx("misc.msg.noon.long"));
    lblAfternoon.setText(SYSTools.xx("misc.msg.afternoon.long"));
    lblEvening.setText(SYSTools.xx("misc.msg.evening.long"));
    lblVeryLate.setText(SYSTools.xx("misc.msg.lateatnight.long"));

    txtEveryDay.setText("1");
    txtEveryWeek.setText("1");
    txtEveryMonth.setText("1");
    txtEveryWDayOfMonth.setText("1");

    //        txtEveryDay.setText(schedule.getTaeglich().toString());
    //        txtEveryWeek.setText(schedule.getWoechentlich().toString());
    //        txtEveryMonth.setText(schedule.getMonatlich().toString());
    //        txtEveryWDayOfMonth.setText(schedule.getTagNum().toString());

    tabWdh.setSelectedIndex(TAB_DAILY);/*  www  .j av  a  2  s . co m*/

    if (schedule.getWoechentlich() > 0) {
        cbMon.setSelected(schedule.getMon() > 0);
        cbTue.setSelected(schedule.getTue() > 0);
        cbWed.setSelected(schedule.getWed() > 0);
        cbThu.setSelected(schedule.getThu() > 0);
        cbFri.setSelected(schedule.getFri() > 0);
        cbSat.setSelected(schedule.getSat() > 0);
        cbSun.setSelected(schedule.getSun() > 0);
        tabWdh.setSelectedIndex(TAB_WEEKLY);
    }

    if (schedule.getMonatlich() > 0) {
        if (schedule.getTagNum() > 0) {
            txtEveryWDayOfMonth.setText(Short.toString(schedule.getTagNum()));
            cmbWDay.setSelectedIndex(0);
        } else {
            if (schedule.getMon() > 0) {
                cmbWDay.setSelectedIndex(1);
                txtEveryWDayOfMonth.setText(Short.toString(schedule.getMon()));
            } else if (schedule.getTue() > 0) {
                cmbWDay.setSelectedIndex(2);
                txtEveryWDayOfMonth.setText(Short.toString(schedule.getTue()));
            } else if (schedule.getWed() > 0) {
                cmbWDay.setSelectedIndex(3);
                txtEveryWDayOfMonth.setText(Short.toString(schedule.getWed()));
            } else if (schedule.getThu() > 0) {
                cmbWDay.setSelectedIndex(4);
                txtEveryWDayOfMonth.setText(Short.toString(schedule.getThu()));
            } else if (schedule.getFri() > 0) {
                cmbWDay.setSelectedIndex(5);
                txtEveryWDayOfMonth.setText(Short.toString(schedule.getFri()));
            } else if (schedule.getSat() > 0) {
                cmbWDay.setSelectedIndex(6);
                txtEveryWDayOfMonth.setText(Short.toString(schedule.getSat()));
            } else if (schedule.getSun() > 0) {
                cmbWDay.setSelectedIndex(7);
                txtEveryWDayOfMonth.setText(Short.toString(schedule.getSun()));
            }
        }
        tabWdh.setSelectedIndex(TAB_MONTHLY);
    }

    //        jdcLDatum.setMinSelectableDate(new Date());
    //        jdcLDatum.setDate(new Date(Math.max(schedule.getLDatum().getTime(), SYSCalendar.startOfDay())));

    DateMidnight scheduleLDate = new DateMidnight(schedule.getLDatum());
    DateMidnight today = new DateMidnight();
    DateMidnight ldate = new DateMidnight(Math.max(scheduleLDate.getMillis(), today.getMillis()));
    txtLDate.setText(DateFormat.getDateInstance().format(ldate.toDate()));

    txtVeryEarly.setText(schedule.getNachtMo().setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
    txtMorning.setText(schedule.getMorgens().setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
    txtNoon.setText(schedule.getMittags().setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
    txtAfternoon.setText(schedule.getNachmittags().setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
    txtEvening.setText(schedule.getAbends().setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
    txtVeryLate.setText(schedule.getNachtAb().setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());
    txtTimeDose.setText(schedule.getUhrzeitDosis().setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString());

    txtMorning.setBackground(SYSConst.lightblue);
    txtNoon.setBackground(SYSConst.gold7);
    txtAfternoon.setBackground(SYSConst.melonrindgreen);
    txtEvening.setBackground(SYSConst.bermuda_sand);
    txtVeryLate.setBackground(SYSConst.bluegrey);

    Date now = null;
    if (schedule.getUhrzeitDosis().compareTo(BigDecimal.ZERO) > 0) {
        splitRegularPos = 0.0d;
        now = schedule.getUhrzeit();
    } else {
        now = new Date();
        splitRegularPos = 1.0d;
    }

    for (Date zeit : timelist) {
        if (SYSCalendar.compareTime(zeit, now) >= 0) {
            now = zeit;
            break;
        }
    }
    cmbUhrzeit.setSelectedItem(now);
    lblTimeDose.setText(SYSTools.xx(internalClassID + ".lblTimeDose") + " "
            + DateFormat.getTimeInstance(DateFormat.SHORT).format(now) + " "
            + SYSTools.xx("misc.msg.Time.short"));

    panelMainComponentResized(null);
}

From source file:op.care.prescription.PnlScheduleDose.java

License:Open Source License

public void save() throws NumberFormatException {

    boolean splitSetToTime = splitRegularPos == 0d;

    if (!isAtLeastOneTxtFieldNotZero() && Double.parseDouble(txtTimeDose.getText()) == 0d) {
        throw new NumberFormatException("All Doses are ZERO");
    }//from   w  w w  .  j a  v a 2 s .com

    schedule.setNachtMo(
            splitSetToTime ? BigDecimal.ZERO : new BigDecimal(Double.parseDouble(txtVeryEarly.getText())));
    schedule.setMorgens(
            splitSetToTime ? BigDecimal.ZERO : new BigDecimal(Double.parseDouble(txtMorning.getText())));
    schedule.setMittags(
            splitSetToTime ? BigDecimal.ZERO : new BigDecimal(Double.parseDouble(txtNoon.getText())));
    schedule.setNachmittags(
            splitSetToTime ? BigDecimal.ZERO : new BigDecimal(Double.parseDouble(txtAfternoon.getText())));
    schedule.setAbends(
            splitSetToTime ? BigDecimal.ZERO : new BigDecimal(Double.parseDouble(txtEvening.getText())));
    schedule.setNachtAb(
            splitSetToTime ? BigDecimal.ZERO : new BigDecimal(Double.parseDouble(txtVeryLate.getText())));
    schedule.setUhrzeitDosis(
            splitSetToTime ? new BigDecimal(Double.parseDouble(txtTimeDose.getText())) : BigDecimal.ZERO);
    schedule.setUhrzeit(splitSetToTime ? (Date) cmbUhrzeit.getSelectedItem() : null);

    schedule.setMaxAnzahl(0);
    schedule.setMaxEDosis(BigDecimal.ZERO);

    schedule.setTaeglich(
            tabWdh.getSelectedIndex() == TAB_DAILY ? Short.parseShort(txtEveryDay.getText()) : (short) 0);
    schedule.setWoechentlich(
            tabWdh.getSelectedIndex() == TAB_WEEKLY ? Short.parseShort(txtEveryWeek.getText()) : (short) 0);
    schedule.setMonatlich(
            tabWdh.getSelectedIndex() == TAB_MONTHLY ? Short.parseShort(txtEveryMonth.getText()) : (short) 0);

    DateMidnight day;
    try {
        day = new DateMidnight(SYSCalendar.parseDate(txtLDate.getText()));
    } catch (NumberFormatException ex) {
        day = new DateMidnight();
    }
    schedule.setLDatum(day.toDate());

    schedule.setMon(tabWdh.getSelectedIndex() == TAB_WEEKLY && cbMon.isSelected() ? (short) 1 : (short) 0);
    schedule.setTue(tabWdh.getSelectedIndex() == TAB_WEEKLY && cbTue.isSelected() ? (short) 1 : (short) 0);
    schedule.setWed(tabWdh.getSelectedIndex() == TAB_WEEKLY && cbWed.isSelected() ? (short) 1 : (short) 0);
    schedule.setThu(tabWdh.getSelectedIndex() == TAB_WEEKLY && cbThu.isSelected() ? (short) 1 : (short) 0);
    schedule.setFri(tabWdh.getSelectedIndex() == TAB_WEEKLY && cbFri.isSelected() ? (short) 1 : (short) 0);
    schedule.setSat(tabWdh.getSelectedIndex() == TAB_WEEKLY && cbSat.isSelected() ? (short) 1 : (short) 0);
    schedule.setSun(tabWdh.getSelectedIndex() == TAB_WEEKLY && cbSun.isSelected() ? (short) 1 : (short) 0);

    if (tabWdh.getSelectedIndex() == TAB_MONTHLY) {
        short s = Short.parseShort(txtEveryWDayOfMonth.getText());
        schedule.setTagNum(cmbWDay.getSelectedIndex() == 0 ? s : (short) 0);

        if (cmbWDay.getSelectedIndex() == 1) {
            schedule.setMon(s);
        } else if (cmbWDay.getSelectedIndex() == 2) {
            schedule.setTue(s);
        } else if (cmbWDay.getSelectedIndex() == 3) {
            schedule.setWed(s);
        } else if (cmbWDay.getSelectedIndex() == 4) {
            schedule.setThu(s);
        } else if (cmbWDay.getSelectedIndex() == 5) {
            schedule.setFri(s);
        } else if (cmbWDay.getSelectedIndex() == 6) {
            schedule.setSat(s);
        } else if (cmbWDay.getSelectedIndex() == 7) {
            schedule.setSun(s);
        }
    }

}

From source file:op.tools.SYSCalendar.java

License:Open Source License

/**
 * determines to which timeofday code a given date object belongs. The settings in SYSProps are taken into account.
 * or in short: it answers a question like "is 0800h early, noon or early in the morning ?"
 *
 * @param date//w ww.j a v  a  2 s  .com
 * @return timecode
 */
public static byte whatTimeIDIs(Date date) {
    byte timeid;

    DateTimeFormatter parser = DateTimeFormat.forPattern("HH:mm");

    DateTime early_in_the_morning = parser
            .parseDateTime(OPDE.getProps().getProperty(DFNTools.STRING_EARLY_IN_THE_MORNING));
    DateTime morning = parser.parseDateTime(OPDE.getProps().getProperty(DFNTools.STRING_MORNING));
    DateTime noon = parser.parseDateTime(OPDE.getProps().getProperty(DFNTools.STRING_NOON));
    DateTime afternoon = parser.parseDateTime(OPDE.getProps().getProperty(DFNTools.STRING_AFTERNOON));
    DateTime evening = parser.parseDateTime(OPDE.getProps().getProperty(DFNTools.STRING_EVENING));
    DateTime late_at_night = parser.parseDateTime(OPDE.getProps().getProperty(DFNTools.STRING_LATE_AT_NIGHT));

    Period period_early_in_the_morning = new Period(early_in_the_morning.getHourOfDay(),
            early_in_the_morning.getMinuteOfHour(), early_in_the_morning.getSecondOfMinute(),
            early_in_the_morning.getMillisOfSecond());
    Period period_morning = new Period(morning.getHourOfDay(), morning.getMinuteOfHour(),
            morning.getSecondOfMinute(), morning.getMillisOfSecond());
    Period period_noon = new Period(noon.getHourOfDay(), noon.getMinuteOfHour(), noon.getSecondOfMinute(),
            noon.getMillisOfSecond());
    Period period_afternoon = new Period(afternoon.getHourOfDay(), afternoon.getMinuteOfHour(),
            afternoon.getSecondOfMinute(), afternoon.getMillisOfSecond());
    Period period_evening = new Period(evening.getHourOfDay(), evening.getMinuteOfHour(),
            evening.getSecondOfMinute(), evening.getMillisOfSecond());
    Period period_late_at_night = new Period(late_at_night.getHourOfDay(), late_at_night.getMinuteOfHour(),
            late_at_night.getSecondOfMinute(), late_at_night.getMillisOfSecond());

    DateTime ref = new DateTime(date);
    DateTime eitm = new DateMidnight(date).toDateTime().plus(period_early_in_the_morning);
    DateTime m = new DateMidnight(date).toDateTime().plus(period_morning);
    DateTime n = new DateMidnight(date).toDateTime().plus(period_noon);
    DateTime a = new DateMidnight(date).toDateTime().plus(period_afternoon);
    DateTime e = new DateMidnight(date).toDateTime().plus(period_evening);
    DateTime lan = new DateMidnight(date).toDateTime().plus(period_late_at_night);

    if (eitm.compareTo(ref) <= 0 && ref.compareTo(m) < 0) {
        timeid = DFNTools.BYTE_EARLY_IN_THE_MORNING;
    } else if (m.compareTo(ref) <= 0 && ref.compareTo(n) < 0) {
        timeid = DFNTools.BYTE_MORNING;
    } else if (n.compareTo(ref) <= 0 && ref.compareTo(a) < 0) {
        timeid = DFNTools.BYTE_NOON;
    } else if (a.compareTo(ref) <= 0 && ref.compareTo(e) < 0) {
        timeid = DFNTools.BYTE_AFTERNOON;
    } else if (e.compareTo(ref) <= 0 && ref.compareTo(lan) < 0) {
        timeid = DFNTools.BYTE_EVENING;
    } else {
        timeid = DFNTools.BYTE_LATE_AT_NIGHT;
    }
    return timeid;
}

From source file:org.akaza.openclinica.logic.expressionTree.OpenClinicaBeanVariableNode.java

License:LGPL

private Object calculateVariable() {
    if (number.equals("_CURRENT_DATE")) {
        String ssTimeZone = getExpressionBeanService().getSSTimeZone();
        if (ssTimeZone == "" || ssTimeZone == null)
            ssTimeZone = TimeZone.getDefault().getID();

        DateTimeZone ssZone = DateTimeZone.forID(ssTimeZone);
        DateMidnight dm = new DateMidnight(ssZone);
        DateTimeFormatter fmt = ISODateTimeFormat.date();
        return fmt.print(dm);
    }/*from  w  w w.ja  v  a2s .  co m*/
    return null;
}

From source file:org.akaza.openclinica.logic.expressionTree.OpenClinicaBeanVariableNode.java

License:LGPL

private String testCalculateVariable() {
    if (number.equals("_CURRENT_DATE")) {
        String ssTimeZone = getExpressionBeanService().getSSTimeZone();
        if (ssTimeZone == "" || ssTimeZone == null)
            ssTimeZone = TimeZone.getDefault().getID();

        DateTimeZone ssZone = DateTimeZone.forID(ssTimeZone);
        DateMidnight dm = new DateMidnight(ssZone);
        DateTimeFormatter fmt = ISODateTimeFormat.date();
        return fmt.print(dm);
    }//from   w w w . j a  va  2s  . c  om
    return null;
}

From source file:org.akaza.openclinica.service.rule.expression.ExpressionService.java

License:LGPL

public HashMap<String, String> getSSDate(String ssZoneId, String serverZoneId) {
    HashMap<String, String> map = new HashMap<String, String>();
    if (ssZoneId == "" || ssZoneId.equals(""))
        ssZoneId = TimeZone.getDefault().getID();

    DateTimeZone ssZone = DateTimeZone.forID(ssZoneId);
    DateMidnight dm = new DateMidnight(ssZone);
    DateTimeFormatter fmt = ISODateTimeFormat.date();
    map.put("ssDate", fmt.print(dm));

    map.put("serverZoneId", serverZoneId);
    DateTimeZone serverZone = DateTimeZone.forID(serverZoneId);
    DateMidnight serverDate = new DateMidnight(serverZone);
    map.put("serverDate", fmt.print(serverDate));
    return map;//w w  w . j  a  va2  s .c o m
}

From source file:org.apereo.portal.io.xml.eventaggr.EventAggregationConfigurationImporterExporter.java

License:Apache License

@Transactional("aggrEventsTransactionManager")
@Override/*from   w  w w  .  j  a  v a  2s.  co  m*/
public void importData(ExternalEventAggregationConfiguration data) {
    //Import interval configs
    final Set<AggregatedIntervalConfig> oldAggregatedIntervalConfigs = new HashSet<AggregatedIntervalConfig>(
            this.aggregationManagementDao.getAggregatedIntervalConfigs());
    for (final ExternalAggregatedIntervalConfig extAggregatedIntervalConfig : data
            .getAggregatedIntervalConfigs()) {
        final String aggregatorTypeName = extAggregatedIntervalConfig.getAggregatorType();

        final Class<? extends IPortalEventAggregator> aggregatorType = getAggregatorType(aggregatorTypeName);
        AggregatedIntervalConfig aggregatedIntervalConfig = this.aggregationManagementDao
                .getAggregatedIntervalConfig(aggregatorType);
        if (aggregatedIntervalConfig == null) {
            aggregatedIntervalConfig = this.aggregationManagementDao
                    .createAggregatedIntervalConfig(aggregatorType);
        }

        //Remove the config from the old configs set, marking it as updated
        oldAggregatedIntervalConfigs.remove(aggregatedIntervalConfig);

        //Copy over excludes
        final Set<AggregationInterval> excluded = aggregatedIntervalConfig.getExcluded();
        excluded.clear();
        for (final ExternalAggregationInterval extInterval : extAggregatedIntervalConfig.getExcludes()) {
            excluded.add(convert(extInterval));
        }

        //Copy over includes
        final Set<AggregationInterval> included = aggregatedIntervalConfig.getIncluded();
        included.clear();
        for (final ExternalAggregationInterval extInterval : extAggregatedIntervalConfig.getIncludes()) {
            included.add(convert(extInterval));
        }

        this.aggregationManagementDao.updateAggregatedIntervalConfig(aggregatedIntervalConfig);
    }

    //Delete interval configs that were not updated
    for (final AggregatedIntervalConfig aggregatedIntervalConfig : oldAggregatedIntervalConfigs) {
        this.aggregationManagementDao.deleteAggregatedIntervalConfig(aggregatedIntervalConfig);
    }

    //Import Group configs
    final Set<AggregatedGroupConfig> oldAggregatedGroupConfigs = new HashSet<AggregatedGroupConfig>(
            this.aggregationManagementDao.getAggregatedGroupConfigs());
    for (final ExternalAggregatedGroupConfig extAggregatedGroupConfig : data.getAggregatedGroupConfigs()) {
        final String aggregatorTypeName = extAggregatedGroupConfig.getAggregatorType();

        final Class<? extends IPortalEventAggregator> aggregatorType = getAggregatorType(aggregatorTypeName);
        AggregatedGroupConfig aggregatedGroupConfig = this.aggregationManagementDao
                .getAggregatedGroupConfig(aggregatorType);
        if (aggregatedGroupConfig == null) {
            aggregatedGroupConfig = this.aggregationManagementDao.createAggregatedGroupConfig(aggregatorType);
        }

        //Remove the config from the old configs set, marking it as updated
        oldAggregatedGroupConfigs.remove(aggregatedGroupConfig);

        //Copy over excludes
        final Set<AggregatedGroupMapping> excluded = aggregatedGroupConfig.getExcluded();
        excluded.clear();
        for (final ExternalAggregatedGroupMapping extGroup : extAggregatedGroupConfig.getExcludes()) {
            excluded.add(convert(extGroup));
        }

        //Copy over includes
        final Set<AggregatedGroupMapping> included = aggregatedGroupConfig.getIncluded();
        included.clear();
        for (final ExternalAggregatedGroupMapping extGroup : extAggregatedGroupConfig.getIncludes()) {
            included.add(convert(extGroup));
        }

        this.aggregationManagementDao.updateAggregatedGroupConfig(aggregatedGroupConfig);
    }

    //Delete interval configs that were not updated
    for (final AggregatedGroupConfig aggregatedGroupConfig : oldAggregatedGroupConfigs) {
        this.aggregationManagementDao.deleteAggregatedGroupConfig(aggregatedGroupConfig);
    }

    //Set quarter details if configured or set default quarters
    final List<ExternalQuarterDetail> extQuarterDetails = data.getQuarterDetails();
    final List<QuarterDetail> quarterDetails;
    if (!extQuarterDetails.isEmpty()) {
        quarterDetails = convertQuarterDetail(extQuarterDetails);
    } else {
        quarterDetails = EventDateTimeUtils.createStandardQuarters();
    }
    this.aggregationManagementDao.setQuarterDetails(quarterDetails);

    //Set academic term if configured
    final List<AcademicTermDetail> academicTerms = Lists.transform(data.getTermDetails(),
            new Function<ExternalTermDetail, AcademicTermDetail>() {
                public AcademicTermDetail apply(ExternalTermDetail externalTermDetail) {
                    return new AcademicTermDetailImpl(new DateMidnight(externalTermDetail.getStart()),
                            new DateMidnight(externalTermDetail.getEnd()), externalTermDetail.getName());
                }
            });
    this.aggregationManagementDao.setAcademicTermDetails(academicTerms);
}

From source file:org.dspace.eperson.Subscribe.java

License:BSD License

/**
 * Sends an email to the given e-person with details of new items in the
 * given collections, items that appeared yesterday. No e-mail is sent if
 * there aren't any new items in any of the collections.
 * // w ww  . j  a  v a  2  s  .com
 * @param context
 *            DSpace context object
 * @param eperson
 *            eperson to send to
 * @param collections
 *            List of collection IDs (Integers)
 * @param test 
 */
public static void sendEmail(Context context, EPerson eperson, List<Collection> collections, boolean test)
        throws IOException, MessagingException, SQLException {
    // Get a resource bundle according to the eperson language preferences
    Locale supportedLocale = I18nUtil.getEPersonLocale(eperson);
    ResourceBundle labels = ResourceBundle.getBundle("Messages", supportedLocale);

    // Get the start and end dates for yesterday

    // The date should reflect the timezone as well. Otherwise we stand to lose that information 
    // in truncation and roll to an earlier date than intended.

    DateTimeFormatter fmt = ISODateTimeFormat.dateTimeNoMillis();
    String midnightYesterday = fmt.print(new DateMidnight(System.currentTimeMillis()));

    // FIXME: text of email should be more configurable from an
    // i18n viewpoint
    StringBuffer emailText = new StringBuffer();
    boolean isFirst = true;

    for (int i = 0; i < collections.size(); i++) {
        Collection c = collections.get(i);

        try {
            boolean includeAll = ConfigurationManager
                    .getBooleanProperty("harvest.includerestricted.subscription", true);

            // we harvest all the changed item from yesterday until now
            List<HarvestedItemInfo> itemInfos = Harvest.harvest(context, c, midnightYesterday, null, 0, // Limit
                    // and
                    // offset
                    // zero,
                    // get
                    // everything
                    0, true, // Need item objects
                    false, // But not containers
                    false, // Or withdrawals
                    includeAll);

            if (ConfigurationManager.getBooleanProperty("eperson.subscription.onlynew", false)) {
                // get only the items archived yesterday
                itemInfos = filterOutModified(itemInfos);
            } else {
                // strip out the item archived today or 
                // not archived yesterday and modified today
                itemInfos = filterOutToday(itemInfos);
            }

            // Only add to buffer if there are new items
            if (itemInfos.size() > 0) {
                if (!isFirst) {
                    emailText.append("\n---------------------------------------\n");
                } else {
                    isFirst = false;
                }

                emailText.append(labels.getString("org.dspace.eperson.Subscribe.new-items")).append(" ")
                        .append(c.getMetadata("name")).append(": ").append(itemInfos.size()).append("\n\n");

                for (int j = 0; j < itemInfos.size(); j++) {
                    HarvestedItemInfo hii = (HarvestedItemInfo) itemInfos.get(j);

                    List<MDValue> titles = hii.item.getMetadata("dc", "title", null, MDValue.ANY);
                    emailText.append("      ").append(labels.getString("org.dspace.eperson.Subscribe.title"))
                            .append(" ");

                    if (titles.size() > 0) {
                        emailText.append(titles.get(0).getValue());
                    } else {
                        emailText.append(labels.getString("org.dspace.eperson.Subscribe.untitled"));
                    }

                    List<MDValue> authors = hii.item.getMetadata("dc", "contributor", MDValue.ANY, MDValue.ANY);

                    if (authors.size() > 0) {
                        emailText.append("\n    ")
                                .append(labels.getString("org.dspace.eperson.Subscribe.authors")).append(" ")
                                .append(authors.get(0).getValue());

                        for (int k = 1; k < authors.size(); k++) {
                            emailText.append("\n             ").append(authors.get(k).getValue());
                        }
                    }

                    emailText.append("\n         ").append(labels.getString("org.dspace.eperson.Subscribe.id"))
                            .append(" ").append(HandleManager.getCanonicalForm(hii.handle)).append("\n\n");
                }
            }
        } catch (ParseException pe) {
            // This should never get thrown as the Dates are auto-generated
        }
    }

    // Send an e-mail if there were any new items
    if (emailText.length() > 0) {

        if (test) {
            log.info(LogManager.getHeader(context, "subscription:", "eperson=" + eperson.getEmail()));
            log.info(LogManager.getHeader(context, "subscription:", "text=" + emailText.toString()));

        } else {

            Email email = Email.fromTemplate(context,
                    I18nUtil.getEmailFilename(supportedLocale, "subscription"));
            email.addRecipient(eperson.getEmail());
            email.addArgument(emailText.toString());
            email.send();

            log.info(LogManager.getHeader(context, "sent_subscription", "eperson_id=" + eperson.getID()));

        }
    }
}

From source file:org.easy.scrum.model.embedded.PersistentPeriod.java

License:Apache License

public org.joda.time.Period toPeriod() {
    return new org.joda.time.Period(new DateMidnight(start.getTime()), new DateMidnight(end.getTime()));
}

From source file:org.easy.scrum.model.embedded.PersistentPeriod.java

License:Apache License

public int getWeeksBetween() {
    return Weeks.weeksBetween(new DateMidnight(start.getTime()), new DateMidnight(end.getTime())).getWeeks();
}