Example usage for org.joda.time LocalDateTime LocalDateTime

List of usage examples for org.joda.time LocalDateTime LocalDateTime

Introduction

In this page you can find the example usage for org.joda.time LocalDateTime LocalDateTime.

Prototype

public LocalDateTime() 

Source Link

Document

Constructs an instance set to the current local time evaluated using ISO chronology in the default zone.

Usage

From source file:ch.icclab.cyclops.resource.impl.TelemetryResource.java

License:Open Source License

/**
 * Evaluates the outcome of the operation to save the Cumulative & Gauge and constructs the
 * response object accordingly/*from w w  w.  j  a  va 2  s . c  om*/
 *
 * @param cumulativeMeterOutput A boolean which indicates the outcome of the operation to save the Cumulative Meter data
 * @param gaugeMeterOutput A boolean which indicates the outcome of the operation to save the Gauge Meter data
 * @return A response object containing the details of the operation
 */
private Response constructResponse(boolean cumulativeMeterOutput, boolean gaugeMeterOutput) {
    Response responseObj = new Response();
    LocalDateTime currentDateTime = new LocalDateTime();

    if (cumulativeMeterOutput && gaugeMeterOutput) {
        responseObj.setTimestamp(currentDateTime.toDateTime().toString());
        responseObj.setStatus("Success");
        responseObj.setMessage("Cumulative & Gauge Meters were Successfully saved into the DB");
    } else if (gaugeMeterOutput) {
        responseObj.setTimestamp(currentDateTime.toDateTime().toString());
        responseObj.setStatus("Success");
        responseObj.setMessage("Only Gauge Meter was Successfully saved into the DB");
    } else {
        responseObj.setTimestamp(currentDateTime.toDateTime().toString());
        responseObj.setStatus("Success");
        responseObj.setMessage("Only Cumulative Meter was Successfully saved into the DB");
    }

    return responseObj;
}

From source file:ch.icclab.cyclops.services.iaas.openstack.resource.impl.ExternalAppResource.java

License:Open Source License

/**
 * Receives the JSON data sent by an external application
 * <p/>/*from   www.j a v a 2s  .com*/
 * Pseudo Code<br/>
 * 1. Receive the data<br/>
 * 2. Extract the JSON array<br/>
 * 3. Send the JSON array to saveData() for further processing<br/>
 *
 * @param entity
 * @return Representation A JSON response is returned
 */
@Post("json:json")
public Representation receiveRequest(JsonRepresentation entity) {
    counter.increment(endpoint);
    logger.trace("BEGIN Representation receiveRequest(JsonRepresentation entity)");
    JSONArray jsonArr = null;
    boolean output = true;

    LocalDateTime currentDateTime = new LocalDateTime();
    Response response = new Response();
    Representation jsonResponse = new JsonRepresentation(response);
    ResponseUtil util = new ResponseUtil();

    try {
        jsonArr = entity.getJsonArray();
        output = saveData(jsonArr);
    } catch (JSONException e) {
        logger.error("EXCEPTION JSONEXCEPTION Representation receiveRequest(JsonRepresentation entity)");
        output = false;
        e.printStackTrace();
    }
    response.setTimestamp(currentDateTime.toDateTime().toString());
    if (output) {
        response.setStatus("Success");
        response.setMessage("Data saved into the DB");
    } else {
        response.setStatus("Failure");
        response.setMessage("Data could not be saved into the DB");
    }
    jsonResponse = util.toJson(response);
    logger.trace("END Representation receiveRequest(JsonRepresentation entity)");
    return jsonResponse;
}

From source file:ch.icclab.cyclops.services.iaas.openstack.resource.impl.MeterResource.java

License:Open Source License

/**
 * Receives the JSON data consisting of meter selection status
 * <p/>/* ww w.ja  v a 2s.c o m*/
 * Pseudo Code<br>
 * 1. Receive the data<br>
 * 2. Extract the JSON array<br>
 * 3. Send the JSON array to saveData() for persistence into the DB
 *
 * @param entity The body of the POST request
 * @return Representation A JSON response containing the status of the request serviced
 */
