예제 #1
0
  public static com.liferay.opensocial.model.Gadget getGadget(PortletPreferences portletPreferences)
      throws Exception {

    String url = portletPreferences.getValue("url", StringPool.BLANK);

    if (Validator.isNull(url)) {
      return null;
    }

    com.liferay.opensocial.model.Gadget gadget = new GadgetImpl();

    GadgetSpec gadgetSpec = null;

    try {
      gadgetSpec = ShindigUtil.getGadgetSpec(url);
    } catch (Exception e) {
      throw new GadgetURLException(e);
    }

    ModulePrefs modulePrefs = gadgetSpec.getModulePrefs();

    gadget.setName(modulePrefs.getTitle());
    gadget.setUrl(url);

    return gadget;
  }
  /**
   * Converts the soap model instance into a normal model instance.
   *
   * @param soapModel the soap model instance to convert
   * @return the normal model instance
   */
  public static Gadget toModel(GadgetSoap soapModel) {
    Gadget model = new GadgetImpl();

    model.setUuid(soapModel.getUuid());
    model.setGadgetId(soapModel.getGadgetId());
    model.setCompanyId(soapModel.getCompanyId());
    model.setCreateDate(soapModel.getCreateDate());
    model.setModifiedDate(soapModel.getModifiedDate());
    model.setName(soapModel.getName());
    model.setUrl(soapModel.getUrl());
    model.setPortletCategoryNames(soapModel.getPortletCategoryNames());

    return model;
  }
  @Override
  protected void doImportStagedModel(PortletDataContext portletDataContext, Gadget gadget)
      throws Exception {

    ServiceContext serviceContext = portletDataContext.createServiceContext(gadget);

    Gadget importedGadget = null;

    if (portletDataContext.isDataStrategyMirror()) {
      Gadget existingGadget =
          GadgetLocalServiceUtil.fetchGadgetByUuidAndCompanyId(
              gadget.getUuid(), portletDataContext.getCompanyId());

      if (existingGadget == null) {
        serviceContext.setUuid(gadget.getUuid());

        importedGadget =
            GadgetLocalServiceUtil.addGadget(
                portletDataContext.getCompanyId(),
                gadget.getUrl(),
                gadget.getPortletCategoryNames(),
                serviceContext);
      } else {
        existingGadget.setName(gadget.getName());
        existingGadget.setUrl(gadget.getUrl());
        existingGadget.setPortletCategoryNames(gadget.getPortletCategoryNames());

        importedGadget = GadgetLocalServiceUtil.updateGadget(existingGadget);
      }
    } else {
      importedGadget =
          GadgetLocalServiceUtil.addGadget(
              portletDataContext.getCompanyId(),
              gadget.getUrl(),
              gadget.getPortletCategoryNames(),
              serviceContext);
    }

    portletDataContext.importClassedModel(gadget, importedGadget);
  }