-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* upgrades gradle upgrades spring security upgrades SecurityConfig fixes docker image in compose to run on latest mysql * upgrade Spring * fixes integration tests * optimize imports * fixes LOB mapping to tinytext * Atomic Writer * fixes integration tests * fixes owasp * Update README.md
- Loading branch information
Showing
46 changed files
with
592 additions
and
241 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
69 changes: 69 additions & 0 deletions
69
src/integration/java/it/gov/innovazione/ndc/integration/InMemoryInstanceManager.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,69 @@ | ||
package it.gov.innovazione.ndc.integration; | ||
|
||
import it.gov.innovazione.ndc.harvester.model.Instance; | ||
import it.gov.innovazione.ndc.model.harvester.Repository; | ||
import it.gov.innovazione.ndc.service.InstanceManager; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.Primary; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
@Service | ||
@Primary | ||
@RequiredArgsConstructor | ||
public class InMemoryInstanceManager implements InstanceManager { | ||
|
||
private final Map<String, Instance> instances = new HashMap<>(); | ||
|
||
private Instance allInstances = Instance.PRIMARY; | ||
|
||
public void setAllInstances(Instance allInstances) { | ||
this.allInstances = allInstances; | ||
instances.replaceAll((k, v) -> allInstances); | ||
} | ||
|
||
@Override | ||
public Instance getNextOnlineInstance(String repoUrl) { | ||
if (instances.containsKey(repoUrl)) { | ||
return instances.get(repoUrl).switchInstance(); | ||
} | ||
Repository fakeRepo = Repository.builder() | ||
.url(repoUrl) | ||
.build(); | ||
return getCurrentInstance(fakeRepo).switchInstance(); | ||
} | ||
|
||
@Override | ||
public Instance getNextOnlineInstance(Repository repository) { | ||
return getCurrentInstance(repository).switchInstance(); | ||
} | ||
|
||
@Override | ||
public Instance getCurrentInstance(Repository repository) { | ||
if (!instances.containsKey(repository.getUrl())) { | ||
instances.put(repository.getUrl(), allInstances); | ||
} | ||
return instances.get(repository.getUrl()); | ||
} | ||
|
||
@Override | ||
public void switchInstances(Repository repository) { | ||
Instance toPut = getCurrentInstance(repository).switchInstance(); | ||
instances.put(repository.getUrl(), toPut); | ||
} | ||
|
||
@Override | ||
public List<RepositoryInstance> getCurrentInstances() { | ||
return instances.entrySet().stream() | ||
.map(entry -> RepositoryInstance.of(entry.getKey(), entry.getValue())) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
public void switchAllInstances() { | ||
instances.replaceAll((k, v) -> v.switchInstance()); | ||
} | ||
} |
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 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 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
Oops, something went wrong.