Пример #1
0
  /**
   * Revision版本数据对比显示 为了避免由于权限配置不严格,导致未授权的Controller数据操作访问,父类提供protected基础实现,子类根据需要覆写public然后调用基类方法
   *
   * @return 在struts.xml中全局的revisionCompare Result定义
   */
  @MetaData(value = "版本数据对比")
  protected HttpHeaders revisionCompare() {
    HttpServletRequest request = this.getRequest();
    String id = String.valueOf(this.getId());
    Long revLeft = Long.valueOf(this.getRequiredParameter("revLeft"));
    Long revRight = Long.valueOf(this.getRequiredParameter("revRight"));
    EntityRevision revLeftEntity = null;
    EntityRevision revRightEntity = null;
    List<EntityRevision> entityRevisions =
        getEntityService().findEntityRevisions(id, revLeft, revRight);
    for (EntityRevision entityRevision : entityRevisions) {
      if (entityRevision.getRevisionEntity().getRev().equals(revLeft)) {
        revLeftEntity = entityRevision;
      } else if (entityRevision.getRevisionEntity().getRev().equals(revRight)) {
        revRightEntity = entityRevision;
      }
    }

    List<Map<String, String>> revEntityProperties = Lists.newArrayList();
    for (Map.Entry<Field, String> me : getRevisionFields().entrySet()) {
      Field field = me.getKey();
      Map<String, String> revEntityProperty = Maps.newHashMap();
      revEntityProperty.put("name", me.getValue());
      if (revLeftEntity != null) {
        try {
          Object value =
              FieldUtils.readDeclaredField(revLeftEntity.getEntity(), field.getName(), true);
          String valueDisplay = convertPropertyDisplay(revLeftEntity.getEntity(), field, value);
          revEntityProperty.put("revLeftPropertyValue", valueDisplay);
        } catch (IllegalAccessException e) {
          throw new WebException(e.getMessage(), e);
        }
      }
      if (revRightEntity != null) {
        try {
          Object value =
              FieldUtils.readDeclaredField(revRightEntity.getEntity(), field.getName(), true);
          String valueDisplay = convertPropertyDisplay(revRightEntity.getEntity(), field, value);
          revEntityProperty.put("revRightPropertyValue", valueDisplay);
        } catch (IllegalAccessException e) {
          throw new WebException(e.getMessage(), e);
        }
      }
      revEntityProperties.add(revEntityProperty);
    }
    request.setAttribute("revLeftEntity", revLeftEntity);
    request.setAttribute("revRightEntity", revRightEntity);
    request.setAttribute("revEntityProperties", revEntityProperties);
    return buildDefaultHttpHeaders("revisionCompare");
  }
Пример #2
0
 /**
  * Revision操作记录列表 为了避免由于权限配置不严格,导致未授权的Controller数据操作访问,父类提供protected基础实现,子类根据需要覆写public然后调用基类方法
  *
  * @return JSON集合数据
  */
 @MetaData(value = "版本数据列表")
 protected HttpHeaders revisionList() {
   String property = this.getParameter("property");
   Boolean hasChanged = null;
   String changed = this.getParameter("changed");
   if (StringUtils.isNotBlank(changed)) {
     hasChanged = BooleanUtils.toBooleanObject(changed);
   }
   List<EntityRevision> entityRevisions =
       getEntityService().findEntityRevisions(this.getId(), property, hasChanged);
   for (EntityRevision entityRevision : entityRevisions) {
     Object entity = entityRevision.getEntity();
     ExtDefaultRevisionEntity revEntity = entityRevision.getRevisionEntity();
     if (entity instanceof OperationAuditable) {
       OperationAuditable aae = (OperationAuditable) entity;
       revEntity.setOldStateDisplay(aae.convertStateToDisplay(revEntity.getOldState()));
       revEntity.setNewStateDisplay(aae.convertStateToDisplay(revEntity.getNewState()));
       revEntity.setOperationEventDisplay(
           aae.convertEventToDisplay(revEntity.getOperationEvent()));
     }
   }
   setModel(buildPageResultFromList(entityRevisions));
   return buildDefaultHttpHeaders();
 }