Skip to content

Commit

Permalink
Revert "#00 | fix for the SNCU sync issue"
Browse files Browse the repository at this point in the history
This reverts commit 7c3ecf9.
  • Loading branch information
vindeolal committed May 6, 2021
1 parent fbc3917 commit 9b24561
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@
import org.openchs.dao.*;
import org.openchs.domain.Checklist;
import org.openchs.domain.ChecklistDetail;
import org.openchs.domain.ProgramEnrolment;
import org.openchs.domain.User;
import org.openchs.framework.security.UserContextHolder;
import org.openchs.service.UserService;
import org.openchs.web.request.ChecklistRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
Expand All @@ -25,15 +20,12 @@
import java.util.Collections;
import java.util.List;

import static java.lang.String.format;

@RestController
public class ChecklistController extends AbstractController<Checklist> implements RestControllerResourceProcessor<Checklist>, OperatingIndividualScopeAwareController<Checklist>, OperatingIndividualScopeAwareFilterController<Checklist> {
private final ChecklistDetailRepository checklistDetailRepository;
private final ChecklistRepository checklistRepository;
private final ProgramEnrolmentRepository programEnrolmentRepository;
private final UserService userService;
private final Logger logger;

@Autowired
public ChecklistController(ChecklistRepository checklistRepository,
Expand All @@ -43,27 +35,15 @@ public ChecklistController(ChecklistRepository checklistRepository,
this.checklistRepository = checklistRepository;
this.programEnrolmentRepository = programEnrolmentRepository;
this.userService = userService;
logger = LoggerFactory.getLogger(this.getClass());
}

@Transactional
@RequestMapping(value = "/txNewChecklistEntitys", method = RequestMethod.POST)
@PreAuthorize(value = "hasAnyAuthority('user', 'organisation_admin')")
public void save(@RequestBody ChecklistRequest checklistRequest) {
Checklist checklist = newOrExistingEntity(checklistRepository, checklistRequest, new Checklist());
ProgramEnrolment programEnrolment = programEnrolmentRepository.findByUuid(checklistRequest.getProgramEnrolmentUUID());
// TODO: this hot fix is done for the user jyotsna@sncu who did not sync the entire data and started editing the
// old enrolments. This generated duplicate checklist on the client, so now she's not able to sync her data.
// This should be removed once she has synced her data to server
User user = UserContextHolder.getUser();
Checklist oldChecklist = checklistRepository.findByProgramEnrolmentId(programEnrolment.getId());
if (user != null && user.getUsername().equals("jyotsna@sncu") && oldChecklist != null && !oldChecklist.getUuid().equals(checklist.getUuid())) {
logger.info(format("Skipping checklist save for enrolment uuid %s", programEnrolment.getUuid()));
// We skip all the duplicate checklists for an enrolment
return;
}
checklist.setChecklistDetail(this.checklistDetailRepository.findByUuid(checklistRequest.getChecklistDetailUUID()));
checklist.setProgramEnrolment(programEnrolment);
checklist.setProgramEnrolment(programEnrolmentRepository.findByUuid(checklistRequest.getProgramEnrolmentUUID()));
checklist.setBaseDate(checklistRequest.getBaseDate());
checklistRepository.save(checklist);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import org.joda.time.DateTime;
import org.openchs.dao.*;
import org.openchs.domain.*;
import org.openchs.framework.security.UserContextHolder;
import org.openchs.domain.Checklist;
import org.openchs.domain.ChecklistDetail;
import org.openchs.domain.ChecklistItem;
import org.openchs.service.ObservationService;
import org.openchs.service.UserService;
import org.openchs.web.request.application.ChecklistItemRequest;
Expand Down Expand Up @@ -56,14 +57,6 @@ public void save(@RequestBody ChecklistItemRequest checklistItemRequest) {
checklistItem.setObservations(this.observationService.createObservations(checklistItemRequest.getObservations()));
if (checklistItem.isNew()) {
Checklist checklist = checklistRepository.findByUuid(checklistItemRequest.getChecklistUUID());
// TODO: this hot fix is done for the user jyotsna@sncu who did not sync the entire data and started editing the
// old enrolments. This generated duplicate checklist on the client, so now she's not able to sync her data.
// This should be removed once she has synced her data to server
User user = UserContextHolder.getUser();
if (checklist == null && user != null && user.getUsername().equals("jyotsna@sncu")) {
// We skip all the checklist items generated for duplicate checklist
return;
}
checklistItem.setChecklist(checklist);
checklistItem.setChecklistItemDetail(checklistItemDetailRepository.findByUuid(checklistItemRequest.getChecklistItemDetailUUID()));
}
Expand Down

0 comments on commit 9b24561

Please sign in to comment.