public static List<RegisterContextRequest> getRegByEntityID(
      final EntityId reqEntityId, final ArrayList<String> discAttrList) {

    List<RegisterContextRequest> results;

    String reqEId = reqEntityId.getId();

    if (reqEId.contentEquals(".*") && reqEntityId.isIsPattern()) {
      System.out.println("\".*\" specified");
      return getRegByEntityType(reqEntityId.getType());
    }

    System.out.println("\".*\" NOT specified");

    results =
        db.query(
            new Predicate<RegisterContextRequest>() {
              public boolean match(RegisterContextRequest req) {

                final int contRegListSize = req.getContextRegistration().size();

                for (int i = 0; i < contRegListSize; i++) {

                  final int reqEIdListSize =
                      req.getContextRegistration().get(i).getEntityId().size();

                  for (int j = 0; j < reqEIdListSize; j++) {

                    String storedId =
                        req.getContextRegistration().get(i).getEntityId().get(j).getId();

                    String storedIdType =
                        req.getContextRegistration().get(i).getEntityId().get(j).getType();

                    //                        String reqEId = reqEntityId.getId();
                    boolean reqIsPattern; // = false;
                    String reqIdType = "";

                    try {
                      if (reqEntityId.getType() != null) {
                        reqIdType = reqEntityId.getType();
                      }
                    } catch (NullPointerException npe) {
                      System.out.println("'type' field missing in request");
                    }
                    if (!reqIdType.isEmpty()) {

                      if (!reqIdType.equals(storedIdType)) {
                        continue;
                      }
                    }

                    try {
                      reqIsPattern = reqEntityId.isIsPattern();
                    } catch (NullPointerException npe) {
                      System.out.println("'isPattern' field missing in request");
                      reqIsPattern = false;
                    }

                    List<ContextRegistrationAttribute> contRegAttrlist =
                        req.getContextRegistration().get(i).getContextRegistrationAttribute();

                    boolean attrMatch = checkAttrMatch(contRegAttrlist, discAttrList);

                    if (reqIsPattern) {
                      if (reqEId.contains("*")) {
                        if (reqEId.startsWith("*")) {
                          String[] suffix = reqEId.split("\\*");
                          //                                       System.out.println("ends with:
                          // "+suffix[1]);
                          //                                       System.out.println("stored:
                          // "+storedId);
                          if ((storedId.endsWith(suffix[1]) && reqIdType.isEmpty())
                              || (storedId.endsWith(suffix[1])
                                  && storedIdType.equals(reqEntityId.getType()))) {
                            System.out.println("'isPattern'");
                            return true;
                          }
                        } else if (reqEId.endsWith(".*")) {
                          String[] suffix = reqEId.split("\\.*");
                          // System.out.println(suffix[0]);
                          if ((storedId.startsWith(suffix[0]) && reqIdType.isEmpty())
                              || (storedId.startsWith(suffix[0])
                                  && storedIdType.equals(reqEntityId.getType()))) {
                            return true;
                          }
                        }
                      }
                    } else {
                      if (reqIdType.isEmpty() && storedId.equals(reqEntityId.getId())) {
                        return true;
                      } else if (storedIdType.equals(reqEntityId.getType())
                          && storedId.equals(reqEntityId.getId())) {
                        return true;
                      }
                    } // if not regIsPattern
                  }
                } // loop until true or end
                return false;
              }
            });
    return results;
  }