1 package com.jetbrains.edu.learning.stepic;
3 import com.google.gson.annotations.SerializedName;
4 import com.jetbrains.edu.learning.courseFormat.Course;
5 import com.jetbrains.edu.learning.courseGeneration.StudyProjectGenerator;
6 import org.jetbrains.annotations.NotNull;
7 import org.jetbrains.annotations.Nullable;
9 import java.util.ArrayList;
10 import java.util.Date;
11 import java.util.List;
12 import java.util.stream.Collectors;
15 * Implementation of class which contains information to be shawn in course description in tool window
16 * and when project is being created
18 public class CourseInfo {
19 public static final CourseInfo INVALID_COURSE = new CourseInfo();
21 @SerializedName("title") private String myName;
24 @SerializedName("is_public") boolean isPublic;
25 List<Integer> sections;
26 List<Integer> instructors = new ArrayList<>();
28 List<StepicUser> myAuthors = new ArrayList<>();
29 @SerializedName("summary") private String myDescription;
30 @SerializedName("course_format") private String myType = "pycharm" + EduStepicConnector.CURRENT_VERSION + " Python"; //course type in format "pycharm <language>"
31 @Nullable private String username;
33 @SerializedName("update_date") private Date updateDate;
34 @SerializedName("is_idea_compatible") private boolean isCompatible = true;
36 public String getName() {
41 public List<StepicUser> getAuthors() {
45 public String getDescription() {
49 public String getType() {
54 public String toString() {
59 public boolean equals(Object o) {
60 if (this == o) return true;
61 if (o == null || getClass() != o.getClass()) return false;
62 CourseInfo that = (CourseInfo)o;
63 if (that.getName() == null || that.getDescription() == null) return false;
64 return that.getName().equals(getName())
65 && that.getDescription().equals(myDescription);
69 public int hashCode() {
70 int result = getName() != null ? getName().hashCode() : 0;
71 result = 31 * result + (myDescription != null ? myDescription.hashCode() : 0);
76 public String getUsername() {
80 public void setUsername(@Nullable String username) {
81 this.username = username;
84 public void setName(String name) {
88 public void setAuthors(List<StepicUser> authors) {
90 for (StepicUser author : authors) {
91 if (author.getId() > 0) {
92 instructors.add(author.getId());
97 public void addAuthor(StepicUser author) {
98 if (myAuthors == null) {
99 myAuthors = new ArrayList<>();
101 myAuthors.add(author);
104 public void setDescription(String description) {
105 myDescription = description;
108 public void setType(String type) {
112 public boolean isAdaptive() {
116 public void setAdaptive(boolean adaptive) {
117 isAdaptive = adaptive;
120 public boolean isPublic() {
124 public void setPublic(boolean aPublic) {
132 public void setId(int id) {
136 public Date getUpdateDate() {
140 public void setUpdateDate(Date updateDate) {
141 this.updateDate = updateDate;
144 public static CourseInfo fromCourse(@Nullable final Course course) {
145 if (course == null) return null;
146 final List<CourseInfo> infos = StudyProjectGenerator.getCoursesFromCache().stream().
147 filter(info -> info.id == course.getId()).collect(Collectors.toList());
148 if (infos.isEmpty()) return null;
152 public List<Integer> getSections() {
156 public boolean isCompatible() {
160 public void setCompatible(boolean compatible) {
161 isCompatible = compatible;