@Atomic public static void importReceivedMailTrackingFromCsv( MailTracking mailTracking, java.util.List<String> importationContents, java.util.List<ImportationReportEntry> results) { boolean errorOcurred = false; for (String line : importationContents) { ImportationReportEntry resultEntry = new ImportationReportEntry(); resultEntry.setLine(line); if (line.startsWith("#")) { break; } try { String[] fields = line.split(";", -1); CorrespondenceEntryBean bean = new CorrespondenceEntryBean(mailTracking); bean.setWhenReceived(convertToLocalDate(fields[RECEIVED_RECEIVED_DATE_IDX].trim(), false)); bean.setSender(fields[RECEIVED_SENDER_IDX].trim()); bean.setWhenSent(convertToLocalDate(fields[RECEIVED_SENT_DATE_IDX].trim(), true)); bean.setSenderLetterNumber(fields[RECEIVED_SENDER_LETTER_NUMBER_IDX].trim()); bean.setSubject(fields[RECEIVED_SUBJECT_IDX].trim()); bean.setRecipient(fields[RECEIVED_RECIPIENT_IDX].trim()); bean.setDispatchedToWhom(fields[DISPATCHED_TO_WHOM_IDX].trim()); CorrespondenceEntry entry = mailTracking.createNewEntry(bean, CorrespondenceType.RECEIVED, null); entry.setReference( String.format("%s/%s", entry.getYear().getName(), fields[RECEIVED_ID_IDX].trim())); resultEntry.setState( BundleUtil.getString("resources/MailTrackingResources", MESSAGE_LINE_IMPORTATION_OK)); } catch (WriteOnReadError e) { throw e; } catch (Exception e) { errorOcurred = true; resultEntry.setState( BundleUtil.getString( "resources/MailTrackingResources", MESSAGE_LINE_IMPORTATION_ERROR)); resultEntry.setReason(e.getMessage()); } results.add(resultEntry); } if (errorOcurred) { throw new MailTrackingDomainException("error.important.error.exception"); } }
@Atomic public static void importSentMailTrackingFromCsv( MailTracking mailTracking, java.util.List<String> importationContents, java.util.List<ImportationReportEntry> results) { boolean errorOcurred = false; for (String line : importationContents) { ImportationReportEntry resultEntry = new ImportationReportEntry(); resultEntry.setLine(line); try { String[] fields = line.split(";", -1); CorrespondenceEntryBean bean = new CorrespondenceEntryBean(mailTracking); bean.setWhenSent(convertToLocalDate(fields[SENT_DATE_IDX].trim(), false)); bean.setRecipient(fields[SENT_RECIPIENT_IDX].trim()); bean.setSubject(fields[SENT_SUBJECT_IDX].trim()); bean.setSender(fields[SENT_SENDER_IDX].trim()); // bean.setObservations(fields[SENT_OBSERVATIONS_IDX]); CorrespondenceEntry entry = mailTracking.createNewEntry(bean, CorrespondenceType.SENT, null); entry.setReference(String.format("%s/%s", entry.getYear().getName(), fields[SENT_ID_IDX])); resultEntry.setState( BundleUtil.getString("resources/MailTrackingResources", MESSAGE_LINE_IMPORTATION_OK)); } catch (WriteOnReadError e) { throw e; } catch (Exception e) { errorOcurred = true; resultEntry.setState( BundleUtil.getString( "resources/MailTrackingResources", MESSAGE_LINE_IMPORTATION_ERROR)); resultEntry.setReason(e.getMessage()); } results.add(resultEntry); } if (errorOcurred) { throw new MailTrackingDomainException("error.important.error.exception"); } }