示例#1
0
 public int compareTo(Object o) {
   if (o instanceof Comment) {
     // Don't compare Date objects! Use the time in milliseconds!
     return Long.valueOf(this.getCreated().getTime())
         .compareTo(Long.valueOf(((Comment) o).getCreated().getTime()));
   }
   return 0;
 }
示例#2
0
  /**
   * Persists a Audit
   *
   * @param object
   * @param persisted
   * @param auditingType
   */
  public void audit(Object object, Object persisted, AuditingType auditingType) {

    try {

      if (isEntity(object)) {

        Field[] fields = object.getClass().getDeclaredFields();
        Method[] methods = object.getClass().getDeclaredMethods();
        Method.setAccessible(methods, true);
        Field.setAccessible(fields, true);

        AbstractAuditing auditing = Configuration.getAbstractAuditing();
        auditing.setIdentifier(Long.valueOf(getId(object).toString()));
        auditing.setEntity(getEntityName(object.getClass()));
        auditing.setAuditingType(auditingType);
        auditing.setEventDate(new Date());
        if (FacesContext.getCurrentInstance() != null) {
          auditing.setIp(FacesUtils.getIP());
        }
        auditing.setAuditClass(object.getClass());
        AbstractAuditingListener listener = Configuration.getAuditingListener();
        if (listener != null) {
          listener.onSave(auditing);
        }

        List<AbstractMetadata> metadatas = null;
        boolean auditPersited = false;
        if (auditingType.equals(AuditingType.INSERT) || auditingType.equals(AuditingType.DELETE)) {
          entityManager.persist(auditing);
          metadatas = getMetadata(object, null, auditing);
          auditPersited = true;
        } else if (auditingType.equals(AuditingType.UPDATE)) {
          metadatas = getMetadata(object, persisted, auditing);
          if (metadatas != null && !metadatas.isEmpty()) {
            entityManager.persist(auditing);
            auditPersited = true;
          }
        }

        auditing.setMetadatas(metadatas);
        // add to context
        if (auditPersited == true) {
          AuditContext context = AuditContext.getCurrentInstance();
          if (context != null) {
            context.setAuditing(object, auditing);
          }
        }

        if (metadatas != null && !metadatas.isEmpty()) {
          for (AbstractMetadata metadata : metadatas) {
            entityManager.persist(metadata);
          }
        }
      }
    } catch (Throwable t) {
      logger.log(Level.SEVERE, t.getMessage(), t);
    }
  }
示例#3
0
  public void setValueTextRoles(String valueTextRoles) {

    try {
      List<PickerItem> listOfPickerItem =
          objectStringConverterImpl.convertToListOfObjects(
              new TypeReference<List<PickerItem>>() {}, valueTextRoles);
      roles.clear();

      for (PickerItem pickerItem : listOfPickerItem) {
        roles.add(roleRepoImpl.find(Long.valueOf(pickerItem.getPickerCode().toString())));
      }
    } catch (Exception e) {
      loggerImpl.logError(e, "security.error.convert.json.to.role");
    }
  }
示例#4
0
文件: OkcMenu.java 项目: wenpi/eno
 // 增加String作为参数的Set方法,目的是为了在对对菜单配置做导入时,使用Java反射机制来统一函数原型  [ ChengKang 2014-07-26 ]
 public void setOkcmenuid(String okcmenuid) {
   if (!StringUtils.hasLength(okcmenuid)) {
     okcmenuid = "0";
   }
   this.okcmenuid = Long.valueOf(okcmenuid);
 }
示例#5
0
文件: OkcMenu.java 项目: wenpi/eno
 // 增加String作为参数的Set方法,目的是为了在对对菜单配置做导入时,使用Java反射机制来统一函数原型  [ ChengKang 2014-07-26 ]
 public void setMenuid(String menuid) {
   if (!StringUtils.hasLength(menuid)) {
     menuid = "0";
   }
   this.menuid = Long.valueOf(menuid);
 }
