use of com.icthh.xm.commons.permission.annotation.PrivilegeDescription in project xm-ms-entity by xm-online.
the class XmEntityResource method updateAvatar.
/**
* Update avatar with simple PUT HTTP request.
*
* @param idOrKey id or key of XmEntity
* @param fileName avatar file name
* @param request HTTP servlet request
* @return HTTP response
* @throws IOException when IO error
*/
@Timed
@PutMapping(path = "/xm-entities/{idOrKey}/avatar", consumes = "image/*")
@PreAuthorize("hasPermission({'idOrKey':#idOrKey, 'fileName':#fileName, 'request':#request}, 'XMENTITY.AVATAR.UPDATE')")
@PrivilegeDescription("Privilege to update avatar")
public ResponseEntity<Void> updateAvatar(@PathVariable String idOrKey, @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.of(idOrKey), avatarEntity);
return buildAvatarUpdateResponse(uri);
}
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-and-template/xm-entities")
@Timed
@PreAuthorize("hasPermission({'typeKey': #typeKey, 'template': #template}, 'XMENTITY.SEARCH.TYPEKEY.TEMPLATE')")
@PrivilegeDescription("Privilege to search for the xmEntity corresponding to the template(not required) and typeKey")
public ResponseEntity<List<XmEntity>> searchByTypeKeyAndQuery(@RequestParam String typeKey, @RequestParam(required = false) String template, @ApiParam TemplateParamsHolder templateParamsHolder, @ApiParam Pageable pageable) {
Page<XmEntity> page = xmEntityService.searchByQueryAndTypeKey(template, templateParamsHolder, typeKey, pageable, null);
HttpHeaders headers = PaginationUtil.generateSearchByTypeKeyWithTemplatePaginationHttpHeaders(typeKey, template, templateParamsHolder, page, "/api/_search-with-typekey-and-template/xm-entities");
return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}
use of com.icthh.xm.commons.permission.annotation.PrivilegeDescription in project xm-ms-entity by xm-online.
the class ExportImportResource method exportXmEntities.
@Timed
@PreAuthorize("hasPermission({'exportDto': #exportDto}, 'XMENTITY.EXPORT')")
@PrivilegeDescription("Privilege to export xmEntities by export specification")
@PostMapping("/export/xm-entities")
public ResponseEntity<byte[]> exportXmEntities(@RequestBody Set<ExportDto> exportDto) {
byte[] media = exportImportService.exportEntities(exportDto);
HttpHeaders headers = new HttpHeaders();
headers.setCacheControl(CacheControl.noCache().getHeaderValue());
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
headers.set("Content-Disposition", "attachment; filename=export.json");
return ResponseEntity.ok().contentLength(media.length).headers(headers).body(media);
}
use of com.icthh.xm.commons.permission.annotation.PrivilegeDescription in project xm-ms-entity by xm-online.
the class XmEntityServiceImpl method searchXmEntitiesToLink.
@LogicExtensionPoint("SearchXmEntitiesToLink")
@Override
@Transactional(readOnly = true)
@FindWithPermission("XMENTITY.SEARCH")
@PrivilegeDescription("Privilege to search for the xmEntity corresponding to the query")
public Page<XmEntity> searchXmEntitiesToLink(IdOrKey idOrKey, String entityTypeKey, String linkTypeKey, String query, Pageable pageable, String privilegeKey) {
LinkSpec linkSpec = xmEntitySpecService.getLinkSpec(entityTypeKey, linkTypeKey).orElseThrow(() -> new IllegalArgumentException("Invalid entity typeKey ot link typeKey"));
if (!TRUE.equals(linkSpec.getIsUnique())) {
return self.search(query, pageable, privilegeKey);
}
Long id;
if (idOrKey.isId()) {
id = idOrKey.getId();
} else {
id = getXmEntityIdKeyTypeKey(idOrKey).getId();
}
List<LinkProjection> links = linkService.findLinkProjectionsBySourceIdAndTypeKey(id, linkTypeKey);
Set<Long> ids = links.stream().map(LinkProjection::getTarget).map(XmEntityId::getId).collect(toSet());
ids = new HashSet<>(ids);
ids.add(id);
return xmEntityPermittedSearchRepository.searchWithIdNotIn(query, ids, linkSpec.getTypeKey(), pageable, privilegeKey);
}
use of com.icthh.xm.commons.permission.annotation.PrivilegeDescription in project xm-ms-entity by xm-online.
the class FunctionResource method callMvcFunction.
/**
* POST /functions/mvc/{functionKey} : Execute a mvc function by key (key in entity specification).
*
* @param functionKey the function key to execute
* @param functionInput function input data context
* @return ModelAndView object
*/
@Timed
@PostMapping("/functions/mvc/{functionKey:.+}")
@PreAuthorize("hasPermission({'functionKey': #functionKey}, 'FUNCTION.MVC.CALL')")
@PrivilegeDescription("Privilege to execute a mvc function by key (key in entity specification)")
public ModelAndView callMvcFunction(@PathVariable("functionKey") String functionKey, @RequestBody(required = false) Map<String, Object> functionInput) {
FunctionContext result = functionService.execute(functionKey, functionInput, "POST");
Object data = result.getData().get("modelAndView");
if (data instanceof ModelAndView) {
return (ModelAndView) data;
}
return null;
}
Aggregations