Skip to content

Commit

Permalink
Merge pull request #118 from StepicOrg/feature/new_catalog
Browse files Browse the repository at this point in the history
Updated courses catalog
#IDEA-244 Fixed
  • Loading branch information
meanmail authored Jul 4, 2017
2 parents e7a7465 + fbfa0fb commit 3b8b623
Show file tree
Hide file tree
Showing 14 changed files with 223 additions and 108 deletions.
22 changes: 22 additions & 0 deletions stepik-java-api/src/main/java/org/stepik/api/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@
import java.net.URLEncoder;
import java.nio.file.Files;
import java.nio.file.Path;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.TimeZone;
import java.util.function.Function;
import java.util.stream.Collectors;

Expand All @@ -29,6 +34,14 @@
*/
public class Utils {
private static final Logger logger = LoggerFactory.getLogger(Utils.class);
public final static SimpleDateFormat timeISOFormat = getTimeISOFormat();

private static SimpleDateFormat getTimeISOFormat() {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
TimeZone tz = TimeZone.getTimeZone("UTC");
format.setTimeZone(tz);
return format;
}

@NotNull
public static String mapToGetString(@NotNull String name, @NotNull String[] values) {
Expand Down Expand Up @@ -143,4 +156,13 @@ public static Boolean getBoolean(@NotNull JsonObject json, @NotNull String membe
public static String cleanString(@NotNull String string) {
return string.replaceAll("[\\u0000-\\u0008\\u000b\\u000c\\u000e-\\u001f]", "");
}

@NotNull
public static Date toDate(@Nullable String date) {
try {
return timeISOFormat.parse(date);
} catch (ParseException e) {
return Date.from(Instant.EPOCH);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.time.Instant;
import java.util.Date;

/**
* @author meanmail
*/
Expand Down Expand Up @@ -35,4 +38,9 @@ public int getPosition() {
public String getProgress() {
return null;
}

@NotNull
public Date getUpdateDate() {
return Date.from(Instant.EPOCH);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@
import org.stepik.api.urls.Urls;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import static org.stepik.api.Utils.timeISOFormat;
import static org.stepik.api.Utils.toDate;

/**
* @author meanmail
*/
Expand Down Expand Up @@ -124,6 +128,7 @@ public class Course extends StudyObject {
private String createDate;
@SerializedName("update_date")
private String updateDate;
private transient Date utcUpdateDate;
@SerializedName("learners_group")
private String learnersGroup;
@SerializedName("testers_group")
Expand Down Expand Up @@ -722,15 +727,16 @@ public void setCreateDate(@Nullable String createDate) {
}

@NotNull
public String getUpdateDate() {
if (updateDate == null) {
updateDate = "";
public Date getUpdateDate() {
if (utcUpdateDate == null) {
utcUpdateDate = toDate(updateDate);
}
return updateDate;
return utcUpdateDate;
}

public void setUpdateDate(@Nullable String updateDate) {
this.updateDate = updateDate;
public void setUpdateDate(@Nullable Date updateDate) {
this.updateDate = timeISOFormat.format(updateDate);
utcUpdateDate = updateDate;
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import org.stepik.api.objects.StudyObject;
import org.stepik.api.objects.units.Unit;

import java.util.Date;

/**
* @author meanmail
*/
Expand Down Expand Up @@ -87,7 +89,7 @@ public String getProgress() {
}

@NotNull
public String getUpdateDate() {
public Date getUpdateDate() {
return lesson.getUpdateDate();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
import org.stepik.api.urls.Urls;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import static org.stepik.api.Utils.timeISOFormat;
import static org.stepik.api.Utils.toDate;

/**
* @author meanmail
*/
Expand Down Expand Up @@ -48,6 +52,7 @@ public class Lesson extends StudyObject {
private String createDate;
@SerializedName("update_date")
private String updateDate;
private transient Date utcUpdateDate;
@SerializedName("learners_group")
private String learnersGroup;
@SerializedName("testers_group")
Expand Down Expand Up @@ -386,15 +391,16 @@ public void setCreateDate(@Nullable String createDate) {
}

@NotNull
public String getUpdateDate() {
if (updateDate == null) {
updateDate = "";
public Date getUpdateDate() {
if (utcUpdateDate == null) {
utcUpdateDate = toDate(updateDate);
}
return updateDate;
return utcUpdateDate;
}

public void setUpdateDate(@Nullable String updateDate) {
this.updateDate = updateDate;
public void setUpdateDate(@Nullable Date updateDate) {
this.updateDate = timeISOFormat.format(updateDate);
utcUpdateDate = updateDate;
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
import org.stepik.api.objects.StudyObject;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import static org.stepik.api.Utils.timeISOFormat;
import static org.stepik.api.Utils.toDate;

/**
* @author meanmail
*/
Expand Down Expand Up @@ -63,6 +67,7 @@ public class Section extends StudyObject {
private String createDate;
@SerializedName("update_date")
private String updateDate;
private transient Date utcUpdateDate;

@Override
public boolean equals(Object o) {
Expand Down Expand Up @@ -413,15 +418,16 @@ public void setCreateDate(@Nullable String createDate) {
}

@NotNull
public String getUpdateDate() {
if (updateDate == null) {
updateDate = "";
public Date getUpdateDate() {
if (utcUpdateDate == null) {
utcUpdateDate = toDate(updateDate);
}
return updateDate;
return utcUpdateDate;
}

public void setUpdateDate(@Nullable String updateDate) {
this.updateDate = updateDate;
public void setUpdateDate(@Nullable Date updateDate) {
this.updateDate = timeISOFormat.format(updateDate);
utcUpdateDate = updateDate;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@
import org.stepik.api.urls.Urls;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.stepik.api.Utils.timeISOFormat;
import static org.stepik.api.Utils.toDate;

/**
* @author meanmail
*/
Expand Down Expand Up @@ -45,6 +49,7 @@ public class Step extends StudyObject {
private String createDate;
@SerializedName("update_date")
private String updateDate;
private transient Date utcUpdateDate;
@SerializedName("discussions_count")
private int discussionsCount;
@SerializedName("discussion_proxy")
Expand Down Expand Up @@ -294,15 +299,16 @@ public void setCreateDate(@Nullable String createDate) {
}

@NotNull
public String getUpdateDate() {
if (updateDate == null) {
updateDate = "";
public Date getUpdateDate() {
if (utcUpdateDate == null) {
utcUpdateDate = toDate(updateDate);
}
return updateDate;
return utcUpdateDate;
}

public void setUpdateDate(@Nullable String updateDate) {
this.updateDate = updateDate;
public void setUpdateDate(@Nullable Date updateDate) {
this.updateDate = timeISOFormat.format(updateDate);
utcUpdateDate = updateDate;
}

public int getDiscussionsCount() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@
import org.stepik.api.objects.AbstractObject;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.util.Date;
import java.util.TimeZone;

import static org.stepik.api.Utils.timeISOFormat;

/**
* @author meanmail
*/
public class Submission extends AbstractObject {
private final static SimpleDateFormat timeISOFormat = getTimeISOFormat();

private String status;
private double score;
private String hint;
Expand All @@ -30,13 +28,6 @@ public class Submission extends AbstractObject {
private double eta;
private transient Date utcTime;

private static SimpleDateFormat getTimeISOFormat() {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
TimeZone tz = TimeZone.getTimeZone("UTC");
format.setTimeZone(tz);
return format;
}

@NotNull
public String getStatus() {
if (status == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.stepik.core.core.EduNames;

import java.util.Collections;
import java.util.Date;
import java.util.List;

public class LessonNode extends Node<CompoundUnitLesson, StepNode, Step, StepNode> {
Expand Down Expand Up @@ -65,7 +66,7 @@ protected boolean loadData(@NotNull StepikApiClient stepikApiClient, long id) {
return true;
}

String updateDate = data.getUpdateDate();
Date updateDate = data.getUpdateDate();

Lessons lessons = stepikApiClient.lessons()
.get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,8 @@ private static class SubmissionDecorator {

@Override
public String toString() {
String localTime;
Date utcTime = submission.getTime();
localTime = timeOutFormat.format(utcTime);
String localTime = timeOutFormat.format(utcTime);

return String.format("#%d %-7s %s", submission.getId(), submission.getStatus(), localTime);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package org.stepik.plugin.projectWizard

import org.stepik.core.SupportedLanguages.ASM32
import org.stepik.core.SupportedLanguages.ASM64
import org.stepik.core.SupportedLanguages.C
import org.stepik.core.SupportedLanguages.CLOJURE
import org.stepik.core.SupportedLanguages.CPP
import org.stepik.core.SupportedLanguages.CPP_11
import org.stepik.core.SupportedLanguages.GO
import org.stepik.core.SupportedLanguages.HASKELL
import org.stepik.core.SupportedLanguages.HASKELL_7_10
import org.stepik.core.SupportedLanguages.HASKELL_8_0
import org.stepik.core.SupportedLanguages.JAVA
import org.stepik.core.SupportedLanguages.JAVA8
import org.stepik.core.SupportedLanguages.JAVASCRIPT
import org.stepik.core.SupportedLanguages.KOTLIN
import org.stepik.core.SupportedLanguages.MONO_CS
import org.stepik.core.SupportedLanguages.OCTAVE
import org.stepik.core.SupportedLanguages.PASCAL_ABC
import org.stepik.core.SupportedLanguages.PYTHON3
import org.stepik.core.SupportedLanguages.R
import org.stepik.core.SupportedLanguages.RUBY
import org.stepik.core.SupportedLanguages.RUST
import org.stepik.core.SupportedLanguages.SCALA
import org.stepik.core.SupportedLanguages.SHELL

object CoursesList {
val DEFAULT_COURSES = listOf(156L, 217L, 1127L, 125L, 126L, 150L)

val ASM_COURSES = listOf(253L, 1780L, 156L, 217L, 1127L, 125L, 126L, 150L)
val CPP_COURSES = listOf(579L, 363L, 144L, 153L, 538L, 7L, 156L, 217L, 1127L, 125L, 126L, 150L)
val HASKELL_COURSES = listOf(75L, 693L, 156L, 217L, 1127L, 125L, 126L, 150L)
val JAVA_COURSES = listOf(187L, 150L, 2403L, 2600L, 1891L, 1595L, 2262L, 217L, 1127L, 125L, 126L)
val JAVASCRIPT_COURSES = listOf(2606L, 2223L, 156L, 217L, 1127L, 125L, 126L, 150L)
val KOTLIN_COURSES = listOf(2852L, 156L, 217L, 1127L, 125L, 126L, 150L)
val PYTHON_COURSES = listOf(67L, 512L, 401L, 568L, 431L, 2057L, 156L, 217L, 1127L, 125L, 126L, 150L)
val R_COURSES = listOf(497L, 129L, 724L, 156L, 217L, 1127L, 125L, 126L, 150L)
val RUBY_COURSES = listOf(156L, 1127L, 125L, 126L, 150L)
val SCALA_COURSES = listOf(2294L, 156L, 217L, 1127L, 125L, 126L, 150L)

@JvmField
val COURSES = mapOf(
ASM32 to ASM_COURSES,
ASM64 to ASM_COURSES,
C to DEFAULT_COURSES,
CLOJURE to DEFAULT_COURSES,
CPP to CPP_COURSES,
CPP_11 to CPP_COURSES,
GO to DEFAULT_COURSES,
HASKELL to HASKELL_COURSES,
HASKELL_7_10 to HASKELL_COURSES,
HASKELL_8_0 to HASKELL_COURSES,
JAVA to JAVA_COURSES,
JAVA8 to JAVA_COURSES,
JAVASCRIPT to JAVASCRIPT_COURSES,
KOTLIN to KOTLIN_COURSES,
MONO_CS to DEFAULT_COURSES,
OCTAVE to DEFAULT_COURSES,
PASCAL_ABC to DEFAULT_COURSES,
PYTHON3 to PYTHON_COURSES,
R to R_COURSES,
RUBY to RUBY_COURSES,
RUST to DEFAULT_COURSES,
SCALA to SCALA_COURSES,
SHELL to DEFAULT_COURSES
)
}
Loading

0 comments on commit 3b8b623

Please sign in to comment.