src/com/vehiclerental/presentationLayer/headOffice/UserHeadOfficeController.java
/**
     * Book a vehicle for the authenticated user in the given branch with the given properties
     *
     * @param request the request parameters
     * @return the result response
     */
Book a vehicle for the authenticated user in the given branch with the given properties
@param request the request parameters
@return the result response
Book a vehicle for the authenticated user in the given branch with the given properties @param request the request parameters @return the result response
public static HeadOfficeResponseMessage HandleBookVehicle(HeadOfficeRequestMessage request) {
        Branch destBranch = getRequestBranch(request);
        if (destBranch == null) {
            return generateError(request.OperationCode, 404, "Branch not found");
        }
        try {
            User user;
            CreateBookingContract createBookingContract = SerializationUtils.deserialize(request.SerializedObject, CreateBookingContract.class);
            if (createBookingContract.bookingOwnerUserId != null) {
                user = doAuthentication(request.getAuthEmail(), request.getAuthPassword(), true);
            } else {
                user = doAuthentication(request.getAuthEmail(), request.getAuthPassword(), false);
            }
            ClusterCommunicationObject<String> rawClusterResponse = ForwardRequestToBranch(destBranch, request.OperationCode, createBookingContract, user);
            Type jsonType = new TypeToken<BranchResponseMessage<BookingContract>>() {}.getType();
            BranchResponseMessage<BookingContract> clusteResponse = SerializationUtils.deserialize(rawClusterResponse.object, jsonType);
            if (clusteResponse.Status != 200) {
                return generateError(request.OperationCode, clusteResponse.Status, clusteResponse.Error);
            }
            return generateSuccessfulResponse(request.OperationCode, clusteResponse.Object);
        } catch (ClusterCommunicatorException e) {
            return generateError(request.OperationCode, 500, "Server error");
        } catch (NotAuthorizedException e) {
            return generateError(request.OperationCode, 401, "Unauthorized");
        }
    }
public static HeadOfficeResponseMessage HandleBookVehicle ( HeadOfficeRequestMessage request ) { Branch destBranch = getRequestBranch ( request ) ; if ( destBranch == null ) { return generateError ( request . OperationCode , 404 , "Branch not found" ) ; } try { User user ; CreateBookingContract createBookingContract = SerializationUtils . deserialize ( request . SerializedObject , CreateBookingContract . class ) ; if ( createBookingContract . bookingOwnerUserId != null ) { user = doAuthentication ( request . getAuthEmail ( ) , request . getAuthPassword ( ) , true ) ; } else { user = doAuthentication ( request . getAuthEmail ( ) , request . getAuthPassword ( ) , false ) ; } ClusterCommunicationObject < String > rawClusterResponse = ForwardRequestToBranch ( destBranch , request . OperationCode , createBookingContract , user ) ; Type jsonType = new TypeToken < BranchResponseMessage < BookingContract > > ( ) { } . getType ( ) ; BranchResponseMessage < BookingContract > clusteResponse = SerializationUtils . deserialize ( rawClusterResponse . object , jsonType ) ; if ( clusteResponse . Status != 200 ) { return generateError ( request . OperationCode , clusteResponse . Status , clusteResponse . Error ) ; } return generateSuccessfulResponse ( request . OperationCode , clusteResponse . Object ) ; } catch ( ClusterCommunicatorException e ) { return generateError ( request . OperationCode , 500 , "Server error" ) ; } catch ( NotAuthorizedException e ) { return generateError ( request . OperationCode , 401 , "Unauthorized" ) ; } }
Book a vehicle for the authenticated user in the given branch with the given properties
 @param request the request parameters
 @return the result response
Book a vehicle for the authenticated user in the given branch with the given properties @param request the request parameters @return the result response
//In this case, the booking is made for someone, so we require staff credentials //User credentials are required otherwise //Parse cluster response //Form socket response //e.printStackTrace();