@Post("json:json")
public Representation setMeterList(Representation entity) {
    counter.increment(endpoint);
    logger.trace("BEGIN Representation setMeterList(Representation entity)");
    boolean output = true;
    ObjectMapper mapper = new ObjectMapper();
    String jsonData = null;
    JsonRepresentation request = null;
    JsonRepresentation responseJson = null;
    LocalDateTime currentDateTime = new LocalDateTime();
    Response response = new Response();

    // Get the JSON representation of the incoming POST request
    try {
        request = new JsonRepresentation(entity);
    } catch (IOException e) {
        logger.error("EXCEPTION IOEXCEPTION Representation setMeterList(Representation entity)");
        e.printStackTrace();
    }
    //Tells to UDR that need to reload the meter list in Load
    Flag.setMeterListReset(true);
    // Process the incoming request
    try {
        output = saveData(request.getJsonObject());
    } catch (JSONException e) {
        logger.error("EXCEPTION JSONGEXCEPTION Representation setMeterList(Representation entity)");
        output = false;
        e.printStackTrace();
    }
    // Set the time stamp
    response.setTimestamp(currentDateTime.toDateTime().toString());
    // Set the status and message
    if (output) {
        response.setStatus("Success");
        response.setMessage("Data saved into the DB");
    } else {
        logger.debug(
                "DEBUG Representation setMeterList(Representation entity): Data could not be saved into the DB");
        response.setStatus("Failure");
        response.setMessage("Data could not be saved into the DB");
    }
    //TODO: jsonMapper method. reusable in all the classes.
    // Convert the Java object to a JSON string
    try {
        jsonData = mapper.writeValueAsString(response);
        responseJson = new JsonRepresentation(jsonData);
    } catch (JsonProcessingException e) {
        logger.error("EXCEPTION JSONPROCESSINGEXCEPTION Representation setMeterList(Representation entity)");
        e.printStackTrace();
    }
    logger.trace("END Representation setMeterList(Representation entity)");
    return responseJson;
}

From source file:ch.icclab.cyclops.services.iaas.openstack.resource.impl.TelemetryResource.java

License:Open Source License

/**
 * Evaluates the outcome of the operation to save the Cumulative & Gauge and constructs the
 * response object accordingly//w w w. j  a  v  a2s  .co m
 *
 * @param cumulativeMeterOutput A boolean which indicates the outcome of the operation to save the Cumulative Meter data
 * @param gaugeMeterOutput      A boolean which indicates the outcome of the operation to save the Gauge Meter data
 * @return A response object containing the details of the operation
 */
private Response constructResponse(boolean cumulativeMeterOutput, boolean gaugeMeterOutput) {
    logger.trace("BEGIN Response constructResponse(boolean cumulativeMeterOutput, boolean gaugeMeterOutput)");
    Response responseObj = new Response();
    LocalDateTime currentDateTime = new LocalDateTime();
    //TODO: response for no usagedata saved.
    if (cumulativeMeterOutput && gaugeMeterOutput) {
        responseObj.setTimestamp(currentDateTime.toDateTime().toString());
        responseObj.setStatus("Success");
        responseObj.setMessage("Cumulative & Gauge Meters were Successfully saved into the DB");
    } else if (gaugeMeterOutput) {
        responseObj.setTimestamp(currentDateTime.toDateTime().toString());
        responseObj.setStatus("Success");
        responseObj.setMessage("Only Gauge Meter was Successfully saved into the DB");
        logger.debug(
                "DEBUG Response constructResponse(boolean cumulativeMeterOutput, boolean gaugeMeterOutput) - Only Gauge Meter was Successfully saved into the DB");
    } else {
        responseObj.setTimestamp(currentDateTime.toDateTime().toString());
        responseObj.setStatus("Success");
        responseObj.setMessage("Only Cumulative Meter was Successfully saved into the DB");
        logger.debug(
                "DEBUG Response constructResponse(boolean cumulativeMeterOutput, boolean gaugeMeterOutput) - Only Cumulative Meter was Successfully saved into the DB");
    }
    logger.trace("END Response constructResponse(boolean cumulativeMeterOutput, boolean gaugeMeterOutput)");
    return responseObj;
}

From source file:ch.icclab.cyclops.usecases.mcn.impl.MCNResource.java

License:Open Source License

/**
 * This method creates the response message of the API call
 *
 * @return/*from  ww  w.j  a v a  2 s  .  c  om*/
 */
//TODO: remove method
private Response constructResponse() {
    logger.trace("BEGIN constructResponse(TSDBData data)");
    Response responseObj = new Response();
    LocalDateTime currentDateTime = new LocalDateTime();

    responseObj.setTimestamp(currentDateTime.toDateTime().toString());
    responseObj.setStatus("Success");
    responseObj.setMessage("Event Data retrieved.");
    logger.trace("BEGIN constructResponse(TSDBData data)");
    return responseObj;
}

From source file:com.avapira.bobroreader.Bober.java

License:Open Source License

@Override
protected void onCreate(final Bundle savedInstanceState) {
    loadingLog("Freezing time...");
    // Build the local caches inside Joda Time
    new LocalDateTime();
    loadingLog("Manuscripts contemplation...");
    HanabiraBoard.Info.loadBoardsInfo(getResources(), R.raw.boards);

    loadingLog("Superposition...");
    super.onCreate(savedInstanceState);
    loadingLog("Dressing...");
    setContentView(R.layout.activity_bober);
    loadingLog("Pulling out a hat...");
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    loadingLog("Dubbing a hat...");
    setSupportActionBar(toolbar);//from   ww  w .  j  a v a  2  s  .c  o  m
    loadingLog("Equipping primary weapon...");
    boardsDrawer = generateBoardsDrawerBuilder(savedInstanceState, toolbar).build();
    loadingLog("Equipping secondary weapon...");
    featuresDrawer = generateFeaturesDrawerBuilder(savedInstanceState).append(boardsDrawer);
    loadingLog("Starting a new journey");
    findViewById(R.id.frame_toolbar_container).setVisibility(View.VISIBLE);
    setTheme(R.style.Bobroreader_Theme_Default);
    // TODO create big enough splash logo
    LocalBroadcastManager.getInstance(this).registerReceiver(new PostOpenBroadcastReceiver(),
            new IntentFilter(Hanabira.Action.OPEN_POST.name()));
}

From source file:com.axelor.apps.base.service.PriceListService.java

License:Open Source License

@Transactional
public PriceList historizePriceList(PriceList priceList) {
    HistorizedPriceList historizedPriceList = new HistorizedPriceList();
    historizedPriceList.setDate(new LocalDateTime());
    List<PriceListLine> priceListLineList = priceList.getPriceListLineList();
    for (PriceListLine priceListLine : priceListLineList) {
        PriceListLine newPriceListLine = priceListLineRepo.copy(priceListLine, false);
        newPriceListLine.setPriceList(null);
        historizedPriceList.addPriceListLineListItem(newPriceListLine);
    }// w  w w.j a  v a2 s.  com
    priceList.addHistorizedPriceList(historizedPriceList);
    priceListRepo.save(priceList);
    return priceList;
}

From source file:com.axelor.apps.businessproduction.service.ProductionOrderSaleOrderServiceBusinessImpl.java

License:Open Source License

@Override
@Transactional(rollbackOn = { AxelorException.class, Exception.class })
public ProductionOrder generateProductionOrder(SaleOrderLine saleOrderLine) throws AxelorException {

    Product product = saleOrderLine.getProduct();

    if (saleOrderLine.getSaleSupplySelect() == ProductRepository.SALE_SUPPLY_PRODUCE && product != null
            && product.getProductTypeSelect().equals(ProductRepository.PRODUCT_TYPE_STORABLE)) {

        BillOfMaterial billOfMaterial = saleOrderLine.getBillOfMaterial();

        if (billOfMaterial == null) {

            billOfMaterial = product.getDefaultBillOfMaterial();

        }/*www  .  j av  a2  s. co m*/

        if (billOfMaterial == null && product.getParentProduct() != null) {

            billOfMaterial = product.getParentProduct().getDefaultBillOfMaterial();

        }

        if (billOfMaterial == null) {

            throw new AxelorException(
                    String.format(I18n.get(IExceptionMessage.PRODUCTION_ORDER_SALES_ORDER_NO_BOM),
                            product.getName(), product.getCode()),
                    IException.CONFIGURATION_ERROR);

        }
        Unit unit = saleOrderLine.getProduct().getUnit();
        BigDecimal qty = saleOrderLine.getQty();
        if (!unit.equals(saleOrderLine.getUnit())) {
            qty = unitConversionService.convertWithProduct(saleOrderLine.getUnit(), unit, qty,
                    saleOrderLine.getProduct());
        }
        return productionOrderRepo.save(productionOrderService.generateProductionOrder(product, billOfMaterial,
                qty, saleOrderLine.getSaleOrder().getProject(), new LocalDateTime()));

    }

    return null;

}

From source file:com.axelor.apps.crm.service.EventService.java

License:Open Source License

