diff --git a/backend/src/main/java/ervu/client/fileupload/impl/ErvuFileUploadClientImpl.java b/backend/src/main/java/ervu/client/fileupload/EmployeeInformationFileWebDavUploadClient.java similarity index 74% rename from backend/src/main/java/ervu/client/fileupload/impl/ErvuFileUploadClientImpl.java rename to backend/src/main/java/ervu/client/fileupload/EmployeeInformationFileWebDavUploadClient.java index d41cfe19..1fc55bfd 100644 --- a/backend/src/main/java/ervu/client/fileupload/impl/ErvuFileUploadClientImpl.java +++ b/backend/src/main/java/ervu/client/fileupload/EmployeeInformationFileWebDavUploadClient.java @@ -1,4 +1,4 @@ -package ervu.client.fileupload.impl; +package ervu.client.fileupload; import java.io.BufferedOutputStream; import java.io.IOException; @@ -6,7 +6,6 @@ import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; -import ervu.client.fileupload.ErvuFileUploadClient; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; @@ -17,17 +16,13 @@ import org.springframework.web.multipart.MultipartFile; * @author Alexandr Shalaginov */ @Component -public class ErvuFileUploadClientImpl implements ErvuFileUploadClient { - private static final Logger logger = LoggerFactory.getLogger(ErvuFileUploadClientImpl.class); +public class EmployeeInformationFileWebDavUploadClient { + private static final Logger logger = LoggerFactory.getLogger(EmployeeInformationFileWebDavUploadClient.class); - @Value("${file.upload.url:#{null}}") + @Value("${file.webdav.upload.url:localhost:5757}") private String url; - @Override - public boolean uploadFile(String filename, MultipartFile multipartFile) { - if (this.url == null) { - throw new RuntimeException("Property file.upload.url is null"); - } + public boolean webDavUploadFile(String filename, MultipartFile multipartFile) { try { HttpURLConnection connection = (HttpURLConnection) new URL(this.url + "/" + filename).openConnection(); connection.setDoInput(true); diff --git a/backend/src/main/java/ervu/client/fileupload/ErvuFileUploadClient.java b/backend/src/main/java/ervu/client/fileupload/ErvuFileUploadClient.java deleted file mode 100644 index 844fbd38..00000000 --- a/backend/src/main/java/ervu/client/fileupload/ErvuFileUploadClient.java +++ /dev/null @@ -1,10 +0,0 @@ -package ervu.client.fileupload; - -import org.springframework.web.multipart.MultipartFile; - -/** - * @author Alexandr Shalaginov - */ -public interface ErvuFileUploadClient { - boolean uploadFile(String filename, MultipartFile multipartFile); -} diff --git a/backend/src/main/java/ervu/client/kafka/KafkaClient.java b/backend/src/main/java/ervu/client/kafka/KafkaClient.java deleted file mode 100644 index 11d02142..00000000 --- a/backend/src/main/java/ervu/client/kafka/KafkaClient.java +++ /dev/null @@ -1,8 +0,0 @@ -package ervu.client.kafka; - -/** - * @author Alexandr Shalaginov - */ -public interface KafkaClient { - boolean sendMessage(String message); -} diff --git a/backend/src/main/java/ervu/client/kafka/impl/KafkaClientImpl.java b/backend/src/main/java/ervu/client/kafka/KafkaSendMessageClient.java similarity index 66% rename from backend/src/main/java/ervu/client/kafka/impl/KafkaClientImpl.java rename to backend/src/main/java/ervu/client/kafka/KafkaSendMessageClient.java index b366f7ef..15433b4d 100644 --- a/backend/src/main/java/ervu/client/kafka/impl/KafkaClientImpl.java +++ b/backend/src/main/java/ervu/client/kafka/KafkaSendMessageClient.java @@ -1,6 +1,5 @@ -package ervu.client.kafka.impl; +package ervu.client.kafka; -import ervu.client.kafka.KafkaClient; import org.apache.kafka.clients.producer.ProducerRecord; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -12,22 +11,19 @@ import org.springframework.stereotype.Component; * @author Alexandr Shalaginov */ @Component -public class KafkaClientImpl implements KafkaClient { - private static final Logger logger = LoggerFactory.getLogger(KafkaClientImpl.class); +public class KafkaSendMessageClient { + private static final Logger logger = LoggerFactory.getLogger(KafkaSendMessageClient.class); - @Value("${kafka.send.topic:#{null}}") - private String kafkaTopic; + @Value("${kafka.send.message.topic.name:messages-topic}") + private String kafkaTopicName; private final KafkaTemplate kafkaTemplate; - public KafkaClientImpl(KafkaTemplate kafkaTemplate) { + public KafkaSendMessageClient(KafkaTemplate kafkaTemplate) { this.kafkaTemplate = kafkaTemplate; } public boolean sendMessage(String message) { - if (this.kafkaTopic == null) { - throw new RuntimeException("Property kafka.send.topic is null"); - } - ProducerRecord record = new ProducerRecord<>(this.kafkaTopic, message); + ProducerRecord record = new ProducerRecord<>(this.kafkaTopicName, message); try { this.kafkaTemplate.send(record).get(); logger.debug("Success send record: {}", record); diff --git a/backend/src/main/java/ervu/controller/EmployeeInformationFileUploadController.java b/backend/src/main/java/ervu/controller/EmployeeInformationFileUploadController.java new file mode 100644 index 00000000..14528068 --- /dev/null +++ b/backend/src/main/java/ervu/controller/EmployeeInformationFileUploadController.java @@ -0,0 +1,31 @@ +package ervu.controller; + +import ervu.service.fileupload.EmployeeInformationFileUploadService; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; + +/** + * @author Alexandr Shalaginov + */ +@RestController +public class EmployeeInformationFileUploadController { + private final EmployeeInformationFileUploadService fileUploadService; + + public EmployeeInformationFileUploadController(EmployeeInformationFileUploadService fileUploadService) { + this.fileUploadService = fileUploadService; + } + + @RequestMapping(value = "/file/upload/employee-information", method = RequestMethod.POST) + public ResponseEntity saveEmployeeInformationFile(@RequestParam("file") MultipartFile multipartFile) { + if (this.fileUploadService.saveEmployeeInformationFile(multipartFile)) { + return ResponseEntity.ok("File successfully uploaded."); + } + else { + return ResponseEntity.internalServerError().body("An error occurred while uploading file."); + } + } +} diff --git a/backend/src/main/java/ervu/controller/FileUploadV2Controller.java b/backend/src/main/java/ervu/controller/FileUploadV2Controller.java deleted file mode 100644 index d9a80dfa..00000000 --- a/backend/src/main/java/ervu/controller/FileUploadV2Controller.java +++ /dev/null @@ -1,35 +0,0 @@ -package ervu.controller; - -import ervu.service.fileupload.FileUploadV2Service; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.multipart.MultipartFile; - -import ru.cg.webbpm.modules.standard_annotations.validation.NotNull; -import ru.cg.webbpm.modules.webkit.beans.Behavior; - -/** - * @author Alexandr Shalaginov - */ -@RestController -public class FileUploadV2Controller extends Behavior { - @NotNull - public final FileUploadV2Service fileUploadV2Service; - - public FileUploadV2Controller(FileUploadV2Service fileUploadV2Service) { - this.fileUploadV2Service = fileUploadV2Service; - } - - @RequestMapping(value = "/file/upload", method = RequestMethod.POST) - public ResponseEntity saveFile(@RequestParam("file") MultipartFile multipartFile) { - if (this.fileUploadV2Service.saveFile(multipartFile)) { - return ResponseEntity.ok("File successfully uploaded."); - } - else { - return ResponseEntity.internalServerError().body("An error occurred while uploading file."); - } - } -} diff --git a/backend/src/main/java/ervu/service/fileupload/impl/ErvuFileUploadV2ServiceImpl.java b/backend/src/main/java/ervu/service/fileupload/EmployeeInformationFileUploadService.java similarity index 66% rename from backend/src/main/java/ervu/service/fileupload/impl/ErvuFileUploadV2ServiceImpl.java rename to backend/src/main/java/ervu/service/fileupload/EmployeeInformationFileUploadService.java index f9512532..c6cbc408 100644 --- a/backend/src/main/java/ervu/service/fileupload/impl/ErvuFileUploadV2ServiceImpl.java +++ b/backend/src/main/java/ervu/service/fileupload/EmployeeInformationFileUploadService.java @@ -1,12 +1,11 @@ -package ervu.service.fileupload.impl; +package ervu.service.fileupload; import java.util.UUID; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import ervu.client.fileupload.ErvuFileUploadClient; -import ervu.client.kafka.KafkaClient; -import ervu.service.fileupload.FileUploadV2Service; +import ervu.client.fileupload.EmployeeInformationFileWebDavUploadClient; +import ervu.client.kafka.KafkaSendMessageClient; import org.apache.commons.io.FilenameUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -19,24 +18,23 @@ import ru.cg.webbpm.modules.security.api.runtime.SecurityContext; * @author Alexandr Shalaginov */ @Service -public class ErvuFileUploadV2ServiceImpl implements FileUploadV2Service { - private static final Logger logger = LoggerFactory.getLogger(ErvuFileUploadV2ServiceImpl.class); - private final KafkaClient kafkaClient; +public class EmployeeInformationFileUploadService { + private static final Logger logger = LoggerFactory.getLogger(EmployeeInformationFileUploadService.class); + private final KafkaSendMessageClient kafkaClient; private final SecurityContext securityContext; - private final ErvuFileUploadClient ervuFileUploadClient; + private final EmployeeInformationFileWebDavUploadClient fileWebDavUploadClient; - public ErvuFileUploadV2ServiceImpl(ErvuFileUploadClient ervuFileUploadClient, - KafkaClient kafkaClient, SecurityContext securityContext) { - this.ervuFileUploadClient = ervuFileUploadClient; + public EmployeeInformationFileUploadService(EmployeeInformationFileWebDavUploadClient fileWebDavUploadClient, + KafkaSendMessageClient kafkaClient, SecurityContext securityContext) { + this.fileWebDavUploadClient = fileWebDavUploadClient; this.kafkaClient = kafkaClient; this.securityContext = securityContext; } - @Override - public boolean saveFile(MultipartFile multipartFile) { + public boolean saveEmployeeInformationFile(MultipartFile multipartFile) { String newFilename = getNewFilename(multipartFile.getOriginalFilename()); - if (this.ervuFileUploadClient.uploadFile(newFilename, multipartFile)) { + if (this.fileWebDavUploadClient.webDavUploadFile(newFilename, multipartFile)) { String jsonMessage = getJsonKafkaMessage( new KafkaMessage( securityContext.getCurrentUsername(), diff --git a/backend/src/main/java/ervu/service/fileupload/FileUploadV2Service.java b/backend/src/main/java/ervu/service/fileupload/FileUploadV2Service.java deleted file mode 100644 index 274a64bd..00000000 --- a/backend/src/main/java/ervu/service/fileupload/FileUploadV2Service.java +++ /dev/null @@ -1,10 +0,0 @@ -package ervu.service.fileupload; - -import org.springframework.web.multipart.MultipartFile; - -/** - * @author Alexandr Shalaginov - */ -public interface FileUploadV2Service { - boolean saveFile(MultipartFile multipartFile); -} diff --git a/backend/src/main/java/ervu/service/fileupload/impl/KafkaMessage.java b/backend/src/main/java/ervu/service/fileupload/KafkaMessage.java similarity index 95% rename from backend/src/main/java/ervu/service/fileupload/impl/KafkaMessage.java rename to backend/src/main/java/ervu/service/fileupload/KafkaMessage.java index 30c6cec6..af65b12f 100644 --- a/backend/src/main/java/ervu/service/fileupload/impl/KafkaMessage.java +++ b/backend/src/main/java/ervu/service/fileupload/KafkaMessage.java @@ -1,4 +1,4 @@ -package ervu.service.fileupload.impl; +package ervu.service.fileupload; /** * @author Alexandr Shalaginov diff --git a/frontend/src/ts/ervu/component/fileupload/FileUploadV2.ts b/frontend/src/ts/ervu/component/fileupload/FileUploadV2.ts index e57153f6..37c3fa23 100644 --- a/frontend/src/ts/ervu/component/fileupload/FileUploadV2.ts +++ b/frontend/src/ts/ervu/component/fileupload/FileUploadV2.ts @@ -49,7 +49,7 @@ export class FileUploadV2 extends InputControl { protected isProgressBarVisible: boolean = false; private fileInputEl: any; - private url: string = '/backend/file/upload'; + private url: string = '/backend/file/upload/employee-information'; private messagesService: MessagesService; constructor(el: ElementRef, cd: ChangeDetectorRef) { diff --git a/resources/src/main/resources/FileUploadV2.component b/resources/src/main/resources/FileUploadV2.component index 11a4763d..8ab4395e 100644 --- a/resources/src/main/resources/FileUploadV2.component +++ b/resources/src/main/resources/FileUploadV2.component @@ -44,21 +44,5 @@ - - - FileUploadV2Controller - ervu.controller - - true - true - - - fileUploadV2Service - - - - - -