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

de.aipark.api.parkingarea.ParkingArea Maven / Gradle / Ivy

package de.aipark.api.parkingarea;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.Point;
import de.aipark.api.chargingstation.ChargingPlugType;
import de.aipark.api.payment.PriceModel;
import io.swagger.annotations.ApiModelProperty;

import java.util.*;

/**
 * Created by torgen on 24.08.17.
 */
@SuppressWarnings({"WeakerAccess", "unused"})
@JsonIgnoreProperties(ignoreUnknown = true)
public class ParkingArea {
    @ApiModelProperty(value = "name of parking area", dataType = "java.lang.String", required = true, example = "Rathaus")
    private String name;

    @ApiModelProperty(value = "shape of parking area, e.g. multipolygon for areas or line for on street parking", required = true)
    private Geometry shape;

    @ApiModelProperty(value = "center point of parking area", required = true)
    private Point center;

    @ApiModelProperty(value = "capacity of parking area (number of spots)", dataType = "java.lang.Integer", required = true, example = "100")
    private Integer capacity;

    @ApiModelProperty(value = "type of parking area, types getting added in the future", dataType = "de.aipark.api.parkingarea.ParkingAreaType", required = true, example = "ON_STREET")
    private String parkingAreaType;

    @ApiModelProperty(value = "orientation of parking", dataType = "de.aipark.api.parkingarea.ParkingOrientation", example = "PARALLEL")
    private ParkingOrientation parkingOrientation;// = ParkingOrientation.getDefaultValue();

    @ApiModelProperty(value = "unique id of parking area", dataType = "java.lang.Long", required = true, example = "504838")
    private Long id;

    @ApiModelProperty(value =
            "value=null indicates no information about capacity designated for disabled, " +
                    "value>0 indicates number of spots designated for women, " +
                    "value=0 indicates no special capacity for women, " +
                    "value=-1 indicates that there are spots designated for women but capacity is unknown",
            dataType = "java.lang.Integer", example = "10")
    private Integer capacityWoman;

    @ApiModelProperty(value =
            "value=null indicates no information about capacity designated for disabled, " +
                    "value>0 indicates number of spots designated for disabled, " +
                    "value=0 indicates no special capacity for disabled, " +
                    "value=-1 indicates that there are spots designated for disabled but capacity is unknown",
            dataType = "java.lang.Integer", example = "10")
    private Integer capacityDisabled;

    @ApiModelProperty(value = "schedule when parking area is opened or closed", dataType = "MapEntry")
    private MapEntry scheduleOpen;

    @ApiModelProperty(value = "schedule for parking disc (value = allowed time in minutes)", dataType = "MapEntry")
    private MapEntry scheduleMaxStay;

    @ApiModelProperty(value = "price model mapping", dataType = "MapEntry")
    private MapEntry schedulePriceModel;

    @ApiModelProperty(value = "schedule with capacity of parking area (number of spots) for residential parking only", dataType = "MapEntry")
    private MapEntry scheduleResidential;

    @ApiModelProperty(value = "entrance point for parking area", dataType = "List")
    private List entrancePoints;

    /**
     * will be removed in future release. Use special designated charging station methods.
     */
//    @JsonIgnore
    @Deprecated
    @ApiModelProperty(value = "mapping of charging plug type to number of plugs with this type", dataType = "MapEntry")
    private MapEntry chargingPlugTypes; //TODO: remove

    public ParkingArea() {
        scheduleOpen = new MapEntry();
        scheduleMaxStay = new MapEntry();
        schedulePriceModel = new MapEntry();
        scheduleResidential = new MapEntry();
        entrancePoints = new ArrayList();
        chargingPlugTypes = new MapEntry(); //TODO: remove
    }

//    /**
//     * use other constructor, this may be removed in future release
//     */
//    @Deprecated
//    public ParkingArea(String name, Geometry shape, Point center, Integer capacity, String parkingAreaType,
//                       Long id, Integer capacityWoman, Integer capacityDisabled, MapEntry scheduleOpen,
//                       MapEntry scheduleMaxStay, MapEntry schedulePriceModel, MapEntry scheduleResidential, List entrancePoints, MapEntry chargingPlugTypes) {
//        this(name, shape, center, capacity, parkingAreaType, null, id, capacityWoman, capacityDisabled, scheduleOpen,
//                scheduleMaxStay, schedulePriceModel, scheduleResidential, entrancePoints, chargingPlugTypes);
//    }

