/**
   * Tests <code>{@link CopilotProjectDAOImpl#retrieveAll()}</code> method.
   *
   * @throws CopilotDAOException if any error occurs
   */
  @Test
  public void testRetrieveAll2() throws CopilotDAOException {

    CopilotProfile copilotProfile1 = TestHelper.createCopilotProfile();
    CopilotProject copilotProject1 = TestHelper.createCopilotProject();

    TestHelper.persistCopilotProjectDependencies(
        hibernateTemplate, copilotProfile1, copilotProject1);
    hibernateTemplate.save(copilotProject1);

    CopilotProfile copilotProfile2 = TestHelper.createCopilotProfile();
    CopilotProject copilotProject2 = TestHelper.createCopilotProject();

    TestHelper.persistCopilotProjectDependencies(
        hibernateTemplate, copilotProfile2, copilotProject2);
    hibernateTemplate.save(copilotProject2);

    List<CopilotProject> result = instance.retrieveAll();

    Assert.assertEquals("Two entities were expected.", 2, result.size());
    assertCopilotProject(copilotProject1, result.get(0));
    assertCopilotProject(copilotProject2, result.get(1));

    hibernateTemplate.delete(copilotProject1);

    result = instance.retrieveAll();

    Assert.assertEquals("One entity was expected.", 1, result.size());
    assertCopilotProject(copilotProject2, result.get(0));

    hibernateTemplate.delete(copilotProject2);

    Assert.assertEquals("No entities were expected.", 0, instance.retrieveAll().size());
  }
  /**
   * Tests <code>{@link CopilotProjectDAOImpl#getCopilotProjects(long)}</code> method.
   *
   * @throws CopilotDAOException if any error occurs
   */
  @Test
  public void testGetCopilotProjects1() throws CopilotDAOException {

    CopilotProfile copilotProfile1 = TestHelper.createCopilotProfile();
    CopilotProject copilotProject1 = TestHelper.createCopilotProject();

    TestHelper.persistCopilotProjectDependencies(
        hibernateTemplate, copilotProfile1, copilotProject1);
    hibernateTemplate.save(copilotProject1);

    CopilotProfile copilotProfile2 = TestHelper.createCopilotProfile();
    CopilotProject copilotProject2 = TestHelper.createCopilotProject();

    TestHelper.persistCopilotProjectDependencies(
        hibernateTemplate, copilotProfile2, copilotProject2);
    hibernateTemplate.save(copilotProject2);

    List<CopilotProject> result =
        instance.getCopilotProjects(copilotProject1.getCopilotProfileId());

    Assert.assertEquals("Only one result was expected.", 1, result.size());
    assertCopilotProject(copilotProject1, result.get(0));

    result = instance.getCopilotProjects(copilotProject2.getCopilotProfileId());

    Assert.assertEquals("Only one result was expected.", 1, result.size());
    assertCopilotProject(copilotProject2, result.get(0));
  }
  /**
   * Tests <code>{@link CopilotProjectDAOImpl#delete(long)}</code> method.
   *
   * @throws CopilotDAOException if any error occurs
   */
  @Test
  @SuppressWarnings("unchecked")
  public void testDelete2() throws CopilotDAOException {

    CopilotProfile copilotProfile = TestHelper.createCopilotProfile();
    CopilotProject copilotProject = TestHelper.createCopilotProject();

    TestHelper.persistCopilotProjectDependencies(hibernateTemplate, copilotProfile, copilotProject);

    CopilotProjectInfoType copilotProjectInfoType = TestHelper.createCopilotProjectInfoType();
    hibernateTemplate.save(copilotProjectInfoType);

    CopilotProjectInfo copilotProjectInfo = TestHelper.createCopilotProjectInfo();
    copilotProjectInfo.setCopilotProjectId(copilotProject.getId());
    copilotProjectInfo.setInfoType(copilotProjectInfoType);
    copilotProject.getProjectInfos().add(copilotProjectInfo);
    hibernateTemplate.save(copilotProject);

    instance.delete(copilotProject.getId());

    Assert.assertEquals(
        "None entity in database should exist.",
        0,
        hibernateTemplate.find("from CopilotProject").size());
    Assert.assertEquals(
        "None entity in database should exist.",
        0,
        hibernateTemplate.find("from CopilotProjectInfo").size());
  }
  /**
   * Tests <code>{@link CopilotProjectDAOImpl#retrieve(long)}</code> method.
   *
   * @throws CopilotDAOException if any error occurs
   */
  @Test
  public void testRetrieve1() throws CopilotDAOException {

    CopilotProfile copilotProfile1 = TestHelper.createCopilotProfile();
    CopilotProject copilotProject1 = TestHelper.createCopilotProject();

    TestHelper.persistCopilotProjectDependencies(
        hibernateTemplate, copilotProfile1, copilotProject1);
    hibernateTemplate.save(copilotProject1);

    CopilotProfile copilotProfile2 = TestHelper.createCopilotProfile();
    CopilotProject copilotProject2 = TestHelper.createCopilotProject();

    TestHelper.persistCopilotProjectDependencies(
        hibernateTemplate, copilotProfile2, copilotProject2);
    hibernateTemplate.save(copilotProject2);

    CopilotProject result = instance.retrieve(copilotProject1.getId());

    assertCopilotProject(copilotProject1, result);

    result = instance.retrieve(copilotProject2.getId());

    assertCopilotProject(copilotProject2, result);
  }
  protected void handleActionRequestInternal(ActionRequest request, ActionResponse response)
      throws Exception {

    Integer relTypeId = null;
    try {
      relTypeId = Integer.valueOf(request.getParameter("relTypeId"));
    } catch (Exception ex) {
      throw new RuntimeException(
          "Error getting relationship type ID from request: " + ex.getMessage(), ex);
    }
    CatalogEntryRelationshipType relType = getCatalogEntryRelationshipTypeDao().getById(relTypeId);
    if (relType == null) {
      throw new RuntimeException("Couldn't find relationship type for id: " + relTypeId);
    }
    HibernateTemplate templ = getCatalogEntryRelationshipTypeDao().getHibernateTemplate();
    CatalogEntryRoleType roleTypeA = relType.getRoleTypeA();
    roleTypeA.setRelationshipType(null);
    relType.setRoleTypeA(null);
    templ.save(roleTypeA);

    CatalogEntryRoleType roleTypeB = relType.getRoleTypeB();
    roleTypeB.setRelationshipType(null);
    relType.setRoleTypeB(null);
    templ.save(roleTypeB);

    templ.save(relType);

    templ.delete(roleTypeA);
    templ.delete(roleTypeB);
    templ.delete(relType);
    getCatalogEntryRelationshipTypeDao().getHibernateTemplate().flush();
    getUserModel().setCurrentRelationshipType(null);
  }
  /**
   * Tests <code>{@link
   * CopilotProjectDAOImpl#update(com.topcoder.direct.services.copilot.model.IdentifiableEntity)}
   * </code> method.
   *
   * @throws CopilotDAOException if any error occurs
   */
  @Test
  @SuppressWarnings("unchecked")
  public void testUpdate() throws CopilotDAOException {

    CopilotProfile copilotProfile = TestHelper.createCopilotProfile();
    CopilotProject copilotProject = TestHelper.createCopilotProject();

    TestHelper.persistCopilotProjectDependencies(hibernateTemplate, copilotProfile, copilotProject);
    hibernateTemplate.save(copilotProject);

    copilotProject.setCompletionDate(new Date());
    copilotProject.setCustomerFeedback("test customer feedback");
    copilotProject.setCustomerRating(0.9F);
    copilotProject.setPmFeedback("test pm feedback");
    copilotProject.setPmRating(0.9F);

    CopilotProjectInfoType copilotProjectInfoType = TestHelper.createCopilotProjectInfoType();
    hibernateTemplate.save(copilotProjectInfoType);

    CopilotProjectInfo copilotProjectInfo = TestHelper.createCopilotProjectInfo();
    copilotProjectInfo.setInfoType(copilotProjectInfoType);
    copilotProject.getProjectInfos().add(copilotProjectInfo);

    instance.update(copilotProject);

    List<CopilotProject> result =
        (List<CopilotProject>)
            hibernateTemplate.find("from CopilotProject where id = ?", copilotProject.getId());

    assertCopilotProject(copilotProject, result.get(0));
  }
