Example usage for org.springframework.web.multipart MultipartFile getName

List of usage examples for org.springframework.web.multipart MultipartFile getName

Introduction

In this page you can find the example usage for org.springframework.web.multipart MultipartFile getName.

Prototype

String getName();

Source Link

Document

Return the name of the parameter in the multipart form.

Usage

From source file:com.opendesign.controller.ProductController.java

/**
 * ??() ?///from  www  .  j  a va 2s .c  o  m
 * 
 * @param product
 * @param request
 * @param saveType
 * @return
 * @throws Exception
 */
private JsonModelAndView saveProduct(DesignWorkVO product, MultipartHttpServletRequest request, int saveType)
        throws Exception {

    /*
     * ?? ? ?  
     */
    boolean isUpdate = saveType == SAVE_TYPE_UPDATE;

    Map<String, Object> resultMap = new HashMap<String, Object>();

    UserVO loginUser = CmnUtil.getLoginUser(request);
    if (loginUser == null || !StringUtil.isNotEmpty(loginUser.getSeq())) {
        resultMap.put("result", "100");
        return new JsonModelAndView(resultMap);
    }

    /*   ?  ? */
    if (isUpdate) {
        DesignWorkVO prevProduct = designerService.getDesignWork(product.getSeq());
        if (!loginUser.getSeq().equals(prevProduct.getMemberSeq())) {
            resultMap.put("result", "101");
            return new JsonModelAndView(resultMap);
        }
    }

    /*
     * ? ?
     */
    MultipartFile fileUrlFile = request.getFile("fileUrlFile");
    if (fileUrlFile != null) {
        String fileName = fileUrlFile.getOriginalFilename().toLowerCase();
        if (!(fileName.endsWith(".jpg") || fileName.endsWith(".png"))) {
            resultMap.put("result", "202");
            return new JsonModelAndView(resultMap);
        }

    } else {
        /* ?  ? . */
        if (!isUpdate) {
            resultMap.put("result", "201");
            return new JsonModelAndView(resultMap);
        }
    }

    /*
     * license
     */
    String license01 = request.getParameter("license01");
    String license02 = request.getParameter("license02");
    String license03 = request.getParameter("license03");
    String license = license01 + license02 + license03;
    product.setLicense(license);

    //??  ?///// 
    String stem = request.getParameter("origin");
    if (stem == null) {
        product.setOriginSeq("0");
    } else {
        product.setOriginSeq(stem);
    }
    //////////////////////////////

    /* 
     * ?? ?  "0"  
     */
    String point = request.getParameter("point");
    point = String.valueOf(CmnUtil.getIntValue(point)); //null--> 0 
    product.setPoint(point);

    /*
     * ? ?
     */
    List<MultipartFile> productFileList = new ArrayList<MultipartFile>();
    List<MultipartFile> openSourceFileList = new ArrayList<MultipartFile>();

    Iterator<String> iterator = request.getFileNames();
    while (iterator.hasNext()) {
        String fileNameKey = iterator.next();

        MultipartFile reqFile = request.getFile(fileNameKey);
        if (reqFile != null) {
            boolean existProuductFile = fileNameKey.startsWith("productFile");
            boolean existOpenSourceFile = fileNameKey.startsWith("openSourceFile");
            if (existProuductFile || existOpenSourceFile) {
                long fileSize = reqFile.getSize();
                if (fileSize > LIMIT_FILE_SIZE) {
                    resultMap.put("result", "203");
                    resultMap.put("fileName", reqFile.getOriginalFilename());
                    return new JsonModelAndView(resultMap);

                }

                if (existProuductFile) {
                    productFileList.add(reqFile);
                }

                if (existOpenSourceFile) {
                    openSourceFileList.add(reqFile);
                }
            }
        }
    }
    product.setMemberSeq(loginUser.getSeq());

    /*
     * ?? 
     */
    String fileUploadDir = CmnUtil.getFileUploadDir(request, FileUploadDomain.PRODUCT);
    File thumbFile = null;
    if (fileUrlFile != null) {
        String saveFileName = UUID.randomUUID().toString();
        thumbFile = CmnUtil.saveFile(fileUrlFile, fileUploadDir, saveFileName);

        String fileUploadDbPath = CmnUtil.getFileUploadDbPath(request, thumbFile);
        product.setThumbUri(fileUploadDbPath);
    }

    /*
     * ??() 
     */
    List<DesignPreviewImageVO> productList = new ArrayList<DesignPreviewImageVO>();
    List<String> productFilePaths = new ArrayList<>();

    for (MultipartFile aFile : productFileList) {
        String saveFileName = UUID.randomUUID().toString();
        File file = CmnUtil.saveFile(aFile, fileUploadDir, saveFileName);

        productFilePaths.add(file.getAbsolutePath());

        String fileUploadDbPath = CmnUtil.getFileUploadDbPath(request, file);

        DesignPreviewImageVO productFile = new DesignPreviewImageVO();
        productFile.setFilename(aFile.getOriginalFilename());
        productFile.setFileUri(fileUploadDbPath);

        productList.add(productFile);

    }
    product.setImageList(productList);

    /*
     *   
     */
    List<DesignWorkFileVO> openSourceList = new ArrayList<DesignWorkFileVO>();
    for (MultipartFile aFile : openSourceFileList) {
        String saveFileName = UUID.randomUUID().toString();
        File file = CmnUtil.saveFile(aFile, fileUploadDir, saveFileName);
        String fileUploadDbPath = CmnUtil.getFileUploadDbPath(request, file);

        //openSourceFile? ??? client?  .
        String filenameOpenSourceFile = StringUtils
                .stripToEmpty(request.getParameter("filename_" + aFile.getName()));

        DesignWorkFileVO openSourceFile = new DesignWorkFileVO();
        openSourceFile.setFilename(filenameOpenSourceFile);
        openSourceFile.setFileUri(fileUploadDbPath);

        openSourceList.add(openSourceFile);

    }
    product.setFileList(openSourceList);

    /*
     * ??/?   ?  ? ? 
     * ?? ? ?  ? ? ? 
     */
    String thumbFilePath = "";
    if (thumbFile != null) {
        thumbFilePath = thumbFile.getAbsolutePath();
    }
    ThumbnailManager.resizeNClone4DesignWork(thumbFilePath, productFilePaths);

    /*
     *  
     */
    String tag = request.getParameter("tag");
    if (StringUtil.isNotEmpty(tag)) {
        String[] tags = tag.split(",");

        int addIndex = 0;
        StringBuffer tagBuffer = new StringBuffer();
        for (String aTag : tags) {
            if (StringUtil.isNotEmpty(aTag)) {
                aTag = aTag.trim();
                tagBuffer.append(aTag);
                tagBuffer.append("|");
                addIndex++;
            }

            if (addIndex >= 5) {
                break;
            }
        }

        if (addIndex > 0) {
            tagBuffer.insert(0, "|");

            tag = tagBuffer.toString();
        }
    }
    product.setTags(tag);

    String currentDate = Day.getCurrentTimestamp().substring(0, 12);
    product.setRegisterTime(currentDate);
    product.setUpdateTime(currentDate);

    String[] categoryCodes = request.getParameterValues("categoryCodes");

    /*
     *  
     */
    if (isUpdate) {
        String[] removeProductSeqs = request.getParameterValues("removeProductSeq");
        String[] removeOpenSourceSeqs = request.getParameterValues("removeOpenSourceSeq");

        int projectSeq = service.updateProduct(product, categoryCodes, removeProductSeqs, removeOpenSourceSeqs);

    } else {
        int projectSeq = service.insertProduct(product, categoryCodes);

    }

    resultMap.put(RstConst.P_NAME, RstConst.V_SUCESS);
    return new JsonModelAndView(resultMap);

}

From source file:at.fh.swenga.firefighters.controller.FireFighterController.java

/**
 * Save uploaded file to the database (as 1:1 relationship to fireFighter)
 * @param model//  w w w .  j  av  a  2 s  .c  om
 * @param fireFighterId
 * @param file
 * @return
 */
@RequestMapping(value = "upload", method = RequestMethod.POST)
public String uploadDocument(Model model, @RequestParam("id") int fireFighterId,
        @RequestParam("myImage") MultipartFile file) {
    try {

        FireFighterModel fireFighter = fireFighterRepository.findOne(fireFighterId);
        // Already a document available -> delete it
        if (fireFighter.getImage() != null) {
            imageRepository.delete(fireFighter.getImage());
            // Don't forget to remove the relationship too 
            fireFighter.setImage(null);
        }

        //Create a new document and set all available infos 
        ImageModel img = new ImageModel();
        img.setContent(file.getBytes());
        img.setContentType(file.getContentType());
        img.setCreated(new Date());
        img.setFilename(file.getOriginalFilename());
        img.setName(file.getName());
        fireFighter.setImage(img);
        fireFighterRepository.save(fireFighter);
    } catch (Exception e) {
        model.addAttribute("errorMessage", "Error:" + e.getMessage());
    }

    return "forward:mitglieder";
}

From source file:com.prcsteel.platform.account.service.impl.AccountServiceImpl.java

private boolean attachmentsContainConsignContract(List<MultipartFile> list) {
    if (list == null) {
        return false;
    }//from w  w w.j a  v  a 2 s. c om
    for (MultipartFile file : list) {
        if (file.getName().equals(AttachmentType.pic_consign_contract.toString())) {
            return true;
        }
    }
    return false;
}

From source file:com.prcsteel.platform.account.service.impl.AccountServiceImpl.java

@Override
@Transactional/*from   ww  w  .  j a v a  2  s.co m*/
public HashMap<String, Object> insert(AccountDto record, List<MultipartFile> attachments,
        AccountContact contact) throws BusinessException {
    HashMap<String, Object> result = new HashMap<String, Object>();
    Account account = record.getAccount();
    String accountCode = account.getAccountCode();
    if (accountCode != null && !"".equals(accountCode.replaceAll(" ", ""))) {
        // ??
        AccountBank accountBank = accountBankDao.selectByAccountCode(StringToReplace.toReplaceAll(accountCode));
        if (accountBank != null) {
            throw new BusinessException(Constant.EXCEPTIONCODE_BUSINESS,
                    "??" + accountCode.substring(accountCode.length() - 4)
                            + "???"
                            + accountDao.selectByPrimaryKey(accountBank.getAccountId()).getName()
                            + "??" + userDao.queryByLoginId("chenhu").getTel()
                            + "?");
        }
    }
    User user = record.getManager();
    account.setManagerId(user.getId());
    account.setCreatedBy(user.getLoginId());
    account.setLastUpdatedBy(user.getLoginId());
    account.setRegTime(new Date());
    account.setCode(getCode());
    if (StringUtils.isEmpty(account.getBusinessType())) {
        account.setBusinessType(null);
    }
    accountDao.insertSelective(account);
    Long accountId = account.getId();
    // ??????? modify by kongbinheng 20150803
    if (accountCode != null && !"".equals(accountCode.replaceAll(" ", ""))) {
        AccountBank accountBank = accountBankDao.selectByAccountCode(StringToReplace.toReplaceAll(accountCode));
        if (accountBank == null) {
            accountBank = new AccountBank();
            accountBank.setAccountId(accountId); // ?ID
            accountBank.setBankCode(StringToReplace.toReplaceAll(account.getBankCode())); // ?
            accountBank.setBankName(StringToReplace.toReplaceAll(account.getBankNameMain())); // 
            accountBank.setBankNameBranch(StringToReplace.toReplaceAll(account.getBankNameBranch())); // 
            accountBank.setBankProvinceId(account.getBankProvinceId());
            accountBank.setBankCityId(account.getBankCityId());
            if (account.getBankProvinceId() != null)
                accountBank.setBankProvinceName(
                        provinceDao.selectByPrimaryKey(account.getBankProvinceId()).getName());
            if (account.getBankCityId() != null)
                accountBank.setBankCityName(cityDao.selectByPrimaryKey(account.getBankCityId()).getName());
            accountBank.setBankAccountCode(StringToReplace.toReplaceAll(accountCode)); // ?
            accountBank.setCreated(new Date());
            accountBank.setCreatedBy(user.getLoginId());
            accountBank.setLastUpdated(new Date());
            accountBank.setLastUpdatedBy(user.getLoginId());
            accountBank.setModificationNumber(0);
            accountBankDao.insertSelective(accountBank);
        } else {
            if (accountId.equals(accountBank.getAccountId())) {
                accountBank.setBankCode(StringToReplace.toReplaceAll(account.getBankCode())); // ?
                accountBank.setBankName(StringToReplace.toReplaceAll(account.getBankNameMain())); // 
                accountBank.setBankNameBranch(StringToReplace.toReplaceAll(account.getBankNameBranch())); // 
                accountBankDao.updateByPrimaryKeySelective(accountBank);
            } else {

            }
        }
    }

    // String basePath = rootPath + ATTACHMENTSAVEPATH + account.getCode()
    // + File.separator;
    boolean hasTaxReg = false;
    boolean hasInvoiceData = false;
    boolean hasPaymentData = false;//
    boolean hasOpenAccountLicense = false;//??
    if (attachments != null) {
        for (MultipartFile file : attachments) {
            if ("pic_tax_reg".equals(file.getName())) {
                hasTaxReg = true;
            } else if ("pic_invoice_data".equals(file.getName())) {
                hasInvoiceData = true;
            } else if ("pic_payment_data".equals(file.getName())) {
                hasPaymentData = true;
            } else if ("pic_open_account_license".equals(file.getName())) {
                hasOpenAccountLicense = true;
            }
            AccountAttachment accountAttachment = new AccountAttachment();
            accountAttachment.setCreatedBy(user.getLoginId());
            accountAttachment.setLastUpdatedBy(user.getLoginId());
            accountAttachment.setAccountId(accountId);
            AttachmentType type = AttachmentType.valueOf(file.getName());
            accountAttachment.setType(type.getCode());
            // String savePath = basePath + type.getCode() + "."
            // + FileUtil.getFileSuffix(file.getOriginalFilename());
            // FileUtil.saveFile(file, savePath);
            String saveKey = "";
            try {
                saveKey = fileService.saveFile(file.getInputStream(),
                        ATTACHMENTSAVEPATH + account.getCode() + File.separator + type.getCode() + "."
                                + FileUtil.getFileSuffix(file.getOriginalFilename()));
            } catch (IOException e) {
                BusinessException be = new BusinessException(Constant.EXCEPTIONCODE_SYSTEM,
                        "?" + AttachmentType.valueOf(file.getName()) + "");
                throw be;
            }
            accountAttachment.setUrl(saveKey);
            aamDao.insertSelective(accountAttachment);

        }
    }
    if (hasTaxReg || hasInvoiceData) {
        accountDao.updateInvoiceDataStatusByPrimaryKey(account.getId(), InvoiceDataStatus.Requested.getCode(),
                null, user.getLoginId());// 
    } else {
        accountDao.updateInvoiceDataStatusByPrimaryKey(account.getId(),
                InvoiceDataStatus.Insufficient.getCode(), null, user.getLoginId());// ?
    }
    // ??
    if (hasPaymentData || hasOpenAccountLicense) {
        accountDao.updateBankDataStatusByPrimaryKey(account.getId(), AccountBankDataStatus.Requested.getCode(),
                null, null, user.getLoginId());
    } else {
        accountDao.updateBankDataStatusByPrimaryKey(account.getId(),
                AccountBankDataStatus.Insufficient.getCode(), null, null, user.getLoginId());
    }

    accountDao.updateByPrimaryKeySelective(account);

    insertAccountContact(contact, accountId, user);

    result.put("success", true);
    result.put("data", accountId);

    return result;
}

