001package org.kuali.ole.batch.rule;
002
003import org.kuali.ole.OLEConstants;
004import org.kuali.ole.batch.bo.OLEBatchProcessProfileBo;
005import org.kuali.ole.batch.bo.OLEBatchProcessProfileConstantsBo;
006import org.kuali.ole.batch.bo.OLEBatchProcessProfileDataMappingOptionsBo;
007import org.kuali.ole.batch.bo.OLEBatchProcessProfileMappingOptionsBo;
008import org.kuali.ole.select.OleSelectConstant;
009import org.kuali.ole.sys.OLEKeyConstants;
010import org.kuali.rice.krad.maintenance.MaintenanceDocument;
011import org.kuali.rice.krad.rules.MaintenanceDocumentRuleBase;
012import org.kuali.rice.krad.util.GlobalVariables;
013import org.kuali.rice.krad.util.KRADConstants;
014
015import java.util.*;
016
017/**
018 * Created with IntelliJ IDEA.
019 * User: ?
020 * Date: 3/21/13
021 * Time: 1:16 PM
022 * To change this template use File | Settings | File Templates.
023 */
024public class OleBatchProcessProfileRule extends MaintenanceDocumentRuleBase {
025
026    private boolean isCurrencyTypeAvailable = false;
027
028    protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
029        boolean isValid = true;
030        OLEBatchProcessProfileBo oleBatchProcessProfileBo = (OLEBatchProcessProfileBo) document.getNewMaintainableObject().getDataObject();
031        if(oleBatchProcessProfileBo.getBatchProcessProfileType().equalsIgnoreCase(OLEConstants.OLEBatchProcess.ORDER_RECORD_IMPORT) || oleBatchProcessProfileBo.getBatchProcessProfileType().equalsIgnoreCase(OLEConstants.OLEBatchProcess.INVOICE_RECORD_IMPORT)){
032            if(oleBatchProcessProfileBo.getBibImportProfileForOrderRecord() == null){
033                GlobalVariables.getMessageMap().putError(OLEConstants.OLEBatchProcess.BIB_IMPORT_PROFILE, OLEKeyConstants.ERROR_REQUIRED, "Bib Import Profile");
034            }
035        }
036        if(oleBatchProcessProfileBo.getBatchProcessProfileType().equalsIgnoreCase(OLEConstants.OLEBatchProcess.ORDER_RECORD_IMPORT)) {
037            isValid &= validateRequiredFieldsForOrderRecordImport(oleBatchProcessProfileBo);
038        }
039        if(oleBatchProcessProfileBo.getBatchProcessProfileType().equalsIgnoreCase(OLEConstants.OLEBatchProcess.INVOICE_RECORD_IMPORT)) {
040            isValid &= validateRequiredFieldsForInvoiceImport(oleBatchProcessProfileBo);
041        }
042        return isValid;
043    }
044
045    /**
046     * This method  validates duplicate Agreement Method Id and return boolean value.
047     *
048     * @param
049     * @return boolean
050     */
051    private boolean validateRequiredFieldsForOrderRecordImport(OLEBatchProcessProfileBo oleBatchProcessProfileBo) {
052        Set<String> availableFields = new HashSet<>();
053        List<OLEBatchProcessProfileMappingOptionsBo> oleBatchProcessProfileMappingOptionsBoList = oleBatchProcessProfileBo.getOleBatchProcessProfileMappingOptionsList();
054        for (OLEBatchProcessProfileMappingOptionsBo oleBatchProcessProfileMappingOptionsBo : oleBatchProcessProfileMappingOptionsBoList) {
055            List<OLEBatchProcessProfileDataMappingOptionsBo> oleBatchProcessProfileDataMappingOptionsBoList = oleBatchProcessProfileMappingOptionsBo.getOleBatchProcessProfileDataMappingOptionsBoList();
056            for (int dataMapCount = 0;dataMapCount<oleBatchProcessProfileDataMappingOptionsBoList.size();dataMapCount++) {
057                if(OLEConstants.OLEBatchProcess.LIST_PRICE.equals(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField())) {
058                    availableFields.add(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField());
059                }
060                else if(OLEConstants.OLEBatchProcess.VENDOR_NUMBER.equals(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField())){
061                    availableFields.add(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField());
062                }
063                else if(OLEConstants.OLEBatchProcess.QUANTITY.equals(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField())){
064                    availableFields.add(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField());
065                }
066                else if(OLEConstants.OLEBatchProcess.ITEM_NO_OF_PARTS.equals(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField())){
067                    availableFields.add(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField());
068                }
069                else if(OLEConstants.OLEBatchProcess.ACCOUNT_NUMBER.equals(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField())){
070                    availableFields.add(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField());
071                }
072                else if(OLEConstants.OLEBatchProcess.OBJECT_CODE.equals(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField())){
073                    availableFields.add(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField());
074                }
075                else if(OLEConstants.OLEBatchProcess.ITEM_CHART_CODE.equals(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField())){
076                    availableFields.add(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField());
077                }
078                else if(OLEConstants.OLEBatchProcess.COST_SOURCE.equals(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField())) {
079                    availableFields.add(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField());
080                }
081                else if(OLEConstants.OLEBatchProcess.METHOD_OF_PO_TRANSMISSION.equals(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField())) {
082                    availableFields.add(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField());
083                }
084                else if(OLEConstants.OLEBatchProcess.BUILDING_CODE.equals(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField())) {
085                    availableFields.add(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField());
086                }
087                else if(OLEConstants.OLEBatchProcess.DELIVERY_BUILDING_ROOM_NUMBER.equals(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField())) {
088                    availableFields.add(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField());
089                }
090                else if(OLEConstants.OLEBatchProcess.DELIVERY_CAMPUS_CODE.equals(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField())) {
091                    availableFields.add(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField());
092                }
093                else if(OLEConstants.OLEBatchProcess.ORG_CODE.equals(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField())) {
094                    availableFields.add(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField());
095                }
096                else if(OLEConstants.OLEBatchProcess.CHART_CODE.equals(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField())) {
097                    availableFields.add(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField());
098                }
099                else if(OLEConstants.OLEBatchProcess.FUNDING_SOURCE.equals(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField())) {
100                    availableFields.add(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField());
101                }
102                else if(OLEConstants.OLEBatchProcess.DEFAULT_LOCATION.equals(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField())) {
103                    availableFields.add(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField());
104                }
105            }
106        }
107        List<OLEBatchProcessProfileConstantsBo> oleBatchProcessProfileConstantsBoList = oleBatchProcessProfileBo.getOleBatchProcessProfileConstantsList();
108            for(int constantCount = 0;constantCount < oleBatchProcessProfileConstantsBoList.size();constantCount++ )  {
109                if(OLEConstants.OLEBatchProcess.LIST_PRICE.equals(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName())) {
110                    availableFields.add(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName());
111                }
112                else if(OLEConstants.OLEBatchProcess.VENDOR_NUMBER.equals(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName())){
113                    availableFields.add(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName());
114                }
115                else if(OLEConstants.OLEBatchProcess.QUANTITY.equals(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName())){
116                    availableFields.add(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName());
117                }
118                else if(OLEConstants.OLEBatchProcess.ITEM_NO_OF_PARTS.equals(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName())){
119                    availableFields.add(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName());
120                }
121                else if(OLEConstants.OLEBatchProcess.ACCOUNT_NUMBER.equals(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName())){
122                    availableFields.add(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName());
123                }
124                else if(OLEConstants.OLEBatchProcess.OBJECT_CODE.equals(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName())){
125                    availableFields.add(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName());
126                }
127                else if(OLEConstants.OLEBatchProcess.ITEM_CHART_CODE.equals(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName())){
128                    availableFields.add(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName());
129                }
130                else if(OLEConstants.OLEBatchProcess.COST_SOURCE.equals(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName())) {
131                    availableFields.add(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName());
132                }
133                else if(OLEConstants.OLEBatchProcess.METHOD_OF_PO_TRANSMISSION.equals(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName())) {
134                    availableFields.add(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName());
135                }
136                else if(OLEConstants.OLEBatchProcess.BUILDING_CODE.equals(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName())) {
137                    availableFields.add(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName());
138                }
139                else if(OLEConstants.OLEBatchProcess.DELIVERY_BUILDING_ROOM_NUMBER.equals(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName())) {
140                    availableFields.add(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName());
141                }
142                else if(OLEConstants.OLEBatchProcess.DELIVERY_CAMPUS_CODE.equals(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName())) {
143                    availableFields.add(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName());
144                }
145                else if(OLEConstants.OLEBatchProcess.ORG_CODE.equals(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName())) {
146                    availableFields.add(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName());
147                }
148                else if(OLEConstants.OLEBatchProcess.CHART_CODE.equals(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName())) {
149                    availableFields.add(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName());
150                }
151                else if(OLEConstants.OLEBatchProcess.FUNDING_SOURCE.equals(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName())) {
152                    availableFields.add(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName());
153                }
154                else if(OLEConstants.OLEBatchProcess.DEFAULT_LOCATION.equals(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName())) {
155                    availableFields.add(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName());
156                }
157            }
158        String requiredFields = null;
159        requiredFields = checkForAllMandatoryFieldsForOrderImport(oleBatchProcessProfileBo,availableFields,requiredFields);
160        if(requiredFields == null){
161            return true;
162        }
163        else {
164            GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS,OLEConstants.OLEBatchProcess.REQUIRED_VALUES_FOR_ORDER_RECORD_IMPORT,requiredFields);
165        }
166        return false;
167    }
168
169    private String checkForAllMandatoryFieldsForOrderImport(OLEBatchProcessProfileBo oleBatchProcessProfileBo,Set<String> availableFields,String requiredFields){
170        List<String> mandatoryFields = new ArrayList<>();
171        if(oleBatchProcessProfileBo.getMarcOnly()){
172            mandatoryFields.add(OLEConstants.OLEBatchProcess.LIST_PRICE);
173            mandatoryFields.add(OLEConstants.OLEBatchProcess.VENDOR_NUMBER);
174            mandatoryFields.add(OLEConstants.OLEBatchProcess.QUANTITY);
175            mandatoryFields.add(OLEConstants.OLEBatchProcess.ITEM_NO_OF_PARTS);
176            mandatoryFields.add(OLEConstants.OLEBatchProcess.ACCOUNT_NUMBER);
177            mandatoryFields.add(OLEConstants.OLEBatchProcess.OBJECT_CODE);
178            mandatoryFields.add(OLEConstants.OLEBatchProcess.ITEM_CHART_CODE);
179        }
180        mandatoryFields.add(OLEConstants.OLEBatchProcess.DEFAULT_LOCATION);
181        mandatoryFields.add(OLEConstants.OLEBatchProcess.COST_SOURCE);
182        mandatoryFields.add(OLEConstants.OLEBatchProcess.METHOD_OF_PO_TRANSMISSION);
183        mandatoryFields.add(OLEConstants.OLEBatchProcess.BUILDING_CODE);
184        mandatoryFields.add(OLEConstants.OLEBatchProcess.DELIVERY_CAMPUS_CODE);
185        mandatoryFields.add(OLEConstants.OLEBatchProcess.DELIVERY_BUILDING_ROOM_NUMBER);
186        mandatoryFields.add(OLEConstants.OLEBatchProcess.ORG_CODE);
187        mandatoryFields.add(OLEConstants.OLEBatchProcess.CHART_CODE);
188        mandatoryFields.add(OLEConstants.OLEBatchProcess.FUNDING_SOURCE);
189        mandatoryFields.removeAll(availableFields);
190        if(mandatoryFields == null || mandatoryFields.size() == 0){
191            return requiredFields;
192        }
193        else {
194            requiredFields = addRequiredFieldsMessageForOrderImport(mandatoryFields);
195            return requiredFields;
196        }
197    }
198
199    private String addRequiredFieldsMessageForOrderImport(List<String> mandatoryFields){
200        StringBuffer fieldsRequired = new StringBuffer();
201        for(int fieldCount = 0; fieldCount < mandatoryFields.size();fieldCount++){
202            if(mandatoryFields.get(fieldCount).equalsIgnoreCase(OLEConstants.OLEBatchProcess.LIST_PRICE)){
203                fieldsRequired.append(OLEConstants.REQUIRED_LIST_PRICE);
204            }
205            else if(mandatoryFields.get(fieldCount).equalsIgnoreCase(OLEConstants.OLEBatchProcess.VENDOR_NUMBER)){
206                fieldsRequired.append(OLEConstants.REQUIRED_VENDOR_NUMBER);
207            }
208            else if(mandatoryFields.get(fieldCount).equalsIgnoreCase(OLEConstants.OLEBatchProcess.QUANTITY)){
209                fieldsRequired.append(OLEConstants.REQUIRED_QTY);
210            }
211            else if(mandatoryFields.get(fieldCount).equalsIgnoreCase(OLEConstants.OLEBatchProcess.ITEM_NO_OF_PARTS)){
212                fieldsRequired.append(OLEConstants.REQUIRED_NO_OF_PARTS);
213            }
214            else if(mandatoryFields.get(fieldCount).equalsIgnoreCase(OLEConstants.OLEBatchProcess.ACCOUNT_NUMBER)){
215                fieldsRequired.append(OLEConstants.REQUIRED_ACCOUNT_NUMBER);
216            }
217            else if(mandatoryFields.get(fieldCount).equalsIgnoreCase(OLEConstants.OLEBatchProcess.OBJECT_CODE)){
218                fieldsRequired.append(OLEConstants.REQUIRED_OBJECT_CODE);
219            }
220            else if(mandatoryFields.get(fieldCount).equalsIgnoreCase(OLEConstants.OLEBatchProcess.ITEM_CHART_CODE)){
221                fieldsRequired.append(OLEConstants.REQUIRED_ITEM_CHART_CD);
222            }
223            else if(mandatoryFields.get(fieldCount).equalsIgnoreCase(OLEConstants.OLEBatchProcess.COST_SOURCE)){
224                fieldsRequired.append(OLEConstants.REQUIRED_COST_SOURCE);
225            }
226            else if(mandatoryFields.get(fieldCount).equalsIgnoreCase(OLEConstants.OLEBatchProcess.METHOD_OF_PO_TRANSMISSION)){
227                fieldsRequired.append(OLEConstants.REQUIRED_METHOD_OF_PO_TRANSMISSION);
228            }
229            else if(mandatoryFields.get(fieldCount).equalsIgnoreCase(OLEConstants.OLEBatchProcess.BUILDING_CODE)){
230                fieldsRequired.append(OLEConstants.REQUIRED_BUILDING_CODE);
231            }
232            else if(mandatoryFields.get(fieldCount).equalsIgnoreCase(OLEConstants.OLEBatchProcess.DELIVERY_BUILDING_ROOM_NUMBER)){
233                fieldsRequired.append(OLEConstants.REQUIRED_DELIVERY_BUILDING_ROOM_NUMBER);
234            }
235            else if(mandatoryFields.get(fieldCount).equalsIgnoreCase(OLEConstants.OLEBatchProcess.DELIVERY_CAMPUS_CODE)){
236                fieldsRequired.append(OLEConstants.REQUIRED_DELIVERY_CAMPUS_CODE);
237            }
238            else if(mandatoryFields.get(fieldCount).equalsIgnoreCase(OLEConstants.OLEBatchProcess.ORG_CODE)){
239                fieldsRequired.append(OLEConstants.REQUIRED_ORG_CODE);
240            }
241            else if(mandatoryFields.get(fieldCount).equalsIgnoreCase(OLEConstants.OLEBatchProcess.CHART_CODE)){
242                fieldsRequired.append(OLEConstants.REQUIRED_CHART_CODE);
243            }
244            else if(mandatoryFields.get(fieldCount).equalsIgnoreCase(OLEConstants.OLEBatchProcess.FUNDING_SOURCE)){
245                fieldsRequired.append(OLEConstants.REQUIRED_FUNDING_SOURCE);
246            }
247            else if(mandatoryFields.get(fieldCount).equalsIgnoreCase(OLEConstants.OLEBatchProcess.DEFAULT_LOCATION)){
248                fieldsRequired.append(OLEConstants.REQUIRED_DEFAULT_LOCATION);
249            }
250            if(!(fieldCount  == mandatoryFields.size()-1)){
251                fieldsRequired.append(", ");
252            }
253        }
254        fieldsRequired.append(mandatoryFields.size() == 1?" is":" are");
255        return fieldsRequired.toString();
256    }
257
258
259    private boolean validateRequiredFieldsForInvoiceImport(OLEBatchProcessProfileBo oleBatchProcessProfileBo){
260        Set<String> availableFields = new HashSet<>();
261        List<OLEBatchProcessProfileMappingOptionsBo> oleBatchProcessProfileMappingOptionsBoList = oleBatchProcessProfileBo.getOleBatchProcessProfileMappingOptionsList();
262        for (OLEBatchProcessProfileMappingOptionsBo oleBatchProcessProfileMappingOptionsBo : oleBatchProcessProfileMappingOptionsBoList) {
263            List<OLEBatchProcessProfileDataMappingOptionsBo> oleBatchProcessProfileDataMappingOptionsBoList = oleBatchProcessProfileMappingOptionsBo.getOleBatchProcessProfileDataMappingOptionsBoList();
264            for (int dataMapCount = 0;dataMapCount<oleBatchProcessProfileDataMappingOptionsBoList.size();dataMapCount++) {
265                if(OLEConstants.OLEBatchProcess.LIST_PRICE.equals(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField())) {
266                    availableFields.add(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField());
267                }
268                else if(OLEConstants.OLEBatchProcess.FOREIGN_LIST_PRICE.equals(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField())) {
269                    availableFields.add(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField());
270                }
271                else if(OLEConstants.OLEBatchProcess.QUANTITY.equals(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField())){
272                    availableFields.add(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField());
273                }
274                else if(OLEConstants.OLEBatchProcess.INVOICE_DATE.equals(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField())){
275                    availableFields.add(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField());
276                }
277                else if(OLEConstants.OLEBatchProcess.VENDOR_NUMBER.equals(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField())){
278                    availableFields.add(oleBatchProcessProfileDataMappingOptionsBoList.get(dataMapCount).getDestinationField());
279                }
280            }
281        }
282        List<OLEBatchProcessProfileConstantsBo> oleBatchProcessProfileConstantsBoList = oleBatchProcessProfileBo.getOleBatchProcessProfileConstantsList();
283            for(int constantCount = 0;constantCount < oleBatchProcessProfileConstantsBoList.size();constantCount++ )  {
284                if(OLEConstants.OLEBatchProcess.LIST_PRICE.equals(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName())) {
285                    availableFields.add(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName());
286                }
287                else if(OLEConstants.OLEBatchProcess.FOREIGN_LIST_PRICE.equals(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName())) {
288                    availableFields.add(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName());
289                }
290                else if(OLEConstants.OLEBatchProcess.QUANTITY.equals(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName())){
291                    availableFields.add(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName());
292                }
293                else if(OLEConstants.OLEBatchProcess.INVOICE_DATE.equals(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName())){
294                    availableFields.add(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName());
295                }
296                else if(OLEConstants.OLEBatchProcess.VENDOR_NUMBER.equals(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName())){
297                    availableFields.add(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName());
298                }
299                else if(OLEConstants.OLEBatchProcess.CURRENCY_TYPE.equals(oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeName())){
300                    if(!oleBatchProcessProfileConstantsBoList.get(constantCount).getAttributeValue().equalsIgnoreCase(OleSelectConstant.CURRENCY_TYPE_NAME)){
301                        isCurrencyTypeAvailable = true;
302                    }
303                }
304            }
305        String requiredFields = null;
306        requiredFields = checkForAllMandatoryFieldsForInvoiceImport(availableFields,requiredFields);
307        if(requiredFields == null){
308            return true;
309        }
310        else {
311            GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS,OLEConstants.OLEBatchProcess.REQUIRED_VALUES_FOR_ORDER_RECORD_IMPORT,requiredFields);
312        }
313        return false;
314    }
315
316
317
318    private String checkForAllMandatoryFieldsForInvoiceImport(Set<String> availableFields,String requiredFields){
319        List<String> mandatoryFields = new ArrayList<>();
320        mandatoryFields.add(OLEConstants.OLEBatchProcess.LIST_PRICE);
321        mandatoryFields.add(OLEConstants.OLEBatchProcess.QUANTITY);
322        mandatoryFields.add(OLEConstants.OLEBatchProcess.INVOICE_DATE);
323        mandatoryFields.add(OLEConstants.OLEBatchProcess.VENDOR_NUMBER);
324        if(isCurrencyTypeAvailable){
325            mandatoryFields.add(OLEConstants.OLEBatchProcess.FOREIGN_LIST_PRICE);
326            mandatoryFields.remove(OLEConstants.OLEBatchProcess.LIST_PRICE);
327        }
328        mandatoryFields.removeAll(availableFields);
329        if(mandatoryFields == null || mandatoryFields.size() == 0){
330            return requiredFields;
331        }
332        else {
333            requiredFields = addRequiredFieldsMessageForInvoiceImport(mandatoryFields);
334            return requiredFields;
335        }
336    }
337
338    private String addRequiredFieldsMessageForInvoiceImport(List<String> mandatoryFields){
339        StringBuffer fieldsRequired = new StringBuffer();
340        for(int fieldCount = 0; fieldCount < mandatoryFields.size();fieldCount++){
341            if(mandatoryFields.get(fieldCount).equalsIgnoreCase(OLEConstants.OLEBatchProcess.LIST_PRICE)){
342                fieldsRequired.append(OLEConstants.REQUIRED_INVOICED_PRICE);
343            }
344            else if(mandatoryFields.get(fieldCount).equalsIgnoreCase(OLEConstants.OLEBatchProcess.FOREIGN_LIST_PRICE)){
345                fieldsRequired.append(OLEConstants.REQUIRED_INVOICED_FOREIGN_PRICE);
346            }
347            else if(mandatoryFields.get(fieldCount).equalsIgnoreCase(OLEConstants.OLEBatchProcess.VENDOR_NUMBER)){
348                fieldsRequired.append(OLEConstants.REQUIRED_VENDOR_NUMBER);
349            }
350            else if(mandatoryFields.get(fieldCount).equalsIgnoreCase(OLEConstants.OLEBatchProcess.QUANTITY)){
351                fieldsRequired.append(OLEConstants.REQUIRED_QTY);
352            }
353            else if(mandatoryFields.get(fieldCount).equalsIgnoreCase(OLEConstants.OLEBatchProcess.INVOICE_DATE)){
354                fieldsRequired.append(OLEConstants.REQUIRED_INVOICE_DATE);
355            }
356            if(!(fieldCount  == mandatoryFields.size()-1)){
357                fieldsRequired.append(", ");
358            }
359        }
360        fieldsRequired.append(mandatoryFields.size() == 1?" is":" are");
361        return fieldsRequired.toString();
362    }
363
364}