Skip to content

Commit

Permalink
Finalize tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sharon2719 committed Oct 3, 2024
1 parent f381186 commit 7e8d8c9
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 152 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ void validateStructureMap(String inputFilePath, boolean validate, String structu
throws IOException {
FctUtils.printInfo("Starting structureMap validation");
FctUtils.printInfo(String.format("Input file path \u001b[35m%s\u001b[0m", inputFilePath));
FctUtils.printInfo(
String.format("Input file path \u001b[35m%s\u001b[0m", structureMapFilePath));

ArrayList<String> questionnaires = getResourceFiles(inputFilePath);
boolean allResourcesValid = true;
Expand Down Expand Up @@ -212,7 +214,7 @@ void validateStructureMapForProject(
FctValidationProcessor.Constants.structuremap, new HashMap<>());

// Map identifiers to filenames for both questionnaires and structure maps
Map<String, String> questionnaireFileMap = mapIdentifierWithFilename(questionnairesFolderPath);
Map<String, String> questionnaireFileMap = mapIdentifierWithFilePath(questionnairesFolderPath);

// Use StructureMapProcessor for structure maps to get their ID-to-filename mapping
StructureMapProcessor structureMapProcessor =
Expand Down Expand Up @@ -245,6 +247,9 @@ void validateStructureMapForProject(

// Call the existing validateStructureMap function for validation and resource
// extraction

System.out.println(questionnaireFile);

try {
validateStructureMap(questionnaireFile, validate, structureMapFile);
} catch (IOException e) {
Expand All @@ -263,7 +268,7 @@ void validateStructureMapForProject(
}
}

Map<String, String> mapIdentifierWithFilename(String folderPath) throws IOException {
Map<String, String> mapIdentifierWithFilePath(String folderPath) throws IOException {
Map<String, String> idToFileNameMap = new HashMap<>();

File folder = new File(folderPath);
Expand All @@ -272,13 +277,12 @@ Map<String, String> mapIdentifierWithFilename(String folderPath) throws IOExcept
if (files != null) {
for (File file : files) {
if (file.isFile() && file.getName().endsWith(".json")) {
String fileName = file.getName();
String fileContent =
new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8);
String id = extractIdFromJson(fileContent);

if (id != null && !id.isEmpty()) {
idToFileNameMap.put(id, fileName);
idToFileNameMap.put(id, file.getAbsolutePath());
}
}
}
Expand Down Expand Up @@ -347,57 +351,6 @@ boolean hasQuestionnaireReferenceToStructureMap(JsonObject questionnaire, String
return false;
}

JsonObject parseCompositionFile(String compositionFilePath) throws IOException {
FctUtils.printInfo("Parsing composition file: " + compositionFilePath);
FctFile compositionFile = FctUtils.readFile(compositionFilePath);
return JsonParser.parseString(compositionFile.getContent()).getAsJsonObject();
}

JsonArray getQuestionnairesFromComposition(JsonObject composition) {
if (composition.has("section")) {
JsonArray sections = composition.getAsJsonArray("section");
for (JsonElement section : sections) {
JsonObject sectionObj = section.getAsJsonObject();
if (sectionObj.has("title")
&& "Questionnaires".equals(sectionObj.get("title").getAsString())) {
return sectionObj.getAsJsonArray("section"); // Get the sections under Questionnaires
}
}
}
return null;
}

JsonArray getStructureMapsFromComposition(JsonObject composition) {
if (composition.has("section")) {
JsonArray sections = composition.getAsJsonArray("section");
for (JsonElement section : sections) {
JsonObject sectionObj = section.getAsJsonObject();
if (sectionObj.has("title")
&& "StructureMaps".equals(sectionObj.get("title").getAsString())) {
return sectionObj.getAsJsonArray("section"); // Get the sections under StructureMaps
}
}
}
return null;
}

String findMatchingStructureMap(String questionnaireTitle, JsonArray structureMaps) {
for (JsonElement structureMapElement : structureMaps) {
JsonObject structureMap = structureMapElement.getAsJsonObject();

// Check if the "title" field exists and is not null
if (structureMap.has("title") && !structureMap.get("title").isJsonNull()) {
String structureMapTitle = structureMap.get("title").getAsString();

// Logic to match questionnaire title with structure map title
if (structureMapTitle.equals(questionnaireTitle)) {
return structureMapTitle; // Return the matched structure map title
}
}
}
return null;
}

static ArrayList<String> getResourceFiles(String pathToFolder) throws IOException {
ArrayList<String> filesArray = new ArrayList<>();
Path projectPath = Paths.get(pathToFolder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,13 @@ public Map<String, String> generateIdToFilepathMap() {
// Extract the actual file name (e.g., child.map)
String actualFileName = path.getFileName().toString();

// Map the StructureMap ID to the file name
structureMapToFilename.put(structureMapId, actualFileName);
if (actualFileName != null) {

// Map the StructureMap ID to the file name
structureMapToFilename.put(structureMapId, actualFileName);
}
// Map the StructureMap ID to the file path
structureMapToFilename.put(structureMapId, currentFile);
}
}
}
Expand Down
Loading

0 comments on commit 7e8d8c9

Please sign in to comment.