Skip to content

Commit

Permalink
reworked logic for exporter factory so that all exporters are spring …
Browse files Browse the repository at this point in the history
…initialized beans
  • Loading branch information
hussainsabir52 committed Jan 30, 2025
1 parent 5176015 commit b65e913
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ public class QuestionnaireController {
@Autowired
private ODMProcessingBean odmReader;

@Autowired
private MetadataExporterFactory metadataExporterFactory;

/**
* Controls the HTTP GET requests for the URL <i>/questionnaire/list</i>. Shows the list of
* questionnaires.
Expand Down Expand Up @@ -410,7 +413,7 @@ public ResponseEntity<ByteArrayResource> downloadQuestionnaire(
}

// Get the bytearray of the selected questionnaire in the selected type
MetadataExporter exporter = MetadataExporterFactory.getMetadataExporter(
MetadataExporter exporter = metadataExporterFactory.getMetadataExporter(
MetadataFormat.valueOf(type));

for (Question question : questionnaire.getQuestions()) {
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/de/imi/mopat/helper/model/JSONHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
import de.imi.mopat.model.dto.export.JsonScoreDTO;
import de.imi.mopat.model.score.Score;
import java.io.IOException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class JSONHelper {

private final ConfigurationDao configurationDao;

public JSONHelper(final ConfigurationDao configurationDao) {
this.configurationDao = configurationDao;
}
@Autowired
private ConfigurationDao configurationDao;

public void initializeJsonQuestionnaireDTO(JsonQuestionnaireDTO jsonQuestionnaireDTO,
final Questionnaire questionnaire) {
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/de/imi/mopat/io/impl/MetadataExporterFHIR.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,17 @@
import org.hl7.fhir.exceptions.FHIRException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

/**
* An exporter for FHIR metadata reprasentation of a {@link Questionnaire}.
*/
@Service
public class MetadataExporterFHIR implements MetadataExporter {

private static final org.slf4j.Logger LOGGER =
org.slf4j.LoggerFactory.getLogger(MetadataExporterPDF.class);
org.slf4j.LoggerFactory.getLogger(MetadataExporterFHIR.class);
private final String ANSWER_OID = "MoPat/Answer/";

@Autowired
Expand Down
29 changes: 23 additions & 6 deletions src/main/java/de/imi/mopat/io/impl/MetadataExporterFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,47 @@

import de.imi.mopat.io.MetadataExporter;
import de.imi.mopat.model.enumeration.MetadataFormat;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* A factory to get a {@link MetadataExporter} for a specific {@link MetadataFormat}.
*/
@Service
public class MetadataExporterFactory {

@Autowired
private MetadataExporterMoPat metadataExporterMoPat;

@Autowired
private MetadataExporterODM metadataExporterODM;

@Autowired
private MetadataExporterPDF metadataExporterPDF;

@Autowired
private MetadataExporterFHIR metadataExporterFHIR;

@Autowired
private MetadataExporterODMExportTemplate metadataExporterODMExportTemplate;
/**
* Returns a {@link MetadataExporter} for the given {@link MetadataFormat}.
*
* @param metadataFormat {@link MetadataFormat} of the requested {@link MetadataExporter}
* @return a {@link MetadataExporter} for the given {@link MetadataFormat}
*/
public static MetadataExporter getMetadataExporter(final MetadataFormat metadataFormat) {
public MetadataExporter getMetadataExporter(final MetadataFormat metadataFormat) {
switch (metadataFormat) {
case MoPat:
return new MetadataExporterMoPat();
return metadataExporterMoPat;
case ODM:
return new MetadataExporterODM();
return metadataExporterODM;
case PDF:
return new MetadataExporterPDF();
return metadataExporterPDF;
case FHIR:
return new MetadataExporterFHIR();
return metadataExporterFHIR;
case ODMExportTemplate:
return new MetadataExporterODMExportTemplate();
return metadataExporterODMExportTemplate;
default:
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.imi.mopat.io.impl;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
Expand All @@ -22,12 +23,19 @@

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

/**
* An exporter for a JSON representation of the metadata of a
* {@link Questionnaire} and everything that is associated with it.
*/
@Service
public class MetadataExporterMoPat implements MetadataExporter {

@Autowired
private JSONHelper jsonHelper;

private static final org.slf4j.Logger LOGGER =
org.slf4j.LoggerFactory.getLogger(MetadataExporterMoPat.class);

Expand Down Expand Up @@ -58,7 +66,6 @@ public byte[] export(

JsonQuestionnaireDTO jsonQuestionnaireDTO =
new JsonQuestionnaireDTO();
JSONHelper jsonHelper = new JSONHelper(configurationDao);
jsonHelper.initializeJsonQuestionnaireDTO(jsonQuestionnaireDTO, questionnaire);
jsonQuestionnaire =
objectMapper.writeValueAsString(jsonQuestionnaireDTO);
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/de/imi/mopat/io/impl/MetadataExporterODM.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
import javax.xml.datatype.XMLGregorianCalendar;

import org.springframework.context.MessageSource;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

/**
* An exporter for an ODM representation of the metadata of a {@link Questionnaire}.
Expand All @@ -82,6 +84,7 @@
* [BaseOID].[questionID].1 and [BaseOID] .[questionID].2 - other questiontypes:
* [BaseOID].[questionID] - CodeListOID: [BaseOID] .[questionID].1
*/
@Service
public class MetadataExporterODM implements MetadataExporter {

private BigInteger orderNumber = BigInteger.ONE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@

import org.apache.commons.io.FileUtils;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

/**
* An exporter for an ODMExportTemplate representation of the metadata of a {@link Questionnaire}.
Expand All @@ -96,6 +98,7 @@
* [BaseOID].[questionID].1 and [BaseOID] .[questionID].2 - other questiontypes:
* [BaseOID].[questionID] - CodeListOID: [BaseOID] .[questionID].1
*/
@Service
public class MetadataExporterODMExportTemplate implements MetadataExporter {

private BigInteger orderNumber = BigInteger.ONE;
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/de/imi/mopat/io/impl/MetadataExporterPDF.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@
import org.apache.http.impl.client.HttpClientBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

/**
* An exporter for a PDF representation of the metadata of a {@link Questionnaire}.
*/
@Service
public class MetadataExporterPDF implements MetadataExporter {

private static final org.slf4j.Logger LOGGER = org.slf4j.LoggerFactory.getLogger(
MetadataExporterPDF.class);
@Autowired
private ServletContext servletContext;

@Override
public byte[] export(final Questionnaire questionnaire, final MessageSource messageSource,
Expand Down

0 comments on commit b65e913

Please sign in to comment.