From 9bbb728aa5b41901c68ae315f0b6ce020e9646fe Mon Sep 17 00:00:00 2001 From: jdotcms Date: Tue, 11 Feb 2025 19:15:48 -0600 Subject: [PATCH] #28827 adding the first draft for the endpoint resource --- .../ajax/PublishingEndpointAjaxAction.java | 2 +- .../business/PublishingEndPointAPI.java | 6 + .../business/PublishingEndPointAPIImpl.java | 10 +- .../com/dotcms/rest/CMSConfigResource.java | 4 +- .../java/com/dotcms/rest/EndpointForm.java | 95 ++++ .../com/dotcms/rest/EndpointResource.java | 472 ++++++++++++++++++ .../rest/ResponseEntityEndpointView.java | 14 + .../rest/ResponseEntityEndpointsView.java | 15 + 8 files changed, 614 insertions(+), 4 deletions(-) create mode 100644 dotCMS/src/main/java/com/dotcms/rest/EndpointForm.java create mode 100644 dotCMS/src/main/java/com/dotcms/rest/EndpointResource.java create mode 100644 dotCMS/src/main/java/com/dotcms/rest/ResponseEntityEndpointView.java create mode 100644 dotCMS/src/main/java/com/dotcms/rest/ResponseEntityEndpointsView.java diff --git a/dotCMS/src/main/java/com/dotcms/publisher/endpoint/ajax/PublishingEndpointAjaxAction.java b/dotCMS/src/main/java/com/dotcms/publisher/endpoint/ajax/PublishingEndpointAjaxAction.java index 4ae8afae8c33..f68b5b96e1a2 100644 --- a/dotCMS/src/main/java/com/dotcms/publisher/endpoint/ajax/PublishingEndpointAjaxAction.java +++ b/dotCMS/src/main/java/com/dotcms/publisher/endpoint/ajax/PublishingEndpointAjaxAction.java @@ -108,7 +108,7 @@ public void addEndpoint(HttpServletRequest request, HttpServletResponse response return; } - String serverName = request.getParameter("serverName"); + String serverName = request.getParameter("serverName"); // endpoint name PublishingEndPoint existingServer = APILocator.getPublisherEndPointAPI().findEndPointByName(serverName); if(existingServer!=null) { diff --git a/dotCMS/src/main/java/com/dotcms/publisher/endpoint/business/PublishingEndPointAPI.java b/dotCMS/src/main/java/com/dotcms/publisher/endpoint/business/PublishingEndPointAPI.java index f65dae7e2b87..c758bd043914 100644 --- a/dotCMS/src/main/java/com/dotcms/publisher/endpoint/business/PublishingEndPointAPI.java +++ b/dotCMS/src/main/java/com/dotcms/publisher/endpoint/business/PublishingEndPointAPI.java @@ -88,4 +88,10 @@ public interface PublishingEndPointAPI { * @throws DotDataException */ List findSendGroups()throws DotDataException; + + /** + * Creates an endPoint of the specified protocol. + * @return PublishingEndPoint + */ + PublishingEndPoint createEndPoint(String protocol) ; } diff --git a/dotCMS/src/main/java/com/dotcms/publisher/endpoint/business/PublishingEndPointAPIImpl.java b/dotCMS/src/main/java/com/dotcms/publisher/endpoint/business/PublishingEndPointAPIImpl.java index 568ad2f1ac3e..bc98e32d87f9 100644 --- a/dotCMS/src/main/java/com/dotcms/publisher/endpoint/business/PublishingEndPointAPIImpl.java +++ b/dotCMS/src/main/java/com/dotcms/publisher/endpoint/business/PublishingEndPointAPIImpl.java @@ -1,13 +1,13 @@ package com.dotcms.publisher.endpoint.business; -import java.util.List; - import com.dotcms.business.CloseDBIfOpened; import com.dotcms.business.WrapInTransaction; import com.dotcms.integritycheckers.IntegrityUtil; import com.dotcms.publisher.endpoint.bean.PublishingEndPoint; import com.dotmarketing.exception.DotDataException; +import java.util.List; + /** * Implementation of publishing_end_point API. * @@ -17,6 +17,7 @@ */ public class PublishingEndPointAPIImpl implements PublishingEndPointAPI { + final com.dotcms.publisher.endpoint.bean.factory.PublishingEndPointFactory factory = new com.dotcms.publisher.endpoint.bean.factory.PublishingEndPointFactory(); private PublishingEndPointFactory publishingEndPointFactory; public PublishingEndPointAPIImpl(PublishingEndPointFactory publishingEndPointFactory){ @@ -129,4 +130,9 @@ public void setPublishingEndPointFactory( PublishingEndPointFactory publishingEndPointFactory) { this.publishingEndPointFactory = publishingEndPointFactory; } + + @Override + public PublishingEndPoint createEndPoint(final String protocol) { + return this.factory.getPublishingEndPoint(protocol); + } } diff --git a/dotCMS/src/main/java/com/dotcms/rest/CMSConfigResource.java b/dotCMS/src/main/java/com/dotcms/rest/CMSConfigResource.java index 60ac36c851e0..2e5af4375045 100644 --- a/dotCMS/src/main/java/com/dotcms/rest/CMSConfigResource.java +++ b/dotCMS/src/main/java/com/dotcms/rest/CMSConfigResource.java @@ -444,6 +444,7 @@ public Response deleteEnvironment ( @Context HttpServletRequest request, /** * Deletes a given end point * + * @deprecated use {@link EndpointResource#delete(HttpServletRequest, HttpServletResponse, String)} * @param request * @param user * @param password @@ -452,6 +453,7 @@ public Response deleteEnvironment ( @Context HttpServletRequest request, * @throws JSONException * @throws IOException */ + @Deprecated @POST @Path ("/deleteEndpoint") @Produces (MediaType.APPLICATION_JSON) @@ -554,4 +556,4 @@ public Response regenerateKey ( @Context final HttpServletRequest request, } -} \ No newline at end of file +} diff --git a/dotCMS/src/main/java/com/dotcms/rest/EndpointForm.java b/dotCMS/src/main/java/com/dotcms/rest/EndpointForm.java new file mode 100644 index 000000000000..63ee2028a7c9 --- /dev/null +++ b/dotCMS/src/main/java/com/dotcms/rest/EndpointForm.java @@ -0,0 +1,95 @@ +package com.dotcms.rest; + +import com.dotcms.repackage.javax.validation.constraints.NotNull; +import com.dotcms.rest.api.Validated; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Encapsulates the data of an endpoint on an environment + * @author jsanca + */ +public class EndpointForm extends Validated implements java.io.Serializable { + + @NotNull + @JsonProperty("name") + private final String name; + + @NotNull + @JsonProperty("protocol") + private final String protocol; + + @NotNull + @JsonProperty("address") + private final String address; + + @NotNull + @JsonProperty("port") + private final String port; + + @JsonProperty("authorizationToken") + private final String authorizationToken; + + @JsonProperty("enabled") + private final boolean enabled; + + @JsonProperty("sending") + private final boolean sending; + + @NotNull + @JsonProperty("environmentId") + private final String environmentId; + + @JsonCreator + public EndpointForm(@JsonProperty("name") final String name, + @JsonProperty("protocol") final String protocol, + @JsonProperty("address") final String address, + @JsonProperty("port") final String port, + @JsonProperty("authorizationToken") final String authorizationToken, + @JsonProperty("enabled") final boolean enabled, + @JsonProperty("sending") final boolean sending, + @JsonProperty("environmentId") final String environmentId + ) { + this.name = name; + this.protocol = protocol; + this.address = address; + this.port = port; + this.authorizationToken = authorizationToken; + this.enabled = enabled; + this.sending = sending; + this.environmentId = environmentId; + checkValid(); + } + + public String getName() { + return name; + } + + public String getProtocol() { + return protocol; + } + + public String getAddress() { + return address; + } + + public String getPort() { + return port; + } + + public String getAuthorizationToken() { + return authorizationToken; + } + + public boolean isEnabled() { + return enabled; + } + + public String getEnvironmentId() { + return environmentId; + } + + public boolean isSending() { + return sending; + } +} diff --git a/dotCMS/src/main/java/com/dotcms/rest/EndpointResource.java b/dotCMS/src/main/java/com/dotcms/rest/EndpointResource.java new file mode 100644 index 000000000000..d4bcd4e73e36 --- /dev/null +++ b/dotCMS/src/main/java/com/dotcms/rest/EndpointResource.java @@ -0,0 +1,472 @@ +package com.dotcms.rest; + +import com.dotcms.publisher.endpoint.bean.PublishingEndPoint; +import com.dotcms.publisher.endpoint.business.PublishingEndPointAPI; +import com.dotcms.publisher.environment.bean.Environment; +import com.dotcms.rest.annotation.NoCache; +import com.dotcms.rest.exception.ForbiddenException; +import com.dotmarketing.business.APILocator; +import com.dotmarketing.business.Role; +import com.dotmarketing.cms.factories.PublicEncryptionFactory; +import com.dotmarketing.exception.DoesNotExistException; +import com.dotmarketing.exception.DotDataException; +import com.dotmarketing.exception.DotSecurityException; +import com.dotmarketing.exception.PublishingEndPointValidationException; +import com.dotmarketing.util.Logger; +import com.dotmarketing.util.PortletID; +import com.dotmarketing.util.UtilMethods; +import com.dotmarketing.util.WebKeys; +import com.dotmarketing.util.json.JSONArray; +import com.dotmarketing.util.json.JSONException; +import com.dotmarketing.util.json.JSONObject; +import com.liferay.portal.model.User; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import org.apache.commons.lang.StringEscapeUtils; +import org.glassfish.jersey.server.JSONP; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.CacheControl; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Objects; +import java.util.Set; + +/** + * Endpoint for managing PP endpoints + @author jsanca + */ +@Path("/v1/environments/endpoints") +public class EndpointResource { + + public static final String THE_USER_KEY = "The user: "; + private final WebResource webResource = new WebResource(); + private final PublishingEndPointAPI publisherEndPointAPI = APILocator.getPublisherEndPointAPI(); + + /** + * Returns the endpoints for the current user + * if it is admin returns all of them, otherwise returns the ones that the user has access to + * + * @throws JSONException + * + */ + @Operation(summary = "Returns the endpoints", + responses = { + @ApiResponse( + responseCode = "200", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = + ResponseEntityEndpointsView.class)), + description = "Collection of environments.") + }) + @GET + @Produces("application/json") + @NoCache + public ResponseEntityEndpointsView getEndpoints(@Context HttpServletRequest request, @Context final HttpServletResponse response) + throws DotDataException, JSONException, DotSecurityException { + + final InitDataObject initData = new WebResource.InitBuilder(webResource) + .requiredBackendUser(true) + .requiredFrontendUser(false) + .requestAndResponse(request, response) + .rejectWhenNoUser(true) + .init(); + + final User user = initData.getUser(); + final boolean isAdmin = user.isAdmin(); + + Logger.debug(this, ()-> "Retrieving PublishingEndPoint for user: " + user.getUserId() + " isAdmin: " + isAdmin); + + return new ResponseEntityEndpointsView(this.publisherEndPointAPI.getAllEndPoints()); + } + + /** + * Returns the endpoints for the current user + * if it is admin returns all of them, otherwise returns the ones that the user has access to + * + * @throws JSONException + * + */ + @Operation(summary = "Returns the endpoints", + responses = { + @ApiResponse( + responseCode = "200", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = + ResponseEntityEndpointsView.class)), + description = "Collection of environments.") + }) + @GET + @Path("/environment/{environmentId}") + @Produces("application/json") + @NoCache + public ResponseEntityEndpointsView getEndpointsByEnvironmentId(@Context HttpServletRequest request, + @Context final HttpServletResponse response, + @PathParam("environmentId") String environmentId) + throws DotDataException, JSONException, DotSecurityException { + + final InitDataObject initData = new WebResource.InitBuilder(webResource) + .requiredBackendUser(true) + .requiredFrontendUser(false) + .requestAndResponse(request, response) + .rejectWhenNoUser(true) + .init(); + + final User user = initData.getUser(); + final boolean isAdmin = user.isAdmin(); + + Logger.debug(this, ()-> "Retrieving PublishingEndPoint for user: " + user.getUserId() + + " isAdmin: " + isAdmin + " environmentId: " + environmentId); + + return new ResponseEntityEndpointsView(this.publisherEndPointAPI.findSendingEndPointsByEnvironment(environmentId)); + } + + /** + * Get an endpoint by id + */ + @Operation(summary = "Returns the endpoint by id", + responses = { + @ApiResponse( + responseCode = "200", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = + ResponseEntityEndpointView.class)), + description = "Collection of environments.") + }) + @GET + @Path("/{endpointId}") + @Produces("application/json") + public ResponseEntityEndpointView getEndpoint(@Context HttpServletRequest request, + @Context final HttpServletResponse response, + @PathParam("endpointId") String endpointId) + throws DotDataException, JSONException { + + final InitDataObject initData = new WebResource.InitBuilder(webResource) + .requiredBackendUser(true) + .requiredFrontendUser(false) + .requestAndResponse(request, response) + .rejectWhenNoUser(true) + .init(); + + Logger.debug(this, ()-> "Retrieving PublishingEndPoint for endpointId: " + endpointId); + return new ResponseEntityEndpointView(this.publisherEndPointAPI.findEndPointById(endpointId)); + } + + /** + * Creates an endpoint and its permissions + * If the permission can not be resolved will be just skipped and logged + * + * @param httpServletRequest + * @throws Exception + */ + @Operation(summary = "Creates an endpoint", + responses = { + @ApiResponse( + responseCode = "200", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = + ResponseEntityEndpointView.class)), + description = "If creation is successfully."), + @ApiResponse( + responseCode = "403", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = + ForbiddenException.class)), + description = "If the user is not an admin or access to the configuration layout or does have permission, it will return a 403."), + @ApiResponse( + responseCode = "400", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = + IllegalArgumentException.class)), + description = "If the endpoint already exits"), + }) + @POST + @JSONP + @NoCache + @Produces({MediaType.APPLICATION_JSON, "application/javascript"}) + public final ResponseEntityEndpointView create(@Context final HttpServletRequest httpServletRequest, + @Context final HttpServletResponse httpServletResponse, + final EndpointForm endpointForm) throws DotDataException, DotSecurityException, PublishingEndPointValidationException { + + final User modUser = new WebResource.InitBuilder(webResource) + .requiredBackendUser(true) + .requiredFrontendUser(false) + .requestAndResponse(httpServletRequest, httpServletResponse) + .rejectWhenNoUser(true) + .init().getUser(); + + final boolean isRoleAdministrator = modUser.isAdmin() || + APILocator.getLayoutAPI().doesUserHaveAccessToPortlet( + PortletID.CONFIGURATION.toString(), modUser); + + if (isRoleAdministrator) { + + final PublishingEndPointAPI publisherEndPointAPI = APILocator.getPublisherEndPointAPI(); + final String endpointName = endpointForm.getName(); + final PublishingEndPoint existingServer = publisherEndPointAPI.findEndPointByName(endpointName); + + if (Objects.nonNull(existingServer)) { + + Logger.info(getClass(), "Can't save endpoint. An endpoint with the given name " + endpointName + " already exists."); + throw new IllegalArgumentException("An endpoint with the given name " + endpointName + " already exists."); + } + + Logger.debug(this, ()-> "Creating endpoint: " + endpointName); + + final String protocol = endpointForm.getProtocol(); + final PublishingEndPoint endpoint = publisherEndPointAPI.createEndPoint(protocol); + endpoint.setServerName(new StringBuilder(endpointName)); + endpoint.setAddress(endpointForm.getAddress()); + endpoint.setPort(endpointForm.getPort()); + endpoint.setProtocol(protocol); + endpoint.setAuthKey(new StringBuilder( + PublicEncryptionFactory.encryptString( + endpointForm.getAuthorizationToken()))); + endpoint.setEnabled(endpointForm.isEnabled()); + endpoint.setSending(endpointForm.isSending()); + endpoint.setGroupId(endpointForm.getEnvironmentId()); + + endpoint.validatePublishingEndPoint(); + + //Save the endpoint. + publisherEndPointAPI.saveEndPoint(endpoint); + + return new ResponseEntityEndpointView(endpoint); + } + + throw new ForbiddenException(THE_USER_KEY + modUser.getUserId() + + " does not have permissions to create an environment/endpoint"); + } // create. + + /** + * Updates an endpoint and its permissions + * If the permission can not be resolved will be just skipped and logged + * + * @param httpServletRequest + * @throws Exception + */ + @Operation(summary = "Updates an endpoint", + responses = { + @ApiResponse( + responseCode = "200", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = + ResponseEntityEndpointView.class)), + description = "If update is success."), + @ApiResponse( + responseCode = "403", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = + ForbiddenException.class)), + description = "If the user is not an admin or access to the configuration layout or does have permission, it will return a 403."), + @ApiResponse( + responseCode = "400", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = + IllegalArgumentException.class)), + description = "If the environment already exits"), + }) + @PUT + @Path("/{id}") + @JSONP + @NoCache + @Produces({MediaType.APPLICATION_JSON, "application/javascript"}) + public final ResponseEntityEndpointView update(@Context final HttpServletRequest httpServletRequest, + @Context final HttpServletResponse httpServletResponse, + @PathParam("id") final String id, + final EndpointForm endpointForm) throws DotDataException, DotSecurityException, PublishingEndPointValidationException { + + final User modUser = new WebResource.InitBuilder(webResource) + .requiredBackendUser(true) + .requiredFrontendUser(false) + .requestAndResponse(httpServletRequest, httpServletResponse) + .rejectWhenNoUser(true) + .init().getUser(); + + final boolean isRoleAdministrator = modUser.isAdmin() || + APILocator.getLayoutAPI().doesUserHaveAccessToPortlet( + PortletID.CONFIGURATION.toString(), modUser); + + if (isRoleAdministrator) { + + return updateEndpoint(httpServletRequest, id, endpointForm, modUser); + } + + throw new ForbiddenException(THE_USER_KEY + modUser.getUserId() + + " does not have permissions to update an endpoint"); + } // update. + + private ResponseEntityEndpointView updateEndpoint(final HttpServletRequest httpServletRequest, + final String id, + final EndpointForm endpointForm, + final User modUser) throws DotDataException, DotSecurityException, PublishingEndPointValidationException { + + final PublishingEndPointAPI publishingEndPointAPI = APILocator.getPublisherEndPointAPI(); + final String endpointName = endpointForm.getName(); + final PublishingEndPoint existingEndpoint = publishingEndPointAPI.findEndPointByName(endpointName); + + if (Objects.isNull(existingEndpoint) + || !existingEndpoint.getId().equals(id)) { + + Logger.info(getClass(), "Can't save EndPoint. An Endpoint with the given name already exists. "); + throw new IllegalArgumentException("An Endpoint with the given id " + id + " does not exist."); + } + + Logger.debug(this, ()-> "Updating endpoint: " + endpointName); + + final String protocol = endpointForm.getProtocol(); + final PublishingEndPoint endpoint = publishingEndPointAPI.createEndPoint(protocol); + endpoint.setId(id); + endpoint.setServerName(new StringBuilder(endpointName)); + endpoint.setAddress(endpointForm.getAddress()); + endpoint.setPort(endpointForm.getPort()); + endpoint.setProtocol(protocol); + endpoint.setAuthKey(new StringBuilder( + PublicEncryptionFactory.encryptString( + endpointForm.getAuthorizationToken()))); + endpoint.setEnabled(endpointForm.isEnabled()); + endpoint.setSending(endpointForm.isSending()); + endpoint.setGroupId(endpointForm.getEnvironmentId()); + + endpoint.validatePublishingEndPoint(); + + //Update the endpoint. + publishingEndPointAPI.updateEndPoint(endpoint); + + return new ResponseEntityEndpointView(endpoint); + } + + private static void updateSelectEnv(HttpServletRequest httpServletRequest, User modUser, Environment environment) { + if (UtilMethods.isSet(httpServletRequest.getSession().getAttribute( + WebKeys.SELECTED_ENVIRONMENTS + modUser.getUserId()))) { + + //Get the selected environments from the session + final List lastSelectedEnvironments = (List) httpServletRequest.getSession() + .getAttribute( WebKeys.SELECTED_ENVIRONMENTS + modUser.getUserId() ); + + if (Objects.nonNull(lastSelectedEnvironments)) { + for (int i = 0; i < lastSelectedEnvironments.size(); ++i) { + //Verify if the current env is on the ones stored in session + final Environment currentEnv = lastSelectedEnvironments.get(i); + if (currentEnv.getId().equals(environment.getId())) { + lastSelectedEnvironments.set(i, environment); + } + } + } + } + } + + /** + * Deletes an endpoint and its permissions + * If the permission can not be resolved will be just skipped and logged + * + * @param httpServletRequest + * @throws Exception + */ + @Operation(summary = "Deletes an endpoint", + responses = { + @ApiResponse( + responseCode = "200", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = + ResponseEntityBooleanView.class)), + description = "If deletion is successfully endpoint."), + @ApiResponse( + responseCode = "403", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = + ForbiddenException.class)), + description = "If the user is not an admin or access to the configuration layout or does have permission, it will return a 403."), + @ApiResponse( + responseCode = "404", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = + DoesNotExistException.class)), + description = "If the endpoint does not exits"), + }) + @DELETE + @Path("/{id}") + @JSONP + @NoCache + @Produces({MediaType.APPLICATION_JSON, "application/javascript"}) + public final ResponseEntityBooleanView delete(@Context final HttpServletRequest httpServletRequest, + @Context final HttpServletResponse httpServletResponse, + @PathParam("id") final String id) throws DotDataException { + + final User modUser = new WebResource.InitBuilder(webResource) + .requiredBackendUser(true) + .requiredFrontendUser(false) + .requestAndResponse(httpServletRequest, httpServletResponse) + .rejectWhenNoUser(true) + .init().getUser(); + + final boolean isRoleAdministrator = modUser.isAdmin() || + APILocator.getLayoutAPI().doesUserHaveAccessToPortlet( + PortletID.CONFIGURATION.toString(), modUser); + + if (isRoleAdministrator) { + + deleteEndpoint(httpServletRequest, id); + + return new ResponseEntityBooleanView(Boolean.TRUE); + } + + throw new ForbiddenException(THE_USER_KEY + modUser.getUserId() + + " does not have permissions to delete an endpoint"); + } // delete . + + private void deleteEndpoint(final HttpServletRequest request, final String id) throws DotDataException { + + final PublishingEndPointAPI publisherEndPointAPI = APILocator.getPublisherEndPointAPI(); + final PublishingEndPoint publishingEndPoint = publisherEndPointAPI.findEndPointById(id); + + if (Objects.isNull(publishingEndPoint)) { + + Logger.info(getClass(), "Can't delete endpoint: " + id + ". An endpoint should exists. "); + throw new DoesNotExistException("Can't delete endpoint: " + id + ". An endpoint should exists. "); + } + + Logger.debug(this, ()-> "Deleting endpoint: " + publishingEndPoint.getServerName()); + + final String environmentId = publishingEndPoint.getGroupId(); + + //Delete the end point + publisherEndPointAPI.deleteEndPointById(id); + + // if the environment is now empty, lets remove it from session + if(publisherEndPointAPI.findSendingEndPointsByEnvironment(environmentId).isEmpty()) { + //If it was deleted successfully lets remove it from session + if (UtilMethods.isSet(request.getSession().getAttribute(WebKeys.SELECTED_ENVIRONMENTS))) { + + //Get the selected environments from the session + final List lastSelectedEnvironments = (List) request.getSession().getAttribute(WebKeys.SELECTED_ENVIRONMENTS); + final Iterator environmentsIterator = lastSelectedEnvironments.iterator(); + + while (environmentsIterator.hasNext()) { + + final Environment currentEnv = environmentsIterator.next(); + //Verify if the current env is on the ones stored in session + if (currentEnv.getId().equals(environmentId)) { + //If we found it lets remove it + environmentsIterator.remove(); + } + } + } + } + } + +} diff --git a/dotCMS/src/main/java/com/dotcms/rest/ResponseEntityEndpointView.java b/dotCMS/src/main/java/com/dotcms/rest/ResponseEntityEndpointView.java new file mode 100644 index 000000000000..7a300fb13a28 --- /dev/null +++ b/dotCMS/src/main/java/com/dotcms/rest/ResponseEntityEndpointView.java @@ -0,0 +1,14 @@ +package com.dotcms.rest; + +import com.dotcms.publisher.endpoint.bean.PublishingEndPoint; + +/** + * View class for Environment/Endpoint + * @author jsanca + */ +public class ResponseEntityEndpointView extends ResponseEntityView { + + public ResponseEntityEndpointView(final PublishingEndPoint entity) { + super(entity); + } +} diff --git a/dotCMS/src/main/java/com/dotcms/rest/ResponseEntityEndpointsView.java b/dotCMS/src/main/java/com/dotcms/rest/ResponseEntityEndpointsView.java new file mode 100644 index 000000000000..c1851a408360 --- /dev/null +++ b/dotCMS/src/main/java/com/dotcms/rest/ResponseEntityEndpointsView.java @@ -0,0 +1,15 @@ +package com.dotcms.rest; + +import com.dotcms.publisher.endpoint.bean.PublishingEndPoint; + +import java.util.Collection; + +/** + * Encapsulates the data of an collectios of endpoints + * @author jsanca + */ +public class ResponseEntityEndpointsView extends ResponseEntityView> { + public ResponseEntityEndpointsView(final Collection entity) { + super(entity); + } +}