From source file:com.prcsteel.platform.account.service.impl.AccountServiceImpl.java

@Override
@Transactional//from www.  j av a2 s . c  o m
public HashMap<String, Object> updateByPrimaryKeySelective(AccountDto record, List<MultipartFile> attachments,
        AccountContact contact) throws BusinessException {
    HashMap<String, Object> result = new HashMap<String, Object>();
    Account account = record.getAccount();
    User user = record.getManager();
    String accountCode = account.getAccountCode();
    if (accountCode != null && !"".equals(accountCode.replaceAll(" ", ""))) {
        // ??
        AccountBank accountBank = accountBankDao.selectByAccountCode(StringToReplace.toReplaceAll(accountCode));
        // ???
        if (accountBank != null && !accountBank.getAccountId().equals(account.getId())) {
            result.put("success", false);
            result.put("data",
                    "???"
                            + accountDao.selectByPrimaryKey(accountBank.getAccountId()).getName()
                            + "??");
            return result;
        }
    }
    Long accountId = account.getId();
    String bankCode = account.getBankCode(); // ?
    // ??????? modify by kongbinheng 20150803
    if (accountCode != null && !"".equals(accountCode.replaceAll(" ", ""))) {
        AccountBank accountBank = accountBankDao.selectByAccountCode(accountCode.replaceAll(" ", ""));
        if (accountBank == null) {
            accountBank = new AccountBank();
            accountBank.setAccountId(accountId); // ?ID
            accountBank.setBankCode(StringToReplace.toReplaceAll(bankCode)); // ?
            accountBank.setBankName(StringToReplace.toReplaceAll(account.getBankNameMain())); // 
            accountBank.setBankNameBranch(StringToReplace.toReplaceAll(account.getBankNameBranch())); // 
            accountBank.setBankProvinceId(account.getBankProvinceId());
            accountBank.setBankCityId(account.getBankCityId());
            if (account.getBankProvinceId() != null)
                accountBank.setBankProvinceName(
                        provinceDao.selectByPrimaryKey(account.getBankProvinceId()).getName());
            if (account.getBankCityId() != null)
                accountBank.setBankCityName(cityDao.selectByPrimaryKey(account.getBankCityId()).getName());
            accountBank.setBankAccountCode(StringToReplace.toReplaceAll(accountCode)); // ?
            accountBank.setCreated(new Date());
            accountBank.setCreatedBy(user.getLoginId());
            accountBank.setLastUpdated(new Date());
            accountBank.setLastUpdatedBy(user.getLoginId());
            accountBank.setModificationNumber(0);
            accountBankDao.insertSelective(accountBank);
        } else {
            // if(accountId.equals(accountBank.getAccountId())){
            accountBank.setBankCode(StringToReplace.toReplaceAll(bankCode)); // ?
            accountBank.setBankName(StringToReplace.toReplaceAll(account.getBankNameMain())); // 
            accountBank.setBankNameBranch(StringToReplace.toReplaceAll(account.getBankNameBranch())); // 
            accountBankDao.updateByPrimaryKeySelective(accountBank);
            // }else{
            // //ID?
            // }
        }
    }

    account.setCode(null);// ?? ????
    account.setName(null);// ?? ????
    if (StringUtils.isEmpty(account.getBusinessType())) {
        account.setBusinessType(null);
    }

    Account tempAccount = accountDao.selectByPrimaryKey(account.getId());

    if (!StringUtils.isBlank(tempAccount.getAccountCode())
            && Constant.FROMBANKTRANSACTIONJOB.equals(account.getRowId())) { // ??????
        account.setBankCode(null);
        account.setBankNameMain(null);
        account.setAccountCode(null);
    }
    // ???????
    if (!AccountType.both.toString().equals(account.getType())) {
        account.setType(tempAccount.getType());
    }

    account.setLastUpdated(new Date());
    account.setLastUpdatedBy(user.getLoginId());
    account.setModificationNumber(tempAccount.getModificationNumber() + 1);

    accountDao.updateByPrimaryKeySelectiveExcludeBankInfo(account);
    // String basePath = rootPath + ATTACHMENTSAVEPATH + old.getCode()
    // + File.separator;

    boolean taxRegChanged = false;
    boolean invoiceDataChange = false;
    boolean paymentDataChanged = false;//
    boolean openAccountLicenseChanged = false;//??
    // ??????
    if (attachmentsContainConsignContract(attachments)) {
        aamDao.deleteByAccountIdAndType(accountId, AttachmentType.pic_consign_contract.getCode());
    }
    if (attachments != null) {
        for (MultipartFile file : attachments) {
            if ("pic_tax_reg".equals(file.getName())) {
                taxRegChanged = true;
            } else if ("pic_invoice_data".equals(file.getName())) {
                invoiceDataChange = true;
            } else if ("pic_payment_data".equals(file.getName())) {
                paymentDataChanged = true;
            } else if ("pic_open_account_license".equals(file.getName())) {
                openAccountLicenseChanged = true;
            }
            AttachmentType type = AttachmentType.valueOf(file.getName());

            AccountAttachment accountAttachment = null;
            if (!AttachmentType.pic_consign_contract.equals(type)) {
                List<AccountAttachment> list = accountAttachmentDao.selectByAccountIdAndType(accountId,
                        type.getCode());
                if (list != null && list.size() > 0) {
                    accountAttachment = list.get(0);
                }
            }
            // String savePath = basePath + type.getCode() + "."
            // + FileUtil.getFileSuffix(file.getOriginalFilename());
            if (accountAttachment == null) {
                accountAttachment = new AccountAttachment();
                accountAttachment.setAccountId(accountId);
                accountAttachment.setType(type.getCode());
                accountAttachment.setCreated(new Date());
                accountAttachment.setCreatedBy(user.getLoginId());
                // accountAttachment.setLastUpdatedBy(user.getLoginId());
            }
            accountAttachment.setLastUpdated(new Date());
            accountAttachment.setLastUpdatedBy(user.getLoginId());
            String saveKey = "";
            try {
                saveKey = fileService.saveFile(file.getInputStream(),
                        ATTACHMENTSAVEPATH + tempAccount.getCode() + File.separator + type.getCode() + "."
                                + FileUtil.getFileSuffix(file.getOriginalFilename()));
            } catch (IOException e) {
                BusinessException be = new BusinessException(Constant.EXCEPTIONCODE_BUSINESS,
                        "?" + AttachmentType.valueOf(file.getName()) + "");
                throw be;
            }
            accountAttachment.setUrl(saveKey);
            if (accountAttachment.getId() == null || type.equals(AttachmentType.pic_consign_contract)) {
                aamDao.insertSelective(accountAttachment);
            } else {
                aamDao.updateByPrimaryKeySelective(accountAttachment);
            }
        }
    }

    // ? 
    if (!account.getType().equals(AccountType.seller)
            && !(((StringUtils.isEmpty(account.getTaxCode()) && StringUtils.isEmpty(tempAccount.getTaxCode()))
                    || (account.getTaxCode() != null && account.getTaxCode().equals(tempAccount.getTaxCode())))
                    && ((StringUtils.isEmpty(account.getAddr()) && StringUtils.isEmpty(tempAccount.getAddr()))
                            || (account.getAddr() != null && account.getAddr().equals(tempAccount.getAddr())))
                    && ((StringUtils.isEmpty(account.getTel()) && StringUtils.isEmpty(tempAccount.getTel()))
                            || (account.getTel() != null && account.getTel().equals(tempAccount.getTel())))
                    && ((StringUtils.isEmpty(account.getBankNameMain())
                            && StringUtils.isEmpty(tempAccount.getBankNameMain()))
                            || (account.getBankNameMain() != null
                                    && account.getBankNameMain().equals(tempAccount.getBankNameMain())))
                    && ((StringUtils.isEmpty(account.getBankNameBranch())
                            && StringUtils.isEmpty(tempAccount.getBankNameBranch()))
                            || (account.getBankNameBranch() != null
                                    && account.getBankNameBranch().equals(tempAccount.getBankNameBranch())))
                    && ((StringUtils.isEmpty(account.getAccountCode())
                            && StringUtils.isEmpty(tempAccount.getAccountCode()))
                            || (account.getAccountCode() != null
                                    && account.getAccountCode().equals(tempAccount.getAccountCode())))
                    && ((StringUtils.isEmpty(account.getInvoiceType())
                            && StringUtils.isEmpty(tempAccount.getInvoiceType()))
                            || (account.getInvoiceType() != null
                                    && account.getInvoiceType().equals(tempAccount.getInvoiceType())))
                    && !taxRegChanged && !invoiceDataChange)) {
        // ???????????
        if (!(InvoiceDataStatus.Insufficient.getCode().equals(tempAccount.getInvoiceDataStatus())
                && !taxRegChanged && !invoiceDataChange)) {
            accountDao.updateInvoiceDataStatusByPrimaryKey(account.getId(),
                    InvoiceDataStatus.Requested.getCode(), null, user.getLoginId());
        }

    }

    // modify kongbinheng 2015-11-20
    // ???????????
    if (!(((StringUtils.isEmpty(account.getBankNameMain())
            && StringUtils.isEmpty(tempAccount.getBankNameMain()))
            || (account.getBankNameMain() != null
                    && account.getBankNameMain().equals(tempAccount.getBankNameMain())))
            && ((StringUtils.isEmpty(account.getBankNameBranch())
                    && StringUtils.isEmpty(tempAccount.getBankNameBranch()))
                    || (account.getBankNameBranch() != null
                            && account.getBankNameBranch().equals(tempAccount.getBankNameBranch())))
            && ((StringUtils.isEmpty(String.valueOf(account.getBankProvinceId()))
                    && StringUtils.isEmpty(String.valueOf(tempAccount.getBankProvinceId())))
                    || (account.getBankProvinceId() != null
                            && account.getBankProvinceId().equals(tempAccount.getBankProvinceId())))
            && ((StringUtils.isEmpty(String.valueOf(account.getBankCityId()))
                    && StringUtils.isEmpty(String.valueOf(tempAccount.getBankCityId())))
                    || (account.getBankCityId() != null
                            && account.getBankCityId().equals(tempAccount.getBankCityId())))
            && ((StringUtils.isEmpty(account.getAccountCode())
                    && StringUtils.isEmpty(tempAccount.getAccountCode()))
                    || (account.getAccountCode() != null
                            && account.getAccountCode().equals(tempAccount.getAccountCode())))
            && ((StringUtils.isEmpty(account.getBankCode()) && StringUtils.isEmpty(tempAccount.getBankCode()))
                    || (account.getBankCode() != null
                            && account.getBankCode().equals(tempAccount.getBankCode())))
            && !paymentDataChanged && !openAccountLicenseChanged)) {
        // ????????????
        if (!(AccountBankDataStatus.Insufficient.getCode().equals(tempAccount.getBankDataStatus())
                && !paymentDataChanged && !openAccountLicenseChanged)) {
            accountDao.updateBankDataStatusByPrimaryKey(account.getId(),
                    AccountBankDataStatus.Requested.getCode(), null, null, user.getLoginId());
        }
    }

    if (contact != null) {
        AccountContact oldContact = accountcontactDao.queryByTel(contact.getTel());
        if (oldContact != null) {
            if (!oldContact.getName().equals(contact.getName())) {
                throw new BusinessException(Constant.EXCEPTIONCODE_BUSINESS,
                        "????");
            } else if (!oldContact.getAccountId().equals(account.getId())) {
                throw new BusinessException(Constant.EXCEPTIONCODE_BUSINESS,
                        "???");
            } else {
                if (oldContact.getIsMain() != Integer.parseInt(Constant.YES.toString())) { // ????
                    Map<String, Object> map = new HashMap<>();
                    map.put("accountId", account.getId());
                    map.put("isMain", Constant.YES.toString());
                    map.put("type", AccountType.buyer.toString());
                    List<AccountContactDto> list = accountcontactDao.queryByAccountId(map); // ??
                    for (AccountContact temp : list) {
                        temp.setIsMain(Integer.parseInt(Constant.NO.toString()));
                        temp.setLastUpdated(new Date());
                        temp.setLastUpdatedBy(user.getLoginId());
                        temp.setModificationNumber(temp.getModificationNumber() + 1);
                        if (accountcontactDao.updateAccountContactById(temp) != 1) {
                            throw new BusinessException(Constant.EXCEPTIONCODE_BUSINESS,
                                    "?");
                        }
                    }
                }
                contact.setId(oldContact.getId());
                contact.setIsMain(Integer.parseInt(Constant.YES.toString()));
                contact.setType(AccountType.both.toString());
                contact.setLastUpdated(new Date());
                contact.setLastUpdatedBy(user.getLoginId());
                contact.setModificationNumber(tempAccount.getModificationNumber() + 1);
                if (accountcontactDao.updateAccountContactById(contact) != 1) {
                    throw new BusinessException(Constant.EXCEPTIONCODE_BUSINESS, "?");
                }
            }
        } else {
            insertAccountContact(contact, accountId, user);
        }
    }

    result.put("success", true);
    result.put("data", account.getId());
    return result;

}

