Example usage for org.joda.time DateTime withZone

List of usage examples for org.joda.time DateTime withZone

Introduction

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

Prototype

public DateTime withZone(DateTimeZone newZone) 

Source Link

Document

Returns a copy of this datetime with a different time zone, preserving the millisecond instant.

Usage

From source file:com.google.sampling.experiential.server.DSQueryBuilder.java

License:Open Source License

private DateTime newDateTimeFromString(String firstDate, DateTimeZone jodaTimeZone) {
    DateTime parsedTime = jodaFormatter.withZone(jodaTimeZone).parseDateTime(firstDate);
    return parsedTime.withZone(DateTimeZone.UTC);
}

From source file:com.google.sampling.experiential.server.JDOQueryBuilder.java

License:Open Source License

private DateTime newDateTimeFromDateString(String firstDate, DateTimeZone jodaTimeZone) {
    DateTime parsedTime = jodaDateFormatter.withZone(jodaTimeZone).parseDateTime(firstDate);
    return parsedTime.withZone(DateTimeZone.UTC);
}

From source file:com.google.sampling.experiential.server.JDOQueryBuilder.java

License:Open Source License

private DateTime newDateTimeFromDateTimeString(String firstDate, DateTimeZone jodaTimeZone) {
    DateTime parsedTime = jodaDateTimeFormatter.parseDateTime(firstDate);
    return parsedTime.withZone(DateTimeZone.UTC);
}

From source file:com.hangum.tadpole.engine.utils.TimeZoneUtil.java

License:Open Source License

/**
 * ?  ? ?  .//w w w  . j av  a  2s.  c om
 * 
 * @param localTimeMills
 * @return
 */
public static long chageTimeZone(long localTimeMills) {
    String dbTimeZone = GetAdminPreference.getDBTimezone();
    // db? timezone    .
    if (StringUtils.isEmpty(dbTimeZone)) {
        return localTimeMills;
    } else {
        //   UTC   . 
        DateTime sourceDateTime = new DateTime(localTimeMills,
                DateTimeZone.forID(SessionManager.getTimezone()));
        DateTime targetDateTime = sourceDateTime.withZone(DateTimeZone.forID(dbTimeZone));
        if (logger.isDebugEnabled()) {
            logger.debug(String.format("[SessionManager dbTimezone] %s => %s => %s",
                    SessionManager.getTimezone(), localTimeMills, sourceDateTime.toString()));
            logger.debug(String.format("[targetDateTime] %s => %s", targetDateTime.getMillis(),
                    targetDateTime.toString()));
            logger.debug("===============================================================");
        }

        return targetDateTime.getMillis();
    }
}

From source file:com.inbravo.scribe.rest.service.writer.utils.ConvertTimeZone.java

License:Open Source License

public static void main(String[] args) throws ParseException {

    DateTimeFormatter parser = ISODateTimeFormat.dateTimeParser();

    DateTime dateTimeHere = parser.parseDateTime("2012-10-31T17:25:54.478-07:00");

    DateTime secondDateTime = dateTimeHere.withZone(DateTimeZone.forID("PST8PDT"));

    System.out.println("second: " + secondDateTime);
}

From source file:com.infinities.skyport.compute.entity.adapter.ISO8601DateAdapter.java

License:Apache License

@Override
public String marshal(Date v) throws Exception {
    try {// ww  w  . j  a  va  2s  .com
        // DateFormat format = iso8601Format.get();
        // return format.format(v);
        DateTime dt = new DateTime(v);
        dt.withZone(timeZone);
        return dt.toString(outputFormatter);
    } catch (Exception e) {
        logger.warn("Failed to format date {}", v.toString());
        return null;
    }
}

From source file:com.infotree.qliktest.admin.web.controller.ModuleController.java

/**
 * This method is to save the new module/package
 */// ww w . j a v a 2s .c  o  m
