List of usage examples for org.springframework.beans BeanUtils copyProperties
public static void copyProperties(Object source, Object target) throws BeansException
From source file:com.taikang.dic.ltci.service.impl.AgencyStaffImpl.java
/** ?? ???staff? */ @Override//from w w w . java 2 s. c o m public ResultDTO staffDetail(String serialNo) { //?? StaffHistoryDOExample example = new StaffHistoryDOExample(); com.taikang.dic.ltci.model.StaffHistoryDOExample.Criteria criteria = example.createCriteria(); criteria.andSerialNoEqualTo(serialNo); List<StaffHistoryDO> staffHistoryList = staffHistoryDAO.selectByExample(example); StaffHistoryDO staffHistoryDO = new StaffHistoryDO(); if (!staffHistoryList.isEmpty()) { staffHistoryDO = staffHistoryList.get(0); } else { throw new NotFoundByIdException("?"); } //?? StaffDOExample staffDOExample = new StaffDOExample(); com.taikang.dic.ltci.model.StaffDOExample.Criteria staffCriteria = staffDOExample.createCriteria(); staffCriteria.andStaffCodeEqualTo(staffHistoryDO.getStaffCode()); List<StaffDO> list = staffDAO.selectByExample(staffDOExample); StaffDO staffDO = new StaffDO(); if (!list.isEmpty()) { staffDO = list.get(0); } else { throw new NotFoundByIdException(""); } StaffComparedDO staffComparedBefore = new StaffComparedDO(); StaffComparedDO staffComparedAfter = new StaffComparedDO(); BeanUtils.copyProperties(staffHistoryDO, staffComparedAfter); BeanUtils.copyProperties(staffDO, staffComparedBefore); List<StaffDiffDO> staffDiffDOs = null; try { staffDiffDOs = convert(staffComparedBefore, staffComparedAfter); } catch (Exception e) { logger.error("?", e); } //?? for (StaffDiffDO staffDiffDO : staffDiffDOs) { if (staffDiffDO.getKey().equals("credentialValidityDate") || staffDiffDO.getKey().equals("degreeDate") || staffDiffDO.getKey().equals("diplomaDate") || staffDiffDO.getKey().equals("qualificationCertificationDate") || staffDiffDO.getKey().equals("practiceCertificationDate")) { staffDiffDO.setNewValue(DateFormatUtil.changeDateType((String) staffDiffDO.getNewValue())); staffDiffDO.setOldValue(DateFormatUtil.changeDateType((String) staffDiffDO.getOldValue())); } } ResultDTO resultDTO = new ResultDTO(); resultDTO.setDatas(staffDiffDOs); resultDTO.setMessage("?"); resultDTO.setStatus(StatusCodeEnum.OK.getValue()); return resultDTO; }
From source file:com.thinkbiganalytics.datalake.authorization.RangerAuthorizationService.java
@Override /**/*from w ww . j av a2 s. c om*/ * If no security policy exists it will be created. If a policy exists it will be updated */ public void updateSecurityGroupsForAllPolicies(String categoryName, String feedName, List<String> securityGroupNames, Map<String, Object> feedProperties) { String rangerHdfsPolicyName = getHdfsPolicyName(categoryName, feedName); RangerPolicy hdfsPolicy = searchHdfsPolicy(rangerHdfsPolicyName); String rangerHivePolicyName = getHivePolicyName(categoryName, feedName); RangerPolicy hivePolicy = searchHivePolicy(rangerHivePolicyName); if (securityGroupNames == null || securityGroupNames.isEmpty()) { // Only delete if the policies exists. It's possibile that someone adds a security group right after feed creation and before initial ingestion if (hivePolicy != null) { deleteHivePolicy(categoryName, feedName); } if (hdfsPolicy != null) { deleteHdfsPolicy(categoryName, feedName, null); } } else { if (hdfsPolicy == null) { // If a feed hasn't run yet the metadata won't exists if (!StringUtils.isEmpty((String) feedProperties.get(REGISTRATION_HDFS_FOLDERS))) { String hdfsFoldersWithCommas = ((String) feedProperties.get(REGISTRATION_HDFS_FOLDERS)) .replace("\n", ","); List<String> hdfsFolders = Stream.of(hdfsFoldersWithCommas).collect(Collectors.toList()); createReadOnlyHdfsPolicy(categoryName, feedName, securityGroupNames, hdfsFolders); } } else { List<String> hdfsPermissions = new ArrayList<>(); hdfsPermissions.add(HDFS_READ_ONLY_PERMISSION); RangerCreateOrUpdatePolicy updatePolicy = new RangerCreateOrUpdatePolicy(); BeanUtils.copyProperties(hdfsPolicy, updatePolicy); updatePolicy.setPermMapList(securityGroupNames, hdfsPermissions); rangerRestClient.updatePolicy(updatePolicy, hdfsPolicy.getId()); } if (hivePolicy == null) { // If a feed hasn't run yet the metadata won't exists if (!StringUtils.isEmpty((String) feedProperties.get(REGISTRATION_HIVE_TABLES))) { String hiveTablesWithCommas = ((String) feedProperties.get(REGISTRATION_HIVE_TABLES)) .replace("\n", ","); List<String> hiveTables = Stream.of(hiveTablesWithCommas).collect(Collectors.toList()); String hiveSchema = ((String) feedProperties.get(REGISTRATION_HIVE_SCHEMA)); createOrUpdateReadOnlyHivePolicy(categoryName, feedName, securityGroupNames, hiveSchema, hiveTables); } } else { List<String> hivePermissions = new ArrayList<>(); hivePermissions.add(HIVE_READ_ONLY_PERMISSION); RangerCreateOrUpdatePolicy updatePolicy = new RangerCreateOrUpdatePolicy(); BeanUtils.copyProperties(hivePolicy, updatePolicy); updatePolicy.setPermMapList(securityGroupNames, hivePermissions); rangerRestClient.updatePolicy(updatePolicy, hivePolicy.getId()); } } }
From source file:com.thinkbiganalytics.discovery.parsers.csv.CSVFileSchemaParser.java
/** * Converts the raw file schema to the target schema with correctly derived types * * @param target the target schema * @param sourceSchema the source//www . j a v a 2 s. c o m * @return the schema */ protected Schema convertToTarget(TableSchemaType target, Schema sourceSchema) { Schema targetSchema; switch (target) { case RAW: targetSchema = sourceSchema; break; case HIVE: DefaultHiveSchema hiveSchema = new DefaultHiveSchema(); BeanUtils.copyProperties(sourceSchema, hiveSchema); hiveSchema.setHiveFormat(deriveHiveRecordFormat()); ParserHelper.deriveDataTypes(target, hiveSchema.getFields()); targetSchema = hiveSchema; break; case RDBMS: DefaultTableSchema rdbmsSchema = new DefaultTableSchema(); BeanUtils.copyProperties(sourceSchema, rdbmsSchema); ParserHelper.deriveDataTypes(target, rdbmsSchema.getFields()); targetSchema = rdbmsSchema; break; default: throw new IllegalArgumentException(target.name() + " is not supported by this parser"); } return targetSchema; }
From source file:com.uwca.operation.modules.api.company.web.CompanyController.java
@RequestMapping(value = "getCompanyInfo") @ResponseBody//w ww . ja v a 2 s.co m public CompanyVo getCompanyInfo(@RequestParam("token") String token) { CompanyVo companyVo = new CompanyVo(); Result result = companyVo.new Result(); try { if (StringUtils.isEmpty(token)) { companyVo.setReturncode(1); companyVo.setMessage("??"); companyVo.setResult(result); return companyVo; } Company company = companyService.getCompanyInfo(TokenTool.getMobile(token)); String businesslicense = company.getBusinesslicense(); if (StringUtils.isNotEmpty(businesslicense)) { @SuppressWarnings("resource") InputStream in = new FileInputStream(Global.getUserfilesBaseDir() + businesslicense); if (null != in) { byte[] bytes = new byte[in.available()]; company.setBusinesslicense(Encodes.encodeBase64(bytes)); } } CompanyResult companyResult = new CompanyResult(); BeanUtils.copyProperties(company, companyResult); result.setCompanyResult(companyResult); companyVo.setResult(result); companyVo.setReturncode(0); companyVo.setMessage("ok"); return companyVo; } catch (Exception e) { companyVo.setReturncode(1); companyVo.setMessage("???"); companyVo.setResult(result); e.printStackTrace(); return companyVo; } }
From source file:com.uwca.operation.modules.api.company.web.CompanyController.java
@RequestMapping(value = "modifyCompanyInfo") @ResponseBody//from ww w.j a v a 2 s.c om public CompanyVo modifyCompanyInfo(@RequestParam("token") String token, @RequestParam("companyname") String companyname, @RequestParam("legalperson") String legalperson, @RequestParam("organizationcode") String organizationcode, @RequestParam("fax") String fax, @RequestParam("mail") String mail, @RequestParam("website") String website, @RequestParam("address") String address, @RequestParam("businesslicense") MultipartFile businesslicense, @RequestParam("sign") String sign) { CompanyVo companyVo = new CompanyVo(); Result result = companyVo.new Result(); try { if (StringUtils.isEmpty(token) || StringUtils.isEmpty(sign)) { companyVo.setReturncode(1); companyVo.setMessage("??"); companyVo.setResult(result); return companyVo; } String newFileName = ""; if (businesslicense != null && !businesslicense.isEmpty()) { String fileName = businesslicense.getOriginalFilename(); String extensionName = fileName.substring(fileName.lastIndexOf(".") + 1); newFileName = String.valueOf(System.currentTimeMillis()) + "." + extensionName; try { saveFile(newFileName, businesslicense); } catch (Exception e) { companyVo.setReturncode(1); companyVo.setMessage("??"); companyVo.setResult(result); return companyVo; } } Map<String, Object> map = new HashMap<String, Object>(); String companyid = TokenTool.getCompanyid(token); map.put("id", companyid); map.put("userid", TokenTool.getUserid(token)); map.put("companyname", companyname); map.put("legalperson", legalperson); map.put("organizationcode", organizationcode); map.put("businesslicense", newFileName); map.put("fax", fax); map.put("mail", mail); map.put("address", address); map.put("website", website); map.put("state", 1); companyService.updateCompany(map); Company company = companyService.getCompanyInfoById(companyid); CompanyResult companyResult = new CompanyResult(); if (null != company) { BeanUtils.copyProperties(company, companyResult); } result.setCompanyResult(companyResult); companyVo.setReturncode(0); companyVo.setMessage("ok"); return companyVo; } catch (Exception e) { companyVo.setReturncode(1); companyVo.setMessage("??"); companyVo.setResult(result); e.printStackTrace(); return companyVo; } }
From source file:com.vwf5.base.utils.DataUtil.java
public static <T> T mapToNewClass(Object source, Class<T> destClass) { try {/*from w ww . jav a 2s . c om*/ if (source == null) { return null; } T dto; dto = destClass.getConstructor().newInstance(); BeanUtils.copyProperties(source, dto); return dto; } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { return null; } }
From source file:com.zhenhappy.ems.action.user.VisaAction.java
@RequestMapping(value = "/visa/saveVisa", method = RequestMethod.POST) public ModelAndView saveVisa(@ModelAttribute(Principle.PRINCIPLE_SESSION_ATTRIBUTE) Principle principle, @ModelAttribute SaveVisaInfoRequest visa, @RequestParam(value = "license", required = false) MultipartFile license, @RequestParam(value = "passportPageFile", required = false) MultipartFile passportPage) { ModelAndView modelAndView = new ModelAndView("/user/callback"); try {/*from w w w. j av a 2s. co m*/ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); if (StringUtils.isNotEmpty(visa.getBirthDay())) { visa.setBirth(sdf.parse(visa.getBirthDay())); } if (StringUtils.isNotEmpty(visa.getFromDate())) { visa.setFrom(sdf.parse(visa.getFromDate())); } if (StringUtils.isNotEmpty(visa.getToDate())) { visa.setTo(sdf.parse(visa.getToDate())); } if (StringUtils.isNotEmpty(visa.getExpireDate())) { visa.setExpDate(sdf.parse(visa.getExpireDate())); } if (license != null) { String fileName = systemConfig.getVal(Constants.appendix_directory) + "/" + new Date().getTime() + "." + FilenameUtils.getExtension(license.getOriginalFilename()); if (license != null && license.getSize() != 0) { FileUtils.copyInputStreamToFile(license.getInputStream(), new File(fileName)); visa.setBusinessLicense(fileName); } } if (passportPage != null) { String fileName = systemConfig.getVal(Constants.appendix_directory) + "/" + new Date().getTime() + "." + FilenameUtils.getExtension(passportPage.getOriginalFilename()); if (passportPage != null && passportPage.getSize() != 0) { FileUtils.copyInputStreamToFile(passportPage.getInputStream(), new File(fileName)); visa.setPassportPage(fileName); } } visa.setEid(principle.getExhibitor().getEid()); TVisa temp = new TVisa(); BeanUtils.copyProperties(visa, temp); visaService.saveOrUpdate(temp); modelAndView.addObject("method", "addSuccess"); } catch (Exception e) { log.error("add visa error", e); modelAndView.addObject("method", "addFailure"); } return modelAndView; }
From source file:com.zigbee.framework.common.util.BeanCopyUtil.java
/** * Bean Copy Method//w w w . ja v a 2 s .co m * @param srcBean source bean instance * @param destBean destination bean instance * @throws AppException Application Exception */ public static void beanCopy(Object srcBean, Object destBean) throws AppException { try { BeanUtils.copyProperties(srcBean, destBean); } catch (BeansException e) { e.printStackTrace(); String errMsg = "BEAN COPY Exception!" + e.getMessage() + e.getStackTrace(); throw new AppException(CommonErrorConstants.BEAN_COPY_EXCEPTION, errMsg, e.getCause()); } }
From source file:de.hybris.platform.acceleratorservices.web.payment.controllers.HostedOrderPageMockController.java
@RequestMapping(method = { RequestMethod.GET, RequestMethod.POST }) public String getHopPaymentForm(final HttpServletRequest request, final Model model) { //Dummy Credit Card Information final PaymentDetailsForm paymentDetailsForm = new PaymentDetailsForm(); // Copy over the default values BeanUtils.copyProperties(getDefaultPaymentDetailsForm(), paymentDetailsForm); // Override DefaultPaymentDetailsForm values with existing customer payment info data if available. if (StringUtils.isNotBlank(getParameter("card_accountNumber", request))) { paymentDetailsForm.setCardTypeCode(getParameter("card_cardType", request)); //Force entry of card number as this is dependent on the card type. paymentDetailsForm.setCardNumber(""); final String verificationNumber = getParameter("card_cvNumber", request); if (StringUtils.isNotBlank(verificationNumber)) { paymentDetailsForm.setVerificationNumber(verificationNumber); }/*from w w w. j a v a 2 s .c o m*/ final String issueNumber = getParameter("card_issueNumber", request); if (StringUtils.isNotBlank(issueNumber)) { paymentDetailsForm.setIssueNumber(issueNumber); } final String startMonth = getParameter("card_startMonth", request); if (StringUtils.isNotBlank(startMonth)) { paymentDetailsForm.setStartMonth(startMonth); } final String startYear = getParameter("card_startYear", request); if (StringUtils.isNotBlank(startYear)) { paymentDetailsForm.setStartYear(startYear); } paymentDetailsForm.setExpiryMonth(getParameter("card_expirationMonth", request)); paymentDetailsForm.setExpiryYear(getParameter("card_expirationYear", request)); } // Store the original parameters sent by the caller paymentDetailsForm.setOriginalParameters(serializeRequestParameters(request)); //Actual Customer Billing Address final AddressForm addressForm = new AddressForm(); if (request != null) { addressForm.setFirstName(getParameter("billTo_firstName", request)); addressForm.setLastName(getParameter("billTo_lastName", request)); addressForm.setLine1(getParameter("billTo_street1", request)); addressForm.setLine2(getParameter("billTo_street2", request)); addressForm.setTownCity(getParameter("billTo_city", request)); addressForm.setState(getParameter("billTo_state", request)); addressForm.setPostcode(getParameter("billTo_postalCode", request)); addressForm.setCountryIso(getParameter("billTo_country", request)); addressForm.setPhoneNumber(getParameter("billTo_phoneNumber", request)); addressForm.setEmailAddress(getParameter("billTo_email", request)); } paymentDetailsForm.setBillingAddress(addressForm); model.addAttribute("paymentDetailsForm", paymentDetailsForm); return HOP_PAYMENT_FORM_PAGE; }
From source file:de.hybris.platform.addressaddon.controllers.pages.checkout.steps.ChineseDeliveryAddressCheckoutStepController.java
@Override @RequestMapping(value = "/select", method = RequestMethod.POST) @RequireHardLogIn//from w w w . jav a 2 s . c o m public String doSelectSuggestedAddress(final AddressForm addressForm, final RedirectAttributes redirectModel) { if (!addressForm.getCountryIso().equals(CHINA_ISOCODE)) { return super.doSelectSuggestedAddress(addressForm, redirectModel); } final HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()) .getRequest(); final ChineseAddressForm chineseAddressForm = new ChineseAddressForm(); BeanUtils.copyProperties(addressForm, chineseAddressForm); if (addressForm.getCountryIso().equals(CHINA_ISOCODE)) { chineseAddressForm.setCityIso(request.getParameter("cityIso")); chineseAddressForm.setDistrictIso(request.getParameter("districtIso")); chineseAddressForm.setFullname(request.getParameter("fullname")); chineseAddressForm.setCellphone(request.getParameter("cellphone")); } final Set<String> resolveCountryRegions = org.springframework.util.StringUtils .commaDelimitedListToSet(Config.getParameter("resolve.country.regions")); final AddressData selectedAddress = chineseAddressHandler.prepareAddressData(chineseAddressForm); final CountryData countryData = getI18NFacade().getCountryForIsocode(addressForm.getCountryIso()); selectedAddress.setCountry(countryData); selectedAddress.setPhone(addressForm.getPhone()); if (resolveCountryRegions.contains(countryData.getIsocode()) && addressForm.getRegionIso() != null && !StringUtils.isEmpty(addressForm.getRegionIso())) { final RegionData regionData = getI18NFacade().getRegion(addressForm.getCountryIso(), addressForm.getRegionIso()); selectedAddress.setRegion(regionData); } if (addressForm.getSaveInAddressBook() != null) { selectedAddress.setVisibleInAddressBook(addressForm.getSaveInAddressBook().booleanValue()); } if (Boolean.TRUE.equals(addressForm.getEditAddress())) { getUserFacade().editAddress(selectedAddress); } else { getUserFacade().addAddress(selectedAddress); } final AddressData previousSelectedAddress = getCheckoutFacade().getCheckoutCart().getDeliveryAddress(); // Set the new address as the selected checkout delivery address getCheckoutFacade().setDeliveryAddress(selectedAddress); if (previousSelectedAddress != null && !previousSelectedAddress.isVisibleInAddressBook()) { // temporary address should be removed getUserFacade().removeAddress(previousSelectedAddress); } GlobalMessages.addFlashMessage(redirectModel, GlobalMessages.CONF_MESSAGES_HOLDER, "checkout.multi.address.added"); return getCheckoutStep().nextStep(); }