-
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
1 parent
020b5df
commit cb6ea39
Showing
10 changed files
with
173 additions
and
14 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 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
14 changes: 13 additions & 1 deletion
14
eBL-backend/src/main/java/com/info7255/ebl/lisetener/EmailListeners.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,20 +1,32 @@ | ||
package com.info7255.ebl.lisetener; | ||
|
||
import com.info7255.ebl.entity.User; | ||
import com.info7255.ebl.event.QuoteEvent; | ||
import com.info7255.ebl.repository.UserRepository; | ||
import com.info7255.ebl.service.EmailService; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.event.EventListener; | ||
import org.springframework.scheduling.annotation.Async; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.Optional; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class EmailListeners { | ||
|
||
@Autowired | ||
private UserRepository userRepository; | ||
private final EmailService emailService; | ||
|
||
@Async | ||
@EventListener | ||
public void onRateQuotationEvent(QuoteEvent event){ | ||
|
||
emailService.sendQuotationEmail(event.getQuote()); | ||
Optional<User> user = userRepository.findById(String.valueOf(event.getQuote().get("customerID"))); | ||
|
||
emailService.sendQuotationEmail(user, event.getQuote()); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
eBL-backend/src/main/java/com/info7255/ebl/lisetener/SemanticQuoteCreationListener.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,45 @@ | ||
package com.info7255.ebl.lisetener; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.info7255.ebl.entity.User; | ||
import com.info7255.ebl.event.QuoteEvent; | ||
import com.info7255.ebl.repository.FreightDAO; | ||
import com.info7255.ebl.repository.UserRepository; | ||
import com.info7255.ebl.service.QuoteService; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.event.EventListener; | ||
import org.springframework.scheduling.annotation.Async; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.Optional; | ||
|
||
@Slf4j | ||
@Component | ||
@RequiredArgsConstructor | ||
public class SemanticQuoteCreationListener { | ||
|
||
@Autowired | ||
private UserRepository userRepository; | ||
|
||
@Autowired | ||
private QuoteService quoteService; | ||
|
||
@Autowired | ||
private FreightDAO dao; | ||
|
||
@Async | ||
@EventListener | ||
public void onRateQuotationEvent(QuoteEvent event) { | ||
|
||
Optional<User> user = userRepository.findById(String.valueOf(event.getQuote().get("customerID"))); | ||
|
||
log.info("Inside SemanticQuoteCreationListener", event); | ||
|
||
JsonNode rate = dao.findRateById(String.valueOf(event.getQuote().get("rateID"))); | ||
|
||
quoteService.generateRDF(rate, user, event.getQuote()); | ||
|
||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
eBL-backend/src/main/java/com/info7255/ebl/resource/VCARD.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,28 @@ | ||
package com.info7255.ebl.resource; | ||
|
||
import org.apache.jena.rdf.model.* ; | ||
|
||
/** VCARD vocabulary class for namespace http://www.w3.org/2001/vcard-rdf/3.0# | ||
*/ | ||
public class VCARD { | ||
|
||
/** | ||
* The namespace of the vocabulary as a string | ||
*/ | ||
public static final String uri ="http://www.w3.org/2001/vcard-rdf/3.0#"; | ||
|
||
/** returns the URI for this schema | ||
* @return the URI for this schema | ||
*/ | ||
public static String getURI() { | ||
return uri; | ||
} | ||
|
||
private static final Model m = ModelFactory.createDefaultModel(); | ||
|
||
public static final Property TWENTY = m.createProperty(uri, "TWENTY" ); | ||
public static final Property FORTY = m.createProperty(uri, "FORTY" ); | ||
public static final Property FORTYHQ = m.createProperty(uri, "FORTYHQ" ); | ||
public static final Property BUY = m.createProperty(uri, "BUY"); | ||
public static final Property SELL = m.createProperty(uri, "SELL"); | ||
} |
10 changes: 9 additions & 1 deletion
10
eBL-backend/src/main/java/com/info7255/ebl/service/EmailService.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,14 +1,22 @@ | ||
package com.info7255.ebl.service; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.info7255.ebl.entity.User; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.Optional; | ||
|
||
@Slf4j | ||
@Service | ||
public class EmailService { | ||
|
||
public EmailService() { | ||
} | ||
|
||
public void sendQuotationEmail(JsonNode quote){ | ||
public void sendQuotationEmail(Optional<User> user, JsonNode quote){ | ||
|
||
|
||
log.info("Email Quotation sent!", quote); | ||
} | ||
} |
40 changes: 35 additions & 5 deletions
40
eBL-backend/src/main/java/com/info7255/ebl/service/QuoteService.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,31 +1,61 @@ | ||
package com.info7255.ebl.service; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import com.info7255.ebl.entity.User; | ||
import com.info7255.ebl.event.QuoteEvent; | ||
import com.info7255.ebl.repository.FreightDAO; | ||
import com.info7255.ebl.resource.VCARD; | ||
import lombok.Data; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.jena.rdf.model.*; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.ApplicationEventPublisher; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
@Slf4j | ||
@Component | ||
@RequiredArgsConstructor | ||
public class QuoteService { | ||
|
||
// private final User user; | ||
|
||
// private final EmailService emailService; | ||
ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
private final ApplicationEventPublisher publisher; | ||
|
||
public void quote(JsonNode quote) { | ||
|
||
// emailService.sendQuotationEmail(quote); | ||
|
||
publisher.publishEvent(new QuoteEvent(quote)); | ||
|
||
} | ||
|
||
public void generateRDF(JsonNode rate, Optional<User> user, JsonNode quote){ | ||
|
||
Model model = ModelFactory.createDefaultModel(); | ||
|
||
JsonNode ppJson = objectMapper.createObjectNode(); | ||
|
||
((ObjectNode) ppJson).put("id", UUID.randomUUID().toString()); | ||
((ObjectNode) ppJson).put("pol", rate.get("pol")); | ||
((ObjectNode) ppJson).put("pod", rate.get("pod")); | ||
|
||
Resource portPair = model.createResource((Resource) ppJson); | ||
|
||
portPair.addProperty(VCARD.BUY, model.createResource() | ||
.addProperty(VCARD.TWENTY, rate.get("twenty").asText()) | ||
.addProperty(VCARD.FORTY, rate.get("forty").asText()) | ||
.addProperty(VCARD.FORTYHQ, rate.get("fortyhq").asText())) | ||
.addProperty(VCARD.SELL, model.createResource() | ||
.addProperty(VCARD.TWENTY, quote.get("sellRate20").asText()) | ||
.addProperty(VCARD.FORTY, quote.get("sellRate40").asText()) | ||
.addProperty(VCARD.FORTYHQ, rate.get("sellRate40HQ").asText())); | ||
|
||
log.info("RDF created", portPair); | ||
|
||
} | ||
|
||
} |
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