示例#1
0
  public void executeQuery(
      ObjectClass objClass, String query, ResultsHandler handler, OperationOptions options) {
    // TODO Auto-generated method stub
    LOG.ok("Query {0} ", query);

    if (!isAccount(objClass)) {
      throw new UnsupportedOperationException(
          "Could not execute query. Object class not supported: " + objClass);
    }

    try {
      String repoId = getFoundationRepoId();

      String template = "<Templates>" + "<Person>" + "</Person>" + "</Templates>";

      int flags = MdOMIUtil.OMI_GET_METADATA | MdOMIUtil.OMI_ALL | MdOMIUtil.OMI_TEMPLATE;
      List objects =
          connection
              .getFactory()
              .getOMIUtil()
              .getMetadataObjects(repoId, MetadataObjects.PERSON, flags, template);

      Iterator iterator = objects.iterator();
      while (iterator.hasNext()) {
        Object obj = iterator.next();
        RootImpl p = (RootImpl) obj;
        ConnectorObjectBuilder cob = new ConnectorObjectBuilder();

        cob.addAttribute(Name.NAME, p.getName());
        cob.addAttribute(Uid.NAME, p.getId());

        Set<Entry<String, String>> attrs = p.getAttrs().entrySet();
        Iterator<Entry<String, String>> attrIterator = attrs.iterator();
        while (attrIterator.hasNext()) {
          Entry<String, String> attr = attrIterator.next();
          // skip id and name..it was set before (icf_name and icf_uid)
          if (attr.getKey().equals(CMetadata.ATTRIBUTE_ID_NAME)) {
            continue;
          }

          if (attr.getKey().equals(CMetadata.ATTRIBUTE_NAME_NAME)) {
            continue;
          }
          if (StringUtil.isEmpty(attr.getValue())) {
            LOG.ok("Skipping setting attribute {0}. Attribute value is blank", attr.getKey());
          } else {
            LOG.ok("Setting attribute {0} with value {1}", attr.getKey(), attr.getValue());
            cob.addAttribute(attr.getKey(), attr.getValue());
          }
        }

        handler.handle(cob.build());
      }

    } catch (RemoteException e) {
      // TODO Auto-generated catch block
      throw new ConnectorException(e);
    } catch (MdException e) {
      // TODO Auto-generated catch block
      throw new ConnectorException(e);
    }
  }