diff --git a/.idea/codeStyleSettings.xml b/.idea/codeStyleSettings.xml index 0be55418b..f5bd97e62 100644 --- a/.idea/codeStyleSettings.xml +++ b/.idea/codeStyleSettings.xml @@ -60,9 +60,7 @@ - - - + @@ -223,6 +221,6 @@ - + \ No newline at end of file diff --git a/api/build.gradle b/api/build.gradle index e376b94a2..502b74d27 100644 --- a/api/build.gradle +++ b/api/build.gradle @@ -7,7 +7,6 @@ apply plugin: 'com.github.dcendents.android-maven' compileJava.options.encoding = "UTF-8" compileTestJava.options.encoding = "UTF-8" - ext { PUBLISH_GROUP_ID = GROUP_ID PUBLISH_ARTIFACT_ID = 'api' @@ -29,7 +28,7 @@ jacocoTestReport { } dependencies { - implementation 'org.jsoup:jsoup:1.10.3' + implementation 'org.jsoup:jsoup:1.11.2' implementation 'org.apache.commons:commons-lang3:3.6' testImplementation 'junit:junit:4.12' diff --git a/api/src/main/java/io/github/wulkanowy/api/SnP.java b/api/src/main/java/io/github/wulkanowy/api/SnP.java new file mode 100644 index 000000000..f89b71cf9 --- /dev/null +++ b/api/src/main/java/io/github/wulkanowy/api/SnP.java @@ -0,0 +1,36 @@ +package io.github.wulkanowy.api; + +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; + +import java.io.IOException; +import java.util.List; + +import io.github.wulkanowy.api.login.NotLoggedInErrorException; + +public interface SnP { + + void setProtocolSchema(String schema); + + String getLogHost(); + + void setLogHost(String hostname); + + String getSymbol(); + + String getId(); + + void storeContextCookies() throws IOException, NotLoggedInErrorException; + + Cookies getCookiesObject(); + + String getRowDataChildValue(Element e, int index); + + Document getSnPPageDocument(String url) throws IOException; + + List getSemesters() throws IOException; + + List getSemesters(Document gradesPage); + + Semester getCurrentSemester(List semesterList); +} diff --git a/api/src/main/java/io/github/wulkanowy/api/StudentAndParent.java b/api/src/main/java/io/github/wulkanowy/api/StudentAndParent.java index dea8b8688..06c2d38f6 100644 --- a/api/src/main/java/io/github/wulkanowy/api/StudentAndParent.java +++ b/api/src/main/java/io/github/wulkanowy/api/StudentAndParent.java @@ -10,16 +10,20 @@ import java.util.List; import io.github.wulkanowy.api.login.NotLoggedInErrorException; -public class StudentAndParent extends Api { +public class StudentAndParent extends Api implements SnP { - private String startPageUrl = "https://uonetplus.vulcan.net.pl/{symbol}/Start.mvc/Index"; + private static final String startPageUrl = "{schema}://uonetplus.{host}/{symbol}/Start.mvc/Index"; - private String baseUrl = "https://uonetplus-opiekun.vulcan.net.pl/{symbol}/{ID}/"; + private static final String baseUrl = "{schema}://uonetplus-opiekun.{host}/{symbol}/{ID}/"; private static final String SYMBOL_PLACEHOLDER = "{symbol}"; private static final String GRADES_PAGE_URL = "Oceny/Wszystkie"; + protected String logHost = "vulcan.net.pl"; + + private String protocolSchema = "https"; + private String symbol; private String id; @@ -34,16 +38,35 @@ public class StudentAndParent extends Api { this.id = id; } - public String getGradesPageUrl() { - return baseUrl + GRADES_PAGE_URL; + public void setProtocolSchema(String schema) { + this.protocolSchema = schema; } - public String getBaseUrl() { - return baseUrl; + public String getLogHost() { + return logHost; + } + + public void setLogHost(String hostname) { + this.logHost = hostname; } public String getStartPageUrl() { - return startPageUrl; + return startPageUrl + .replace("{schema}", protocolSchema) + .replace("{host}", logHost) + .replace(SYMBOL_PLACEHOLDER, getSymbol()); + } + + public String getBaseUrl() { + return baseUrl + .replace("{schema}", protocolSchema) + .replace("{host}", logHost) + .replace(SYMBOL_PLACEHOLDER, getSymbol()) + .replace("{ID}", getId()); + } + + public String getGradesPageUrl() { + return getBaseUrl() + GRADES_PAGE_URL; } public String getSymbol() { @@ -60,11 +83,11 @@ public class StudentAndParent extends Api { public String getSnpPageUrl() throws IOException, NotLoggedInErrorException { if (null != getId()) { - return getBaseUrl().replace(SYMBOL_PLACEHOLDER, getSymbol()).replace("{ID}", getId()); + return getBaseUrl(); } // get url to uonetplus-opiekun.vulcan.net.pl - Document startPage = getPageByUrl(getStartPageUrl().replace(SYMBOL_PLACEHOLDER, getSymbol())); + Document startPage = getPageByUrl(getStartPageUrl()); Element studentTileLink = startPage.select(".panel.linkownia.pracownik.klient > a").first(); if (null == studentTileLink) { @@ -79,7 +102,7 @@ public class StudentAndParent extends Api { } public String getExtractedIdFromUrl(String snpPageUrl) throws NotLoggedInErrorException { - String[] path = snpPageUrl.split("vulcan.net.pl/")[1].split("/"); + String[] path = snpPageUrl.split(getLogHost() + "/")[1].split("/"); if (4 != path.length) { throw new NotLoggedInErrorException(); diff --git a/api/src/main/java/io/github/wulkanowy/api/Vulcan.java b/api/src/main/java/io/github/wulkanowy/api/Vulcan.java index fb965fb43..e6707e91a 100644 --- a/api/src/main/java/io/github/wulkanowy/api/Vulcan.java +++ b/api/src/main/java/io/github/wulkanowy/api/Vulcan.java @@ -12,6 +12,7 @@ import io.github.wulkanowy.api.login.BadCredentialsException; import io.github.wulkanowy.api.login.Login; import io.github.wulkanowy.api.login.LoginErrorException; import io.github.wulkanowy.api.login.NotLoggedInErrorException; +import io.github.wulkanowy.api.login.VulcanOfflineException; import io.github.wulkanowy.api.notes.AchievementsList; import io.github.wulkanowy.api.notes.NotesList; import io.github.wulkanowy.api.school.SchoolInfo; @@ -26,29 +27,80 @@ public class Vulcan extends Api { private String symbol; - private StudentAndParent snp; + private SnP snp; - public void login(Cookies cookies, String symbol) { + private String protocolSchema = "https"; + + private String logHost = "vulcan.net.pl"; + + private String email; + + public Vulcan login(Cookies cookies, String symbol) { this.cookies = cookies; this.symbol = symbol; + + return this; } - public void login(String email, String password, String symbol) - throws BadCredentialsException, AccountPermissionException, LoginErrorException, IOException { - Login login = new Login(new Cookies()); - String realSymbol = login.login(email, password, symbol); + public Vulcan login(String email, String password, String symbol) + throws BadCredentialsException, AccountPermissionException, + LoginErrorException, IOException, VulcanOfflineException { + Login login = getLoginObject(); + + setFullEndpointInfo(email); + login.setProtocolSchema(protocolSchema); + login.setLogHost(logHost); + + String realSymbol = login.login(this.email, password, symbol); login(login.getCookiesObject(), realSymbol); + + return this; } - public void login(String email, String password, String symbol, String id) - throws BadCredentialsException, AccountPermissionException, LoginErrorException, IOException { + public Vulcan login(String email, String password, String symbol, String id) + throws BadCredentialsException, AccountPermissionException, + LoginErrorException, IOException, VulcanOfflineException { login(email, password, symbol); this.id = id; + + return this; } - public StudentAndParent getStudentAndParent() throws IOException, NotLoggedInErrorException { + public String getProtocolSchema() { + return protocolSchema; + } + + public String getLogHost() { + return logHost; + } + + public String getEmail() { + return email; + } + + public Login getLoginObject() { + return new Login(new Cookies()); + } + + public Vulcan setFullEndpointInfo(String email) { + String[] creds = email.split("\\\\"); + + this.email = email; + + if (creds.length >= 2) { + String[] url = creds[0].split("://"); + + this.protocolSchema = url[0]; + this.logHost = url[1]; + this.email = creds[2]; + } + + return this; + } + + public SnP getStudentAndParent() throws IOException, NotLoggedInErrorException { if (null == getCookiesObject()) { throw new NotLoggedInErrorException(); } @@ -58,6 +110,8 @@ public class Vulcan extends Api { } snp = createSnp(cookies, symbol, id); + snp.setLogHost(logHost); + snp.setProtocolSchema(protocolSchema); snp.storeContextCookies(); @@ -66,7 +120,7 @@ public class Vulcan extends Api { return snp; } - public StudentAndParent createSnp(Cookies cookies, String symbol, String id) { + public SnP createSnp(Cookies cookies, String symbol, String id) { if (null == id) { return new StudentAndParent(cookies, symbol); } diff --git a/api/src/main/java/io/github/wulkanowy/api/attendance/AttendanceStatistics.java b/api/src/main/java/io/github/wulkanowy/api/attendance/AttendanceStatistics.java index 53d9bcfaf..c51948341 100644 --- a/api/src/main/java/io/github/wulkanowy/api/attendance/AttendanceStatistics.java +++ b/api/src/main/java/io/github/wulkanowy/api/attendance/AttendanceStatistics.java @@ -8,15 +8,15 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -import io.github.wulkanowy.api.StudentAndParent; +import io.github.wulkanowy.api.SnP; public class AttendanceStatistics { - private StudentAndParent snp; + private SnP snp; private String attendancePageUrl = "Frekwencja.mvc"; - public AttendanceStatistics(StudentAndParent snp) { + public AttendanceStatistics(SnP snp) { this.snp = snp; } diff --git a/api/src/main/java/io/github/wulkanowy/api/attendance/AttendanceTable.java b/api/src/main/java/io/github/wulkanowy/api/attendance/AttendanceTable.java index 1452d9e14..0576257e2 100644 --- a/api/src/main/java/io/github/wulkanowy/api/attendance/AttendanceTable.java +++ b/api/src/main/java/io/github/wulkanowy/api/attendance/AttendanceTable.java @@ -7,15 +7,15 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -import io.github.wulkanowy.api.StudentAndParent; +import io.github.wulkanowy.api.SnP; public class AttendanceTable { - private StudentAndParent snp; + private SnP snp; private String attendancePageUrl = "Frekwencja.mvc?data="; - public AttendanceTable(StudentAndParent snp) { + public AttendanceTable(SnP snp) { this.snp = snp; } diff --git a/api/src/main/java/io/github/wulkanowy/api/exams/ExamsWeek.java b/api/src/main/java/io/github/wulkanowy/api/exams/ExamsWeek.java index 0cb326fe8..09b75a945 100644 --- a/api/src/main/java/io/github/wulkanowy/api/exams/ExamsWeek.java +++ b/api/src/main/java/io/github/wulkanowy/api/exams/ExamsWeek.java @@ -8,15 +8,15 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -import io.github.wulkanowy.api.StudentAndParent; +import io.github.wulkanowy.api.SnP; public class ExamsWeek { - private final StudentAndParent snp; - private static final String EXAMS_PAGE_URL = "Sprawdziany.mvc/Terminarz?rodzajWidoku=2&data="; - public ExamsWeek(StudentAndParent snp) { + private final SnP snp; + + public ExamsWeek(SnP snp) { this.snp = snp; } diff --git a/api/src/main/java/io/github/wulkanowy/api/grades/GradesList.java b/api/src/main/java/io/github/wulkanowy/api/grades/GradesList.java index 123e648ba..cc2e4c4ac 100644 --- a/api/src/main/java/io/github/wulkanowy/api/grades/GradesList.java +++ b/api/src/main/java/io/github/wulkanowy/api/grades/GradesList.java @@ -15,17 +15,17 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import io.github.wulkanowy.api.Semester; -import io.github.wulkanowy.api.StudentAndParent; +import io.github.wulkanowy.api.SnP; public class GradesList { - private StudentAndParent snp = null; - private static final String GRADES_PAGE_URL = "Oceny/Wszystkie?details=2&okres="; + private SnP snp = null; + private List grades = new ArrayList<>(); - public GradesList(StudentAndParent snp) { + public GradesList(SnP snp) { this.snp = snp; } diff --git a/api/src/main/java/io/github/wulkanowy/api/grades/SubjectsList.java b/api/src/main/java/io/github/wulkanowy/api/grades/SubjectsList.java index fef666c77..decf44686 100644 --- a/api/src/main/java/io/github/wulkanowy/api/grades/SubjectsList.java +++ b/api/src/main/java/io/github/wulkanowy/api/grades/SubjectsList.java @@ -8,15 +8,15 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -import io.github.wulkanowy.api.StudentAndParent; +import io.github.wulkanowy.api.SnP; public class SubjectsList { - private StudentAndParent snp = null; - private static final String SUBJECTS_PAGE_URL = "Oceny/Wszystkie?details=1"; - public SubjectsList(StudentAndParent snp) { + private SnP snp = null; + + public SubjectsList(SnP snp) { this.snp = snp; } diff --git a/api/src/main/java/io/github/wulkanowy/api/login/Login.java b/api/src/main/java/io/github/wulkanowy/api/login/Login.java index 70a79fe2e..7908bfd1a 100644 --- a/api/src/main/java/io/github/wulkanowy/api/login/Login.java +++ b/api/src/main/java/io/github/wulkanowy/api/login/Login.java @@ -6,34 +6,57 @@ import org.jsoup.parser.Parser; import org.jsoup.select.Elements; import java.io.IOException; +import java.util.regex.Pattern; import io.github.wulkanowy.api.Api; import io.github.wulkanowy.api.Cookies; public class Login extends Api { - private String loginPageUrl = "https://cufs.vulcan.net.pl/{symbol}/Account/LogOn" + + private static final String loginPageUrl = "{schema}://cufs.{host}/{symbol}/Account/LogOn" + "?ReturnUrl=%2F{symbol}%2FFS%2FLS%3Fwa%3Dwsignin1.0%26wtrealm%3D" + - "https%253a%252f%252fuonetplus.vulcan.net.pl%252f{symbol}%252fLoginEndpoint.aspx%26wctx%3D" + - "https%253a%252f%252fuonetplus.vulcan.net.pl%252f{symbol}%252fLoginEndpoint.aspx"; + "{schema}%253a%252f%252fuonetplus.{host}%252f{symbol}%252fLoginEndpoint.aspx%26wctx%3D" + + "{schema}%253a%252f%252fuonetplus.{host}%252f{symbol}%252fLoginEndpoint.aspx"; - private String loginEndpointPageUrl = - "https://uonetplus.vulcan.net.pl/{symbol}/LoginEndpoint.aspx"; + private static final String loginEndpointPageUrl = + "{schema}://uonetplus.{host}/{symbol}/LoginEndpoint.aspx"; + + private String protocolSchema = "https"; + + private String logHost = "vulcan.net.pl"; + + private String symbol = "Default"; public Login(Cookies cookies) { this.cookies = cookies; } + public void setProtocolSchema(String schema) { + this.protocolSchema = schema; + } + + public void setLogHost(String hostname) { + this.logHost = hostname; + } + public String getLoginPageUrl() { - return loginPageUrl; + return loginPageUrl + .replace("{schema}", protocolSchema) + .replaceFirst(Pattern.quote("{host}"), logHost) + .replace("{host}", logHost.replace(":", "%253A")) + .replace("{symbol}", symbol); } public String getLoginEndpointPageUrl() { - return loginEndpointPageUrl; + return loginEndpointPageUrl + .replace("{schema}", protocolSchema) + .replace("{host}", logHost) + .replace("{symbol}", symbol); } public String login(String email, String password, String symbol) - throws BadCredentialsException, LoginErrorException, AccountPermissionException, IOException { + throws BadCredentialsException, LoginErrorException, + AccountPermissionException, IOException, VulcanOfflineException { String certificate = sendCredentials(email, password, symbol); return sendCertificate(certificate, symbol); @@ -41,9 +64,9 @@ public class Login extends Api { public String sendCredentials(String email, String password, String symbol) throws IOException, BadCredentialsException { - loginPageUrl = getLoginPageUrl().replace("{symbol}", symbol); + this.symbol = symbol; - Document html = postPageByUrl(loginPageUrl, new String[][]{ + Document html = postPageByUrl(getLoginPageUrl(), new String[][]{ {"LoginName", email}, {"Password", password} }); @@ -56,13 +79,10 @@ public class Login extends Api { } public String sendCertificate(String certificate, String defaultSymbol) - throws IOException, LoginErrorException, AccountPermissionException { - String symbol = findSymbol(defaultSymbol, certificate); + throws IOException, LoginErrorException, AccountPermissionException, VulcanOfflineException { + this.symbol = findSymbol(defaultSymbol, certificate); - loginEndpointPageUrl = getLoginEndpointPageUrl() - .replace("{symbol}", symbol); - - Document html = postPageByUrl(loginEndpointPageUrl, new String[][]{ + Document html = postPageByUrl(getLoginEndpointPageUrl(), new String[][]{ {"wa", "wsignin1.0"}, {"wresult", certificate} }); @@ -71,11 +91,15 @@ public class Login extends Api { throw new AccountPermissionException(); } + if (html.getElementsByTag("title").text().equals("Przerwa techniczna")) { + throw new VulcanOfflineException(); + } + if (!html.select("title").text().equals("Uonet+")) { throw new LoginErrorException(); } - return symbol; + return this.symbol; } public String findSymbol(String symbol, String certificate) { diff --git a/api/src/main/java/io/github/wulkanowy/api/login/VulcanOfflineException.java b/api/src/main/java/io/github/wulkanowy/api/login/VulcanOfflineException.java new file mode 100644 index 000000000..45cf64583 --- /dev/null +++ b/api/src/main/java/io/github/wulkanowy/api/login/VulcanOfflineException.java @@ -0,0 +1,4 @@ +package io.github.wulkanowy.api.login; + +public class VulcanOfflineException extends Exception { +} diff --git a/api/src/main/java/io/github/wulkanowy/api/notes/AchievementsList.java b/api/src/main/java/io/github/wulkanowy/api/notes/AchievementsList.java index ee41f71cc..c821e8bec 100644 --- a/api/src/main/java/io/github/wulkanowy/api/notes/AchievementsList.java +++ b/api/src/main/java/io/github/wulkanowy/api/notes/AchievementsList.java @@ -7,17 +7,17 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -import io.github.wulkanowy.api.StudentAndParent; +import io.github.wulkanowy.api.SnP; public class AchievementsList { - private StudentAndParent snp = null; + private static final String NOTES_PAGE_URL = "UwagiOsiagniecia.mvc/Wszystkie"; + + private SnP snp = null; private List achievements = new ArrayList<>(); - private static final String NOTES_PAGE_URL = "UwagiOsiagniecia.mvc/Wszystkie"; - - public AchievementsList(StudentAndParent snp) { + public AchievementsList(SnP snp) { this.snp = snp; } diff --git a/api/src/main/java/io/github/wulkanowy/api/notes/NotesList.java b/api/src/main/java/io/github/wulkanowy/api/notes/NotesList.java index 4ee6bb648..34b8540d9 100644 --- a/api/src/main/java/io/github/wulkanowy/api/notes/NotesList.java +++ b/api/src/main/java/io/github/wulkanowy/api/notes/NotesList.java @@ -7,17 +7,17 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -import io.github.wulkanowy.api.StudentAndParent; +import io.github.wulkanowy.api.SnP; public class NotesList { - private StudentAndParent snp = null; + private static final String NOTES_PAGE_URL = "UwagiOsiagniecia.mvc/Wszystkie"; + + private SnP snp = null; private List notes = new ArrayList<>(); - private static final String NOTES_PAGE_URL = "UwagiOsiagniecia.mvc/Wszystkie"; - - public NotesList(StudentAndParent snp) { + public NotesList(SnP snp) { this.snp = snp; } diff --git a/api/src/main/java/io/github/wulkanowy/api/school/SchoolInfo.java b/api/src/main/java/io/github/wulkanowy/api/school/SchoolInfo.java index 44bd77033..4eeb641cc 100644 --- a/api/src/main/java/io/github/wulkanowy/api/school/SchoolInfo.java +++ b/api/src/main/java/io/github/wulkanowy/api/school/SchoolInfo.java @@ -4,15 +4,15 @@ import org.jsoup.nodes.Element; import java.io.IOException; -import io.github.wulkanowy.api.StudentAndParent; +import io.github.wulkanowy.api.SnP; public class SchoolInfo { - private StudentAndParent snp = null; - private static final String SCHOOL_PAGE_URL = "Szkola.mvc/Nauczyciele"; - public SchoolInfo(StudentAndParent snp) { + private SnP snp = null; + + public SchoolInfo(SnP snp) { this.snp = snp; } diff --git a/api/src/main/java/io/github/wulkanowy/api/school/TeachersInfo.java b/api/src/main/java/io/github/wulkanowy/api/school/TeachersInfo.java index f37b7c543..e8af67446 100644 --- a/api/src/main/java/io/github/wulkanowy/api/school/TeachersInfo.java +++ b/api/src/main/java/io/github/wulkanowy/api/school/TeachersInfo.java @@ -8,15 +8,15 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -import io.github.wulkanowy.api.StudentAndParent; +import io.github.wulkanowy.api.SnP; public class TeachersInfo { - private StudentAndParent snp = null; - private static final String SCHOOL_PAGE_URL = "Szkola.mvc/Nauczyciele"; - public TeachersInfo(StudentAndParent snp) { + private SnP snp = null; + + public TeachersInfo(SnP snp) { this.snp = snp; } diff --git a/api/src/main/java/io/github/wulkanowy/api/timetable/Timetable.java b/api/src/main/java/io/github/wulkanowy/api/timetable/Timetable.java index efff17806..cbece431b 100644 --- a/api/src/main/java/io/github/wulkanowy/api/timetable/Timetable.java +++ b/api/src/main/java/io/github/wulkanowy/api/timetable/Timetable.java @@ -12,15 +12,15 @@ import java.util.Date; import java.util.List; import java.util.Locale; -import io.github.wulkanowy.api.StudentAndParent; +import io.github.wulkanowy.api.SnP; public class Timetable { - private StudentAndParent snp; - private static final String TIMETABLE_PAGE_URL = "Lekcja.mvc/PlanLekcji?data="; - public Timetable(StudentAndParent snp) { + private SnP snp; + + public Timetable(SnP snp) { this.snp = snp; } diff --git a/api/src/main/java/io/github/wulkanowy/api/user/BasicInformation.java b/api/src/main/java/io/github/wulkanowy/api/user/BasicInformation.java index 2a1a01f8d..875cc8da0 100644 --- a/api/src/main/java/io/github/wulkanowy/api/user/BasicInformation.java +++ b/api/src/main/java/io/github/wulkanowy/api/user/BasicInformation.java @@ -5,19 +5,19 @@ import org.jsoup.nodes.Element; import java.io.IOException; -import io.github.wulkanowy.api.StudentAndParent; +import io.github.wulkanowy.api.SnP; public class BasicInformation { - private Document studentDataPageDocument; - - private StudentAndParent snp; - private static final String STUDENT_DATA_PAGE_URL = "Uczen.mvc/DanePodstawowe"; private static final String CONTENT_QUERY = ".mainContainer > article"; - public BasicInformation(StudentAndParent snp) { + private Document studentDataPageDocument; + + private SnP snp; + + public BasicInformation(SnP snp) { this.snp = snp; } diff --git a/api/src/main/java/io/github/wulkanowy/api/user/FamilyInformation.java b/api/src/main/java/io/github/wulkanowy/api/user/FamilyInformation.java index 214224f8f..555de8664 100644 --- a/api/src/main/java/io/github/wulkanowy/api/user/FamilyInformation.java +++ b/api/src/main/java/io/github/wulkanowy/api/user/FamilyInformation.java @@ -7,15 +7,15 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -import io.github.wulkanowy.api.StudentAndParent; +import io.github.wulkanowy.api.SnP; public class FamilyInformation { - private StudentAndParent snp; - private static final String STUDENT_DATA_PAGE_URL = "Uczen.mvc/DanePodstawowe"; - public FamilyInformation(StudentAndParent snp) { + private SnP snp; + + public FamilyInformation(SnP snp) { this.snp = snp; } diff --git a/api/src/test/java/io/github/wulkanowy/api/StudentAndParentTest.java b/api/src/test/java/io/github/wulkanowy/api/StudentAndParentTest.java index 9b0609e32..e8ca13427 100644 --- a/api/src/test/java/io/github/wulkanowy/api/StudentAndParentTest.java +++ b/api/src/test/java/io/github/wulkanowy/api/StudentAndParentTest.java @@ -26,7 +26,8 @@ public class StudentAndParentTest { Mockito.when(snp.getSnPPageDocument(Mockito.anyString())).thenReturn(gradesPageDocument); Mockito.when(snp.getExtractedIdFromUrl(Mockito.anyString())).thenCallRealMethod(); - Mockito.when(snp.getBaseUrl()).thenReturn("https://uonetplus-opiekun.vulcan.net.pl/{symbol}/{ID}/"); + Mockito.when(snp.getLogHost()).thenReturn("vulcan.net.pl"); + Mockito.when(snp.getBaseUrl()).thenReturn("https://uonetplus-opiekun.vulcan.net.pl/symbol/123456/"); Mockito.when(snp.getSymbol()).thenReturn("symbol"); Mockito.when(snp.getId()).thenReturn("123456"); Mockito.when(snp.getSemesters()).thenCallRealMethod(); diff --git a/api/src/test/java/io/github/wulkanowy/api/VulcanTest.java b/api/src/test/java/io/github/wulkanowy/api/VulcanTest.java index 844733861..7a87ed6e9 100644 --- a/api/src/test/java/io/github/wulkanowy/api/VulcanTest.java +++ b/api/src/test/java/io/github/wulkanowy/api/VulcanTest.java @@ -8,8 +8,10 @@ import org.mockito.Mockito; import io.github.wulkanowy.api.attendance.AttendanceStatistics; import io.github.wulkanowy.api.attendance.AttendanceTable; +import io.github.wulkanowy.api.exams.ExamsWeek; import io.github.wulkanowy.api.grades.GradesList; import io.github.wulkanowy.api.grades.SubjectsList; +import io.github.wulkanowy.api.login.Login; import io.github.wulkanowy.api.login.NotLoggedInErrorException; import io.github.wulkanowy.api.notes.AchievementsList; import io.github.wulkanowy.api.notes.NotesList; @@ -31,6 +33,38 @@ public class VulcanTest extends Vulcan { .thenReturn(snp); } + @Test + public void setFullEndpointInfoTest() throws Exception { + SnP snp = new StudentAndParent(new Cookies(), "Default"); + Login login = Mockito.mock(Login.class); + + Vulcan vulcan = Mockito.mock(Vulcan.class); + Mockito.when(vulcan.login(Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).thenCallRealMethod(); + Mockito.when(vulcan.login(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).thenCallRealMethod(); + Mockito.when(vulcan.getLoginObject()).thenReturn(login); + Mockito.when(vulcan.createSnp(Mockito.any(Cookies.class), Mockito.anyString(), Mockito.anyString())).thenReturn(snp); + Mockito.when(vulcan.getCookiesObject()).thenCallRealMethod(); + Mockito.when(vulcan.getStudentAndParent()).thenCallRealMethod(); + + Mockito.when(vulcan.setFullEndpointInfo(Mockito.anyString())).thenCallRealMethod(); + + Mockito.when(vulcan.getProtocolSchema()).thenCallRealMethod(); + Mockito.when(vulcan.getLogHost()).thenCallRealMethod(); + Mockito.when(vulcan.getEmail()).thenCallRealMethod(); + + vulcan.login("http://fakelog.net\\\\admin", "pass", "Default", "123"); + Assert.assertEquals("http", vulcan.getProtocolSchema()); + Assert.assertEquals("fakelog.net", vulcan.getLogHost()); + Assert.assertEquals("admin", vulcan.getEmail()); + } + + @Test + public void getLoginObjectTest() throws Exception { + Mockito.when(vulcan.getLoginObject()).thenCallRealMethod(); + + Assert.assertThat(vulcan.getLoginObject(), CoreMatchers.instanceOf(Login.class)); + } + @Test public void getStudentAndParentTest() throws Exception { Cookies cookies = new Cookies(); @@ -47,7 +81,7 @@ public class VulcanTest extends Vulcan { Mockito.when(vulcan.getStudentAndParent()).thenCallRealMethod(); - StudentAndParent vulcanSnP = vulcan.getStudentAndParent(); + SnP vulcanSnP = vulcan.getStudentAndParent(); Assert.assertEquals(snp, vulcanSnP); Assert.assertEquals(vulcanSnP, vulcan.getStudentAndParent()); @@ -93,6 +127,13 @@ public class VulcanTest extends Vulcan { CoreMatchers.instanceOf(AttendanceStatistics.class)); } + @Test + public void getExamsListTest() throws Exception { + Mockito.when(vulcan.getExamsList()).thenCallRealMethod(); + Assert.assertThat(vulcan.getExamsList(), + CoreMatchers.instanceOf(ExamsWeek.class)); + } + @Test public void getGradesListTest() throws Exception { Mockito.when(vulcan.getGradesList()).thenCallRealMethod(); diff --git a/api/src/test/java/io/github/wulkanowy/api/login/LoginTest.java b/api/src/test/java/io/github/wulkanowy/api/login/LoginTest.java index fb5f3d17b..e277ed19c 100644 --- a/api/src/test/java/io/github/wulkanowy/api/login/LoginTest.java +++ b/api/src/test/java/io/github/wulkanowy/api/login/LoginTest.java @@ -108,6 +108,14 @@ public class LoginTest { login.sendCertificate(getFixtureAsString("cert.xml"), "demo123"); } + @Test(expected = VulcanOfflineException.class) + public void sendCertificateVulcanOfflineTest() throws Exception { + Login login = getSetUpLogin("PrzerwaTechniczna.html"); + Mockito.when(login.findSymbol(Mockito.anyString(), Mockito.anyString())).thenCallRealMethod(); + Mockito.when(login.sendCertificate(Mockito.anyString(), Mockito.anyString())).thenCallRealMethod(); + login.sendCertificate(getFixtureAsString("cert.xml"), "demo123"); + } + @Test public void findSymbolInCertificateTest() throws Exception { Login login = new Login(new Cookies()); diff --git a/api/src/test/java/io/github/wulkanowy/api/timetable/TimetableTest.java b/api/src/test/java/io/github/wulkanowy/api/timetable/TimetableTest.java index 2ad08b2b8..ad7411e3b 100644 --- a/api/src/test/java/io/github/wulkanowy/api/timetable/TimetableTest.java +++ b/api/src/test/java/io/github/wulkanowy/api/timetable/TimetableTest.java @@ -90,6 +90,15 @@ public class TimetableTest extends StudentAndParentTestCase { Assert.assertEquals("3", holidays.getWeekTable().getDay(3).getLesson(3).getNumber()); } + @Test + public void getLessonDayTest() throws Exception { + Assert.assertEquals("2017-06-19", std.getWeekTable().getDay(0).getLesson(1).getDate()); + Assert.assertEquals("2017-06-23", std.getWeekTable().getDay(4).getLesson(4).getDate()); + Assert.assertEquals("2017-06-20", full.getWeekTable().getDay(1).getLesson(6).getDate()); + Assert.assertEquals("2017-06-22", full.getWeekTable().getDay(3).getLesson(3).getDate()); + Assert.assertEquals("2017-08-02", holidays.getWeekTable().getDay(2).getLesson(8).getDate()); + } + @Test public void getLessonSubjectTest() throws Exception { Assert.assertEquals("Historia", std.getWeekTable().getDay(0).getLesson(1).getSubject()); diff --git a/api/src/test/resources/io/github/wulkanowy/api/login/PrzerwaTechniczna.html b/api/src/test/resources/io/github/wulkanowy/api/login/PrzerwaTechniczna.html new file mode 100644 index 000000000..062f9b60c --- /dev/null +++ b/api/src/test/resources/io/github/wulkanowy/api/login/PrzerwaTechniczna.html @@ -0,0 +1,23 @@ + + + + + Przerwa techniczna + + + + + + Przerwa techniczna + Aktualnie trwają prace konserwacyjne. Witryna będzie dostępna za kilka minut.> + + + Przejdź do strony głównej + + + 3 + + + + + diff --git a/app/src/androidTest/java/io/github/wulkanowy/services/VulcanSynchronizationTest.java b/app/src/androidTest/java/io/github/wulkanowy/services/VulcanSynchronizationTest.java index afabf30a9..0a92e4ecb 100644 --- a/app/src/androidTest/java/io/github/wulkanowy/services/VulcanSynchronizationTest.java +++ b/app/src/androidTest/java/io/github/wulkanowy/services/VulcanSynchronizationTest.java @@ -2,7 +2,6 @@ package io.github.wulkanowy.services; import android.support.test.runner.AndroidJUnit4; -import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/app/src/androidTest/java/io/github/wulkanowy/services/synchronization/CurrentAccountLoginTest.java b/app/src/androidTest/java/io/github/wulkanowy/services/synchronization/CurrentAccountLoginTest.java index a20db9599..8b45dd6f8 100644 --- a/app/src/androidTest/java/io/github/wulkanowy/services/synchronization/CurrentAccountLoginTest.java +++ b/app/src/androidTest/java/io/github/wulkanowy/services/synchronization/CurrentAccountLoginTest.java @@ -20,6 +20,7 @@ import io.github.wulkanowy.api.Vulcan; import io.github.wulkanowy.api.login.AccountPermissionException; import io.github.wulkanowy.api.login.BadCredentialsException; import io.github.wulkanowy.api.login.LoginErrorException; +import io.github.wulkanowy.api.login.VulcanOfflineException; import io.github.wulkanowy.dao.entities.Account; import io.github.wulkanowy.dao.entities.AccountDao; import io.github.wulkanowy.dao.entities.DaoMaster; @@ -60,7 +61,7 @@ public class CurrentAccountLoginTest { @Test(expected = IOException.class) public void emptyUserIdTest() throws CryptoException, BadCredentialsException, - AccountPermissionException, IOException, LoginErrorException { + AccountPermissionException, IOException, LoginErrorException, VulcanOfflineException { CurrentAccountLogin currentAccountLogin = new CurrentAccountLogin(context, daoSession, new Vulcan()); currentAccountLogin.loginCurrentUser(); @@ -80,7 +81,7 @@ public class CurrentAccountLoginTest { setUserIdSharePreferences(userId); Vulcan vulcan = Mockito.mock(Vulcan.class); - Mockito.doNothing().when(vulcan).login("TEST@TEST", "TEST", "TEST_SYMBOL", "TEST_ID"); + Mockito.when(vulcan.login("TEST@TEST", "TEST", "TEST_SYMBOL", "TEST_ID")).thenReturn(new Vulcan()); CurrentAccountLogin currentAccountLogin = new CurrentAccountLogin(targetContext, daoSession, vulcan); LoginSession loginSession = currentAccountLogin.loginCurrentUser(); diff --git a/app/src/androidTest/java/io/github/wulkanowy/services/synchronization/FirstAccountLoginTest.java b/app/src/androidTest/java/io/github/wulkanowy/services/synchronization/FirstAccountLoginTest.java index 612555d35..958503c35 100644 --- a/app/src/androidTest/java/io/github/wulkanowy/services/synchronization/FirstAccountLoginTest.java +++ b/app/src/androidTest/java/io/github/wulkanowy/services/synchronization/FirstAccountLoginTest.java @@ -14,7 +14,6 @@ import org.mockito.Mockito; import io.github.wulkanowy.api.StudentAndParent; import io.github.wulkanowy.api.Vulcan; -import io.github.wulkanowy.api.login.Login; import io.github.wulkanowy.api.user.BasicInformation; import io.github.wulkanowy.api.user.PersonalData; import io.github.wulkanowy.dao.entities.Account; @@ -49,17 +48,6 @@ public class FirstAccountLoginTest { setUserIdSharePreferences(0); } - @Test - public void connectTest() throws Exception { - String certificate = "Certificate"; - Login login = Mockito.mock(Login.class); - Mockito.when(login.sendCredentials(Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) - .thenReturn(certificate); - FirstAccountLogin firstAccountLogin = new FirstAccountLogin(login, new Vulcan(), "TEST@TEST", "TEST_PASS", "TEST_SYMBOL"); - - Assert.assertEquals(certificate, firstAccountLogin.connect()); - } - @Test public void loginTest() throws Exception { StudentAndParent snp = Mockito.mock(StudentAndParent.class); @@ -76,11 +64,8 @@ public class FirstAccountLoginTest { Mockito.doReturn(basicInformation).when(vulcan).getBasicInformation(); Mockito.doReturn(snp).when(vulcan).getStudentAndParent(); - Login login = Mockito.mock(Login.class); - Mockito.when(login.sendCertificate(Mockito.anyString(), Mockito.anyString())).thenReturn("TEST-SYMBOL"); - - FirstAccountLogin firstAccountLogin = new FirstAccountLogin(login, vulcan, "TEST@TEST", "TEST-PASS", "default"); - LoginSession loginSession = firstAccountLogin.login(targetContext, daoSession, "cert"); + FirstAccountLogin firstAccountLogin = new FirstAccountLogin(targetContext, daoSession, vulcan); + LoginSession loginSession = firstAccountLogin.login("TEST@TEST", "TEST-PASS", "default"); Long userId = targetContext.getSharedPreferences("LoginData", Context.MODE_PRIVATE).getLong("userId", 0); diff --git a/app/src/main/java/io/github/wulkanowy/services/VulcanSynchronization.java b/app/src/main/java/io/github/wulkanowy/services/VulcanSynchronization.java index 07bf5462f..0f66ee282 100644 --- a/app/src/main/java/io/github/wulkanowy/services/VulcanSynchronization.java +++ b/app/src/main/java/io/github/wulkanowy/services/VulcanSynchronization.java @@ -6,13 +6,12 @@ import android.util.Log; import java.io.IOException; -import io.github.wulkanowy.api.Cookies; import io.github.wulkanowy.api.Vulcan; import io.github.wulkanowy.api.login.AccountPermissionException; import io.github.wulkanowy.api.login.BadCredentialsException; -import io.github.wulkanowy.api.login.Login; import io.github.wulkanowy.api.login.LoginErrorException; import io.github.wulkanowy.api.login.NotLoggedInErrorException; +import io.github.wulkanowy.api.login.VulcanOfflineException; import io.github.wulkanowy.dao.entities.DaoSession; import io.github.wulkanowy.security.CryptoException; import io.github.wulkanowy.services.jobs.VulcanJobHelper; @@ -26,10 +25,6 @@ public class VulcanSynchronization { private LoginSession loginSession; - private FirstAccountLogin firstAccountLogin; - - private String certificate; - public VulcanSynchronization(LoginSession loginSession) { this.loginSession = loginSession; } @@ -38,30 +33,21 @@ public class VulcanSynchronization { this.loginSession = new LoginSession(); } - public void firstLoginConnectStep(String email, String password, String symbol) - throws BadCredentialsException, IOException { - firstAccountLogin = new FirstAccountLogin(new Login(new Cookies()), new Vulcan(), email, password, symbol); - certificate = firstAccountLogin.connect(); - } - - public void firstLoginSignInStep(Context context, DaoSession daoSession) - throws NotLoggedInErrorException, AccountPermissionException, IOException, CryptoException { - if (firstAccountLogin != null && certificate != null) { - loginSession = firstAccountLogin.login(context, daoSession, certificate); - } else { - Log.e(VulcanJobHelper.DEBUG_TAG, "Before first login, should call firstLoginConnectStep", - new UnsupportedOperationException()); - } + public void firstLoginSignInStep(Context context, DaoSession daoSession, String email, String password, String symbol) + throws NotLoggedInErrorException, AccountPermissionException, IOException, CryptoException, VulcanOfflineException, BadCredentialsException { + FirstAccountLogin firstAccountLogin = new FirstAccountLogin(context, daoSession, new Vulcan()); + loginSession = firstAccountLogin.login(email, password, symbol); } public VulcanSynchronization loginCurrentUser(Context context, DaoSession daoSession) throws CryptoException, - BadCredentialsException, AccountPermissionException, LoginErrorException, IOException { + BadCredentialsException, AccountPermissionException, LoginErrorException, IOException, VulcanOfflineException { return loginCurrentUser(context, daoSession, new Vulcan()); } public VulcanSynchronization loginCurrentUser(Context context, DaoSession daoSession, Vulcan vulcan) throws CryptoException, BadCredentialsException, AccountPermissionException, - LoginErrorException, IOException { + LoginErrorException, IOException, VulcanOfflineException { + CurrentAccountLogin currentAccountLogin = new CurrentAccountLogin(context, daoSession, vulcan); loginSession = currentAccountLogin.loginCurrentUser(); return this; diff --git a/app/src/main/java/io/github/wulkanowy/services/synchronisation/CurrentAccountLogin.java b/app/src/main/java/io/github/wulkanowy/services/synchronisation/CurrentAccountLogin.java index c3ecd04b8..7ea2c5a98 100644 --- a/app/src/main/java/io/github/wulkanowy/services/synchronisation/CurrentAccountLogin.java +++ b/app/src/main/java/io/github/wulkanowy/services/synchronisation/CurrentAccountLogin.java @@ -9,6 +9,7 @@ import io.github.wulkanowy.api.Vulcan; import io.github.wulkanowy.api.login.AccountPermissionException; import io.github.wulkanowy.api.login.BadCredentialsException; import io.github.wulkanowy.api.login.LoginErrorException; +import io.github.wulkanowy.api.login.VulcanOfflineException; import io.github.wulkanowy.dao.entities.Account; import io.github.wulkanowy.dao.entities.AccountDao; import io.github.wulkanowy.dao.entities.DaoSession; @@ -32,7 +33,7 @@ public class CurrentAccountLogin { } public LoginSession loginCurrentUser() throws CryptoException, - BadCredentialsException, AccountPermissionException, IOException, LoginErrorException { + BadCredentialsException, AccountPermissionException, IOException, LoginErrorException, VulcanOfflineException { AccountDao accountDao = daoSession.getAccountDao(); @@ -44,6 +45,7 @@ public class CurrentAccountLogin { Safety safety = new Safety(); Account account = accountDao.load(userId); + vulcan.login( account.getEmail(), safety.decrypt(account.getEmail(), account.getPassword()), diff --git a/app/src/main/java/io/github/wulkanowy/services/synchronisation/FirstAccountLogin.java b/app/src/main/java/io/github/wulkanowy/services/synchronisation/FirstAccountLogin.java index 9b88de4a7..afae82249 100644 --- a/app/src/main/java/io/github/wulkanowy/services/synchronisation/FirstAccountLogin.java +++ b/app/src/main/java/io/github/wulkanowy/services/synchronisation/FirstAccountLogin.java @@ -8,8 +8,8 @@ import java.io.IOException; import io.github.wulkanowy.api.Vulcan; import io.github.wulkanowy.api.login.AccountPermissionException; import io.github.wulkanowy.api.login.BadCredentialsException; -import io.github.wulkanowy.api.login.Login; import io.github.wulkanowy.api.login.NotLoggedInErrorException; +import io.github.wulkanowy.api.login.VulcanOfflineException; import io.github.wulkanowy.dao.entities.Account; import io.github.wulkanowy.dao.entities.AccountDao; import io.github.wulkanowy.dao.entities.DaoSession; @@ -19,38 +19,22 @@ import io.github.wulkanowy.services.LoginSession; public class FirstAccountLogin { + private final Context context; - private final Login login; + private final DaoSession daoSession; private final Vulcan vulcan; - private final String email; - - private final String password; - - private final String symbol; - - public FirstAccountLogin(Login login, Vulcan vulcan, String email, String password, String symbol) { - this.login = login; + public FirstAccountLogin(Context context, DaoSession daoSession, Vulcan vulcan) { + this.context = context; + this.daoSession = daoSession; this.vulcan = vulcan; - this.email = email; - this.password = password; - this.symbol = symbol; } - public String connect() - throws BadCredentialsException, IOException { - return login.sendCredentials(email, password, symbol); - } + public LoginSession login(String email, String password, String symbol) + throws NotLoggedInErrorException, AccountPermissionException, IOException, CryptoException, VulcanOfflineException, BadCredentialsException { - public LoginSession login(Context context, DaoSession daoSession, String certificate) - throws NotLoggedInErrorException, AccountPermissionException, IOException, CryptoException { - - long userId; - - String realSymbol = login.sendCertificate(certificate, symbol); - - vulcan.login(login.getCookiesObject(), realSymbol); + vulcan.login(email, password, symbol); AccountDao accountDao = daoSession.getAccountDao(); Safety safety = new Safety(); @@ -61,7 +45,7 @@ public class FirstAccountLogin { .setSymbol(vulcan.getStudentAndParent().getSymbol()) .setSnpId(vulcan.getStudentAndParent().getId()); - userId = accountDao.insert(account); + long userId = accountDao.insert(account); SharedPreferences sharedPreferences = context.getSharedPreferences("LoginData", Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedPreferences.edit(); diff --git a/app/src/main/java/io/github/wulkanowy/ui/login/LoginActivity.java b/app/src/main/java/io/github/wulkanowy/ui/login/LoginActivity.java index 05df7d23c..c6b941dc0 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/login/LoginActivity.java +++ b/app/src/main/java/io/github/wulkanowy/ui/login/LoginActivity.java @@ -171,11 +171,11 @@ public class LoginActivity extends Activity { } private boolean isEmailValid(String email) { - return email.contains("@"); + return email.contains("@") || email.contains("\\\\"); } private boolean isPasswordValid(String password) { - return password.length() > 7; + return password.length() > 4; } private void hideSoftKeyboard() { diff --git a/app/src/main/java/io/github/wulkanowy/ui/login/LoginTask.java b/app/src/main/java/io/github/wulkanowy/ui/login/LoginTask.java index dc51516bc..7066d2528 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/login/LoginTask.java +++ b/app/src/main/java/io/github/wulkanowy/ui/login/LoginTask.java @@ -24,6 +24,7 @@ import io.github.wulkanowy.R; import io.github.wulkanowy.api.login.AccountPermissionException; import io.github.wulkanowy.api.login.BadCredentialsException; import io.github.wulkanowy.api.login.NotLoggedInErrorException; +import io.github.wulkanowy.api.login.VulcanOfflineException; import io.github.wulkanowy.dao.entities.DaoSession; import io.github.wulkanowy.security.CryptoException; import io.github.wulkanowy.services.LoginSession; @@ -68,20 +69,15 @@ public class LoginTask extends AsyncTask { @Override protected Integer doInBackground(Void... params) { if (ConnectionUtilities.isOnline(activity.get())) { + DaoSession daoSession = ((WulkanowyApp) activity.get().getApplication()).getDaoSession(); VulcanSynchronization vulcanSynchronization = new VulcanSynchronization(new LoginSession()); - DaoSession daoSession = ((WulkanowyApp) activity.get().getApplication()).getDaoSession(); - try { - publishProgress("1", activity.get().getResources().getString(R.string.step_connecting)); - vulcanSynchronization.firstLoginConnectStep(email, password, symbol); + publishProgress("1", activity.get().getResources().getString(R.string.step_login)); + vulcanSynchronization.firstLoginSignInStep(activity.get(), daoSession, email, password, symbol); - publishProgress("2", activity.get().getResources().getString(R.string.step_login)); - vulcanSynchronization.firstLoginSignInStep(activity.get(), daoSession); - - publishProgress("3", activity.get().getResources().getString(R.string.step_synchronization)); + publishProgress("2", activity.get().getResources().getString(R.string.step_synchronization)); vulcanSynchronization.syncAll(); - } catch (BadCredentialsException e) { return R.string.login_bad_credentials_text; } catch (AccountPermissionException e) { @@ -94,6 +90,8 @@ public class LoginTask extends AsyncTask { return R.string.generic_timeout_error; } catch (NotLoggedInErrorException | IOException e) { return R.string.login_denied_text; + } catch (VulcanOfflineException e) { + return R.string.error_host_offline; } catch (UnsupportedOperationException e) { return -1; } @@ -109,7 +107,7 @@ public class LoginTask extends AsyncTask { @Override protected void onProgressUpdate(String... progress) { - showText.get().setText(String.format("%1$s/3 - %2$s...", progress[0], progress[1])); + showText.get().setText(String.format("%1$s/2 - %2$s...", progress[0], progress[1])); } @Override diff --git a/app/src/main/java/io/github/wulkanowy/ui/main/RefreshTask.java b/app/src/main/java/io/github/wulkanowy/ui/main/RefreshTask.java index 46e661dd8..5ea01d65c 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/main/RefreshTask.java +++ b/app/src/main/java/io/github/wulkanowy/ui/main/RefreshTask.java @@ -3,12 +3,12 @@ package io.github.wulkanowy.ui.main; import android.os.AsyncTask; import android.util.Log; -import java.io.IOException; import java.net.SocketTimeoutException; import java.net.UnknownHostException; import java.util.List; import io.github.wulkanowy.R; +import io.github.wulkanowy.api.login.VulcanOfflineException; public class RefreshTask extends AsyncTask> { @@ -30,12 +30,16 @@ public class RefreshTask extends AsyncTask> { } catch (UnknownHostException e) { stringEventId = R.string.noInternet_text; Log.i(DEBUG_TAG, "Synchronization is failed because occur problem with internet", - new IOException()); + e.getCause()); return null; } catch (SocketTimeoutException e) { stringEventId = R.string.generic_timeout_error; Log.i(DEBUG_TAG, "Too long wait for connection with internet", e); return null; + } catch (VulcanOfflineException e) { + stringEventId = R.string.error_host_offline; + Log.i(DEBUG_TAG, "VULCAN services is offline"); + return null; } catch (Exception e) { stringEventId = R.string.refresh_error_text; Log.e(DEBUG_TAG, "There was a synchronization problem", e); diff --git a/app/src/main/java/io/github/wulkanowy/ui/main/grades/GradesFragment.java b/app/src/main/java/io/github/wulkanowy/ui/main/grades/GradesFragment.java index 4117ae1fa..985002f5f 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/main/grades/GradesFragment.java +++ b/app/src/main/java/io/github/wulkanowy/ui/main/grades/GradesFragment.java @@ -22,6 +22,7 @@ import java.util.List; import io.github.wulkanowy.R; import io.github.wulkanowy.api.Vulcan; +import io.github.wulkanowy.api.login.VulcanOfflineException; import io.github.wulkanowy.dao.DatabaseAccess; import io.github.wulkanowy.dao.entities.Account; import io.github.wulkanowy.dao.entities.AccountDao; @@ -146,7 +147,7 @@ public class GradesFragment extends Fragment { } } - private static class RefreshTask extends AsyncTask { + private static class RefreshTask extends AsyncTask { private DaoSession daoSession; @@ -161,24 +162,27 @@ public class GradesFragment extends Fragment { } @Override - protected Boolean doInBackground(Void... params) { + protected Integer doInBackground(Void... params) { VulcanSynchronization vulcanSynchronization = new VulcanSynchronization(new LoginSession()); try { vulcanSynchronization.loginCurrentUser(activity.get(), daoSession, new Vulcan()); vulcanSynchronization.syncGrades(); downloadGradesFormDatabase(daoSession); - return true; + return 1; + } catch (VulcanOfflineException e) { + Log.e(VulcanJobHelper.DEBUG_TAG, "There was a synchronization problem, because vulcan is offline", e); + return R.string.error_host_offline; } catch (Exception e) { Log.e(VulcanJobHelper.DEBUG_TAG, "There was a synchronization problem", e); - return false; + return R.string.refresh_error_text; } } @Override - protected void onPostExecute(Boolean result) { - super.onPostExecute(result); + protected void onPostExecute(Integer messageID) { + super.onPostExecute(messageID); - if (result) { + if (1 == messageID) { if (mainView.get() != null && activity.get() != null) { createExpList(mainView.get(), activity.get()); } @@ -195,7 +199,7 @@ public class GradesFragment extends Fragment { Snackbar.LENGTH_SHORT).show(); } } else { - Toast.makeText(activity.get(), R.string.refresh_error_text, Toast.LENGTH_SHORT).show(); + Toast.makeText(activity.get(), messageID, Toast.LENGTH_SHORT).show(); } if (mainView.get() != null) { diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index 3d7951eab..1d05451ea 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -39,6 +39,7 @@ Brak ocen Brak połączenia z internetem + Przerwa techniczna. Spróbuj ponownie później Szyfrowanie nie powiodło się. Automatyczne logowanie zostało wyłączone Wersja %1$s "Podczas odświeżania zawartości wystąpił błąd. " diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 193f90d4b..f79e15a3e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -72,6 +72,7 @@ Average: %1$.2f No average + Technical break Room %s
Aktualnie trwają prace konserwacyjne. Witryna będzie dostępna za kilka minut.
3