@RequestMapping(value = "/save", method = RequestMethod.POST)
public String save(@Valid Module entity, BindingResult bindingResult, Model model, HttpServletRequest request) {
    try {
        DateTime dt = new DateTime();
        DateTimeZone dtZone = DateTimeZone.forID("Asia/Kolkata");
        DateTime dtus = dt.withZone(dtZone);
        Date dateInIndia = dtus.toLocalDateTime().toDate();
        Module m = null;
        String constraintId = entity.getConstraintId();
        String value = entity.getValue();

        String[] constraints = constraintId.split(",");
        String[] values = value.split(",");

        int numDupes = 0;

        for (int i = 1; i < constraints.length; i++) {
            if (constraints[i].equals(constraints[i - 1])) {
                numDupes++;
            }
        }

        if (numDupes != 0) {
            model.addAttribute("createmodule", "createmodule");
            model.addAttribute("active_module_list", moduleService.getModuleList());
            model.addAttribute("constraints_list", constraintsService.list());
            model.addAttribute("modulealreadyexists", "You Can Not Assign Two Values for the same control");
            model.addAttribute("permissions_list", permissionsService.list());
            model.addAttribute("reports_list", reportsService.list());
        } else {

            String[] namelist = entity.getName().split(",");
            String name = namelist[0];
            model.addAttribute("crudObj", getEntityInstance());
            if (moduleService.findByName(name) != null) {
                model.addAttribute("createmodule", "createmodule");
                model.addAttribute("active_module_list", moduleService.getModuleList());
                model.addAttribute("modulealreadyexists",
                        "Package already exists. Pl. enter a different Name.");
            } else {
                Module module = new Module();
                module.setName(name.trim());
                module.setDescription(entity.getDescription());
                module.setCreatedBy(entity.getCreatedBy());

                module.setCreatedDate(dateInIndia);
                m = moduleService.save(module);
                /**
                 * Prepare the audit log record
                 */
                AuditLogRecord record = new AuditLogRecord();
                record.setActionDate(new java.util.Date());
                record.setActionType(AuditType.CREATE);
                record.setActionData("Module Name :" + name);
                record.setIpOrigin(request.getSession().getAttribute("ipAddress").toString());
                /*try {
                java.net.InetAddress inetAddress = java.net.InetAddress.getLocalHost();
                record.setIpOrigin(inetAddress.getHostAddress());
                } catch (UnknownHostException e) {
                e.printStackTrace();
                }*/
                record.setUserId((Integer) request.getSession().getAttribute("userid"));
                record.setUserName(request.getSession().getAttribute("username").toString());
                auditLogService.saveRecord(record);
                //assigning the permissions to the module
                List<Integer> permissionsList = entity.getPermissionsId();
                if (permissionsList != null) {
                    Iterator<Integer> iterator = permissionsList.iterator();
                    while (iterator.hasNext()) {
                        ModulePermissions md = new ModulePermissions();
                        ModulePermissionsComp modperComp = new ModulePermissionsComp();
                        modperComp.setModuleId(module.getId());
                        modperComp.setPermissionId(iterator.next());
                        md.setModulePermissionsComp(modperComp);
                        md.setCreatedBy(entity.getCreatedBy());
                        md.setCreatedDate(dateInIndia);

                        modulePermissionsService.save(md);
                    }
                }
                /**
                 * assign reports to the module
                 */
                List<Integer> reportsList = entity.getReportIds();
                if (reportsList != null) {
                    Iterator<Integer> iterator = reportsList.iterator();
                    while (iterator.hasNext()) {
                        ModuleReportsAssign moduleReport = new ModuleReportsAssign();
                        ModuleReportComp moduleReportComp = new ModuleReportComp();
                        moduleReportComp.setModuleId(module.getId());
                        moduleReportComp.setReportId(iterator.next());
                        moduleReport.setModuleReportComp(moduleReportComp);
                        moduleReport.setCreatedBy(entity.getCreatedBy());
                        moduleReport.setCreatedDate(dateInIndia);
                        moduleReportService.save(moduleReport);
                        model.addAttribute("moduleassigned", "Reports Assigned");
                    }
                }

                /**
                 * assigning the constraints and values to the package
                 */
                ModuleConstraintComp comp = new ModuleConstraintComp();
                ModuleConstraints moduleConstraints = new ModuleConstraints();
                for (int i = 0; i < constraints.length; i++) {
                    comp.setConstraintId(Integer.parseInt(constraints[i]));
                    comp.setModuleId(m.getId());
                    moduleConstraints.setModuleConstraintComp(comp);
                    if (values[i] == null || values[i].trim().equals(""))
                        moduleConstraints.setValue(0);
                    else
                        moduleConstraints.setValue(Integer.parseInt(values[i]));
                    moduleConstraints.setCreatedBy(entity.getCreatedBy());
                    moduleConstraints.setCreatedDate(dateInIndia);
                    moduleConstraintsService.save(moduleConstraints);
                }
                model.addAttribute("permissions_list", permissionsService.list());
                model.addAttribute("reports_list", reportsService.list());
                model.addAttribute("createmodule", "createmodule");
                model.addAttribute("active_module_list", moduleService.getModuleList());
                model.addAttribute("modulecreated", "Package '" + name + "' created.");
                model.addAttribute("constraints_list", constraintsService.list());
            }
        }

        entity.setName(null);
    } catch (Exception e) {
        LOG.error(e.toString());
        e.printStackTrace();
    }
    return "home";
}

