use of org.entando.entando.aps.system.services.group.model.GroupDto in project entando-core by entando.
the class GroupController method getGroups.
@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> getGroups(RestListRequest requestList) throws JsonProcessingException {
this.getGroupValidator().validateRestListRequest(requestList);
PagedMetadata<GroupDto> result = this.getGroupService().getGroups(requestList);
this.getGroupValidator().validateRestListResult(requestList, result);
logger.debug("Main Response -> {}", result);
return new ResponseEntity<>(new RestResponse(result.getBody(), null, result), HttpStatus.OK);
}
use of org.entando.entando.aps.system.services.group.model.GroupDto in project entando-core by entando.
the class GroupController method updateGroup.
@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/{groupCode}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> updateGroup(@PathVariable String groupCode, @Valid @RequestBody GroupRequest groupRequest, BindingResult bindingResult) {
// field validations
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
this.getGroupValidator().validateBodyName(groupCode, groupRequest, bindingResult);
if (bindingResult.hasErrors()) {
throw new ValidationGenericException(bindingResult);
}
GroupDto group = this.getGroupService().updateGroup(groupCode, groupRequest.getName());
return new ResponseEntity<>(new RestResponse(group), HttpStatus.OK);
}
use of org.entando.entando.aps.system.services.group.model.GroupDto in project entando-core by entando.
the class GroupService method getGroups.
@SuppressWarnings("rawtypes")
@Override
public PagedMetadata<GroupDto> getGroups(RestListRequest restListReq) {
try {
// transforms the filters by overriding the key specified in the request with the correct one known by the dto
List<FieldSearchFilter> filters = new ArrayList<FieldSearchFilter>(restListReq.buildFieldSearchFilters());
filters.stream().filter(i -> i.getKey() != null).forEach(i -> i.setKey(GroupDto.getEntityFieldName(i.getKey())));
SearcherDaoPaginatedResult<Group> groups = this.getGroupManager().getGroups(filters);
List<GroupDto> dtoList = dtoBuilder.convert(groups.getList());
PagedMetadata<GroupDto> pagedMetadata = new PagedMetadata<>(restListReq, groups);
pagedMetadata.setBody(dtoList);
return pagedMetadata;
} catch (Throwable t) {
logger.error("error in search groups", t);
throw new RestServerError("error in search groups", t);
}
}
use of org.entando.entando.aps.system.services.group.model.GroupDto in project entando-core by entando.
the class GroupService method getGroup.
@Override
public GroupDto getGroup(String groupCode) {
Group group = this.getGroupManager().getGroup(groupCode);
if (null == group) {
logger.warn("no group found with code {}", groupCode);
throw new RestRourceNotFoundException(GroupValidator.ERRCODE_GROUP_NOT_FOUND, "group", groupCode);
}
GroupDto dto = this.getDtoBuilder().convert(group);
dto.setReferences(this.getReferencesInfo(group));
return dto;
}
use of org.entando.entando.aps.system.services.group.model.GroupDto in project entando-core by entando.
the class GroupControllerIntegrationTest method testAddExistingGroup.
@Test
public void testAddExistingGroup() throws Exception {
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
GroupDto group = this.groupService.getGroup(Group.FREE_GROUP_NAME);
GroupRequest groupRequest = new GroupRequest();
groupRequest.setCode(group.getCode());
groupRequest.setName(group.getName());
ObjectMapper mapper = new ObjectMapper();
String payload = mapper.writeValueAsString(groupRequest);
ResultActions result = mockMvc.perform(post("/groups").content(payload).contentType(MediaType.APPLICATION_JSON_VALUE).header("Authorization", "Bearer " + accessToken));
// System.out.println(result.andReturn().getResponse().getContentAsString());
result.andExpect(status().isConflict());
}
Aggregations