@Before
  public void setUp() {

    jsfServiceMock = (JsfServiceMock) jsfService;
    currentUser.setProxyUser("admin", "test", new String[] {"VIEW_ENTITY", "CREATE_ENTITY"});

    mother = genericDao.findByProperty(Individual.class, "extId", "NBAS1I", false);
    fieldWorker = genericDao.findByProperty(FieldWorker.class, "extId", "FWEK1D");
    visit = genericDao.findByProperty(Visit.class, "extId", "VLOCMBI11J");
  }
  @RequestMapping(
      method = RequestMethod.POST,
      produces = "application/xml",
      consumes = "application/xml")
  @Transactional
  public ResponseEntity<? extends Serializable> processForm(
      @RequestBody InMigrationForm inMigrationForm) throws JAXBException {

    try {
      context = JAXBContext.newInstance(InMigrationForm.class);
      marshaller = context.createMarshaller();
      marshaller.setAdapter(adapter);
    } catch (JAXBException e) {
      throw new RuntimeException(
          "Could not create JAXB context and marshaller for InMigrationFormResource");
    }

    InMigration inMigration = new InMigration();

    inMigration.setRecordedDate(inMigrationForm.getMigrationDate());
    inMigration.setReason(inMigrationForm.getMigrationReason());
    inMigration.setOrigin(inMigrationForm.getMigrationOrigin());

    // TODO: determine a consistent configuration plan between siteProperties and MigrationType enum
    // TODO: (question) why use an enum and not the siteproperties?
    if ("internal_inmigration".equals(inMigrationForm.getMigrationType())) {
      inMigration.setMigType(MigrationType.INTERNAL_INMIGRATION);
    } else {
      inMigration.setMigType(MigrationType.EXTERNAL_INMIGRATION);
    }

    FieldWorker fieldWorker = fieldWorkerService.getByUuid(inMigrationForm.getFieldWorkerUuid());
    if (null == fieldWorker) {
      ConstraintViolations cv = new ConstraintViolations();
      cv.addViolations(
          ConstraintViolations.INVALID_FIELD_WORKER_UUID
              + " : "
              + inMigrationForm.getFieldWorkerUuid());
      logError(
          cv,
          fieldWorker,
          createDTOPayload(inMigrationForm),
          InMigrationForm.class.getSimpleName(),
          ConstraintViolations.INVALID_FIELD_WORKER_UUID);
      return requestError(cv);
    }
    inMigration.setCollectedBy(fieldWorker);

    Visit visit = visitService.findVisitByUuid(inMigrationForm.getVisitUuid());
    if (null == visit) {
      ConstraintViolations cv = new ConstraintViolations();
      cv.addViolations(
          ConstraintViolations.INVALID_VISIT_UUID + " : " + inMigrationForm.getVisitUuid());
      logError(
          cv,
          fieldWorker,
          createDTOPayload(inMigrationForm),
          InMigrationForm.class.getSimpleName(),
          ConstraintViolations.INVALID_VISIT_UUID);
      return requestError(cv);
    }
    inMigration.setVisit(visit);

    Individual individual = individualService.getByUuid(inMigrationForm.getIndividualUuid());
    if (null == individual) {
      ConstraintViolations cv = new ConstraintViolations();
      cv.addViolations(
          ConstraintViolations.INVALID_INDIVIDUAL_UUID
              + " : "
              + inMigrationForm.getIndividualUuid());
      logError(
          cv,
          fieldWorker,
          createDTOPayload(inMigrationForm),
          InMigrationForm.class.getSimpleName(),
          ConstraintViolations.INVALID_INDIVIDUAL_UUID);
      return requestError(cv);
    }
    inMigration.setIndividual(individual);

    Location location = locationService.getByUuid(inMigrationForm.getLocationUuid());
    if (null == location) {
      ConstraintViolations cv = new ConstraintViolations();
      cv.addViolations(
          ConstraintViolations.INVALID_LOCATION_UUID + " : " + inMigrationForm.getLocationUuid());
      logError(
          cv,
          fieldWorker,
          createDTOPayload(inMigrationForm),
          InMigrationForm.class.getSimpleName(),
          ConstraintViolations.INVALID_LOCATION_UUID);
      return requestError(cv);
    }

    Residency newResidency = new Residency();

    // TODO: since the InMigration domain model contains a reference to a Residency instead of a
    // Location,
    // we must assemble the Residency at this level to provide a fully-graphed InMigration to the
    // service
    newResidency.setCollectedBy(fieldWorker);

    newResidency.setLocation(location);
    newResidency.setIndividual(individual);
    newResidency.setUuid(UUID.randomUUID().toString().replace("-", ""));
    newResidency.setStartDate(inMigration.getRecordedDate());
    newResidency.setStartType(sitePropertiesService.getInmigrationCode());
    newResidency.setEndType(sitePropertiesService.getNotApplicableCode());

    if (null != currentUser) {
      newResidency.setInsertBy(currentUser.getCurrentUser());
    }

    Calendar insertDate = calendarUtil.convertDateToCalendar(new Date());
    newResidency.setInsertDate(insertDate);

    newResidency.setStatus(sitePropertiesService.getDataStatusPendingCode());

    inMigration.setResidency(newResidency);

    try {
      inMigrationService.create(inMigration);
    } catch (ConstraintViolations cv) {
      logError(
          cv,
          fieldWorker,
          createDTOPayload(inMigrationForm),
          InMigrationForm.class.getSimpleName(),
          ConstraintViolations.INVALID_IN_MIGRATION);
      return requestError(cv);
    }

    return new ResponseEntity<InMigrationForm>(inMigrationForm, HttpStatus.CREATED);
  }