Skip to content

Commit 268c0bf

Browse files
add minify version of server
1 parent f2a61d5 commit 268c0bf

27 files changed

+1813
-70
lines changed

api/pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,18 @@
6868
<groupId>org.jboss.resteasy</groupId>
6969
<artifactId>resteasy-multipart-provider</artifactId>
7070
</dependency>
71+
<dependency>
72+
<groupId>io.quarkus</groupId>
73+
<artifactId>quarkus-rest-client</artifactId>
74+
</dependency>
7175
<dependency>
7276
<groupId>io.quarkus</groupId>
7377
<artifactId>quarkus-artemis-jms</artifactId>
7478
</dependency>
79+
<dependency>
80+
<groupId>io.quarkus</groupId>
81+
<artifactId>quarkus-quartz</artifactId>
82+
</dependency>
7583

7684
<!--Camel-->
7785
<dependency>
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/**
2+
* Copyright 2019 Project OpenUBL, Inc. and/or its affiliates
3+
* and other contributors as indicated by the @author tags.
4+
*
5+
* Licensed under the Eclipse Public License - v 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* https://www.eclipse.org/legal/epl-2.0/
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package io.github.project.openubl.xmlsender.bootstrap;
18+
19+
import io.github.project.openubl.xmlsender.events.EventProvider;
20+
import io.github.project.openubl.xmlsender.models.jpa.DocumentRepository;
21+
import io.github.project.openubl.xmlsender.models.jpa.entities.DocumentEntity;
22+
import io.github.project.openubl.xmlsender.ws.WSSunatClient;
23+
import io.quarkus.arc.Arc;
24+
import io.quarkus.runtime.StartupEvent;
25+
import io.quarkus.scheduler.Scheduled;
26+
import org.eclipse.microprofile.config.inject.ConfigProperty;
27+
import org.quartz.*;
28+
29+
import javax.enterprise.context.ApplicationScoped;
30+
import javax.enterprise.event.Observes;
31+
import javax.inject.Inject;
32+
import javax.transaction.Transactional;
33+
import java.util.List;
34+
35+
@ApplicationScoped
36+
public class JobsBootstrap {
37+
38+
@ConfigProperty(name = "openubl.event-manager")
39+
EventProvider.Type eventManager;
40+
41+
@ConfigProperty(name = "openubl.event-manager.basic.retry-delay")
42+
Long retryDelay;
43+
44+
@Inject
45+
Scheduler quartz;
46+
47+
@Inject
48+
DocumentRepository documentRepository;
49+
50+
@Inject
51+
WSSunatClient wsSunatClient;
52+
53+
void onStart(@Observes StartupEvent ev) throws SchedulerException {
54+
if (eventManager.equals(EventProvider.Type.basic)) {
55+
JobDetail job = JobBuilder.newJob(RetryJob.class)
56+
.withIdentity("retryJob", "retryGroup")
57+
.build();
58+
Trigger trigger = TriggerBuilder.newTrigger()
59+
.withIdentity("retryJob", "retryGroup")
60+
.startNow()
61+
.withSchedule(
62+
SimpleScheduleBuilder.simpleSchedule()
63+
.withIntervalInMilliseconds(retryDelay)
64+
.repeatForever())
65+
.build();
66+
quartz.scheduleJob(job, trigger);
67+
}
68+
}
69+
70+
71+
// Just to force Quartz to start
72+
@Scheduled(cron = "0 0 0 * * ?")
73+
void schedule() {
74+
75+
}
76+
77+
@Transactional
78+
void performTask() {
79+
// Resend documents
80+
List<DocumentEntity> documentScheduled = documentRepository.findDocumentScheduled();
81+
for (DocumentEntity documentEntity : documentScheduled) {
82+
wsSunatClient.sendDocument(documentEntity.id);
83+
}
84+
85+
// Resend tickets
86+
List<DocumentEntity> documentsWithUncheckedTickets = documentRepository.findTickedCheckScheduled();
87+
88+
for (DocumentEntity documentEntity : documentsWithUncheckedTickets) {
89+
wsSunatClient.checkDocumentTicket(documentEntity.id);
90+
}
91+
}
92+
93+
public static class RetryJob implements Job {
94+
@Override
95+
public void execute(JobExecutionContext context) throws JobExecutionException {
96+
Arc.container().instance(JobsBootstrap.class).get().performTask();
97+
}
98+
}
99+
100+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/**
2+
* Copyright 2019 Project OpenUBL, Inc. and/or its affiliates
3+
* and other contributors as indicated by the @author tags.
4+
*
5+
* Licensed under the Eclipse Public License - v 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* https://www.eclipse.org/legal/epl-2.0/
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package io.github.project.openubl.xmlsender.events;
18+
19+
import io.github.project.openubl.xmlsender.events.jms.SendTicketQueueConsumer;
20+
import io.github.project.openubl.xmlsender.idm.DocumentRepresentation;
21+
import io.github.project.openubl.xmlsender.models.DocumentEvent;
22+
import io.github.project.openubl.xmlsender.models.jpa.DocumentRepository;
23+
import io.github.project.openubl.xmlsender.models.jpa.entities.DocumentEntity;
24+
import io.github.project.openubl.xmlsender.models.utils.EntityToRepresentation;
25+
import io.github.project.openubl.xmlsender.resources.client.CallbackClientService;
26+
import io.github.project.openubl.xmlsender.ws.WSSunatClient;
27+
import org.eclipse.microprofile.rest.client.inject.RestClient;
28+
import org.jboss.logging.Logger;
29+
30+
import javax.enterprise.context.ApplicationScoped;
31+
import javax.enterprise.event.Observes;
32+
import javax.enterprise.event.TransactionPhase;
33+
import javax.inject.Inject;
34+
import javax.transaction.Transactional;
35+
import javax.ws.rs.WebApplicationException;
36+
37+
@ApplicationScoped
38+
public class BasicEventManager {
39+
40+
private static final Logger LOG = Logger.getLogger(BasicEventManager.class);
41+
42+
@Inject
43+
WSSunatClient wsSunatClient;
44+
45+
@Inject
46+
@RestClient
47+
CallbackClientService callbackClientService;
48+
49+
@Inject
50+
DocumentRepository documentRepository;
51+
52+
public void onDocumentCreate(
53+
@Observes(during = TransactionPhase.AFTER_SUCCESS)
54+
@EventProvider(EventProvider.Type.basic) DocumentEvent.Created event
55+
) {
56+
wsSunatClient.sendDocument(event.getId());
57+
}
58+
59+
public void onDocumentRequireCheckTicket(
60+
@Observes(during = TransactionPhase.AFTER_SUCCESS)
61+
@EventProvider(EventProvider.Type.basic) DocumentEvent.RequireCheckTicket event
62+
) {
63+
wsSunatClient.checkDocumentTicket(event.getId());
64+
}
65+
66+
@Transactional
67+
public void onDocumentDelivered(
68+
@Observes(during = TransactionPhase.AFTER_SUCCESS)
69+
@EventProvider(EventProvider.Type.basic) DocumentEvent.Delivered event
70+
) {
71+
DocumentEntity documentEntity = documentRepository.findById(event.getId());
72+
DocumentRepresentation rep = EntityToRepresentation.toRepresentation(documentEntity);
73+
try {
74+
callbackClientService.callback(rep);
75+
} catch (WebApplicationException e) {
76+
LOG.error("Could not send webhook callback, message=" + e.getMessage());
77+
}
78+
}
79+
80+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Copyright 2019 Project OpenUBL, Inc. and/or its affiliates
3+
* and other contributors as indicated by the @author tags.
4+
*
5+
* Licensed under the Eclipse Public License - v 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* https://www.eclipse.org/legal/epl-2.0/
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package io.github.project.openubl.xmlsender.events;
18+
19+
import javax.inject.Qualifier;
20+
import java.lang.annotation.ElementType;
21+
import java.lang.annotation.Retention;
22+
import java.lang.annotation.RetentionPolicy;
23+
import java.lang.annotation.Target;
24+
25+
@Qualifier
26+
@Retention(RetentionPolicy.RUNTIME)
27+
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE})
28+
public @interface EventProvider {
29+
30+
Type value();
31+
32+
enum Type {
33+
basic,
34+
jms
35+
}
36+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* Copyright 2019 Project OpenUBL, Inc. and/or its affiliates
3+
* and other contributors as indicated by the @author tags.
4+
*
5+
* Licensed under the Eclipse Public License - v 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* https://www.eclipse.org/legal/epl-2.0/
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package io.github.project.openubl.xmlsender.events;
18+
19+
import javax.enterprise.util.AnnotationLiteral;
20+
import javax.inject.Qualifier;
21+
import java.lang.annotation.ElementType;
22+
import java.lang.annotation.Retention;
23+
import java.lang.annotation.RetentionPolicy;
24+
import java.lang.annotation.Target;
25+
26+
public class EventProviderLiteral extends AnnotationLiteral<EventProvider> implements EventProvider {
27+
28+
private final EventProvider.Type type;
29+
30+
public EventProviderLiteral(EventProvider.Type type) {
31+
this.type = type;
32+
}
33+
34+
@Override
35+
public Type value() {
36+
return type;
37+
}
38+
}

api/src/main/java/io/github/project/openubl/xmlsender/managers/EventsManager.java renamed to api/src/main/java/io/github/project/openubl/xmlsender/events/JMSEventManager.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
package io.github.project.openubl.xmlsender.managers;
17+
package io.github.project.openubl.xmlsender.events;
1818

1919
import io.github.project.openubl.xmlsender.models.DocumentEvent;
2020
import org.eclipse.microprofile.config.inject.ConfigProperty;
@@ -26,32 +26,41 @@
2626
import javax.jms.*;
2727

2828
@ApplicationScoped
29-
public class EventsManager {
29+
public class JMSEventManager {
3030

31-
@ConfigProperty(name = "openubl.jms.delay")
31+
@ConfigProperty(name = "openubl.event-manager.jms.delay")
3232
Long messageDelay;
3333

34-
@ConfigProperty(name = "openubl.jms.sendFileQueue")
34+
@ConfigProperty(name = "openubl.event-manager.jms.sendFileQueue")
3535
String sendFileQueue;
3636

37-
@ConfigProperty(name = "openubl.jms.callbackQueue")
37+
@ConfigProperty(name = "openubl.event-manager.jms.callbackQueue")
3838
String callbackQueue;
3939

40-
@ConfigProperty(name = "openubl.jms.ticketQueue")
40+
@ConfigProperty(name = "openubl.event-manager.jms.ticketQueue")
4141
String ticketQueue;
4242

4343
@Inject
4444
ConnectionFactory connectionFactory;
4545

46-
public void onDocumentCreate(@Observes(during = TransactionPhase.AFTER_SUCCESS) DocumentEvent.Created event) {
46+
public void onDocumentCreate(
47+
@Observes(during = TransactionPhase.AFTER_SUCCESS)
48+
@EventProvider(EventProvider.Type.jms) DocumentEvent.Created event
49+
) {
4750
produceMessage(sendFileQueue, event.getId());
4851
}
4952

50-
public void onDocumentRequireCheckTicket(@Observes(during = TransactionPhase.AFTER_SUCCESS) DocumentEvent.RequireCheckTicket event) {
53+
public void onDocumentRequireCheckTicket(
54+
@Observes(during = TransactionPhase.AFTER_SUCCESS)
55+
@EventProvider(EventProvider.Type.jms) DocumentEvent.RequireCheckTicket event
56+
) {
5157
produceMessage(ticketQueue, event.getId());
5258
}
5359

54-
public void onDocumentDelivered(@Observes(during = TransactionPhase.AFTER_SUCCESS) DocumentEvent.Delivered event) {
60+
public void onDocumentDelivered(
61+
@Observes(during = TransactionPhase.AFTER_SUCCESS)
62+
@EventProvider(EventProvider.Type.jms) DocumentEvent.Delivered event
63+
) {
5564
produceMessage(callbackQueue, event.getId());
5665
}
5766

api/src/main/java/io/github/project/openubl/xmlsender/jms/SendFileQueueConsumer.java renamed to api/src/main/java/io/github/project/openubl/xmlsender/events/jms/SendFileQueueConsumer.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
package io.github.project.openubl.xmlsender.jms;
17+
package io.github.project.openubl.xmlsender.events.jms;
1818

19+
import io.github.project.openubl.xmlsender.events.EventProvider;
1920
import io.quarkus.runtime.ShutdownEvent;
2021
import io.quarkus.runtime.StartupEvent;
2122
import org.eclipse.microprofile.config.inject.ConfigProperty;
@@ -35,23 +36,32 @@ public class SendFileQueueConsumer implements Runnable {
3536

3637
private static final Logger LOG = Logger.getLogger(SendFileQueueConsumer.class);
3738

39+
@ConfigProperty(name = "openubl.event-manager")
40+
EventProvider.Type eventManager;
41+
3842
@Inject
3943
WSSunatClient wsSunatClient;
4044

4145
@Inject
4246
ConnectionFactory connectionFactory;
4347

44-
@ConfigProperty(name = "openubl.jms.sendFileQueue")
48+
@ConfigProperty(name = "openubl.event-manager.jms.sendFileQueue")
4549
String sendFileQueue;
4650

4751
private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
4852

4953
void onStart(@Observes StartupEvent ev) {
50-
scheduler.scheduleWithFixedDelay(this, 0L, 5L, TimeUnit.SECONDS);
54+
if (eventManager.equals(EventProvider.Type.jms)) {
55+
scheduler.scheduleWithFixedDelay(this, 0L, 5L, TimeUnit.SECONDS);
56+
} else {
57+
scheduler.shutdown();
58+
}
5159
}
5260

5361
void onStop(@Observes ShutdownEvent ev) {
54-
scheduler.shutdown();
62+
if (!scheduler.isShutdown()) {
63+
scheduler.shutdown();
64+
}
5565
}
5666

5767
@Override

0 commit comments

Comments
 (0)