use of com.jetbrains.edu.learning.stepic.StepicUser in project intellij-community by JetBrains.
the class StudyProjectGenerator method getCourseInfo.
/**
* Parses course json meta file and finds course name
*
* @return information about course or null if course file is invalid
*/
@Nullable
private static CourseInfo getCourseInfo(File courseFile) {
if (courseFile.isDirectory()) {
File[] courseFiles = courseFile.listFiles((dir, name) -> name.equals(EduNames.COURSE_META_FILE));
if (courseFiles == null || courseFiles.length != 1) {
LOG.info("More than one or without course files");
return null;
}
courseFile = courseFiles[0];
}
CourseInfo courseInfo = null;
BufferedReader reader = null;
try {
if (courseFile.getName().equals(EduNames.COURSE_META_FILE)) {
reader = new BufferedReader(new InputStreamReader(new FileInputStream(courseFile), "UTF-8"));
JsonReader r = new JsonReader(reader);
JsonParser parser = new JsonParser();
JsonElement el = parser.parse(r);
String courseName = el.getAsJsonObject().get(COURSE_NAME_ATTRIBUTE).getAsString();
String courseDescription = el.getAsJsonObject().get(COURSE_DESCRIPTION).getAsString();
JsonArray courseAuthors = el.getAsJsonObject().get(AUTHOR_ATTRIBUTE).getAsJsonArray();
String language = el.getAsJsonObject().get(LANGUAGE_ATTRIBUTE).getAsString();
courseInfo = new CourseInfo();
courseInfo.setName(courseName);
courseInfo.setDescription(courseDescription);
courseInfo.setType("pycharm " + language);
final ArrayList<StepicUser> authors = new ArrayList<>();
for (JsonElement author : courseAuthors) {
final JsonObject authorAsJsonObject = author.getAsJsonObject();
final StepicUser stepicUser = new StepicUser();
stepicUser.setFirstName(authorAsJsonObject.get("first_name").getAsString());
stepicUser.setLastName(authorAsJsonObject.get("last_name").getAsString());
authors.add(stepicUser);
}
courseInfo.setAuthors(authors);
}
} catch (Exception e) {
//error will be shown in UI
} finally {
StudyUtils.closeSilently(reader);
}
return courseInfo;
}
use of com.jetbrains.edu.learning.stepic.StepicUser in project intellij-community by JetBrains.
the class Course method setAuthorsAsString.
@Transient
public void setAuthorsAsString(String[] authors) {
this.authors = new ArrayList<>();
for (String name : authors) {
final List<String> firstLast = StringUtil.split(name, " ");
if (!firstLast.isEmpty()) {
final StepicUser stepicUser = new StepicUser();
stepicUser.setFirstName(firstLast.remove(0));
if (firstLast.size() > 0) {
stepicUser.setLastName(StringUtil.join(firstLast, " "));
}
this.authors.add(stepicUser);
}
}
}
Aggregations