示例#7
0
 /**
  * creates user in database
  *
  * @param user user reference
  */
 @Override
 public User create(User user) {
   Page page = new Page();
   hibernateTemplate.save(page);
   user.setPageId(page.getPageId());
   hibernateTemplate.save(user);
   return user;
 }
  @Before
  public void setUp() {
    t = new HibernateTemplate(sess);

    brh = new UserProfile("brh", 12.);
    admin = new UserProfile("admin", 10., Boolean.TRUE);

    t.save(brh);
    t.save(admin);
  }
  /**
   * Tests <code>{@link CopilotProjectDAOImpl#getCopilotProjects(long)}</code> method.
   *
   * @throws CopilotDAOException if any error occurs
   */
  @Test
  public void testGetCopilotProjects2() throws CopilotDAOException {

    CopilotProfile copilotProfile = TestHelper.createCopilotProfile();
    CopilotProject copilotProject1 = TestHelper.createCopilotProject();
    CopilotProject copilotProject2 = TestHelper.createCopilotProject();

    hibernateTemplate.save(copilotProfile.getStatus());
    hibernateTemplate.save(copilotProfile);

    copilotProject1.setCopilotProfileId(copilotProfile.getId());
    hibernateTemplate.save(copilotProject1.getStatus());
    hibernateTemplate.save(copilotProject1.getCopilotType());
    hibernateTemplate.save(copilotProject1);

    copilotProject2.setCopilotProfileId(copilotProfile.getId());
    hibernateTemplate.save(copilotProject2.getStatus());
    hibernateTemplate.save(copilotProject2.getCopilotType());
    hibernateTemplate.save(copilotProject2);

    List<CopilotProject> result =
        instance.getCopilotProjects(copilotProject1.getCopilotProfileId());

    Assert.assertEquals("Two results were expected.", 2, result.size());
    assertCopilotProject(copilotProject1, result.get(0));
    assertCopilotProject(copilotProject2, result.get(1));
  }
