Skip to content

Commit

Permalink
Refactoring; fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBestPessimist committed Nov 1, 2019
1 parent d36c169 commit e58e2ae
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 62 deletions.
Expand Up @@ -22,15 +22,6 @@

package de.metas.shipper.gateway.dpd;

import de.metas.shipper.gateway.spi.model.PackageDimensions;
import de.metas.shipper.gateway.spi.model.PickupDate;
import lombok.NonNull;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

public class DPDConstants
{
// TODO
Expand All @@ -49,48 +40,4 @@ public static class DpdNotificationChannel
public static int EMAIL = 1;
public static int SMS = 3;
}

/**
* dpd wants to store the volume in the format LLLWWWHHH as an Integer.
* how am i supposed to store the leading zeroes in an int!!?!?!?!?!?!!?
* eg. for
* - l = 10 cm
* - w = 20 cm
* - h = 30 cm
* => volume = Integer(magically)(010020030)
* wtf dpd?!?
* i'm not even shamed of this.
*/
public static int formatVolume(@NonNull final PackageDimensions packageDimensions)
{
return Integer.parseInt(String.format("%03d%03d%03d", packageDimensions.getLengthInCM(), packageDimensions.getWidthInCM(), packageDimensions.getHeightInCM()));
}

/**
* Return date as Integer in format `YYYYMMDD`
*/
public static int formatDate(@NonNull final LocalDate date)
{
return Integer.parseInt(date.format(DateTimeFormatter.BASIC_ISO_DATE));
}

/**
* Return Day Of Week as Integer
* - 0 = Sunday
* - 1 = Monday
* - etc.
*/
public static int getPickupDayOfTheWeek(@NonNull final PickupDate pickupDate)
{
final DayOfWeek dayOfWeek = pickupDate.getDate().getDayOfWeek();
return dayOfWeek.getValue() % 7;
}

/**
* Return the time as Integer in format `hhmm`
*/
public static int formatTime(@NonNull final LocalTime time)
{
return Integer.parseInt(time.format(DateTimeFormatter.ofPattern("HHmm")));
}
}
Expand Up @@ -23,11 +23,12 @@
package de.metas.shipper.gateway.dpd.model;

/**
* Defines the shipment type
* Defines the shipment type.
* It is somehow related to service type (aka dpd product), but i don't understand how.
*/
public class DpdOrderType
{
public static final String CONSIGNMENT = "consignment";
public static final String CONSIGNMENT = "consignment"; // i think this is the default
public static final String COLLECTION_REQUEST_ORDER = "collection request order";
public static final String PICKUP_INFORMATION = "pickup information";
}
Expand Up @@ -30,7 +30,6 @@
@UtilityClass
public class DpdClientUtil
{

public static final String LOGIN_SERVICE_API_URL = "https://public-ws-stage.dpd.com/services/LoginService/V2_0/";
public static final String SHIPMENT_SERVICE_API_URL = "https://public-ws-stage.dpd.com/services/ShipmentService/V3_2/";

Expand Down
@@ -0,0 +1,81 @@
/*
* #%L
* de.metas.shipper.gateway.dpd
* %%
* Copyright (C) 2019 metas GmbH
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-2.0.html>.
* #L%
*/

package de.metas.shipper.gateway.dpd.util;

import de.metas.shipper.gateway.spi.model.PackageDimensions;
import de.metas.shipper.gateway.spi.model.PickupDate;
import lombok.NonNull;
import lombok.experimental.UtilityClass;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

@UtilityClass
public class DpdConversionUtil
{
/**
* dpd wants to store the volume in the format LLLWWWHHH as an Integer.
* how am i supposed to store the leading zeroes in an int!!?!?!?!?!?!!?
* eg. for
* - l = 10 cm
* - w = 20 cm
* - h = 30 cm
* => volume = Integer(magically)(010020030)
* wtf dpd?!?
* i'm not even shamed of this.
*/
public static int formatVolume(@NonNull final PackageDimensions packageDimensions)
{
return Integer.parseInt(String.format("%03d%03d%03d", packageDimensions.getLengthInCM(), packageDimensions.getWidthInCM(), packageDimensions.getHeightInCM()));
}

/**
* Return date as Integer in format `YYYYMMDD`
*/
public static int formatDate(@NonNull final LocalDate date)
{
return Integer.parseInt(date.format(DateTimeFormatter.BASIC_ISO_DATE));
}

/**
* Return Day Of Week as Integer
* - 0 = Sunday
* - 1 = Monday
* - etc.
*/
public static int getPickupDayOfTheWeek(@NonNull final PickupDate pickupDate)
{
final DayOfWeek dayOfWeek = pickupDate.getDate().getDayOfWeek();
return dayOfWeek.getValue() % 7;
}

/**
* Return the time as Integer in format `hhmm`
*/
public static int formatTime(@NonNull final LocalTime time)
{
return Integer.parseInt(time.format(DateTimeFormatter.ofPattern("HHmm")));
}
}
Expand Up @@ -198,7 +198,7 @@ static void dumpPdfToDisk(final byte[] pdf)
{
Files.write(Paths.get("C:", "a", Instant.now().toString().replace(":", ".") + ".pdf"), pdf);
}
catch (IOException e)
catch (final IOException e)
{
e.printStackTrace();
}
Expand Down
Expand Up @@ -40,6 +40,7 @@
import de.metas.shipper.gateway.dpd.model.DPDServiceType;
import de.metas.shipper.gateway.dpd.model.DpdOrderType;
import de.metas.shipper.gateway.dpd.util.DpdClientUtil;
import de.metas.shipper.gateway.dpd.util.DpdConversionUtil;
import de.metas.shipper.gateway.dpd.util.DpdSoapHeaderWithAuth;
import de.metas.shipper.gateway.spi.model.ContactPerson;
import de.metas.shipper.gateway.spi.model.DeliveryOrder;
Expand Down Expand Up @@ -154,7 +155,7 @@ private StoreOrders createStoreOrdersFromDeliveryOrder(final DeliveryOrder deliv
final Parcel parcel = shipmentServiceOF.createParcel();
shipmentServiceData.getParcels().add(parcel);
parcel.setContent(deliveryPosition.getContent());
parcel.setVolume(DPDConstants.formatVolume(deliveryPosition.getPackageDimensions()));
parcel.setVolume(DpdConversionUtil.formatVolume(deliveryPosition.getPackageDimensions()));
parcel.setWeight(deliveryPosition.getGrossWeightKg() * 100); // uom = decagram (1dag = 10g => 100dag = 1kg)
// parcel.setInternational(); // todo god save us
}
Expand Down Expand Up @@ -186,10 +187,10 @@ private Pickup createPickupDateAndTime(@NonNull final PickupDate pickupDate, fin
{
final Pickup pickup = shipmentServiceOF.createPickup();
pickup.setQuantity(numberOfPackages);
pickup.setDate(DPDConstants.formatDate(pickupDate.getDate()));
pickup.setDay(DPDConstants.getPickupDayOfTheWeek(pickupDate));
pickup.setFromTime1(DPDConstants.formatTime(pickupDate.getTimeFrom()));
pickup.setToTime1(DPDConstants.formatTime(pickupDate.getTimeTo()));
pickup.setDate(DpdConversionUtil.formatDate(pickupDate.getDate()));
pickup.setDay(DpdConversionUtil.getPickupDayOfTheWeek(pickupDate));
pickup.setFromTime1(DpdConversionUtil.formatTime(pickupDate.getTimeFrom()));
pickup.setToTime1(DpdConversionUtil.formatTime(pickupDate.getTimeTo()));
// pickup.setExtraPickup(true); // optional
pickup.setCollectionRequestAddress(createAddress(sender));
return pickup;
Expand Down

0 comments on commit e58e2ae

Please sign in to comment.