Exemple #1
0
  private Set<OrganizacionEvento> buscarEventos(Element eventsEl, Organizacion organizacion) {
    if (eventsEl == null) return null;

    Set<OrganizacionEvento> ret = new HashSet<OrganizacionEvento>();

    NodeList nodeLst = eventsEl.getElementsByTagName("event");

    for (int s = 0; s < nodeLst.getLength(); s++) {
      Node fstNode = nodeLst.item(s);
      if (fstNode.getNodeType() == Node.ELEMENT_NODE) {
        Element elEvento = (Element) fstNode;

        String localization = XmlParserUtil.getStringNodeValue(elEvento, "localization");
        String title = XmlParserUtil.getStringNodeValue(elEvento, "title");
        String description = XmlParserUtil.getStringNodeValue(elEvento, "description");
        String date = XmlParserUtil.getStringNodeValue(elEvento, "date");

        Date fecha = null;
        try {
          fecha = formatter.parse(date);
        } catch (ParseException e) {
        }

        Evento evento = null;

        if (organizacion.getEventos() != null) {
          for (OrganizacionEvento oe : organizacion.getEventos()) {
            Evento e = oe.getEvento();
            if (e.getTitulo().equals(title)) {
              evento = e;
              break;
            }
          }
        }
        if (evento == null) {
          evento = new Evento();

          evento.setLocalizacion(localization);
          evento.setTitulo(title);
          evento.setDescripcion(description);
          evento.setFecha(fecha);
          try {
            organizacionService.saveEvento(evento);

            OrganizacionEvento eventoOrg = new OrganizacionEvento();
            eventoOrg.setEvento(evento);
            eventoOrg.setOrganizacion(organizacion);
            ret.add(eventoOrg);
          } catch (ServiceException e) {
            logger.error(e.getMessage());
          }
        }
      }
    }
    return ret;
  }
Exemple #2
0
  private Set<OrganizacionCapacidadOferta> buscarOfertas(
      Element capacitiesEl, Organizacion organizacion) {
    if (capacitiesEl == null) return null;

    Set<OrganizacionCapacidadOferta> ret = new HashSet<OrganizacionCapacidadOferta>();
    NodeList nodeLst = capacitiesEl.getElementsByTagName("capacity");

    for (int s = 0; s < nodeLst.getLength(); s++) {
      Node fstNode = nodeLst.item(s);
      if (fstNode.getNodeType() == Node.ELEMENT_NODE) {
        Element elCapacity = (Element) fstNode;

        String capacityCode = XmlParserUtil.getAttribute(elCapacity, "capacity_code");
        String sectorCode = XmlParserUtil.getAttribute(elCapacity, "sector_code");
        String resources = XmlParserUtil.getAttribute(elCapacity, "resources");
        String score = XmlParserUtil.getAttribute(elCapacity, "score");
        String billingProportion = XmlParserUtil.getAttribute(elCapacity, "billingProportion");
        String description = XmlParserUtil.getAttribute(elCapacity, "description");

        Capacidad capacidad = buscarCapacidad(Integer.parseInt(capacityCode));
        Sector sector = buscarSector(Integer.parseInt(sectorCode));

        OrganizacionCapacidadOferta oferta = null;

        if (organizacion.getOfertas() != null) {
          for (OrganizacionCapacidadOferta o : organizacion.getOfertas()) {
            if (o.getSector().equals(sector) && o.getCapacidad().equals(capacidad)) {
              oferta = o;
              break;
            }
          }
        }

        if (oferta == null) {
          oferta = new OrganizacionCapacidadOferta();
          oferta.setOrganizacion(organizacion);
          oferta.setCapacidad(capacidad);
          oferta.setSector(sector);
        }
        oferta.setRecursos(Integer.parseInt(resources));
        oferta.setPuntuacion(Integer.parseInt(score));
        oferta.setPorcentajeFacturacion(Integer.parseInt(billingProportion));
        oferta.setDescripcion(description);

        ret.add(oferta);
      }
    }

    return ret;
  }
Exemple #3
0
  private Set<OrganizacionCapacidadDemanda> buscarDemandas(
      Element demandsEl, Organizacion organizacion) {
    Set<OrganizacionCapacidadDemanda> ret = new HashSet<OrganizacionCapacidadDemanda>();

    NodeList nodeLst = demandsEl.getElementsByTagName("demand");

    for (int s = 0; s < nodeLst.getLength(); s++) {
      Node fstNode = nodeLst.item(s);
      if (fstNode.getNodeType() == Node.ELEMENT_NODE) {
        Element elDemand = (Element) fstNode;

        String capacityCode = XmlParserUtil.getAttribute(elDemand, "capacity_code");
        String sectorCode = XmlParserUtil.getAttribute(elDemand, "sector_code");
        String description = XmlParserUtil.getAttribute(elDemand, "description");

        Sector sector = buscarSector(Integer.parseInt(sectorCode));
        Capacidad capacidad = buscarCapacidad(Integer.parseInt(capacityCode));

        if (capacidad != null) {
          OrganizacionCapacidadDemanda demanda = null;

          if (organizacion.getDemandas() != null) {
            for (OrganizacionCapacidadDemanda d : organizacion.getDemandas()) {
              if (d.getSector().equals(sector) && d.getCapacidad().equals(capacidad)) {
                demanda = d;
                break;
              }
            }
          }

          if (demanda == null) {
            demanda = new OrganizacionCapacidadDemanda();
            demanda.setOrganizacion(organizacion);
            demanda.setCapacidad(capacidad);
            demanda.setSector(sector);
          }
          demanda.setDescripcion(description);

          ret.add(demanda);
        } else {
          if (logger.isTraceEnabled()) {
            logger.trace("No se ha agregado la Demanda con código de capacidad: " + capacityCode);
          }
        }
      }
    }

    return ret;
  }
Exemple #4
0
  private Set<OrganizacionAsociacion> buscarAsociaciones(
      Element associationsEl, Organizacion organizacion) {
    if (associationsEl == null) return null;
    Set<OrganizacionAsociacion> ret = new HashSet<OrganizacionAsociacion>();

    NodeList nodeLst = associationsEl.getElementsByTagName("associationMembership");

    for (int s = 0; s < nodeLst.getLength(); s++) {
      Node fstNode = nodeLst.item(s);
      if (fstNode.getNodeType() == Node.ELEMENT_NODE) {
        Element elDemand = (Element) fstNode;

        String code = XmlParserUtil.getAttribute(elDemand, "code");
        String url = XmlParserUtil.getAttribute(elDemand, "url");
        String icon = XmlParserUtil.getAttribute(elDemand, "icon");

        Asociacion asoc = buscarAsociacion(Integer.parseInt(code));
        boolean found = false;
        if (organizacion.getOrganizacionAsociacions() != null) {
          for (OrganizacionAsociacion orgAsoc : organizacion.getOrganizacionAsociacions()) {
            if (orgAsoc.getAsociacion().getName().equalsIgnoreCase(asoc.getName())) {
              found = true;
              break;
            }
          }
        }
        if (!found) {
          asoc.setUrl(url);
          asoc.setIcon(icon);
          try {
            asociacionService.save(asoc);
            OrganizacionAsociacion asociacion = new OrganizacionAsociacion();
            asociacion.setOrganizacion(organizacion);
            asociacion.setAsociacion(asoc);
            ret.add(asociacion);
          } catch (ServiceException e) {
            logger.error(e.getMessage());
          }
        }
      }
    }

    return ret;
  }
