Example usage for org.apache.commons.lang3 StringUtils upperCase

List of usage examples for org.apache.commons.lang3 StringUtils upperCase

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils upperCase.

Prototype

public static String upperCase(final String str) 

Source Link

Document

Converts a String to upper case as per String#toUpperCase() .

A null input String returns null .

 StringUtils.upperCase(null)  = null StringUtils.upperCase("")    = "" StringUtils.upperCase("aBc") = "ABC" 

Note: As described in the documentation for String#toUpperCase() , the result of this method is affected by the current locale.

Usage

From source file:pe.gob.mef.gescon.web.ui.BuenaPracticaMB.java

public void addDiscusion(ActionEvent event) {
    try {//from   ww w  .j  a  v  a 2s. c  om
        this.setDiscusionHtml(JSFUtils.getRequestParameter("txtHtml"));
        if (this.getTipoDiscusion() == null) {
            FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "ERROR.",
                    "Seleccione el tipo de discusin a agregar.");
            FacesContext.getCurrentInstance().addMessage(null, message);
            return;
        }
        if (StringUtils.isBlank(this.getTituloDiscusion())) {
            FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "ERROR.",
                    "Ingrese el ttulo de la discusin a agregar.");
            FacesContext.getCurrentInstance().addMessage(null, message);
            return;
        }
        if (StringUtils.isBlank(this.getDiscusionHtml())) {
            FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "ERROR.",
                    "Ingrese el detalle de la discusin a agregar.");
            FacesContext.getCurrentInstance().addMessage(null, message);
            return;
        }
        DiscusionSeccion discusionSeccion = new DiscusionSeccion();
        discusionSeccion.setNtipodiscusion(this.getTipoDiscusion());
        discusionSeccion.setVtitulo(StringUtils.upperCase(this.getTituloDiscusion().trim()));
        discusionSeccion.setDiscusionHtml(this.getDiscusionHtml());
        discusionSeccion.setDiscusionPlain(Jsoup.parse(discusionSeccion.getDiscusionHtml()).text());
        discusionSeccion.setDfechacreacion(new Date());
        if (this.getListaDiscusionSeccion() == null) {
            this.setListaDiscusionSeccion(new ArrayList());
        }
        this.getListaDiscusionSeccion().add(discusionSeccion);
        RequestContext.getCurrentInstance().execute("PF('dlgSec').hide();");
    } catch (Exception e) {
        e.getMessage();
        e.printStackTrace();
    }
}

From source file:pe.gob.mef.gescon.web.ui.BuenaPracticaMB.java

public void editDiscusion(ActionEvent event) {
    try {//from   ww w  .  ja  v a  2 s .c om
        this.getSelectedDiscusionSeccion().setDiscusionHtml(JSFUtils.getRequestParameter("etxtHtml"));
        if (this.getSelectedDiscusionSeccion().getNtipodiscusion() == null) {
            FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "ERROR.",
                    "Seleccione el tipo de discusin a editar.");
            FacesContext.getCurrentInstance().addMessage(null, message);
            return;
        }
        if (StringUtils.isBlank(this.getSelectedDiscusionSeccion().getVtitulo())) {
            FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "ERROR.",
                    "Ingrese el ttulo de la discusin a editar.");
            FacesContext.getCurrentInstance().addMessage(null, message);
            return;
        }
        if (StringUtils.isBlank(this.getSelectedDiscusionSeccion().getDiscusionHtml())) {
            FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "ERROR.",
                    "Ingrese el detalle de la discusin a editar.");
            FacesContext.getCurrentInstance().addMessage(null, message);
            return;
        }
        this.getSelectedDiscusionSeccion()
                .setVtitulo(StringUtils.upperCase(this.getSelectedDiscusionSeccion().getVtitulo().trim()));
        this.getSelectedDiscusionSeccion()
                .setDiscusionPlain(Jsoup.parse(this.getSelectedDiscusionSeccion().getDiscusionHtml()).text());
        RequestContext.getCurrentInstance().execute("PF('dlgEsec').hide();");
    } catch (Exception e) {
        e.getMessage();
        e.printStackTrace();
    }
}

From source file:pe.gob.mef.gescon.web.ui.BuenaPracticaMB.java