示例#10
0
  /*
   * Adding a new Shipping Address
   */
  public void addAddress(AddressVO addAddressBean, String userId) throws SapeStoreException {

    // addAddressBean.setAddressId(123456);
    LOGGER.debug(" AddressDao.addNewAddress method: START");
    try {
      Address address = new Address();
      address.setAddressId(addAddressBean.getAddressId());
      address.setUserId(userId);
      address.setStateId(addAddressBean.getStateId());
      address.setCityId(addAddressBean.getCityId());
      address.setCountryId(addAddressBean.getCountryId());
      address.setAddressLine1(addAddressBean.getAddressLine1());
      address.setAddressLine2(addAddressBean.getAddressLine2());
      address.setPostalCode(addAddressBean.getPostalCode());
      address.setCreatedDate(new java.util.Date());
      address.setUpdatedDate(new java.util.Date());
      address.setPhone(addAddressBean.getPhone());
      address.setIsActive(addAddressBean.getIsActive());
      address.setName(addAddressBean.getName());

      hibernateTemplate.save(address);
      LOGGER.debug(" Address is added ");
    } catch (SapeStoreSystemException se) {
      LOGGER.fatal("A DB exception occured while inserting the address's information", se);
    }
    LOGGER.debug(" AddressDao.addNewAddresss method: END ");
  }
  public void saveDocumentMapping(JSONObject jobj) throws ServiceException {
    try {
      Docmap docMap = new Docmap();

      if (jobj.has("docid") && !StringUtil.isNullOrEmpty(jobj.getString("docid"))) {
        Docs doc = (Docs) hibernateTemplate.get(Docs.class, jobj.getString("docid"));
        docMap.setDocid(doc);
        if (jobj.has("companyid") && !StringUtil.isNullOrEmpty(jobj.getString("companyid"))) {
          Company company =
              (Company) hibernateTemplate.get(Company.class, jobj.getString("companyid"));
          doc.setCompany(company);
        }
        if (jobj.has("userid") && !StringUtil.isNullOrEmpty(jobj.getString("userid"))) {
          User user = (User) hibernateTemplate.get(User.class, jobj.getString("userid"));
          doc.setUserid(user);
        }
      }
      if (jobj.has("refid")) {
        docMap.setRecid(jobj.getString("refid"));
      }
      if (jobj.has("map")) {
        docMap.setRelatedto(jobj.getString("map"));
      }
      hibernateTemplate.save(docMap);
    } catch (Exception ex) {
      throw ServiceException.FAILURE("documentDAOImpl.saveDocumentMapping", ex);
    }
  }
