/
PackageableRow.java
204 lines (175 loc) · 6.43 KB
/
PackageableRow.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
package de.metas.ui.web.pickingV2.packageable;
import java.time.LocalDate;
import java.time.ZonedDateTime;
import java.util.Collection;
import org.adempiere.warehouse.WarehouseTypeId;
import org.compiere.util.TimeUtil;
import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import de.metas.i18n.ITranslatableString;
import de.metas.inoutcandidate.api.Packageable;
import de.metas.inoutcandidate.api.ShipmentScheduleId;
import de.metas.inoutcandidate.model.I_M_Packageable_V;
import de.metas.order.OrderId;
import de.metas.ui.web.view.IViewRow;
import de.metas.ui.web.view.ViewRowFieldNameAndJsonValues;
import de.metas.ui.web.view.ViewRowFieldNameAndJsonValuesHolder;
import de.metas.ui.web.view.descriptor.annotation.ViewColumn;
import de.metas.ui.web.window.datatypes.DocumentId;
import de.metas.ui.web.window.datatypes.DocumentPath;
import de.metas.ui.web.window.datatypes.LookupValue;
import de.metas.ui.web.window.descriptor.DocumentFieldWidgetType;
import de.metas.user.UserId;
import de.metas.util.Check;
import lombok.Builder;
import lombok.Getter;
import lombok.NonNull;
import lombok.Singular;
import lombok.ToString;
/*
* #%L
* metasfresh-webui-api
* %%
* Copyright (C) 2018 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%
*/
@ToString(exclude = "values")
public final class PackageableRow implements IViewRow
{
public static PackageableRow cast(final IViewRow row)
{
return (PackageableRow)row;
}
@ViewColumn(widgetType = DocumentFieldWidgetType.Text, captionKey = I_M_Packageable_V.COLUMNNAME_C_OrderSO_ID, seqNo = 10)
@Getter
private final String orderDocumentNo;
@ViewColumn(widgetType = DocumentFieldWidgetType.Lookup, captionKey = I_M_Packageable_V.COLUMNNAME_C_BPartner_Customer_ID, seqNo = 20)
@Getter
private final LookupValue customer;
@ViewColumn(widgetType = DocumentFieldWidgetType.Text, captionKey = I_M_Packageable_V.COLUMNNAME_M_Warehouse_Type_ID, seqNo = 30)
private final ITranslatableString warehouseTypeName;
@ViewColumn(widgetType = DocumentFieldWidgetType.Integer, captionKey = "Lines", seqNo = 40)
private final int lines;
@ViewColumn(widgetType = DocumentFieldWidgetType.Text, captionKey = "Picking_User_ID", seqNo = 50)
private final LookupValue lockedByUser;
@ViewColumn(widgetType = DocumentFieldWidgetType.Lookup, captionKey = I_M_Packageable_V.COLUMNNAME_M_Shipper_ID, seqNo = 60)
private final LookupValue shipper;
@ViewColumn(widgetType = DocumentFieldWidgetType.LocalDate, captionKey = I_M_Packageable_V.COLUMNNAME_DeliveryDate, seqNo = 70)
private final LocalDate deliveryDate;
@ViewColumn(widgetType = DocumentFieldWidgetType.Text, captionKey = "LineNetAmt", seqNo = 80)
private final ITranslatableString lineNetAmt;
@ViewColumn(widgetType = DocumentFieldWidgetType.ZonedDateTime, captionKey = I_M_Packageable_V.COLUMNNAME_PreparationDate, seqNo = 80)
@Getter
private final ZonedDateTime preparationDate;
//
private final ViewRowFieldNameAndJsonValuesHolder<PackageableRow> values = ViewRowFieldNameAndJsonValuesHolder.newInstance(PackageableRow.class);
private final PackageableRowId rowId;
@Getter
private final ImmutableList<Packageable> packageables;
@Getter
private final ImmutableSet<ShipmentScheduleId> shipmentScheduleIds;
@Builder
private PackageableRow(
@NonNull final OrderId orderId,
@NonNull final String orderDocumentNo,
@NonNull final LookupValue customer,
final WarehouseTypeId warehouseTypeId,
final ITranslatableString warehouseTypeName,
final int lines,
final LookupValue lockedByUser,
final LookupValue shipper,
final ITranslatableString lineNetAmt,
@NonNull @Singular final Collection<Packageable> packageables)
{
Check.assumeNotEmpty(packageables, "packageables is not empty");
this.rowId = PackageableRowId.of(orderId, warehouseTypeId);
this.orderDocumentNo = orderDocumentNo;
this.customer = customer;
this.warehouseTypeName = warehouseTypeName;
this.lines = lines;
this.lockedByUser = lockedByUser;
this.shipper = shipper;
this.deliveryDate = calculateEarliestDeliveryDate(packageables);
this.lineNetAmt = lineNetAmt;
this.preparationDate = calculateEarliestPreparationTime(packageables);
this.packageables = ImmutableList.copyOf(packageables);
this.shipmentScheduleIds = extractShipmentScheduleIds(packageables);
}
private static LocalDate calculateEarliestDeliveryDate(final Collection<Packageable> packageables)
{
return packageables.stream()
.map(Packageable::getDeliveryDate)
.filter(Predicates.notNull())
.map(TimeUtil::asLocalDate)
.min(LocalDate::compareTo)
.orElse(null);
}
private static ZonedDateTime calculateEarliestPreparationTime(final Collection<Packageable> packageables)
{
return packageables.stream()
.map(Packageable::getPreparationDate)
.filter(Predicates.notNull())
.min(ZonedDateTime::compareTo)
.orElse(null);
}
private static ImmutableSet<ShipmentScheduleId> extractShipmentScheduleIds(final Collection<Packageable> packageables)
{
return packageables.stream()
.map(Packageable::getShipmentScheduleId)
.collect(ImmutableSet.toImmutableSet());
}
@Override
public DocumentId getId()
{
return rowId.getDocumentId();
}
@Override
public boolean isProcessed()
{
return false;
}
@Override
public DocumentPath getDocumentPath()
{
// TODO Auto-generated method stub
return null;
}
@Override
public ImmutableSet<String> getFieldNames()
{
return values.getFieldNames();
}
@Override
public ViewRowFieldNameAndJsonValues getFieldNameAndJsonValues()
{
return values.get(this);
}
public boolean isLocked()
{
return lockedByUser != null;
}
public boolean isNotLocked()
{
return !isLocked();
}
public boolean isLockedBy(@NonNull final UserId userId)
{
return lockedByUser != null
&& UserId.equals(userId, lockedByUser.getIdAs(UserId::ofRepoId));
}
}