From source file:com.infotree.qliktest.admin.web.controller.ModuleController.java

/**
 * This method is to save the permissioins to the module
 *///  w  w  w  . j  a  v a 2s. c o m
@RequestMapping(value = "/saveassignpermissionstomodule", method = RequestMethod.POST)
public String saveAssignPermissionsToModule(@Valid ModulePermissionsPojo entity, BindingResult bindingResult,
        Model model, HttpServletRequest request) {
    try {
        List<Integer> permissionIds = entity.getPermissionsId();
        modulePermissionsService.deleteByModuleId(entity.getModuleId());
        if (permissionIds != null) {
            Iterator<Integer> iterator = permissionIds.iterator();
            while (iterator.hasNext()) {
                ModulePermissions md = new ModulePermissions();
                ModulePermissionsComp modperComp = new ModulePermissionsComp();
                modperComp.setModuleId(entity.getModuleId());
                modperComp.setPermissionId(iterator.next());
                md.setModulePermissionsComp(modperComp);
                md.setCreatedBy(entity.getCreatedBy());
                DateTime dt = new DateTime();
                DateTimeZone dtZone = DateTimeZone.forID("Asia/Kolkata");
                DateTime dtus = dt.withZone(dtZone);
                Date dateInIndia = dtus.toLocalDateTime().toDate();
                md.setCreatedDate(dateInIndia);

                modulePermissionsService.save(md);
            }
            model.addAttribute("modulesassigned", "Permissions Assigned");
        } else {
            model.addAttribute("modulesassigned", " All Permissions Removed Successfully");
        }

        model.addAttribute("modulesassigned", "Permissions Assigned");
        model.addAttribute("crudObj", new ModulePermissionsPojo());
        model.addAttribute("module_list", moduleService.list());
        model.addAttribute("assignpermissionstomodule", "assignpermissionstomodule");
    } catch (Exception e) {
        LOG.error(e.toString());
        e.printStackTrace();
    }
    return "home";
}

From source file:com.infotree.qliktest.admin.web.controller.ModuleController.java

/**
 * This method is to update the module with the new data
 *//*ww  w . jav  a  2  s  .c o m*/
