Example usage for java.math BigDecimal ONE

List of usage examples for java.math BigDecimal ONE

Introduction

In this page you can find the example usage for java.math BigDecimal ONE.

Prototype

BigDecimal ONE

To view the source code for java.math BigDecimal ONE.

Click Source Link

Document

The value 1, with a scale of 0.

Usage

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

public void publicarOmejora(ActionEvent event) {
    try {//from   w  w w .ja va2  s .  co  m
        //this.setContenidoHtml(JSFUtils.getRequestParameter("descHtml"));
        if (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;
            }
        }
        this.setContenidoPlain(Jsoup.parse(this.getContenidoHtml()).text());
        LoginMB loginMB = (LoginMB) JSFUtils.getSessionAttribute("loginMB");
        User usuario = loginMB.getUser();
        ConocimientoService conocimientoService = (ConocimientoService) ServiceFinder
                .findBean("ConocimientoService");
        this.getSelectedOmejora().setNcategoriaid(this.getSelectedCategoria().getNcategoriaid());
        this.getSelectedOmejora().setVtitulo(StringUtils.upperCase(this.getSelectedOmejora().getVtitulo()));
        this.getSelectedOmejora()
                .setVdescripcion(StringUtils.upperCase(this.getSelectedOmejora().getVdescripcion()));
        if (this.getContenidoPlain().length() < 400) {
            this.getSelectedOmejora().setVcontenido(StringUtils.capitalize(this.getContenidoPlain()));
        } else {
            this.getSelectedOmejora()
                    .setVcontenido(StringUtils.capitalize(this.getContenidoPlain().substring(0, 399)));
        }
        this.getSelectedOmejora().setNdestacado(this.getChkDestacado() ? BigDecimal.ONE : BigDecimal.ZERO);
        this.getSelectedOmejora().setDfechamodificacion(new Date());
        this.getSelectedOmejora().setVusuariomodificacion(usuario.getVlogin());
        this.getSelectedOmejora()
                .setNsituacionid(BigDecimal.valueOf(Long.parseLong(Constante.SITUACION_VERIFICADO)));
        this.getSelectedOmejora().setDfechapublicacion(new Date());
        conocimientoService.saveOrUpdate(this.getSelectedOmejora());

        this.setContenidoPlain(Jsoup.parse(this.getContenidoHtml()).text());
        GcmFileUtils.writeStringToFileServer(this.getSelectedOmejora().getVruta(), "html.txt",
                this.getContenidoHtml());
        GcmFileUtils.writeStringToFileServer(this.getSelectedOmejora().getVruta(), "plain.txt",
                this.getContenidoPlain());

        HistorialService historialService = (HistorialService) ServiceFinder.findBean("HistorialService");
        Historial lastHistorial = historialService
                .getLastHistorialByConocimiento(this.getSelectedOmejora().getNconocimientoid());
        int lastversion;
        if (lastHistorial != null) {
            lastversion = lastHistorial.getNnumversion().intValue();
        } else {
            lastversion = 0;
        }
        String url = this.pathom.concat(this.getSelectedOmejora().getNconocimientoid().toString()).concat("/")
                .concat(Integer.toString(lastversion + 1)).concat("/");

        ThistorialId thistorialId = new ThistorialId();
        thistorialId.setNconocimientoid(this.getSelectedOmejora().getNconocimientoid());
        thistorialId.setNhistorialid(historialService.getNextPK());
        Historial historial = new Historial();
        historial.setId(thistorialId);
        historial.setNtipoconocimientoid(Constante.OPORTUNIDADMEJORA);
        historial.setNcategoriaid(this.getSelectedCategoria().getNcategoriaid());
        historial.setVtitulo(this.getSelectedOmejora().getVtitulo());
        historial.setVdescripcion(this.getSelectedOmejora().getVdescripcion());
        historial.setNactivo(BigDecimal.ONE);
        historial.setNsituacionid(this.getSelectedOmejora().getNsituacionid());
        historial.setVruta(url);
        historial.setNnumversion(BigDecimal.valueOf(lastversion + 1));
        historial.setDfechacreacion(new Date());
        historial.setVusuariocreacion(usuario.getVlogin());
        historial.setVmsjsolicita(this.getSelectedOmejora().getVmsjsolicita());
        historial.setVmsjrespuesta(this.getSelectedOmejora().getVmsjrespuesta());
        historialService.saveOrUpdate(historial);

        GcmFileUtils.writeStringToFileServer(url, "html.txt", this.getContenidoHtml());
        GcmFileUtils.writeStringToFileServer(url, "plain.txt", this.getContenidoPlain());

        if (org.apache.commons.collections.CollectionUtils.isNotEmpty(this.getListaSeccion())) {
            String url0 = this.getSelectedOmejora().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(usuario.getVlogin());
                } else {
                    seccion.setNseccionid(seccionService.getNextPK());
                    seccion.setNconocimientoid(this.getSelectedOmejora().getNconocimientoid());
                    seccion.setDfechacreacion(new Date());
                    seccion.setVusuariocreacion(usuario.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(usuario.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 (org.apache.commons.collections.CollectionUtils.isNotEmpty(this.getListaTargetVinculos())) {
            VinculoService vinculoService = (VinculoService) ServiceFinder.findBean("VinculoService");
            VinculoHistService vinculoHistService = (VinculoHistService) ServiceFinder
                    .findBean("VinculoHistService");
            vinculoService.deleteByConocimiento(this.getSelectedOmejora().getNconocimientoid());
            for (Consulta consulta : this.getListaTargetVinculos()) {
                Vinculo vinculo = new Vinculo();
                vinculo.setNvinculoid(vinculoService.getNextPK());
                vinculo.setNconocimientoid(this.getSelectedOmejora().getNconocimientoid());
                vinculo.setNconocimientovinc(consulta.getIdconocimiento());
                vinculo.setNtipoconocimientovinc(consulta.getIdTipoConocimiento());
                vinculo.setDfechacreacion(new Date());
                vinculo.setVusuariocreacion(usuario.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(usuario.getVlogin());
                vinculoHistService.saveOrUpdate(vinculoHist);
            }
        }

        AsignacionService serviceasig = (AsignacionService) ServiceFinder.findBean("AsignacionService");
        this.getSelectedAsignacion().setNestadoid(BigDecimal.valueOf(Long.parseLong("2")));
        this.getSelectedAsignacion().setDfechaatencion(new Date());
        this.getSelectedAsignacion().setNaccionid(BigDecimal.valueOf(Long.parseLong("8")));
        serviceasig.saveOrUpdate(this.getSelectedAsignacion());

        Asignacion asignacion = new Asignacion();
        asignacion.setNasignacionid(serviceasig.getNextPK());
        asignacion.setNtipoconocimientoid(Constante.OPORTUNIDADMEJORA);
        asignacion.setNconocimientoid(this.getSelectedOmejora().getNconocimientoid());
        asignacion.setNestadoid(BigDecimal.valueOf(Long.parseLong("1")));
        CategoriaService categoriaService = (CategoriaService) ServiceFinder.findBean("CategoriaService");
        asignacion.setNusuarioid(categoriaService.getCategoriaById(this.getSelectedOmejora().getNcategoriaid())
                .getNespecialista());
        asignacion.setDfechaasignacion(new Date());
        asignacion.setDfechacreacion(new Date());
        serviceasig.saveOrUpdate(asignacion);

        loginMB.refreshNotifications();
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "INFO.",
                "Se public la oportunidad de mejora.");
        FacesContext.getCurrentInstance().addMessage(null, message);
        FacesContext.getCurrentInstance().getExternalContext().redirect("/gescon/index.xhtml");

    } catch (Exception e) {
        log.error(e.getMessage());
        e.printStackTrace();
    }
}

From source file:org.openbravo.test.costing.TestCosting.java

@Test
public void testCostingLC1113() throws Exception {

    final int day0 = 0;
    final int day1 = 5;
    final int day2 = 10;
    final int day3 = 15;
    final BigDecimal price1 = new BigDecimal("111.00");
    final BigDecimal price2 = new BigDecimal("222.00");
    final BigDecimal price3 = new BigDecimal("333.00");
    final BigDecimal price4 = new BigDecimal("325.00");
    final BigDecimal price5 = new BigDecimal("425.00");
    final BigDecimal price6 = new BigDecimal("112.50");
    final BigDecimal price7 = new BigDecimal("111.6818");
    final BigDecimal price8 = new BigDecimal("225.00");
    final BigDecimal quantity1 = new BigDecimal("50");
    final BigDecimal quantity2 = new BigDecimal("150");
    final BigDecimal quantity3 = new BigDecimal("75");
    final BigDecimal quantity4 = new BigDecimal("125");
    final BigDecimal quantity5 = new BigDecimal("80");
    final BigDecimal quantity6 = new BigDecimal("60");
    final BigDecimal quantity7 = BigDecimal.ONE;

    try {/*from w w  w.  j av a  2s . c om*/

        OBContext.setOBContext(USER_ID, ROLE_ID, CLIENT_ID, ORGANIZATION_ID);
        OBContext.setAdminMode(true);

        // Create a new product for the test
        Product product1 = createProduct(price1);

        // Create a new product for the test
        Product product2 = createProduct(price2);

        // Create a new product for the test
        Product product3 = createProduct(price3);

        // Create purchase order and book it
        Order purchaseOrder1 = createPurchaseOrder(product1, price1, quantity1, day0);

        // Create purchase order and book it
        Order purchaseOrder2 = createPurchaseOrder(product2, price2, quantity2, day0);

        // Create purchase order and book it
        Order purchaseOrder3 = createPurchaseOrder(product2, price2, quantity3, day0);

        // Create purchase order and book it
        Order purchaseOrder4 = createPurchaseOrder(product3, price3, quantity4, day0);

        // Create purchase order and book it
        Order purchaseOrder5 = createPurchaseOrder(product3, price3, quantity5, day0);

        // Create purchase order and book it
        Order purchaseOrder6 = createPurchaseOrder(product1, price1, quantity6, day0);

        // Create goods receipt, run costing background, post it and assert it
        List<Order> purchaseOrderList1 = new ArrayList<Order>();
        purchaseOrderList1.add(purchaseOrder1);
        purchaseOrderList1.add(purchaseOrder2);
        ShipmentInOut goodsReceipt1 = createGoodsReceipt(purchaseOrderList1, null, quantity1.add(quantity2),
                day0);

        // Create goods receipt, run costing background, post it and assert it
        List<Order> purchaseOrderList2 = new ArrayList<Order>();
        purchaseOrderList2.add(purchaseOrder3);
        purchaseOrderList2.add(purchaseOrder4);
        ShipmentInOut goodsReceipt2 = createGoodsReceipt(purchaseOrderList2, null, quantity3.add(quantity4),
                day1);

        // Create goods receipt, run costing background, post it and assert it
        List<Order> purchaseOrderList3 = new ArrayList<Order>();
        purchaseOrderList3.add(purchaseOrder5);
        purchaseOrderList3.add(purchaseOrder6);
        ShipmentInOut goodsReceipt3 = createGoodsReceipt(purchaseOrderList3, null, quantity5.add(quantity6),
                day2);

        // Create Landed Cost
        List<String> landedCostTypeIdList = new ArrayList<String>();
        landedCostTypeIdList.add(LANDEDCOSTTYPE2_ID);
        landedCostTypeIdList.add(LANDEDCOSTTYPE1_ID);
        List<BigDecimal> amountList = new ArrayList<BigDecimal>();
        amountList.add(quantity7.multiply(price4));
        amountList.add(quantity7.multiply(price5));
        List<ShipmentInOut> receiptList = new ArrayList<ShipmentInOut>();
        receiptList.add(goodsReceipt1);
        receiptList.add(goodsReceipt2);
        List<ShipmentInOutLine> receiptLineList = new ArrayList<ShipmentInOutLine>();
        receiptLineList.add(null);
        receiptLineList.add(goodsReceipt2.getMaterialMgmtShipmentInOutLineList().get(0));
        createLandedCost(landedCostTypeIdList, amountList, receiptList, receiptLineList, day3);

        // Assert product transactions 1
        List<ProductTransactionAssert> productTransactionAssertList1 = new ArrayList<ProductTransactionAssert>();
        productTransactionAssertList1.add(
                new ProductTransactionAssert(OBDal.getInstance().get(ShipmentInOut.class, goodsReceipt1.getId())
                        .getMaterialMgmtShipmentInOutLineList().get(0), price1, price6, price1));
        productTransactionAssertList1.add(
                new ProductTransactionAssert(OBDal.getInstance().get(ShipmentInOut.class, goodsReceipt3.getId())
                        .getMaterialMgmtShipmentInOutLineList().get(1), price1, price1));
        assertProductTransaction(product1.getId(), productTransactionAssertList1);

        // Assert product transactions 2
        List<ProductTransactionAssert> productTransactionAssertList2 = new ArrayList<ProductTransactionAssert>();
        productTransactionAssertList2.add(
                new ProductTransactionAssert(OBDal.getInstance().get(ShipmentInOut.class, goodsReceipt1.getId())
                        .getMaterialMgmtShipmentInOutLineList().get(1), price2, price8, price2));
        productTransactionAssertList2.add(
                new ProductTransactionAssert(OBDal.getInstance().get(ShipmentInOut.class, goodsReceipt2.getId())
                        .getMaterialMgmtShipmentInOutLineList().get(0), price2, price8, price2));
        assertProductTransaction(product2.getId(), productTransactionAssertList2);

        // Assert product transactions 3
        List<ProductTransactionAssert> productTransactionAssertList3 = new ArrayList<ProductTransactionAssert>();
        productTransactionAssertList3.add(
                new ProductTransactionAssert(OBDal.getInstance().get(ShipmentInOut.class, goodsReceipt2.getId())
                        .getMaterialMgmtShipmentInOutLineList().get(1), price3, price3));
        productTransactionAssertList3.add(
                new ProductTransactionAssert(OBDal.getInstance().get(ShipmentInOut.class, goodsReceipt3.getId())
                        .getMaterialMgmtShipmentInOutLineList().get(0), price3, price3));
        assertProductTransaction(product3.getId(), productTransactionAssertList3);

        // Assert product costing 1
        List<MaterialTransaction> transactionList1 = getProductTransactions(product1.getId());
        List<ProductCostingAssert> productCostingAssertList1 = new ArrayList<ProductCostingAssert>();
        productCostingAssertList1
                .add(new ProductCostingAssert(transactionList1.get(0), price1, price1, price6, quantity1));
        productCostingAssertList1.add(new ProductCostingAssert(transactionList1.get(1), price1, price1, price7,
                quantity1.add(quantity6)));
        assertProductCosting(product1.getId(), productCostingAssertList1);

        // Assert product costing 2
        List<MaterialTransaction> transactionList2 = getProductTransactions(product2.getId());
        List<ProductCostingAssert> productCostingAssertList2 = new ArrayList<ProductCostingAssert>();
        productCostingAssertList2
                .add(new ProductCostingAssert(transactionList2.get(0), price2, price2, price8, quantity2));
        productCostingAssertList2.add(new ProductCostingAssert(transactionList2.get(1), price2, price2, price8,
                quantity2.add(quantity3)));
        assertProductCosting(product2.getId(), productCostingAssertList2);

        // Assert product costing 3
        List<MaterialTransaction> transactionList3 = getProductTransactions(product3.getId());
        List<ProductCostingAssert> productCostingAssertList3 = new ArrayList<ProductCostingAssert>();
        productCostingAssertList3
                .add(new ProductCostingAssert(transactionList3.get(0), price3, null, price3, quantity4));
        productCostingAssertList3.add(new ProductCostingAssert(transactionList3.get(1), price3, null, price3,
                quantity4.add(quantity5)));
        assertProductCosting(product3.getId(), productCostingAssertList3);

        // Assert cost adjustment 1
        List<CostAdjustment> costAdjustmentList1 = getCostAdjustment(product1.getId());
        List<List<CostAdjustmentAssert>> costAdjustmentAssertList1 = new ArrayList<List<CostAdjustmentAssert>>();
        List<CostAdjustmentAssert> costAdjustmentAssertLineList11 = new ArrayList<CostAdjustmentAssert>();
        costAdjustmentAssertLineList11.add(new CostAdjustmentAssert(transactionList1.get(0), "LC",
                quantity1.multiply(price6).add(quantity1.multiply(price1).negate()), day3, true, false));
        costAdjustmentAssertLineList11.add(new CostAdjustmentAssert(transactionList2.get(0), "LC",
                quantity2.multiply(price8).add(quantity2.multiply(price2).negate()), day3, true, false));
        costAdjustmentAssertLineList11.add(new CostAdjustmentAssert(transactionList2.get(1), "LC",
                quantity3.multiply(price8).add(quantity3.multiply(price2).negate()), day3, true, false));
        costAdjustmentAssertList1.add(costAdjustmentAssertLineList11);
        assertCostAdjustment(costAdjustmentList1, costAdjustmentAssertList1);

        // Assert cost adjustment 2
        List<CostAdjustment> costAdjustmentList2 = getCostAdjustment(product2.getId());
        List<List<CostAdjustmentAssert>> costAdjustmentAssertList2 = new ArrayList<List<CostAdjustmentAssert>>();
        List<CostAdjustmentAssert> costAdjustmentAssertLineList12 = new ArrayList<CostAdjustmentAssert>();
        costAdjustmentAssertLineList12.add(new CostAdjustmentAssert(transactionList1.get(0), "LC",
                quantity1.multiply(price6).add(quantity1.multiply(price1).negate()), day3, true, false));
        costAdjustmentAssertLineList12.add(new CostAdjustmentAssert(transactionList2.get(0), "LC",
                quantity2.multiply(price8).add(quantity2.multiply(price2).negate()), day3, true, false));
        costAdjustmentAssertLineList12.add(new CostAdjustmentAssert(transactionList2.get(1), "LC",
                quantity3.multiply(price8).add(quantity3.multiply(price2).negate()), day3, true, false));
        costAdjustmentAssertList2.add(costAdjustmentAssertLineList12);
        assertCostAdjustment(costAdjustmentList2, costAdjustmentAssertList2);

        // Assert cost adjustment 3
        assertEquals(getCostAdjustment(product3.getId()), null);

        OBDal.getInstance().commitAndClose();

    } catch (Exception e) {
        System.out.println(e.getMessage());
        throw new OBException(e);
    }

    finally {
        OBContext.restorePreviousMode();
    }
}

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

public void analizarOmejora(ActionEvent event) {
    try {/* w w  w . j av a2s. c o m*/
        if (this.getAnalisis() == null) {
            FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "ERROR.",
                    "Seleccione el anlisis correspondiente a la oportunidad de mejora.");
            FacesContext.getCurrentInstance().addMessage(null, message);
            return;
        } else if (this.getAnalisis().equals(BigDecimal.ONE)) {
            if (this.getDias() < 1) {
                FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "ERROR.",
                        "Ingrese los das de implementacin.");
                FacesContext.getCurrentInstance().addMessage(null, message);
                return;
            }
        } else {
            if (StringUtils.isBlank(this.getMotivo())) {
                FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "ERROR.",
                        "Ingrese el motivo del rechazo.");
                FacesContext.getCurrentInstance().addMessage(null, message);
                return;
            }
        }
        LoginMB loginMB = (LoginMB) JSFUtils.getSessionAttribute("loginMB");
        User user = loginMB.getUser();
        this.getSelectedOmejora().setNanalisis(this.getAnalisis());
        this.getSelectedOmejora().setNdias(BigDecimal.valueOf(this.getDias()));
        this.getSelectedOmejora().setVobservacion(this.getMotivo());
        this.getSelectedOmejora().setDfechamodificacion(new Date());
        this.getSelectedOmejora().setVusuariomodificacion(user.getVlogin());
        this.getSelectedOmejora()
                .setNsituacionid(BigDecimal.valueOf(Long.parseLong(Constante.SITUACION_APROBADO)));
        ConocimientoService conocimientoService = (ConocimientoService) ServiceFinder
                .findBean("ConocimientoService");
        conocimientoService.saveOrUpdate(this.getSelectedOmejora());

        String mensaje = "";
        AsignacionService serviceasig = (AsignacionService) ServiceFinder.findBean("AsignacionService");
        this.getSelectedAsignacion().setNestadoid(BigDecimal.valueOf(Long.parseLong("2")));
        this.getSelectedAsignacion().setDfechaatencion(new Date());
        if (this.getAnalisis().equals(BigDecimal.ONE)) {
            this.getSelectedAsignacion().setNaccionid(BigDecimal.valueOf(Long.parseLong("14")));
            mensaje = "Se aprob la iportunidad de mejora.";
        } else {
            this.getSelectedAsignacion().setNaccionid(BigDecimal.valueOf(Long.parseLong("13")));
            mensaje = "Se rechaz la iportunidad de mejora.";
        }

        serviceasig.saveOrUpdate(this.getSelectedAsignacion());

        Asignacion asignacion = new Asignacion();
        asignacion.setNasignacionid(serviceasig.getNextPK());
        asignacion.setNtipoconocimientoid(Constante.OPORTUNIDADMEJORA);
        asignacion.setNconocimientoid(this.getSelectedOmejora().getNconocimientoid());
        asignacion.setNestadoid(BigDecimal.valueOf(Long.parseLong("1")));
        CategoriaService categoriaService = (CategoriaService) ServiceFinder.findBean("CategoriaService");
        asignacion.setNusuarioid(categoriaService.getCategoriaById(this.getSelectedOmejora().getNcategoriaid())
                .getNespecialista());
        asignacion.setDfechaasignacion(new Date());
        asignacion.setDfechacreacion(new Date());
        serviceasig.saveOrUpdate(asignacion);

        loginMB.refreshNotifications();

        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "INFO.", mensaje);
        FacesContext.getCurrentInstance().addMessage(null, message);
        FacesContext.getCurrentInstance().getExternalContext().redirect("/gescon/index.xhtml");
    } catch (Exception e) {
        e.getMessage();
        e.printStackTrace();
    }
}

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

