List of usage examples for org.apache.commons.csv CSVRecord size
public int size()
From source file:org.hoteia.qalingo.translation.LoaderTranslationUtil.java
private static void processLineWithValue(DataOutputStream writer, String prefixKey, CSVRecord line, int languagePosition, int linePosition, String outputEncoding) throws UnsupportedEncodingException, IOException { if (line.size() > 1) { String key = prefixKey + "."; String firstCell = line.get(0); if (StringUtils.isNotEmpty(firstCell)) { key = key + I18nKeyUtil.handleKey(firstCell).trim() + "."; }/*from w ww.j a va 2 s . c o m*/ String secondCell = line.get(1); if (StringUtils.isNotEmpty(secondCell)) { key = key + I18nKeyUtil.handleKey(secondCell).trim(); if (StringUtils.isNotEmpty(secondCell) && line.size() > languagePosition) { String value = line.get(languagePosition); if (value.contains("\\\"")) { LOG.warn("Some properties values contain double quote twice: " + value); value = value.replace("\\\"", "\""); } writer.write(((String) key + "=" + value).getBytes(outputEncoding)); } } if (linePosition != 1) { writer.write(buildCarriageReturn(outputEncoding)); } } }
From source file:org.italiangrid.storm.webdav.authz.vomap.MapfileVOMembershipSource.java
private boolean isValidCSVRecord(CSVRecord r) { if (r.size() > 3) { logger.debug("Invalid CSVRecord: {}. Illegal size: {}", r, r.size()); return false; }//from w w w.j a v a 2s . c o m if (!r.get(0).startsWith("/")) { logger.debug("Invalid CSVRecord: {}. Subject does not start with / : {}", r, r.get(0)); return false; } return true; }
From source file:org.kisoonlineapp.kisoonlineapp.csv.DefaultOutputTemplate.java
@Override protected void outputData(CSVRecord csvRecord) { for (int i = 0; i < csvRecord.size(); i++) { System.out.print("\'" + csvRecord.get(i) + "\', "); }/*from ww w .j ava 2 s . co m*/ }
From source file:org.n52.wps.csv2wiki.CSV2TWikiProcess.java
private String transformWithParser(CSVParser parser) throws IOException { StringBuilder sb = new StringBuilder(); boolean header = true; for (CSVRecord h : parser.getRecords()) { for (int i = 0; i < h.size(); i++) { if (header) { sb.append("| *"); sb.append(h.get(i));/*from w ww.ja v a 2 s . c o m*/ sb.append("* "); } else { sb.append("| "); sb.append(h.get(i)); sb.append(" "); } } sb.append("|"); sb.append(System.getProperty("line.separator")); header = false; } return sb.toString(); }
From source file:org.nuxeo.ecm.csv.core.CSVImporterWork.java
protected void doImport(CSVParser parser) { log.info(String.format("Importing CSV file: %s", getBlob().getFilename())); Map<String, Integer> header = parser.getHeaderMap(); if (header == null) { logError(0, "No header line, empty file?", LABEL_CSV_IMPORTER_EMPTY_FILE); return;/*from www. ja va 2s. co m*/ } if (!header.containsKey(CSV_NAME_COL)) { logError(0, "Missing 'name' column", LABEL_CSV_IMPORTER_MISSING_NAME_COLUMN); return; } hasTypeColumn = header.containsKey(CSV_TYPE_COL); try { int batchSize = options.getBatchSize(); Iterable<CSVRecord> it = parser; if (computeTotal) { try { List<CSVRecord> l = parser.getRecords(); total = l.size(); it = l; } catch (IOException e) { log.warn("Could not compute total number of document to be imported"); } } for (CSVRecord record : it) { if (record.size() == 0) { // empty record importLogs.add(new CSVImportLog(getLineNumber(record), Status.SKIPPED, "Empty record", LABEL_CSV_IMPORTER_EMPTY_LINE)); continue; } try { if (importRecord(record, header)) { docsCreatedCount++; getStore().putParameter(id, "status", new CSVImportStatus(CSVImportStatus.State.RUNNING, docsCreatedCount, total)); if (docsCreatedCount % batchSize == 0) { commitOrRollbackTransaction(); startTransaction(); } } } catch (NuxeoException e) { // try next line Throwable unwrappedException = unwrapException(e); logError(getLineNumber(parser), "Error while importing line: %s", LABEL_CSV_IMPORTER_ERROR_IMPORTING_LINE, unwrappedException.getMessage()); log.debug(unwrappedException, unwrappedException); } } try { session.save(); } catch (NuxeoException e) { Throwable ue = unwrapException(e); logError(getLineNumber(parser), "Unable to save: %s", LABEL_CSV_IMPORTER_UNABLE_TO_SAVE, ue.getMessage()); log.debug(ue, ue); } } finally { commitOrRollbackTransaction(); startTransaction(); } log.info(String.format("Done importing CSV file: %s", getBlob().getFilename())); }
From source file:org.nuxeo.ecm.directory.DirectoryCSVLoader.java
/** * Loads the CSV data file based on the provided schema, and creates the corresponding entries using the provided * loader.//from w ww . ja v a2s. c om * * @param dataFileName the file name containing CSV data * @param delimiter the CSV column separator * @param schema the data schema * @param loader the actual consumer of loaded rows * @since 8.4 */ public static void loadData(String dataFileName, char delimiter, Schema schema, Consumer<Map<String, Object>> loader) throws DirectoryException { try (InputStream in = getResource(dataFileName); // CSVParser csvParser = new CSVParser(new InputStreamReader(in, "UTF-8"), CSVFormat.DEFAULT.withDelimiter(delimiter).withHeader())) { Map<String, Integer> header = csvParser.getHeaderMap(); List<Field> fields = new ArrayList<>(); for (String columnName : header.keySet()) { Field field = schema.getField(columnName.trim()); if (field == null) { throw new DirectoryException( "Column not found: " + columnName + " in schema: " + schema.getName()); } fields.add(field); } int lineno = 1; // header was first line for (CSVRecord record : csvParser) { lineno++; if (record.size() == 0 || record.size() == 1 && StringUtils.isBlank(record.get(0))) { // NXP-2538: allow columns with only one value but skip empty lines continue; } if (!record.isConsistent()) { log.error("Invalid column count while reading CSV file: " + dataFileName + ", line: " + lineno + ", values: " + record); continue; } Map<String, Object> map = new HashMap<String, Object>(); for (int i = 0; i < header.size(); i++) { Field field = fields.get(i); String value = record.get(i); Object v = CSV_NULL_MARKER.equals(value) ? null : decode(field, value); map.put(field.getName().getPrefixedName(), v); } loader.accept(map); } } catch (IOException e) { throw new DirectoryException("Read error while reading data file: " + dataFileName, e); } }
From source file:org.nuxeo.theme.Utils.java
public static List<String> csvToList(String str) throws IOException { if ("".equals(str) || str == null) { return new ArrayList<>(); }//from www. jav a2 s . com StringReader sr = new StringReader(str); try (CSVParser reader = new CSVParser(sr, CSVFormat.DEFAULT.withDelimiter(','))) { Iterator<CSVRecord> iterator = reader.iterator(); if (!iterator.hasNext()) { return new ArrayList<>(); } else { CSVRecord nextRecord = iterator.next(); List<String> result = new ArrayList<>(nextRecord.size()); for (String value : nextRecord) { result.add(value); } return result; } } }
From source file:org.nuxeo.theme.vocabularies.VocabularyManager.java
public List<VocabularyItem> getItems(String name) { VocabularyType vocabularyType = (VocabularyType) Manager.getTypeRegistry().lookup(TypeFamily.VOCABULARY, name);/*from w w w . j a v a2 s .c o m*/ if (vocabularyType == null) { return null; } final String path = vocabularyType.getPath(); final String className = vocabularyType.getClassName(); if (path == null && className == null) { log.error("Must specify a class name or a path for vocabulary: " + name); return null; } if (path != null && className != null) { log.error("Cannot specify both a class name and a path for vocabulary: " + name); return null; } if (className != null) { Vocabulary vocabulary = getInstance(className); if (vocabulary == null) { log.error("Vocabulary class not found: " + className); return null; } return vocabulary.getItems(); } if (path != null) { if (!path.endsWith(".csv")) { log.error("Only .csv vocabularies are supported: " + path); return null; } final List<VocabularyItem> items = new ArrayList<>(); try (InputStream is = getClass().getClassLoader().getResourceAsStream(path)) { if (is == null) { log.error("Vocabulary file not found: " + path); return null; } try (CSVParser reader = new CSVParser(new InputStreamReader(is, Charsets.UTF_8), CSVFormat.DEFAULT)) { for (CSVRecord record : reader) { final String value = record.get(0); String label = value; if (record.size() >= 2) { label = record.get(1); } items.add(new VocabularyItem(value, label)); } } } catch (IOException e) { log.error("Could not read vocabulary file: " + path, e); } return items; } return null; }
From source file:org.ofbiz.magento.CatalogServices.java
public static Map<String, Object> importMagentoProducts(DispatchContext ctx, Map<String, ? extends Object> context) { Delegator delegator = ctx.getDelegator(); LocalDispatcher dispatcher = ctx.getDispatcher(); GenericValue userLogin = (GenericValue) context.get("userLogin"); Locale locale = (Locale) context.get("locale"); Map<String, Object> serviceResult = new HashMap<String, Object>(); int errorRecords = 0; int processedRecords = 0; try {// ww w . j a v a 2 s.c om serviceResult = dispatcher.runSync("getMagentoProducts", context); if (ServiceUtil.isError(serviceResult)) { ServiceUtil.returnError( UtilProperties.getMessage(resource, "MagentoErrorInGettingProductsFromMagento", locale)); } serviceResult.clear(); File csvFile = new File(System.getProperty("ofbiz.home") + "/runtime/tmp/MagentoProductInfo.csv"); BufferedReader reader = new BufferedReader(new FileReader(csvFile)); String fieldDelimiter = ","; String fieldEncapsulator = "\""; CSVFormat csvFormat = CSVFormat.DEFAULT.withDelimiter(fieldDelimiter.charAt(0)) .withQuote(fieldEncapsulator.charAt(0)).withIgnoreEmptyLines(true) .withIgnoreSurroundingSpaces(true); CSVParser parser = new CSVParser(reader, csvFormat); Boolean isFirstLine = true; String[] mappedKeys = null; Map<String, Object> processedResult = new HashMap<String, Object>(); Map<String, Object> serviceResp = new HashMap<String, Object>(); for (CSVRecord csvRecord : csvFormat.parse(reader)) { int csvRecordSize = csvRecord.size(); if (isFirstLine) { mappedKeys = new String[csvRecordSize]; for (int i = 0; i < csvRecordSize; i++) { mappedKeys[i] = csvRecord.get(i); } isFirstLine = false; } else { Map<String, Object> mappedValues = new HashMap<String, Object>(); for (int i = 0; i < mappedKeys.length; i++) { String csvValue = csvRecord.get(i); String value = (i < csvRecordSize ? csvValue : ""); if (UtilValidate.isNotEmpty(value)) { value = value.trim().replaceAll(">|<", ""); } mappedValues.put(mappedKeys[i], value); } Map<String, Object> serviceInMap = UtilMisc.toMap("userLogin", userLogin, "productId", mappedValues.get("Product Id"), "externalId", mappedValues.get("Product Id"), "sku", mappedValues.get("SKU"), "productTypeId", mappedValues.get("Product Type Id"), "productName", mappedValues.get("Product Name"), "bundleParentId", mappedValues.get("Bundle Parent Id"), "configurableParentId", mappedValues.get("Configurable Parent Id"), "groupedParentId", mappedValues.get("Grouped Parent Id"), "description", mappedValues.get("Description"), "longDescription", mappedValues.get("Long Description"), "price", mappedValues.get("Price"), "taxClassId", mappedValues.get("Tax Class Id"), "categoryIds", mappedValues.get("Category Ids"), "webSiteIds", mappedValues.get("Web Site Ids"), "thumbnailImageUrl", mappedValues.get("Thumbnail Image Url"), "smallImageUrl", mappedValues.get("Small Image Url"), "originalImageUrl", mappedValues.get("Original Image Url"), "urlKey", mappedValues.get("Url Key"), "urlPath", mappedValues.get("Url Path"), "metaDescription", mappedValues.get("Meta Description"), "metaKeyword", mappedValues.get("Meta Keyword"), "metaTitle", mappedValues.get("Meta Title"), "status", mappedValues.get("Status"), "specialFromDate", mappedValues.get("Special From Date"), "specialPrice", mappedValues.get("Special Price"), "createdDate", mappedValues.get("Created At"), "lastModifiedDate", mappedValues.get("Updated At")); Boolean isError = false; if (UtilValidate.isEmpty(serviceInMap.get("productId"))) { isError = true; Debug.logError("Product ID is missing : ", module); } String productId = (String) serviceInMap.get("productId"); productId = "MAG-" + productId.trim(); serviceInMap.put("productId", productId); String bundleParentId = ((String) serviceInMap.get("bundleParentId")).trim(); if (!("NA".equalsIgnoreCase(bundleParentId))) { bundleParentId = "MAG-" + bundleParentId; } serviceInMap.put("bundleParentId", bundleParentId); String configurableParentId = ((String) serviceInMap.get("configurableParentId")).trim(); if (!("NA".equalsIgnoreCase(configurableParentId))) { configurableParentId = "MAG-" + configurableParentId; } serviceInMap.put("configurableParentId", configurableParentId); String groupedParentId = ((String) serviceInMap.get("groupedParentId")).trim(); if (!("NA".equalsIgnoreCase(groupedParentId))) { groupedParentId = "MAG-" + groupedParentId; } serviceInMap.put("groupedParentId", groupedParentId); if (UtilValidate.isEmpty(serviceInMap.get("productTypeId"))) { isError = true; Debug.logError("Product Type ID is missing for product id : " + productId, module); } if (UtilValidate.isEmpty(serviceInMap.get("productName"))) { isError = true; Debug.logError("Name is missing for product id : " + productId, module); } if (UtilValidate.isEmpty(serviceInMap.get("price"))) { isError = true; Debug.logError("Price is missing for product id : " + productId, module); } Debug.logInfo("Begin processing for productId [" + productId + "]", module); if (!isError) { Debug.logInfo("Create / Update product having productId [" + productId + "]", module); serviceResult = dispatcher.runSync("createMagentoProducts", serviceInMap, 600, true); } if (ServiceUtil.isError(serviceResult) || isError) { errorRecords++; processedResult.put(productId, "Error"); Debug.logInfo("Completed processing for productId [" + productId + "] with ERROR ", module); if (ServiceUtil.isError(serviceResult)) { Debug.logInfo(ServiceUtil.getErrorMessage(serviceResp), module); } } else { processedResult.put(productId, "Success"); Debug.logInfo("Processing successfully completed for product [" + productId + "]", module); } processedRecords++; } } } catch (GenericServiceException e) { Debug.logError(e, e.getMessage(), module); e.printStackTrace(); } catch (IOException e) { Debug.logError(e, e.getMessage(), module); e.printStackTrace(); } return ServiceUtil.returnSuccess(UtilProperties.getMessage(resource, "MagentoProductsHaveBeenImportedSuccessfully", UtilMisc.toMap("processedRecords", processedRecords, "successRecords", (processedRecords - errorRecords)), locale)); }
From source file:org.ofbiz.magento.InventoryServices.java
public static Map<String, Object> loadAndImportWarehouseLocations(DispatchContext dctx, Map<String, Object> context) { Delegator delegator = dctx.getDelegator(); Locale locale = (Locale) context.get("locale"); LocalDispatcher dispatcher = dctx.getDispatcher(); String fileName = (String) context.get("_uploadedFile_fileName"); String processData = (String) context.get("processData"); String contentId = (String) context.get("contentId"); GenericValue userLogin = (GenericValue) context.get("userLogin"); List<Map<String, Object>> productFacilityLocations = FastList.newInstance(); List<Map<String, Object>> processedProductFacilityLocations = FastList.newInstance(); String facilityId = (String) context.get("facilityId"); Map<String, Object> serviceResult = FastMap.newInstance(); try {// w w w .ja va 2 s. co m if (UtilValidate.isEmpty(fileName) && "N".equalsIgnoreCase(processData)) { return ServiceUtil.returnError( UtilProperties.getMessage(resource, "MagentoPleaseSelectCSVFileForImport", locale)); } boolean isCsv = false; if (UtilValidate.isNotEmpty(fileName) && "N".equalsIgnoreCase(processData)) { isCsv = fileName.contains(".csv"); } if (!isCsv && "N".equalsIgnoreCase(processData)) { isCsv = fileName.contains(".CSV"); } // If file passed and it is not csv file if (!isCsv && "N".equalsIgnoreCase(processData)) { return ServiceUtil.returnError( UtilProperties.getMessage(resource, "MagentoPleaseSelectTheFileInCSVFormat", locale)); } if (UtilValidate.isEmpty(contentId) && "Y".equalsIgnoreCase(processData)) { return ServiceUtil .returnError(UtilProperties.getMessage(resource, "MagentoNoDataExistsToProcess", locale)); } if (UtilValidate.isNotEmpty(fileName)) { Map<String, Object> fileUploadToServerCtx = dctx.getModelService("fileUploadToServer") .makeValid(context, ModelService.IN_PARAM); fileUploadToServerCtx.put("contentTypeId", "PROD_FAC_CSV_CNT"); fileUploadToServerCtx.put("statusId", "PROD_FAC_CSV_INPRGRS"); fileUploadToServerCtx.put("userLogin", userLogin); Map<String, Object> fileUploadToServerResp = dispatcher.runSync("fileUploadToServer", fileUploadToServerCtx); if (ServiceUtil.isError(fileUploadToServerResp)) { return ServiceUtil.returnError(ServiceUtil.getErrorMessage(fileUploadToServerResp)); } contentId = (String) fileUploadToServerResp.get("contentId"); } } catch (GenericServiceException ex) { // TODO Auto-generated catch block return ServiceUtil.returnError(ex.getMessage()); } catch (Exception e) { return ServiceUtil.returnError(e.getMessage()); } try { String xmlString = ContentWorker.renderContentAsText(dispatcher, delegator, contentId, null, locale, "text/plain", false); BufferedReader reader = new BufferedReader( new InputStreamReader(new ByteArrayInputStream(xmlString.getBytes()))); String fieldDelimiter = ","; String fieldEncapsulator = "\""; CSVFormat csvFormat = CSVFormat.DEFAULT.withDelimiter(fieldDelimiter.charAt(0)) .withQuote(fieldEncapsulator.charAt(0)).withIgnoreEmptyLines(true) .withIgnoreSurroundingSpaces(true); Boolean isFirstLine = true; String[] mappedKeys = null; List<String> serviceFields = new ArrayList<String>(); serviceFields.add("Product Id"); serviceFields.add("Location Seq Id"); serviceFields.add("Area Id"); serviceFields.add("Aisle Id"); serviceFields.add("Section Id"); serviceFields.add("Level Id"); serviceFields.add("Position Id"); serviceFields.add("Inventory Count"); for (CSVRecord csvRecord : csvFormat.parse(reader)) { int csvRecordSize = csvRecord.size(); if (isFirstLine) { mappedKeys = new String[csvRecordSize]; for (int i = 0; i < csvRecordSize; i++) { if (serviceFields.contains(csvRecord.get(i).trim())) { mappedKeys[i] = csvRecord.get(i); } else { return ServiceUtil.returnError( UtilProperties.getMessage(resource, "MagentoInvalidColumnFoundInCSV", locale) + csvRecord.get(i)); } } isFirstLine = false; } else { Map<String, Object> mappedValues = new HashMap<String, Object>(); for (int i = 0; i < mappedKeys.length; i++) { String csvValue = csvRecord.get(i); String value = (i < csvRecordSize ? csvValue : ""); if (UtilValidate.isNotEmpty(value)) { value = value.trim(); } mappedValues.put(mappedKeys[i], value); } Map<String, Object> serviceInMap = FastMap.newInstance(); Boolean isError = false; StringBuilder errorMessage = new StringBuilder(); String productId = (String) mappedValues.get("Product Id"); String locationSeqId = (String) mappedValues.get("Location Seq Id"); String areaId = (String) mappedValues.get("Area Id"); String aisleId = (String) mappedValues.get("Aisle Id"); String sectionId = (String) mappedValues.get("Section Id"); String levelId = (String) mappedValues.get("Level Id"); String positionId = (String) mappedValues.get("Position Id"); String inventoryCount = (String) mappedValues.get("Inventory Count"); if (UtilValidate.isEmpty(productId)) { errorMessage.append( UtilProperties.getMessage(resource, "MagentoErrorProductIdIsMissing", locale)); isError = true; } if (UtilValidate.isNotEmpty(productId)) { GenericValue goodIdentification = delegator.findOne("GoodIdentification", UtilMisc.toMap("productId", productId, "goodIdentificationTypeId", "MAGENTO_ID"), true); if (UtilValidate.isEmpty(goodIdentification)) { errorMessage.append(UtilProperties.getMessage(resource, "MagentoErrorProductNotFound", UtilMisc.toMap("productId", productId), locale)); isError = true; } else { GenericValue product = delegator.findOne("Product", UtilMisc.toMap("productId", productId), true); if (UtilValidate.isNotEmpty(product) && (product.getString("isVirtual").equalsIgnoreCase("Y"))) { errorMessage.append( UtilProperties.getMessage(resource, "MagentoErrorProductIsAVirtualProduct", UtilMisc.toMap("productId", productId), locale)); isError = true; } } } if (UtilValidate.isEmpty(locationSeqId)) { if (UtilValidate.isNotEmpty(errorMessage)) { errorMessage.append(", "); } else { errorMessage .append(UtilProperties.getMessage(resource, "MagentoError", locale) + " : "); } errorMessage.append( UtilProperties.getMessage(resource, "MagentoLocationSeqIdIsMissing", locale)); isError = true; } if (UtilValidate.isEmpty(inventoryCount)) { if (UtilValidate.isNotEmpty(errorMessage)) { errorMessage.append(", "); } else { errorMessage .append(UtilProperties.getMessage(resource, "MagentoError", locale) + " : "); } errorMessage .append(UtilProperties.getMessage(resource, "MagentoQuantityIsMissing", locale)); isError = true; } else { Integer inventory = Integer.valueOf(inventoryCount); if (inventory < 0) { if (UtilValidate.isNotEmpty(errorMessage)) { errorMessage.append(", "); } else { errorMessage.append( UtilProperties.getMessage(resource, "MagentoError", locale) + " : "); } errorMessage.append( UtilProperties.getMessage(resource, "MagentoQuantityCannotBeNegative", locale)); isError = true; } } serviceInMap.put("productId", productId); serviceInMap.put("locationSeqId", locationSeqId); serviceInMap.put("areaId", areaId); serviceInMap.put("aisleId", aisleId); serviceInMap.put("sectionId", sectionId); serviceInMap.put("levelId", levelId); serviceInMap.put("positionId", positionId); serviceInMap.put("inventoryCount", inventoryCount); serviceInMap.put("facilityId", facilityId); if (isError) { serviceInMap.put("message", errorMessage); serviceResult.put("isError", "Y"); } else { serviceInMap.put("message", "Success"); } serviceInMap.put("isError", isError); productFacilityLocations.add(serviceInMap); } } } catch (IOException e) { throw new GeneralRuntimeException( UtilProperties.getMessage(resource, "MagentoErrorInResponseWriterOutputStream", locale) + e.toString(), e); } catch (GeneralException e) { throw new GeneralRuntimeException( UtilProperties.getMessage(resource, "MagentoErrorRenderingContent", locale) + e.toString(), e); } Map<String, Object> processedResult = FastMap.newInstance(); int errorRecords = 0; int processedRecords = 0; if ("Y".equalsIgnoreCase(processData)) { if (!productFacilityLocations.isEmpty()) { for (Map<String, Object> productFacilityLocation : productFacilityLocations) { String productId = (String) productFacilityLocation.get("productId"); processedRecords++; try { productFacilityLocation.put("userLogin", userLogin); productFacilityLocation.remove("message"); productFacilityLocation.remove("isError"); Map<String, Object> serviceResp = dispatcher.runSync( "createUpdateProductFacilityAndLocation", productFacilityLocation, 3600, true); if (ServiceUtil.isError(serviceResp)) { processedResult.put(productId, "Error"); errorRecords++; } else { processedResult.put(productId, "Success"); } processedProductFacilityLocations.add(productFacilityLocation); } catch (Exception ex) { return ServiceUtil.returnError(ex.getMessage()); } } } String jobId = FileUploadHelper.getJobId(delegator, "importWarehouseLocations"); if (UtilValidate.isNotEmpty(jobId)) { String statusId = null; if (errorRecords == processedRecords) { statusId = "PROD_FAC_CSV_FAIL"; } else if (errorRecords == 0) { statusId = "PROD_FAC_CSV_SUCCESS"; } else { statusId = "PROD_FAC_CSV_PARTIAL"; } try { String message = FileUploadHelper.getPlainCustomMessage(processedResult, errorRecords, processedRecords); Map<String, Object> updateContentResp = dispatcher.runSync("updateContent", UtilMisc.<String, Object>toMap("contentId", contentId, "statusId", statusId, "userLogin", userLogin)); if (ServiceUtil.isError(updateContentResp)) { Debug.logError(ServiceUtil.getErrorMessage(updateContentResp), module); return ServiceUtil.returnError(ServiceUtil.getErrorMessage(updateContentResp)); } Map<String, Object> createSimpleTextContentDataResp = dispatcher .runSync("createSimpleTextContentData", UtilMisc.<String, Object>toMap("contentName", "Result_" + jobId + ".txt", "contentTypeId", "PROD_FAC_CSV_LOG", "text", message, "userLogin", userLogin)); if (ServiceUtil.isError(createSimpleTextContentDataResp)) { Debug.logError(ServiceUtil.getErrorMessage(createSimpleTextContentDataResp), module); return ServiceUtil .returnError(ServiceUtil.getErrorMessage(createSimpleTextContentDataResp)); } Map<String, Object> createContentAssocResp = dispatcher.runSync("createContentAssoc", UtilMisc.toMap("contentIdFrom", contentId, "contentIdTo", createSimpleTextContentDataResp.get("contentId"), "contentAssocTypeId", "PROD_FAC_CSV_RESULT", "userLogin", userLogin)); if (ServiceUtil.isError(createContentAssocResp)) { Debug.logError(ServiceUtil.getErrorMessage(createContentAssocResp), module); return ServiceUtil.returnError(ServiceUtil.getErrorMessage(createContentAssocResp)); } } catch (GenericServiceException ex) { return ServiceUtil.returnError(ex.getMessage()); } } } serviceResult.put("productFacilityLocations", productFacilityLocations); if ("Y".equalsIgnoreCase(processData)) { serviceResult.put("processedProductFacilityLocations", processedProductFacilityLocations); } else { serviceResult.put("loadFileContent", contentId); } return serviceResult; }