Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public static void addYearToStudyAdditionalInfo(Program program, BrAPIStudy stud
* @throws IllegalStateException if any ObsUnit ID is repeated in the import rows
* @throws HttpStatusException if there is a mix of ObsUnit IDs for some but not all rows
*/
public static Set<String> collateReferenceOUIds(AppendOverwriteMiddlewareContext context) {
public static Set<String> collateReferenceOUIds(AppendOverwriteMiddlewareContext context) throws HttpStatusException, IllegalStateException {
// Initialize variables to track the presence of ObsUnit IDs
Set<String> referenceOUIds = new HashSet<>();
boolean hasNoReferenceUnitIds = true;
Expand All @@ -333,7 +333,7 @@ public static Set<String> collateReferenceOUIds(AppendOverwriteMiddlewareContext

if (!hasNoReferenceUnitIds && !hasAllReferenceUnitIds) {
// Throw exception if there is a mix of ObsUnit IDs for some but not all rows
throw new HttpStatusException(HttpStatus.UNPROCESSABLE_ENTITY, ExpImportProcessConstants.ErrMessage.MISSING_OBS_UNIT_ID_ERROR);
throw new HttpStatusException(HttpStatus.UNPROCESSABLE_ENTITY, ExpImportProcessConstants.ErrMessage.MISSING_OBS_UNIT_ID_ERROR.getValue());
}

return referenceOUIds;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,25 @@
package org.breedinginsight.brapps.importer.services.processors.experiment.appendoverwrite.middleware;

import io.micronaut.context.annotation.Prototype;
import io.micronaut.http.exceptions.HttpStatusException;
import lombok.extern.slf4j.Slf4j;
import org.breedinginsight.brapps.importer.services.processors.experiment.ExperimentUtilities;
import org.breedinginsight.brapps.importer.services.processors.experiment.appendoverwrite.model.AppendOverwriteMiddlewareContext;
import org.breedinginsight.brapps.importer.services.processors.experiment.appendoverwrite.model.AppendOverwriteMiddleware;
import org.breedinginsight.brapps.importer.services.processors.experiment.appendoverwrite.model.MiddlewareException;

@Slf4j
@Prototype
public class AppendOverwriteIDValidation extends AppendOverwriteMiddleware {
@Override
public AppendOverwriteMiddlewareContext process(AppendOverwriteMiddlewareContext context) {

context.getAppendOverwriteWorkflowContext().setReferenceOUIds(ExperimentUtilities.collateReferenceOUIds(context));
try {
context.getAppendOverwriteWorkflowContext().setReferenceOUIds(ExperimentUtilities.collateReferenceOUIds(context));
} catch (HttpStatusException | IllegalStateException e) {
context.getAppendOverwriteWorkflowContext().setProcessError(new MiddlewareException(e));
return this.compensate(context);
}
return processNext(context);
}

@Override
public AppendOverwriteMiddlewareContext compensate(AppendOverwriteMiddlewareContext context) {
// tag an error if it occurred in this local transaction
context.getAppendOverwriteWorkflowContext().getProcessError().tag(this.getClass().getName());

// undo the prior local transaction
return compensatePrior(context);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class ExpImportProcessConstants {

public enum ErrMessage {
MULTIPLE_EXP_TITLES("File contains more than one Experiment Title"),
MISSING_OBS_UNIT_ID_ERROR("Experimental entities are missing ObsUnitIDs"),
MISSING_OBS_UNIT_ID_ERROR("Required field is blank"),
PREEXISTING_EXPERIMENT_TITLE("Experiment Title already exists");

private String value;
Expand Down