Example usage for org.apache.commons.lang.time DateUtils addDays

List of usage examples for org.apache.commons.lang.time DateUtils addDays

Introduction

In this page you can find the example usage for org.apache.commons.lang.time DateUtils addDays.

Prototype

public static Date addDays(Date date, int amount) 

Source Link

Document

Adds a number of days to a date returning a new object.

Usage

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

private LandedCost createLandedCost(List<String> landedCostTypeIdList, List<BigDecimal> amountList,
        List<String> invoiceIdList, List<String> receiptIdList, List<String> receiptLineIdList, int day) {
    try {/*from   w w  w. ja  v a2  s .  com*/
        LandedCost landedCost = OBProvider.getInstance().get(LandedCost.class);
        setGeneralData(landedCost);
        landedCost.setReferenceDate(DateUtils.addDays(today, day));
        landedCost.setDocumentType(OBDal.getInstance().get(DocumentType.class, LANDEDCOST_DOCUMENTTYPE_ID));
        landedCost.setDocumentNo(getDocumentNo(landedCost.getDocumentType().getDocumentSequence().getId()));
        OBDal.getInstance().save(landedCost);

        for (int i = 0; i < (landedCostTypeIdList != null ? landedCostTypeIdList.size()
                : invoiceIdList.size()); i++) {
            LandedCostCost landedCostCost = OBProvider.getInstance().get(LandedCostCost.class);
            setGeneralData(landedCostCost);

            if (landedCostTypeIdList != null) {
                String landedCostTypeId = landedCostTypeIdList.get(i);

                if (landedCostTypeId.equals(LANDEDCOSTTYPE1_ID))
                    landedCostCost.setLandedCostType(OBDal.getInstance().get(GLItem.class, landedCostTypeId)
                            .getLandedCostTypeAccountList().get(0));
                else
                    landedCostCost.setLandedCostType(OBDal.getInstance().get(Product.class, landedCostTypeId)
                            .getLandedCostTypeList().get(0));

                landedCostCost.setAmount(amountList.get(i));

                if (landedCostTypeId.equals(LANDEDCOSTTYPE3_ID))
                    landedCostCost.setCurrency(OBDal.getInstance().get(Currency.class, CURRENCY2_ID));
                else
                    landedCostCost.setCurrency(OBDal.getInstance().get(Currency.class, CURRENCY1_ID));
            }

            else {
                String invoiceId = invoiceIdList.get(i);
                InvoiceLine invoiceLine = OBDal.getInstance().get(Invoice.class, invoiceId).getInvoiceLineList()
                        .get(0);

                if (invoiceLine.getAccount() != null)
                    landedCostCost
                            .setLandedCostType(invoiceLine.getAccount().getLandedCostTypeAccountList().get(0));
                else
                    landedCostCost.setLandedCostType(invoiceLine.getProduct().getLandedCostTypeList().get(0));

                landedCostCost.setInvoiceLine(invoiceLine);
                landedCostCost.setAmount(invoiceLine.getLineNetAmount());
                landedCostCost.setCurrency(invoiceLine.getInvoice().getCurrency());
            }

            landedCostCost.setLandedCostDistributionAlgorithm(
                    OBDal.getInstance().get(LCDistributionAlgorithm.class, LANDEDCOSTCOST_ALGORITHM_ID));
            landedCostCost.setAccountingDate(DateUtils.addDays(today, day));
            landedCostCost.setLineNo(new Long((i + 1) * 10));
            landedCostCost.setDocumentType(
                    OBDal.getInstance().get(DocumentType.class, LANDEDCOSTCOST_DOCUMENTTYPE_ID));

            landedCostCost.setLandedCost(landedCost);
            landedCost.getLandedCostCostList().add(landedCostCost);

            OBDal.getInstance().save(landedCostCost);
            OBDal.getInstance().flush();
            OBDal.getInstance().refresh(landedCostCost);
        }

        for (int i = 0; i < receiptIdList.size(); i++) {
            LCReceipt landedCostReceipt = OBProvider.getInstance().get(LCReceipt.class);
            setGeneralData(landedCostReceipt);
            if (receiptIdList.get(i) != null)
                landedCostReceipt
                        .setGoodsShipment(OBDal.getInstance().get(ShipmentInOut.class, receiptIdList.get(i)));
            if (receiptLineIdList.get(i) != null)
                landedCostReceipt.setGoodsShipmentLine(
                        OBDal.getInstance().get(ShipmentInOutLine.class, receiptLineIdList.get(i)));
            landedCostReceipt.setLandedCost(landedCost);
            landedCost.getLandedCostReceiptList().add(landedCostReceipt);

            OBDal.getInstance().save(landedCostReceipt);
            OBDal.getInstance().flush();
            OBDal.getInstance().refresh(landedCostReceipt);
        }

        OBDal.getInstance().save(landedCost);
        OBDal.getInstance().flush();
        OBDal.getInstance().refresh(landedCost);
        return landedCost;
    } catch (Exception e) {
        throw new OBException(e);
    }
}

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

