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) throws BeansException 

Source Link

Document

Copy the property values of the given source bean into the target bean.

Usage

From source file:com.frank.search.solr.server.support.SolrClientUtils.java

private static HttpClient cloneHttpClient(HttpClient sourceClient) throws InstantiationException,
        IllegalAccessException, IllegalArgumentException, InvocationTargetException {

    if (sourceClient == null) {
        return null;
    }/*from   w  ww  .j  av a 2  s. c  o  m*/

    Class<?> clientType = ClassUtils.getUserClass(sourceClient);
    Constructor<?> constructor = ClassUtils.getConstructorIfAvailable(clientType, HttpParams.class);
    if (constructor != null) {

        HttpClient targetClient = (HttpClient) constructor.newInstance(sourceClient.getParams());
        BeanUtils.copyProperties(sourceClient, targetClient);
        return targetClient;
    } else {
        return new DefaultHttpClient(sourceClient.getParams());
    }

}

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

/**
 * ?//w ww .j  av a2s .co  m
 */
@RequestMapping(value = "/save", method = RequestMethod.POST)
public String save(Product product, Long productCategoryId, Long brandId, Long[] tagIds,
        Long[] specificationIds, HttpServletRequest request, RedirectAttributes redirectAttributes) {
    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:add.jhtml";
            }
        }
    }
    product.setProductCategory(productCategoryService.find(productCategoryId));
    product.setBrand(brandService.find(brandId));
    product.setTags(new HashSet<Tag>(tagService.findList(tagIds)));
    if (!isValid(product)) {
        return ERROR_VIEW;
    }
    if (StringUtils.isNotEmpty(product.getSn()) && productService.snExists(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);
    }
    product.setFullName(null);
    product.setAllocatedStock(0);
    product.setScore(0F);
    product.setTotalScore(0L);
    product.setScoreCount(0L);
    product.setHits(0L);
    product.setWeekHits(0L);
    product.setMonthHits(0L);
    product.setSales(0L);
    product.setWeekSales(0L);
    product.setMonthSales(0L);
    product.setWeekHitsDate(new Date());
    product.setMonthHitsDate(new Date());
    product.setWeekSalesDate(new Date());
    product.setMonthSalesDate(new Date());
    product.setReviews(null);
    product.setConsultations(null);
    product.setFavoriteMembers(null);
    product.setPromotions(null);
    product.setCartItems(null);
    product.setOrderItems(null);
    product.setGiftItems(null);
    product.setProductNotifies(null);

    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 = new Goods();
    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) {
                            product.setGoods(goods);
                            product.setSpecifications(new HashSet<Specification>());
                            product.setSpecificationValues(new HashSet<SpecificationValue>());
                            products.add(product);
                        } 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.setGoods(goods);
        product.setSpecifications(null);
        product.setSpecificationValues(null);
        products.add(product);
    }
    goods.getProducts().clear();
    goods.getProducts().addAll(products);
    goodsService.save(goods);
    addFlashMessage(redirectAttributes, SUCCESS_MESSAGE);
    return "redirect:list.jhtml";
}

From source file:com.iselect.kernal.pageflow.service.PageFlowServiceImpl.java

@Override
public void insertPageFlowRequest(PageRequestDto requestDto) throws ISelectException {
    PageRequestModel requestModel = modelFactory.createPageRequest();
    BeanUtils.copyProperties(requestDto, requestModel);
    List<PageResponseDto> responseDtos = requestDto.getPageResponses();
    for (PageResponseDto responseDto : responseDtos) {
        PageResponseModel responseModel = modelFactory.createPageResponse();
        BeanUtils.copyProperties(responseDto, responseModel);
        requestModel.addPageResponse(responseModel);
    }// w w w  .  j av  a2 s  . com
    insertPageFlowRequest(requestModel);
}

From source file:com.allinfinance.bo.impl.mchnt.TblMchntServiceImpl1.java

