Commit 5a644f49 authored by Ådne Karstad's avatar Ådne Karstad

[minor] Add derived attribute numberOfSemesters and validate credits for program

parent e76c84d6
......@@ -18,7 +18,7 @@
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Program">
<eAnnotations source="http://www.eclipse.org/emf/2002/Ecore">
<details key="constraints" value="needsEnoughSemesters"/>
<details key="constraints" value="needsEnoughSemesters needsEnoughCredits"/>
</eAnnotations>
<eOperations name="getCredits" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EFloat"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
......@@ -31,6 +31,8 @@
eType="#//MandatoryCourses" containment="true" eOpposite="#//MandatoryCourses/program"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="electiveCourses" upperBound="-1"
eType="#//ElectiveCourses" containment="true" eOpposite="#//ElectiveCourses/program"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="numberOfSemesters" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"
changeable="false" volatile="true" transient="true" derived="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Semester">
<eAnnotations source="http://www.eclipse.org/emf/2002/Ecore">
......
......@@ -40,6 +40,8 @@
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference spp.ecore#//Program/specialisation"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference spp.ecore#//Program/mandatoryCourses"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference spp.ecore#//Program/electiveCourses"/>
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute spp.ecore#//Program/numberOfSemesters"/>
<genOperations ecoreOperation="spp.ecore#//Program/getCredits"/>
</genClasses>
<genClasses ecoreClass="spp.ecore#//Semester">
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute spp.ecore#//Semester/season"/>
......
......@@ -21,10 +21,11 @@ import org.eclipse.emf.ecore.EObject;
* <li>{@link tdt4250.spp.Program#getSpecialisation <em>Specialisation</em>}</li>
* <li>{@link tdt4250.spp.Program#getMandatoryCourses <em>Mandatory Courses</em>}</li>
* <li>{@link tdt4250.spp.Program#getElectiveCourses <em>Elective Courses</em>}</li>
* <li>{@link tdt4250.spp.Program#getNumberOfSemesters <em>Number Of Semesters</em>}</li>
* </ul>
*
* @see tdt4250.spp.SppPackage#getProgram()
* @model annotation="http://www.eclipse.org/emf/2002/Ecore constraints='needsEnoughSemesters'"
* @model annotation="http://www.eclipse.org/emf/2002/Ecore constraints='needsEnoughSemesters needsEnoughCredits'"
* @generated
*/
public interface Program extends EObject {
......@@ -141,6 +142,17 @@ public interface Program extends EObject {
*/
EList<ElectiveCourses> getElectiveCourses();
/**
* Returns the value of the '<em><b>Number Of Semesters</b></em>' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @return the value of the '<em>Number Of Semesters</em>' attribute.
* @see tdt4250.spp.SppPackage#getProgram_NumberOfSemesters()
* @model transient="true" changeable="false" volatile="true" derived="true"
* @generated
*/
int getNumberOfSemesters();
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
......
......@@ -232,6 +232,15 @@ public interface SppPackage extends EPackage {
*/
int PROGRAM__ELECTIVE_COURSES = 5;
/**
* The feature id for the '<em><b>Number Of Semesters</b></em>' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
* @ordered
*/
int PROGRAM__NUMBER_OF_SEMESTERS = 6;
/**
* The number of structural features of the '<em>Program</em>' class.
* <!-- begin-user-doc -->
......@@ -239,7 +248,7 @@ public interface SppPackage extends EPackage {
* @generated
* @ordered
*/
int PROGRAM_FEATURE_COUNT = 6;
int PROGRAM_FEATURE_COUNT = 7;
/**
* The operation id for the '<em>Get Credits</em>' operation.
......@@ -745,6 +754,17 @@ public interface SppPackage extends EPackage {
*/
EReference getProgram_ElectiveCourses();
/**
* Returns the meta object for the attribute '{@link tdt4250.spp.Program#getNumberOfSemesters <em>Number Of Semesters</em>}'.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @return the meta object for the attribute '<em>Number Of Semesters</em>'.
* @see tdt4250.spp.Program#getNumberOfSemesters()
* @see #getProgram()
* @generated
*/
EAttribute getProgram_NumberOfSemesters();
/**
* Returns the meta object for the '{@link tdt4250.spp.Program#getCredits() <em>Get Credits</em>}' operation.
* <!-- begin-user-doc -->
......@@ -1170,6 +1190,14 @@ public interface SppPackage extends EPackage {
*/
EReference PROGRAM__ELECTIVE_COURSES = eINSTANCE.getProgram_ElectiveCourses();
/**
* The meta object literal for the '<em><b>Number Of Semesters</b></em>' attribute feature.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
EAttribute PROGRAM__NUMBER_OF_SEMESTERS = eINSTANCE.getProgram_NumberOfSemesters();
/**
* The meta object literal for the '<em><b>Get Credits</b></em>' operation.
* <!-- begin-user-doc -->
......
......@@ -41,6 +41,7 @@ import tdt4250.spp.SppPackage;
* <li>{@link tdt4250.spp.impl.ProgramImpl#getSpecialisation <em>Specialisation</em>}</li>
* <li>{@link tdt4250.spp.impl.ProgramImpl#getMandatoryCourses <em>Mandatory Courses</em>}</li>
* <li>{@link tdt4250.spp.impl.ProgramImpl#getElectiveCourses <em>Elective Courses</em>}</li>
* <li>{@link tdt4250.spp.impl.ProgramImpl#getNumberOfSemesters <em>Number Of Semesters</em>}</li>
* </ul>
*
* @generated
......@@ -126,6 +127,16 @@ public class ProgramImpl extends MinimalEObjectImpl.Container implements Program
*/
protected EList<ElectiveCourses> electiveCourses;
/**
* The default value of the '{@link #getNumberOfSemesters() <em>Number Of Semesters</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getNumberOfSemesters()
* @generated
* @ordered
*/
protected static final int NUMBER_OF_SEMESTERS_EDEFAULT = 0;
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
......@@ -275,6 +286,17 @@ public class ProgramImpl extends MinimalEObjectImpl.Container implements Program
return electiveCourses;
}
/**
* <!-- begin-user-doc -->
* The number of semesters should be equal to the duration multiplied by two semesters.
* <!-- end-user-doc -->
* @generated NOPE
*/
@Override
public int getNumberOfSemesters() {
return this.duration.getValue() * 2;
}
/**
* <!-- begin-user-doc -->
* Get credits for all semesters
......@@ -353,6 +375,8 @@ public class ProgramImpl extends MinimalEObjectImpl.Container implements Program
return getMandatoryCourses();
case SppPackage.PROGRAM__ELECTIVE_COURSES:
return getElectiveCourses();
case SppPackage.PROGRAM__NUMBER_OF_SEMESTERS:
return getNumberOfSemesters();
}
return super.eGet(featureID, resolve, coreType);
}
......@@ -441,6 +465,8 @@ public class ProgramImpl extends MinimalEObjectImpl.Container implements Program
return mandatoryCourses != null && !mandatoryCourses.isEmpty();
case SppPackage.PROGRAM__ELECTIVE_COURSES:
return electiveCourses != null && !electiveCourses.isEmpty();
case SppPackage.PROGRAM__NUMBER_OF_SEMESTERS:
return getNumberOfSemesters() != NUMBER_OF_SEMESTERS_EDEFAULT;
}
return super.eIsSet(featureID);
}
......
......@@ -332,6 +332,16 @@ public class SppPackageImpl extends EPackageImpl implements SppPackage {
return (EReference)programEClass.getEStructuralFeatures().get(5);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
public EAttribute getProgram_NumberOfSemesters() {
return (EAttribute)programEClass.getEStructuralFeatures().get(6);
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
......@@ -638,6 +648,7 @@ public class SppPackageImpl extends EPackageImpl implements SppPackage {
createEReference(programEClass, PROGRAM__SPECIALISATION);
createEReference(programEClass, PROGRAM__MANDATORY_COURSES);
createEReference(programEClass, PROGRAM__ELECTIVE_COURSES);
createEAttribute(programEClass, PROGRAM__NUMBER_OF_SEMESTERS);
createEOperation(programEClass, PROGRAM___GET_CREDITS);
semesterEClass = createEClass(SEMESTER);
......@@ -720,6 +731,7 @@ public class SppPackageImpl extends EPackageImpl implements SppPackage {
initEReference(getProgram_Specialisation(), this.getSpecialisation(), this.getSpecialisation_Program(), "specialisation", null, 0, 1, Program.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEReference(getProgram_MandatoryCourses(), this.getMandatoryCourses(), this.getMandatoryCourses_Program(), "mandatoryCourses", null, 0, -1, Program.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEReference(getProgram_ElectiveCourses(), this.getElectiveCourses(), this.getElectiveCourses_Program(), "electiveCourses", null, 0, -1, Program.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
initEAttribute(getProgram_NumberOfSemesters(), ecorePackage.getEInt(), "numberOfSemesters", null, 0, 1, Program.class, IS_TRANSIENT, IS_VOLATILE, !IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, IS_DERIVED, IS_ORDERED);
initEOperation(getProgram__GetCredits(), ecorePackage.getEFloat(), "getCredits", 0, 1, IS_UNIQUE, IS_ORDERED);
......@@ -788,7 +800,7 @@ public class SppPackageImpl extends EPackageImpl implements SppPackage {
(programEClass,
source,
new String[] {
"constraints", "needsEnoughSemesters"
"constraints", "needsEnoughSemesters needsEnoughCredits"
});
addAnnotation
(semesterEClass,
......
......@@ -146,6 +146,7 @@ public class SppValidator extends EObjectValidator {
if (result || diagnostics != null) result &= validate_EveryKeyUnique(program, diagnostics, context);
if (result || diagnostics != null) result &= validate_EveryMapEntryUnique(program, diagnostics, context);
if (result || diagnostics != null) result &= validateProgram_needsEnoughSemesters(program, diagnostics, context);
if (result || diagnostics != null) result &= validateProgram_needsEnoughCredits(program, diagnostics, context);
return result;
}
......@@ -180,6 +181,37 @@ public class SppValidator extends EObjectValidator {
return true;
}
/**
* Validates the needsEnoughCredits constraint of '<em>Program</em>'.
* <!-- begin-user-doc -->
* We assume that the program has enough credits as long as the sum of semesters multiplied by 30 credits are fulfilled..
* That means that in theory this validation does not care if one semester has 15 credits, as long as the average is 30 or more.
* <!-- end-user-doc -->
* @generated NOPE
*/
public boolean validateProgram_needsEnoughCredits(Program program, DiagnosticChain diagnostics, Map<Object, Object> context) {
float credits = 0.0f;
for (Semester sem : program.getSemesters()) {
credits += sem.getCredits();
}
if (credits < program.getNumberOfSemesters() * 30.0f) {
if (diagnostics != null) {
diagnostics.add
(createDiagnostic
(Diagnostic.ERROR,
DIAGNOSTIC_SOURCE,
0,
"_UI_GenericConstraint_diagnostic",
new Object[] { "needsEnoughCredits", getObjectLabel(program, context) },
new Object[] { program },
context));
}
return false;
}
return true;
}
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment