Commit 0631a1b3 authored by huriarte's avatar huriarte

Logica de Negocio para el manejo de archivos cargados

con validacion de formato
parent cf6d3f18
<?xml version="1.0" encoding="UTF-8"?>
<project-shared-configuration>
<!--
This file contains additional configuration written by modules in the NetBeans IDE.
The configuration is intended to be shared among all the users of project and
therefore it is assumed to be part of version control checkout.
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
-->
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
<!--
Properties that influence various parts of the IDE, especially code formatting and the like.
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
That way multiple projects can share the same settings (useful for formatting rules for example).
Any value defined here will override the pom.xml file value but is only applicable to the current project.
-->
<netbeans.hint.jdkPlatform>JDK_1.8</netbeans.hint.jdkPlatform>
</properties>
</project-shared-configuration>
<?xml version="1.0" encoding="UTF-8"?>
<actions>
<action>
<actionName>run</actionName>
<packagings>
<packaging>jar</packaging>
</packagings>
<goals>
<goal>process-classes</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:1.5.0:exec</goal>
</goals>
<properties>
<exec.args>-classpath %classpath com.bytesw.bytebot.BytebotApplication -Djasypt.encryptor.password=179CD78D24F9BC63D6E677272D1A7 -Xms256M -Xmx512M</exec.args>
<exec.executable>java</exec.executable>
</properties>
</action>
<action>
<actionName>debug</actionName>
<packagings>
<packaging>jar</packaging>
</packagings>
<goals>
<goal>process-classes</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:1.5.0:exec</goal>
</goals>
<properties>
<exec.args>-agentlib:jdwp=transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath com.bytesw.bytebot.BytebotApplication -Djasypt.encryptor.password=179CD78D24F9BC63D6E677272D1A7 -Xms256M -Xmx512M</exec.args>
<exec.executable>java</exec.executable>
<jpda.listen>true</jpda.listen>
</properties>
</action>
<action>
<actionName>profile</actionName>
<packagings>
<packaging>jar</packaging>
</packagings>
<goals>
<goal>process-classes</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:1.5.0:exec</goal>
</goals>
<properties>
<exec.args>-classpath %classpath com.bytesw.bytebot.BytebotApplication -Djasypt.encryptor.password=179CD78D24F9BC63D6E677272D1A7 -Xms256M -Xmx512M</exec.args>
<exec.executable>java</exec.executable>
</properties>
</action>
</actions>
<?xml version="1.0" encoding="UTF-8"?>
<actions>
<action>
<actionName>CUSTOM-clean install no test</actionName>
<displayName>clean install no test</displayName>
<goals>
<goal>clean</goal>
<goal>install</goal>
</goals>
<properties>
<skipTests>true</skipTests>
<dockerfile.skip>true</dockerfile.skip>
</properties>
</action>
</actions>
......@@ -12,7 +12,7 @@
<artifactId>bytebot-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>${packaging.type}</packaging>
<packaging>jar</packaging>
<properties>
<xdf.version>3.1.0</xdf.version>
......@@ -160,6 +160,7 @@
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.2</version>
</dependency>
<!-- websocket-->
......
......@@ -3,14 +3,15 @@ package com.bytesw.bytebot.controller;
import com.bytesw.bytebot.bean.AgentBean;
import com.bytesw.bytebot.controller.bean.ResponseController;
import com.bytesw.bytebot.http.FileValidationResponse;
import com.bytesw.bytebot.service.AgentService;
import com.bytesw.bytebot.service.FileManagementService;
import com.bytesw.xdf.annotation.ProgramSecurity;
import com.bytesw.xdf.sql.beans.Pagination;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import java.util.UUID;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -18,6 +19,7 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@Log4j2
@RestController
......@@ -27,6 +29,9 @@ public class AgentController {
@Autowired
private AgentService agentService;
@Autowired
private FileManagementService fileManagementService;
@Autowired
private GsonBuilder gsonBuilder;
......@@ -155,4 +160,18 @@ public class AgentController {
return new ResponseEntity<>(gsonBuilder.create().toJson(ExceptionUtils.getFullStackTrace(e)), hs);
}
}
@PostMapping("/file-upload")
public ResponseEntity<String> uploadFile(@RequestParam("file") MultipartFile file) {
Gson gson = new GsonBuilder().create();
try {
String uuid = UUID.randomUUID().toString();
FileValidationResponse response = fileManagementService.validateAndSaveFile(uuid, file);
return new ResponseEntity<>(gson.toJson(response), HttpStatus.OK);
} catch (Exception e) {
e.printStackTrace();
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.bytesw.bytebot.http;
import lombok.Getter;
import lombok.Setter;
@Getter @Setter
public class FileValidationResponse {
private Long id;
private String uuid;
private String fileName;
private String status;
private FileValidationResult fileValidationResult;
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.bytesw.bytebot.http;
import com.bytesw.bytebot.http.enums.ValidationStatusEnum;
import java.util.Map;
import lombok.Getter;
import lombok.Setter;
@Getter @Setter
public class FileValidationResult {
private ValidationStatusEnum status;
private Map<String, String> headersErrorMap;
private Map<Integer, Object> recordsErrorMap;
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.bytesw.bytebot.http.enums;
import java.util.HashMap;
import java.util.Map;
import java.util.NoSuchElementException;
public enum ValidationStatusEnum {
OK("OK"),
INCOMPATIBLE_EXTENSION("IE"),
HEADER_ERROR ("HE"),
CONTENT_ERROR("CE");
private final String name;
private static final Map<String, ValidationStatusEnum> map = new HashMap<>();
static {
for (ValidationStatusEnum type : ValidationStatusEnum.values()) {
map.put(type.name, type);
}
}
ValidationStatusEnum(String name) {
this.name = name;
}
public String getName() {
return name;
}
public static ValidationStatusEnum fromString(String name) {
if (map.containsKey(name)) {
return map.get(name);
}
throw new NoSuchElementException(name + " not found");
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.bytesw.bytebot.model;
import java.time.LocalDateTime;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
@Entity
@Getter
@Setter
@ToString
@EqualsAndHashCode(of = "id")
@NoArgsConstructor
@Table(name = "BBOT_QUESTION_FILE")
@NamedQuery(name = "QuestionFile.findByPK", query = "Select u from QuestionFile u where u.id = ?1")
public class QuestionFile {
@Id
@Column(name = "QUFI_ID")
@TableGenerator(name = "BBOT_QUESTION_FILE_GENERATOR", table = "SEQUENCE_TABLE", pkColumnName = "SEQ_NAME",
valueColumnName = "SEQ_COUNT", pkColumnValue = "BBOT_QUESTION_FILE_SEQ", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.TABLE, generator = "BBOT_QUESTION_FILE_GENERATOR")
private Long id;
@Column(name = "QUFI_UUID", nullable = false)
private String uuid;
@Column(name = "QUFI_NAME", nullable = false)
private String name;
@Column(name = "QUFI_SIZE", nullable = false)
private Long size;
@Column(name = "QUFI_UDATE", columnDefinition = "TIMESTAMP")
private LocalDateTime uploadDate;
@Lob
@Basic(fetch = FetchType.LAZY)
@Column(name = "QUFI_DATA", length= 100000, nullable = false)
private byte[] data;
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.bytesw.bytebot.model.converters;
import com.bytesw.bytebot.model.enums.FileQuestionStatusEnum;
import javax.persistence.AttributeConverter;
import org.apache.camel.Converter;
/**
* @author Hernán Uriarte Melchor
* @version 13-sep-2020
*
* Copyright (c) 2020 Byte, S.A. Todos los derechos reservados.
*
* Este software constituye información confidencial y propietaria de Byte, S.A.
* ("Información Confidencial"). Usted no debe develar dicha Información
* Confidencial y debe usarla de acuerdo con los términos de aceptación de
* licencia de uso que firmó con Byte.
*/
@Converter
public class FileQuestionStatusConverter implements AttributeConverter<FileQuestionStatusEnum, String> {
@Override
public String convertToDatabaseColumn(FileQuestionStatusEnum value) {
return value.getName();
}
@Override
public FileQuestionStatusEnum convertToEntityAttribute(String value) {
return FileQuestionStatusEnum.fromString(value);
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.bytesw.bytebot.model.enums;
import java.util.HashMap;
import java.util.Map;
import lombok.Getter;
/**
* @author Hernán Uriarte Melchor
* @version 13-sep-2020
*
* Copyright (c) 2020 Byte, S.A. Todos los derechos reservados.
*
* Este software constituye información confidencial y propietaria de Byte, S.A.
* ("Información Confidencial"). Usted no debe develar dicha Información
* Confidencial y debe usarla de acuerdo con los términos de aceptación de
* licencia de uso que firmó con Byte.
*/
@Getter
public enum FileQuestionStatusEnum {
ACTIVE("AC"),
LOADED("LO"),
DISABLED("DI");
private static final Map<String, FileQuestionStatusEnum> map = new HashMap<>();
private String name;
FileQuestionStatusEnum(String name) {
this.name = name;
}
static {
for (FileQuestionStatusEnum type : FileQuestionStatusEnum.values()) {
map.put(type.name, type);
}
}
public static FileQuestionStatusEnum fromString(String name) {
return map.get(name);
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.bytesw.bytebot.repository;
import com.bytesw.bytebot.model.QuestionFile;
import org.springframework.data.repository.CrudRepository;
/**
* @author Hernán Uriarte Melchor.
* @version 13-sep-2020
* <p>
* Copyright (c) 2020 Byte, S.A. Todos los derechos reservados.
* <p>
* Este software constituye información confidencial y propietaria de Byte, S.A.
* ("Información Confidencial"). Usted no debe develar dicha Información
* Confidencial y debe usarla de acuerdo con los términos de aceptación de
* licencia de uso que firmó con Byte.
*/
public interface QuestionFileRepository extends CrudRepository<QuestionFile, Long> {
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.bytesw.bytebot.utils;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Utilities {
public static String convertDateToString(Date date, String format){
DateFormat formatter = new SimpleDateFormat(format);
return formatter.format(date);
}
}
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