Merge pull request 'implement Config for Supplier and Delivery Service' (#107) from feature/reading_config into master
reviewed by Lukas
This commit is contained in:
commit
fb53c68be3
|
@ -1,5 +1,6 @@
|
|||
package org.hso.ecommerce.api;
|
||||
|
||||
import org.hso.ecommerce.app.config.AppSettings;
|
||||
import org.hso.ecommerce.entities.shop.CustomerOrder;
|
||||
import org.hso.ecommerce.uimodel.DeliveryData;
|
||||
import org.hso.ecommerce.uimodel.DeliveryDataEnum;
|
||||
|
@ -20,11 +21,16 @@ public class RestServiceForDelivery {
|
|||
@Autowired
|
||||
private final RestTemplateBuilder restTemplateBuilder = null;
|
||||
|
||||
private final String DELIVERY_IP_ADDRESS = "http://[::1]:8082";
|
||||
@Autowired
|
||||
private final AppSettings settings = null;
|
||||
|
||||
private String getDeliveryEndpoint() {
|
||||
return settings.getParcelServiceApiURL();
|
||||
}
|
||||
|
||||
|
||||
public String getDeliveryID(CustomerOrder customerOrder) throws ResourceAccessException {
|
||||
String url = DELIVERY_IP_ADDRESS + "/newDelivery";
|
||||
String url = getDeliveryEndpoint() + "/newDelivery";
|
||||
|
||||
RestTemplate restTemplate = restTemplateBuilder.build();
|
||||
|
||||
|
@ -49,7 +55,7 @@ public class RestServiceForDelivery {
|
|||
|
||||
public DeliveryData getDeliveryData(String trackingID) {
|
||||
|
||||
String url = DELIVERY_IP_ADDRESS + "/status";
|
||||
String url = getDeliveryEndpoint() + "/status";
|
||||
|
||||
RestTemplate restTemplate = restTemplateBuilder.build();
|
||||
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
package org.hso.ecommerce.components;
|
||||
|
||||
import org.hso.ecommerce.app.config.AppSettings;
|
||||
import org.hso.ecommerce.app.config.YAMLData;
|
||||
import org.hso.ecommerce.entities.supplier.Supplier;
|
||||
import org.hso.ecommerce.repos.supplier.SupplierRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
public class SupplierInitializer {
|
||||
|
||||
@Autowired
|
||||
private final SupplierRepository supplierRepository = null;
|
||||
|
||||
@Autowired
|
||||
private final AppSettings appSettings = null;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
for (YAMLData.Supplier cfg : appSettings.getSuppliers()) {
|
||||
Optional<Supplier> sup = supplierRepository.findByUuid(cfg.id);
|
||||
|
||||
Supplier supplier;
|
||||
if (sup.isPresent()) {
|
||||
supplier = sup.get();
|
||||
supplier.name = cfg.name;
|
||||
supplier.apiUrl = cfg.apiURL;
|
||||
} else {
|
||||
supplier = new Supplier();
|
||||
supplier.uuid = cfg.id;
|
||||
supplier.apiUrl = cfg.apiURL;
|
||||
supplier.name = cfg.name;
|
||||
}
|
||||
supplierRepository.save(supplier);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,19 +1,23 @@
|
|||
package org.hso.ecommerce.repos.supplier;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.hso.ecommerce.entities.supplier.Supplier;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface SupplierRepository extends JpaRepository<Supplier, Long> {
|
||||
|
||||
|
||||
@Query("SELECT a FROM Supplier a")
|
||||
List<Supplier> findAll();
|
||||
|
||||
|
||||
@Query("SELECT a FROM Supplier a WHERE a.id = :supplierId")
|
||||
Supplier findSupplierById(@Param("supplierId") long supplierId);
|
||||
|
||||
@Query("SELECT a FROM Supplier a WHERE a.uuid = :uuid")
|
||||
Optional<Supplier> findByUuid(@Param("uuid") String uuid);
|
||||
}
|
Reference in New Issue