Search in sources :

Example 11 with PrivilegeDescription

use of com.icthh.xm.commons.permission.annotation.PrivilegeDescription in project xm-ms-entity by xm-online.

the class XmEntityResource method updateSelfAvatar.

// TODO remove this method after deal with hasPermission check for self
@Timed
@PutMapping(path = "/xm-entities/self/avatar", consumes = "image/*")
@PreAuthorize("hasPermission({'fileName':#fileName, 'request':#request}, 'XMENTITY.SELF.AVATAR.UPDATE')")
@PrivilegeDescription("Privilege to update avatar of current user")
public ResponseEntity<Void> updateSelfAvatar(@RequestHeader(value = XM_HEADER_CONTENT_NAME, required = false) String fileName, HttpServletRequest request) throws IOException {
    HttpEntity<Resource> avatarEntity = XmHttpEntityUtils.buildAvatarHttpEntity(request, fileName);
    URI uri = xmEntityService.updateAvatar(IdOrKey.SELF, avatarEntity);
    return buildAvatarUpdateResponse(uri);
}
Also used : Resource(org.springframework.core.io.Resource) URI(java.net.URI) Timed(com.codahale.metrics.annotation.Timed) PutMapping(org.springframework.web.bind.annotation.PutMapping) PrivilegeDescription(com.icthh.xm.commons.permission.annotation.PrivilegeDescription) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 12 with PrivilegeDescription

use of com.icthh.xm.commons.permission.annotation.PrivilegeDescription in project xm-ms-entity by xm-online.

the class XmEntityResource method searchXmEntitiesToLink.

@Timed
@GetMapping("/xm-entities/{entityTypeKey}/{idOrKey}/links/{linkTypeKey}/search")
@PreAuthorize("hasPermission({'query': #query}, 'XMENTITY.SEARCH.TO_LINK.QUERY')")
@PrivilegeDescription("Privilege to search candidates for link with specified XmEntity")
public ResponseEntity<List<XmEntity>> searchXmEntitiesToLink(@PathVariable String idOrKey, @PathVariable String entityTypeKey, @PathVariable String linkTypeKey, @RequestParam String query, @ApiParam Pageable pageable) {
    Page<XmEntity> page = xmEntityService.searchXmEntitiesToLink(IdOrKey.of(idOrKey), entityTypeKey, linkTypeKey, query, pageable, null);
    HttpHeaders headers = PaginationUtil.generateSearchPaginationHttpHeaders(query, page, String.format("/api/xm-entities/%s/%s/links/%s/search", entityTypeKey, idOrKey, linkTypeKey));
    return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) GetMapping(org.springframework.web.bind.annotation.GetMapping) Timed(com.codahale.metrics.annotation.Timed) PrivilegeDescription(com.icthh.xm.commons.permission.annotation.PrivilegeDescription) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 13 with PrivilegeDescription

use of com.icthh.xm.commons.permission.annotation.PrivilegeDescription in project xm-ms-entity by xm-online.

the class XmEntityResource method searchXmEntitiesV2.

@GetMapping("/_search/v2/xm-entities")
@Timed
@PreAuthorize("hasPermission({'query': #query}, 'XMENTITY.SEARCH.QUERY')")
@PrivilegeDescription("Privilege to search for the xmEntity corresponding to the query")
public ResponseEntity<List<XmEntity>> searchXmEntitiesV2(@RequestParam String query, @ApiParam Pageable pageable, @ApiParam ElasticFetchSourceFilterDto fetchSourceFilterDto) {
    SearchDto searchDto = SearchDto.builder().query(query).pageable(pageable).entityClass(XmEntity.class).fetchSourceFilter(new FetchSourceFilter(fetchSourceFilterDto.getIncludes(), fetchSourceFilterDto.getExcludes())).build();
    Page<XmEntity> page = xmEntityService.searchV2(searchDto, null);
    HttpHeaders headers = PaginationUtil.generateSearchPaginationHttpHeaders(query, page, "/api/_search/xm-entities");
    return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) FetchSourceFilter(org.springframework.data.elasticsearch.core.query.FetchSourceFilter) SearchDto(com.icthh.xm.ms.entity.service.dto.SearchDto) XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) GetMapping(org.springframework.web.bind.annotation.GetMapping) Timed(com.codahale.metrics.annotation.Timed) PrivilegeDescription(com.icthh.xm.commons.permission.annotation.PrivilegeDescription) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 14 with PrivilegeDescription

use of com.icthh.xm.commons.permission.annotation.PrivilegeDescription in project xm-ms-entity by xm-online.

the class XmEntityResource method updateAvatar.

/**
 * Multipart update avatar.
 *
 * @param idOrKey       id or key of XmEntity
 * @param multipartFile multipart file with avatar
 * @return HTTP response
 * @throws IOException when IO error
 */
@Timed
@PostMapping("/xm-entities/{idOrKey}/avatar")
@PreAuthorize("hasPermission({'idOrKey':#idOrKey, 'multipartFile':#multipartFile}, 'XMENTITY.AVATAR.UPDATE')")
@PrivilegeDescription("Privilege to update avatar")
public ResponseEntity<Void> updateAvatar(@PathVariable String idOrKey, @RequestParam("file") MultipartFile multipartFile) throws IOException {
    HttpEntity<Resource> avatarEntity = XmHttpEntityUtils.buildAvatarHttpEntity(multipartFile);
    URI uri = xmEntityService.updateAvatar(IdOrKey.of(idOrKey), avatarEntity);
    return buildAvatarUpdateResponse(uri);
}
Also used : Resource(org.springframework.core.io.Resource) URI(java.net.URI) PostMapping(org.springframework.web.bind.annotation.PostMapping) Timed(com.codahale.metrics.annotation.Timed) PrivilegeDescription(com.icthh.xm.commons.permission.annotation.PrivilegeDescription) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 15 with PrivilegeDescription

use of com.icthh.xm.commons.permission.annotation.PrivilegeDescription in project xm-ms-entity by xm-online.

the class XmEntityResource method searchXmEntities.

@GetMapping("/_search-with-template/xm-entities")
@Timed
@PreAuthorize("hasPermission({'template': #template}, 'XMENTITY.SEARCH.TEMPLATE')")
@PrivilegeDescription("Privilege to search for the xmEntity by query template")
public ResponseEntity<List<XmEntity>> searchXmEntities(@RequestParam String template, @ApiParam TemplateParamsHolder templateParamsHolder, @ApiParam Pageable pageable) {
    Page<XmEntity> page = xmEntityService.search(template, templateParamsHolder, pageable, null);
    HttpHeaders headers = PaginationUtil.generateSearchWithTemplatePaginationHttpHeaders(template, templateParamsHolder, page, "/api/_search-with-template/xm-entities");
    return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) GetMapping(org.springframework.web.bind.annotation.GetMapping) Timed(com.codahale.metrics.annotation.Timed) PrivilegeDescription(com.icthh.xm.commons.permission.annotation.PrivilegeDescription) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

PrivilegeDescription (com.icthh.xm.commons.permission.annotation.PrivilegeDescription)16 Timed (com.codahale.metrics.annotation.Timed)15 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)15 HttpHeaders (org.springframework.http.HttpHeaders)8 XmEntity (com.icthh.xm.ms.entity.domain.XmEntity)7 ResponseEntity (org.springframework.http.ResponseEntity)7 GetMapping (org.springframework.web.bind.annotation.GetMapping)7 PostMapping (org.springframework.web.bind.annotation.PostMapping)6 URI (java.net.URI)5 Resource (org.springframework.core.io.Resource)4 FunctionContext (com.icthh.xm.ms.entity.domain.FunctionContext)2 PutMapping (org.springframework.web.bind.annotation.PutMapping)2 LogicExtensionPoint (com.icthh.xm.commons.lep.LogicExtensionPoint)1 FindWithPermission (com.icthh.xm.commons.permission.annotation.FindWithPermission)1 Event (com.icthh.xm.ms.entity.domain.Event)1 LinkSpec (com.icthh.xm.ms.entity.domain.spec.LinkSpec)1 LinkProjection (com.icthh.xm.ms.entity.projection.LinkProjection)1 SearchDto (com.icthh.xm.ms.entity.service.dto.SearchDto)1 SneakyThrows (lombok.SneakyThrows)1 FetchSourceFilter (org.springframework.data.elasticsearch.core.query.FetchSourceFilter)1