Commit dc869573 authored by Roberto Loayza's avatar Roberto Loayza

Update Models and File Deployment

parent 3816c6e8
......@@ -6,7 +6,6 @@ import lombok.ToString;
import javax.persistence.*;
//AVB_INTENT
@Cacheable(false)
@Entity
@Getter @Setter @ToString
......
......@@ -17,6 +17,7 @@ public class FileValidationResponse {
private String status;
private String user;
private String uploadDate;
private String menssage;
private FileValidationResult fileValidationResult;
}
......@@ -14,7 +14,7 @@ import javax.persistence.*;
import java.io.Serializable;
import java.util.List;
//@Audited
@Audited
@Entity
@Getter @Setter @EqualsAndHashCode(of = "id")
@NoArgsConstructor
......
......@@ -11,7 +11,7 @@ import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.NamedQuery;
//@Audited
@Audited
@Entity
@DiscriminatorValue(value=AnnualCalendarException.DISCRIMINATOR_VALUE)
@NamedQuery(name = "AnnualCalendarException.findByPK", query = "Select u from AnnualCalendarException u where u.id = ?1")
......
......@@ -49,10 +49,6 @@ public class CalendarExceptionFull implements Serializable {
@Column(name = "CALE_ID")
private String calendarID;
// @ManyToOne(optional = false)
// @JoinColumn(name = "CALE_ID", referencedColumnName = "CALE_ID", nullable = false)
// private Calendar calendar;
@Column(name = "CALE_EXC_MONTH")
private BigInteger month;
......
......@@ -22,7 +22,7 @@ import java.util.List;
* Confidencial y debe usarla de acuerdo con los términos de aceptación de
* licencia de uso que firmó con Byte.
*/
//@Audited
@Audited
@Entity
@Table(name = "AVB_DEPLOYMENT_CHANNEL")
@Getter
......
......@@ -19,7 +19,7 @@ import javax.persistence.*;
* Confidencial y debe usarla de acuerdo con los términos de aceptación de
* licencia de uso que firmó con Byte.
*/
//@Audited
@Audited
@Entity
@Table(name = "AVB_DEPLOYMENT_CHANNEL_PARAM_VALUE")
@Getter
......
......@@ -25,7 +25,7 @@ import java.time.OffsetDateTime;
* Confidencial y debe usarla de acuerdo con los términos de aceptación de
* licencia de uso que firmó con Byte.
*/
//@Audited
@Audited
@Entity
@Table(name = "AVB_FREQUENT_QUESTION")
@Getter
......
......@@ -16,7 +16,7 @@ import lombok.ToString;
import org.hibernate.annotations.Type;
import org.hibernate.envers.Audited;
//@Audited
@Audited
@Entity
@Getter
@Setter
......
......@@ -41,6 +41,10 @@ public class BucketService {
@Value("${application.bucket.modelBucket}")
private String modelDir;
@Value("${application.bucket.version}")
private String version;
@Autowired
private QuestionFileRepository questionFileRepository;
......@@ -55,20 +59,20 @@ public class BucketService {
public boolean generate(byte[] file, FileValidationResponse response) {
Optional<BusinessParameter> businessParameter = businessParameterRepository.findByKey("Bucket");
boolean result = false;
if (!businessParameter.isPresent()) {
throw new NotFoundException("No existe el parametro de negocio del bucket.");
throw new NotFoundException();
}
boolean result = false;
String bucketName = businessParameter.get().getDefaultValue();
File mainFile = new File(response.getFileName());
try {
FileOutputStream stream = new FileOutputStream(mainFile);
stream.write(file);
String newFile = String.format("%s/%s/1.0/%s/%s",tenant, response.getUuid(), fileDir, mainFile.getName());
String newFile = String.format("%s/%s/%s/%s/%s",tenant, response.getUuid(), version, fileDir, mainFile.getName());
PutObjectRequest request = new PutObjectRequest(bucketName, newFile, mainFile);
AmazonS3 amazonS3 = getS3Client();
amazonS3.putObject(request);
String modelFile = String.format("%s/%s/1.0/%s",tenant, response.getUuid(), modelDir);
String modelFile = String.format("%s/%s/%s/%s",tenant, response.getUuid(), version, modelDir);
createFolder(bucketName, modelFile, amazonS3);
mainFile.delete();
result = true;
......@@ -99,9 +103,9 @@ public class BucketService {
if (!questionFile.isPresent()) {
throw new NotFoundException("El uuid no se encuentra enlazado con un file");
}
String keyName = String.format("%s/%s/1.0/%s/%s",tenant, uuid, fileDir, questionFile.get().getName());
String keyName = String.format("%s/%s/%s/%s/%s",tenant, uuid, version, fileDir, questionFile.get().getName());
s3Client.deleteObject(new DeleteObjectRequest(bucketName, keyName));
keyName = String.format("%s/%s/1.0/%s/",tenant, uuid, modelDir);
keyName = String.format("%s/%s/%s/%s/",tenant, uuid, version, modelDir);
s3Client.deleteObject(new DeleteObjectRequest(bucketName, keyName));
} catch (AmazonServiceException e) {
e.printStackTrace();
......
......@@ -27,10 +27,13 @@ public class KnowledgeService {
@Value("${application.knowledge.url}")
private String url;
@Value("${application.bucket.version}")
private String version;
public boolean generate(FileValidationResponse response) throws IOException {
boolean result = false;
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpPost httppost = new HttpPost(String.format("%s/clients/%s/versions/1.0", url, tenant));
HttpPost httppost = new HttpPost(String.format("%s/clients/%s/versions/%s", url, tenant, version));
String json = String.format("{\"filename_csv\": \"%s\", \"index_name\": \"%s\"}",response.getFileName(), response.getUuid());
StringEntity entity = new StringEntity(json);
try {
......@@ -52,7 +55,7 @@ public class KnowledgeService {
if (status.equals("success")){
result = true;
}
} catch (IOException e) {
} catch (Exception e) {
log.error(e.getMessage());
}
return result;
......@@ -61,7 +64,7 @@ public class KnowledgeService {
public boolean delete(String uuid) {
boolean result = false;
try {
HttpDelete httpDelete = new HttpDelete(String.format("%s/clients/%s/indexes/%s/versions/1.0", url, tenant, uuid));
HttpDelete httpDelete = new HttpDelete(String.format("%s/clients/%s/indexes/%s/versions/%s", url, tenant, uuid, version));
System.out.println("Executing request " + httpDelete.getRequestLine());
ResponseHandler<String> responseHandler = response -> {
int status = response.getStatusLine().getStatusCode();
......
......@@ -18,7 +18,6 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.Optional;
@Service
......@@ -49,7 +48,12 @@ public class OrquestadorService {
FileValidationResponse response = new FileValidationResponse();
boolean step = false;
try{
//Modo de despliegue
Optional<BusinessParameter> deployment = businessParameterRepository.findByKey("Despliegue");
if (!deployment.isPresent()) {
response.setMenssage("NOT.FOUND.BUSINESS.PARAMETER");
throw new NotFoundException();
}
//Valida y guarda en base de datos
response = fileManagementService.saveFile(uuid, file);
if(response.getFileValidationResult().getStatus().getName() != ValidationStatusEnum.OK.getName()) {
......@@ -63,16 +67,12 @@ public class OrquestadorService {
model.setStatus(StatusBcdEnum.CARGADO.getName());
model = bdcControlRepository.save(model);
//Modo de despliegue
Optional<BusinessParameter> deployment = businessParameterRepository.findByKey("Despliegue");
if (!deployment.isPresent()) {
throw new NotFoundException("Modo de despliegue no encontrado");
}
if (deployment.get().getDefaultValue().equalsIgnoreCase("onCloud")) {
//Carga archivo a bucket
step = bucketService.generate(file.getBytes(), response);
if (!step) {
throw new NotFoundException("Error a cargar archivo.");
response.setMenssage("NOT.FOUND.BUCKET");
throw new NotFoundException();
}
step = false;
model.setStatus(StatusBcdEnum.INDEXANDO.getName());
......@@ -82,35 +82,47 @@ public class OrquestadorService {
//Generacion del modelo
step = knowledgeService.generate(response);
if (!step) {
throw new NotFoundException("Error a cargar archivo.");
response.setMenssage("NOT.FOUND.KNOWLEDGE");
throw new NotFoundException();
}
response.setStatus(FrequentQuestionStatusEnum.CORRECTO.getName());
model.setStatus(StatusBcdEnum.INDEXADO.getName());
model = bdcControlRepository.save(model);
}catch (Exception e) {
System.out.println(e.getMessage());
if (response.getMenssage() == null) {
response.setMenssage("ERROR.UPLOAD");
}
response.setStatus(FrequentQuestionStatusEnum.ERROR.getName());
}
return response;
}
public FileValidationResponse retry(String uuid) {
Optional<BdcControl> modelBdc = bdcControlRepository.findByUuid(uuid);
if (!modelBdc.isPresent()) {
throw new NotFoundException("No se subio archivo a la BD");
throw new NotFoundException("NOT.FOUND.DATA.CONTROL");
}
boolean step = false;
BdcControl model = modelBdc.get();
FileValidationResponse response = modelToFileValidation(model);
try {
Optional<BusinessParameter> deployment = businessParameterRepository.findByKey("Despliegue");
if (!deployment.isPresent()) {
response.setMenssage("NOT.FOUND.BUSINESS.PARAMETER");
throw new NotFoundException();
}
if (model.getStatus().equals(StatusBcdEnum.CARGADO.getName())) {
Optional<QuestionFile> questionFile = questionFileRepository.findByUuid(uuid);
if (!questionFile.isPresent()) {
throw new NotFoundException("No se encontro archivo en la BD");
response.setMenssage("NOT.FOUND.DATA");
throw new NotFoundException();
}
step = bucketService.generate(questionFile.get().getData(), response);
if (!step) {
throw new NotFoundException("Error a cargar archivo.");
response.setMenssage("NOT.FOUND.BUCKET");
throw new NotFoundException();
}
model.setStatus(StatusBcdEnum.INDEXANDO.getName());
model = bdcControlRepository.save(model);
......@@ -119,13 +131,17 @@ public class OrquestadorService {
if (model.getStatus().equals(StatusBcdEnum.INDEXANDO.getName())) {
step = knowledgeService.generate(response);
if (!step) {
throw new NotFoundException("Error a cargar knowledge.");
response.setMenssage("NOT.FOUND.KNOWLEDGE");
throw new NotFoundException();
}
}
model.setStatus(StatusBcdEnum.INDEXADO.getName());
model = bdcControlRepository.save(model);
response.setStatus(FrequentQuestionStatusEnum.CORRECTO.getName());
} catch (IOException e) {
} catch (Exception e) {
if (response.getMenssage() == null) {
response.setMenssage("ERROR.UPLOAD");
}
response.setStatus(FrequentQuestionStatusEnum.ERROR.getName());
}
return response;
......
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