private void manualCostAdjustment(String materialTransactionId, BigDecimal amount, boolean incremental,
        boolean unitCost, int day) {
    try {/*from w  ww  . ja  v  a2 s  . c  o m*/
        OBDal.getInstance().commitAndClose();
        String url = "/org.openbravo.client.kernel?processId=D395B727675C45C98320F8A40E0768E7&windowId=140&_action=org.openbravo.costing.ManualCostAdjustmentProcessHandler";
        String content = "{\r    'M_Transaction_ID':'" + materialTransactionId
                + "', \r    '_params':{\r        'Cost':" + amount.toString() + ", \r        'DateAcct':'"
                + formatDate(DateUtils.addDays(today, day)) + "', \r        'IsIncremental':" + incremental
                + ", \r        'IsUnitCost':" + unitCost + "\r    }\r}";
        String type = "application/json;charset=UTF-8";
        String response = doRequest(url, content, 200, "POST", type);
        assertTrue(response.contains("success"));
        assertFalse(response.contains("error"));
    } catch (Exception e) {
        throw new OBException(e);
    }
}

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

private void assertPhysicalInventory(List<InventoryCount> physicalInventoryList,
        PhysicalInventoryAssert physicalInventoryAssert) {
    try {//from w  w  w.j a v a 2 s.  com
        int i = 0;
        for (InventoryCount physicalInventory : physicalInventoryList) {
            assertGeneralData(physicalInventory);
            assertGeneralData(physicalInventory.getMaterialMgmtInventoryCountLineList().get(0));

            if (i % 2 == 0) {
                assertEquals(physicalInventory.getName(), "Inventory Amount Update Closing Inventory");
                assertEquals(physicalInventory.getInventoryType(), "C");

                assertEquals(physicalInventory.getMaterialMgmtInventoryCountLineList().get(0).getBookQuantity(),
                        physicalInventoryAssert.getQuantity());
                assertEquals(
                        physicalInventory.getMaterialMgmtInventoryCountLineList().get(0).getQuantityCount(),
                        amount0);
                assertEquals(physicalInventory.getMaterialMgmtInventoryCountLineList().get(0).getCost(), null);
                assertEquals(
                        physicalInventory.getMaterialMgmtInventoryCountLineList().get(0).getRelatedInventory(),
                        physicalInventoryList.get(i + 1).getMaterialMgmtInventoryCountLineList().get(0));
            }

            else {
                assertEquals(physicalInventory.getName(), "Inventory Amount Update Opening Inventory");
                assertEquals(physicalInventory.getInventoryType(), "O");

                assertEquals(physicalInventory.getMaterialMgmtInventoryCountLineList().get(0).getBookQuantity(),
                        amount0);
                assertEquals(
                        physicalInventory.getMaterialMgmtInventoryCountLineList().get(0).getQuantityCount(),
                        physicalInventoryAssert.getQuantity());
                assertEquals(physicalInventory.getMaterialMgmtInventoryCountLineList().get(0).getCost()
                        .setScale(2, BigDecimal.ROUND_HALF_UP), physicalInventoryAssert.getPrice());
                assertEquals(
                        physicalInventory.getMaterialMgmtInventoryCountLineList().get(0).getRelatedInventory(),
                        null);
            }

            assertEquals(physicalInventory.getDescription(), null);
            assertEquals(physicalInventory.getWarehouse(),
                    OBDal.getInstance().get(Warehouse.class, WAREHOUSE1_ID));
            assertEquals(formatDate(physicalInventory.getMovementDate()),
                    formatDate(DateUtils.addDays(today, physicalInventoryAssert.getDay())));
            assertTrue(physicalInventory.isProcessed());
            assertFalse(physicalInventory.isUpdateQuantities());
            assertFalse(physicalInventory.isGenerateList());
            assertEquals(physicalInventory.getTrxOrganization(), null);
            assertEquals(physicalInventory.getProject(), null);
            assertEquals(physicalInventory.getSalesCampaign(), null);
            assertEquals(physicalInventory.getActivity(), null);
            assertEquals(physicalInventory.getStDimension(), null);
            assertEquals(physicalInventory.getNdDimension(), null);
            assertEquals(physicalInventory.getCostCenter(), null);
            assertEquals(physicalInventory.getAsset(), null);

            assertEquals(physicalInventory.getMaterialMgmtInventoryCountLineList().get(0).getPhysInventory(),
                    physicalInventory);
            assertEquals(physicalInventory.getMaterialMgmtInventoryCountLineList().get(0).getStorageBin(),
                    OBDal.getInstance().get(Locator.class, LOCATOR1_ID));
            assertEquals(physicalInventory.getMaterialMgmtInventoryCountLineList().get(0).getProduct(),
                    physicalInventoryAssert.getProduct());
            assertEquals(physicalInventory.getMaterialMgmtInventoryCountLineList().get(0).getLineNo(),
                    new Long(10));
            assertEquals(physicalInventory.getMaterialMgmtInventoryCountLineList().get(0).getDescription(),
                    null);
            assertEquals(
                    physicalInventory.getMaterialMgmtInventoryCountLineList().get(0).getAttributeSetValue(),
                    OBDal.getInstance().get(AttributeSetInstance.class, "0"));
            assertEquals(physicalInventory.getMaterialMgmtInventoryCountLineList().get(0).getOrderUOM(), null);
            assertEquals(physicalInventory.getMaterialMgmtInventoryCountLineList().get(0).getOrderQuantity(),
                    null);
            assertEquals(physicalInventory.getMaterialMgmtInventoryCountLineList().get(0).getUOM().getName(),
                    "Unit");
            assertEquals(
                    physicalInventory.getMaterialMgmtInventoryCountLineList().get(0).getQuantityOrderBook(),
                    null);

            i++;
        }
    } catch (Exception e) {
        throw new OBException(e);
    }
}

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

