/
C_Request_CreateFromInout_Async.java
158 lines (137 loc) · 4.41 KB
/
C_Request_CreateFromInout_Async.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
/*
* #%L
* de.metas.swat.base
* %%
* Copyright (C) 2020 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.request.service.async.spi.impl;
import com.google.common.base.MoreObjects;
import de.metas.async.api.IQueueDAO;
import de.metas.async.model.I_C_Queue_WorkPackage;
import de.metas.async.spi.WorkpackageProcessorAdapter;
import de.metas.async.spi.WorkpackagesOnCommitSchedulerTemplate;
import de.metas.inout.model.I_M_InOutLine;
import de.metas.request.api.IRequestBL;
import de.metas.util.Services;
import org.adempiere.ad.trx.api.ITrx;
import org.adempiere.util.lang.impl.TableRecordReference;
import org.compiere.util.Env;
import java.util.List;
import java.util.Properties;
public class C_Request_CreateFromInout_Async extends WorkpackageProcessorAdapter
{
/**
* Schedule the request creation based on the given inoutline ids
* <p>
* These requests will contain information taken from the lines and from their inout headers:
* <li>inout
* <li>product
* <li>partner
* <li>dateDelivered
* <li>qualityNotice
* <li>org
* <li>linked salesrep of the org, etc.
*/
public static void createWorkpackage(final List<Integer> inOutLineIds)
{
if (inOutLineIds == null || inOutLineIds.isEmpty())
{
// no lines to process
return;
}
for (final Integer inOutLineId : inOutLineIds)
{
if (inOutLineId == null || inOutLineId <= 0)
{
// should not happen
continue;
}
// Schedule the request creation based on the given inoutline ids
SCHEDULER.schedule(InOutLineWithQualityIssues.of(inOutLineId));
}
}
/**
* Class to keep information about the inout lines with quality issues (Quality Discount Percent).
* This model will be used ion the
*
* @author metas-dev <dev@metasfresh.com>
*/
private static final class InOutLineWithQualityIssues
{
public static InOutLineWithQualityIssues of(int inOutLineId)
{
return new InOutLineWithQualityIssues(inOutLineId);
}
private final int inOutLineId;
private InOutLineWithQualityIssues(int inOutLineId)
{
super();
this.inOutLineId = inOutLineId;
}
@Override
public String toString()
{
return MoreObjects.toStringHelper(this)
.add("inOutLineId", inOutLineId)
.toString();
}
public int getM_InOutLine_ID()
{
return inOutLineId;
}
}
private static final WorkpackagesOnCommitSchedulerTemplate<InOutLineWithQualityIssues> SCHEDULER = new WorkpackagesOnCommitSchedulerTemplate<InOutLineWithQualityIssues>(C_Request_CreateFromInout_Async.class)
{
@Override
protected boolean isEligibleForScheduling(final InOutLineWithQualityIssues model)
{
return model != null && model.getM_InOutLine_ID() > 0;
}
;
@Override
protected Properties extractCtxFromItem(final InOutLineWithQualityIssues item)
{
return Env.getCtx();
}
@Override
protected String extractTrxNameFromItem(final InOutLineWithQualityIssues item)
{
return ITrx.TRXNAME_ThreadInherited;
}
@Override
protected Object extractModelToEnqueueFromItem(final Collector collector, final InOutLineWithQualityIssues item)
{
return TableRecordReference.of(I_M_InOutLine.Table_Name, item.getM_InOutLine_ID());
}
};
@Override
public Result processWorkPackage(final I_C_Queue_WorkPackage workPackage, final String localTrxName)
{
// Services
final IQueueDAO queueDAO = Services.get(IQueueDAO.class);
final IRequestBL requestBL = Services.get(IRequestBL.class);
// retrieve the items (inout lines) that were enqueued and put them in a list
final List<I_M_InOutLine> lines = queueDAO.retrieveItems(workPackage, I_M_InOutLine.class, localTrxName);
// for each line that was enqueued, create a R_Request containing the information from the inout line and inout
for (final I_M_InOutLine line : lines)
{
requestBL.createRequestFromInOutLine(line);
}
return Result.SUCCESS;
}
}