示例#12
0
 // 添加消息 根据类型添加类型1 普通消息 2帖子消息 3 活动消息
 public boolean saveMessage(Message message) {
   Integer id = (Integer) hibernateTemplate.save(message);
   if (id > 0) {
     return true;
   }
   return false;
 }
  /**
   * Tests <code>{@link CopilotProjectDAOImpl#getCopilotProjects(long)}</code> method.
   *
   * <p>{@link CopilotDAOException} is expected.
   *
   * @throws CopilotDAOException if any error occurs
   */
  @Test(expected = CopilotDAOException.class)
  public void testGetCopilotProjectsFailure2() throws CopilotDAOException {

    CopilotProject copilotProject = TestHelper.createCopilotProject();

    hibernateTemplate.save(copilotProject);

    instance.getCopilotProjects(1L);
  }
  /**
   * Tests <code>{@link
   * CopilotProjectDAOImpl#create(com.topcoder.direct.services.copilot.model.IdentifiableEntity)}
   * </code> method.
   *
   * <p>{@link CopilotDAOException} is expected.
   *
   * @throws CopilotDAOException if any error occurs
   */
  @Test(expected = CopilotDAOException.class)
  public void testCreateFailure1() throws CopilotDAOException {

    CopilotProject copilotProject = TestHelper.createCopilotProject();
    copilotProject.setId(1);
    hibernateTemplate.save(copilotProject.getStatus());

    instance.create(copilotProject);
  }
示例#15
0
 public User insertUser(User user) {
   try {
     hibernateTemplate.save(user);
     return user;
   } catch (Exception e) {
     e.printStackTrace();
     return null;
   }
 }
示例#16
0
 public void save(Consumable transientInstance) {
   log.debug("saving Consumable instance");
   try {
     hibernateTemplate.save(transientInstance);
     log.debug("save successful");
   } catch (RuntimeException re) {
     log.error("save failed", re);
     throw re;
   }
 }
  /**
   * Tests <code>{@link CopilotProjectDAOImpl#delete(long)}</code> method.
   *
   * @throws CopilotDAOException if any error occurs
   */
  @Test
  @SuppressWarnings("unchecked")
  public void testDelete1() throws CopilotDAOException {

    CopilotProfile copilotProfile1 = TestHelper.createCopilotProfile();
    CopilotProject copilotProject1 = TestHelper.createCopilotProject();

    TestHelper.persistCopilotProjectDependencies(
        hibernateTemplate, copilotProfile1, copilotProject1);
    hibernateTemplate.save(copilotProject1);

    CopilotProfile copilotProfile2 = TestHelper.createCopilotProfile();
    CopilotProject copilotProject2 = TestHelper.createCopilotProject();

    TestHelper.persistCopilotProjectDependencies(
        hibernateTemplate, copilotProfile2, copilotProject2);
    hibernateTemplate.save(copilotProject2);

    instance.delete(copilotProject1.getId());

    List<CopilotProject> result =
        hibernateTemplate.find("from CopilotProject where id = ?", copilotProject1.getId());

    Assert.assertEquals(
        "One entity in database should still exist.",
        1,
        hibernateTemplate.find("from CopilotProject").size());
    Assert.assertEquals("Entity was not deleted.", 0, result.size());

    instance.delete(copilotProject2.getId());

    result = hibernateTemplate.find("from CopilotProject where id = ?", copilotProject2.getId());

    Assert.assertEquals(
        "None entity in database should exist.",
        0,
        hibernateTemplate.find("from CopilotProject").size());
    Assert.assertEquals("Entity was not deleted.", 0, result.size());
  }
