Package com.m4f.business.domain

Examples of com.m4f.business.domain.CronTaskReport


  @RequestMapping(value="/feeds", method={RequestMethod.POST,RequestMethod.GET})
  @ResponseStatus(HttpStatus.OK)
  public void generateCoursesFeed(@RequestParam(required=true) Long mediationId,
      HttpServletRequest request) throws Exception {
    // Create a new CronTaskReport
    CronTaskReport report = cronTaskReportService.create();
    report.setObject_id(mediationId);
    report.setDate(new Date());
    report.setType(CronTaskReport.TYPE.INTERNAL_FEED);
    MediationService mediationService = mediatorService.getMediationService(mediationId, null);
    report.setDescription(new StringBuffer("Creating feed for MediationService ").append(mediationService.getName()).toString());
    if(mediationService.getHasFeed()) {
      report.setResult("NOOK because has feed.");
      cronTaskReportService.save(report);
      return;
    }
    try {
      LOGGER.info("Creating feeds for " + mediationService.getName() + " service");   
      Provider provider =  providerService.getProviderByMediationService(mediationId, null);   
      FeedSchools feedSchools = internalFeedService.createFeedSchools(host, provider, mediationService);
      internalFeedService.saveFeedSchools(feedSchools);
      HashMap<Long, ExtendedSchool> schools = new HashMap<Long, ExtendedSchool>();
      Collection<ExtendedCourse> courses =
          extendedCourseService.getCoursesByOwner(mediationService.getId(), null, null);
      for(ExtendedCourse course : courses) {
        ExtendedSchool school = extendedSchoolService.getSchool(course.getSchool(), Locale.getDefault());
        if(school != null) schools.put(school.getId(), school);
      }
      for(ExtendedSchool school : schools.values()) {
        FeedCourses feedCourse = internalFeedService.createFeedCourses(host,
            provider, mediationService, school, this.getAvailableLanguages());  
        internalFeedService.saveFeedCourses(feedCourse);
      }
      report.setResult("OK");
    } catch (Exception e) {
      LOGGER.severe(StackTraceUtil.getStackTrace(e));
      report.setResult(new StringBuffer("ERROR: ").append(e.getMessage()).toString());
      throw e;
    } finally {
      cronTaskReportService.save(report);
    }
  }
