-
Notifications
You must be signed in to change notification settings - Fork 12
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
1 parent
224dac9
commit 73396af
Showing
23 changed files
with
448 additions
and
300 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
This file was deleted.
Oops, something went wrong.
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,99 @@ | ||
package org.openubl.factories; | ||
|
||
import io.github.carlosthe19916.webservices.providers.BillServiceModel; | ||
import org.openubl.models.SendFileModel; | ||
|
||
import javax.jms.JMSException; | ||
import javax.jms.Message; | ||
import java.util.Enumeration; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class ModelFactory { | ||
|
||
private ModelFactory() { | ||
// Just static methods | ||
} | ||
|
||
public static SendFileModel getSendFilePropertiesModel(Message message) throws JMSException { | ||
SendFileModel.Builder builder = SendFileModel.Builder.aSunatJMSMessageModel(); | ||
|
||
Enumeration<?> enumeration = message.getPropertyNames(); | ||
if (enumeration != null) { | ||
while (enumeration.hasMoreElements()) { | ||
String key = (String) enumeration.nextElement(); | ||
switch (key) { | ||
case "documentType": | ||
builder.withDocumentType(message.getStringProperty(key)); | ||
break; | ||
case "serverUrl": | ||
builder.withServerUrl(message.getStringProperty(key)); | ||
break; | ||
case "fileName": | ||
builder.withFileName(message.getStringProperty(key)); | ||
break; | ||
case "username": | ||
builder.withUsername(message.getStringProperty(key)); | ||
break; | ||
case "password": | ||
builder.withPassword(message.getStringProperty(key)); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
return builder.build(); | ||
} | ||
|
||
public static Map<String, String> getAsMap(SendFileModel model) { | ||
Map<String, String> map = new HashMap<>(); | ||
|
||
map.put("fileName", model.getFileName()); | ||
map.put("serverUrl", model.getServerUrl()); | ||
map.put("documentType", model.getDocumentType()); | ||
map.put("username", model.getUsername()); | ||
map.put("password", model.getPassword()); | ||
|
||
return map; | ||
} | ||
|
||
public static BillServiceModel getBillServiceModel(Message message) throws JMSException { | ||
BillServiceModel model = new BillServiceModel(); | ||
|
||
model.setCdr(message.getBody(byte[].class)); | ||
|
||
Enumeration<?> enumeration = message.getPropertyNames(); | ||
if (enumeration != null) { | ||
while (enumeration.hasMoreElements()) { | ||
String key = (String) enumeration.nextElement(); | ||
switch (key) { | ||
case "code": | ||
model.setCode(message.getIntProperty(key)); | ||
break; | ||
case "description": | ||
model.setDescription(message.getStringProperty(key)); | ||
break; | ||
case "ticket": | ||
model.setTicket(message.getStringProperty(key)); | ||
break; | ||
case "status": | ||
model.setStatus(BillServiceModel.Status.valueOf(message.getStringProperty(key))); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
return model; | ||
} | ||
|
||
public static Map<String, Object> getAsMap(BillServiceModel model) { | ||
Map<String, Object> map = new HashMap<>(); | ||
|
||
map.put("code", model.getCode()); | ||
map.put("description", model.getDescription()); | ||
map.put("ticket", model.getTicket()); | ||
map.put("status", model.getStatus().toString()); | ||
|
||
return map; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
58 changes: 58 additions & 0 deletions
58
src/main/java/org/openubl/jms/SendCallbackJMSConsumer.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,58 @@ | ||
package org.openubl.jms; | ||
|
||
import io.github.carlosthe19916.webservices.providers.BillServiceModel; | ||
import io.quarkus.runtime.ShutdownEvent; | ||
import io.quarkus.runtime.StartupEvent; | ||
import org.eclipse.microprofile.config.inject.ConfigProperty; | ||
import org.openubl.factories.ModelFactory; | ||
import org.openubl.providers.CallbackRSProvider; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.event.Observes; | ||
import javax.inject.Inject; | ||
import javax.jms.*; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
@ApplicationScoped | ||
public class SendCallbackJMSConsumer implements Runnable { | ||
|
||
@Inject | ||
CallbackRSProvider callbackRSProvider; | ||
|
||
@Inject | ||
ConnectionFactory connectionFactory; | ||
|
||
@ConfigProperty(name = "openubl.callbackQueue") | ||
String callbackQueue; | ||
|
||
private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(); | ||
|
||
void onStart(@Observes StartupEvent ev) { | ||
scheduler.scheduleWithFixedDelay(this, 0L, 5L, TimeUnit.SECONDS); | ||
} | ||
|
||
void onStop(@Observes ShutdownEvent ev) { | ||
scheduler.shutdown(); | ||
} | ||
|
||
@Override | ||
public void run() { | ||
// try (JMSContext context = connectionFactory.createContext(Session.AUTO_ACKNOWLEDGE)) { | ||
// JMSConsumer jmsConsumer = context.createConsumer(context.createQueue(callbackQueue)); | ||
// while (true) { | ||
// Message message = jmsConsumer.receive(); | ||
// if (!(message instanceof BytesMessage)) { | ||
// return; | ||
// } | ||
// | ||
// BillServiceModel billServiceModel = ModelFactory.getBillServiceModel(message); | ||
// callbackRSProvider.sendCallback(billServiceModel); | ||
// } | ||
// } catch (JMSException e) { | ||
// throw new RuntimeException(e); | ||
// } | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/org/openubl/jms/SendCallbackJMSProducer.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,41 @@ | ||
package org.openubl.jms; | ||
|
||
import io.github.carlosthe19916.webservices.providers.BillServiceModel; | ||
import org.eclipse.microprofile.config.inject.ConfigProperty; | ||
import org.openubl.factories.ModelFactory; | ||
import org.openubl.models.SendFileModel; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.inject.Inject; | ||
import javax.jms.*; | ||
import java.util.Map; | ||
|
||
@ApplicationScoped | ||
public class SendCallbackJMSProducer { | ||
|
||
@ConfigProperty(name = "openubl.callbackQueue") | ||
String callbackQueue; | ||
|
||
@Inject | ||
ConnectionFactory connectionFactory; | ||
|
||
public void produceSendCallbackMessage(BillServiceModel billServiceModel) { | ||
// try (JMSContext context = connectionFactory.createContext(Session.AUTO_ACKNOWLEDGE)) { | ||
// JMSProducer jmsProducer = context.createProducer(); | ||
// | ||
// for (Map.Entry<String, Object> entry : ModelFactory.getAsMap(billServiceModel).entrySet()) { | ||
// jmsProducer.setProperty(entry.getKey(), entry.getValue()); | ||
// } | ||
// | ||
// Queue queue = context.createQueue(callbackQueue); | ||
// | ||
// BytesMessage message = context.createBytesMessage(); | ||
// message.writeBytes(billServiceModel.getCdr()); | ||
// | ||
// jmsProducer.send(queue, message); | ||
// } catch (JMSRuntimeException | JMSException ex) { | ||
// // handle exception (details omitted) | ||
// System.out.println(ex); | ||
// } | ||
} | ||
} |
Oops, something went wrong.