Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/campaign' into redis-Integration
Browse files Browse the repository at this point in the history
  • Loading branch information
ashish-egov committed Jun 19, 2024
2 parents 843da2c + 9e66851 commit ac0f558
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const deliveryConfig = [
conditionConfig: [
{
deliveryType: "DIRECT",
disableDeliveryType: true,
attributeConfig: [
{
key: 1,
Expand Down Expand Up @@ -78,6 +79,7 @@ export const deliveryConfig = [
],
},
{
disableDeliveryType: true,
deliveryType: "DIRECT",
attributeConfig: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function AddProduct() {
tenantId: tenantId,
productId: i?.id,
variation: target?.variant,
sku: target?.variant,
sku: `${target?.name} - ${target?.variant}`,
};
}
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ const SetupCampaign = ({ hierarchyType }) => {
const noAction = searchParams.get("action");
const isDraft = searchParams.get("draft");
const isSkip = searchParams.get("skip");
const keyParam = searchParams.get("key");
const [isDraftCreated, setIsDraftCreated] = useState(false);
const filteredBoundaryData = params?.HCM_CAMPAIGN_SELECTING_BOUNDARY_DATA?.boundaryType?.selectedData;
const client = useQueryClient();
Expand Down Expand Up @@ -1364,8 +1365,15 @@ const SetupCampaign = ({ hierarchyType }) => {
const relatedSteps = campaignConfig?.[0]?.form.filter((step) => nonNullFormDataKeys.includes(step.name));

const highestStep = relatedSteps.reduce((max, step) => Math.max(max, parseInt(step.stepCount)), 0);

if(isDraft == "true"){
const filteredSteps = campaignConfig?.[0]?.form.find((item) => item.key === keyParam)?.stepCount;
setActive(filteredSteps);
}
else{
setActive(highestStep);
}

// setActive(highestStep);
};

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,12 @@ const AddDeliveryRule = ({ targetedData, deliveryRules, setDeliveryRules, index,
optionsKey="code"
onSelect={(value) => updateDeliveryType(value)}
t={t}
disabled={
filteredDeliveryConfig?.deliveryConfig?.find((i, n) => n === targetedData?.deliveryIndex - 1)?.conditionConfig?.[delivery?.ruleKey - 1]
?.disableDeliveryType
? true
: false
}
/>
</LabelFieldPair>
)}
Expand Down
17 changes: 10 additions & 7 deletions utilities/project-factory/src/server/kafka/Listener.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Consumer, KafkaClient, Message } from 'kafka-node';
import { Message ,ConsumerGroup, ConsumerGroupOptions} from 'kafka-node';
import config from '../config';
import { getFormattedStringForDebug, logger } from '../utils/logger'; // Importing logger utility for logging
import { producer } from './Producer'; // Importing producer from the Producer module
Expand All @@ -9,27 +9,30 @@ import { throwError } from '../utils/genericUtils';


// Replace with the correct Kafka broker(s) and topic name
const kafkaConfig = {
const kafkaConfig:ConsumerGroupOptions = {
kafkaHost: config?.host?.KAFKA_BROKER_HOST, // Use the correct broker address and port
groupId: 'project-factory',
autoCommit: true,
autoCommitIntervalMs: 5000,
fromOffset: 'latest',

};

const topicName = config?.kafka?.KAFKA_START_CAMPAIGN_MAPPING_TOPIC;

// Create a Kafka client
const kafkaClient = new KafkaClient(kafkaConfig);
// const kafkaClient = new KafkaClient(kafkaConfig);

// Create a Kafka consumer
const consumer = new Consumer(kafkaClient, [{ topic: topicName, partition: 0 }], { autoCommit: true });
// const consumer = new Consumer(kafkaClient, [{ topic: topicName, partition: 0 }], { autoCommit: true });


const consumerGroup=new ConsumerGroup(kafkaConfig, topicName)

// Exported listener function
export function listener() {
// Set up a message event handler
consumer.on('message', async (message: Message) => {
consumerGroup.on('message', async (message: Message) => {
try {
// Parse the message value as an array of objects
const messageObject: any = JSON.parse(message.value?.toString() || '{}');
Expand All @@ -53,11 +56,11 @@ export function listener() {
});

// Set up error event handlers
consumer.on('error', (err) => {
consumerGroup.on('error', (err) => {
console.error(`Consumer Error: ${err}`);
});

consumer.on('offsetOutOfRange', (err) => {
consumerGroup.on('offsetOutOfRange', (err) => {
console.error(`Offset out of range error: ${err}`);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,28 +233,28 @@ async function validateTargets(request: any, data: any[], errors: any[], localiz
errors.push({
status: "INVALID",
rowNumber: obj["!row#number!"],
errorDetails: `Target value is missing at row ${obj['!row#number!']} in sheet ${key}. Please provide a numeric integer between 1 and 100000.`,
errorDetails: `Target value is missing at row ${obj['!row#number!']} in sheet ${key}.(Targets values can only be positive numbers less than 1 Million)`,
sheetName: key
});
} else if (typeof target !== 'number') {
errors.push({
status: "INVALID",
rowNumber: obj["!row#number!"],
errorDetails: `Target value at row ${obj['!row#number!']} in sheet ${key} is not a number. Target values must be numeric integers between 1 and 100000.`,
errorDetails: `Target value at row ${obj['!row#number!']} in sheet ${key} is not a number.(Targets values can only be positive numbers less than 1 Million)`,
sheetName: key
});
} else if (target <= 0 || target > 100000) {
} else if (target <= 0 || target > 1000000) {
errors.push({
status: "INVALID",
rowNumber: obj["!row#number!"],
errorDetails: `Target value ${target} at row ${obj['!row#number!']} in sheet ${key} is out of range. Target values must be numeric integers between 1 and 100000.`,
errorDetails: `Target value at row ${obj['!row#number!']} in sheet ${key} is out of range.(Targets values can only be positive numbers less than 1 Million)`,
sheetName: key
});
} else if (!Number.isInteger(target)) {
errors.push({
status: "INVALID",
rowNumber: obj["!row#number!"],
errorDetails: `Target value ${target} at row ${obj['!row#number!']} in sheet ${key} is not an integer. Target values must be whole numbers between 1 and 100000.`,
errorDetails: `Target value at row ${obj['!row#number!']} in sheet ${key} is not an integer.(Targets values can only be positive numbers less than 1 Million)`,
sheetName: key
});
}
Expand Down

0 comments on commit ac0f558

Please sign in to comment.