Example usage for org.springframework.beans BeanUtils copyProperties

List of usage examples for org.springframework.beans BeanUtils copyProperties

Introduction

In this page you can find the example usage for org.springframework.beans BeanUtils copyProperties.

Prototype

public static void copyProperties(Object source, Object target, String... ignoreProperties)
        throws BeansException 

Source Link

Document

Copy the property values of the given source bean into the given target bean, ignoring the given "ignoreProperties".

Usage

From source file:gov.nih.nci.cabig.caaers.domain.SAEReportPreExistingCondition.java

/**
 * Copy.//ww  w  .  j  a  v a 2 s. c  o  m
 *
 * @param object the object
 * @return the sAE report pre existing condition
 */
private static SAEReportPreExistingCondition copy(Object object) {
    SAEReportPreExistingCondition saeReportPreExistingCondition = new SAEReportPreExistingCondition();
    BeanUtils.copyProperties(object, saeReportPreExistingCondition,
            new String[] { "id", "gridId", "version", "report" });
    return saeReportPreExistingCondition;
}

From source file:gov.nih.nci.cabig.caaers.domain.SAEReportPriorTherapy.java

/**
 * Copy basic properties.//from ww w. ja v a  2  s .co  m
 *
 * @param object the object
 * @return the sAE report prior therapy
 */
private static SAEReportPriorTherapy copyBasicProperties(Object object) {
    SAEReportPriorTherapy saeReportPriorTherapy = new SAEReportPriorTherapy();
    BeanUtils.copyProperties(object, saeReportPriorTherapy, new String[] { "id", "gridId", "version",
            "priorTherapyAgents", "report", "priorTherapyAgentsInternal" });
    return saeReportPriorTherapy;
}

From source file:gov.nih.nci.cabig.caaers.domain.TreatmentInformation.java

/**
 * Copy.//  w  ww .java2s . co m
 *
 * @return the treatment information
 */
public TreatmentInformation copy() {
    TreatmentInformation treatmentInformation = new TreatmentInformation();
    BeanUtils.copyProperties(this, treatmentInformation,
            new String[] { "id", "gridId", "version", "courseAgentsInternal", "report", "courseAgents" });

    for (CourseAgent courseAgent : getCourseAgentsInternal()) {
        treatmentInformation.addCourseAgent(courseAgent.copy());
    }

    return treatmentInformation;
}

From source file:gr.abiss.calipso.tiers.service.impl.AbstractAclAwareServiceImpl.java

/**
 * {@inheritDoc}//from   ww  w. java  2  s.co  m
 */
@Override
@Transactional(readOnly = false)
@PreAuthorize(T.PRE_AUTHORIZE_UPDATE)
public T patch(@P("resource") T resource) {
    // make sure entity is set to support partial updates
    T persisted = this.findById(resource.getId());
    // copy non-null properties to persisted
    BeanUtils.copyProperties(resource, persisted, EntityUtil.getNullPropertyNames(resource));
    resource = persisted;
    // FW to normal update
    return this.update(persisted);
}

From source file:net.shopxx.controller.admin.ProductController.java

/**
 * /*  w  ww .  j  a  v  a 2s.  c om*/
 */
@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) {

    Merchant merchant = merchantService.getCurrent();
    product.setMerchant(merchant);

    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);
    goodsService.update(goods);
    addFlashMessage(redirectAttributes, SUCCESS_MESSAGE);
    return "redirect:list.jhtml";
}

From source file:org.apache.syncope.client.console.rest.ConnectorRestClient.java

public Pair<Boolean, String> check(final ConnInstanceTO connectorTO) {
    ConnInstanceTO toBeChecked = new ConnInstanceTO();
    BeanUtils.copyProperties(connectorTO, toBeChecked, new String[] { "configuration", "configurationMap" });
    toBeChecked.getConf().addAll(filterProperties(connectorTO.getConf()));

    boolean check = false;
    String errorMessage = null;/*from w w  w . j  a v a 2  s.  c  om*/
    try {
        getService(ConnectorService.class).check(toBeChecked);
        check = true;
    } catch (Exception e) {
        LOG.error("While checking {}", toBeChecked, e);
        errorMessage = e.getMessage();
    }

    return Pair.of(check, errorMessage);
}

From source file:org.davidmendoza.irsvped.dao.impl.EventDaoHibernate.java

@Override
public Event update(Event event) {
    log.debug("Updating event {}", event.getId());
    Event e = (Event) currentSession().get(Event.class, event.getId());
    log.debug("Found event {}", e);
    if (StringUtils.isBlank(event.getImageName())) {
        BeanUtils.copyProperties(event, e,
                new String[] { "id", "dateCreated", "contentType", "imageName", "imageSize", "imageData" });
    } else {//from w w w.j av  a 2s.c  om
        BeanUtils.copyProperties(event, e, new String[] { "id", "dateCreated" });
    }
    currentSession().update(e);
    return e;
}