示例#18
0
  public void insertAuditLog(
      AuditAction action, String details, String ipAddress, User user, String recid, String extraid)
      throws ServiceException {
    try {
      String aid = UUID.randomUUID().toString();
      AuditTrail auditTrail = new AuditTrail();
      auditTrail.setID(aid);
      auditTrail.setAction(action);
      auditTrail.setAuditTime(new Date());
      auditTrail.setDetails(details);
      auditTrail.setIPAddress(ipAddress);
      auditTrail.setRecid(recid);
      auditTrail.setUser(user);
      auditTrail.setExtraid(extraid);
      hibernateTemplate.save(auditTrail);

      ArrayList<Object> indexFieldDetails = new ArrayList<Object>();
      ArrayList<String> indexFieldName = new ArrayList<String>();
      indexFieldDetails.add(details);
      indexFieldName.add("details");
      indexFieldDetails.add(aid);
      indexFieldName.add("transactionid");
      indexFieldDetails.add(action.getID());
      indexFieldName.add("actionid");
      indexFieldDetails.add(ipAddress);
      indexFieldName.add("ipaddr");
      String userName =
          user.getUserLogin().getUserName() + " " + user.getFirstName() + " " + user.getLastName();
      indexFieldDetails.add(userName);
      indexFieldName.add("username");
      indexFieldDetails.add(auditTrail.getAuditTime());
      indexFieldName.add("timestamp");
      String indexPath = storageHandlerImplObj.GetAuditTrailIndexPath();
      com.krawler.esp.indexer.KrawlerIndexCreator kwlIndex =
          new com.krawler.esp.indexer.KrawlerIndexCreator();
      kwlIndex.setIndexPath(indexPath);
      com.krawler.esp.indexer.CreateIndex cIndex = new com.krawler.esp.indexer.CreateIndex();
      cIndex.indexAlert(kwlIndex, indexFieldDetails, indexFieldName);

    } catch (Exception e) {
      throw ServiceException.FAILURE(e.getMessage(), e);
    }
  }
  public KwlReturnObject uploadFile(FileItem fi, String userid) throws ServiceException {
    Docs docObj = new Docs();
    List ll = new ArrayList();
    int dl = 0;
    try {
      String fileName = new String(fi.getName().getBytes(), "UTF8");
      String Ext = "";
      String a = "";

      if (fileName.contains(".")) {
        Ext = fileName.substring(fileName.indexOf(".") + 1, fileName.length());
        a = Ext.toUpperCase();
      }

      User userObj = (User) hibernateTemplate.get(User.class, userid);
      docObj.setDocname(fileName);
      docObj.setUserid(userObj);
      docObj.setStorename("");
      docObj.setDoctype(a + " " + "File");
      docObj.setUploadedon(new Date());
      docObj.setStorageindex(1);
      docObj.setDocsize(fi.getSize() + "");

      hibernateTemplate.save(docObj);

      String fileid = docObj.getDocid();
      if (Ext.length() > 0) {
        fileid = fileid + Ext;
      }
      docObj.setStorename(fileid);

      hibernateTemplate.update(docObj);

      ll.add(docObj);

      //            String temp = "/home/trainee";
      String temp = storageHandlerImplObj.GetDocStorePath();
      uploadFile(fi, temp, fileid);
    } catch (Exception e) {
      throw ServiceException.FAILURE(e.getMessage(), e);
    }
    return new KwlReturnObject(true, KwlReturnMsg.S01, "", ll, dl);
  }