public void implementarOmejora(ActionEvent event) {
    try {//from  w w  w. j a v a  2  s  . c  o m
        //this.setContenidoHtml(JSFUtils.getRequestParameter("descHtml"));
        if (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;
            }
        }
        this.setContenidoPlain(Jsoup.parse(this.getContenidoHtml()).text());
        LoginMB loginMB = (LoginMB) JSFUtils.getSessionAttribute("loginMB");
        User usuario = loginMB.getUser();
        ImplementacionService implementacionService = (ImplementacionService) ServiceFinder
                .findBean("ImplementacionService");
        Implementacion implementacion = new Implementacion();
        implementacion.setNimplementacionid(implementacionService.getNextPK());
        implementacion.setNconocimientoid(this.getSelectedOmejora().getNconocimientoid());
        implementacion.setNtipoconocimientoid(this.getSelectedOmejora().getNtipoconocimientoid());
        implementacion.setNcategoriaid(this.getSelectedOmejora().getNcategoriaid());
        implementacion.setVtitulo(StringUtils.upperCase(this.getSelectedOmejora().getVtitulo()));
        implementacion.setVdescripcion(StringUtils.upperCase(this.getSelectedOmejora().getVdescripcion()));
        if (this.getContenidoPlain().length() < 400) {
            implementacion.setVcontenido(StringUtils.capitalize(this.getContenidoPlain()));
        } else {
            implementacion.setVcontenido(StringUtils.capitalize(this.getContenidoPlain().substring(0, 399)));
        }
        implementacion.setNdestacado(this.getChkDestacado() ? BigDecimal.ONE : BigDecimal.ZERO);

        implementacion.setDfechacreacion(new Date());
        implementacion.setVusuariocreacion(usuario.getVlogin());
        implementacion.setNsituacionid(BigDecimal.valueOf((long) 11));
        implementacionService.saveOrUpdate(implementacion);

        String np = this.pathom.concat(this.getSelectedOmejora().getNconocimientoid().toString())
                .concat("/impl/");
        this.setContenidoPlain(Jsoup.parse(this.getContenidoHtml()).text());
        GcmFileUtils.writeStringToFileServer(np, "html.txt", this.getContenidoHtml());
        GcmFileUtils.writeStringToFileServer(np, "plain.txt", this.getContenidoPlain());

        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 (org.apache.commons.collections.CollectionUtils.isNotEmpty(this.getListaTargetVinculos())) {
            VinculoImplementacionService vinculoService = (VinculoImplementacionService) ServiceFinder
                    .findBean("VinculoImplementacionService");
            vinculoService.deleteByConocimiento(implementacion.getNimplementacionid());
            for (Consulta consulta : this.getListaTargetVinculos()) {
                VinculoImplementacion vinculo = new VinculoImplementacion();
                vinculo.setNimplvinculoid(vinculoService.getNextPK());
                vinculo.setNimplementacionid(implementacion.getNconocimientoid());
                vinculo.setNconocimientovinc(consulta.getIdconocimiento());
                vinculo.setNtipoconocimientovinc(consulta.getIdTipoConocimiento());
                vinculo.setDfechacreacion(new Date());
                vinculo.setVusuariocreacion(usuario.getVlogin());
                vinculoService.saveOrUpdate(vinculo);
            }
        }

        ConocimientoService conocimientoService = (ConocimientoService) ServiceFinder
                .findBean("ConocimientoService");
        this.getSelectedOmejora().setNsituacionid(BigDecimal.valueOf((long) 11));
        conocimientoService.saveOrUpdate(this.getSelectedOmejora());

        AsignacionService serviceasig = (AsignacionService) ServiceFinder.findBean("AsignacionService");
        this.getSelectedAsignacion().setNestadoid(BigDecimal.valueOf(Long.parseLong("2")));
        this.getSelectedAsignacion().setDfechaatencion(new Date());
        this.getSelectedAsignacion().setNaccionid(BigDecimal.valueOf(Long.parseLong("15")));
        serviceasig.saveOrUpdate(this.getSelectedAsignacion());

        Asignacion asignacion = new Asignacion();
        asignacion.setNasignacionid(serviceasig.getNextPK());
        asignacion.setNtipoconocimientoid(Constante.OPORTUNIDADMEJORA);
        asignacion.setNconocimientoid(this.getSelectedOmejora().getNconocimientoid());
        asignacion.setNestadoid(BigDecimal.valueOf(Long.parseLong("1")));
        CategoriaService categoriaService = (CategoriaService) ServiceFinder.findBean("CategoriaService");
        asignacion.setNusuarioid(
                categoriaService.getCategoriaById(this.getSelectedOmejora().getNcategoriaid()).getNmoderador());
        asignacion.setDfechaasignacion(new Date());
        asignacion.setDfechacreacion(new Date());
        serviceasig.saveOrUpdate(asignacion);

        loginMB.refreshNotifications();
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "INFO.",
                "Se implement la oportunidad de mejora.");
        FacesContext.getCurrentInstance().addMessage(null, message);
        FacesContext.getCurrentInstance().getExternalContext().redirect("/gescon/index.xhtml");

    } catch (Exception e) {
        log.error(e.getMessage());
        e.printStackTrace();
    }
}