From source file:edu.unc.lib.dl.admin.controller.IngestController.java

@RequestMapping(value = "ingest/{pid}", method = RequestMethod.POST)
public @ResponseBody Map<String, ? extends Object> ingestPackageController(@PathVariable("pid") String pid,
        @RequestParam("type") String type, @RequestParam(value = "name", required = false) String name,
        @RequestParam("file") MultipartFile ingestFile, HttpServletRequest request,
        HttpServletResponse response) {/*  www  . j av a 2 s.  co  m*/
    String destinationUrl = swordUrl + "collection/" + pid;
    HttpClient client = HttpClientUtil.getAuthenticatedClient(destinationUrl, swordUsername, swordPassword);
    client.getParams().setAuthenticationPreemptive(true);
    PostMethod method = new PostMethod(destinationUrl);

    // Set SWORD related headers for performing ingest
    method.addRequestHeader(HttpClientUtil.FORWARDED_GROUPS_HEADER, GroupsThreadStore.getGroupString());
    method.addRequestHeader("Packaging", type);
    method.addRequestHeader("On-Behalf-Of", GroupsThreadStore.getUsername());
    method.addRequestHeader("Content-Type", ingestFile.getContentType());
    method.addRequestHeader("Content-Length", Long.toString(ingestFile.getSize()));
    method.addRequestHeader("mail", request.getHeader("mail"));
    method.addRequestHeader("Content-Disposition", "attachment; filename=" + ingestFile.getOriginalFilename());
    if (name != null && name.trim().length() > 0)
        method.addRequestHeader("Slug", name);

    // Setup the json response
    Map<String, Object> result = new HashMap<String, Object>();
    result.put("action", "ingest");
    result.put("destination", pid);
    try {
        method.setRequestEntity(
                new InputStreamRequestEntity(ingestFile.getInputStream(), ingestFile.getSize()));
        client.executeMethod(method);
        response.setStatus(method.getStatusCode());

        // Object successfully "create", or at least queued
        if (method.getStatusCode() == 201) {
            Header location = method.getResponseHeader("Location");
            String newPid = location.getValue();
            newPid = newPid.substring(newPid.lastIndexOf('/'));
            result.put("pid", newPid);
        } else if (method.getStatusCode() == 401) {
            // Unauthorized
            result.put("error", "Not authorized to ingest to container " + pid);
        } else if (method.getStatusCode() == 400 || method.getStatusCode() >= 500) {
            // Server error, report it to the client
            result.put("error", "A server error occurred while attempting to ingest \"" + ingestFile.getName()
                    + "\" to " + pid);

            // Inspect the SWORD response, extracting the stacktrace
            InputStream entryPart = method.getResponseBodyAsStream();
            Abdera abdera = new Abdera();
            Parser parser = abdera.getParser();
            Document<Entry> entryDoc = parser.parse(entryPart);
            Object rootEntry = entryDoc.getRoot();
            String stackTrace;
            if (rootEntry instanceof FOMExtensibleElement) {
                stackTrace = ((org.apache.abdera.parser.stax.FOMExtensibleElement) entryDoc.getRoot())
                        .getExtension(SWORD_VERBOSE_DESCRIPTION).getText();
                result.put("errorStack", stackTrace);
            } else {
                stackTrace = ((Entry) rootEntry).getExtension(SWORD_VERBOSE_DESCRIPTION).getText();
                result.put("errorStack", stackTrace);
            }
            log.warn("Failed to upload ingest package file " + ingestFile.getName() + " from user "
                    + GroupsThreadStore.getUsername(), stackTrace);
        }
        return result;
    } catch (Exception e) {
        log.warn("Encountered an unexpected error while ingesting package " + ingestFile.getName()
                + " from user " + GroupsThreadStore.getUsername(), e);
        result.put("error", "A server error occurred while attempting to ingest \"" + ingestFile.getName()
                + "\" to " + pid);
        return result;
    } finally {
        method.releaseConnection();
        try {
            ingestFile.getInputStream().close();
        } catch (IOException e) {
            log.warn("Failed to close ingest package file", e);
        }
    }
}