public void saveOrUpdateDiscusion(ActionEvent event) {
    Discusion discusion = null;//from w w  w  .  j  a  v a2  s .c  o m
    DiscusionHist discusionHist;
    try {
        LoginMB loginMB = (LoginMB) JSFUtils.getSessionAttribute("loginMB");
        User user = loginMB.getUser();
        DiscusionService discusionService = (DiscusionService) ServiceFinder.findBean("DiscusionService");
        DiscusionHistService discusionHistService = (DiscusionHistService) ServiceFinder
                .findBean("DiscusionHistService");
        if (this.getSelectedDiscusion() == null) {
            discusion = new Discusion();
            discusion.setNdiscusionid(discusionService.getNextPK());
            discusion.setNconocimientoid(this.getSelectedBuenaPractica().getNconocimientoid());
            discusion.setDfechacreacion(new Date());
            discusion.setVusuariocreacion(user.getVlogin());
            discusionService.saveOrUpdate(discusion);

            discusionHist = new DiscusionHist();
            discusionHist.setNnumversion(BigDecimal.ONE);
        } else {
            discusion = this.getSelectedDiscusion();
            discusionHist = discusionHistService
                    .getDiscusionHistByConocimiento(this.getSelectedBuenaPractica().getNconocimientoid());
            int version = discusionHist.getNnumversion().intValue() + 1;
            discusionHist.setNnumversion(BigDecimal.valueOf(version));
        }
        discusionHist.setNdiscusionhid(discusionHistService.getNextPK());
        discusionHist.setNconocimientoid(this.getSelectedBuenaPractica().getNconocimientoid());
        discusionHist.setDfechacreacion(new Date());
        discusionHist.setVusuariocreacion(user.getVlogin());
        discusionHistService.saveOrUpdate(discusionHist);

        if (CollectionUtils.isNotEmpty(this.getListaDiscusionSeccion())) {
            String url0 = this.path.concat(this.getSelectedBuenaPractica().getNconocimientoid().toString())
                    .concat("/0/d/").concat(BigDecimal.ZERO.toString()).concat("/s");
            String url1 = this.path.concat(this.getSelectedBuenaPractica().getNconocimientoid().toString())
                    .concat("/0/d/").concat(discusionHist.getNnumversion().toString()).concat("/s");
            DiscusionSeccionService discusionSeccionService = (DiscusionSeccionService) ServiceFinder
                    .findBean("DiscusionSeccionService");
            DiscusionSeccionHistService discusionSeccionHistService = (DiscusionSeccionHistService) ServiceFinder
                    .findBean("DiscusionSeccionHistService");
            for (DiscusionSeccion seccion : this.getListaDiscusionSeccion()) {
                if (seccion.getNdiscusionseccionid() == null) {
                    seccion.setNdiscusionseccionid(discusionSeccionService.getNextPK());
                    seccion.setNdiscusionid(discusion.getNdiscusionid());
                    seccion.setDfechacreacion(new Date());
                    seccion.setVusuariocreacion(user.getVlogin());
                } else {
                    seccion.setDfechamodificacion(new Date());
                    seccion.setVusuariomodificacion(user.getVlogin());
                }
                String ruta0 = url0.concat(seccion.getNdiscusionseccionid().toString()).concat("/");
                seccion.setNtipodiscusion(seccion.getNtipodiscusion());
                seccion.setVtitulo(StringUtils.upperCase(seccion.getVtitulo()));
                seccion.setVruta(ruta0);
                seccion.setDiscusionPlain(Jsoup.parse(seccion.getDiscusionHtml()).text());
                discusionSeccionService.saveOrUpdate(seccion);

                GcmFileUtils.writeStringToFileServer(ruta0, "html.txt", seccion.getDiscusionHtml());
                GcmFileUtils.writeStringToFileServer(ruta0, "plain.txt", seccion.getDiscusionPlain());

                String ruta1 = url1.concat(seccion.getNdiscusionseccionid().toString()).concat("/");
                DiscusionSeccionHist seccionHist = new DiscusionSeccionHist();
                seccionHist.setNdiscusionseccionhid(discusionSeccionHistService.getNextPK());
                seccionHist.setNdiscusionhid(discusionHist.getNdiscusionhid());
                seccionHist.setNtipodiscusion(seccion.getNtipodiscusion());
                seccionHist.setVtitulo(StringUtils.upperCase(seccion.getVtitulo()));
                seccionHist.setVruta(ruta1);
                seccionHist.setDfechacreacion(new Date());
                seccionHist.setVusuariocreacion(user.getVlogin());
                discusionSeccionHistService.saveOrUpdate(seccionHist);

                GcmFileUtils.writeStringToFileServer(ruta1, "html.txt", seccion.getDiscusionHtml());
                GcmFileUtils.writeStringToFileServer(ruta1, "plain.txt", seccion.getDiscusionPlain());
            }
        }
        FacesContext context = FacesContext.getCurrentInstance();
        context.addMessage(null, new FacesMessage("Informacin", "Discusin registrada con xito."));
    } catch (Exception e) {
        e.getMessage();
        e.printStackTrace();
    }
}

