Search in sources :

Example 1 with PrivilegeDescription

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);
}
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 2 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-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);
}
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 3 with PrivilegeDescription

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);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) 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 4 with PrivilegeDescription

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);
}
Also used : LinkSpec(com.icthh.xm.ms.entity.domain.spec.LinkSpec) LinkProjection(com.icthh.xm.ms.entity.projection.LinkProjection) FindWithPermission(com.icthh.xm.commons.permission.annotation.FindWithPermission) LogicExtensionPoint(com.icthh.xm.commons.lep.LogicExtensionPoint) PrivilegeDescription(com.icthh.xm.commons.permission.annotation.PrivilegeDescription) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with PrivilegeDescription

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;
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) FunctionContext(com.icthh.xm.ms.entity.domain.FunctionContext) 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)

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