Skip to content

Commit

Permalink
Merge branch 'release/0.5.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
micheljung committed May 11, 2017
2 parents 4b59e0e + 286c5dd commit 6fd3123
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ apply plugin: 'org.springframework.boot'
apply plugin: 'propdeps'

group = 'micheljung'
version = '0.5.4'
version = '0.5.5'

sourceCompatibility = 1.8
targetCompatibility = 1.8
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/faforever/api/mod/ModRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Optional;

@Repository
@Transactional(propagation = Propagation.MANDATORY)
public interface ModRepository extends JpaRepository<Mod, Integer> {
Expand All @@ -30,4 +32,6 @@ public interface ModRepository extends JpaRepository<Mod, Integer> {
"AND NOT EXISTS (SELECT mod_id FROM mod_stats WHERE mod_id = id)", nativeQuery = true)
@Modifying
void insertModStats(@Param("displayName") String displayName);

Optional<Mod> findOneByDisplayName(String name);
}
29 changes: 14 additions & 15 deletions src/main/java/com/faforever/api/mod/ModService.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ public void processUploadedMod(Path uploadedFile, Player uploader) {

private boolean modExists(String displayName, short version) {
ModVersion probe = new ModVersion()
.setVersion(version)
.setMod(new Mod()
.setDisplayName(displayName)
);
.setVersion(version)
.setMod(new Mod()
.setDisplayName(displayName)
);
return modVersionRepository.exists(Example.of(probe, ExampleMatcher.matching().withIgnoreCase()));
}

Expand Down Expand Up @@ -172,9 +172,9 @@ private String generateFolderName(String displayName, short version) {

private String generateFileName(String displayName) {
return Normalizer.normalize(displayName.toLowerCase(Locale.US)
.replace("..", ".")
.replaceAll("[/\\\\ ]", "_"),
Form.NFKC);
.replace("..", ".")
.replaceAll("[/\\\\ ]", "_"),
Form.NFKC);
}

private void store(com.faforever.commons.mod.Mod modInfo, Optional<Path> thumbnailPath, Player uploader, String zipFileName) {
Expand All @@ -186,14 +186,13 @@ private void store(com.faforever.commons.mod.Mod modInfo, Optional<Path> thumbna
.setFilename(MOD_PATH_PREFIX + zipFileName)
.setIcon(thumbnailPath.map(path -> path.getFileName().toString()).orElse(null));

List<ModVersion> modVersions = new ArrayList<>();
modVersions.add(modVersion);

Mod mod = new Mod()
.setAuthor(modInfo.getAuthor())
.setDisplayName(modInfo.getName())
.setVersions(modVersions)
.setUploader(uploader);
Mod mod = modRepository.findOneByDisplayName(modInfo.getName())
.orElse(new Mod()
.setAuthor(modInfo.getAuthor())
.setDisplayName(modInfo.getName())
.setVersions(new ArrayList<>())
.setUploader(uploader));
mod.getVersions().add(modVersion);

modVersion.setMod(mod);

Expand Down

0 comments on commit 6fd3123

Please sign in to comment.