private void assertCostAdjustment(List<CostAdjustment> costAdjustmentList,
        List<List<CostAdjustmentAssert>> costAdjustmentAssertList) {
    try {//  w  w w  .  j  a va  2 s . c o m

        // Assert Cost Adjustment header data
        assertEquals(costAdjustmentList.size(), costAdjustmentAssertList.size());
        int i = 0;
        for (CostAdjustment costAdjustment : costAdjustmentList) {

            List<CostAdjustmentAssert> costAdjustmentAssertLineList = costAdjustmentAssertList.get(i);
            assertGeneralData(costAdjustment);
            assertEquals(costAdjustment.getDocumentType().getName(), "Cost Adjustment");
            assertEquals(formatDate(costAdjustment.getReferenceDate()), formatDate(today));
            assertEquals(costAdjustment.getSourceProcess(), costAdjustmentAssertLineList.get(0).getType());
            assertTrue(costAdjustment.isProcessed());
            assertFalse(costAdjustment.isProcess());
            assertEquals(costAdjustment.getDocumentStatus(), costAdjustmentAssertLineList.get(0).getStatus());
            assertFalse(costAdjustment.isCancelProcess());
            assertEquals(costAdjustment.getCostAdjustmentLineList().size(),
                    costAdjustmentAssertLineList.size());

            if (costAdjustmentAssertLineList.get(0).getStatus().equals("VO")) {
                OBCriteria<CostAdjustmentLine> criteria = OBDal.getInstance()
                        .createCriteria(CostAdjustmentLine.class);
                criteria.add(Restrictions.eq(CostAdjustmentLine.PROPERTY_INVENTORYTRANSACTION,
                        costAdjustmentAssertLineList.get(0).getMaterialTransaction()));
                criteria.add(Restrictions.eq(CostAdjustmentLine.PROPERTY_ADJUSTMENTAMOUNT,
                        costAdjustmentAssertLineList.get(0).getAmount().negate()));
                criteria.add(Restrictions.ne(CostAdjustmentLine.PROPERTY_COSTADJUSTMENT, costAdjustment));
                assertEquals(costAdjustment.getCostAdjustmentCancel(),
                        criteria.list().get(0).getCostAdjustment().getCostAdjustmentCancel() != null ? null
                                : criteria.list().get(0).getCostAdjustment());
            } else
                assertEquals(costAdjustment.getCostAdjustmentCancel(), null);

            // Assert Cost Adjustment lines data
            int j = 0;
            for (CostAdjustmentLine costAdjustmentLine : costAdjustment.getCostAdjustmentLineList()) {

                CostAdjustmentAssert costAdjustmentAssertLine = costAdjustmentAssertLineList.get(j);
                assertGeneralData(costAdjustment);

                assertEquals(costAdjustmentLine.getCostAdjustment(), costAdjustment);
                assertEquals(costAdjustmentLine.getInventoryTransaction(),
                        costAdjustmentAssertLine.getMaterialTransaction());
                assertEquals(costAdjustmentLine.getLineNo(), new Long((j + 1) * 10));

                assertEquals(costAdjustmentLine.getAdjustmentAmount().setScale(2, BigDecimal.ROUND_HALF_UP),
                        costAdjustmentAssertLine.getAmount().setScale(2, BigDecimal.ROUND_HALF_UP));
                assertEquals(costAdjustmentLine.isSource(), costAdjustmentAssertLine.isSource());
                assertEquals(costAdjustmentLine.isUnitCost(), costAdjustmentAssertLine.isUnit());
                assertEquals(formatDate(costAdjustmentLine.getAccountingDate()),
                        formatDate(DateUtils.addDays(today, costAdjustmentAssertLine.getDay())));
                assertTrue(costAdjustmentLine.isRelatedTransactionAdjusted());
                assertEquals(costAdjustmentLine.getCurrency(), costAdjustmentAssertLine.getCurrency());

                if (costAdjustmentAssertLine.getType().equals("NSC")) {
                    assertFalse(costAdjustmentLine.isBackdatedTrx());
                    assertTrue(costAdjustmentLine.isNegativeStockCorrection());
                } else if (costAdjustmentAssertLine.getType().equals("BDT")) {
                    assertTrue(costAdjustmentLine.isBackdatedTrx());
                    assertFalse(costAdjustmentLine.isNegativeStockCorrection());
                } else {
                    assertFalse(costAdjustmentLine.isBackdatedTrx());
                    assertFalse(costAdjustmentLine.isNegativeStockCorrection());
                }

                if (costAdjustmentAssertLine.getAmount().setScale(2, BigDecimal.ROUND_HALF_UP)
                        .equals(amount0.setScale(2, BigDecimal.ROUND_HALF_UP))
                        || costAdjustmentAssertLine.getType().equals("LC"))
                    assertFalse(costAdjustmentLine.isNeedsPosting());
                else
                    assertTrue(costAdjustmentLine.isNeedsPosting());

                if (j == 0
                        || (j == 1 && costAdjustmentAssertLine.isSource()
                                && !costAdjustmentLine.getInventoryTransaction().getStorageBin()
                                        .equals(costAdjustment.getCostAdjustmentLineList().get(j - 1)
                                                .getInventoryTransaction().getStorageBin()))
                        || (j == 1 && !costAdjustmentLine.getInventoryTransaction().getProduct()
                                .equals(costAdjustment.getCostAdjustmentLineList().get(j - 1)
                                        .getInventoryTransaction().getProduct()))
                        || (j == 2
                                && !costAdjustmentLine.getInventoryTransaction().getProduct()
                                        .equals(costAdjustment.getCostAdjustmentLineList().get(j - 2)
                                                .getInventoryTransaction().getProduct())
                                && !costAdjustmentLine.getInventoryTransaction().getProduct()
                                        .equals(costAdjustment.getCostAdjustmentLineList().get(j - 1)
                                                .getInventoryTransaction().getProduct()))
                        || (j == 3
                                && !costAdjustmentLine.getInventoryTransaction().getProduct()
                                        .isBillOfMaterials()
                                && !costAdjustmentLine.getInventoryTransaction().getProduct()
                                        .equals(costAdjustment.getCostAdjustmentLineList().get(j - 3)
                                                .getInventoryTransaction().getProduct())
                                && !costAdjustmentLine.getInventoryTransaction().getProduct()
                                        .equals(costAdjustment.getCostAdjustmentLineList().get(j - 2)
                                                .getInventoryTransaction().getProduct())
                                && !costAdjustmentLine.getInventoryTransaction().getProduct()
                                        .equals(costAdjustment.getCostAdjustmentLineList().get(j - 1)
                                                .getInventoryTransaction().getProduct())))
                    assertEquals(costAdjustmentLine.getParentCostAdjustmentLine(), null);
                else if (costAdjustmentLine.getInventoryTransaction().getProduct()
                        .equals(costAdjustment.getCostAdjustmentLineList().get(0).getInventoryTransaction()
                                .getProduct())
                        && (costAdjustmentLine.getInventoryTransaction().getStorageBin()
                                .equals(costAdjustment.getCostAdjustmentLineList().get(0)
                                        .getInventoryTransaction().getStorageBin())
                                || costAdjustmentAssertLineList.size() == 2))
                    assertEquals(costAdjustmentLine.getParentCostAdjustmentLine(),
                            costAdjustment.getCostAdjustmentLineList().get(0));
                else if (costAdjustmentLine.getInventoryTransaction().getProduct()
                        .equals(costAdjustment.getCostAdjustmentLineList().get(1).getInventoryTransaction()
                                .getProduct())
                        && (costAdjustmentLine.getInventoryTransaction().getStorageBin()
                                .equals(costAdjustment.getCostAdjustmentLineList().get(1)
                                        .getInventoryTransaction().getStorageBin())
                                || costAdjustmentAssertLineList.size() == 3))
                    assertEquals(costAdjustmentLine.getParentCostAdjustmentLine(),
                            costAdjustment.getCostAdjustmentLineList().get(1));
                else if ((costAdjustmentLine.getInventoryTransaction().getProduct()
                        .equals(costAdjustment.getCostAdjustmentLineList().get(2).getInventoryTransaction()
                                .getProduct())
                        && (costAdjustmentLine.getInventoryTransaction().getStorageBin()
                                .equals(costAdjustment.getCostAdjustmentLineList().get(2)
                                        .getInventoryTransaction().getStorageBin())
                                || costAdjustmentAssertLineList.size() == 4))
                        || costAdjustmentLine.getInventoryTransaction().getProduct().isBillOfMaterials()
                                && costAdjustmentLine.getAdjustmentAmount().equals(costAdjustment
                                        .getCostAdjustmentLineList().get(2).getAdjustmentAmount()))
                    assertEquals(costAdjustmentLine.getParentCostAdjustmentLine(),
                            costAdjustment.getCostAdjustmentLineList().get(2));
                else
                    assertEquals(costAdjustmentLine.getParentCostAdjustmentLine(),
                            costAdjustment.getCostAdjustmentLineList().get(3));

                j++;
            }
            i++;
        }
    } catch (Exception e) {
        throw new OBException(e);
    }
}

