Merge pull request #15 from Kitzanos/update-document-entity-fields
Updated Document entity
previous->/v1/document/uploadFile/call/{callId}
new->/v1/document/uploadFile/source/{sourceId}
This commit is contained in:
@@ -8,7 +8,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.gepafin.tendermanagement.enums.RoleStatusEnum;
|
||||
import net.gepafin.tendermanagement.enums.DocumentSourceTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.RoleStatusEnum;
|
||||
import net.gepafin.tendermanagement.model.response.*;
|
||||
import net.gepafin.tendermanagement.service.*;
|
||||
@@ -179,14 +179,14 @@ public class CallDao {
|
||||
}
|
||||
|
||||
|
||||
public List<DocumentEntity> convertToDocumentEntities(List<DocumentReq> documentReqList, CallEntity callEntity,
|
||||
public List<DocumentEntity> convertToDocumentEntities(List<DocumentReq> documentReqList, Long sourceId,
|
||||
DocumentTypeEnum documentType) {
|
||||
if (documentReqList == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<DocumentEntity> existingDocuments = documentRepository
|
||||
.findByCallIdAndTypeAndIsDeletedFalse(callEntity.getId(), documentType.getValue());
|
||||
.findBySourceIdAndTypeAndIsDeletedFalse(sourceId, documentType.getValue());
|
||||
|
||||
List<Long> incomingIds = documentReqList.stream().map(DocumentReq::getId).filter(id -> id != null && id > 0)
|
||||
.collect(Collectors.toList());
|
||||
@@ -194,7 +194,7 @@ public class CallDao {
|
||||
existingDocuments.stream().filter(document -> !incomingIds.contains(document.getId()))
|
||||
.forEach(this::softDeleteDocument);
|
||||
List<DocumentEntity> documentEntities = documentReqList.stream()
|
||||
.map(req -> convertToDocumentEntity(req, callEntity)).collect(Collectors.toList());
|
||||
.map(req -> convertToDocumentEntity(req, sourceId)).collect(Collectors.toList());
|
||||
documentRepository.saveAll(documentEntities);
|
||||
return documentEntities;
|
||||
}
|
||||
@@ -204,9 +204,9 @@ public class CallDao {
|
||||
documentRepository.save(documentEntity);
|
||||
}
|
||||
|
||||
private DocumentEntity convertToDocumentEntity(DocumentReq documentReq, CallEntity callEntity) {
|
||||
private DocumentEntity convertToDocumentEntity(DocumentReq documentReq,Long sourceId) {
|
||||
validateDocumentEntity(documentReq.getId());
|
||||
DocumentEntity documentEntity = documentRepository.findByIdAndCallIdAndIsDeletedFalse(documentReq.getId(), callEntity.getId())
|
||||
DocumentEntity documentEntity = documentRepository.findByIdAndSourceIdAndIsDeletedFalse(documentReq.getId(),sourceId)
|
||||
.orElseThrow(() -> new ResourceNotFoundException(Status.NOT_FOUND,
|
||||
Translator.toLocale(GepafinConstant.DOCUMENT_NOT_FOUND)));
|
||||
return documentEntity;
|
||||
@@ -287,7 +287,9 @@ public class CallDao {
|
||||
DocumentResponseBean responseBean = new DocumentResponseBean();
|
||||
responseBean.setId(entity.getId());
|
||||
responseBean.setName(entity.getFileName());
|
||||
responseBean.setDescription(entity.getDescription());
|
||||
responseBean.setType(DocumentTypeEnum.valueOf(entity.getType()));
|
||||
responseBean.setSource(DocumentSourceTypeEnum.valueOf(entity.getSource()));
|
||||
responseBean.setSourceId(entity.getSourceId());
|
||||
responseBean.setFilePath(entity.getFilePath());
|
||||
responseBean.setCreatedDate(entity.getCreatedDate());
|
||||
responseBean.setUpdatedDate(entity.getUpdatedDate());
|
||||
@@ -374,9 +376,9 @@ public class CallDao {
|
||||
callRepository.save(callEntity);
|
||||
convertToEvaluationCriteriaEntities(createCallRequest.getCriteria(), callEntity, LookUpDataTypeEnum.EVALUATION_CRITERIA);
|
||||
|
||||
convertToDocumentEntities(createCallRequest.getDocs(), callEntity, DocumentTypeEnum.DOCUMENT);
|
||||
convertToDocumentEntities(createCallRequest.getDocs(), callEntity.getId(), DocumentTypeEnum.DOCUMENT);
|
||||
|
||||
convertToDocumentEntities(createCallRequest.getImages(), callEntity, DocumentTypeEnum.IMAGES);
|
||||
convertToDocumentEntities(createCallRequest.getImages(), callEntity.getId(), DocumentTypeEnum.IMAGES);
|
||||
|
||||
updateLookUpData(callEntity, createCallRequest.getCheckList(), LookUpDataTypeEnum.CHECKLIST);
|
||||
|
||||
@@ -535,9 +537,9 @@ public class CallDao {
|
||||
}
|
||||
|
||||
private CallResponse getCallResponseBean(CallEntity callEntity) {
|
||||
List<DocumentEntity> documentEntities = documentRepository.findByCallIdAndTypeAndIsDeletedFalse(callEntity.getId(),
|
||||
List<DocumentEntity> documentEntities = documentRepository.findBySourceIdAndTypeAndIsDeletedFalse(callEntity.getId(),
|
||||
DocumentTypeEnum.DOCUMENT.getValue());
|
||||
List<DocumentEntity> imageEntities = documentRepository.findByCallIdAndTypeAndIsDeletedFalse(callEntity.getId(),
|
||||
List<DocumentEntity> imageEntities = documentRepository.findBySourceIdAndTypeAndIsDeletedFalse(callEntity.getId(),
|
||||
DocumentTypeEnum.IMAGES.getValue());
|
||||
List<LookUpDataResponse> amiedTo = callTargetAudienceChecklistRepository
|
||||
.findByCallIdAndLookupDataTypeAndIsDeletedFalse(callEntity.getId(), LookUpDataTypeEnum.AIMED_TO.getValue()).stream()
|
||||
|
||||
@@ -3,6 +3,7 @@ package net.gepafin.tendermanagement.dao;
|
||||
import java.io.IOException;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.gepafin.tendermanagement.enums.DocumentSourceTypeEnum;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -40,16 +41,17 @@ public class DocumentDao {
|
||||
@Autowired
|
||||
private CallService callService;
|
||||
|
||||
public List<DocumentResponseBean> uploadFiles(List<MultipartFile> files, Long callId, DocumentTypeEnum fileType) {
|
||||
public List<DocumentResponseBean> uploadFiles(List<MultipartFile> files, Long sourceId, DocumentSourceTypeEnum sourceType, DocumentTypeEnum fileType) {
|
||||
List<DocumentEntity> documentEntities = new ArrayList<>();
|
||||
CallEntity callEntity = callService.validateCall(callId);
|
||||
Long source = resolveSourceId(sourceId, sourceType);
|
||||
for (MultipartFile file : files) {
|
||||
try {
|
||||
uploadFileOnAmazonS3 result = uploadFileOnAmazonS3(file);
|
||||
if (result != null) {
|
||||
DocumentEntity documentEntity = new DocumentEntity();
|
||||
documentEntity.setFileName(result.fileName());
|
||||
documentEntity.setCall(callEntity);
|
||||
documentEntity.setSource(sourceType.getValue());
|
||||
documentEntity.setSourceId(source);
|
||||
documentEntity.setType(fileType.getValue());
|
||||
documentEntity.setFilePath(result.filepath());
|
||||
documentEntity.setIsDeleted(false);
|
||||
@@ -61,6 +63,18 @@ public class DocumentDao {
|
||||
documentRepository.saveAll(documentEntities);
|
||||
return documentEntities.stream().map(callDao::convertToDocumentResponseBean).collect(Collectors.toList());
|
||||
}
|
||||
private Long resolveSourceId(Long sourceId, DocumentSourceTypeEnum sourceType) {
|
||||
if (sourceType == DocumentSourceTypeEnum.CALL) {
|
||||
CallEntity callEntity = callService.validateCall(sourceId);
|
||||
return callEntity.getId();
|
||||
}
|
||||
// else if (sourceType == SourceTypeEnum.APPLICATION) {
|
||||
// ApplicationEntity applicationEntity = applicationService.validateApplication(sourceId);
|
||||
// return applicationEntity.getId(); // Assuming ApplicationEntity has getId()
|
||||
// }
|
||||
//
|
||||
return sourceId;
|
||||
}
|
||||
|
||||
private uploadFileOnAmazonS3 uploadFileOnAmazonS3(MultipartFile file) throws IOException {
|
||||
String extension = FilenameUtils.getExtension(file.getOriginalFilename());
|
||||
@@ -109,6 +123,8 @@ public class DocumentDao {
|
||||
documentEntity.setFilePath(result.filepath);
|
||||
documentEntity.setFileName(result.fileName);
|
||||
documentEntity.setType(documentTypeEnum.getValue());
|
||||
documentEntity.setSource(documentEntity.getSource());
|
||||
documentEntity.setSourceId(documentEntity.getSourceId());
|
||||
documentRepository.save(documentEntity);
|
||||
}
|
||||
return callDao.convertToDocumentResponseBean(documentEntity);
|
||||
|
||||
@@ -20,12 +20,11 @@ public class DocumentEntity extends BaseEntity{
|
||||
@Column(name="TYPE")
|
||||
private String type;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "CALL_ID")
|
||||
private CallEntity call;
|
||||
@Column(name="SOURCE")
|
||||
private String source;
|
||||
|
||||
@Column(name = "DESCRIPTION", columnDefinition = "TEXT")
|
||||
private String description;
|
||||
@Column(name="SOURCE_ID")
|
||||
private Long sourceId;
|
||||
|
||||
@Column(name ="IS_DELETED", nullable = false)
|
||||
private Boolean isDeleted = false;
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package net.gepafin.tendermanagement.enums;
|
||||
|
||||
public enum DocumentSourceTypeEnum {
|
||||
CALL("CALL"),
|
||||
|
||||
APPLICATION("APPLICATION");
|
||||
|
||||
private String value;
|
||||
|
||||
DocumentSourceTypeEnum(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
package net.gepafin.tendermanagement.model.response;
|
||||
|
||||
import lombok.Data;
|
||||
import net.gepafin.tendermanagement.enums.DocumentSourceTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.DocumentTypeEnum;
|
||||
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@@ -13,7 +16,11 @@ public class DocumentResponseBean {
|
||||
|
||||
private String filePath;
|
||||
|
||||
private String description;
|
||||
private DocumentTypeEnum type;
|
||||
|
||||
private DocumentSourceTypeEnum source;
|
||||
|
||||
private Long sourceId;
|
||||
|
||||
private LocalDateTime createdDate;
|
||||
|
||||
|
||||
@@ -15,9 +15,9 @@ public interface DocumentRepository extends JpaRepository<DocumentEntity, Long>
|
||||
@Query("SELECT d FROM DocumentEntity d WHERE d.id = :id AND d.isDeleted = false")
|
||||
Optional<DocumentEntity> findById(@Param("id") Long id);
|
||||
|
||||
List<DocumentEntity> findByCallIdAndTypeAndIsDeletedFalse(Long callId, String type);
|
||||
List<DocumentEntity> findBySourceIdAndTypeAndIsDeletedFalse(Long sourceId, String type);
|
||||
|
||||
Optional<DocumentEntity> findByIdAndCallIdAndIsDeletedFalse(Long id, Long callId);
|
||||
Optional<DocumentEntity> findByIdAndSourceIdAndIsDeletedFalse(Long id, Long sourceId);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.gepafin.tendermanagement.service;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import net.gepafin.tendermanagement.enums.DocumentSourceTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.DocumentTypeEnum;
|
||||
import net.gepafin.tendermanagement.model.response.DocumentResponseBean;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
@@ -9,7 +10,7 @@ import java.util.List;
|
||||
|
||||
public interface DocumentService {
|
||||
|
||||
public List<DocumentResponseBean> uploadFile(List<MultipartFile> files,Long callId, DocumentTypeEnum fileType);
|
||||
public List<DocumentResponseBean> uploadFile(List<MultipartFile> files, Long sourceId, DocumentSourceTypeEnum sourceType, DocumentTypeEnum fileType);
|
||||
|
||||
public void deleteFile(Long documentId);
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.util.List;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import net.gepafin.tendermanagement.dao.DocumentDao;
|
||||
import net.gepafin.tendermanagement.enums.DocumentSourceTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.DocumentTypeEnum;
|
||||
import net.gepafin.tendermanagement.model.response.DocumentResponseBean;
|
||||
import net.gepafin.tendermanagement.service.DocumentService;
|
||||
@@ -21,8 +22,8 @@ public class DocumentServiceImpl implements DocumentService {
|
||||
private DocumentDao documentDao;
|
||||
|
||||
@Override
|
||||
public List<DocumentResponseBean> uploadFile(List<MultipartFile> files,Long callId,DocumentTypeEnum fileType) {
|
||||
return documentDao.uploadFiles(files,callId,fileType);
|
||||
public List<DocumentResponseBean> uploadFile(List<MultipartFile> files, Long sourceId, DocumentSourceTypeEnum sourceType, DocumentTypeEnum fileType) {
|
||||
return documentDao.uploadFiles(files,sourceId,sourceType,fileType);
|
||||
}
|
||||
@Override
|
||||
public void deleteFile(Long documentId){
|
||||
|
||||
@@ -6,6 +6,7 @@ import io.swagger.v3.oas.annotations.media.Content;
|
||||
import io.swagger.v3.oas.annotations.media.ExampleObject;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import net.gepafin.tendermanagement.enums.DocumentSourceTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.DocumentTypeEnum;
|
||||
import net.gepafin.tendermanagement.model.response.DocumentResponseBean;
|
||||
import net.gepafin.tendermanagement.model.util.Response;
|
||||
@@ -29,8 +30,8 @@ public interface DocumentApi {
|
||||
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE) })),
|
||||
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE) }))})
|
||||
@PostMapping(value = "/uploadFile/call/{callId}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
default ResponseEntity<Response<List<DocumentResponseBean>>> uploadFile(HttpServletRequest httpServletRequest, @Parameter(description = "call id", required = true) @PathVariable("callId") Long callId, @RequestParam("file") List<MultipartFile> files, @RequestParam("documentType") DocumentTypeEnum documentTypeEnum) {
|
||||
@PostMapping(value = "/uploadFile/source/{sourceId}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
default ResponseEntity<Response<List<DocumentResponseBean>>> uploadFile(HttpServletRequest httpServletRequest, @Parameter(description = "Source Id", required = true) @PathVariable("sourceId") Long sourceId, @RequestParam DocumentSourceTypeEnum sourceType, @RequestParam("file") List<MultipartFile> files, @RequestParam("documentType") DocumentTypeEnum documentTypeEnum) {
|
||||
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package net.gepafin.tendermanagement.web.rest.api.impl;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import net.gepafin.tendermanagement.config.Translator;
|
||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||
import net.gepafin.tendermanagement.enums.DocumentSourceTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.DocumentTypeEnum;
|
||||
import net.gepafin.tendermanagement.model.response.DocumentResponseBean;
|
||||
import net.gepafin.tendermanagement.model.util.Response;
|
||||
@@ -27,10 +28,10 @@ DocumentApiController implements DocumentApi {
|
||||
private DocumentService documentService;
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Response<List<DocumentResponseBean>>> uploadFile(HttpServletRequest httpServletRequest, Long callId,
|
||||
public ResponseEntity<Response<List<DocumentResponseBean>>> uploadFile(HttpServletRequest httpServletRequest, Long sourceId, DocumentSourceTypeEnum sourceType,
|
||||
List<MultipartFile> files, DocumentTypeEnum fileType) {
|
||||
try {
|
||||
List<DocumentResponseBean> responseBeans = documentService.uploadFile(files, callId, fileType);
|
||||
List<DocumentResponseBean> responseBeans = documentService.uploadFile(files, sourceId,sourceType, fileType);
|
||||
return ResponseEntity.status(HttpStatus.CREATED)
|
||||
.body(new Response<List<DocumentResponseBean>>(responseBeans, Status.SUCCESS, Translator.toLocale(GepafinConstant.FILES_UPLOADED_MSG)));
|
||||
} catch (CustomValidationException ex) {
|
||||
|
||||
@@ -540,15 +540,15 @@
|
||||
columnName="order_no" />
|
||||
</changeSet>
|
||||
|
||||
<changeSet id="03-09-2024_1" author="Rajesh Khore">
|
||||
<sql>
|
||||
TRUNCATE TABLE FORM_FIELD RESTART IDENTITY;
|
||||
</sql>
|
||||
<sqlFile dbms="postgresql"
|
||||
<changeSet id="03-09-2024_1" author="Rajesh Khore">
|
||||
<sql>
|
||||
TRUNCATE TABLE FORM_FIELD RESTART IDENTITY;
|
||||
</sql>
|
||||
<sqlFile dbms="postgresql"
|
||||
path="db/dump/update_form_field_data_04_09_2024.sql" />
|
||||
</changeSet>
|
||||
</changeSet>
|
||||
|
||||
<changeSet id="04-09-2024_1" author="Rajesh Khore">
|
||||
<changeSet id="04-09-2024_1" author="Rajesh Khore">
|
||||
<dropColumn tableName="FAQ" columnName="question_short" />
|
||||
<dropColumn tableName="FAQ" columnName="question" />
|
||||
<dropColumn tableName="FAQ" columnName="response_short" />
|
||||
@@ -564,6 +564,15 @@
|
||||
<modifyDataType tableName="LOOKUP_DATA" columnName="title" newDataType="TEXT"/>
|
||||
</changeSet>
|
||||
|
||||
<changeSet id="09-09-2024_2" author="Harish Bagora">
|
||||
<renameColumn tableName="document" oldColumnName="call_id" newColumnName="source_id" columnDataType="BIGINT"/>
|
||||
<addColumn tableName="document">
|
||||
<column name="source" type="VARCHAR(255)"/>
|
||||
</addColumn>
|
||||
<dropColumn tableName="document" columnName="description"/>
|
||||
<dropForeignKeyConstraint baseTableName="document" constraintName="fk_call_document"/>
|
||||
</changeSet>
|
||||
|
||||
<changeSet id="09-09-2024_1" author="Rajesh Khore">
|
||||
<createTable tableName="application_form">
|
||||
<column name="id" type="INTEGER" autoIncrement="true">
|
||||
|
||||
Reference in New Issue
Block a user