From source file:com.prcsteel.platform.account.service.impl.AccountServiceImpl.java

private void checkFile(MultipartFile file) {
    if (file == null) {
        throw new BusinessException(Constant.ERROR_MISSING_REQUIRED_PARAM, "");
    }/* www .j  a v a  2 s .  c  o m*/

    String suffix = FileUtil.getFileSuffix(file.getOriginalFilename());

    if (suffix == null || !Constant.IMAGE_SUFFIX.contains(suffix.toLowerCase())) {
        throw new BusinessException(Constant.ERROR_MISSING_REQUIRED_PARAM,
                AttachmentType.valueOf(file.getName()).getName() + "??");
    }
    if (file.getSize() / Constant.M_SIZE > Constant.MAX_IMG_SIZE) {
        throw new BusinessException(Constant.ERROR_MISSING_REQUIRED_PARAM,
                AttachmentType.valueOf(file.getName()).getName() + "" + Constant.MAX_IMG_SIZE + "M");
    }
}

From source file:org.openmrs.module.clinicalsummary.web.controller.utils.ExtendedDataGeneralController.java

@RequestMapping(method = RequestMethod.POST)
public void processRequest(final @RequestParam(required = true, value = "data") MultipartFile data,
        final @RequestParam(required = true, value = "conceptNames") String conceptNames,
        final HttpServletResponse response) throws IOException {

    List<Concept> concepts = new ArrayList<Concept>();
    for (String conceptName : StringUtils.splitPreserveAllTokens(conceptNames, ",")) {
        Concept concept = Context.getConceptService().getConcept(conceptName);
        if (concept != null)
            concepts.add(concept);//  www .  j a  v  a  2  s .c  om
    }

    PatientService patientService = Context.getPatientService();
    PatientSetService patientSetService = Context.getPatientSetService();

    File identifierData = File.createTempFile(STUDY_DATA, INPUT_PREFIX);
    OutputStream identifierDataStream = new BufferedOutputStream(new FileOutputStream(identifierData));
    FileCopyUtils.copy(data.getInputStream(), identifierDataStream);

    File extendedData = File.createTempFile(STUDY_DATA, OUTPUT_PREFIX);
    BufferedWriter writer = new BufferedWriter(new FileWriter(extendedData));

    String line;
    BufferedReader reader = new BufferedReader(new FileReader(identifierData));
    while ((line = reader.readLine()) != null) {
        Patient patient = null;
        if (isDigit(StringUtils.trim(line)))
            patient = patientService.getPatient(NumberUtils.toInt(line));
        else {
            Cohort cohort = patientSetService.convertPatientIdentifier(Arrays.asList(line));
            for (Integer patientId : cohort.getMemberIds()) {
                Patient cohortPatient = patientService.getPatient(patientId);
                if (cohortPatient != null && !cohortPatient.isVoided())
                    patient = cohortPatient;
            }
        }

        if (patient != null) {
            ExtendedData extended = new ExtendedData(patient, null);
            extended.setEncounters(searchEncounters(patient));
            for (Concept concept : concepts)
                extended.addObservations(concept, searchObservations(patient, concept));
            writer.write(extended.generatePatientData());
            writer.newLine();

            ResultCacheInstance.getInstance().clearCache(patient);
        } else {
            writer.write("Unresolved patient id or patient identifier for " + line);
            writer.newLine();
        }
    }
    reader.close();
    writer.close();

    InputStream inputStream = new BufferedInputStream(new FileInputStream(extendedData));

    response.setHeader("Content-Disposition", "attachment; filename=" + data.getName());
    response.setContentType("text/plain");
    FileCopyUtils.copy(inputStream, response.getOutputStream());
}

