Search in sources :

Example 6 with Link

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

the class XmEntityServiceImpl method deleteLinkTarget.

@Override
public void deleteLinkTarget(IdOrKey idOrKey, String linkId) {
    XmEntity source = toSourceXmEntity(idOrKey);
    Long longLinkId = Long.parseLong(linkId);
    Link foundLink = linkService.findOne(longLinkId);
    if (foundLink == null) {
        throw new IllegalArgumentException("Link not found by id " + linkId);
    }
    Long foundSourceId = foundLink.getSource().getId();
    if (!foundSourceId.equals(source.getId())) {
        throw new BusinessException("Wrong source id. Expected " + source.getId() + " found " + foundSourceId);
    }
    log.debug("Delete link by id " + linkId);
    linkService.delete(longLinkId);
}
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 7 with Link

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

the class XmEntityUtils method getLinkedTarget.

public static Optional<XmEntity> getLinkedTarget(XmEntity xmEntity, String linkTypeKey, String linkTargetTypeKey) {
    Optional<Link> firstLink = findFirstLink(xmEntity, linkTypeKey);
    if (firstLink.isPresent()) {
        Link link = firstLink.get();
        XmEntity target = Objects.requireNonNull(link.getTarget(), "Link with type key '" + linkTypeKey + "' has null target");
        if (Objects.equals(target.getTypeKey(), linkTargetTypeKey)) {
            return Optional.of(target);
        }
    }
    return Optional.empty();
}
Also used : XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) Link(com.icthh.xm.ms.entity.domain.Link)

Example 8 with Link

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

the class LinkResource method getAllLinks.

/**
 * GET  /links : get all the links.
 *
 * @param pageable the pagination information
 * @return the ResponseEntity with status 200 (OK) and the list of links in body
 */
@GetMapping("/links")
@Timed
public ResponseEntity<List<Link>> getAllLinks(@ApiParam Pageable pageable) {
    Page<Link> page = linkService.findAll(pageable, null);
    HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/links");
    return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) Link(com.icthh.xm.ms.entity.domain.Link) GetMapping(org.springframework.web.bind.annotation.GetMapping) Timed(com.codahale.metrics.annotation.Timed)

Example 9 with Link

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

the class LinkResource method searchLinks.

/**
 * SEARCH  /_search/links?query=:query : search for the link corresponding
 * to the query.
 *
 * @param query the query of the link search
 * @param pageable the pagination information
 * @return the result of the search
 */
@GetMapping("/_search/links")
@Timed
public ResponseEntity<List<Link>> searchLinks(@RequestParam String query, @ApiParam Pageable pageable) {
    Page<Link> page = linkService.search(query, pageable, null);
    HttpHeaders headers = PaginationUtil.generateSearchPaginationHttpHeaders(query, page, "/api/_search/links");
    return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) Link(com.icthh.xm.ms.entity.domain.Link) GetMapping(org.springframework.web.bind.annotation.GetMapping) Timed(com.codahale.metrics.annotation.Timed)

Example 10 with Link

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

the class XmEntityResourceExtendedIntTest method createXmEntityWithSourceLinks.

@Test
@Transactional
public void createXmEntityWithSourceLinks() throws Exception {
    XmEntity presaved = xmEntityService.save(createEntity(em));
    int databaseSizeBeforeCreate = xmEntityRepository.findAll().size();
    XmEntity entity = xmEntityIncoming;
    entity.setSources(Collections.singleton(new Link().typeKey(DEFAULT_LN_TARGET_KEY).name(DEFAULT_LN_TARGET_NAME).startDate(DEFAULT_LN_TARGET_START_DATE).source(presaved)));
    // Create the XmEntity with tag
    MvcResult result = performPost("/api/xm-entities", entity).andExpect(status().isCreated()).andExpect(jsonPath("$.key").value(DEFAULT_KEY)).andReturn();
    Integer id = JsonPath.read(result.getResponse().getContentAsString(), "$.id");
    em.detach(presaved);
    List<XmEntity> xmEntityList = validateEntityInDB(databaseSizeBeforeCreate + 1);
    XmEntity testXmEntity = xmEntityList.get(xmEntityList.size() - 1);
    presaved = xmEntityService.findOne(IdOrKey.of(presaved.getId()));
    // Get the xmEntityPersisted with tag by ID
    performGet("/api/xm-entities/{id}", presaved.getId()).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)).andExpect(jsonPath("$.id").value(presaved.getId())).andExpect(jsonPath("$.key").value(DEFAULT_KEY)).andExpect(jsonPath("$.typeKey").value(DEFAULT_TYPE_KEY)).andExpect(jsonPath("$.stateKey").value(DEFAULT_STATE_KEY)).andExpect(jsonPath("$.name").value(DEFAULT_NAME)).andExpect(jsonPath("$.startDate").value(sameInstant(MOCKED_START_DATE))).andExpect(jsonPath("$.updateDate").value(sameInstant(MOCKED_UPDATE_DATE))).andExpect(jsonPath("$.endDate").value(sameInstant(DEFAULT_END_DATE))).andExpect(jsonPath("$.avatarUrl").value(containsString("aaaaa.jpg"))).andExpect(jsonPath("$.description").value(DEFAULT_DESCRIPTION)).andExpect(jsonPath("$.data.AAAAAAAAAA").value("BBBBBBBBBB")).andExpect(jsonPath("$.targets[0].id").value(notNullValue())).andExpect(jsonPath("$.targets[0].name").value(DEFAULT_LN_TARGET_NAME)).andExpect(jsonPath("$.targets[0].typeKey").value(DEFAULT_LN_TARGET_KEY)).andExpect(jsonPath("$.targets[0].source").value(presaved.getId())).andExpect(jsonPath("$.targets[0].target.id").value(id));
    // Validate the XmEntity in Elasticsearch
    XmEntity xmEntityEs = xmEntitySearchRepository.findOne(Long.valueOf(id.toString()));
    assertThat(xmEntityEs).isEqualToIgnoringGivenFields(testXmEntity, "sources", "avatarUrl");
}
Also used : XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) MvcResult(org.springframework.test.web.servlet.MvcResult) Link(com.icthh.xm.ms.entity.domain.Link) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Link (com.icthh.xm.ms.entity.domain.Link)32 XmEntity (com.icthh.xm.ms.entity.domain.XmEntity)20 Test (org.junit.Test)19 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)19 Transactional (org.springframework.transaction.annotation.Transactional)16 LogicExtensionPoint (com.icthh.xm.commons.lep.LogicExtensionPoint)3 WithMockUser (org.springframework.security.test.context.support.WithMockUser)3 Timed (com.codahale.metrics.annotation.Timed)2 BusinessException (com.icthh.xm.commons.exceptions.BusinessException)2 Attachment (com.icthh.xm.ms.entity.domain.Attachment)2 SneakyThrows (lombok.SneakyThrows)2 HttpHeaders (org.springframework.http.HttpHeaders)2 ResponseEntity (org.springframework.http.ResponseEntity)2 MvcResult (org.springframework.test.web.servlet.MvcResult)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 Calendar (com.icthh.xm.ms.entity.domain.Calendar)1 Comment (com.icthh.xm.ms.entity.domain.Comment)1 Location (com.icthh.xm.ms.entity.domain.Location)1 Rating (com.icthh.xm.ms.entity.domain.Rating)1 Tag (com.icthh.xm.ms.entity.domain.Tag)1