Skip to content

Commit

Permalink
ENG-66: Definition of default widgets available via PageModel api (#909)
Browse files Browse the repository at this point in the history
* ENG-66: added missing objects for default widgets definition

* ENG-66: Improvement of pageModel request converter and improvement of integration tests

* ENG-66: Improvement of pageModel service and integration tests

* ENG-66: Improvement of service and integration test

* ENG-66: Message upgrade

* ENG-66: Fix unit test
  • Loading branch information
eugeniosant committed Jun 18, 2020
1 parent ae0c501 commit b25248b
Show file tree
Hide file tree
Showing 14 changed files with 464 additions and 173 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
/*
* Copyright 2020-Present Entando Inc. (http://www.entando.com) All rights reserved.
*
* This library 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 2.1 of the License, or (at your option)
* any later version.
*
* This library 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.
*/
package org.entando.entando.aps.system.services.pagemodel.model;

import com.agiletec.aps.util.ApsProperties;
Expand All @@ -23,4 +36,5 @@ public Properties getProperties() {
public void setProperties(Properties properties) {
this.properties = properties;
}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
/*
* Copyright 2020-Present Entando Inc. (http://www.entando.com) All rights reserved.
*
* This library 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 2.1 of the License, or (at your option)
* any later version.
*
* This library 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.
*/
package org.entando.entando.aps.system.services.pagemodel.model;

import com.agiletec.aps.system.services.pagemodel.FrameSketch;

public class FrameDto {

private int pos;

private String descr;
private boolean mainFrame;
private DefaultWidgetDto defaultWidget = new DefaultWidgetDto();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
/*
* Copyright 2020-Present Entando Inc. (http://www.entando.com) All rights reserved.
*
* This library 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 2.1 of the License, or (at your option)
* any later version.
*
* This library 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.
*/
package org.entando.entando.aps.system.services.pagemodel.model;

import com.fasterxml.jackson.annotation.JsonProperty;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
/*
* Copyright 2020-Present Entando Inc. (http://www.entando.com) All rights reserved.
*
* This library 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 2.1 of the License, or (at your option)
* any later version.
*
* This library 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.
*/
package org.entando.entando.aps.system.services.pagemodel.model;

import com.fasterxml.jackson.annotation.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
/*
* Copyright 2020-Present Entando Inc. (http://www.entando.com) All rights reserved.
*
* This library 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 2.1 of the License, or (at your option)
* any later version.
*
* This library 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.
*/
package org.entando.entando.aps.system.services.pagemodel.model;

import com.agiletec.aps.system.services.page.Widget;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import io.swagger.annotations.*;
import org.entando.entando.aps.system.services.pagemodel.IPageModelService;
import org.entando.entando.aps.system.services.pagemodel.model.PageModelDto;
import org.entando.entando.aps.system.services.widgettype.model.WidgetDto;
import org.entando.entando.web.common.annotation.RestAccessControl;
import org.entando.entando.web.common.exceptions.ValidationGenericException;
import org.entando.entando.web.common.model.*;
Expand All @@ -40,6 +39,7 @@
@RestController
@RequestMapping(value = "/pageModels", produces = MediaType.APPLICATION_JSON_VALUE)
public class PageModelController {

public static final String COMPONENT_ID = "pageTemplate";

private final Logger logger = LoggerFactory.getLogger(getClass());
Expand All @@ -53,7 +53,6 @@ public PageModelController(IPageModelService pageModelService, PageModelValidato
this.pageModelValidator = pageModelValidator;
}


@ApiOperation("Retrieve multiple page templates")
@ApiResponses({
@ApiResponse(code = 200, message = "OK"),
Expand All @@ -64,16 +63,12 @@ public PageModelController(IPageModelService pageModelService, PageModelValidato
public ResponseEntity<PagedRestResponse<PageModelDto>> getPageModels(
RestListRequest requestList, @RequestParam Map<String, String> requestParams) {
logger.trace("loading page templates");

pageModelValidator.validateRestListRequest(requestList, PageModelDto.class);
PagedMetadata<PageModelDto> result = pageModelService.getPageModels(requestList, requestParams);

pageModelValidator.validateRestListResult(requestList, result);

this.pageModelValidator.validateRestListRequest(requestList, PageModelDto.class);
PagedMetadata<PageModelDto> result = this.pageModelService.getPageModels(requestList, requestParams);
this.pageModelValidator.validateRestListResult(requestList, result);
return ResponseEntity.ok(new PagedRestResponse<>(result));
}


@ApiOperation("Retrieve page template by code")
@ApiResponses({
@ApiResponse(code = 200, message = "OK"),
Expand All @@ -82,11 +77,10 @@ public ResponseEntity<PagedRestResponse<PageModelDto>> getPageModels(
@RestAccessControl(permission = Permission.MANAGE_PAGES)
@GetMapping(value = "/{code:.+}")
public ResponseEntity<SimpleRestResponse<PageModelDto>> getPageModel(@PathVariable String code) {
PageModelDto pageModelDto = pageModelService.getPageModel(code);
PageModelDto pageModelDto = this.pageModelService.getPageModel(code);
return ResponseEntity.ok(new SimpleRestResponse<>(pageModelDto));
}


@ApiOperation("Retrieve page template references")
@ApiResponses({
@ApiResponse(code = 200, message = "OK")
Expand All @@ -95,8 +89,7 @@ public ResponseEntity<SimpleRestResponse<PageModelDto>> getPageModel(@PathVariab
@GetMapping(value = "/{code:.+}/references/{manager}")
public ResponseEntity<PagedRestResponse<?>> getPageModelReferences(
@PathVariable String code, @PathVariable String manager, RestListRequest requestList) {

PagedMetadata<?> result = pageModelService.getPageModelReferences(code, manager, requestList);
PagedMetadata<?> result = this.pageModelService.getPageModelReferences(code, manager, requestList);
return ResponseEntity.ok(new PagedRestResponse<>(result));
}

Expand All @@ -108,17 +101,14 @@ public ResponseEntity<PagedRestResponse<?>> getPageModelReferences(
@RequestMapping(value = "/{code}/usage", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<SimpleRestResponse<ComponentUsage>> getComponentUsage(@PathVariable String code) {
logger.trace("get {} usage by code {}", COMPONENT_ID, code);

ComponentUsage usage = ComponentUsage.builder()
.type(COMPONENT_ID)
.code(code)
.usage(pageModelService.getComponentUsage(code))
.build();

return new ResponseEntity<>(new SimpleRestResponse<>(usage), HttpStatus.OK);
}


@ApiOperation("Retrieve pageModel usage count")
@ApiResponses({
@ApiResponse(code = 200, message = "OK"),
Expand All @@ -127,18 +117,13 @@ public ResponseEntity<SimpleRestResponse<ComponentUsage>> getComponentUsage(@Pat
@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/{code}/usage/details", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<PagedRestResponse<ComponentUsageEntity>> getComponentUsageDetails(@PathVariable String code, PageSearchRequest searchRequest) {

logger.trace("get {} usage details by code {}", COMPONENT_ID, code);

// clear filters
searchRequest.setFilters(new Filter[0]);

PagedMetadata<ComponentUsageEntity> result = pageModelService.getComponentUsageDetails(code, searchRequest);

return new ResponseEntity<>(new PagedRestResponse<>(result), HttpStatus.OK);
}


@ApiOperation("Update page template")
@ApiResponses({
@ApiResponse(code = 200, message = "OK"),
Expand All @@ -148,25 +133,21 @@ public ResponseEntity<PagedRestResponse<ComponentUsageEntity>> getComponentUsage
@PutMapping(value = "/{code:.+}", name = "roleGroup")
public ResponseEntity<SimpleRestResponse<PageModelDto>> updatePageModel(@PathVariable String code,
@Valid @RequestBody PageModelRequest pageModelRequest, BindingResult bindingResult) {

validateWithBodyName(code, pageModelRequest, bindingResult);

PageModelDto pageModel = pageModelService.updatePageModel(pageModelRequest);
this.validateWithBodyName(code, pageModelRequest, bindingResult);
PageModelDto pageModel = this.pageModelService.updatePageModel(pageModelRequest);
return ResponseEntity.ok(new SimpleRestResponse<>(pageModel));
}

private void validateWithBodyName(String code, PageModelRequest pageModelRequest, BindingResult bindingResult) {

if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
pageModelValidator.validateBodyName(code, pageModelRequest, bindingResult);
this.pageModelValidator.validateBodyName(code, pageModelRequest, bindingResult);
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
}


@ApiOperation("Add page template")
@ApiResponses({
@ApiResponse(code = 200, message = "OK"),
Expand All @@ -177,9 +158,7 @@ private void validateWithBodyName(String code, PageModelRequest pageModelRequest
@PostMapping
public ResponseEntity<SimpleRestResponse<PageModelDto>> addPageModel(
@Valid @RequestBody PageModelRequest pagemodelRequest, BindingResult bindingResult) {

validatePageModelRequest(pagemodelRequest, bindingResult);

this.validatePageModelRequest(pagemodelRequest, bindingResult);
PageModelDto dto = pageModelService.addPageModel(pagemodelRequest);
return ResponseEntity.ok(new SimpleRestResponse<>(dto));
}
Expand All @@ -188,13 +167,12 @@ private void validatePageModelRequest(@RequestBody @Valid PageModelRequest pagem
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
pageModelValidator.validate(pagemodelRequest, bindingResult);
this.pageModelValidator.validate(pagemodelRequest, bindingResult);
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
}


@ApiOperation("Delete page template")
@ApiResponses({
@ApiResponse(code = 200, message = "OK")
Expand All @@ -203,8 +181,9 @@ private void validatePageModelRequest(@RequestBody @Valid PageModelRequest pagem
@DeleteMapping(value = "/{code:.+}")
public ResponseEntity<SimpleRestResponse<Map>> deletePageModel(@PathVariable String code) {
logger.debug("deleting {}", code);
pageModelService.removePageModel(code);
this.pageModelService.removePageModel(code);
Map<String, String> result = ImmutableMap.of("code", code);
return ResponseEntity.ok(new SimpleRestResponse<>(result));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2020-Present Entando Inc. (http://www.entando.com) All rights reserved.
*
* This library 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 2.1 of the License, or (at your option)
* any later version.
*
* This library 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.
*/
package org.entando.entando.web.pagemodel.model;

import java.util.HashMap;
import java.util.Map;

public class DefaultWidgetReq {

private String code;
private Map<String, String> properties = new HashMap<>();

public String getCode() {
return code;
}

public void setCode(String code) {
this.code = code;
}

public Map getProperties() {
return properties;
}

public void setProperties(Map properties) {
this.properties = properties;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class PageModelFrameReq {

private boolean mainFrame;
private FrameSketch sketch;
private DefaultWidgetReq defaultWidget = new DefaultWidgetReq();

public PageModelFrameReq() {

Expand Down Expand Up @@ -72,4 +73,12 @@ public void setSketch(FrameSketch sketch) {
this.sketch = sketch;
}

public DefaultWidgetReq getDefaultWidget() {
return defaultWidget;
}

public void setDefaultWidget(DefaultWidgetReq defaultWidget) {
this.defaultWidget = defaultWidget;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@
*/
package org.entando.entando.web.pagemodel.validator;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;
import org.entando.entando.aps.system.services.pagemodel.model.PageModelDto;
import org.entando.entando.web.common.validator.AbstractPaginationValidator;
import org.entando.entando.web.pagemodel.model.PageModelFrameReq;
import org.entando.entando.web.pagemodel.model.PageModelRequest;
Expand All @@ -34,6 +32,8 @@ public class PageModelValidator extends AbstractPaginationValidator {
public static final String ERRCODE_PAGEMODEL_REFERENCES = "3";
public static final String ERRCODE_URINAME_MISMATCH = "4";
public static final String ERRCODE_FRAMES_POS_MISMATCH = "5";
public static final String ERRCODE_DEFAULT_WIDGET_NOT_EXISTS = "6";
public static final String ERRCODE_DEFAULT_WIDGET_INVALID_PARAMETER = "7";

@Override
public boolean supports(Class<?> paramClass) {
Expand Down
2 changes: 2 additions & 0 deletions engine/src/main/resources/rest/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ pageModel.code.exists=The page template ''{0}'' already exists
pageModel.frames.pos.mismatch=frame position should be zero based and progressive
pageModel.code.mismatch=the code specified the URI ''{0}'' does not match with the one provided in the payload ''{1}''
pageModel.cannot.delete.references=The page template ''{0}'' can not be deleted due to references
pageModel.defaultWidget.notExists=Default widget ''{0}'' specified in frame ''{1}'' does not exists
pageModel.defaultWidget.invalidParameter=Parameter ''{0}'' of default Widget ''{1}'' specified in frame ''{2}'' is invalid
#pageModel.update.patch.invalid.generic=The provided patch for pageModel ''{0}'' is not valid
#pageModel.update.patch.invalid.code=The provided JSON patch can not contain operations on the code property

Expand Down

0 comments on commit b25248b

Please sign in to comment.