/** * Checks to see if this object has been tagged with any of the given tags. * * @param tags the tags to add (String to tokenize, NSArray<String>, etc) * @return true if this eo is tagged with any of the given tag names, false otherwise */ public boolean isTaggedWithAny(Object tags) { NSArray<String> tagNames = _entity.splitTagNames(tags); return ERXQ.filtered(tags(), ERTag.NAME.in(tagNames)).count() > 0; }
/** * This method removes tags from the target object, by parsing the tags parameter * into Tag object instances and removing them from the tag collection of the object if they exist. * * @param tags the tags to remove (String to tokenize, NSArray<String>, etc) */ public void removeTags(Object tags) { NSArray<ERTag> erTags = tags(); NSArray<ERTag> matchingTags = ERXQ.filtered(erTags, ERTag.NAME.in(_entity.splitTagNames(tags))); for (ERTag tag : matchingTags) { removeTag(tag); } }
/** * Checks to see if this object has been tagged with all the given tags. * * @param tags the tags to add (String to tokenize, NSArray<String>, etc) * @return true if this eo is tagged with all of the given tag names, false otherwise */ public boolean isTaggedWithAll(Object tags) { NSArray<String> tagNames = _entity.splitTagNames(tags); return ERXQ.filtered(tags(), ERTag.NAME.in(tagNames)).count() == tagNames.count(); }
/** * This method returns a simple count of the number of distinct objects which match the tags provided. * * @param editingContext the editing context to fetch into * @param tags the tags to search (String to tokenize, NSArray<String>, etc) * @param inclusion find matches for ANY tags or ALL tags provided * @return the count of distinct objects for the given tags */ public int countUniqueTaggedWith(EOEditingContext editingContext, ERTag.Inclusion inclusion, Object tags) { NSArray<String> tagNames = splitTagNames(tags); if (tagNames.count() == 0) { throw new IllegalArgumentException("No tags were passed in."); } EOQualifier qualifier = new ERXKey<ERTag>(_tagsRelationship.name()).append(ERTag.NAME).in(tagNames); EOFetchSpecification fetchSpec = new EOFetchSpecification(_entity.name(), qualifier, null); fetchSpec.setUsesDistinct(true); ERXSQLHelper sqlHelper = ERXSQLHelper.newSQLHelper(_entity.model()); EOSQLExpression sqlExpression = sqlHelper.sqlExpressionForFetchSpecification(editingContext, fetchSpec, 0, -1); sqlHelper.addGroupByClauseToExpression(editingContext, fetchSpec, sqlExpression); if (inclusion == ERTag.Inclusion.ALL) { sqlHelper.addHavingCountClauseToExpression(EOQualifier.QualifierOperatorEqual, tagNames.count(), sqlExpression); } int count = sqlHelper.rowCountForFetchSpecification(editingContext, fetchSpec); return count; }
EOQualifier qualifier = new ERXKey<ERTag>(_tagsRelationship.name()).append(ERTag.NAME).in(tagNames); if (additionalQualifier != null) { qualifier = ERXQ.and(qualifier, additionalQualifier);
EOQualifier tagNameQualifier = new ERXKey<ERTag>(_tagsRelationship.name()).append(ERTag.NAME).in(tagNames); EOFetchSpecification fetchSpec = new EOFetchSpecification(_entity.name(), tagNameQualifier, null); EOSQLExpression sqlExpression = sqlHelper.sqlExpressionForFetchSpecification(editingContext, fetchSpec, 0, -1, fetchAttributes); tagsFetchAttributes.addObject(countAttribute); EOQualifier idQualifier = new ERXKey<Object>("id").in(itemPrimaryKeys); EOFetchSpecification tagsFetchSpec = new EOFetchSpecification(_entity.name(), idQualifier, null); EOSQLExpression tagsSqlExpression = sqlHelper.sqlExpressionForFetchSpecification(editingContext, tagsFetchSpec, 0, -1, tagsFetchAttributes);