From source file:org.kuali.kfs.module.tem.document.TravelAuthorizationDocument.java

/**
 *
 * @param doc//ww w .ja  va2  s .c om
 * @param documentID
 */
protected void toCopyTravelAuthorizationDocument(TravelAuthorizationDocument copyToDocument) {
    String documentID = copyToDocument.getDocumentNumber();

    //copy over all possible elements from this self to TravelAuthorizationDocument except document header
    BeanUtils.copyProperties(this, copyToDocument, new String[] { KFSConstants.DOCUMENT_HEADER_PROPERTY_NAME });

    FinancialSystemDocumentHeader documentHeader = new FinancialSystemDocumentHeader();
    documentHeader.setDocumentNumber(documentID);
    BeanUtils.copyProperties(copyToDocument.getDocumentHeader(), documentHeader,
            new String[] { KFSPropertyConstants.DOCUMENT_NUMBER, KFSPropertyConstants.OBJECT_ID,
                    KFSPropertyConstants.VERSION_NUMBER });
    documentHeader.setOrganizationDocumentNumber(this.getDocumentHeader().getOrganizationDocumentNumber());
    copyToDocument.setDocumentHeader(documentHeader);

    copyToDocument.setTransportationModes(
            getTravelDocumentService().copyTransportationModeDetails(getTransportationModes(), documentID));
    copyToDocument.setPerDiemExpenses(
            getTravelDocumentService().copyPerDiemExpenses(getPerDiemExpenses(), documentID));
    copyToDocument.setSpecialCircumstances(
            getTravelDocumentService().copySpecialCircumstances(getSpecialCircumstances(), documentID));
    copyToDocument.setTravelerDetailId(null);
    copyToDocument.setTraveler(getTravelerService().copyTravelerDetail(getTraveler(), documentID));
    copyToDocument
            .setGroupTravelers(getTravelDocumentService().copyGroupTravelers(getGroupTravelers(), documentID));
    copyToDocument.setImportedExpenses(new ArrayList<ImportedExpense>());

    copyToDocument.getNotes().clear();
    copyToDocument.getDocumentHeader().setDocumentDescription(getDocumentHeader().getDocumentDescription());
    copyToDocument.setTravelDocumentIdentifier(getTravelDocumentIdentifier());
    copyToDocument.setDocumentNumber(documentID);
    copyToDocument.setGeneralLedgerPendingEntries(new ArrayList<GeneralLedgerPendingEntry>());

    //reset to only include the encumbrance line
    List<TemSourceAccountingLine> newList = new ArrayList<TemSourceAccountingLine>();
    int sequence = 1;
    for (TemSourceAccountingLine line : copyToDocument.getEncumbranceSourceAccountingLines()) {
        line.setSequenceNumber(new Integer(sequence));
        sequence++;
        newList.add(line);
    }
    copyToDocument.setSourceAccountingLines(newList);
    copyToDocument.setNextSourceLineNumber(new Integer(sequence));

    copyToDocument.initiateAdvancePaymentAndLines();// should we be reinitiating all travel advance info here?  Funcs will tell us if that's wrong....
}

From source file:org.kuali.kfs.module.tem.service.impl.TravelerServiceImpl.java

/**
 * @see org.kuali.kfs.module.tem.service.TravelerService#copyTravelerDetail(org.kuali.kfs.module.tem.businessobject.TravelerDetail, java.lang.String)
 *//*  w ww. j  a v  a 2  s  .  co m*/
@Override
public TravelerDetail copyTravelerDetail(TravelerDetail travelerDetail, String documentNumber) {

    TravelerDetail newTravelerDetail = new TravelerDetail();

    //dateOfBirth actually doesn't belong to TravelDetail (only in Profile) so skipping it as it cause error in copyProperties
    BeanUtils.copyProperties(travelerDetail, newTravelerDetail,
            new String[] { TemProfileProperties.DATE_OF_BIRTH });
    newTravelerDetail.setId(null);
    newTravelerDetail.setVersionNumber(null);
    newTravelerDetail.setDocumentNumber(documentNumber);
    newTravelerDetail.setEmergencyContacts(
            copyTravelerDetailEmergencyContact(travelerDetail.getEmergencyContacts(), documentNumber));

    return newTravelerDetail;
}

From source file:org.kuali.kra.award.budget.AwardBudgetServiceImpl.java