示例#20
0
  public Object saveOrUpdateAll(Object obj, HibernateTemplate ht, Session session)
      throws Exception {
    // System.out.println("saveOrUpdateAll");
    Object id = getEntityId(obj, ht);
    if (id != null && !id.toString().trim().equals("")) {
      // System.out.println("saving");
      Object old = ht.get(superClass, (Serializable) id);
      ht.evict(old);
      setInputInfo(old, obj);
      return updateAll(obj, ht, session);
    } else {
      setInputInfo(obj);
      Object main = superClass.newInstance();
      BeanUtils.copyProperties(obj, main);
      // System.out.println("fkName is " + fkName);
      ht.save(main);
      id = getEntityId(main, ht);
      setFK(obj, id, fkName);

      saveDetails(obj, ht);
      return id;
    }
  }
  /**
   * Tests <code>{@link
   * CopilotProjectDAOImpl#create(com.topcoder.direct.services.copilot.model.IdentifiableEntity)}
   * </code> method.
   *
   * @throws com.topcoder.direct.services.copilot.dao.CopilotDAOException if any error occurs
   */
  @Test
  @SuppressWarnings("unchecked")
  public void testCreate2() throws CopilotDAOException {

    CopilotProfile copilotProfile = TestHelper.createCopilotProfile();
    CopilotProject copilotProject = TestHelper.createCopilotProject();

    TestHelper.persistCopilotProjectDependencies(hibernateTemplate, copilotProfile, copilotProject);

    CopilotProjectInfoType copilotProjectInfoType = TestHelper.createCopilotProjectInfoType();
    hibernateTemplate.save(copilotProjectInfoType);

    CopilotProjectInfo copilotProjectInfo = TestHelper.createCopilotProjectInfo();
    copilotProjectInfo.setInfoType(copilotProjectInfoType);
    copilotProject.getProjectInfos().add(copilotProjectInfo);

    instance.create(copilotProject);

    List<CopilotProject> result =
        (List<CopilotProject>)
            hibernateTemplate.find("from CopilotProject where id = ?", copilotProject.getId());

    assertCopilotProject(copilotProject, result.get(0));
  }
  @Before
  public void before() throws IOException, JDOMException {

    factory = fixture.getFactory();

    fixture.initSystemData();

    StringBuffer configXml = new StringBuffer();
    configXml.append("<config name=\"MyContentType\" version=\"1.0\">");
    configXml.append("     <form>");

    configXml.append("         <title name=\"myTitle\"/>");

    configXml.append("         <block name=\"General\">");

    configXml.append("             <input name=\"myTitle\" required=\"true\" type=\"text\">");
    configXml.append("                 <display>My title</display>");
    configXml.append("                 <xpath>contentdata/mytitle</xpath>");
    configXml.append("             </input>");

    configXml.append("         </block>");

    configXml.append("         <block name=\"Related content\">");

    configXml.append(
        "             <input name=\"myMultipleRelatedContent\" type=\"relatedcontent\" multiple=\"true\">");
    configXml.append("                 <display>My related content</display>");
    configXml.append("                 <xpath>contentdata/myrelatedcontents</xpath>");
    configXml.append("             </input>");

    configXml.append(
        "             <input name=\"mySoleRelatedContent\" type=\"relatedcontent\" multiple=\"false\">");
    configXml.append("                 <display>My sole related content</display>");
    configXml.append("                 <xpath>contentdata/mysolerelatedcontent</xpath>");
    configXml.append("                 <contenttype name=\"MyContentType\"/>");
    configXml.append("             </input>");

    configXml.append("         </block>");
    configXml.append("     </form>");
    configXml.append("</config>");
    configEl = JDOMUtil.parseDocument(configXml.toString()).getRootElement();
    config = XMLDocumentFactory.create(configXml.toString()).getAsJDOMDocument();

    fixture.createAndStoreNormalUserWithUserGroup("testuser", "testuser fullname", "testuserstore");
    hibernateTemplate.save(
        factory.createContentHandler(
            "Custom content", ContentHandlerName.CUSTOM.getHandlerClassShortName()));
    hibernateTemplate.save(
        factory.createContentType(
            "MyContentType", ContentHandlerName.CUSTOM.getHandlerClassShortName(), config));
    hibernateTemplate.save(factory.createUnit("MyUnit"));
    hibernateTemplate.save(
        factory.createCategory(
            "MyCategory", null, "MyContentType", "MyUnit", "testuser", "testuser"));
    hibernateTemplate.save(
        factory.createCategoryAccess(
            "MyCategory", fixture.findUserByName("testuser"), "read, create, approve"));

    hibernateTemplate.flush();
    hibernateTemplate.clear();

    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRemoteAddr("127.0.0.1");
    ServletRequestAccessor.setRequest(request);
  }
