public boolean store(JDCConnection oConn, String sLanguage) throws SQLException,IllegalStateException,NullPointerException {
Date dtNow = new Date();
Locale oLoc = new Locale(sLanguage);
SimpleDateFormat oXMLDate = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
DecimalFormat oNumFmt = (DecimalFormat) NumberFormat.getNumberInstance(oLoc);
oNumFmt.setMaximumFractionDigits(2);
if (!containsKey(DB.gu_project)) throw new NullPointerException("DutiesWorkReport duties report, project is required");
if (!containsKey(DB.gu_writer)) throw new NullPointerException("DutiesWorkReport duties report, writer user is required");
if (containsKey(DB.gu_workreport)) {
if (DBCommand.queryExists(oConn, DB.k_duties_workreports, DB.gu_workreport+"='"+getString(DB.gu_workreport)+"'"))
throw new IllegalStateException("DutiesWorkReport, it is not allowed to update an already existing report");
} else {
put(DB.gu_workreport, Gadgets.generateUUID());
}
if (!containsKey(DB.tl_workreport)) {
String sNmProject = DBCommand.queryStr(oConn, "SELECT "+DB.nm_project+" FROM "+DB.k_projects+" WHERE "+DB.gu_project+"='"+getStringNull(DB.gu_project,"")+"'");
put(DB.tl_workreport, sNmProject+" "+dtNow.toString());
}
ACLUser oWriter = new ACLUser(oConn, getString(DB.gu_writer));
Project oProj = new Project(oConn, getString(DB.gu_project));
HashMap oPrioritiesMap = DBLanguages.getLookUpMap(oConn, DB.k_duties_lookup, oProj.getString(DB.gu_owner), DB.od_priority, sLanguage);
HashMap oDutyTypesMap = DBLanguages.getLookUpMap(oConn, DB.k_duties_lookup, oProj.getString(DB.gu_owner), DB.tp_duty, sLanguage);
HashMap oStatusMap = DBLanguages.getLookUpMap(oConn, DB.k_duties_lookup, oProj.getString(DB.gu_owner), DB.tx_status, sLanguage);
HashMap oResourcesMap = DBLanguages.getLookUpMap(oConn, DB.k_duties_lookup, oProj.getString(DB.gu_owner), DB.nm_resource, sLanguage);
int nDuties = oDuties.size();
StringBuffer oStrBuf = new StringBuffer(1000+500*nDuties);
oStrBuf.append("<DutiesWorkReport>\n");
oStrBuf.append("<tl_workreport><![CDATA["+getString(DB.tl_workreport)+"]]></tl_workreport>\n");
oStrBuf.append("<dt_created>"+oXMLDate.format(dtNow)+"</dt_created>\n");
oStrBuf.append("<de_workreport><![CDATA["+getStringNull(DB.de_workreport,"")+"]]></de_workreport>\n");
oStrBuf.append("<Writer>\n");
oStrBuf.append(" <tx_nickname>"+oWriter.getStringNull(DB.tx_nickname,"")+"</tx_nickname>\n");
oStrBuf.append(" <tx_full_name><![CDATA["+(oWriter.getStringNull(DB.nm_user,"")+" "+oWriter.getStringNull(DB.tx_surname1,"")+" "+oWriter.getStringNull(DB.tx_surname2,"")).trim()+"]]></tx_full_name>\n");
oStrBuf.append(" <nm_company><![CDATA["+oWriter.getStringNull(DB.nm_company,"")+"]]></nm_company>\n");
oStrBuf.append(" <tx_main_email><![CDATA["+oWriter.getStringNull(DB.tx_main_email,"")+"]]></tx_main_email>\n");
oStrBuf.append("</Writer>\n");
oStrBuf.append(oProj.toXML());
oStrBuf.append('\n');
PreparedStatement oStmt = oConn.prepareStatement("SELECT "+DB.nm_resource+","+DB.pct_time+" FROM "+DB.k_x_duty_resource+" WHERE "+DB.gu_duty+"=?",
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
oStrBuf.append("<Duties count=\""+String.valueOf(nDuties)+"\">\n");
for (int d=0; d<nDuties; d++) {
Duty oDut = oDuties.get(d);
oStrBuf.append("<Duty>\n");
oStrBuf.append(" <gu_duty>"+oDut.getString(DB.gu_duty)+"</gu_duty>\n");
oStrBuf.append(" <nm_duty>"+oDut.getString(DB.nm_duty)+"</nm_duty>\n");
if (oDut.isNull(DB.dt_modified)) oStrBuf.append(" <dt_modified/>\n"); else oStrBuf.append(" <dt_modified>"+oXMLDate.format(oDut.getDate(DB.dt_modified))+"</dt_modified>\n");
if (oDut.isNull(DB.dt_start)) oStrBuf.append(" <dt_start/>\n"); else oStrBuf.append(" <dt_start>"+oDut.getDateShort(DB.dt_start)+"</dt_start>\n");
if (oDut.isNull(DB.dt_end)) oStrBuf.append(" <dt_end/>\n"); else oStrBuf.append(" <dt_end>"+oDut.getDateShort(DB.dt_end)+"</dt_end>\n");
if (oDut.isNull(DB.ti_duration)) oStrBuf.append(" <ti_duration/>\n"); else oStrBuf.append(" <ti_duration>"+oDut.getDecimalFormated(DB.ti_duration,oLoc,2)+"</ti_duration>\n");
if (oDut.isNull(DB.pr_cost)) oStrBuf.append(" <pr_cost/>\n"); else oStrBuf.append(" <pr_cost>"+oNumFmt.format(new BigDecimal(oDut.getFloat(DB.pr_cost)))+"</pr_cost>\n");
if (oDut.isNull(DB.pct_complete)) oStrBuf.append(" <pct_complete/>\n"); else oStrBuf.append(" <pct_complete>"+String.valueOf(oDut.getFloat(DB.pct_complete)+"</pct_complete>\n"));
if (oDut.isNull(DB.od_priority)) {
oStrBuf.append(" <od_priority/>\n");
} else {
Object oPriority = oPrioritiesMap.get(oDut.get(DB.od_priority));