From source file:org.openbravo.test.costing.TestCosting.java

@Test
public void testCostingLC1114() throws Exception {

    final int day0 = 0;
    final int day1 = 5;
    final int day2 = 10;
    final int day3 = 15;
    final BigDecimal price1 = new BigDecimal("111.00");
    final BigDecimal price2 = new BigDecimal("222.00");
    final BigDecimal price3 = new BigDecimal("333.00");
    final BigDecimal price4 = new BigDecimal("325.00");
    final BigDecimal price5 = new BigDecimal("425.00");
    final BigDecimal price6 = new BigDecimal("112.50");
    final BigDecimal price7 = new BigDecimal("111.6818");
    final BigDecimal price8 = new BigDecimal("225.00");
    final BigDecimal quantity1 = new BigDecimal("50");
    final BigDecimal quantity2 = new BigDecimal("150");
    final BigDecimal quantity3 = new BigDecimal("75");
    final BigDecimal quantity4 = new BigDecimal("125");
    final BigDecimal quantity5 = new BigDecimal("80");
    final BigDecimal quantity6 = new BigDecimal("60");
    final BigDecimal quantity7 = BigDecimal.ONE;

    try {// www . ja v  a2 s  .com

        OBContext.setOBContext(USER_ID, ROLE_ID, CLIENT_ID, ORGANIZATION_ID);
        OBContext.setAdminMode(true);

        // Create a new product for the test
        Product product1 = createProduct(price1);

        // Create a new product for the test
        Product product2 = createProduct(price2);

        // Create a new product for the test
        Product product3 = createProduct(price3);

        // Create purchase order and book it
        Order purchaseOrder1 = createPurchaseOrder(product1, price1, quantity1, day0);

        // Create purchase order and book it
        Order purchaseOrder2 = createPurchaseOrder(product2, price2, quantity2, day0);

        // Create purchase order and book it
        Order purchaseOrder3 = createPurchaseOrder(product2, price2, quantity3, day0);

        // Create purchase order and book it
        Order purchaseOrder4 = createPurchaseOrder(product3, price3, quantity4, day0);

        // Create purchase order and book it
        Order purchaseOrder5 = createPurchaseOrder(product3, price3, quantity5, day0);

        // Create purchase order and book it
        Order purchaseOrder6 = createPurchaseOrder(product1, price1, quantity6, day0);

        // Create goods receipt, run costing background, post it and assert it
        List<Order> purchaseOrderList1 = new ArrayList<Order>();
        purchaseOrderList1.add(purchaseOrder1);
        purchaseOrderList1.add(purchaseOrder2);
        ShipmentInOut goodsReceipt1 = createGoodsReceipt(purchaseOrderList1, null, quantity1.add(quantity2),
                day0);

        // Create goods receipt, run costing background, post it and assert it
        List<Order> purchaseOrderList2 = new ArrayList<Order>();
        purchaseOrderList2.add(purchaseOrder3);
        purchaseOrderList2.add(purchaseOrder4);
        ShipmentInOut goodsReceipt2 = createGoodsReceipt(purchaseOrderList2, null, quantity3.add(quantity4),
                day1);

        // Create goods receipt, run costing background, post it and assert it
        List<Order> purchaseOrderList3 = new ArrayList<Order>();
        purchaseOrderList3.add(purchaseOrder5);
        purchaseOrderList3.add(purchaseOrder6);
        ShipmentInOut goodsReceipt3 = createGoodsReceipt(purchaseOrderList3, null, quantity5.add(quantity6),
                day2);

        // Create Landed Cost
        List<String> landedCostTypeIdList = new ArrayList<String>();
        landedCostTypeIdList.add(LANDEDCOSTTYPE2_ID);
        landedCostTypeIdList.add(LANDEDCOSTTYPE1_ID);
        List<BigDecimal> amountList = new ArrayList<BigDecimal>();
        amountList.add(quantity7.multiply(price4));
        amountList.add(quantity7.multiply(price5));
        List<ShipmentInOut> receiptList = new ArrayList<ShipmentInOut>();
        receiptList.add(goodsReceipt1);
        receiptList.add(goodsReceipt1);
        receiptList.add(goodsReceipt2);
        List<ShipmentInOutLine> receiptLineList = new ArrayList<ShipmentInOutLine>();
        receiptLineList.add(goodsReceipt1.getMaterialMgmtShipmentInOutLineList().get(0));
        receiptLineList.add(goodsReceipt1.getMaterialMgmtShipmentInOutLineList().get(1));
        receiptLineList.add(goodsReceipt2.getMaterialMgmtShipmentInOutLineList().get(0));
        createLandedCost(landedCostTypeIdList, amountList, receiptList, receiptLineList, day3);

        // Assert product transactions 1
        List<ProductTransactionAssert> productTransactionAssertList1 = new ArrayList<ProductTransactionAssert>();
        productTransactionAssertList1.add(
                new ProductTransactionAssert(OBDal.getInstance().get(ShipmentInOut.class, goodsReceipt1.getId())
                        .getMaterialMgmtShipmentInOutLineList().get(0), price1, price6, price1));
        productTransactionAssertList1.add(
                new ProductTransactionAssert(OBDal.getInstance().get(ShipmentInOut.class, goodsReceipt3.getId())
                        .getMaterialMgmtShipmentInOutLineList().get(1), price1, price1));
        assertProductTransaction(product1.getId(), productTransactionAssertList1);

        // Assert product transactions 2
        List<ProductTransactionAssert> productTransactionAssertList2 = new ArrayList<ProductTransactionAssert>();
        productTransactionAssertList2.add(
                new ProductTransactionAssert(OBDal.getInstance().get(ShipmentInOut.class, goodsReceipt1.getId())
                        .getMaterialMgmtShipmentInOutLineList().get(1), price2, price8, price2));
        productTransactionAssertList2.add(
                new ProductTransactionAssert(OBDal.getInstance().get(ShipmentInOut.class, goodsReceipt2.getId())
                        .getMaterialMgmtShipmentInOutLineList().get(0), price2, price8, price2));
        assertProductTransaction(product2.getId(), productTransactionAssertList2);

        // Assert product transactions 3
        List<ProductTransactionAssert> productTransactionAssertList3 = new ArrayList<ProductTransactionAssert>();
        productTransactionAssertList3.add(
                new ProductTransactionAssert(OBDal.getInstance().get(ShipmentInOut.class, goodsReceipt2.getId())
                        .getMaterialMgmtShipmentInOutLineList().get(1), price3, price3));
        productTransactionAssertList3.add(
                new ProductTransactionAssert(OBDal.getInstance().get(ShipmentInOut.class, goodsReceipt3.getId())
                        .getMaterialMgmtShipmentInOutLineList().get(0), price3, price3));
        assertProductTransaction(product3.getId(), productTransactionAssertList3);

        // Assert product costing 1
        List<MaterialTransaction> transactionList1 = getProductTransactions(product1.getId());
        List<ProductCostingAssert> productCostingAssertList1 = new ArrayList<ProductCostingAssert>();
        productCostingAssertList1
                .add(new ProductCostingAssert(transactionList1.get(0), price1, price1, price6, quantity1));
        productCostingAssertList1.add(new ProductCostingAssert(transactionList1.get(1), price1, price1, price7,
                quantity1.add(quantity6)));
        assertProductCosting(product1.getId(), productCostingAssertList1);

        // Assert product costing 2
        List<MaterialTransaction> transactionList2 = getProductTransactions(product2.getId());
        List<ProductCostingAssert> productCostingAssertList2 = new ArrayList<ProductCostingAssert>();
        productCostingAssertList2
                .add(new ProductCostingAssert(transactionList2.get(0), price2, price2, price8, quantity2));
        productCostingAssertList2.add(new ProductCostingAssert(transactionList2.get(1), price2, price2, price8,
                quantity2.add(quantity3)));
        assertProductCosting(product2.getId(), productCostingAssertList2);

        // Assert product costing 3
        List<MaterialTransaction> transactionList3 = getProductTransactions(product3.getId());
        List<ProductCostingAssert> productCostingAssertList3 = new ArrayList<ProductCostingAssert>();
        productCostingAssertList3
                .add(new ProductCostingAssert(transactionList3.get(0), price3, null, price3, quantity4));
        productCostingAssertList3.add(new ProductCostingAssert(transactionList3.get(1), price3, null, price3,
                quantity4.add(quantity5)));
        assertProductCosting(product3.getId(), productCostingAssertList3);

        // Assert cost adjustment 1
        List<CostAdjustment> costAdjustmentList1 = getCostAdjustment(product1.getId());
        List<List<CostAdjustmentAssert>> costAdjustmentAssertList1 = new ArrayList<List<CostAdjustmentAssert>>();
        List<CostAdjustmentAssert> costAdjustmentAssertLineList11 = new ArrayList<CostAdjustmentAssert>();
        costAdjustmentAssertLineList11.add(new CostAdjustmentAssert(transactionList1.get(0), "LC",
                quantity1.multiply(price6).add(quantity1.multiply(price1).negate()), day3, true, false));
        costAdjustmentAssertLineList11.add(new CostAdjustmentAssert(transactionList2.get(0), "LC",
                quantity2.multiply(price8).add(quantity2.multiply(price2).negate()), day3, true, false));
        costAdjustmentAssertLineList11.add(new CostAdjustmentAssert(transactionList2.get(1), "LC",
                quantity3.multiply(price8).add(quantity3.multiply(price2).negate()), day3, true, false));
        costAdjustmentAssertList1.add(costAdjustmentAssertLineList11);
        assertCostAdjustment(costAdjustmentList1, costAdjustmentAssertList1);

        // Assert cost adjustment 2
        List<CostAdjustment> costAdjustmentList2 = getCostAdjustment(product2.getId());
        List<List<CostAdjustmentAssert>> costAdjustmentAssertList2 = new ArrayList<List<CostAdjustmentAssert>>();
        List<CostAdjustmentAssert> costAdjustmentAssertLineList12 = new ArrayList<CostAdjustmentAssert>();
        costAdjustmentAssertLineList12.add(new CostAdjustmentAssert(transactionList1.get(0), "LC",
                quantity1.multiply(price6).add(quantity1.multiply(price1).negate()), day3, true, false));
        costAdjustmentAssertLineList12.add(new CostAdjustmentAssert(transactionList2.get(0), "LC",
                quantity2.multiply(price8).add(quantity2.multiply(price2).negate()), day3, true, false));
        costAdjustmentAssertLineList12.add(new CostAdjustmentAssert(transactionList2.get(1), "LC",
                quantity3.multiply(price8).add(quantity3.multiply(price2).negate()), day3, true, false));
        costAdjustmentAssertList2.add(costAdjustmentAssertLineList12);
        assertCostAdjustment(costAdjustmentList2, costAdjustmentAssertList2);

        // Assert cost adjustment 3
        assertEquals(getCostAdjustment(product3.getId()), null);

        OBDal.getInstance().commitAndClose();

    } catch (Exception e) {
        System.out.println(e.getMessage());
        throw new OBException(e);
    }

    finally {
        OBContext.restorePreviousMode();
    }
}

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

