refactor: reformat code(attachment)
This commit is contained in:
@@ -1,9 +1,12 @@
|
|||||||
package org.egovframe.cloud.portalservice.api.attachment.dto;
|
package org.egovframe.cloud.portalservice.api.attachment.dto;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
import org.egovframe.cloud.portalservice.domain.attachment.Attachment;
|
||||||
|
import org.egovframe.cloud.portalservice.domain.attachment.AttachmentId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* org.egovframe.cloud.portalservice.api.attachment.dto.AttachmentFileResponseDto
|
* org.egovframe.cloud.portalservice.api.attachment.dto.AttachmentFileResponseDto
|
||||||
@@ -36,4 +39,17 @@ public class AttachmentFileResponseDto extends AttachmentUploadResponseDto {
|
|||||||
this.size = size;
|
this.size = size;
|
||||||
this.physicalFileName = physicalFileName;
|
this.physicalFileName = physicalFileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Attachment toEntity(AttachmentId attachmentId, AttachmentUploadRequestDto uploadRequestDto) {
|
||||||
|
return Attachment.builder()
|
||||||
|
.attachmentId(attachmentId)
|
||||||
|
.uniqueId(UUID.randomUUID().toString())
|
||||||
|
.physicalFileName(this.physicalFileName)
|
||||||
|
.originalFileName(this.originalFileName)
|
||||||
|
.size(this.size)
|
||||||
|
.fileType(this.fileType)
|
||||||
|
.entityName(uploadRequestDto.getEntityName())
|
||||||
|
.entityId(uploadRequestDto.getEntityId())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
package org.egovframe.cloud.portalservice.api.attachment.dto;
|
package org.egovframe.cloud.portalservice.api.attachment.dto;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.UUID;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
import org.egovframe.cloud.portalservice.domain.attachment.Attachment;
|
||||||
|
import org.egovframe.cloud.portalservice.domain.attachment.AttachmentId;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -55,4 +58,17 @@ public class AttachmentTempSaveRequestDto {
|
|||||||
public boolean hasUniqueId() {
|
public boolean hasUniqueId() {
|
||||||
return Objects.nonNull(uniqueId) || StringUtils.hasText(uniqueId);
|
return Objects.nonNull(uniqueId) || StringUtils.hasText(uniqueId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Attachment toEntity(AttachmentId attachmentId, String physicalFileName) {
|
||||||
|
return Attachment.builder()
|
||||||
|
.attachmentId(attachmentId)
|
||||||
|
.uniqueId(UUID.randomUUID().toString())
|
||||||
|
.physicalFileName(physicalFileName)
|
||||||
|
.originalFileName(this.originalName)
|
||||||
|
.size(this.size)
|
||||||
|
.fileType(this.fileType)
|
||||||
|
.entityName(this.entityName)
|
||||||
|
.entityId(this.entityId)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -242,18 +242,7 @@ public class AttachmentService extends AbstractService {
|
|||||||
// 첨부파일 .temp 제거
|
// 첨부파일 .temp 제거
|
||||||
String renameTemp = storageUtils.renameTemp(requestDto.getPhysicalFileName());
|
String renameTemp = storageUtils.renameTemp(requestDto.getPhysicalFileName());
|
||||||
|
|
||||||
attachmentRepository.save(
|
attachmentRepository.save(requestDto.toEntity(attachmentId, renameTemp));
|
||||||
Attachment.builder()
|
|
||||||
.attachmentId(attachmentId)
|
|
||||||
.uniqueId(UUID.randomUUID().toString())
|
|
||||||
.physicalFileName(renameTemp)
|
|
||||||
.originalFileName(requestDto.getOriginalName())
|
|
||||||
.size(requestDto.getSize())
|
|
||||||
.fileType(requestDto.getFileType())
|
|
||||||
.entityName(requestDto.getEntityName())
|
|
||||||
.entityId(requestDto.getEntityId())
|
|
||||||
.build()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return attachmentCode;
|
return attachmentCode;
|
||||||
}
|
}
|
||||||
@@ -282,18 +271,8 @@ public class AttachmentService extends AbstractService {
|
|||||||
AttachmentId attachmentId = attachmentRepository.getId(attachmentCode);
|
AttachmentId attachmentId = attachmentRepository.getId(attachmentCode);
|
||||||
//새로운 첨부파일 저장 (물리적 파일 .temp 제거)
|
//새로운 첨부파일 저장 (물리적 파일 .temp 제거)
|
||||||
String renameTemp = storageUtils.renameTemp(saveRequestDto.getPhysicalFileName());
|
String renameTemp = storageUtils.renameTemp(saveRequestDto.getPhysicalFileName());
|
||||||
attachmentRepository.save(
|
|
||||||
Attachment.builder()
|
attachmentRepository.save(saveRequestDto.toEntity(attachmentId, renameTemp));
|
||||||
.attachmentId(attachmentId)
|
|
||||||
.uniqueId(UUID.randomUUID().toString())
|
|
||||||
.originalFileName(saveRequestDto.getOriginalName())
|
|
||||||
.physicalFileName(renameTemp)
|
|
||||||
.size(saveRequestDto.getSize())
|
|
||||||
.fileType(saveRequestDto.getFileType())
|
|
||||||
.entityName(saveRequestDto.getEntityName())
|
|
||||||
.entityId(saveRequestDto.getEntityId())
|
|
||||||
.build()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -353,18 +332,7 @@ public class AttachmentService extends AbstractService {
|
|||||||
// 물리적 파일 생성
|
// 물리적 파일 생성
|
||||||
AttachmentFileResponseDto fileResponseDto = upload(files.get(i), BASE_PATH, false);
|
AttachmentFileResponseDto fileResponseDto = upload(files.get(i), BASE_PATH, false);
|
||||||
|
|
||||||
attachmentRepository.save(
|
attachmentRepository.save(fileResponseDto.toEntity(attachmentId, uploadRequestDto));
|
||||||
Attachment.builder()
|
|
||||||
.attachmentId(attachmentId)
|
|
||||||
.uniqueId(UUID.randomUUID().toString())
|
|
||||||
.physicalFileName(fileResponseDto.getPhysicalFileName())
|
|
||||||
.originalFileName(fileResponseDto.getOriginalFileName())
|
|
||||||
.size(fileResponseDto.getSize())
|
|
||||||
.fileType(fileResponseDto.getFileType())
|
|
||||||
.entityName(uploadRequestDto.getEntityName())
|
|
||||||
.entityId(uploadRequestDto.getEntityId())
|
|
||||||
.build()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return attachmentCode;
|
return attachmentCode;
|
||||||
@@ -388,16 +356,9 @@ public class AttachmentService extends AbstractService {
|
|||||||
List<AttachmentUpdateRequestDto> updateRequestDtoList) throws EntityNotFoundException {
|
List<AttachmentUpdateRequestDto> updateRequestDtoList) throws EntityNotFoundException {
|
||||||
|
|
||||||
// 기존 파일 삭제 처리
|
// 기존 파일 삭제 처리
|
||||||
if (updateRequestDtoList != null) {
|
deleteExistingFile(updateRequestDtoList);
|
||||||
for (AttachmentUpdateRequestDto saveRequestDto : updateRequestDtoList) {
|
|
||||||
if (saveRequestDto.getIsDelete()) {
|
|
||||||
Attachment attachment = findAttachmentByUniqueId(saveRequestDto.getUniqueId());
|
|
||||||
attachment.updateIsDelete(saveRequestDto.getIsDelete());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (files != null) {
|
if (Objects.nonNull(files)) {
|
||||||
//새로운 파일 저장 처리
|
//새로운 파일 저장 처리
|
||||||
for (int i = 0; i < files.size(); i++) {
|
for (int i = 0; i < files.size(); i++) {
|
||||||
// 해당 attachment에 seq 조회해서 attachmentid 생성
|
// 해당 attachment에 seq 조회해서 attachmentid 생성
|
||||||
@@ -406,18 +367,7 @@ public class AttachmentService extends AbstractService {
|
|||||||
// 물리적 파일 생성
|
// 물리적 파일 생성
|
||||||
AttachmentFileResponseDto fileResponseDto = upload(files.get(i), BASE_PATH, false);
|
AttachmentFileResponseDto fileResponseDto = upload(files.get(i), BASE_PATH, false);
|
||||||
|
|
||||||
attachmentRepository.save(
|
attachmentRepository.save(fileResponseDto.toEntity(attachmentId, uploadRequestDto));
|
||||||
Attachment.builder()
|
|
||||||
.attachmentId(attachmentId)
|
|
||||||
.uniqueId(UUID.randomUUID().toString())
|
|
||||||
.physicalFileName(fileResponseDto.getPhysicalFileName())
|
|
||||||
.originalFileName(fileResponseDto.getOriginalFileName())
|
|
||||||
.size(fileResponseDto.getSize())
|
|
||||||
.fileType(fileResponseDto.getFileType())
|
|
||||||
.entityName(uploadRequestDto.getEntityName())
|
|
||||||
.entityId(uploadRequestDto.getEntityId())
|
|
||||||
.build()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -425,6 +375,7 @@ public class AttachmentService extends AbstractService {
|
|||||||
return attachmentCode;
|
return attachmentCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* entity 정보 update
|
* entity 정보 update
|
||||||
*
|
*
|
||||||
@@ -491,4 +442,21 @@ public class AttachmentService extends AbstractService {
|
|||||||
.orElseThrow(() -> new EntityNotFoundException(getMessage("valid.file.not_found") + " ID= " + uniqueId));
|
.orElseThrow(() -> new EntityNotFoundException(getMessage("valid.file.not_found") + " ID= " + uniqueId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 기존 첨부파일 삭제 처리
|
||||||
|
*
|
||||||
|
* @param updateRequestDtoList
|
||||||
|
*/
|
||||||
|
private void deleteExistingFile(List<AttachmentUpdateRequestDto> updateRequestDtoList) {
|
||||||
|
if (Objects.isNull(updateRequestDtoList)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (AttachmentUpdateRequestDto saveRequestDto : updateRequestDtoList) {
|
||||||
|
if (saveRequestDto.getIsDelete()) {
|
||||||
|
Attachment attachment = findAttachmentByUniqueId(saveRequestDto.getUniqueId());
|
||||||
|
attachment.updateIsDelete(saveRequestDto.getIsDelete());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user