List of usage examples for org.joda.time LocalDate LocalDate
public LocalDate()
From source file:com.axelor.apps.crm.web.EventController.java
License:Open Source License
@Transactional public void generateRecurrentEvents(ActionRequest request, ActionResponse response) throws AxelorException { Long eventId = new Long(request.getContext().get("_idEvent").toString()); Event event = eventRepo.find(eventId); RecurrenceConfiguration conf = request.getContext().asType(RecurrenceConfiguration.class); RecurrenceConfigurationRepository confRepo = Beans.get(RecurrenceConfigurationRepository.class); conf = confRepo.save(conf);/*from ww w . j ava2 s.c o m*/ event.setRecurrenceConfiguration(conf); event = eventRepo.save(event); if (request.getContext().get("recurrenceType") == null) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_RECURRENCE_TYPE)), IException.CONFIGURATION_ERROR); } int recurrenceType = new Integer(request.getContext().get("recurrenceType").toString()); if (request.getContext().get("periodicity") == null) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_PERIODICITY)), IException.CONFIGURATION_ERROR); } int periodicity = new Integer(request.getContext().get("periodicity").toString()); if (periodicity < 1) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_PERIODICITY)), IException.CONFIGURATION_ERROR); } boolean monday = (boolean) request.getContext().get("monday"); boolean tuesday = (boolean) request.getContext().get("tuesday"); boolean wednesday = (boolean) request.getContext().get("wednesday"); boolean thursday = (boolean) request.getContext().get("thursday"); boolean friday = (boolean) request.getContext().get("friday"); boolean saturday = (boolean) request.getContext().get("saturday"); boolean sunday = (boolean) request.getContext().get("sunday"); Map<Integer, Boolean> daysMap = new HashMap<Integer, Boolean>(); Map<Integer, Boolean> daysCheckedMap = new HashMap<Integer, Boolean>(); if (recurrenceType == 2) { daysMap.put(DateTimeConstants.MONDAY, monday); daysMap.put(DateTimeConstants.TUESDAY, tuesday); daysMap.put(DateTimeConstants.WEDNESDAY, wednesday); daysMap.put(DateTimeConstants.THURSDAY, thursday); daysMap.put(DateTimeConstants.FRIDAY, friday); daysMap.put(DateTimeConstants.SATURDAY, saturday); daysMap.put(DateTimeConstants.SUNDAY, sunday); for (Integer day : daysMap.keySet()) { if (daysMap.get(day)) { daysCheckedMap.put(day, daysMap.get(day)); } } if (daysMap.isEmpty()) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_DAYS_CHECKED)), IException.CONFIGURATION_ERROR); } } int monthRepeatType = new Integer(request.getContext().get("monthRepeatType").toString()); int endType = new Integer(request.getContext().get("endType").toString()); int repetitionsNumber = 0; if (endType == 1) { if (request.getContext().get("repetitionsNumber") == null) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_REPETITION_NUMBER)), IException.CONFIGURATION_ERROR); } repetitionsNumber = new Integer(request.getContext().get("repetitionsNumber").toString()); if (repetitionsNumber < 1) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_REPETITION_NUMBER)), IException.CONFIGURATION_ERROR); } } LocalDate endDate = new LocalDate(); if (endType == 2) { if (request.getContext().get("endDate") == null) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_END_DATE)), IException.CONFIGURATION_ERROR); } endDate = new LocalDate(request.getContext().get("endDate").toString()); if (endDate.isBefore(event.getStartDateTime()) && endDate.isEqual(event.getStartDateTime())) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_END_DATE)), IException.CONFIGURATION_ERROR); } } switch (recurrenceType) { case 1: eventService.addRecurrentEventsByDays(event, periodicity, endType, repetitionsNumber, endDate); break; case 2: eventService.addRecurrentEventsByWeeks(event, periodicity, endType, repetitionsNumber, endDate, daysCheckedMap); break; case 3: eventService.addRecurrentEventsByMonths(event, periodicity, endType, repetitionsNumber, endDate, monthRepeatType); break; case 4: eventService.addRecurrentEventsByYears(event, periodicity, endType, repetitionsNumber, endDate); break; default: break; } response.setCanClose(true); response.setReload(true); }
From source file:com.axelor.apps.crm.web.EventController.java
License:Open Source License
@Transactional public void changeAll(ActionRequest request, ActionResponse response) throws AxelorException { Long eventId = new Long(request.getContext().get("_idEvent").toString()); Event event = eventRepo.find(eventId); Event child = eventRepo.all().filter("self.parentEvent.id = ?1", event.getId()).fetchOne(); Event parent = event.getParentEvent(); child.setParentEvent(null);//w ww . j ava 2 s .co m Event eventDeleted = child; child = eventRepo.all().filter("self.parentEvent.id = ?1", eventDeleted.getId()).fetchOne(); while (child != null) { child.setParentEvent(null); eventRepo.remove(eventDeleted); eventDeleted = child; child = eventRepo.all().filter("self.parentEvent.id = ?1", eventDeleted.getId()).fetchOne(); } while (parent != null) { Event nextParent = parent.getParentEvent(); eventRepo.remove(parent); parent = nextParent; } RecurrenceConfiguration conf = request.getContext().asType(RecurrenceConfiguration.class); RecurrenceConfigurationRepository confRepo = Beans.get(RecurrenceConfigurationRepository.class); conf = confRepo.save(conf); event.setRecurrenceConfiguration(conf); event = eventRepo.save(event); if (conf.getRecurrenceType() == null) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_RECURRENCE_TYPE)), IException.CONFIGURATION_ERROR); } int recurrenceType = conf.getRecurrenceType(); if (conf.getPeriodicity() == null) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_PERIODICITY)), IException.CONFIGURATION_ERROR); } int periodicity = conf.getPeriodicity(); if (periodicity < 1) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_PERIODICITY)), IException.CONFIGURATION_ERROR); } boolean monday = conf.getMonday(); boolean tuesday = conf.getTuesday(); boolean wednesday = conf.getWednesday(); boolean thursday = conf.getThursday(); boolean friday = conf.getFriday(); boolean saturday = conf.getSaturday(); boolean sunday = conf.getSunday(); Map<Integer, Boolean> daysMap = new HashMap<Integer, Boolean>(); Map<Integer, Boolean> daysCheckedMap = new HashMap<Integer, Boolean>(); if (recurrenceType == 2) { daysMap.put(DateTimeConstants.MONDAY, monday); daysMap.put(DateTimeConstants.TUESDAY, tuesday); daysMap.put(DateTimeConstants.WEDNESDAY, wednesday); daysMap.put(DateTimeConstants.THURSDAY, thursday); daysMap.put(DateTimeConstants.FRIDAY, friday); daysMap.put(DateTimeConstants.SATURDAY, saturday); daysMap.put(DateTimeConstants.SUNDAY, sunday); for (Integer day : daysMap.keySet()) { if (daysMap.get(day)) { daysCheckedMap.put(day, daysMap.get(day)); } } if (daysMap.isEmpty()) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_DAYS_CHECKED)), IException.CONFIGURATION_ERROR); } } int monthRepeatType = conf.getMonthRepeatType(); int endType = conf.getEndType(); int repetitionsNumber = 0; if (endType == 1) { if (conf.getRepetitionsNumber() == null) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_REPETITION_NUMBER)), IException.CONFIGURATION_ERROR); } repetitionsNumber = conf.getRepetitionsNumber(); if (repetitionsNumber < 1) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_REPETITION_NUMBER)), IException.CONFIGURATION_ERROR); } } LocalDate endDate = new LocalDate(); if (endType == 2) { if (conf.getEndDate() == null) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_END_DATE)), IException.CONFIGURATION_ERROR); } endDate = new LocalDate(conf.getEndDate()); if (endDate.isBefore(event.getStartDateTime()) && endDate.isEqual(event.getStartDateTime())) { throw new AxelorException(String.format(I18n.get(IExceptionMessage.RECURRENCE_END_DATE)), IException.CONFIGURATION_ERROR); } } switch (recurrenceType) { case 1: eventService.addRecurrentEventsByDays(event, periodicity, endType, repetitionsNumber, endDate); break; case 2: eventService.addRecurrentEventsByWeeks(event, periodicity, endType, repetitionsNumber, endDate, daysCheckedMap); break; case 3: eventService.addRecurrentEventsByMonths(event, periodicity, endType, repetitionsNumber, endDate, monthRepeatType); break; case 4: eventService.addRecurrentEventsByYears(event, periodicity, endType, repetitionsNumber, endDate); break; default: break; } response.setCanClose(true); response.setReload(true); }
From source file:com.axelor.apps.project.service.ProjectPlanningService.java
License:Open Source License
public static String getNameForColumns(int year, int week, int day) { LocalDate date = new LocalDate().withYear(year).withWeekOfWeekyear(week).withDayOfWeek(1); LocalDate newDate = date.plusDays(day - 1); return " " + Integer.toString(newDate.getDayOfMonth()) + "/" + Integer.toString(newDate.getMonthOfYear()); }
From source file:com.axelor.apps.project.service.ProjectPlanningService.java
License:Open Source License
public void getTasksForUser(ActionRequest request, ActionResponse response) { List<Map<String, String>> dataList = new ArrayList<Map<String, String>>(); try {//from ww w . ja va2s. c o m LocalDate todayDate = Beans.get(GeneralService.class).getTodayDate(); List<ProjectPlanningLine> linesList = Beans.get(ProjectPlanningLineRepository.class).all() .filter("self.user.id = ?1 AND self.year >= ?2 AND self.week >= ?3", AuthUtils.getUser().getId(), todayDate.getYear(), todayDate.getWeekOfWeekyear()) .fetch(); for (ProjectPlanningLine line : linesList) { if (line.getMonday().compareTo(BigDecimal.ZERO) != 0) { LocalDate date = new LocalDate().withYear(line.getYear()).withWeekOfWeekyear(line.getWeek()) .withDayOfWeek(DateTimeConstants.MONDAY); if (date.isAfter(todayDate) || date.isEqual(todayDate)) { Map<String, String> map = new HashMap<String, String>(); map.put("taskId", line.getProjectTask().getId().toString()); map.put("name", line.getProjectTask().getFullName()); if (line.getProjectTask().getProject() != null) { map.put("projectName", line.getProjectTask().getProject().getFullName()); } else { map.put("projectName", ""); } map.put("date", date.toString()); map.put("duration", line.getMonday().toString()); dataList.add(map); } } if (line.getTuesday().compareTo(BigDecimal.ZERO) != 0) { LocalDate date = new LocalDate().withYear(line.getYear()).withWeekOfWeekyear(line.getWeek()) .withDayOfWeek(DateTimeConstants.TUESDAY); if (date.isAfter(todayDate) || date.isEqual(todayDate)) { Map<String, String> map = new HashMap<String, String>(); map.put("taskId", line.getProjectTask().getId().toString()); map.put("name", line.getProjectTask().getFullName()); if (line.getProjectTask().getProject() != null) { map.put("projectName", line.getProjectTask().getProject().getFullName()); } else { map.put("projectName", ""); } map.put("date", date.toString()); map.put("duration", line.getTuesday().toString()); dataList.add(map); } } if (line.getWednesday().compareTo(BigDecimal.ZERO) != 0) { LocalDate date = new LocalDate().withYear(line.getYear()).withWeekOfWeekyear(line.getWeek()) .withDayOfWeek(DateTimeConstants.WEDNESDAY); if (date.isAfter(todayDate) || date.isEqual(todayDate)) { Map<String, String> map = new HashMap<String, String>(); map.put("taskId", line.getProjectTask().getId().toString()); map.put("name", line.getProjectTask().getFullName()); if (line.getProjectTask().getProject() != null) { map.put("projectName", line.getProjectTask().getProject().getFullName()); } else { map.put("projectName", ""); } map.put("date", date.toString()); map.put("duration", line.getWednesday().toString()); dataList.add(map); } } if (line.getThursday().compareTo(BigDecimal.ZERO) != 0) { LocalDate date = new LocalDate().withYear(line.getYear()).withWeekOfWeekyear(line.getWeek()) .withDayOfWeek(DateTimeConstants.THURSDAY); if (date.isAfter(todayDate) || date.isEqual(todayDate)) { Map<String, String> map = new HashMap<String, String>(); map.put("taskId", line.getProjectTask().getId().toString()); map.put("name", line.getProjectTask().getFullName()); if (line.getProjectTask().getProject() != null) { map.put("projectName", line.getProjectTask().getProject().getFullName()); } else { map.put("projectName", ""); } map.put("date", date.toString()); map.put("duration", line.getThursday().toString()); dataList.add(map); } } if (line.getFriday().compareTo(BigDecimal.ZERO) != 0) { LocalDate date = new LocalDate().withYear(line.getYear()).withWeekOfWeekyear(line.getWeek()) .withDayOfWeek(DateTimeConstants.FRIDAY); if (date.isAfter(todayDate) || date.isEqual(todayDate)) { Map<String, String> map = new HashMap<String, String>(); map.put("taskId", line.getProjectTask().getId().toString()); map.put("name", line.getProjectTask().getFullName()); if (line.getProjectTask().getProject() != null) { map.put("projectName", line.getProjectTask().getProject().getFullName()); } else { map.put("projectName", ""); } map.put("date", date.toString()); map.put("duration", line.getFriday().toString()); dataList.add(map); } } if (line.getSaturday().compareTo(BigDecimal.ZERO) != 0) { LocalDate date = new LocalDate().withYear(line.getYear()).withWeekOfWeekyear(line.getWeek()) .withDayOfWeek(DateTimeConstants.SATURDAY); if (date.isAfter(todayDate) || date.isEqual(todayDate)) { Map<String, String> map = new HashMap<String, String>(); map.put("taskId", line.getProjectTask().getId().toString()); map.put("name", line.getProjectTask().getFullName()); if (line.getProjectTask().getProject() != null) { map.put("projectName", line.getProjectTask().getProject().getFullName()); } else { map.put("projectName", ""); } map.put("date", date.toString()); map.put("duration", line.getSaturday().toString()); dataList.add(map); } } if (line.getSunday().compareTo(BigDecimal.ZERO) != 0) { LocalDate date = new LocalDate().withYear(line.getYear()).withWeekOfWeekyear(line.getWeek()) .withDayOfWeek(DateTimeConstants.SUNDAY); if (date.isAfter(todayDate) || date.isEqual(todayDate)) { Map<String, String> map = new HashMap<String, String>(); map.put("taskId", line.getProjectTask().getId().toString()); map.put("name", line.getProjectTask().getFullName()); if (line.getProjectTask().getProject() != null) { map.put("projectName", line.getProjectTask().getProject().getFullName()); } else { map.put("projectName", ""); } map.put("date", date.toString()); map.put("duration", line.getSunday().toString()); dataList.add(map); } } } response.setData(dataList); } catch (Exception e) { response.setStatus(-1); response.setError(e.getMessage()); } }
From source file:com.axelor.csv.script.ValidateSupplyChain.java
License:Open Source License
@Transactional void validatePurchaseOrder(Long poId) { StockMoveService stockMoveService = Beans.get(StockMoveService.class); try {//from w w w .j av a2s . c o m PurchaseOrder purchaseOrder = purchaseOrderRepo.find(poId); purchaseOrderServiceSupplychainImpl.computePurchaseOrder(purchaseOrder); if (purchaseOrder.getStatusSelect() == 4 || purchaseOrder.getStatusSelect() == 5 && purchaseOrder.getLocation() == null) { purchaseOrderServiceSupplychainImpl.createStocksMove(purchaseOrder); StockMove stockMove = stockMoveRepo.all().filter("purchaseOrder.id = ?1", purchaseOrder.getId()) .fetchOne(); if (stockMove != null) { stockMoveService.copyQtyToRealQty(stockMove); stockMoveService.realize(stockMove); stockMove.setRealDate(purchaseOrder.getDeliveryDate()); } purchaseOrder.setValidationDate(purchaseOrder.getOrderDate()); purchaseOrder.setValidatedByUser(AuthUtils.getUser()); purchaseOrder .setSupplierPartner(purchaseOrderServiceSupplychainImpl.validateSupplier(purchaseOrder)); Invoice invoice = Beans.get(PurchaseOrderInvoiceService.class).generateInvoice(purchaseOrder); if (purchaseOrder.getValidationDate() != null) { invoice.setInvoiceDate(purchaseOrder.getValidationDate()); } else { invoice.setInvoiceDate(new LocalDate()); } invoiceService.compute(invoice); invoiceService.validate(invoice); invoiceService.ventilate(invoice); } purchaseOrderRepo.save(purchaseOrder); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.axelor.csv.script.ValidateSupplyChain.java
License:Open Source License
@Transactional void validateSaleOrder(Long soId) { SaleOrderService saleOrderService = Beans.get(SaleOrderService.class); StockMoveService stockMoveService = Beans.get(StockMoveService.class); try {//from w ww .j a v a 2 s .c o m SaleOrder saleOrder = saleOrderRepo.find(soId); for (SaleOrderLine line : saleOrder.getSaleOrderLineList()) line.setTaxLine(saleOrderLineService.getTaxLine(saleOrder, line)); saleOrderService.computeSaleOrder(saleOrder); if (saleOrder.getStatusSelect() == ISaleOrder.STATUS_ORDER_CONFIRMED) { //taskSaleOrderService.createTasks(saleOrder); TODO once we will have done the generation of tasks in project module saleOrderStockService.createStocksMovesFromSaleOrder(saleOrder); Beans.get(SaleOrderPurchaseService.class).createPurchaseOrders(saleOrder); // productionOrderSaleOrderService.generateProductionOrder(saleOrder); saleOrder.setClientPartner(saleOrderService.validateCustomer(saleOrder)); //Generate invoice from sale order Invoice invoice = Beans.get(SaleOrderInvoiceService.class).generateInvoice(saleOrder); if (saleOrder.getConfirmationDate() != null) { invoice.setInvoiceDate(saleOrder.getConfirmationDate()); } else { invoice.setInvoiceDate(new LocalDate()); } invoiceService.compute(invoice); invoiceService.validate(invoice); invoiceService.ventilate(invoice); StockMove stockMove = stockMoveRepo.all().filter("saleOrder = ?1", saleOrder).fetchOne(); if (stockMove != null && stockMove.getStockMoveLineList() != null && !stockMove.getStockMoveLineList().isEmpty()) { stockMoveService.copyQtyToRealQty(stockMove); stockMoveService.validate(stockMove); stockMove.setRealDate(saleOrder.getConfirmationDate()); } } saleOrderRepo.save(saleOrder); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.axelor.script.ScriptBindings.java
License:Open Source License
@SuppressWarnings("all") private Object getSpecial(String name) throws Exception { switch (name) { case "__id__": if (variables.containsKey("id")) return Longs.tryParse(variables.get("id").toString()); if (variables.containsKey("_id")) return Longs.tryParse(variables.get("_id").toString()); return ((Context) variables).asType(Model.class).getId(); case "__ids__": return variables.get("_ids"); case "__this__": return ((Context) variables).asType(Model.class); case "__parent__": return ((Context) variables).getParentContext(); case "__date__": return new LocalDate(); case "__time__": return new LocalDateTime(); case "__datetime__": return new DateTime(); case "__config__": if (configContext == null) { configContext = new ConfigContext(); }/* w ww.j a v a 2 s.c o m*/ return configContext; case "__user__": return AuthUtils.getUser(); case "__self__": Model bean = ((Context) variables).asType(Model.class); if (bean == null || bean.getId() == null) return null; return JPA.em().getReference(EntityHelper.getEntityClass(bean), bean.getId()); case "__ref__": Map values = (Map) variables.get("_ref"); Class<?> klass = Class.forName((String) values.get("_model")); return JPA.em().getReference(klass, Long.parseLong(values.get("id").toString())); } return null; }
From source file:com.axelor.tool.template.TemplateMaker.java
License:Open Source License
public String make() { if (Strings.isNullOrEmpty(this.template)) { throw new IllegalArgumentException(I18n.get(IExceptionMessage.TEMPLATE_MAKER_2)); }/*ww w .j a v a2s.co m*/ ST st = new ST(stGroup, template); Map<String, Object> _map = Maps.newHashMap(); if (localContext != null && !localContext.isEmpty()) { _map.putAll(localContext); } _map.putAll(context); //Internal context _map.put("__user__", AuthUtils.getUser()); _map.put("__date__", new LocalDate()); _map.put("__time__", new LocalTime()); _map.put("__datetime__", new LocalDateTime()); for (String key : _map.keySet()) { st.add(key, _map.get(key)); } return _make(st); }
From source file:com.axelor.web.service.DmsService.java
License:Open Source License
@POST @Path("download/batch") public javax.ws.rs.core.Response onDownload(Request request) { final List<Object> ids = request.getRecords(); if (ids == null || ids.isEmpty()) { return javax.ws.rs.core.Response.status(Status.NOT_FOUND).build(); }//from ww w .j a v a 2 s .c o m final List<DMSFile> records = repository.all().filter("self.id in :ids").bind("ids", ids).fetch(); if (records.size() != ids.size()) { return javax.ws.rs.core.Response.status(Status.NOT_FOUND).build(); } final String batchId = UUID.randomUUID().toString(); final Map<String, Object> data = new HashMap<>(); String batchName = "documents-" + new LocalDate().toString("yyyy-MM-dd") + ".zip"; if (records.size() == 1) { batchName = records.get(0).getFileName(); } data.put("batchId", batchId); data.put("batchName", batchName); httpRequest.getSession().setAttribute(batchId, ids); return javax.ws.rs.core.Response.ok(data).build(); }
From source file:com.axelor.web.service.DmsService.java
License:Open Source License
@GET @Path("download/{batchId}") @Produces(MediaType.APPLICATION_OCTET_STREAM) public javax.ws.rs.core.Response doDownload(@PathParam("batchId") String batchId) { @SuppressWarnings("all") final List<Object> ids = (List) httpRequest.getSession().getAttribute(batchId); if (ids == null) { return javax.ws.rs.core.Response.status(Status.NOT_FOUND).build(); }//from w ww .ja v a2s.c o m final List<DMSFile> records = repository.all().filter("self.id in :ids").bind("ids", ids).fetch(); if (records.size() != ids.size()) { return javax.ws.rs.core.Response.status(Status.NOT_FOUND).build(); } // if file if (records.size() == 1 && records.get(0).getMetaFile() != null) { MetaFile file = records.get(0).getMetaFile(); return stream(MetaFiles.getPath(file).toFile(), file.getFileName()); } final StreamingOutput so = new StreamingOutput() { @Override public void write(OutputStream output) throws IOException, WebApplicationException { final ZipOutputStream zos = new ZipOutputStream(output); try { for (DMSFile file : records) { writeToZip(zos, file); } } finally { zos.close(); } } }; final String batchName = "documents-" + new LocalDate().toString("yyyy-MM-dd") + ".zip"; return stream(so, batchName); }