-
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.
- Loading branch information
Showing
7 changed files
with
122 additions
and
21 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
56 changes: 56 additions & 0 deletions
56
...c/main/java/sunflower/server/application/eventlistener/BrailleTranslateEventListener.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,56 @@ | ||
package sunflower.server.application.eventlistener; | ||
|
||
import lombok.NoArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.ApplicationEventPublisher; | ||
import org.springframework.scheduling.annotation.Async; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.springframework.transaction.event.TransactionalEventListener; | ||
import sunflower.server.application.event.BrailleTranslateEvent; | ||
import sunflower.server.client.ApiBrailleTranslationClient; | ||
import sunflower.server.entity.Translations; | ||
import sunflower.server.repository.TranslationsRepository; | ||
|
||
import java.io.File; | ||
import java.nio.file.Paths; | ||
|
||
import static org.springframework.transaction.annotation.Propagation.REQUIRES_NEW; | ||
|
||
@Slf4j | ||
@NoArgsConstructor | ||
@Component | ||
public class BrailleTranslateEventListener { | ||
|
||
private TranslationsRepository translationsRepository; | ||
private ApiBrailleTranslationClient apiBrailleTranslationClient; | ||
private ApplicationEventPublisher eventPublisher; | ||
|
||
@Autowired | ||
public BrailleTranslateEventListener( | ||
final TranslationsRepository translationsRepository, | ||
final ApiBrailleTranslationClient apiBrailleTranslationClient, | ||
final ApplicationEventPublisher eventPublisher | ||
) { | ||
this.translationsRepository = translationsRepository; | ||
this.apiBrailleTranslationClient = apiBrailleTranslationClient; | ||
this.eventPublisher = eventPublisher; | ||
} | ||
|
||
@Async | ||
@TransactionalEventListener | ||
@Transactional(propagation = REQUIRES_NEW) | ||
public void downloadLatexFile(final BrailleTranslateEvent event) { | ||
final Translations translations = translationsRepository.getById(event.getId()); | ||
|
||
final String latexPath = translations.getLatexPath(); | ||
final File latexFile = Paths.get(latexPath).toFile(); | ||
|
||
if (!latexFile.exists()) { | ||
throw new RuntimeException("파일이 존재하지 않습니다!"); | ||
} | ||
|
||
final File brfFile = apiBrailleTranslationClient.translate(latexFile); | ||
} | ||
} |
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
4 changes: 3 additions & 1 deletion
4
server/src/main/java/sunflower/server/client/BrailleTranslationClient.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,8 +1,10 @@ | ||
package sunflower.server.client; | ||
|
||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
|
||
public interface BrailleTranslationClient { | ||
|
||
File translate(final Long id); | ||
File translate(File file) throws IOException; | ||
} |
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