Search in sources :

Example 91 with XmEntity

use of com.icthh.xm.ms.entity.domain.XmEntity 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
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)

Example 92 with XmEntity

use of com.icthh.xm.ms.entity.domain.XmEntity in project xm-ms-entity by xm-online.

the class XmEntitySpecResource method generateXmEntity.

/**
 * POST  /xm-entity-specs/generate-xm-entity : Generate a new xmEntity.
 *
 * @return the ResponseEntity with status 201 (Created) and with body the new xmEntity
 * @throws URISyntaxException if the Location URI syntax is incorrect
 */
@PostMapping("/xm-entity-specs/generate-xm-entity")
@Timed
@PreAuthorize("hasPermission({'rootTypeKey': #rootTypeKey}, 'XMENTITY_SPEC.GENERATE')")
public ResponseEntity<XmEntity> generateXmEntity(@ApiParam String rootTypeKey) throws URISyntaxException {
    log.debug("REST request to generate XmEntity");
    XmEntity result = xmEntityGeneratorService.generateXmEntity(rootTypeKey != null ? rootTypeKey : "");
    return ResponseEntity.created(new URI("/api/xm-entities/" + result.getId())).headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString())).body(result);
}
Also used : XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) URI(java.net.URI) PostMapping(org.springframework.web.bind.annotation.PostMapping) Timed(com.codahale.metrics.annotation.Timed) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 93 with XmEntity

use of com.icthh.xm.ms.entity.domain.XmEntity in project xm-ms-entity by xm-online.

the class XmEntityUtils method getRequiredLinkedTarget.

public static XmEntity getRequiredLinkedTarget(XmEntity xmEntity, String targetTypeKey) {
    Optional<Link> linkOpt = getLink(xmEntity, targetTypeKey);
    XmEntity target = linkOpt.orElseThrow(() -> new BusinessException("Can't find linkOpt with target type key: " + targetTypeKey)).getTarget();
    return Objects.requireNonNull(target, "Target in link with typeKey: " + targetTypeKey + " is null");
}
Also used : BusinessException(com.icthh.xm.commons.exceptions.BusinessException) XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) Link(com.icthh.xm.ms.entity.domain.Link)

Example 94 with XmEntity

use of com.icthh.xm.ms.entity.domain.XmEntity in project xm-ms-entity by xm-online.

the class FunctionServiceImpl method toFunctionContext.

private FunctionContext toFunctionContext(String functionKey, IdOrKey idOrKey, Map<String, Object> data) {
    XmEntity xmEntity = (idOrKey != null) ? xmEntityService.findOne(idOrKey) : null;
    FunctionContext functionResult = new FunctionContext();
    // TODO review key & typeKey ...
    functionResult.setKey(functionKey + "-" + UUID.randomUUID().toString());
    functionResult.setTypeKey(functionKey);
    functionResult.setData(data);
    functionResult.setStartDate(Instant.now());
    functionResult.setUpdateDate(functionResult.getStartDate());
    functionResult.setXmEntity(xmEntity);
    return functionResult;
}
Also used : XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) FunctionContext(com.icthh.xm.ms.entity.domain.FunctionContext)

Example 95 with XmEntity

use of com.icthh.xm.ms.entity.domain.XmEntity in project xm-ms-entity by xm-online.

the class XmEntityServiceImpl method saveLinkTarget.

@LogicExtensionPoint("SaveLinkTarget")
@Override
public Link saveLinkTarget(IdOrKey idOrKey, Link link, MultipartFile file) {
    // resolve source entity by idOrKey
    XmEntity source = toSourceXmEntity(idOrKey);
    // resolve target entity by key
    XmEntity target = findOne(toIdOrKey(link.getTarget()));
    // save link
    link.setSource(source);
    link.setTarget(target);
    link.setStartDate(Instant.now());
    Link savedLink = linkService.save(link);
    log.debug("Link saved with id {}", link.getId());
    // save file to storage and attachment
    if (file != null) {
        addFileAttachment(savedLink.getTarget(), file);
    }
    return savedLink;
}
Also used : XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) Link(com.icthh.xm.ms.entity.domain.Link) LogicExtensionPoint(com.icthh.xm.commons.lep.LogicExtensionPoint)

Aggregations

XmEntity (com.icthh.xm.ms.entity.domain.XmEntity)102 Test (org.junit.Test)60 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)46 Transactional (org.springframework.transaction.annotation.Transactional)32 Link (com.icthh.xm.ms.entity.domain.Link)22 Tag (com.icthh.xm.ms.entity.domain.Tag)10 ConstraintViolation (javax.validation.ConstraintViolation)9 WithMockUser (org.springframework.security.test.context.support.WithMockUser)9 MvcResult (org.springframework.test.web.servlet.MvcResult)9 HashMap (java.util.HashMap)8 Map (java.util.Map)8 SneakyThrows (lombok.SneakyThrows)8 Attachment (com.icthh.xm.ms.entity.domain.Attachment)7 Location (com.icthh.xm.ms.entity.domain.Location)7 lombok.val (lombok.val)7 Calendar (com.icthh.xm.ms.entity.domain.Calendar)6 Profile (com.icthh.xm.ms.entity.domain.Profile)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 Rating (com.icthh.xm.ms.entity.domain.Rating)5 Timed (com.codahale.metrics.annotation.Timed)4