From source file:org.openkoala.koala.monitor.common.KoalaDateUtils.java

/**
 * ??<br>//from ww  w.  j a va 2  s. c  o  m
 * generate by: vakin jiang at 2012-5-21
 * 
 * @param date
 * @return
 */
@SuppressWarnings("deprecation")
public static boolean isLastDayOfMonth(Date date) {
    return DateUtils.addDays(date, 1).getMonth() != date.getMonth();
}

From source file:org.openkoala.koala.monitor.common.KoalaDateUtils.java

/**
 * ???<br>/*from   w w  w  . j  a  v  a 2 s.c o  m*/
 * generate by: vakin jiang at 2012-5-21
 * 
 * @param date
 * @return
 */
public static Date getLastDateOfMonth(Date date) {
    return DateUtils.addDays(DateUtils.truncate(DateUtils.addMonths(date, 1), Calendar.MONTH), -1);
}

From source file:org.openkoala.koala.monitor.service.MonitorDataServiceImpl.java

@Override
public final List<CountVo> getHttpMonitorCount(String nodeId, String statUnit, Date beginTime) {
    List<CountVo> list = new ArrayList<CountVo>();
    String sql = null;/* w  ww. ja  v  a2s  .  c o  m*/
    Date beginDt = KoalaDateUtils.getDayBegin(beginTime);
    Date endDt = null;
    if (Constant.UNIT_HOUR.equals(statUnit)) {
        sql = "select m.HOUR, count(*) from KM_HTTP_DETAILS h left join KM_MAIN_STAT m on h.THREAD_KEY = m.THREAD_KEY and m.FK_NODE_ID=? and (m.BEGIN_TIME between ? and ?) group by m.HOUR order by m.HOUR";
        endDt = KoalaDateUtils.getDayEnd(beginDt);
    } else if (Constant.UNIT_DAY.equals(statUnit)) {
        sql = "select m.DAY, count(*) from KM_HTTP_DETAILS h left join KM_MAIN_STAT m on h.THREAD_KEY = m.THREAD_KEY and m.FK_NODE_ID=? and (m.BEGIN_TIME between ? and ?) group by m.DAY order by m.DAY";
        endDt = KoalaDateUtils.getLastDateOfMonth(beginDt);
    } else {
        throw new RuntimeException("?");
    }

    final Map<Integer, String> tmpMap = new HashMap<Integer, String>();
    Object[] objects = new Object[] { nodeId, beginDt, endDt };
    jdbcTemplate.query(sql, objects, new ResultSetExtractor<Object>() {
        @Override
        public Object extractData(ResultSet rs) throws SQLException, DataAccessException {
            while (rs.next()) {
                if (rs.getObject(1) != null) {
                    tmpMap.put(rs.getInt(1), rs.getObject(2).toString());
                }
            }
            return null;
        }
    });

    int index = Constant.UNIT_HOUR.equals(statUnit) ? 0 : 1;
    for (;;) {
        if (beginDt.compareTo(endDt) > 0)
            break;
        CountVo countVo = new CountVo();
        if (tmpMap.containsKey(index)) {
            countVo.setHttpCount(Integer.parseInt(tmpMap.get(index)));
        } else {
            countVo.setHttpCount(0);
        }
        list.add(countVo);
        if (Constant.UNIT_HOUR.equals(statUnit)) {
            countVo.setDateStr(KoalaDateUtils.format(beginDt, "yyyy-MM-dd HH"));
            beginDt = DateUtils.addHours(beginDt, 1);
        } else if (Constant.UNIT_DAY.equals(statUnit)) {
            countVo.setDateStr(KoalaDateUtils.format(beginDt, "yyyy-MM-dd"));
            beginDt = DateUtils.addDays(beginDt, 1);
        }
        index++;
    }
    return list;
}

