Beispiel #1
1
  /**
   * Gets the name.
   *
   * @return the name
   */
  public String getName() {
    StringBuilder name = new StringBuilder();

    if (!StringUtil.isNullOrEmpty(title)) {
      name.append(title);
    }

    if (!StringUtil.isNullOrEmpty(firstname)) {
      if (name.length() > 0) {
        name.append(" ");
      }

      name.append(firstname);
    }

    if (!StringUtil.isNullOrEmpty(lastname)) {
      if (name.length() > 0) {
        name.append(" ");
      }

      name.append(lastname);
    }

    return name.toString();
  }
 private static String generateToken() {
   final StringBuilder builder = new StringBuilder(260);
   while (builder.length() < 256) {
     builder.append(Long.toHexString(TOKEN_GENERATOR.nextLong()));
   }
   return builder.substring(0, 256);
 }
Beispiel #3
1
  @Override
  public Object bind(
      RootParamNode rootParamNode,
      String name,
      Class clazz,
      java.lang.reflect.Type type,
      Annotation[] annotations) {
    // TODO need to be more generic in order to work with JPASupport
    if (clazz.isAnnotationPresent(Entity.class)) {

      ParamNode paramNode = rootParamNode.getChild(name, true);

      String[] keyNames = new JPAModelLoader(clazz).keyNames();
      ParamNode[] ids = new ParamNode[keyNames.length];
      // Collect the matching ids
      int i = 0;
      for (String keyName : keyNames) {
        ids[i++] = paramNode.getChild(keyName, true);
      }
      if (ids != null && ids.length > 0) {
        try {
          EntityManager em = JPABase.getJPAConfig(clazz).getJPAContext().em();
          StringBuilder q =
              new StringBuilder().append("from ").append(clazz.getName()).append(" o where");
          int keyIdx = 1;
          for (String keyName : keyNames) {
            q.append(" o.").append(keyName).append(" = ?").append(keyIdx++).append(" and ");
          }
          if (q.length() > 4) {
            q = q.delete(q.length() - 4, q.length());
          }
          Query query = em.createQuery(q.toString());
          // The primary key can be a composite.
          Class[] pk = new JPAModelLoader(clazz).keyTypes();
          int j = 0;
          for (ParamNode id : ids) {
            if (id.getValues() == null
                || id.getValues().length == 0
                || id.getFirstValue(null) == null
                || id.getFirstValue(null).trim().length() <= 0) {
              // We have no ids, it is a new entity
              return GenericModel.create(rootParamNode, name, clazz, annotations);
            }
            query.setParameter(
                j + 1,
                Binder.directBind(
                    id.getOriginalKey(), annotations, id.getValues()[0], pk[j++], null));
          }
          Object o = query.getSingleResult();
          return GenericModel.edit(rootParamNode, name, o, annotations);
        } catch (NoResultException e) {
          // ok
        } catch (Exception e) {
          throw new UnexpectedException(e);
        }
      }
      return GenericModel.create(rootParamNode, name, clazz, annotations);
    }
    return null;
  }
Beispiel #4
0
 public String getFullName() {
   StringBuilder str = new StringBuilder();
   str.append(firstName);
   str.append(" ");
   str.append(lastName);
   return str.toString();
 }
Beispiel #5
0
 @Override
 public String toString() {
   StringBuilder sb = new StringBuilder();
   sb.append(new Date(dateTime)).append(":");
   sb.append("FA(").append(fromAccountId).append(")->").append(fromAmount).append(",");
   sb.append("TA(").append(toAccountId).append(")->").append(toAmount);
   return sb.toString();
 }
Beispiel #6
0
 @Override
 public String toString() {
   final StringBuilder sb = new StringBuilder("UserRoles{");
   sb.append("roleId=").append(roleId);
   sb.append(", roleName='").append(roleName).append('\'');
   sb.append('}');
   return sb.toString();
 }
 @Override
 public String toString() {
   final StringBuilder sb = new StringBuilder();
   sb.append("UserRoleBean");
   sb.append("{id=").append(id);
   sb.append(", role='").append(role).append('\'');
   sb.append('}');
   return sb.toString();
 }