public String accept(String mchntId) throws IllegalAccessException, InvocationTargetException {

    TblMchtBaseInfTmp tmp = tblMchtBaseInfTmpDAO.get(mchntId);
    TblMchtSettleInfTmp tmpSettle = tblMchtSettleInfTmpDAO.get(mchntId);

    //??//from  ww w  .ja  v a  2 s .c  om
    String status = tmp.getMchtStatus();
    //cre
    String crtDateTmp = tmp.getRecCrtTs();

    if (null == tmp || null == tmpSettle) {
        return "??";
    }

    // ??
    TblMchtBaseInf inf = tblMchtBaseInfDAO.get(tmp.getMchtNo());
    TblMchtSettleInf infSettle = tblMchtSettleInfDAO.get(tmpSettle.getMchtNo());

    //?cre
    String crtDate = "0";
    if (null != inf) {
        crtDate = inf.getRecCrtTs();
    }
    if (null == inf) {
        inf = new TblMchtBaseInf();
    }
    if (null == infSettle) {
        infSettle = new TblMchtSettleInf();
    }

    // 
    tmp.setRecUpdTs(CommonFunction.getCurrentDateTime());
    Operator opr = (Operator) ServletActionContext.getRequest().getSession()
            .getAttribute(Constants.OPERATOR_INFO);
    tmp.setUpdOprId(opr.getOprId());
    tmpSettle.setRecUpdTs(CommonFunction.getCurrentDateTime());

    //??
    //      if (TblMchntInfoConstants.MCHNT_ST_MODI_UNCK.equals(tmp.getMchtStatus()) 
    //            && (inf.getMchtCnAbbr() == null ||!inf.getMchtCnAbbr().equals(tmp.getMchtCnAbbr())
    //            ||inf.getEngName() == null ||!inf.getEngName().equals(tmp.getEngName()))) {
    ////         TODO ??
    //       StringBuffer sql0 = new StringBuffer("update tbl_term_inf set term_para = substr(term_para,1,50)||'")
    //       .append(CommonFunction.fillStringByDB(tmp.getMchtCnAbbr(), ' ', 40, true)).append("'||substr(term_para,91,20)||'")
    //       .append(CommonFunction.fillStringByDB(tmp.getEngName()==null?"":tmp.getEngName(), ' ', 40, true)).append("'||substr(term_para,151) where MCHT_CD = '")
    //       .append(mchntId).append("'");
    //      
    //       StringBuffer sql1 = new StringBuffer("update tbl_term_inf_tmp set term_para = substr(term_para,1,53)||'")
    //       .append(CommonFunction.fillStringByDB(tmp.getMchtCnAbbr(), ' ', 40, true)).append("'||substr(term_para,94,22)||'")
    //       .append(CommonFunction.fillStringByDB(tmp.getEngName()==null?"":tmp.getEngName(), ' ', 40, true)).append("'||substr(term_para,156) where MCHT_CD = '")
    //       .append(mchntId).append("'");
    //         
    //       //??
    //       CommonFunction.getCommQueryDAO().excute(sql0.toString());
    //       CommonFunction.getCommQueryDAO().excute(sql1.toString());
    //      }

    if (tmp.getMchtStatus().equals(TblMchntInfoConstants.MCHNT_ST_DEL_UNCK)) {//?
        String update0 = "update tbl_term_inf set TERM_STA = '7' where MCHT_CD = '" + tmp.getMchtNo() + "'";
        String update1 = "update tbl_term_inf_tmp set TERM_STA = '7' where MCHT_CD = '" + tmp.getMchtNo() + "'";
        CommonFunction.getCommQueryDAO().excute(update0);
        CommonFunction.getCommQueryDAO().excute(update1);
    } else if (tmp.getMchtStatus().equals(TblMchntInfoConstants.MCHNT_ST_STOP_UNCK)) {//??
        String update0 = "update tbl_term_inf set TERM_STA = '4' where MCHT_CD = '" + tmp.getMchtNo() + "'";
        String update1 = "update tbl_term_inf_tmp set TERM_STA = '4' where MCHT_CD = '" + tmp.getMchtNo() + "'";
        String update2 = "update TBL_ALARM_MCHT set BLOCK_MCHT_FLAG='1' where CARD_ACCP_ID='" + tmp.getMchtNo()
                + "' ";
        CommonFunction.getCommQueryDAO().excute(update0);
        CommonFunction.getCommQueryDAO().excute(update1);
        CommonFunction.getCommQueryDAO().excute(update2);
    } else if (tmp.getMchtStatus().equals(TblMchntInfoConstants.MCHNT_ST_MODI_UNCK)) {//
        if (!tmp.getBankNo().equals(inf.getBankNo())) {
            String update0 = "update BTH_CHK_TXN_SUSPS set stlm_inst='" + tmp.getBankNo()
                    + "' where card_accp_id='" + tmp.getMchtNo() + "'";
            String update1 = "update BTH_CHK_TXN set stlm_inst='" + tmp.getBankNo() + "' where card_accp_id = '"
                    + tmp.getMchtNo() + "'";
            String update2 = "update tbl_mchnt_infile_dtl set brh_code='" + tmp.getBankNo()
                    + "' where mcht_no = '" + tmp.getMchtNo() + "'";
            String update3 = "update tbl_algo_dtl set brh_ins_id_cd='" + tmp.getBankNo() + "' where mcht_cd = '"
                    + tmp.getMchtNo() + "'";
            String update4 = "update tbl_term_algo_sum set brh_ins_id_cd='" + tmp.getBankNo()
                    + "' where mcht_cd = '" + tmp.getMchtNo() + "'";
            CommonFunction.getCommQueryDAO().excute(update0);
            CommonFunction.getCommQueryDAO().excute(update1);
            CommonFunction.getCommQueryDAO().excute(update2);
            CommonFunction.getCommQueryDAO().excute(update3);
            CommonFunction.getCommQueryDAO().excute(update4);
        }
    } else if (tmp.getMchtStatus().equals(TblMchntInfoConstants.MCHNT_ST_RCV_UNCK)) {//??? 
        String update0 = "update TBL_ALARM_MCHT set BLOCK_MCHT_FLAG='0' where CARD_ACCP_ID='" + tmp.getMchtNo()
                + "' ";
        CommonFunction.getCommQueryDAO().excute(update0);
    }

    String tmpStatus = tmp.getMchtStatus();

    // ?
    tmp.setMchtStatus(StatusUtil.getNextStatus("G." + tmp.getMchtStatus()));

    // ??
    BeanUtils.copyProperties(tmp, inf);
    BeanUtils.copyProperties(tmpSettle, infSettle);

    //?crt??
    if (!TblMchntInfoConstants.MCHNT_ST_NEW_UNCK.equals(status)
            && !TblMchntInfoConstants.MCHNT_ST_NEW_FIRST_UNCK.equals(status)) {
        inf.setRecCrtTs(crtDate);
    }

    tblMchtBaseInfTmpDAO.update(tmp);
    tblMchtSettleInfTmpDAO.update(tmpSettle);
    tblMchtBaseInfDAO.saveOrUpdate(inf);
    tblMchtSettleInfDAO.saveOrUpdate(infSettle);

    return Constants.SUCCESS_CODE;
}

From source file:au.org.ala.biocache.dao.SearchDAOImpl.java

/**
 * Returns a list of species that are endemic to the supplied region. Values are cached 
 * due to the "expensive" operation./*  ww w  .  j av  a  2s .c o  m*/
 */
@Cacheable(cacheName = "endemicCache")
public List<FieldResultDTO> getEndemicSpecies(SpatialSearchRequestParams requestParams) throws Exception {
    if (executor == null) {
        executor = Executors.newFixedThreadPool(maxMultiPartThreads);
    }
    // 1)get a list of species that are in the WKT
    logger.debug("Starting to get Endemic Species...");
    List<FieldResultDTO> list1 = getValuesForFacet(requestParams);//new ArrayList(Arrays.asList(getValuesForFacets(requestParams)));
    logger.debug("Retrieved species within area...(" + list1.size() + ")");
    // 2)get a list of species that occur in the inverse WKT

    String reverseQuery = SpatialUtils.getWKTQuery(spatialField, requestParams.getWkt(), true);//"-geohash:\"Intersects(" +wkt + ")\"";

    logger.debug("The reverse query:" + reverseQuery);

    requestParams.setWkt(null);

    int i = 0, localterms = 0;

    String facet = requestParams.getFacets()[0];
    String[] originalFqs = requestParams.getFq();
    //add the negated WKT query to the fq
    originalFqs = (String[]) ArrayUtils.add(originalFqs, reverseQuery);
    List<Future<List<FieldResultDTO>>> threads = new ArrayList<Future<List<FieldResultDTO>>>();
    //batch up the rest of the world query so that we have fqs based on species we want to test for. This should improve the performance of the endemic services.       
    while (i < list1.size()) {
        StringBuffer sb = new StringBuffer();
        while ((localterms == 0 || localterms % termQueryLimit != 0) && i < list1.size()) {
            if (localterms != 0)
                sb.append(" OR ");
            sb.append(facet).append(":").append(ClientUtils.escapeQueryChars(list1.get(i).getFieldValue()));
            i++;
            localterms++;
        }
        String newfq = sb.toString();
        if (localterms == 1)
            newfq = newfq + " OR " + newfq; //cater for the situation where there is only one term.  We don't want the term to be escaped again
        localterms = 0;
        //System.out.println("FQ = " + newfq);
        SpatialSearchRequestParams srp = new SpatialSearchRequestParams();
        BeanUtils.copyProperties(requestParams, srp);
        srp.setFq((String[]) ArrayUtils.add(originalFqs, newfq));
        int batch = i / termQueryLimit;
        EndemicCallable callable = new EndemicCallable(srp, batch, this);
        threads.add(executor.submit(callable));
    }
    for (Future<List<FieldResultDTO>> future : threads) {
        List<FieldResultDTO> list = future.get();
        if (list != null)
            list1.removeAll(list);
    }
    logger.debug("Determined final endemic list (" + list1.size() + ")...");
    return list1;
}

From source file:com.hihsoft.baseclass.web.controller.BaseController.java

/**
 * ?/*from w w  w .  j av a 2 s.c  om*/
 * 
 * @param target
 * @param source
 */
public static void copyProperties(Object target, Object source) {
    BeanUtils.copyProperties(target, source);
}

From source file:au.org.ala.biocache.dao.SearchDAOImpl.java

/**
 * (Endemic)/*from   w  ww . j a v  a  2  s  .  c  o m*/
 *
 * Returns a list of species that are only within a subQuery.
 *
 * The subQuery is a subset of parentQuery.
 */
public List<FieldResultDTO> getSubquerySpeciesOnly(SpatialSearchRequestParams subQuery,
        SpatialSearchRequestParams parentQuery) throws Exception {
    if (executor == null) {
        executor = Executors.newFixedThreadPool(maxMultiPartThreads);
    }
    // 1)get a list of species that are in the WKT
    logger.debug("Starting to get Endemic Species...");
    subQuery.setFacet(true);
    subQuery.setFacets(parentQuery.getFacets());
    List<FieldResultDTO> list1 = getValuesForFacet(subQuery);
    logger.debug("Retrieved species within area...(" + list1.size() + ")");

    int i = 0, localterms = 0;

    String facet = parentQuery.getFacets()[0];
    String[] originalFqs = parentQuery.getFq();
    List<Future<List<FieldResultDTO>>> threads = new ArrayList<Future<List<FieldResultDTO>>>();
    //batch up the rest of the world query so that we have fqs based on species we want to test for. This should improve the performance of the endemic services.
    while (i < list1.size()) {
        StringBuffer sb = new StringBuffer();
        while ((localterms == 0 || localterms % termQueryLimit != 0) && i < list1.size()) {
            if (localterms != 0)
                sb.append(" OR ");
            String value = list1.get(i).getFieldValue();
            if (facet.equals(NAMES_AND_LSID)) {
                if (value.startsWith("\"") && value.endsWith("\"")) {
                    value = value.substring(1, value.length() - 1);
                }
                value = "\"" + ClientUtils.escapeQueryChars(value) + "\"";
            } else {
                value = ClientUtils.escapeQueryChars(value);
            }
            sb.append(facet).append(":").append(value);
            i++;
            localterms++;
        }
        String newfq = sb.toString();
        if (localterms == 1)
            newfq = newfq + " OR " + newfq; //cater for the situation where there is only one term.  We don't want the term to be escaped again
        localterms = 0;
        SpatialSearchRequestParams srp = new SpatialSearchRequestParams();
        BeanUtils.copyProperties(parentQuery, srp);
        srp.setFq((String[]) ArrayUtils.add(originalFqs, newfq));
        int batch = i / termQueryLimit;
        EndemicCallable callable = new EndemicCallable(srp, batch, this);
        threads.add(executor.submit(callable));
    }

    Collections.sort(list1);
    for (Future<List<FieldResultDTO>> future : threads) {
        List<FieldResultDTO> list = future.get();
        if (list != null) {
            for (FieldResultDTO find : list) {
                int idx = Collections.binarySearch(list1, find);
                //remove if subquery count < parentquery count
                if (idx >= 0 && list1.get(idx).getCount() < find.getCount()) {
                    list1.remove(idx);
                }
            }
        }
    }
    logger.debug("Determined final endemic list (" + list1.size() + ")...");
    return list1;
}