From source file:org.openkoala.koala.monitor.task.ServerStatusCollectorTask.java

/**
 * ????//from  w w w  .  j  a  va 2s.  co m
 * 
 * @return
 */
public Map<String, Object> getServerStatusInfos() {
    String yesterday = KoalaDateUtils.format(DateUtils.addDays(new Date(), -1), "yyyy-MM-dd");
    String today = KoalaDateUtils.format(new Date(), "yyyy-MM-dd");

    int currentHour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
    Map<String, Object> map = new HashMap<String, Object>();
    // MEM
    Map<String, Double> memDatas = formatEveryHourDadas(memUsageEveryHour, yesterday, today, currentHour);
    map.put(MEM_INFO, memDatas);

    // CPU
    Map<String, Map<String, Double>> cpuDatas = new HashMap<String, Map<String, Double>>();
    Set<String> keys = cpuUsageEveryHour.keySet();
    //???
    for (String model : keys) {
        Map<String, Double> modelDatas = formatEveryHourDadas(cpuUsageEveryHour.get(model), yesterday, today,
                currentHour);
        cpuDatas.put(model, modelDatas);
    }
    map.put(CPU_INFO, cpuDatas);

    // DISK
    Map<String, Map<String, Double>> diskDatas = new TreeMap<String, Map<String, Double>>();
    keys = diskUsageEveryHour.keySet();
    Map<String, Double> singgleDiskData;
    List<Double> dataList;
    for (String key : keys) {
        singgleDiskData = new HashMap<String, Double>();
        dataList = diskUsageEveryHour.get(key);
        singgleDiskData.put("total", dataList.get(0));
        singgleDiskData.put("used", dataList.get(1));
        if (dataList.size() > 2) {
            singgleDiskData.put("readRate", dataList.get(2));
            singgleDiskData.put("writeRate", dataList.get(3));
        }
        diskDatas.put(key, singgleDiskData);
    }
    map.put(DISK_INFO, diskDatas);

    return map;
}

