Example usage for org.springframework.dao DuplicateKeyException DuplicateKeyException

List of usage examples for org.springframework.dao DuplicateKeyException DuplicateKeyException

Introduction

In this page you can find the example usage for org.springframework.dao DuplicateKeyException DuplicateKeyException.

Prototype

public DuplicateKeyException(String msg) 

Source Link

Document

Constructor for DuplicateKeyException.

Usage

From source file:edu.pitt.dbmi.ccd.anno.group.GroupController.java

/**
 * Edit group//from  ww  w .j  a v a 2s.co m
 *
 * @param name group name
 * @return group
 */
@RequestMapping(value = GroupLinks.GROUP, method = RequestMethod.PUT)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public GroupResource editGroup(@AuthenticationPrincipal UserAccountDetails principal, @PathVariable String name,
        @RequestBody @Valid GroupForm form)
        throws NotFoundException, DuplicateKeyException, ForbiddenException, ConstraintViolationException {
    UserAccount requester = principal.getUserAccount();
    final Group group = groupService.findByName(name);
    if (group == null) {
        throw new GroupNotFoundException(name);
    }
    if (group.getModerators().stream().map(UserAccount::getId).anyMatch(u -> u.equals(requester.getId()))) {
        final String newName = form.getName();
        final String newDescription = form.getDescription();
        if (!group.getName().equalsIgnoreCase(newName)) {
            if (groupService.findByName(newName) != null) {
                throw new DuplicateKeyException("Group already exists with name: " + newName);
            }
        }
        group.setName(newName);
        if (!group.getDescription().equalsIgnoreCase(newDescription)) {
            group.setDescription(newDescription);
        }
        final Group updated = groupService.save(group);
        final GroupResource resource = assembler.toResource(updated);
        return resource;
    } else {
        throw new ForbiddenException(requester, request);
    }
}

From source file:edu.pitt.dbmi.ccd.anno.group.GroupController.java

/**
 * Patch group//from  w  w w.  ja v  a  2  s. c  o m
 *
 * @param principal [description]
 * @param name [description]
 * @param form [description]
 * @return [description]
 */
@RequestMapping(value = GroupLinks.GROUP, method = RequestMethod.PATCH)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public GroupResource patchGroup(@AuthenticationPrincipal UserAccountDetails principal,
        @PathVariable String name, @RequestBody GroupForm form)
        throws NotFoundException, DuplicateKeyException, ConstraintViolationException {
    UserAccount requester = principal.getUserAccount();
    final Group group = groupService.findByName(name);
    if (group == null) {
        throw new GroupNotFoundException(name);
    }
    if (group.getModerators().stream().map(UserAccount::getId).anyMatch(u -> u.equals(requester.getId()))) {
        final String newName = form.getName();
        final String newDescription = form.getDescription();
        if (!isEmpty(newName) && !group.getName().equalsIgnoreCase(newName)) {
            if (groupService.findByName(newName) != null) {
                throw new DuplicateKeyException("Group already exists with name: " + newName);
            }
            group.setName(newName);
        }
        if (!isEmpty(newDescription) && !group.getDescription().equalsIgnoreCase(newDescription)) {
            group.setDescription(newDescription);
        }
        final Group patched = groupService.save(group);
        final GroupResource resource = assembler.toResource(patched);
        return resource;
    } else {
        throw new ForbiddenException(requester, request);
    }
}

From source file:com.poscoict.license.service.ManagementService.java

@SuppressWarnings("unchecked")
public void newContract(ContractPersonInfo per, ContractProductInfo pro, String[] etcFile, HttpSession session)
        throws UserException {
    logger.info("newContract");
    TransactionStatus status = this.transactionManager.getTransaction(new DefaultTransactionDefinition());
    try {//from ww w  .jav a2  s.  com
        System.out.println("company: " + per.getORDER_COMPANY_CODE());
        String licenseUpPath = Consts.LICENSE_FILE_HOME;

        String userNo = per.getUSER_NO();

        if (pro != null) {
            ArrayList<MultipartFile> upFileList = (ArrayList<MultipartFile>) pro.getFile();
            ArrayList<String> productList = (ArrayList<String>) pro.getPRODUCT_FILE_ID();
            ArrayList<String> licenseKeyList = (ArrayList<String>) pro.getLICENSE_KEY();
            ArrayList<String> quantityList = (ArrayList<String>) pro.getLICENSE_QUANTITY();
            ArrayList<String> fileCheckList = (ArrayList<String>) pro.getCHECKBOX();

            for (int i = 0; i < productList.size(); i++) {
                String licensePath = "";

                String licenseName = "";
                String objectId = productList.get(i);
                String licenseKey = licenseKeyList.get(i);
                String quantity = quantityList.get(i);
                String fileCheck = fileCheckList.get(i);
                if (fileCheck.equals("false")) {
                    MultipartFile upFile = upFileList.get(i);
                    licenseName = upFile.getOriginalFilename(); // ???
                    logger.info("newContract: fileName= " + licenseName);
                    try {
                        File upfile = new File(licenseUpPath + userNo + File.separator + licenseName);

                        if (upfile.isFile())
                            throw new UserException(
                                    "???? . ??  .");

                        if (!upfile.exists())
                            upfile.mkdirs();

                        upFile.transferTo(upfile);
                        licensePath = upfile.getAbsolutePath();
                        logger.info("newContract: licensePath= " + licensePath);
                    } catch (IOException e) {
                        logger.error("newContract(File Upload Error): ", e);
                    }
                    // ?? 
                }
                managementDao.addLicenseInfo(userNo, licenseKey, objectId,
                        (String) session.getAttribute("USER_NO"), licensePath, licenseName, quantity);
            }
        }
        if (etcFile != null) {
            for (int i = 0; i < etcFile.length; i++) {
                String etcId = etcFile[i];
                managementDao.addUserEtcFileInfo(userNo, etcId, (String) session.getAttribute("USER_NO"));
            }
        }

        //  
        managementDao.addUser(per, (String) session.getAttribute("USER_NO"), passwordEncoder(userNo),
                Consts.USERLV_PUBLIC);
        //   
        Map<String, Object> map = getClientPermission();
        String codes = (String) map.get("codes");
        String codeTypes = (String) map.get("codeTypes");
        int size = (Integer) map.get("size");

        logger.info("codes : " + codes);
        logger.info("codeTypes : " + codeTypes);
        logger.info("size : " + size);
        logger.info("userNo : " + userNo);

        managementDao.insert_user_permission(codes, codeTypes, userNo, size);

        // ??  ??
        if (!per.getPRODUCT_SETUP_DATE().isEmpty()) {
            managementDao.updateProductSetupDate(userNo, per.getPRODUCT_SETUP_DATE());
        }
        this.transactionManager.commit(status);
    } catch (DuplicateKeyException e) {
        this.transactionManager.rollback(status);
        logger.error("plusProduct: ", e);
        throw new DuplicateKeyException(
                " ?. ?? ? .");
    } catch (RuntimeException e) {
        this.transactionManager.rollback(status);
        logger.error("plusProduct: ", e);
    }

    //        return "redirect:/management";
}

From source file:com.poscoict.license.service.ManagementService.java

public void modifyProduct(String userNo, String licenseKey, String productFileId, String newLicenseKey,
        String licenseQuantity, String selectFile, String checkBox, MultipartFile file, HttpSession session)
        throws UserException {
    logger.info("modifyProduct: userNo= " + userNo + " PRODUCT_FILE_ID= " + productFileId);
    TransactionStatus status = this.transactionManager.getTransaction(new DefaultTransactionDefinition());
    String licenseUpPath = Consts.LICENSE_FILE_HOME;

    try {//from ww  w .ja v  a  2 s .c  o  m
        String oldLiscensePath = managementDao.getLicensePath2(licenseKey, userNo);
        managementDao.updateInstallFilName((String) session.getAttribute("USER_NO"), userNo, licenseKey);
        managementDao.updateProductInfo(userNo, newLicenseKey, productFileId, licenseQuantity,
                (String) session.getAttribute("USER_NO"), licenseKey);
        if (selectFile.equals("change")) {
            String path = "";
            String licenseName = "";

            if (checkBox == null) {
                MultipartFile upFile = file;
                licenseName = upFile.getOriginalFilename(); // ???
                try {

                    File upfile = new File(licenseUpPath + userNo + File.separator + licenseName);
                    if (upfile.isFile())
                        throw new UserException(
                                "???? . ??  .");

                    if (!upfile.exists())
                        upfile.mkdirs();

                    upFile.transferTo(upfile);
                    path = upfile.getAbsolutePath();
                    logger.info("modifyProduct: upFileName= " + licenseName + " path= " + path);
                } catch (IOException e) {
                    logger.error("modifyProduct(File Upload Error): ", e);
                }
            }
            managementDao.updateLicenseInfo(userNo, licenseKey, licenseName, path,
                    (String) session.getAttribute("USER_NO"));

            // ?? ? 
            File oldLicenseFile = new File(oldLiscensePath);
            if (oldLicenseFile.exists())
                oldLicenseFile.delete();
        }
        this.transactionManager.commit(status);
    } catch (DuplicateKeyException e) {
        this.transactionManager.rollback(status);
        logger.error("plusProduct: ", e);
        throw new DuplicateKeyException(
                " ?. ?? ? .");
    } catch (RuntimeException e) {
        this.transactionManager.rollback(status);
        logger.error("plusProduct: ", e);
    }
}

From source file:com.poscoict.license.service.ManagementService.java

public String modifyProfile(ContractPersonInfo info, String oldUserNo, String[] etcFile, HttpSession session) {
    logger.info("modifyProfile: oldUserNo= " + oldUserNo);
    logger.info("modifyProfile: etcFile= " + etcFile);
    TransactionStatus status = this.transactionManager.getTransaction(new DefaultTransactionDefinition());
    try {/*from ww w .  j a v a 2 s.co m*/
        managementDao.updateProductSetupDate(oldUserNo,
                info.getPRODUCT_SETUP_DATE().isEmpty() ? null : info.getPRODUCT_SETUP_DATE());
        managementDao.updateProfileInfo(info, oldUserNo, (String) session.getAttribute("USER_NO"));

        if (!info.getUSER_NO().equals(oldUserNo)) {
            System.out.println("update USER_NO");
            managementDao.updateLicenseUserNo(info.getUSER_NO(), oldUserNo,
                    (String) session.getAttribute("USER_NO"));
        }

        managementDao.deleteUserEtcFileInfo(oldUserNo);
        if (etcFile != null) {
            for (int i = 0; i < etcFile.length; i++) {
                String objectId = etcFile[i];
                managementDao.addUserEtcFileInfo(info.getUSER_NO(), objectId,
                        (String) session.getAttribute("USER_NO"));
            }
        }

        this.transactionManager.commit(status);
    } catch (DuplicateKeyException e) {
        this.transactionManager.rollback(status);
        logger.error("plusProduct: ", e);
        throw new DuplicateKeyException(
                " ?. ?? ? .");
    } catch (RuntimeException e) {
        this.transactionManager.rollback(status);
        logger.error("plusProduct: ", e);
    }
    return info.getUSER_NO();
}

From source file:com.poscoict.license.service.ManagementService.java

@SuppressWarnings("unchecked")
public String plusProduct(ContractProductInfo info, String userNo, HttpSession session) throws UserException {
    logger.info("plusProduct: userNo= " + userNo);
    TransactionStatus status = this.transactionManager.getTransaction(new DefaultTransactionDefinition());
    try {/*from   w w  w . j a v  a  2 s .  co  m*/
        String licenseUpPath = Consts.LICENSE_FILE_HOME;
        if (info != null) {
            ArrayList<MultipartFile> upFileList = (ArrayList<MultipartFile>) info.getFile();
            ArrayList<String> proIdList = (ArrayList<String>) info.getPRODUCT_FILE_ID();
            ArrayList<String> licenseKeyList = (ArrayList<String>) info.getLICENSE_KEY();
            ArrayList<String> quantityList = (ArrayList<String>) info.getLICENSE_QUANTITY();
            ArrayList<String> fileCheckList = (ArrayList<String>) info.getCHECKBOX();
            for (int i = 0; i < proIdList.size(); i++) {
                String path = "";
                String licenseName = ""; // ???

                String objectId = proIdList.get(i);
                String licenseKey = licenseKeyList.get(i);
                String quantity = quantityList.get(i);
                String fileCheck = fileCheckList.get(i);

                if (fileCheck.equals("false")) {
                    try {
                        MultipartFile upFile = upFileList.get(i);
                        licenseName = upFile.getOriginalFilename(); // ???

                        File upfile = new File(licenseUpPath + userNo + File.separator + licenseName);
                        if (upfile.isFile())
                            throw new UserException(
                                    "???? . ??  .");

                        if (!upfile.exists())
                            upfile.mkdirs();

                        upFile.transferTo(upfile);
                        path = upfile.getAbsolutePath();
                        logger.info("plusProduct: upFileName= " + licenseName + " path= " + path);
                    } catch (IOException e) {
                        logger.error("plusProduct(File Upload Error): ", e);
                    }
                }

                // ?? 
                managementDao.addLicenseInfo(userNo, licenseKey, objectId,
                        (String) session.getAttribute("USER_NO"), path, licenseName, quantity);
            }
        }
        this.transactionManager.commit(status);
    } catch (DuplicateKeyException e) {
        this.transactionManager.rollback(status);
        logger.error("plusProduct: ", e);
        throw new DuplicateKeyException(
                " ?. ?? ? .");
    } catch (RuntimeException e) {
        this.transactionManager.rollback(status);
        logger.error("plusProduct: ", e);
    }

    return userNo;
}

From source file:com.poscoict.license.service.ManagementService.java

public String addOrderCompany(ContractPersonInfo info, String admin) throws Exception {
    logger.debug("getVersionList- addCompany: " + info.getUSER_NO());
    TransactionStatus status = this.transactionManager.getTransaction(new DefaultTransactionDefinition());
    info.setPROJECT_NAME("");

    try {/*  w w w  .j av  a  2s.  c  om*/
        int cnt = managementDao.orderCompanyCount();
        String sortString = sortOrder(cnt + 1);
        managementDao.addOrderCompany(sortString, info.getUSER_NAME(), info.getUSER_NO(), admin);
        managementDao.addOrderCompanyInfo(info, passwordEncoder(info.getUSER_NO()), Consts.USERLV_ORDER_COMPANY,
                admin);

        Map<String, Object> map = getOrderCompanyPermission();
        String codes = (String) map.get("codes");
        String codeTypes = (String) map.get("codeTypes");
        int size = (Integer) map.get("size");
        managementDao.insert_user_permission(codes, codeTypes, info.getUSER_NO(), size);

        this.transactionManager.commit(status);
    } catch (NullPointerException e) {
        this.transactionManager.rollback(status);
        logger.error("addCompany: ", e);
        throw new NullPointerException("?  - NullPointerException");
    } catch (DuplicateKeyException e) {
        this.transactionManager.rollback(status);
        logger.error("plusProduct: ", e);
        throw new DuplicateKeyException(
                " ?. ?? ? .");
    } catch (Exception e) {
        this.transactionManager.rollback(status);
        logger.error("addCompany: ", e);
        throw new UserException("? ");
    }

    String msg = "(" + info.getUSER_NAME() + ") ?";
    return msg;
}

From source file:com.poscoict.license.service.ManagementService.java

public void upload(String folder, String packageVersion, MultipartFile file, String comment, String mode,
        HttpSession session) throws Exception {
    TransactionStatus status = transactionManager.getTransaction(new DefaultTransactionDefinition());
    try {/*from  w ww.  j  a va  2  s. co  m*/
        String folderPath = getFolderPath(folder);
        String objectId = "";
        if (mode.equals("package")) {
            if (packageVersion != null && packageVersion != "") {
                folderPath += packageVersion + File.separator;
                objectId = "pk_" + attachFileDateFormat()
                        + UUID.randomUUID().toString().replaceAll("-", "").substring(0, 12);
            }
        } else {
            folderPath += packageVersion + File.separator + "patch" + File.separator;
            objectId = "pt_" + attachFileDateFormat()
                    + UUID.randomUUID().toString().replaceAll("-", "").substring(0, 12);
            ;
        }

        MultipartFile upFile = file;
        String fileName = null;
        if (upFile != null) {
            fileName = upFile.getOriginalFilename();
            System.out.println("up: fileName: " + fileName + " " + folderPath);
            if (mode.equals("package")) {
                managementDao.addFileInfo(objectId, folder, folder.equals("etc") ? fileName : packageVersion,
                        fileName, comment.replaceAll("\n", "<br>"), folderPath + fileName,
                        (String) session.getAttribute("USER_NO"));
            } else {
                String pObjectId = managementDao.getProductKey(folder, packageVersion);
                managementDao.addPatchFileInfo(objectId, pObjectId, folder, packageVersion, fileName,
                        comment.replaceAll("\n", "<br>"), folderPath + fileName,
                        (String) session.getAttribute("USER_NO"));
            }
            try {
                File ufile = new File(folderPath + fileName);

                if (ufile.isFile()) {
                    logger.error("upload- Duplicate FileName: " + folderPath + fileName);
                    throw new UserException(
                            "???? . ??  .");
                }

                if (!ufile.exists()) {
                    ufile.mkdirs();
                }
                upFile.transferTo(ufile);
            } catch (IOException e) {
                e.printStackTrace();
                logger.error("packageUpload/patchUpload(File Upload Error): ", e);
                throw new IOException();
            }
        }
        this.transactionManager.commit(status);
    } catch (DuplicateKeyException e) {
        this.transactionManager.rollback(status);
        logger.error("packageUpload/patchUpload(File Upload Error): ", e);
        throw new DuplicateKeyException(
                " ?. ?? ? .");
    } catch (Exception e) {
        this.transactionManager.rollback(status);
        logger.error("packageUpload/patchUpload(File Upload Error): ", e);
        throw new Exception(e);
    }
}

From source file:org.springframework.integration.cluster.redis.ClusterStatusRepositoryImpl.java

public void create(ClusterStatus clusterStatus) {
    String applicationId = clusterStatus.getApplicationId();
    this.lockHandler.acquireLock(applicationId, this.instanceInfo);
    ClusterStatus status = statusTemplate.opsForValue().get(applicationId);
    if (status != null) {
        throw new DuplicateKeyException("Cluster status already exists for application " + applicationId);
    }//w ww  .jav  a2  s.c  o m
    statusTemplate.opsForValue().set(applicationId, clusterStatus);
    this.lockHandler.relinquishLock(applicationId, this.instanceInfo);
}

From source file:org.yes.cart.service.vo.impl.VoCustomerServiceImpl.java

/**
 * {@inheritDoc}/*from ww  w. j a va 2  s . c  o  m*/
 */
public VoCustomer create(final VoCustomer vo) throws Exception {

    final List<CustomerDTO> existing = dtoCustomerService.findCustomer(vo.getEmail(), null, null, null, null,
            null, null);
    final Map<String, Set<Long>> registered = new HashMap<>();
    if (!existing.isEmpty()) {
        for (final CustomerDTO existingDto : existing) {
            final Map<ShopDTO, Boolean> shops = dtoCustomerService.getAssignedShop(existingDto.getCustomerId());
            final Set<Long> shopIds = new HashSet<>();
            for (final ShopDTO shopDTO : shops.keySet()) {
                shopIds.add(shopDTO.getShopId());
            }
            if (registered.containsKey(existingDto.getEmail())) {
                registered.get(existingDto.getEmail()).addAll(shopIds);
            } else {
                registered.put(existingDto.getEmail(), shopIds);
            }
        }
    }

    if (CollectionUtils.isNotEmpty(vo.getCustomerShops())) {

        final Set<Long> alreadyRegistered = registered.get(vo.getEmail());

        for (final VoCustomerShopLink link : vo.getCustomerShops()) {
            if (!federationFacade.isShopAccessibleByCurrentManager(link.getShopId())) {
                throw new AccessDeniedException("Access is denied");
            }
            if (alreadyRegistered != null && alreadyRegistered.contains(link.getShopId())) {
                throw new DuplicateKeyException(
                        vo.getEmail() + " is already registered in " + link.getShopId());
            }
        }
    } else {
        throw new AccessDeniedException("Access is denied");
    }

    CustomerDTO customerDTO = voAssemblySupport.assembleDto(CustomerDTO.class, VoCustomerInfo.class,
            dtoCustomerService.getNew(), vo);
    customerDTO.setEmail(vo.getEmail());
    customerDTO = dtoCustomerService.createForShop(customerDTO, vo.getCustomerShops().get(0).getShopId());

    for (final VoCustomerShopLink link : vo.getCustomerShops()) {
        dtoCustomerService.grantShop(customerDTO.getCustomerId(), link.getShopId(), false);
    }

    return getById(customerDTO.getCustomerId());
}