This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 57
/
TranslationUpdatedManager.java
68 lines (59 loc) · 2.37 KB
/
TranslationUpdatedManager.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package org.zanata.service.impl;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Observer;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.core.Events;
import org.zanata.dao.TextFlowDAO;
import org.zanata.events.DocumentStatisticUpdatedEvent;
import org.zanata.events.TextFlowTargetStateEvent;
import org.zanata.service.TranslationStateCache;
import com.google.common.annotations.VisibleForTesting;
import lombok.extern.slf4j.Slf4j;
/**
* Manager that handles post update of translation. Important:
* TextFlowTargetStateEvent IS NOT asynchronous, that is why
* DocumentStatisticUpdatedEvent is used for webhook processes. See
* {@link org.zanata.events.TextFlowTargetStateEvent} See
* {@link org.zanata.events.DocumentStatisticUpdatedEvent}
*
* @author Alex Eng <a href="mailto:aeng@redhat.com">aeng@redhat.com</a>
*/
@Name("translationUpdatedManager")
@Scope(ScopeType.STATELESS)
@Slf4j
public class TranslationUpdatedManager {
@In
private TranslationStateCache translationStateCacheImpl;
@In
private TextFlowDAO textFlowDAO;
/**
* This method contains all logic to be run immediately after a Text Flow
* Target has been successfully translated.
*/
@Observer(TextFlowTargetStateEvent.EVENT_NAME)
public void textFlowStateUpdated(TextFlowTargetStateEvent event) {
translationStateCacheImpl.textFlowStateUpdated(event);
publishAsyncEvent(event);
}
// Fire asynchronous event
public void publishAsyncEvent(TextFlowTargetStateEvent event) {
if (Events.exists()) {
int wordCount = textFlowDAO.getWordCount(event.getTextFlowId());
Events.instance().raiseAsynchronousEvent(
DocumentStatisticUpdatedEvent.EVENT_NAME,
new DocumentStatisticUpdatedEvent(
event.getProjectIterationId(),
event.getDocumentId(), event.getLocaleId(),
wordCount,
event.getPreviousState(), event.getNewState()));
}
}
@VisibleForTesting
public void init(TranslationStateCache translationStateCacheImpl,
TextFlowDAO textFlowDAO) {
this.translationStateCacheImpl = translationStateCacheImpl;
this.textFlowDAO = textFlowDAO;
}
}