Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extended course info #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,35 @@ curl https://yourbbinstall.edu/webapps/atd-bbws-BBLEARN/ws/courses/my_test_cours

````

#### Get a single Course (extended info)

**GET** `/courses/{courseId}/extended`

Currently also provides availability information (both GUI-set Availability and row_status)

* `courseId` is the value stored in the `COURSE_ID` column in the DB.

curl Example
```` shell
curl https://yourbbinstall.edu/webapps/atd-bbws-BBLEARN/ws/courses/other_test_course/extended
````
#### Example Response

```` json
{
"id": "_5_1",
"courseId": "other_test_course",
"externalId": "other_test_course",
"title": "My Other Test Course",
"children": null,
"rowStatus": "0",
"isAvailable" : true
}


````


### Get all Assessments for a course

**GET** `/courses/{courseId}/gradebook/assessments`
Expand Down Expand Up @@ -229,4 +258,4 @@ curl https://yourbbinstall.edu/webapps/atd-bbws-BBLEARN/ws/users/administrator/c
"children": null
}
]
````
````
5 changes: 2 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ sourceCompatibility = 1.7
targetCompatibility = 1.7

task wrapper(type: Wrapper) {
gradleVersion = "1.11"
gradleVersion = "2.11"
}

if (isBuildingBlock()) {
Expand All @@ -34,7 +34,6 @@ configurations {

dependencies {
b2deploy 'org.oscelot:b2deploy-task:0.1.0'

compile 'org.slf4j:slf4j-api:1.7.5'
compile 'org.slf4j:jul-to-slf4j:1.7.5'
compile 'org.slf4j:slf4j-log4j12:1.7.5'
Expand All @@ -55,8 +54,8 @@ dependencies {
providedCompile 'javax.servlet:javax.servlet-api:3.0.1'
providedCompile 'jstl:jstl:1.2'
providedCompile 'blackboard.platform:bb-platform:9.1.201404.160205'
providedCompile 'blackboard.platform:bb-cms-admin:9.1.201404.160205'
providedCompile 'blackboard.platform:bb-taglibs:9.1.201404.160205'

testCompile "junit:junit:4.11"
}

Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Nov 20 15:51:20 EST 2014
#Fri Aug 19 15:57:28 EDT 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.11-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.11-bin.zip
31 changes: 31 additions & 0 deletions src/main/java/com/alltheducks/bbws/model/CourseExtendedDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.alltheducks.bbws.model;

/**
* Created by hanleybrand on 8/19/16.
*/

public class CourseExtendedDto extends CourseDto {


String rowStatus;
Boolean isAvailable;


public String getRowStatus() {
return rowStatus;
}

public void setRowStatus(String rowStatus) {
this.rowStatus = rowStatus;
}

public Boolean getIsAvailable() {
return isAvailable;
}

public void setAvailableInd(Boolean isAvailable) {
this.isAvailable = isAvailable;
}


}
36 changes: 36 additions & 0 deletions src/main/java/com/alltheducks/bbws/util/BbCourseHelper.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package com.alltheducks.bbws.util;

import blackboard.admin.data.IAdminObject;
import blackboard.admin.data.course.CourseSite;
import blackboard.admin.persist.course.CourseSiteLoader;
import blackboard.admin.persist.course.impl.CourseSiteDbLoader;
import blackboard.data.course.Course;
import blackboard.persist.PersistenceException;
import com.alltheducks.bbws.model.CourseDto;
import com.alltheducks.bbws.model.CourseExtendedDto;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -29,4 +35,34 @@ public static CourseDto convertBbCourseToCourseDto(Course bbCourse) {
return course;
}

public static List<CourseExtendedDto> convertBbCoursesToCourseExtendedDtos(List<Course> bbCourses) throws PersistenceException {
List<CourseExtendedDto> courses = new ArrayList<>();
for (Course bbCourse : bbCourses) {
courses.add(convertBbCourseToCourseExtendedDto(bbCourse));
}
return courses;
}

public static CourseExtendedDto convertBbCourseToCourseExtendedDto(Course bbCourse) throws PersistenceException {
CourseExtendedDto course = new CourseExtendedDto();
CourseSiteLoader courseLoader = CourseSiteDbLoader.Default.getInstance();
CourseSite cs = courseLoader.load(bbCourse.getBatchUid());
IAdminObject.RowStatus status = cs.getRowStatus();
course.setId(bbCourse.getId().getExternalString());
course.setTitle(bbCourse.getTitle());
course.setExternalId(bbCourse.getBatchUid());
course.setCourseId(bbCourse.getCourseId());
course.setAvailableInd(bbCourse.getIsAvailable());

if (status.equals(IAdminObject.RowStatus.ENABLED)){ course.setRowStatus("0"); }
else if (status.equals(IAdminObject.RowStatus.SOFT_DELETE)){ course.setRowStatus("1"); }
else if (status.equals(IAdminObject.RowStatus.DISABLED)){ course.setRowStatus("2"); }
else if (status.equals(IAdminObject.RowStatus.DELETE_PENDING)){ course.setRowStatus("3"); }
else if (status.equals(IAdminObject.RowStatus.COPY_PENDING)){ course.setRowStatus("4"); }
/// this should probably never happen, but if it does:
else { course.setRowStatus("U");}

return course;
}

}
47 changes: 47 additions & 0 deletions src/main/java/com/alltheducks/bbws/ws/CoursesResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import blackboard.platform.gradebook2.impl.*;
import com.alltheducks.bbws.model.AssessmentItemDto;
import com.alltheducks.bbws.model.CourseDto;
import com.alltheducks.bbws.model.CourseExtendedDto;
import com.alltheducks.bbws.model.MarkDto;
import com.alltheducks.bbws.security.RequiresAuthentication;
import com.alltheducks.bbws.util.BbCourseHelper;
Expand Down Expand Up @@ -61,6 +62,21 @@ public List<CourseDto> listCourses() {
return courses;
}

@GET
@Produces("application/json")
public List<CourseExtendedDto> listCoursesExtended() {
List<CourseExtendedDto> courses = new ArrayList<CourseExtendedDto>();
try {
List<Course> bbCourses = courseDbLoader.loadAllCourses();
courses = BbCourseHelper.convertBbCoursesToCourseExtendedDtos(bbCourses);
} catch (PersistenceException ex) {
logger.error("Error while retrieving courses", ex);
throw new WebApplicationException("Error retrieving Courses", 500);
}

return courses;
}

@GET
@Path("/{courseId}")
@Produces("application/json")
Expand Down Expand Up @@ -91,6 +107,37 @@ public CourseDto getCourseInfo(@PathParam("courseId") String courseId) {
return course;
}


@GET
@Path("/{courseId}/extended")
@Produces("application/json")
public CourseExtendedDto getCourseExtendedInfo(@PathParam("courseId") String courseId) {
CourseExtendedDto course;

try {
Course bbCourse = courseDbLoader.loadByCourseId(courseId);
List<CourseCourse> children = courseCourseDbLoader.loadByParentId(bbCourse.getId());
course = BbCourseHelper.convertBbCourseToCourseExtendedDto(bbCourse);
if (children != null && !children.isEmpty()) {
course.setChildren(new ArrayList<CourseDto>());
for (CourseCourse childCc : children) {
Course childBbCourse = courseDbLoader.loadById(childCc.getChildCourseId());
CourseDto childCourse = BbCourseHelper.convertBbCourseToCourseDto(childBbCourse);
course.getChildren().add(childCourse);
}
}

} catch (KeyNotFoundException ex) {
logger.debug(String.format("No Course with CourseId {} found.", courseId));
throw new WebApplicationException(String.format("No Course with CourseId %s found.", courseId), 404);
} catch (PersistenceException ex) {
logger.error("Error while retrieving courses", ex);
throw new WebApplicationException("Error retrieving Courses", 500);
}

return course;
}

@GET
@Path("/{courseId}/gradebook/assessments")
@Produces("application/json")
Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/WEB-INF/bb-manifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<description value="plugin.description"/>
<default-locale value="en_GB"/>
<webapp-type value="javaext" />
<version value="0.1.2"/>
<version value="0.1.3"/>
<requires>
<bbversion value="9.1"/>
</requires>
Expand Down