From source file:com.allinfinance.bo.impl.mchnt.TblMchntServiceImpl1.java

public String refuse(String mchntId, String refuseInfo)
        throws IllegalAccessException, InvocationTargetException {

    TblMchtBaseInfTmp tmp = tblMchtBaseInfTmpDAO.get(mchntId);
    TblMchtSettleInfTmp tmpSettle = tblMchtSettleInfTmpDAO.get(mchntId);

    String crtDateTmp = tmp.getRecCrtTs();

    if (null == tmp || null == tmpSettle) {
        return "??";
    }/*from  w  ww  .java  2 s  .co  m*/

    Operator opr = (Operator) ServletActionContext.getRequest().getSession()
            .getAttribute(Constants.OPERATOR_INFO);

    // ??
    TblMchntRefuse refuse = new TblMchntRefuse();
    TblMchntRefusePK tblMchntRefusePK = new TblMchntRefusePK(mchntId, CommonFunction.getCurrentDateTime());
    refuse.setId(tblMchntRefusePK);
    refuse.setRefuseInfo(refuseInfo);
    refuse.setBrhId(tmp.getBankNo());
    refuse.setOprId(opr.getOprId());

    // ??
    refuse.setRefuseType(StatusUtil.getNextStatus("RM." + tmp.getMchtStatus()));

    // ???
    // ?????-C 20120913
    if (TblMchntInfoConstants.MCHNT_ST_NEW_FIRST_UNCK.equals(tmp.getMchtStatus())) {
        /*tblMchtBaseInfTmpDAO.delete(tmp);
        tblMchtSettleInfTmpDAO.delete(tmpSettle);
        tblMchntRefuseDAO.save(refuse);
        ICommQueryDAO commQueryDAO = (ICommQueryDAO) ContextUtil.getBean("CommQueryDAO");
        commQueryDAO.excute("delete from tbl_term_inf_tmp where mcht_cd='" + mchntId + "'");*/
        tmp.setMchtStatus("C");
        tmp.setRecUpdTs(CommonFunction.getCurrentDateTime());
        tmp.setUpdOprId(opr.getOprId());
        tmpSettle.setRecUpdTs(CommonFunction.getCurrentDateTime());
        tblMchtBaseInfTmpDAO.update(tmp);
        tblMchtSettleInfTmpDAO.update(tmpSettle);
        tblMchntRefuseDAO.save(refuse);

    } else if (TblMchntInfoConstants.MCHNT_ST_BULK_IPT_UNCK.equals(tmp.getMchtStatus())) {
        tblMchtBaseInfTmpDAO.delete(tmp);
        tblMchtSettleInfTmpDAO.delete(tmpSettle);
        tblMchntRefuseDAO.save(refuse);
    } else {
        // ??
        TblMchtBaseInf inf = tblMchtBaseInfDAO.get(tmp.getMchtNo());
        TblMchtSettleInf infSettle = tblMchtSettleInfDAO.get(tmpSettle.getMchtNo());
        if (null == inf || null == infSettle) {
            return "???";
        } else {
            // 
            inf.setRecUpdTs(CommonFunction.getCurrentDateTime());
            inf.setUpdOprId(opr.getOprId());

            // ??
            BeanUtils.copyProperties(inf, tmp);
            BeanUtils.copyProperties(infSettle, tmpSettle);

            tmp.setRecCrtTs(crtDateTmp);

            // ?
            tblMchtBaseInfTmpDAO.update(tmp);
            tblMchtBaseInfDAO.update(inf);
            tblMchtSettleInfTmpDAO.update(tmpSettle);
            tblMchtSettleInfDAO.update(infSettle);
            tblMchntRefuseDAO.save(refuse);
        }
    }

    return Constants.SUCCESS_CODE;
}

From source file:org.excalibur.service.manager.NodeManager.java

public void provision(ApplicationDescriptor descriptor) throws JsonProcessingException {
    checkNotNull(descriptor);/*ww w.  j  a  v a2  s  .co m*/

    User user = this.userService_.findUserByUsername(descriptor.getUser().getUsername());

    if (user == null) {
        if (descriptor.getUser() == null || isNullOrEmpty(descriptor.getUser().getUsername())) {
            throw new IllegalArgumentException("A user is required");
        }

        user = descriptor.getUser();
        this.userService_.insertUser(user);
    } else {
        descriptor.setUser(user);
    }

    String group = String
            .format("%s-%s", configuration_.getUser().getUsername().replaceAll("\\W", ""), descriptor.getName())
            .replaceAll("\\W", "");

    LOG.info("Received the job [{}] with [{}] application(s) to execute on [{}] cloud(s)", descriptor.getId(),
            descriptor.getApplications().size(), descriptor.getClouds().size());

    for (Cloud cloud : descriptor.getClouds()) {
        Deployment deployment = new Deployment().setDescription(descriptor.getDescription())
                .setUser(configuration_.getUser()).setUsername(configuration_.getUser().getUsername())
                .withCredential(new Credential().setName(String.format("%s-%s-%s",
                        descriptor.getUser().getUsername(), descriptor.getName(), descriptor.getId())));

        int i = 1;

        for (final Region region : cloud.getRegions()) {
            Region region_ = regionRepository_.findByName(region.getName());
            checkArgument(region_ != null, "Invalid region [%s]", region.getName());

            region_.addZones(regionRepository_.listZoneOfRegion(region_.getId()));
            BeanUtils.copyProperties(region_, region);
            region.addZones(region_.getZones());

            Zone zone = Lists2.first(region_.getZones());
            checkState(zone != null, "Invalid system's state. Region %s does not have one zone (data center).",
                    region_.getName());

            for (InstanceTypeReq type : this.getInstanceReqTypes(cloud)) {
                VirtualMachineImage image = instanceService_
                        .listAvailableImagesForInstanceType(type.getName(), region_.getId()).get(0);

                Node node = new Node().setCount(type.getNumberOfInstances())
                        .setGroup(type.getInstanceType().getSupportPlacementGroup().toBoolean() ? group : null)
                        .setName(String.format("%s-%s", descriptor.getId(), i++))
                        .setProvider(new Provider().setImageId(image.getName()).setInstanceType(type.getName())
                                .setName(cloud.getProvider().getName()))
                        .setRegion(region_.getName()).setZone(zone.getName())
                        .addTags(new Tag().setName("app-deployment-id").setValue(descriptor.getId()))
                        .addTags(new Tag().setName("manager").setValue(this.thisNode_.getName()));

                deployment.withNode(node);
            }
        }
        deploymentService_.create(deployment);
    }

    descriptor.setPlainText(YAML_MAPPER.writeValueAsString(descriptor));
    descriptor.setCreatedIn(System.currentTimeMillis());

    this.jobService_.insertJob(descriptor);

    for (Application task : descriptor.getApplications()) {
        this.waitingApplications_.offer(task);
    }
}

