List of usage examples for org.springframework.beans BeanUtils copyProperties
public static void copyProperties(Object source, Object target, String... ignoreProperties) throws BeansException
From source file:com.smi.travel.datalayer.dao.impl.AirticketPnrImpl.java
@Override public int UpdateAirticketPnr(AirticketPnr airPnr) { int result = 0; try {/*from w w w. ja va 2 s. c o m*/ Session session = this.sessionFactory.openSession(); transaction = session.beginTransaction(); AirticketPnr dbAirPnr = (AirticketPnr) session.get(AirticketPnr.class, airPnr.getId()); Set<AirticketAirline> airlines = airPnr.getAirticketAirlines(); for (AirticketAirline airline : airlines) { if (StringUtils.isEmpty(airline.getId())) { dbAirPnr.getAirticketAirlines().add(airline); } else { Set<AirticketFlight> flights = airline.getAirticketFlights(); for (AirticketFlight flight : flights) { if (StringUtils.isEmpty(flight.getId())) { // new flight AirticketAirline dbAirline = (AirticketAirline) session.get(AirticketAirline.class, airline.getId()); dbAirline.getAirticketFlights().add(flight); session.saveOrUpdate(dbAirline); } else { // update flight AirticketFlight dbFlight = (AirticketFlight) session.get(AirticketFlight.class, flight.getId()); //might need to update airline. if (!flight.getAirticketAirline().getId() .equalsIgnoreCase(dbFlight.getAirticketAirline().getId())) { // AirticketAirline oldDbAirline = (AirticketAirline) session.get(AirticketAirline.class, dbFlight.getAirticketAirline().getId()); // oldDbAirline.getAirticketFlights().remove(dbFlight); // AirticketAirline newDbAirline = (AirticketAirline) session.get(AirticketAirline.class, flight.getAirticketAirline().getId()); // newDbAirline.getAirticketFlights().add(dbFlight); // dbFlight.setAirticketAirline(newDbAirline); // session.saveOrUpdate(oldDbAirline); // session.saveOrUpdate(newDbAirline); } BeanUtils.copyProperties(flight, dbFlight, new String[] { "id" }); session.saveOrUpdate(dbFlight); } } Set<AirticketPassenger> passengers = airline.getAirticketPassengers(); for (AirticketPassenger passenger : passengers) { if (StringUtils.isEmpty(passenger.getId())) { // new passenger AirticketAirline dbAirline = (AirticketAirline) session.get(AirticketAirline.class, airline.getId()); dbAirline.getAirticketPassengers().add(passenger); session.saveOrUpdate(dbAirline); } else { // upddbAirlineate passenger AirticketPassenger dbPassenger = (AirticketPassenger) session .get(AirticketPassenger.class, passenger.getId()); BeanUtils.copyProperties(passenger, dbPassenger, new String[] { "id" }); session.saveOrUpdate(dbPassenger); } } if (airline.getAirticketFlights().isEmpty() && airline.getAirticketPassengers().isEmpty()) { AirticketAirline dbAirline = (AirticketAirline) session.get(AirticketAirline.class, airline.getId()); // dbAirline.getAirticketFlights().clear(); // dbAirline.getAirticketPassengers().clear(); dbAirPnr.getAirticketAirlines().remove(dbAirline); // session.delete(dbAirline); } } } session.update(dbAirPnr); transaction.commit(); session.close(); this.sessionFactory.close(); result = 1; } catch (Exception ex) { ex.printStackTrace(); result = 0; } return result; }
From source file:com.zswxsqxt.core.action.SubscribAction.java
/** * ?// w w w. j a v a 2 s . c o m * @return * @throws Exception */ public String save() throws Exception { String msg = null; LoginInfo li = getCurrUser(); if (StrUtil.isNullOrBlank(entity.getId())) { entity.setId(null); entity.setTs(new Date()); entity.setChangeTime(new Date()); User user = new User(); user.setId(li.getUserID()); entity.setChangeUser(user); entity.setCreationUser(user); msg = "?"; } else { Subscrib persistence = customerInfoService.get(entity.getId()); BeanUtils.copyProperties(entity, persistence, new String[] { "id" }); entity = persistence; msg = ""; } try { customerInfoService.saveOrUpdate(entity); Flash.current().success(msg); } catch (Exception e) { e.printStackTrace(); Flash.current().error("??"); logger.error(e); } return "listAction"; }
From source file:com.zswxsqxt.core.action.SubscribAuditAction.java
/** * ?/*from w w w.j a v a 2s .c o m*/ * @return * @throws Exception */ public String save() throws Exception { String msg = null; LoginInfo li = getCurrUser(); if (StrUtil.isNullOrBlank(entity.getId())) { entity.setId(null); entity.setTs(new Date()); entity.setChangeTime(new Date()); User user = new User(); user.setId(li.getUserID()); entity.setChangeUser(user); entity.setCreationUser(user); msg = "?"; } else { Subscrib persistence = customerInfoService.get(entity.getId()); BeanUtils.copyProperties(entity, persistence, new String[] { "id" }); entity = persistence; msg = ""; } try { customerInfoService.saveOrUpdate(entity); Flash.current().success(msg); } catch (Exception e) { Flash.current().error("??"); logger.error(e); } return "listAction"; }
From source file:de.hybris.platform.secureportaladdon.facades.impl.DefaultB2BRegistrationFacade.java
/** * Converts a {@link B2BRegistrationData} into a {@B2BRegistrationModel} * /*from w ww . j a v a2 s . co m*/ * @param data * The registration data * @return An unsaved instance of type {@B2BRegistrationModel} */ protected B2BRegistrationModel toRegistrationModel(final B2BRegistrationData data) { final B2BRegistrationModel model = modelService.create(B2BRegistrationModel.class); // Use reflection to copy most properties and ignore these since we want to manage them manually BeanUtils.copyProperties(data, model, new String[] { "titleCode", "companyAddressCountryIso", "companyAddressRegion", "baseStore", "cmsSite", "currency", "language" }); // Title is mandatory final TitleModel title = userService.getTitleForCode(data.getTitleCode()); model.setTitle(title); // Country is mandatory final CountryModel country = commonI18NService.getCountry(data.getCompanyAddressCountryIso()); model.setCompanyAddressCountry(country); // Region is optional if (StringUtils.isNotBlank(data.getCompanyAddressRegion())) { final RegionModel region = commonI18NService.getRegion(country, data.getCompanyAddressRegion()); model.setCompanyAddressRegion(region); } // Get these from current context model.setBaseStore(baseStoreService.getCurrentBaseStore()); model.setCmsSite(cmsSiteService.getCurrentSite()); model.setCurrency(commonI18NService.getCurrentCurrency()); model.setLanguage(commonI18NService.getCurrentLanguage()); return model; }
From source file:dstrelec.nats.listener.DefaultNatsListenerContainer.java
/** * Construct an instance with the supplied configuration properties. * @param connectionFactory the connection factory. * @param containerProperties the container properties. *//* ww w .j a v a 2s. c o m*/ public DefaultNatsListenerContainer(NatsConnectionFactory connectionFactory, ContainerProperties containerProperties) { Assert.notNull(containerProperties, "'containerProperties' cannot be null"); Assert.notNull(connectionFactory, "A NatsConnectionFactory must be provided"); if (containerProperties.getSubjects() != null) { this.containerProperties = new ContainerProperties(containerProperties.getSubjects()); } else { this.containerProperties = new ContainerProperties(); } BeanUtils.copyProperties(containerProperties, this.containerProperties, "subjects"); this.connectionFactory = connectionFactory; }
From source file:gov.gtas.services.CaseDispositionServiceImpl.java
/** * Wrapper method over BeanUtils.copyProperties * * @param src//from w w w . j av a2 s. co m * @param target */ public static void copyIgnoringNullValues(Object src, Object target) { try { BeanUtils.copyProperties(src, target, getNullPropertyNames(src)); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:gov.guilin.controller.admin.ProductController.java
/** * // w ww. j a va 2 s. co m */ @RequestMapping(value = "/update", method = RequestMethod.POST) public String update(Product product, Long productCategoryId, Long brandId, Long[] tagIds, Long[] specificationIds, Long[] specificationProductIds, HttpServletRequest request, RedirectAttributes redirectAttributes, Long supplierId) { for (Iterator<ProductImage> iterator = product.getProductImages().iterator(); iterator.hasNext();) { ProductImage productImage = iterator.next(); if (productImage == null || productImage.isEmpty()) { iterator.remove(); continue; } if (productImage.getFile() != null && !productImage.getFile().isEmpty()) { if (!fileService.isValid(FileType.image, productImage.getFile())) { addFlashMessage(redirectAttributes, Message.error("admin.upload.invalid")); return "redirect:edit.jhtml?id=" + product.getId(); } } } product.setProductCategory(productCategoryService.find(productCategoryId)); product.setBrand(brandService.find(brandId)); product.setTags(new HashSet<Tag>(tagService.findList(tagIds))); if (!isValid(product)) { return ERROR_VIEW; } Product pProduct = productService.find(product.getId()); if (pProduct == null) { return ERROR_VIEW; } if (StringUtils.isNotEmpty(product.getSn()) && !productService.snUnique(pProduct.getSn(), product.getSn())) { return ERROR_VIEW; } if (product.getMarketPrice() == null) { BigDecimal defaultMarketPrice = calculateDefaultMarketPrice(product.getPrice()); product.setMarketPrice(defaultMarketPrice); } if (product.getPoint() == null) { long point = calculateDefaultPoint(product.getPrice()); product.setPoint(point); } for (MemberRank memberRank : memberRankService.findAll()) { String price = request.getParameter("memberPrice_" + memberRank.getId()); if (StringUtils.isNotEmpty(price) && new BigDecimal(price).compareTo(new BigDecimal(0)) >= 0) { product.getMemberPrice().put(memberRank, new BigDecimal(price)); } else { product.getMemberPrice().remove(memberRank); } } for (ProductImage productImage : product.getProductImages()) { productImageService.build(productImage); } Collections.sort(product.getProductImages()); if (product.getImage() == null && product.getThumbnail() != null) { product.setImage(product.getThumbnail()); } for (ParameterGroup parameterGroup : product.getProductCategory().getParameterGroups()) { for (Parameter parameter : parameterGroup.getParameters()) { String parameterValue = request.getParameter("parameter_" + parameter.getId()); if (StringUtils.isNotEmpty(parameterValue)) { product.getParameterValue().put(parameter, parameterValue); } else { product.getParameterValue().remove(parameter); } } } for (Attribute attribute : product.getProductCategory().getAttributes()) { String attributeValue = request.getParameter("attribute_" + attribute.getId()); if (StringUtils.isNotEmpty(attributeValue)) { product.setAttributeValue(attribute, attributeValue); } else { product.setAttributeValue(attribute, null); } } Goods goods = pProduct.getGoods(); List<Product> products = new ArrayList<Product>(); if (specificationIds != null && specificationIds.length > 0) { for (int i = 0; i < specificationIds.length; i++) { Specification specification = specificationService.find(specificationIds[i]); String[] specificationValueIds = request .getParameterValues("specification_" + specification.getId()); if (specificationValueIds != null && specificationValueIds.length > 0) { for (int j = 0; j < specificationValueIds.length; j++) { if (i == 0) { if (j == 0) { BeanUtils.copyProperties(product, pProduct, new String[] { "id", "createDate", "modifyDate", "fullName", "allocatedStock", "score", "totalScore", "scoreCount", "hits", "weekHits", "monthHits", "sales", "weekSales", "monthSales", "weekHitsDate", "monthHitsDate", "weekSalesDate", "monthSalesDate", "goods", "reviews", "consultations", "favoriteMembers", "specifications", "specificationValues", "promotions", "cartItems", "orderItems", "giftItems", "productNotifies" }); pProduct.setSpecifications(new HashSet<Specification>()); pProduct.setSpecificationValues(new HashSet<SpecificationValue>()); products.add(pProduct); } else { if (specificationProductIds != null && j < specificationProductIds.length) { Product specificationProduct = productService.find(specificationProductIds[j]); if (specificationProduct == null || (specificationProduct.getGoods() != null && !specificationProduct.getGoods().equals(goods))) { return ERROR_VIEW; } specificationProduct.setSpecifications(new HashSet<Specification>()); specificationProduct.setSpecificationValues(new HashSet<SpecificationValue>()); products.add(specificationProduct); } else { Product specificationProduct = new Product(); BeanUtils.copyProperties(product, specificationProduct); specificationProduct.setId(null); specificationProduct.setCreateDate(null); specificationProduct.setModifyDate(null); specificationProduct.setSn(null); specificationProduct.setFullName(null); specificationProduct.setAllocatedStock(0); specificationProduct.setIsList(false); specificationProduct.setScore(0F); specificationProduct.setTotalScore(0L); specificationProduct.setScoreCount(0L); specificationProduct.setHits(0L); specificationProduct.setWeekHits(0L); specificationProduct.setMonthHits(0L); specificationProduct.setSales(0L); specificationProduct.setWeekSales(0L); specificationProduct.setMonthSales(0L); specificationProduct.setWeekHitsDate(new Date()); specificationProduct.setMonthHitsDate(new Date()); specificationProduct.setWeekSalesDate(new Date()); specificationProduct.setMonthSalesDate(new Date()); specificationProduct.setGoods(goods); specificationProduct.setReviews(null); specificationProduct.setConsultations(null); specificationProduct.setFavoriteMembers(null); specificationProduct.setSpecifications(new HashSet<Specification>()); specificationProduct.setSpecificationValues(new HashSet<SpecificationValue>()); specificationProduct.setPromotions(null); specificationProduct.setCartItems(null); specificationProduct.setOrderItems(null); specificationProduct.setGiftItems(null); specificationProduct.setProductNotifies(null); products.add(specificationProduct); } } } Product specificationProduct = products.get(j); SpecificationValue specificationValue = specificationValueService .find(Long.valueOf(specificationValueIds[j])); specificationProduct.getSpecifications().add(specification); specificationProduct.getSpecificationValues().add(specificationValue); } } } } else { product.setSpecifications(null); product.setSpecificationValues(null); BeanUtils.copyProperties(product, pProduct, new String[] { "id", "createDate", "modifyDate", "fullName", "allocatedStock", "score", "totalScore", "scoreCount", "hits", "weekHits", "monthHits", "sales", "weekSales", "monthSales", "weekHitsDate", "monthHitsDate", "weekSalesDate", "monthSalesDate", "goods", "reviews", "consultations", "favoriteMembers", "promotions", "cartItems", "orderItems", "giftItems", "productNotifies" }); products.add(pProduct); } goods.getProducts().clear(); goods.getProducts().addAll(products); //? if (supplierId != null) { Supplier supplier = supplierService.find(supplierId); if (supplier != null) { for (Product p : goods.getProducts()) { p.setSupplier(supplier); } } // Supplier pp = p.getSupplier(); // System.out.println(pp.getSupplierCode()); } goodsService.update(goods); addFlashMessage(redirectAttributes, SUCCESS_MESSAGE); return "redirect:list.jhtml"; }
From source file:gov.nih.nci.cabig.caaers.domain.DiseaseHistory.java
/** * Copy basic properties./*from w w w.j ava 2s. c o m*/ * * @param object the object * @return the disease history */ private static DiseaseHistory copyBasicProperties(Object object) { DiseaseHistory saeReportDiseaseHistory = new DiseaseHistory(); BeanUtils.copyProperties(object, saeReportDiseaseHistory, new String[] { "id", "gridId", "version", "report", "metastaticDiseaseSitesInternal", "metastaticDiseaseSites", "meddraStudyDisease", "ctepStudyDisease", "otherCondition" }); return saeReportDiseaseHistory; }
From source file:gov.nih.nci.cabig.caaers.domain.Lab.java
/** * Copy./*from w w w. j ava2s . c o m*/ * * @return the lab */ public Lab copy() { Lab lab = new Lab(); BeanUtils.copyProperties(this, lab, new String[] { "id", "gridId", "version", "report" }); return lab; }
From source file:gov.nih.nci.cabig.caaers.domain.MetastaticDiseaseSite.java
/** * Copy basic properties./*from ww w . ja va 2 s . com*/ * * @param object the object * @return the metastatic disease site */ private static MetastaticDiseaseSite copyBasicProperties(Object object) { MetastaticDiseaseSite metastaticDiseaseSite = new MetastaticDiseaseSite(); BeanUtils.copyProperties(object, metastaticDiseaseSite, new String[] { "id", "gridId", "version" }); return metastaticDiseaseSite; }