Commit 3fb905f6 authored by Philippe Fonzin's avatar Philippe Fonzin

fix merge conflicts

parents 02039659 d25573e1
FROM openjdk:11-jre-slim
COPY target/warehouse-0.0.1-SNAPSHOT.jar /usr/local/lib/warehouse.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","/usr/local/lib/warehouse.jar"]
# BELOW IS FOR LOCAL TESTING
# FROM maven:3.6.0-jdk-11-slim AS build
# COPY src /home/app/src
# COPY pom.xml /home/app
# RUN mvn -f /home/app/pom.xml clean package -DskipTests
#
# FROM openjdk:11-jre-slim
# COPY --from=build /home/app/target/warehouse-0.0.1-SNAPSHOT.jar /usr/local/lib/warehouse.jar
# EXPOSE 8080
# ENTRYPOINT ["java","-jar","/usr/local/lib/warehouse.jar"]
FROM node:13.12.0-alpine as build
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
COPY package.json ./
COPY package-lock.json ./
RUN npm ci
RUN npm install react-scripts@3.4.1 -g
COPY . ./
RUN npm run build
FROM nginx:stable-alpine
COPY --from=build /app/build /usr/share/nginx/html
COPY nginx/nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
......@@ -95,9 +95,14 @@
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.7.0</version>
</dependency>
</dependencies>
......
......@@ -2,13 +2,25 @@ package com.ascendfinalproject.warehouse;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@SpringBootApplication
@EnableSwagger2
public class WarehouseApplication {
public static void main(String[] args) {
SpringApplication.run(WarehouseApplication.class, args);
}
@Bean
public Docket productApi() {
return new Docket(DocumentationType.SWAGGER_2).select()
.apis(RequestHandlerSelectors.basePackage("com.ascendfinalproject.warehouse")).build();
}
}
package com.ascendfinalproject.warehouse.config;
import com.ascendfinalproject.warehouse.models.WarehouseOrderRequest;
import com.ascendfinalproject.warehouse.models.WarehouseOrderResponse;
import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.common.serialization.StringDeserializer;
......@@ -9,8 +8,6 @@ import org.apache.kafka.common.serialization.StringSerializer;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.kafka.support.serializer.JsonDeserializer;
import reactor.core.publisher.Mono;
import reactor.kafka.receiver.KafkaReceiver;
import reactor.kafka.receiver.ReceiverOptions;
import reactor.kafka.sender.KafkaSender;
......@@ -42,13 +39,11 @@ public class KafkaConfig {
receiverConfigProps.put(ConsumerConfig.GROUP_ID_CONFIG, groupId);
receiverConfigProps.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
receiverConfigProps.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
// receiverConfigProps.put(JsonDeserializer.TRUSTED_PACKAGES, WarehouseOrderRequest.class);
return receiverConfigProps;
}
@Bean
public KafkaReceiver<String, String> kafkaEventReceiver(@Value("${kafka.topic.input}") String topic) {
// creates specified config options for kafkaReceiver using consumerFactory
ReceiverOptions<String, String> receiverOptions = ReceiverOptions.create(consumerFactory());
receiverOptions.maxCommitAttempts(5);
return KafkaReceiver.create(receiverOptions.addAssignListener(Collection::iterator).subscription(Collections.singleton(topic)));
......@@ -68,9 +63,7 @@ public class KafkaConfig {
@Bean
public KafkaSender<String, WarehouseOrderRequest> kafkaEventProducer() {
// creates specified config options for kafkaSender using producerFactory
SenderOptions<String, WarehouseOrderRequest> senderOptions = SenderOptions.create(producerFactory());
return KafkaSender.create(senderOptions);
}
}
......@@ -68,11 +68,8 @@ public class WarehouseController {
@CrossOrigin
@PutMapping(value = "/orders/{id}")
public Mono<ResponseEntity> updateOrder(@RequestBody WarehouseOrderResponse order, @PathVariable(value = "id") String id) {
return orderService.updateOrder(order, id)
.map(updatedOrder -> (ResponseEntity.status(HttpStatus.OK).body(order)))
.cast(ResponseEntity.class)
.defaultIfEmpty(ResponseEntity.status(HttpStatus.NOT_FOUND).body(null));
public Mono<WarehouseOrderResponse> updateOrder(@RequestBody WarehouseOrderResponse order, @PathVariable(value = "id") String id) {
return orderService.updateOrder(order, id);
}
@CrossOrigin
......
package com.ascendfinalproject.warehouse.kafkaservice;
import com.ascendfinalproject.warehouse.models.Address;
import com.ascendfinalproject.warehouse.models.Item;
import com.ascendfinalproject.warehouse.models.WarehouseOrderRequest;
import com.ascendfinalproject.warehouse.models.WarehouseOrderResponse;
import com.ascendfinalproject.warehouse.services.WarehouseOrderService;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.event.EventListener;
......@@ -17,9 +12,6 @@ import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;
import reactor.kafka.receiver.KafkaReceiver;
import java.util.Arrays;
import java.util.List;
@Service
@Slf4j
......@@ -44,7 +36,6 @@ public class Receiver {
log.info("ORDER objectMapper {}", order);
Mono<WarehouseOrderResponse> mono = orderService.createOrder(order);
mono.subscribe();
// mono.block();
} catch (Exception e) {
log.error("Caught error", e);
}
......@@ -52,5 +43,4 @@ public class Receiver {
.doOnError(throwable -> System.out.println(throwable.getMessage()))
.subscribe();
}
}
......@@ -22,12 +22,9 @@ public class Sender {
private static final String TOPIC = "test_topic";
//STEP TWO
public void sendOrder(WarehouseOrderRequest currentOrder) {
log.info(String.format("Sender message: %s ", currentOrder));
// CREATE RECORD
ProducerRecord<String, WarehouseOrderRequest> record = new ProducerRecord<>(TOPIC, currentOrder);
//SEND RECORD
Flux<SenderResult<WarehouseOrderRequest>> sendToKafka = kafkaEventProducer.send(Mono.just(SenderRecord.create(record, currentOrder)))
.doOnError(throwable -> System.out.println(throwable))
.doOnNext(t -> {
......
......@@ -6,8 +6,9 @@ import com.ascendfinalproject.warehouse.models.WarehouseOrderRequest;
import com.ascendfinalproject.warehouse.models.WarehouseOrderResponse;
import com.ascendfinalproject.warehouse.repositories.WarehouseOrderRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import reactor.core.CoreSubscriber;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
......@@ -16,6 +17,10 @@ import java.util.Date;
@Service
public class WarehouseOrderService {
private String RECEIVED = "RECEIVED";
private String FULFILLED = "FULFILLED";
private String CANCELLED = "CANCELLED";
@Autowired
WarehouseOrderRepository orderRepository;
......@@ -32,47 +37,33 @@ public class WarehouseOrderService {
WarehouseOrderResponse response = new WarehouseOrderResponse();
response.setOrderId(order.getId());
response.setStatus("RECEIVED");
// response.setCreatedAt(order.getOrderCreatedAt());
// response.setModifiedAt(System.currentTimeMillis());
response.setStatus(RECEIVED);
response.setCreatedAt(new Date(order.getOrderCreatedAt()));
response.setModifiedAt(new Date(System.currentTimeMillis()));
response.setOrderItems(order.getOrderItems());
Address address = order.getCustomerAddress();
response.setAddress(address.getStreet() + " " +
address.getCity() + " " +
address.getState() + " " +
response.setAddress(address.getStreet() + ", " +
address.getCity() + ", " +
address.getState() + ", " +
address.getZip()
);
System.out.println("built response " + response);
System.out.println("-----------");
return orderRepository.save(response);
}
// WarehouseOrderResponse{id='null', orderId='6085cb1e7681124ea05d2cab', status='RECEIVED', createdAt=Fri May 07 16:23:18 PDT 2021,
// modifiedAt=Fri May 07 16:21:39 PDT 2021, orderItems=[com.ascendfinalproject.warehouse.models.Item@2bfa9ace,
// com.ascendfinalproject.warehouse.models.Item@4a236e68, com.ascendfinalproject.warehouse.models.Item@8c53158,
// com.ascendfinalproject.warehouse.models.Item@b50f9d1], address='390 15th st., New York, NY, 10010'}
//
//
// ++++++++WarehouseOrderResponse(id=null, orderId=6085cb1e7681124ea05d2cab, status=RECEIVED, createdAt=Fri May 07 19:23:18 EDT 2021,
// modifiedAt=Wed Dec 31 19:00:00 EST 1969, orderItems=[Item(itemId=1, itemName=item name, itemQuantity=5,
// itemPrice=5.99, itemSku=1234)], address=390 15th st., New York, NY, 10010)
public Mono<WarehouseOrderResponse> updateOrder(WarehouseOrderResponse order, String id) {
return orderRepository.findById(id)
.flatMap(existingOrder -> {
if (existingOrder.getStatus().equals(RECEIVED)) {
if (order.getStatus().equals(FULFILLED) || order.getStatus().equals(CANCELLED)) {
existingOrder.setStatus(order.getStatus());
// existingOrder.setModifiedAt(System.currentTimeMillis());
existingOrder.setModifiedAt(new Date(System.currentTimeMillis()));
}
}
return orderRepository.save(existingOrder);
});
}
public Mono<Void> deleteOrder(String id) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment