private String gidStringForObject(EOEnterpriseObject eo) { EOKeyGlobalID gid = ((ERXGenericRecord) eo).permanentGlobalID(); String pk = ERXKeyGlobalID.globalIDForGID(gid).asString(); return pk; }
protected void handleUpdate(EOEditingContext ec, EOEnterpriseObject target, String keyPath, EOEnterpriseObject eo) { ERXGenericRecord rec = (ERXGenericRecord) target; EOEnterpriseObject oldValue = (EOEnterpriseObject) rec.valueForKeyPath(keyPath); handleChange(ec, target, ERCAuditTrailType.UPDATED, keyPath, oldValue, oldValue); }
/** * Adds the tag to this item. This is the single method that to override * if you need to perform some additional operations. * * @param tag the tag to add */ protected void addTag(ERTag tag) { _item.addObjectToBothSidesOfRelationshipWithKey(tag, _entity.tagsRelationshipName()); }
protected NSArray indexableObjectsForObject(String type, EOEnterpriseObject object) { ERXGenericRecord eo = (ERXGenericRecord) object; EOEditingContext ec = eo.editingContext(); NSMutableSet<EOEnterpriseObject> result = new NSMutableSet(); String entityName = eo.entityName(); ConfigurationEntry config = _configuration.entryForKey(entityName); if (config != null) { value = eo.valueForKey(key); } else { if (eo.isNewObject()) { if (!_warned.containsObject(entityName)) { log.error("We currently don't support unsaved related objects for this entity: " + entityName);
/** * Performs submit action. Overridden to reset the nested validation setting on the * object. */ // FIXME - Is this needed here? davidleber @Override public WOComponent submitAction() throws Throwable { WOComponent result = super.submitAction(); if (object() instanceof ERXGenericRecord) { ((ERXGenericRecord)object()).setValidatedWhenNested(true); } return result; }
/** * This method applies tags to the target object, by parsing the tags parameter * into Tag object instances and adding them to the tag collection of the object. * If the tag name already exists in the tags table, it just adds a relationship * to the existing tag record. If it doesn't exist, it then creates a new * Tag record for it. * * @param tags the tags to add (String to tokenize, NSArray<String>, etc) * @param clear if true, existing tags will be removed first */ public void addTags(boolean clear, Object tags) { // clear the collection if appropriate if (clear) { clearTags(); } NSArray<ERTag> erTags = tags(); EOEditingContext editingContext = _item.editingContext(); // append the tag names to the collection for (String tagName : _entity.splitTagNames(tags)) { // ensure that tag names don't get duplicated ERTag tag = _entity.fetchTagNamed(editingContext, tagName, true); if (!erTags.containsObject(tag)) { addTag(tag); } } }
@Override public int hashCode() { return _item.hashCode(); }
@Override public boolean equals(Object obj) { return (obj instanceof ERTaggable && ((ERTaggable<?>)obj)._item.equals(_item)); }
/** * Shortcut for getting an ERTaggableEntity for an EO. * * @param <T> the type of the entity * @param eo the EO * @return an ERTaggableEntity corresponding to the entity of the EO */ public static <T extends ERXGenericRecord> ERTaggableEntity<T> taggableEntity(T eo) { return ERTaggableEntity.taggableEntity(eo.entity()); }
@Override public void init(EOEditingContext ec) { super.init(ec); if (this instanceof ERCLogEntryInterface) { ERCLogEntryInterface lei = (ERCLogEntryInterface) this; String relationshipName =lei.relationshipNameForLogEntry(); EOEnterpriseObject logType = lei.logEntryType(); if (relationshipName != null && logType != null) { insertionLogEntry=ERCLogEntry.clazz.createLogEntryLinkedToEO(logType, null, this, relationshipName); } } // We now set the date created/last modified in willInsert/Update/Delete // A side effect of this technique is that for new EOs, created/lastModified is null until the EO actually gets saved // which means it'll fail the validation // two options: either we poke a value in those attributes here (even though it will be modified in willInsert, // or we make the property keys not mandatory // I am option for the former. NSTimestamp t=new NSTimestamp(); setCreated(t); setLastModified(t); }
/** * Performs the newObjectAction. Creates a new object and sets the inline task * to 'create' */ public WOComponent newObjectAction() { EOEditingContext newEc = ERXEC.newEditingContext(masterObject().editingContext()); EOClassDescription relatedObjectClassDescription = masterObject().classDescriptionForDestinationKey(relationshipKey()); EOEnterpriseObject relatedObject = EOUtilities.createAndInsertInstance(newEc, relatedObjectClassDescription.entityName()); EOEnterpriseObject localObj = EOUtilities.localInstanceOfObject(relatedObject.editingContext(), masterObject()); if (localObj instanceof ERXGenericRecord) { ((ERXGenericRecord)localObj).setValidatedWhenNested(false); } localObj.addObjectToBothSidesOfRelationshipWithKey(relatedObject, relationshipKey()); setSelectedObject(relatedObject); setInlineTaskSafely("create"); return null; }
public NSArray<String> availableTags() { clearCacheIfNecessary(); if (_availableTags == null) { EOEditingContext editingContext = taggable().item().editingContext(); int minimum = minimum(); int limit = limit(); NSArray<String> availableTags; if (minimum == -1) { NSDictionary<String, Integer> tagCount = taggable().taggableEntity().tagCount(editingContext, limit, additionalQualifier()); availableTags = tagCount.allKeys(); } else { NSDictionary<String, Integer> tagCount = taggable().taggableEntity().tagCount(editingContext, ERXQ.GTEQ, minimum, limit, additionalQualifier()); availableTags = tagCount.allKeys(); } _availableTags = ERXArrayUtilities.sortedArrayUsingComparator(availableTags, NSComparator.AscendingStringComparator); } return _availableTags; }
public void setObject(EOEnterpriseObject eo) { EOGlobalID gid; if (gid() == null) { if (eo instanceof ERXGenericRecord) { gid = ((ERXGenericRecord) eo).permanentGlobalID(); } else { throw new IllegalArgumentException("Can't handle non ERXGenericRecord"); } ERXKeyGlobalID keyGID = ERXKeyGlobalID.globalIDForGID((EOKeyGlobalID) gid); setGid(keyGID); } }
/** * Action called when user clicks the Add button */ public WOActionResults addObject() { String currentPageConfiguration = stringValueForBinding(Keys.pageConfiguration); NSDictionary<String, String> extraValues = currentPageConfiguration != null ? new NSDictionary<String, String>(currentPageConfiguration, Keys.pageConfiguration) : null; String createPageConfigurationName = (String)ERDirectToWeb.d2wContextValueForKey(Keys.createConfigurationName, destinationEntityName(), extraValues); EditPageInterface epi = (EditPageInterface)D2W.factory().pageForConfigurationNamed(createPageConfigurationName, session()); EOEditingContext newEc = ERXEC.newEditingContext(object().editingContext()); EOEnterpriseObject relatedObject = EOUtilities.createAndInsertInstance(newEc, destinationEntityName()); EOEnterpriseObject localObj = ERXEOControlUtilities.localInstanceOfObject(relatedObject.editingContext(), object()); if (localObj instanceof ERXGenericRecord) { ((ERXGenericRecord)localObj).setValidatedWhenNested(false); } localObj.addObjectToBothSidesOfRelationshipWithKey(relatedObject, propertyKey()); epi.setNextPage(context().page()); epi.setObject(relatedObject); // Null out the current searchValue so when we come back, it regenerates _searchValue = null; return (WOActionResults) epi; }
/** * Returns an array of ERTags associated with this item. * * @return an array of ERTags associated with this item */ @SuppressWarnings("unchecked") public NSArray<ERTag> tags() { String tagsRelationshipName = _entity.tagsRelationshipName(); return (NSArray<ERTag>) _item.valueForKeyPath(tagsRelationshipName); }
protected void handleChange(EOEditingContext ec, EOEnterpriseObject eo, ERCAuditTrailType type, String keyPath, Object oldValue, Object newValue) { ERXGenericRecord rec = (ERXGenericRecord) eo; ERCAuditTrail trail = ERCAuditTrail.clazz.auditTrailForObject(ec, eo); if (trail == null) { trail = ERCAuditTrail.clazz.createAuditTrailForObject(ec, eo); } log.info("{} {}: {} {} from {} to {}", trail, type, rec.permanentGlobalID(), keyPath, oldValue, newValue); if (oldValue instanceof ERXGenericRecord) { ERXGenericRecord rec1 = (ERXGenericRecord) oldValue; oldValue = ERXKeyGlobalID.globalIDForGID(rec1.permanentGlobalID()).asString(); } if (newValue instanceof ERXGenericRecord) { ERXGenericRecord rec1 = (ERXGenericRecord) newValue; newValue = ERXKeyGlobalID.globalIDForGID(rec1.permanentGlobalID()).asString(); } trail.createEntry(type, keyPath, oldValue, newValue); } }
protected Document createDocumentForObject(EOEnterpriseObject eo) { EOKeyGlobalID gid = ((ERXGenericRecord) eo).permanentGlobalID(); IndexDocument document = createDocumentForGlobalID(gid); Document doc = document.document(); for (IndexAttribute info : attributes()) { String key = info.name(); Object value = eo.valueForKeyPath(key); if (log.isDebugEnabled()) { log.info(key + "->" + value); } String stringValue = info.formatValue(value); if (stringValue != null) { Field field = new Field(key, stringValue, info.store(), info.index(), info.termVector()); document.document().add(field); } } return doc; }
@Override public void init(EOEditingContext ec) { super.init(ec); EOEnterpriseObject user = ERCoreBusinessLogic.actor(ec); if (user != null && user instanceof ERXGenericRecord) { ERXKeyGlobalID gid = ERXKeyGlobalID.globalIDForGID(((ERXGenericRecord) user).permanentGlobalID()); setUserGlobalID(gid); } setCreated(new NSTimestamp()); }
public ERCAuditTrail auditTrailForObject(EOEditingContext ec, EOEnterpriseObject eo) { EOKeyGlobalID gid = null; if (eo instanceof ERXGenericRecord) { gid = ((ERXGenericRecord) eo).permanentGlobalID(); } else { throw new IllegalArgumentException("Can't handle non ERXGenericRecord"); } ERCAuditTrail trail = (ERCAuditTrail) ERXEOControlUtilities.objectWithQualifier(ec, ENTITY_NAME, ERXQ.equals(Key.GID, ERXKeyGlobalID.globalIDForGID(gid))); if (trail == null) { trail = (ERCAuditTrail) EOQualifier.filteredArrayWithQualifier(ec.insertedObjects(), ERXQ.equals("entityName", ENTITY_NAME).and(ERXQ.equals(Key.GID + ".globalID", gid))).lastObject(); } return trail; }
protected NSDictionary serializeObject(EOEnterpriseObject eo) { NSMutableDictionary<String, Object> result = new NSMutableDictionary<>(); result.addEntriesFromDictionary(eo.snapshot()); for (Enumeration e = eo.snapshot().keyEnumerator(); e.hasMoreElements();) { String key = (String) e.nextElement(); Object value = result.objectForKey(key); if (value instanceof ERXConstant.Constant) { ERXConstant.Constant constant = (ERXConstant.Constant) value; result.setObjectForKey(constant.value(), key); } else if (value == NSKeyValueCoding.NullValue) { result.removeObjectForKey(key); } else if (value instanceof ERXGenericRecord) { ERXGenericRecord rec = (ERXGenericRecord) value; result.setObjectForKey(ERXKeyGlobalID.globalIDForGID(rec.permanentGlobalID()).asString(), key); } else if (value instanceof NSArray) { NSArray oldValue = (NSArray) value; NSMutableArray newValue = new NSMutableArray(oldValue.count()); for (Enumeration e1 = newValue.objectEnumerator(); e1.hasMoreElements();) { ERXGenericRecord rec = (ERXGenericRecord) e1.nextElement(); newValue.addObject(ERXKeyGlobalID.globalIDForGID(rec.permanentGlobalID()).asString()); } result.setObjectForKey(newValue, key); } } return result; }