From source file:com.allinfinance.bo.impl.mchnt.TblMchntServiceImpl.java

public String accept(String mchntId, TblMchtBaseInfTmp tmp, TblMchtSettleInfTmp tmpSettle, TblMchtBaseInf inf,
        TblMchtSettleInf infSettle, TblRiskParamMng tblRiskParamMng) throws Exception {

    //      TblMchtBaseInfTmp tmp = tblMchtBaseInfTmpDAO.get(mchntId);
    //      TblMchtSettleInfTmp tmpSettle = tblMchtSettleInfTmpDAO.get(mchntId);
    //      if (null == tmp || null == tmpSettle) {
    //         return "??";
    //      }/*from w  ww. j a  v  a 2 s. c o  m*/
    //??
    String newMchtNo;
    if (mchntId.contains("AAA")) {
        String idStr = "848" + tmp.getAreaNo().trim() + tmp.getMcc().trim();
        newMchtNo = GenerateNextId.getMchntId(idStr);
        newMchtNo = StringUtils.trim(newMchtNo);

    } else {
        newMchtNo = mchntId;
    }
    System.out.println("?" + newMchtNo);

    //??
    String status = tmp.getMchtStatus();
    //cre
    //      String crtDateTmp= tmp.getRecCrtTs();
    //?
    String upDateTmp = tmp.getRecUpdTs();
    //?
    String oprid = tmp.getUpdOprId();
    if (null == oprid) {
        oprid = tmp.getCrtOprId();
    }

    // ??
    //      TblMchtBaseInf inf = tblMchtBaseInfDAO.get(newMchtNo);
    //      TblMchtSettleInf infSettle = tblMchtSettleInfDAO.get(newMchtNo);
    //?cre
    String crtDate = "0";

    if (null != inf) {
        inf.setMchtStatus("0");
        crtDate = inf.getRecCrtTs();
    }
    if (null == inf) {
        inf = new TblMchtBaseInf();
    }
    if (null == infSettle) {
        infSettle = new TblMchtSettleInf();
    }

    // 
    tmp.setRecUpdTs(CommonFunction.getCurrentDateTime());
    Operator opr = (Operator) ServletActionContext.getRequest().getSession()
            .getAttribute(Constants.OPERATOR_INFO);
    tmp.setUpdOprId(opr.getOprId());
    tmpSettle.setRecUpdTs(CommonFunction.getCurrentDateTime());

    // ?
    tmp.setMchtStatus(StatusUtil.getNextStatus("A." + status));

    // ?
    TblMchntRefuse refuse = new TblMchntRefuse();
    TblMchntRefusePK tblMchntRefusePK = new TblMchntRefusePK(newMchtNo, CommonFunction.getCurrentDateTime());
    refuse.setId(tblMchntRefusePK);
    refuse.setRefuseInfo("");
    refuse.setBrhId(tmp.getBankNo());
    refuse.setOprId(opr.getOprId());

    // ?
    refuse.setRefuseType("");

    //?
    Object[] ret = insertTblMchtBaseInfTmpLog(tmp, inf, tmpSettle, infSettle, status, upDateTmp, oprid);
    String retMsg = Constants.SUCCESS_CODE;
    /*
     * ?
            
     */
    String txnCode = "";
    boolean isOpen = (Boolean) ret[1];
    if (TblMchntInfoConstants.MCHNT_ST_NEW_UNCK.equals(status)
            || TblMchntInfoConstants.MCHNT_ST_NEW_FIRST_UNCK.equals(status)) {
        txnCode = FrontMcht.TXN_CODE_ADDACCT;
        isOpen = true;
    }
    if (!TblMchntInfoConstants.MCHNT_ST_NEW_UNCK.equals(status)
            && !TblMchntInfoConstants.MCHNT_ST_NEW_FIRST_UNCK.equals(status)) {
        if (TblMchntInfoConstants.MCHNT_ST_MODI_UNCK.equals(status)) {
            txnCode = FrontMcht.TXN_CODE_UPDACCT;
        } else if (TblMchntInfoConstants.MCHNT_ST_DEL_UNCK.equals(status)) {
            txnCode = FrontMcht.TXN_CODE_DELACCT;
            isOpen = true;
        }
    }
    if (isOpen) {
        retMsg = optMchtAcct(inf, infSettle, txnCode);
    }

    //======================

    log.info("????");
    retMsg = this.sendMessage(newMchtNo, tmp, inf, tmpSettle, infSettle);
    log.info(":" + retMsg);
    if (!Constants.SUCCESS_CODE.equals(retMsg)) {
        return retMsg;
    }
    log.info("?????");
    //?
    TblRiskParamMngPK key = new TblRiskParamMngPK();
    key.setMchtId(newMchtNo);
    key.setTermId(CommonFunction.fillString("00000000", ' ', 12, true));
    key.setRiskType("0");
    tblRiskParamMng.setId(key);
    tblRiskParamMngDAO.saveOrUpdate(tblRiskParamMng);
    //=============================

    // ????clone??clone???
    //      if(mchntId.contains("AAA")){
    BeanUtils.copyProperties(tmp, inf);
    BeanUtils.copyProperties(tmpSettle, infSettle);
    //      }
    log.info("???" + inf.getCashFlag());
    //??
    if ("1".equals(inf.getCashFlag())) {
        if (mchntId.contains("AAA")) {
            TblMchtCashInfTmpTmp tblMchtCashInfTmpTmp = cashInfTmpTmpDAO.get(mchntId);
            TblMchtCashInfTmp tblMchtCashInfTmp = cashInfTmpDAO.get(mchntId);
            if (tblMchtCashInfTmp != null && tblMchtCashInfTmpTmp != null) {
                tblMchtCashInfTmp.setUpdOpr(inf.getUpdOprId());
                tblMchtCashInfTmp.setUpdTime(CommonFunction.getCurrentDateTime());
                TblMchtCashInf cashInf = new TblMchtCashInf(newMchtNo);
                TblMchtCashInfTmp cashInfTmp = new TblMchtCashInfTmp(newMchtNo);
                TblMchtCashInfTmpTmp cashInfTmpTmp = new TblMchtCashInfTmpTmp(newMchtNo);
                BeanUtils.copyProperties(tblMchtCashInfTmp, cashInf, new String[] { "mchtId" });
                BeanUtils.copyProperties(tblMchtCashInfTmp, cashInfTmp, new String[] { "mchtId" });
                BeanUtils.copyProperties(tblMchtCashInfTmp, cashInfTmpTmp, new String[] { "mchtId" });
                cashInfTmpDAO.delete(tblMchtCashInfTmp);
                cashInfTmpTmpDAO.delete(tblMchtCashInfTmpTmp);
                cashInfDAO.saveOrUpdate(cashInf);
                cashInfTmpDAO.saveOrUpdate(cashInfTmp);
                cashInfTmpTmpDAO.saveOrUpdate(cashInfTmpTmp);
            }
        } else {
            TblMchtCashInfTmp tblMchtCashInfTmp = cashInfTmpDAO.get(mchntId);
            if (tblMchtCashInfTmp != null) {
                tblMchtCashInfTmp.setUpdOpr(inf.getUpdOprId());
                tblMchtCashInfTmp.setUpdTime(CommonFunction.getCurrentDateTime());
                TblMchtCashInf cashInf = new TblMchtCashInf(newMchtNo);
                BeanUtils.copyProperties(tblMchtCashInfTmp, cashInf);
                cashInfDAO.saveOrUpdate(cashInf);
            }
        }
    }
    //
    if (TblMchntInfoConstants.MCHNT_ST_NEW_UNCK.equals(status)
            || TblMchntInfoConstants.MCHNT_ST_NEW_FIRST_UNCK.equals(status)) {
        inf.setRecCrtTs(CommonFunction.getCurrentDateTime());//
    }
    //?crt??
    if (!TblMchntInfoConstants.MCHNT_ST_NEW_UNCK.equals(status)
            && !TblMchntInfoConstants.MCHNT_ST_NEW_FIRST_UNCK.equals(status)) {
        inf.setRecCrtTs(crtDate);
    }

    if (Constants.SUCCESS_CODE.equals(retMsg)) {

        if (status.equals(TblMchntInfoConstants.MCHNT_ST_DEL_UNCK)) {//?
            String update0 = "update tbl_term_inf set TERM_STA = '7' where MCHT_CD = '" + tmp.getMchtNo() + "'";
            String update1 = "update tbl_term_inf_tmp set TERM_STA = '7' where MCHT_CD = '" + tmp.getMchtNo()
                    + "'";
            commQueryDAO.excute(update0);
            commQueryDAO.excute(update1);
        } else if (status.equals(TblMchntInfoConstants.MCHNT_ST_STOP_UNCK)) {//??
            String update0 = "update tbl_term_inf set TERM_STA = '4' where MCHT_CD = '" + tmp.getMchtNo() + "'";
            String update1 = "update tbl_term_inf_tmp set TERM_STA = '4' where MCHT_CD = '" + tmp.getMchtNo()
                    + "'";
            String update2 = "update TBL_ALARM_MCHT set BLOCK_MCHT_FLAG='1' where CARD_ACCP_ID='"
                    + tmp.getMchtNo() + "' ";
            commQueryDAO.excute(update0);
            commQueryDAO.excute(update1);
            commQueryDAO.excute(update2);
        } else if (status.equals(TblMchntInfoConstants.MCHNT_ST_MODI_UNCK)) {//
            if (!tmp.getBankNo().equals(inf.getBankNo())) {
                String update0 = "update BTH_CHK_TXN_SUSPS set stlm_inst='" + tmp.getBankNo()
                        + "' where card_accp_id='" + tmp.getMchtNo() + "'";
                String update1 = "update BTH_CHK_TXN set stlm_inst='" + tmp.getBankNo()
                        + "' where card_accp_id = '" + tmp.getMchtNo() + "'";
                String update2 = "update tbl_mchnt_infile_dtl set brh_code='" + tmp.getBankNo()
                        + "' where mcht_no = '" + tmp.getMchtNo() + "'";
                String update3 = "update tbl_algo_dtl set brh_ins_id_cd='" + tmp.getBankNo()
                        + "' where mcht_cd = '" + tmp.getMchtNo() + "'";
                String update4 = "update tbl_term_algo_sum set brh_ins_id_cd='" + tmp.getBankNo()
                        + "' where mcht_cd = '" + tmp.getMchtNo() + "'";
                String update5 = "update TBL_TERM_INF set TERM_BRANCH='" + tmp.getBankNo()
                        + "' where mcht_cd = '" + tmp.getMchtNo() + "'";
                String update6 = "update TBL_TERM_INF_TMP set TERM_BRANCH='" + tmp.getBankNo()
                        + "' where mcht_cd = '" + tmp.getMchtNo() + "'";
                commQueryDAO.excute(update0);
                commQueryDAO.excute(update1);
                commQueryDAO.excute(update2);
                commQueryDAO.excute(update3);
                commQueryDAO.excute(update4);
                commQueryDAO.excute(update5);
                commQueryDAO.excute(update6);
            }
        } else if (status.equals(TblMchntInfoConstants.MCHNT_ST_RCV_UNCK)) {//??? 
            String update0 = "update TBL_ALARM_MCHT set BLOCK_MCHT_FLAG='0' where CARD_ACCP_ID='"
                    + tmp.getMchtNo() + "' ";
            commQueryDAO.excute(update0);
        }

        // ID?ID?
        if (mchntId.contains("AAA")) {
            String updateRefuse = "update tbl_Mchnt_Refuse set mchnt_id='" + newMchtNo + "' where mchnt_id='"
                    + mchntId + "'";
            commQueryDAO.excute(updateRefuse);
        }
        //TBL_INF_DISC_CD.DISC_NM
        String updateDiscCd = "UPDATE TBL_INF_DISC_CD SET DISC_NM='" + tmp.getMchtFunction().trim()
                + "',REC_UPD_TS='" + CommonFunction.getCurrentDateTime() + "' WHERE DISC_CD='"
                + tmpSettle.getFeeRate().trim() + "'";
        commQueryDAO.excute(updateDiscCd);
        String updateHisDisc = "UPDATE TBL_HIS_DISC_ALGO A SET A.REC_UPD_TS='"
                + CommonFunction.getCurrentDateTime() + "' WHERE A.DISC_ID='" + tmpSettle.getFeeRate().trim()
                + "'";
        commQueryDAO.excute(updateHisDisc);
        if (TblMchntInfoConstants.MCHNT_ST_NEW_UNCK.equals(status)) {
            //?TBL_INF_DISC_CD_MIRROR,TBL_HIS_DISC_ALGO_MIRROR??
            String updateDiscMirror = "INSERT INTO TBL_INF_DISC_CD_MIRROR A SELECT * FROM TBL_INF_DISC_CD B WHERE B.DISC_CD='"
                    + tmpSettle.getFeeRate().trim() + "'";
            commQueryDAO.excute(updateDiscMirror);
            String updateHisDiscMirror = "INSERT INTO TBL_HIS_DISC_ALGO_MIRROR A SELECT * FROM TBL_HIS_DISC_ALGO B WHERE B.DISC_ID='"
                    + tmpSettle.getFeeRate().trim() + "'";
            commQueryDAO.excute(updateHisDiscMirror);
        }

        //?
        iTblMchtBaseInfTmpLogDAO.saveOrUpdate((TblMchtBaseInfTmpLog) ret[0]);
        if (FrontMcht.TXN_CODE_ADDACCT.equals(txnCode)) {// ??
            addOprInfo(newMchtNo);
        }

        //List<TblTermKey> termKeyList=tblTermKeyDAO.getByMchnt(mchntId);
        //         if(termKeyList!=null&&termKeyList.size()!=0){

        //            for (TblTermKey tblTermKey : termKeyList) {
        //? 
        List<TblTermInfTmp> list = null;
        String currentDateTime = CommonFunction.getCurrentDateTime();
        if (!"4".equals(status)) {
            list = tblTermInfTmpDAO.getByMchntAll(mchntId);
            tblTermKeyDAO.updateByTremId(mchntId, newMchtNo, currentDateTime);
        }
        //               String termId = tblTermKey.getId().getTermId();
        //               tblTermKey.setRecUpdTs(CommonFunction.getCurrentDateTime());
        //            }
        //         }
        //termkey
        // 
        if (list != null && list.size() != 0) {
            for (TblTermInfTmp tblTermInfTmp : list) {

                TblTermInf termInf;

                //??
                TblTermInf tblTermInfOld = tblTermInfDAO.get(tblTermInfTmp.getId().getTermId());
                if (tblTermInfOld != null) {
                    tblTermInfOld = (TblTermInf) tblTermInfTmp.cloneHasExists(tblTermInfOld);
                    termInf = tblTermInfOld;
                    tblTermInfTmp.setMisc1(tblTermInfOld.getMisc1());
                    tblTermInfTmp.setProductCd(tblTermInfOld.getProductCd());
                } else {
                    termInf = new TblTermInf();
                    termInf = (TblTermInf) tblTermInfTmp.clone();
                }
                termInf.setTermSerialNum(tblTermInfTmp.getTermSerialNum());
                termInf.setTermPara(tblTermInfTmp.getTermPara().replaceAll("\\|", ""));
                if (tblTermInfTmp.getMisc2() != null && !tblTermInfTmp.getMisc2().equals("")) {
                    EposMisc epos = new EposMisc(termInf.getMisc2());
                    epos.setVersion(tblTermInfTmp.getMisc2());
                    termInf.setMisc2(epos.toString());
                }
                //814???YYYYMMDD YYYYMMDDHHMMSS
                //tblTermInf.setRecUpdTs(CommonFunction.getCurrentDate());
                termInf.setRecUpdTs(CommonFunction.getCurrentDateTime());
                Operator opra = (Operator) ServletActionContext.getRequest().getSession()
                        .getAttribute(Constants.OPERATOR_INFO);
                termInf.setRecUpdOpr(opra.getOprId());
                //mis?7---
                if (!"7".equals(tblTermInfTmp.getTermSta())) {
                    termInf.setTermSta("1");
                    tblTermInfTmp.setTermSta("1");
                }

                tblTermInfTmp.setRecUpdOpr(opra.getOprId());
                tblTermInfTmp.setRecUpdTs(CommonFunction.getCurrentDateTime());
                tblTermInfTmp.setMchtCd(newMchtNo);
                tblTermInfTmpDAO.update(tblTermInfTmp);

                termInf.setMchtCd(newMchtNo);
                tblTermInfDAO.saveOrUpdate(termInf);
                if (mchntId.contains("AAA")) {
                    //?
                    TblRiskParamMng termRiskParamMngNew = new TblRiskParamMng();
                    TblRiskParamMngPK riskParamMngPK = new TblRiskParamMngPK(newMchtNo,
                            tblTermInfTmp.getId().getTermId(), "1");
                    TblRiskParamMng termRiskParamMng = tblRiskParamMngDAO.get(mchntId,
                            CommonFunction.fillString(tblTermInfTmp.getId().getTermId(), ' ', 12, true), "1");
                    if (termRiskParamMng == null) {
                        termRiskParamMngNew.setId(riskParamMngPK);
                        termRiskParamMngNew.setCreditDayAmt(0.0);
                        termRiskParamMngNew.setCreditMonAmt(0.0);
                        termRiskParamMngNew.setCreditSingleAmt(tblRiskParamMng.getCreditSingleAmt());
                        termRiskParamMngNew.setDebitDayAmt(0.0);
                        termRiskParamMngNew.setDebitMonAmt(0.0);
                        termRiskParamMngNew.setDebitSingleAmt(tblRiskParamMng.getDebitSingleAmt());
                        tblRiskParamMngDAO.saveOrUpdate(termRiskParamMngNew);
                    } else {
                        termRiskParamMngNew = (TblRiskParamMng) org.apache.commons.beanutils.BeanUtils
                                .cloneBean(termRiskParamMng);
                        termRiskParamMngNew.setId(riskParamMngPK);
                        tblRiskParamMngDAO.delete(termRiskParamMng);
                        tblRiskParamMngDAO.saveOrUpdate(termRiskParamMngNew);
                    }
                }

            }
        } ////

        //??
        if (!mchntId.equals(newMchtNo)) {
            //List<TblMchtBaseInfTmpHist> histList=tblMchtBaseInfTmpHistDAO.getByMchtNo(mchntId);
            tblMchtBaseInfTmpHistDAO.updateByMchtNo(newMchtNo, mchntId);
            tblMchtSettleInfTmpHistDAO.updateByMchtNo(newMchtNo, mchntId);
        }
        // ?
        if (mchntId.contains("AAA")) {
            tblMchtBaseInfTmpDAO.delete(mchntId);
            tblMchtSettleInfTmpDAO.delete(mchntId);
        }
        //         tblMchtBaseInfDAO.delete(mchntId);
        //         tblMchtSettleInfDAO.delete(mchntId);

        if (tmp.getMchtNo().contains("AAA")) {
            String sql1 = "update TBL_MCHT_BASE_INF_TMP_HIST set MCHT_NO='" + inf.getMchtNo()
                    + "' where MCHT_NO = '" + tmp.getMchtNo() + "'";
            String sql2 = "update TBL_MCHT_SETTLE_INF_TMP_HIST set MCHT_NO='" + inf.getMchtNo()
                    + "' where MCHT_NO = '" + tmpSettle.getMchtNo() + "'";
            commQueryDAO.excute(sql1);
            commQueryDAO.excute(sql2);
        }

        if (mchntId.contains("AAA")) { //?
            inf.setOpenVirtualAcctFlag("1");
            tmp.setOpenVirtualAcctFlag("1");
        }
        inf.setMchtNo(newMchtNo);
        infSettle.setMchtNo(newMchtNo);
        tmp.setMchtNo(newMchtNo);
        tmpSettle.setMchtNo(newMchtNo);

        tblMchtSettleInfDAO.saveOrUpdate(infSettle);
        tblMchtBaseInfTmpDAO.saveOrUpdate(tmp);
        tblMchtBaseInfDAO.saveOrUpdate(inf);
        tblMchtSettleInfTmpDAO.saveOrUpdate(tmpSettle);
        tblMchntRefuseDAO.save(refuse);

        // 
        String basePath = SysParamUtil.getParam(SysParamConstants.FILE_UPLOAD_DISK);
        basePath = basePath.replace("\\", "/");
        String basePathOld = basePath + mchntId + "/";
        for (int i = 0; i < 11; i++) {
            String upload = "upload";
            if (i == 0) {
                upload += "/";
            } else
                upload = upload + i + "/";
            File deleteFile = new File(basePathOld + upload);
            if (deleteFile.exists()) {
                String basePathNew = basePath + newMchtNo + "/" + upload;
                File writeFile = new File(basePathNew);
                if (!writeFile.exists()) {
                    writeFile.mkdirs();
                }

                FileFilter filter = new FileFilter(mchntId);
                File[] files = deleteFile.listFiles(filter);
                for (File file : files) {
                    file.renameTo(new File(basePathNew + file.getName().replaceAll(mchntId, newMchtNo)));// 
                }

                deleteFile.delete();
            }
            // 

        }
        return Constants.SUCCESS_CODE;
    }
    return retMsg;

}