Examples of FeedCourses


Examples of com.m4f.business.domain.extended.FeedCourses

  @Override
  public FeedCourses createFeedCourses(String contextPath, Provider provider,
      MediationService mediationService, ExtendedSchool school, Collection<Locale> locales) throws Exception {
       
    FeedCourses feed = (FeedCourses) this.DAO.createInstance(FeedCourses.class);
   
    // Starting xml generation
    Element root = new Element(COURSE_ROOT);
    root.setAttribute(new Attribute("noNamespaceSchemaLocation","http://hirubila.appspot.com/schema/kurtsoak-1.0.xsd",
        Namespace.getNamespace("xsi","http://www.w3.org/1999/XMLSchema-instance")));

    Collection<ExtendedCourse> courses = this.courseService.getCoursesBySchoolByMediation(school.getId(),
        mediationService.getId(), "title", null);

   
    // DATE format
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
   
    for(ExtendedCourse course : courses) {
      // Make a map with languages and course with this language
      HashMap<String, ExtendedCourse> i18nCourse = new HashMap<String, ExtendedCourse>();

     
      for(Locale locale : locales) {
        i18nCourse.put(locale.getLanguage(), this.courseService.getCourse(course.getId(), locale));
      }
     
      // Make course node element with i18n properties
      Element courseNode = new Element(COURSE_ELEMENT);
      for(String attr : COURSE_ATTRS) {
        if(COURSE_ATTR_ID.equals(attr)) {
          courseNode.setContent(new Element(attr).addContent(mediationService.getId() != null && course.getId() != null ? new CDATA(new StringBuffer(String.valueOf(mediationService.getId())).append("-").append(String.valueOf(course.getId())).toString()) : new CDATA("")));
        } else if(COURSE_ATTR_NAME.equals(attr)) { // I18nProperty
          Iterator<String> it = i18nCourse.keySet().iterator();
          while(it.hasNext()) {
            String language = it.next();
            String i18nAttr = new StringBuffer(attr).append(language).toString();
            ExtendedCourse c = i18nCourse.get(language);
            courseNode.addContent(new Element(i18nAttr).setContent(c.getTitle() != null ? new CDATA(c.getTitle()) : new CDATA("")));
          }
        } else if(COURSE_ATTR_URL.equals(attr)) { // I18nProperty // TODO may be better a function...
          Iterator<String> it = i18nCourse.keySet().iterator();
          while(it.hasNext()) {
            String language = it.next();
            String i18nAttr = new StringBuffer(attr).append(language).toString();
            ExtendedCourse c = i18nCourse.get(language);
            String url = new StringBuffer(contextPath).append("/").append(language).append(COURSE_DETAIL_URL).append(course.getId()).toString();
            courseNode.addContent(new Element(i18nAttr).setContent(new CDATA(url)));
          }
        } else if(COURSE_ATTR_START.equals(attr)) {
          courseNode.addContent(new Element(attr).setContent(course.getStart() != null ? new CDATA(dateFormat.format(course.getStart())) : new CDATA("")));
        } else if(COURSE_ATTR_END.equals(attr)) {
          courseNode.addContent(new Element(attr).setContent(course.getEnd() != null ? new CDATA(dateFormat.format(course.getEnd())) : new CDATA("")));
        } else if(COURSE_ATTR_INFO.equals(attr)) { // I18nProperty // TODO may be better a function...
          Iterator<String> it = i18nCourse.keySet().iterator();
          while(it.hasNext()) {
            String language = it.next();
            String i18nAttr = new StringBuffer(attr).append(language).toString();
            ExtendedCourse c = i18nCourse.get(language);
            courseNode.addContent(new Element(i18nAttr).setContent(c.getInformation() != null ? new CDATA(c.getInformation().getValue()) : new CDATA("")));
          }
        } else if(COURSE_ATTR_GAIAK.equals(attr)) {
          Element tagsNode = new Element(attr);
          for(Category category : course.getTags()) {
            Element tagNode = new Element(COURSE_ATTR_GAIA);
            for(String gaiaAttr : GAIA_ATTRS) {
              Element tagAttrNode = new Element(gaiaAttr);
              if(GAIA_ATTR_ID.equals(gaiaAttr)) {
                tagAttrNode.setText("");
              } else if(GAIA_ATTR_NAME.equals(gaiaAttr)) {
                tagAttrNode.setContent(new CDATA(category.getCategory()));
              }
              tagNode.addContent(tagAttrNode);
            }
            tagsNode.addContent(tagNode);
          }
          courseNode.addContent(tagsNode);
        }
      }
      root.addContent(courseNode);
    }
   
    Document document = new Document(root);
      XMLOutputter outputter = new XMLOutputter();   
      String content = outputter.outputString(document);
      feed.setContent(new Blob(content.getBytes("UTF-8")));
      feed.setSchool(school.getId());
      feed.setDate(new Date());
      feed.setProviderId(provider.getId());
     
    return feed;
  }
View Full Code Here

Examples of com.m4f.business.domain.extended.FeedCourses

  public FeedCourses getLastFeedCourses(Long providerId, Long extendedSchoolId)
      throws Exception {
    Collection<FeedCourses> feed = this.DAO.findEntitiesByRange(FeedCourses.class, "providerId == providerIdParam && school == idParam", "java.lang.Long providerIdParam, java.lang.Long idParam", new Object[]{providerId, extendedSchoolId}"date desc", 0, 1);
    //Collection<FeedCourses> feed = this.DAO.findEntitiesByRange(FeedCourses.class, "date desc", 0, 1);
    if(feed != null && !feed.isEmpty()) return (FeedCourses) feed.toArray()[0];
    return new FeedCourses();
  }
View Full Code Here

Examples of com.m4f.business.domain.extended.FeedCourses

        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");
View Full Code Here

Examples of com.m4f.business.domain.extended.FeedCourses

        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");
View Full Code Here

Examples of com.m4f.business.domain.extended.FeedCourses

      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) {
View Full Code Here

Examples of com.m4f.business.domain.extended.FeedCourses

        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");
View Full Code Here

Examples of com.m4f.business.domain.extended.FeedCourses

  @RequestMapping(value="/public/course/feed/{providerId}/{schoolId}", method=RequestMethod.GET)
  public void getCoursesFeed(@PathVariable Long providerId,
      @PathVariable Long schoolId, HttpServletResponse response,
      Locale locale, Model model) {
    try {
      FeedCourses feed = this.serviceLocator.getInternalFeedService().getLastFeedCourses(providerId, schoolId);
      byte[] content = feed != null && feed.getContent() != null? feed.getContent().getBytes() : null;
      response.setContentType("text/xml");
      response.setCharacterEncoding("UTF-8");
      if(content != null) {
        response.setContentLength(content.length);
        response.getOutputStream().write(content);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.