Skip to content

Commit

Permalink
RDF functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
parekhrikin committed Aug 9, 2023
1 parent 020b5df commit cb6ea39
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 14 deletions.
24 changes: 24 additions & 0 deletions eBL-backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,31 @@
<version>5.0.0</version>
</dependency>

<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-core</artifactId>
<version>4.9.0</version>
</dependency>

<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>apache-jena-libs</artifactId>
<version>4.9.0</version>
<type>pom</type>
</dependency>

<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-rdfconnection</artifactId>
<version>4.9.0</version>
</dependency>

<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena</artifactId>
<version>4.9.0</version>
<type>pom</type>
</dependency>

</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.web.filter.ShallowEtagHeaderFilter;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

//import javax.servlet.Filter;

@EnableAsync
@Configuration
@SpringBootApplication(exclude = {ErrorMvcAutoConfiguration.class})
@EnableWebMvc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.google.common.hash.Hashing;
import com.info7255.ebl.MyToken;
import com.info7255.ebl.repository.FreightDAO;
import com.info7255.ebl.service.QuoteService;
import org.everit.json.schema.Schema;
import org.everit.json.schema.loader.SchemaLoader;
import org.json.JSONObject;
Expand Down Expand Up @@ -39,6 +40,9 @@ public class FreightController {
static ObjectMapper mapper = new ObjectMapper();
static String jws;

@Autowired
private QuoteService quoteService;


@PostMapping("/schema")
public ResponseEntity saveSchema(@RequestBody JsonNode schema, @RequestHeader HttpHeaders headers) throws IOException {
Expand Down Expand Up @@ -128,6 +132,10 @@ public ResponseEntity remove(@PathVariable String id, @RequestHeader HttpHeaders
@PostMapping("/quote")
public ResponseEntity quote(@RequestBody JsonNode quote, @RequestHeader HttpHeaders requestHeaders) {



quoteService.quote(quote);

return ResponseEntity.ok("Quoted");

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class QuoteEvent {
private JsonNode quote;

public QuoteEvent(JsonNode quote) {
quote = this.quote;
this.quote = quote;
}

public JsonNode getQuote() {
Expand Down
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());
}
}
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 eBL-backend/src/main/java/com/info7255/ebl/resource/VCARD.java
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");
}
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);
}
}
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);

}

}
14 changes: 8 additions & 6 deletions react-admin-dashboard/src/scenes/rates/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const Rates = () => {
customers: []
});
const [openDialog, setOpenDialog] = useState(false);
const [selectedRowId, setSelectedRowId] = useState(null);
const theme = useTheme();
const colors = tokens(theme.palette.mode);

Expand Down Expand Up @@ -49,7 +50,8 @@ const Rates = () => {
.then(() => console.log('Delete successful'));
};

const handleQuote = () => {
const handleQuote = (rowID) => {
setSelectedRowId(rowID);
setOpenDialog(true);
};

Expand All @@ -60,7 +62,7 @@ const Rates = () => {
return (
<Box>
<IconButton
onClick={handleQuote}
onClick={() => handleQuote(params.row.id)}
color="primary"
aria-label="quote"
>
Expand All @@ -82,21 +84,21 @@ const Rates = () => {
{custList.customers.length > 0 ? (
<Formik
initialValues={{
name: '',
customerID: '',
note: '',
sellRate20: '',
sellRate40: '',
sellRate40HQ: '',
}}
onSubmit={(values) => {
console.log(values);
console.log(selectedRowId);
// Handle form submission
fetch('http://localhost:8080/quote', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({...values, ["rateID"]: params.row.id})
body: JSON.stringify({...values, ["rateID"]: selectedRowId})
})
.then(response => {
console.log(response.json());
Expand Down Expand Up @@ -125,7 +127,7 @@ const Rates = () => {
>
<Form>
<Box>
<Field as={TextField} name="name" label="Customer Name" select fullWidth>
<Field as={TextField} name="customerID" label="Customer Name" select fullWidth>
{custList.customers.map((customer) => (
<MenuItem key={customer.id} value={customer.id}>
{customer.companyName}
Expand Down

0 comments on commit cb6ea39

Please sign in to comment.