コード例 #1
0
  /**
   * @see com.pureinfo.importer.ref.IImportorRef#convert(com.pureinfo.dolphin.model.DolphinObject,
   *     com.pureinfo.dolphin.model.DolphinObject, java.lang.String, java.lang.String,
   *     com.pureinfo.dolphin.persister.ISession, com.pureinfo.dolphin.persister.ISession,
   *     com.pureinfo.dolphin.mapping.EntityMetadata, java.lang.String, java.lang.String)
   */
  public Object convert(
      DolphinObject _old,
      DolphinObject _new,
      String _sFromProperty,
      String _sToProperty,
      ISession _fromSession,
      ISession _toSession,
      EntityMetadata _metadata,
      String _sKey,
      String _sToTable)
      throws PureException {
    String sAdminName = _old.getStrProperty(_sFromProperty);
    if (sAdminName == null) return null;
    String sDeptCode = _old.getStrProperty("单位代码");
    _new.setProperty("firstAuthorName", sAdminName);

    IObjects users = null;
    IStatement query = null;
    SRMUser user = null;
    int nUserId = 0;
    try {
      ISRMUserMgr userMgr = (ISRMUserMgr) ArkContentHelper.getContentMgrOf(SRMUser.class);
      query =
          userMgr.createQuery(
              "SELECT * FROM {this} WHERE {this.trueName}=?", DolphinConstants.MAXSIZE_UNLIMITED);
      query.setString(0, sAdminName);
      users = query.executeQuery();
      SRMUser[] aUsers = (SRMUser[]) users.toList().toArray(new SRMUser[0]);
      if (aUsers.length == 0) {
        nUserId = 0;
      } else if (aUsers.length == 1) {
        user = aUsers[0];
        nUserId = user.getId();
      } else {
        if (sDeptCode == null) {
          sDeptCode = _old.getStrProperty("字段1");
        }
        String sCollege = sDeptCode.substring(0, 2);
        for (int i = 0; i < aUsers.length; i++) {
          Organization org = aUsers[i].getDepartment();
          String sCode = null;
          if (org != null) sCode = org.getCode();
          if (sCode != null && sCode.length() > 2) sCode = sCode.substring(0, 2);
          if (sCode != null && sCode.equals(sCollege)) {
            user = aUsers[i];
            nUserId = user.getId();
            break;
          }
        }
        if (user == null) {
          logger.error(_old.getStrProperty("成果名称") + "," + _old.getStrProperty("负责人"));
          user = aUsers[0];
          nUserId = user.getId();
        }
      }
      LocalContextHelper.currentSession().autoGenerateProperty(_new, "id");
      int nProductId = _new.getIntProperty("id", -1);
      ObjUserMapping author = new ObjUserMapping();

      author.setObjType(SRMTypes.PRODUCT);
      author.setUserType("1");
      author.setUserId(nUserId);
      author.setUserName(sAdminName);
      author.setOrderNo(1);
      author.setObjId(nProductId);
      author.setWeightYear(WeightConstants.WEIGHT_YEAR_DEFAULT_VALUE);

      IObjUserMappingMgr puMgr =
          (IObjUserMappingMgr) ArkContentHelper.getContentMgrOf(ObjUserMapping.class);
      puMgr.save(author);
    } finally {
      DolphinHelper.clear(users, query);
    }
    return "" + nUserId;
  }