From source file:org.openlmis.core.upload.AbstractModelPersistenceHandlerTest.java

@Test
public void shouldAddFromExistingModel() throws Exception {

    final Date currentTimestamp = new Date();
    AuditFields auditFields = new AuditFields(1L, currentTimestamp);
    Importable currentRecord = new TestImportable();
    BaseModel existing = new BaseModel() {
    };/*from   w  w w  .j  ava 2 s  . com*/
    existing.setId(2L);
    existing.setModifiedDate(DateUtils.addDays(currentTimestamp, -1));

    handler = instantiateHandler(existing);

    handler.execute(currentRecord, 1, auditFields);

    assertThat(((BaseModel) currentRecord).getModifiedDate(), is(currentTimestamp));
    assertThat(((BaseModel) currentRecord).getModifiedBy(), is(1L));
    assertThat(((BaseModel) currentRecord).getId(), is(2L));
}

From source file:org.openmrs.cwf.ui.obsviewer.MainController.java

private void doRefresh(boolean force) {
    needsRefresh |= force;/*w  w  w. j a va 2s .  co  m*/

    if (!needsRefresh) {
        return;
    }

    observations = null;
    lbObs.setModel((ListModel<?>) null);
    lbObs.getItems().clear();

    if (patient == null) {
        needsRefresh = false;
        showInfo("obsViewer.noPatient");
        return;
    }

    if (!isActive) {
        return;
    }

    needsRefresh = false;
    ObsService svc = Context.getObsService();
    List<Person> whom = Collections.singletonList((Person) PatientUtil.fromFhir(patient));
    List<Concept> questions = null;
    List<Location> locations = null;
    Integer mostRecentN = null;
    Date fromDate = datRange.getStartDate();
    Date toDate = datRange.getEndDate();
    toDate = toDate == null ? null : DateUtils.addMilliseconds(DateUtils.addDays(toDate, 1), -1);
    observations = svc.getObservations(whom, null, questions, null, null, locations, null, mostRecentN, null,
            fromDate, toDate, false);
    ListModel<Obs> model = new ListModelList<Obs>(observations);
    lbObs.setModel(model);
    showInfo(observations.isEmpty() ? "obsViewer.noResults" : null);
}