Search in sources :

Example 1 with TagChild

use of org.finra.herd.model.api.xml.TagChild in project herd by FINRAOS.

the class TagServiceImpl method getTags.

@Override
public TagListResponse getTags(String tagTypeCode, String tagCode) {
    // Validate and trim the tag type code.
    String tagTypeCodeLocal = alternateKeyHelper.validateStringParameter("tag type code", tagTypeCode);
    String cleanTagCode = tagCode;
    // Retrieve and ensure that a tag type exists for the specified tag type code.
    tagTypeDaoHelper.getTagTypeEntity(new TagTypeKey(tagTypeCodeLocal));
    // Get the list of tag keys.
    TagListResponse response = new TagListResponse();
    // getTag method will validate the requested tag exists
    if (tagCode != null) {
        cleanTagCode = alternateKeyHelper.validateStringParameter("tag code", tagCode);
        TagKey tagKey = new TagKey(tagTypeCodeLocal, cleanTagCode);
        Tag tag = getTag(tagKey);
        response.setTagKey(tag.getTagKey());
        response.setParentTagKey(tag.getParentTagKey());
    }
    List<TagChild> tagChildren = tagDao.getTagsByTagTypeAndParentTagCode(tagTypeCodeLocal, cleanTagCode);
    response.setTagChildren(tagChildren);
    return response;
}
Also used : TagChild(org.finra.herd.model.api.xml.TagChild) TagListResponse(org.finra.herd.model.api.xml.TagListResponse) TagTypeKey(org.finra.herd.model.api.xml.TagTypeKey) TagKey(org.finra.herd.model.api.xml.TagKey) Tag(org.finra.herd.model.api.xml.Tag)

Example 2 with TagChild

use of org.finra.herd.model.api.xml.TagChild in project herd by FINRAOS.

the class TagServiceTest method testGetTags.

@Test
public void testGetTags() {
    // Create and persist a tag type entity.
    TagTypeEntity tagTypeEntity = tagTypeDaoTestHelper.createTagTypeEntity(TAG_TYPE, TAG_TYPE_DISPLAY_NAME, TAG_TYPE_ORDER, TAG_TYPE_DESCRIPTION);
    // Create and persist two tag entities for the same tag type.
    tagDaoTestHelper.createTagEntity(tagTypeEntity, TAG_CODE, TAG_DISPLAY_NAME, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION);
    tagDaoTestHelper.createTagEntity(tagTypeEntity, TAG_CODE_2, TAG_TYPE_DISPLAY_NAME_2, TAG_SEARCH_SCORE_MULTIPLIER_2, TAG_DESCRIPTION_2);
    // Retrieve a list of tag keys.
    TagListResponse resultTagKeys = tagService.getTags(TAG_TYPE, NO_PARENT_TAG_CODE);
    // Validate the returned object.
    assertNotNull(resultTagKeys);
    assertEquals(Arrays.asList(new TagChild(new TagKey(TAG_TYPE, TAG_CODE), TAG_HAS_NO_CHILDREN), new TagChild(new TagKey(TAG_TYPE, TAG_CODE_2), TAG_HAS_NO_CHILDREN)), resultTagKeys.getTagChildren());
}
Also used : TagChild(org.finra.herd.model.api.xml.TagChild) TagListResponse(org.finra.herd.model.api.xml.TagListResponse) TagTypeEntity(org.finra.herd.model.jpa.TagTypeEntity) TagKey(org.finra.herd.model.api.xml.TagKey) Test(org.junit.Test)

Example 3 with TagChild

use of org.finra.herd.model.api.xml.TagChild in project herd by FINRAOS.

the class TagDaoImpl method getTagsByTagTypeAndParentTagCode.

@Override
public List<TagChild> getTagsByTagTypeAndParentTagCode(String tagType, String parentTagCode) {
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<TagEntity> criteria = builder.createQuery(TagEntity.class);
    // The criteria root is the tag entity.
    Root<TagEntity> tagEntityRoot = criteria.from(TagEntity.class);
    // Join to the other tables we can filter on.
    Join<TagEntity, TagTypeEntity> tagTypeEntityJoin = tagEntityRoot.join(TagEntity_.tagType);
    // Get the columns.
    Path<String> displayNameColumn = tagEntityRoot.get(TagEntity_.displayName);
    // Create the standard restrictions (i.e. the standard where clauses).
    List<Predicate> predicates = new ArrayList<>();
    predicates.add(builder.equal(builder.upper(tagTypeEntityJoin.get(TagTypeEntity_.code)), tagType.toUpperCase()));
    if (parentTagCode == null) {
        // Parent tag code is not specified, then return all tags with no parents, i.e. root tags.
        predicates.add(builder.isNull(tagEntityRoot.get(TagEntity_.parentTagEntity)));
    } else {
        // Add a restriction for the parent tag code.
        predicates.add(builder.equal(builder.upper(tagEntityRoot.get(TagEntity_.parentTagEntity).get(TagEntity_.tagCode)), parentTagCode.toUpperCase()));
    }
    // Add all clauses to the query.
    criteria.select(tagEntityRoot).where(builder.and(predicates.toArray(new Predicate[predicates.size()]))).orderBy(builder.asc(displayNameColumn));
    // Run the query to get a list of tag entities back.
    List<TagEntity> tagEntities = entityManager.createQuery(criteria).getResultList();
    // Populate tag child objects from the returned tag entities.
    List<TagChild> tagChildren = new ArrayList<>();
    for (TagEntity tagEntity : tagEntities) {
        boolean hasChildren = !tagEntity.getChildrenTagEntities().isEmpty();
        tagChildren.add(new TagChild(new TagKey(tagEntity.getTagType().getCode(), tagEntity.getTagCode()), hasChildren));
    }
    return tagChildren;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) TagChild(org.finra.herd.model.api.xml.TagChild) TagTypeEntity(org.finra.herd.model.jpa.TagTypeEntity) ArrayList(java.util.ArrayList) Predicate(javax.persistence.criteria.Predicate) TagEntity(org.finra.herd.model.jpa.TagEntity) TagKey(org.finra.herd.model.api.xml.TagKey)

Example 4 with TagChild

use of org.finra.herd.model.api.xml.TagChild in project herd by FINRAOS.

the class TagDaoTest method testGetTagsByTagTypeAndParentTagCode.

@Test
public void testGetTagsByTagTypeAndParentTagCode() {
    // Create a tag type entity.
    TagTypeEntity tagTypeEntity = tagTypeDaoTestHelper.createTagTypeEntity(TAG_TYPE, TAG_TYPE_DISPLAY_NAME, TAG_TYPE_ORDER, TAG_TYPE_DESCRIPTION);
    // Create two root tag entities for the tag type with tag display name in reverse order.
    List<TagEntity> rootTagEntities = Arrays.asList(tagDaoTestHelper.createTagEntity(tagTypeEntity, TAG_CODE, TAG_DISPLAY_NAME_2, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION), tagDaoTestHelper.createTagEntity(tagTypeEntity, TAG_CODE_2, TAG_DISPLAY_NAME, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION));
    // Create two children for the first root tag with tag display name in reverse order.
    List<TagEntity> childrenTagEntities = Arrays.asList(tagDaoTestHelper.createTagEntity(tagTypeEntity, TAG_CODE_3, TAG_DISPLAY_NAME_4, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION, rootTagEntities.get(0)), tagDaoTestHelper.createTagEntity(tagTypeEntity, TAG_CODE_4, TAG_DISPLAY_NAME_3, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION, rootTagEntities.get(0)));
    // Create one grand child of the first root tag.
    tagDaoTestHelper.createTagEntity(tagTypeEntity, TAG_CODE_5, TAG_DISPLAY_NAME_5, TAG_SEARCH_SCORE_MULTIPLIER, TAG_DESCRIPTION, childrenTagEntities.get(0));
    // Get root tag entities (by not specifying parent tag code).
    assertEquals(Arrays.asList(new TagChild(new TagKey(TAG_TYPE, TAG_CODE_2), TAG_HAS_NO_CHILDREN), new TagChild(new TagKey(TAG_TYPE, TAG_CODE), TAG_HAS_CHILDREN)), tagDao.getTagsByTagTypeAndParentTagCode(TAG_TYPE, null));
    // Get root tag entities by passing all case-insensitive parameters in uppercase.
    assertEquals(Arrays.asList(new TagChild(new TagKey(TAG_TYPE, TAG_CODE_2), TAG_HAS_NO_CHILDREN), new TagChild(new TagKey(TAG_TYPE, TAG_CODE), TAG_HAS_CHILDREN)), tagDao.getTagsByTagTypeAndParentTagCode(TAG_TYPE.toUpperCase(), null));
    // Get root tag entities by passing all case-insensitive parameters in lowercase.
    assertEquals(Arrays.asList(new TagChild(new TagKey(TAG_TYPE, TAG_CODE_2), TAG_HAS_NO_CHILDREN), new TagChild(new TagKey(TAG_TYPE, TAG_CODE), TAG_HAS_CHILDREN)), tagDao.getTagsByTagTypeAndParentTagCode(TAG_TYPE.toLowerCase(), null));
    // Try to get root tags with invalid values for all input parameters.
    assertTrue(tagDao.getTagsByTagTypeAndParentTagCode(I_DO_NOT_EXIST, null).isEmpty());
    // Get children tags (by specifying both tag type and parent tag type code).
    assertEquals(Arrays.asList(new TagChild(new TagKey(TAG_TYPE, TAG_CODE_4), TAG_HAS_NO_CHILDREN), new TagChild(new TagKey(TAG_TYPE, TAG_CODE_3), TAG_HAS_CHILDREN)), tagDao.getTagsByTagTypeAndParentTagCode(TAG_TYPE, TAG_CODE));
    // Get children tags by passing all case-insensitive parameters in uppercase.
    assertEquals(Arrays.asList(new TagChild(new TagKey(TAG_TYPE, TAG_CODE_4), TAG_HAS_NO_CHILDREN), new TagChild(new TagKey(TAG_TYPE, TAG_CODE_3), TAG_HAS_CHILDREN)), tagDao.getTagsByTagTypeAndParentTagCode(TAG_TYPE.toUpperCase(), TAG_CODE.toUpperCase()));
    // Get children tags by passing all case-insensitive parameters in lowercase.
    assertEquals(Arrays.asList(new TagChild(new TagKey(TAG_TYPE, TAG_CODE_4), TAG_HAS_NO_CHILDREN), new TagChild(new TagKey(TAG_TYPE, TAG_CODE_3), TAG_HAS_CHILDREN)), tagDao.getTagsByTagTypeAndParentTagCode(TAG_TYPE.toLowerCase(), TAG_CODE.toLowerCase()));
    // Try to get children tags with invalid values for all input parameters.
    assertTrue(tagDao.getTagsByTagTypeAndParentTagCode(I_DO_NOT_EXIST, TAG_CODE).isEmpty());
    assertTrue(tagDao.getTagsByTagTypeAndParentTagCode(TAG_TYPE, I_DO_NOT_EXIST).isEmpty());
}
Also used : TagChild(org.finra.herd.model.api.xml.TagChild) TagEntity(org.finra.herd.model.jpa.TagEntity) TagTypeEntity(org.finra.herd.model.jpa.TagTypeEntity) TagKey(org.finra.herd.model.api.xml.TagKey) Test(org.junit.Test)

Example 5 with TagChild

use of org.finra.herd.model.api.xml.TagChild in project herd by FINRAOS.

the class TagRestControllerTest method testGetTags.

@Test
public void testGetTags() {
    List<TagChild> tagChildren = new ArrayList<>();
    tagChildren.add(new TagChild(new TagKey(TAG_TYPE, TAG_CODE), false));
    tagChildren.add(new TagChild(new TagKey(TAG_TYPE, TAG_CODE_2), false));
    TagListResponse tagListResponse = new TagListResponse();
    tagListResponse.setTagChildren(tagChildren);
    when(tagService.getTags(TAG_TYPE, TAG_CODE)).thenReturn(tagListResponse);
    // Retrieve the tag.
    TagListResponse resultTagKeys = tagRestController.getTags(TAG_TYPE, TAG_CODE);
    // Verify the external calls.
    verify(tagService).getTags(TAG_TYPE, TAG_CODE);
    verifyNoMoreInteractions(tagService);
    // Validate the returned object.
    assertEquals(tagListResponse, resultTagKeys);
    ;
}
Also used : TagChild(org.finra.herd.model.api.xml.TagChild) TagListResponse(org.finra.herd.model.api.xml.TagListResponse) ArrayList(java.util.ArrayList) TagKey(org.finra.herd.model.api.xml.TagKey) Test(org.junit.Test)

Aggregations

TagChild (org.finra.herd.model.api.xml.TagChild)8 TagKey (org.finra.herd.model.api.xml.TagKey)8 TagListResponse (org.finra.herd.model.api.xml.TagListResponse)6 TagTypeEntity (org.finra.herd.model.jpa.TagTypeEntity)6 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)2 TagEntity (org.finra.herd.model.jpa.TagEntity)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 Predicate (javax.persistence.criteria.Predicate)1 Tag (org.finra.herd.model.api.xml.Tag)1 TagTypeKey (org.finra.herd.model.api.xml.TagTypeKey)1