@Test public void shouldValidateShipmentFileTemplateAndThrowErrorIfMandatoryColumnIsNotIncluded() { EDIConfiguration shipmentConfiguration = new EDIConfiguration(); List<EDIFileColumn> shipmentFileColumns = new ArrayList<>(); EDIFileColumn shipmentFileColumn = new EDIFileColumn("productCode", "Product Code", false, true, 1, "dd/MM/yy"); shipmentFileColumns.add(shipmentFileColumn); shipmentFileColumn = new EDIFileColumn("test_column2", "Test Column 2", true, true, 1, "dd/MM/yy"); shipmentFileColumns.add(shipmentFileColumn); EDIFileTemplate fileTemplate = new EDIFileTemplate(shipmentConfiguration, shipmentFileColumns); exException.expect(DataException.class); exException.expectMessage("file.mandatory.columns.not.included"); fileTemplate.validateAndSetModifiedBy(1l, asList("productCode", "orderId", "quantityShipped")); }
public void validateAndSetModifiedBy(Long userId, List<String> mandatoryColumnNames) { Set<Integer> positions = new HashSet(); Integer includedColumnCount = 0; configuration.setModifiedBy(userId); for (EDIFileColumn ediFileColumn : columns) { ediFileColumn.validate(); if (mandatoryColumnNames.contains(ediFileColumn.getName()) && !ediFileColumn.getInclude()) { throw new DataException("file.mandatory.columns.not.included"); } if (ediFileColumn.getInclude()) { positions.add(ediFileColumn.getPosition()); includedColumnCount++; } if (positions.size() != includedColumnCount) { throw new DataException("file.duplicate.position"); } ediFileColumn.setModifiedBy(userId); } }
EDIFileTemplate { public void validateAndSetModifiedBy(Long userId, List<String> mandatoryColumnNames) { Set<Integer> positions = new HashSet(); Integer includedColumnCount = 0; configuration.setModifiedBy(userId); for (EDIFileColumn ediFileColumn : columns) { ediFileColumn.validate(); if (mandatoryColumnNames.contains(ediFileColumn.getName()) && !ediFileColumn.getInclude()) { throw new DataException("file.mandatory.columns.not.included"); } if (ediFileColumn.getInclude()) { positions.add(ediFileColumn.getPosition()); includedColumnCount++; } if (positions.size() != includedColumnCount) { throw new DataException("file.duplicate.position"); } ediFileColumn.setModifiedBy(userId); } } }
EDIFileTemplate { public void validateAndSetModifiedBy(Long userId, List<String> mandatoryColumnNames) { Set<Integer> positions = new HashSet(); Integer includedColumnCount = 0; configuration.setModifiedBy(userId); for (EDIFileColumn ediFileColumn : columns) { ediFileColumn.validate(); if (mandatoryColumnNames.contains(ediFileColumn.getName()) && !ediFileColumn.getInclude()) { throw new DataException("file.mandatory.columns.not.included"); } if (ediFileColumn.getInclude()) { positions.add(ediFileColumn.getPosition()); includedColumnCount++; } if (positions.size() != includedColumnCount) { throw new DataException("file.duplicate.position"); } ediFileColumn.setModifiedBy(userId); } }  }
EDIFileTemplate { public void validateAndSetModifiedBy(Long userId, List<String> mandatoryColumnNames) { Set<Integer> positions = new HashSet(); Integer includedColumnCount = 0; configuration.setModifiedBy(userId); for (EDIFileColumn ediFileColumn : columns) { ediFileColumn.validate(); if (mandatoryColumnNames.contains(ediFileColumn.getName()) && !ediFileColumn.getInclude()) { throw new DataException("file.mandatory.columns.not.included"); } if (ediFileColumn.getInclude()) { positions.add(ediFileColumn.getPosition()); includedColumnCount++; } if (positions.size() != includedColumnCount) { throw new DataException("file.duplicate.position"); } ediFileColumn.setModifiedBy(userId); } }  Collection<EDIFileColumn> filterIncludedColumns(); void validateAndSetModifiedBy(Long userId, List<String> mandatoryColumnNames); @JsonIgnore Integer getRowOffset(); @JsonIgnore String getDateFormatForColumn(final String columnName); }
EDIFileTemplate { public void validateAndSetModifiedBy(Long userId, List<String> mandatoryColumnNames) { Set<Integer> positions = new HashSet(); Integer includedColumnCount = 0; configuration.setModifiedBy(userId); for (EDIFileColumn ediFileColumn : columns) { ediFileColumn.validate(); if (mandatoryColumnNames.contains(ediFileColumn.getName()) && !ediFileColumn.getInclude()) { throw new DataException("file.mandatory.columns.not.included"); } if (ediFileColumn.getInclude()) { positions.add(ediFileColumn.getPosition()); includedColumnCount++; } if (positions.size() != includedColumnCount) { throw new DataException("file.duplicate.position"); } ediFileColumn.setModifiedBy(userId); } }  Collection<EDIFileColumn> filterIncludedColumns(); void validateAndSetModifiedBy(Long userId, List<String> mandatoryColumnNames); @JsonIgnore Integer getRowOffset(); @JsonIgnore String getDateFormatForColumn(final String columnName);  }