protected void importWSRPConsumerPortlet(
      PortletDataContext portletDataContext,
      WSRPConsumer wsrpConsumer,
      Element wsrpConsumerPortletElement,
      WSRPConsumerPortlet wsrpConsumerPortlet)
      throws Exception {

    try {
      WSRPConsumerPortlet importedWSRPConsumerPortlet =
          WSRPConsumerPortletLocalServiceUtil.getWSRPConsumerPortlet(wsrpConsumerPortlet.getUuid());

      importedWSRPConsumerPortlet.setWsrpConsumerId(wsrpConsumer.getWsrpConsumerId());
      importedWSRPConsumerPortlet.setName(wsrpConsumerPortlet.getName());
      importedWSRPConsumerPortlet.setPortletHandle(wsrpConsumerPortlet.getPortletHandle());

      WSRPConsumerPortletLocalServiceUtil.updateWSRPConsumerPortlet(
          importedWSRPConsumerPortlet, false);
    } catch (NoSuchConsumerPortletException nscpe) {
      ServiceContext serviceContext =
          portletDataContext.createServiceContext(
              wsrpConsumerPortletElement, wsrpConsumerPortlet, _NAMESPACE);

      serviceContext.setUuid(wsrpConsumerPortlet.getUuid());

      WSRPConsumerPortletLocalServiceUtil.addWSRPConsumerPortlet(
          wsrpConsumer.getUuid(),
          wsrpConsumerPortlet.getName(),
          wsrpConsumerPortlet.getPortletHandle(),
          null,
          serviceContext);
    }
  }
  protected void exportWSRPConsumer(
      PortletDataContext portletDataContext,
      Element wsrpConsumersElement,
      WSRPConsumer wsrpConsumer)
      throws Exception {

    String path = getWSRPConsumerPath(portletDataContext, wsrpConsumer);

    if (!portletDataContext.isPathNotProcessed(path)) {
      return;
    }

    Element wsrpConsumerElement = wsrpConsumersElement.addElement("wsrp-consumer");

    portletDataContext.addClassedModel(wsrpConsumerElement, path, wsrpConsumer, _NAMESPACE);

    if (portletDataContext.getBooleanParameter(_NAMESPACE, "wsrp-consumer-portlets")) {

      List<WSRPConsumerPortlet> wsrpConsumerPortlets =
          WSRPConsumerPortletLocalServiceUtil.getWSRPConsumerPortlets(
              wsrpConsumer.getWsrpConsumerId(), QueryUtil.ALL_POS, QueryUtil.ALL_POS);

      Element wsrpConsumerPortletsElement =
          wsrpConsumerElement.addElement("wsrp-consumer-portlets");

      for (WSRPConsumerPortlet wsrpConsumerPortlet : wsrpConsumerPortlets) {

        exportWSRPConsumerPortlet(
            portletDataContext, wsrpConsumerPortletsElement, wsrpConsumerPortlet);
      }
    }
  }
  @Override
  public boolean equals(Object obj) {
    if (this == obj) {
      return true;
    }

    if (!(obj instanceof WSRPConsumer)) {
      return false;
    }

    WSRPConsumer wsrpConsumer = (WSRPConsumer) obj;

    long primaryKey = wsrpConsumer.getPrimaryKey();

    if (getPrimaryKey() == primaryKey) {
      return true;
    } else {
      return false;
    }
  }
  protected String getWSRPConsumerPath(
      PortletDataContext portletDataContext, WSRPConsumer wsrpConsumer) {

    StringBundler sb = new StringBundler(4);

    sb.append(portletDataContext.getPortletPath(_PORTLET_KEY));
    sb.append("/wsrp-consumers/");
    sb.append(wsrpConsumer.getUuid());
    sb.append(".xml");

    return sb.toString();
  }
  @Override
  public int compareTo(WSRPConsumer wsrpConsumer) {
    int value = 0;

    value = getName().compareTo(wsrpConsumer.getName());

    if (value != 0) {
      return value;
    }

    return 0;
  }
  protected WSRPConsumer importWSRPConsumer(
      PortletDataContext portletDataContext, Element wsrpConsumerElement, WSRPConsumer wsrpConsumer)
      throws Exception {

    WSRPConsumer importedWSRPConsumer = null;

    try {
      importedWSRPConsumer = WSRPConsumerLocalServiceUtil.getWSRPConsumer(wsrpConsumer.getUuid());

      importedWSRPConsumer.setName(wsrpConsumer.getName());
      importedWSRPConsumer.setUrl(wsrpConsumer.getUrl());
      importedWSRPConsumer.setWsdl(wsrpConsumer.getWsdl());
      importedWSRPConsumer.setForwardCookies(wsrpConsumer.getForwardCookies());

      WSRPConsumerLocalServiceUtil.updateWSRPConsumer(importedWSRPConsumer, false);
    } catch (NoSuchConsumerException nsce) {
      ServiceContext serviceContext =
          portletDataContext.createServiceContext(wsrpConsumerElement, wsrpConsumer, _NAMESPACE);

      serviceContext.setUuid(wsrpConsumer.getUuid());

      importedWSRPConsumer =
          WSRPConsumerLocalServiceUtil.addWSRPConsumer(
              portletDataContext.getCompanyId(),
              null,
              wsrpConsumer.getName(),
              wsrpConsumer.getUrl(),
              wsrpConsumer.getForwardCookies(),
              null,
              serviceContext);
    }

    return importedWSRPConsumer;
  }