@Transactional
public void addRecurrentEventsByWeeks(Event event, int periodicity, int endType, int repetitionsNumber,
        LocalDate endDate, Map<Integer, Boolean> daysCheckedMap) {
    Event lastEvent = event;/*  w w  w  .  j  a va  2 s . c o  m*/
    List<Integer> list = new ArrayList<Integer>();
    for (int day : daysCheckedMap.keySet()) {
        list.add(day);
    }
    Collections.sort(list);
    if (endType == 1) {
        int repeated = 0;
        Event copy = eventRepo.copy(lastEvent, false);
        copy.setParentEvent(lastEvent);
        int dayOfWeek = copy.getStartDateTime().getDayOfWeek();
        LocalDateTime nextDateTime = new LocalDateTime();
        if (dayOfWeek < list.get(0)) {
            nextDateTime = new LocalDateTime(copy.getStartDateTime().plusDays(list.get(0) - dayOfWeek));
        } else if (dayOfWeek > list.get(0)) {
            nextDateTime = new LocalDateTime(copy.getStartDateTime().plusDays((7 - dayOfWeek) + list.get(0)));
        }
        Duration dur = new Duration(copy.getStartDateTime().toDateTime(), copy.getEndDateTime().toDateTime());

        for (Integer integer : list) {
            nextDateTime.plusDays(integer - nextDateTime.getDayOfWeek());
            copy.setStartDateTime(nextDateTime);
            copy.setEndDateTime(nextDateTime.plus(dur));
            eventRepo.save(copy);
            lastEvent = copy;
            repeated++;
        }

        while (repeated < repetitionsNumber) {
            copy = eventRepo.copy(lastEvent, false);
            copy.setParentEvent(lastEvent);
            copy.setStartDateTime(copy.getStartDateTime().plusWeeks(periodicity));
            copy.setEndDateTime(copy.getEndDateTime().plusWeeks(periodicity));

            dayOfWeek = copy.getStartDateTime().getDayOfWeek();
            nextDateTime = new LocalDateTime();
            if (dayOfWeek < list.get(0)) {
                nextDateTime = new LocalDateTime(copy.getStartDateTime().plusDays(list.get(0) - dayOfWeek));
            } else if (dayOfWeek > list.get(0)) {
                nextDateTime = new LocalDateTime(
                        copy.getStartDateTime().plusDays((7 - dayOfWeek) + list.get(0)));
            }
            dur = new Duration(copy.getStartDateTime().toDateTime(), copy.getEndDateTime().toDateTime());

            for (Integer integer : list) {
                nextDateTime.plusDays(integer - nextDateTime.getDayOfWeek());
                copy.setStartDateTime(nextDateTime);
                copy.setEndDateTime(nextDateTime.plus(dur));
                eventRepo.save(copy);
                lastEvent = copy;
                repeated++;
            }
        }
    } else {

        Event copy = eventRepo.copy(lastEvent, false);
        copy.setParentEvent(lastEvent);
        int dayOfWeek = copy.getStartDateTime().getDayOfWeek();
        LocalDateTime nextDateTime = new LocalDateTime();
        if (dayOfWeek < list.get(0)) {
            nextDateTime = new LocalDateTime(copy.getStartDateTime().plusDays(list.get(0) - dayOfWeek));
        } else if (dayOfWeek > list.get(0)) {
            nextDateTime = new LocalDateTime(copy.getStartDateTime().plusDays((7 - dayOfWeek) + list.get(0)));
        }
        Duration dur = new Duration(copy.getStartDateTime().toDateTime(), copy.getEndDateTime().toDateTime());

        for (Integer integer : list) {
            nextDateTime.plusDays(integer - nextDateTime.getDayOfWeek());
            copy.setStartDateTime(nextDateTime);
            copy.setEndDateTime(nextDateTime.plus(dur));
            eventRepo.save(copy);
            lastEvent = copy;
        }

        while (!copy.getStartDateTime().plusWeeks(periodicity).isAfter(endDate)) {
            copy = eventRepo.copy(lastEvent, false);
            copy.setParentEvent(lastEvent);
            copy.setStartDateTime(copy.getStartDateTime().plusWeeks(periodicity));
            copy.setEndDateTime(copy.getEndDateTime().plusWeeks(periodicity));

            dayOfWeek = copy.getStartDateTime().getDayOfWeek();
            nextDateTime = new LocalDateTime();
            if (dayOfWeek < list.get(0)) {
                nextDateTime = new LocalDateTime(copy.getStartDateTime().plusDays(list.get(0) - dayOfWeek));
            } else if (dayOfWeek > list.get(0)) {
                nextDateTime = new LocalDateTime(
                        copy.getStartDateTime().plusDays((7 - dayOfWeek) + list.get(0)));
            }
            dur = new Duration(copy.getStartDateTime().toDateTime(), copy.getEndDateTime().toDateTime());

            for (Integer integer : list) {
                nextDateTime.plusDays(integer - nextDateTime.getDayOfWeek());
                copy.setStartDateTime(nextDateTime);
                copy.setEndDateTime(nextDateTime.plus(dur));
                eventRepo.save(copy);
                lastEvent = copy;
            }
        }
    }
}

From source file:com.axelor.apps.production.service.ProductionOrderServiceImpl.java

License:Open Source License

@Transactional(rollbackOn = { AxelorException.class, Exception.class })
public ProductionOrder addManufOrder(ProductionOrder productionOrder, Product product,
        BillOfMaterial billOfMaterial, BigDecimal qtyRequested) throws AxelorException {

    ManufOrder manufOrder = manufOrderService.generateManufOrder(product, qtyRequested,
            ManufOrderService.DEFAULT_PRIORITY, ManufOrderService.IS_TO_INVOICE, billOfMaterial,
            new LocalDateTime());

    productionOrder.addManufOrderListItem(manufOrder);

    return productionOrderRepo.save(productionOrder);

}