コード例 #1
0
  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;
  }
コード例 #2
0
  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);
  }