/**
   * Retrieve objects according to the <code>subscriptionsForMessageTypeAndUser</code> fetch
   * specification.
   *
   * @param context The editing context to use
   * @param messageTypeBinding fetch spec parameter
   * @param userBinding fetch spec parameter
   * @return an NSArray of the entities retrieved
   */
  public static NSArray<UserMessageSubscription> subscriptionsForMessageTypeAndUser(
      EOEditingContext context, String messageTypeBinding, org.webcat.core.User userBinding) {
    EOFetchSpecification spec =
        WCFetchSpecification.fetchSpecificationNamed(
            "subscriptionsForMessageTypeAndUser", "UserMessageSubscription");

    NSMutableDictionary<String, Object> bindings = new NSMutableDictionary<String, Object>();

    if (messageTypeBinding != null) {
      bindings.setObjectForKey(messageTypeBinding, "messageType");
    }
    if (userBinding != null) {
      bindings.setObjectForKey(userBinding, "user");
    }
    spec = spec.fetchSpecificationWithQualifierBindings(bindings);

    NSArray<UserMessageSubscription> objects = objectsWithFetchSpecification(context, spec);
    if (log.isDebugEnabled()) {
      log.debug(
          "subscriptionsForMessageTypeAndUser(ec"
              + ", "
              + messageTypeBinding
              + ", "
              + userBinding
              + "): "
              + objects);
    }
    return objects;
  }
  /**
   * Retrieve the count of objects using a list of keys and values to match.
   *
   * @param context The editing context to use
   * @param keysAndValues a list of keys and values to match, alternating "key", "value", "key",
   *     "value"...
   * @return the count of objects that match the specified values
   */
  public static int countOfObjectsMatchingValues(
      EOEditingContext context, Object... keysAndValues) {
    if (keysAndValues.length % 2 != 0) {
      throw new IllegalArgumentException(
          "There should a value "
              + "corresponding to every key that was passed. Args = "
              + java.util.Arrays.toString(keysAndValues));
    }

    NSMutableDictionary<String, Object> valueDictionary = new NSMutableDictionary<String, Object>();

    for (int i = 0; i < keysAndValues.length; i += 2) {
      Object key = keysAndValues[i];
      Object value = keysAndValues[i + 1];

      if (key == null) {
        throw new IllegalArgumentException(
            "Found null where a String key was expected, arguments = "
                + java.util.Arrays.toString(keysAndValues));
      } else if (!(key instanceof String)) {
        throw new IllegalArgumentException(
            "Found a "
                + key.getClass().getName()
                + " ["
                + key
                + "]"
                + " where a String key was expected, arguments = "
                + java.util.Arrays.toString(keysAndValues));
      }

      valueDictionary.setObjectForKey(value, (String) key);
    }

    return countOfObjectsMatchingValues(context, valueDictionary);
  }
Example #3
0
 public static NSArray<edu.umich.marketplace.eof.Category> fetchSubCategories(
     EOEditingContext editingContext, edu.umich.marketplace.eof.Category parentBinding) {
   EOFetchSpecification fetchSpec =
       EOFetchSpecification.fetchSpecificationNamed("subCategories", "Category");
   NSMutableDictionary<String, Object> bindings = new NSMutableDictionary<String, Object>();
   bindings.takeValueForKey(parentBinding, "parent");
   fetchSpec = fetchSpec.fetchSpecificationWithQualifierBindings(bindings);
   return (NSArray<edu.umich.marketplace.eof.Category>)
       editingContext.objectsWithFetchSpecification(fetchSpec);
 }
 public static NSArray<org.pachyderm.foundation.eof.PDBPresentation>
     fetchPresentationNamesAndIdentities(EOEditingContext editingContext, String authorBinding) {
   EOFetchSpecification fetchSpec =
       EOFetchSpecification.fetchSpecificationNamed(
           "presentationNamesAndIdentities", _PDBPresentation.ENTITY_NAME);
   NSMutableDictionary<String, Object> bindings = new NSMutableDictionary<String, Object>();
   bindings.takeValueForKey(authorBinding, "author");
   fetchSpec = fetchSpec.fetchSpecificationWithQualifierBindings(bindings);
   return (NSArray<org.pachyderm.foundation.eof.PDBPresentation>)
       editingContext.objectsWithFetchSpecification(fetchSpec);
 }