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 Provincia findProvincia(String provId, String provincia) {
    if (!StringUtils.hasLength(provId)) return null;

    try {
      return provinciaService.findProvincia(satelite, provincia, Integer.parseInt(provId));
    } catch (NumberFormatException e) {
      logger.error(e.getMessage());
    } catch (ServiceException e) {
      logger.error(e.getMessage());
    }
    return null;
  }
Exemple #3
0
  private Capacidad importCapacidad(String xmlString, Integer capacityId)
      throws ParserConfigurationException, SAXException, IOException {
    Document doc = XmlParserUtil.createDocumentFromString(xmlString);
    Capacidad ret = null;
    NodeList nodeLst = doc.getElementsByTagName("capacity");

    for (int s = 0; s < nodeLst.getLength(); s++) {
      Node fstNode = nodeLst.item(s);
      if (fstNode.getNodeType() == Node.ELEMENT_NODE) {
        Element elPDU = (Element) fstNode;
        String code = XmlParserUtil.getAttribute(elPDU, "code");
        String category = XmlParserUtil.getAttribute(elPDU, "category");
        NodeList fstNm = elPDU.getChildNodes();
        String capacidadName = null;

        if (fstNm.getLength() > 0) {
          capacidadName = ((Node) fstNm.item(0)).getNodeValue();

          Integer capId = getId(code);
          Capacidad capacidad = null;
          try {
            List<Capacidad> capacidades = organizacionService.findCapacidadByName(capacidadName);

            if (capacidades != null && capacidades.size() > 0) {
              capacidad = capacidades.get(0);
            } else {
              capacidad = new Capacidad();
              capacidad.setName(capacidadName);
              if (StringUtils.hasLength(category)) capacidad.setCategoria(category);
              organizacionService.saveCapacidad(capacidad);
            }

            if (capId != null && capId.equals(capacityId)) {
              ret = capacidad;
            }
          } catch (ServiceException e) {
            logger.error(e.getMessage());
          }
        }
      }
    }

    if (ret != null) {
      if (logger.isTraceEnabled()) logger.trace("Se devuelve la Capacidad: " + ret);
      return ret;
    }
    if (logger.isTraceEnabled())
      logger.trace("No se ha encontrado la Capacidad con Id: " + capacityId);
    return null;
  }
Exemple #4
0
  private Asociacion importAsociacion(String xmlString, Integer associationCode)
      throws ParserConfigurationException, SAXException, IOException {
    Document doc = XmlParserUtil.createDocumentFromString(xmlString);
    Asociacion ret = null;
    NodeList nodeLst = doc.getElementsByTagName("association");

    for (int s = 0; s < nodeLst.getLength(); s++) {
      Node fstNode = nodeLst.item(s);
      if (fstNode.getNodeType() == Node.ELEMENT_NODE) {
        Element elPDU = (Element) fstNode;
        String code = XmlParserUtil.getAttribute(elPDU, "code");
        String url = XmlParserUtil.getAttribute(elPDU, "url");
        String icon = XmlParserUtil.getAttribute(elPDU, "icon");
        NodeList fstNm = elPDU.getChildNodes();
        String associationName = null;

        if (fstNm.getLength() > 0) {
          associationName = ((Node) fstNm.item(0)).getNodeValue();

          Integer capId = getId(code);
          Asociacion association = null;
          try {
            Collection<Asociacion> associations = asociacionService.findByName(associationName);

            if (associations != null && associations.size() > 0) {
              association = associations.iterator().next();
            } else {
              association = new Asociacion();
              association.setName(associationName);
              association.setUrl(url);
              association.setIcon(icon);
              logger.info(
                  "Saving Asociacion: " + associationName + " url: " + url + " icon " + icon);
              asociacionService.save(association);
            }

            if (capId != null && capId.equals(associationCode)) {
              ret = association;
            }
          } catch (ServiceException e) {
            logger.error(e.getMessage());
          }
        }
      }
    }
    return ret;
  }
Exemple #5
0
  private FormaJuridica findFormaJuridica(String orgTypeCode, String formaJuridica) {
    if (!StringUtils.hasLength(orgTypeCode)) return null;

    Integer id = getId(orgTypeCode);
    FormaJuridica ret = null;
    List<FormaJuridica> l = null;
    try {
      l = formaJuridicaService.findByName(formaJuridica);
    } catch (ServiceException e) {
      logger.error(e.getMessage());
    }
    if (l != null && l.size() > 0) {
      ret = l.get(0);
    } else {
      ret = findRestFormaJuridica(id);
    }
    return ret;
  }
Exemple #6
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 #7
0
  private ClasificacionOrganizacion findClasificacionOrganizacion(
      String orgClassCode, String organizationClasification) {
    if (!StringUtils.hasLength(orgClassCode)) return null;

    Integer id = getId(orgClassCode);
    ClasificacionOrganizacion ret = null;
    List<ClasificacionOrganizacion> l = null;
    try {
      l = organizacionService.findClasificacionOrganizacionByName(organizationClasification);
    } catch (ServiceException e) {
      logger.error(e.getMessage());
    }
    if (l != null && l.size() > 0) {
      ret = l.get(0);
    } else {
      ret = findRestClasificacionOrganizacion(id);
    }
    return ret;
  }