    public ParkingArea(String name, Geometry shape, Point center, Integer capacity, String parkingAreaType, ParkingOrientation parkingOrientation,
                       Long id, Integer capacityWoman, Integer capacityDisabled, MapEntry scheduleOpen,
                       MapEntry scheduleMaxStay, MapEntry schedulePriceModel, MapEntry scheduleResidential, List entrancePoints, MapEntry chargingPlugTypes) {
        this.name = name;
        this.shape = shape;
        this.center = center;
        this.capacity = capacity;
        this.parkingAreaType = parkingAreaType;
        this.parkingOrientation = parkingOrientation;
        this.id = id;
        this.capacityWoman = capacityWoman;
        this.capacityDisabled = capacityDisabled;
        this.scheduleOpen = scheduleOpen;
        this.scheduleMaxStay = scheduleMaxStay;
        this.schedulePriceModel = schedulePriceModel;
        this.scheduleResidential = scheduleResidential;
        this.entrancePoints = entrancePoints;
//        this.chargingPlugTypes = chargingPlugTypes;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Geometry getShape() {
        return shape;
    }

    public void setShape(Geometry shape) {
        this.shape = shape;
    }

    public Integer getCapacity() {
        return capacity;
    }

    public void setCapacity(Integer capacity) {
        this.capacity = capacity;
    }

    public ParkingAreaType getParkingAreaType() {
        try {
            return ParkingAreaType.valueOf(parkingAreaType);
        } catch (IllegalArgumentException e) {
            return ParkingAreaType.PARKINGAREA;
        }
    }

    public void setParkingAreaType(String parkingAreaType) {
        this.parkingAreaType = parkingAreaType;
    }

    public ParkingOrientation getParkingOrientation() {
        return parkingOrientation;
    }

