Ejemplo n.º 1
0
 /**
  * 将对象Value对象转换为显示字符串,子类可根据需要覆写此方法输出定制格式字符串
  *
  * @param entity 版本数据实体对象
  * @param field 版本字段属性
  * @param value 版本属性数据值
  * @return 格式化后处理的字符串
  */
 protected String convertPropertyDisplay(Object entity, Field field, Object value) {
   if (value == null) {
     return "";
   }
   if (value instanceof PersistableEntity) {
     @SuppressWarnings("rawtypes")
     PersistableEntity persistableEntity = (PersistableEntity) value;
     String label = "N/A";
     try {
       label = persistableEntity.getDisplayLabel();
     } catch (EntityNotFoundException e) {
       // Hibernate Envers默认始终查询对应Audit版本数据,有可能关联对象之前没有Audit记录,从而会导致Envers抛出未找到数据异常
       // 此处做Hack处理:如果没有找到关联Audit记录,则查询关联主对象记录
       try {
         // 从Hibernate AOP增强对象反查对应实体对象数据
         JavassistLazyInitializer jli =
             (JavassistLazyInitializer) FieldUtils.readDeclaredField(value, "handler", true);
         Class entityClass = jli.getPersistentClass();
         Serializable id = jli.getIdentifier();
         Object obj = getEntityService().findEntity(entityClass, id);
         PersistableEntity auditTargetEntity = (PersistableEntity) obj;
         label = auditTargetEntity.getDisplayLabel();
       } catch (IllegalAccessException iae) {
         logger.warn(e.getMessage());
       }
     }
     return label;
   }
   return String.valueOf(value);
 }
  /**
   * <b>Purpose:</b> delete a Genotype<br>
   * <b>Overview:</b> delete changes. <br>
   *
   * @return String action returned to faces-config.xml
   */
  public String deleteGenotypeAction() {
    int mIndex = (Integer) getSessionParameter("mIndex");
    int gIndex = (Integer) getSessionParameter("gIndex");
    int mKey = (Integer) getSessionParameter("mKey");
    int gKey = 0;

    if (getSessionParameter("gKey") != null) {
      gKey = (Integer) getSessionParameter("gKey");
    }

    System.out.println(
        "entered into delete with mouseKey "
            + mKey
            + " genotype key "
            + gKey
            + " and mouseIndex "
            + mIndex
            + " genotypeIndex "
            + gIndex);

    try {
      if (this.getMouseGenotypeLst().get(mIndex).getMouseEntity().getMouseKey() == mKey
          || this.getMouseGenotypeLst().get(mIndex).getMouseEntity().getMouseKey().equals(mKey)) {

        System.out.println("entered into if");

        // set the genotype with mouseEntity
        GenotypeEntity ge = new GenotypeEntity();
        ge =
            (GenotypeEntity)
                this.getMouseGenotypeLst().get(mIndex).getGenotypeList().get(gIndex).getEntity();
        ge.setMouseKey(this.getMouseGenotypeLst().get(mIndex).getMouseEntity());

        if (gKey > 0) {
          System.out.println("entered into db delete");
          // delete from db
          new SaveAppService().baseDelete(ge);

          addToMessageQueue(
              "Genotype for the gene "
                  + ge.getGeneKey().getLabSymbol()
                  + " and mouse "
                  + ge.getMouseKey().getId()
                  + " has been deleted",
              FacesMessage.SEVERITY_INFO);
          this.getLogger()
              .logInfo(
                  this.formatLogMessage(
                      "save",
                      "Gene "
                          + ge.getGeneKey().getLabSymbol()
                          + " and mouse "
                          + ge.getMouseKey().getId()
                          + " has been deleted"));
        } else {
          addToMessageQueue(
              "Genotype for the mouse " + ge.getMouseKey().getId() + " has been deleted",
              FacesMessage.SEVERITY_INFO);
          this.getLogger()
              .logInfo(
                  this.formatLogMessage(
                      "save",
                      "Genotype for the mouse " + ge.getMouseKey().getId() + " has been deleted"));
        }

        // delete from the list
        this.getMouseGenotypeLst().get(mIndex).getGenotypeList().remove(gIndex);
        this.clearSessionVariables();
        this.tempAlleles = false;
        setSetDirtyFlag(false);

        this.getMouseGenotypeLst()
            .get(mIndex)
            .setShowHideFlag(!this.getMouseGenotypeLst().get(mIndex).getGenotypeList().isEmpty());
      }
    } catch (EntityNotFoundException se) {
      String msg = se.getMessage();
      addToMessageQueue(msg, FacesMessage.SEVERITY_ERROR);
      this.getLogger().logError(this.formatLogMessage(msg, "deleteAction"));
      return null;
    } // General catch-all for failed saves. The exception's message has already been customized for
      // user display.
    catch (IllegalStateException ex) {
      String msg =
          "The system failed to save any mouse updates.  "
              + "Please report this problem to the web master with date "
              + "and time of error.  ";

      // Display user friendly error message
      this.addToMessageQueue(msg, FacesMessage.SEVERITY_ERROR);
      this.getLogger().logError(this.formatLogMessage(msg, "deleteAction"));

      // Return null to indicate that the JSF implementation
      // should reload the same page.
      return null;
    } catch (Exception se) {
      String msg = se.getMessage();
      addToMessageQueue(msg, FacesMessage.SEVERITY_ERROR);
      this.getLogger().logError(this.formatLogMessage(msg, "deleteAction"));
      return null;
    }
    // Redisplay the page.
    return null;
  }