Exemple #5
0
  private Organizacion parseOrganizacion(String xmlString)
      throws ParserConfigurationException, SAXException, IOException, ServiceException {
    Document doc = XmlParserUtil.createDocumentFromString(xmlString);

    Organizacion ret = null;

    NodeList nodeLst = doc.getElementsByTagName(ORGANIZATION_TAG);
    for (int s = 0; s < nodeLst.getLength(); s++) {
      Node fstNode = nodeLst.item(s);
      if (fstNode.getNodeType() == Node.ELEMENT_NODE) {
        Element elOrg = (Element) fstNode;

        String legalId = XmlParserUtil.getStringNodeValue(elOrg, "legalID");
        if (!legalId.isEmpty()) {
          ret = organizacionService.findByCIF(legalId);
          if (ret == null) {
            if (logger.isTraceEnabled()) ;
            logger.trace("Organizacion con CIF: " + legalId + " no encontrada, AGREGANDO");
            ret = new Organizacion();
          } else {
            if (logger.isTraceEnabled()) ;
            logger.trace("Organizacion con CIF: " + legalId + " encontrada, ACTUALIZANDO");
          }

          String name = XmlParserUtil.getStringNodeValue(elOrg, "name");
          String description = XmlParserUtil.getStringNodeValue(elOrg, "description");
          String web = XmlParserUtil.getStringNodeValue(elOrg, "web");
          String logoUrl = XmlParserUtil.getStringNodeValue(elOrg, "logo_url");
          String direccion = XmlParserUtil.getStringNodeValue(elOrg, "HQstreet");
          String localidad = XmlParserUtil.getStringNodeValue(elOrg, "HQlocality");

          String newsTitle = XmlParserUtil.getStringNodeValue(elOrg, "newsTitle");
          String newsBody = XmlParserUtil.getStringNodeValue(elOrg, "newsBody");

          Element provEl = XmlParserUtil.getChildren(elOrg, "HQprovince");
          String provId = XmlParserUtil.getAttribute(provEl, "code");
          String provincia = XmlParserUtil.getStringNodeValue(elOrg, "HQprovince");
          String codPostal = XmlParserUtil.getStringNodeValue(elOrg, "HQpostalCode");
          String year = XmlParserUtil.getStringNodeValue(elOrg, "year");

          String partners = XmlParserUtil.getStringNodeValue(elOrg, "partners");
          String corpGroup = XmlParserUtil.getStringNodeValue(elOrg, "enpresarialGroup");
          String phoneNumber = XmlParserUtil.getStringNodeValue(elOrg, "telephone");
          String email = XmlParserUtil.getStringNodeValue(elOrg, "email");
          String research =
              XmlParserUtil.getStringNodeValue(elOrg, "researchAndDevelopmentProgrammes");
          String relacionesComunidad =
              XmlParserUtil.getStringNodeValue(elOrg, "communityRelationships");
          String qualityCertifications =
              XmlParserUtil.getStringNodeValue(elOrg, "qualityCertifications");

          Element orgClassEl = XmlParserUtil.getChildren(elOrg, "organizationClasification");
          String orgClassCode = XmlParserUtil.getAttribute(orgClassEl, "code");
          String organizationClasification =
              XmlParserUtil.getStringNodeValue(elOrg, "organizationClasification");

          Element orgTypeEl = XmlParserUtil.getChildren(elOrg, "organizationType");
          String orgTypeCode = XmlParserUtil.getAttribute(orgTypeEl, "code");
          String organizationType = XmlParserUtil.getStringNodeValue(elOrg, "organizationType");

          Element degationsEl = XmlParserUtil.getChildren(elOrg, "delegations");
          Element capacitiesEl = XmlParserUtil.getChildren(elOrg, "capacities");
          Element demandsEl = XmlParserUtil.getChildren(elOrg, "demands");
          Element eventsEl = XmlParserUtil.getChildren(elOrg, "events");
          // Association Memberships
          Element associationsEl = XmlParserUtil.getChildren(elOrg, "associationMemberships");
          // username
          String username = XmlParserUtil.getStringNodeValue(elOrg, "username");
          // password
          String password = XmlParserUtil.getStringNodeValue(elOrg, "password");

          ret.setCif(legalId);
          ret.setName(name);
          ret.setDescripcion(description);
          ret.setNewsTitle(newsTitle);
          ret.setNewsBody(newsBody);
          ret.setWeb(web);
          ret.setLogoUrl(logoUrl);
          ret.setDireccion(direccion);
          ret.setLocalidad(localidad);
          ret.setProvincia(findProvincia(provId, provincia));
          ret.setCodigoPostal(Integer.parseInt(codPostal));
          try {
            if (year != null && !year.isEmpty()) ret.setAnoConstitucion(Integer.parseInt(year));
          } catch (NumberFormatException e) {
          }
          ret.setPartners(partners);
          ret.setGrupoEmpresarial(corpGroup);
          ret.setTelefono(phoneNumber);
          ret.setEmail(email);
          ret.setActividadesImasD(!research.isEmpty());
          ret.setParticipacionImasD(research);
          ret.setRelacionesComunidad(relacionesComunidad);
          ret.setCertificacionesCalidad(Organizacion.decoded(qualityCertifications));

          if (orgClassEl != null && StringUtils.hasLength(orgClassCode)) {
            ret.setClasificacionOrganizacion(
                findClasificacionOrganizacion(orgClassCode, organizationClasification));
          }
          if (orgTypeEl != null && StringUtils.hasLength(orgTypeCode)) {
            ret.setFormaJuridica(findFormaJuridica(orgTypeCode, organizationType));
          }
          if (degationsEl != null) {
            Set<OrganizacionSede> sedes = buscarSedes(degationsEl, ret);
            if (ret.getSedes() == null) {
              ret.setSedes(sedes);
            } else {
              ret.getSedes().addAll(sedes);
            }
          }
          if (capacitiesEl != null) {
            Set<OrganizacionCapacidadOferta> ofertas = buscarOfertas(capacitiesEl, ret);
            if (ret.getOfertas() == null) {
              ret.setOfertas(ofertas);
            } else {
              ret.getOfertas().addAll(ofertas);
            }
          }
          if (demandsEl != null) {
            Set<OrganizacionCapacidadDemanda> demandas = buscarDemandas(demandsEl, ret);
            if (ret.getDemandas() == null) {
              ret.setDemandas(demandas);
            } else {
              ret.getDemandas().addAll(demandas);
            }
          }
          if (associationsEl != null) {
            Set<OrganizacionAsociacion> organizacionAsociacions =
                buscarAsociaciones(associationsEl, ret);
            if (ret.getOrganizacionAsociacions() == null) {
              ret.setOrganizacionAsociacions(organizacionAsociacions);
            } else {
              ret.getOrganizacionAsociacions().addAll(organizacionAsociacions);
            }
          }
          if (eventsEl != null) {
            Set<OrganizacionEvento> eventos = buscarEventos(eventsEl, ret);
            if (ret.getEventos() == null) {
              ret.setEventos(eventos);
            } else {
              ret.getEventos().addAll(eventos);
            }
          }

          ret.setUsername(username);
          ret.setPassword(password);
        }
      }
    }

    return ret;
  }