示例#23
0
 public void save(Manager manager) {
   hibernateTemplate.save(manager);
 }
示例#24
0
 @Transactional
 @Override
 public void add(LookFor lookFor) {
   template.save(lookFor);
   template.flush();
 }
示例#25
0
 public void add(UserBean u) {
   System.out.println("UserDao.add()");
   hibernateTemplate.save(u);
 }
示例#26
0
 @Override
 public void saveOrUpdate(Object domain) {
   hibernateTemplate.save(domain);
 }
  @Override
  @Transactional(rollbackFor = Exception.class)
  public TrusteeshipOperation createOperation(Invest invest, FacesContext fc) throws IOException {
    String transferApplyId = invest.getTransferApply().getId();
    // 购买债权人的id
    String userId = invest.getUser().getId();
    // 购买的债权本金 transferCorpus(投资时填写的投资额)
    double transferCorpus = invest.getInvestMoney();
    double remainCorpus = transferService.calculateRemainCorpus(transferApplyId);
    if (transferCorpus <= 0 || transferCorpus > remainCorpus) {
      throw new YeePayOperationException("购买本金必须小于等于" + remainCorpus + "且大于0");
    }
    TransferApply ta = ht.get(TransferApply.class, transferApplyId);
    // 购买的本金占剩余本金的比例corpusRate
    double corpusRate = ArithUtil.div(transferCorpus, remainCorpus);
    // 购买的本金占所有转让本金的比例corpusRateInAll
    double corpusRateInAll = ArithUtil.div(transferCorpus, ta.getCorpus());
    // 投资人实际出的钱=债权的购买金额=债权转出价格*corpusRateInAll (债权转出价格=本金-折让金)
    double buyPrice = ArithUtil.mul(ta.getPrice(), corpusRateInAll, 2);

    if (buyPrice > userBillBO.getBalance(userId)) {
      throw new YeePayOperationException("余额不足。");
    }

    // 购买时候,扣除手续费,从转让人收到的金额中扣除。费用根据购买价格计算
    double fee = feeConfigBO.getFee(FeePoint.TRANSFER, FeeType.FACTORAGE, null, null, buyPrice);

    Invest investNew = new Invest();
    investNew.setId(IdGenerator.randomUUID());
    investNew.setMoney(transferCorpus);
    investNew.setStatus(InvestConstants.InvestStatus.CANCEL);
    investNew.setRate(ta.getInvest().getRate());
    investNew.setTransferApply(ta);
    investNew.setLoan(ta.getInvest().getLoan());
    investNew.setTime(new Date());
    investNew.setUser(new User(userId));
    investNew.setInvestMoney(transferCorpus);
    // 在这里添加投标状态是手动投标
    investNew.setIsAutoInvest(false);
    ht.save(investNew);
    ht.update(ta);

    DecimalFormat currentNumberFormat = new DecimalFormat("#0.00");
    // 构建投资参数实体
    CPTransaction cp = new CPTransaction();
    cp.setNotifyUrl(
        YeePayConstants.ResponseS2SUrl.PRE_RESPONSE_URL + YeePayConstants.OperationType.TRANSFER);
    cp.setCallbackUrl(
        YeePayConstants.ResponseWebUrl.PRE_RESPONSE_URL + YeePayConstants.OperationType.TRANSFER);
    // cp.setExpired(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(DateUtil.addMinute(new
    // Date(), 10)));
    cp.setRequestNo(YeePayConstants.RequestNoPre.TRANSFER + investNew.getId());
    cp.setPlateformNo(YeePayConstants.Config.MER_CODE);
    cp.setPlatformUserNo(userId);
    cp.setBizType(YeepayCpTransactionConstant.CREDIT_ASSIGNMENT.name());
    cp.setUserType("MEMBER");

    // 资金明细
    FundDetail fd = new FundDetail();
    // 给转让债权的人的钱
    fd.setAmount(currentNumberFormat.format(buyPrice - fee));
    fd.setTargetPlatformUserNo(ta.getInvest().getUser().getId());
    fd.setTargetUserType("MEMBER");
    fd.setBizType(YeepayCpTransactionConstant.CREDIT_ASSIGNMENT.name());
    cp.getFundDetails().add(fd);

    // 平台分润
    if (fee > 0.0) {
      fd = new FundDetail();
      // 投资人给平台的钱=fee
      fd.setAmount(currentNumberFormat.format(fee));
      fd.setTargetPlatformUserNo(YeePayConstants.Config.MER_CODE);
      fd.setTargetUserType("MERCHANT");
      fd.setBizType(YeepayCpTransactionConstant.COMMISSION.name());
      cp.getFundDetails().add(fd);
    }

    // 扩展参数
    Extend extend = new Extend();
    Loan loan = ta.getInvest().getLoan();
    extend.setTenderOrderNo(loan.getId());
    extend.setCreditorPlatformUserNo(ta.getInvest().getUser().getId());
    // 判断购买的债券是否是自动投标
    if (ta.getInvest().getIsAutoInvest()) {
      extend.setOriginalRequestNo(
          YeePayConstants.RequestNoPre.AUTO_INVEST + ta.getInvest().getId());
    } else {
      extend.setOriginalRequestNo(YeePayConstants.RequestNoPre.INVEST + ta.getInvest().getId());
    }
    cp.setExtend(extend);
    log.debug(cp.toString());

    Map<String, String> params = new HashMap<String, String>();
    params.put("req", cp.toString());
    String sign = CFCASignUtil.sign(cp.toString());
    params.put("sign", sign);

    // 保存本地
    TrusteeshipOperation to = new TrusteeshipOperation();
    to.setId(IdGenerator.randomUUID());
    to.setMarkId(investNew.getId());
    to.setOperator(Double.toString(buyPrice) + "&" + Double.toString(corpusRate) + "&" + userId);
    to.setRequestUrl(YeePayConstants.RequestUrl.TRANSFER);
    to.setRequestData(MapUtil.mapToString(params));
    to.setStatus(TrusteeshipConstants.Status.UN_SEND);
    to.setType(YeePayConstants.OperationType.TRANSFER);
    to.setTrusteeship("yeepay");
    trusteeshipOperationBO.save(to);
    try {
      // 发送信息
      sendOperation(to.getId(), "utf-8", fc);
    } catch (IOException e) {
      e.printStackTrace();
    }

    return null;
  }
示例#28
0
 @Override
 public void save(Object entity) {
   hibernateTemplate.save(entity);
 }
示例#29
0
 @Override
 public void save(GroupHistory gh) {
   ht.save(gh);
 }
示例#30
0
 public void save(Object r) {
   hibernateTemplate.save(r);
 }