class MovementRepository {

    public MovementRequest saveMovement(final MovementRequest movementRequest) {
        ProcessInstance processInstance = new ProcessInstance();
        Long stateId = null;
        if (StringUtils.isEmpty(movementRequest.getType()))
            processInstance = workFlowService.start(movementRequest);
        if (processInstance.getId() != null)
            stateId = Long.valueOf(processInstance.getId());
        final Date now = new Date();
        final UserResponse userResponse = userService.findUserByUserNameAndTenantId(movementRequest.getRequestInfo());
        for (final Movement movement : movementRequest.getMovement()) {
            movement.setStateId(stateId);
            final Object[] obj = new Object[]{movement.getId(), movement.getEmployeeId(), movement.getTypeOfMovement().toString(),
                    movement.getCurrentAssignment(), movement.getTransferType().toString(),
                    movement.getPromotionBasis().getId(), movement.getRemarks(), movement.getReason().getId(),
                    movement.getEffectiveFrom(), movement.getEnquiryPassedDate(), movement.getTransferedLocation(),
                    movement.getDepartmentAssigned(), movement.getDesignationAssigned(), movement.getPositionAssigned(),
                    movement.getFundAssigned(), movement.getFunctionAssigned(), movement.getEmployeeAcceptance(),
                    movement.getStatus(), movement.getStateId(), userResponse.getUsers().get(0).getId(), now,
                    userResponse.getUsers().get(0).getId(), now, movement.getTenantId()};
            if (movement.getDocuments() != null && !movement.getDocuments().isEmpty())
                documentsRepository.save(movement.getId(), movement.getDocuments(), movement.getTenantId());
            jdbcTemplate.update(MovementQueryBuilder.insertMovementQuery(), obj);
        }
        return movementRequest;
    }

}