Package com.m4f.business.domain.extended

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


    this.courseService = courseService;
  }

  @Override
  public FeedSchools createFeedSchools(String contextPath, Provider provider, MediationService mediationService) throws Exception {
    FeedSchools feed = (FeedSchools) this.DAO.createInstance(FeedSchools.class);
   
    // TODO Get configuration object a load different languages
    ArrayList<Locale> locales = new ArrayList<Locale>();
    // TODO hard-coded languages
    locales.add(new Locale("es"));
    locales.add(new Locale("eu"));
   
    // Starting xml generation
    Element root = new Element(SCHOOL_ROOT);
    root.setAttribute(new Attribute("noNamespaceSchemaLocation","http://hirubila.appspot.com/schema/zentroak-1.0.xsd",
        Namespace.getNamespace("xsi","http://www.w3.org/1999/XMLSchema-instance")));
   
    // NEW PART Get all schools. To do it, first we've to get all courses by mediationService and then get for each course its school.
    HashMap<Long, ExtendedSchool> schools = new HashMap<Long, ExtendedSchool>();
    Locale locale = locales.get(0);
    //Provider provider = this.providerService.getProviderById(providerId, locale);
    //MediationService mediation = this.mediationService.getMediationService(provider.getMediationService(), locale);
    Collection<ExtendedCourse> courses = this.courseService.getCoursesByOwner(mediationService.getId(), null, locale);
    for(ExtendedCourse course : courses) {
      ExtendedSchool school = this.schoolService.getSchool(course.getSchool(), locale);
      if(school != null) schools.put(school.getId(), school);
    }
   
    for(ExtendedSchool school : schools.values()) {
      Element schoolNode = new Element(SCHOOL_ELEMENT);
      for(String attr : SCHOOL_ATTRS) {
        Element attrNode = new Element(attr);
        if(SCHOOL_ATTR_ID.equals(attr)) {
          //attrNode.setContent(school.getId() != null ? this.createCData(school.getId().toString()) : "");
          attrNode.setContent(mediationService.getId() != null && school.getId() != null ? new CDATA(new StringBuffer(String.valueOf(mediationService.getId())).append("-").append(String.valueOf(school.getId())).toString()) : new CDATA(""));
        } else if(SCHOOL_ATTR_NAME.equals(attr)) {
          attrNode.setContent(school.getName() != null ? new CDATA(school.getName()) : new CDATA(""));
        } else if(SCHOOL_ATTR_PHONE.equals(attr)) {
          attrNode.addContent(school.getContactInfo() != null && school.getContactInfo().getTelephone() != null ?
              new CDATA(school.getContactInfo().getTelephone()) : new CDATA(""));
        } else if(SCHOOL_ATTR_FAX.equals(attr)) {
          attrNode.addContent(school.getContactInfo() != null &&school.getContactInfo().getFax() != null ?
              new CDATA(school.getContactInfo().getFax()) : new CDATA(""));
        } else if(SCHOOL_ATTR_MAIL.equals(attr)) {
          attrNode.addContent(school.getContactInfo() != null && school.getContactInfo().getEmail() != null ?
              new CDATA(school.getContactInfo().getEmail()) : new CDATA(""));
        } else if(SCHOOL_ATTR_ADDR.equals(attr)) {
          attrNode.addContent(school.getContactInfo() != null && school.getContactInfo().getStreetAddress() != null ?
              new CDATA(school.getContactInfo().getStreetAddress()) : new CDATA(""));
        } else if(SCHOOL_ATTR_PK.equals(attr)) {
          attrNode.addContent(school.getContactInfo() != null && school.getContactInfo().getZipCode() != null ?
              new CDATA(school.getContactInfo().getZipCode()) : new CDATA(""));
        } else if(SCHOOL_ATTR_WEB.equals(attr)) {
          attrNode.addContent(school.getContactInfo() != null && school.getContactInfo().getWebSite() != null ?
              new CDATA(school.getContactInfo().getWebSite()) : new CDATA(""));
        } else if(SCHOOL_ATTR_CITY.equals(attr)) {
          attrNode.addContent(school.getContactInfo() != null && school.getContactInfo().getCity() != null ?
              new CDATA(school.getContactInfo().getCity()) : new CDATA(""));
        } else if(SCHOOL_ATTR_FEED.equals(attr)) {         
          StringBuffer sb = new StringBuffer(contextPath).append("/").append(locale).append(COURSES_FEED).append(provider.getId()).append("/").append(school.getId());
          attrNode.addContent(new CDATA(sb.toString()));
        }
        schoolNode.addContent(attrNode);
      }
     
      root.addContent(schoolNode);
    }
    Document document = new Document(root);
      XMLOutputter outputter = new XMLOutputter();   
      String content = outputter.outputString(document);
      feed.setContent(new Blob(content.getBytes("UTF-8")));
      feed.setDate(new Date());
      feed.setProviderId(provider.getId());
    return feed;
  }
View Full Code Here


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

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

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

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

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

   */
  @RequestMapping(value="/public/school/feed/{providerId}", method=RequestMethod.GET)
  public void getSchoolFeed(@PathVariable Long providerId,
      HttpServletResponse response, Locale locale, Model model) {
    try {
      FeedSchools feed = this.serviceLocator.getInternalFeedService().getLastFeedSchools(providerId);
      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

Related Classes of com.m4f.business.domain.extended.FeedSchools

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.