Where ,what and how to achieve code update below thing based on the above code flow ?
Modification in ReturnChannelsController -> /fetchReturnChannels/v2
Adding return shipnode in the channel api at header level
logic in ticket
see in the ticket comment section...
The design has been finalised. There are two activities from the Returns team-
Api team to send new field "returnShipNode" in channel API based on logic- check if child client id is 0 if present otherwise we need to see postcode at header level. We must send this new attribute when Ollerton is selected as the return address. Values for this field will be 8222, but it needs to be configurable.
The front end will use the attribute if the value is there and stamp in shipnode attribute in the confirm return API request.
Operations Team is having difficulty tracking the return items for dropship orders
the OMS Team has developed an approach
Modification in ReturnChannelsController -> /fetchReturnChannels/v2
Based on the information provided, here are the steps you can take to resolve the issue and summarize the necessary modifications:
Modify the Returns team's API:
a. Introduce a new field named "returnShipNode" in the channel API.
b. Implement logic to determine the value of "returnShipNode" based on the following criteria:
If the child client ID is 0, set the value to "8222" or a configurable value.
If the child client ID is not 0, use the postcode at the header level to determine the value.
c. Ensure this new attribute is included in the API only when Ollerton is selected as the return address.
Adjust Frontend implementation:
a. Modify the frontend to utilize the "returnShipNode" attribute if it is present.
b. Stamp the "shipnode" attribute in the confirm return API request with the value received from the "returnShipNode" field.
Implement Operations Team's tracking solution:
a. Update the ReturnChannelsController with modifications in the /fetchReturnChannels/v2 endpoint or any other relevant endpoints to facilitate better tracking of return items for dropship orders.
Summary:
Modify the Returns team's API to include the "returnShipNode" attribute with necessary logic and only when Ollerton is selected as the return address.
Update frontend implementation to utilize the new attribute and stamp it in the confirm return API request.
Implement improvements in the ReturnChannelsController to improve tracking of return items for dropship orders.
mongo=
{
orderRef:
"601-0000261-1333601"}
Modification in ReturnChannelsController -> /fetchReturnChannels/v2
Adding return shipnode in the channel api at header level
logic in ticket
see in the ticket comment section...
The design has been finalised. There are two activities from the Returns team-
Api team to send new field "returnShipNode" in channel API based on logic- check if child client id is 0 if present otherwise we need to see postcode at header level. We must send this new attribute when Ollerton is selected as the return address. Values for this field will be 8222, but it needs to be configurable.
The front end will use the attribute if the value is there and stamp in shipnode attribute in the confirm return API request.
Operations Team is having difficulty tracking the return items for dropship orders
the OMS Team has developed an approach
Modification in ReturnChannelsController -> /fetchReturnChannels/v2
Based on the information provided, here are the steps you can take to resolve the issue and summarize the necessary modifications:
Modify the Returns team's API:
a. Introduce a new field named "returnShipNode" in the channel API.
b. Implement logic to determine the value of "returnShipNode" based on the following criteria:
If the child client ID is 0, set the value to "8222" or a configurable value.
If the child client ID is not 0, use the postcode at the header level to determine the value.
c. Ensure this new attribute is included in the API only when Ollerton is selected as the return address.
Adjust Frontend implementation:
a. Modify the frontend to utilize the "returnShipNode" attribute if it is present.
b. Stamp the "shipnode" attribute in the confirm return API request with the value received from the "returnShipNode" field.
Implement Operations Team's tracking solution:
a. Update the ReturnChannelsController with modifications in the /fetchReturnChannels/v2 endpoint or any other relevant endpoints to facilitate better tracking of return items for dropship orders.
Summary:
Modify the Returns team's API to include the "returnShipNode" attribute with necessary logic and only when Ollerton is selected as the return address.
Update frontend implementation to utilize the new attribute and stamp it in the confirm return API request.
Implement improvements in the ReturnChannelsController to improve tracking of return items for dropship orders.
I am sumbmitting existing code below.....after i am finished sumbmitting existing code....tell me the updated code based on the requirement above
@PostMapping("/fetchReturnChannels/v2")
@Operation(
summary = "Service to fetch return Channels for an order.",
description = "For a given order fetch possible return channels and addresses.")
public ReturnChannelResponse fetchReturnChannelsv2(@RequestBody ReturnChannelRequest returnChannelRequest){
String countryCode = returnChannelRequest.getCountryCode();
returnChannelRequest.setCountryCode(countryCode == null ? DEFAULT_COUNTRY : countryCode);
ReturnChannelResponse fetchReturnChannels = returnsChannelService.fetchReturnChannels(returnChannelRequest, true);
String blockSalesItems = channelServicesConfig.fetchReturnChannelConfigBean().get(RULE_SALES_ITEM_CLICK_AND_COLLECT_ENABLE);
if (blockSalesItems.equalsIgnoreCase("Y")) {
log.info("Applying filer rule ITEM_CLICK_AND_COLLECT for order number {}", returnChannelRequest.getOrderNumber());
ReturnChannelResponse response = filterChannelResponse.filterChannelResponseImpl(fetchReturnChannels, returnChannelRequest);
parcelForceFilter.overrideParcelForcePostCode(response);
return response;
}
return fetchReturnChannels;
}
this is existing code.... @Description("Produces return channel response object for incoming line items") public ReturnChannelResponse fetchReturnChannels(ReturnChannelRequest returnChannelRequest, boolean isParcelForceHeaderEnabled) {
log.info("Request Payload : {} ", JsonUtils.getString(returnChannelRequest));
String countryCode = returnChannelRequest.getCountryCode();
log.debug("Processing return channel request for country {}", countryCode);
// Load configurations stored in mongoDB.
Map<String, String> ilrConfigMap = channelServicesConfig.fetchReturnChannelConfig();
//Dropship only
boolean allDropShip = true;
// All same supplier
boolean allSameSupplier = true;
// BT postcode scenario flag
boolean btPostCode = false;
// Min return value flag
boolean minimumReturnValue = true;
// For optimizing order level return channel roll-up
int smallestChannelSize = Integer.MAX_VALUE;
String smallestSku = "";
// For line item total less than 15 pounds to enforce in store return
float orderReturnTotal = 0.0F;
List<OrderItem> orderItemList = returnChannelRequest.getOrderItemList();
String[] suppliers = new String[orderItemList.size()];
int arrayIndex = 0;
Map<String, List<LineItemChannel>> strokeMap = new HashMap<>();
log.info("About to start iteration of payload...");
for (OrderItem orderItem : orderItemList) {
ItemDetails itemDetails = orderItem.getItemDetails();
String strokeNumber = itemDetails.getStrokeNumber();
String deptNumber = itemDetails.getDepartmentNumber();
String shipFromNode = orderItem.getShipNode();
String sku = orderItem.getSku();
if (!shipFromNode.equalsIgnoreCase("")) {
suppliers[arrayIndex] = shipFromNode;
arrayIndex++;
}
float lineTotal = Float.parseFloat(itemDetails.getLineTotal());
orderReturnTotal = orderReturnTotal + lineTotal;
//checking restricted postcodes
if (null != itemDetails.getPostalCode()
&& StringUtils.startsWith(itemDetails.getPostalCode(),
(ilrConfigMap.get(EVRI_EXCLUSION_PREFIXES)))) {
btPostCode = true;
}
//Checking if all are dropship
if (null != itemDetails.getServiceItem()
&& !itemDetails.getServiceItem().equalsIgnoreCase("Dropship")) {
allDropShip=false;
}
// To check if all are same dropship suppliers
List<String> supplierList = Arrays.stream(suppliers).distinct().toList();
if (supplierList.size() > 1 ) {
allSameSupplier = false;
}
//Check in mongodb//
log.info("Fetching return channels for sku : {}", sku);
List<StrokeChannelData> strokeChannelDataList = strokeChannelRepository.fetchStrokeData(strokeNumber, deptNumber, shipFromNode);
//Assuming more than one result is returned always , apply priority rules 1, 2, and 3//
StrokeChannelData strokeChannelData;
if (isParcelForceHeaderEnabled) {
strokeChannelData = fetchResultBasedOnPriorityParcelForce(strokeChannelDataList, strokeNumber, deptNumber, shipFromNode, countryCode);
} else {
strokeChannelData = fetchResultBasedOnPriority(strokeChannelDataList, strokeNumber, deptNumber, shipFromNode, countryCode);
}
List<LineItemChannel> lineItemChannels =
returnChannelTransformer.returnChannelsFormatter(strokeChannelData.getReturnChannels(),
strokeChannelData.getChannelID(), countryCode, isParcelForceHeaderEnabled);
final int channelSizes = lineItemChannels.size();
if (channelSizes <= smallestChannelSize) {
smallestChannelSize = channelSizes;
smallestSku = sku;
}
strokeMap.put(sku, lineItemChannels);
}
if (ilrConfigMap.get(MIN_RETURN_PRICE_CHECK_ENABLED).equalsIgnoreCase("Y") && orderReturnTotal < Float.parseFloat(ilrConfigMap.get(MIN_RETURN_ORDER))) {
minimumReturnValue = false;
}
ChannelAddress commonAddress = returnChannelTransformer.resolveCommonAddress(strokeMap, countryCode);
List<OrderChannel> orderChannels = returnChannelTransformer.
resolveOrderLevelReturnChannel(strokeMap, commonAddress, smallestSku, btPostCode, allDropShip, allSameSupplier, minimumReturnValue);
return buildResponse(returnChannelRequest, strokeMap, orderChannels, commonAddress.getDsvReturnAddress());
}
this is existing code.... private StrokeChannelData fetchResultBasedOnPriority(List resultSet, String strokeNumber, String deptNo, String node, String countryCode) { StrokeChannelData strokeChannelData = null; if (resultSet.size() > 0) { for (StrokeChannelData channelData : resultSet) { // For more than one result, we filter result based on strokeNumber as first priority if (channelData.getStrokeId().equalsIgnoreCase(strokeNumber)) { strokeChannelData = channelData; break; } // Dept number takes second priority if (null == strokeChannelData && !deptNo.equalsIgnoreCase("")) { if (channelData.getDeptId().equalsIgnoreCase(deptNo)) { strokeChannelData = channelData; break; } } // Nodes take last priority if (null == strokeChannelData) { if (Arrays.asList(channelData.getNodes()).contains(node) && !node.equalsIgnoreCase("")) { strokeChannelData = channelData; break; } } } } // If there aren't any results then build default CH11 rule. if(null ==strokeChannelData || resultSet.size() == 0) { strokeChannelData = strokeChannelRepository.fetchDefaultChannelAddressByCountry(countryCode); } return strokeChannelData; }
this is existing code.... @Description("Iterate and build the item level return channels from dataList object") public List returnChannelsFormatter(ReturnChannels returnChannels, String channelId, String countryCode, boolean isParcelForceHeaderEnabled) { //fetch address ChannelAddress address = channelAddressRepository.fetchChannelAddress(channelId, countryCode); List lineItemChannels = new ArrayList<>(); JSONObject returnChannelObj = JsonUtils.JSONObjectConverter(returnChannels); returnChannelObj.keySet().forEach(key-> { LineItemChannel lineItemChannel = LineItemChannel.builder().build(); JSONObject subChannelObjects = (JSONObject) returnChannelObj.get(key); List subChannelTypes = new ArrayList<>(); subChannelObjects.keySet().forEach(subChannelKey -> { try { JSONObject jsonObject = subChannelObjects.getJSONObject(subChannelKey); boolean isApplicable = jsonObject.getBoolean("isApplicable"); List eligibleCountries = getEligibleCountries(jsonObject.getJSONArray("eligibleCountries")); if (isApplicable && eligibleCountries.contains(countryCode)) { //Todo - isParcelForceHeaderEnabled Remove once we add new carrier if(isParcelForceHeaderEnabled){ populateAndCheckParcelForce(returnChannels, key, subChannelTypes, subChannelKey); } else { subChannelTypes.add(SubChannelType.builder().subChannelType(subChannelKey).build()); } lineItemChannel.setChannelType(key); lineItemChannel.setSubChannelTypes(subChannelTypes); lineItemChannel.setAddress(address); } } catch (Exception exception) { log.warn("No mapping found for key {} / unable to get object for key {}", subChannelKey, subChannelKey); } }); if (null != lineItemChannel.getChannelType()) { lineItemChannels.add(lineItemChannel); } }); return lineItemChannels; }
this is existing code....private void populateAndCheckParcelForce(ReturnChannels returnChannels, String key, List subChannelTypes, String subChannelKey) { if (subChannelKey.equalsIgnoreCase(PARCEL_FORCE_CARRIER) ) { List subCategories = new ArrayList<>(); if (key.equalsIgnoreCase("postal")) { subCategories = returnChannels.getPostal().getParcelForce().getSubCategories(); } else if (key.equalsIgnoreCase("collectFromHome")) { subCategories = returnChannels.getCollectFromHome().getParcelForce().getSubCategories(); } List filterSubCategories = new ArrayList<>(); for (SubCategories categories : subCategories) { if(categories.getIsApplicable()){ filterSubCategories.add(categories); } } if (!filterSubCategories.isEmpty()) { subChannelTypes.add(SubChannelType.builder().subChannelType(subChannelKey).subCategories(filterSubCategories).build()); } } else { subChannelTypes.add(SubChannelType.builder().subChannelType(subChannelKey).build()); } }
this is existing code.....private List getEligibleCountries(JSONArray eligibleCountries) { List eligibleCountriesList = new ArrayList<>(); int length = eligibleCountries.length(); for (int index = 0; index < length ; index ++){ Object country = eligibleCountries.get(index); eligibleCountriesList.add(country.toString()); } return eligibleCountriesList; }
public List resolveOrderLevelReturnChannel(Map<String, List> strokeMap,
ChannelAddress commonAddress,
String smallestSku, Boolean isBTPostCode,
Boolean allDropShip, Boolean allSameSupplier,
Boolean minimumReturnValue) {
log.info("Resolve order level return channels.");
// Fetching smallest lineItemChannel for comparison
List lineItemChannels = strokeMap.get(smallestSku);
List orderChannels = new ArrayList<>();
lineItemChannels.forEach(lineItemChannel -> {
String channel = lineItemChannel.getChannelType();
OrderChannel orderChannel = OrderChannel.builder().build();
strokeMap.forEach((s, lineItemChannels1) -> {
for(LineItemChannel lineItemChannel1 : lineItemChannels1) {
List subChannels = lineItemChannel1.getSubChannelTypes().stream()
.map(SubChannelType::getSubChannelType).collect(Collectors.toList());
List subChannelTypes = new ArrayList<>();
lineItemChannel.getSubChannelTypes().stream().forEach(subChannelType -> {
String subChannel = subChannelType.getSubChannelType();
if(subChannels.contains(subChannel)) {
SubChannelType subChannelType1 = SubChannelType.builder().subChannelType(subChannelType.getSubChannelType()).subCategories(subChannelType.getSubCategories())
.build();
if(!subChannelTypes.contains(subChannelType1)) {
subChannelTypes.add(subChannelType1);
}
}
});
if(!subChannelTypes.isEmpty()) {
orderChannel.setSubChannelTypes(subChannelTypes);
orderChannel.setChannelType(channel);
// Setting address common for all methods
if(!channel.equalsIgnoreCase("Instore")) {
orderChannel.setAddress(commonAddress);
}
if(!orderChannels.contains(orderChannel)) {
orderChannels.add(orderChannel);
}
}
}
});
});
// remove EVRI for BT postcodes
List<OrderChannel> updatedOrderChannels = removeEVRIForBTPostCodes(isBTPostCode,orderChannels);
// remove postal if return total is < 15
List<OrderChannel> updatedOrderChannels2 = removePostalForMinReturnTotal
(minimumReturnValue, updatedOrderChannels);
if(updatedOrderChannels2.size() ==0) {
// means there is no channel left, so we add instore with Ollerton
OrderChannel orderChannel = OrderChannel.builder().channelType("instore")
.subChannelTypes(List.of(
SubChannelType.builder().subChannelType("clothAndHome").build(),
SubChannelType.builder().subChannelType("simplyFood").build()))
.build();
updatedOrderChannels2.add(orderChannel);
}
return updatedOrderChannels2;
}
private List removePostalForMinReturnTotal(Boolean minimumReturnValue, List updatedOrderChannels) {
List updatedOrderChannels2 = new ArrayList<>();
log.info("Checking minimum return total ...");
if (!minimumReturnValue) {
log.info("Minimum return total is not satisfied...");
for (OrderChannel orderChannel : updatedOrderChannels) {
if (!(orderChannel.getChannelType().equalsIgnoreCase("Postal") ||
orderChannel.getChannelType().equalsIgnoreCase("CollectFromHome"))) {
updatedOrderChannels2.add(orderChannel);
}
}
}
else {
updatedOrderChannels2 = updatedOrderChannels;
}
return updatedOrderChannels2;
}
public ChannelAddress resolveCommonAddress(Map<String, List> strokeMap, String countryCode) {
log.info("Resolve common address");
List addressList = new ArrayList<>();
strokeMap.forEach((s, lineItemChannels) -> {
addressList.add(lineItemChannels.get(0).getAddress().getCity());
});
List commonAddressList = addressList.stream().distinct().toList();
ChannelAddress[] channelAddress = new ChannelAddress[1];
if (commonAddressList.size() == 1 ) {
strokeMap.forEach((s, lineItemChannels) -> {
for(LineItemChannel lineItemChannel : lineItemChannels) {
if (lineItemChannel.getAddress().getCity().equalsIgnoreCase(commonAddressList.get(0))) {
channelAddress[0] = lineItemChannel.getAddress();
}
}
});
}
else {
channelAddress[0] = channelAddressRepository.getDefaultChannelAddress(countryCode);
}
return channelAddress[0];
}
private List removeEVRIForBTPostCodes(boolean isBTPostCode, List orderChannels ) {
log.info("Checking BT postcode scenario...");
List updatedOrderChannels = new ArrayList<>();
if (isBTPostCode) {
log.info("Restricted postcodes found...");
for (OrderChannel orderChannel : orderChannels) {
OrderChannel updatedOrderChannel = OrderChannel.builder()
.channelType(orderChannel.getChannelType())
.address(orderChannel.getAddress()).build();
List subChannelTypes = orderChannel.getSubChannelTypes();
List updatedSubChannelTypes = new ArrayList<>();
subChannelTypes.forEach(subChannelType -> {
if (!subChannelType.getSubChannelType().equalsIgnoreCase("EVRI")) {
updatedSubChannelTypes.add(SubChannelType.builder()
.subChannelType(subChannelType.getSubChannelType())
.build());
}
});
updatedOrderChannel.setSubChannelTypes(updatedSubChannelTypes);
if (updatedSubChannelTypes.size() > 0) {
// Adding to order channels if there is atleast once subchannel left.
updatedOrderChannels.add(updatedOrderChannel);
};
}
}
else {
updatedOrderChannels = orderChannels;
}
return updatedOrderChannels;
}
public StrokeChannelData fetchDefaultChannelAddressByCountry(String countryCode) { Map<String, String> config = loadConfigKeys.fetchReturnChannelConfig(); String channelId = config.get(DEFAULT_ADDRESS + "_" + countryCode); log.debug("Found channel id key {}", channelId); Criteria defaultCriteria = Criteria.where("channelID").is(channelId); Query query = new Query(new Criteria().orOperator(defaultCriteria)); log.debug("Fetching channel for channelId : {}, for country code {}", channelId, countryCode); return mongoTemplate.findOne(query, StrokeChannelData.class); }....this is existong code
this is existing code....public Map<String, String> fetchReturnChannelConfig() { List ilrConfigList = null; if(ilrConfigMap.isEmpty()) { log.info("Configuration map is empty, fetching list from db"); ilrConfigList = ilrConfigRepository.loadConfigKeys(); ilrConfigList.forEach(ilrConfig -> ilrConfigMap.put(ilrConfig.getKey(), ilrConfig.getValue())); } return ilrConfigMap; }
To update the existing code based on the requirements mentioned in the provided information, you will need to make the following modifications:
Add a new field "returnShipNode" in the channel API based on the logic provided.
Modify the frontend to use the "returnShipNode" attribute if present and stamp it in the confirm return API request.
Adjust the ReturnChannelsController to include the "returnShipNode" field at the header level.
Here is the updated code based on the requirements:
@PostMapping("/fetchReturnChannels/v2")
@Operation(
summary = "Service to fetch return Channels for an order.",
description = "For a given order fetch possible return channels and addresses.")
public ReturnChannelResponse fetchReturnChannelsv2(@RequestBody ReturnChannelRequest returnChannelRequest){
String countryCode = returnChannelRequest.getCountryCode();
returnChannelRequest.setCountryCode(countryCode == null ? DEFAULT_COUNTRY : countryCode);
ReturnChannelResponse fetchReturnChannels = returnsChannelService.fetchReturnChannels(returnChannelRequest, true);
String blockSalesItems = channelServicesConfig.fetchReturnChannelConfigBean().get(RULE_SALES_ITEM_CLICK_AND_COLLECT_ENABLE);
if (blockSalesItems.equalsIgnoreCase("Y")) {
log.info("Applying filer rule ITEM_CLICK_AND_COLLECT for order number {}", returnChannelRequest.getOrderNumber());
ReturnChannelResponse response = filterChannelResponse.filterChannelResponseImpl(fetchReturnChannels, returnChannelRequest);
parcelForceFilter.overrideParcelForcePostCode(response);
return response;
}
return fetchReturnChannels;
}
public ReturnChannelResponse fetchReturnChannels(ReturnChannelRequest returnChannelRequest, boolean isParcelForceHeaderEnabled) {
log.info("Request Payload : {} ", JsonUtils.getString(returnChannelRequest));
// Existing code here
// Add logic to determine the value of "returnShipNode" based on provided criteria
String returnShipNode = determineReturnShipNode(returnChannelRequest);
// Update the returnChannelRequest with the new "returnShipNode"
returnChannelRequest.setReturnShipNode(returnShipNode);
// Existing code here
return buildResponse(returnChannelRequest, strokeMap, orderChannels, commonAddress.getDsvReturnAddress());
}
public String determineReturnShipNode(ReturnChannelRequest returnChannelRequest) {
String returnShipNode = "";
// Logic to determine the value for "returnShipNode" based on child client ID and postcode at header level
// Check if child client ID is 0, set value to "8222"
// Otherwise, determine based on postcode at header level
// Ensure to make it configurable
// Use the "Ollerton" return address as a condition for setting the value
return returnShipNode;
}
This code snippet outlines the necessary changes to include the new "returnShipNode" field in the channel API at the header level and update the logic to determine its value based on the provided requirements and configurations. Additionally, it integrates the new field in the returnChannelRequest for further processing.
Feel free to incorporate this updated code into your existing implementation as needed. Let me know if you require any further assistance or clarifications.