/*==========================================================================*\ | _Assignment.java |*-------------------------------------------------------------------------*| | Created by eogenerator | DO NOT EDIT. Make changes to Assignment.java instead. |*-------------------------------------------------------------------------*| | Copyright (C) 2006-2012 Virginia Tech | | This file is part of Web-CAT. | | Web-CAT is free software; you can redistribute it and/or modify | it under the terms of the GNU Affero General Public License as published | by the Free Software Foundation; either version 3 of the License, or | (at your option) any later version. | | Web-CAT is distributed in the hope that it will be useful, | but WITHOUT ANY WARRANTY; without even the implied warranty of | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | GNU General Public License for more details. | | You should have received a copy of the GNU Affero General Public License | along with Web-CAT; if not, see <http://www.gnu.org/licenses/>. \*==========================================================================*/ package org.webcat.grader; import com.webobjects.eoaccess.*; import com.webobjects.eocontrol.*; import com.webobjects.foundation.*; import er.extensions.eof.ERXEOControlUtilities; import er.extensions.eof.ERXKey; import org.apache.log4j.Logger; import org.webcat.core.EOBasedKeyGenerator; import org.webcat.woextensions.WCFetchSpecification; // ------------------------------------------------------------------------- /** * An automatically generated EOGenericRecord subclass. DO NOT EDIT. * To change, use EOModeler, or make additions in * Assignment.java. * * @author Generated by eogenerator * @version version suppressed to control auto-generation */ public abstract class _Assignment extends org.webcat.core.EOBase { //~ Constructors .......................................................... // ---------------------------------------------------------- /** * Creates a new _Assignment object. */ public _Assignment() { super(); } // ---------------------------------------------------------- /** * A static factory method for creating a new * Assignment object given required * attributes and relationships. * @param editingContext The context in which the new object will be * inserted * @param trackOpinionsValue * @return The newly created object */ public static Assignment create( EOEditingContext editingContext, boolean trackOpinionsValue ) { Assignment eoObject = (Assignment) EOUtilities.createAndInsertInstance( editingContext, _Assignment.ENTITY_NAME); eoObject.setTrackOpinions(trackOpinionsValue); return eoObject; } // ---------------------------------------------------------- /** * Get a local instance of the given object in another editing context. * @param editingContext The target editing context * @param eo The object to import * @return An instance of the given object in the target editing context */ public static Assignment localInstance( EOEditingContext editingContext, Assignment eo) { return (eo == null) ? null : (Assignment)EOUtilities.localInstanceOfObject( editingContext, eo); } // ---------------------------------------------------------- /** * Look up an object by id number. Assumes the editing * context is appropriately locked. * @param ec The editing context to use * @param id The id to look up * @return The object, or null if no such id exists */ public static Assignment forId( EOEditingContext ec, int id) { Assignment obj = null; if (id > 0) { NSArray<Assignment> objects = objectsMatchingValues(ec, "id", new Integer(id)); if (objects != null && objects.count() > 0) { obj = objects.objectAtIndex(0); } } return obj; } // ---------------------------------------------------------- /** * Look up an object by id number. Assumes the editing * context is appropriately locked. * @param ec The editing context to use * @param id The id to look up * @return The object, or null if no such id exists */ public static Assignment forId( EOEditingContext ec, String id) { return forId(ec, er.extensions.foundation.ERXValueUtilities.intValue(id)); } //~ Constants (for key names) ............................................. // Attributes --- public static final String FILE_UPLOAD_MESSAGE_KEY = "fileUploadMessage"; public static final ERXKey<String> fileUploadMessage = new ERXKey<String>(FILE_UPLOAD_MESSAGE_KEY); public static final String MOODLE_ID_KEY = "moodleId"; public static final ERXKey<Long> moodleId = new ERXKey<Long>(MOODLE_ID_KEY); public static final String NAME_KEY = "name"; public static final ERXKey<String> name = new ERXKey<String>(NAME_KEY); public static final String SHORT_DESCRIPTION_KEY = "shortDescription"; public static final ERXKey<String> shortDescription = new ERXKey<String>(SHORT_DESCRIPTION_KEY); public static final String TRACK_OPINIONS_KEY = "trackOpinions"; public static final ERXKey<Integer> trackOpinions = new ERXKey<Integer>(TRACK_OPINIONS_KEY); public static final String URL_KEY = "url"; public static final ERXKey<String> url = new ERXKey<String>(URL_KEY); // To-one relationships --- public static final String AUTHOR_KEY = "author"; public static final ERXKey<org.webcat.core.User> author = new ERXKey<org.webcat.core.User>(AUTHOR_KEY); public static final String GRADING_CRITERIA_KEY = "gradingCriteria"; public static final ERXKey<org.webcat.grader.GradingCriteria> gradingCriteria = new ERXKey<org.webcat.grader.GradingCriteria>(GRADING_CRITERIA_KEY); public static final String SUBMISSION_PROFILE_KEY = "submissionProfile"; public static final ERXKey<org.webcat.grader.SubmissionProfile> submissionProfile = new ERXKey<org.webcat.grader.SubmissionProfile>(SUBMISSION_PROFILE_KEY); // To-many relationships --- public static final String OFFERINGS_KEY = "offerings"; public static final ERXKey<org.webcat.grader.AssignmentOffering> offerings = new ERXKey<org.webcat.grader.AssignmentOffering>(OFFERINGS_KEY); public static final String STEPS_KEY = "steps"; public static final ERXKey<org.webcat.grader.Step> steps = new ERXKey<org.webcat.grader.Step>(STEPS_KEY); // Fetch specifications --- public static final String ASSIGNMENTS_FOR_REUSE_IN_COURSE_FSPEC = "assignmentsForReuseInCourse"; public static final String NEIGHBOR_ASSIGNMENTS_FSPEC = "neighborAssignments"; public static final String ENTITY_NAME = "Assignment"; public transient final EOBasedKeyGenerator generateKey = new EOBasedKeyGenerator(this); //~ Methods ............................................................... // ---------------------------------------------------------- /** * Get a local instance of this object in another editing context. * @param editingContext The target editing context * @return An instance of this object in the target editing context */ public Assignment localInstance(EOEditingContext editingContext) { return (Assignment)EOUtilities.localInstanceOfObject( editingContext, this); } // ---------------------------------------------------------- /** * Get a list of changes between this object's current state and the * last committed version. * @return a dictionary of the changes that have not yet been committed */ @SuppressWarnings("unchecked") public NSDictionary<String, Object> changedProperties() { return changesFromSnapshot( editingContext().committedSnapshotForObject(this)); } // ---------------------------------------------------------- /** * Retrieve this object's <code>id</code> value. * @return the value of the attribute */ public Number id() { try { return (Number)EOUtilities.primaryKeyForObject( editingContext() , this).objectForKey("id"); } catch (Exception e) { return er.extensions.eof.ERXConstant.ZeroInteger; } } // ---------------------------------------------------------- /** * Retrieve this object's <code>fileUploadMessage</code> value. * @return the value of the attribute */ public String fileUploadMessage() { return (String)storedValueForKey( "fileUploadMessage" ); } // ---------------------------------------------------------- /** * Change the value of this object's <code>fileUploadMessage</code> * property. * * @param value The new value for this property */ public void setFileUploadMessage( String value ) { if (log.isDebugEnabled()) { log.debug( "setFileUploadMessage(" + value + "): was " + fileUploadMessage() ); } takeStoredValueForKey( value, "fileUploadMessage" ); } // ---------------------------------------------------------- /** * Retrieve this object's <code>moodleId</code> value. * @return the value of the attribute */ public Long moodleId() { return (Long)storedValueForKey( "moodleId" ); } // ---------------------------------------------------------- /** * Change the value of this object's <code>moodleId</code> * property. * * @param value The new value for this property */ public void setMoodleId( Long value ) { if (log.isDebugEnabled()) { log.debug( "setMoodleId(" + value + "): was " + moodleId() ); } takeStoredValueForKey( value, "moodleId" ); } // ---------------------------------------------------------- /** * Retrieve this object's <code>name</code> value. * @return the value of the attribute */ public String name() { return (String)storedValueForKey( "name" ); } // ---------------------------------------------------------- /** * Change the value of this object's <code>name</code> * property. * * @param value The new value for this property */ public void setName( String value ) { if (log.isDebugEnabled()) { log.debug( "setName(" + value + "): was " + name() ); } takeStoredValueForKey( value, "name" ); } // ---------------------------------------------------------- /** * Retrieve this object's <code>shortDescription</code> value. * @return the value of the attribute */ public String shortDescription() { return (String)storedValueForKey( "shortDescription" ); } // ---------------------------------------------------------- /** * Change the value of this object's <code>shortDescription</code> * property. * * @param value The new value for this property */ public void setShortDescription( String value ) { if (log.isDebugEnabled()) { log.debug( "setShortDescription(" + value + "): was " + shortDescription() ); } takeStoredValueForKey( value, "shortDescription" ); } // ---------------------------------------------------------- /** * Retrieve this object's <code>trackOpinions</code> value. * @return the value of the attribute */ public boolean trackOpinions() { Integer returnValue = (Integer)storedValueForKey( "trackOpinions" ); return ( returnValue == null ) ? false : ( returnValue.intValue() > 0 ); } // ---------------------------------------------------------- /** * Change the value of this object's <code>trackOpinions</code> * property. * * @param value The new value for this property */ public void setTrackOpinions( boolean value ) { if (log.isDebugEnabled()) { log.debug( "setTrackOpinions(" + value + "): was " + trackOpinions() ); } Integer actual = er.extensions.eof.ERXConstant.integerForInt( value ? 1 : 0 ); setTrackOpinionsRaw( actual ); } // ---------------------------------------------------------- /** * Retrieve this object's <code>trackOpinions</code> value. * @return the value of the attribute */ public Integer trackOpinionsRaw() { return (Integer)storedValueForKey( "trackOpinions" ); } // ---------------------------------------------------------- /** * Change the value of this object's <code>trackOpinions</code> * property. * * @param value The new value for this property */ public void setTrackOpinionsRaw( Integer value ) { if (log.isDebugEnabled()) { log.debug( "setTrackOpinionsRaw(" + value + "): was " + trackOpinionsRaw() ); } takeStoredValueForKey( value, "trackOpinions" ); } // ---------------------------------------------------------- /** * Retrieve this object's <code>url</code> value. * @return the value of the attribute */ public String url() { return (String)storedValueForKey( "url" ); } // ---------------------------------------------------------- /** * Change the value of this object's <code>url</code> * property. * * @param value The new value for this property */ public void setUrl( String value ) { if (log.isDebugEnabled()) { log.debug( "setUrl(" + value + "): was " + url() ); } takeStoredValueForKey( value, "url" ); } // ---------------------------------------------------------- /** * Retrieve the entity pointed to by the <code>author</code> * relationship. * @return the entity in the relationship */ public org.webcat.core.User author() { return (org.webcat.core.User)storedValueForKey( "author" ); } // ---------------------------------------------------------- /** * Set the entity pointed to by the <code>author</code> * relationship (DO NOT USE--instead, use * <code>setAuthorRelationship()</code>. * This method is provided for WebObjects use. * * @param value The new entity to relate to */ public void setAuthor( org.webcat.core.User value ) { if (log.isDebugEnabled()) { log.debug( "setAuthor(" + value + "): was " + author() ); } takeStoredValueForKey( value, "author" ); } // ---------------------------------------------------------- /** * Set the entity pointed to by the <code>author</code> * relationship. This method is a type-safe version of * <code>addObjectToBothSidesOfRelationshipWithKey()</code>. * * @param value The new entity to relate to */ public void setAuthorRelationship( org.webcat.core.User value ) { if (log.isDebugEnabled()) { log.debug( "setAuthorRelationship(" + value + "): was " + author() ); } if ( value == null ) { org.webcat.core.User object = author(); if ( object != null ) removeObjectFromBothSidesOfRelationshipWithKey( object, "author" ); } else { addObjectToBothSidesOfRelationshipWithKey( value, "author" ); } } // ---------------------------------------------------------- /** * Retrieve the entity pointed to by the <code>gradingCriteria</code> * relationship. * @return the entity in the relationship */ public org.webcat.grader.GradingCriteria gradingCriteria() { return (org.webcat.grader.GradingCriteria)storedValueForKey( "gradingCriteria" ); } // ---------------------------------------------------------- /** * Set the entity pointed to by the <code>gradingCriteria</code> * relationship (DO NOT USE--instead, use * <code>setGradingCriteriaRelationship()</code>. * This method is provided for WebObjects use. * * @param value The new entity to relate to */ public void setGradingCriteria( org.webcat.grader.GradingCriteria value ) { if (log.isDebugEnabled()) { log.debug( "setGradingCriteria(" + value + "): was " + gradingCriteria() ); } takeStoredValueForKey( value, "gradingCriteria" ); } // ---------------------------------------------------------- /** * Set the entity pointed to by the <code>gradingCriteria</code> * relationship. This method is a type-safe version of * <code>addObjectToBothSidesOfRelationshipWithKey()</code>. * * @param value The new entity to relate to */ public void setGradingCriteriaRelationship( org.webcat.grader.GradingCriteria value ) { if (log.isDebugEnabled()) { log.debug( "setGradingCriteriaRelationship(" + value + "): was " + gradingCriteria() ); } if ( value == null ) { org.webcat.grader.GradingCriteria object = gradingCriteria(); if ( object != null ) removeObjectFromBothSidesOfRelationshipWithKey( object, "gradingCriteria" ); } else { addObjectToBothSidesOfRelationshipWithKey( value, "gradingCriteria" ); } } // ---------------------------------------------------------- /** * Retrieve the entity pointed to by the <code>submissionProfile</code> * relationship. * @return the entity in the relationship */ public org.webcat.grader.SubmissionProfile submissionProfile() { return (org.webcat.grader.SubmissionProfile)storedValueForKey( "submissionProfile" ); } // ---------------------------------------------------------- /** * Set the entity pointed to by the <code>submissionProfile</code> * relationship (DO NOT USE--instead, use * <code>setSubmissionProfileRelationship()</code>. * This method is provided for WebObjects use. * * @param value The new entity to relate to */ public void setSubmissionProfile( org.webcat.grader.SubmissionProfile value ) { if (log.isDebugEnabled()) { log.debug( "setSubmissionProfile(" + value + "): was " + submissionProfile() ); } takeStoredValueForKey( value, "submissionProfile" ); } // ---------------------------------------------------------- /** * Set the entity pointed to by the <code>submissionProfile</code> * relationship. This method is a type-safe version of * <code>addObjectToBothSidesOfRelationshipWithKey()</code>. * * @param value The new entity to relate to */ public void setSubmissionProfileRelationship( org.webcat.grader.SubmissionProfile value ) { if (log.isDebugEnabled()) { log.debug( "setSubmissionProfileRelationship(" + value + "): was " + submissionProfile() ); } if ( value == null ) { org.webcat.grader.SubmissionProfile object = submissionProfile(); if ( object != null ) removeObjectFromBothSidesOfRelationshipWithKey( object, "submissionProfile" ); } else { addObjectToBothSidesOfRelationshipWithKey( value, "submissionProfile" ); } } // ---------------------------------------------------------- /** * Retrieve the entities pointed to by the <code>offerings</code> * relationship. * @return an NSArray of the entities in the relationship */ @SuppressWarnings("unchecked") public NSArray<org.webcat.grader.AssignmentOffering> offerings() { return (NSArray)storedValueForKey( "offerings" ); } // ---------------------------------------------------------- /** * Replace the list of entities pointed to by the * <code>offerings</code> relationship. * * @param value The new set of entities to relate to */ public void setOfferings( NSMutableArray<org.webcat.grader.AssignmentOffering> value ) { if (log.isDebugEnabled()) { log.debug( "setOfferings(" + value + "): was " + offerings() ); } takeStoredValueForKey( value, "offerings" ); } // ---------------------------------------------------------- /** * Add a new entity to the <code>offerings</code> * relationship (DO NOT USE--instead, use * <code>addToOfferingsRelationship()</code>. * This method is provided for WebObjects use. * * @param value The new entity to relate to */ public void addToOfferings( org.webcat.grader.AssignmentOffering value ) { if (log.isDebugEnabled()) { log.debug( "addToOfferings(" + value + "): was " + offerings() ); } NSMutableArray<org.webcat.grader.AssignmentOffering> array = (NSMutableArray<org.webcat.grader.AssignmentOffering>)offerings(); willChange(); array.addObject( value ); } // ---------------------------------------------------------- /** * Remove a specific entity from the <code>offerings</code> * relationship (DO NOT USE--instead, use * <code>removeFromOfferingsRelationship()</code>. * This method is provided for WebObjects use. * * @param value The entity to remove from the relationship */ public void removeFromOfferings( org.webcat.grader.AssignmentOffering value ) { if (log.isDebugEnabled()) { log.debug( "RemoveFromOfferings(" + value + "): was " + offerings() ); } NSMutableArray<org.webcat.grader.AssignmentOffering> array = (NSMutableArray<org.webcat.grader.AssignmentOffering>)offerings(); willChange(); array.removeObject( value ); } // ---------------------------------------------------------- /** * Add a new entity to the <code>offerings</code> * relationship. * * @param value The new entity to relate to */ public void addToOfferingsRelationship( org.webcat.grader.AssignmentOffering value ) { if (log.isDebugEnabled()) { log.debug( "addToOfferingsRelationship(" + value + "): was " + offerings() ); } addObjectToBothSidesOfRelationshipWithKey( value, "offerings" ); } // ---------------------------------------------------------- /** * Remove a specific entity from the <code>offerings</code> * relationship. * * @param value The entity to remove from the relationship */ public void removeFromOfferingsRelationship( org.webcat.grader.AssignmentOffering value ) { if (log.isDebugEnabled()) { log.debug( "removeFromOfferingsRelationship(" + value + "): was " + offerings() ); } removeObjectFromBothSidesOfRelationshipWithKey( value, "offerings" ); } // ---------------------------------------------------------- /** * Create a brand new object that is a member of the * <code>offerings</code> relationship. * * @return The new entity */ public org.webcat.grader.AssignmentOffering createOfferingsRelationship() { if (log.isDebugEnabled()) { log.debug( "createOfferingsRelationship()" ); } EOClassDescription eoClassDesc = EOClassDescription .classDescriptionForEntityName( "AssignmentOffering" ); EOEnterpriseObject eoObject = eoClassDesc .createInstanceWithEditingContext( editingContext(), null ); editingContext().insertObject( eoObject ); addObjectToBothSidesOfRelationshipWithKey( eoObject, "offerings" ); return (org.webcat.grader.AssignmentOffering)eoObject; } // ---------------------------------------------------------- /** * Remove and then delete a specific entity that is a member of the * <code>offerings</code> relationship. * * @param value The entity to remove from the relationship and then delete */ public void deleteOfferingsRelationship( org.webcat.grader.AssignmentOffering value ) { if (log.isDebugEnabled()) { log.debug( "deleteOfferingsRelationship(" + value + "): was " + offerings() ); } removeObjectFromBothSidesOfRelationshipWithKey( value, "offerings" ); editingContext().deleteObject( value ); } // ---------------------------------------------------------- /** * Remove (and then delete, if owned) all entities that are members of the * <code>offerings</code> relationship. */ public void deleteAllOfferingsRelationships() { if (log.isDebugEnabled()) { log.debug( "deleteAllOfferingsRelationships(): was " + offerings() ); } for (org.webcat.grader.AssignmentOffering object : offerings()) { deleteOfferingsRelationship(object); } } // ---------------------------------------------------------- /** * Retrieve the entities pointed to by the <code>steps</code> * relationship. * @return an NSArray of the entities in the relationship */ @SuppressWarnings("unchecked") public NSArray<org.webcat.grader.Step> steps() { return (NSArray)storedValueForKey( "steps" ); } // ---------------------------------------------------------- /** * Replace the list of entities pointed to by the * <code>steps</code> relationship. * * @param value The new set of entities to relate to */ public void setSteps( NSMutableArray<org.webcat.grader.Step> value ) { if (log.isDebugEnabled()) { log.debug( "setSteps(" + value + "): was " + steps() ); } takeStoredValueForKey( value, "steps" ); } // ---------------------------------------------------------- /** * Add a new entity to the <code>steps</code> * relationship (DO NOT USE--instead, use * <code>addToStepsRelationship()</code>. * This method is provided for WebObjects use. * * @param value The new entity to relate to */ public void addToSteps( org.webcat.grader.Step value ) { if (log.isDebugEnabled()) { log.debug( "addToSteps(" + value + "): was " + steps() ); } NSMutableArray<org.webcat.grader.Step> array = (NSMutableArray<org.webcat.grader.Step>)steps(); willChange(); array.addObject( value ); } // ---------------------------------------------------------- /** * Remove a specific entity from the <code>steps</code> * relationship (DO NOT USE--instead, use * <code>removeFromStepsRelationship()</code>. * This method is provided for WebObjects use. * * @param value The entity to remove from the relationship */ public void removeFromSteps( org.webcat.grader.Step value ) { if (log.isDebugEnabled()) { log.debug( "RemoveFromSteps(" + value + "): was " + steps() ); } NSMutableArray<org.webcat.grader.Step> array = (NSMutableArray<org.webcat.grader.Step>)steps(); willChange(); array.removeObject( value ); } // ---------------------------------------------------------- /** * Add a new entity to the <code>steps</code> * relationship. * * @param value The new entity to relate to */ public void addToStepsRelationship( org.webcat.grader.Step value ) { if (log.isDebugEnabled()) { log.debug( "addToStepsRelationship(" + value + "): was " + steps() ); } addObjectToBothSidesOfRelationshipWithKey( value, "steps" ); } // ---------------------------------------------------------- /** * Remove a specific entity from the <code>steps</code> * relationship. * * @param value The entity to remove from the relationship */ public void removeFromStepsRelationship( org.webcat.grader.Step value ) { if (log.isDebugEnabled()) { log.debug( "removeFromStepsRelationship(" + value + "): was " + steps() ); } removeObjectFromBothSidesOfRelationshipWithKey( value, "steps" ); } // ---------------------------------------------------------- /** * Create a brand new object that is a member of the * <code>steps</code> relationship. * * @return The new entity */ public org.webcat.grader.Step createStepsRelationship() { if (log.isDebugEnabled()) { log.debug( "createStepsRelationship()" ); } EOClassDescription eoClassDesc = EOClassDescription .classDescriptionForEntityName( "Step" ); EOEnterpriseObject eoObject = eoClassDesc .createInstanceWithEditingContext( editingContext(), null ); editingContext().insertObject( eoObject ); addObjectToBothSidesOfRelationshipWithKey( eoObject, "steps" ); return (org.webcat.grader.Step)eoObject; } // ---------------------------------------------------------- /** * Remove and then delete a specific entity that is a member of the * <code>steps</code> relationship. * * @param value The entity to remove from the relationship and then delete */ public void deleteStepsRelationship( org.webcat.grader.Step value ) { if (log.isDebugEnabled()) { log.debug( "deleteStepsRelationship(" + value + "): was " + steps() ); } removeObjectFromBothSidesOfRelationshipWithKey( value, "steps" ); editingContext().deleteObject( value ); } // ---------------------------------------------------------- /** * Remove (and then delete, if owned) all entities that are members of the * <code>steps</code> relationship. */ public void deleteAllStepsRelationships() { if (log.isDebugEnabled()) { log.debug( "deleteAllStepsRelationships(): was " + steps() ); } for (org.webcat.grader.Step object : steps()) { deleteStepsRelationship(object); } } // ---------------------------------------------------------- /** * Retrieve objects using a fetch specification. * * @param context The editing context to use * @param fspec The fetch specification to use * * @return an NSArray of the entities retrieved */ @SuppressWarnings("unchecked") public static NSArray<Assignment> objectsWithFetchSpecification( EOEditingContext context, EOFetchSpecification fspec) { return context.objectsWithFetchSpecification(fspec); } // ---------------------------------------------------------- /** * Retrieve all objects of this type. * * @param context The editing context to use * * @return an NSArray of the entities retrieved */ public static NSArray<Assignment> allObjects( EOEditingContext context) { return objectsMatchingQualifier(context, null, null); } // ---------------------------------------------------------- /** * Retrieve objects using a qualifier. * * @param context The editing context to use * @param qualifier The qualifier to use * * @return an NSArray of the entities retrieved */ public static NSArray<Assignment> objectsMatchingQualifier( EOEditingContext context, EOQualifier qualifier) { return objectsMatchingQualifier(context, qualifier, null); } // ---------------------------------------------------------- /** * Retrieve objects using a qualifier and sort orderings. * * @param context The editing context to use * @param qualifier The qualifier to use * @param sortOrderings The sort orderings to use * * @return an NSArray of the entities retrieved */ public static NSArray<Assignment> objectsMatchingQualifier( EOEditingContext context, EOQualifier qualifier, NSArray<EOSortOrdering> sortOrderings) { @SuppressWarnings("unchecked") EOFetchSpecification fspec = new WCFetchSpecification( ENTITY_NAME, qualifier, sortOrderings); fspec.setUsesDistinct(true); return objectsWithFetchSpecification(context, fspec); } // ---------------------------------------------------------- /** * Retrieve the first object that matches a qualifier, when * sorted with the specified sort orderings. * * @param context The editing context to use * @param qualifier The qualifier to use * @param sortOrderings the sort orderings * * @return the first entity that was retrieved, or null if there was none */ public static Assignment firstObjectMatchingQualifier( EOEditingContext context, EOQualifier qualifier, NSArray<EOSortOrdering> sortOrderings) { NSArray<Assignment> objects = objectsMatchingQualifier(context, qualifier, sortOrderings); return (objects.size() > 0) ? objects.get(0) : null; } // ---------------------------------------------------------- /** * Retrieve a single object using a list of keys and values to match. * * @param context The editing context to use * @param qualifier The qualifier to use * * @return the single entity that was retrieved * * @throws EOUtilities.MoreThanOneException * if there is more than one matching object */ public static Assignment uniqueObjectMatchingQualifier( EOEditingContext context, EOQualifier qualifier) throws EOUtilities.MoreThanOneException { NSArray<Assignment> objects = objectsMatchingQualifier(context, qualifier); if (objects.size() > 1) { String msg = "fetching Assignment"; try { if (qualifier != null) { msg += " where " + qualifier; } msg += ", result = " + objects; } catch (Exception e) { log.error("Exception building MoreThanOneException message, " + "contents so far: " + msg, e); } throw new EOUtilities.MoreThanOneException(msg); } return (objects.size() > 0) ? objects.get(0) : null; } // ---------------------------------------------------------- /** * Retrieve 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 an NSArray of the entities retrieved */ public static NSArray<Assignment> objectsMatchingValues( 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, key); } return objectsMatchingValues(context, valueDictionary); } // ---------------------------------------------------------- /** * Retrieve objects using a dictionary of keys and values to match. * * @param context The editing context to use * @param keysAndValues a dictionary of keys and values to match * * @return an NSArray of the entities retrieved */ @SuppressWarnings("unchecked") public static NSArray<Assignment> objectsMatchingValues( EOEditingContext context, NSDictionary<String, Object> keysAndValues) { return EOUtilities.objectsMatchingValues(context, ENTITY_NAME, keysAndValues); } // ---------------------------------------------------------- /** * Retrieve the first object that matches a set of keys and values, when * sorted with the specified sort orderings. * * @param context The editing context to use * @param sortOrderings the sort orderings * @param keysAndValues a list of keys and values to match, alternating * "key", "value", "key", "value"... * * @return the first entity that was retrieved, or null if there was none */ public static Assignment firstObjectMatchingValues( EOEditingContext context, NSArray<EOSortOrdering> sortOrderings, 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, key); } return firstObjectMatchingValues( context, sortOrderings, valueDictionary); } // ---------------------------------------------------------- /** * Retrieves the first object that matches a set of keys and values, when * sorted with the specified sort orderings. * * @param context The editing context to use * @param sortOrderings the sort orderings * @param keysAndValues a dictionary of keys and values to match * * @return the first entity that was retrieved, or null if there was none */ public static Assignment firstObjectMatchingValues( EOEditingContext context, NSArray<EOSortOrdering> sortOrderings, NSDictionary<String, Object> keysAndValues) { @SuppressWarnings("unchecked") EOFetchSpecification fspec = new WCFetchSpecification( ENTITY_NAME, EOQualifier.qualifierToMatchAllValues(keysAndValues), sortOrderings); fspec.setFetchLimit(1); NSArray<Assignment> objects = objectsWithFetchSpecification( context, fspec ); if ( objects.count() == 0 ) { return null; } else { return objects.objectAtIndex(0); } } // ---------------------------------------------------------- /** * Retrieve a single object 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 single entity that was retrieved, or null if there was none * * @throws EOUtilities.MoreThanOneException * if there is more than one matching object */ public static Assignment uniqueObjectMatchingValues( EOEditingContext context, Object... keysAndValues) throws EOUtilities.MoreThanOneException { 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, key); } return uniqueObjectMatchingValues(context, valueDictionary); } // ---------------------------------------------------------- /** * Retrieve an object using a dictionary of keys and values to match. * * @param context The editing context to use * @param keysAndValues a dictionary of keys and values to match * * @return the single entity that was retrieved, or null if there was none * * @throws EOUtilities.MoreThanOneException * if there is more than one matching object */ public static Assignment uniqueObjectMatchingValues( EOEditingContext context, NSDictionary<String, Object> keysAndValues) throws EOUtilities.MoreThanOneException { try { return (Assignment)EOUtilities.objectMatchingValues( context, ENTITY_NAME, keysAndValues); } catch (EOObjectNotAvailableException e) { return null; } } // ---------------------------------------------------------- /** * Retrieve the count of all objects of this type. * * @param context The editing context to use * * @return the count of all objects */ public static int countOfAllObjects(EOEditingContext context) { return countOfObjectsMatchingQualifier(context, null); } // ---------------------------------------------------------- /** * Retrieve the count of objects that match a qualifier. * * @param context The editing context to use * @param qualifier The qualifier to use * * @return the count of objects matching the qualifier */ public static int countOfObjectsMatchingQualifier( EOEditingContext context, EOQualifier qualifier) { return ERXEOControlUtilities.objectCountWithQualifier( context, ENTITY_NAME, qualifier); } // ---------------------------------------------------------- /** * 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, key); } return countOfObjectsMatchingValues(context, valueDictionary); } // ---------------------------------------------------------- /** * Retrieve the count of objects using a dictionary of keys and values to * match. * * @param context The editing context to use * @param keysAndValues a dictionary of keys and values to match * * @return the count of objects that matched the specified values */ public static int countOfObjectsMatchingValues( EOEditingContext context, NSDictionary<String, Object> keysAndValues) { return countOfObjectsMatchingQualifier(context, EOQualifier.qualifierToMatchAllValues(keysAndValues)); } // ---------------------------------------------------------- /** * Retrieve objects according to the <code>assignmentsForReuseInCourse</code> * fetch specification. * * @param context The editing context to use * @param courseBinding fetch spec parameter * @param courseOfferingBinding fetch spec parameter * @return an NSArray of the entities retrieved */ public static NSArray<Assignment> assignmentsForReuseInCourse( EOEditingContext context, org.webcat.core.Course courseBinding, org.webcat.core.CourseOffering courseOfferingBinding) { EOFetchSpecification spec = WCFetchSpecification .fetchSpecificationNamed("assignmentsForReuseInCourse", "Assignment"); NSMutableDictionary<String, Object> bindings = new NSMutableDictionary<String, Object>(); if (courseBinding != null) { bindings.setObjectForKey(courseBinding, "course"); } if (courseOfferingBinding != null) { bindings.setObjectForKey(courseOfferingBinding, "courseOffering"); } spec = spec.fetchSpecificationWithQualifierBindings(bindings); NSArray<Assignment> objects = objectsWithFetchSpecification(context, spec); if (log.isDebugEnabled()) { log.debug("assignmentsForReuseInCourse(ec" + ", " + courseBinding + ", " + courseOfferingBinding + "): " + objects); } return objects; } // ---------------------------------------------------------- /** * Retrieve objects according to the <code>neighborAssignments</code> * fetch specification. * * @param context The editing context to use * @param courseOfferingBinding fetch spec parameter * @return an NSArray of the entities retrieved */ public static NSArray<Assignment> neighborAssignments( EOEditingContext context, org.webcat.core.CourseOffering courseOfferingBinding) { EOFetchSpecification spec = WCFetchSpecification .fetchSpecificationNamed("neighborAssignments", "Assignment"); NSMutableDictionary<String, Object> bindings = new NSMutableDictionary<String, Object>(); if (courseOfferingBinding != null) { bindings.setObjectForKey(courseOfferingBinding, "courseOffering"); } spec = spec.fetchSpecificationWithQualifierBindings(bindings); NSArray<Assignment> objects = objectsWithFetchSpecification(context, spec); if (log.isDebugEnabled()) { log.debug("neighborAssignments(ec" + ", " + courseOfferingBinding + "): " + objects); } return objects; } // ---------------------------------------------------------- /** * Produce a string representation of this object. This implementation * calls UserPresentableDescription(), which uses WebObjects' internal * mechanism to print out the visible fields of this object. Normally, * subclasses would override userPresentableDescription() to change * the way the object is printed. * * @return A string representation of the object's value */ public String toString() { return userPresentableDescription(); } //~ Instance/static variables ............................................. static Logger log = Logger.getLogger(Assignment.class); }