diff --git a/opencti-platform/opencti-graphql/src/parser/csv-bundler.ts b/opencti-platform/opencti-graphql/src/parser/csv-bundler.ts index 184837564542..0d67251ed16d 100644 --- a/opencti-platform/opencti-graphql/src/parser/csv-bundler.ts +++ b/opencti-platform/opencti-graphql/src/parser/csv-bundler.ts @@ -12,6 +12,7 @@ import { validateInputCreation } from '../schema/schema-validator'; import { parsingProcess } from './csv-parser'; import { isStixDomainObjectContainer } from '../schema/stixDomainObject'; import { objects } from '../schema/stixRefRelationship'; +import { isEmptyField } from '../database/utils'; const validateInput = async (context: AuthContext, user: AuthUser, inputs: Record[]) => { await Promise.all(inputs.map(async (input) => { @@ -35,10 +36,11 @@ export const bundleProcess = async (context: AuthContext, user: AuthUser, conten const records = await parsingProcess(content, mapper.separator); if (records) { await Promise.all((records.map(async (record: string[]) => { + const isEmptyLine = record.length === 1 && isEmptyField(record[0]); // Handle header if (skipLine) { skipLine = false; - } else { + } else if (!isEmptyLine) { // Compute input by representation const inputs = mappingProcess(sanitizedMapper, record); // Remove inline elements diff --git a/opencti-platform/opencti-graphql/src/parser/csv-mapper.ts b/opencti-platform/opencti-graphql/src/parser/csv-mapper.ts index b5097b5fbcde..ee9dcf4eca08 100644 --- a/opencti-platform/opencti-graphql/src/parser/csv-mapper.ts +++ b/opencti-platform/opencti-graphql/src/parser/csv-mapper.ts @@ -14,7 +14,7 @@ import { CsvMapperRepresentationType, Operator } from '../modules/internal/csvMa import type { AttributeColumn } from '../generated/graphql'; import { isValidTargetType } from '../modules/internal/csvMapper/csvMapper-utils'; -export type InputType = string | string[] | number | Record; +export type InputType = string | string[] | boolean | number | Record; // -- HANDLE VALUE -- @@ -23,10 +23,12 @@ const formatValue = (value: string, type: AttrType, column: AttributeColumn) => const timezone = column.configuration?.timezone; if (type === 'string') { return value.trim(); - } if (type === 'numeric') { + } + if (type === 'numeric') { const formattedValue = Number(value); return Number.isNaN(formattedValue) ? null : formattedValue; - } if (type === 'date') { + } + if (type === 'date') { try { moment.suppressDeprecationWarnings = true; if (isNotEmptyField(pattern_date)) { @@ -40,6 +42,11 @@ const formatValue = (value: string, type: AttrType, column: AttributeColumn) => return null; } } + if (type === 'boolean') { + const stringBoolean = value.toLowerCase().trim(); + // TODO Matching value must be configurable in parser option + return stringBoolean === 'true' || stringBoolean === 'yes' || stringBoolean === '1'; + } return value; };