Commit ef6323e7 authored by houssem870's avatar houssem870
Browse files

1st commit

parents
Pipeline #2372 failed with stages
in 0 seconds
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile default="true" name="Default" enabled="true" />
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="BookReview" />
</profile>
</annotationProcessing>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="https://repo.maven.apache.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="corretto-17" project-jdk-type="JavaSDK" />
</project>
\ No newline at end of file
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.workflow</groupId>
<artifactId>BookReview</artifactId>
<version>1.0.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.7.9</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.camunda.bpm</groupId>
<artifactId>camunda-bom</artifactId>
<version>7.19.0</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.camunda.bpm.springboot</groupId>
<artifactId>camunda-bpm-spring-boot-starter-rest</artifactId>
</dependency>
<dependency>
<groupId>org.camunda.bpm.springboot</groupId>
<artifactId>camunda-bpm-spring-boot-starter-webapp</artifactId>
</dependency>
<dependency>
<groupId>org.camunda.bpm</groupId>
<artifactId>camunda-engine-plugin-spin</artifactId>
</dependency>
<dependency>
<groupId>org.camunda.spin</groupId>
<artifactId>camunda-spin-dataformat-all</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.camunda.bpm.run/camunda-bpm-run-modules-swaggerui -->
<dependency>
<groupId>org.camunda.bpm</groupId>
<artifactId>camunda-engine-rest-openapi</artifactId>
<version>7.19.0</version>
</dependency>
<dependency>
<groupId>org.camunda.bpm.extension</groupId>
<artifactId>camunda-bpm-mail-core</artifactId>
<version>1.5.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.5.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-websocket -->
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-websocket -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>com.twilio.sdk</groupId>
<artifactId>twilio</artifactId>
<version>7.1.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.4.5</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-email</artifactId>
<version>1.5</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.7.9</version>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
package com.example.workflow;
import org.camunda.bpm.spring.boot.starter.annotation.EnableProcessApplication;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@EnableProcessApplication
public class Application {
public static void main(String... args) {
SpringApplication.run(Application.class, args);
}
}
\ No newline at end of file
package com.example.workflow.DTO;
import com.example.workflow.entities.Review;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class TaskCompletionRequest {
private String bookId;
private Review review;
// Constructor, getters, and setters
}
package com.example.workflow.conf;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import java.util.Properties;
@Configuration
public class MailConfig {
@Bean
public JavaMailSender javaMailSender() {
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setHost("smtp.gmail.com");
mailSender.setPort(587);
mailSender.setUsername("cammundac@gmail.com"); // Replace with your Gmail email address
mailSender.setPassword("ycskqwnsqvfaqayi"); // Replace with your Gmail password
Properties props = mailSender.getJavaMailProperties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.debug", "true");
return mailSender;
}
}
package com.example.workflow.conf;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
config.enableSimpleBroker("/lesson");
config.setApplicationDestinationPrefixes("/app");
}
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/gs-guide-websocket").withSockJS();
}
}
\ No newline at end of file
package com.example.workflow.controller;
import com.example.workflow.entities.Book;
import com.example.workflow.entities.Review;
import com.example.workflow.services.BookService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/books")
public class BookController {
private final BookService bookService;
public BookController(BookService bookService) {
this.bookService = bookService;
}
@PostMapping
public ResponseEntity<Book> createBook(@RequestBody Book book) {
Book createdBook = bookService.createBook(book);
return ResponseEntity.status(HttpStatus.CREATED).body(createdBook);
}
@GetMapping("/{id}")
public ResponseEntity<Book> getBookById(@PathVariable int id) {
Book book = bookService.getBookById(id);
if (book != null) {
return ResponseEntity.ok(book);
} else {
return ResponseEntity.notFound().build();
}
}
@PostMapping("/{bookId}/reviews")
public ResponseEntity<Review> createReview(@PathVariable int bookId, @RequestBody Review review) {
Review createdReview = bookService.createReview(bookId, review);
if (createdReview != null) {
return ResponseEntity.status(HttpStatus.CREATED).body(createdReview);
} else {
return ResponseEntity.notFound().build();
}
}
@PostMapping("/{bookId}/reviews/{reviewId}/publish")
public ResponseEntity<Void> publishReview(@PathVariable int bookId, @PathVariable int reviewId) {
bookService.publishReview(bookId, reviewId);
return ResponseEntity.ok().build();
}
@PostMapping("/reviews/reviewBook")
public ResponseEntity<Void> bookReview() {
System.out.println("Still under Review");
return ResponseEntity.ok().build();
}
}
package com.example.workflow.controller;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import com.example.workflow.entities.SmsPojo;
import com.example.workflow.services.SmsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class SMSController {
@Autowired
SmsService service;
@Autowired
private SimpMessagingTemplate webSocket;
private final String TOPIC_DESTINATION = "/lesson/sms";
@RequestMapping(value = "/sms", method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public void smsSubmit(@RequestBody SmsPojo sms) {
try{
service.send(sms);
}
catch(Exception e){
webSocket.convertAndSend(TOPIC_DESTINATION, getTimeStamp() + ": Error sending the SMS: "+e.getMessage());
throw e;
}
webSocket.convertAndSend(TOPIC_DESTINATION, getTimeStamp() + ": SMS has been sent!: "+sms.getTo());
}
@RequestMapping(value = "/smscallback", method = RequestMethod.POST,
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public void smsCallback(@RequestBody MultiValueMap<String, String> map) {
service.receive(map);
webSocket.convertAndSend(TOPIC_DESTINATION, getTimeStamp() + ": Twilio has made a callback request! Here are the contents: "+map.toString());
}
private String getTimeStamp() {
return DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.now());
}
}
package com.example.workflow.controller;
import com.example.workflow.DTO.TaskCompletionRequest;
import com.example.workflow.entities.Review;
import org.camunda.bpm.engine.RuntimeService;
import org.camunda.bpm.engine.TaskService;
import org.camunda.bpm.engine.task.Task;
import org.camunda.bpm.engine.task.TaskQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/api/tasks")
public class TaskController {
private final TaskService taskService;
private final RuntimeService runtimeService;
@Autowired
public TaskController(TaskService taskService, RuntimeService runtimeService) {
this.taskService = taskService;
this.runtimeService = runtimeService;
}
@PostMapping("/{taskId}/complete")
public void completeTask(@RequestBody TaskCompletionRequest taskCompletionRequest) {
TaskQuery taskop = taskService.createTaskQuery()
.taskDefinitionKey("Activity_06flnxw")
.orderByLastUpdated().asc();
List<Task> taskList=taskop.list();
for (int i=0 ; i<taskList.size() ;i++){System.out.println(taskList.get(i));}
Task task = taskList.get(taskList.size()-1);
String taskId = task.getId();
if (task != null) {
String bookId = taskCompletionRequest.getBookId();
Review review = taskCompletionRequest.getReview();
// Complete the task and set process variables
Map<String, Object> variables = new HashMap<>();
variables.put("bookId", bookId);
variables.put("review", review);
taskService.complete(taskId, variables); }
else {System.out.println("Null Task");}
}
@GetMapping("/tasks")
public List<Task> getTasks() {
List<Task> tasks = taskService.createTaskQuery()
// Add filters if needed
.list();
System.out.println(tasks);
return tasks;
}
}
package com.example.workflow.delegate;
import com.example.workflow.entities.Review;
import com.example.workflow.services.BookService;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Component;
import static javax.xml.bind.DatatypeConverter.parseInt;
@ComponentScan
@Component("CreateBookReviewDelegate")
public class CreateBookReviewDelegate implements JavaDelegate {
@Autowired
BookService bookService;
@Override
public void execute(DelegateExecution delegateExecution) throws Exception {
int bookId = parseInt(delegateExecution.getVariable("bookId").toString());
Review review = (Review) delegateExecution.getVariable("review");
bookService.createReview(bookId, review);
System.out.println("ReviewCreated");
}
}
package com.example.workflow.delegate;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;
@ComponentScan
@Component("Email")
public class Email implements JavaDelegate{
private final JavaMailSender javaMailSender;
@Autowired
public Email(JavaMailSender javaMailSender) {
this.javaMailSender = javaMailSender;
}
@Override
public void execute(DelegateExecution execution) throws Exception {
String recipient = "houssem.abassino@gmail.com";
String subject = "Confirmation";
String text = "Welcome to Camunda";
SimpleMailMessage message = new SimpleMailMessage();
message.setTo(recipient);
message.setSubject(subject);
message.setText(text);
try {
javaMailSender.send(message);
System.out.println("Email sent successfully");
} catch (Exception e) {
e.printStackTrace();
System.out.println("Failed to send email");
}
}
}
package com.example.workflow.delegate;
import com.example.workflow.repository.ReviewRepository;
import com.example.workflow.services.BookService;
import org.camunda.bpm.engine.TaskService;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
import static javax.xml.bind.DatatypeConverter.parseInt;
@Component("PublishReviewDelegate")
public class PublishReviewDelegate implements JavaDelegate {
@Autowired
BookService bookService ;
@Autowired
ReviewRepository reviewRepository;
private final TaskService taskService;
@Autowired
public PublishReviewDelegate(TaskService taskService) {
this.taskService = taskService;
}
@Override
public void execute(DelegateExecution delegateExecution) throws Exception {
System.out.println("im here !!!!");
int bookId = parseInt(delegateExecution.getVariable("bookId").toString());
reviewRepository.findAll().size();
bookService.publishReview(bookId, reviewRepository.findAll().size());
}
}
package com.example.workflow.delegate;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
import org.springframework.stereotype.Component;
@Component("ReviewBookDelegate")
public class ReviewBookDelegate implements JavaDelegate {
@Override
public void execute(DelegateExecution delegateExecution) throws Exception {
System.out.println("under Review");
}
}
package com.example.workflow.entities;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
public class Book {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String title;
private String author;
// Add more attributes as needed
// Getters and setters
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
// Add more getters and setters for additional attributes
}
Supports Markdown
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