@RequestMapping(value = "/updatemodule", method = RequestMethod.POST)
public String updateModule(@ModelAttribute("crudObj") @Valid Module entity, BindingResult bindingResult,
        Model model, HttpServletRequest request) {
    try {
        DateTime dt = new DateTime();
        DateTimeZone dtZone = DateTimeZone.forID("Asia/Kolkata");
        DateTime dtus = dt.withZone(dtZone);
        Date dateInIndia = dtus.toLocalDateTime().toDate();
        int status = 0;
        String conArr[] = null;
        String valArr[] = null;
        List<String> conList = null;

        Module mod = moduleService.getById(entity.getId());
        Module module = moduleService.getModuleByNameAndId(entity.getName(), entity.getId());
        String constraintId = entity.getConstraintId();
        String value = entity.getValue();

        if (constraintId != null) {
            conArr = new String[constraintId.length()];
            conArr = constraintId.split(",");
            conList = Arrays.asList(conArr);
        }
        if (value != null) {
            valArr = new String[value.length()];
            valArr = value.split(",");
        }
        if (conList.size() != 0) {
            TreeSet<String> conSet = new TreeSet<String>(conList);
            if (conList.size() != conSet.size()) {
                status = 1;
            }
        }
        if (module != null) {
            status = 2;
        }
        if (status != 0) {
            if (status == 1) {
                model.addAttribute("moduleupdated", "You can't assign multiple values for the same control");
            } else {
                model.addAttribute("moduleupdated", "Package Name Already Exists");
            }
        } else {
            entity.setName(entity.getName().trim());

            entity.setModifiedDate(dateInIndia);
            moduleService.updateModule(entity);

            /**
             * preparing the audit log 
             */
            AuditLogRecord record = new AuditLogRecord();
            record.setActionDate(new java.util.Date());
            record.setActionType(AuditType.MODIFY);
            record.setActionData(
                    "Old Module Name :" + mod.getName() + " And new module name is " + entity.getName());
            record.setIpOrigin(request.getSession().getAttribute("ipAddress").toString());
            /*try {
               InetAddress inetAddress = InetAddress.getLocalHost();
               record.setIpOrigin(inetAddress.getHostAddress());
            } catch (UnknownHostException e) {
               e.printStackTrace();
            }*/
            record.setUserId((Integer) request.getSession().getAttribute("userid"));
            record.setUserName(request.getSession().getAttribute("username").toString());
            auditLogService.saveRecord(record);

            /**
             * assigning the permission to the license
             */

            modulePermissionsService.deleteByModuleId(entity.getId());
            List<Integer> permissionsList = entity.getPermissionsId();
            if (permissionsList != null) {
                Iterator<Integer> iterator = permissionsList.iterator();
                while (iterator.hasNext()) {
                    ModulePermissions md = new ModulePermissions();
                    ModulePermissionsComp modperComp = new ModulePermissionsComp();
                    modperComp.setModuleId(entity.getId());
                    modperComp.setPermissionId(iterator.next());
                    md.setModulePermissionsComp(modperComp);
                    md.setCreatedBy(entity.getCreatedBy());

                    md.setCreatedDate(dateInIndia);

                    modulePermissionsService.save(md);
                }
            }
            /**
             * assign reports to the module
             */
            moduleReportService.deleteByModuleId(entity.getId());
            List<Integer> reportsList = entity.getReportIds();
            if (reportsList != null) {
                Iterator<Integer> iterator = reportsList.iterator();
                while (iterator.hasNext()) {
                    ModuleReportsAssign moduleReport = new ModuleReportsAssign();
                    ModuleReportComp moduleReportComp = new ModuleReportComp();
                    moduleReportComp.setModuleId(entity.getId());
                    moduleReportComp.setReportId(iterator.next());
                    moduleReport.setModuleReportComp(moduleReportComp);
                    moduleReport.setCreatedBy(entity.getCreatedBy());
                    moduleReport.setCreatedDate(dateInIndia);
                    moduleReportService.save(moduleReport);
                    model.addAttribute("moduleassigned", "Reports Assigned");
                }
            }

            /**
             * assigning the constraints to the module
             */
            if (conArr != null && valArr != null) {
                moduleConstraintsService.deleteByModuleId(entity.getId());
                ModuleConstraintComp comp = new ModuleConstraintComp();
                ModuleConstraints moduleConstraints = new ModuleConstraints();
                for (int i = 0; i < conArr.length; i++) {
                    comp.setConstraintId(Integer.parseInt(conArr[i]));
                    comp.setModuleId(entity.getId());
                    moduleConstraints.setModuleConstraintComp(comp);
                    moduleConstraints.setValue(Integer.parseInt(valArr[i]));
                    moduleConstraints.setCreatedBy(entity.getCreatedBy());
                    moduleConstraints.setCreatedDate(dateInIndia);
                    moduleConstraintsService.save(moduleConstraints);
                }
            }

            model.addAttribute("moduleupdated", "Package Updated Successfully");
        }
        model.addAttribute("crudObj", getEntityInstance());
        model.addAttribute("editmodule", "editmodule");
        List<Module> moduleList = moduleService.getOrderBydesc();
        List<Module> modules = new ArrayList<Module>();
        if (moduleList != null) {
            Iterator<Module> iterator = moduleList.iterator();
            while (iterator.hasNext()) {
                Module m = iterator.next();
                Integer userId;
                if (m.getModifiedBy() != null) {
                    userId = Integer.parseInt(m.getModifiedBy());
                    User u = userService.getById(userId);
                    m.setCreatedName(u.getUserName());
                } else {
                    userId = Integer.parseInt(m.getCreatedBy());
                    User u = userService.getById(userId);
                    m.setCreatedName(u.getUserName());
                }

                modules.add(m);
            }
        }
        model.addAttribute("permissions_list", permissionsService.list());
        model.addAttribute("roles_list", roleService.list());
        model.addAttribute("reports_list", reportsService.list());
        model.addAttribute("constraints_list", constraintsService.list());
        model.addAttribute("module_list", modules);
    } catch (Exception e) {
        LOG.error(e.toString());
        e.printStackTrace();
    }
    return "home";
}