From source file:service.AdService.java

public void create(Boolean isAutherized, Long catId, String email, String phone, String price,
        MultipartFile previews[], String name, String desc, Long booleanIds[], String booleanVals[],
        Long stringIds[], String stringVals[], Long numIds[], String snumVals[], Long dateIds[],
        Date dateVals[], Long selIds[], Long selVals[], Long multyIds[], String multyVals[], Date dateFrom,
        Date dateTo, Long localIds[]) throws IOException {
    Boolean newUser = false;/*from w w w. j  a va2s . c o m*/
    if (catId != null) {
        Category cat = catDao.find(catId);
        if (cat != null) {
            if (isAutherized || (!isAutherized && email != null && !email.equals(""))) {

                PhoneEditor phe = new PhoneEditor();
                phone = phe.getPhone(phone);
                addError(phe.error);

                if ((phone == null || phone.equals("")) && (email == null || email.equals(""))) {
                    addError(
                            "  email    ? ");
                }

                User user = userService.getUserByMail(email);
                if (!isAutherized && user == null) {
                    user = userService.registerStandardUser(email);
                    newUser = true;
                    List<String> userErrors = userService.getErrors();
                    if (!userErrors.isEmpty()) {
                        for (String er : userErrors) {
                            addError("user_service: " + er + "; ");
                        }
                    }
                }
                Ad ad = new Ad();
                ad.setInsertDate(new Date());
                ad.setShowCount((long) 0);
                ad.setStatus(Ad.NEW);
                ad.setDateFrom(dateFrom);
                ad.setDateTo(dateTo);
                ad.setEmail(email);
                ad.setPhone(phone);

                ad.setAuthor(user);

                ad.setCat(cat);

                Set<Locality> locals = new HashSet();
                /*if (region != null) {
                 if (region.isAllRussia()) {
                 locals.addAll(locDao.getAll());
                 } else {
                 locals.addAll(region.getLocalities());
                 }
                 }*/
                if (localIds != null && localIds.length > 0) {
                    locals.addAll(locDao.getLocs(localIds));
                } else {
                    addError("  ?   ");
                }
                ad.setLocalities(locals);
                ad.setName(name);
                ad.setDescription(desc);
                ad.setPrice(getNumFromString(price, true));
                ad.setValues(new HashSet());
                if (validate(ad) && getErrors().isEmpty()) {
                    adDao.save(ad);

                    List<Long> reqParamIds = catDao.getRequiredParamsIds(catId);
                    List<Parametr> catParams = paramDao.getParamsFromCat(catId);
                    int i = 0;
                    ArrayList<String> paramValsErrs = new ArrayList();
                    // ? ??  ? ?  ? ??,  ?, ? ?  
                    //? ad

                    ArrayList<ParametrValue> list4Save = new ArrayList();

                    //      
                    if (booleanIds != null) {
                        if (booleanVals == null) {
                            booleanVals = new String[booleanIds.length];
                        }
                        while (i < booleanIds.length) {
                            Parametr p = paramDao.find(booleanIds[i]);
                            if (catParams.contains(p) && Parametr.BOOL == p.getParamType()) {
                                Long val = ParametrValue.NO;
                                String sval = "";
                                if (booleanVals[i] != null) {
                                    val = ParametrValue.YES;
                                    sval = "";
                                }
                                ParametrValue pv = new ParametrValue();
                                pv.setAd(ad);
                                pv.setParametr(p);
                                pv.setSelectVal(val);
                                pv.setStringVal(sval);
                                if (validate(pv)) {
                                    list4Save.add(pv);
                                }

                            }
                            i++;
                        }
                    }

                    if (stringVals != null && stringVals.length > 0) {
                        i = 0;
                        while (i < stringIds.length) {
                            Long paramId = stringIds[i];
                            Parametr p = paramDao.find(paramId);
                            if (catParams.contains(p) && Parametr.TEXT == p.getParamType()) {
                                String val = stringVals[i];
                                if (val != null && !val.equals("")) {
                                    if (reqParamIds.contains(paramId)) {
                                        reqParamIds.remove(paramId);
                                    }

                                    ParametrValue pv = new ParametrValue();
                                    pv.setAd(ad);
                                    pv.setParametr(p);
                                    pv.setStringVal(val);
                                    if (validate(pv)) {
                                        list4Save.add(pv);
                                    }

                                }
                            }
                            i++;
                        }
                    }

                    if (snumVals != null && snumVals.length > 0) {
                        i = 0;
                        while (i < numIds.length) {
                            Long paramId = numIds[i];
                            Parametr p = paramDao.find(paramId);
                            if (catParams.contains(p) && Parametr.NUM == p.getParamType()) {
                                String sval = snumVals[i];
                                if (sval != null && !sval.equals("")) {
                                    Double val = getNumFromString(sval, true);
                                    if (reqParamIds.contains(paramId)) {
                                        reqParamIds.remove(paramId);
                                    }
                                    ParametrValue pv = new ParametrValue();
                                    pv.setAd(ad);
                                    pv.setParametr(p);
                                    pv.setNumVal(val);
                                    pv.setStringVal(StringAdapter.getString(val));
                                    if (validate(pv)) {
                                        list4Save.add(pv);
                                    }

                                }
                            }
                            i++;
                        }
                        if (!getErrors().isEmpty()) {
                            for (String e : getErrors()) {
                                paramValsErrs.add(e);
                            }
                        }
                    }

                    if (dateVals != null && dateVals.length > 0) {
                        i = 0;
                        while (i < dateIds.length) {
                            Long paramId = dateIds[i];
                            Parametr p = paramDao.find(paramId);
                            if (catParams.contains(p) && Parametr.DATE == p.getParamType()) {
                                Date val = dateVals[i];
                                if (val != null) {
                                    if (reqParamIds.contains(paramId)) {
                                        reqParamIds.remove(paramId);
                                    }
                                    ParametrValue pv = new ParametrValue();
                                    pv.setAd(ad);
                                    pv.setParametr(p);
                                    pv.setDateVal(val);
                                    pv.setStringVal(DateAdapter.formatByDate(val, DateAdapter.SMALL_FORMAT));
                                    if (validate(pv)) {
                                        list4Save.add(pv);
                                    }

                                }
                            }
                            i++;
                        }
                    }

                    if (selVals != null && selVals.length > 0) {
                        i = 0;

                        while (i < selIds.length) {
                            Long paramId = selIds[i];
                            Parametr p = paramDao.find(paramId);
                            if (catParams.contains(p) && Parametr.SELECTING == p.getParamType()) {
                                Long val = selVals[i];
                                if (val != null && !val.equals(0L)) {
                                    if (reqParamIds.contains(paramId)) {
                                        reqParamIds.remove(paramId);
                                    }
                                    ParametrValue pv = new ParametrValue();
                                    pv.setAd(ad);
                                    pv.setParametr(p);
                                    pv.setSelectVal(val);
                                    pv.setStringVal(paramSelDao.find(val).getName());
                                    if (validate(pv)) {
                                        list4Save.add(pv);
                                    }

                                }
                            }
                            i++;
                        }
                    }

                    //?  ?
                    //TO DO       (??)
                    if (multyVals != null && multyVals.length > 0) {
                        for (String rawVal : multyVals) {
                            String idValArr[] = rawVal.split("_");
                            if (idValArr.length == 2) {
                                String strId = idValArr[0];
                                String strVal = idValArr[1];
                                Long paramId = Long.valueOf(strId);
                                Long val = Long.valueOf(strVal);
                                Parametr p = paramDao.find(paramId);
                                if (catParams.contains(p) && Parametr.MULTISELECTING == p.getParamType()) {
                                    if (reqParamIds.contains(paramId) && val != null) {
                                        reqParamIds.remove(paramId);
                                    }
                                    ParametrValue pv = new ParametrValue();
                                    pv.setAd(ad);
                                    pv.setParametr(p);
                                    pv.setSelectVal(val);
                                    pv.setStringVal(paramSelDao.find(val).getName());
                                    if (validate(pv)) {
                                        list4Save.add(pv);
                                    }
                                }
                            }
                        }
                    }

                    //?  ?    ?    ?
                    if (!reqParamIds.isEmpty() || !paramValsErrs.isEmpty()) {
                        for (Long id : reqParamIds) {
                            addError("    "
                                    + paramDao.find(id).getName() + "; ");
                        }
                        //?
                        adDao.delete(ad);
                    } else {

                        for (ParametrValue pv : list4Save) {
                            paramValueDao.save(pv);
                        }

                        File file = new File("/usr/local/seller/preview/" + ad.getId() + "/");
                        if (file.exists()) {
                            for (File f : file.listFiles()) {
                                f.delete();
                            }
                            file.delete();
                        }
                        file.mkdirs();
                        if (previews != null && previews.length > 0) {
                            i = 0;
                            while (i < 10 && i < previews.length) {
                                MultipartFile prev = previews[i];
                                if (prev != null && 0L < prev.getSize()) {
                                    if (prev.getSize() <= (long) 3 * 1024 * 1024) {
                                        File f = new File(
                                                "/usr/local/seller/preview/" + ad.getId() + "/supPreview");
                                        if (f.exists()) {
                                            f.delete();
                                        }
                                        prev.transferTo(f);
                                        //to do  ? - ??
                                        try {
                                            BufferedImage bi = ImageIO.read(f);
                                            BigDecimal x = BigDecimal.valueOf(0);
                                            BigDecimal y = BigDecimal.valueOf(0);
                                            BigDecimal h = BigDecimal.valueOf(bi.getHeight());
                                            BigDecimal w = BigDecimal.valueOf(bi.getWidth());
                                            if (h.compareTo(w) > 0) {
                                                y = (h.subtract(w)).divide(BigDecimal.valueOf(2),
                                                        RoundingMode.HALF_UP);
                                                h = w;
                                            } else if (h.compareTo(w) < 0) {
                                                x = (w.subtract(h)).divide(BigDecimal.valueOf(2),
                                                        RoundingMode.HALF_UP);
                                                w = h;
                                            }
                                            bi = bi.getSubimage(x.intValue(), y.intValue(), w.intValue(),
                                                    h.intValue());
                                            f.delete();
                                            f = new File("/usr/local/seller/preview/" + ad.getId() + "/" + i);
                                            ImageIO.write(bi, "png", f);
                                        } catch (Exception e) {
                                            addError(
                                                    "? ?   "
                                                            + prev.getName()
                                                            + /*"; s="+prev.getSize()+"; t="+prev.getContentType()+"; l="+previews.length+*/ "; "
                                                            + StringAdapter.getStackTraceException(e));
                                        }
                                    } else {
                                        addError(" " + prev.getName()
                                                + "   ,      ?  3 .");
                                    }
                                }
                                i++;
                            }
                        }

                        if (newUser) {
                            userService.notifyAboutRegistration(email);
                        }
                    }

                } /* else {
                  addError("user:" + user.getId() + " " + user.getName());
                  }*/

            } else {
                addError(
                        "?  ??     email");
            }
        } else {
            addError("? ?  " + catId + "   .");
        }
    } else {
        addError("?  ");
    }
}