public void saveBpracticaEdit(ActionEvent event) {
    String pagina = null;/*from w  w  w.  j  a v  a  2  s.c o  m*/
    try {
        //this.setDescripcionHtml(JSFUtils.getRequestParameter("descHtml"));
        if (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;
            }
        }
        this.setDescripcionPlain(Jsoup.parse(this.getDescripcionHtml()).text());
        LoginMB loginMB = (LoginMB) JSFUtils.getSessionAttribute("loginMB");
        User usuario = loginMB.getUser();
        ConocimientoService conocimientoService = (ConocimientoService) ServiceFinder
                .findBean("ConocimientoService");

        if (this.getSelectedCategoria() == null) {
            this.getSelectedBpractica().setNcategoriaid(this.getSelectedBpractica().getNcategoriaid());
            cat_nueva = this.getSelectedBpractica().getNcategoriaid();
        } else {
            this.getSelectedBpractica().setNcategoriaid(this.getSelectedBpractica().getNcategoriaid());
            cat_nueva = this.getSelectedBpractica().getNcategoriaid();
        }

        this.getSelectedBpractica()
                .setVtitulo(StringUtils.upperCase(this.getSelectedBpractica().getVtitulo().trim()));
        if (this.getDescripcionPlain().length() < 400) {
            this.getSelectedBpractica().setVdescripcion(StringUtils.capitalize(this.getDescripcionPlain()));
        } else {
            this.getSelectedBpractica()
                    .setVdescripcion(StringUtils.capitalize(this.getDescripcionPlain().substring(0, 399)));
        }
        this.getSelectedBpractica().setNdestacado(this.getChkDestacado() ? BigDecimal.ONE : BigDecimal.ZERO);
        this.getSelectedBpractica().setDfechamodificacion(new Date());
        this.getSelectedBpractica().setVusuariomodificacion(usuario.getVlogin());
        conocimientoService.saveOrUpdate(this.getSelectedBpractica());

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

        HistorialService historialService = (HistorialService) ServiceFinder.findBean("HistorialService");
        Historial lastHistorial = historialService
                .getLastHistorialByConocimiento(this.getSelectedBpractica().getNconocimientoid());
        int lastversion;
        if (lastHistorial != null) {
            lastversion = lastHistorial.getNnumversion().intValue();
        } else {
            lastversion = 0;
        }
        String url = this.pathbp.concat(this.getSelectedBpractica().getNconocimientoid().toString()).concat("/")
                .concat(Integer.toString(lastversion + 1)).concat("/");

        ThistorialId thistorialId = new ThistorialId();
        thistorialId.setNconocimientoid(this.getSelectedBpractica().getNconocimientoid());
        thistorialId.setNhistorialid(historialService.getNextPK());
        Historial historial = new Historial();
        historial.setId(thistorialId);
        historial.setNtipoconocimientoid(Constante.BUENAPRACTICA);
        historial.setNcategoriaid(this.getSelectedCategoria().getNcategoriaid());
        historial.setVtitulo(this.getSelectedBpractica().getVtitulo());
        historial.setNactivo(BigDecimal.ONE);
        historial.setNsituacionid(this.getSelectedBpractica().getNsituacionid());
        historial.setVruta(url);
        historial.setNnumversion(BigDecimal.valueOf(lastversion + 1));
        historial.setDfechacreacion(new Date());
        historial.setVusuariocreacion(usuario.getVlogin());
        historial.setVmsjsolicita(this.getSelectedBpractica().getVmsjsolicita());
        historial.setVmsjrespuesta(this.getSelectedBpractica().getVmsjrespuesta());
        historialService.saveOrUpdate(historial);

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

        if (org.apache.commons.collections.CollectionUtils.isNotEmpty(this.getListaSeccion())) {
            String url0 = this.getSelectedBpractica().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(usuario.getVlogin());
                } else {
                    seccion.setNseccionid(seccionService.getNextPK());
                    seccion.setNconocimientoid(this.getSelectedBpractica().getNconocimientoid());
                    seccion.setDfechacreacion(new Date());
                    seccion.setVusuariocreacion(usuario.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(usuario.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 (org.apache.commons.collections.CollectionUtils.isNotEmpty(this.getListaTargetVinculos())) {
            VinculoService vinculoService = (VinculoService) ServiceFinder.findBean("VinculoService");
            VinculoHistService vinculoHistService = (VinculoHistService) ServiceFinder
                    .findBean("VinculoHistService");
            vinculoService.deleteByConocimiento(this.getSelectedBpractica().getNconocimientoid());
            for (Consulta consulta : this.getListaTargetVinculos()) {
                Vinculo vinculo = new Vinculo();
                vinculo.setNvinculoid(vinculoService.getNextPK());
                vinculo.setNconocimientoid(this.getSelectedBpractica().getNconocimientoid());
                vinculo.setNconocimientovinc(consulta.getIdconocimiento());
                vinculo.setNtipoconocimientovinc(consulta.getIdTipoConocimiento());
                vinculo.setDfechacreacion(new Date());
                vinculo.setVusuariocreacion(usuario.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(usuario.getVlogin());
                vinculoHistService.saveOrUpdate(vinculoHist);
            }
        }

        if (cat_antigua != cat_nueva) {
            AsignacionService serviceasig = (AsignacionService) ServiceFinder.findBean("AsignacionService");
            this.getSelectedAsignacion().setNestadoid(BigDecimal.valueOf(Long.parseLong("2")));
            this.getSelectedAsignacion().setDfechaatencion(new Date());
            this.getSelectedAsignacion().setNaccionid(BigDecimal.valueOf(Long.parseLong("12")));
            serviceasig.saveOrUpdate(this.getSelectedAsignacion());

            Asignacion asignacion = new Asignacion();
            asignacion.setNasignacionid(serviceasig.getNextPK());
            asignacion.setNtipoconocimientoid(Constante.BUENAPRACTICA);
            asignacion.setNconocimientoid(this.getSelectedBpractica().getNconocimientoid());
            asignacion.setNestadoid(BigDecimal.valueOf(Long.parseLong("1")));
            CategoriaService categoriaService = (CategoriaService) ServiceFinder.findBean("CategoriaService");
            asignacion.setNusuarioid(categoriaService
                    .getCategoriaById(this.getSelectedBpractica().getNcategoriaid()).getNmoderador());
            asignacion.setDfechaasignacion(new Date());
            asignacion.setDfechacreacion(new Date());
            serviceasig.saveOrUpdate(asignacion);

            pagina = "/gescon/index.xhtml";
        } else {
            pagina = "";
        }
        loginMB.refreshNotifications();
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "INFO.",
                "Actualizacin exitosa!.");
        FacesContext.getCurrentInstance().addMessage(null, message);
        FacesContext.getCurrentInstance().getExternalContext().redirect(pagina);
    } catch (Exception e) {
        e.getMessage();
        e.printStackTrace();
    }
}

From source file:org.openbravo.test.costing.TestCosting.java

@Test
public void testCostingLC1115() throws Exception {

    final int day0 = 0;
    final int day1 = 5;
    final int day2 = 10;
    final int day3 = 15;
    final BigDecimal price1 = new BigDecimal("111.00");
    final BigDecimal price2 = new BigDecimal("222.00");
    final BigDecimal price3 = new BigDecimal("333.00");
    final BigDecimal price4 = new BigDecimal("325.00");
    final BigDecimal price5 = new BigDecimal("425.00");
    final BigDecimal price6 = new BigDecimal("111.6726");
    final BigDecimal price7 = new BigDecimal("111.3057");
    final BigDecimal price8 = new BigDecimal("223.345267");
    final BigDecimal price9 = new BigDecimal("335.0179");
    final BigDecimal price10 = new BigDecimal("335.0180");
    final BigDecimal quantity1 = new BigDecimal("50");
    final BigDecimal quantity2 = new BigDecimal("150");
    final BigDecimal quantity3 = new BigDecimal("75");
    final BigDecimal quantity4 = new BigDecimal("125");
    final BigDecimal quantity5 = new BigDecimal("80");
    final BigDecimal quantity6 = new BigDecimal("60");
    final BigDecimal quantity7 = BigDecimal.ONE;

    try {/*ww  w.  ja  v a 2s  .c  om*/

        OBContext.setOBContext(USER_ID, ROLE_ID, CLIENT_ID, ORGANIZATION_ID);
        OBContext.setAdminMode(true);

        // Create a new product for the test
        Product product1 = createProduct(price1);

        // Create a new product for the test
        Product product2 = createProduct(price2);

        // Create a new product for the test
        Product product3 = createProduct(price3);

        // Create purchase order and book it
        Order purchaseOrder1 = createPurchaseOrder(product1, price1, quantity1, day0);

        // Create purchase order and book it
        Order purchaseOrder2 = createPurchaseOrder(product2, price2, quantity2, day0);

        // Create purchase order and book it
        Order purchaseOrder3 = createPurchaseOrder(product2, price2, quantity3, day0);

        // Create purchase order and book it
        Order purchaseOrder4 = createPurchaseOrder(product3, price3, quantity4, day0);

        // Create purchase order and book it
        Order purchaseOrder5 = createPurchaseOrder(product3, price3, quantity5, day0);

        // Create purchase order and book it
        Order purchaseOrder6 = createPurchaseOrder(product1, price1, quantity6, day0);

        // Create goods receipt, run costing background, post it and assert it
        List<Order> purchaseOrderList1 = new ArrayList<Order>();
        purchaseOrderList1.add(purchaseOrder1);
        purchaseOrderList1.add(purchaseOrder2);
        ShipmentInOut goodsReceipt1 = createGoodsReceipt(purchaseOrderList1, null, quantity1.add(quantity2),
                day0);

        // Create goods receipt, run costing background, post it and assert it
        List<Order> purchaseOrderList2 = new ArrayList<Order>();
        purchaseOrderList2.add(purchaseOrder3);
        purchaseOrderList2.add(purchaseOrder4);
        ShipmentInOut goodsReceipt2 = createGoodsReceipt(purchaseOrderList2, null, quantity3.add(quantity4),
                day1);

        // Create goods receipt, run costing background, post it and assert it
        List<Order> purchaseOrderList3 = new ArrayList<Order>();
        purchaseOrderList3.add(purchaseOrder5);
        purchaseOrderList3.add(purchaseOrder6);
        ShipmentInOut goodsReceipt3 = createGoodsReceipt(purchaseOrderList3, null, quantity5.add(quantity6),
                day2);

        // Create Landed Cost
        List<String> landedCostTypeIdList = new ArrayList<String>();
        landedCostTypeIdList.add(LANDEDCOSTTYPE2_ID);
        landedCostTypeIdList.add(LANDEDCOSTTYPE1_ID);
        List<BigDecimal> amountList = new ArrayList<BigDecimal>();
        amountList.add(quantity7.multiply(price4));
        amountList.add(quantity7.multiply(price5));
        List<ShipmentInOut> receiptList = new ArrayList<ShipmentInOut>();
        receiptList.add(goodsReceipt1);
        receiptList.add(goodsReceipt2);
        receiptList.add(goodsReceipt2);
        receiptList.add(goodsReceipt3);
        List<ShipmentInOutLine> receiptLineList = new ArrayList<ShipmentInOutLine>();
        receiptLineList.add(null);
        receiptLineList.add(goodsReceipt2.getMaterialMgmtShipmentInOutLineList().get(0));
        receiptLineList.add(goodsReceipt2.getMaterialMgmtShipmentInOutLineList().get(1));
        receiptLineList.add(goodsReceipt3.getMaterialMgmtShipmentInOutLineList().get(0));
        createLandedCost(landedCostTypeIdList, amountList, receiptList, receiptLineList, day3);

        // Assert product transactions 1
        List<ProductTransactionAssert> productTransactionAssertList1 = new ArrayList<ProductTransactionAssert>();
        productTransactionAssertList1.add(
                new ProductTransactionAssert(OBDal.getInstance().get(ShipmentInOut.class, goodsReceipt1.getId())
                        .getMaterialMgmtShipmentInOutLineList().get(0), price1, price6, price1));
        productTransactionAssertList1.add(
                new ProductTransactionAssert(OBDal.getInstance().get(ShipmentInOut.class, goodsReceipt3.getId())
                        .getMaterialMgmtShipmentInOutLineList().get(1), price1, price1));
        assertProductTransaction(product1.getId(), productTransactionAssertList1);

        // Assert product transactions 2
        List<ProductTransactionAssert> productTransactionAssertList2 = new ArrayList<ProductTransactionAssert>();
        productTransactionAssertList2.add(
                new ProductTransactionAssert(OBDal.getInstance().get(ShipmentInOut.class, goodsReceipt1.getId())
                        .getMaterialMgmtShipmentInOutLineList().get(1), price2, price8, price2));
        productTransactionAssertList2.add(
                new ProductTransactionAssert(OBDal.getInstance().get(ShipmentInOut.class, goodsReceipt2.getId())
                        .getMaterialMgmtShipmentInOutLineList().get(0), price2, price8, price2));
        assertProductTransaction(product2.getId(), productTransactionAssertList2);

        // Assert product transactions 3
        List<ProductTransactionAssert> productTransactionAssertList3 = new ArrayList<ProductTransactionAssert>();
        productTransactionAssertList3.add(
                new ProductTransactionAssert(OBDal.getInstance().get(ShipmentInOut.class, goodsReceipt2.getId())
                        .getMaterialMgmtShipmentInOutLineList().get(1), price3, price9, price3));
        productTransactionAssertList3.add(
                new ProductTransactionAssert(OBDal.getInstance().get(ShipmentInOut.class, goodsReceipt3.getId())
                        .getMaterialMgmtShipmentInOutLineList().get(0), price3, price10, price3));
        assertProductTransaction(product3.getId(), productTransactionAssertList3);

        // Assert product costing 1
        List<MaterialTransaction> transactionList1 = getProductTransactions(product1.getId());
        List<ProductCostingAssert> productCostingAssertList1 = new ArrayList<ProductCostingAssert>();
        productCostingAssertList1
                .add(new ProductCostingAssert(transactionList1.get(0), price1, price1, price6, quantity1));
        productCostingAssertList1.add(new ProductCostingAssert(transactionList1.get(1), price1, price1, price7,
                quantity1.add(quantity6)));
        assertProductCosting(product1.getId(), productCostingAssertList1);

        // Assert product costing 2
        List<MaterialTransaction> transactionList2 = getProductTransactions(product2.getId());
        List<ProductCostingAssert> productCostingAssertList2 = new ArrayList<ProductCostingAssert>();
        productCostingAssertList2
                .add(new ProductCostingAssert(transactionList2.get(0), price2, price2, price8, quantity2));
        productCostingAssertList2.add(new ProductCostingAssert(transactionList2.get(1), price2, price2, price8,
                quantity2.add(quantity3)));
        assertProductCosting(product2.getId(), productCostingAssertList2);

        // Assert product costing 3
        List<MaterialTransaction> transactionList3 = getProductTransactions(product3.getId());
        List<ProductCostingAssert> productCostingAssertList3 = new ArrayList<ProductCostingAssert>();
        productCostingAssertList3
                .add(new ProductCostingAssert(transactionList3.get(0), price3, price3, price9, quantity4));
        productCostingAssertList3.add(new ProductCostingAssert(transactionList3.get(1), price3, price3, price10,
                quantity4.add(quantity5)));
        assertProductCosting(product3.getId(), productCostingAssertList3);

        // Assert cost adjustment 1
        List<CostAdjustment> costAdjustmentList1 = getCostAdjustment(product1.getId());
        List<List<CostAdjustmentAssert>> costAdjustmentAssertList1 = new ArrayList<List<CostAdjustmentAssert>>();
        List<CostAdjustmentAssert> costAdjustmentAssertLineList11 = new ArrayList<CostAdjustmentAssert>();
        costAdjustmentAssertLineList11.add(new CostAdjustmentAssert(transactionList1.get(0), "LC",
                quantity1.multiply(price6).add(quantity1.multiply(price1).negate()), day3, true, false));
        costAdjustmentAssertLineList11.add(new CostAdjustmentAssert(transactionList2.get(0), "LC",
                quantity2.multiply(price8).add(quantity2.multiply(price2).negate()), day3, true, false));
        costAdjustmentAssertLineList11.add(new CostAdjustmentAssert(transactionList2.get(1), "LC",
                quantity3.multiply(price8).add(quantity3.multiply(price2).negate()), day3, true, false));
        costAdjustmentAssertLineList11.add(new CostAdjustmentAssert(transactionList3.get(0), "LC",
                quantity4.multiply(price9).add(quantity4.multiply(price3).negate()), day3, true, false));
        costAdjustmentAssertLineList11.add(new CostAdjustmentAssert(transactionList3.get(1), "LC",
                quantity5.multiply(price10).add(quantity5.multiply(price3).negate()), day3, true, false));
        costAdjustmentAssertList1.add(costAdjustmentAssertLineList11);
        assertCostAdjustment(costAdjustmentList1, costAdjustmentAssertList1);

        // Assert cost adjustment 2
        List<CostAdjustment> costAdjustmentList2 = getCostAdjustment(product2.getId());
        List<List<CostAdjustmentAssert>> costAdjustmentAssertList2 = new ArrayList<List<CostAdjustmentAssert>>();
        List<CostAdjustmentAssert> costAdjustmentAssertLineList12 = new ArrayList<CostAdjustmentAssert>();
        costAdjustmentAssertLineList12.add(new CostAdjustmentAssert(transactionList1.get(0), "LC",
                quantity1.multiply(price6).add(quantity1.multiply(price1).negate()), day3, true, false));
        costAdjustmentAssertLineList12.add(new CostAdjustmentAssert(transactionList2.get(0), "LC",
                quantity2.multiply(price8).add(quantity2.multiply(price2).negate()), day3, true, false));
        costAdjustmentAssertLineList12.add(new CostAdjustmentAssert(transactionList2.get(1), "LC",
                quantity3.multiply(price8).add(quantity3.multiply(price2).negate()), day3, true, false));
        costAdjustmentAssertLineList12.add(new CostAdjustmentAssert(transactionList3.get(0), "LC",
                quantity4.multiply(price9).add(quantity4.multiply(price3).negate()), day3, true, false));
        costAdjustmentAssertLineList12.add(new CostAdjustmentAssert(transactionList3.get(1), "LC",
                quantity5.multiply(price10).add(quantity5.multiply(price3).negate()), day3, true, false));
        costAdjustmentAssertList2.add(costAdjustmentAssertLineList12);
        assertCostAdjustment(costAdjustmentList2, costAdjustmentAssertList2);

        // Assert cost adjustment 3
        List<CostAdjustment> costAdjustmentList3 = getCostAdjustment(product3.getId());
        List<List<CostAdjustmentAssert>> costAdjustmentAssertList3 = new ArrayList<List<CostAdjustmentAssert>>();
        List<CostAdjustmentAssert> costAdjustmentAssertLineList13 = new ArrayList<CostAdjustmentAssert>();
        costAdjustmentAssertLineList13.add(new CostAdjustmentAssert(transactionList1.get(0), "LC",
                quantity1.multiply(price6).add(quantity1.multiply(price1).negate()), day3, true, false));
        costAdjustmentAssertLineList13.add(new CostAdjustmentAssert(transactionList2.get(0), "LC",
                quantity2.multiply(price8).add(quantity2.multiply(price2).negate()), day3, true, false));
        costAdjustmentAssertLineList13.add(new CostAdjustmentAssert(transactionList2.get(1), "LC",
                quantity3.multiply(price8).add(quantity3.multiply(price2).negate()), day3, true, false));
        costAdjustmentAssertLineList13.add(new CostAdjustmentAssert(transactionList3.get(0), "LC",
                quantity4.multiply(price9).add(quantity4.multiply(price3).negate()), day3, true, false));
        costAdjustmentAssertLineList13.add(new CostAdjustmentAssert(transactionList3.get(1), "LC",
                quantity5.multiply(price10).add(quantity5.multiply(price3).negate()), day3, true, false));
        costAdjustmentAssertList3.add(costAdjustmentAssertLineList13);
        assertCostAdjustment(costAdjustmentList3, costAdjustmentAssertList3);

        OBDal.getInstance().commitAndClose();

    } catch (Exception e) {
        System.out.println(e.getMessage());
        throw new OBException(e);
    }

    finally {
        OBContext.restorePreviousMode();
    }
}

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

public void saveOmejoraEdit(ActionEvent event) {
    String pagina = null;//  w  ww.  j a  v  a  2s .c o  m
    try {
        //this.setContenidoHtml(JSFUtils.getRequestParameter("descHtml"));
        if (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;
            }
        }
        this.setContenidoPlain(Jsoup.parse(this.getContenidoHtml()).text());
        LoginMB loginMB = (LoginMB) JSFUtils.getSessionAttribute("loginMB");
        User usuario = loginMB.getUser();
        ConocimientoService conocimientoService = (ConocimientoService) ServiceFinder
                .findBean("ConocimientoService");

        if (this.getSelectedCategoria() == null) {
            this.getSelectedOmejora().setNcategoriaid(this.getSelectedOmejora().getNcategoriaid());
            cat_nueva = this.getSelectedOmejora().getNcategoriaid();
        } else {
            this.getSelectedOmejora().setNcategoriaid(this.getSelectedOmejora().getNcategoriaid());
            cat_nueva = this.getSelectedOmejora().getNcategoriaid();
        }

        this.getSelectedOmejora().setVtitulo(StringUtils.upperCase(this.getSelectedOmejora().getVtitulo()));
        this.getSelectedOmejora()
                .setVdescripcion(StringUtils.upperCase(this.getSelectedOmejora().getVdescripcion()));
        if (this.getContenidoPlain().length() < 400) {
            this.getSelectedOmejora().setVcontenido(StringUtils.capitalize(this.getContenidoPlain()));
        } else {
            this.getSelectedOmejora()
                    .setVcontenido(StringUtils.capitalize(this.getContenidoPlain().substring(0, 399)));
        }
        this.getSelectedOmejora().setNdestacado(this.getChkDestacado() ? BigDecimal.ONE : BigDecimal.ZERO);
        this.getSelectedOmejora().setDfechamodificacion(new Date());
        this.getSelectedOmejora().setVusuariomodificacion(usuario.getVlogin());
        conocimientoService.saveOrUpdate(this.getSelectedOmejora());

        this.setContenidoPlain(Jsoup.parse(this.getContenidoHtml()).text());
        GcmFileUtils.writeStringToFileServer(this.getSelectedOmejora().getVruta(), "html.txt",
                this.getContenidoHtml());
        GcmFileUtils.writeStringToFileServer(this.getSelectedOmejora().getVruta(), "plain.txt",
                this.getContenidoPlain());

        HistorialService historialService = (HistorialService) ServiceFinder.findBean("HistorialService");
        Historial lastHistorial = historialService
                .getLastHistorialByConocimiento(this.getSelectedOmejora().getNconocimientoid());
        int lastversion;
        if (lastHistorial != null) {
            lastversion = lastHistorial.getNnumversion().intValue();
        } else {
            lastversion = 0;
        }
        String url = this.pathom.concat(this.getSelectedOmejora().getNconocimientoid().toString()).concat("/")
                .concat(Integer.toString(lastversion + 1)).concat("/");

        ThistorialId thistorialId = new ThistorialId();
        thistorialId.setNconocimientoid(this.getSelectedOmejora().getNconocimientoid());
        thistorialId.setNhistorialid(historialService.getNextPK());
        Historial historial = new Historial();
        historial.setId(thistorialId);
        historial.setNtipoconocimientoid(Constante.OPORTUNIDADMEJORA);
        historial.setNcategoriaid(this.getSelectedCategoria().getNcategoriaid());
        historial.setVtitulo(this.getSelectedOmejora().getVtitulo());
        historial.setVdescripcion(this.getSelectedOmejora().getVdescripcion());
        historial.setNactivo(BigDecimal.ONE);
        historial.setNsituacionid(this.getSelectedOmejora().getNsituacionid());
        historial.setVruta(url);
        historial.setNnumversion(BigDecimal.valueOf(lastversion + 1));
        historial.setDfechacreacion(new Date());
        historial.setVusuariocreacion(usuario.getVlogin());
        historial.setVmsjsolicita(this.getSelectedOmejora().getVmsjsolicita());
        historial.setVmsjrespuesta(this.getSelectedOmejora().getVmsjrespuesta());
        historialService.saveOrUpdate(historial);

        GcmFileUtils.writeStringToFileServer(url, "html.txt", this.getContenidoHtml());
        GcmFileUtils.writeStringToFileServer(url, "plain.txt", this.getContenidoPlain());

        if (org.apache.commons.collections.CollectionUtils.isNotEmpty(this.getListaSeccion())) {
            String url0 = this.getSelectedOmejora().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(usuario.getVlogin());
                } else {
                    seccion.setNseccionid(seccionService.getNextPK());
                    seccion.setNconocimientoid(this.getSelectedOmejora().getNconocimientoid());
                    seccion.setDfechacreacion(new Date());
                    seccion.setVusuariocreacion(usuario.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(usuario.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 (org.apache.commons.collections.CollectionUtils.isNotEmpty(this.getListaTargetVinculos())) {
            VinculoService vinculoService = (VinculoService) ServiceFinder.findBean("VinculoService");
            VinculoHistService vinculoHistService = (VinculoHistService) ServiceFinder
                    .findBean("VinculoHistService");
            vinculoService.deleteByConocimiento(this.getSelectedOmejora().getNconocimientoid());
            for (Consulta consulta : this.getListaTargetVinculos()) {
                Vinculo vinculo = new Vinculo();
                vinculo.setNvinculoid(vinculoService.getNextPK());
                vinculo.setNconocimientoid(this.getSelectedOmejora().getNconocimientoid());
                vinculo.setNconocimientovinc(consulta.getIdconocimiento());
                vinculo.setNtipoconocimientovinc(consulta.getIdTipoConocimiento());
                vinculo.setDfechacreacion(new Date());
                vinculo.setVusuariocreacion(usuario.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(usuario.getVlogin());
                vinculoHistService.saveOrUpdate(vinculoHist);
            }
        }

        if (cat_antigua != cat_nueva) {
            AsignacionService serviceasig = (AsignacionService) ServiceFinder.findBean("AsignacionService");
            this.getSelectedAsignacion().setNestadoid(BigDecimal.valueOf(Long.parseLong("2")));
            this.getSelectedAsignacion().setDfechaatencion(new Date());
            this.getSelectedAsignacion().setNaccionid(BigDecimal.valueOf(Long.parseLong("12")));
            serviceasig.saveOrUpdate(this.getSelectedAsignacion());

            Asignacion asignacion = new Asignacion();
            asignacion.setNasignacionid(serviceasig.getNextPK());
            asignacion.setNtipoconocimientoid(Constante.OPORTUNIDADMEJORA);
            asignacion.setNconocimientoid(this.getSelectedOmejora().getNconocimientoid());
            asignacion.setNestadoid(BigDecimal.valueOf(Long.parseLong("1")));
            CategoriaService categoriaService = (CategoriaService) ServiceFinder.findBean("CategoriaService");
            asignacion.setNusuarioid(categoriaService
                    .getCategoriaById(this.getSelectedOmejora().getNcategoriaid()).getNmoderador());
            asignacion.setDfechaasignacion(new Date());
            asignacion.setDfechacreacion(new Date());
            serviceasig.saveOrUpdate(asignacion);

            pagina = "/gescon/index.xhtml";
        } else {
            pagina = "";
        }
        loginMB.refreshNotifications();
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "INFO.",
                "Actualizacin exitosa!.");
        FacesContext.getCurrentInstance().addMessage(null, message);
        FacesContext.getCurrentInstance().getExternalContext().redirect(pagina);
    } catch (Exception e) {
        e.getMessage();
        e.printStackTrace();
    }
}

From source file:org.openbravo.test.costing.TestCosting.java

@Test
public void testCostingLC1116() throws Exception {

    final int day0 = 0;
    final int day1 = 5;
    final int day2 = 10;
    final int day3 = 15;
    final BigDecimal price1 = new BigDecimal("111.00");
    final BigDecimal price2 = new BigDecimal("222.00");
    final BigDecimal price3 = new BigDecimal("333.00");
    final BigDecimal price4 = new BigDecimal("325.00");
    final BigDecimal price5 = new BigDecimal("425.00");
    final BigDecimal price6 = new BigDecimal("111.6726");
    final BigDecimal price7 = new BigDecimal("111.3057");
    final BigDecimal price8 = new BigDecimal("223.345267");
    final BigDecimal price9 = new BigDecimal("335.0179");
    final BigDecimal price10 = new BigDecimal("335.0180");
    final BigDecimal quantity1 = new BigDecimal("50");
    final BigDecimal quantity2 = new BigDecimal("150");
    final BigDecimal quantity3 = new BigDecimal("75");
    final BigDecimal quantity4 = new BigDecimal("125");
    final BigDecimal quantity5 = new BigDecimal("80");
    final BigDecimal quantity6 = new BigDecimal("60");
    final BigDecimal quantity7 = BigDecimal.ONE;

    try {/* ww w  .  j  av  a 2 s. c o  m*/

        OBContext.setOBContext(USER_ID, ROLE_ID, CLIENT_ID, ORGANIZATION_ID);
        OBContext.setAdminMode(true);

        // Create a new product for the test
        Product product1 = createProduct(price1);

        // Create a new product for the test
        Product product2 = createProduct(price2);

        // Create a new product for the test
        Product product3 = createProduct(price3);

        // Create purchase order and book it
        Order purchaseOrder1 = createPurchaseOrder(product1, price1, quantity1, day0);

        // Create purchase order and book it
        Order purchaseOrder2 = createPurchaseOrder(product2, price2, quantity2, day0);

        // Create purchase order and book it
        Order purchaseOrder3 = createPurchaseOrder(product2, price2, quantity3, day0);

        // Create purchase order and book it
        Order purchaseOrder4 = createPurchaseOrder(product3, price3, quantity4, day0);

        // Create purchase order and book it
        Order purchaseOrder5 = createPurchaseOrder(product3, price3, quantity5, day0);

        // Create purchase order and book it
        Order purchaseOrder6 = createPurchaseOrder(product1, price1, quantity6, day0);

        // Create goods receipt, run costing background, post it and assert it
        List<Order> purchaseOrderList1 = new ArrayList<Order>();
        purchaseOrderList1.add(purchaseOrder1);
        purchaseOrderList1.add(purchaseOrder2);
        ShipmentInOut goodsReceipt1 = createGoodsReceipt(purchaseOrderList1, null, quantity1.add(quantity2),
                day0);

        // Create goods receipt, run costing background, post it and assert it
        List<Order> purchaseOrderList2 = new ArrayList<Order>();
        purchaseOrderList2.add(purchaseOrder3);
        purchaseOrderList2.add(purchaseOrder4);
        ShipmentInOut goodsReceipt2 = createGoodsReceipt(purchaseOrderList2, null, quantity3.add(quantity4),
                day1);

        // Create goods receipt, run costing background, post it and assert it
        List<Order> purchaseOrderList3 = new ArrayList<Order>();
        purchaseOrderList3.add(purchaseOrder5);
        purchaseOrderList3.add(purchaseOrder6);
        ShipmentInOut goodsReceipt3 = createGoodsReceipt(purchaseOrderList3, null, quantity5.add(quantity6),
                day2);

        // Create Landed Cost
        List<String> landedCostTypeIdList = new ArrayList<String>();
        landedCostTypeIdList.add(LANDEDCOSTTYPE2_ID);
        landedCostTypeIdList.add(LANDEDCOSTTYPE1_ID);
        List<BigDecimal> amountList = new ArrayList<BigDecimal>();
        amountList.add(quantity7.multiply(price4));
        amountList.add(quantity7.multiply(price5));
        List<ShipmentInOut> receiptList = new ArrayList<ShipmentInOut>();
        receiptList.add(goodsReceipt1);
        receiptList.add(goodsReceipt2);
        receiptList.add(goodsReceipt3);
        List<ShipmentInOutLine> receiptLineList = new ArrayList<ShipmentInOutLine>();
        receiptLineList.add(null);
        receiptLineList.add(null);
        receiptLineList.add(goodsReceipt3.getMaterialMgmtShipmentInOutLineList().get(0));
        createLandedCost(landedCostTypeIdList, amountList, receiptList, receiptLineList, day3);

        // Assert product transactions 1
        List<ProductTransactionAssert> productTransactionAssertList1 = new ArrayList<ProductTransactionAssert>();
        productTransactionAssertList1.add(
                new ProductTransactionAssert(OBDal.getInstance().get(ShipmentInOut.class, goodsReceipt1.getId())
                        .getMaterialMgmtShipmentInOutLineList().get(0), price1, price6, price1));
        productTransactionAssertList1.add(
                new ProductTransactionAssert(OBDal.getInstance().get(ShipmentInOut.class, goodsReceipt3.getId())
                        .getMaterialMgmtShipmentInOutLineList().get(1), price1, price1));
        assertProductTransaction(product1.getId(), productTransactionAssertList1);

        // Assert product transactions 2
        List<ProductTransactionAssert> productTransactionAssertList2 = new ArrayList<ProductTransactionAssert>();
        productTransactionAssertList2.add(
                new ProductTransactionAssert(OBDal.getInstance().get(ShipmentInOut.class, goodsReceipt1.getId())
                        .getMaterialMgmtShipmentInOutLineList().get(1), price2, price8, price2));
        productTransactionAssertList2.add(
                new ProductTransactionAssert(OBDal.getInstance().get(ShipmentInOut.class, goodsReceipt2.getId())
                        .getMaterialMgmtShipmentInOutLineList().get(0), price2, price8, price2));
        assertProductTransaction(product2.getId(), productTransactionAssertList2);

        // Assert product transactions 3
        List<ProductTransactionAssert> productTransactionAssertList3 = new ArrayList<ProductTransactionAssert>();
        productTransactionAssertList3.add(
                new ProductTransactionAssert(OBDal.getInstance().get(ShipmentInOut.class, goodsReceipt2.getId())
                        .getMaterialMgmtShipmentInOutLineList().get(1), price3, price9, price3));
        productTransactionAssertList3.add(
                new ProductTransactionAssert(OBDal.getInstance().get(ShipmentInOut.class, goodsReceipt3.getId())
                        .getMaterialMgmtShipmentInOutLineList().get(0), price3, price10, price3));
        assertProductTransaction(product3.getId(), productTransactionAssertList3);

        // Assert product costing 1
        List<MaterialTransaction> transactionList1 = getProductTransactions(product1.getId());
        List<ProductCostingAssert> productCostingAssertList1 = new ArrayList<ProductCostingAssert>();
        productCostingAssertList1
                .add(new ProductCostingAssert(transactionList1.get(0), price1, price1, price6, quantity1));
        productCostingAssertList1.add(new ProductCostingAssert(transactionList1.get(1), price1, price1, price7,
                quantity1.add(quantity6)));
        assertProductCosting(product1.getId(), productCostingAssertList1);

        // Assert product costing 2
        List<MaterialTransaction> transactionList2 = getProductTransactions(product2.getId());
        List<ProductCostingAssert> productCostingAssertList2 = new ArrayList<ProductCostingAssert>();
        productCostingAssertList2
                .add(new ProductCostingAssert(transactionList2.get(0), price2, price2, price8, quantity2));
        productCostingAssertList2.add(new ProductCostingAssert(transactionList2.get(1), price2, price2, price8,
                quantity2.add(quantity3)));
        assertProductCosting(product2.getId(), productCostingAssertList2);

        // Assert product costing 3
        List<MaterialTransaction> transactionList3 = getProductTransactions(product3.getId());
        List<ProductCostingAssert> productCostingAssertList3 = new ArrayList<ProductCostingAssert>();
        productCostingAssertList3
                .add(new ProductCostingAssert(transactionList3.get(0), price3, price3, price9, quantity4));
        productCostingAssertList3.add(new ProductCostingAssert(transactionList3.get(1), price3, price3, price10,
                quantity4.add(quantity5)));
        assertProductCosting(product3.getId(), productCostingAssertList3);

        // Assert cost adjustment 1
        List<CostAdjustment> costAdjustmentList1 = getCostAdjustment(product1.getId());
        List<List<CostAdjustmentAssert>> costAdjustmentAssertList1 = new ArrayList<List<CostAdjustmentAssert>>();
        List<CostAdjustmentAssert> costAdjustmentAssertLineList11 = new ArrayList<CostAdjustmentAssert>();
        costAdjustmentAssertLineList11.add(new CostAdjustmentAssert(transactionList1.get(0), "LC",
                quantity1.multiply(price6).add(quantity1.multiply(price1).negate()), day3, true, false));
        costAdjustmentAssertLineList11.add(new CostAdjustmentAssert(transactionList2.get(0), "LC",
                quantity2.multiply(price8).add(quantity2.multiply(price2).negate()), day3, true, false));
        costAdjustmentAssertLineList11.add(new CostAdjustmentAssert(transactionList2.get(1), "LC",
                quantity3.multiply(price8).add(quantity3.multiply(price2).negate()), day3, true, false));
        costAdjustmentAssertLineList11.add(new CostAdjustmentAssert(transactionList3.get(0), "LC",
                quantity4.multiply(price9).add(quantity4.multiply(price3).negate()), day3, true, false));
        costAdjustmentAssertLineList11.add(new CostAdjustmentAssert(transactionList3.get(1), "LC",
                quantity5.multiply(price10).add(quantity5.multiply(price3).negate()), day3, true, false));
        costAdjustmentAssertList1.add(costAdjustmentAssertLineList11);
        assertCostAdjustment(costAdjustmentList1, costAdjustmentAssertList1);

        // Assert cost adjustment 2
        List<CostAdjustment> costAdjustmentList2 = getCostAdjustment(product2.getId());
        List<List<CostAdjustmentAssert>> costAdjustmentAssertList2 = new ArrayList<List<CostAdjustmentAssert>>();
        List<CostAdjustmentAssert> costAdjustmentAssertLineList12 = new ArrayList<CostAdjustmentAssert>();
        costAdjustmentAssertLineList12.add(new CostAdjustmentAssert(transactionList1.get(0), "LC",
                quantity1.multiply(price6).add(quantity1.multiply(price1).negate()), day3, true, false));
        costAdjustmentAssertLineList12.add(new CostAdjustmentAssert(transactionList2.get(0), "LC",
                quantity2.multiply(price8).add(quantity2.multiply(price2).negate()), day3, true, false));
        costAdjustmentAssertLineList12.add(new CostAdjustmentAssert(transactionList2.get(1), "LC",
                quantity3.multiply(price8).add(quantity3.multiply(price2).negate()), day3, true, false));
        costAdjustmentAssertLineList12.add(new CostAdjustmentAssert(transactionList3.get(0), "LC",
                quantity4.multiply(price9).add(quantity4.multiply(price3).negate()), day3, true, false));
        costAdjustmentAssertLineList12.add(new CostAdjustmentAssert(transactionList3.get(1), "LC",
                quantity5.multiply(price10).add(quantity5.multiply(price3).negate()), day3, true, false));
        costAdjustmentAssertList2.add(costAdjustmentAssertLineList12);
        assertCostAdjustment(costAdjustmentList2, costAdjustmentAssertList2);

        // Assert cost adjustment 3
        List<CostAdjustment> costAdjustmentList3 = getCostAdjustment(product3.getId());
        List<List<CostAdjustmentAssert>> costAdjustmentAssertList3 = new ArrayList<List<CostAdjustmentAssert>>();
        List<CostAdjustmentAssert> costAdjustmentAssertLineList13 = new ArrayList<CostAdjustmentAssert>();
        costAdjustmentAssertLineList13.add(new CostAdjustmentAssert(transactionList1.get(0), "LC",
                quantity1.multiply(price6).add(quantity1.multiply(price1).negate()), day3, true, false));
        costAdjustmentAssertLineList13.add(new CostAdjustmentAssert(transactionList2.get(0), "LC",
                quantity2.multiply(price8).add(quantity2.multiply(price2).negate()), day3, true, false));
        costAdjustmentAssertLineList13.add(new CostAdjustmentAssert(transactionList2.get(1), "LC",
                quantity3.multiply(price8).add(quantity3.multiply(price2).negate()), day3, true, false));
        costAdjustmentAssertLineList13.add(new CostAdjustmentAssert(transactionList3.get(0), "LC",
                quantity4.multiply(price9).add(quantity4.multiply(price3).negate()), day3, true, false));
        costAdjustmentAssertLineList13.add(new CostAdjustmentAssert(transactionList3.get(1), "LC",
                quantity5.multiply(price10).add(quantity5.multiply(price3).negate()), day3, true, false));
        costAdjustmentAssertList3.add(costAdjustmentAssertLineList13);
        assertCostAdjustment(costAdjustmentList3, costAdjustmentAssertList3);

        OBDal.getInstance().commitAndClose();

    } catch (Exception e) {
        System.out.println(e.getMessage());
        throw new OBException(e);
    }

    finally {
        OBContext.restorePreviousMode();
    }
}

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

public void saveWikiEdit(ActionEvent event) {
    String pagina = null;//from w w  w. j  a  va 2s .co m
    try {
        //this.setDescripcionHtml(JSFUtils.getRequestParameter("descHtml"));
        if (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;
            }
        }
        LoginMB loginMB = (LoginMB) JSFUtils.getSessionAttribute("loginMB");
        User usuario = loginMB.getUser();
        ConocimientoService conocimientoService = (ConocimientoService) ServiceFinder
                .findBean("ConocimientoService");
        this.setDescripcionPlain(Jsoup.parse(this.getDescripcionHtml()).text());

        if (this.getSelectedCategoria() == null) {
            this.getSelectedWiki().setNcategoriaid(this.getSelectedWiki().getNcategoriaid());
            cat_nueva = this.getSelectedWiki().getNcategoriaid();
        } else {
            this.getSelectedWiki().setNcategoriaid(this.getSelectedWiki().getNcategoriaid());
            cat_nueva = this.getSelectedWiki().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, 399)));
        }
        this.getSelectedWiki().setNdestacado(this.getChkDestacado() ? BigDecimal.ONE : BigDecimal.ZERO);
        this.getSelectedWiki().setDfechamodificacion(new Date());
        this.getSelectedWiki().setVusuariomodificacion(usuario.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.pathwk.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(usuario.getVlogin());
        historial.setVmsjsolicita(this.getSelectedWiki().getVmsjsolicita());
        historial.setVmsjrespuesta(this.getSelectedWiki().getVmsjrespuesta());
        historialService.saveOrUpdate(historial);

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

        if (org.apache.commons.collections.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(usuario.getVlogin());
                } else {
                    seccion.setNseccionid(seccionService.getNextPK());
                    seccion.setNconocimientoid(this.getSelectedWiki().getNconocimientoid());
                    seccion.setDfechacreacion(new Date());
                    seccion.setVusuariocreacion(usuario.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(usuario.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 (org.apache.commons.collections.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(usuario.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(usuario.getVlogin());
                vinculoHistService.saveOrUpdate(vinculoHist);
            }
        }

        if (cat_antigua != cat_nueva) {
            AsignacionService serviceasig = (AsignacionService) ServiceFinder.findBean("AsignacionService");
            this.getSelectedAsignacion().setNestadoid(BigDecimal.valueOf(Long.parseLong("2")));
            this.getSelectedAsignacion().setDfechaatencion(new Date());
            this.getSelectedAsignacion().setNaccionid(BigDecimal.valueOf(Long.parseLong("12")));
            serviceasig.saveOrUpdate(this.getSelectedAsignacion());

            Asignacion asignacion = new Asignacion();
            asignacion.setNasignacionid(serviceasig.getNextPK());
            asignacion.setNtipoconocimientoid(Constante.WIKI);
            asignacion.setNconocimientoid(this.getSelectedWiki().getNconocimientoid());
            asignacion.setNestadoid(BigDecimal.valueOf(Long.parseLong("1")));
            CategoriaService categoriaService = (CategoriaService) ServiceFinder.findBean("CategoriaService");
            asignacion.setNusuarioid(categoriaService.getCategoriaById(this.getSelectedWiki().getNcategoriaid())
                    .getNmoderador());
            asignacion.setDfechaasignacion(new Date());
            asignacion.setDfechacreacion(new Date());
            serviceasig.saveOrUpdate(asignacion);

            pagina = "/gescon/index.xhtml";
        } else {
            pagina = "";
        }
        loginMB.refreshNotifications();
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "INFO.",
                "Actualizacin exitosa!.");
        FacesContext.getCurrentInstance().addMessage(null, message);
        FacesContext.getCurrentInstance().getExternalContext().redirect(pagina);
    } catch (Exception e) {
        e.getMessage();
        e.printStackTrace();
    }
}