Exemplo n.º 1
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;
  }
Exemplo n.º 2
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;
  }