List of usage examples for java.math BigDecimal intValue
@Override public int intValue()
From source file:pe.gob.mef.gescon.web.ui.WikiMB.java
public void edit(ActionEvent event) { try {//from w w w . j a va 2 s.c o m this.setDescripcionHtml(JSFUtils.getRequestParameter("descHtml")); if (this.getSelectedCategoria() == null) { FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "ERROR.", "Categora del wiki requerida. Seleccione la categora del wiki a registrar."); FacesContext.getCurrentInstance().addMessage(null, message); return; } if (StringUtils.isBlank(this.getSelectedWiki().getVtitulo())) { FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "ERROR.", "Ttulo del wiki requerido. Ingrese el ttulo del wiki a registrar."); FacesContext.getCurrentInstance().addMessage(null, message); return; } if (StringUtils.isBlank(this.getDescripcionHtml())) { FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "ERROR.", "Descripcin del wiki requerido. Ingrese la descripcin del wiki a registrar."); FacesContext.getCurrentInstance().addMessage(null, message); return; } if (this.getSelectedWiki().getNdestacado().equals(BigDecimal.ZERO) && this.getChkDestacado()) { ConsultaService consultaService = (ConsultaService) ServiceFinder.findBean("ConsultaService"); HashMap filter = new HashMap(); filter.put("ntipoconocimientoid", Constante.WIKI); BigDecimal cant = consultaService.countDestacadosByTipoConocimiento(filter); if (cant.intValue() >= 10) { this.setListaDestacados(consultaService.getDestacadosByTipoConocimiento(filter)); RequestContext.getCurrentInstance().execute("PF('destDialog').show();"); return; } } /* Validando si exiten vnculos de bases legales derogadas */ int contador = 0; if (CollectionUtils.isNotEmpty(this.getListaTargetVinculosBL())) { for (Consulta c : this.getListaTargetVinculosBL()) { if (c.getIdEstado().toString().equals(Constante.ESTADO_BASELEGAL_DEROGADA)) { contador++; } } } LoginMB loginMB = (LoginMB) JSFUtils.getSessionAttribute("loginMB"); User user = loginMB.getUser(); ConocimientoService conocimientoService = (ConocimientoService) ServiceFinder .findBean("ConocimientoService"); this.setDescripcionPlain(Jsoup.parse(this.getDescripcionHtml()).text()); this.getSelectedWiki().setNcategoriaid(this.getSelectedCategoria().getNcategoriaid()); this.getSelectedWiki().setVtitulo(StringUtils.upperCase(this.getSelectedWiki().getVtitulo())); if (this.getDescripcionPlain().length() < 400) { this.getSelectedWiki().setVdescripcion(StringUtils.capitalize(this.getDescripcionPlain())); } else { this.getSelectedWiki() .setVdescripcion(StringUtils.capitalize(this.getDescripcionPlain().substring(0, 300))); } if (contador > 0) { this.getSelectedWiki().setNflgvinculo(BigDecimal.ONE); } else { this.getSelectedWiki().setNflgvinculo(BigDecimal.ZERO); } this.getSelectedWiki().setNdestacado(this.getChkDestacado() ? BigDecimal.ONE : BigDecimal.ZERO); this.getSelectedWiki().setDfechamodificacion(new Date()); this.getSelectedWiki().setVusuariomodificacion(user.getVlogin()); conocimientoService.saveOrUpdate(this.getSelectedWiki()); GcmFileUtils.writeStringToFileServer(this.getSelectedWiki().getVruta(), "html.txt", this.getDescripcionHtml()); GcmFileUtils.writeStringToFileServer(this.getSelectedWiki().getVruta(), "plain.txt", this.getDescripcionPlain()); HistorialService historialService = (HistorialService) ServiceFinder.findBean("HistorialService"); Historial lastHistorial = historialService .getLastHistorialByConocimiento(this.getSelectedWiki().getNconocimientoid()); int lastversion; if (lastHistorial != null) { lastversion = lastHistorial.getNnumversion().intValue(); } else { lastversion = 0; } String url = this.path.concat(this.getSelectedWiki().getNconocimientoid().toString()).concat("/") .concat(Integer.toString(lastversion + 1)).concat("/"); ThistorialId thistorialId = new ThistorialId(); thistorialId.setNconocimientoid(this.getSelectedWiki().getNconocimientoid()); thistorialId.setNhistorialid(historialService.getNextPK()); Historial historial = new Historial(); historial.setId(thistorialId); historial.setNtipoconocimientoid(Constante.WIKI); historial.setNcategoriaid(this.getSelectedCategoria().getNcategoriaid()); historial.setVtitulo(this.getSelectedWiki().getVtitulo()); historial.setNactivo(BigDecimal.ONE); historial.setNsituacionid(this.getSelectedWiki().getNsituacionid()); historial.setVruta(url); historial.setNnumversion(BigDecimal.valueOf(lastversion + 1)); historial.setDfechacreacion(new Date()); historial.setVusuariocreacion(user.getVlogin()); historialService.saveOrUpdate(historial); GcmFileUtils.writeStringToFileServer(url, "html.txt", this.getDescripcionHtml()); GcmFileUtils.writeStringToFileServer(url, "plain.txt", this.getDescripcionPlain()); if (CollectionUtils.isNotEmpty(this.getListaSeccion())) { String url0 = this.getSelectedWiki().getVruta().concat("s"); String url1 = url.concat("s"); SeccionService seccionService = (SeccionService) ServiceFinder.findBean("SeccionService"); SeccionHistService seccionHistService = (SeccionHistService) ServiceFinder .findBean("SeccionHistService"); for (Seccion seccion : this.getListaSeccion()) { String ruta0 = url0.concat(seccion.getNorden().toString()).concat("/"); seccion.setVruta(ruta0); if (seccion.getNseccionid() != null) { seccion.setDfechamodificacion(new Date()); seccion.setVusuariomodificacion(user.getVlogin()); } else { seccion.setNseccionid(seccionService.getNextPK()); seccion.setNconocimientoid(this.getSelectedWiki().getNconocimientoid()); seccion.setDfechacreacion(new Date()); seccion.setVusuariocreacion(user.getVlogin()); } seccionService.saveOrUpdate(seccion); seccion.setDetallePlain(Jsoup.parse(seccion.getDetalleHtml()).text()); GcmFileUtils.writeStringToFileServer(ruta0, "html.txt", seccion.getDetalleHtml()); GcmFileUtils.writeStringToFileServer(ruta0, "plain.txt", seccion.getDetallePlain()); String ruta1 = url1.concat(seccion.getNorden().toString()).concat("/"); TseccionHistId tseccionHistId = new TseccionHistId(); tseccionHistId.setNconocimientoid(thistorialId.getNconocimientoid()); tseccionHistId.setNhistorialid(thistorialId.getNhistorialid()); tseccionHistId.setNseccionhid(seccionHistService.getNextPK()); SeccionHist seccionHist = new SeccionHist(); seccionHist.setId(tseccionHistId); seccionHist.setNorden(seccion.getNorden()); seccionHist.setVruta(ruta1); seccionHist.setVtitulo(seccion.getVtitulo()); seccionHist.setVusuariocreacion(user.getVlogin()); seccionHist.setDfechacreacion(new Date()); seccionHistService.saveOrUpdate(seccionHist); GcmFileUtils.writeStringToFileServer(ruta1, "html.txt", seccion.getDetalleHtml()); GcmFileUtils.writeStringToFileServer(ruta1, "plain.txt", seccion.getDetallePlain()); } } this.setListaTargetVinculos(new ArrayList()); this.getListaTargetVinculos().addAll(this.getListaTargetVinculosBL()); this.getListaTargetVinculos().addAll(this.getListaTargetVinculosBP()); this.getListaTargetVinculos().addAll(this.getListaTargetVinculosCT()); this.getListaTargetVinculos().addAll(this.getListaTargetVinculosOM()); this.getListaTargetVinculos().addAll(this.getListaTargetVinculosPR()); this.getListaTargetVinculos().addAll(this.getListaTargetVinculosWK()); if (CollectionUtils.isNotEmpty(this.getListaTargetVinculos())) { VinculoService vinculoService = (VinculoService) ServiceFinder.findBean("VinculoService"); VinculoHistService vinculoHistService = (VinculoHistService) ServiceFinder .findBean("VinculoHistService"); vinculoService.deleteByConocimiento(this.getSelectedWiki().getNconocimientoid()); for (Consulta consulta : this.getListaTargetVinculos()) { Vinculo vinculo = new Vinculo(); vinculo.setNvinculoid(vinculoService.getNextPK()); vinculo.setNconocimientoid(this.getSelectedWiki().getNconocimientoid()); vinculo.setNconocimientovinc(consulta.getIdconocimiento()); vinculo.setNtipoconocimientovinc(consulta.getIdTipoConocimiento()); vinculo.setDfechacreacion(new Date()); vinculo.setVusuariocreacion(user.getVlogin()); vinculoService.saveOrUpdate(vinculo); TvinculoHistId vinculoHistId = new TvinculoHistId(); vinculoHistId.setNvinculohid(vinculoHistService.getNextPK()); vinculoHistId.setNconocimientoid(thistorialId.getNconocimientoid()); vinculoHistId.setNhistorialid(thistorialId.getNhistorialid()); VinculoHist vinculoHist = new VinculoHist(); vinculoHist.setId(vinculoHistId); vinculoHist.setNconocimientovinc(vinculo.getNconocimientovinc()); vinculoHist.setDfechacreacion(new Date()); vinculoHist.setVusuariocreacion(user.getVlogin()); vinculoHistService.saveOrUpdate(vinculoHist); } } this.setListaWiki(conocimientoService.getConocimientosByType(Constante.WIKI)); FacesContext.getCurrentInstance().getExternalContext().redirect("/gescon/pages/wiki/lista.xhtml"); } catch (Exception e) { e.getMessage(); e.printStackTrace(); } }
From source file:pe.gob.mef.gescon.web.ui.WikiMB.java
public void post(ActionEvent event) { try {/*from w ww .j a v a 2s . co m*/ this.setDescripcionHtml(JSFUtils.getRequestParameter("descHtml")); if (this.getSelectedCategoria() == null) { FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "ERROR.", "Categora del wiki requerida. Seleccione la categora del wiki a registrar."); FacesContext.getCurrentInstance().addMessage(null, message); return; } if (StringUtils.isBlank(this.getSelectedWiki().getVtitulo())) { FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "ERROR.", "Ttulo del wiki requerido. Ingrese el ttulo del wiki a registrar."); FacesContext.getCurrentInstance().addMessage(null, message); return; } if (StringUtils.isBlank(this.getDescripcionHtml())) { FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "ERROR.", "Descripcin del wiki requerido. Ingrese la descripcin del wiki a registrar."); FacesContext.getCurrentInstance().addMessage(null, message); return; } if (this.getSelectedWiki().getNdestacado().equals(BigDecimal.ZERO) && this.getChkDestacado()) { ConsultaService consultaService = (ConsultaService) ServiceFinder.findBean("ConsultaService"); HashMap filter = new HashMap(); filter.put("ntipoconocimientoid", Constante.WIKI); BigDecimal cant = consultaService.countDestacadosByTipoConocimiento(filter); if (cant.intValue() >= 10) { this.setListaDestacados(consultaService.getDestacadosByTipoConocimiento(filter)); RequestContext.getCurrentInstance().execute("PF('destDialog').show();"); return; } } /* Validando si exiten vnculos de bases legales derogadas */ int contador = 0; if (CollectionUtils.isNotEmpty(this.getListaTargetVinculosBL())) { for (Consulta c : this.getListaTargetVinculosBL()) { if (c.getIdEstado().toString().equals(Constante.ESTADO_BASELEGAL_DEROGADA)) { contador++; } } } LoginMB loginMB = (LoginMB) JSFUtils.getSessionAttribute("loginMB"); User user = loginMB.getUser(); ConocimientoService conocimientoService = (ConocimientoService) ServiceFinder .findBean("ConocimientoService"); this.setDescripcionPlain(Jsoup.parse(this.getDescripcionHtml()).text()); this.getSelectedWiki().setNcategoriaid(this.getSelectedCategoria().getNcategoriaid()); this.getSelectedWiki().setVtitulo(StringUtils.upperCase(this.getSelectedWiki().getVtitulo())); if (this.getDescripcionPlain().length() < 400) { this.getSelectedWiki().setVdescripcion(StringUtils.capitalize(this.getDescripcionPlain())); } else { this.getSelectedWiki() .setVdescripcion(StringUtils.capitalize(this.getDescripcionPlain().substring(0, 300))); } if (contador > 0) { this.getSelectedWiki().setNflgvinculo(BigDecimal.ONE); } else { this.getSelectedWiki().setNflgvinculo(BigDecimal.ZERO); } this.getSelectedWiki().setNdestacado(this.getChkDestacado() ? BigDecimal.ONE : BigDecimal.ZERO); this.getSelectedWiki() .setNsituacionid(BigDecimal.valueOf(Long.parseLong(Constante.SITUACION_PUBLICADO))); this.getSelectedWiki().setDfechapublicacion(new Date()); this.getSelectedWiki().setDfechamodificacion(new Date()); this.getSelectedWiki().setVusuariomodificacion(user.getVlogin()); conocimientoService.saveOrUpdate(this.getSelectedWiki()); GcmFileUtils.writeStringToFileServer(this.getSelectedWiki().getVruta(), "html.txt", this.getDescripcionHtml()); GcmFileUtils.writeStringToFileServer(this.getSelectedWiki().getVruta(), "plain.txt", this.getDescripcionPlain()); HistorialService historialService = (HistorialService) ServiceFinder.findBean("HistorialService"); Historial lastHistorial = historialService .getLastHistorialByConocimiento(this.getSelectedWiki().getNconocimientoid()); int lastversion; if (lastHistorial != null) { lastversion = lastHistorial.getNnumversion().intValue(); } else { lastversion = 0; } String url = this.path.concat(this.getSelectedWiki().getNconocimientoid().toString()).concat("/") .concat(Integer.toString(lastversion + 1)).concat("/"); ThistorialId thistorialId = new ThistorialId(); thistorialId.setNconocimientoid(this.getSelectedWiki().getNconocimientoid()); thistorialId.setNhistorialid(historialService.getNextPK()); Historial historial = new Historial(); historial.setId(thistorialId); historial.setNtipoconocimientoid(Constante.WIKI); historial.setNcategoriaid(this.getSelectedCategoria().getNcategoriaid()); historial.setVtitulo(this.getSelectedWiki().getVtitulo()); historial.setNactivo(BigDecimal.ONE); historial.setNsituacionid(this.getSelectedWiki().getNsituacionid()); historial.setVruta(url); historial.setNnumversion(BigDecimal.valueOf(lastversion + 1)); historial.setDfechacreacion(new Date()); historial.setVusuariocreacion(user.getVlogin()); historialService.saveOrUpdate(historial); GcmFileUtils.writeStringToFileServer(url, "html.txt", this.getDescripcionHtml()); GcmFileUtils.writeStringToFileServer(url, "plain.txt", this.getDescripcionPlain()); if (CollectionUtils.isNotEmpty(this.getListaSeccion())) { String url0 = this.getSelectedWiki().getVruta().concat("s"); String url1 = url.concat("s"); SeccionService seccionService = (SeccionService) ServiceFinder.findBean("SeccionService"); SeccionHistService seccionHistService = (SeccionHistService) ServiceFinder .findBean("SeccionHistService"); for (Seccion seccion : this.getListaSeccion()) { String ruta0 = url0.concat(seccion.getNorden().toString()).concat("/"); seccion.setVruta(ruta0); if (seccion.getNseccionid() != null) { seccion.setDfechamodificacion(new Date()); seccion.setVusuariomodificacion(user.getVlogin()); } else { seccion.setNseccionid(seccionService.getNextPK()); seccion.setNconocimientoid(this.getSelectedWiki().getNconocimientoid()); seccion.setDfechacreacion(new Date()); seccion.setVusuariocreacion(user.getVlogin()); } seccionService.saveOrUpdate(seccion); seccion.setDetallePlain(Jsoup.parse(seccion.getDetalleHtml()).text()); GcmFileUtils.writeStringToFileServer(ruta0, "html.txt", seccion.getDetalleHtml()); GcmFileUtils.writeStringToFileServer(ruta0, "plain.txt", seccion.getDetallePlain()); String ruta1 = url1.concat(seccion.getNorden().toString()).concat("/"); TseccionHistId tseccionHistId = new TseccionHistId(); tseccionHistId.setNconocimientoid(thistorialId.getNconocimientoid()); tseccionHistId.setNhistorialid(thistorialId.getNhistorialid()); tseccionHistId.setNseccionhid(seccionHistService.getNextPK()); SeccionHist seccionHist = new SeccionHist(); seccionHist.setId(tseccionHistId); seccionHist.setNorden(seccion.getNorden()); seccionHist.setVruta(ruta1); seccionHist.setVtitulo(seccion.getVtitulo()); seccionHist.setVusuariocreacion(user.getVlogin()); seccionHist.setDfechacreacion(new Date()); seccionHistService.saveOrUpdate(seccionHist); GcmFileUtils.writeStringToFileServer(ruta1, "html.txt", seccion.getDetalleHtml()); GcmFileUtils.writeStringToFileServer(ruta1, "plain.txt", seccion.getDetallePlain()); } } this.setListaTargetVinculos(new ArrayList()); this.getListaTargetVinculos().addAll(this.getListaTargetVinculosBL()); this.getListaTargetVinculos().addAll(this.getListaTargetVinculosBP()); this.getListaTargetVinculos().addAll(this.getListaTargetVinculosCT()); this.getListaTargetVinculos().addAll(this.getListaTargetVinculosOM()); this.getListaTargetVinculos().addAll(this.getListaTargetVinculosPR()); this.getListaTargetVinculos().addAll(this.getListaTargetVinculosWK()); if (CollectionUtils.isNotEmpty(this.getListaTargetVinculos())) { VinculoService vinculoService = (VinculoService) ServiceFinder.findBean("VinculoService"); VinculoHistService vinculoHistService = (VinculoHistService) ServiceFinder .findBean("VinculoHistService"); vinculoService.deleteByConocimiento(this.getSelectedWiki().getNconocimientoid()); for (Consulta consulta : this.getListaTargetVinculos()) { Vinculo vinculo = new Vinculo(); vinculo.setNvinculoid(vinculoService.getNextPK()); vinculo.setNconocimientoid(this.getSelectedWiki().getNconocimientoid()); vinculo.setNconocimientovinc(consulta.getIdconocimiento()); vinculo.setNtipoconocimientovinc(consulta.getIdTipoConocimiento()); vinculo.setDfechacreacion(new Date()); vinculo.setVusuariocreacion(user.getVlogin()); vinculoService.saveOrUpdate(vinculo); TvinculoHistId vinculoHistId = new TvinculoHistId(); vinculoHistId.setNvinculohid(vinculoHistService.getNextPK()); vinculoHistId.setNconocimientoid(thistorialId.getNconocimientoid()); vinculoHistId.setNhistorialid(thistorialId.getNhistorialid()); VinculoHist vinculoHist = new VinculoHist(); vinculoHist.setId(vinculoHistId); vinculoHist.setNconocimientovinc(vinculo.getNconocimientovinc()); vinculoHist.setDfechacreacion(new Date()); vinculoHist.setVusuariocreacion(user.getVlogin()); vinculoHistService.saveOrUpdate(vinculoHist); } } WikiService servicewk = (WikiService) ServiceFinder.findBean("WikiService"); List<Asignacion> listaAsignacion = servicewk.obtenerWikixAsig( this.getSelectedWiki().getNconocimientoid(), user.getNusuarioid(), Constante.WIKI); if (CollectionUtils.isNotEmpty(listaAsignacion)) { Asignacion asignacion = listaAsignacion.get(0); asignacion.setNestadoid(BigDecimal.valueOf(Long.parseLong("2"))); if (asignacion.getDfecharecepcion() == null) { asignacion.setDfecharecepcion(new Date()); } asignacion.setDfechaatencion(new Date()); asignacion.setNaccionid(BigDecimal.valueOf(Long.parseLong("8"))); AsignacionService asignacionService = (AsignacionService) ServiceFinder .findBean("AsignacionService"); asignacionService.saveOrUpdate(asignacion); } this.setListaWiki(conocimientoService.getConocimientosByType(Constante.WIKI)); FacesContext.getCurrentInstance().getExternalContext().redirect("/gescon/pages/wiki/lista.xhtml"); } catch (Exception e) { e.getMessage(); e.printStackTrace(); } }
From source file:pe.gob.mef.gescon.web.ui.BuenaPracticaMB.java
public void edit(ActionEvent event) { try {/* ww w . j a v a 2 s . com*/ this.setDescripcionHtml(JSFUtils.getRequestParameter("descHtml")); if (this.getSelectedCategoria() == null) { FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "ERROR.", "Categora del wiki requerida. Seleccione la categora del wiki a registrar."); FacesContext.getCurrentInstance().addMessage(null, message); return; } if (StringUtils.isBlank(this.getSelectedBuenaPractica().getVtitulo())) { FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "ERROR.", "Ttulo del wiki requerido. Ingrese el ttulo del wiki a registrar."); FacesContext.getCurrentInstance().addMessage(null, message); return; } if (StringUtils.isBlank(this.getDescripcionHtml())) { FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "ERROR.", "Descripcin del wiki requerido. Ingrese la descripcin del wiki a registrar."); FacesContext.getCurrentInstance().addMessage(null, message); return; } if (CollectionUtils.isEmpty(this.getListaSeccion())) { FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "ERROR.", "Ingrese al menos un (01) paso a seguir."); FacesContext.getCurrentInstance().addMessage(null, message); return; } if (this.getSelectedBuenaPractica().getNdestacado().equals(BigDecimal.ZERO) && this.getChkDestacado()) { ConsultaService consultaService = (ConsultaService) ServiceFinder.findBean("ConsultaService"); HashMap filter = new HashMap(); filter.put("ntipoconocimientoid", Constante.BUENAPRACTICA); BigDecimal cant = consultaService.countDestacadosByTipoConocimiento(filter); if (cant.intValue() >= 10) { this.setListaDestacados(consultaService.getDestacadosByTipoConocimiento(filter)); RequestContext.getCurrentInstance().execute("PF('destDialog').show();"); return; } } /* Validando si exiten vnculos de bases legales derogadas */ int contador = 0; if (CollectionUtils.isNotEmpty(this.getListaTargetVinculosBL())) { for (Consulta c : this.getListaTargetVinculosBL()) { if (c.getIdEstado().toString().equals(Constante.ESTADO_BASELEGAL_DEROGADA)) { contador++; } } } LoginMB loginMB = (LoginMB) JSFUtils.getSessionAttribute("loginMB"); User user = loginMB.getUser(); ConocimientoService conocimientoService = (ConocimientoService) ServiceFinder .findBean("ConocimientoService"); this.setDescripcionPlain(Jsoup.parse(this.getDescripcionHtml()).text()); this.getSelectedBuenaPractica().setNcategoriaid(this.getSelectedCategoria().getNcategoriaid()); this.getSelectedBuenaPractica() .setNdestacado(this.getChkDestacado() ? BigDecimal.ONE : BigDecimal.ZERO); this.getSelectedBuenaPractica() .setVtitulo(StringUtils.upperCase(this.getSelectedBuenaPractica().getVtitulo().trim())); if (this.getDescripcionPlain().length() < 400) { this.getSelectedBuenaPractica().setVdescripcion(StringUtils.capitalize(this.getDescripcionPlain())); } else { this.getSelectedBuenaPractica() .setVdescripcion(StringUtils.capitalize(this.getDescripcionPlain().substring(0, 400))); } if (contador > 0) { this.getSelectedBuenaPractica().setNflgvinculo(BigDecimal.ONE); } else { this.getSelectedBuenaPractica().setNflgvinculo(BigDecimal.ZERO); } this.getSelectedBuenaPractica().setDfechamodificacion(new Date()); this.getSelectedBuenaPractica().setVusuariomodificacion(user.getVlogin()); conocimientoService.saveOrUpdate(this.getSelectedBuenaPractica()); GcmFileUtils.writeStringToFileServer(this.getSelectedBuenaPractica().getVruta(), "html.txt", this.getDescripcionHtml()); GcmFileUtils.writeStringToFileServer(this.getSelectedBuenaPractica().getVruta(), "plain.txt", this.getDescripcionPlain()); HistorialService historialService = (HistorialService) ServiceFinder.findBean("HistorialService"); Historial lastHistorial = historialService .getLastHistorialByConocimiento(this.getSelectedBuenaPractica().getNconocimientoid()); int lastversion; if (lastHistorial != null) { lastversion = lastHistorial.getNnumversion().intValue(); } else { lastversion = 0; } String url = this.path.concat(this.getSelectedBuenaPractica().getNconocimientoid().toString()) .concat("/").concat(Integer.toString(lastversion + 1)).concat("/"); ThistorialId thistorialId = new ThistorialId(); thistorialId.setNconocimientoid(this.getSelectedBuenaPractica().getNconocimientoid()); thistorialId.setNhistorialid(historialService.getNextPK()); Historial historial = new Historial(); historial.setId(thistorialId); historial.setNtipoconocimientoid(Constante.WIKI); historial.setNcategoriaid(this.getSelectedCategoria().getNcategoriaid()); historial.setVtitulo(this.getSelectedBuenaPractica().getVtitulo()); historial.setNactivo(BigDecimal.ONE); historial.setNsituacionid(this.getSelectedBuenaPractica().getNsituacionid()); historial.setVruta(url); historial.setNnumversion(BigDecimal.valueOf(lastversion + 1)); historial.setDfechacreacion(new Date()); historial.setVusuariocreacion(user.getVlogin()); historialService.saveOrUpdate(historial); GcmFileUtils.writeStringToFileServer(url, "html.txt", this.getDescripcionHtml()); GcmFileUtils.writeStringToFileServer(url, "plain.txt", this.getDescripcionPlain()); if (CollectionUtils.isNotEmpty(this.getListaSeccion())) { String url0 = this.getSelectedBuenaPractica().getVruta().concat("s"); String url1 = url.concat("s"); SeccionService seccionService = (SeccionService) ServiceFinder.findBean("SeccionService"); SeccionHistService seccionHistService = (SeccionHistService) ServiceFinder .findBean("SeccionHistService"); for (Seccion seccion : this.getListaSeccion()) { String ruta0 = url0.concat(seccion.getNorden().toString()).concat("/"); seccion.setVruta(ruta0); if (seccion.getNseccionid() != null) { seccion.setDfechamodificacion(new Date()); seccion.setVusuariomodificacion(user.getVlogin()); } else { seccion.setNseccionid(seccionService.getNextPK()); seccion.setNconocimientoid(this.getSelectedBuenaPractica().getNconocimientoid()); seccion.setDfechacreacion(new Date()); seccion.setVusuariocreacion(user.getVlogin()); } seccionService.saveOrUpdate(seccion); seccion.setDetallePlain(Jsoup.parse(seccion.getDetalleHtml()).text()); GcmFileUtils.writeStringToFileServer(ruta0, "html.txt", seccion.getDetalleHtml()); GcmFileUtils.writeStringToFileServer(ruta0, "plain.txt", seccion.getDetallePlain()); String ruta1 = url1.concat(seccion.getNorden().toString()).concat("/"); TseccionHistId tseccionHistId = new TseccionHistId(); tseccionHistId.setNconocimientoid(thistorialId.getNconocimientoid()); tseccionHistId.setNhistorialid(thistorialId.getNhistorialid()); tseccionHistId.setNseccionhid(seccionHistService.getNextPK()); SeccionHist seccionHist = new SeccionHist(); seccionHist.setId(tseccionHistId); seccionHist.setNorden(seccion.getNorden()); seccionHist.setVruta(ruta1); seccionHist.setVtitulo(seccion.getVtitulo()); seccionHist.setVusuariocreacion(user.getVlogin()); seccionHist.setDfechacreacion(new Date()); seccionHistService.saveOrUpdate(seccionHist); GcmFileUtils.writeStringToFileServer(ruta1, "html.txt", seccion.getDetalleHtml()); GcmFileUtils.writeStringToFileServer(ruta1, "plain.txt", seccion.getDetallePlain()); } } this.setListaTargetVinculos(new ArrayList()); this.getListaTargetVinculos().addAll(this.getListaTargetVinculosBL()); this.getListaTargetVinculos().addAll(this.getListaTargetVinculosBP()); this.getListaTargetVinculos().addAll(this.getListaTargetVinculosCT()); this.getListaTargetVinculos().addAll(this.getListaTargetVinculosOM()); this.getListaTargetVinculos().addAll(this.getListaTargetVinculosPR()); this.getListaTargetVinculos().addAll(this.getListaTargetVinculosWK()); if (CollectionUtils.isNotEmpty(this.getListaTargetVinculos())) { VinculoService vinculoService = (VinculoService) ServiceFinder.findBean("VinculoService"); VinculoHistService vinculoHistService = (VinculoHistService) ServiceFinder .findBean("VinculoHistService"); vinculoService.deleteByConocimiento(this.getSelectedBuenaPractica().getNconocimientoid()); for (Consulta consulta : this.getListaTargetVinculos()) { Vinculo vinculo = new Vinculo(); vinculo.setNvinculoid(vinculoService.getNextPK()); vinculo.setNconocimientoid(this.getSelectedBuenaPractica().getNconocimientoid()); vinculo.setNconocimientovinc(consulta.getIdconocimiento()); vinculo.setNtipoconocimientovinc(consulta.getIdTipoConocimiento()); vinculo.setDfechacreacion(new Date()); vinculo.setVusuariocreacion(user.getVlogin()); vinculoService.saveOrUpdate(vinculo); TvinculoHistId vinculoHistId = new TvinculoHistId(); vinculoHistId.setNvinculohid(vinculoHistService.getNextPK()); vinculoHistId.setNconocimientoid(thistorialId.getNconocimientoid()); vinculoHistId.setNhistorialid(thistorialId.getNhistorialid()); VinculoHist vinculoHist = new VinculoHist(); vinculoHist.setId(vinculoHistId); vinculoHist.setNconocimientovinc(vinculo.getNconocimientovinc()); vinculoHist.setDfechacreacion(new Date()); vinculoHist.setVusuariocreacion(user.getVlogin()); vinculoHistService.saveOrUpdate(vinculoHist); } } this.setListaBuenaPractica(conocimientoService.getConocimientosByType(Constante.BUENAPRACTICA)); FacesContext.getCurrentInstance().getExternalContext() .redirect("/gescon/pages/buenapractica/lista.xhtml"); } catch (Exception e) { e.getMessage(); e.printStackTrace(); } }
From source file:com.citrix.cpbm.portal.fragment.controllers.AbstractTenantController.java
/** * deletes subscription/*from www . j a va 2 s.c om*/ * * @param subscriptionId * @param map which is to be filled by method. Contains all the UI accessible variables as an attribute * @param form * @param result * @return */ @ResponseBody @RequestMapping(value = "/alerts/edit", method = RequestMethod.POST) public SpendAlertSubscription editSpendAlertSubscription( @RequestParam(value = "Id", required = true) String subscriptionId, @RequestParam(value = "newValue", required = true) String newVal, @ModelAttribute("subscriptionForm") CustomAlertForm form, BindingResult result, ModelMap map, HttpServletRequest request) { logger.debug("###Entering editSubscription method @POST"); SpendAlertSubscription subscription = notificationService .getSpendAlertSubscription(new Long(subscriptionId)); if (newVal == null) { result.rejectValue("tenantPercentage", "js.errors.tenantPercentage.required"); throw new AjaxFormValidationException(result); } BigDecimal percentage = new BigDecimal(newVal); if ((percentage.intValue() < 0) || (percentage.intValue() > 100)) { result.rejectValue("tenantPercentage", "js.errors.tenantPercentage.percentage"); throw new AjaxFormValidationException(result); } Tenant effectiveTenant = (Tenant) request.getAttribute(UserContextInterceptor.EFFECTIVE_TENANT_KEY); form.setTenantPercentage(new BigDecimal(newVal)); if (effectiveTenant != null) { List<SpendAlertSubscription> spendAlertSubscription = notificationService .getAllSubscriptions(effectiveTenant); if (CollectionUtils.isNotEmpty(spendAlertSubscription)) { for (SpendAlertSubscription spendAlertSubscription2 : spendAlertSubscription) { if (spendAlertSubscription2.getPercentage().doubleValue() == form.getTenantPercentage() .doubleValue()) { result.rejectValue("tenantPercentage", "js.errors.tenantPercentage.validatePercentage"); throw new AjaxFormValidationException(result); } } } } subscription.setPercentage(percentage); subscription = notificationService.saveSubscription(subscription); logger.debug("###Leaving editSubscription method @POST"); return subscription; }
From source file:pe.gob.mef.gescon.web.ui.BuenaPracticaMB.java
public void post(ActionEvent event) { try {//from w w w.j a va 2 s.c o m this.setDescripcionHtml(JSFUtils.getRequestParameter("descHtml")); if (this.getSelectedCategoria() == null) { FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "ERROR.", "Categora del wiki requerida. Seleccione la categora del wiki a registrar."); FacesContext.getCurrentInstance().addMessage(null, message); return; } if (StringUtils.isBlank(this.getSelectedBuenaPractica().getVtitulo())) { FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "ERROR.", "Ttulo del wiki requerido. Ingrese el ttulo del wiki a registrar."); FacesContext.getCurrentInstance().addMessage(null, message); return; } if (StringUtils.isBlank(this.getDescripcionHtml())) { FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "ERROR.", "Descripcin del wiki requerido. Ingrese la descripcin del wiki a registrar."); FacesContext.getCurrentInstance().addMessage(null, message); return; } if (CollectionUtils.isEmpty(this.getListaSeccion())) { FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "ERROR.", "Ingrese al menos un (01) paso a seguir."); FacesContext.getCurrentInstance().addMessage(null, message); return; } if (this.getSelectedBuenaPractica().getNdestacado().equals(BigDecimal.ZERO) && this.getChkDestacado()) { ConsultaService consultaService = (ConsultaService) ServiceFinder.findBean("ConsultaService"); HashMap filter = new HashMap(); filter.put("ntipoconocimientoid", Constante.BUENAPRACTICA); BigDecimal cant = consultaService.countDestacadosByTipoConocimiento(filter); if (cant.intValue() >= 10) { this.setListaDestacados(consultaService.getDestacadosByTipoConocimiento(filter)); RequestContext.getCurrentInstance().execute("PF('destDialog').show();"); return; } } int contador = 0; if (CollectionUtils.isNotEmpty(this.getListaTargetVinculosBL())) { for (Consulta c : this.getListaTargetVinculosBL()) { if (c.getIdEstado().toString().equals(Constante.ESTADO_BASELEGAL_DEROGADA)) { contador++; } } } LoginMB loginMB = (LoginMB) JSFUtils.getSessionAttribute("loginMB"); User user = loginMB.getUser(); ConocimientoService conocimientoService = (ConocimientoService) ServiceFinder .findBean("ConocimientoService"); this.setDescripcionPlain(Jsoup.parse(this.getDescripcionHtml()).text()); this.getSelectedBuenaPractica().setNcategoriaid(this.getSelectedCategoria().getNcategoriaid()); this.getSelectedBuenaPractica() .setNdestacado(this.getChkDestacado() ? BigDecimal.ONE : BigDecimal.ZERO); this.getSelectedBuenaPractica() .setNsituacionid(BigDecimal.valueOf(Long.parseLong(Constante.SITUACION_PUBLICADO))); this.getSelectedBuenaPractica() .setVtitulo(StringUtils.upperCase(this.getSelectedBuenaPractica().getVtitulo().trim())); if (this.getDescripcionPlain().length() < 400) { this.getSelectedBuenaPractica().setVdescripcion(StringUtils.capitalize(this.getDescripcionPlain())); } else { this.getSelectedBuenaPractica() .setVdescripcion(StringUtils.capitalize(this.getDescripcionPlain().substring(0, 400))); } if (contador > 0) { this.getSelectedBuenaPractica().setNflgvinculo(BigDecimal.ONE); } else { this.getSelectedBuenaPractica().setNflgvinculo(BigDecimal.ZERO); } this.getSelectedBuenaPractica().setDfechapublicacion(new Date()); this.getSelectedBuenaPractica().setDfechamodificacion(new Date()); this.getSelectedBuenaPractica().setVusuariomodificacion(user.getVlogin()); conocimientoService.saveOrUpdate(this.getSelectedBuenaPractica()); GcmFileUtils.writeStringToFileServer(this.getSelectedBuenaPractica().getVruta(), "html.txt", this.getDescripcionHtml()); GcmFileUtils.writeStringToFileServer(this.getSelectedBuenaPractica().getVruta(), "plain.txt", this.getDescripcionPlain()); HistorialService historialService = (HistorialService) ServiceFinder.findBean("HistorialService"); Historial lastHistorial = historialService .getLastHistorialByConocimiento(this.getSelectedBuenaPractica().getNconocimientoid()); int lastversion; if (lastHistorial != null) { lastversion = lastHistorial.getNnumversion().intValue(); } else { lastversion = 0; } String url = this.path.concat(this.getSelectedBuenaPractica().getNconocimientoid().toString()) .concat("/").concat(Integer.toString(lastversion + 1)).concat("/"); ThistorialId thistorialId = new ThistorialId(); thistorialId.setNconocimientoid(this.getSelectedBuenaPractica().getNconocimientoid()); thistorialId.setNhistorialid(historialService.getNextPK()); Historial historial = new Historial(); historial.setId(thistorialId); historial.setNtipoconocimientoid(Constante.WIKI); historial.setNcategoriaid(this.getSelectedCategoria().getNcategoriaid()); historial.setVtitulo(this.getSelectedBuenaPractica().getVtitulo()); historial.setNactivo(BigDecimal.ONE); historial.setNsituacionid(this.getSelectedBuenaPractica().getNsituacionid()); historial.setVruta(url); historial.setNnumversion(BigDecimal.valueOf(lastversion + 1)); historial.setDfechacreacion(new Date()); historial.setVusuariocreacion(user.getVlogin()); historialService.saveOrUpdate(historial); GcmFileUtils.writeStringToFileServer(url, "html.txt", this.getDescripcionHtml()); GcmFileUtils.writeStringToFileServer(url, "plain.txt", this.getDescripcionPlain()); if (CollectionUtils.isNotEmpty(this.getListaSeccion())) { String url0 = this.getSelectedBuenaPractica().getVruta().concat("s"); String url1 = url.concat("s"); SeccionService seccionService = (SeccionService) ServiceFinder.findBean("SeccionService"); SeccionHistService seccionHistService = (SeccionHistService) ServiceFinder .findBean("SeccionHistService"); for (Seccion seccion : this.getListaSeccion()) { String ruta0 = url0.concat(seccion.getNorden().toString()).concat("/"); seccion.setVruta(ruta0); if (seccion.getNseccionid() != null) { seccion.setDfechamodificacion(new Date()); seccion.setVusuariomodificacion(user.getVlogin()); } else { seccion.setNseccionid(seccionService.getNextPK()); seccion.setNconocimientoid(this.getSelectedBuenaPractica().getNconocimientoid()); seccion.setDfechacreacion(new Date()); seccion.setVusuariocreacion(user.getVlogin()); } seccionService.saveOrUpdate(seccion); seccion.setDetallePlain(Jsoup.parse(seccion.getDetalleHtml()).text()); GcmFileUtils.writeStringToFileServer(ruta0, "html.txt", seccion.getDetalleHtml()); GcmFileUtils.writeStringToFileServer(ruta0, "plain.txt", seccion.getDetallePlain()); String ruta1 = url1.concat(seccion.getNorden().toString()).concat("/"); TseccionHistId tseccionHistId = new TseccionHistId(); tseccionHistId.setNconocimientoid(thistorialId.getNconocimientoid()); tseccionHistId.setNhistorialid(thistorialId.getNhistorialid()); tseccionHistId.setNseccionhid(seccionHistService.getNextPK()); SeccionHist seccionHist = new SeccionHist(); seccionHist.setId(tseccionHistId); seccionHist.setNorden(seccion.getNorden()); seccionHist.setVruta(ruta1); seccionHist.setVtitulo(seccion.getVtitulo()); seccionHist.setVusuariocreacion(user.getVlogin()); seccionHist.setDfechacreacion(new Date()); seccionHistService.saveOrUpdate(seccionHist); GcmFileUtils.writeStringToFileServer(ruta1, "html.txt", seccion.getDetalleHtml()); GcmFileUtils.writeStringToFileServer(ruta1, "plain.txt", seccion.getDetallePlain()); } } this.setListaTargetVinculos(new ArrayList()); this.getListaTargetVinculos().addAll(this.getListaTargetVinculosBL()); this.getListaTargetVinculos().addAll(this.getListaTargetVinculosBP()); this.getListaTargetVinculos().addAll(this.getListaTargetVinculosCT()); this.getListaTargetVinculos().addAll(this.getListaTargetVinculosOM()); this.getListaTargetVinculos().addAll(this.getListaTargetVinculosPR()); this.getListaTargetVinculos().addAll(this.getListaTargetVinculosWK()); if (CollectionUtils.isNotEmpty(this.getListaTargetVinculos())) { VinculoService vinculoService = (VinculoService) ServiceFinder.findBean("VinculoService"); VinculoHistService vinculoHistService = (VinculoHistService) ServiceFinder .findBean("VinculoHistService"); vinculoService.deleteByConocimiento(this.getSelectedBuenaPractica().getNconocimientoid()); for (Consulta consulta : this.getListaTargetVinculos()) { Vinculo vinculo = new Vinculo(); vinculo.setNvinculoid(vinculoService.getNextPK()); vinculo.setNconocimientoid(this.getSelectedBuenaPractica().getNconocimientoid()); vinculo.setNconocimientovinc(consulta.getIdconocimiento()); vinculo.setNtipoconocimientovinc(consulta.getIdTipoConocimiento()); vinculo.setDfechacreacion(new Date()); vinculo.setVusuariocreacion(user.getVlogin()); vinculoService.saveOrUpdate(vinculo); TvinculoHistId vinculoHistId = new TvinculoHistId(); vinculoHistId.setNvinculohid(vinculoHistService.getNextPK()); vinculoHistId.setNconocimientoid(thistorialId.getNconocimientoid()); vinculoHistId.setNhistorialid(thistorialId.getNhistorialid()); VinculoHist vinculoHist = new VinculoHist(); vinculoHist.setId(vinculoHistId); vinculoHist.setNconocimientovinc(vinculo.getNconocimientovinc()); vinculoHist.setDfechacreacion(new Date()); vinculoHist.setVusuariocreacion(user.getVlogin()); vinculoHistService.saveOrUpdate(vinculoHist); } } AsignacionService asignacionService = (AsignacionService) ServiceFinder.findBean("AsignacionService"); List<Asignacion> listaAsignacion = conocimientoService.obtenerBpracticaxAsig( this.getSelectedBuenaPractica().getNconocimientoid(), user.getNusuarioid(), Constante.BUENAPRACTICA); if (CollectionUtils.isNotEmpty(listaAsignacion)) { Asignacion asignacion = listaAsignacion.get(0); asignacion.setNestadoid(BigDecimal.valueOf(Long.parseLong("2"))); if (asignacion.getDfecharecepcion() == null) { asignacion.setDfecharecepcion(new Date()); } asignacion.setDfechaatencion(new Date()); asignacion.setNaccionid(BigDecimal.valueOf(Long.parseLong("8"))); asignacionService.saveOrUpdate(asignacion); } this.setListaBuenaPractica(conocimientoService.getConocimientosByType(Constante.BUENAPRACTICA)); FacesContext.getCurrentInstance().getExternalContext() .redirect("/gescon/pages/buenapractica/lista.xhtml"); } catch (Exception e) { e.getMessage(); e.printStackTrace(); } }
From source file:com.osafe.events.CheckOutEvents.java
public static String setShipGroups(HttpServletRequest request, HttpServletResponse response) { LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher"); Delegator delegator = (Delegator) request.getAttribute("delegator"); Locale locale = UtilHttp.getLocale(request); ShoppingCart shoppingCart = ShoppingCartEvents.getCartObject(request); String sItemTotalQty = request.getParameter("itemTotalQuantity"); String sNumberOfItems = request.getParameter("numberOfItems"); int iNumberOfItems = Integer.valueOf(sNumberOfItems); int iItemTotalQty = 0; BigDecimal bcartItemTotalQty = shoppingCart.getTotalQuantity(); Map shippingContactMechMap = FastMap.newInstance(); Map cartLineShippingContactMechQtyMap = FastMap.newInstance(); Map cartLineShippingContactMechGiftMsgMap = FastMap.newInstance(); Map cartLineQtyMap = FastMap.newInstance(); Map cartLineProductInfoMap = FastMap.newInstance(); Map cartItemQtyMap = FastMap.newInstance(); List<MessageString> error_list = new ArrayList<MessageString>(); MessageString messageString = null;/*from ww w .ja v a2s .c o m*/ String message = null; if (UtilValidate.isNotEmpty(sItemTotalQty)) { iItemTotalQty = Integer.valueOf(sItemTotalQty).intValue(); } /* Build quantity-product maps based on items on page */ for (int i = 0; i < iItemTotalQty; i++) { String shippingContactMechId = request.getParameter("shippingContactMechId_" + i); String sCartLineIndex = request.getParameter("cartLineIndex_" + i); int iCartLineIndex = Integer.valueOf(sCartLineIndex).intValue(); String qtyInCart = request.getParameter("qtyInCart_" + i); String productName = request.getParameter("productName_" + i); String productId = request.getParameter("productId_" + i); String productCategoryId = request.getParameter("productCategoryId_" + i); String prodCatalogId = request.getParameter("prodCatelogId_" + i); String unitPrice = request.getParameter("unitPrice_" + i); Map productInfoMap = FastMap.newInstance(); productInfoMap.put("productName", productName); productInfoMap.put("productId", productId); productInfoMap.put("productCategoryId", productCategoryId); productInfoMap.put("prodCatalogId", prodCatalogId); productInfoMap.put("unitPrice", unitPrice); String giftMsgFrom = request.getParameter("lineItemGiftFrom_" + i); String giftMsgTo = request.getParameter("lineItemGiftTo_" + i); String giftMsg = request.getParameter("lineItemGiftMsg_" + i); Map giftMessageInfoMap = FastMap.newInstance(); if (UtilValidate.isNotEmpty(giftMsgFrom)) { giftMessageInfoMap.put("from", giftMsgFrom); } if (UtilValidate.isNotEmpty(giftMsgTo)) { giftMessageInfoMap.put("to", giftMsgTo); } if (UtilValidate.isNotEmpty(giftMsg)) { giftMessageInfoMap.put("msg", giftMsg); } BigDecimal bLineQty = BigDecimal.ZERO; BigDecimal bShipQty = BigDecimal.ZERO; BigDecimal bCartQty = BigDecimal.ZERO; try { if (UtilValidate.isNotEmpty(qtyInCart)) { Double dQty = Double.valueOf(qtyInCart); if (UtilValidate.isInteger(qtyInCart) && dQty >= 0) { bLineQty = BigDecimal.valueOf(dQty.doubleValue()); } else { bLineQty = BigDecimal.ZERO; message = OSAFE_UI_LABELS.getString("PDPQtyDecimalNumberError"); message = StringUtil.replaceString(message, "_PRODUCT_NAME_", productName); messageString = new MessageString(message, "qtyInCart_" + i, true); error_list.add(messageString); } } } catch (Exception e) { bLineQty = BigDecimal.ZERO; message = OSAFE_UI_LABELS.getString("PDPQtyDecimalNumberError"); message = StringUtil.replaceString(message, "_PRODUCT_NAME_", productName); messageString = new MessageString(message, "qtyInCart_" + i, true); error_list.add(messageString); } shippingContactMechMap.put(shippingContactMechId, shippingContactMechId); if (cartLineShippingContactMechQtyMap.containsKey(sCartLineIndex + "_" + shippingContactMechId)) { BigDecimal bTempQty = (BigDecimal) cartLineShippingContactMechQtyMap .get(sCartLineIndex + "_" + shippingContactMechId); bShipQty = bShipQty.add(bTempQty); } bShipQty = bShipQty.add(bLineQty); cartLineShippingContactMechQtyMap.put(sCartLineIndex + "_" + shippingContactMechId, bShipQty); if (UtilValidate.isNotEmpty(giftMessageInfoMap)) { List lGiftMsg = null; if (cartLineShippingContactMechGiftMsgMap .containsKey(sCartLineIndex + "_" + shippingContactMechId)) { lGiftMsg = (List) cartLineShippingContactMechGiftMsgMap .get(sCartLineIndex + "_" + shippingContactMechId); } else { lGiftMsg = FastList.newInstance(); } lGiftMsg.add(giftMessageInfoMap); cartLineShippingContactMechGiftMsgMap.put(sCartLineIndex + "_" + shippingContactMechId, lGiftMsg); } if (cartLineQtyMap.containsKey(sCartLineIndex)) { BigDecimal bTempQty = (BigDecimal) cartLineQtyMap.get(sCartLineIndex); bCartQty = bCartQty.add(bTempQty); } bCartQty = bCartQty.add(bLineQty); cartLineQtyMap.put(sCartLineIndex, bCartQty); cartLineProductInfoMap.put(sCartLineIndex, productInfoMap); } /* Validate Quantities entered */ if (UtilValidate.isNotEmpty(cartLineQtyMap)) { try { String pdpQtyMin = Util.getProductStoreParm(request, "PDP_QTY_MIN"); if (UtilValidate.isEmpty(pdpQtyMin)) { pdpQtyMin = "1"; } String pdpQtyMax = Util.getProductStoreParm(request, "PDP_QTY_MAX"); if (UtilValidate.isEmpty(pdpQtyMax)) { pdpQtyMax = "99"; } BigDecimal bPdpQtyMin = BigDecimal.valueOf(Double.valueOf(pdpQtyMin).doubleValue()); BigDecimal bPdpQtyMax = BigDecimal.valueOf(Double.valueOf(pdpQtyMax).doubleValue()); Iterator<String> cartItemIter = cartLineQtyMap.keySet().iterator(); while (cartItemIter.hasNext()) { String sCartLineIndex = cartItemIter.next(); BigDecimal bChangeQty = (BigDecimal) cartLineQtyMap.get(sCartLineIndex); if (bChangeQty.compareTo(BigDecimal.ZERO) == 0) { continue; } int iCartLineIndex = Integer.valueOf(sCartLineIndex).intValue(); Map productInfoMap = (Map) cartLineProductInfoMap.get(sCartLineIndex); GenericValue prodPdpQtyMin = delegator.findOne("ProductAttribute", UtilMisc.toMap("productId", productInfoMap.get("productId"), "attrName", "PDP_QTY_MIN"), true); GenericValue prodPdpQtyMax = delegator.findOne("ProductAttribute", UtilMisc.toMap("productId", productInfoMap.get("productId"), "attrName", "PDP_QTY_MAX"), true); if (UtilValidate.isNotEmpty(prodPdpQtyMin) && UtilValidate.isNotEmpty(prodPdpQtyMax)) { bPdpQtyMin = BigDecimal .valueOf(Double.valueOf(prodPdpQtyMin.getString("attrValue")).doubleValue()); bPdpQtyMax = BigDecimal .valueOf(Double.valueOf(prodPdpQtyMax.getString("attrValue")).doubleValue()); } if (bChangeQty.compareTo(bPdpQtyMin) < 0) { message = OSAFE_UI_LABELS.getString("PDPMinQtyError"); message = StringUtil.replaceString(message, "_PRODUCT_NAME_", "" + productInfoMap.get("productName")); message = StringUtil.replaceString(message, "_PDP_QTY_MIN_", "" + bPdpQtyMin.intValue()); messageString = new MessageString(message, "qtyInCart_" + sCartLineIndex, true); error_list.add(messageString); } if (bChangeQty.compareTo(bPdpQtyMax) > 0) { message = OSAFE_UI_LABELS.getString("PDPMaxQtyError"); message = StringUtil.replaceString(message, "_PRODUCT_NAME_", "" + productInfoMap.get("productName")); message = StringUtil.replaceString(message, "_PDP_QTY_MAX_", "" + bPdpQtyMax.intValue()); messageString = new MessageString(message, "qtyInCart_" + sCartLineIndex, true); error_list.add(messageString); } } } catch (Exception e) { Debug.logError(e, "Error: updating cart quantity", module); } } if (error_list.size() != 0) { request.setAttribute("_ERROR_MESSAGE_LIST_", error_list); return "error"; } /* Check the number of items passed from the screen matches the number of items in the cart. * If the number of items has changed remove all products from the cart and add back. * If the number of items have not changed remove zero quantities and set changed item quantities * The number of item check is essentially protecting against the usage of the back button. */ if (UtilValidate.isNotEmpty(cartLineQtyMap)) { if (shoppingCart.items().size() != iNumberOfItems) { ShoppingCartItem shoppingCartItem = null; try { Iterator<ShoppingCartItem> cartItemIter = shoppingCart.items().iterator(); while (cartItemIter.hasNext()) { shoppingCartItem = (ShoppingCartItem) cartItemIter.next(); shoppingCart.removeCartItem(shoppingCartItem, dispatcher); } Iterator<String> cartLineItemIter = cartLineQtyMap.keySet().iterator(); while (cartLineItemIter.hasNext()) { String sCartLineIndex = cartLineItemIter.next(); BigDecimal bChangeQty = (BigDecimal) cartLineQtyMap.get(sCartLineIndex); if (bChangeQty.compareTo(BigDecimal.ZERO) == 0) { continue; } Map productInfoMap = (Map) cartLineProductInfoMap.get(sCartLineIndex); String unitPrice = (String) productInfoMap.get("unitPrice"); BigDecimal bUnitPrice = null; if (UtilValidate.isNotEmpty(unitPrice)) { bUnitPrice = BigDecimal.valueOf(Double.valueOf(unitPrice).doubleValue()); } if (UtilValidate.isEmpty(bUnitPrice)) { message = OSAFE_UI_LABELS.getString("PDPMaxQtyError"); error_list.add(messageString); request.setAttribute("_ERROR_MESSAGE_LIST_", error_list); return "error"; } ShoppingCartItem item = ShoppingCartItem.makeItem(null, "" + productInfoMap.get("productId"), null, bChangeQty, bUnitPrice, null, null, null, null, null, null, null, null, null, "" + productInfoMap.get("prodCatelogId"), null, null, null, dispatcher, shoppingCart, Boolean.TRUE, Boolean.FALSE, "" + productInfoMap.get("parentProductId"), Boolean.TRUE, Boolean.TRUE); shoppingCart.addItemToEnd(item); com.osafe.events.ShoppingCartEvents.setProductFeaturesOnCart(shoppingCart, "" + productInfoMap.get("productId")); } } catch (Exception e) { Debug.logError("Error: removing cart item" + shoppingCartItem, module); } } else { try { Iterator<String> cartItemIter = cartLineQtyMap.keySet().iterator(); while (cartItemIter.hasNext()) { String sCartLineIndex = cartItemIter.next(); BigDecimal bChangeQty = (BigDecimal) cartLineQtyMap.get(sCartLineIndex); int iCartLineIndex = Integer.valueOf(sCartLineIndex).intValue(); ShoppingCartItem shoppingCartItem = shoppingCart.findCartItem(iCartLineIndex); if (bChangeQty.compareTo(BigDecimal.ZERO) == 0) { shoppingCart.removeCartItem(shoppingCartItem, dispatcher); continue; } if (bChangeQty.compareTo(shoppingCartItem.getQuantity()) != 0) { shoppingCartItem.setQuantity(bChangeQty, dispatcher, shoppingCart); } } } catch (Exception e) { Debug.logError("Error: updating cart quantity", module); } } } if (UtilValidate.isNotEmpty(shoppingCart.items())) { Iterator<ShoppingCartItem> cartItemIter = shoppingCart.items().iterator(); int iItemIndex = 0; while (cartItemIter.hasNext()) { ShoppingCartItem shoppingCartItem = (ShoppingCartItem) cartItemIter.next(); BigDecimal itemQuantity = shoppingCartItem.getQuantity(); cartItemQtyMap.put("" + iItemIndex, itemQuantity); iItemIndex++; /* Clear Gift Messages per item. Will be Reset * */ Map<String, String> orderItemAttributesMap = shoppingCartItem.getOrderItemAttributes(); if (UtilValidate.isNotEmpty(orderItemAttributesMap)) { for (Entry<String, String> itemAttr : orderItemAttributesMap.entrySet()) { String sAttrName = (String) itemAttr.getKey(); if (sAttrName.startsWith("GIFT_MSG_FROM_")) { shoppingCartItem.removeOrderItemAttribute(sAttrName); } if (sAttrName.startsWith("GIFT_MSG_TO_")) { shoppingCartItem.removeOrderItemAttribute(sAttrName); } if (sAttrName.startsWith("GIFT_MSG_TEXT_")) { shoppingCartItem.removeOrderItemAttribute(sAttrName); } } } } } else { return "emptyCart"; } /* Clear item Ship Groups and create new ones */ if (UtilValidate.isNotEmpty(shippingContactMechMap)) { Iterator<ShoppingCartItem> cartItemIter = shoppingCart.items().iterator(); while (cartItemIter.hasNext()) { shoppingCart.clearItemShipInfo(cartItemIter.next()); } shoppingCart.cleanUpShipGroups(); Iterator<String> shipGroupIter = shippingContactMechMap.keySet().iterator(); while (shipGroupIter.hasNext()) { int shipGroupIndex = shoppingCart.addShipInfo(); String shippingContactMechId = shipGroupIter.next(); shoppingCart.setShippingContactMechId(shipGroupIndex, shippingContactMechId); shippingContactMechMap.put(shippingContactMechId, Integer.valueOf(shipGroupIndex)); } } if (UtilValidate.isNotEmpty(cartLineShippingContactMechQtyMap)) { Map<ShoppingCartItem, String> cartItemMessageCount = FastMap.newInstance(); Iterator<String> cartLineShippingQtyIter = cartLineShippingContactMechQtyMap.keySet().iterator(); while (cartLineShippingQtyIter.hasNext()) { String cartLineShippingContactMechKey = cartLineShippingQtyIter.next(); int iKeySeparator = cartLineShippingContactMechKey.indexOf('_'); String sCartLineIndex = cartLineShippingContactMechKey.substring(0, iKeySeparator); int iCartLineIndex = Integer.valueOf(sCartLineIndex); int iItemGiftMsgCount = 0; String shippingContactMechId = cartLineShippingContactMechKey.substring(iKeySeparator + 1); BigDecimal bShipQty = (BigDecimal) cartLineShippingContactMechQtyMap .get(cartLineShippingContactMechKey); BigDecimal bCartItemQty = (BigDecimal) cartItemQtyMap.get(sCartLineIndex); BigDecimal bCartQty = BigDecimal.ZERO; if (UtilValidate.isNotEmpty(bCartItemQty)) { bCartQty = bCartItemQty; } BigDecimal bTotalShipGroupQty = BigDecimal.ZERO; BigDecimal bAddShipQty = BigDecimal.ZERO; if (bShipQty.compareTo(BigDecimal.ZERO) > 0) { Map shipGroupQtyMap = shoppingCart.getShipGroups(iCartLineIndex); Iterator shipGroupQtyIter = shipGroupQtyMap.keySet().iterator(); while (shipGroupQtyIter.hasNext()) { BigDecimal bShipGroupQty = (BigDecimal) shipGroupQtyMap.get(shipGroupQtyIter.next()); bTotalShipGroupQty = bTotalShipGroupQty.add(bShipGroupQty); } /* Total quantity designated to Ship has already been met */ if (bTotalShipGroupQty.compareTo(bCartQty) == 0) { continue; } /* If the ship quantity is greater than the quantity in the cart, set the ship quantity equal to cart quantity. */ if (bShipQty.compareTo(bCartQty) > 0) { bShipQty = bCartQty; } /* Add the Ship quantity to total ship quantity, If greater set the ship quantity to the quantity left that can be shipped * (cart quantity minus total ship quantity) */ bAddShipQty = bShipQty.add(bTotalShipGroupQty); if (bAddShipQty.compareTo(bCartQty) > 0) { bShipQty = bCartQty.subtract(bTotalShipGroupQty); } if (bShipQty.compareTo(BigDecimal.ZERO) > 0) { int shipGroupIndex = ((Integer) shippingContactMechMap.get(shippingContactMechId)) .intValue(); shoppingCart.setItemShipGroupQty(iCartLineIndex, bShipQty, shipGroupIndex); /* Check Cart item Gift Messages going to this Ship Group (Address) * */ List lGiftMsg = (List) cartLineShippingContactMechGiftMsgMap .get(cartLineShippingContactMechKey); if (UtilValidate.isNotEmpty(lGiftMsg)) { ShoppingCartItem cartItem = shoppingCart.findCartItem(iCartLineIndex); for (int i = 0; i < lGiftMsg.size(); i++) { if (i > bShipQty.intValue()) { break; } String sItemGiftMsgCount = (String) cartItemMessageCount.get(cartItem); if (UtilValidate.isEmpty(sItemGiftMsgCount)) { iItemGiftMsgCount = 1; } else { iItemGiftMsgCount = Integer.valueOf(sItemGiftMsgCount); iItemGiftMsgCount++; } sItemGiftMsgCount = "" + iItemGiftMsgCount; cartItemMessageCount.put(cartItem, sItemGiftMsgCount); Map giftMsgMap = (Map) lGiftMsg.get(i); String msgFrom = (String) giftMsgMap.get("from"); if (UtilValidate.isNotEmpty(msgFrom)) { cartItem.setOrderItemAttribute( "GIFT_MSG_FROM_" + sItemGiftMsgCount + "_" + (shipGroupIndex + 1), msgFrom); } String msgTo = (String) giftMsgMap.get("to"); if (UtilValidate.isNotEmpty(msgTo)) { cartItem.setOrderItemAttribute( "GIFT_MSG_TO_" + sItemGiftMsgCount + "_" + (shipGroupIndex + 1), msgTo); } String msg = (String) giftMsgMap.get("msg"); if (UtilValidate.isNotEmpty(msg)) { cartItem.setOrderItemAttribute( "GIFT_MSG_TEXT_" + sItemGiftMsgCount + "_" + (shipGroupIndex + 1), msg); } } } } } } /* Now check all quantities of each cart items have been assigned to a ship group * If not calculate and add the missing quantity to the last ship group defined for the item * */ Iterator<ShoppingCartItem> cartItemIter = shoppingCart.items().iterator(); while (cartItemIter.hasNext()) { ShoppingCartItem shoppingCartItem = (ShoppingCartItem) cartItemIter.next(); BigDecimal bTotalShipGroupQty = BigDecimal.ZERO; BigDecimal bCartQty = shoppingCartItem.getQuantity(); BigDecimal bShipGroupQty = BigDecimal.ZERO; int iShipGroupIndex = 0; Map shipGroupQtyMap = shoppingCart.getShipGroups(shoppingCartItem); Iterator shipGroupQtyIter = shipGroupQtyMap.keySet().iterator(); while (shipGroupQtyIter.hasNext()) { iShipGroupIndex = Integer.valueOf(shipGroupQtyIter.next().toString()); bShipGroupQty = (BigDecimal) shipGroupQtyMap.get(iShipGroupIndex); bTotalShipGroupQty = bTotalShipGroupQty.add(bShipGroupQty); } if (bTotalShipGroupQty.compareTo(bCartQty) < 0) { BigDecimal bAddShipQty = bCartQty.subtract(bTotalShipGroupQty); bAddShipQty = bAddShipQty.add(bShipGroupQty); shoppingCart.setItemShipGroupQty(shoppingCartItem, bAddShipQty, iShipGroupIndex); } } /* Clean up ship groups, if no quantities in group the group is removed. * If not calculate and add the missing quantity to the last ship group defined for the item * */ shoppingCart.cleanUpShipGroups(); /* Check ship group with multiple items, if more than one item in the group check * the shipping options available for each item,; if different count the group is split. * */ splitShipGroupByShipOptions(request, response); } return "success"; }
From source file:pe.gob.mef.gescon.web.ui.OportunidadMB.java
public void edit(ActionEvent event) { try {/*from w ww . j ava 2 s. c o m*/ this.setContenidoHtml(JSFUtils.getRequestParameter("descHtml")); if (this.getSelectedCategoria() == null) { FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "ERROR.", "Seleccione la categora de la oportunidad de mejora a registrar."); FacesContext.getCurrentInstance().addMessage(null, message); return; } if (StringUtils.isBlank(this.getSelectedOportunidad().getVtitulo())) { FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "ERROR.", "Ingrese el ttulo de la oportunidad de mejora a registrar."); FacesContext.getCurrentInstance().addMessage(null, message); return; } if (StringUtils.isBlank(this.getSelectedOportunidad().getVdescripcion())) { FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "ERROR.", "Ingrese la descripcin de la oportunidad de mejora a registrar."); FacesContext.getCurrentInstance().addMessage(null, message); return; } if (StringUtils.isBlank(this.getContenidoHtml())) { FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "ERROR.", "Ingrese el contenido de la oportunidad de mejora a registrar."); FacesContext.getCurrentInstance().addMessage(null, message); return; } if (this.getSelectedOportunidad().getNdestacado().equals(BigDecimal.ZERO) && this.getChkDestacado()) { ConsultaService consultaService = (ConsultaService) ServiceFinder.findBean("ConsultaService"); HashMap filter = new HashMap(); filter.put("ntipoconocimientoid", Constante.OPORTUNIDADMEJORA); BigDecimal cant = consultaService.countDestacadosByTipoConocimiento(filter); if (cant.intValue() >= 10) { this.setListaDestacados(consultaService.getDestacadosByTipoConocimiento(filter)); RequestContext.getCurrentInstance().execute("PF('destDialog').show();"); return; } } /* Validando si exiten vnculos de bases legales derogadas */ int contador = 0; if (CollectionUtils.isNotEmpty(this.getListaTargetVinculosBL())) { for (Consulta c : this.getListaTargetVinculosBL()) { if (c.getIdEstado().toString().equals(Constante.ESTADO_BASELEGAL_DEROGADA)) { contador++; } } } LoginMB loginMB = (LoginMB) JSFUtils.getSessionAttribute("loginMB"); User user = loginMB.getUser(); ConocimientoService conocimientoService = (ConocimientoService) ServiceFinder .findBean("ConocimientoService"); this.getSelectedOportunidad().setNcategoriaid(this.getSelectedCategoria().getNcategoriaid()); this.getSelectedOportunidad() .setVtitulo(StringUtils.upperCase(this.getSelectedOportunidad().getVtitulo())); this.getSelectedOportunidad() .setVdescripcion(StringUtils.capitalize(this.getSelectedOportunidad().getVdescripcion())); this.getSelectedOportunidad().setNdestacado(this.getChkDestacado() ? BigDecimal.ONE : BigDecimal.ZERO); this.getSelectedOportunidad().setDfechamodificacion(new Date()); this.getSelectedOportunidad().setVusuariomodificacion(user.getVlogin()); if (contador > 0) { this.getSelectedOportunidad().setNflgvinculo(BigDecimal.ONE); } else { this.getSelectedOportunidad().setNflgvinculo(BigDecimal.ZERO); } conocimientoService.saveOrUpdate(this.getSelectedOportunidad()); this.setContenidoPlain(Jsoup.parse(this.getContenidoHtml()).text()); GcmFileUtils.writeStringToFileServer(this.getSelectedOportunidad().getVruta(), "html.txt", this.getContenidoHtml()); GcmFileUtils.writeStringToFileServer(this.getSelectedOportunidad().getVruta(), "plain.txt", this.getContenidoHtml()); HistorialService historialService = (HistorialService) ServiceFinder.findBean("HistorialService"); Historial lastHistorial = historialService .getLastHistorialByConocimiento(this.getSelectedOportunidad().getNconocimientoid()); int lastversion; if (lastHistorial != null) { lastversion = lastHistorial.getNnumversion().intValue(); } else { lastversion = 0; } String url = this.path.concat(this.getSelectedOportunidad().getNconocimientoid().toString()).concat("/") .concat(Integer.toString(lastversion + 1)).concat("/"); ThistorialId thistorialId = new ThistorialId(); thistorialId.setNconocimientoid(this.getSelectedOportunidad().getNconocimientoid()); thistorialId.setNhistorialid(historialService.getNextPK()); Historial historial = new Historial(); historial.setId(thistorialId); historial.setNtipoconocimientoid(Constante.OPORTUNIDADMEJORA); historial.setNcategoriaid(this.getSelectedCategoria().getNcategoriaid()); historial.setVtitulo(this.getSelectedOportunidad().getVtitulo()); historial.setVdescripcion(this.getSelectedOportunidad().getVdescripcion()); historial.setNactivo(BigDecimal.ONE); historial.setNsituacionid(this.getSelectedOportunidad().getNsituacionid()); historial.setVruta(url); historial.setNnumversion(BigDecimal.valueOf(lastversion + 1)); historial.setDfechacreacion(new Date()); historial.setVusuariocreacion(user.getVlogin()); historialService.saveOrUpdate(historial); GcmFileUtils.writeStringToFileServer(url, "html.txt", this.getContenidoHtml()); GcmFileUtils.writeStringToFileServer(url, "plain.txt", this.getContenidoPlain()); if (CollectionUtils.isNotEmpty(this.getListaSeccion())) { String url0 = this.getSelectedOportunidad().getVruta().concat("s"); String url1 = url.concat("s"); SeccionService seccionService = (SeccionService) ServiceFinder.findBean("SeccionService"); SeccionHistService seccionHistService = (SeccionHistService) ServiceFinder .findBean("SeccionHistService"); for (Seccion seccion : this.getListaSeccion()) { String ruta0 = url0.concat(seccion.getNorden().toString()).concat("/"); seccion.setVruta(ruta0); if (seccion.getNseccionid() != null) { seccion.setDfechamodificacion(new Date()); seccion.setVusuariomodificacion(user.getVlogin()); } else { seccion.setNseccionid(seccionService.getNextPK()); seccion.setNconocimientoid(this.getSelectedOportunidad().getNconocimientoid()); seccion.setDfechacreacion(new Date()); seccion.setVusuariocreacion(user.getVlogin()); } seccionService.saveOrUpdate(seccion); seccion.setDetallePlain(Jsoup.parse(seccion.getDetalleHtml()).text()); GcmFileUtils.writeStringToFileServer(ruta0, "html.txt", seccion.getDetalleHtml()); GcmFileUtils.writeStringToFileServer(ruta0, "plain.txt", seccion.getDetallePlain()); String ruta1 = url1.concat(seccion.getNorden().toString()).concat("/"); TseccionHistId tseccionHistId = new TseccionHistId(); tseccionHistId.setNconocimientoid(thistorialId.getNconocimientoid()); tseccionHistId.setNhistorialid(thistorialId.getNhistorialid()); tseccionHistId.setNseccionhid(seccionHistService.getNextPK()); SeccionHist seccionHist = new SeccionHist(); seccionHist.setId(tseccionHistId); seccionHist.setNorden(seccion.getNorden()); seccionHist.setVruta(ruta1); seccionHist.setVtitulo(seccion.getVtitulo()); seccionHist.setVusuariocreacion(user.getVlogin()); seccionHist.setDfechacreacion(new Date()); seccionHistService.saveOrUpdate(seccionHist); GcmFileUtils.writeStringToFileServer(ruta1, "html.txt", seccion.getDetalleHtml()); GcmFileUtils.writeStringToFileServer(ruta1, "plain.txt", seccion.getDetallePlain()); } } this.setListaTargetVinculos(new ArrayList()); this.getListaTargetVinculos().addAll(this.getListaTargetVinculosBL()); this.getListaTargetVinculos().addAll(this.getListaTargetVinculosBP()); this.getListaTargetVinculos().addAll(this.getListaTargetVinculosCT()); this.getListaTargetVinculos().addAll(this.getListaTargetVinculosOM()); this.getListaTargetVinculos().addAll(this.getListaTargetVinculosPR()); this.getListaTargetVinculos().addAll(this.getListaTargetVinculosWK()); if (CollectionUtils.isNotEmpty(this.getListaTargetVinculos())) { VinculoService vinculoService = (VinculoService) ServiceFinder.findBean("VinculoService"); VinculoHistService vinculoHistService = (VinculoHistService) ServiceFinder .findBean("VinculoHistService"); vinculoService.deleteByConocimiento(this.getSelectedOportunidad().getNconocimientoid()); for (Consulta consulta : this.getListaTargetVinculos()) { Vinculo vinculo = new Vinculo(); vinculo.setNvinculoid(vinculoService.getNextPK()); vinculo.setNconocimientoid(this.getSelectedOportunidad().getNconocimientoid()); vinculo.setNconocimientovinc(consulta.getIdconocimiento()); vinculo.setNtipoconocimientovinc(consulta.getIdTipoConocimiento()); vinculo.setDfechacreacion(new Date()); vinculo.setVusuariocreacion(user.getVlogin()); vinculoService.saveOrUpdate(vinculo); TvinculoHistId vinculoHistId = new TvinculoHistId(); vinculoHistId.setNvinculohid(vinculoHistService.getNextPK()); vinculoHistId.setNconocimientoid(thistorialId.getNconocimientoid()); vinculoHistId.setNhistorialid(thistorialId.getNhistorialid()); VinculoHist vinculoHist = new VinculoHist(); vinculoHist.setId(vinculoHistId); vinculoHist.setNconocimientovinc(vinculo.getNconocimientovinc()); vinculoHist.setDfechacreacion(new Date()); vinculoHist.setVusuariocreacion(user.getVlogin()); vinculoHistService.saveOrUpdate(vinculoHist); } } this.setListaOportunidad(conocimientoService.getConocimientosByType(Constante.OPORTUNIDADMEJORA)); FacesContext.getCurrentInstance().getExternalContext() .redirect("/gescon/pages/oportunidad/lista.xhtml"); } catch (Exception e) { e.getMessage(); e.printStackTrace(); } }
From source file:pe.gob.mef.gescon.web.ui.OportunidadMB.java
public void post(ActionEvent event) { try {/*from www . j ava2s .com*/ this.setContenidoHtml(JSFUtils.getRequestParameter("descHtml")); if (this.getSelectedCategoria() == null) { FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "ERROR.", "Seleccione la categora de la oportunidad de mejora a registrar."); FacesContext.getCurrentInstance().addMessage(null, message); return; } if (StringUtils.isBlank(this.getSelectedOportunidad().getVtitulo())) { FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "ERROR.", "Ingrese el ttulo de la oportunidad de mejora a registrar."); FacesContext.getCurrentInstance().addMessage(null, message); return; } if (StringUtils.isBlank(this.getSelectedOportunidad().getVdescripcion())) { FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "ERROR.", "Ingrese la descripcin de la oportunidad de mejora a registrar."); FacesContext.getCurrentInstance().addMessage(null, message); return; } if (StringUtils.isBlank(this.getContenidoHtml())) { FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "ERROR.", "Ingrese el contenido de la oportunidad de mejora a registrar."); FacesContext.getCurrentInstance().addMessage(null, message); return; } if (this.getSelectedOportunidad().getNdestacado().equals(BigDecimal.ZERO) && this.getChkDestacado()) { ConsultaService consultaService = (ConsultaService) ServiceFinder.findBean("ConsultaService"); HashMap filter = new HashMap(); filter.put("ntipoconocimientoid", Constante.OPORTUNIDADMEJORA); BigDecimal cant = consultaService.countDestacadosByTipoConocimiento(filter); if (cant.intValue() >= 10) { this.setListaDestacados(consultaService.getDestacadosByTipoConocimiento(filter)); RequestContext.getCurrentInstance().execute("PF('destDialog').show();"); return; } } /* Validando si exiten vnculos de bases legales derogadas */ int contador = 0; if (CollectionUtils.isNotEmpty(this.getListaTargetVinculosBL())) { for (Consulta c : this.getListaTargetVinculosBL()) { if (c.getIdEstado().toString().equals(Constante.ESTADO_BASELEGAL_DEROGADA)) { contador++; } } } LoginMB loginMB = (LoginMB) JSFUtils.getSessionAttribute("loginMB"); User user = loginMB.getUser(); ConocimientoService conocimientoService = (ConocimientoService) ServiceFinder .findBean("ConocimientoService"); this.getSelectedOportunidad().setNcategoriaid(this.getSelectedCategoria().getNcategoriaid()); this.getSelectedOportunidad() .setVtitulo(StringUtils.upperCase(this.getSelectedOportunidad().getVtitulo())); this.getSelectedOportunidad() .setVdescripcion(StringUtils.capitalize(this.getSelectedOportunidad().getVdescripcion())); this.getSelectedOportunidad().setDfechapublicacion(new Date()); this.getSelectedOportunidad() .setNsituacionid(BigDecimal.valueOf(Long.parseLong(Constante.SITUACION_PUBLICADO))); this.getSelectedOportunidad().setNdestacado(this.getChkDestacado() ? BigDecimal.ONE : BigDecimal.ZERO); this.getSelectedOportunidad().setDfechamodificacion(new Date()); this.getSelectedOportunidad().setVusuariomodificacion(user.getVlogin()); if (contador > 0) { this.getSelectedOportunidad().setNflgvinculo(BigDecimal.ONE); } else { this.getSelectedOportunidad().setNflgvinculo(BigDecimal.ZERO); } conocimientoService.saveOrUpdate(this.getSelectedOportunidad()); this.setContenidoPlain(Jsoup.parse(this.getContenidoHtml()).text()); GcmFileUtils.writeStringToFileServer(this.getSelectedOportunidad().getVruta(), "html.txt", this.getContenidoHtml()); GcmFileUtils.writeStringToFileServer(this.getSelectedOportunidad().getVruta(), "plain.txt", this.getContenidoHtml()); HistorialService historialService = (HistorialService) ServiceFinder.findBean("HistorialService"); Historial lastHistorial = historialService .getLastHistorialByConocimiento(this.getSelectedOportunidad().getNconocimientoid()); int lastversion; if (lastHistorial != null) { lastversion = lastHistorial.getNnumversion().intValue(); } else { lastversion = 0; } String url = this.path.concat(this.getSelectedOportunidad().getNconocimientoid().toString()).concat("/") .concat(Integer.toString(lastversion + 1)).concat("/"); ThistorialId thistorialId = new ThistorialId(); thistorialId.setNconocimientoid(this.getSelectedOportunidad().getNconocimientoid()); thistorialId.setNhistorialid(historialService.getNextPK()); Historial historial = new Historial(); historial.setId(thistorialId); historial.setNtipoconocimientoid(Constante.OPORTUNIDADMEJORA); historial.setNcategoriaid(this.getSelectedCategoria().getNcategoriaid()); historial.setVtitulo(this.getSelectedOportunidad().getVtitulo()); historial.setVdescripcion(this.getSelectedOportunidad().getVdescripcion()); historial.setNactivo(BigDecimal.ONE); historial.setNsituacionid(this.getSelectedOportunidad().getNsituacionid()); historial.setVruta(url); historial.setNnumversion(BigDecimal.valueOf(lastversion + 1)); historial.setDfechacreacion(new Date()); historial.setVusuariocreacion(user.getVlogin()); historialService.saveOrUpdate(historial); GcmFileUtils.writeStringToFileServer(url, "html.txt", this.getContenidoHtml()); GcmFileUtils.writeStringToFileServer(url, "plain.txt", this.getContenidoPlain()); if (CollectionUtils.isNotEmpty(this.getListaSeccion())) { String url0 = this.getSelectedOportunidad().getVruta().concat("s"); String url1 = url.concat("s"); SeccionService seccionService = (SeccionService) ServiceFinder.findBean("SeccionService"); SeccionHistService seccionHistService = (SeccionHistService) ServiceFinder .findBean("SeccionHistService"); for (Seccion seccion : this.getListaSeccion()) { String ruta0 = url0.concat(seccion.getNorden().toString()).concat("/"); seccion.setVruta(ruta0); if (seccion.getNseccionid() != null) { seccion.setDfechamodificacion(new Date()); seccion.setVusuariomodificacion(user.getVlogin()); } else { seccion.setNseccionid(seccionService.getNextPK()); seccion.setNconocimientoid(this.getSelectedOportunidad().getNconocimientoid()); seccion.setDfechacreacion(new Date()); seccion.setVusuariocreacion(user.getVlogin()); } seccionService.saveOrUpdate(seccion); seccion.setDetallePlain(Jsoup.parse(seccion.getDetalleHtml()).text()); GcmFileUtils.writeStringToFileServer(ruta0, "html.txt", seccion.getDetalleHtml()); GcmFileUtils.writeStringToFileServer(ruta0, "plain.txt", seccion.getDetallePlain()); String ruta1 = url1.concat(seccion.getNorden().toString()).concat("/"); TseccionHistId tseccionHistId = new TseccionHistId(); tseccionHistId.setNconocimientoid(thistorialId.getNconocimientoid()); tseccionHistId.setNhistorialid(thistorialId.getNhistorialid()); tseccionHistId.setNseccionhid(seccionHistService.getNextPK()); SeccionHist seccionHist = new SeccionHist(); seccionHist.setId(tseccionHistId); seccionHist.setNorden(seccion.getNorden()); seccionHist.setVruta(ruta1); seccionHist.setVtitulo(seccion.getVtitulo()); seccionHist.setVusuariocreacion(user.getVlogin()); seccionHist.setDfechacreacion(new Date()); seccionHistService.saveOrUpdate(seccionHist); GcmFileUtils.writeStringToFileServer(ruta1, "html.txt", seccion.getDetalleHtml()); GcmFileUtils.writeStringToFileServer(ruta1, "plain.txt", seccion.getDetallePlain()); } } this.setListaTargetVinculos(new ArrayList()); this.getListaTargetVinculos().addAll(this.getListaTargetVinculosBL()); this.getListaTargetVinculos().addAll(this.getListaTargetVinculosBP()); this.getListaTargetVinculos().addAll(this.getListaTargetVinculosCT()); this.getListaTargetVinculos().addAll(this.getListaTargetVinculosOM()); this.getListaTargetVinculos().addAll(this.getListaTargetVinculosPR()); this.getListaTargetVinculos().addAll(this.getListaTargetVinculosWK()); if (CollectionUtils.isNotEmpty(this.getListaTargetVinculos())) { VinculoService vinculoService = (VinculoService) ServiceFinder.findBean("VinculoService"); VinculoHistService vinculoHistService = (VinculoHistService) ServiceFinder .findBean("VinculoHistService"); vinculoService.deleteByConocimiento(this.getSelectedOportunidad().getNconocimientoid()); for (Consulta consulta : this.getListaTargetVinculos()) { Vinculo vinculo = new Vinculo(); vinculo.setNvinculoid(vinculoService.getNextPK()); vinculo.setNconocimientoid(this.getSelectedOportunidad().getNconocimientoid()); vinculo.setNconocimientovinc(consulta.getIdconocimiento()); vinculo.setNtipoconocimientovinc(consulta.getIdTipoConocimiento()); vinculo.setDfechacreacion(new Date()); vinculo.setVusuariocreacion(user.getVlogin()); vinculoService.saveOrUpdate(vinculo); TvinculoHistId vinculoHistId = new TvinculoHistId(); vinculoHistId.setNvinculohid(vinculoHistService.getNextPK()); vinculoHistId.setNconocimientoid(thistorialId.getNconocimientoid()); vinculoHistId.setNhistorialid(thistorialId.getNhistorialid()); VinculoHist vinculoHist = new VinculoHist(); vinculoHist.setId(vinculoHistId); vinculoHist.setNconocimientovinc(vinculo.getNconocimientovinc()); vinculoHist.setDfechacreacion(new Date()); vinculoHist.setVusuariocreacion(user.getVlogin()); vinculoHistService.saveOrUpdate(vinculoHist); } } AsignacionService asignacionService = (AsignacionService) ServiceFinder.findBean("AsignacionService"); List<Asignacion> listaAsignacion = conocimientoService.obtenerOmejoraxAsig( this.getSelectedOportunidad().getNconocimientoid(), user.getNusuarioid(), Constante.OPORTUNIDADMEJORA); if (CollectionUtils.isNotEmpty(listaAsignacion)) { Asignacion asignacion = listaAsignacion.get(0); asignacion.setNestadoid(BigDecimal.valueOf(Long.parseLong("2"))); if (asignacion.getDfecharecepcion() == null) { asignacion.setDfecharecepcion(new Date()); } asignacion.setDfechaatencion(new Date()); asignacion.setNaccionid(BigDecimal.valueOf(Long.parseLong("8"))); asignacionService.saveOrUpdate(asignacion); } Asignacion nueva_asignacion = new Asignacion(); AsignacionService serviceasig = (AsignacionService) ServiceFinder.findBean("AsignacionService"); nueva_asignacion.setNasignacionid(serviceasig.getNextPK()); nueva_asignacion.setNtipoconocimientoid(Constante.OPORTUNIDADMEJORA); nueva_asignacion.setNconocimientoid(this.getSelectedOportunidad().getNconocimientoid()); nueva_asignacion.setNestadoid(BigDecimal.valueOf(Long.parseLong(Constante.SITUACION_POR_ANALIZAR))); CategoriaService categoriaService = (CategoriaService) ServiceFinder.findBean("CategoriaService"); nueva_asignacion.setNusuarioid(categoriaService .getCategoriaById(this.getSelectedOportunidad().getNcategoriaid()).getNespecialista()); nueva_asignacion.setDfechaasignacion(new Date()); nueva_asignacion.setDfechacreacion(new Date()); serviceasig.saveOrUpdate(nueva_asignacion); this.setListaOportunidad(conocimientoService.getConocimientosByType(Constante.OPORTUNIDADMEJORA)); FacesContext.getCurrentInstance().getExternalContext() .redirect("/gescon/pages/oportunidad/lista.xhtml"); } catch (Exception e) { e.getMessage(); e.printStackTrace(); } }
From source file:org.egov.dao.budget.BudgetDetailsHibernateDAO.java
/** * This API is to check whether the planning budget is available or not.For * the amount passed if there is sufficient budget available API will return * TRUE. Else it will return FALSE. At any point the budgetavailable will * show the right picture of how much more we can plan for. * <p>//from www . j a va 2 s.c o m * Assumptions- 1) on load of the budget there will be budgetavailable * amount loaded using the multiplier factor. 2) on load of supplementary * budget budget available is recalculated and updated. * <p> * For the sake of audit we should be updating the budgetusage object with * the reference object and the moduleid and amount for any budget consumed. * This will be used for reporting as to which object consumed how much and * when. * * @param financialyearid * This is the id from the financial year object * @param moduleid * This is the id of the module, say for payroll 7 and for stores * 8 and for PTIS it is 2 * @param referencenumber * This is the module object reference number, say purchase order * number or estimate number * @param departmentid * This is the id of the department object * @param functionid * This is the id of the function object * @param functionaryid * This is the id of the functionary object * @param schemeid * This is the id of the scheme object * @param subschemeid * This is the id of the sub scheme object * @param boundaryid * This is the id of the boundary object * @param budgetheadid * This is the id of budgegroup object * @param amount * This is the amount of which budget needs to be allocated * @return boolean * @throws Exception */ public boolean consumeEncumbranceBudget(final Map<String, Object> detailsMap) { if (detailsMap == null) throw new ValidationException( Arrays.asList(new ValidationError("required input is null", "required input is null"))); detailsMap.put(Constants.CONSUMEORRELEASE, true); final BigDecimal bd = getDetails(detailsMap); return bd.intValue() == 1; }
From source file:org.egov.dao.budget.BudgetDetailsHibernateDAO.java
/** * This API will be called for releasing the budget that was already * allocated to some estimate or purchase order. On calling this the amount * that was allocated to some entity will get released. Budget available * will be increased./* www.j a v a2s .com*/ * <p> * On modify of any entity they should first call the release budget and * then call the consume budget. The budget usage table needs to be updated * anytime this is invoked with the date and reference object number. * * @param detailsMap * is the map containig following fields financialyearid This is * the id from the financial year object moduleid This is the id * of the module, say for payroll 7 and for stores 8 and for PTIS * it is 2 referencenumber This is the module object reference * number, say purchase order number or estimate number * departmentid This is the id of the department object * functionid This is the id of the function object functionaryid * This is the id of the functionary object schemeid This is the * id of the scheme object subschemeid This is the id of the sub * scheme object fieldid This is the id of the boundary object * budgetheadid This is the id of budgegroup object amount This * is the amount of which budget needs to be allocated * @throws Exception */ public boolean releaseEncumbranceBudget(final Map<String, Object> detailsMap) { if (detailsMap == null) throw new ValidationException( Arrays.asList(new ValidationError("required input is null", "required input is null"))); detailsMap.put(Constants.CONSUMEORRELEASE, false); final BigDecimal bd = getDetails(detailsMap); return bd.intValue() == 1; }