示例#6
0
  public List<AbstractMetadata> getMetadata(
      Object object, Object persisted, AbstractAuditing auditing) throws Exception {
    List<Method> methodsGet = getMethods(object);
    List<AbstractMetadata> metadatas = new ArrayList<AbstractMetadata>();
    boolean isDelete =
        auditing.getAuditingType() != null
            && auditing.getAuditingType().equals(AuditingType.DELETE);
    for (Method method : methodsGet) {
      try {
        Object fieldValue = method.invoke(object);
        Object fieldOld = null;
        if (persisted != null) {
          fieldOld = method.invoke(persisted);
        }
        AbstractMetadata metadata = Configuration.getAbstractMetadata();
        if (fieldValue != null && fieldValue.getClass().isAnnotationPresent(Embeddable.class)) {
          List<AbstractMetadata> embedableMetadata = getMetadata(fieldValue, persisted, auditing);
          if (embedableMetadata != null && !embedableMetadata.isEmpty()) {
            metadatas.addAll(embedableMetadata);
          }
        } else {
          boolean addMetadata = persisted == null;
          if (fieldValue instanceof Collection) { // para as coleções
            Collection collectionNew = (Collection<Object>) fieldValue;
            Collection collectionOld = (Collection<Object>) fieldOld;
            StringBuilder newValue = new StringBuilder();
            if (fieldOld == null) {
              for (Object item : collectionNew) {
                newValue.append(item.toString()).append("; ");
              }
              addMetadata = true;
            } else {
              StringBuilder oldValue = new StringBuilder();
              if ((!(collectionNew instanceof PersistentBag)
                      && !(collectionNew instanceof PersistentCollection))
                  || isDelete == true) {
                if ((collectionNew == null && collectionOld != null)
                    || (collectionNew != null && collectionOld == null)
                    || (collectionNew.size() != collectionOld.size())) {
                  addMetadata = true;
                } else {
                  for (Object current : collectionNew) {
                    if (collectionOld != null && !collectionOld.contains(current)) {
                      for (Object currentOld : collectionOld) {
                        if (!currentOld.equals(current)) {
                          addMetadata = true;
                          break;
                        }
                      }
                    }
                  }
                }
                for (Object old : collectionOld) {
                  oldValue.append(old).append("; ");
                }
                for (Object item : collectionNew) {
                  newValue.append(item.toString()).append("; ");
                }
                metadata.setOldValue(oldValue.toString());
              }
            }
            metadata.setNewValue(newValue.toString());
          } else if (isEntity(method.getReturnType())) {
            Object newId = getId(fieldValue);
            // a proxy doesnt has value changed
            if (!(fieldValue instanceof HibernateProxy) || isDelete == true) {
              /** One to One cascade ALL */
              if (isOneToOneCascadeAll(method)) {
                List<AbstractMetadata> embedableMetadata = null;
                // add metadata for oneToOne cascade all based on new object
                if (persisted == null) {
                  embedableMetadata = getMetadata(fieldValue, null, auditing);
                } else {
                  embedableMetadata = getMetadata(fieldValue, getPersisted(fieldValue), auditing);
                }

                if (embedableMetadata != null && !embedableMetadata.isEmpty()) {
                  metadatas.addAll(embedableMetadata);
                }
              }

              Object oldId = null;
              if (fieldOld instanceof HibernateProxy) {
                oldId = ((HibernateProxy) fieldOld).getHibernateLazyInitializer().getIdentifier();
              } else {
                oldId = getId(fieldOld);
              }
              metadata.setOldIdentifier(oldId == null ? null : Long.valueOf(oldId.toString()));
              metadata.setOldValue(fieldOld == null ? "" : fieldOld.toString());
              if ((oldId == null && newId != null)
                  || (oldId != null && newId == null)
                  || (oldId != null && !oldId.equals(newId))) {
                addMetadata = true;
              }
              metadata.setEntity(method.getDeclaringClass().getName());
              metadata.setNewIdentifier(newId == null ? null : Long.valueOf(newId.toString()));
              metadata.setNewValue(fieldValue == null ? "" : fieldValue.toString());
            }
          } else {
            if (fieldOld != null) {
              metadata.setOldValue(getToString(fieldOld));
            }
            if (fieldValue != null) {
              metadata.setNewValue(getToString(fieldValue));
            }
            // verify empty String
            if (fieldValue instanceof String) {
              if ((fieldOld == null && fieldValue != null && !fieldValue.toString().isEmpty())
                  || (fieldOld != null && !fieldOld.toString().isEmpty() && fieldValue == null)
                  || (fieldOld != null && !fieldOld.equals(fieldValue))) {
                addMetadata = true;
              }
            } else {
              if ((fieldOld == null && fieldValue != null)
                  || (fieldOld != null && fieldValue == null)
                  || (fieldOld != null && !fieldOld.equals(fieldValue))) {
                addMetadata = true;
              }
            }
          }
          metadata.setField(getMethodName(method));
          metadata.setAuditing(auditing);
          if (addMetadata) {
            metadatas.add(metadata);
          }
        }
      } catch (Throwable t) {
        logger.log(Level.SEVERE, t.getMessage(), t);
      }
    }
    return metadatas;
  }
 @Override
 public int hashCode() {
   return Long.valueOf(this.learnerPlanObjectiveId).hashCode();
 }