List of usage examples for java.text DateFormatSymbols DateFormatSymbols
private DateFormatSymbols(boolean flag)
From source file:model.manager.SearchManager.java
public static List<PatientIdentifier> getPatientIdentifiersByName(Session session, String patientId, boolean includeInactivePatients, List<IdentifierType> types) throws HibernateException { String jsonString;// ww w. jav a2 s . c o m String[] resourceArray; String nid; Date theDate; Date _theDate; List<PatientIdentifier> patientIdentifiers = new ArrayList<PatientIdentifier>(); RestClient restClient = new RestClient(); String resource = restClient.getOpenMRSResource("patient?q=" + StringUtils.replace(patientId, " ", "%20")); String _resource = (String) resource.subSequence(11, resource.length()); _resource = _resource.substring(0, _resource.length() - 1); JSONArray jsonArray = new JSONArray(_resource); for (int i = 0; i < JsonHelper.toList(jsonArray).size(); i++) { PatientIdentifier identifier = new PatientIdentifier(); patient = new Patient(); jsonString = JsonHelper.toList(jsonArray).get(i).toString().replaceAll("display=", "") .replaceAll("uuid=", ""); jsonString = jsonString.substring(1, jsonString.length() - 1); resourceArray = jsonString.split(iDartProperties.ARRAY_SPLIT); String nameNid = (resourceArray[0].replaceAll(resourceArray[0].substring(0, 18), " ")).trim(); List<String> fullName = RestUtils.splitName(nameNid); patient.setFirstNames((fullName.get(0) + iDartProperties.SPACE + fullName.get(1)) .replaceAll(iDartProperties.HIFEN, iDartProperties.SPACE).trim()); patient.setLastname(fullName.get(2).replaceAll("-", " ").trim()); nid = restClient.getOpenMRSResource(iDartProperties.REST_GET_PATIENT_GENERIC + resourceArray[3].trim()); JSONObject jsonObject = new JSONObject(nid); nid = String.valueOf(jsonObject.get("display")); nid = nid.substring(0, nid.indexOf("-")).trim(); String strBirthdate = jsonObject.getJSONObject("person").getString("birthdate"); char gender = jsonObject.getJSONObject("person").getString("gender").charAt(0); String year = strBirthdate.substring(0, 4); String month = new DateFormatSymbols(Locale.ENGLISH) .getMonths()[Integer.valueOf(strBirthdate.substring(5, 7)) - 1]; Integer day = Integer.valueOf(strBirthdate.substring(8, 10)); SimpleDateFormat _sdf = new SimpleDateFormat("d-MMMM-yyyy", Locale.ENGLISH); String dataInicioTarv = restClient.getOpenMRSResource(iDartProperties.REST_OBS_PATIENT + resourceArray[3].trim() + iDartProperties.CONCEPT_DATA_INICIO_TARV); if (dataInicioTarv.length() > 14) { dataInicioTarv = dataInicioTarv.substring(94); dataInicioTarv = dataInicioTarv.substring(0, 10); String _year = dataInicioTarv.substring(6, 10); String _month = new DateFormatSymbols(Locale.ENGLISH) .getMonths()[Integer.valueOf(dataInicioTarv.substring(3, 5)) - 1]; Integer _day = Integer.valueOf(dataInicioTarv.substring(0, 2)); _theDate = null;//Data de Inicio Tarv try { _theDate = _sdf.parse(_day.toString() + "-" + _month + "-" + _year); } catch (ParseException e1) { System.out.println(e1.getMessage()); } patient.setAttributeValue(PatientAttribute.ARV_START_DATE, _theDate); } SimpleDateFormat sdf = new SimpleDateFormat("d-MMMM-yyyy", Locale.ENGLISH); theDate = null;//Data de Nascimento try { theDate = sdf.parse(day.toString() + "-" + month + "-" + year); } catch (ParseException e1) { System.out.println(e1.getMessage()); } patient.setDateOfBirth(theDate); patient.setPatientId(nid); patient.setSex(gender); identifier.setType(types.get(0)); identifier.setValueEdit(null); identifier.setValue(nid); identifier.setPatient(patient); patientIdentifiers.add(identifier); } return patientIdentifiers; }
From source file:DateFormatUtils.java
/** * <p>Returns a list of Rules given a pattern.</p> * //from w ww. ja v a2s .com * @return a <code>List</code> of Rule objects * @throws IllegalArgumentException if pattern is invalid */ protected List parsePattern() { DateFormatSymbols symbols = new DateFormatSymbols(mLocale); List rules = new ArrayList(); String[] ERAs = symbols.getEras(); String[] months = symbols.getMonths(); String[] shortMonths = symbols.getShortMonths(); String[] weekdays = symbols.getWeekdays(); String[] shortWeekdays = symbols.getShortWeekdays(); String[] AmPmStrings = symbols.getAmPmStrings(); int length = mPattern.length(); int[] indexRef = new int[1]; for (int i = 0; i < length; i++) { indexRef[0] = i; String token = parseToken(mPattern, indexRef); i = indexRef[0]; int tokenLen = token.length(); if (tokenLen == 0) { break; } Rule rule; char c = token.charAt(0); switch (c) { case 'G': // era designator (text) rule = new TextField(Calendar.ERA, ERAs); break; case 'y': // year (number) if (tokenLen >= 4) { rule = selectNumberRule(Calendar.YEAR, tokenLen); } else { rule = TwoDigitYearField.INSTANCE; } break; case 'M': // month in year (text and number) if (tokenLen >= 4) { rule = new TextField(Calendar.MONTH, months); } else if (tokenLen == 3) { rule = new TextField(Calendar.MONTH, shortMonths); } else if (tokenLen == 2) { rule = TwoDigitMonthField.INSTANCE; } else { rule = UnpaddedMonthField.INSTANCE; } break; case 'd': // day in month (number) rule = selectNumberRule(Calendar.DAY_OF_MONTH, tokenLen); break; case 'h': // hour in am/pm (number, 1..12) rule = new TwelveHourField(selectNumberRule(Calendar.HOUR, tokenLen)); break; case 'H': // hour in day (number, 0..23) rule = selectNumberRule(Calendar.HOUR_OF_DAY, tokenLen); break; case 'm': // minute in hour (number) rule = selectNumberRule(Calendar.MINUTE, tokenLen); break; case 's': // second in minute (number) rule = selectNumberRule(Calendar.SECOND, tokenLen); break; case 'S': // millisecond (number) rule = selectNumberRule(Calendar.MILLISECOND, tokenLen); break; case 'E': // day in week (text) rule = new TextField(Calendar.DAY_OF_WEEK, tokenLen < 4 ? shortWeekdays : weekdays); break; case 'D': // day in year (number) rule = selectNumberRule(Calendar.DAY_OF_YEAR, tokenLen); break; case 'F': // day of week in month (number) rule = selectNumberRule(Calendar.DAY_OF_WEEK_IN_MONTH, tokenLen); break; case 'w': // week in year (number) rule = selectNumberRule(Calendar.WEEK_OF_YEAR, tokenLen); break; case 'W': // week in month (number) rule = selectNumberRule(Calendar.WEEK_OF_MONTH, tokenLen); break; case 'a': // am/pm marker (text) rule = new TextField(Calendar.AM_PM, AmPmStrings); break; case 'k': // hour in day (1..24) rule = new TwentyFourHourField(selectNumberRule(Calendar.HOUR_OF_DAY, tokenLen)); break; case 'K': // hour in am/pm (0..11) rule = selectNumberRule(Calendar.HOUR, tokenLen); break; case 'z': // time zone (text) if (tokenLen >= 4) { rule = new TimeZoneNameRule(mTimeZone, mTimeZoneForced, mLocale, TimeZone.LONG); } else { rule = new TimeZoneNameRule(mTimeZone, mTimeZoneForced, mLocale, TimeZone.SHORT); } break; case 'Z': // time zone (value) if (tokenLen == 1) { rule = TimeZoneNumberRule.INSTANCE_NO_COLON; } else { rule = TimeZoneNumberRule.INSTANCE_COLON; } break; case '\'': // literal text String sub = token.substring(1); if (sub.length() == 1) { rule = new CharacterLiteral(sub.charAt(0)); } else { rule = new StringLiteral(sub); } break; default: throw new IllegalArgumentException("Illegal pattern component: " + token); } rules.add(rule); } return rules; }
From source file:de.fau.amos.ChartRenderer.java
/** * Creates Chart (JFreeChart object) using TimeSeriesCollection. Used for forecast only. * //from w w w . j a v a2 s . c o m * @param collection TimeSeriesCollection that provides basis for chart. * @param time Time where "real" data ends. * @param unit Unit of displayed values (kWh,TNF,kWh/TNF) * @return Returns finished JFreeChart. */ private JFreeChart createForecastChart(final TimeSeriesCollection collection, String time, String unit) { // Modification of X-Axis Label int day = Integer.parseInt(time.substring(8, 10)); int month = Integer.parseInt(time.substring(5, 7)); int year = Integer.parseInt(time.substring(0, 4)); //get Weekday Calendar c = Calendar.getInstance(); c.set(year, month - 1, day, 0, 0); int weekDay = c.get(Calendar.DAY_OF_WEEK); String dayString = new DateFormatSymbols(Locale.US).getWeekdays()[weekDay] + ", " + day + ". "; String monthString = new DateFormatSymbols(Locale.US).getMonths()[month - 1]; String xAxisLabel = "" + dayString + monthString + " " + time.substring(0, 4); //Creation of the lineChart JFreeChart lineChart = ChartFactory.createTimeSeriesChart("Forecast", // title xAxisLabel, // x-axis label // "Energy Consumption "+("1".equals(unit)?"[kWh]":("2".equals(unit)?"[kWh/TNF]":("3".equals(unit)?"[TNF]":""))), // y-axis label ("1".equals(unit) ? "Energy Consumption [kWh]" : ("2".equals(unit) ? "Energy Consumption [kWh/TNF]" : ("3".equals(unit) ? "Produced Pieces [TNF]" : ""))), collection, // data true, // create legend? false, // generate tooltips? false // generate URLs? ); //graphical modifications for LineChart lineChart.setBackgroundPaint(Color.white); XYPlot plot = lineChart.getXYPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(0, 0, 0, 0)); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer() { private static final long serialVersionUID = 1L; // Stroke soild = new BasicStroke(2.0f); Stroke dashed = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[] { 10.0f }, 0.0f); @Override public Stroke getItemStroke(int row, int column) { //third series in collection -> forecast collection if (row == 2) { return dashed; //partial dashed->not needed now, maybe later // double x = collection.getXValue(row, column); // // if ( x > 4){ // return dashed; // } else { // return soild; // } } else return super.getItemStroke(row, column); } }; renderer.setBaseShapesVisible(false); renderer.setBaseShapesFilled(true); renderer.setBaseStroke(new BasicStroke(3)); plot.setRenderer(renderer); return lineChart; }
From source file:org.celllife.idart.gui.patient.AddPatient.java
/** * //w w w.j ava 2 s . c om */ private void editPatientIdentifiers() { PatientIdentifierDialog dialog = new PatientIdentifierDialog(getShell(), getHSession(), localPatient); dialog.openAndWait(); identifierChangesMade = dialog.isChangesMade(); if (localPatient.getPatientId() == null || localPatient.getPatientId().isEmpty()) { cmdClearWidgetSelected(); } else { txtPatientId.setText(localPatient.getPatientId()); //Preparar Prim.Nomes, Apelido e Data de Nascimento apartir do NID usando REST WEB SERVICES String nid = txtPatientId.getText().toUpperCase().trim(); String resource = new RestClient() .getOpenMRSResource(iDartProperties.REST_GET_PATIENT + StringUtils.replace(nid, " ", "%20")); String personUuid = resource.substring(21, 57); String personDemografics = new RestClient() .getOpenMRSResource(iDartProperties.REST_GET_PERSON_GENERIC + personUuid); JSONObject jsonObject = new org.json.JSONObject(personDemografics); String fullName = jsonObject.getJSONObject("preferredName").getString("display"); String[] names = fullName.trim().split(" "); System.out.println(names[0]); System.out.println(names[names.length - 1]); txtFirstNames.setText(names[0]);//Primeiros nomes localPatient.setFirstNames(txtFirstNames.getText());//Primeiros nomes txtSurname.setText(names[names.length - 1]);//Apelido localPatient.setLastname(txtSurname.getText());//Apelido String gender = jsonObject.getString("gender").trim(); cmbSex.setText(gender); localPatient.setSex(cmbSex.getText().charAt(0)); String birthDate = jsonObject.getString("birthdate").trim(); String year = birthDate.substring(0, 4); String month = new DateFormatSymbols(Locale.ENGLISH) .getMonths()[Integer.valueOf(birthDate.substring(5, 7)) - 1]; Integer day = Integer.valueOf(birthDate.substring(8, 10)); SimpleDateFormat sdf = new SimpleDateFormat("d-MMMM-yyyy", Locale.ENGLISH); theDate = null;//Data de Nascimento try { theDate = sdf.parse(day.toString() + "-" + month + "-" + year); } catch (ParseException e1) { getLog().error("Error parsing date: ", e1); } cmbDOBDay.setText(day.toString()); cmbDOBMonth.setText(month); cmbDOBYear.setText(year); localPatient.setDateOfBirth(theDate); } }
From source file:org.celllife.idart.gui.patient.AddPatientIdart.java
/** * //from w w w . j a v a2 s. c o m */ private void editPatientIdentifiers() { PatientIdentifierDialog dialog = new PatientIdentifierDialog(getShell(), getHSession(), localPatient); dialog.openAndWait(); identifierChangesMade = dialog.isChangesMade(); if (localPatient.getPatientId() == null || localPatient.getPatientId().isEmpty()) { cmdClearWidgetSelected(); } else { txtPatientId.setText(localPatient.getPatientId()); //Preparar Prim.Nomes, Apelido e Data de Nascimento apartir do NID usando REST WEB SERVICES String nid = txtPatientId.getText().toUpperCase().trim(); String resource = new RestClient() .getOpenMRSResource(iDartProperties.REST_GET_PATIENT + StringUtils.replace(nid, " ", "%20")); String personUuid = resource.substring(21, 57); String personDemografics = new RestClient().getOpenMRSResource("person/" + personUuid); JSONObject jsonObject = new org.json.JSONObject(personDemografics); String fullName = jsonObject.getJSONObject("preferredName").getString("display"); String[] names = fullName.trim().split(" "); System.out.println(names[0]); System.out.println(names[names.length - 1]); txtFirstNames.setText(names[0]);//Primeiros nomes localPatient.setFirstNames(txtFirstNames.getText());//Primeiros nomes txtSurname.setText(names[names.length - 1]);//Apelido localPatient.setLastname(txtSurname.getText());//Apelido String gender = jsonObject.getString("gender").trim(); cmbSex.setText(gender); localPatient.setSex(cmbSex.getText().charAt(0)); String birthDate = jsonObject.getString("birthdate").trim(); String year = birthDate.substring(0, 4); String month = new DateFormatSymbols(Locale.ENGLISH) .getMonths()[Integer.valueOf(birthDate.substring(5, 7)) - 1]; Integer day = Integer.valueOf(birthDate.substring(8, 10)); SimpleDateFormat sdf = new SimpleDateFormat("d-MMMM-yyyy", Locale.ENGLISH); theDate = null;//Data de Nascimento try { theDate = sdf.parse(day.toString() + "-" + month + "-" + year); } catch (ParseException e1) { getLog().error("Error parsing date: ", e1); } cmbDOBDay.setText(day.toString()); cmbDOBMonth.setText(month); cmbDOBYear.setText(year); localPatient.setDateOfBirth(theDate); } }
From source file:org.exoplatform.calendar.webui.popup.UIEventForm.java
/** * Build the repeating summary, i.e: daily every 2 days, until 02/03/2011. <br/> * The summary structure is defined in resource bundle, it contains some parameters and </br> * will be replaced by values from repeatEvent. <br/> * <p>There are 6 parameters: {count}, {until}, {interval}, {byDays}, {theDay}, {theNumber}.<br/> * Some labels in resource bundle to define numbers (the first, the second, ...) which were used in summary * @param repeatEvent the repeating event * @return summary string about repeating event * @throws Exception/*from ww w . ja va2 s . c o m*/ */ public String buildRepeatSummary(CalendarEvent repeatEvent) throws Exception { CalendarSetting calSetting = CalendarUtils.getCurrentUserCalendarSetting(); WebuiRequestContext context = WebuiRequestContext.getCurrentInstance(); Locale locale = context.getParentAppRequestContext().getLocale(); DateFormat format = new SimpleDateFormat(calSetting.getDateFormat(), locale); DateFormatSymbols symbols = new DateFormatSymbols(locale); String[] dayOfWeeks = symbols.getWeekdays(); String summary = ""; if (repeatEvent == null) return ""; String repeatType = repeatEvent.getRepeatType(); if (CalendarEvent.RP_NOREPEAT.equals(repeatType) || repeatType == null) return ""; int interval = (int) repeatEvent.getRepeatInterval(); int count = (int) repeatEvent.getRepeatCount(); Date until = repeatEvent.getRepeatUntilDate(); String endType = RP_END_NEVER; if (count > 0) endType = RP_END_AFTER; if (until != null) endType = RP_END_BYDATE; String pattern = ""; if (repeatType.equals(CalendarEvent.RP_DAILY)) { if (interval == 1) { //pattern = "Daily"; pattern = getLabel("daily"); } else { //pattern = "Every {interval} days"; pattern = getLabel("every-day"); } if (endType.equals(RP_END_AFTER)) { //pattern = "Daily, {count} times"; //pattern = "Every {interval} days, {count} times"; pattern += ", "; pattern += getLabel("count-times"); } if (endType.equals(RP_END_BYDATE)) { //pattern = "Daily, until {until}"; //pattern = "Every {interval} days, until {until}"; pattern += ", "; pattern += getLabel("until"); } summary = pattern.replace("{interval}", String.valueOf(interval)) .replace("{count}", String.valueOf(repeatEvent.getRepeatCount())) .replace("{until}", repeatEvent.getRepeatUntilDate() == null ? "" : format.format(repeatEvent.getRepeatUntilDate())); return summary; } if (repeatType.equals(CalendarEvent.RP_WEEKLY)) { if (interval == 1) { //pattern = "Weekly on {byDays}"; pattern = getLabel("weekly"); } else { //pattern = "Every {interval} weeks on {byDays}"; pattern = getLabel("every-week"); } if (endType.equals(RP_END_AFTER)) { //pattern = "Weekly on {byDays}, {count} times"; //pattern = "Every {interval} weeks on {byDays}, {count} times"; pattern += ", "; pattern += getLabel("count-times"); } if (endType.equals(RP_END_BYDATE)) { //pattern = "Weekly on {byDays}, until {until}"; //pattern = "Every {interval} weeks on {byDays}, until {until}"; pattern += ", "; pattern += getLabel("until"); } String[] weeklyByDays = repeatEvent.getRepeatByDay(); StringBuffer byDays = new StringBuffer(); for (int i = 0; i < weeklyByDays.length; i++) { if (i == 0) { byDays.append(dayOfWeeks[UIRepeatEventForm.convertToDayOfWeek(weeklyByDays[0])]); } else { byDays.append(", "); byDays.append(dayOfWeeks[UIRepeatEventForm.convertToDayOfWeek(weeklyByDays[i])]); } } summary = pattern.replace("{interval}", String.valueOf(interval)) .replace("{count}", String.valueOf(repeatEvent.getRepeatCount())) .replace("{until}", repeatEvent.getRepeatUntilDate() == null ? "" : format.format(repeatEvent.getRepeatUntilDate())) .replace("{byDays}", byDays.toString()); return summary; } if (repeatType.equals(CalendarEvent.RP_MONTHLY)) { String monthlyType = UIRepeatEventForm.RP_MONTHLY_BYMONTHDAY; if (repeatEvent.getRepeatByDay() != null && repeatEvent.getRepeatByDay().length > 0) monthlyType = UIRepeatEventForm.RP_MONTHLY_BYDAY; if (interval == 1) { // pattern = "Monthly on" pattern = getLabel("monthly"); } else { // pattern = "Every {interval} months on pattern = getLabel("every-month"); } if (monthlyType.equals(UIRepeatEventForm.RP_MONTHLY_BYDAY)) { // pattern = "Monthly on {theNumber} {theDay} // pattern = "Every {interval} months on {theNumber} {theDay} pattern += " "; pattern += getLabel("monthly-by-day"); } else { // pattern = "Monthly on day {theDay} // pattern = "Every {interval} months on day {theDay} pattern += " "; pattern += getLabel("monthly-by-month-day"); } if (endType.equals(RP_END_AFTER)) { pattern += ", "; pattern += getLabel("count-times"); } if (endType.equals(RP_END_BYDATE)) { pattern += ", "; pattern += getLabel("until"); } String theNumber = ""; // the first, the second, the third, ... String theDay = ""; // in monthly by day, it's Monday, Tuesday, ... (day of week), in monthly by monthday, it's 1-31 (day of month) if (monthlyType.equals(UIRepeatEventForm.RP_MONTHLY_BYDAY)) { java.util.Calendar temp = CalendarUtils.getInstanceOfCurrentCalendar(); temp.setTime(repeatEvent.getFromDateTime()); int weekOfMonth = temp.get(java.util.Calendar.WEEK_OF_MONTH); java.util.Calendar temp2 = CalendarUtils.getInstanceOfCurrentCalendar(); temp2.setTime(temp.getTime()); temp2.add(java.util.Calendar.DATE, 7); if (temp2.get(java.util.Calendar.MONTH) != temp.get(java.util.Calendar.MONTH)) weekOfMonth = 5; int dayOfWeek = temp.get(java.util.Calendar.DAY_OF_WEEK); String[] weekOfMonths = new String[] { getLabel("summary-the-first"), getLabel("summary-the-second"), getLabel("summary-the-third"), getLabel("summary-the-fourth"), getLabel("summary-the-last") }; theNumber = weekOfMonths[weekOfMonth - 1]; theDay = dayOfWeeks[dayOfWeek]; } else { java.util.Calendar temp = CalendarUtils.getInstanceOfCurrentCalendar(); temp.setTime(repeatEvent.getFromDateTime()); int dayOfMonth = temp.get(java.util.Calendar.DAY_OF_MONTH); theDay = String.valueOf(dayOfMonth); } summary = pattern.replace("{interval}", String.valueOf(interval)) .replace("{count}", String.valueOf(repeatEvent.getRepeatCount())) .replace("{until}", repeatEvent.getRepeatUntilDate() == null ? "" : format.format(repeatEvent.getRepeatUntilDate())) .replace("{theDay}", theDay).replace("{theNumber}", theNumber); return summary; } if (repeatType.equals(CalendarEvent.RP_YEARLY)) { if (interval == 1) { // pattern = "Yearly on {theDay}" pattern = getLabel("yearly"); } else { // pattern = "Every {interval} years on {theDay}" pattern = getLabel("every-year"); } if (endType.equals(RP_END_AFTER)) { // pattern = "Yearly on {theDay}, {count} times" // pattern = "Every {interval} years on {theDay}, {count} times" pattern += ", "; pattern += getLabel("count-times"); } if (endType.equals(RP_END_BYDATE)) { // pattern = "Yearly on {theDay}, until {until}" // pattern = "Every {interval} years on {theDay}, until {until}" pattern += ", "; pattern += getLabel("until"); } String theDay = format.format(repeatEvent.getFromDateTime()); // summary = pattern.replace("{interval}", String.valueOf(interval)) .replace("{count}", String.valueOf(repeatEvent.getRepeatCount())) .replace("{until}", repeatEvent.getRepeatUntilDate() == null ? "" : format.format(repeatEvent.getRepeatUntilDate())) .replace("{theDay}", theDay); return summary; } return summary; }
From source file:com.xpn.xwiki.XWiki.java
public String formatDate(Date date, String format, XWikiContext context) { if (date == null) { return ""; }/*from ww w.ja v a2 s . c o m*/ String xformat = format; String defaultFormat = "yyyy/MM/dd HH:mm"; if (format == null) { xformat = getXWikiPreference("dateformat", defaultFormat, context); } try { DateFormatSymbols formatSymbols = null; try { String language = getLanguagePreference(context); formatSymbols = new DateFormatSymbols(new Locale(language)); } catch (Exception e2) { String language = getXWikiPreference("default_language", context); if ((language != null) && (!language.equals(""))) { formatSymbols = new DateFormatSymbols(new Locale(language)); } } SimpleDateFormat sdf; if (formatSymbols != null) { sdf = new SimpleDateFormat(xformat, formatSymbols); } else { sdf = new SimpleDateFormat(xformat); } try { sdf.setTimeZone(TimeZone.getTimeZone(getUserTimeZone(context))); } catch (Exception e) { } return sdf.format(date); } catch (Exception e) { LOGGER.info("Failed to format date [" + date + "] with pattern [" + xformat + "]: " + e.getMessage()); if (format == null) { if (xformat.equals(defaultFormat)) { return date.toString(); } else { return formatDate(date, defaultFormat, context); } } else { return formatDate(date, null, context); } } }
From source file:com.lp.server.fertigung.ejbfac.FertigungFacBean.java
@TransactionAttribute(TransactionAttributeType.SUPPORTS) public int wiederholendeLoseAnlegen(TheClientDto theClientDto) { int iAnzahlAngelegterLose = 0; DateFormatSymbols symbols = new DateFormatSymbols(theClientDto.getLocUi()); String[] defaultMonths = symbols.getMonths(); int iStandarddurchlaufzeit = 0; try {/*from w w w .j a va2s. c om*/ ParametermandantDto parameter = getParameterFac().getMandantparameter(theClientDto.getMandant(), ParameterFac.KATEGORIE_FERTIGUNG, ParameterFac.INTERNEBESTELLUNG_DEFAULTDURCHLAUFZEIT); iStandarddurchlaufzeit = ((Integer) parameter.getCWertAsObject()).intValue(); } catch (RemoteException ex2) { throwEJBExceptionLPRespectOld(ex2); } Session session = FLRSessionFactory.getFactory().openSession(); Criteria crit = session.createCriteria(FLRWiederholendelose.class); crit.add(Restrictions.eq("mandant_c_nr", theClientDto.getMandant())); crit.add(Restrictions.eq(FertigungFac.FLR_WIEDERHOLENDELOSE_B_VERSTECKT, Helper.boolean2Short(false))); List<?> resultList = crit.list(); Iterator<?> resultListIterator = resultList.iterator(); while (resultListIterator.hasNext()) { FLRWiederholendelose flrWiederholendelose = (FLRWiederholendelose) resultListIterator.next(); // Naechster faelliger Termin nach Heute Calendar cBeginn = Calendar.getInstance(); cBeginn.setTimeInMillis(flrWiederholendelose.getT_termin().getTime()); String intervall = flrWiederholendelose.getAuftragwiederholungsintervall_c_nr(); Timestamp tHeute = Helper.cutTimestamp(new Timestamp(System.currentTimeMillis())); while (cBeginn.getTimeInMillis() < tHeute.getTime()) { if (intervall.equals(AuftragServiceFac.AUFTRAGWIEDERHOLUNGSINTERVALL_2WOECHENTLICH)) { cBeginn.set(Calendar.DAY_OF_MONTH, cBeginn.get(Calendar.DAY_OF_MONTH) + 14); } else if (intervall.equals(AuftragServiceFac.AUFTRAGWIEDERHOLUNGSINTERVALL_WOECHENTLICH)) { cBeginn.set(Calendar.DAY_OF_MONTH, cBeginn.get(Calendar.DAY_OF_MONTH) + 7); } if (intervall.equals(AuftragServiceFac.AUFTRAGWIEDERHOLUNGSINTERVALL_JAHR)) { cBeginn.set(Calendar.YEAR, cBeginn.get(Calendar.YEAR) + 1); } else if (intervall.equals(AuftragServiceFac.AUFTRAGWIEDERHOLUNGSINTERVALL_2JAHR)) { cBeginn.set(Calendar.YEAR, cBeginn.get(Calendar.YEAR) + 2); } else if (intervall.equals(AuftragServiceFac.AUFTRAGWIEDERHOLUNGSINTERVALL_3JAHR)) { cBeginn.set(Calendar.YEAR, cBeginn.get(Calendar.YEAR) + 3); } else if (intervall.equals(AuftragServiceFac.AUFTRAGWIEDERHOLUNGSINTERVALL_4JAHR)) { cBeginn.set(Calendar.YEAR, cBeginn.get(Calendar.YEAR) + 4); } else if (intervall.equals(AuftragServiceFac.AUFTRAGWIEDERHOLUNGSINTERVALL_5JAHR)) { cBeginn.set(Calendar.YEAR, cBeginn.get(Calendar.YEAR) + 5); } else if (intervall.equals(AuftragServiceFac.AUFTRAGWIEDERHOLUNGSINTERVALL_MONATLICH)) { cBeginn.set(Calendar.MONTH, cBeginn.get(Calendar.MONTH) + 1); } else if (intervall.equals(AuftragServiceFac.AUFTRAGWIEDERHOLUNGSINTERVALL_QUARTAL)) { cBeginn.set(Calendar.MONTH, cBeginn.get(Calendar.MONTH) + 3); } } Timestamp tBeginndatumFuerLos = new Timestamp(cBeginn.getTimeInMillis()); // Voreilende Tage abziehen String monatsname = defaultMonths[cBeginn.get(Calendar.MONTH)]; int iJahr = cBeginn.get(Calendar.YEAR); int iTageVoreilend = flrWiederholendelose.getI_tagevoreilend(); cBeginn.set(Calendar.DAY_OF_MONTH, cBeginn.get(Calendar.DAY_OF_MONTH) - iTageVoreilend); Timestamp tAnlagedatum = new Timestamp(cBeginn.getTimeInMillis()); if (tAnlagedatum.before(tHeute) || tAnlagedatum.equals(tHeute)) { // try { Query query = em.createNamedQuery("LosfindWiederholendeloseIIdTProduktionsbeginnMandantCNr"); query.setParameter(1, flrWiederholendelose.getI_id()); query.setParameter(2, tBeginndatumFuerLos); query.setParameter(3, theClientDto.getMandant()); Collection<?> cl = query.getResultList(); // if (cl.isEmpty()) { // throw new EJBExceptionLP(EJBExceptionLP.FEHLER, null); // } LosDto[] lose = assembleLosDtos(cl); // Wenn noch nicht angelegt if (lose.length == 0) { WiederholendeloseDto dto = wiederholendeloseFindByPrimaryKey(flrWiederholendelose.getI_id()); String projektname = ""; if (dto.getCProjekt() != null) { projektname += dto.getCProjekt() + " "; } projektname += monatsname + " " + iJahr; if (projektname.length() > 50) { projektname = projektname.substring(0, 49); } LosDto losDto = new LosDto(); losDto.setWiederholendeloseIId(dto.getIId()); losDto.setCProjekt(projektname); losDto.setFertigungsgruppeIId(dto.getFertigungsgruppeIId()); losDto.setKostenstelleIId(dto.getKostenstelleIId()); losDto.setLagerIIdZiel(dto.getLagerIIdZiel()); losDto.setMandantCNr(theClientDto.getMandant()); losDto.setNLosgroesse(dto.getNLosgroesse()); losDto.setPartnerIIdFertigungsort(dto.getPartnerIIdFertigungsort()); losDto.setStuecklisteIId(dto.getStuecklisteIId()); losDto.setTProduktionsbeginn(new java.sql.Date(tBeginndatumFuerLos.getTime())); // Produktionsende try { int laufzeit = iStandarddurchlaufzeit; if (dto.getStuecklisteIId() != null) { StuecklisteDto stuecklisteDto = getStuecklisteFac() .stuecklisteFindByPrimaryKey(dto.getStuecklisteIId(), theClientDto); if (stuecklisteDto.getNDefaultdurchlaufzeit() != null) { laufzeit = stuecklisteDto.getNDefaultdurchlaufzeit().intValue(); } } Calendar cTemp = Calendar.getInstance(); cTemp.setTimeInMillis(tBeginndatumFuerLos.getTime()); cTemp.set(Calendar.DAY_OF_MONTH, cTemp.get(Calendar.DAY_OF_MONTH) + laufzeit); losDto.setTProduktionsende(new java.sql.Date(cTemp.getTime().getTime())); context.getBusinessObject(FertigungFac.class).createLos(losDto, theClientDto); } catch (RemoteException ex1) { throwEJBExceptionLPRespectOld(ex1); } iAnzahlAngelegterLose++; } // } // catch (FinderException ex) { // throw new EJBExceptionLP(EJBExceptionLP.FEHLER, ex); // } } } return iAnzahlAngelegterLose; }