Search in sources :

Example 1 with LucidCalcReader

use of eu.ggnet.lucidcalc.LucidCalcReader in project dwoss by gg-net.

the class JExcelReaderTest method testReadFile.

/**
 * Test of read method, of class JExcelLucidCalcReader.
 */
@Test
public void testReadFile() {
    LucidCalcReader reader = new JExcelLucidCalcReader();
    reader.addColumn(0, String.class).addColumn(1, Double.class).addColumn(2, Integer.class).addColumn(3, Double.class);
    List<List<? extends Object>> expResult = new ArrayList<List<? extends Object>>();
    expResult.add(Arrays.asList("AAA", Double.valueOf(1.3), Integer.valueOf(1), Double.valueOf(10.0)));
    expResult.add(Arrays.asList("BBB", Double.valueOf(1.4), Integer.valueOf(2), Double.valueOf(1.5)));
    expResult.add(Arrays.asList("CCC", Double.valueOf(1.5), Integer.valueOf(3), Double.valueOf(2.49)));
    expResult.add(Arrays.asList("DDD", Double.valueOf(3.55), Integer.valueOf(4), Double.valueOf(55.33)));
    List result = reader.read(TEST_DATA);
    assertEquals(expResult, result);
    assertFalse(reader.isError());
    assertEquals(0, reader.getErrors().size());
}
Also used : LucidCalcReader(eu.ggnet.lucidcalc.LucidCalcReader) Test(org.junit.Test)

Example 2 with LucidCalcReader

use of eu.ggnet.lucidcalc.LucidCalcReader in project dwoss by gg-net.

the class ImageIdHandlerOperation method importMissing.

@Override
public Reply<Void> importMissing(FileJacket inFile) {
    final SubMonitor m = monitorFactory.newSubMonitor("Image Ids importieren", 100);
    m.message("Reading File");
    m.start();
    LucidCalcReader reader = new JExcelLucidCalcReader();
    reader.addColumn(0, String.class);
    reader.addColumn(1, String.class);
    reader.addColumn(2, String.class);
    reader.addColumn(3, String.class);
    reader.addColumn(4, Integer.class);
    reader.setHeadline(true);
    reader.setTrim(true);
    File f = inFile.toTemporaryFile();
    List<ImageIdLine> lines = reader.read(f, ImageIdLine.class);
    List<String> errors = reader.getErrors();
    ProductEao productEao = new ProductEao(uuEm);
    m.message("Importing Data");
    m.setWorkRemaining(lines.size());
    for (ImageIdLine line : lines) {
        m.worked(1, "importing " + line.getPartNo());
        if (line.getImageId() == null) {
            errors.add("No ImageId for " + line.getPartNo());
            continue;
        }
        Product p = productEao.findByPartNo(line.getPartNo());
        if (p != null) {
            p.setImageId(line.getImageId());
        } else {
            errors.add("No Product for '" + line.getPartNo() + "'");
        }
    }
    m.finish();
    if (!errors.isEmpty())
        return Reply.failure(errors.toString());
    return Reply.success(null);
}
Also used : JExcelLucidCalcReader(eu.ggnet.lucidcalc.jexcel.JExcelLucidCalcReader) SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) JExcelLucidCalcReader(eu.ggnet.lucidcalc.jexcel.JExcelLucidCalcReader) LucidCalcReader(eu.ggnet.lucidcalc.LucidCalcReader) ProductEao(eu.ggnet.dwoss.uniqueunit.ee.eao.ProductEao) File(java.io.File)

Example 3 with LucidCalcReader

use of eu.ggnet.lucidcalc.LucidCalcReader in project dwoss by gg-net.

the class JExcelReaderTest method testReadFileGenericType.

/**
 * Test of read method, of class JExcelLucidCalcReader.
 */
@Test
public void testReadFileGenericType() {
    LucidCalcReader reader = new JExcelLucidCalcReader();
    reader.addColumn(0, String.class).addColumn(1, Double.class).addColumn(2, Integer.class).addColumn(3, Double.class);
    List<SampleBean> expResult = new ArrayList<>();
    expResult.add(new SampleBean("AAA", 1.3, 1, 10.0));
    expResult.add(new SampleBean("BBB", 1.4, 2, 1.5));
    expResult.add(new SampleBean("CCC", 1.5, 3, 2.49));
    expResult.add(new SampleBean("DDD", 3.55, 4, 55.33));
    List<SampleBean> result = reader.read(TEST_DATA, new SampleBean());
    assertEquals(expResult, result);
    assertFalse(reader.isError());
    assertEquals(0, reader.getErrors().size());
}
Also used : LucidCalcReader(eu.ggnet.lucidcalc.LucidCalcReader) Test(org.junit.Test)

