Bir csv dosyasını ve csv'nin her satırının bir nesnesini oluşturan başka bir sınıfı okumamı sağlayan bir sınıfa sahibim, böylece her satır için ayrı ayrı eylemler gerçekleştirebilirim . bunu otomasyon için kullanıyoruz.csv dosyasını okurken bir sonraki satıra geçme
import java.io.File
import com.github.tototoshi.csv.CSVReader
import jxl.{Cell, Workbook}
import scala.collection.mutable
trait DataSource {
def read (fileName: String): Seq[Map[String, String]]
}
object CsvDataSource extends DataSource {
import com.github.tototoshi.csv.CSVFormat
import com.github.tototoshi.csv.Quoting
import com.github.tototoshi.csv.QUOTE_MINIMAL
implicit object VATBoxFormat extends CSVFormat {
val delimiter: Char = '\t'
val quoteChar: Char = '"'
val escapeChar: Char = '"'
val lineTerminator: String = "\r\n"
val quoting: Quoting = QUOTE_MINIMAL
val treatEmptyLineAsNil: Boolean = false
}
override def read(file: String): Seq[Map[String, String]] = {
val reader = CSVReader.open(file, "UTF-16")(VATBoxFormat)
reader.iteratorWithHeaders.toSeq
}
}
bu PurchaseInfo geçerli: programım durur bir satırdan sonra nedense itibaren
... benbu benim csv okuyucu sınıftır .. yanlış ne olduğunu bilmiyorum bu yüzden önce çalışmış purc bir dizi elde insertData adlı bir yöntem yoktur tüm işlemleri sınıfında,
case class PurchaseInfo(
something1: String,
something2: String,
something3: String,
something4: String) {
}
object PurchaseInfo {
private def changeDateFormat(dateInString: String): String = {
//System.out.println(dateInString)
val formatter: SimpleDateFormat = new SimpleDateFormat("MMM dd, yyyy")
val formatter2: SimpleDateFormat = new SimpleDateFormat("dd/MM/yyyy")
val date: Date = formatter.parse(dateInString)
return formatter2.format(date).toString
}
def fromDataSource (ds: DataSource)(fileName: String): Seq[PurchaseInfo] = {
ds.read(fileName).map { c =>
PurchaseInfo(
something1 = c("Supplier Address Street Number"),
something2 = c("Supplier Address Route"),
something3 = c("Supplier Address Locality"),
something4 = c("Supplier Address Postal Code")
)
}
}
}
Şimdi: CSV her satırın bir nesne oluşturma olan sınıf haseInfos ve bu seq içindeki her purchaseInfo ile başka bir yöntemi çağırır ....
def insertData (purchaseInfos: Seq[PurchaseInfo]) = {
//logging in and then getting directed to the right path (where we start the invoices automation)
login()
val res = purchaseInfos.map { case purchaseInfo =>
println(purchaseInfo.invoiceNumber)
(purchaseInfo, Try(addInvoiceFlow(purchaseInfo)))
}
res
}
sorun insertData ... neden addInvoiceFlow ilk purchaseInfo ile tek çağırır ve durur o? Kontrol ettim ve 34 hatları csv dosyası ile hiçbir prob yoktur bu yüzden .. vardır
bu scala yazılır ancak satır sonlandırıcı dizisi \r\n
ise java çok :)
"insertData" öğesinin "purchaseInfos" argümanının nasıl oluşturulduğunu göstermiyorsunuz. Bu sırada birden fazla giriş olduğundan emin misiniz? – Tim