Skip to content

Commit

Permalink
add minify version of server
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosthe19916 committed Apr 27, 2020
1 parent f2a61d5 commit 268c0bf
Show file tree
Hide file tree
Showing 27 changed files with 1,813 additions and 70 deletions.
8 changes: 8 additions & 0 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,18 @@
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-multipart-provider</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-artemis-jms</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-quartz</artifactId>
</dependency>

<!--Camel-->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/**
* Copyright 2019 Project OpenUBL, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Eclipse Public License - v 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.eclipse.org/legal/epl-2.0/
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.github.project.openubl.xmlsender.bootstrap;

import io.github.project.openubl.xmlsender.events.EventProvider;
import io.github.project.openubl.xmlsender.models.jpa.DocumentRepository;
import io.github.project.openubl.xmlsender.models.jpa.entities.DocumentEntity;
import io.github.project.openubl.xmlsender.ws.WSSunatClient;
import io.quarkus.arc.Arc;
import io.quarkus.runtime.StartupEvent;
import io.quarkus.scheduler.Scheduled;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.quartz.*;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;
import javax.inject.Inject;
import javax.transaction.Transactional;
import java.util.List;

@ApplicationScoped
public class JobsBootstrap {

@ConfigProperty(name = "openubl.event-manager")
EventProvider.Type eventManager;

@ConfigProperty(name = "openubl.event-manager.basic.retry-delay")
Long retryDelay;

@Inject
Scheduler quartz;

@Inject
DocumentRepository documentRepository;

@Inject
WSSunatClient wsSunatClient;

void onStart(@Observes StartupEvent ev) throws SchedulerException {
if (eventManager.equals(EventProvider.Type.basic)) {
JobDetail job = JobBuilder.newJob(RetryJob.class)
.withIdentity("retryJob", "retryGroup")
.build();
Trigger trigger = TriggerBuilder.newTrigger()
.withIdentity("retryJob", "retryGroup")
.startNow()
.withSchedule(
SimpleScheduleBuilder.simpleSchedule()
.withIntervalInMilliseconds(retryDelay)
.repeatForever())
.build();
quartz.scheduleJob(job, trigger);
}
}


// Just to force Quartz to start
@Scheduled(cron = "0 0 0 * * ?")
void schedule() {

}

@Transactional
void performTask() {
// Resend documents
List<DocumentEntity> documentScheduled = documentRepository.findDocumentScheduled();
for (DocumentEntity documentEntity : documentScheduled) {
wsSunatClient.sendDocument(documentEntity.id);
}

// Resend tickets
List<DocumentEntity> documentsWithUncheckedTickets = documentRepository.findTickedCheckScheduled();

for (DocumentEntity documentEntity : documentsWithUncheckedTickets) {
wsSunatClient.checkDocumentTicket(documentEntity.id);
}
}

public static class RetryJob implements Job {
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
Arc.container().instance(JobsBootstrap.class).get().performTask();
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/**
* Copyright 2019 Project OpenUBL, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Eclipse Public License - v 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.eclipse.org/legal/epl-2.0/
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.github.project.openubl.xmlsender.events;

import io.github.project.openubl.xmlsender.events.jms.SendTicketQueueConsumer;
import io.github.project.openubl.xmlsender.idm.DocumentRepresentation;
import io.github.project.openubl.xmlsender.models.DocumentEvent;
import io.github.project.openubl.xmlsender.models.jpa.DocumentRepository;
import io.github.project.openubl.xmlsender.models.jpa.entities.DocumentEntity;
import io.github.project.openubl.xmlsender.models.utils.EntityToRepresentation;
import io.github.project.openubl.xmlsender.resources.client.CallbackClientService;
import io.github.project.openubl.xmlsender.ws.WSSunatClient;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.jboss.logging.Logger;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;
import javax.enterprise.event.TransactionPhase;
import javax.inject.Inject;
import javax.transaction.Transactional;
import javax.ws.rs.WebApplicationException;

@ApplicationScoped
public class BasicEventManager {

private static final Logger LOG = Logger.getLogger(BasicEventManager.class);

@Inject
WSSunatClient wsSunatClient;

@Inject
@RestClient
CallbackClientService callbackClientService;

@Inject
DocumentRepository documentRepository;

public void onDocumentCreate(
@Observes(during = TransactionPhase.AFTER_SUCCESS)
@EventProvider(EventProvider.Type.basic) DocumentEvent.Created event
) {
wsSunatClient.sendDocument(event.getId());
}

public void onDocumentRequireCheckTicket(
@Observes(during = TransactionPhase.AFTER_SUCCESS)
@EventProvider(EventProvider.Type.basic) DocumentEvent.RequireCheckTicket event
) {
wsSunatClient.checkDocumentTicket(event.getId());
}

@Transactional
public void onDocumentDelivered(
@Observes(during = TransactionPhase.AFTER_SUCCESS)
@EventProvider(EventProvider.Type.basic) DocumentEvent.Delivered event
) {
DocumentEntity documentEntity = documentRepository.findById(event.getId());
DocumentRepresentation rep = EntityToRepresentation.toRepresentation(documentEntity);
try {
callbackClientService.callback(rep);
} catch (WebApplicationException e) {
LOG.error("Could not send webhook callback, message=" + e.getMessage());
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Copyright 2019 Project OpenUBL, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Eclipse Public License - v 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.eclipse.org/legal/epl-2.0/
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.github.project.openubl.xmlsender.events;

import javax.inject.Qualifier;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Qualifier
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE})
public @interface EventProvider {

Type value();

enum Type {
basic,
jms
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Copyright 2019 Project OpenUBL, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Eclipse Public License - v 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.eclipse.org/legal/epl-2.0/
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.github.project.openubl.xmlsender.events;

import javax.enterprise.util.AnnotationLiteral;
import javax.inject.Qualifier;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

public class EventProviderLiteral extends AnnotationLiteral<EventProvider> implements EventProvider {

private final EventProvider.Type type;

public EventProviderLiteral(EventProvider.Type type) {
this.type = type;
}

@Override
public Type value() {
return type;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.github.project.openubl.xmlsender.managers;
package io.github.project.openubl.xmlsender.events;

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

@ApplicationScoped
public class EventsManager {
public class JMSEventManager {

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

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

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

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

@Inject
ConnectionFactory connectionFactory;

public void onDocumentCreate(@Observes(during = TransactionPhase.AFTER_SUCCESS) DocumentEvent.Created event) {
public void onDocumentCreate(
@Observes(during = TransactionPhase.AFTER_SUCCESS)
@EventProvider(EventProvider.Type.jms) DocumentEvent.Created event
) {
produceMessage(sendFileQueue, event.getId());
}

public void onDocumentRequireCheckTicket(@Observes(during = TransactionPhase.AFTER_SUCCESS) DocumentEvent.RequireCheckTicket event) {
public void onDocumentRequireCheckTicket(
@Observes(during = TransactionPhase.AFTER_SUCCESS)
@EventProvider(EventProvider.Type.jms) DocumentEvent.RequireCheckTicket event
) {
produceMessage(ticketQueue, event.getId());
}

public void onDocumentDelivered(@Observes(during = TransactionPhase.AFTER_SUCCESS) DocumentEvent.Delivered event) {
public void onDocumentDelivered(
@Observes(during = TransactionPhase.AFTER_SUCCESS)
@EventProvider(EventProvider.Type.jms) DocumentEvent.Delivered event
) {
produceMessage(callbackQueue, event.getId());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.github.project.openubl.xmlsender.jms;
package io.github.project.openubl.xmlsender.events.jms;

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

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

@ConfigProperty(name = "openubl.event-manager")
EventProvider.Type eventManager;

@Inject
WSSunatClient wsSunatClient;

@Inject
ConnectionFactory connectionFactory;

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

private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();

void onStart(@Observes StartupEvent ev) {
scheduler.scheduleWithFixedDelay(this, 0L, 5L, TimeUnit.SECONDS);
if (eventManager.equals(EventProvider.Type.jms)) {
scheduler.scheduleWithFixedDelay(this, 0L, 5L, TimeUnit.SECONDS);
} else {
scheduler.shutdown();
}
}

void onStop(@Observes ShutdownEvent ev) {
scheduler.shutdown();
if (!scheduler.isShutdown()) {
scheduler.shutdown();
}
}

@Override
Expand Down
Loading

0 comments on commit 268c0bf

Please sign in to comment.