-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from MathieuSoysal/road-to-v2
Road to v2
- Loading branch information
Showing
86 changed files
with
754 additions
and
711 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/main/java/io/github/mathieusoysal/archivers/ArchivedResidences.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package io.github.mathieusoysal.archivers; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
import io.github.mathieusoysal.data.managment.collectors.DataCollectorFromArchive; | ||
import io.github.mathieusoysal.residence.Residence; | ||
|
||
class ArchivedResidences { | ||
|
||
private Map<Integer, Residence> residences; | ||
|
||
public ArchivedResidences(Set<Residence> residences) { | ||
this.residences = residences | ||
.stream() | ||
.collect(Collectors.toMap(Residence::getId, residence -> residence)); | ||
} | ||
|
||
public ArchivedResidences() { | ||
this.residences = new HashMap<>(); | ||
} | ||
|
||
public static ArchivedResidences generateArchivedResidencesFromLinkArchive(final String linkToArchive) { | ||
var dataCollector = new DataCollectorFromArchive(linkToArchive); | ||
var residences = new ArchivedResidences(); | ||
residences.addResidences(dataCollector.getAllResidences()); | ||
return residences; | ||
} | ||
|
||
public void addResidence(Residence residence) { | ||
if (!residences.containsKey(residence.getId())) | ||
residences.put(residence.getId(), residence); | ||
else { | ||
Residence existingResidence = residences.get(residence.getId()); | ||
existingResidence.addResidence(residence); | ||
} | ||
} | ||
|
||
public void addResidences(Collection<Residence> residences) { | ||
residences.forEach(this::addResidence); | ||
} | ||
|
||
public void addResidences(Residence[][] residences) { | ||
for (Residence[] residences2 : residences) | ||
for (Residence residence : residences2) | ||
addResidence(residence); | ||
} | ||
|
||
public List<Residence> getResidences() { | ||
return new ArrayList<>(residences.values()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 6 additions & 4 deletions
10
src/main/java/io/github/mathieusoysal/archivers/ArchiverDay.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,20 @@ | ||
package io.github.mathieusoysal.archivers; | ||
|
||
import io.github.mathieusoysal.data.managment.collectors.DataCollectorFromArchive; | ||
import io.github.mathieusoysal.data.managment.convertors.Convertor; | ||
import io.github.mathieusoysal.data.managment.savers.ArchiveName; | ||
|
||
public class ArchiverDay implements Archiver { | ||
class ArchiverDay implements Archiver { | ||
|
||
@Override | ||
public void archive() { | ||
var dataCollector = new DataCollectorFromArchive(Archiver.getLinkToArchive()); | ||
var sumUpOfTheDay = dataCollector.getSumUpOfDay(Archiver.getDayToArchive()); | ||
var sumUpOfTheDay = dataCollector.getConvertedSumUpOfDay(Archiver.getDayToArchive()); | ||
String sumUpOfTheDayAsString = Convertor.convertIdMatrixToJson(sumUpOfTheDay); | ||
ARCHIVE_SAVER | ||
.addPath("available") | ||
.addPath("available-residences-id") | ||
.addPath(Archiver.getDayToArchive()) | ||
.endPathAndSaveData(ArchiveName.DAY_SUM_UP, sumUpOfTheDay); | ||
.endPathAndSaveData(ArchiveName.DAY_SUM_UP, sumUpOfTheDayAsString); | ||
} | ||
|
||
} |
17 changes: 13 additions & 4 deletions
17
src/main/java/io/github/mathieusoysal/archivers/ArchiverHour.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,30 @@ | ||
package io.github.mathieusoysal.archivers; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
import io.github.mathieusoysal.Properties; | ||
import io.github.mathieusoysal.data.managment.collectors.DataCollectorFromCrous; | ||
import io.github.mathieusoysal.data.managment.savers.ArchiveName; | ||
import io.github.mathieusoysal.residence.Residence; | ||
|
||
public class ArchiverHour implements Archiver { | ||
class ArchiverHour implements Archiver { | ||
|
||
@Override | ||
public void archive() { | ||
var logements = DataCollectorFromCrous.getAvailableLogementsWithConnection(Properties.MAIL.getValue(), | ||
var residences = archiveHour(); | ||
ArchiverAllResidences.updateArchiveOfAllResidences(residences); | ||
} | ||
|
||
private List<Residence> archiveHour() { | ||
var residences = DataCollectorFromCrous.getAvailableResidencesWithConnection(Properties.MAIL.getValue(), | ||
Properties.PASSWORD.getValue()); | ||
var ids = residences.stream().map(Residence::getId).toList(); | ||
ARCHIVE_SAVER | ||
.addPath("available") | ||
.addPath("available-residences-id") | ||
.addPath(LocalDate.now()) | ||
.endPathAndSaveData(ArchiveName.HOUR, logements); | ||
.endPathAndSaveData(ArchiveName.HOUR, ids); | ||
return residences; | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/io/github/mathieusoysal/archivers/Archivers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package io.github.mathieusoysal.archivers; | ||
|
||
public enum Archivers implements Archiver { | ||
ARCHIVER_DAY(new ArchiverDay()), | ||
ARCHIVER_HOUR(new ArchiverHour()); | ||
|
||
private Archiver archiver; | ||
|
||
Archivers(Archiver archiver) { | ||
this.archiver = archiver; | ||
} | ||
|
||
@Override | ||
public void archive() { | ||
archiver.archive(); | ||
} | ||
|
||
} |
Oops, something went wrong.