Skip to content

Commit

Permalink
Fix oss report upload function of rest api
Browse files Browse the repository at this point in the history
  • Loading branch information
FOSSLight-dev committed Aug 23, 2023
1 parent 9712889 commit 97da9ea
Show file tree
Hide file tree
Showing 11 changed files with 197 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,8 @@ public CommonResult ossReportSrc(
@RequestHeader String _token,
@ApiParam(value = "Project id", required = true) @RequestParam(required = true) String prjId,
@ApiParam(value = "OSS Report > sheetName : all sheets starting with 'SRC'", required = false) @RequestPart(required = false) MultipartFile ossReport,
@ApiParam(value = "Comment", required = false) @RequestParam(required = false) String comment){
@ApiParam(value = "Comment", required = false) @RequestParam(required = false) String comment,
@ApiParam(value = "Reset Flag (YES : Y, NO : N, Default : Y)", required = false, allowableValues = "Y,N") @RequestParam(required = false) String resetFlag){

T2Users userInfo = userService.checkApiUserAuth(_token);
Map<String, Object> resultMap = new HashMap<String, Object>(); // 성공, 실패에 대한 정보를 return하기 위한 map;
Expand All @@ -647,6 +648,14 @@ public CommonResult ossReportSrc(

boolean searchFlag = apiProjectService.existProjectCnt(paramMap); // 조회가 안된다면 권한이 없는 project id를 입력함.
if (searchFlag) {
String oldFileId = "";
if (CoConstDef.FLAG_NO.equals(avoidNull(resetFlag))) {
Map<String, Object> prjInfo = apiProjectService.selectProjectMaster(prjId);
if (prjInfo.get("srcCsvFileId") != null) {
oldFileId = String.valueOf((int) prjInfo.get("srcCsvFileId"));
}
}

if (ossReport != null) {
if (ossReport.getOriginalFilename().contains("xls") // 확장자 xls, xlsx, xlsm 허용
&& CoConstDef.CD_XLSX_UPLOAD_FILE_SIZE_LIMIT > ossReport.getSize()) { // file size 5MB 이하만 허용.
Expand All @@ -657,7 +666,12 @@ public CommonResult ossReportSrc(
, CoCodeManager.getCodeString(CoConstDef.CD_OPEN_API_MESSAGE, CoConstDef.CD_OPEN_API_UPLOAD_TARGET_ERROR_MESSAGE));
}

UploadFile bean = apiFileService.uploadFile(ossReport); // file 등록 처리 이후 upload된 file정보를 return함.
UploadFile bean = null;
if (!isEmpty(oldFileId)) {
bean = apiFileService.uploadFile(ossReport, null, oldFileId);
} else {
bean = apiFileService.uploadFile(ossReport); // file 등록 처리 이후 upload된 file정보를 return함.
}

// get Excel Sheet name starts with SRC
List<String> sheet = null;
Expand Down Expand Up @@ -689,10 +703,21 @@ public CommonResult ossReportSrc(
return responseService.getFailResult(CoConstDef.CD_OPEN_API_DATA_VALIDERROR_MESSAGE
, CoCodeManager.getCodeString(CoConstDef.CD_OPEN_API_MESSAGE, CoConstDef.CD_OPEN_API_DATA_VALIDERROR_MESSAGE));
} else {
List<ProjectIdentification> ossComponentList = new ArrayList<>();
List<List<ProjectIdentification>> ossComponentsLicenseList = new ArrayList<>();

if (CoConstDef.FLAG_NO.equals(avoidNull(resetFlag))) {
apiProjectService.getIdentificationGridList(prjId, CoConstDef.CD_DTL_COMPONENT_ID_SRC, ossComponentList, ossComponentsLicenseList);
}

ossComponentList.addAll(ossComponents);
ossComponentsLicenseList.addAll(ossComponentsLicense);

Project project = new Project();
project.setPrjId(prjId);
project.setSrcCsvFileId(bean.getRegistFileId()); // set file id
projectService.registSrcOss(ossComponents, ossComponentsLicense, project);

projectService.registSrcOss(ossComponentList, ossComponentsLicenseList, project);

// oss name이 nick name으로 등록되어 있는 경우, 자동치환된 Data를 comment his에 등록
try {
Expand Down Expand Up @@ -770,7 +795,8 @@ public CommonResult ossReportBin(
@ApiParam(value = "Project id", required = true) @RequestParam(required = true) String prjId,
@ApiParam(value = "OSS Report > sheetName : 'BIN'", required = false) @RequestPart(required = false) MultipartFile ossReport,
@ApiParam(value = "Binary.txt", required = false) @RequestPart(required = false) MultipartFile binartTxt,
@ApiParam(value = "Comment", required = false) @RequestParam(required = false) String comment){
@ApiParam(value = "Comment", required = false) @RequestParam(required = false) String comment,
@ApiParam(value = "Reset Flag (YES : Y, NO : N, Default : Y)", required = false, allowableValues = "Y,N") @RequestParam(required = false) String resetFlag){


T2Users userInfo = userService.checkApiUserAuth(_token); // token이 정상적인 값인지 확인
Expand Down Expand Up @@ -798,6 +824,14 @@ public CommonResult ossReportBin(
UploadFile ossReportBean = null;
UploadFile binartTxtBean = null;

String oldFileId = "";
if (CoConstDef.FLAG_NO.equals(avoidNull(resetFlag))) {
Map<String, Object> prjInfo = apiProjectService.selectProjectMaster(prjId);
if (prjInfo.get("binCsvFileId") != null) {
oldFileId = String.valueOf((int) prjInfo.get("binCsvFileId"));
}
}

if (ossReport != null) {
if (!ossReport.getOriginalFilename().contains("xls")) { // 확장자 xls, xlsx, xlsm 허용
return responseService.getFailResult(CoConstDef.CD_OPEN_API_EXT_UNSUPPORT_MESSAGE
Expand All @@ -813,7 +847,12 @@ public CommonResult ossReportBin(
, CoCodeManager.getCodeString(CoConstDef.CD_OPEN_API_MESSAGE, CoConstDef.CD_OPEN_API_UPLOAD_TARGET_ERROR_MESSAGE));
}

ossReportBean = apiFileService.uploadFile(ossReport); // file 등록 처리 이후 upload된 file정보를 return함.
if (!isEmpty(oldFileId)) {
ossReportBean = apiFileService.uploadFile(ossReport, null, oldFileId);
} else {
ossReportBean = apiFileService.uploadFile(ossReport);
}

String[] sheet = new String[1];
Map<String, Object> result = apiProjectService.getSheetData(ossReportBean, prjId, "BIN", sheet);
String errorMsg = (String) result.get("errorMessage");
Expand Down Expand Up @@ -892,8 +931,18 @@ public CommonResult ossReportBin(
return responseService.getFailResult(CoConstDef.CD_OPEN_API_DATA_VALIDERROR_MESSAGE
, CoCodeManager.getCodeString(CoConstDef.CD_OPEN_API_MESSAGE, CoConstDef.CD_OPEN_API_DATA_VALIDERROR_MESSAGE));
} else {
List<ProjectIdentification> ossComponentList = new ArrayList<>();
List<List<ProjectIdentification>> ossComponentsLicenseList = new ArrayList<>();

if (CoConstDef.FLAG_NO.equals(avoidNull(resetFlag))) {
apiProjectService.getIdentificationGridList(prjId, CoConstDef.CD_DTL_COMPONENT_ID_BIN, ossComponentList, ossComponentsLicenseList);
}

ossComponentList.addAll(ossComponents);
ossComponentsLicenseList.addAll(ossComponentsLicense);

project.setPrjId(prjId);
projectService.registSrcOss(ossComponents, ossComponentsLicense, project, CoConstDef.CD_DTL_COMPONENT_ID_BIN); // bin tab
projectService.registSrcOss(ossComponentList, ossComponentsLicenseList, project, CoConstDef.CD_DTL_COMPONENT_ID_BIN); // bin tab

String csvFileId = project.getBinCsvFileId();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ public CommonResult createSelfCheck(
public CommonResult ossReportSelfCheck(
@RequestHeader String _token,
@ApiParam(value = "Project id", required = true) @RequestParam(required = true) String prjId,
@ApiParam(value = "OSS Report > sheetName : 'Start with Self-Check, SRC or BIN '", required = false) @RequestPart(required = false) MultipartFile ossReport){
@ApiParam(value = "OSS Report > sheetName : 'Start with Self-Check, SRC or BIN '", required = false) @RequestPart(required = false) MultipartFile ossReport,
@ApiParam(value = "Reset Flag (YES : Y, NO : N, Default : Y)", required = false, allowableValues = "Y,N") @RequestParam(required = false) String resetFlag){

T2Users userInfo = userService.checkApiUserAuth(_token);
Map<String, Object> resultMap = new HashMap<String, Object>(); // 성공, 실패에 대한 정보를 return하기 위한 map;
Expand All @@ -148,8 +149,22 @@ public CommonResult ossReportSelfCheck(
boolean searchFlag = apiSelfCheckService.existProjectCnt(paramMap); // 조회가 안된다면 권한이 없는 project id를 입력함.

if (searchFlag) {
String oldFileId = "";
if (CoConstDef.FLAG_NO.equals(avoidNull(resetFlag))) {
Map<String, Object> prjInfo = apiSelfCheckService.selectProjectMaster(prjId);
if (prjInfo.get("srcCsvFileId") != null) {
oldFileId = String.valueOf((int) prjInfo.get("srcCsvFileId"));
}
}

if (ossReport != null) {
UploadFile bean = apiFileService.uploadFile(ossReport); // file 등록 처리 이후 upload된 file정보를 return함.
UploadFile bean = null;
if (!isEmpty(oldFileId)) {
bean = apiFileService.uploadFile(ossReport, null, oldFileId);
} else {
bean = apiFileService.uploadFile(ossReport); // file 등록 처리 이후 upload된 file정보를 return함.
}

List<UploadFile> list = new ArrayList<UploadFile>();
list.add(bean);
ArrayList<Object> checkFileLimit = null;
Expand Down Expand Up @@ -193,10 +208,20 @@ public CommonResult ossReportSelfCheck(
if (!vr.isValid()) {
return responseService.getFailResult(getMessage("api.dataValidationError.code"), getMessage("api.dataValidationError.msg")); // data validation error
} else {
List<ProjectIdentification> ossComponentList = new ArrayList<>();
List<List<ProjectIdentification>> ossComponentsLicenseList = new ArrayList<>();

if (CoConstDef.FLAG_NO.equals(avoidNull(resetFlag))) {
apiSelfCheckService.getIdentificationGridList(prjId, CoConstDef.CD_DTL_SELF_COMPONENT_ID, ossComponentList, ossComponentsLicenseList);
}

ossComponentList.addAll(ossComponents);
ossComponentsLicenseList.addAll(ossComponentsLicense);

Project project = new Project();
project.setPrjId(prjId);
project.setSrcCsvFileId(bean.getRegistFileId()); // set file id
selfCheckService.registSrcOss(ossComponents, ossComponentsLicense, project);
selfCheckService.registSrcOss(ossComponentList, ossComponentsLicenseList, project);

// 정상처리된 경우 세션 삭제
deleteSession(CommonFunction.makeSessionKey(loginUserName(), CoConstDef.CD_DTL_COMPONENT_ID_SRC, prjId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ public interface ApiSelfCheckMapper {
int getCreateProjectCnt(@Param("userId") String userId);

int selectProjectCount(Map<String, Object> paramMap);

Map<String, Object> selectProjectMaster(@Param("prjId") String prjId);
}
2 changes: 2 additions & 0 deletions src/main/java/oss/fosslight/service/ApiFileService.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ public interface ApiFileService {

public UploadFile uploadFile(MultipartFile uploadFile, String filePath);

public UploadFile uploadFile(MultipartFile uploadFile, String filePath, String fileId);

public Map<String, UploadFile> uploadNoticeXMLFile(MultipartFile uploadFile, String prjId);
}
5 changes: 5 additions & 0 deletions src/main/java/oss/fosslight/service/ApiProjectService.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import org.springframework.stereotype.Service;

import oss.fosslight.domain.ProjectIdentification;
import oss.fosslight.domain.UploadFile;

@Service
Expand Down Expand Up @@ -71,4 +72,8 @@ public interface ApiProjectService {
public boolean existsWatcherByEmail(String prjId, String email);

public void insertWatcher(Map<String, Object> paramMap);

public Map<String, Object> selectProjectMaster(String prjId);

public void getIdentificationGridList(String prjId, String code, List<ProjectIdentification> ossComponentList, List<List<ProjectIdentification>> ossComponentsLicenseList);
}
7 changes: 7 additions & 0 deletions src/main/java/oss/fosslight/service/ApiSelfCheckService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,22 @@

package oss.fosslight.service;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import oss.fosslight.domain.ProjectIdentification;

@Service
public interface ApiSelfCheckService {
int getCreateProjectCnt(String userId);

Map<String, Object> createSelfCheck(Map<String, Object> paramMap);

boolean existProjectCnt(Map<String, Object> paramMap);

Map<String, Object> selectProjectMaster(String prjId);

void getIdentificationGridList(String prjId, String code, List<ProjectIdentification> ossComponentList, List<List<ProjectIdentification>> ossComponentsLicenseList);
}
15 changes: 13 additions & 2 deletions src/main/java/oss/fosslight/service/impl/ApiFileServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,24 @@ public class ApiFileServiceImpl implements ApiFileService {

@Override
public UploadFile uploadFile(MultipartFile mFile){
return uploadFile(mFile, null);
return uploadFile(mFile, null, null);
}

@Override
public UploadFile uploadFile(MultipartFile mFile, String filePath){
return uploadFile(mFile, filePath, null);
}

@Override
public UploadFile uploadFile(MultipartFile mFile, String filePath, String oldFileId) {
boolean uploadSucc = false;
String fileId = StringUtil.avoidNull(fileMapper.getFileId(), "1");//max+1 file Id 가져옴 20160524 ms-kwon
String fileId = "";
if (oldFileId != null) {
fileId = oldFileId;
} else {
fileId = StringUtil.avoidNull(fileMapper.getFileId(), "1");//max+1 file Id 가져옴 20160524 ms-kwon
}

int indexNum = 0;
UploadFile upFile = new UploadFile();
T2File registFile = new T2File();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2856,4 +2856,29 @@ public boolean existsWatcherByEmail(String prjId, String email) {
public void insertWatcher(Map<String, Object> paramMap) {
apiProjectMapper.insertWatcher(paramMap);
}

@Override
public Map<String, Object> selectProjectMaster(String prjId) {
Map<String, Object> param = new HashMap<>();
param.put("prjId", prjId);
return apiProjectMapper.selectProjectMaster(param);
}

@SuppressWarnings("unchecked")
@Override
public void getIdentificationGridList(String prjId, String code, List<ProjectIdentification> ossComponentList, List<List<ProjectIdentification>> ossComponentsLicenseList) {
ProjectIdentification identification = new ProjectIdentification();
identification.setReferenceId(prjId);
identification.setReferenceDiv(code);
Map<String, Object> map = projectService.getIdentificationGridList(identification, true);
if (map.containsKey("mainData")) {
List<ProjectIdentification> gridDatas = (List<ProjectIdentification>) map.get("mainData");
if (gridDatas != null && !gridDatas.isEmpty()) {
List<List<ProjectIdentification>> gridDataLicenses = CommonFunction.setOssComponentLicense(gridDatas);
Map<String, Object> remakeComponentsMap = CommonFunction.remakeMutiLicenseComponents(gridDatas, gridDataLicenses);
ossComponentList.addAll((List<ProjectIdentification>) remakeComponentsMap.get("mainList"));
ossComponentsLicenseList.addAll((List<List<ProjectIdentification>>) remakeComponentsMap.get("subList"));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,24 @@

package oss.fosslight.service.impl;

import java.math.BigInteger;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import oss.fosslight.common.CommonFunction;
import oss.fosslight.domain.ProjectIdentification;
import oss.fosslight.repository.ApiSelfCheckMapper;
import oss.fosslight.service.ApiSelfCheckService;
import oss.fosslight.service.SelfCheckService;

@Service
public class ApiSelfCheckServiceImpl implements ApiSelfCheckService {
@Autowired SelfCheckService selfCheckService;
@Autowired ApiSelfCheckMapper apiSelfcheckMapper;

@Override
Expand All @@ -45,4 +49,27 @@ public boolean existProjectCnt(Map<String, Object> paramMap) {

return records == 1 ? true : false;
}

@Override
public Map<String, Object> selectProjectMaster(String prjId) {
return apiSelfcheckMapper.selectProjectMaster(prjId);
}

@SuppressWarnings("unchecked")
@Override
public void getIdentificationGridList(String prjId, String code, List<ProjectIdentification> ossComponentList, List<List<ProjectIdentification>> ossComponentsLicenseList) {
ProjectIdentification identification = new ProjectIdentification();
identification.setReferenceId(prjId);
identification.setReferenceDiv(code);
Map<String, Object> map = selfCheckService.getIdentificationGridList(identification);
if (map.containsKey("mainData")) {
List<ProjectIdentification> gridDatas = (List<ProjectIdentification>) map.get("mainData");
if (gridDatas != null && !gridDatas.isEmpty()) {
List<List<ProjectIdentification>> gridDataLicenses = CommonFunction.setOssComponentLicense(gridDatas);
Map<String, Object> remakeComponentsMap = CommonFunction.remakeMutiLicenseComponents(gridDatas, gridDataLicenses);
ossComponentList.addAll((List<ProjectIdentification>) remakeComponentsMap.get("mainList"));
ossComponentsLicenseList.addAll((List<List<ProjectIdentification>>) remakeComponentsMap.get("subList"));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@
, A.NOTICE_TYPE_ETC AS NOTICE_PLATFORM
, A.PRIORITY
, A.STATUS
, A.SRC_CSV_FILE_ID
, A.BIN_CSV_FILE_ID
, A.BIN_BINARY_FILE_ID
FROM (
SELECT T1.PRJ_ID
, T1.PRJ_NAME
Expand All @@ -114,6 +117,9 @@
, IFNULL(T1.VERIFICATION_STATUS, '') AS VERIFICATION_STATUS
, IFNULL(T1.DESTRIBUTION_STATUS, '') AS DESTRIBUTION_STATUS
, T1.DISTRIBUTION_TYPE
, T1.SRC_CSV_FILE_ID
, T1.BIN_CSV_FILE_ID
, T1.BIN_BINARY_FILE_ID
, T3.CD_DTL_NM
, T3.CD_DTL_NO
, IF(T1.NETWORK_SERVER_TYPE IS NULL OR T1.NETWORK_SERVER_TYPE = '', 'NO', 'YES') AS NETWORK_SERVER_TYPE
Expand Down
26 changes: 26 additions & 0 deletions src/main/resources/oss/fosslight/repository/ApiSelfCheckMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,30 @@
) A
WHERE 1=1
</select>

<select id="selectProjectMaster" parameterType="String" resultType="oss.fosslight.domain.CamelMap">
/* apiSelfCheckMapper.selectProjectMaster */
SELECT A.PRJ_ID
, A.PRJ_NAME
, A.PRJ_VERSION
, A.DISTRIBUTION_TYPE
, CASE WHEN B.CONTENTS IS NULL THEN A.COMMENT ELSE B.CONTENTS END AS COMMENT
, B.COMM_ID AS COMMENT_IDX
, A.OS_TYPE
, A.OS_TYPE_ETC
, A.USE_YN

/** FILE_ID **/
, A.SRC_CSV_FILE_ID
, A.CREATOR
, A.CREATED_DATE
, A.MODIFIER
, A.MODIFIED_DATE
, (SELECT USER_NAME FROM T2_USERS WHERE USER_ID = A.CREATOR) AS PRJ_USER_NAME
, (SELECT CD_DTL_NM FROM T2_CODE_DTL WHERE CD_NO = '200' AND CD_DTL_NO = A.DIVISION) AS PRJ_DIVISION_NAME
FROM
PRE_PROJECT_MASTER A
LEFT JOIN COMMENTS_HISTORY B ON A.COMMENT = B.COMM_ID
WHERE A.PRJ_ID = #{prjId}
</select>
</mapper>

0 comments on commit 97da9ea

Please sign in to comment.