public LinkedHashMap<String, Object> getGroupParams() throws PortalException {

    if (_groupParams != null) {
      return _groupParams;
    }

    long groupId = ParamUtil.getLong(_request, "groupId");
    boolean includeCurrentGroup = ParamUtil.getBoolean(_request, "includeCurrentGroup", true);

    String type = getType();

    ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY);

    PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();
    User user = themeDisplay.getUser();

    boolean filterManageableGroups = true;

    if (permissionChecker.isCompanyAdmin()) {
      filterManageableGroups = false;
    }

    _groupParams = new LinkedHashMap<>();

    _groupParams.put("active", Boolean.TRUE);

    if (isManualMembership()) {
      _groupParams.put("manualMembership", Boolean.TRUE);
    }

    if (type.equals("child-sites")) {
      Group parentGroup = GroupLocalServiceUtil.getGroup(groupId);

      List<Group> parentGroups = new ArrayList<>();

      parentGroups.add(parentGroup);

      _groupParams.put("groupsTree", parentGroups);
    } else if (filterManageableGroups) {
      _groupParams.put("usersGroups", user.getUserId());
    }

    _groupParams.put("site", Boolean.TRUE);

    if (!includeCurrentGroup && (groupId > 0)) {
      List<Long> excludedGroupIds = new ArrayList<>();

      Group group = GroupLocalServiceUtil.getGroup(groupId);

      if (group.isStagingGroup()) {
        excludedGroupIds.add(group.getLiveGroupId());
      } else {
        excludedGroupIds.add(groupId);
      }

      _groupParams.put("excludedGroupIds", excludedGroupIds);
    }

    return _groupParams;
  }
  public static BreadcrumbEntry getGuestGroupBreadcrumbEntry(ThemeDisplay themeDisplay)
      throws Exception {

    Group group = GroupLocalServiceUtil.getGroup(themeDisplay.getCompanyId(), GroupConstants.GUEST);

    if (group.getPublicLayoutsPageCount() == 0) {
      return null;
    }

    LayoutSet layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(group.getGroupId(), false);

    BreadcrumbEntry breadcrumbEntry = new BreadcrumbEntry();

    Account account = themeDisplay.getAccount();

    breadcrumbEntry.setTitle(account.getName());

    String layoutSetFriendlyURL = PortalUtil.getLayoutSetFriendlyURL(layoutSet, themeDisplay);

    if (themeDisplay.isAddSessionIdToURL()) {
      layoutSetFriendlyURL =
          PortalUtil.getURLWithSessionId(layoutSetFriendlyURL, themeDisplay.getSessionId());
    }

    breadcrumbEntry.setURL(layoutSetFriendlyURL);

    return breadcrumbEntry;
  }
Esempio n. 3
0
  public void setSiteGroupId(long siteGroupId) {
    _siteGroupId = siteGroupId;

    if (_siteGroupId > 0) {
      try {
        _siteGroup = GroupLocalServiceUtil.getGroup(_siteGroupId);
      } catch (Exception e) {
        _log.error(e, e);
      }
    }
  }
Esempio n. 4
0
  public void setRefererGroupId(long refererGroupId) {
    _refererGroupId = refererGroupId;

    if (_refererGroupId > 0) {
      try {
        _refererGroup = GroupLocalServiceUtil.getGroup(_refererGroupId);
      } catch (Exception e) {
        _log.error(e, e);
      }
    }
  }
Esempio n. 5
0
  public static Tuple getElements(String xml, String className, int inactiveGroupsCount) {

    List<Element> resultRows = new ArrayList<>();
    int totalRows = 0;

    try {
      xml = XMLUtil.stripInvalidChars(xml);

      Document document = SAXReaderUtil.read(xml);

      Element rootElement = document.getRootElement();

      List<Element> elements = rootElement.elements("entry");

      totalRows =
          GetterUtil.getInteger(
              rootElement.elementText(
                  OpenSearchUtil.getQName("totalResults", OpenSearchUtil.OS_NAMESPACE)));

      for (Element element : elements) {
        try {
          long entryScopeGroupId =
              GetterUtil.getLong(
                  element.elementText(
                      OpenSearchUtil.getQName("scopeGroupId", OpenSearchUtil.LIFERAY_NAMESPACE)));

          if ((entryScopeGroupId != 0) && (inactiveGroupsCount > 0)) {
            Group entryGroup = GroupServiceUtil.getGroup(entryScopeGroupId);

            if (entryGroup.isLayout()) {
              entryGroup = GroupLocalServiceUtil.getGroup(entryGroup.getParentGroupId());
            }

            if (!entryGroup.isActive()) {
              totalRows--;

              continue;
            }
          }

          resultRows.add(element);
        } catch (Exception e) {
          _log.error("Unable to retrieve individual search result for " + className, e);

          totalRows--;
        }
      }
    } catch (Exception e) {
      _log.error("Unable to display content for " + className, e);
    }

    return new Tuple(resultRows, totalRows);
  }
  @Override
  public void deleteStagedModel(String uuid, long groupId, String className, String extraData)
      throws PortalException {

    Group group = GroupLocalServiceUtil.getGroup(groupId);

    Gadget gadget =
        GadgetLocalServiceUtil.fetchGadgetByUuidAndCompanyId(uuid, group.getCompanyId());

    if (gadget != null) {
      deleteStagedModel(gadget);
    }
  }
  /**
   * Returns an export layout settings map if the type is {@link
   * ExportImportConfigurationConstants#TYPE_EXPORT_LAYOUT}; otherwise, returns either a local or
   * remote publish layout settings map, depending on the staging type.
   *
   * @param portletRequest the portlet request
   * @param groupId the primary key of the group
   * @param type the export/import option type
   * @return an export layout settings map if the type is an export layout; otherwise, returns
   *     either a local or remote publish layout settings map, depending on the staging type
   */
  public static Map<String, Serializable> buildSettingsMap(
      PortletRequest portletRequest, long groupId, int type) throws PortalException {

    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    boolean privateLayout = ParamUtil.getBoolean(portletRequest, "privateLayout");

    Map<Long, Boolean> layoutIdMap = ExportImportHelperUtil.getLayoutIdMap(portletRequest);

    if (type == ExportImportConfigurationConstants.TYPE_EXPORT_LAYOUT) {
      long[] layoutIds = ExportImportHelperUtil.getLayoutIds(layoutIdMap);

      return buildExportLayoutSettingsMap(
          themeDisplay.getUserId(),
          groupId,
          privateLayout,
          layoutIds,
          portletRequest.getParameterMap(),
          themeDisplay.getLocale(),
          themeDisplay.getTimeZone());
    }

    Group stagingGroup = GroupLocalServiceUtil.getGroup(groupId);

    Group liveGroup = stagingGroup.getLiveGroup();

    Map<String, String[]> parameterMap =
        ExportImportConfigurationParameterMapFactory.buildParameterMap(portletRequest);

    if (liveGroup != null) {
      long[] layoutIds = ExportImportHelperUtil.getLayoutIds(layoutIdMap, liveGroup.getGroupId());

      return buildPublishLayoutLocalSettingsMap(
          themeDisplay.getUserId(),
          stagingGroup.getGroupId(),
          liveGroup.getGroupId(),
          privateLayout,
          layoutIds,
          parameterMap,
          themeDisplay.getLocale(),
          themeDisplay.getTimeZone());
    }

    UnicodeProperties groupTypeSettingsProperties = stagingGroup.getTypeSettingsProperties();

    String remoteAddress =
        ParamUtil.getString(
            portletRequest,
            "remoteAddress",
            groupTypeSettingsProperties.getProperty("remoteAddress"));

    remoteAddress = StagingUtil.stripProtocolFromRemoteAddress(remoteAddress);

    int remotePort =
        ParamUtil.getInteger(
            portletRequest,
            "remotePort",
            GetterUtil.getInteger(groupTypeSettingsProperties.getProperty("remotePort")));
    String remotePathContext =
        ParamUtil.getString(
            portletRequest,
            "remotePathContext",
            groupTypeSettingsProperties.getProperty("remotePathContext"));
    boolean secureConnection =
        ParamUtil.getBoolean(
            portletRequest,
            "secureConnection",
            GetterUtil.getBoolean(groupTypeSettingsProperties.getProperty("secureConnection")));
    long remoteGroupId =
        ParamUtil.getLong(
            portletRequest,
            "remoteGroupId",
            GetterUtil.getLong(groupTypeSettingsProperties.getProperty("remoteGroupId")));
    boolean remotePrivateLayout = ParamUtil.getBoolean(portletRequest, "remotePrivateLayout");

    StagingUtil.validateRemote(
        groupId, remoteAddress, remotePort, remotePathContext, secureConnection, remoteGroupId);

    return buildPublishLayoutRemoteSettingsMap(
        themeDisplay.getUserId(),
        groupId,
        privateLayout,
        layoutIdMap,
        parameterMap,
        remoteAddress,
        remotePort,
        remotePathContext,
        secureConnection,
        remoteGroupId,
        remotePrivateLayout,
        themeDisplay.getLocale(),
        themeDisplay.getTimeZone());
  }
  @AfterClass
  public static void tearDownClass() throws PortalException {
    GroupLocalServiceUtil.deleteGroup(_group);

    UserLocalServiceUtil.deleteUser(_user);
  }
 @Test
 public void test3() throws Exception {
   GroupLocalServiceUtil.dynamicQuery();
 }
  public GroupSearch getGroupSearch() throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY);

    Company company = themeDisplay.getCompany();

    GroupSearch groupSearch = new GroupSearch(_liferayPortletRequest, getPortletURL());

    GroupSearchTerms groupSearchTerms = (GroupSearchTerms) groupSearch.getSearchTerms();

    List<Group> results = new ArrayList<>();

    int additionalSites = 0;
    int total = 0;

    boolean includeCompany = ParamUtil.getBoolean(_request, "includeCompany");
    boolean includeUserPersonalSite = ParamUtil.getBoolean(_request, "includeUserPersonalSite");

    long[] classNameIds = _CLASS_NAME_IDS;

    if (includeCompany) {
      classNameIds = ArrayUtil.append(classNameIds, PortalUtil.getClassNameId(Company.class));
    }

    if (includeUserPersonalSite) {
      if (groupSearch.getStart() == 0) {
        Group userPersonalSite =
            GroupLocalServiceUtil.getGroup(
                company.getCompanyId(), GroupConstants.USER_PERSONAL_SITE);

        results.add(userPersonalSite);
      }

      additionalSites++;
    }

    String type = getType();

    if (type.equals("layoutScopes")) {
      total =
          GroupLocalServiceUtil.getGroupsCount(
              themeDisplay.getCompanyId(), Layout.class.getName(), getGroupId());
    } else if (type.equals("parent-sites")) {
    } else {
      total =
          GroupLocalServiceUtil.searchCount(
              themeDisplay.getCompanyId(),
              classNameIds,
              groupSearchTerms.getKeywords(),
              getGroupParams());
    }

    total += additionalSites;

    groupSearch.setTotal(total);

    int start = groupSearch.getStart();

    if (groupSearch.getStart() > additionalSites) {
      start = groupSearch.getStart() - additionalSites;
    }

    int end = groupSearch.getEnd() - additionalSites;

    List<Group> groups = null;

    if (type.equals("layoutScopes")) {
      groups =
          GroupLocalServiceUtil.getGroups(
              company.getCompanyId(), Layout.class.getName(), getGroupId(), start, end);

      groups = _filterLayoutGroups(groups, isPrivateLayout());
    } else if (type.equals("parent-sites")) {
      Group group = GroupLocalServiceUtil.getGroup(getGroupId());

      groups = group.getAncestors();

      String filter = getFilter();

      if (Validator.isNotNull(filter)) {
        groups = _filterGroups(groups, filter);
      }

      total = groups.size();

      total += additionalSites;

      groupSearch.setTotal(total);
    } else {
      groups =
          GroupLocalServiceUtil.search(
              company.getCompanyId(),
              classNameIds,
              groupSearchTerms.getKeywords(),
              getGroupParams(),
              start,
              end,
              groupSearch.getOrderByComparator());
    }

    results.addAll(groups);

    groupSearch.setResults(results);

    return groupSearch;
  }
  public void doView(RenderRequest renderRequest, RenderResponse renderResponse)
      throws IOException, PortletException {

    ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
    HashMap<Date, ArrayList<HashMap<String, Object>>> resultado =
        new HashMap<Date, ArrayList<HashMap<String, Object>>>();
    List<TimeLinePopUp> listaPopUps = new ArrayList<TimeLinePopUp>();

    PortletPreferences prefs = renderRequest.getPreferences();
    String showInMain = prefs.getValue("showInMain", "true");
    String showItems = prefs.getValue("showItems", "true");
    String showAlerts = prefs.getValue("showAlerts", "true");

    // *********************
    // 1) Sites de LIFERAY
    // *********************
    List<Group> offices = new ArrayList<Group>();

    // Si el portlet se muestra en la pagina ppal, recorremos todas las oficianas a partir de un
    // sitio padre leido desde properties
    if (showInMain.equals("true")) {
      String mainSiteGroupId = com.liferay.util.portlet.PortletProps.get("lfvo.main.site.group.id");
      if (mainSiteGroupId != null && !"".equals(mainSiteGroupId)) {
        try {
          offices =
              GroupLocalServiceUtil.getGroups(
                  themeDisplay.getCompanyId(), Long.parseLong(mainSiteGroupId), true);

        } catch (NumberFormatException e) {
          e.printStackTrace();
          offices = GroupLocalServiceUtil.getGroups(themeDisplay.getCompanyId(), 0, true);
        }
      } else {
        offices = GroupLocalServiceUtil.getGroups(themeDisplay.getCompanyId(), 0, true);
      }
      // Si el portlet no se muestra en la pagina ppal, cogemos la oficina del sitio
    } else {
      offices.add(themeDisplay.getScopeGroup());
    }

    // *********************
    // 2) Sites de FIREBASE
    // *********************
    HashMap<String, Object> officesMap = new HashMap<String, Object>();
    try {
      DatabaseReference ref = FirebaseDatabase.getInstance().getReference("/offices/");
      Firebase firebase = new Firebase(ref.toString());
      FirebaseResponse response = firebase.get();
      officesMap = (HashMap<String, Object>) response.getBody();

    } catch (FirebaseException e2) {
      e2.printStackTrace();
    }

    if (officesMap != null) {
      for (Group office : offices) {

        HashMap<String, Object> officeBD =
            (HashMap<String, Object>)
                officesMap.get(
                    String.valueOf(office.getGroupId())); // Site Firebase <> Site Liferay
        if (officeBD != null) {

          try {
            List<Item> items = ItemLocalServiceUtil.getItems(office.getGroupId(), -1, -1);
            for (Item item : items) {

              // Si s�lo mostramos ITEMS y no ALERTS...
              if (showItems.equals("true") & showAlerts.equals("false")) {
                if (!"".equals(item.getType())
                    & !item.getType()
                        .equals("office")) { // Si tiene tipo, pero no es 'office' descartamos
                  continue;
                }
              }

              // Si s�lo mostramos ALERTS y no ITEMS...
              if (showItems.equals("false") & showAlerts.equals("true")) {
                if ("".equals(item.getType())
                    || item.getType()
                        .equals("office")) { // Si es vacio o es 'office' descartamos							
                  continue;
                }
              }

              // Si no mostramos nada...
              if (showItems.equals("false") & showAlerts.equals("false")) {
                continue;
              }

              HashMap<String, Object> miItem = new HashMap<String, Object>();

              // Creamos una fecha con formato simple
              Date createDate = item.getCreateDate();
              String fechaFormat = "";
              String fechaFormatEus = "";
              SimpleDateFormat dt1 = new SimpleDateFormat("dd/MM/yyyy");
              SimpleDateFormat dt2 = new SimpleDateFormat("yyyy/MM/dd");
              if (createDate != null) {
                fechaFormat = dt1.format(item.getCreateDate());
                fechaFormatEus = dt2.format(item.getCreateDate());
              } else {
                fechaFormat = dt1.format(item.getModifiedDate());
                fechaFormatEus = dt2.format(item.getModifiedDate());
              }

              // Quitamos la hora y minutos de la fecha original
              SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
              Date b = new Date();
              try {
                b = formatter.parse(fechaFormat);
              } catch (ParseException e) {

              }

              // PopUp - Mapa Street
              TimeLinePopUp miPopUp = new TimeLinePopUp();
              miPopUp.setDate_es(fechaFormat);
              miPopUp.setDate_eu(fechaFormatEus);
              miPopUp.setName(item.getName());
              miPopUp.setImage(this.obtenerImagenItem(item.getItemId()));
              miPopUp.setLat(String.valueOf(item.getLat()));
              miPopUp.setLng(String.valueOf(item.getLng()));

              listaPopUps.add(miPopUp);

              // HashMaps - Timeline
              miItem.put("image", this.obtenerImagenItem(item.getItemId()));
              miItem.put("name", item.getName());
              miItem.put("desc", item.getDescription());
              miItem.put("lat", item.getLat());
              miItem.put("lng", item.getLng());
              miItem.put("type", item.getType());

              if (resultado.get(b) == null) {
                resultado.put(b, new ArrayList<HashMap<String, Object>>());
              }
              resultado.get(b).add(miItem);
            }
          } catch (PortalException e) {
            e.printStackTrace();
          }
        }
      }
    }

    // Lista de PopUps
    Type listType = new TypeToken<List<TimeLinePopUp>>() {}.getType();
    Gson gson = new Gson();
    String json = gson.toJson(listaPopUps, listType);

    renderRequest.setAttribute("popUps", json);

    // En vez de ordenar el hashmap, ordenamos las keys
    ArrayList<Date> miArray = new ArrayList<Date>();
    for (Date date : resultado.keySet()) {
      miArray.add(date);
    }
    Collections.sort(miArray);

    renderRequest.setAttribute("resultado", resultado);
    renderRequest.setAttribute("orderedKeys", miArray);

    super.doView(renderRequest, renderResponse);
  }