View Full Code Here


  @RequestMapping(value = "/feed", method = {RequestMethod.POST,RequestMethod.GET})
    @ResponseStatus(HttpStatus.OK)
    public void loadFeed(@RequestParam Long providerId)
                    throws ParserConfigurationException, SAXException, IOException, Exception {
    Provider provider = null;
    CronTaskReport report = null;
    Dump dump = null;
   
        try {
          provider = this.providerService.getProviderById(providerId, null);
           
            // CRON REPORT
            report = cronTaskReportService.create();
            report.setObject_id(providerId);
            report.setDate(new Date());
            report.setType(CronTaskReport.TYPE.PROVIDER_FEED);
      report.setDescription(new StringBuffer("Proveedor: ").append(provider.getName()).toString());
     
      // DUMP
      dump = this.dumpService.createDump();
          String message = "Proceso de importacion del proveedor: " + provider.getName() + " (" +
              provider.getId() + "-" + " " + ")";
      dump.setDescription(message);
      dump.setLaunched(Calendar.getInstance(new Locale("es")).getTime());
      dump.setOwner(provider.getId());
      dump.setOwnerClass(Provider.class.getName());
      this.dumpService.save(dump);
         
      // IMPORT PROVIDER'S SCHOOLS FROM FEED
      providerImporter.importSchools(provider, dump);
     
      // IMPORT PROVIDER'S COURSES FROM EACH SCHOOL
            PageManager<School> paginator = new PageManager<School>();
          long total = schoolService.countSchoolsByProvider(providerId);
          paginator.setOffset(RANGE);
          paginator.setStart(0);
          paginator.setSize(total);
          ArrayList<School> fails = new ArrayList<School>();
          for (Integer page : paginator.getTotalPagesIterator()) {
                int start = (page - 1) * RANGE;
                int end = (page) * RANGE;
                Collection<School> schools = schoolService.getSchoolsByProvider(providerId,
                                "updated", null, start, end);
                for(School school : schools) {
                  /*Map<String, String> params = new HashMap<String, String>();
                 
          params.put("providerId", String.valueOf(providerId));
          params.put("schoolId", String.valueOf(school.getId()));
          params.put("dumpId", String.valueOf(dump.getId()));
         
                  worker.addWork("school", "/provider/school", params); */
                  try {
                    providerImporter.importCourses(provider, school, dump);
                  } catch(Exception e) {
                    fails.add(school);
                  }
                }
          }
         
          // Retries
          for(School school : fails) {
            providerImporter.importCourses(provider, school, dump);
          }
         
          // Set result into report
      report.setResult("OK");
        } catch(Exception e) {
                report.setResult(new StringBuffer("ERROR: ").append(e.getMessage()).toString());
                throw e;
        } finally {
          cronTaskReportService.save(report);
          dumpService.save(dump);
          /*String[] cacheNames =  {"courses", "schools", "coursesCatalog"};
View Full Code Here

        @RequestParam(required=true) Long dumpId)
                    throws ParserConfigurationException, SAXException, IOException, Exception {
      Provider provider = null;
      School school = null;
    Dump dump = null;
    CronTaskReport report = null;
   

    try {
      provider = providerService.getProviderById(providerId, null);
      school = schoolService.getSchool(schoolId, null);
      dump = dumpService.getDump(dumpId);
     
      report = cronTaskReportService.create();
            report.setObject_id(providerId);
            report.setDate(new Date());
            report.setType(CronTaskReport.TYPE.PROVIDER_SCHOOLS);
      report.setDescription(new StringBuffer("School: ").append(provider.getName()).toString());
      int retries = 5;
      while(retries > 0) {
          try {
           providerImporter.importCourses(provider, school, dump);
           } catch(Exception e) {
             LOGGER.info("" + retries + " Fail importing courses: "+school.getName() );
             retries--;
             if(!(retries > 0)) {
               throw e;
             }
           }
      }     
      // Set result into report
     
      report.setResult("OK");
    } catch(Exception e) {
      LOGGER.severe(StackTraceUtil.getStackTrace(e));
      report.setResult(new StringBuffer("ERROR: ").append(e.getMessage()).toString());
      throw e;
    }
       
         
    }
View Full Code Here

  public void generateInternalFeedsByMediationId(@RequestParam(required=true) Long mediationId,
      @RequestHeader("host") String host) throws Exception {
    final String FRONTEND_HOST = "http://localhost:8888";
    //LOGGER.info("referer: " + referer);
    // Create a new CronTaskReport
    CronTaskReport report = cronTaskReportService.create();
    report.setObject_id(mediationId);
    report.setDate(new Date());
    report.setType(CronTaskReport.TYPE.INTERNAL_FEED);
    try {
      // Start the process   
      Provider provider =  providerService.getProviderByMediationService(mediationId, null);   
      MediationService mediationService = mediatorService.getMediationService(mediationId, null);
      //Set report description
      report.setDescription(new StringBuffer("Servicio de mediación: ").append(mediationService.getName()).toString());
     
      if(!mediationService.getHasFeed()) { // All must be manual mediator, but it's another check.
        FeedSchools feedSchools = internalFeedService.createFeedSchools(FRONTEND_HOST, provider, mediationService);
        internalFeedService.saveFeedSchools(feedSchools);
        HashMap<Long, ExtendedSchool> schools = new HashMap<Long, ExtendedSchool>();
        Collection<ExtendedCourse> courses =
          extendedCourseService.getCoursesByOwner(mediationService.getId(), null, null);
        for(ExtendedCourse course : courses) {
          ExtendedSchool school = extendedSchoolService.getSchool(course.getSchool(), Locale.getDefault());
          if(school != null) schools.put(school.getId(), school);
        }
        for(ExtendedSchool school : schools.values()) {
          FeedCourses feedCourse = internalFeedService.createFeedCourses(FRONTEND_HOST,
              provider, mediationService, school, this.getAvailableLanguages());  
          internalFeedService.saveFeedCourses(feedCourse);
        }
        // Set result into report
        report.setResult("OK");
      }
     
    } catch (Exception e) {
      LOGGER.log(Level.SEVERE, StackTraceUtil.getStackTrace(e));
      report.setResult(new StringBuffer("ERROR: ").append(e.getMessage()).toString());
      throw e;
    } finally {
      cronTaskReportService.save(report);
    }
  }
View Full Code Here

   
    final String FRONTEND_HOST = "hirubila.appspot.com";
    //LOGGER.info("referer: " + referer);
    // Create a new CronTaskReport
    Provider provider = null;
    CronTaskReport report = cronTaskReportService.create();
    report.setObject_id(mediationId);
    report.setDate(new Date());
    report.setType(CronTaskReport.TYPE.INTERNAL_FEED);
    try {
      // Start the process   
      provider =  providerService.getProviderByMediationService(mediationId, null);   
      MediationService mediationService = mediatorService.getMediationService(mediationId, null);
      LOGGER.info("Mediation name: " + mediationService.getName());
      //Set report description
      report.setDescription(new StringBuffer("Internal feed para Srv. mediacion: ").append(mediationService.getName()).toString());
     
      if(!mediationService.getHasFeed() && provider != null) { // All must be manual mediator, but it's another check.
        FeedSchools feedSchools = internalFeedService.createFeedSchools(FRONTEND_HOST, provider, mediationService);
        internalFeedService.saveFeedSchools(feedSchools);
        HashMap<Long, ExtendedSchool> schools = new HashMap<Long, ExtendedSchool>();
        Collection<ExtendedCourse> courses =
          extendedCourseService.getCoursesByOwner(mediationService.getId(), null, null);
        for(ExtendedCourse course : courses) {
          ExtendedSchool school = extendedSchoolService.getSchool(course.getSchool(), Locale.getDefault());
          if(school != null) schools.put(school.getId(), school);
        }
        for(ExtendedSchool school : schools.values()) {
          FeedCourses feedCourse = internalFeedService.createFeedCourses(FRONTEND_HOST,
              provider, mediationService, school, this.getAvailableLanguages());  
          internalFeedService.saveFeedCourses(feedCourse);
        }
        // Set result into report
        report.setResult("OK");
       
        // Invoke to update this provider information.
        if(provider != null) {
          Map<String, String> params = new HashMap<String, String>();
          params.put("providerId", String.valueOf(provider.getId()));
          params.put("manual", "true");
          worker.addWork("provider", "/task/provider/feed", params);
        }
      }
     
    } catch (Exception e) {
      LOGGER.log(Level.SEVERE, StackTraceUtil.getStackTrace(e));
      report.setResult(new StringBuffer("ERROR: ").append(e.getMessage()).toString());
      throw e;
    } finally {
      cronTaskReportService.save(report);
    }
  }
View Full Code Here

    @ResponseStatus(HttpStatus.OK)
    public void loadProviderFeed(@RequestParam Long providerId, @RequestParam(required=false, defaultValue="false") String manual, @RequestParam(required=false, defaultValue="true") String register)
                    throws ParserConfigurationException, SAXException, IOException, Exception {
    LOGGER.info("Updating provider with id: " + providerId);
    Provider provider = null;
    CronTaskReport report = null;
    Dump dump = null;
   
        try {
          // CRON REPORT
            report = cronTaskReportService.create();
            provider = this.providerService.getProviderById(providerId, null);
           
            report.setObject_id(providerId);
            report.setDate(new Date());
           
            if(("true").equals(manual)) {
              report.setType(CronTaskReport.TYPE.INTERNAL_FEED);
            } else {
              report.setType(CronTaskReport.TYPE.PROVIDER_FEED);
            }
           
      report.setDescription(new StringBuffer("Proveedor: ").append(provider.getName()).toString());
     
      // DUMP
      dump = this.dumpService.createDump();
          String message = "Proceso de importacion del proveedor: " + provider.getName() + " (" +
              provider.getId() + "-" + " " + ")";
      dump.setDescription(message);
      dump.setLaunched(Calendar.getInstance(new Locale("es")).getTime());
      dump.setOwner(provider.getId());
      dump.setOwnerClass(Provider.class.getName());
      this.dumpService.save(dump);
         
      // IMPORT PROVIDER'S SCHOOLS FROM FEED
      providerImporter.importSchools(provider, dump);
       
      // Create task to update provider�s schools from other task.
      Map<String, String> params = new HashMap<String, String>();
      params.put("providerId", String.valueOf(provider.getId()));
        worker.addWork("school", "/task/provider/schools", params);
       
      // IMPORT PROVIDER'S COURSES FROM EACH SCHOOL
            /*PageManager<School> paginator = new PageManager<School>();
          long total = schoolService.countSchoolsByProvider(providerId);
          paginator.setOffset(RANGE);
          paginator.setStart(0);
          paginator.setSize(total);
          ArrayList<School> fails = new ArrayList<School>();
          for (Integer page : paginator.getTotalPagesIterator()) {
                int start = (page - 1) * RANGE;
                int end = (page) * RANGE;
                Collection<Long> schoolsIds =
                /*Collection<School> schools = schoolService.getSchoolsByProvider(providerId,
                                "updated", null, start, end);
                for(School school : schools) {
                  try {
                    providerImporter.createLoadTask(provider, school, dump);
                  } catch(Exception e) {
                    LOGGER.warning("Error with school: " + school.getName());
                    LOGGER.warning(StackTraceUtil.getStackTrace(e));
                    fails.add(school);
                  }
                }
          }
         
          // Retries
          for(School school : fails) {
            providerImporter.createLoadTask(provider, school, dump);
          } */
         
          // Set result into report
        report.setResult("OK");
       
        } catch(Exception e) {
                report.setResult(new StringBuffer("ERROR: ").append(e.getMessage()).toString());
                throw e;
        } finally {
          if("true".equals(register)) {
            cronTaskReportService.save(report);
          }
View Full Code Here

  @Override
  public CronTaskReport getLastCronTaskReport(TYPE type) throws Exception {
    Collection<CronTaskReport> reports = this.DAO.findEntitiesByRange(CronTaskReport.class, "type == typeParam", "java.lang.String typeParam", new Object[]{type.getValue()}"date desc", 0, 1);
    if(reports != null && !reports.isEmpty()) return (CronTaskReport) reports.toArray()[0];
    return new CronTaskReport();
 
View Full Code Here

    LOGGER.info("Updating school with id: " + schoolId);
   
    Provider provider = null;
      School school = null;
    Dump dump = null;
    CronTaskReport report = null;
   
    try {
      school = schoolService.getSchool(schoolId, null);
      LOGGER.info("School name: " + school.getName());
      provider = providerService.getProviderById(school.getProvider(), null);
      //school = schoolService.getSchool(schoolId, null);
      dump = dumpService.getLastDumpByOwner(school.getProvider());
     
      report = cronTaskReportService.create();
            report.setObject_id(school.getProvider());
            report.setDate(new Date());
            report.setType(CronTaskReport.TYPE.PROVIDER_SCHOOLS);
      report.setDescription(new StringBuffer("School: ").append(provider.getName()).toString());
      int retries = 1;
      boolean errors = false;
      StringBuffer errorsSb = new StringBuffer();
      while(retries > 0) {
          try {
           providerImporter.importCourses(provider, school, dump);
           retries = -1; // Break the loop
           } catch(Exception e) {
             LOGGER.severe(StackTraceUtil.getStackTrace(e));
             LOGGER.info("" + retries + " Fail importing courses: "+school.getName() );
             retries--;
             if(!(retries > 0)) {
               errors = true;
               errorsSb.append(school.getName()).append(" -> ").append(e.getCause()).append("\n");
               LOGGER.severe(StackTraceUtil.getStackTrace(e));
             }
           }
      }     
     
      // Set result into report
      if(errors) {
        report.setResult("NO OK" + errorsSb.toString());
      } else {
        report.setResult("OK");
      }
    } catch(Exception e) {
      LOGGER.severe(StackTraceUtil.getStackTrace(e));
      report.setResult(new StringBuffer("ERROR: ").append(e.getMessage()).toString());
      throw e;
    }
       
    }
View Full Code Here

   */
  @RequestMapping(value="/internalFeeds/mediation", method=RequestMethod.POST)
  public String generateInternalFeedsByMediationId(@RequestParam(required=true) Long mediationId,
      @RequestHeader("host") String host, HttpServletRequest request) throws Exception {
    // Create a new CronTaskReport
    CronTaskReport report = cronTaskReportService.create();
    report.setObject_id(mediationId);
    report.setDate(new Date());
    report.setType(CronTaskReport.TYPE.INTERNAL_FEED);
    try {
      // Start the process   
      Provider provider =  providerService.getProviderByMediationService(mediationId, null);   
      MediationService mediationService = mediatorService.getMediationService(mediationId, null);
      //Set report description
      report.setDescription(new StringBuffer("Servicio de mediación: ").append(mediationService.getName()).toString());
     
      if(!mediationService.getHasFeed()) { // All must be manual mediator, but it's another check.
        FeedSchools feedSchools = internalFeedService.createFeedSchools(host, provider, mediationService);
        internalFeedService.saveFeedSchools(feedSchools);
        HashMap<Long, ExtendedSchool> schools = new HashMap<Long, ExtendedSchool>();
        Collection<ExtendedCourse> courses =
          extendedCourseService.getCoursesByOwner(mediationService.getId(), null, null);
        for(ExtendedCourse course : courses) {
          ExtendedSchool school = extendedSchoolService.getSchool(course.getSchool(), Locale.getDefault());
          if(school != null) schools.put(school.getId(), school);
        }
        for(ExtendedSchool school : schools.values()) {
          FeedCourses feedCourse = internalFeedService.createFeedCourses(host,
              provider, mediationService, school, this.getAvailableLanguages());  
          internalFeedService.saveFeedCourses(feedCourse);
        }
        // Set result into report
        report.setResult("OK");
      }
     
    } catch (Exception e) {
      LOGGER.log(Level.SEVERE, StackTraceUtil.getStackTrace(e));
      report.setResult(new StringBuffer("ERROR: ").append(e.getMessage()).toString());
      throw e;
    } finally {
      cronTaskReportService.save(report);
    }
    return "task.launched";
View Full Code Here

   * Cron task to update provider's information that has external Feed, using a round-robin method. It invokes a backend task to do it.
   */
  @RequestMapping(value="/update/provider", method=RequestMethod.GET)
  @ResponseStatus(HttpStatus.OK)
  public void updateManualProviderInformation(@RequestParam(required=false) Long providerId) throws Exception {
    CronTaskReport report = null;
    boolean register = true;
   
    try {
      report = this.serviceLocator.getCronTaskReportService().getLastCronTaskReport(CronTaskReport.TYPE.PROVIDER_FEED);
    } catch(Exception e) {
      LOGGER.severe(new StringBuffer("No se ha podido recuperara el " +
          "ultimo CronTaskReport").append(StackTraceUtil.getStackTrace(e)).toString());     
    }
    try {
      Long id = null;
   
      if(providerId == null) {
        List<Long> manualMediation = this.serviceLocator.getMediatorService().getAllMediationServiceIds(Boolean.TRUE);
        List<Long> ids = this.serviceLocator.getProviderService().getProviderIdsByMediations(manualMediation);
        StringBuffer idsSb = new StringBuffer();
        // Start log info
        for(Long idTest : manualMediation) {
          idsSb.append("[").append(idTest).append("] ");
        }
        LOGGER.info("Los ids de los mediadores son: " + idsSb.toString());
       
        idsSb = new StringBuffer();
        for(Long idTest : ids) {
          idsSb.append("[").append(idTest).append("] ");
        }
        LOGGER.info("Los ids de los providers son: " + idsSb.toString());
        // End log info
        if(ids != null && ids.size() > 0) {
          id = this.getNextIdCronTaskReport(report != null ? report.getObject_id() : null, ids);
        }
      } else {
        register = false;
        id = providerId;
      }
View Full Code Here

TOP

Related Classes of com.m4f.business.domain.CronTaskReport

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.