@Override
  protected PortletPreferences doDeleteData(
      PortletDataContext portletDataContext,
      String portletId,
      PortletPreferences portletPreferences)
      throws Exception {

    long companyId = portletDataContext.getCompanyId();

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

      List<WSRPProducer> wsrpProducers =
          WSRPProducerLocalServiceUtil.getWSRPProducers(
              companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS);

      for (WSRPProducer wsrpProducer : wsrpProducers) {
        WSRPProducerLocalServiceUtil.deleteWSRPProducer(wsrpProducer);
      }
    }

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

      List<WSRPConsumer> wsrpConsumers =
          WSRPConsumerLocalServiceUtil.getWSRPConsumers(
              companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS);

      for (WSRPConsumer wsrpConsumer : wsrpConsumers) {
        WSRPConsumerLocalServiceUtil.deleteWSRPConsumer(wsrpConsumer);
      }
    }

    return null;
  }
  protected void importWSRPProducer(
      PortletDataContext portletDataContext, Element wsrpProducerElement, WSRPProducer wsrpProducer)
      throws Exception {

    try {
      WSRPProducer importedWSRPProducer =
          WSRPProducerLocalServiceUtil.getWSRPProducer(wsrpProducer.getUuid());

      importedWSRPProducer.setName(wsrpProducer.getName());
      importedWSRPProducer.setVersion(wsrpProducer.getVersion());
      importedWSRPProducer.setPortletIds(wsrpProducer.getPortletIds());

      WSRPProducerLocalServiceUtil.updateWSRPProducer(importedWSRPProducer, false);
    } catch (NoSuchProducerException nspe) {
      ServiceContext serviceContext =
          portletDataContext.createServiceContext(wsrpProducerElement, wsrpProducer, _NAMESPACE);

      serviceContext.setUuid(wsrpProducer.getUuid());

      WSRPProducerLocalServiceUtil.addWSRPProducer(
          portletDataContext.getUserId(null),
          wsrpProducer.getName(),
          wsrpProducer.getVersion(),
          wsrpProducer.getPortletIds(),
          serviceContext);
    }
  }
  @Override
  protected String doExportData(
      PortletDataContext portletDataContext,
      String portletId,
      PortletPreferences portletPreferences)
      throws Exception {

    Document document = SAXReaderUtil.createDocument();

    Element rootElement = document.addElement("wsrp-data");

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

      Element wsrpProducersElement = rootElement.addElement("wsrp-producers");

      List<WSRPProducer> wsrpProducers =
          WSRPProducerLocalServiceUtil.getWSRPProducers(
              portletDataContext.getCompanyId(), QueryUtil.ALL_POS, QueryUtil.ALL_POS);

      for (WSRPProducer wsrpProducer : wsrpProducers) {
        exportWSRPProducer(portletDataContext, wsrpProducersElement, wsrpProducer);
      }
    }

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

      Element wsrpConsumersElement = rootElement.addElement("wsrp-consumers");

      List<WSRPConsumer> wsrpConsumers =
          WSRPConsumerLocalServiceUtil.getWSRPConsumers(
              portletDataContext.getCompanyId(), QueryUtil.ALL_POS, QueryUtil.ALL_POS);

      for (WSRPConsumer wsrpConsumer : wsrpConsumers) {
        exportWSRPConsumer(portletDataContext, wsrpConsumersElement, wsrpConsumer);
      }
    }

    return document.formattedString();
  }