Skip to content

Commit

Permalink
VAL-353 Update ManifestCheck report
Browse files Browse the repository at this point in the history
  • Loading branch information
QuyenLy87 committed May 15, 2024
1 parent e9473a6 commit ffe2fed
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@
import javax.xml.bind.JAXBException;

import org.ihtsdo.buildcloud.core.dao.BuildDAO;
import org.ihtsdo.buildcloud.core.dao.helper.S3PathHelper;
import org.ihtsdo.buildcloud.core.entity.Build;
import org.ihtsdo.buildcloud.core.manifest.FileType;
import org.ihtsdo.buildcloud.core.manifest.FolderType;
import org.ihtsdo.buildcloud.core.manifest.ListingType;
import org.ihtsdo.buildcloud.core.service.InputFileService;
import org.ihtsdo.buildcloud.core.service.build.RF2Constants;
import org.ihtsdo.buildcloud.core.service.helper.ManifestXmlFileParser;
import org.ihtsdo.otf.rest.exception.ResourceNotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.stereotype.Service;

Expand Down Expand Up @@ -48,6 +52,9 @@ public class ManifestCheck extends PreconditionCheck {
@Autowired
private BuildDAO buildDAO;

@Autowired
private InputFileService inputFileService;

@Value("${srs.release.package.pattern}")
private String releasePackagePattern;

Expand Down Expand Up @@ -100,6 +107,12 @@ public void runCheck(final Build build) {
warning(warningMsg);
return;
}

String invalidSourceMsg = validateFileNamesAgainstSource(manifestListing, build);
if (invalidSourceMsg != null) {
warning(invalidSourceMsg);
return;
}
}
pass();
} catch (ResourceNotFoundException | JAXBException | IOException e) {
Expand Down Expand Up @@ -306,4 +319,28 @@ private List<String> getFileNamesContainsAny(List<String> fileNames, String... p

return result;
}

private String validateFileNamesAgainstSource(final ListingType manifestListing, final Build build) {
final StringBuilder invalidSourceMsgBuilder = new StringBuilder();
final List<FileType> fileTypes = ManifestFileListingHelper.getAllFileTypes(manifestListing);
final List<String> sourceFilePaths = inputFileService.listSourceFilePaths(build.getReleaseCenterKey(), build.getProductKey(), build.getId());
if (!CollectionUtils.isEmpty(sourceFilePaths)) {
for (final FileType fileType : fileTypes) {
final String fileName = (fileType.getName().startsWith(RF2Constants.BETA_RELEASE_PREFIX)? fileType.getName().replaceFirst(RF2Constants.BETA_RELEASE_PREFIX, RF2Constants.EMPTY_SPACE) : fileType.getName()).replace(RF2Constants.SNAPSHOT, RF2Constants.DELTA);
List<String> sources = fileType.getSources().getSource();
if (sources.size() == 1 && (sourceFilePaths.stream().noneMatch(item -> item.contains(sources.get(0) + S3PathHelper.SEPARATOR + fileName)))) {
String another = sourceFilePaths.stream().filter(item -> item.contains(S3PathHelper.SEPARATOR + fileName)).findFirst().orElse(null);
if (another != null) {
String anotherSource = another.substring(0, another.indexOf(S3PathHelper.SEPARATOR));
invalidSourceMsgBuilder.append(String.format("The Manifest states that %s should come from the following source: %s, but found in the source: %s. ", fileType.getName(), sources.get(0), anotherSource));
}

}
}
}
if (!invalidSourceMsgBuilder.isEmpty()) {
return invalidSourceMsgBuilder.toString().trim();
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.ihtsdo.buildcloud.core.manifest.FileType;
import org.ihtsdo.buildcloud.core.manifest.FolderType;
import org.ihtsdo.buildcloud.core.manifest.ListingType;
import org.springframework.util.CollectionUtils;

public class ManifestFileListingHelper {

Expand All @@ -16,6 +17,13 @@ public static List<String> listAllFiles(ListingType listingType) {
return result;
}

public static List<FileType> getAllFileTypes(ListingType listingType) {
FolderType rootFolder = listingType.getFolder();
List<FileType> result = new ArrayList<>();
getFileTypesFromCurrentAndSubFolders(rootFolder, result);
return result;
}

public static List<String> getFilesByFolderName(ListingType listingType, String folderName) {
List<String> result = new ArrayList<>();
List<FolderType> folderTypes = listingType.getFolder().getFolder();
Expand Down Expand Up @@ -43,4 +51,21 @@ private static void getFilesFromCurrentAndSubFolders(FolderType folder, List<Str
}
}
}

private static void getFileTypesFromCurrentAndSubFolders(FolderType folder, List<FileType> fileTypes) {
if (folder != null) {
if (folder.getFile() != null) {
for (FileType fileType : folder.getFile()) {
if (fileType.getSources() != null && !CollectionUtils.isEmpty(fileType.getSources().getSource())) {
fileTypes.add(fileType);
}
}
}
if (folder.getFolder() != null) {
for (FolderType subFolder : folder.getFolder()) {
getFileTypesFromCurrentAndSubFolders(subFolder, fileTypes);
}
}
}
}
}

0 comments on commit ffe2fed

Please sign in to comment.