From source file:pe.gob.mef.gescon.web.ui.BuenaPracticaMB.java

public void save(ActionEvent event) {
    try {// w w w.j  av  a 2 s .  c  o m
        this.setDescripcionHtml(JSFUtils.getRequestParameter("descHtml"));
        if (this.getSelectedCategoria() == null) {
            FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "ERROR.",
                    "Seleccione la categora de la buena prctica a registrar.");
            FacesContext.getCurrentInstance().addMessage(null, message);
            return;
        }
        if (StringUtils.isBlank(this.getNombre())) {
            FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "ERROR.",
                    "Ingrese el ttulo de la buena prctica a registrar.");
            FacesContext.getCurrentInstance().addMessage(null, message);
            return;
        }
        if (StringUtils.isBlank(this.getDescripcionHtml())) {
            FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "ERROR.",
                    "Ingrese la descripcin de la buena prctica 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;
        }
        /* 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());
        Conocimiento conocimiento = new Conocimiento();
        conocimiento.setNtipoconocimientoid(Constante.BUENAPRACTICA);
        conocimiento.setNconocimientoid(conocimientoService.getNextPK());
        conocimiento.setNcategoriaid(this.getSelectedCategoria().getNcategoriaid());
        conocimiento.setNdestacado(BigDecimal.ZERO);
        conocimiento.setVtitulo(StringUtils.upperCase(this.getNombre()));
        if (this.getDescripcionPlain().length() < 400) {
            conocimiento.setVdescripcion(StringUtils.capitalize(this.getDescripcionPlain()));
        } else {
            conocimiento.setVdescripcion(StringUtils.capitalize(this.getDescripcionPlain().substring(0, 400)));
        }
        if (contador > 0) {
            conocimiento.setNflgvinculo(BigDecimal.ONE);
        } else {
            conocimiento.setNflgvinculo(BigDecimal.ZERO);
        }
        if (this.getSelectedCategoria().getNflagbp().equals(BigDecimal.ONE)) {
            conocimiento.setNsituacionid(BigDecimal.valueOf(Long.parseLong(Constante.SITUACION_POR_VERIFICAR)));
        } else {
            conocimiento.setNsituacionid(BigDecimal.valueOf(Long.parseLong(Constante.SITUACION_PUBLICADO)));
            conocimiento.setDfechapublicacion(new Date());
        }
        String np0 = this.path.concat(conocimiento.getNconocimientoid().toString()).concat("/0/");
        conocimiento.setVruta(np0);
        conocimiento.setNactivo(BigDecimal.ONE);
        conocimiento.setDfechacreacion(new Date());
        conocimiento.setVusuariocreacion(user.getVlogin());
        conocimientoService.saveOrUpdate(conocimiento);

        GcmFileUtils.writeStringToFileServer(np0, "html.txt", this.getDescripcionHtml());
        GcmFileUtils.writeStringToFileServer(np0, "plain.txt", this.getDescripcionPlain());

        String np1 = this.path.concat(conocimiento.getNconocimientoid().toString()).concat("/1/");
        HistorialService historialService = (HistorialService) ServiceFinder.findBean("HistorialService");
        ThistorialId thistorialId = new ThistorialId();
        thistorialId.setNconocimientoid(conocimiento.getNconocimientoid());
        thistorialId.setNhistorialid(historialService.getNextPK());
        Historial historial = new Historial();
        historial.setId(thistorialId);
        historial.setNtipoconocimientoid(Constante.BUENAPRACTICA);
        historial.setNcategoriaid(this.getSelectedCategoria().getNcategoriaid());
        historial.setVtitulo(this.getNombre());
        historial.setNactivo(BigDecimal.ONE);
        historial.setNsituacionid(conocimiento.getNsituacionid());
        historial.setVruta(np1);
        historial.setNnumversion(BigDecimal.ONE);
        historial.setDfechacreacion(new Date());
        historial.setVusuariocreacion(user.getVlogin());
        historialService.saveOrUpdate(historial);

        GcmFileUtils.writeStringToFileServer(np1, "html.txt", this.getDescripcionHtml());
        GcmFileUtils.writeStringToFileServer(np1, "plain.txt", this.getDescripcionPlain());

        if (CollectionUtils.isNotEmpty(this.getListaSeccion())) {
            String url0 = this.path.concat(conocimiento.getNconocimientoid().toString()).concat("/0/s");
            String url1 = this.path.concat(conocimiento.getNconocimientoid().toString()).concat("/1/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);
                seccion.setNseccionid(seccionService.getNextPK());
                seccion.setNconocimientoid(conocimiento.getNconocimientoid());
                seccion.setDfechacreacion(new Date());
                seccion.setVusuariocreacion(user.getVlogin());
                seccionService.saveOrUpdate(seccion);

                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", this.getDetalleHtml());
                GcmFileUtils.writeStringToFileServer(ruta1, "plain.txt", this.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");
            for (Consulta consulta : this.getListaTargetVinculos()) {
                Vinculo vinculo = new Vinculo();
                vinculo.setNvinculoid(vinculoService.getNextPK());
                vinculo.setNconocimientoid(conocimiento.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);
            }
        }

        if (this.getSelectedCategoria().getNflagbp().toString().equals("1")) {
            Asignacion asignacion = new Asignacion();
            AsignacionService serviceasig = (AsignacionService) ServiceFinder.findBean("AsignacionService");
            asignacion.setNasignacionid(serviceasig.getNextPK());
            asignacion.setNtipoconocimientoid(Constante.BUENAPRACTICA);
            asignacion.setNconocimientoid(conocimiento.getNconocimientoid());
            asignacion.setNestadoid(BigDecimal.valueOf(Long.parseLong("1")));
            CategoriaService categoriaService = (CategoriaService) ServiceFinder.findBean("CategoriaService");
            asignacion.setNusuarioid(
                    categoriaService.getCategoriaById(conocimiento.getNcategoriaid()).getNmoderador());
            asignacion.setDfechaasignacion(new Date());
            asignacion.setDfechacreacion(new Date());
            serviceasig.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:pe.gob.mef.gescon.web.ui.BuenaPracticaMB.java

public void edit(ActionEvent event) {
    try {//w  w w.j  a v  a  2  s  .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.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:pe.gob.mef.gescon.web.ui.BuenaPracticaMB.java

public void post(ActionEvent event) {
    try {/*from  w w w  .  ja  v a 2  s. 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.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:pe.gob.mef.gescon.web.ui.ContenidoMB.java

public void saveOrUpdateDiscusion(ActionEvent event) {
    Discusion discusion = null;//from   w  w w  .  ja  va2s .  c  o m
    DiscusionHist discusionHist;
    try {
        LoginMB loginMB = (LoginMB) JSFUtils.getSessionAttribute("loginMB");
        User user = loginMB.getUser();
        DiscusionService discusionService = (DiscusionService) ServiceFinder.findBean("DiscusionService");
        DiscusionHistService discusionHistService = (DiscusionHistService) ServiceFinder
                .findBean("DiscusionHistService");
        if (this.getSelectedDiscusion() == null) {
            discusion = new Discusion();
            discusion.setNdiscusionid(discusionService.getNextPK());
            discusion.setNconocimientoid(this.getSelectedContenido().getNconocimientoid());
            discusion.setDfechacreacion(new Date());
            discusion.setVusuariocreacion(user.getVlogin());
            discusionService.saveOrUpdate(discusion);

            discusionHist = new DiscusionHist();
            discusionHist.setNnumversion(BigDecimal.ONE);
        } else {
            discusion = this.getSelectedDiscusion();
            discusionHist = discusionHistService
                    .getDiscusionHistByConocimiento(this.getSelectedContenido().getNconocimientoid());
            int version = discusionHist.getNnumversion().intValue() + 1;
            discusionHist.setNnumversion(BigDecimal.valueOf(version));
        }
        discusionHist.setNdiscusionhid(discusionHistService.getNextPK());
        discusionHist.setNconocimientoid(this.getSelectedContenido().getNconocimientoid());
        discusionHist.setDfechacreacion(new Date());
        discusionHist.setVusuariocreacion(user.getVlogin());
        discusionHistService.saveOrUpdate(discusionHist);

        if (CollectionUtils.isNotEmpty(this.getListaDiscusionSeccion())) {
            String url0 = this.path.concat(this.getSelectedContenido().getNconocimientoid().toString())
                    .concat("/0/d/").concat(BigDecimal.ZERO.toString()).concat("/s");
            String url1 = this.path.concat(this.getSelectedContenido().getNconocimientoid().toString())
                    .concat("/0/d/").concat(discusionHist.getNnumversion().toString()).concat("/s");
            DiscusionSeccionService discusionSeccionService = (DiscusionSeccionService) ServiceFinder
                    .findBean("DiscusionSeccionService");
            DiscusionSeccionHistService discusionSeccionHistService = (DiscusionSeccionHistService) ServiceFinder
                    .findBean("DiscusionSeccionHistService");
            for (DiscusionSeccion seccion : this.getListaDiscusionSeccion()) {
                if (seccion.getNdiscusionseccionid() == null) {
                    seccion.setNdiscusionseccionid(discusionSeccionService.getNextPK());
                    seccion.setNdiscusionid(discusion.getNdiscusionid());
                    seccion.setDfechacreacion(new Date());
                    seccion.setVusuariocreacion(user.getVlogin());
                } else {
                    seccion.setDfechamodificacion(new Date());
                    seccion.setVusuariomodificacion(user.getVlogin());
                }
                String ruta0 = url0.concat(seccion.getNdiscusionseccionid().toString()).concat("/");
                seccion.setNtipodiscusion(seccion.getNtipodiscusion());
                seccion.setVtitulo(StringUtils.upperCase(seccion.getVtitulo()));
                seccion.setVruta(ruta0);
                seccion.setDiscusionPlain(Jsoup.parse(seccion.getDiscusionHtml()).text());
                discusionSeccionService.saveOrUpdate(seccion);

                GcmFileUtils.writeStringToFileServer(ruta0, "html.txt", seccion.getDiscusionHtml());
                GcmFileUtils.writeStringToFileServer(ruta0, "plain.txt", seccion.getDiscusionPlain());

                String ruta1 = url1.concat(seccion.getNdiscusionseccionid().toString()).concat("/");
                DiscusionSeccionHist seccionHist = new DiscusionSeccionHist();
                seccionHist.setNdiscusionseccionhid(discusionSeccionHistService.getNextPK());
                seccionHist.setNdiscusionhid(discusionHist.getNdiscusionhid());
                seccionHist.setNtipodiscusion(seccion.getNtipodiscusion());
                seccionHist.setVtitulo(StringUtils.upperCase(seccion.getVtitulo()));
                seccionHist.setVruta(ruta1);
                seccionHist.setDfechacreacion(new Date());
                seccionHist.setVusuariocreacion(user.getVlogin());
                discusionSeccionHistService.saveOrUpdate(seccionHist);

                GcmFileUtils.writeStringToFileServer(ruta1, "html.txt", seccion.getDiscusionHtml());
                GcmFileUtils.writeStringToFileServer(ruta1, "plain.txt", seccion.getDiscusionPlain());
            }
        }
        FacesContext context = FacesContext.getCurrentInstance();
        context.addMessage(null, new FacesMessage("Informacin", "Discusin registrada con xito."));
    } catch (Exception e) {
        e.getMessage();
        e.printStackTrace();
    }
}

From source file:pe.gob.mef.gescon.web.ui.EntidadMB.java

public void save(ActionEvent event) {
    try {/*from  ww  w  . j ava 2  s  .co  m*/
        if (CollectionUtils.isEmpty(this.getListaEntidad())) {
            this.setListaEntidad(Collections.EMPTY_LIST);
        }
        Entidad entidad = new Entidad();
        entidad.setVnombre(this.getNombre());
        entidad.setVcodigoentidad(this.getCodigo());
        entidad.setVdescripcion(this.getDescripcion());
        if (!errorValidation(entidad)) {
            LoginMB loginMB = (LoginMB) JSFUtils.getSessionAttribute("loginMB");
            User user = loginMB.getUser();
            EntidadService service = (EntidadService) ServiceFinder.findBean("EntidadService");
            entidad.setNentidadid(service.getNextPK());
            entidad.setVnombre(StringUtils.upperCase(this.getNombre().trim()));
            entidad.setVcodigoentidad(this.getCodigo());
            entidad.setVdescripcion(StringUtils.capitalize(this.getDescripcion().trim()));
            entidad.setNactivo(BigDecimal.ONE);
            entidad.setDfechacreacion(new Date());
            entidad.setVusuariocreacion(user.getVlogin());
            entidad.setVdepartamento(this.getDepartamento());
            entidad.setVprovincia(this.getProvincia());
            entidad.setVdistrito(this.getDistrito());
            entidad.setVdepartamento(this.getDepartamento());
            entidad.setNtipoid(BigDecimal.valueOf(Long.parseLong(this.getTipoentidad())));
            service.saveOrUpdate(entidad);
            this.setListaEntidad(service.getEntidades());
            this.cleanAttributes();
            RequestContext.getCurrentInstance().execute("PF('newDialog').hide();");
        }
    } catch (Exception e) {
        log.error(e.getMessage());
        e.printStackTrace();
    }
}

From source file:pe.gob.mef.gescon.web.ui.EntidadMB.java

public void update(ActionEvent event) {
    try {//ww w . j  av a 2  s.c  om
        if (event != null) {
            if (StringUtils.isBlank(this.getSelectedEntidad().getVnombre())) {
                FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, Constante.SEVERETY_ALERTA,
                        "Nombre requerido. Ingrese el nombre de la Entidad.");
                FacesContext.getCurrentInstance().addMessage(null, message);
                return;
            }
            if (this.getSelectedEntidad().getVcodigoentidad() == null) {
                FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, Constante.SEVERETY_ALERTA,
                        "Codigo requerido. Ingrese el codigo de la entidad.");
                FacesContext.getCurrentInstance().addMessage(null, message);
                return;
            }
            if (StringUtils.isBlank(this.getSelectedEntidad().getVdescripcion())) {
                FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, Constante.SEVERETY_ALERTA,
                        "Descripcin requerida. Ingrese la descripcin de la Entidad.");
                FacesContext.getCurrentInstance().addMessage(null, message);
                return;
            }
            LoginMB loginMB = (LoginMB) JSFUtils.getSessionAttribute("loginMB");
            User user = loginMB.getUser();
            this.getSelectedEntidad()
                    .setVnombre(StringUtils.upperCase(this.getSelectedEntidad().getVnombre().trim()));
            this.getSelectedEntidad().setVcodigoentidad(this.getSelectedEntidad().getVcodigoentidad());
            this.getSelectedEntidad().setVdescripcion(
                    StringUtils.capitalize(this.getSelectedEntidad().getVdescripcion().trim()));
            this.getSelectedEntidad().setVusuariomodificacion(user.getVlogin());
            this.getSelectedEntidad().setDfechamodificacion(new Date());
            this.getSelectedEntidad().setVdepartamento(this.getSelectedEntidad().getVdepartamento());
            this.getSelectedEntidad().setVprovincia(this.getSelectedEntidad().getVprovincia());
            this.getSelectedEntidad().setVdistrito(this.getSelectedEntidad().getVdistrito());
            this.getSelectedEntidad().setNtipoid(this.getSelectedEntidad().getNtipoid());
            EntidadService service = (EntidadService) ServiceFinder.findBean("EntidadService");
            service.saveOrUpdate(this.getSelectedEntidad());
            this.setListaEntidad(service.getEntidades());
            this.cleanAttributes();
            RequestContext.getCurrentInstance().execute("PF('editDialog').hide();");
        }
    } catch (Exception e) {
        log.error(e.getMessage());
        e.printStackTrace();
    }
}

From source file:pe.gob.mef.gescon.web.ui.OportunidadMB.java

public void saveOrUpdateDiscusion(ActionEvent event) {
    Discusion discusion = null;/*from  ww w.  j a v  a  2  s  .  co m*/
    DiscusionHist discusionHist;
    try {
        LoginMB loginMB = (LoginMB) JSFUtils.getSessionAttribute("loginMB");
        User user = loginMB.getUser();
        DiscusionService discusionService = (DiscusionService) ServiceFinder.findBean("DiscusionService");
        DiscusionHistService discusionHistService = (DiscusionHistService) ServiceFinder
                .findBean("DiscusionHistService");
        if (this.getSelectedDiscusion() == null) {
            discusion = new Discusion();
            discusion.setNdiscusionid(discusionService.getNextPK());
            discusion.setNconocimientoid(this.getSelectedOportunidad().getNconocimientoid());
            discusion.setDfechacreacion(new Date());
            discusion.setVusuariocreacion(user.getVlogin());
            discusionService.saveOrUpdate(discusion);

            discusionHist = new DiscusionHist();
            discusionHist.setNnumversion(BigDecimal.ONE);
        } else {
            discusion = this.getSelectedDiscusion();
            discusionHist = discusionHistService
                    .getDiscusionHistByConocimiento(this.getSelectedOportunidad().getNconocimientoid());
            int version = discusionHist.getNnumversion().intValue() + 1;
            discusionHist.setNnumversion(BigDecimal.valueOf(version));
        }
        discusionHist.setNdiscusionhid(discusionHistService.getNextPK());
        discusionHist.setNconocimientoid(this.getSelectedOportunidad().getNconocimientoid());
        discusionHist.setDfechacreacion(new Date());
        discusionHist.setVusuariocreacion(user.getVlogin());
        discusionHistService.saveOrUpdate(discusionHist);

        if (CollectionUtils.isNotEmpty(this.getListaDiscusionSeccion())) {
            String url0 = this.path.concat(this.getSelectedOportunidad().getNconocimientoid().toString())
                    .concat("/0/d/").concat(BigDecimal.ZERO.toString()).concat("/s");
            String url1 = this.path.concat(this.getSelectedOportunidad().getNconocimientoid().toString())
                    .concat("/0/d/").concat(discusionHist.getNnumversion().toString()).concat("/s");
            DiscusionSeccionService discusionSeccionService = (DiscusionSeccionService) ServiceFinder
                    .findBean("DiscusionSeccionService");
            DiscusionSeccionHistService discusionSeccionHistService = (DiscusionSeccionHistService) ServiceFinder
                    .findBean("DiscusionSeccionHistService");
            for (DiscusionSeccion seccion : this.getListaDiscusionSeccion()) {
                if (seccion.getNdiscusionseccionid() == null) {
                    seccion.setNdiscusionseccionid(discusionSeccionService.getNextPK());
                    seccion.setNdiscusionid(discusion.getNdiscusionid());
                    seccion.setDfechacreacion(new Date());
                    seccion.setVusuariocreacion(user.getVlogin());
                } else {
                    seccion.setDfechamodificacion(new Date());
                    seccion.setVusuariomodificacion(user.getVlogin());
                }
                String ruta0 = url0.concat(seccion.getNdiscusionseccionid().toString()).concat("/");
                seccion.setNtipodiscusion(seccion.getNtipodiscusion());
                seccion.setVtitulo(StringUtils.upperCase(seccion.getVtitulo()));
                seccion.setVruta(ruta0);
                seccion.setDiscusionPlain(Jsoup.parse(seccion.getDiscusionHtml()).text());
                discusionSeccionService.saveOrUpdate(seccion);

                GcmFileUtils.writeStringToFileServer(ruta0, "html.txt", seccion.getDiscusionHtml());
                GcmFileUtils.writeStringToFileServer(ruta0, "plain.txt", seccion.getDiscusionPlain());

                String ruta1 = url1.concat(seccion.getNdiscusionseccionid().toString()).concat("/");
                DiscusionSeccionHist seccionHist = new DiscusionSeccionHist();
                seccionHist.setNdiscusionseccionhid(discusionSeccionHistService.getNextPK());
                seccionHist.setNdiscusionhid(discusionHist.getNdiscusionhid());
                seccionHist.setNtipodiscusion(seccion.getNtipodiscusion());
                seccionHist.setVtitulo(StringUtils.upperCase(seccion.getVtitulo()));
                seccionHist.setVruta(ruta1);
                seccionHist.setDfechacreacion(new Date());
                seccionHist.setVusuariocreacion(user.getVlogin());
                discusionSeccionHistService.saveOrUpdate(seccionHist);

                GcmFileUtils.writeStringToFileServer(ruta1, "html.txt", seccion.getDiscusionHtml());
                GcmFileUtils.writeStringToFileServer(ruta1, "plain.txt", seccion.getDiscusionPlain());
            }
        }
        FacesContext context = FacesContext.getCurrentInstance();
        context.addMessage(null, new FacesMessage("Informacin", "Discusin registrada con xito."));
    } catch (Exception e) {
        e.getMessage();
        e.printStackTrace();
    }
}