Example 4 with LucidCalcReader

use of eu.ggnet.lucidcalc.LucidCalcReader in project dwoss by gg-net.

the class ImporterOperation method fromXls.

/**
 * Imports the Pricemanagement from an XLS file with a defined form.
 * The Form is as follows
 * <ul>
 * <li>Column 1 (A) = Refurbished Id, Type:Integer</li>
 * <li>Column 2 (C) = Manufacturer PartNo, Type:String</li>
 * <li>Column 4 (E) = Retailer Price, Type:Double</li>
 * <li>Column 7 (H) = Customer Price without Tax, Type:Double</li>
 * <li>Column 9 (J) = Set/Unset PartNoFixed Price, Type:Integer</li>
 * <li>Column 10 (K) = Warranty Id, Type:Integer</li>
 * </ul>
 *
 * @param jacket  the file in a jacket
 * @param arranger
 * @return a Reply of FileJacket
 * @throws UserInfoException
 */
@Override
public Reply<File> fromXls(FileJacket jacket, String arranger) throws UserInfoException {
    final SubMonitor m = monitorFactory.newSubMonitor("Import from Xls", 10);
    m.start();
    File f = jacket.toTemporaryFile();
    LucidCalcReader reader = new JExcelLucidCalcReader();
    // RefurbishedId
    reader.addColumn(0, String.class);
    // PartNo
    reader.addColumn(2, String.class);
    // RetailerPrice
    reader.addColumn(4, Double.class);
    // CustomerPrice
    reader.addColumn(7, Double.class);
    // UnitFixPrice
    reader.addColumn(9, Integer.class);
    // PartFixPrice
    reader.addColumn(10, Integer.class);
    // WarrantyId
    reader.addColumn(11, Integer.class);
    List<PriceEngineResult> imports = reader.read(f, new PriceEngineResult());
    m.worked(2);
    if (reader.isError()) {
        m.finish();
        throw new UserInfoException(reader.getErrors());
    }
    core.store(imports, "ImportPriceManagementOperation.fromXls()", arranger, m);
    return Reply.success(f);
}
Also used : JExcelLucidCalcReader(eu.ggnet.lucidcalc.jexcel.JExcelLucidCalcReader) PriceEngineResult(eu.ggnet.dwoss.price.engine.PriceEngineResult) SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) JExcelLucidCalcReader(eu.ggnet.lucidcalc.jexcel.JExcelLucidCalcReader) LucidCalcReader(eu.ggnet.lucidcalc.LucidCalcReader) UserInfoException(eu.ggnet.dwoss.util.UserInfoException) File(java.io.File)

Example 5 with LucidCalcReader

use of eu.ggnet.lucidcalc.LucidCalcReader in project dwoss by gg-net.

the class ContractorPricePartNoImporterOperation method fromContractorXls.

// Manufacturer PartNo | EAN | Name | Contractor Reference Price | ContractorPartNo <br />
/**
 * See {@link ContractorPricePartNoImporter#fromContractorXls(de.dw.rules.TradeName, de.dw.util.FileJacket, java.lang.String) }.
 * <p/>
 * @param inFile   the inFile
 * @param arranger the arranger
 * @return
 */
@Override
public Reply<Void> fromContractorXls(TradeName contractor, FileJacket inFile, String arranger) {
    final SubMonitor m = monitorFactory.newSubMonitor(contractor + " Preise und Artikelnummern importieren", 100);
    m.start();
    m.message("Reading File");
    ProductEao productEao = new ProductEao(uuEm);
    ReportLineEao reportLineEao = new ReportLineEao(reportEm);
    LucidCalcReader reader = new JExcelLucidCalcReader();
    reader.addColumn(0, String.class).addColumn(1, String.class).addColumn(2, String.class).addColumn(3, Double.class).addColumn(4, String.class);
    List<ContractorImport> imports = reader.read(inFile.toTemporaryFile(), ContractorImport.class);
    List<String> errors = reader.getErrors();
    List<String> info = new ArrayList<>();
    // here for size, needed down below
    List<ReportLine> missingContractorPartNo = reportLineEao.findMissingContractorPartNo(contractor);
    m.worked(5);
    m.setWorkRemaining((int) (imports.size() + imports.size() * 0.5 + missingContractorPartNo.size()));
    int databaseLines = 0;
    int updatedGtin = 0;
    int newPrices = 0;
    int updatedPrices = 0;
    int updatedContractorPartNo = 0;
    Map<Product, SortedSet<ContractorImport>> importable = new HashMap<>();
    for (ContractorImport ci : imports) {
        m.worked(1, "Preparing and Sorting (" + ci.manufacturerPartNo + ")");
        if (!ci.hasManufacturerPartNoOrGtin()) {
            errors.add("No ManufacturerPartNo or EAN found for " + ci);
            continue;
        }
        Product p = null;
        // First, try finding it via gtin
        if (ci.hasValidGtin())
            p = productEao.findByGtin(Long.parseLong(ci.gtin));
        // Second try finding it via the partNo field raw
        if (p == null && !StringUtils.isBlank(ci.manufacturerPartNo))
            p = productEao.findByPartNo(ci.manufacturerPartNo);
        if (p == null) {
            // Third, try it by regex matching of part no patterns
            // Todo: implement more partno patterns an use them here, or add the type of import to this method.
            Matcher matcher = AcerRules.PART_NO_PATTERN.matcher(ci.manufacturerPartNo);
            if (matcher.find())
                p = productEao.findByPartNo(matcher.group());
        }
        if (p == null) {
            errors.add("No UniqueUnit.Product Entity found for PartNo " + ci.manufacturerPartNo + " bzw. Gtin " + ci.gtin + ", Ignoring");
            continue;
        }
        databaseLines++;
        if (importable.containsKey(p)) {
            // sorting based on product
            importable.get(p).add(ci);
        } else {
            SortedSet<ContractorImport> set = new TreeSet<>(Comparator.comparing(ContractorImport::getReferencePrice));
            set.add(ci);
            importable.put(p, set);
        }
    }
    // update size
    m.setWorkRemaining(missingContractorPartNo.size() + importable.size());
    for (Entry<Product, SortedSet<ContractorImport>> entry : importable.entrySet()) {
        Product p = entry.getKey();
        // only us the importline with the lowest price.
        ContractorImport ci = entry.getValue().first();
        m.worked(1, "Importing " + ProductFormater.toDetailedName(p));
        if (p.getGtin() == 0 && ci.hasValidGtin()) {
            // Optional set of gtin, if it is missing.
            p.setGtin(Long.parseLong(ci.gtin));
            updatedGtin++;
        }
        if (ci.getReferencePrice() > 0.01 && !TwoDigits.equals(p.getPrice(CONTRACTOR_REFERENCE), ci.getReferencePrice())) {
            // If price is valid and not equal, set it.
            double oldPrice = p.getPrice(CONTRACTOR_REFERENCE);
            if (p.hasPrice(CONTRACTOR_REFERENCE))
                updatedPrices++;
            else
                newPrices++;
            p.setPrice(CONTRACTOR_REFERENCE, ci.getReferencePrice(), "Import by " + arranger);
            info.add(ProductFormater.toDetailedName(p) + " added/updated contractor reference price from " + oldPrice + " to " + ci.getReferencePrice());
        } else {
            errors.add(ci + " hat keinen Preis");
        }
        if (ci.hasValidContractorPartNo(contractor)) {
            // If partNo is valid, set it.
            String contractorPartNo = ci.toNormalizeContractorPart(contractor);
            if (!contractorPartNo.equals(p.getAdditionalPartNo(contractor))) {
                info.add(ProductFormater.toDetailedName(p) + " added/updated contractor partno from " + p.getAdditionalPartNo(contractor) + " to " + contractorPartNo);
                p.setAdditionalPartNo(contractor, contractorPartNo);
                updatedContractorPartNo++;
            }
        } else {
            errors.add(ci.violationMessagesOfContractorPartNo(contractor));
        }
    }
    uuEm.flush();
    // Also update existing report lines, which have unset values.
    // TODO: This should happen from the report component on needed basis or as event call. not here.
    m.message("Updateing existing Reportlines");
    int updatedReportLinePartNo = 0;
    int updatedReportLineReferencePrice = 0;
    int updatedReportLineGtin = 0;
    for (ReportLine line : missingContractorPartNo) {
        Product product = uuEm.find(Product.class, line.getProductId());
        m.worked(1, "Updating ReportLine: " + line.getId());
        String head = "ReportLine(id=" + line.getId() + ") of " + ProductFormater.toDetailedName(product);
        String msg = "";
        if (product.getAdditionalPartNo(contractor) != null) {
            line.setContractorPartNo(product.getAdditionalPartNo(contractor));
            msg += " contractorPartNo:" + line.getContractorPartNo();
            updatedReportLinePartNo++;
        }
        if (product.hasPrice(CONTRACTOR_REFERENCE) && line.getContractorReferencePrice() == 0) {
            line.setContractorReferencePrice(product.getPrice(CONTRACTOR_REFERENCE));
            msg += " contractorReferencePrice:" + line.getContractorReferencePrice();
            updatedReportLineReferencePrice++;
        }
        if (product.getGtin() != line.getGtin()) {
            line.setGtin(product.getGtin());
            msg += " gtin:" + line.getGtin();
            updatedReportLineGtin++;
        }
        if (StringUtils.isBlank(msg)) {
            errors.add(head + ", no updateable values found in product.");
        } else {
            info.add(head + " updated " + msg);
        }
    }
    String summary = "Zeilen, mit gefunden (db)Artikeln: " + databaseLines + " (Entweder über PartNo oder Gtin)\n" + "GTIN/EAN aktuallisiert: " + updatedGtin + "\n" + "Neue Preise hinterlegt: " + newPrices + "\n" + "Preise aktualisiert: " + updatedPrices + "\n" + "Lieferantenartikelnummer aktualisiert: " + updatedContractorPartNo + "\n" + "Report-Fehlende GTIN/Preise/Artikelnummern Zeilen: " + missingContractorPartNo.size() + "\n" + "Report-GTIN/EAN aktuallisiert: " + updatedReportLineGtin + "\n" + "Report-Preise aktualisiert: " + updatedReportLineReferencePrice + "\n" + "Report-Lieferantenartikelnummer aktualisiert: " + updatedReportLinePartNo;
    StringBuilder details = new StringBuilder();
    if (!info.isEmpty()) {
        details.append("Infos\n-----\n");
        info.forEach((i) -> details.append(i).append("\n"));
    }
    details.append("-----------------\nFehler/Nicht importierbar\n-----------------\n");
    errors.forEach((error) -> details.append(error).append("\n"));
    m.finish();
    if (updatedGtin + newPrices + updatedPrices + updatedContractorPartNo == 0)
        return Reply.failure(summary, details.toString());
    else
        return Reply.success(null, summary, details.toString());
}
Also used : JExcelLucidCalcReader(eu.ggnet.lucidcalc.jexcel.JExcelLucidCalcReader) ReportLine(eu.ggnet.dwoss.report.ee.entity.ReportLine) Matcher(java.util.regex.Matcher) SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) ProductEao(eu.ggnet.dwoss.uniqueunit.ee.eao.ProductEao) ReportLineEao(eu.ggnet.dwoss.report.ee.eao.ReportLineEao) JExcelLucidCalcReader(eu.ggnet.lucidcalc.jexcel.JExcelLucidCalcReader) LucidCalcReader(eu.ggnet.lucidcalc.LucidCalcReader)

Aggregations

LucidCalcReader (eu.ggnet.lucidcalc.LucidCalcReader)6 SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)4 JExcelLucidCalcReader (eu.ggnet.lucidcalc.jexcel.JExcelLucidCalcReader)4 ProductEao (eu.ggnet.dwoss.uniqueunit.ee.eao.ProductEao)3 Product (eu.ggnet.dwoss.uniqueunit.ee.entity.Product)3 File (java.io.File)2 Test (org.junit.Test)2 PriceEngineResult (eu.ggnet.dwoss.price.engine.PriceEngineResult)1 ReportLineEao (eu.ggnet.dwoss.report.ee.eao.ReportLineEao)1 ReportLine (eu.ggnet.dwoss.report.ee.entity.ReportLine)1 PartNoSupport (eu.ggnet.dwoss.rules.partno.PartNoSupport)1 UserInfoException (eu.ggnet.dwoss.util.UserInfoException)1 Matcher (java.util.regex.Matcher)1