List of usage examples for java.util GregorianCalendar getTimeInMillis
public long getTimeInMillis()
From source file:com.lp.server.auftrag.ejbfac.AuftragFacBean.java
/** * Methode zum Erzeugen eines neues Auftrags als Kopie eines bestehenden * Auftrags. <br>// w w w . j a v a 2 s.co m * Es werden auch die Positionen kopiert. * * @param iIdAuftragI * PK des bestehenden Auftrags * @param theClientDto * der aktuelle Benutzer * @return Integer PK des neuen Auftrags * @throws EJBExceptionLP * Ausnahme */ public Integer erzeugeAuftragAusAuftrag(Integer iIdAuftragI, TheClientDto theClientDto) throws EJBExceptionLP { checkAuftragIId(iIdAuftragI); AuftragDto auftragBasisDto = getAuftragFac().auftragFindByPrimaryKey(iIdAuftragI); Integer iIdAuftragKopie = null; try { GregorianCalendar calendar = new GregorianCalendar(); AuftragDto auftragDto = (AuftragDto) auftragBasisDto.clone(); auftragDto.setFWechselkursmandantwaehrungzubelegwaehrung( new Double(getLocaleFac().getWechselkurs2(theClientDto.getSMandantenwaehrung(), auftragDto.getCAuftragswaehrung(), theClientDto).doubleValue())); ParametermandantDto parametermandantLieferzeitDto = getParameterFac().getMandantparameter( theClientDto.getMandant(), ParameterFac.KATEGORIE_AUFTRAG, ParameterFac.PARAMETER_DEFAULT_LIEFERZEIT_AUFTRAG); int defaultLieferzeitAuftrag = ((Integer) parametermandantLieferzeitDto.getCWertAsObject()).intValue(); calendar = new GregorianCalendar(); calendar.add(Calendar.DATE, defaultLieferzeitAuftrag); Timestamp aktuelleDatumPlusLieferZeit = new Timestamp(calendar.getTimeInMillis()); ParametermandantDto parametermandantLieferdatumDto = getParameterFac().getMandantparameter( theClientDto.getMandant(), ParameterFac.KATEGORIE_AUFTRAG, ParameterFac.PARAMETER_AUFTRAG_KOPIEREN_LIEFERDATUM_UEBERNEHMEN); if ((Boolean) parametermandantLieferdatumDto.getCWertAsObject()) { auftragDto.setDLiefertermin(auftragBasisDto.getDLiefertermin()); auftragDto.setDFinaltermin(auftragBasisDto.getDLiefertermin()); } else { auftragDto.setDLiefertermin(aktuelleDatumPlusLieferZeit); auftragDto.setDFinaltermin(aktuelleDatumPlusLieferZeit); } auftragDto.setDBestelldatum(new java.sql.Timestamp(System.currentTimeMillis())); iIdAuftragKopie = createAuftrag(auftragDto, theClientDto); // PJ 15507 Auftragdokumente kopieren AuftragauftragdokumentDto[] auftragauftragdokumentDtos = getAuftragServiceFac() .auftragauftragdokumentFindByAuftragIId(iIdAuftragI); if (auftragauftragdokumentDtos != null && auftragauftragdokumentDtos.length > 0) { ArrayList<AuftragdokumentDto> al = new ArrayList<AuftragdokumentDto>(); for (int i = 0; i < auftragauftragdokumentDtos.length; i++) { AuftragdokumentDto dto = new AuftragdokumentDto(); dto.setIId(auftragauftragdokumentDtos[i].getAuftragdokumentIId()); al.add(dto); } getAuftragServiceFac().updateAuftragdokumente(iIdAuftragKopie, al); } // alle Positionen kopieren AuftragpositionDto[] aAuftragpositionBasis = getAuftragpositionFac() .auftragpositionFindByAuftrag(iIdAuftragI); Integer positionIId = null; Integer positionIIdSet = null; for (int i = 0; i < aAuftragpositionBasis.length; i++) { AuftragpositionDto auftragpositionDto = (AuftragpositionDto) aAuftragpositionBasis[i].clone(); if (auftragBasisDto.getAuftragartCNr().equals(AuftragServiceFac.AUFTRAGART_ABRUF)) { auftragpositionDto.setAuftragpositionIIdRahmenposition( aAuftragpositionBasis[i].getAuftragpositionIIdRahmenposition()); } // Wenn sich sie MWST seither geaendert hat if (auftragpositionDto.getMwstsatzIId() != null) { MwstsatzDto mwstsatzDto = getMandantFac() .mwstsatzFindByPrimaryKey(auftragpositionDto.getMwstsatzIId(), theClientDto); mwstsatzDto = getMandantFac().mwstsatzFindByMwstsatzbezIIdAktuellster( mwstsatzDto.getIIMwstsatzbezId(), theClientDto); BigDecimal mwstBetrag = Helper.getProzentWert(auftragpositionDto.getNNettoeinzelpreis(), new BigDecimal(mwstsatzDto.getFMwstsatz()), 4); auftragpositionDto.setMwstsatzIId(mwstsatzDto.getIId()); auftragpositionDto.setNMwstbetrag(mwstBetrag); auftragpositionDto .setNBruttoeinzelpreis(auftragpositionDto.getNNettoeinzelpreis().add(mwstBetrag)); } if (aAuftragpositionBasis[i].getPositioniIdArtikelset() != null) { auftragpositionDto.setPositioniIdArtikelset(positionIIdSet); } auftragpositionDto.setBelegIId(iIdAuftragKopie); if ((Boolean) parametermandantLieferdatumDto.getCWertAsObject()) { auftragpositionDto.setTUebersteuerbarerLiefertermin(auftragBasisDto.getDLiefertermin()); } else { auftragpositionDto.setTUebersteuerbarerLiefertermin(aktuelleDatumPlusLieferZeit); } if (auftragpositionDto.getTypCNr() != null) { if (auftragpositionDto.isPosition()) { if (auftragpositionDto.getCZusatzbez().equals(LocaleFac.POSITIONBEZ_BEGINN)) { positionIId = getAuftragpositionFac().createAuftragposition(auftragpositionDto, false, theClientDto); } else if (auftragpositionDto.getCZusatzbez().equals(LocaleFac.POSITIONBEZ_ENDE)) { getAuftragpositionFac().createAuftragposition(auftragpositionDto, false, theClientDto); } } else { auftragpositionDto.setPositioniId(positionIId); getAuftragpositionFac().createAuftragposition(auftragpositionDto, false, theClientDto); } } else { if (aAuftragpositionBasis[i].isIntelligenteZwischensumme()) { Integer von = getAuftragpositionFac() .getPositionNummer(aAuftragpositionBasis[i].getZwsVonPosition()); auftragpositionDto.setZwsVonPosition( getAuftragpositionFac().getPositionIIdFromPositionNummer(iIdAuftragKopie, von)); Integer bis = getAuftragpositionFac() .getPositionNummer(aAuftragpositionBasis[i].getZwsBisPosition()); auftragpositionDto.setZwsBisPosition( getAuftragpositionFac().getPositionIIdFromPositionNummer(iIdAuftragKopie, bis)); } if (auftragpositionDto.getPositioniIdArtikelset() == null) { positionIIdSet = getAuftragpositionFac().createAuftragposition(auftragpositionDto, false, theClientDto); } else { getAuftragpositionFac().createAuftragposition(auftragpositionDto, false, theClientDto); } } } // kopieren der Auftrageigenschaften PaneldatenDto[] aPaneldatenDtoBasis = getPanelFac() .paneldatenFindByPanelCNrCKey(PanelFac.PANEL_AUFTRAGSEIGENSCHAFTEN, iIdAuftragI.toString()); PaneldatenDto[] datenKorrigiert = new PaneldatenDto[aPaneldatenDtoBasis.length]; for (int y = 0; y < aPaneldatenDtoBasis.length; y++) { PaneldatenDto paneldatenDto = (PaneldatenDto) aPaneldatenDtoBasis[y].clone(); paneldatenDto.setCKey(iIdAuftragKopie.toString()); datenKorrigiert[y] = paneldatenDto; } if (datenKorrigiert != null) { getPanelFac().createPaneldaten(datenKorrigiert); } myLogger.exit("Der Auftrag wurde mit " + aAuftragpositionBasis.length + " Positionen erzeugt."); } catch (RemoteException ex) { throwEJBExceptionLPRespectOld(ex); } return iIdAuftragKopie; }
From source file:org.eevolution.form.VSCRP.java
public CategoryDataset createDataset(Timestamp start, MResource r) { //System.out.println("Create new data set"); GregorianCalendar gc1 = new GregorianCalendar(); gc1.setTimeInMillis(start.getTime()); gc1.clear(Calendar.MILLISECOND); gc1.clear(Calendar.SECOND);// w ww . j a va 2 s . c om gc1.clear(Calendar.MINUTE); gc1.clear(Calendar.HOUR_OF_DAY); Timestamp date = start; String namecapacity = Msg.translate(Env.getCtx(), "Capacity"); System.out.println("\n Namecapacity :" + namecapacity); String nameload = Msg.translate(Env.getCtx(), "Load"); System.out.println("\n Nameload :" + nameload); String namesummary = Msg.translate(Env.getCtx(), "Summary"); System.out.println("\n Namesummary :" + namesummary); MResourceType t = new MResourceType(Env.getCtx(), r.getS_ResourceType_ID(), null); System.out.println("\n Resourcetype " + t); int days = 1; long hours = 0; if (t.isTimeSlot()) { hours = MMPCMRP.getHoursAvailable(t.getTimeSlotStart(), t.getTimeSlotEnd()); } else { //fjviejo e-evolution MachineQty if (r.getDailyCapacity().multiply(r.getMachineQty()).compareTo(Env.ZERO) != 0) hours = r.getDailyCapacity().multiply(r.getMachineQty()).longValue(); else //fjviejo e-evolution end hours = 24; } DefaultCategoryDataset dataset = new DefaultCategoryDataset(); // Long Hours = new Long(hours); int C_UOM_ID = DB.getSQLValue(null, "SELECT C_UOM_ID FROM M_Product WHERE S_Resource_ID = ? ", r.getS_Resource_ID()); MUOM uom = new MUOM(Env.getCtx(), C_UOM_ID, null); System.out.println("\n uom1 " + uom + "\n"); //System.out.println("um.isHour()"+ uom.isHour() ); if (!uom.isHour()) { System.out.println("\n uom2 " + uom + "\n"); return dataset; } System.out.println("\n Dataset " + dataset + "\n"); int summary = 0; int secondsAcum = 0; long hoursAcum = 0; while (days < 29) { //System.out.println("Day Number" + days); String day = new String(new Integer(date.getDate()).toString()); System.out.println("r.getS_Resource_ID()" + r.getS_Resource_ID()); System.out.println("Date:" + date); int seconds = getLoad(r.getS_Resource_ID(), date, date); Long Hours = new Long(hours); System.out.println("Summary " + summary); System.out.println("Capacity " + hours); System.out.println("Load " + seconds); /* ** Realizo la verificacin sobre que da me encuentro ** para graficar cada 7 dias el estado de la semana. ** ** secondsAcum y hoursAcum llevan los acumulados para la semana ** los reinicio en cada nueva semana. ** ** VIT4B - 07/12/2006 */ if (days == 1 || days == 8 || days == 15 || days == 22) { secondsAcum = 0; hoursAcum = 0; } secondsAcum += seconds; hoursAcum += hours; switch (gc1.get(Calendar.DAY_OF_WEEK)) { case Calendar.SUNDAY: if (t.isOnSunday()) { /* ** Realizo la verificacin sobre que da me encuentro ** para graficar cada 7 dias el estado de la semana. ** ** VIT4B - 07/12/2006 */ if (days == 7 || days == 14 || days == 21 || days == 28) { dataset.addValue(hoursAcum, namecapacity, day); dataset.addValue(secondsAcum / 3600, nameload, day); dataset.addValue(summary, namesummary, day); } summary = summary + Hours.intValue() - (seconds / 3600); //+ (Hours.intValue() - ((seconds / 3600))); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } else { /* ** Realizo la verificacin sobre que da me encuentro ** para graficar cada 7 dias el estado de la semana. ** ** VIT4B - 07/12/2006 */ if (days == 7 || days == 14 || days == 21 || days == 28) { dataset.addValue(hoursAcum, namecapacity, day); dataset.addValue(secondsAcum / 3600, nameload, day); dataset.addValue(summary, namesummary, day); } summary = summary - (seconds / 3600); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } case Calendar.MONDAY: if (t.isOnMonday()) { /* ** Realizo la verificacin sobre que da me encuentro ** para graficar cada 7 dias el estado de la semana. ** ** VIT4B - 07/12/2006 */ if (days == 7 || days == 14 || days == 21 || days == 28) { dataset.addValue(hoursAcum, namecapacity, day); dataset.addValue(secondsAcum / 3600, nameload, day); dataset.addValue(summary, namesummary, day); } summary = summary + Hours.intValue() - (seconds / 3600); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } else { /* ** Realizo la verificacin sobre que da me encuentro ** para graficar cada 7 dias el estado de la semana. ** ** VIT4B - 07/12/2006 */ if (days == 7 || days == 14 || days == 21 || days == 28) { dataset.addValue(hoursAcum, namecapacity, day); dataset.addValue(secondsAcum / 3600, nameload, day); dataset.addValue(summary, namesummary, day); } summary = summary - (seconds / 3600); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } case Calendar.TUESDAY: if (t.isOnTuesday()) { /* ** Realizo la verificacin sobre que da me encuentro ** para graficar cada 7 dias el estado de la semana. ** ** VIT4B - 07/12/2006 */ if (days == 7 || days == 14 || days == 21 || days == 28) { dataset.addValue(hoursAcum, namecapacity, day); dataset.addValue(secondsAcum / 3600, nameload, day); dataset.addValue(summary, namesummary, day); } summary = summary + Hours.intValue() - (seconds / 3600); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } else { /* ** Realizo la verificacin sobre que da me encuentro ** para graficar cada 7 dias el estado de la semana. ** ** VIT4B - 07/12/2006 */ if (days == 7 || days == 14 || days == 21 || days == 28) { dataset.addValue(hoursAcum, namecapacity, day); dataset.addValue(secondsAcum / 3600, nameload, day); dataset.addValue(summary, namesummary, day); } summary = summary - (seconds / 3600); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } case Calendar.WEDNESDAY: if (t.isOnWednesday()) { /* ** Realizo la verificacin sobre que da me encuentro ** para graficar cada 7 dias el estado de la semana. ** ** VIT4B - 07/12/2006 */ if (days == 7 || days == 14 || days == 21 || days == 28) { dataset.addValue(hoursAcum, namecapacity, day); dataset.addValue(secondsAcum / 3600, nameload, day); dataset.addValue(summary, namesummary, day); } summary = summary + Hours.intValue() - (seconds / 3600); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } else { /* ** Realizo la verificacin sobre que da me encuentro ** para graficar cada 7 dias el estado de la semana. ** ** VIT4B - 07/12/2006 */ if (days == 7 || days == 14 || days == 21 || days == 28) { dataset.addValue(hoursAcum, namecapacity, day); dataset.addValue(secondsAcum / 3600, nameload, day); dataset.addValue(summary, namesummary, day); } summary = summary - (seconds / 3600); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } case Calendar.THURSDAY: if (t.isOnThursday()) { /* ** Realizo la verificacin sobre que da me encuentro ** para graficar cada 7 dias el estado de la semana. ** ** VIT4B - 07/12/2006 */ if (days == 7 || days == 14 || days == 21 || days == 28) { dataset.addValue(hoursAcum, namecapacity, day); dataset.addValue(secondsAcum / 3600, nameload, day); dataset.addValue(summary, namesummary, day); } summary = summary + Hours.intValue() - (seconds / 3600); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } else { /* ** Realizo la verificacin sobre que da me encuentro ** para graficar cada 7 dias el estado de la semana. ** ** VIT4B - 07/12/2006 */ if (days == 7 || days == 14 || days == 21 || days == 28) { dataset.addValue(hoursAcum, namecapacity, day); dataset.addValue(secondsAcum / 3600, nameload, day); dataset.addValue(summary, namesummary, day); } summary = summary - (seconds / 3600); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } case Calendar.FRIDAY: if (t.isOnFriday()) { /* ** Realizo la verificacin sobre que da me encuentro ** para graficar cada 7 dias el estado de la semana. ** ** VIT4B - 07/12/2006 */ if (days == 7 || days == 14 || days == 21 || days == 28) { dataset.addValue(hoursAcum, namecapacity, day); dataset.addValue(secondsAcum / 3600, nameload, day); dataset.addValue(summary, namesummary, day); } summary = summary + Hours.intValue() - (seconds / 3600); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } else { /* ** Realizo la verificacin sobre que da me encuentro ** para graficar cada 7 dias el estado de la semana. ** ** VIT4B - 07/12/2006 */ if (days == 7 || days == 14 || days == 21 || days == 28) { dataset.addValue(hoursAcum, namecapacity, day); dataset.addValue(secondsAcum / 3600, nameload, day); dataset.addValue(summary, namesummary, day); } summary = summary - (seconds / 3600); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } case Calendar.SATURDAY: if (t.isOnSaturday()) { /* ** Realizo la verificacin sobre que da me encuentro ** para graficar cada 7 dias el estado de la semana. ** ** VIT4B - 07/12/2006 */ if (days == 7 || days == 14 || days == 21 || days == 28) { dataset.addValue(hoursAcum, namecapacity, day); dataset.addValue(secondsAcum / 3600, nameload, day); dataset.addValue(summary, namesummary, day); } summary = summary + Hours.intValue() - (seconds / 3600); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } else { /* ** Realizo la verificacin sobre que da me encuentro ** para graficar cada 7 dias el estado de la semana. ** ** VIT4B - 07/12/2006 */ if (days == 7 || days == 14 || days == 21 || days == 28) { dataset.addValue(hoursAcum, namecapacity, day); dataset.addValue(secondsAcum / 3600, nameload, day); dataset.addValue(summary, namesummary, day); } summary = summary - (seconds / 3600); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } } days++; } return dataset; }
From source file:com.lp.server.auftrag.ejbfac.AuftragFacBean.java
/** * Fuer eine bestimmte Auftragsart fuer einen bestimmten Zeitraum und eine * bestimmte Terminart (Belegdatum, Liefertermin, Finaltermin) den * Nettoauftragswert in Abhaengigkeit vom aktuellen Mandanten bestimmen. <br> * Beruecksichtigt werden koennen entweder alle offenen Auftraege oder alle * eingegangenen Auftraege.//from w w w.j a v a2 s . c o m * * @param cNrAuftragartI * die Auftragart (Frei, Rahmen, Abruf) * @param whichKriteriumI * welche Zeitraumart (Belegdatum, Liefertermin, Finaltermin) * @param gcBerechnungsdatumVonI * ab diesem Datum * @param gcBerechnungsdatumBisI * bis zu diesem Datum * @param offenOderEingegangenI * sollen alle offenen oder alle eingegangengen Auftraegr * beruecksichtigt werden * @param theClientDto * der aktuelle Benutzer * @return BigDecimal der Nettoauftragswert, 0 wenn keine offenen Positionen * gefunden wurden * @throws EJBExceptionLP * Ausnahme */ public BigDecimal berechneSummeAuftragsnettowert(String cNrAuftragartI, String whichKriteriumI, GregorianCalendar gcBerechnungsdatumVonI, GregorianCalendar gcBerechnungsdatumBisI, String offenOderEingegangenI, TheClientDto theClientDto) throws EJBExceptionLP { StringBuffer buff = new StringBuffer(); buff.append(offenOderEingegangenI).append(", ").append(whichKriteriumI).append(", ").append(cNrAuftragartI) .append(", ").append("Von: ") .append(Helper.formatDatum(gcBerechnungsdatumVonI.getTime(), theClientDto.getLocUi())) .append(", Bis: ") .append(Helper.formatDatum(gcBerechnungsdatumBisI.getTime(), theClientDto.getLocUi())); myLogger.info(buff.toString()); BigDecimal nSummeAuftragsnettowert = new BigDecimal(0); Session session = null; try { SessionFactory factory = FLRSessionFactory.getFactory(); session = factory.openSession(); // Criteria duerfen keine Texts oder Blobs enthalten! // Criteria anlegen fuer alle referenzierten Objekte anlegen Criteria crit = session.createCriteria(FLRAuftragFuerUebersicht.class); // Einschraenken nach Mandant crit.add(Restrictions.eq("mandant_c_nr", theClientDto.getMandant())); // Einschraenken nach Auftragart crit.add(Restrictions.eq(AuftragFac.FLR_AUFTRAG_AUFTRAGART_C_NR, cNrAuftragartI)); if (whichKriteriumI.equals(AuftragFac.KRIT_BELEGDATUM)) { // Belegdatum von bis: flrauftrag.t_belegdatum if (gcBerechnungsdatumVonI != null) { crit.add(Restrictions.ge(AuftragFac.FLR_AUFTRAG_D_BELEGDATUM, new java.sql.Date(gcBerechnungsdatumVonI.getTimeInMillis()))); } if (gcBerechnungsdatumBisI != null) { crit.add(Restrictions.lt(AuftragFac.FLR_AUFTRAG_D_BELEGDATUM, new java.sql.Date(gcBerechnungsdatumBisI.getTimeInMillis()))); } } else if (whichKriteriumI.equals(AuftragFac.KRIT_LIEFERTERMIN)) { // Liefertermin von bis: flrauftrag.t_liefertermin if (gcBerechnungsdatumVonI != null) { crit.add(Restrictions.ge(AuftragFac.FLR_AUFTRAG_T_LIEFERTERMIN, new java.sql.Date(gcBerechnungsdatumVonI.getTimeInMillis()))); } if (gcBerechnungsdatumBisI != null) { crit.add(Restrictions.le(AuftragFac.FLR_AUFTRAG_T_LIEFERTERMIN, new java.sql.Date(gcBerechnungsdatumBisI.getTimeInMillis()))); } } else if (whichKriteriumI.equals(AuftragFac.KRIT_FINALTERMIN)) { // Belegdatum von bis: flrauftrag.t_finaltermin if (gcBerechnungsdatumVonI != null) { crit.add(Restrictions.ge(AuftragFac.FLR_AUFTRAG_T_FINALTERMIN, new java.sql.Date(gcBerechnungsdatumVonI.getTimeInMillis()))); } if (gcBerechnungsdatumBisI != null) { crit.add(Restrictions.le(AuftragFac.FLR_AUFTRAG_T_FINALTERMIN, new java.sql.Date(gcBerechnungsdatumBisI.getTimeInMillis()))); } } // Einschraenken nach Auftragstatus if (offenOderEingegangenI.equals(AuftragFac.AUFT_UMSATZUEBERSICHT_OFFEN)) { crit.add(Expression.or( Restrictions.eq(AuftragFac.FLR_AUFTRAG_AUFTRAGSTATUS_C_NR, AuftragServiceFac.AUFTRAGSTATUS_OFFEN), Restrictions.eq(AuftragFac.FLR_AUFTRAG_AUFTRAGSTATUS_C_NR, AuftragServiceFac.AUFTRAGSTATUS_TEILERLEDIGT))); } else if (offenOderEingegangenI.equals(AuftragFac.AUFT_UMSATZUEBERSICHT_EINGANG)) { crit.add(Restrictions.ne(AuftragFac.FLR_AUFTRAG_AUFTRAGSTATUS_C_NR, AuftragServiceFac.AUFTRAGSTATUS_ANGELEGT)); crit.add(Restrictions.ne(AuftragFac.FLR_AUFTRAG_AUFTRAGSTATUS_C_NR, AuftragServiceFac.AUFTRAGSTATUS_STORNIERT)); } List<?> list = crit.list(); if (offenOderEingegangenI.equals(AuftragFac.AUFT_UMSATZUEBERSICHT_OFFEN)) { nSummeAuftragsnettowert = berechneAuftragsnettowertOffen(list, session, theClientDto); } else if (offenOderEingegangenI.equals(AuftragFac.AUFT_UMSATZUEBERSICHT_EINGANG)) { nSummeAuftragsnettowert = berechneAuftragsnettowertEingang(list, theClientDto); } } catch (Throwable t) { throw new EJBExceptionLP(EJBExceptionLP.FEHLER_FLR, new Exception(t)); } finally { try { session.close(); } catch (HibernateException he) { throw new EJBExceptionLP(EJBExceptionLP.FEHLER_HIBERNATE, he); } } return nSummeAuftragsnettowert; }
From source file:org.sakaiproject.calendar.impl.BaseCalendarService.java
/** * Collect the fields that need to be stored outside the XML (for the resource). * /*from www.ja v a2s .co m*/ * @return An array of field values to store in the record outside the XML (for the resource). */ public Object[] storageFields(Entity r) { Object[] rv = new Object[4]; TimeRange range = ((CalendarEvent) r).getRange(); rv[0] = range.firstTime(); // %%% fudge? rv[1] = range.lastTime(); // %%% fudge? // we use hours rather than ms for the range to reduce the index size in the database // I dont what to use days just incase we want sub day range finds long oneHour = 60L * 60L * 1000L; rv[2] = (int) (range.firstTime().getTime() / oneHour); rv[3] = (int) (range.lastTime().getTime() / oneHour); // find the end of the sequence RecurrenceRuleBase rr = (RecurrenceRuleBase) ((CalendarEvent) r).getRecurrenceRule(); if (rr != null) { Time until = rr.getUntil(); if (until != null) { rv[3] = (int) (until.getTime() / oneHour); } else { int count = rr.getCount(); int interval = rr.getInterval(); long endevent = range.lastTime().getTime(); if (count == 0) { rv[3] = Integer.MAX_VALUE - 1; // hours since epoch, this represnts 9 Oct 246953 07:00:00 } else { String frequency = rr.getFrequency(); GregorianCalendar c = new GregorianCalendar(); c.setTimeInMillis(endevent); c.add(rr.getRecurrenceType(), count * interval); rv[3] = (int) (c.getTimeInMillis() / oneHour); } } } return rv; }
From source file:com.flexive.core.storage.genericSQL.GenericHierarchicalStorage.java
/** * Set a properties data for inserts or updates * * @param insert perform insert or update? * @param prop current property * @param allData all data of the instance (might be needed to buld references, etc.) * @param con an open and valid connection * @param data current property data * @param ps prepared statement for the data table * @param ft fulltext indexer * @param upperColumnPos position of the uppercase column (if present, else <code>-1</code>) * @param includeFullText add fulltext entries? Will be skipped for position only changes * @throws SQLException on errors * @throws FxUpdateException on errors * @throws FxDbException on errors * @throws FxNoAccessException for FxNoAccess values *//* w w w . ja v a 2 s.c o m*/ private void setPropertyData(boolean insert, FxProperty prop, List<FxData> allData, Connection con, FxPropertyData data, PreparedStatement ps, FulltextIndexer ft, int upperColumnPos, boolean includeFullText) throws SQLException, FxUpdateException, FxDbException, FxNoAccessException { FxValue value = data.getValue(); if (value instanceof FxNoAccess) throw new FxNoAccessException("ex.content.value.noaccess"); if (value.isMultiLanguage() != ((FxPropertyAssignment) data.getAssignment()).isMultiLang()) { if (((FxPropertyAssignment) data.getAssignment()).isMultiLang()) throw new FxUpdateException("ex.content.value.invalid.multilanguage.ass.multi", data.getXPathFull()); else throw new FxUpdateException("ex.content.value.invalid.multilanguage.ass.single", data.getXPathFull()); } int pos_lang = insert ? INSERT_LANG_POS : UPDATE_ID_POS + 2; int pos_isdef_lang = insert ? INSERT_ISDEF_LANG_POS : UPDATE_MLDEF_POS; final FxEnvironment env = CacheAdmin.getEnvironment(); if (prop.getDataType().isSingleRowStorage()) { //Data types that just use one db row can be handled in a very similar way Object translatedValue; GregorianCalendar gc = null; final long[] translatedLanguages = value.getTranslatedLanguages(); for (long translatedLanguage : translatedLanguages) { translatedValue = value.getTranslation(translatedLanguage); if (translatedValue == null) { LOG.warn("Translation for " + data.getXPath() + " is null!"); } ps.setLong(pos_lang, translatedLanguage); if (!value.isMultiLanguage()) ps.setBoolean(pos_isdef_lang, true); else ps.setBoolean(pos_isdef_lang, value.isDefaultLanguage(translatedLanguage)); if (upperColumnPos != -1) { final Locale locale = value.isMultiLanguage() ? env.getLanguage(translatedLanguage).getLocale() : Locale.getDefault(); ps.setString(upperColumnPos, translatedValue.toString().toUpperCase(locale)); } int[] pos = insert ? getColumnPosInsert(prop) : getColumnPosUpdate(prop); switch (prop.getDataType()) { case Double: checkDataType(FxDouble.class, value, data.getXPathFull()); ps.setDouble(pos[0], (Double) translatedValue); break; case Float: checkDataType(FxFloat.class, value, data.getXPathFull()); ps.setFloat(pos[0], (Float) translatedValue); break; case LargeNumber: checkDataType(FxLargeNumber.class, value, data.getXPathFull()); ps.setLong(pos[0], (Long) translatedValue); break; case Number: checkDataType(FxNumber.class, value, data.getXPathFull()); ps.setInt(pos[0], (Integer) translatedValue); break; case HTML: checkDataType(FxHTML.class, value, data.getXPathFull()); boolean useTidy = ((FxHTML) value).isTidyHTML(); ps.setBoolean(pos[1], useTidy); final String extractorInput = doTidy(data.getXPathFull(), (String) translatedValue); if (useTidy) { translatedValue = extractorInput; } final HtmlExtractor result = new HtmlExtractor(extractorInput, true); setBigString(ps, pos[2], result.getText()); setBigString(ps, pos[0], (String) translatedValue); break; case String1024: case Text: checkDataType(FxString.class, value, data.getXPathFull()); setBigString(ps, pos[0], (String) translatedValue); break; case Boolean: checkDataType(FxBoolean.class, value, data.getXPathFull()); ps.setBoolean(pos[0], (Boolean) translatedValue); break; case Date: checkDataType(FxDate.class, value, data.getXPathFull()); if (gc == null) gc = new GregorianCalendar(); gc.setTime((Date) translatedValue); //strip all time information, this might not be necessary since ps.setDate() strips them //for most databases but won't hurt either ;) gc.set(GregorianCalendar.HOUR, 0); gc.set(GregorianCalendar.MINUTE, 0); gc.set(GregorianCalendar.SECOND, 0); gc.set(GregorianCalendar.MILLISECOND, 0); ps.setDate(pos[0], new java.sql.Date(gc.getTimeInMillis())); break; case DateTime: checkDataType(FxDateTime.class, value, data.getXPathFull()); if (gc == null) gc = new GregorianCalendar(); gc.setTime((Date) translatedValue); ps.setTimestamp(pos[0], new Timestamp(gc.getTimeInMillis())); break; case DateRange: checkDataType(FxDateRange.class, value, data.getXPathFull()); if (gc == null) gc = new GregorianCalendar(); gc.setTime(((DateRange) translatedValue).getLower()); gc.set(GregorianCalendar.HOUR, 0); gc.set(GregorianCalendar.MINUTE, 0); gc.set(GregorianCalendar.SECOND, 0); gc.set(GregorianCalendar.MILLISECOND, 0); ps.setDate(pos[0], new java.sql.Date(gc.getTimeInMillis())); gc.setTime(((DateRange) translatedValue).getUpper()); gc.set(GregorianCalendar.HOUR, 0); gc.set(GregorianCalendar.MINUTE, 0); gc.set(GregorianCalendar.SECOND, 0); gc.set(GregorianCalendar.MILLISECOND, 0); ps.setDate(pos[1], new java.sql.Date(gc.getTimeInMillis())); break; case DateTimeRange: checkDataType(FxDateTimeRange.class, value, data.getXPathFull()); if (gc == null) gc = new GregorianCalendar(); gc.setTime(((DateRange) translatedValue).getLower()); ps.setTimestamp(pos[0], new Timestamp(gc.getTimeInMillis())); gc.setTime(((DateRange) translatedValue).getUpper()); ps.setTimestamp(pos[1], new Timestamp(gc.getTimeInMillis())); break; case Binary: checkDataType(FxBinary.class, value, data.getXPathFull()); BinaryDescriptor binary = (BinaryDescriptor) translatedValue; if (!binary.isNewBinary()) { ps.setLong(pos[0], binary.getId()); } else { try { //transfer the binary from the transit table to the binary table BinaryDescriptor created = binaryStorage.binaryTransit(con, binary); ps.setLong(pos[0], created.getId()); //check all other properties if they contain the same handle //and replace with the data of the new binary for (FxData _curr : allData) { if (_curr instanceof FxPropertyData && !_curr.isEmpty() && ((FxPropertyData) _curr).getValue() instanceof FxBinary) { FxBinary _val = (FxBinary) ((FxPropertyData) _curr).getValue(); _val._replaceHandle(binary.getHandle(), created); } } } catch (FxApplicationException e) { throw new FxDbException(e); } } break; case SelectOne: checkDataType(FxSelectOne.class, value, data.getXPathFull()); ps.setLong(pos[0], ((FxSelectListItem) translatedValue).getId()); break; case SelectMany: checkDataType(FxSelectMany.class, value, data.getXPathFull()); SelectMany sm = (SelectMany) translatedValue; for (int i1 = 0; i1 < sm.getSelected().size(); i1++) { FxSelectListItem item = sm.getSelected().get(i1); if (i1 > 0) { if (batchContentDataChanges()) ps.addBatch(); else ps.executeUpdate(); } ps.setLong(pos[0], item.getId()); ps.setString(pos[1], sm.getSelectedIdsList()); ps.setLong(pos[2], sm.getSelectedIds().size()); } if (sm.getSelected().size() == 0) ps.setLong(pos[0], 0); //write the virtual item as a marker to have a valid row break; case Reference: //reference integrity check is done prior to saving ps.setLong(pos[0], ((FxPK) translatedValue).getId()); break; case InlineReference: default: throw new FxDbException(LOG, "ex.db.notImplemented.store", prop.getDataType().getName()); } int valueDataPos = insert ? getValueDataInsertPos(prop.getDataType()) : getValueDataUpdatePos(prop.getDataType()); if (value.hasValueData(translatedLanguage)) { ps.setInt(valueDataPos, value.getValueDataRaw(translatedLanguage)); } else ps.setNull(valueDataPos, Types.NUMERIC); if (batchContentDataChanges()) ps.addBatch(); else { try { ps.executeUpdate(); } catch (SQLException e) { LOG.error(prop.getName(), e); throw e; } } } } else { switch (prop.getDataType()) { //TODO: implement datatype specific insert default: throw new FxDbException(LOG, "ex.db.notImplemented.store", prop.getDataType().getName()); } } if (ft != null && prop.isFulltextIndexed() && includeFullText) ft.index(data); }
From source file:gov.noaa.pfel.coastwatch.Projects.java
/** * Generate ncml which assigns "days since 1970-01-01" coordValue to a file for a range of times. * E.g., <netcdf location="V2013074.L3m_DAY_NPP_CHL_chlor_a_4km" coordValue="15779"/> * The string is displayed and put on the clipboard. * /*from w w w.j a v a 2 s .c o m*/ * @param location with '*' where YYYYDDD goes. * @param startIso * @param stopIso (inclusive) * @param increment e.g., 1, 7, or 3 * @param field e.g. Calendar2.DAY_OF_YEAR, Calendar2.MONTH * @return ncml which assigns "days since 1970-01-01" coordValue to a file for a range of times. */ public static String makeNcmlCoordValues(String location, String startIso, String stopIso, int increment, int field) throws Exception { StringBuilder sb = new StringBuilder(); double baseFactor[] = Calendar2.getTimeBaseAndFactor("days since 1970-01-01"); GregorianCalendar gc = Calendar2.parseISODateTimeZulu(startIso); GregorianCalendar stopGc = Calendar2.parseISODateTimeZulu(stopIso); long stopMillis = stopGc.getTimeInMillis(); while (gc.getTimeInMillis() <= stopMillis) { int daysSince = Math2.roundToInt(Calendar2.epochSecondsToUnitsSince(baseFactor[0], baseFactor[1], Calendar2.gcToEpochSeconds(gc))); sb.append("<netcdf location=\"" + String2.replaceAll(location, "*", Calendar2.formatAsYYYYDDD(gc)) + "\" coordValue=\"" + daysSince + "\"/>\n"); gc.add(field, increment); } String s = sb.toString(); String2.setClipboardString(s); String2.log(s); return s; }
From source file:gov.noaa.pfel.coastwatch.Projects.java
/** * This was used by Bob to convert the source Calcatch .csv data into .nc files * suitable for ERDDAP EDDTableFromNcFiles. * <br>Lynn made the .csv files 2009-12-31. * ftp://192.168.31.10/outgoing/ldewitt/Simons/calcatch/ * <br>This data is different from Jan's similar data. *///from w w w .ja va 2 s .c om public static void convertFedCalLandings() throws Exception { String2.log("\n*** EDDTableFromNcFiles.convertFedCalLandings"); String sourceDir = "c:/data/rawSource/fedCalLandings2010-01-05/"; String sourceCsv = "dbo_block_summary.csv"; String sourceMarCat = "dbo_market_categories.csv"; String destDir = "c:/u00/data/points/fedCalLandings/"; int mv = -9999; double timeNaN = -1e30; String dataColNames[] = String2.split( /* region Int8 (4), year Int8 (4), mark_cat Int8 (4), month Int8 (4), block Int8 (4), pounds Char (76), really!!! why? area Char (50), imported Char (2), region_caught Int8 (4) */ "region, year, market_category, month, block, " + "pounds, area, imported, region_caught", ','); Class dataColTypes[] = { //month and region_caught could be byte, but mv=-9999 wouldn't fit short.class, short.class, short.class, short.class, short.class, int.class, String.class, String.class, short.class }; String dataUnits[] = { //date will be ... null, null, null, null, null, "pounds", null, null, null }; Test.ensureEqual(dataColNames.length, dataColTypes.length, "dataColNames.length != dataColTypes.length"); //recursively delete any files in destDir File2.deleteAllFiles(destDir, true, true); //read the data source file String2.log("\nreading the data source file"); Table dataTable = new Table(); dataTable.readASCII(sourceDir + sourceCsv, String2.readLinesFromFile(sourceDir + sourceCsv, null, 3), -1, 0, "", null, null, null, null, false); //don't simplify Test.ensureEqual(dataTable.nColumns(), dataColNames.length, "dataTable.nColumns() != dataColNames.length"); String2.log(""); //find bad rows (no market category)? PrimitiveArray tPa = dataTable.getColumn(2); for (int row = 0; row < tPa.size(); row++) { if (tPa.getString(row).length() == 0) { String2.log("!!! data row=" + row + " has no marCat. Removing it..."); dataTable.removeRow(row); } } String2.log(""); for (int col = 0; col < dataColNames.length; col++) { //set the column name dataTable.setColumnName(col, dataColNames[col]); //set the units if (dataUnits[col] != null) dataTable.columnAttributes(col).set("units", dataUnits[col]); //change the columnType if (dataColTypes[col] != String.class) { PrimitiveArray pa = PrimitiveArray.factory(dataColTypes[col], 1, false); PrimitiveArray opa = dataTable.getColumn(col); //ensure dataColType is appropriate int n = opa.size(); int max = dataColTypes[col] == short.class ? Short.MAX_VALUE : dataColTypes[col] == int.class ? Integer.MAX_VALUE : -1; Test.ensureTrue(max != -1, "Unrecognized dataColType for col=" + col); for (int row = 0; row < n; row++) { String s = opa.getString(row); int ti = String2.parseInt(s); if ((s.length() > 0 && ti == Integer.MAX_VALUE) || //e.g., a word (ti < Integer.MAX_VALUE && ti >= max)) Test.ensureTrue(false, "invalid value: col=" + col + " row=" + row + " s=" + s + " ti=" + ti + " max=" + max); } pa.append(opa); dataTable.setColumn(col, pa); //set missing value to mv String2.log(pa.switchFromTo("", "" + mv) + " " + dataColNames[col] + " values converted from '' to " + mv); dataTable.columnAttributes(col).set("missing_value", mv); } //convert "Ship of Opportu" //if (col == 9) { // PrimitiveArray pa = dataTable.getColumn(col); // String2.log(pa.switchFromTo("Ship of Opportu", "Ship of Opportunity") + // " project values converted from \"Ship of Opportu\"."); //} } //sort (so all data for a given stationCode will be stored together) String2.log("\nsorting dataTable\n"); dataTable.leftToRightSort(5); //region, year, month, market_category, block //make time (Z) from year and month PrimitiveArray yearPa = dataTable.findColumn("year"); PrimitiveArray monthPa = dataTable.findColumn("month"); DoubleArray timePa = new DoubleArray(); int nTimeNaN = 0; for (int row = 0; row < yearPa.size(); row++) { int year = yearPa.getInt(row); int month = monthPa.getInt(row); if (year == mv || month == mv) { timePa.add(timeNaN); nTimeNaN++; continue; } GregorianCalendar gc = Calendar2.newGCalendarZulu(year, month, 15); timePa.add(Math2.roundToDouble(gc.getTimeInMillis() / 1000.0)); if (row % 10000 == 0) String2.log("row=" + row + " year=" + year + " month=" + month + " time=" + Calendar2.epochSecondsToIsoStringT(timePa.get(row))); } String2.log("\nnTimeNaN=" + nTimeNaN + "\n"); Test.ensureEqual(timePa.size(), yearPa.size(), "timePa size is incorrect."); dataTable.addColumn(dataTable.nColumns(), "time", timePa, (new Attributes()).add("units", Calendar2.SECONDS_SINCE_1970).add("missing_value", timeNaN)); //read the marCat file String marCatColNames[] = String2.split( /* market_category Int8 (4), description Char (200), nominal_species Char (8), species_group Char (20), comments Char (240) */ "market_category, description, nominal_species, species_group, comments", ','); //schema has double.class for lat, lon, but I think not necessary Class marCatColTypes[] = { short.class, String.class, String.class, String.class, String.class }; String2.log("\nreading the marCat source file"); Table marCatTable = new Table(); marCatTable.readASCII(sourceDir + sourceMarCat, -1, 0, "", null, null, null, null); Test.ensureEqual(marCatTable.nColumns(), marCatColNames.length, "marCatTable.nColumns() != marCatColNames.length"); for (int col = 0; col < marCatColNames.length; col++) { //set the column name marCatTable.setColumnName(col, marCatColNames[col]); //change the columnType if (marCatColTypes[col] != String.class) { PrimitiveArray pa = PrimitiveArray.factory(marCatColTypes[col], 1, false); pa.append(marCatTable.getColumn(col)); marCatTable.setColumn(col, pa); } } //sort marCatTable so can use binarySearch String2.log("\nsorting marCatTable\n"); marCatTable.leftToRightSort(1); //marCat String2.log(marCatTable.toString()); //generate the marCat columns for the dataTable String2.log("\ngenerate marCat columns"); PrimitiveArray marCatPa = marCatTable.findColumn("market_category"); PrimitiveArray dataMarCatPa = dataTable.findColumn("market_category"); StringArray saa[] = new StringArray[5]; //0 isn't used for (int c = 1; c < 5; c++) { saa[c] = new StringArray(); dataTable.addColumn(dataTable.nColumns(), marCatColNames[c], saa[c], new Attributes()); } int marCatPaSize = marCatPa.size(); int nRows = dataMarCatPa.size(); for (int row = 0; row < nRows; row++) { int dataMarCat = dataMarCatPa.getInt(row); int po = marCatPa.binarySearch(0, marCatPaSize - 1, dataMarCat); if (po < 0) { //marCat=7 isn't defined String2.log("dataMarCat=" + dataMarCat + " not in marCatPa"); for (int c = 1; c < 5; c++) saa[c].add(""); } else { for (int c = 1; c < 5; c++) saa[c].add(marCatTable.getStringData(c, po)); } } //save in files PrimitiveArray regionPa = dataTable.findColumn("region"); //already have yearPa int lastRegion = regionPa.getInt(0); int lastYear = yearPa.getInt(0); int startRow = 0; nRows = regionPa.size(); for (int row = 0; row < nRows; row++) { int tRegion = regionPa.getInt(row); int tYear = yearPa.getInt(row); if (row == nRows - 1 || tRegion != lastRegion || tYear != lastYear) { int lastRow = row == nRows - 1 ? row : row - 1; String fullName = destDir + tRegion + "/" + tYear + ".nc"; File2.makeDirectory(destDir + tRegion + "/"); Table table = new Table(); for (int col = 0; col < dataTable.nColumns(); col++) { PrimitiveArray oldPa = dataTable.getColumn(col); PrimitiveArray newPa = PrimitiveArray.factory(oldPa.elementClass(), lastRow - startRow + 1, false); for (int tRow = startRow; tRow <= lastRow; tRow++) newPa.addString(oldPa.getString(tRow)); table.addColumn(col, dataTable.getColumnName(col), newPa, (Attributes) (dataTable.columnAttributes(col).clone())); } table.saveAsFlatNc(fullName, "row", false); if (startRow < 100 || row == nRows - 1) String2.log(table.toString()); //if (startRow > 100) Test.ensureTrue(false, "Evaluate the tables."); lastRegion = tRegion; lastYear = tYear; startRow = lastRow + 1; } } String2.log("Finished!"); }
From source file:gov.noaa.pfel.coastwatch.Projects.java
/** Make VH mday .ncml files. * coordValue is firstDay of the month. First 3 of 2012 are 15340, 15371, 15400. *///from www . ja v a 2s . co m public static void makeVHmdayNcmlFiles(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++) { 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/VHncml/" + varDirNames[var] + "/ncmlmon/V" + yj1 + yj2 + ".ncml"); w.write( /* C:/content/scripts/VHncml/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='l3m_data'/>\n" + " <netcdf location='V" + yj1 + yj2 + ".L3m_MO_NPP_" + jplNames[var] + "_4km' " + "coordValue='" + daysSince + "'/>\n" + " </aggregation>\n" + "</netcdf>\n"); w.close(); } } } }
From source file:gov.noaa.pfel.coastwatch.Projects.java
/** Make VH2 mday .ncml files. * coordValue is firstDay of the month. First 3 of 2012 are 15340, 15371, 15400. *///from ww w.j a v a 2s.c o m public static void makeVH2mdayNcmlFiles(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/VH2ncml/" + varDirNames[var] + "/ncmlmon/V" + yj1 + yj2 + ".ncml"); w.write( /* C:/content/scripts/VH2ncml/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_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 mday .ncml files. * coordValue is firstDay of the month. First 3 of 2012 are 15340, 15371, 15400. */// w w w .j a va 2 s . c om public static void makeVH3mdayNcmlFiles(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/VH3ncml/" + varDirNames[var] + "/ncmlmon/V" + yj1 + yj2 + ".ncml"); w.write( /* C:/content/scripts/VH3ncml/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(); } } } }