Skip to content

Commit

Permalink
Fix review
Browse files Browse the repository at this point in the history
  • Loading branch information
azayati committed Sep 4, 2023
1 parent f5382b6 commit c50c3b9
Show file tree
Hide file tree
Showing 15 changed files with 238 additions and 281 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
import org.exoplatform.portal.mop.user.HttpUserPortalContext;
import org.exoplatform.portal.mop.user.UserNavigation;
import org.exoplatform.portal.mop.user.UserNode;
import org.exoplatform.portal.mop.user.UserPortal;
import org.exoplatform.portal.mop.user.UserNodeFilterConfig;
import org.exoplatform.portal.mop.user.UserPortal;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.exoplatform.services.organization.*;
Expand Down Expand Up @@ -86,7 +86,6 @@
import org.exoplatform.social.service.rest.Util;
import org.exoplatform.social.service.rest.api.VersionResources;
import org.exoplatform.ws.frameworks.json.impl.*;

import static org.exoplatform.portal.mop.rest.EntityBuilder.toUserNodeRestEntity;

public class EntityBuilder {
Expand All @@ -97,8 +96,6 @@ public class EntityBuilder {

private static final Log LOG = ExoLogger.getLogger(EntityBuilder.class);

public static final String GROUP = "group";

/** Group Space Binding */
public static final String GROUP_SPACE_BINDING_REPORT_OPERATIONS_TYPE = "groupSpaceBindingReportOperations";

Expand Down Expand Up @@ -166,6 +163,14 @@ public class EntityBuilder {
public static final CacheControl NO_CACHE_CC = new CacheControl();

private static final JsonEntityProvider JSON_ENTITY_PROVIDER = new JsonEntityProvider();

public static final String GROUP = "group";

private static UserPortalConfigService userPortalConfigService;

private static LayoutService layoutService;

private static UserACL userACL;

static {
NO_CACHE_CC.setNoCache(true);
Expand All @@ -182,13 +187,6 @@ public class EntityBuilder {

private static ActivityManager activityManager;

private static UserPortalConfigService userPortalConfigService;

private static LayoutService layoutService;

private static UserACL userACL;


private EntityBuilder() {
// Static class for utilities, thus a private constructor is declared
}
Expand Down Expand Up @@ -1710,6 +1708,10 @@ public static RelationshipManager getRelationshipManager() {
}
return relationshipManager;
}

public static List<SiteEntity> buildSiteEntities(List<PortalConfig> sites, HttpServletRequest request, SiteFilter siteFilter) {
return sites.stream().map(site -> buildSiteEntity(site, request, siteFilter)).filter(Objects::nonNull).toList();
}

private static SiteEntity buildSiteEntity(PortalConfig site, HttpServletRequest request, SiteFilter siteFilter) {
if (site == null) {
Expand Down Expand Up @@ -1749,27 +1751,21 @@ private static SiteEntity buildSiteEntity(PortalConfig site, HttpServletRequest
}
}
return new SiteEntity(siteType,
site.getName(),
!StringUtils.isBlank(displayName) ? displayName : site.getName(),
site.getDescription(),
accessPermissions,
editPermission,
isDefaultSite(site.getName()) || site.isDisplayed(),
site.getDisplayOrder(),
isDefaultSite(site.getName()),
rootNode == null ? null
: toUserNodeRestEntity(rootNode.getChildren(),
true,
getOrganizationService(),
getLayoutService(),
getUserACL()));

}

public static List<SiteEntity> buildSiteEntities(List<PortalConfig> sites,
HttpServletRequest request,
SiteFilter siteFilter) {
return sites.stream().map(site -> buildSiteEntity(site, request, siteFilter)).filter(Objects::nonNull).toList();
site.getName(),
!StringUtils.isBlank(displayName) ? displayName : site.getName(),
site.getDescription(),
accessPermissions,
editPermission,
site.isDisplayed(),
site.getDisplayOrder(),
isMetaSite(site.getName()),
rootNode == null ? null
: toUserNodeRestEntity(rootNode.getChildren(),
true,
getOrganizationService(),
getLayoutService(),
getUserACL()));

}

private static List<Map<String, Object>> computePermissions(String[] permissions) {
Expand Down Expand Up @@ -1809,7 +1805,7 @@ private static LayoutService getLayoutService() {
return layoutService;
}

private static boolean isDefaultSite(String siteName) {
private static boolean isMetaSite(String siteName) {
return getUserPortalConfigService().getDefaultPortal().equals(siteName);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
*/
package org.exoplatform.social.rest.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
import java.util.Map;

import org.exoplatform.portal.mop.SiteType;
import org.exoplatform.portal.mop.rest.model.UserNodeRestEntity;

import java.util.List;
import java.util.Map;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
Expand All @@ -46,7 +47,7 @@ public class SiteEntity {

private int displayOrder;

private boolean isDefaultSite;
private boolean metaSite;

List<UserNodeRestEntity> siteNavigations;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*
* This file is part of the Meeds project (https://meeds.io/).
* Copyright (C) 2023 Meeds Association
* [email protected]
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.exoplatform.social.rest.impl.site;

import java.util.List;

import javax.annotation.security.RolesAllowed;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.exoplatform.portal.config.model.PortalConfig;
import org.exoplatform.portal.mop.SiteFilter;
import org.exoplatform.portal.mop.SiteType;
import org.exoplatform.portal.mop.service.LayoutService;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.exoplatform.services.rest.resource.ResourceContainer;
import org.exoplatform.social.rest.api.EntityBuilder;
import org.exoplatform.social.service.rest.api.VersionResources;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;

@Path(VersionResources.VERSION_ONE + "/social/sites")
@Tag(name = VersionResources.VERSION_ONE + "/social/sites", description = "Manage sites")
public class SiteRest implements ResourceContainer {

private static final Log LOG = ExoLogger.getLogger(SiteRest.class);

private LayoutService layoutService;

public SiteRest(LayoutService layoutService) {
this.layoutService = layoutService;
}

@GET
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed("users")
@Operation(summary = "Gets sites", description = "Gets sites", method = "GET")
@ApiResponses(value = { @ApiResponse(responseCode = "200", description = "Request fulfilled"),
@ApiResponse(responseCode = "500", description = "Internal server error"), })
public Response getSites(@Context
HttpServletRequest request,
@Parameter(description = "Portal site type, possible values: PORTAL, GROUP or USER", required = true)
@QueryParam("siteType")
String siteTypeName,
@Parameter(description = "Site name to be excluded")
@QueryParam("excludedSiteName")
String excludedSiteName,
@Parameter(description = "to include empty site in results in portal type case")
@DefaultValue("true")
@QueryParam("includeEmpty")
boolean includeEmpty,
@Parameter(description = "to expand site navigations nodes")
@DefaultValue("false")
@QueryParam("expandNavigations")
boolean expandNavigations,
@Parameter(description = "to retrieve sites with its displayed status")
@DefaultValue("false")
@QueryParam("displayed")
boolean displayed,
@Parameter(description = "to retrieve all sites")
@DefaultValue("true")
@QueryParam("allSites")
boolean allSites,
@Parameter(description = "to filter sites by view/edit permissions")
@DefaultValue("false")
@QueryParam("filterByPermissions")
boolean filterByPermission,
@Parameter(description = "Offset of results to retrieve")
@QueryParam("offset")
@DefaultValue("0")
int offset,
@Parameter(description = "Limit of results to retrieve")
@QueryParam("limit")
@DefaultValue("0")
int limit) {
try {
SiteFilter siteFilter = new SiteFilter();
if (siteTypeName != null) {
siteFilter.setSiteType(SiteType.valueOf(siteTypeName.toUpperCase()));
}
siteFilter.setExcludedSiteName(excludedSiteName);
siteFilter.setIncludeEmpty(includeEmpty);
siteFilter.setDisplayed(displayed);
siteFilter.setAllSites(allSites);
siteFilter.setExpandNavigations(expandNavigations);
siteFilter.setFilterByPermission(filterByPermission);
siteFilter.setLimit(limit);
siteFilter.setOffset(offset);
List<PortalConfig> sites = layoutService.getSites(siteFilter);
return Response.ok(EntityBuilder.buildSiteEntities(sites, request, siteFilter)).build();
} catch (Exception e) {
LOG.warn("Error while retrieving sites", e);
return Response.serverError().build();
}
}
}

This file was deleted.

Loading

0 comments on commit c50c3b9

Please sign in to comment.