List of usage examples for java.util GregorianCalendar getTimeInMillis
public long getTimeInMillis()
From source file:gov.noaa.pfel.coastwatch.Projects.java
/** Make VH2018 mday .ncml files. * coordValue is firstDay of the month. First 3 of 2012 are 15340, 15371, 15400. */// w w w .j a v a2 s . c o m public static void makeVH2018mdayNcmlFiles(int startYear, int endYear) throws Throwable { String varDirNames[] = new String[] { "chla", "k490", "r671", "par", "pic", "poc" }; String jplFileNames[] = new String[] { "CHL_chlor_a", "KD490_Kd_490", "RRS_Rrs_671", "PAR_par", "PIC_pic", "POC_poc" }; String jplVarNames[] = new String[] { "chlor_a", "Kd_490", "Rrs_671", "par", "pic", "poc" }; for (int year = startYear; year <= endYear; year++) { for (int month = 1; month <= 12; month++) { GregorianCalendar firstDay = Calendar2.newGCalendarZulu(year, month, 1); GregorianCalendar lastDay = Calendar2.newGCalendarZulu(year, month + 1, 0); String yj1 = Calendar2.formatAsYYYYDDD(firstDay); String yj2 = Calendar2.formatAsYYYYDDD(lastDay); int daysSince = Math2.roundToInt(Calendar2.epochSecondsToUnitsSince(0, Calendar2.SECONDS_PER_DAY, firstDay.getTimeInMillis() / 1000)); String2.log(yj1 + " " + yj2 + " " + daysSince); for (int var = 0; var < varDirNames.length; var++) { FileWriter w = new FileWriter( "/content/scripts/VH2018ncml/" + varDirNames[var] + "/ncmlmon/V" + yj1 + yj2 + ".ncml"); w.write( /* C:/content/scripts/VH2018ncml/chla/ncmlmon/V20120012012031.ncml is <netcdf xmlns='http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2'> <variable name='time' type='int' shape='time' /> <aggregation dimName='time' type='joinNew'> <variableAgg name='l3m_data'/> <netcdf location='V20120012012031.L3m_MO_NPP_CHL_chlor_a_4km' coordValue='15340'/> </aggregation> </netcdf> */ "<netcdf xmlns='http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2'>\n" + " <variable name='time' type='int' shape='time' />\n" + " <aggregation dimName='time' type='joinNew'>\n" + " <variableAgg name='" + jplVarNames[var] + "'/>\n" + " <netcdf location='V" + yj1 + yj2 + ".L3m_MO_SNPP_" + jplFileNames[var] + "_4km.nc' " + "coordValue='" + daysSince + "'/>\n" + " </aggregation>\n" + "</netcdf>\n"); w.close(); } } } }
From source file:gov.noaa.pfel.coastwatch.Projects.java
/** Make VH2 8day .ncml files. * coordValue is firstDay. First 3 of 2012 are 15340, 15348, 15356. * Every year, start again Jan 1-8, 9-16, ... * End of year, /* w w w .j av a 2 s .c o m*/ */ public static void makeVH28dayNcmlFiles(int startYear, int endYear) throws Throwable { String varDirNames[] = new String[] { "chla", "k490", "r671", "par", "pic", "poc" }; String jplFileNames[] = new String[] { "CHL_chlor_a", "KD490_Kd_490", "RRS_Rrs_671", "PAR_par", "PIC_pic", "POC_poc" }; String jplVarNames[] = new String[] { "chlor_a", "Kd_490", "Rrs_671", "par", "pic", "poc" }; for (int year = startYear; year <= endYear; year++) { int nDays = year % 4 == 0 ? 366 : 365; for (int day1 = 1; day1 <= nDays; day1 += 8) { GregorianCalendar firstDay = Calendar2.newGCalendarZulu(year, day1); GregorianCalendar lastDay = Calendar2.newGCalendarZulu(year, Math.min(nDays, day1 + 7)); String yj1 = Calendar2.formatAsYYYYDDD(firstDay); String yj2 = Calendar2.formatAsYYYYDDD(lastDay); int daysSince = Math2.roundToInt(Calendar2.epochSecondsToUnitsSince(0, Calendar2.SECONDS_PER_DAY, firstDay.getTimeInMillis() / 1000)); if (day1 + 7 > nDays) daysSince--; //imperfect String2.log(yj1 + " " + yj2 + " " + daysSince); for (int var = 0; var < varDirNames.length; var++) { FileWriter w = new FileWriter( "/content/scripts/VH2ncml/" + varDirNames[var] + "/ncml8day/V" + yj1 + yj2 + ".ncml"); w.write( /* C:/content/scripts/VH2ncml/chla/ncml8day/V20120012012008.ncml is <netcdf xmlns='http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2'> <variable name='time' type='int' shape='time' /> <aggregation dimName='time' type='joinNew'> <variableAgg name='l3m_data'/> <netcdf location='V20120012012008.L3m_8D_NPP_CHL_chlor_a_4km' coordValue='15340'/> </aggregation> </netcdf> */ "<netcdf xmlns='http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2'>\n" + " <variable name='time' type='int' shape='time' />\n" + " <aggregation dimName='time' type='joinNew'>\n" + " <variableAgg name='" + jplVarNames[var] + "'/>\n" + " <netcdf location='V" + yj1 + yj2 + ".L3m_8D_NPP_" + jplFileNames[var] + "_4km.nc' " + "coordValue='" + daysSince + "'/>\n" + " </aggregation>\n" + "</netcdf>\n"); w.close(); } } } }
From source file:gov.noaa.pfel.coastwatch.Projects.java
/** Make VH3 8day .ncml files. * coordValue is firstDay. First 3 of 2012 are 15340, 15348, 15356. * Every year, start again Jan 1-8, 9-16, ... * End of year, //from ww w .ja v a 2s .c om */ public static void makeVH38dayNcmlFiles(int startYear, int endYear) throws Throwable { String varDirNames[] = new String[] { "chla", "k490", "r671", "par", "pic", "poc" }; String jplFileNames[] = new String[] { "CHL_chlor_a", "KD490_Kd_490", "RRS_Rrs_671", "PAR_par", "PIC_pic", "POC_poc" }; String jplVarNames[] = new String[] { "chlor_a", "Kd_490", "Rrs_671", "par", "pic", "poc" }; for (int year = startYear; year <= endYear; year++) { int nDays = year % 4 == 0 ? 366 : 365; for (int day1 = 1; day1 <= nDays; day1 += 8) { GregorianCalendar firstDay = Calendar2.newGCalendarZulu(year, day1); GregorianCalendar lastDay = Calendar2.newGCalendarZulu(year, Math.min(nDays, day1 + 7)); String yj1 = Calendar2.formatAsYYYYDDD(firstDay); String yj2 = Calendar2.formatAsYYYYDDD(lastDay); int daysSince = Math2.roundToInt(Calendar2.epochSecondsToUnitsSince(0, Calendar2.SECONDS_PER_DAY, firstDay.getTimeInMillis() / 1000)); if (day1 + 7 > nDays) daysSince--; //imperfect String2.log(yj1 + " " + yj2 + " " + daysSince); for (int var = 0; var < varDirNames.length; var++) { FileWriter w = new FileWriter( "/content/scripts/VH3ncml/" + varDirNames[var] + "/ncml8day/V" + yj1 + yj2 + ".ncml"); w.write( /* C:/content/scripts/VH3ncml/chla/ncml8day/V20120012012008.ncml is <netcdf xmlns='http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2'> <variable name='time' type='int' shape='time' /> <aggregation dimName='time' type='joinNew'> <variableAgg name='l3m_data'/> <netcdf location='V20120012012008.L3m_8D_NPP_CHL_chlor_a_4km' coordValue='15340'/> </aggregation> </netcdf> */ "<netcdf xmlns='http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2'>\n" + " <variable name='time' type='int' shape='time' />\n" + " <aggregation dimName='time' type='joinNew'>\n" + " <variableAgg name='" + jplVarNames[var] + "'/>\n" + " <netcdf location='V" + yj1 + yj2 + ".L3m_8D_SNPP_" + jplFileNames[var] + "_4km.nc' " + "coordValue='" + daysSince + "'/>\n" + " </aggregation>\n" + "</netcdf>\n"); w.close(); } } } }
From source file:gov.noaa.pfel.coastwatch.Projects.java
/** Make VH2018 8day .ncml files. * coordValue is firstDay. First 3 of 2012 are 15340, 15348, 15356. * Every year, start again Jan 1-8, 9-16, ... * End of year, /*from www . j a v a2 s.com*/ */ public static void makeVH20188dayNcmlFiles(int startYear, int endYear) throws Throwable { String varDirNames[] = new String[] { "chla", "k490", "r671", "par", "pic", "poc" }; String jplFileNames[] = new String[] { "CHL_chlor_a", "KD490_Kd_490", "RRS_Rrs_671", "PAR_par", "PIC_pic", "POC_poc" }; String jplVarNames[] = new String[] { "chlor_a", "Kd_490", "Rrs_671", "par", "pic", "poc" }; for (int year = startYear; year <= endYear; year++) { int nDays = year % 4 == 0 ? 366 : 365; for (int day1 = 1; day1 <= nDays; day1 += 8) { GregorianCalendar firstDay = Calendar2.newGCalendarZulu(year, day1); GregorianCalendar lastDay = Calendar2.newGCalendarZulu(year, Math.min(nDays, day1 + 7)); String yj1 = Calendar2.formatAsYYYYDDD(firstDay); String yj2 = Calendar2.formatAsYYYYDDD(lastDay); int daysSince = Math2.roundToInt(Calendar2.epochSecondsToUnitsSince(0, Calendar2.SECONDS_PER_DAY, firstDay.getTimeInMillis() / 1000)); if (day1 + 7 > nDays) daysSince--; //imperfect String2.log(yj1 + " " + yj2 + " " + daysSince); for (int var = 0; var < varDirNames.length; var++) { FileWriter w = new FileWriter("/content/scripts/VH2018ncml/" + varDirNames[var] + "/ncml8day/V" + yj1 + yj2 + ".ncml"); w.write( /* C:/content/scripts/VH2018ncml/chla/ncml8day/V20120012012008.ncml is <netcdf xmlns='http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2'> <variable name='time' type='int' shape='time' /> <aggregation dimName='time' type='joinNew'> <variableAgg name='l3m_data'/> <netcdf location='V20120012012008.L3m_8D_NPP_CHL_chlor_a_4km' coordValue='15340'/> </aggregation> </netcdf> */ "<netcdf xmlns='http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2'>\n" + " <variable name='time' type='int' shape='time' />\n" + " <aggregation dimName='time' type='joinNew'>\n" + " <variableAgg name='" + jplVarNames[var] + "'/>\n" + " <netcdf location='V" + yj1 + yj2 + ".L3m_8D_SNPP_" + jplFileNames[var] + "_4km.nc' " + "coordValue='" + daysSince + "'/>\n" + " </aggregation>\n" + "</netcdf>\n"); w.close(); } } } }
From source file:gov.noaa.pfel.coastwatch.Projects.java
/** Make VH 8day .ncml files. * coordValue is firstDay. First 3 of 2012 are 15340, 15348, 15356. * Every year, start again Jan 1-8, 9-16, ... * End of year, /*from w ww .j a va2 s . co m*/ */ public static void makeVH8dayNcmlFiles(int startYear, int endYear) throws Throwable { String varDirNames[] = new String[] { "chla", "k490", "r671", "par", "pic", "poc" }; String jplNames[] = new String[] { "CHL_chlor_a", "KD490_Kd_490", "RRS_Rrs_671", "PAR_par", "PIC_pic", "POC_poc" }; for (int year = startYear; year <= endYear; year++) { int nDays = year % 4 == 0 ? 366 : 365; for (int day1 = 1; day1 <= nDays; day1 += 8) { GregorianCalendar firstDay = Calendar2.newGCalendarZulu(year, day1); GregorianCalendar lastDay = Calendar2.newGCalendarZulu(year, Math.min(nDays, day1 + 7)); String yj1 = Calendar2.formatAsYYYYDDD(firstDay); String yj2 = Calendar2.formatAsYYYYDDD(lastDay); int daysSince = Math2.roundToInt(Calendar2.epochSecondsToUnitsSince(0, Calendar2.SECONDS_PER_DAY, firstDay.getTimeInMillis() / 1000)); if (day1 + 7 > nDays) daysSince--; //imperfect String2.log(yj1 + " " + yj2 + " " + daysSince); for (int var = 0; var < varDirNames.length; var++) { FileWriter w = new FileWriter( "/content/scripts/VHncml/" + varDirNames[var] + "/ncml8day/V" + yj1 + yj2 + ".ncml"); w.write( /* C:/content/scripts/VHncml/chla/ncml8day/V20120012012008.ncml is <netcdf xmlns='http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2'> <variable name='time' type='int' shape='time' /> <aggregation dimName='time' type='joinNew'> <variableAgg name='l3m_data'/> <netcdf location='V20120012012008.L3m_8D_NPP_CHL_chlor_a_4km' coordValue='15340'/> </aggregation> </netcdf> */ "<netcdf xmlns='http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2'>\n" + " <variable name='time' type='int' shape='time' />\n" + " <aggregation dimName='time' type='joinNew'>\n" + " <variableAgg name='l3m_data'/>\n" + " <netcdf location='V" + yj1 + yj2 + ".L3m_8D_NPP_" + jplNames[var] + "_4km' " + "coordValue='" + daysSince + "'/>\n" + " </aggregation>\n" + "</netcdf>\n"); w.close(); } } } }
From source file:org.nuclos.common2.SeriesUtils.java
/** * /*from w ww.j a v a 2 s. c o m*/ * @param series * @param dateOrigin * @return the next date calculated by series from origin. * origin could be a calculated date (result >= origin) */ public static DateTime getSeriesNext(String series, DateTime dateOrigin) { if (series == null) return dateOrigin; GregorianCalendar calendar = new GregorianCalendar(); calendar.setTime(dateOrigin.getDate()); String[] split = org.apache.commons.lang.StringUtils.split(series, '|'); if (split.length > 0) { String modus = split[0]; if ("d".equals(modus)) { int hour = Integer.parseInt(split[1]); int minute = Integer.parseInt(split[2]); calendar.set(GregorianCalendar.HOUR_OF_DAY, hour); calendar.set(GregorianCalendar.MINUTE, minute); int days = Integer.parseInt(split[3]); if (days == 0) { // add one day if calculated date is before origin if (calendar.getTime().before(dateOrigin.getDate())) { calendar.add(GregorianCalendar.DAY_OF_MONTH, 1); } while (!isWorkingDay(calendar.get(GregorianCalendar.DAY_OF_WEEK))) { calendar.add(GregorianCalendar.DAY_OF_MONTH, 1); } } else { // add one day if calculated date is before origin if (calendar.getTime().before(dateOrigin.getDate())) { calendar.add(GregorianCalendar.DAY_OF_MONTH, 1); } if (days > 1) { calendar.add(GregorianCalendar.DAY_OF_MONTH, days - 1); } } } else if ("w".equals(modus)) { int hour = Integer.parseInt(split[1]); int minute = Integer.parseInt(split[2]); calendar.set(GregorianCalendar.HOUR_OF_DAY, hour); calendar.set(GregorianCalendar.MINUTE, minute); int weeks = Integer.parseInt(split[3]); List<Integer> possibleWeekdays = new ArrayList<Integer>(); int firstSelectedWeekday = -1000; int lastWeekday = -1000; // use getWeekdayItems() in order to get the right start (end) of the week for (SeriesListItem sli : getWeekdayItems()) { boolean addWeekday = false; switch (sli.getId()) { case GregorianCalendar.MONDAY: if (split[4].equals("0") ? false : true) addWeekday = true; break; case GregorianCalendar.TUESDAY: if (split[5].equals("0") ? false : true) addWeekday = true; break; case GregorianCalendar.WEDNESDAY: if (split[6].equals("0") ? false : true) addWeekday = true; break; case GregorianCalendar.THURSDAY: if (split[7].equals("0") ? false : true) addWeekday = true; break; case GregorianCalendar.FRIDAY: if (split[8].equals("0") ? false : true) addWeekday = true; break; case GregorianCalendar.SATURDAY: if (split[9].equals("0") ? false : true) addWeekday = true; break; case GregorianCalendar.SUNDAY: if (split[10].equals("0") ? false : true) addWeekday = true; break; } if (addWeekday) { possibleWeekdays.add(sli.getId()); if (firstSelectedWeekday == -1000) firstSelectedWeekday = sli.getId(); } lastWeekday = sli.getId(); } // add one day if calculated date is before origin boolean weeksAdded = false; if (calendar.getTime().before(dateOrigin.getDate())) { if (lastWeekday == calendar.get(GregorianCalendar.DAY_OF_WEEK)) { calendar.add(GregorianCalendar.WEEK_OF_YEAR, weeks - 1); weeksAdded = true; } else { calendar.add(GregorianCalendar.DAY_OF_MONTH, 1); } } while (!possibleWeekdays.contains(new Integer(calendar.get(GregorianCalendar.DAY_OF_WEEK)))) { if (!weeksAdded && lastWeekday == calendar.get(GregorianCalendar.DAY_OF_WEEK)) { calendar.add(GregorianCalendar.WEEK_OF_YEAR, weeks - 1); } calendar.add(GregorianCalendar.DAY_OF_MONTH, 1); } } else if ("m".equals(modus)) { int hour = Integer.parseInt(split[1]); int minute = Integer.parseInt(split[2]); calendar.set(GregorianCalendar.HOUR_OF_DAY, hour); calendar.set(GregorianCalendar.MINUTE, minute); if ("m1".equals(split[3])) { int day = Integer.parseInt(split[4]); int months = Integer.parseInt(split[5]); calendar.set(GregorianCalendar.DAY_OF_MONTH, day); // add one month if calculated date is before origin if (calendar.getTime().before(dateOrigin.getDate())) { calendar.add(GregorianCalendar.MONTH, 1); calendar.set(GregorianCalendar.DAY_OF_MONTH, day); } if (months > 1) { calendar.add(GregorianCalendar.MONTH, months - 1); calendar.set(GregorianCalendar.DAY_OF_MONTH, day); } } else { int number = Integer.parseInt(split[4]); int weekday = Integer.parseInt(split[5]); int months = Integer.parseInt(split[6]); calendar.set(GregorianCalendar.DAY_OF_WEEK, weekday); calendar.set(GregorianCalendar.DAY_OF_WEEK_IN_MONTH, number); // add one month if calculated date is before origin if (calendar.getTime().before(dateOrigin.getDate())) { calendar.add(GregorianCalendar.MONTH, 1); calendar.set(GregorianCalendar.DAY_OF_WEEK, weekday); calendar.set(GregorianCalendar.DAY_OF_WEEK_IN_MONTH, number); } if (months > 1) { calendar.add(GregorianCalendar.MONTH, months - 1); calendar.set(GregorianCalendar.DAY_OF_WEEK, weekday); calendar.set(GregorianCalendar.DAY_OF_WEEK_IN_MONTH, number); } } } else if ("y".equals(modus)) { int hour = Integer.parseInt(split[1]); int minute = Integer.parseInt(split[2]); calendar.set(GregorianCalendar.HOUR_OF_DAY, hour); calendar.set(GregorianCalendar.MINUTE, minute); if ("y1".equals(split[3])) { int day = Integer.parseInt(split[4]); int month = Integer.parseInt(split[5]); calendar.set(GregorianCalendar.MONTH, month); calendar.set(GregorianCalendar.DAY_OF_MONTH, day); // add one year if calculated date is before origin if (calendar.getTime().before(dateOrigin.getDate())) { calendar.add(GregorianCalendar.YEAR, 1); calendar.set(GregorianCalendar.MONTH, month); calendar.set(GregorianCalendar.DAY_OF_MONTH, day); } } else { int number = Integer.parseInt(split[4]); int weekday = Integer.parseInt(split[5]); int month = Integer.parseInt(split[6]); calendar.set(GregorianCalendar.MONTH, month); calendar.set(GregorianCalendar.DAY_OF_WEEK, weekday); calendar.set(GregorianCalendar.DAY_OF_WEEK_IN_MONTH, number); // add one year if calculated date is before origin if (calendar.getTime().before(dateOrigin.getDate())) { calendar.add(GregorianCalendar.YEAR, 1); calendar.set(GregorianCalendar.MONTH, month); calendar.set(GregorianCalendar.DAY_OF_WEEK, weekday); calendar.set(GregorianCalendar.DAY_OF_WEEK_IN_MONTH, number); } } } } return new DateTime(calendar.getTimeInMillis()); }
From source file:com.lp.server.fertigung.ejbfac.FertigungFacBean.java
@TransactionAttribute(TransactionAttributeType.NEVER) public KapazitaetsvorschauDto getKapazitaetsvorschau(TheClientDto theClientDto) throws EJBExceptionLP { KapazitaetsvorschauDto kapDto = null; Session session = null;/*from ww w .j a v a 2 s. c om*/ try { // ------------------------------------------------------------------ // ----- // Benoetigte Parameter holen // ------------------------------------------------------------------ // ----- // Default Sicht nach Wochen // final int iSicht = FertigungFac.KAPAZITAETSVORSCHAU_NACH_WOCHEN; // Anzahl der angezeigten Vatergruppen. Alles andere wird nach // "Sonstige" verdichtet final ParametermandantDto parameterAnzahlGruppen = getParameterFac().getMandantparameter( theClientDto.getMandant(), ParameterFac.KATEGORIE_FERTIGUNG, ParameterFac.PARAMETER_FERTIGUNG_KAPAZITAETSVORSCHAU_ANZAHL_GRUPPEN); final int iParamAnzahlGruppen = (Integer) parameterAnzahlGruppen.getCWertAsObject(); // Angezeigter Zeitraum = Anzahl der Spalten final ParametermandantDto parameterZeitraum = getParameterFac().getMandantparameter( theClientDto.getMandant(), ParameterFac.KATEGORIE_FERTIGUNG, ParameterFac.PARAMETER_FERTIGUNG_KAPAZITAETSVORSCHAU_ZEITRAUM); final int iParamZeitraum = (Integer) parameterZeitraum.getCWertAsObject(); // ------------------------------------------------------------------ // ----- // Hibernate-Session erstellen // ------------------------------------------------------------------ // ----- SessionFactory factory = FLRSessionFactory.getFactory(); session = factory.openSession(); // ------------------------------------------------------------------ // ----- // Artikel- / Maschinen-Vatergruppen holen // ------------------------------------------------------------------ // ----- // Alle Artikel-Vatergruppen Criteria cArtikelVatergruppen = session.createCriteria(FLRArtikelgruppe.class); cArtikelVatergruppen.add(Restrictions.isNull(ArtikelFac.FLR_ARTIKELGRUPPE_FLRARTIKELGRUPPE)); List<?> listArtikelgruppen = cArtikelVatergruppen.list(); // Alle Maschinen-Vatergruppen Criteria cMaschinengruppen = session.createCriteria(FLRMaschinengruppe.class); List<?> listMaschinengruppen = cMaschinengruppen.list(); // ------------------------------------------------------------------ // ----- // Anzahl der sub-Diagramme bestimmen // das ist grundsaetzlich (iParamAnzahlGruppen + 1) x 2 ... // (Anzahl d. anzuzeigenden Vatergruppen + Sonstige) f. AZ und // Maschinen // wenn es weniger Vatergruppen als anzuzeigende gibt, reduziert // sich das aber // Gibt es keine Vatergruppe, wird daher alles nach "Sonstige" // verdichtet // ------------------------------------------------------------------ // ----- final int iAnzuzeigendeArtikelgruppen = Math.min(iParamAnzahlGruppen, listArtikelgruppen.size()); final int iAnzuzeigendeMaschinengruppen = Math.min(iParamAnzahlGruppen, listMaschinengruppen.size()); final int iAnzahlZeilen = iAnzuzeigendeArtikelgruppen + 1 + iAnzuzeigendeMaschinengruppen + 1; // ------------------------------------------------------------------ // ----- // Dto initialisieren // ------------------------------------------------------------------ // ----- kapDto = new KapazitaetsvorschauDto(iAnzahlZeilen, iParamZeitraum); // ------------------------------------------------------------------ // ----- // Beschriftung der x-Achse ermitteln. das sind die Kalenderwochen // ------------------------------------------------------------------ // ----- HashMap<Integer, Integer> hmKWIndizes = new HashMap<Integer, Integer>(); String[] kw = new String[iParamZeitraum]; GregorianCalendar gc = new GregorianCalendar(); for (int i = 0; i < kw.length; i++) { int iKw = gc.get(GregorianCalendar.WEEK_OF_YEAR); kw[i] = "" + iKw; kapDto.setISpaltenueberschrift(i, kw[i]); hmKWIndizes.put(gc.get(GregorianCalendar.WEEK_OF_YEAR), i); gc.setTimeInMillis(gc.getTimeInMillis() + 7 * 24 * 60 * 60 * 1000); // 1 Woche dazu } // ------------------------------------------------------------------ // ----- // Beschriftung der y-Achse ermitteln. das sind die Namen der // Vatergruppen bzw. 2 x "Sonstige". // Weiters werden die Indizes im Daten-Array fuer die jeweiligen // Gruppen festgelegt. // ------------------------------------------------------------------ // ----- String sSonstige = getTextRespectUISpr("lp.sonstige", theClientDto.getMandant(), theClientDto.getLocUi()); HashMap<Integer, Integer> hmArtikelGruppenIndizes = new HashMap<Integer, Integer>(); HashMap<Integer, Integer> hmMaschinenGruppenIndizes = new HashMap<Integer, Integer>(); // zuerst die Artikelvatergruppen for (int i = 0; i < iAnzuzeigendeArtikelgruppen; i++) { FLRArtikelgruppe item = (FLRArtikelgruppe) listArtikelgruppen.get(i); kapDto.setIZeilenueberschrift(i, item.getC_nr()); hmArtikelGruppenIndizes.put(item.getI_id(), i); } // Dann Sonstige Artikelgruppen final int indexSonstigeArtikelGruppen = iAnzuzeigendeArtikelgruppen; kapDto.setIZeilenueberschrift(indexSonstigeArtikelGruppen, sSonstige); // Maschinengruppen for (int i = 0; i < iAnzuzeigendeMaschinengruppen; i++) { FLRMaschinengruppe item = (FLRMaschinengruppe) listMaschinengruppen.get(i); int index = iAnzuzeigendeArtikelgruppen + 1 + i; kapDto.setIZeilenueberschrift(index, item.getC_bez()); hmMaschinenGruppenIndizes.put(item.getI_id(), index); } // zuletzt Sonstige Maschinengruppen final int indexSonstigeMaschinenGruppen = iAnzuzeigendeArtikelgruppen + 1 + iAnzuzeigendeMaschinengruppen; kapDto.setIZeilenueberschrift(indexSonstigeMaschinenGruppen, sSonstige); // ------------------------------------------------------------------ // ----- // Lose holen // ------------------------------------------------------------------ // ----- Criteria cLose = session.createCriteria(FLRLos.class); // Filter nach Mandant cLose.add(Restrictions.eq(FertigungFac.FLR_LOS_MANDANT_C_NR, theClientDto.getMandant())); // Alle Stati ausser Erledigt, Gestoppt, Storniert Collection<String> cLoseStati = new LinkedList<String>(); cLoseStati.add(FertigungFac.STATUS_ERLEDIGT); cLoseStati.add(FertigungFac.STATUS_GESTOPPT); cLoseStati.add(FertigungFac.STATUS_STORNIERT); cLose.add(Restrictions.not(Restrictions.in(FertigungFac.FLR_LOS_STATUS_C_NR, cLoseStati))); List<?> listLose = cLose.list(); // ------------------------------------------------------------------ // ----- // Auswertungszeitraum und verfuegbare Kapazitaeten ermitteln // ------------------------------------------------------------------ // ----- // 3 Monate in die zukunft Calendar c = Calendar.getInstance(); c.setTimeInMillis(System.currentTimeMillis()); c.set(Calendar.MONTH, c.get(Calendar.MONTH) + 3); java.util.Date dMax = Helper.cutDate(new java.sql.Date(c.getTimeInMillis())); java.sql.Timestamp tVon = Helper.cutTimestamp(new java.sql.Timestamp(System.currentTimeMillis())); java.sql.Timestamp tBis = Helper.cutTimestamp(new java.sql.Timestamp(dMax.getTime())); // Verfuegbare Zeiten holen SollverfuegbarkeitDto[] oVerfuegbar = getZeiterfassungFac().getVerfuegbareSollzeit(tVon, tBis, theClientDto); // diese nun aufteilen for (int i = 0; i < oVerfuegbar.length; i++) { SollverfuegbarkeitDto svDto = oVerfuegbar[i]; // "normale" AZ if (svDto.isBMannarbeitszeit()) { // die sind einer Artikelgruppe zugeordnet if (svDto.getIGruppeid() != null) { Integer iZeile = hmArtikelGruppenIndizes.get(svDto.getIGruppeid()); // ist das eine sichtbare Gruppe if (iZeile != null) { for (int iSpalte = 0; iSpalte < kapDto.getDetails()[iZeile].length; iSpalte++) { // mal 5 Tage kapDto.addBdVerfuegbareStunden(iZeile, iSpalte, svDto.getNSollstunden().multiply(new BigDecimal(5))); } } // wenn nicht, dann zu den sonstigen else { for (int iSpalte = 0; iSpalte < kapDto .getDetails()[indexSonstigeArtikelGruppen].length; iSpalte++) { // mal 5 Tage kapDto.addBdVerfuegbareStunden(indexSonstigeArtikelGruppen, iSpalte, svDto.getNSollstunden().multiply(new BigDecimal(5))); } } } // Rest = Sonstige Artikelgruppen else { if (svDto.getTDatum() != null) { // Die KW dieses Datums ermitteln, damit das // zugeordnet werden kann GregorianCalendar gcSV = new GregorianCalendar(); gcSV.setTime(svDto.getTDatum()); int kwSV = gcSV.get(Calendar.WEEK_OF_YEAR); Integer iIndexDerKW = hmKWIndizes.get(kwSV); if (iIndexDerKW != null) { // Hier nicht mit 5 multiplizieren, da es fuer // jeden Tag einen eigenen Eintrag gibt kapDto.addBdVerfuegbareStunden(indexSonstigeArtikelGruppen, iIndexDerKW, svDto.getNSollstunden()); } else { // diese KW wird nicht mehr angezeigt - brauch // ich nicht einrechnen } } } } // Maschinenzeit - die Verfuegbarkeit ist jeden Tag gleich else { Integer iZeile = hmMaschinenGruppenIndizes.get(svDto.getIGruppeid()); // ist das eine sichtbare Gruppe if (iZeile != null) { for (int iSpalte = 0; iSpalte < kapDto.getDetails()[iZeile].length; iSpalte++) { // mal 5 Tage kapDto.addBdVerfuegbareStunden(iZeile, iSpalte, svDto.getNSollstunden().multiply(new BigDecimal(5))); } } // wenn nicht, dann zu den sonstigen else { for (int iSpalte = 0; iSpalte < kapDto .getDetails()[indexSonstigeMaschinenGruppen].length; iSpalte++) { // mal 5 Tage kapDto.addBdVerfuegbareStunden(indexSonstigeMaschinenGruppen, iSpalte, svDto.getNSollstunden().multiply(new BigDecimal(5))); } } } } // ------------------------------------------------------------------ // ----- // Offene Zeiten ermitteln // ------------------------------------------------------------------ // ----- for (Iterator<?> iter = listLose.iterator(); iter.hasNext();) { FLRLos los = (FLRLos) iter.next(); // Offene Menge ermitteln BigDecimal bdOffen = los.getN_losgroesse(); for (Iterator<?> iterAblieferung = los.getAblieferungset().iterator(); iterAblieferung.hasNext();) { FLRLosablieferung item = (FLRLosablieferung) iterAblieferung.next(); bdOffen = bdOffen.subtract(item.getN_menge()); } // nur Lose mit tatsaechlich offener Menge>0 if (bdOffen.compareTo(new BigDecimal(0)) > 0) { // Faktor zur Berechnung der offenen Zeiten = offene Menge / // Losgroesse. 2 Nachkommastellen sollten reichen. BigDecimal bdFaktor = bdOffen.divide(los.getN_losgroesse(), 2, BigDecimal.ROUND_HALF_EVEN); // Arbeitsplan holen Criteria cLosAZ = session.createCriteria(FLRLossollarbeitsplan.class); cLosAZ.add(Restrictions.eq(FertigungFac.FLR_LOSSOLLARBEITSPLAN_LOS_I_ID, los.getI_id())); List<?> listLosAZ = cLosAZ.list(); // fuer alle Taetigkeiten for (Iterator<?> iterAZ = listLosAZ.iterator(); iterAZ.hasNext();) { FLRLossollarbeitsplan losAZ = (FLRLossollarbeitsplan) iterAZ.next(); BigDecimal bdOffeneStunden = losAZ.getN_gesamtzeit().multiply(bdFaktor); // ------------------------------------------------------ // ----------------- // Index der Gruppe bestimmen, der ich das zuordnen muss // ------------------------------------------------------ // ----------------- int iZeilenIndex; // 1. nach Maschinengruppe // 2. nach Artikelgruppe der Taetigkeit FLRMaschine flrMaschine = losAZ.getFlrmaschine(); Integer iMaschinengruppeIId = null; Integer iArtikelgruppeIId = null; if (flrMaschine != null) { FLRMaschinengruppe flrMaschinengruppe = flrMaschine.getFlrmaschinengruppe(); if (flrMaschinengruppe != null) { // Wenn diese Maschinengruppe dargestellt wird, // dann kommt hier der index raus. Integer i = hmMaschinenGruppenIndizes.get(flrMaschinengruppe.getI_id()); iMaschinengruppeIId = flrMaschinengruppe.getI_id(); if (i != null) { iZeilenIndex = i; } // wenn nicht -> sonstige. else { iZeilenIndex = indexSonstigeMaschinenGruppen; } } // Maschinen ohne Maschinengruppe werden nach // "Sonstige" verdichtet. else { iZeilenIndex = indexSonstigeMaschinenGruppen; } } else { FLRArtikel flrArtikel = losAZ.getFlrartikel(); FLRArtikelgruppe flrArtikelgruppe = flrArtikel.getFlrartikelgruppe(); if (flrArtikelgruppe != null) { // Wenn diese Artikelgruppe dargestellt wird, // dann kommt hier der index raus. Integer i = hmArtikelGruppenIndizes.get(flrArtikelgruppe.getI_id()); iArtikelgruppeIId = flrArtikelgruppe.getI_id(); if (i != null) { iZeilenIndex = i; } // wenn nicht -> sonstige. else { iZeilenIndex = indexSonstigeArtikelGruppen; } } // Taetigkeiten ohne Artikelgruppe werden nach // "Sonstige" verdichtet. else { iZeilenIndex = indexSonstigeArtikelGruppen; } } // ------------------------------------------------------ // ----------------- // Jetzt hab ich die Gruppe, der ich das zuordnen muss // nun muss die Zeit aufgeteilt werden // ------------------------------------------------------ // ----------------- java.util.Date tLosStarttermin = los.getT_produktionsbeginn(); java.util.Date tLosEndetermin = los.getT_produktionsende(); // beide Termine duerfen nicht vor heute liegen if (tLosStarttermin.before(getDate())) { tLosStarttermin = getDate(); } if (tLosEndetermin.before(getDate())) { tLosEndetermin = getDate(); } // Anzahl der betroffenen Kalenderwochen bestimmen GregorianCalendar gcStart = new GregorianCalendar(); gcStart.setTime(tLosStarttermin); GregorianCalendar gcEnde = new GregorianCalendar(); gcEnde.setTime(tLosEndetermin); int iStartKW = gcStart.get(Calendar.WEEK_OF_YEAR); int iEndeKW = gcEnde.get(Calendar.WEEK_OF_YEAR); int iAnzahlKW = 1 + iEndeKW - iStartKW; // nun auf die Wochen aufteilen BigDecimal bdOffeneStundenJeWoche = bdOffeneStunden; if (iAnzahlKW > 0) { bdOffeneStundenJeWoche = bdOffeneStunden.divide(new BigDecimal(iAnzahlKW), 2, RoundingMode.HALF_UP); } for (int iAktuelleKW = iStartKW; iAktuelleKW <= iEndeKW; iAktuelleKW++) { Integer indexDerKW = hmKWIndizes.get(iAktuelleKW); // wird diese Woche auch angezeigt? if (indexDerKW != null) { KapazitaetsvorschauDetailDto detailDto = new KapazitaetsvorschauDetailDto(); detailDto.setArtikelgruppeIId(iArtikelgruppeIId); detailDto.setArtikelIIdTaetigkeit(losAZ.getFlrartikel().getI_id()); detailDto.setBdDauer(bdOffeneStundenJeWoche); detailDto.setLosIId(los.getI_id()); detailDto.setLossollarbeitsplanIId(losAZ.getI_id()); detailDto.setMaschinengruppeIId(iMaschinengruppeIId); kapDto.addDetail(iZeilenIndex, indexDerKW, detailDto); } } } } } // ------------------------------------------------------------------ // ----- // Diagramm aus den Daten erstellen // ------------------------------------------------------------------ // ----- SymbolAxis xAchse = new SymbolAxis("KW", kw); CombinedDomainXYPlot plot = new CombinedDomainXYPlot(xAchse); for (int iZeile = 0; iZeile < kapDto.getDetails().length; iZeile++) { XYSeries datenZeile = new XYSeries(kapDto.getIZeilenueberschrift(iZeile)); // Balkenfarben festlegen ( >100% = rot, sonst hellgrau) // fuer jede zeile und jede spalte Paint[][] paints = new Paint[1][kapDto.getDetails()[iZeile].length]; for (int iSpalte = 0; iSpalte < kapDto.getDetails()[iZeile].length; iSpalte++) { BigDecimal bdVerfuegbar = kapDto.getBdVerfuegbareStunden()[iZeile][iSpalte]; BigDecimal bdBenoetigt = new BigDecimal(0); // Benoetigte Zeit jet Gruppe je Woche ermitteln for (Iterator<?> iter = kapDto.getDetails()[iZeile][iSpalte].iterator(); iter.hasNext();) { KapazitaetsvorschauDetailDto item = (KapazitaetsvorschauDetailDto) iter.next(); bdBenoetigt = bdBenoetigt.add(item.getBdDauer()); } BigDecimal value = new BigDecimal(0); if (bdVerfuegbar.compareTo(new BigDecimal(0)) > 0) { value = (bdBenoetigt.multiply(new BigDecimal(100))).divide(bdVerfuegbar, 4, BigDecimal.ROUND_HALF_EVEN); if (value.doubleValue() > 100.0) { paints[0][iSpalte] = Color.red; } else { paints[0][iSpalte] = Color.lightGray; } } // tage ohne Verfuegbarkeit mach ich 100% und weisz else { value = new BigDecimal(100.0); // Wochen ohne Kapazitaet aber mit geplanter Zeit if (bdBenoetigt.compareTo(new BigDecimal(0)) > 0) { paints[0][iSpalte] = Color.MAGENTA; } // Wenn nichts verfuegbar aber auch nichts benoetigt -> // weiss else { paints[0][iSpalte] = Color.white; } } XYDataItem data = new XYDataItem(iSpalte, value.doubleValue()); datenZeile.add(data); } // Zur Collection XYSeriesCollection xyDataset = new XYSeriesCollection(); xyDataset.addSeries(datenZeile); // subplot erstellen XYItemRenderer renderer1 = new CustomXYBarRenderer(paints); // renderer1.setItemLabelsVisible(true); // Legende nicht anzeigen renderer1.setBaseSeriesVisibleInLegend(false); NumberAxis zeilenAchse = new NumberAxis(kapDto.getIZeilenueberschrift(iZeile)); // Beschriftung der Y-Achse um 90 grad drehen zeilenAchse.setLabelAngle(Math.PI / 2.0); zeilenAchse.setAutoRange(true); XYPlot subplot1 = new XYPlot(xyDataset, null, zeilenAchse, renderer1); subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); // Markierung bei 100% final Marker target = new ValueMarker(100.0); target.setPaint(Color.darkGray); // target.setLabel("100 %"); // Label // target.setLabelAnchor(RectangleAnchor.TOP_RIGHT); // target.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT); subplot1.addRangeMarker(target); plot.add(subplot1); // plot.add(subplot1, 1); } JFreeChart lStackedBarChart = new JFreeChart(plot); kapDto.setJfcKapazitaetsvorschau(lStackedBarChart); } catch (RemoteException ex) { throwEJBExceptionLPRespectOld(ex); } finally { if (session != null) { session.close(); } } return kapDto; }
From source file:gov.noaa.pfel.erddap.dataset.EDDTableFromNcFiles.java
/** *//*from w w w .j a va 2 s.c o m*/ public static void testNow() throws Throwable { String2.log("\n*** EDDTableFromNcFiles.testNow"); EDDTable tedd = (EDDTable) oneFromDatasetsXml(null, "ndbcSosWaves"); //has very recent data //these query tests need a dataset that has recent data (or request is rejected) //these tests moved here 2014-01-23 GregorianCalendar gc = Calendar2.newGCalendarZulu(); gc.set(Calendar2.MILLISECOND, 0); gc.add(Calendar2.SECOND, 1); //now it is "now" long nowMillis = gc.getTimeInMillis(); String s; StringArray rv = new StringArray(); StringArray cv = new StringArray(); StringArray co = new StringArray(); StringArray cv2 = new StringArray(); gc = Calendar2.newGCalendarZulu(nowMillis); String2.log("now = " + Calendar2.formatAsISODateTimeT3(gc)); //non-regex EDVTimeStamp conValues will be ""+epochSeconds tedd.parseUserDapQuery("time&time=now", rv, cv, co, cv2, false); Test.ensureEqual(rv.toString(), "time", ""); Test.ensureEqual(cv.toString(), "time", ""); Test.ensureEqual(co.toString(), "=", ""); Test.ensureEqual(cv2.toString(), "" + Calendar2.gcToEpochSeconds(gc), ""); gc = Calendar2.newGCalendarZulu(nowMillis); gc.add(Calendar2.SECOND, -1); String2.log("now-1second = " + Calendar2.formatAsISODateTimeT3(gc)); //non-regex EDVTimeStamp conValues will be ""+epochSeconds tedd.parseUserDapQuery("time&time=now-1second", rv, cv, co, cv2, false); Test.ensureEqual(rv.toString(), "time", ""); Test.ensureEqual(cv.toString(), "time", ""); Test.ensureEqual(co.toString(), "=", ""); Test.ensureEqual(cv2.toString(), "" + Calendar2.gcToEpochSeconds(gc), ""); gc = Calendar2.newGCalendarZulu(nowMillis); gc.add(Calendar2.SECOND, 2); String2.log("now+2seconds = " + Calendar2.formatAsISODateTimeT3(gc)); //non-regex EDVTimeStamp conValues will be ""+epochSeconds tedd.parseUserDapQuery("time&time=now%2B2seconds", rv, cv, co, cv2, false); Test.ensureEqual(cv2.toString(), "" + Calendar2.gcToEpochSeconds(gc), ""); //non-%encoded '+' will be decoded as ' ', so treat ' ' as equal to '+' gc = Calendar2.newGCalendarZulu(nowMillis); gc.add(Calendar2.SECOND, 2); String2.log("now 2seconds = " + Calendar2.formatAsISODateTimeT3(gc)); //non-regex EDVTimeStamp conValues will be ""+epochSeconds tedd.parseUserDapQuery("time&time=now 2seconds", rv, cv, co, cv2, false); Test.ensureEqual(cv2.toString(), "" + Calendar2.gcToEpochSeconds(gc), ""); gc = Calendar2.newGCalendarZulu(nowMillis); gc.add(Calendar2.MINUTE, -3); String2.log("now-3minutes = " + Calendar2.formatAsISODateTimeT3(gc)); //non-regex EDVTimeStamp conValues will be ""+epochSeconds tedd.parseUserDapQuery("time&time=now-3minutes", rv, cv, co, cv2, false); Test.ensureEqual(cv2.toString(), "" + Calendar2.gcToEpochSeconds(gc), ""); gc = Calendar2.newGCalendarZulu(nowMillis); gc.add(Calendar2.HOUR_OF_DAY, -4); String2.log("now-4hours = " + Calendar2.formatAsISODateTimeT3(gc)); //non-regex EDVTimeStamp conValues will be ""+epochSeconds tedd.parseUserDapQuery("time&time=now-4hours", rv, cv, co, cv2, false); Test.ensureEqual(cv2.toString(), "" + Calendar2.gcToEpochSeconds(gc), ""); gc = Calendar2.newGCalendarZulu(nowMillis); gc.add(Calendar2.DATE, -5); String2.log("now-5days = " + Calendar2.formatAsISODateTimeT3(gc)); //non-regex EDVTimeStamp conValues will be ""+epochSeconds tedd.parseUserDapQuery("time&time=now-5days", rv, cv, co, cv2, false); Test.ensureEqual(cv2.toString(), "" + Calendar2.gcToEpochSeconds(gc), ""); gc = Calendar2.newGCalendarZulu(nowMillis); gc.add(Calendar2.MONTH, -6); String2.log("now-6months = " + Calendar2.formatAsISODateTimeT3(gc)); //non-regex EDVTimeStamp conValues will be ""+epochSeconds tedd.parseUserDapQuery("time&time=now-6months", rv, cv, co, cv2, false); Test.ensureEqual(cv2.toString(), "" + Calendar2.gcToEpochSeconds(gc), ""); gc = Calendar2.newGCalendarZulu(nowMillis); gc.add(Calendar2.YEAR, -2); String2.log("now-7years = " + Calendar2.formatAsISODateTimeT3(gc)); //non-regex EDVTimeStamp conValues will be ""+epochSeconds tedd.parseUserDapQuery("time&time=now-2years", rv, cv, co, cv2, false); Test.ensureEqual(cv2.toString(), "" + Calendar2.gcToEpochSeconds(gc), ""); //if (true) throw new RuntimeException("stop here"); }
From source file:org.sakaiproject.assignment.impl.BaseAssignmentService.java
public Map<String, String> transferCopyEntitiesRefMigrator(String fromContext, String toContext, List resourceIds) {//from w ww .j av a 2 s . c o m Map<String, String> transversalMap = new HashMap<String, String>(); // import Assignment objects Iterator oAssignments = getAssignmentsForContext(fromContext); while (oAssignments.hasNext()) { Assignment oAssignment = (Assignment) oAssignments.next(); String oAssignmentId = oAssignment.getId(); boolean toBeImported = true; if (resourceIds != null && resourceIds.size() > 0) { // if there is a list for import assignments, only import those assignments and relative submissions toBeImported = false; for (int m = 0; m < resourceIds.size() && !toBeImported; m++) { if (((String) resourceIds.get(m)).equals(oAssignmentId)) { toBeImported = true; } } } if (toBeImported) { AssignmentEdit nAssignment = null; AssignmentContentEdit nContent = null; if (!m_assignmentStorage.check(oAssignmentId)) { } else { try { // add new Assignment content String oContentReference = oAssignment.getContentReference(); String oContentId = contentId(oContentReference); if (!m_contentStorage.check(oContentId)) throw new IdUnusedException(oContentId); else { AssignmentContent oContent = getAssignmentContent(oContentReference); nContent = addAssignmentContent(toContext); // attributes nContent.setAllowAttachments(oContent.getAllowAttachments()); nContent.setContext(toContext); nContent.setGroupProject(oContent.getGroupProject()); nContent.setHonorPledge(oContent.getHonorPledge()); nContent.setHideDueDate(oContent.getHideDueDate()); nContent.setIndividuallyGraded(oContent.individuallyGraded()); // replace all occurrence of old context with new context inside instruction text String instructions = oContent.getInstructions(); if (instructions.indexOf(fromContext) != -1) { instructions = instructions.replaceAll(fromContext, toContext); } nContent.setInstructions(instructions); nContent.setMaxGradePoint(oContent.getMaxGradePoint()); nContent.setFactor(oContent.getFactor()); nContent.setReleaseGrades(oContent.releaseGrades()); nContent.setTimeLastModified(oContent.getTimeLastModified()); nContent.setTitle(oContent.getTitle()); nContent.setTypeOfGrade(oContent.getTypeOfGrade()); nContent.setTypeOfSubmission(oContent.getTypeOfSubmission()); // review service nContent.setAllowReviewService(oContent.getAllowReviewService()); // properties ResourcePropertiesEdit p = nContent.getPropertiesEdit(); p.clear(); p.addAll(oContent.getProperties()); // update live properties addLiveProperties(p); // attachment List oAttachments = oContent.getAttachments(); List nAttachments = m_entityManager.newReferenceList(); for (int n = 0; n < oAttachments.size(); n++) { Reference oAttachmentRef = (Reference) oAttachments.get(n); String oAttachmentId = ((Reference) oAttachments.get(n)).getId(); if (oAttachmentId.indexOf(fromContext) != -1) { // transfer attachment, replace the context string and add new attachment if necessary transferAttachment(fromContext, toContext, nAttachments, oAttachmentId); } else { nAttachments.add(oAttachmentRef); } } nContent.replaceAttachments(nAttachments); // complete the edit m_contentStorage.commit(nContent); ((BaseAssignmentContentEdit) nContent).closeEdit(); } } catch (Exception e) { if (M_log.isWarnEnabled()) M_log.warn(" transferCopyEntities " + e.toString() + " oAssignmentId=" + oAssignmentId); } if (nContent != null) { try { // add new assignment nAssignment = addAssignment(toContext); // attribute nAssignment.setCloseTime(oAssignment.getCloseTime()); nAssignment.setContentReference(nContent.getReference()); nAssignment.setContext(toContext); // when importing, refer to property to determine draft status if ("false".equalsIgnoreCase( m_serverConfigurationService.getString("import.importAsDraft"))) { nAssignment.setDraft(oAssignment.getDraft()); } else { nAssignment.setDraft(true); } nAssignment.setGroup(oAssignment.isGroup()); nAssignment.setDropDeadTime(oAssignment.getDropDeadTime()); nAssignment.setDueTime(oAssignment.getDueTime()); nAssignment.setOpenTime(oAssignment.getOpenTime()); nAssignment.setSection(oAssignment.getSection()); nAssignment.setTitle(oAssignment.getTitle()); nAssignment.setPosition_order(oAssignment.getPosition_order()); nAssignment.setAllowPeerAssessment(nAssignment.getAllowPeerAssessment()); nAssignment.setPeerAssessmentAnonEval(oAssignment.getPeerAssessmentAnonEval()); nAssignment.setPeerAssessmentInstructions(oAssignment.getPeerAssessmentInstructions()); nAssignment.setPeerAssessmentNumReviews(oAssignment.getPeerAssessmentNumReviews()); nAssignment.setPeerAssessmentStudentViewReviews( oAssignment.getPeerAssessmentStudentViewReviews()); nAssignment.setPeerAssessmentPeriod(oAssignment.getPeerAssessmentPeriod()); if (nAssignment.getPeerAssessmentPeriod() == null && nAssignment.getCloseTime() != null) { // set the peer period time to be 10 mins after accept until date GregorianCalendar c = new GregorianCalendar(); c.setTimeInMillis(nAssignment.getCloseTime().getTime()); c.add(GregorianCalendar.MINUTE, 10); nAssignment.setPeerAssessmentPeriod(TimeService.newTime(c.getTimeInMillis())); } // properties ResourcePropertiesEdit p = nAssignment.getPropertiesEdit(); p.clear(); p.addAll(oAssignment.getProperties()); // one more touch on the gradebook-integration link String associatedGradebookAssignment = StringUtils .trimToNull(p.getProperty(PROP_ASSIGNMENT_ASSOCIATE_GRADEBOOK_ASSIGNMENT)); if (associatedGradebookAssignment != null) { // see if the old assignment's associated gradebook item is an internal gradebook entry or externally defined boolean isExternalAssignmentDefined = m_gradebookExternalAssessmentService .isExternalAssignmentDefined(oAssignment.getContent().getContext(), associatedGradebookAssignment); if (isExternalAssignmentDefined) { // if this is an external defined (came from assignment) // mark the link as "add to gradebook" for the new imported assignment, since the assignment is still of draft state //later when user posts the assignment, the corresponding assignment will be created in gradebook. p.removeProperty(PROP_ASSIGNMENT_ASSOCIATE_GRADEBOOK_ASSIGNMENT); p.addProperty(NEW_ASSIGNMENT_ADD_TO_GRADEBOOK, GRADEBOOK_INTEGRATION_ADD); } } // remove the link btw assignment and announcement item. One can announce the open date afterwards p.removeProperty(ResourceProperties.NEW_ASSIGNMENT_CHECK_AUTO_ANNOUNCE); p.removeProperty("new_assignment_open_date_announced"); p.removeProperty(ResourceProperties.PROP_ASSIGNMENT_OPENDATE_ANNOUNCEMENT_MESSAGE_ID); // remove the link btw assignment and calendar item. One can add the due date to calendar afterwards p.removeProperty(ResourceProperties.NEW_ASSIGNMENT_CHECK_ADD_DUE_DATE); p.removeProperty("new_assignment_due_date_scheduled"); p.removeProperty(ResourceProperties.PROP_ASSIGNMENT_DUEDATE_CALENDAR_EVENT_ID); // update live properties addLiveProperties(p); // complete the edit m_assignmentStorage.commit(nAssignment); ((BaseAssignmentEdit) nAssignment).closeEdit(); transversalMap.put("assignment/" + oAssignment.getId(), "assignment/" + nAssignment.getId()); M_log.info("old assignment id:" + oAssignment.getId() + " - new assignment id:" + nAssignment.getId()); try { if (m_taggingManager.isTaggable()) { for (TaggingProvider provider : m_taggingManager.getProviders()) { provider.transferCopyTags( m_assignmentActivityProducer.getActivity(oAssignment), m_assignmentActivityProducer.getActivity(nAssignment)); } } } catch (PermissionException pe) { M_log.error(this + " transferCopyEntities " + pe.toString() + " oAssignmentId=" + oAssignment.getId() + " nAssignmentId=" + nAssignment.getId()); } } catch (Exception ee) { M_log.error(this + " transferCopyEntities " + ee.toString() + " oAssignmentId=" + oAssignment.getId() + " nAssignmentId=" + nAssignment.getId()); } } } // if-else } // if } // for return transversalMap; }
From source file:org.sakaiproject.assignment.tool.AssignmentAction.java
/** * Action is to show the edit assignment screen *//*from w ww .j av a2s. c o m*/ public void doEdit_assignment(RunData data) { SessionState state = ((JetspeedRunData) data).getPortletSessionState(((JetspeedRunData) data).getJs_peid()); ParameterParser params = data.getParameters(); String assignmentId = StringUtils.trimToNull(params.getString("assignmentId")); if (AssignmentService.allowUpdateAssignment(assignmentId)) { Assignment a = getAssignment(assignmentId, "doEdit_assignment", state); if (a != null) { // whether the user can modify the assignment state.setAttribute(EDIT_ASSIGNMENT_ID, assignmentId); // for the non_electronice assignment, submissions are auto-generated by the time that assignment is created; // don't need to go through the following checkings. if (a.getContent().getTypeOfSubmission() != Assignment.NON_ELECTRONIC_ASSIGNMENT_SUBMISSION) { Iterator submissions = AssignmentService.getSubmissions(a).iterator(); if (submissions.hasNext()) { // any submitted? boolean anySubmitted = false; for (; submissions.hasNext() && !anySubmitted;) { AssignmentSubmission s = (AssignmentSubmission) submissions.next(); if (s.getSubmitted() && s.getTimeSubmitted() != null) { anySubmitted = true; } } // any draft submission boolean anyDraft = false; for (; submissions.hasNext() && !anyDraft;) { AssignmentSubmission s = (AssignmentSubmission) submissions.next(); if (!s.getSubmitted()) { anyDraft = true; } } if (anySubmitted) { // if there is any submitted submission to this assignment, show alert addAlert(state, rb.getFormattedMessage("hassum", new Object[] { a.getTitle() })); } if (anyDraft) { // otherwise, show alert about someone has started working on the assignment, not necessarily submitted addAlert(state, rb.getString("hasDraftSum")); } } } // SECTION MOD state.setAttribute(STATE_SECTION_STRING, a.getSection()); // put the names and values into vm file state.setAttribute(NEW_ASSIGNMENT_TITLE, a.getTitle()); state.setAttribute(NEW_ASSIGNMENT_ORDER, a.getPosition_order()); if (Boolean .valueOf(ServerConfigurationService.getBoolean("assignment.visible.date.enabled", false))) { putTimePropertiesInState(state, a.getVisibleTime(), NEW_ASSIGNMENT_VISIBLEMONTH, NEW_ASSIGNMENT_VISIBLEDAY, NEW_ASSIGNMENT_VISIBLEYEAR, NEW_ASSIGNMENT_VISIBLEHOUR, NEW_ASSIGNMENT_VISIBLEMIN); state.setAttribute(NEW_ASSIGNMENT_VISIBLETOGGLE, a.getVisibleTime() != null); } putTimePropertiesInState(state, a.getOpenTime(), NEW_ASSIGNMENT_OPENMONTH, NEW_ASSIGNMENT_OPENDAY, NEW_ASSIGNMENT_OPENYEAR, NEW_ASSIGNMENT_OPENHOUR, NEW_ASSIGNMENT_OPENMIN); // generate alert when editing an assignment past open date if (a.getOpenTime().before(TimeService.newTime())) { addAlert(state, rb.getString("youarenot20")); } putTimePropertiesInState(state, a.getDueTime(), NEW_ASSIGNMENT_DUEMONTH, NEW_ASSIGNMENT_DUEDAY, NEW_ASSIGNMENT_DUEYEAR, NEW_ASSIGNMENT_DUEHOUR, NEW_ASSIGNMENT_DUEMIN); // generate alert when editing an assignment past due date if (a.getDueTime().before(TimeService.newTime())) { addAlert(state, rb.getString("youarenot17")); } if (a.getCloseTime() != null) { state.setAttribute(NEW_ASSIGNMENT_ENABLECLOSEDATE, Boolean.valueOf(true)); putTimePropertiesInState(state, a.getCloseTime(), NEW_ASSIGNMENT_CLOSEMONTH, NEW_ASSIGNMENT_CLOSEDAY, NEW_ASSIGNMENT_CLOSEYEAR, NEW_ASSIGNMENT_CLOSEHOUR, NEW_ASSIGNMENT_CLOSEMIN); } else { state.setAttribute(NEW_ASSIGNMENT_ENABLECLOSEDATE, Boolean.valueOf(false)); state.setAttribute(NEW_ASSIGNMENT_CLOSEMONTH, state.getAttribute(NEW_ASSIGNMENT_DUEMONTH)); state.setAttribute(NEW_ASSIGNMENT_CLOSEDAY, state.getAttribute(NEW_ASSIGNMENT_DUEDAY)); state.setAttribute(NEW_ASSIGNMENT_CLOSEYEAR, state.getAttribute(NEW_ASSIGNMENT_DUEYEAR)); state.setAttribute(NEW_ASSIGNMENT_CLOSEHOUR, state.getAttribute(NEW_ASSIGNMENT_DUEHOUR)); state.setAttribute(NEW_ASSIGNMENT_CLOSEMIN, state.getAttribute(NEW_ASSIGNMENT_DUEMIN)); } state.setAttribute(NEW_ASSIGNMENT_SECTION, a.getSection()); state.setAttribute(NEW_ASSIGNMENT_SUBMISSION_TYPE, Integer.valueOf(a.getContent().getTypeOfSubmission())); state.setAttribute(NEW_ASSIGNMENT_CATEGORY, getAssignmentCategoryAsInt(a)); int typeOfGrade = a.getContent().getTypeOfGrade(); state.setAttribute(NEW_ASSIGNMENT_GRADE_TYPE, Integer.valueOf(typeOfGrade)); if (typeOfGrade == 3) { state.setAttribute(NEW_ASSIGNMENT_GRADE_POINTS, a.getContent().getMaxGradePointDisplay()); } state.setAttribute(NEW_ASSIGNMENT_DESCRIPTION, a.getContent().getInstructions()); state.setAttribute(NEW_ASSIGNMENT_CHECK_HIDE_DUE_DATE, Boolean.valueOf(a.getContent().getHideDueDate()).toString()); ResourceProperties properties = a.getProperties(); state.setAttribute(ResourceProperties.NEW_ASSIGNMENT_CHECK_ADD_DUE_DATE, properties.getProperty(ResourceProperties.NEW_ASSIGNMENT_CHECK_ADD_DUE_DATE)); state.setAttribute(ResourceProperties.NEW_ASSIGNMENT_CHECK_AUTO_ANNOUNCE, properties.getProperty(ResourceProperties.NEW_ASSIGNMENT_CHECK_AUTO_ANNOUNCE)); String defaultNotification = ServerConfigurationService .getString("announcement.default.notification", "n"); if (defaultNotification.equalsIgnoreCase("r")) { state.setAttribute(Assignment.ASSIGNMENT_OPENDATE_NOTIFICATION, Assignment.ASSIGNMENT_OPENDATE_NOTIFICATION_HIGH); } else if (defaultNotification.equalsIgnoreCase("o")) { state.setAttribute(Assignment.ASSIGNMENT_OPENDATE_NOTIFICATION, Assignment.ASSIGNMENT_OPENDATE_NOTIFICATION_LOW); } else { state.setAttribute(Assignment.ASSIGNMENT_OPENDATE_NOTIFICATION, Assignment.ASSIGNMENT_OPENDATE_NOTIFICATION_NONE); } state.setAttribute(NEW_ASSIGNMENT_CHECK_ADD_HONOR_PLEDGE, Integer.toString(a.getContent().getHonorPledge())); state.setAttribute(AssignmentService.NEW_ASSIGNMENT_ADD_TO_GRADEBOOK, properties.getProperty(AssignmentService.NEW_ASSIGNMENT_ADD_TO_GRADEBOOK)); state.setAttribute(AssignmentService.PROP_ASSIGNMENT_ASSOCIATE_GRADEBOOK_ASSIGNMENT, properties.getProperty(AssignmentService.PROP_ASSIGNMENT_ASSOCIATE_GRADEBOOK_ASSIGNMENT)); state.setAttribute(ATTACHMENTS, a.getContent().getAttachments()); // submission notification option if (properties.getProperty(Assignment.ASSIGNMENT_INSTRUCTOR_NOTIFICATIONS_VALUE) != null) { state.setAttribute(Assignment.ASSIGNMENT_INSTRUCTOR_NOTIFICATIONS_VALUE, properties.getProperty(Assignment.ASSIGNMENT_INSTRUCTOR_NOTIFICATIONS_VALUE)); } // release grade notification option if (properties.getProperty(Assignment.ASSIGNMENT_RELEASEGRADE_NOTIFICATION_VALUE) != null) { state.setAttribute(Assignment.ASSIGNMENT_RELEASEGRADE_NOTIFICATION_VALUE, properties.getProperty(Assignment.ASSIGNMENT_RELEASEGRADE_NOTIFICATION_VALUE)); } // group setting if (a.getAccess().equals(Assignment.AssignmentAccess.SITE)) { state.setAttribute(NEW_ASSIGNMENT_RANGE, "site"); } else { state.setAttribute(NEW_ASSIGNMENT_RANGE, "groups"); } // SAK-17606 state.setAttribute(NEW_ASSIGNMENT_CHECK_ANONYMOUS_GRADING, properties.getProperty(NEW_ASSIGNMENT_CHECK_ANONYMOUS_GRADING)); // put the resubmission option into state assignment_resubmission_option_into_state(a, null, state); // set whether we use peer assessment or not Time peerAssessmentPeriod = a.getPeerAssessmentPeriod(); //check if peer assessment time exist? if not, this could be an old assignment, so just set it //to 10 min after accept until date if (peerAssessmentPeriod == null && a.getCloseTime() != null) { // set the peer period time to be 10 mins after accept until date GregorianCalendar c = new GregorianCalendar(); c.setTimeInMillis(a.getCloseTime().getTime()); c.add(GregorianCalendar.MINUTE, 10); peerAssessmentPeriod = TimeService.newTime(c.getTimeInMillis()); } if (peerAssessmentPeriod != null) { state.setAttribute(NEW_ASSIGNMENT_USE_PEER_ASSESSMENT, Boolean.valueOf(a.getAllowPeerAssessment()).toString()); putTimePropertiesInState(state, peerAssessmentPeriod, NEW_ASSIGNMENT_PEERPERIODMONTH, NEW_ASSIGNMENT_PEERPERIODDAY, NEW_ASSIGNMENT_PEERPERIODYEAR, NEW_ASSIGNMENT_PEERPERIODHOUR, NEW_ASSIGNMENT_PEERPERIODMIN); state.setAttribute(NEW_ASSIGNMENT_PEER_ASSESSMENT_ANON_EVAL, Boolean.valueOf(a.getPeerAssessmentAnonEval()).toString()); state.setAttribute(NEW_ASSIGNMENT_PEER_ASSESSMENT_STUDENT_VIEW_REVIEWS, Boolean.valueOf(a.getPeerAssessmentStudentViewReviews()).toString()); state.setAttribute(NEW_ASSIGNMENT_PEER_ASSESSMENT_NUM_REVIEWS, a.getPeerAssessmentNumReviews()); state.setAttribute(NEW_ASSIGNMENT_PEER_ASSESSMENT_INSTRUCTIONS, a.getPeerAssessmentInstructions()); } if (!allowPeerAssessment) { state.setAttribute(NEW_ASSIGNMENT_USE_PEER_ASSESSMENT, false); } // set whether we use the review service or not state.setAttribute(NEW_ASSIGNMENT_USE_REVIEW_SERVICE, Boolean.valueOf(a.getContent().getAllowReviewService()).toString()); //set whether students can view the review service results state.setAttribute(NEW_ASSIGNMENT_ALLOW_STUDENT_VIEW, Boolean.valueOf(a.getContent().getAllowStudentViewReport()).toString()); state.setAttribute(NEW_ASSIGNMENT_REVIEW_SERVICE_SUBMIT_RADIO, a.getContent().getSubmitReviewRepo()); state.setAttribute(NEW_ASSIGNMENT_REVIEW_SERVICE_REPORT_RADIO, a.getContent().getGenerateOriginalityReport()); state.setAttribute(NEW_ASSIGNMENT_REVIEW_SERVICE_CHECK_TURNITIN, Boolean.valueOf(a.getContent().isCheckTurnitin()).toString()); state.setAttribute(NEW_ASSIGNMENT_REVIEW_SERVICE_CHECK_INTERNET, Boolean.valueOf(a.getContent().isCheckInternet()).toString()); state.setAttribute(NEW_ASSIGNMENT_REVIEW_SERVICE_CHECK_PUB, Boolean.valueOf(a.getContent().isCheckPublications()).toString()); state.setAttribute(NEW_ASSIGNMENT_REVIEW_SERVICE_CHECK_INSTITUTION, Boolean.valueOf(a.getContent().isCheckInstitution()).toString()); //exclude bibliographic state.setAttribute(NEW_ASSIGNMENT_REVIEW_SERVICE_EXCLUDE_BIBLIOGRAPHIC, Boolean.valueOf(a.getContent().isExcludeBibliographic()).toString()); //exclude quoted state.setAttribute(NEW_ASSIGNMENT_REVIEW_SERVICE_EXCLUDE_QUOTED, Boolean.valueOf(a.getContent().isExcludeQuoted()).toString()); //exclude type state.setAttribute(NEW_ASSIGNMENT_REVIEW_SERVICE_EXCLUDE_TYPE, a.getContent().getExcludeType()); //exclude value state.setAttribute(NEW_ASSIGNMENT_REVIEW_SERVICE_EXCLUDE_VALUE, a.getContent().getExcludeValue()); state.setAttribute(NEW_ASSIGNMENT_GROUPS, a.getGroups()); state.setAttribute(NEW_ASSIGNMENT_GROUP_SUBMIT, a.isGroup() ? "1" : "0"); // get all supplement item info into state setAssignmentSupplementItemInState(state, a); state.setAttribute(STATE_MODE, MODE_INSTRUCTOR_NEW_EDIT_ASSIGNMENT); } } else { addAlert(state, rb.getString("youarenot6")); } }