protected void copyProposalBudgetLineItemsToAwardBudget(BudgetPeriod awardBudgetPeriod,
        BudgetPeriod proposalBudgetPeriod) {
    List<BudgetLineItem> awardBudgetLineItems = awardBudgetPeriod.getBudgetLineItems();
    List<BudgetLineItem> lineItems = proposalBudgetPeriod.getBudgetLineItems();
    for (BudgetLineItem budgetLineItem : lineItems) {
        String[] ignoreProperties = { BUDGET_ID, BUDGET_LINE_ITEM_ID, BUDGET_PERIOD_ID,
                SUBMIT_COST_SHARING_FLAG, BUDGET_LINE_ITEM_CALCULATED_AMOUNTS, BUDGET_PERSONNEL_DETAILS_LIST,
                BUDGET_RATE_AND_BASE_LIST, BUDGET_SUB_AWARD };
        AwardBudgetLineItemExt awardBudgetLineItem = new AwardBudgetLineItemExt();
        BeanUtils.copyProperties(budgetLineItem, awardBudgetLineItem, ignoreProperties);
        awardBudgetLineItem.setLineItemNumber(
                awardBudgetPeriod.getBudget().getNextValue(Constants.BUDGET_LINEITEM_NUMBER));
        awardBudgetLineItem.setBudgetId(awardBudgetPeriod.getBudgetId());
        awardBudgetLineItem.setStartDate(awardBudgetPeriod.getStartDate());
        awardBudgetLineItem.setEndDate(awardBudgetPeriod.getEndDate());
        List<BudgetPersonnelDetails> awardBudgetPersonnelLineItems = awardBudgetLineItem
                .getBudgetPersonnelDetailsList();
        List<BudgetPersonnelDetails> budgetPersonnelLineItems = budgetLineItem.getBudgetPersonnelDetailsList();
        for (BudgetPersonnelDetails budgetPersonnelDetails : budgetPersonnelLineItems) {
            budgetPersonnelDetails.setBudgetLineItemId(budgetLineItem.getBudgetLineItemId());
            budgetPersonnelDetails.setBudgetLineItem(budgetLineItem);
            AwardBudgetPersonnelDetailsExt awardBudgetPerDetails = new AwardBudgetPersonnelDetailsExt();
            BeanUtils.copyProperties(budgetPersonnelDetails, awardBudgetPerDetails,
                    BUDGET_PERSONNEL_LINE_ITEM_ID, BUDGET_LINE_ITEM_ID, BUDGET_ID, SUBMIT_COST_SHARING_FLAG,
                    BUDGET_PERSONNEL_CALCULATED_AMOUNTS, BUDGET_PERSONNEL_RATE_AND_BASE_LIST,
                    VALID_TO_APPLY_IN_RATE);
            awardBudgetPerDetails.setPersonNumber(
                    awardBudgetPeriod.getBudget().getNextValue(Constants.BUDGET_PERSON_LINE_NUMBER));
            BudgetPerson oldBudgetPerson = budgetPersonnelDetails.getBudgetPerson();
            BudgetPerson currentBudgetPerson = findMatchingPersonInBudget(awardBudgetPeriod.getBudget(),
                    oldBudgetPerson, budgetPersonnelDetails.getJobCode());
            if (currentBudgetPerson == null) {
                currentBudgetPerson = new BudgetPerson();
                BeanUtils.copyProperties(oldBudgetPerson, currentBudgetPerson, BUDGET_ID,
                        PERSON_SEQUENCE_NUMBER);
                currentBudgetPerson.setBudgetId(awardBudgetPeriod.getBudgetId());
                currentBudgetPerson.setPersonSequenceNumber(
                        awardBudgetPeriod.getBudget().getNextValue(Constants.PERSON_SEQUENCE_NUMBER));
                awardBudgetPeriod.getBudget().getBudgetPersons().add(currentBudgetPerson);
            }/*  w ww  .  ja v a  2  s  .  c o m*/
            awardBudgetPerDetails.setBudgetPerson(currentBudgetPerson);
            awardBudgetPerDetails.setPersonSequenceNumber(currentBudgetPerson.getPersonSequenceNumber());
            awardBudgetPerDetails.setBudget(awardBudgetPeriod.getBudget());
            awardBudgetPerDetails.setBudgetId(awardBudgetPeriod.getBudgetId());
            awardBudgetPerDetails.setCostElement(awardBudgetLineItem.getCostElement());
            awardBudgetPerDetails.setStartDate(awardBudgetLineItem.getStartDate());
            awardBudgetPerDetails.setEndDate(awardBudgetLineItem.getEndDate());
            awardBudgetPersonnelLineItems.add(awardBudgetPerDetails);
        }
        awardBudgetLineItems.add(awardBudgetLineItem);
        getAwardBudgetCalculationService().populateCalculatedAmount(awardBudgetPeriod.getBudget(),
                awardBudgetLineItem);
    }
}