Skip to content

Commit

Permalink
MET-5961 code review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jeortizquan committed Jul 30, 2024
1 parent 4c5b8ed commit f811fdc
Show file tree
Hide file tree
Showing 14 changed files with 308 additions and 203 deletions.
52 changes: 2 additions & 50 deletions src/main/java/eu/europeana/metis/sandbox/config/DebiasConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import eu.europeana.metis.sandbox.repository.debias.DetectRepository;
import eu.europeana.metis.sandbox.service.debias.CompletedState;
import eu.europeana.metis.sandbox.service.debias.DebiasMachineService;
import eu.europeana.metis.sandbox.service.debias.DebiasDetectService;
import eu.europeana.metis.sandbox.service.debias.DetectService;
import eu.europeana.metis.sandbox.service.debias.ErrorState;
import eu.europeana.metis.sandbox.service.debias.ProcessingState;
Expand All @@ -25,55 +25,7 @@ public class DebiasConfig {
*/
@Bean
public DetectService debiasMachine(DetectRepository detectRepository) {
return new DebiasMachineService(detectRepository);
}

/**
* Ready state
*
* @param debiasMachine the debias machine
* @param detectRepository the detect repository
* @return the ready state
*/
@Bean
ReadyState readyState(DetectService debiasMachine, DetectRepository detectRepository) {
return new ReadyState(debiasMachine, detectRepository);
}

/**
* Completed state
*
* @param debiasMachine the debias machine
* @param detectRepository the detect repository
* @return the completed state
*/
@Bean
CompletedState completedState(DetectService debiasMachine, DetectRepository detectRepository) {
return new CompletedState(debiasMachine, detectRepository);
}

/**
* Processing state
*
* @param debiasMachine the debias machine
* @param detectRepository the detect repository
* @return the processing state
*/
@Bean
ProcessingState processingState(DetectService debiasMachine, DetectRepository detectRepository) {
return new ProcessingState(debiasMachine, detectRepository);
}

/**
* Error state
*
* @param debiasMachine the debias machine
* @param detectRepository the detect repository
* @return the error state
*/
@Bean
ErrorState errorState(DetectService debiasMachine, DetectRepository detectRepository) {
return new ErrorState(debiasMachine, detectRepository);
return new DebiasDetectService(detectRepository);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,14 @@ class DatasetController {
/**
* Instantiates a new Dataset controller.
*
* @param datasetService the dataset service
* @param datasetLogService the dataset log service
* @param reportService the report service
* @param recordService the record service
* @param recordLogService the record log service
* @param datasetService the dataset service
* @param datasetLogService the dataset log service
* @param reportService the report service
* @param recordService the record service
* @param recordLogService the record log service
* @param recordTierCalculationService the record tier calculation service
* @param harvestPublishService the harvest publish service
* @param harvestPublishService the harvest publish service
* @param debiasDetectService the debias detect service
*/
public DatasetController(DatasetService datasetService, DatasetLogService datasetLogService,
DatasetReportService reportService, RecordService recordService,
Expand All @@ -134,11 +135,11 @@ public DatasetController(DatasetService datasetService, DatasetLogService datase
* POST API calls for harvesting and processing the records given a zip, tar or tar.gz file
*
* @param datasetName the given name of the dataset to be processed
* @param country the given country from which the records refer to
* @param language the given language that the records contain
* @param stepsize the stepsize
* @param dataset the given dataset itself to be processed as a compressed file
* @param xsltFile the xslt file used for transformation to edm external
* @param country the given country from which the records refer to
* @param language the given language that the records contain
* @param stepsize the stepsize
* @param dataset the given dataset itself to be processed as a compressed file
* @param xsltFile the xslt file used for transformation to edm external
* @return 202 if it's processed correctly, 4xx or 500 otherwise
*/
@Operation(summary = "Harvest dataset from file", description = "Process the given dataset by HTTP providing a file")
Expand Down Expand Up @@ -176,11 +177,11 @@ public DatasetIdDto harvestDatasetFromFile(
* POST API calls for harvesting and processing the records given a URL of a compressed file
*
* @param datasetName the given name of the dataset to be processed
* @param country the given country from which the records refer to
* @param language the given language that the records contain
* @param stepsize the stepsize
* @param url the given dataset itself to be processed as a URL of a zip file
* @param xsltFile the xslt file used for transformation to edm external
* @param country the given country from which the records refer to
* @param language the given language that the records contain
* @param stepsize the stepsize
* @param url the given dataset itself to be processed as a URL of a zip file
* @param xsltFile the xslt file used for transformation to edm external
* @return 202 if it's processed correctly, 4xx or 500 otherwise
*/
@Operation(summary = "Harvest dataset from url", description = "Process the given dataset by HTTP providing an URL")
Expand Down Expand Up @@ -221,16 +222,16 @@ public DatasetIdDto harvestDatasetFromURL(
/**
* POST API calls for harvesting and processing the records given a URL of an OAI-PMH endpoint
*
* @param datasetName the given name of the dataset to be processed
* @param country the given country from which the records refer to
* @param language the given language that the records contain
* @param stepsize the stepsize
* @param url the given URL of the OAI-PMH repository to be processed
* @param setspec forms a unique identifier for the set within the repository, it must be
* unique for each set.
* @param datasetName the given name of the dataset to be processed
* @param country the given country from which the records refer to
* @param language the given language that the records contain
* @param stepsize the stepsize
* @param url the given URL of the OAI-PMH repository to be processed
* @param setspec forms a unique identifier for the set within the repository, it must be
* unique for eac set.
* @param metadataformat or metadata prefix is a string to specify the metadata format in OAI-PMH
* requests issued to the repository
* @param xsltFile the xslt file used for transformation to edm external
* requests issued to the repository
* @param xsltFile the xslt file used for transformation to edm external
* @return 202 if it's processed correctly, 4xx or 500 otherwise
*/
@Operation(summary = "Harvest dataset from OAI-PMH protocol", description = "Process the given dataset using OAI-PMH")
Expand Down Expand Up @@ -313,7 +314,7 @@ public DatasetInfoDto getDatasetInfo(
* GET API returns the generated tier calculation view for a stored record.
*
* @param datasetId the dataset id
* @param recordId the record id
* @param recordId the record id
* @return the record tier calculation view
* @throws NoRecordFoundException if record was not found
*/
Expand All @@ -332,8 +333,8 @@ public RecordTierCalculationView computeRecordTierCalculation(
* GET API returns the string representation of the stored record.
*
* @param datasetId the dataset id
* @param recordId the record id
* @param step the step name
* @param recordId the record id
* @param step the step name
* @return the string representation of the stored record
* @throws NoRecordFoundException if record was not found
*/
Expand All @@ -352,7 +353,6 @@ public String getRecord(@PathVariable("id") String datasetId, @RequestParam("rec
*
* @param datasetId the dataset id
* @return the records tier of a given dataset
*
*/
@Operation(summary = "Gets a list of records tier", description = "Get list of records tiers")
@ApiResponse(responseCode = "200", description = "List of records tiers")
Expand Down Expand Up @@ -409,23 +409,35 @@ public List<LanguageView> getAllLanguages() {
return Language.getLanguageListSortedByName().stream().map(LanguageView::new).toList();
}

/**
* Process DeBias boolean.
*
* @param datasetId the dataset id
* @return the boolean
*/
@Operation(description = "Process debias detection dataset")
@ApiResponse(responseCode = "200", description = "Process debias detection feature", content = {
@Content(mediaType = APPLICATION_JSON_VALUE)})
@ApiResponse(responseCode = "400", description = MESSAGE_FOR_400_CODE)
@PostMapping(value = "{id}/debias", produces = APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public boolean processDebias(@PathVariable("id") Long datasetId) {
public boolean processDebias(@PathVariable("id") Integer datasetId) {
return debiasDetectService.process(datasetId);
}

@Operation(description = "Get debias detection dataset")
@ApiResponse(responseCode = "200", description = "Get detection information about debias detection", content = {
/**
* Gets DeBias detection information.
*
* @param datasetId the dataset id
* @return the DeBias detection
*/
@Operation(description = "Get DeBias detection dataset")
@ApiResponse(responseCode = "200", description = "Get detection information about DeBias detection", content = {
@Content(mediaType = APPLICATION_JSON_VALUE)})
@ApiResponse(responseCode = "400", description = MESSAGE_FOR_400_CODE)
@GetMapping(value = "{id}/debias", produces = APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public DetectionInfoDto getDebiasDetection(@PathVariable("id") Long datasetId) {
public DetectionInfoDto getDebiasDetection(@PathVariable("id") Integer datasetId) {
return debiasDetectService.getDetectionInfo(datasetId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ public class DetectionInfoDto {
public static final String SWAGGER_MODEL_NAME = "DebiasDetectionInfo";

@JsonProperty("dataset-id")
private final Long datasetId;
private final Integer datasetId;

@JsonProperty("state")
private final String state;

@JsonProperty("creation-date")
@JsonFormat(pattern="yyyy-MM-dd'T'HH:mm:ss.nZ")
@JsonFormat(pattern="yyyy-MM-dd'T'HH:mm:ss")
private final ZonedDateTime creationDate;

/**
Expand All @@ -33,7 +33,7 @@ public class DetectionInfoDto {
* @param state the state
* @param creationDate the creation date
*/
public DetectionInfoDto(Long datasetId, String state, ZonedDateTime creationDate) {
public DetectionInfoDto(Integer datasetId, String state, ZonedDateTime creationDate) {
this.datasetId = datasetId;
this.state = state;
this.creationDate = creationDate;
Expand All @@ -44,7 +44,7 @@ public DetectionInfoDto(Long datasetId, String state, ZonedDateTime creationDate
*
* @return the dataset id
*/
public Long getDatasetId() {
public Integer getDatasetId() {
return datasetId;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
package eu.europeana.metis.sandbox.repository.debias;

import eu.europeana.metis.sandbox.entity.debias.DetectionEntity;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

/**
* The interface Detect repository.
*/
public interface DetectRepository extends JpaRepository<DetectionEntity, Long> {

@Query("SELECT dec.datasetId, dec.state, dec.createdDate FROM DetectionEntity dec")
List<DetectionEntity> listDbEntries();

DetectionEntity findDetectionEntityByDatasetId_DatasetId(Long datasetId);
/**
* Find detection entity by dataset id detection entity.
*
* @param datasetId the dataset id
* @return the detection entity
*/
DetectionEntity findDetectionEntityByDatasetId_DatasetId(Integer datasetId);

/**
* Update state.
*
* @param datasetId the dataset id
* @param state the state
*/
@Modifying
@Query("UPDATE DetectionEntity dec SET dec.state = '?2' WHERE dec.datasetId = ?1")
void updateState(Long datasetId, String state);
void updateState(Integer datasetId, String state);

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,24 @@

import eu.europeana.metis.sandbox.entity.debias.DetectionEntity;
import eu.europeana.metis.sandbox.repository.debias.DetectRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.transaction.annotation.Transactional;

/**
* The type Completed state.
*/
public class CompletedState extends State implements Stateful {

private static final Logger LOGGER = LoggerFactory.getLogger(CompletedState.class);
private static final String STATE_NAME = "COMPLETED";

/**
* Instantiates a new Completed state.
*
* @param debiasMachine the debias machine
* @param detectRepository the detect repository
*/
public CompletedState(DetectService debiasMachine, DetectRepository detectRepository) {
this.stateMachine = debiasMachine;
this.name = STATE_NAME;
Expand All @@ -16,18 +28,18 @@ public CompletedState(DetectService debiasMachine, DetectRepository detectReposi
}

@Override
public void fail(Long datasetId) {
public void fail(Integer datasetId) {
this.stateMachine.setState(this.stateMachine.getError());
}

@Override
public void success(Long datasetId) {
public void success(Integer datasetId) {
// do nothing, processing completed.
}

@Transactional
@Override
public boolean process(Long datasetId) {
public boolean process(Integer datasetId) {
LOGGER.info("{} {}", STATE_NAME, datasetId);
try {
DetectionEntity detectionEntity = detectRepository.findDetectionEntityByDatasetId_DatasetId(datasetId);
Expand All @@ -49,6 +61,11 @@ public boolean process(Long datasetId) {
return terminalState;
}

/**
* Gets name.
*
* @return the name
*/
public String getName() {
return STATE_NAME;
}
Expand Down
Loading

0 comments on commit f811fdc

Please sign in to comment.