Exemple #8
0
  private Sector importSector(String xmlString, Integer id)
      throws ParserConfigurationException, SAXException, IOException {
    Document doc = XmlParserUtil.createDocumentFromString(xmlString);
    Sector ret = null;
    NodeList nodeLst = doc.getElementsByTagName("sector");

    for (int s = 0; s < nodeLst.getLength(); s++) {
      Node fstNode = nodeLst.item(s);
      if (fstNode.getNodeType() == Node.ELEMENT_NODE) {
        Element elPDU = (Element) fstNode;
        String code = XmlParserUtil.getAttribute(elPDU, "code");
        NodeList fstNm = elPDU.getChildNodes();
        String sectorName = null;

        if (fstNm.getLength() > 0) {
          String tmp = ((Node) fstNm.item(0)).getNodeValue();
          byte[] utf8 = tmp.getBytes("UTF-8");
          sectorName = new String(utf8, "UTF-8");

          Integer capId = getId(code);
          Sector sector = null;
          try {
            Collection<Sector> sectores = sectorService.findByName(sectorName);

            if (sectores != null && sectores.size() > 0) {
              sector = sectores.iterator().next();
            } else {
              sector = new Sector();
              sector.setName(sectorName);
              sectorService.save(sector);
            }

            if (capId != null && capId.equals(id)) {
              ret = sector;
            }
          } catch (ServiceException e) {
            logger.error(e.getMessage());
          }
        }
      }
    }
    return ret;
  }
Exemple #9
0
  private ClasificacionOrganizacion importClasificacionOrganizacion(String xmlString, Integer id)
      throws ParserConfigurationException, SAXException, IOException {
    Document doc = XmlParserUtil.createDocumentFromString(xmlString);
    ClasificacionOrganizacion ret = null;
    NodeList nodeLst = doc.getElementsByTagName("classification");

    for (int s = 0; s < nodeLst.getLength(); s++) {
      Node fstNode = nodeLst.item(s);
      if (fstNode.getNodeType() == Node.ELEMENT_NODE) {
        Element elPDU = (Element) fstNode;
        String code = XmlParserUtil.getAttribute(elPDU, "code");
        NodeList fstNm = elPDU.getChildNodes();
        String classOrg = null;

        if (fstNm.getLength() > 0) {
          classOrg = ((Node) fstNm.item(0)).getNodeValue();

          Integer orgId = getId(code);
          ClasificacionOrganizacion clasificacionOrganizacion = null;
          try {
            List<ClasificacionOrganizacion> lCO =
                organizacionService.findClasificacionOrganizacionByName(classOrg);

            if (lCO != null && lCO.size() > 0) {
              clasificacionOrganizacion = lCO.get(0);
            } else {
              clasificacionOrganizacion = new ClasificacionOrganizacion();
              clasificacionOrganizacion.setName(classOrg);
              organizacionService.saveClasificacionOrganizacion(clasificacionOrganizacion);
            }

            if (orgId != null && orgId.equals(id)) {
              ret = clasificacionOrganizacion;
            }
          } catch (ServiceException e) {
            logger.error(e.getMessage());
          }
        }
      }
    }
    return ret;
  }
Exemple #10
0
  private FormaJuridica importFormaJuridica(String xmlString, Integer id)
      throws ParserConfigurationException, SAXException, IOException {
    Document doc = XmlParserUtil.createDocumentFromString(xmlString);
    FormaJuridica ret = null;
    NodeList nodeLst = doc.getElementsByTagName("organizationType");

    for (int s = 0; s < nodeLst.getLength(); s++) {
      Node fstNode = nodeLst.item(s);
      if (fstNode.getNodeType() == Node.ELEMENT_NODE) {
        Element elPDU = (Element) fstNode;
        String code = XmlParserUtil.getAttribute(elPDU, "code");
        NodeList fstNm = elPDU.getChildNodes();
        String organizationType = null;

        if (fstNm.getLength() > 0) {
          organizationType = ((Node) fstNm.item(0)).getNodeValue();

          Integer orgId = getId(code);
          FormaJuridica formaJuridica = null;
          try {
            List<FormaJuridica> lFJ = formaJuridicaService.findByName(organizationType);

            if (lFJ != null && lFJ.size() > 0) {
              formaJuridica = lFJ.get(0);
            } else {
              formaJuridica = new FormaJuridica();
              formaJuridica.setName(organizationType);
              formaJuridicaService.save(formaJuridica);
            }

            if (orgId != null && orgId.equals(id)) {
              ret = formaJuridica;
            }
          } catch (ServiceException e) {
            logger.error(e.getMessage());
          }
        }
      }
    }
    return ret;
  }
Exemple #11
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();
      }
    }
  }