Beispiel #8
0
 @Override
 public String toString() {
   final StringBuilder sb = new StringBuilder();
   sb.append("Event");
   sb.append("{id='").append(id).append('\'');
   sb.append(", name='").append(name).append('\'');
   sb.append(", workload=").append(workload);
   sb.append('}');
   return sb.toString();
 }
Beispiel #9
0
 @Override
 public String toString() {
   final StringBuilder sb = new StringBuilder();
   sb.append("Product");
   sb.append("{id=").append(id);
   sb.append(", name='").append(name).append('\'');
   sb.append(", description='").append(description).append('\'');
   sb.append('}');
   return sb.toString();
 }
Beispiel #10
0
 @Override
 public String toString() {
   StringBuilder builder = new StringBuilder();
   builder.append("Tourney [id=");
   builder.append(id);
   builder.append(", name=");
   builder.append(name);
   builder.append("]");
   return builder.toString();
 }
Beispiel #11
0
 @Override
 public String toString() {
   final StringBuilder sb = new StringBuilder();
   sb.append("Purchase");
   sb.append("{id=").append(id);
   sb.append(", user="******", book=").append(book);
   sb.append(", discount=").append(discount);
   sb.append('}');
   return sb.toString();
 }
Beispiel #12
0
 @Override
 public String toString() {
   StringBuilder sb = new StringBuilder();
   sb.append(getClass().getSimpleName());
   sb.append(" [");
   sb.append("Hash = ").append(hashCode());
   sb.append(", id=").append(id);
   sb.append(", name=").append(name);
   sb.append(", uri=").append(uri);
   sb.append(", method=").append(method);
   sb.append(", description=").append(description);
   sb.append(", serialVersionUID=").append(serialVersionUID);
   sb.append("]");
   return sb.toString();
 }
Beispiel #13
0
 private static void addParam(
     StringBuilder builder, List<Object> params, String param, String value) {
   if (StringUtils.isNotBlank(value)) {
     builder.append(param);
     params.add(value);
   }
 }
Beispiel #14
0
 public String computeUrl() {
   StringBuilder sb = new StringBuilder();
   if (null != title) {
     for (int i = 0; i < title.length(); i++) {
       Character c = title.charAt(i);
       sb.append(Character.isLetterOrDigit(c) ? c : '_');
     }
   }
   sb.append('_');
   if (null != id) {
     sb.append(id);
   }
   url = sb.toString();
   Logger.info("url: " + url);
   return url;
 }
Beispiel #15
0
 public static String generatePassword() {
   String charset = "0123456789abcdefghijklmnopqrstuvwxyz";
   Random rand = new Random(System.currentTimeMillis());
   StringBuilder sb = new StringBuilder();
   for (int i = 0; i < charset.length(); i++) {
     int pos = rand.nextInt(charset.length());
     sb.append(charset.charAt(pos));
   }
   return sb.toString();
 }
 @Override
 public String toString() {
   final StringBuilder sb = new StringBuilder();
   sb.append("Order");
   sb.append("{id=").append(id);
   sb.append(", orderDate=").append(orderDate);
   sb.append(", customer=").append(customer);
   sb.append(", orderLines=").append(orderLines == null ? 0 : orderLines.size());
   sb.append(", deliveryAddress=").append(deliveryAddress);
   sb.append(", creditCard=").append(creditCard);
   sb.append('}');
   return sb.toString();
 }
 @Override
 public String toString() {
   final StringBuilder sb = new StringBuilder();
   sb.append("Book");
   sb.append("{id=").append(id);
   sb.append(", title='").append(title).append('\'');
   sb.append(", price=").append(price);
   sb.append(", description='").append(description).append('\'');
   sb.append(", isbn='").append(isbn).append('\'');
   sb.append(", nbOfPage=").append(nbOfPage);
   sb.append(", illustrations=").append(illustrations);
   sb.append('}');
   return sb.toString();
 }
Beispiel #18
0
 @Override
 public String toString() {
   final StringBuilder sb = new StringBuilder("Budget{");
   sb.append("id=").append(id);
   sb.append(", actual=").append(actual);
   sb.append(", name='").append(name).append('\'');
   sb.append(", createdAt=").append(createdAt);
   sb.append(", user="******", category=").append(category);
   sb.append('}');
   return sb.toString();
 }
Beispiel #19
0
  @Override
  public String toString() {
    StringBuilder builder = new StringBuilder();

    Class cls = this.getClass();
    int ii = 0;
    builder.append(this.getClass()).append(" [");
    for (Field f : cls.getDeclaredFields()) {
      String str = "null";
      if (f.getName().equals(PROP_CLUB)) {

        if (this.getFamClub() != null) {
          str = this.getFamClub().getLibClub();
        }
        builder.append(ii++ == 0 ? "\n" : "\n,").append(f.getName()).append(" : ").append(str);

      } else if (f.getName().equals(PROP_TEAM)) {

        if (this.getFamTeam() != null) {
          str = this.getFamTeam().getLibTeam();
        }
        builder.append(ii++ == 0 ? "\n" : "\n,").append(f.getName()).append(" : ").append(str);
      } else if (f.getName().equals(PROP_SEASON)) {

        if (this.getFamSeason() != null) {
          str = this.getFamSeason().getLibSeason();
        }
        builder.append(ii++ == 0 ? "\n" : "\n,").append(f.getName()).append(" : ").append(str);
      } else if (f.getName().equals(PROP_PLAYER)) {

        if (this.getFamPlayer() != null) {
          str = this.getFamPlayer().getDisplayName();
        }
        builder.append(ii++ == 0 ? "\n" : "\n,").append(f.getName()).append(" : ").append(str);
      } else {
        try {
          builder
              .append(ii++ == 0 ? "\n" : "\n,")
              .append(f.getName())
              .append(" : ")
              .append(f.get(this));
        } catch (IllegalArgumentException e) {
          // TODO Auto-generated catch block
          LogUtil.log("Erreur!", Level.SEVERE, e);
        } catch (IllegalAccessException e) {
          // TODO Auto-generated catch block
          LogUtil.log("Erreur!", Level.SEVERE, e);
        }
      }
    }
    builder.append("\n]");
    return builder.toString();
  }
Beispiel #20
0
 @Override
 public String toString() {
   StringBuilder sb = new StringBuilder();
   sb.append("StageFile [ID=");
   sb.append(getId());
   sb.append(", baseName=");
   sb.append(getBaseName());
   sb.append(", extension=");
   sb.append(getExtension());
   sb.append(", fileDate=");
   sb.append(getFileDate());
   sb.append(", fileSize=");
   sb.append(getFileSize());
   if (getStageDirectory() != null) {
     sb.append(", stageDirectory=");
     sb.append(getStageDirectory().getDirectoryPath());
   }
   sb.append("]");
   return sb.toString();
 }
Beispiel #21
0
  public static List<TuserInfo> findTuserInfos(TuserInfo userinfo) {
    StringBuilder builder = new StringBuilder(" where");
    List<Object> params = new ArrayList<Object>();

    /*if(StringUtils.isNotBlank(userinfo.getInfo())){
        builder.append(" o.info like ?");
        params.add('%'+userinfo.getInfo()+'%');
    }
    if(StringUtils.isNotBlank(userinfo.getAddress())){
        builder.append(" o.info like ?");
        params.add('%'+userinfo.getAddress()+'%');
    }*/
    if (userinfo.getUserno() != null) {
      builder.append(" o.userno=?");
      params.add(userinfo.getUserno());
    }
    addParam(builder, params, " o.username=?", userinfo.getUsername());
    addParam(builder, params, " o.nickname=?", userinfo.getNickname());
    addParam(builder, params, " o.email=?", userinfo.getEmail());
    addParam(builder, params, " o.mobile=?", userinfo.getMobile());
    addParam(builder, params, " o.name=?", userinfo.getName());
    addParam(builder, params, " o.qq=?", userinfo.getQq());
    return TuserInfo.getList(builder.toString(), " order by o.regTime asc", params);
  }
Beispiel #22
0
 /**
  * Obtiene una cadena con los valores que representan la licencia
  *
  * @param sep Separador de Items
  * @param lineSep Separador de lineas
  * @return Cadena con el contenido de la licencia
  */
 public String getLicencia(String sep, String lineSep) {
   StringBuilder text = new StringBuilder();
   text.append(id_licencia)
       .append(sep)
       .append(id_aplicacion)
       .append(sep)
       .append(id_distribuidor)
       .append(sep)
       .append(id_cliente)
       .append(sep);
   text.append(Converter.formatDate(fecha_inicio, "dd/MM/yyyy"))
       .append(sep)
       .append(Converter.formatDate(fecha_final, "dd/MM/yyyy"))
       .append(sep);
   text.append(Converter.formatDate(fecha_actualizacion, "dd/MM/yyyy")).append(sep);
   text.append(trial_tiempo)
       .append(sep)
       .append(trial_terminado ? "S" : "N")
       .append(sep)
       .append(activa ? "S" : "N")
       .append(sep);
   text.append(dias_invalida)
       .append(sep)
       .append(Converter.isEmpty(param_1) ? "" : param_1)
       .append(sep)
       .append(Converter.isEmpty(param_2) ? "" : param_2)
       .append(sep);
   text.append(Converter.isEmpty(param_3) ? "" : param_3)
       .append(sep)
       .append(Converter.isEmpty(param_4) ? "" : param_4)
       .append(sep);
   text.append(Converter.isEmpty(param_5) ? "" : param_5).append(lineSep);
   if (!Converter.isEmpty(items)) {
     for (APPEX_LICENCIA_ITEMS licencia_item : items) {
       if (licencia_item.getActivo()) {
         text.append(licencia_item.getId_item())
             .append(sep)
             .append(licencia_item.getTipo())
             .append(sep);
         if ("I".equals(licencia_item.getTipo())) text.append(licencia_item.getInt_valor());
         else if ("S".equals(licencia_item.getTipo())) text.append(licencia_item.getStr_valor());
         else if ("D".equals(licencia_item.getTipo()))
           text.append(Converter.formatDate(licencia_item.getDate_valor(), "dd/MM/yyyy"));
         text.append(sep)
             .append(licencia_item.getImp_tipo())
             .append(sep)
             .append(Converter.formatFloat(licencia_item.getImporte(), 2))
             .append(lineSep);
       }
     }
   }
   return text.toString();
 }
Beispiel #23
0
 @Override
 public String toString() {
   final StringBuilder sb = new StringBuilder();
   sb.append("City");
   sb.append("{cityid=").append(cityid);
   sb.append(", province=").append(province);
   sb.append(", cityname='").append(cityname).append('\'');
   sb.append(", citykey='").append(citykey).append('\'');
   sb.append(", cityFlag='").append(cityFlag).append('\'');
   sb.append(", zipcode='").append(zipcode).append('\'');
   sb.append(", code='").append(code).append('\'');
   sb.append(", areacode='").append(areacode).append('\'');
   sb.append(", spellid=").append(spellid);
   sb.append('}');
   return sb.toString();
 }
 @Override
 public String toString() {
   StringBuilder builder = new StringBuilder();
   builder.append("PhysicalResourceGroup [");
   if (id != null) {
     builder.append("id=");
     builder.append(id);
     builder.append(", ");
   }
   if (version != null) {
     builder.append("version=");
     builder.append(version);
     builder.append(", ");
   }
   if (institute != null) {
     builder.append("institute=");
     builder.append(institute);
     builder.append(", ");
   }
   if (adminGroup != null) {
     builder.append("adminGroup=");
     builder.append(adminGroup);
     builder.append(", ");
   }
   if (managerEmail != null) {
     builder.append("managerEmail=");
     builder.append(managerEmail);
     builder.append(", ");
   }
   if (active != null) {
     builder.append("active=");
     builder.append(active);
     builder.append(", ");
   }
   if (physicalPorts != null) {
     builder.append("physicalPorts=");
     builder.append(physicalPorts);
     builder.append(", ");
   }
   if (virtualPortRequestLinks != null) {
     builder.append("virtualPortRequestLinks=");
     builder.append(virtualPortRequestLinks);
   }
   builder.append("]");
   return builder.toString();
 }
Beispiel #25
0
  @Override
  public String toString() {
    final StringBuilder builder = new StringBuilder();
    builder.append("Audit >>> ");
    if (userName != null) {
      builder.append(userName);
    }
    if (event != null) {
      if (builder.length() > 0) {
        builder.append(' ');
      }
      builder.append(event);
    }

    if (dataLabel != null) {
      if (builder.length() > 0) {
        builder.append(' ');
      }
      builder.append(dataLabel);
      builder.append('.');
    }

    if (dataId != null) {
      if (builder.length() > 0) {
        builder.append(' ');
      }
      builder.append("ID: '");
      builder.append(dataId);
      builder.append("' Type: '");
      builder.append(dataType);
      builder.append("'");
    }

    if (dataOldVersionId != null || dataNewVersionId != null) {
      if (builder.length() > 0) {
        builder.append(' ');
      }
      builder.append(" Versions: '");
      builder.append(dataOldVersionId);
      builder.append("' -> '");
      builder.append(dataNewVersionId);
      builder.append("'");
    }
    return builder.toString();
  }
Beispiel #26
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 String toString() {
   final StringBuilder sb = new StringBuilder("HibernateOrder{");
   sb.append("id=").append(id);
   sb.append(", buyer=").append(buyer);
   sb.append(", token='").append(token).append('\'');
   sb.append(", amount=").append(amount);
   sb.append(", shipmentAmount=").append(shipmentAmount);
   sb.append(", shipmentType=").append(shipmentType);
   sb.append(", shipmentAddress=").append(shipmentAddress);
   sb.append(", created=").append(created);
   sb.append(", timestamp=").append(timestamp);
   sb.append(", payer='").append(payer).append('\'');
   sb.append(", payerNote='").append(payerNote).append('\'');
   sb.append(", paymentId='").append(paymentId).append('\'');
   sb.append(", tracking=").append(tracking);
   sb.append(", exceptedResume=").append(exceptedResume);
   sb.append(", refundToken='").append(refundToken).append('\'');
   sb.append(", commentary='").append(commentary).append('\'');
   sb.append(", referenceTracking='").append(referenceTracking).append('\'');
   sb.append(", chinaMailTracking='").append(chinaMailTracking).append('\'');
   sb.append(", internationalTracking='").append(internationalTracking).append('\'');
   sb.append(", orderState=").append(orderState);
   sb.append(", orderItems=").append(orderItems);
   sb.append(", orderLogs=").append(orderLogs);
   sb.append(", shipment=").append(shipment);
   sb.append('}');
   return sb.toString();
 }
 @Override
 public String toString() {
   StringBuilder builder = new StringBuilder("toString() - Server ");
   builder.append(AbstractServer.class).append(" [ ID = :").append(id).append(":]");
   return builder.toString();
 }
Beispiel #29
0
  public Query buildQuery(Integer type, T example, String... orden) {
    StringBuilder qry;
    List<String> ids = new ArrayList<String>();
    if (type == 1) {
      qry = new StringBuilder(SELECT_COUNT);
      qry.append(example.getClass().getSimpleName());
    } else {
      qry = new StringBuilder(SELECT);
      qry.append(example.getClass().getSimpleName());
      ids = this.obtenerId(example);
    }
    qry.append(FROM);
    qry.append(WHERE);
    List<Object> parametros = new ArrayList();
    Criterio criterio = new Criterio();
    Map<String, Object> propiedades = this.obtenerPropiedades(example);
    criterio.contruccion(propiedades);
    Set<String> igualdad = criterio.igualdad.keySet();
    Integer idx = 1;
    for (String key : igualdad) {
      if (idx > 1) {
        qry.append(AND);
      }
      qry.append(OBJ);
      qry.append(key);
      qry.append(EQ);
      qry.append(idx);
      parametros.add(criterio.igualdad.get(key));
      idx++;
    }

    Set<String> likeKeys = criterio.like.keySet();
    for (String key : likeKeys) {
      if (idx > 1) {
        qry.append(AND);
      }
      Object valor = criterio.like.get(key);
      if (valor instanceof String) {
        qry.append(LOWER);
        qry.append(OBJ);
        qry.append(key);
        qry.append(")");
        qry.append(LIKE);
        qry.append(idx);
        parametros.add(((String) valor).toLowerCase());
      } else {
        qry.append(OBJ);
        qry.append(key);
        qry.append(LIKE);
        qry.append(idx);
        parametros.add(valor);
      }
      idx++;
    }

    Set<String> compositeKeys = criterio.compuesto.keySet();
    for (String key : compositeKeys) {
      Object value = criterio.compuesto.get(key);
      try {
        if (value.toString().startsWith("class java.util")) {
          continue;
        } else if (StringUtils.containsIgnoreCase(key, "pk")) {
          Map<String, Object> propsComposites = this.obtenerPropiedades(value, key);
          Criterio criterioCompuesto = new Criterio();
          criterioCompuesto.contruccion(propsComposites);
          if (!criterioCompuesto.igualdad.isEmpty()) {
            Set<String> eqKeysPK = criterioCompuesto.igualdad.keySet();
            for (String keyPK : eqKeysPK) {
              if (idx > 1) {
                qry.append(AND);
              }
              qry.append(OBJ);
              qry.append(keyPK);
              qry.append(EQ);
              qry.append(idx);
              parametros.add(criterioCompuesto.igualdad.get(keyPK));
              idx++;
            }
          }
          if (!criterioCompuesto.like.isEmpty()) {
            Set<String> likeKeysPK = criterioCompuesto.like.keySet();
            for (String keyPK : likeKeysPK) {
              if (idx > 1) {
                qry.append(AND);
              }
              Object valor = criterioCompuesto.like.get(keyPK);
              if (valor instanceof String) {
                qry.append(LOWER);
                qry.append(OBJ);
                qry.append(keyPK);
                qry.append(")");
                qry.append(LIKE);
                qry.append(idx);
                parametros.add(((String) valor).toLowerCase());
              } else {
                qry.append(OBJ);
                qry.append(keyPK);
                qry.append(LIKE);
                qry.append(idx);
                parametros.add(valor);
              }
              idx++;
            }
          }
        } else {
          Map<String, Object> propsComposites = this.obtenerPropiedades(value);
          Criterio criterioCompuesto = new Criterio();
          criterioCompuesto.contruccion(propsComposites);
          if (!criterioCompuesto.igualdad.isEmpty()) {
            Set<String> eqKeysPK = criterioCompuesto.igualdad.keySet();
            for (String keyPK : eqKeysPK) {
              if (idx > 1) {
                qry.append(AND);
              }
              qry.append(OBJ);
              qry.append(key);
              qry.append(".");
              qry.append(keyPK);
              qry.append(EQ);
              qry.append(idx);
              parametros.add(criterioCompuesto.igualdad.get(keyPK));
              idx++;
            }
          }
          if (!criterioCompuesto.like.isEmpty()) {
            Set<String> likeKeysPK = criterioCompuesto.like.keySet();
            for (String keyPK : likeKeysPK) {
              System.out.println(
                  "Compuesto LIKE: " + keyPK + ", " + criterioCompuesto.igualdad.get(keyPK));
              if (idx > 1) {
                qry.append(AND);
              }
              Object valor = criterioCompuesto.like.get(keyPK);
              if (valor instanceof String) {
                qry.append(LOWER);
                qry.append(OBJ);
                qry.append(key);
                qry.append(".");
                qry.append(keyPK);
                qry.append(")");
                qry.append(LIKE);
                qry.append(idx);
                parametros.add(((String) valor).toLowerCase());
              } else {
                qry.append(OBJ);
                qry.append(key);
                qry.append(".");
                qry.append(keyPK);
                qry.append(LIKE);
                qry.append(idx);
                parametros.add(valor);
              }
              idx++;
            }
          }
        }
      } catch (RuntimeException e) {
        continue;
      }
    }

    if (idx == 1) {
      qry.append(" 1=1");
    }
    if (!ids.isEmpty()) {
      qry.append(ORDER);
    } else {
      qry.append("  ");
    }
    if (orden.length > 0) {
      for (String ord : orden) {
        qry.append(OBJ);
        qry.append(ord.substring(2));
        if (ord.startsWith("A,")) {
          qry.append(ASC);
        } else if (ord.startsWith("D,")) {
          qry.append(DESC);
        }
      }
    } else {
      for (String id : ids) {
        if (!id.contains("_persistence")) {
          qry.append(OBJ);
          qry.append(id);
          qry.append(ASC);
        }
      }
    }

    System.out.println(qry.substring(0, qry.length() - 2));
    Query query = this.em.createQuery(qry.substring(0, qry.length() - 2));
    if (!parametros.isEmpty()) {
      int i = 1;
      for (Object obj : parametros) {
        query.setParameter(i, obj);
        i++;
      }
    }
    return query;
  }
