Permalink
Browse files

Added the engagement types and their enumerations and test cases

  • Loading branch information...
1 parent b6ae2ef commit efd76b7e078cb5259f9b4df566fe3ea89ddd0d13 @scottbw committed Jan 5, 2012
@@ -38,6 +38,9 @@
import org.junit.Test;
import org.xcri.Namespaces;
import org.xcri.exceptions.InvalidElementException;
+import org.xcri.presentation.AttendanceMode;
+import org.xcri.presentation.AttendancePattern;
+import org.xcri.presentation.StudyMode;
public class PresentationTest {
@@ -230,9 +233,44 @@ public void testInheritDescription() throws InvalidElementException, JDOMExcepti
*
* Note: These are mutually exclusive terms, so 'Full time' does not include 'Part of a full time programme'.
*/
+ @Test
+ public void studyModeTest1() throws InvalidElementException, JDOMException, IOException{
+ Logger logger = Logger.getLogger(StudyMode.class.getName());
+
+ Formatter formatter = new SimpleFormatter();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ Handler handler = new StreamHandler(out, formatter);
+ logger.addHandler(handler);
+
+ try {
+ Catalog catalog = new Catalog();
+ SAXBuilder builder = new SAXBuilder();
+ Document document = builder.build(new StringReader("<catalog xmlns=\""+Namespaces.XCRI_NAMESPACE+"\" xmlns:mlo=\""+Namespaces.MLO_NAMESPACE+"\" xmlns:dc=\""+Namespaces.DC_NAMESPACE+"\" xmlns:xsi=\""+Namespaces.XSI_NAMESPACE+"\"><provider><course><presentation><studyMode identifier=\"TEST\"></studyMode></presentation></course></provider></catalog>"));
+ catalog.fromXml(document);
+
+ handler.flush();
+ String logMsg = out.toString();
+
+ assertNotNull(logMsg);
+ assertTrue(logMsg.contains("WARNING: StudyMode : identifier (\"TEST\") is not a member of the recommended vocabulary"));
+
+ } finally {
+ logger.removeHandler(handler);
+ }
+ }
+ @Test
+ public void studyModeTest2() throws InvalidElementException, JDOMException, IOException{
+
+ Catalog catalog = new Catalog();
+ SAXBuilder builder = new SAXBuilder();
+ Document document = builder.build(new StringReader("<catalog xmlns=\""+Namespaces.XCRI_NAMESPACE+"\" xmlns:mlo=\""+Namespaces.MLO_NAMESPACE+"\" xmlns:dc=\""+Namespaces.DC_NAMESPACE+"\" xmlns:xsi=\""+Namespaces.XSI_NAMESPACE+"\"><provider><course><presentation><studyMode identifier=\"FT\"></studyMode></presentation></course></provider></catalog>"));
+ catalog.fromXml(document);
+
+ assertEquals(StudyMode.StudyModeType.FT, catalog.getProviders()[0].getCourses()[0].getPresentations()[0].getStudyMode().getStudyModeType());
+ }
/**
- * TODO Attendance Mode
+ * Attendance Mode
*
* Recommended Values: Producers SHOULD use the following values for this element, with the
* two-letter code used in the @identifier attribute, and the label in the element content:
@@ -246,9 +284,44 @@ public void testInheritDescription() throws InvalidElementException, JDOMExcepti
* ON Online (no attendance)
* WB Work-based
*/
+ @Test
+ public void attenanceModeTest1() throws InvalidElementException, JDOMException, IOException{
+ Logger logger = Logger.getLogger(AttendanceMode.class.getName());
+
+ Formatter formatter = new SimpleFormatter();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ Handler handler = new StreamHandler(out, formatter);
+ logger.addHandler(handler);
+
+ try {
+ Catalog catalog = new Catalog();
+ SAXBuilder builder = new SAXBuilder();
+ Document document = builder.build(new StringReader("<catalog xmlns=\""+Namespaces.XCRI_NAMESPACE+"\" xmlns:mlo=\""+Namespaces.MLO_NAMESPACE+"\" xmlns:dc=\""+Namespaces.DC_NAMESPACE+"\" xmlns:xsi=\""+Namespaces.XSI_NAMESPACE+"\"><provider><course><presentation><attendanceMode identifier=\"TEST\"></attendanceMode></presentation></course></provider></catalog>"));
+ catalog.fromXml(document);
+
+ handler.flush();
+ String logMsg = out.toString();
+
+ assertNotNull(logMsg);
+ assertTrue(logMsg.contains("WARNING: AttendanceMode : identifier (\"TEST\") is not a member of the recommended vocabulary"));
+
+ } finally {
+ logger.removeHandler(handler);
+ }
+ }
+ @Test
+ public void attendanceModeTest2() throws InvalidElementException, JDOMException, IOException{
+
+ Catalog catalog = new Catalog();
+ SAXBuilder builder = new SAXBuilder();
+ Document document = builder.build(new StringReader("<catalog xmlns=\""+Namespaces.XCRI_NAMESPACE+"\" xmlns:mlo=\""+Namespaces.MLO_NAMESPACE+"\" xmlns:dc=\""+Namespaces.DC_NAMESPACE+"\" xmlns:xsi=\""+Namespaces.XSI_NAMESPACE+"\"><provider><course><presentation><attendanceMode identifier=\"MM\"></attendanceMode></presentation></course></provider></catalog>"));
+ catalog.fromXml(document);
+
+ assertEquals(AttendanceMode.AttendanceModeType.MM, catalog.getProviders()[0].getCourses()[0].getPresentations()[0].getAttendanceMode().getAttendanceModeType());
+ }
/**
- * TODO Attendance Pattern
+ * Attendance Pattern
*
* Recommended Values: Producers SHOULD use the following values for this element, with
* the two-letter code used in the @identifier attribute, and the label in the element content:
@@ -260,6 +333,41 @@ public void testInheritDescription() throws InvalidElementException, JDOMExcepti
* WE Weekend
* CS Customised
*/
+ @Test
+ public void attenancePatternTest1() throws InvalidElementException, JDOMException, IOException{
+ Logger logger = Logger.getLogger(AttendancePattern.class.getName());
+
+ Formatter formatter = new SimpleFormatter();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ Handler handler = new StreamHandler(out, formatter);
+ logger.addHandler(handler);
+
+ try {
+ Catalog catalog = new Catalog();
+ SAXBuilder builder = new SAXBuilder();
+ Document document = builder.build(new StringReader("<catalog xmlns=\""+Namespaces.XCRI_NAMESPACE+"\" xmlns:mlo=\""+Namespaces.MLO_NAMESPACE+"\" xmlns:dc=\""+Namespaces.DC_NAMESPACE+"\" xmlns:xsi=\""+Namespaces.XSI_NAMESPACE+"\"><provider><course><presentation><attendancePattern identifier=\"TEST\"></attendancePattern></presentation></course></provider></catalog>"));
+ catalog.fromXml(document);
+
+ handler.flush();
+ String logMsg = out.toString();
+
+ assertNotNull(logMsg);
+ assertTrue(logMsg.contains("WARNING: AttendancePattern : identifier (\"TEST\") is not a member of the recommended vocabulary"));
+
+ } finally {
+ logger.removeHandler(handler);
+ }
+ }
+ @Test
+ public void attendancePattern2() throws InvalidElementException, JDOMException, IOException{
+
+ Catalog catalog = new Catalog();
+ SAXBuilder builder = new SAXBuilder();
+ Document document = builder.build(new StringReader("<catalog xmlns=\""+Namespaces.XCRI_NAMESPACE+"\" xmlns:mlo=\""+Namespaces.MLO_NAMESPACE+"\" xmlns:dc=\""+Namespaces.DC_NAMESPACE+"\" xmlns:xsi=\""+Namespaces.XSI_NAMESPACE+"\"><provider><course><presentation><attendancePattern identifier=\"EV\"></attendancePattern></presentation></course></provider></catalog>"));
+ catalog.fromXml(document);
+
+ assertEquals(AttendancePattern.AttendancePatternType.EV, catalog.getProviders()[0].getCourses()[0].getPresentations()[0].getAttendancePattern().getAttendancePatternType());
+ }
/**
* TODO Places
@@ -29,9 +29,13 @@
import org.xcri.presentation.ApplyFrom;
import org.xcri.presentation.ApplyTo;
import org.xcri.presentation.ApplyUntil;
+import org.xcri.presentation.AttendanceMode;
+import org.xcri.presentation.AttendancePattern;
import org.xcri.presentation.Duration;
import org.xcri.presentation.End;
+import org.xcri.presentation.Engagement;
import org.xcri.presentation.Start;
+import org.xcri.presentation.StudyMode;
import org.xcri.types.CommonDescriptiveType;
import org.xcri.types.CommonType;
@@ -45,6 +49,16 @@
private ApplyFrom applyFrom;
private ApplyUntil applyUntil;
private ApplyTo applyTo;
+ private Engagement[] engagements;
+ private StudyMode studyMode;
+ private AttendanceMode attendanceMode;
+ private AttendancePattern attendancePattern;
+ // TODO languageOfINstruction
+ // TODO languageOfAssessment
+ // TODO places
+ // TODO cost
+ // TODO age
+ // TODO venue
/* (non-Javadoc)
* @see org.xcri.types.CommonType#toXml()
@@ -55,6 +69,12 @@ public Element toXml() {
if (this.getStart() != null) element.addContent(this.getStart().toXml());
if (this.getEnd() != null) element.addContent(this.getEnd().toXml());
if (this.getDuration() != null) element.addContent(this.getDuration().toXml());
+ if (this.getApplyFrom() != null) element.addContent(this.getApplyFrom().toXml());
+ if (this.getApplyUntil() != null) element.addContent(this.getApplyUntil().toXml());
+ if (this.getApplyTo() != null) element.addContent(this.getApplyTo().toXml());
+ // TODO Engagement
+ if (this.getStudyMode() != null) element.addContent(this.getStudyMode().toXml());
+ if (this.getAttendanceMode() != null) element.addContent(this.getAttendanceMode().toXml());
return element;
}
@@ -138,6 +158,36 @@ public void fromXml(Element element) throws InvalidElementException {
}
}
+ // TODO engagement
+
+ if (element.getChild("studyMode", Namespaces.XCRI_NAMESPACE_NS)!=null){
+ StudyMode studyMode = new StudyMode();
+ try {
+ studyMode.fromXml(element.getChild("studyMode", Namespaces.XCRI_NAMESPACE_NS));
+ this.setStudyMode(studyMode);
+ } catch (InvalidElementException e) {
+ log.warn("presentation : skipping invalid studyMode element: "+e.getMessage());
+ }
+ }
+ if (element.getChild("attendanceMode", Namespaces.XCRI_NAMESPACE_NS)!=null){
+ AttendanceMode attendanceMode = new AttendanceMode();
+ try {
+ attendanceMode.fromXml(element.getChild("attendanceMode", Namespaces.XCRI_NAMESPACE_NS));
+ this.setAttendanceMode(attendanceMode);
+ } catch (InvalidElementException e) {
+ log.warn("presentation : skipping invalid attendanceMode element: "+e.getMessage());
+ }
+ }
+ if (element.getChild("attendancePattern", Namespaces.XCRI_NAMESPACE_NS)!=null){
+ AttendancePattern attendancePattern = new AttendancePattern();
+ try {
+ attendancePattern.fromXml(element.getChild("attendancePattern", Namespaces.XCRI_NAMESPACE_NS));
+ this.setAttendancePattern(attendancePattern);
+ } catch (InvalidElementException e) {
+ log.warn("presentation : skipping invalid attendancePattern element: "+e.getMessage());
+ }
+ }
+
}
/* (non-Javadoc)
@@ -252,6 +302,62 @@ public ApplyTo getApplyTo() {
public void setApplyTo(ApplyTo applyTo) {
this.applyTo = applyTo;
}
+
+ /**
+ * @return the engagements
+ */
+ public Engagement[] getEngagements() {
+ return engagements;
+ }
+
+ /**
+ * @param engagements the engagements to set
+ */
+ public void setEngagements(Engagement[] engagements) {
+ this.engagements = engagements;
+ }
+
+ /**
+ * @return the studyMode
+ */
+ public StudyMode getStudyMode() {
+ return studyMode;
+ }
+
+ /**
+ * @param studyMode the studyMode to set
+ */
+ public void setStudyMode(StudyMode studyMode) {
+ this.studyMode = studyMode;
+ }
+
+ /**
+ * @return the attendanceMode
+ */
+ public AttendanceMode getAttendanceMode() {
+ return attendanceMode;
+ }
+
+ /**
+ * @param attendanceMode the attendanceMode to set
+ */
+ public void setAttendanceMode(AttendanceMode attendanceMode) {
+ this.attendanceMode = attendanceMode;
+ }
+
+ /**
+ * @return the attendancePattern
+ */
+ public AttendancePattern getAttendancePattern() {
+ return attendancePattern;
+ }
+
+ /**
+ * @param attendancePattern the attendancePattern to set
+ */
+ public void setAttendancePattern(AttendancePattern attendancePattern) {
+ this.attendancePattern = attendancePattern;
+ }
@@ -0,0 +1,111 @@
+/**
+ * Copyright (c) 2011 University of Bolton
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this
+ * software and associated documentation files (the "Software"), to deal in the Software
+ * without restriction, including without limitation the rights to use, copy, modify,
+ * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to the following
+ * conditions:
+ * The above copyright notice and this permission notice shall be included in all copies
+ * or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+ * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
+ * OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+package org.xcri.presentation;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jdom.Element;
+import org.jdom.Namespace;
+import org.xcri.Namespaces;
+import org.xcri.exceptions.InvalidElementException;
+import org.xcri.types.XcriElement;
+
+public class AttendanceMode extends XcriElement {
+
+ private Log log = LogFactory.getLog(AttendanceMode.class);
+
+ public enum AttendanceModeType {
+ CM,
+ DA,
+ DS,
+ NC,
+ MM,
+ ON,
+ WB;
+ }
+
+ public AttendanceModeType getAttendanceModeType(){
+ try {
+ return AttendanceModeType.valueOf(getIdentifier());
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ private String identifier;
+
+
+ @Override
+ public Namespace getNamespace() {
+ return Namespaces.XCRI_NAMESPACE_NS;
+ }
+
+ @Override
+ public String getName() {
+ return "attendanceMode";
+ }
+
+ @Override
+ public Element toXml() {
+ return super.toXml();
+ }
+
+ @Override
+ public void fromXml(Element element) throws InvalidElementException {
+ super.fromXml(element);
+
+ /**
+ * Recommended Values: Producers SHOULD use the following values for this element, with the two-letter code used in the @identifier attribute, and the label in the element content:
+ * The value of this element MUST be one of:
+ * CM Campus
+ * DA Distance with attendance
+ * DS Distance without attendance
+ * NC Face-to-face non-campus
+ * MM Mixed mode
+ * ON Online (no attendance)
+ * WB Work-based
+ */
+
+ String identifier = element.getAttributeValue("identifier");
+ if (identifier != null){
+ this.setIdentifier(identifier);
+ if (this.getAttendanceModeType() == null){
+ log.warn("AttendanceMode : identifier (\""+identifier+"\") is not a member of the recommended vocabulary");
+ }
+ }
+ }
+
+ /**
+ * @return the identifier
+ */
+ public String getIdentifier() {
+ return identifier;
+ }
+
+ /**
+ * @param identifier the identifier to set
+ */
+ public void setIdentifier(String identifier) {
+ this.identifier = identifier;
+ }
+
+
+
+}
Oops, something went wrong.

0 comments on commit efd76b7

Please sign in to comment.