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);
}
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();
}
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);
}
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);
}
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");
}
Aggregations