Search in sources :

Example 6 with PrivilegeDescription

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

the class FunctionResource method callUploadFunction.

@Timed
@PostMapping(value = "/functions/**" + UPLOAD, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
@PreAuthorize("hasPermission({'functionKey': #functionKey}, 'FUNCTION.UPLOAD.CALL')")
@SneakyThrows
@PrivilegeDescription("Privilege to call upload function")
public ResponseEntity<Object> callUploadFunction(HttpServletRequest request, @RequestParam(value = "file", required = false) List<MultipartFile> files, HttpServletRequest httpServletRequest) {
    Map<String, Object> functionInput = of("httpServletRequest", httpServletRequest, "files", files);
    String functionKey = getFunctionKey(request);
    functionKey = functionKey.substring(0, functionKey.length() - UPLOAD.length());
    FunctionContext result = functionService.execute(functionKey, functionInput, "POST");
    return ResponseEntity.ok().body(result.functionResult());
}
Also used : FunctionContext(com.icthh.xm.ms.entity.domain.FunctionContext) PostMapping(org.springframework.web.bind.annotation.PostMapping) Timed(com.codahale.metrics.annotation.Timed) SneakyThrows(lombok.SneakyThrows) PrivilegeDescription(com.icthh.xm.commons.permission.annotation.PrivilegeDescription) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 7 with PrivilegeDescription

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

the class CalendarResource method getCalendarEvents.

/**
 * GET  /calendars/{id}/events : get events for specific calendar.
 *
 * @param calendarId the id of the calendar to retrieve events
 * @return the ResponseEntity with status 200 (OK) and with body events
 */
@GetMapping("/calendars/{calendarId}/events")
@Timed
@PreAuthorize("hasPermission({'calendarId': #calendarId}, 'calendar', 'CALENDAR.GET_LIST.ITEM.EVENTS')")
@PrivilegeDescription("Privilege to get events for specific calendar")
public ResponseEntity<List<Event>> getCalendarEvents(@PathVariable Long calendarId, EventFilter filter, Pageable pageable) {
    Page<Event> page = calendarService.findEvents(calendarId, filter, pageable);
    HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/calendars/{id}/events");
    return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) Event(com.icthh.xm.ms.entity.domain.Event) 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 8 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
@PostMapping("/xm-entities/self/avatar")
@PreAuthorize("hasPermission({'multipartFile': #multipartFile}, 'XMENTITY.SELF.AVATAR.UPDATE')")
@PrivilegeDescription("Privilege to update avatar of current user")
public ResponseEntity<Void> updateSelfAvatar(@RequestParam("file") MultipartFile multipartFile) throws IOException {
    HttpEntity<Resource> avatarEntity = XmHttpEntityUtils.buildAvatarHttpEntity(multipartFile);
    URI uri = xmEntityService.updateAvatar(IdOrKey.SELF, 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 9 with PrivilegeDescription

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

the class XmEntityResource method searchXmEntities.

/**
 * SEARCH  /_search/xm-entities?query=:query : search for the xmEntity corresponding to the query.
 *
 * @param query    the query of the xmEntity search
 * @param pageable the pagination information
 * @return the result of the search
 */
@GetMapping("/_search/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>> searchXmEntities(@RequestParam String query, @ApiParam Pageable pageable) {
    Page<XmEntity> page = xmEntityService.search(query, pageable, 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) 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 10 with PrivilegeDescription

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

the class XmEntityResource method searchByTypeKeyAndQuery.

@GetMapping("/_search-with-typekey/xm-entities")
@Timed
@PreAuthorize("hasPermission({'typeKey': #typeKey, 'query': #query}, 'XMENTITY.SEARCH.TYPEKEY.QUERY')")
@PrivilegeDescription("Privilege to search for the xmEntity corresponding to the query(not required) and typeKey")
public ResponseEntity<List<XmEntity>> searchByTypeKeyAndQuery(@RequestParam String typeKey, @RequestParam(required = false) String query, @ApiParam Pageable pageable) {
    Page<XmEntity> page = xmEntityService.searchByQueryAndTypeKey(query, typeKey, pageable, null);
    HttpHeaders headers = PaginationUtil.generateSearchByTypeKeyPaginationHttpHeaders(typeKey, query, page, "/api/_search-with-typekey/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