All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.hypertrack.factory.DriverFactory Maven / Gradle / Ivy

There is a newer version: 1.0.1
Show newest version
package io.hypertrack.factory;

import io.hypertrack.model.Driver;
import io.hypertrack.net.HyperTrackClient;
import io.hypertrack.net.HyperTrackException;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

/**
 * Factory class for Driver model.
 */
public class DriverFactory extends HyperTrackFactory {
    private static String modelUrl = "drivers/";

    public DriverFactory(HyperTrackClient client) {
        super(client);
    }

    @Override
    protected Driver makeNew(Map params) {
        return new Driver(params);
    }

    @Override
    protected String getModelUrl() {
        return modelUrl;
    }

    /**
     * Patch driver instance with a photo.
     *
     * @param   driver      Driver instance to be patched
     * @param   photo       Photo file
     */
    public void patchWithPhoto(Driver driver, File photo) {
        String driverId = driver.getId();
        HyperTrackClient client = getClient();
        try {
            Map fileParam = new HashMap<>();
            fileParam.put("photo", photo);
            String response = client.request(getInstanceUrl(driverId), fileParam);
            updateFromParams(driver, getMapFromResponse(response));
        } catch (HyperTrackException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy