Search in sources :

Example 6 with TypeSpec

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

the class XmEntityGeneratorServiceIntTest method generateXmEntityWithTagsTest.

@Test
@SneakyThrows
public void generateXmEntityWithTagsTest() {
    XmEntity generatedEntity = xmEntityGeneratorService.generateXmEntity(ENTITY_TYPE_WITH_TAGS_AND_LOCATIONS_KEY);
    log.info(new ObjectMapper().writeValueAsString(generatedEntity));
    Set<Tag> tags = generatedEntity.getTags();
    assertFalse("No tags generated", isEmpty(tags));
    TypeSpec specType = xmEntitySpecService.findTypeByKey("TYPE1.SUBTYPE1");
    List<TagSpec> tagsSpecs = specType.getTags();
    Set<String> specTagsKeys = tagsSpecs.stream().map(TagSpec::getKey).collect(toSet());
    Set<String> tagsKeys = tags.stream().map(Tag::getTypeKey).collect(toSet());
    assertTrue("Tag type not from tag specification", specTagsKeys.containsAll(tagsKeys));
    for (val tag : tags) {
        assertFalse("Name of tag is empty", isBlank(tag.getName()));
    }
}
Also used : lombok.val(lombok.val) TagSpec(com.icthh.xm.ms.entity.domain.spec.TagSpec) XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) Tag(com.icthh.xm.ms.entity.domain.Tag) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TypeSpec(com.icthh.xm.ms.entity.domain.spec.TypeSpec) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) SneakyThrows(lombok.SneakyThrows)

Example 7 with TypeSpec

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

the class XmEntitySpecServiceUnitTest method testFindTypeByKey.

@Test
public void testFindTypeByKey() {
    TypeSpec type = xmEntitySpecService.findTypeByKey(KEY1);
    assertNotNull(type);
    assertEquals(KEY1, type.getKey());
    type = xmEntitySpecService.findTypeByKey(KEY3);
    assertNotNull(type);
    assertEquals(KEY3, type.getKey());
    type = xmEntitySpecService.findTypeByKey(KEY4);
    assertNull(type);
}
Also used : TypeSpec(com.icthh.xm.ms.entity.domain.spec.TypeSpec) Test(org.junit.Test)

Example 8 with TypeSpec

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

the class XmEntitySpecResource method getTypeSpec.

/**
 * GET  /xm-entity-specs/:key : get the "key" typeSpec.
 *
 * @param key the key of the typeSpec to retrieve
 * @return the ResponseEntity with status 200 (OK) and with body the typeSpec, or with status 404 (Not Found)
 */
@GetMapping("/xm-entity-specs/{key}")
@Timed
@PostAuthorize("hasPermission({'returnObject': returnObject.body}, 'XMENTITY_SPEC.GET_LIST.ITEM')")
public ResponseEntity<TypeSpec> getTypeSpec(@PathVariable String key) {
    log.debug("REST request to get TypeSpec : {}", key);
    TypeSpec typeSpec = xmEntitySpecService.findTypeByKey(key);
    return RespContentUtil.wrapOrNotFound(Optional.ofNullable(typeSpec));
}
Also used : TypeSpec(com.icthh.xm.ms.entity.domain.spec.TypeSpec) GetMapping(org.springframework.web.bind.annotation.GetMapping) Timed(com.codahale.metrics.annotation.Timed) PostAuthorize(org.springframework.security.access.prepost.PostAuthorize)

Example 9 with TypeSpec

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

the class XmEntityServiceImpl method deleteXmEntity.

private void deleteXmEntity(XmEntity xmEntity) {
    TypeSpec spec = xmEntitySpecService.findTypeByKey(xmEntity.getTypeKey());
    Map<String, String> linkSpec = ofNullable(spec).map(TypeSpec::getLinks).orElse(emptyList()).stream().collect(toMap(LinkSpec::getKey, LinkSpec::getBuilderType));
    Iterator<Link> iterator = nullSafe(xmEntity.getTargets()).iterator();
    while (iterator.hasNext()) {
        Link target = iterator.next();
        iterator.remove();
        linkService.delete(target.getId());
        if (NEW_BUILDER_TYPE.equalsIgnoreCase(linkSpec.get(target.getTypeKey()))) {
            deleteNewLink(target);
        } else if (!SEARCH_BUILDER_TYPE.equals(linkSpec.get(target.getTypeKey()))) {
            log.warn("Unknown link builder type |{}| for link type {}", linkSpec.get(target.getTypeKey()), target.getTypeKey());
        }
    }
    xmEntityRepository.delete(xmEntity.getId());
    xmEntitySearchRepository.delete(xmEntity.getId());
}
Also used : Link(com.icthh.xm.ms.entity.domain.Link) TypeSpec(com.icthh.xm.ms.entity.domain.spec.TypeSpec)

Aggregations

TypeSpec (com.icthh.xm.ms.entity.domain.spec.TypeSpec)9 XmEntity (com.icthh.xm.ms.entity.domain.XmEntity)4 Test (org.junit.Test)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Attachment (com.icthh.xm.ms.entity.domain.Attachment)2 Link (com.icthh.xm.ms.entity.domain.Link)2 Location (com.icthh.xm.ms.entity.domain.Location)2 Tag (com.icthh.xm.ms.entity.domain.Tag)2 StateSpec (com.icthh.xm.ms.entity.domain.spec.StateSpec)2 SneakyThrows (lombok.SneakyThrows)2 lombok.val (lombok.val)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 Timed (com.codahale.metrics.annotation.Timed)1 BusinessException (com.icthh.xm.commons.exceptions.BusinessException)1 EntityNotFoundException (com.icthh.xm.commons.exceptions.EntityNotFoundException)1 ErrorConstants (com.icthh.xm.commons.exceptions.ErrorConstants)1 LogicExtensionPoint (com.icthh.xm.commons.lep.LogicExtensionPoint)1 LepService (com.icthh.xm.commons.lep.spring.LepService)1 FindWithPermission (com.icthh.xm.commons.permission.annotation.FindWithPermission)1 XmAuthenticationContextHolder (com.icthh.xm.commons.security.XmAuthenticationContextHolder)1