    public void setParkingOrientation(ParkingOrientation parkingOrientation) {
        this.parkingOrientation = parkingOrientation;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Integer getCapacityWoman() {
        return capacityWoman;
    }

    public void setCapacityWoman(Integer capacityWoman) {
        this.capacityWoman = capacityWoman;
    }

    public Integer getCapacityDisabled() {
        return capacityDisabled;
    }

    public void setCapacityDisabled(Integer capacityDisabled) {
        this.capacityDisabled = capacityDisabled;
    }

    public MapEntry getScheduleOpen() {
        return scheduleOpen;
    }

    public void setScheduleOpen(MapEntry scheduleOpen) {
        this.scheduleOpen = scheduleOpen;
    }

    public MapEntry getScheduleMaxStay() {
        return scheduleMaxStay;
    }

    public void setScheduleMaxStay(MapEntry scheduleMaxStay) {
        this.scheduleMaxStay = scheduleMaxStay;
    }

    public MapEntry getSchedulePriceModel() {
        return schedulePriceModel;
    }

    public void setSchedulePriceModel(MapEntry schedulePriceModel) {
        this.schedulePriceModel = schedulePriceModel;
    }

    public MapEntry getScheduleResidential() {
        return scheduleResidential;
    }

    public void setScheduleResidential(MapEntry scheduleResidential) {
        this.scheduleResidential = scheduleResidential;
    }

    public List getEntrancePoints() {
        return entrancePoints;
    }

    public void setEntrancePoints(List entrancePoints) {
        this.entrancePoints = entrancePoints;
    }

    /**
     * will be removed in future release. Use special designated charging station methods.
     */
//    //@JsonIgnore
    @Deprecated
    public MapEntry getChargingPlugTypes() { //TODO: remove
        return chargingPlugTypes;
    }

    /**
     * will be removed in future release. Use special designated charging station methods.
     */
    @Deprecated
    public void setChargingPlugTypes(MapEntry chargingPlugTypes) { //TODO: remove
        this.chargingPlugTypes = chargingPlugTypes;
    }

    public Point getCenter() {
        return center;
    }

    public void setCenter(Point center) {
        this.center = center;
    }

    @Override
    public String toString() {
        return "ParkingArea{" +
                "name='" + name + '\'' +
                ", shape=" + shape +
                ", center=" + center +
                ", capacity=" + capacity +
                ", parkingAreaType='" + parkingAreaType + '\'' +
                ", parkingOrientation=" + parkingOrientation +
                ", id=" + id +
                ", capacityWoman=" + capacityWoman +
                ", capacityDisabled=" + capacityDisabled +
                ", scheduleOpen=" + scheduleOpen +
                ", scheduleMaxStay=" + scheduleMaxStay +
                ", schedulePriceModel=" + schedulePriceModel +
                ", scheduleResidential=" + scheduleResidential +
                ", entrancePoints=" + entrancePoints +
//                ", chargingPlugTypes=" + chargingPlugTypes +
                '}';
    }

    @SuppressWarnings("StringConcatenationInLoop") //compatibility with js converter
    @JsonIgnore
    public String getPriceString() {
        ResourceBundle bundle = ResourceBundle.getBundle("Api");
        String result = "";
        Map> scheduleListMap = new HashMap>();
        for (MapEntry.Entry entry : schedulePriceModel.getEntryList()) {
            List priceModels = scheduleListMap.get(entry.getKey());
            if (priceModels == null) {
                priceModels = new ArrayList();
            }
            priceModels.add(entry.getValue());
            scheduleListMap.put(entry.getKey(), priceModels);
        }
        List schedules = new ArrayList(scheduleListMap.keySet());
        Collections.sort(schedules);
        boolean onlyDefaultPriceModels = false;
        for (Schedule schedule : schedules) {
            if (schedule.toString().isEmpty()) {
                if (schedules.size() > 1) {
                    result += bundle.getString("otherwise") + ":\n";
                } else {
                    onlyDefaultPriceModels = true;
                }
            } else {
                result += schedule.toString() + ":\n";
            }
            List priceModels = new ArrayList(scheduleListMap.get(schedule));
            Collections.sort(priceModels);
            boolean hasPeriodPricemodels = false;
            for (PriceModel priceModel : priceModels) {
                if (!onlyDefaultPriceModels) {
                    result += "\t";
                }
                if (priceModel.getFromMinute() != null || priceModel.getUntilMinute() != null) {
                    hasPeriodPricemodels = true;
                } else if (hasPeriodPricemodels && priceModel.getInterval() != null && priceModel.getMaxPriceInCent() == null) {
                    result += bundle.getString("otherwise") + " ";
                }
                result += priceModel.toString() + "\n";
            }
        }
        return result;
    }

    @SuppressWarnings("StringConcatenationInLoop") //compatibility with js converter
    @JsonIgnore
    public String getMaxStayString() {
        ResourceBundle bundle = ResourceBundle.getBundle("Api");
        String result = "";
        for (MapEntry.Entry entry : scheduleMaxStay.getEntryList()) {
            if (!result.isEmpty()) {
                result += "\n";
            }
            result += entry.getKey().toString() + " " + bundle.getString("maximal") + " " + entry.getValue() + " " + bundle.getString("minutes");
        }
        return result;
    }

    @SuppressWarnings("StringConcatenationInLoop") //compatibility with js converter
    @JsonIgnore
    public String getOpeningHoursString() {
        ResourceBundle bundle = ResourceBundle.getBundle("Api");
        String result = "";
        for(MapEntry.Entry entry :scheduleOpen.getEntryList()){
            String opened = bundle.getString("closed");
            if(entry.getValue().equals(OpeningStatus.OPEN)){
                    opened = bundle.getString("open");
            }
            result += entry.getKey().toString() + " " + opened + "\n";
        }
        if(result.length() > 0){
            result = result.substring(0, result.length() - 1);
        }
        return result;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy