package com.ds.listing.control.scheduled;

import com.ds.listing.model.Listing;
import com.ds.listing.services.eBayListingService;

import javax.ejb.Schedule;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import java.util.List;

/**
 * Scheduled Tasks
 * Created by bithack on 3/31/15.
 */
@Stateless
public class Tasks {

    @PersistenceContext(unitName="primary")
    private EntityManager em;

    @Schedule(second = "*/15", minute = "*", hour = "*")
    public void checkForNewListings() {
        eBayListingService listingService = new eBayListingService();
        List<Listing> listings = findListings();
        for(Listing item : listings){
            if(listingService.addListing(item)){
                item.setStatus(true);
                em.persist(item);
            }
        }

    }

    private List<Listing> findListings(){
        Query query = em.createQuery("Select l from Listing l where l.status = false");
        return (List<Listing>) query.getResultList();
    }

}

@@ -123,16 +123,59 @@
 Service;
+%0Aimport com.ds.listing.properties.eBayAuth;
 %0A%0Aimport
@@ -362,16 +362,44 @@
 il.List;
+%0Aimport javax.inject.Inject;
 %0A%0A/**%0A *
@@ -486,16 +486,56 @@
 asks %7B%0A%0A
+    @Inject%0A    private eBayAuth auth;%0A%0A
     @Per
@@ -698,16 +698,63 @@
 ngs() %7B%0A
+        System.out.println(auth.getVersion());%0A
         
@@ -812,16 +812,36 @@
 Service(
+auth.getApiContext()
 );%0A     

Update Tasks.java