working pipeline. curl admin/imports/4 imported a test product into the db.

This commit is contained in:
2025-11-29 10:55:56 -05:00
parent 0baae3bc6c
commit 5407c245eb
4 changed files with 135 additions and 3 deletions

View File

@@ -1,5 +1,9 @@
package group.goforward.ballistic.imports;
public interface MerchantFeedImportService {
/**
* Import the feed for a given merchant id.
*/
void importMerchantFeed(Integer merchantId);
}

View File

@@ -1,16 +1,108 @@
package group.goforward.ballistic.imports;
import group.goforward.ballistic.model.Brand;
import group.goforward.ballistic.model.Merchant;
import group.goforward.ballistic.model.Product;
import group.goforward.ballistic.repos.BrandRepository;
import group.goforward.ballistic.repos.MerchantRepository;
import group.goforward.ballistic.repos.ProductRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
@Transactional
public class MerchantFeedImportServiceImpl implements MerchantFeedImportService {
private final MerchantRepository merchantRepository;
private final BrandRepository brandRepository;
private final ProductRepository productRepository;
public MerchantFeedImportServiceImpl(MerchantRepository merchantRepository,
BrandRepository brandRepository,
ProductRepository productRepository) {
this.merchantRepository = merchantRepository;
this.brandRepository = brandRepository;
this.productRepository = productRepository;
}
@Override
public void importMerchantFeed(Integer merchantId) {
// TODO: real import logic will be re-added.
// This stub exists to fix the repository/package mixup and get the project compiling again.
throw new UnsupportedOperationException("Merchant feed import not yet implemented after refactor.");
System.out.println("IMPORT >>> importMerchantFeed(" + merchantId + ")");
Merchant merchant = merchantRepository.findById(merchantId)
.orElseThrow(() -> new IllegalArgumentException("Merchant not found: " + merchantId));
// For now, just pick a brand to prove inserts work.
Brand brand = brandRepository.findByNameIgnoreCase("Aero Precision")
.orElseThrow(() -> new IllegalStateException("Brand 'Aero Precision' not found"));
// Fake a single row well swap this for real CSV parsing once the plumbing works
MerchantFeedRow row = new MerchantFeedRow(
"TEST-SKU-001",
"APPG100002",
brand.getName(),
"Test Product From Import",
null, null, null, null, null,
null, null, null, null, null,
null, null,
null, null, null, null, null, null, null, null
);
Product p = createProduct(brand, row);
System.out.println("IMPORT >>> created product id=" + p.getId()
+ ", name=" + p.getName()
+ ", merchant=" + merchant.getName());
}
private Product createProduct(Brand brand, MerchantFeedRow row) {
System.out.println("IMPORT >>> createProduct brand=" + brand.getName()
+ ", sku=" + row.sku()
+ ", productName=" + row.productName());
Product p = new Product();
p.setBrand(brand);
String name = row.productName();
if (name == null || name.isBlank()) {
name = row.sku();
}
if (name == null || name.isBlank()) {
name = "Unknown Product";
}
// Set required fields: name and slug
p.setName(name);
// Generate a simple slug from the name (fallback to SKU if needed)
String baseForSlug = name;
if (baseForSlug == null || baseForSlug.isBlank()) {
baseForSlug = row.sku();
}
if (baseForSlug == null || baseForSlug.isBlank()) {
baseForSlug = "product-" + System.currentTimeMillis();
}
String slug = baseForSlug
.toLowerCase()
.replaceAll("[^a-z0-9]+", "-")
.replaceAll("(^-|-$)", "");
if (slug.isBlank()) {
slug = "product-" + System.currentTimeMillis();
}
p.setSlug(slug);
if (p.getPlatform() == null || p.getPlatform().isBlank()) {
p.setPlatform("AR-15");
}
if (p.getPartRole() == null || p.getPartRole().isBlank()) {
p.setPartRole("unknown");
}
return productRepository.save(p);
}
}

View File

@@ -0,0 +1,30 @@
package group.goforward.ballistic.imports;
import java.math.BigDecimal;
public record MerchantFeedRow(
String sku,
String manufacturerId,
String brandName,
String productName,
String longDescription,
String shortDescription,
String department,
String category,
String subCategory,
String thumbUrl,
String imageUrl,
String buyLink,
String keywords,
String reviews,
BigDecimal retailPrice,
BigDecimal salePrice,
String brandPageLink,
String brandLogoImage,
String productPageViewTracking,
String variantsXml,
String mediumImageUrl,
String productContentWidget,
String googleCategorization,
String itemBasedCommission
) {}

View File

@@ -1,11 +1,17 @@
package group.goforward.ballistic.repos;
import group.goforward.ballistic.model.Product;
import group.goforward.ballistic.model.Brand;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.Optional;
import java.util.UUID;
public interface ProductRepository extends JpaRepository<Product, Integer> {
Optional<Product> findByUuid(UUID uuid);
Optional<Product> findByBrandAndMpn(Brand brand, String mpn);
Optional<Product> findByBrandAndUpc(Brand brand, String upc);
}