Exemple #6
0
  private void buscarOrganizacion(String token) {
    Organizacion organizacion = null;
    if (logger.isDebugEnabled()) logger.debug("Buscando Organizaciones para Satelite: " + satelite);

    HttpClient httpclient = getHttpClient();

    GetMethod get = new GetMethod(restUrl.getOrganizacionUrl());
    get.addRequestHeader("Accept", "application/xml");
    NameValuePair tokenParam = new NameValuePair("token", token);
    int id = 0;
    //		if(satelite.getLastOrgId() != null)
    //			id = satelite.getLastOrgId();

    int leap = idLeap;

    while (true) {
      id = id + 1;

      if (logger.isTraceEnabled()) {
        logger.trace("Buscando Organizacion con id: " + id + " en el Satelite: " + satelite);
      }

      NameValuePair passwordParam = new NameValuePair("id", String.valueOf(id));
      NameValuePair[] params = new NameValuePair[] {tokenParam, passwordParam};

      get.setQueryString(params);
      String queryString = get.getQueryString();

      int statusCode;
      try {
        if (logger.isTraceEnabled()) {
          logger.trace("Query String: " + queryString);
        }

        statusCode = httpclient.executeMethod(get);
        if (statusCode != HttpStatus.SC_OK) {
          logger.error("Method failed: " + get.getStatusLine());
        } else {
          String xmlString = get.getResponseBodyAsString();
          if (logger.isInfoEnabled()) {
            logger.info("Xml Received.");
          }

          String xmlHash = constructXmlHash(xmlString);

          organizacion = organizacionService.findByHash(xmlHash);
          if (organizacion == null) {
            organizacion = parseOrganizacion(xmlString);
            if (organizacion == null) {
              leap--;
              if (leap <= 0) {
                logger.info(
                    "Se llegó al fin de las Organizaciones. Saliendo del Satelite: " + satelite);
                break;
              } else {
                logger.info("Leap: " + leap);
              }
            } else {
              if (organizacion.getSatelites() == null) {
                organizacion.setSatelites(new HashSet<OrganizacionSatelite>());
              }
              boolean sateliteFound = false;
              for (OrganizacionSatelite sat : organizacion.getSatelites()) {
                if (sat.getSatelite().getName().equals(satelite.getName())) {
                  sateliteFound = true;
                  break;
                }
              }
              if (!sateliteFound) {
                OrganizacionSatelite newSat = new OrganizacionSatelite();
                newSat.setSatelite(satelite);
                newSat.setOrganizacion(organizacion);
                organizacion.getSatelites().add(newSat);
              }

              organizacion.setXmlHash(xmlHash);
              organizacionService.saveOrganization(organizacion);

              int numEmpresas = 0;
              if (satelite.getNumEmpresas() != null) {
                numEmpresas = satelite.getNumEmpresas();
              }
              numEmpresas++;

              Date now = new Date();
              satelite.setNumEmpresas(numEmpresas);
              satelite.setLastRetrieval(new Timestamp(now.getTime()));
              satelite.setLastOrgId(id);
              sateliteService.saveSatelite(satelite);
            }
          } else {
            if (logger.isInfoEnabled()) {
              logger.info("Organizacion with id: " + id + " already in centraldir");
            }
          }
        }
      } catch (HttpException e) {
        logger.error(e.getMessage());
      } catch (IOException e) {
        logger.error(e.getMessage());
      } catch (ParserConfigurationException e) {
        logger.error(e.getMessage());
      } catch (SAXException e) {
        logger.error(e.getMessage());
      } catch (ServiceException e) {
        logger.error(e.getMessage());
      } catch (NoSuchAlgorithmException e) {
        logger.error(e.getMessage());
      } finally {
        get.releaseConnection();
      }
    }
  }