Beispiel #30
0
 @Override
 public String toString() {
   StringBuilder strBuf = new StringBuilder("AfterSales{");
   strBuf.append("id=").append(this.id);
   strBuf.append(", ");
   strBuf.append("code=").append(this.code);
   strBuf.append(", ");
   strBuf.append("source=").append(this.source);
   strBuf.append(", ");
   strBuf.append("orderId=").append(this.orderId);
   strBuf.append(", ");
   strBuf.append("revisitId=").append(this.revisitId);
   strBuf.append(", ");
   strBuf.append("serviceUserId=").append(this.serviceUserId);
   strBuf.append(", ");
   strBuf.append("serviceUserName="******", ");
   strBuf.append("reasonCode=").append(this.reasonCode);
   strBuf.append(", ");
   strBuf.append("reason=").append(this.reason);
   strBuf.append(", ");
   strBuf.append("remark=").append(this.remark);
   strBuf.append(", ");
   strBuf.append("status=").append(this.status);
   strBuf.append(", ");
   strBuf.append("statusBefore=").append(this.statusBefore);
   strBuf.append(", ");
   strBuf.append("statusRemark=").append(this.statusRemark);
   strBuf.append(", ");
   strBuf.append("send=").append(this.send);
   strBuf.append(", ");
   strBuf.append("buildOrder=").append(this.buildOrder);
   strBuf.append(", ");
   strBuf.append("brandId=").append(this.brandId);
   strBuf.append(", ");
   strBuf.append("brandName=").append(this.brandName);
   strBuf.append(", ");
   strBuf.append("platformType=").append(this.platformType);
   strBuf.append(", ");
   strBuf.append("platformOrderNo=").append(this.platformOrderNo);
   strBuf.append(", ");
   strBuf.append("operatorId=").append(this.operatorId);
   strBuf.append(", ");
   strBuf.append("createTime=").append(this.createTime);
   strBuf.append(", ");
   strBuf.append("updateTime=").append(this.updateTime);
   strBuf.append(", ");
   strBuf.append("version=").append(this.version);
   strBuf.append("}");
   return strBuf.toString();
 }