From source file:com.infotree.qliktest.admin.web.controller.ModuleController.java

/**
 * This method is to saave the reports to the module/package
 *///w w w . j a v  a2s .  c  o m

@RequestMapping(value = "/saveassignedreports", method = RequestMethod.POST)
public String assignReportsToRoleCompleted(@Valid ModuleReportsPojo entity, BindingResult bindingResult,
        Model model) {
    try {
        moduleReportService.deleteByModuleId(entity.getModuleId());
        List<Integer> reportsList = entity.getReportIds();
        if (reportsList != null) {
            Iterator<Integer> iterator = reportsList.iterator();
            while (iterator.hasNext()) {
                ModuleReportsAssign moduleReport = new ModuleReportsAssign();
                ModuleReportComp moduleReportComp = new ModuleReportComp();
                moduleReportComp.setModuleId(entity.getModuleId());
                moduleReportComp.setReportId(iterator.next());
                moduleReport.setModuleReportComp(moduleReportComp);
                moduleReport.setCreatedBy(entity.getCreatedBy());
                DateTime dt = new DateTime();
                DateTimeZone dtZone = DateTimeZone.forID("Asia/Kolkata");
                DateTime dtus = dt.withZone(dtZone);
                Date dateInIndia = dtus.toLocalDateTime().toDate();
                moduleReport.setCreatedDate(dateInIndia);
                moduleReportService.save(moduleReport);
                model.addAttribute("moduleassigned", "Reports Assigned");
            }
        } else {
            model.addAttribute("moduleassigned", "Reports Removed Successfully");
        }

        model.addAttribute("crudObj", new ModuleReportsPojo());
        model.addAttribute("assignreportstomodule", "assignreportstomodule");
        model.addAttribute("module_list", moduleService.list());
    } catch (Exception e) {
        LOG.error(e.toString());
        e.printStackTrace();
    }
    return "home";
}