From source file:org.openmrs.module.dhisconnector.api.impl.DHISConnectorServiceImpl.java

@SuppressWarnings("rawtypes")
@Override//www  .  jav a  2  s.  c o m
public String uploadMappings(MultipartFile mapping) {
    String msg = "";
    String tempFolderName = OpenmrsUtil.getApplicationDataDirectory() + DHISCONNECTOR_TEMP_FOLDER
            + File.separator;
    String mappingFolderName = OpenmrsUtil.getApplicationDataDirectory() + DHISCONNECTOR_MAPPINGS_FOLDER
            + File.separator;
    String mappingName = mapping.getOriginalFilename();

    if (mappingName.endsWith(".zip")) {
        boolean allFailed = true;
        File tempMappings = new File(tempFolderName + mappingName);

        (new File(tempFolderName)).mkdirs();
        try {
            mapping.transferTo(tempMappings);

            try {
                ZipFile zipfile = new ZipFile(tempMappings);

                for (Enumeration e = zipfile.entries(); e.hasMoreElements();) {
                    ZipEntry entry = (ZipEntry) e.nextElement();

                    if (entry.isDirectory()) {
                        System.out.println("Incorrect file (Can't be a folder instead): " + entry.getName()
                                + " has been ignored");
                    } else if (entry.getName().endsWith(DHISCONNECTOR_MAPPING_FILE_SUFFIX)) {
                        File outputFile = new File(mappingFolderName, entry.getName());

                        if (outputFile.exists()) {
                            System.out.println(
                                    "File: " + outputFile.getName() + " already exists and has been ignored");
                        } else {
                            BufferedInputStream inputStream = new BufferedInputStream(
                                    zipfile.getInputStream(entry));
                            BufferedOutputStream outputStream = new BufferedOutputStream(
                                    new FileOutputStream(outputFile));

                            try {
                                System.out.println("Extracting: " + entry);
                                IOUtils.copy(inputStream, outputStream);
                                allFailed = false;
                            } finally {
                                outputStream.close();
                                inputStream.close();
                            }
                        }
                    } else {
                        System.out.println("Incorrect file: " + entry.getName() + " has been ignored");
                    }
                }
                if (!allFailed) {
                    msg = Context.getMessageSourceService()
                            .getMessage("dhisconnector.uploadMapping.groupSuccess");
                } else {
                    msg = Context.getMessageSourceService().getMessage("dhisconnector.uploadMapping.allFailed");
                }
                FileUtils.deleteDirectory(new File(tempFolderName));
            } catch (Exception e) {
                System.out.println("Error while extracting file:" + mapping.getName() + " ; " + e);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } else if (mappingName.endsWith(DHISCONNECTOR_MAPPING_FILE_SUFFIX)) {
        try {
            File uploadedMapping = new File(mappingFolderName + mappingName);
            if (uploadedMapping.exists()) {
                msg = Context.getMessageSourceService().getMessage("dhisconnector.uploadMapping.exists");
            } else {
                mapping.transferTo(uploadedMapping);
                msg = Context.getMessageSourceService().getMessage("dhisconnector.uploadMapping.singleSuccess");
            }

        } catch (IllegalStateException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } else {
        msg = Context.getMessageSourceService().getMessage("dhisconnector.uploadMapping.wrongType");
    }

    return msg;
}