Search in sources :

Example 1 with DeduplicationMergeParams

use of org.hisp.dhis.deduplication.DeduplicationMergeParams in project dhis2-core by dhis2.

the class DeduplicationController method mergePotentialDuplicate.

@PostMapping(value = "/{id}/merge")
@ResponseStatus(value = HttpStatus.OK)
public void mergePotentialDuplicate(@PathVariable String id, @RequestParam(defaultValue = "AUTO") MergeStrategy mergeStrategy, @RequestBody(required = false) MergeObject mergeObject) throws NotFoundException, PotentialDuplicateConflictException, PotentialDuplicateForbiddenException {
    PotentialDuplicate potentialDuplicate = getPotentialDuplicateBy(id);
    if (potentialDuplicate.getOriginal() == null || potentialDuplicate.getDuplicate() == null) {
        throw new PotentialDuplicateConflictException("PotentialDuplicate is missing references and cannot be merged.");
    }
    TrackedEntityInstance original = getTei(potentialDuplicate.getOriginal());
    TrackedEntityInstance duplicate = getTei(potentialDuplicate.getDuplicate());
    if (mergeObject == null) {
        mergeObject = new MergeObject();
    }
    DeduplicationMergeParams params = DeduplicationMergeParams.builder().potentialDuplicate(potentialDuplicate).mergeObject(mergeObject).original(original).duplicate(duplicate).build();
    if (MergeStrategy.MANUAL.equals(mergeStrategy)) {
        deduplicationService.manualMerge(params);
    } else {
        deduplicationService.autoMerge(params);
    }
}
Also used : PotentialDuplicateConflictException(org.hisp.dhis.deduplication.PotentialDuplicateConflictException) MergeObject(org.hisp.dhis.deduplication.MergeObject) PotentialDuplicate(org.hisp.dhis.deduplication.PotentialDuplicate) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) DeduplicationMergeParams(org.hisp.dhis.deduplication.DeduplicationMergeParams) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus)

Aggregations

DeduplicationMergeParams (org.hisp.dhis.deduplication.DeduplicationMergeParams)1 MergeObject (org.hisp.dhis.deduplication.MergeObject)1 PotentialDuplicate (org.hisp.dhis.deduplication.PotentialDuplicate)1 PotentialDuplicateConflictException (org.hisp.dhis.deduplication.PotentialDuplicateConflictException)1 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)1