コード例 #2
0
  public DolphinObject next() throws PureException {
    Publication publication = null;
    try {
      String sLine = buffReader.readLine();
      if (sLine == null) {
        clear();
        return null;
      }
      IProductMgr mgr = (IProductMgr) ArkContentHelper.getContentMgrOf(Product.class);
      int i = 0, j = 1;
      String sName, sValue = "", sTemp, sAuthorNames = "";
      while (sLine != null) {
        Product product = new Product();
        sName = sLine.trim();
        if ("题名".equals(sName)) {
          sValue = buffReader.readLine().trim();
        } else {
          sName = buffReader.readLine().trim();
          if ("题名".equals(sName)) {
            sValue = buffReader.readLine().trim();
          } else {
            sName = buffReader.readLine().trim();
            sValue = buffReader.readLine().trim();
          }
        }
        sTemp = buffReader.readLine().trim();
        for (i = 0; !sTemp.equals("作者"); i++) {
          sValue += sTemp;
          sTemp = buffReader.readLine().trim();
        }
        logger.debug("[" + (j++) + "] 题名:" + sValue);
        product.setProductName(sValue);
        sName = sTemp;
        //                sName = buffReader.readLine().trim();
        if (sName.length() == 0) {
          sName = buffReader.readLine().trim();
        }
        if ("作者".equals(sName)) {
          sValue = buffReader.readLine().trim();
          if (sValue.length() > 0) {
            sAuthorNames = sValue.substring(0, sValue.length() - 1);
          } else {
            sAuthorNames = "";
          }
          //                    logger.debug("作者:" + sValue);
        }
        sName = buffReader.readLine().trim();
        if (sName.length() == 0) {
          sName = buffReader.readLine().trim();
        }
        if ("中文关键词".equals(sName)) {
          sValue = buffReader.readLine().trim();
          product.setProperty("chineseKeyWords", sValue);
          //                    logger.debug("中文关键词:" + sValue);
        }
        sName = buffReader.readLine().trim();
        if (sName.length() == 0) {
          sName = buffReader.readLine().trim();
        }
        if ("单位".equals(sName)) {
          sValue = buffReader.readLine().trim();
        }
        sTemp = buffReader.readLine().trim();
        for (i = 0; !sTemp.equals("中文摘要"); i++) {
          sValue += sTemp;
          sTemp = buffReader.readLine().trim();
        }
        //                logger.debug("单位:" + sValue);
        product.setProperty("englishAuthorsDepts", sValue);
        int nPos = sValue.indexOf(",");
        if (nPos == -1) nPos = sValue.indexOf(" ");
        String sFirstAuthorDept = sValue.substring(0, nPos);
        product.setProperty("englishDept", sFirstAuthorDept);
        if (sFirstAuthorDept.indexOf("浙江大学") >= 0) {
          product.setProperty("isZju", true);
        } else {
          product.setProperty("isZju", false);
        }
        //                logger.debug("第一单位:" + sFirstAuthorDept + "; isZju:" +
        // product.getPropertyAsString("isZju"));

        sValue = buffReader.readLine().trim();
        for (i = 0; !sTemp.equals("基金"); i++) {
          sValue += sTemp;
          sTemp = buffReader.readLine().trim();
        }
        if (sValue.endsWith("中文摘要")) {
          sValue = sValue.substring(0, sValue.indexOf("中文摘要"));
        }
        //                logger.debug("中文摘要:" + sValue);
        product.setProperty("abstraction", sValue);

        sValue = buffReader.readLine().trim();
        for (i = 0; !sTemp.equals("刊名"); i++) {
          sValue += sTemp;
          sTemp = buffReader.readLine().trim();
        }
        if (sValue.endsWith("基金")) {
          sValue = sValue.substring(0, sValue.indexOf("基金"));
        }
        //                logger.debug("基金:" + sValue);
        product.setProperty("fund", sValue);

        sValue = buffReader.readLine().trim();
        //                logger.debug("刊名:" + sValue);
        product.setPublicationName(sValue);

        sName = buffReader.readLine().trim();
        if (sName.length() == 0) {
          sName = buffReader.readLine().trim();
        }
        if ("ISSN".equals(sName)) {
          sValue = buffReader.readLine().trim();
          //                    logger.debug("ISSN:" + sValue);
          product.setISSNCode(sValue);
          product.setPublicationId(getPublicationId(sValue));
        }
        sName = buffReader.readLine().trim();
        if (sName.length() == 0) {
          sName = buffReader.readLine().trim();
        }
        int nPublicationYear = 0;
        if ("年".equals(sName)) {
          sValue = buffReader.readLine().trim();
          //                    logger.debug("年:" + sValue);
          nPublicationYear = Integer.parseInt(sValue);
          product.setPublicationYear(nPublicationYear);
        }
        sName = buffReader.readLine().trim();
        if (sName.length() == 0) {
          sName = buffReader.readLine().trim();
        }
        if ("期".equals(sName)) {
          sValue = buffReader.readLine().trim();
          //                    logger.debug("期:" + sValue);
          product.setPublishNo(sValue);
        }
        sName = buffReader.readLine().trim();
        if (sName.length() == 0) {
          sName = buffReader.readLine().trim();
        }
        int nFirstAuthorId = 0;
        if ("第一责任人".equals(sName)) {
          sValue = buffReader.readLine().trim();
          //                    logger.debug("第一责任人:" + sValue);
          if (sValue.length() > 0) {
            sValue = sValue.substring(0, sValue.length() - 1);
            product.setProperty("firstAuthorName", sValue);
            nFirstAuthorId = getAuthorId(sValue);
            if (nFirstAuthorId > 0) {
              product.setProperty("firstAuthorType", 1);
              product.setInsideAuthorId(nFirstAuthorId);
              product.setInsideAuthorNo(1);
            } else {
              product.setProperty("firstAuthorType", 6);
            }
          }
        }
        sLine = buffReader.readLine();
        //                logger.debug("-----------------");

        // 论著编号
        product.setProductForm(ProductConstants.SPRODUCT_FORM_PAPER);
        product.setPublishDate(
            DateTimeUtil.parse(nPublicationYear + "-01-01", ForceConstants.DATE_FORMAT_STR));
        product.setProperty("serialNo", mgr.generateSerialNo(product));
        product.setProperty("isImport", true);
        product.setCreateUser("2006国内论文txt文件");

        String[] arrNames = StrUtil.split(sAuthorNames, ";");
        product.setAuthorsNum(arrNames.length);
        mgr.save(product);

        // --- save authors
        int nProductId = product.getId();
        //                logger.debug("product id : ; " + product.getId());

        IObjUserMappingMgr puMgr =
            (IObjUserMappingMgr) ArkContentHelper.getContentMgrOf(ObjUserMapping.class);
        boolean bFirstInsideAuthor = true;
        for (int k = 0; k < arrNames.length; k++) {
          ObjUserMapping author = new ObjUserMapping();
          int nAuthorId = getAuthorId(arrNames[k]);
          if (nAuthorId > 0) {
            author.setUserType("1");
            author.setUserId(nAuthorId);
            if (nFirstAuthorId == 0 && bFirstInsideAuthor) {
              product.setInsideAuthorId(nAuthorId);
              product.setInsideAuthorNo(k + 1);
              bFirstInsideAuthor = false;
            }
          } else {
            author.setUserType("2");
            author.setUserId(nAuthorId);
          }
          author.setUserName(arrNames[k]);
          author.setOrderNo(k + 1);
          author.setObjId(nProductId);
          author.setObjType(SRMTypes.PRODUCT);
          author.setWeightYear(WeightConstants.WEIGHT_YEAR_DEFAULT_VALUE);
          author.setCreateUser("2006国内论文txt文件");
          puMgr.save(author);
        }
      }
    } catch (IOException ex) {
      logger.error("IOException");
    }
    return publication;
  }