Search in sources :

Example 11 with BusinessObjectDefinitionTagEntity

use of org.finra.herd.model.jpa.BusinessObjectDefinitionTagEntity in project herd by FINRAOS.

the class BusinessObjectDefinitionTagDaoImpl method getBusinessObjectDefinitionTagsByTagEntities.

@Override
public List<BusinessObjectDefinitionTagKey> getBusinessObjectDefinitionTagsByTagEntities(List<TagEntity> tagEntities) {
    // Create the criteria builder and a tuple style criteria query.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Tuple> criteria = builder.createTupleQuery();
    // The criteria root is the business object definition tag entity.
    Root<BusinessObjectDefinitionTagEntity> businessObjectDefinitionTagEntityRoot = criteria.from(BusinessObjectDefinitionTagEntity.class);
    // Join to the other tables we can filter on.
    Join<BusinessObjectDefinitionTagEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntityJoin = businessObjectDefinitionTagEntityRoot.join(BusinessObjectDefinitionTagEntity_.businessObjectDefinition);
    Join<BusinessObjectDefinitionEntity, NamespaceEntity> namespaceEntityJoin = businessObjectDefinitionEntityJoin.join(BusinessObjectDefinitionEntity_.namespace);
    Join<BusinessObjectDefinitionTagEntity, TagEntity> tagEntityJoin = businessObjectDefinitionTagEntityRoot.join(BusinessObjectDefinitionTagEntity_.tag);
    Join<TagEntity, TagTypeEntity> tagTypeEntityJoin = tagEntityJoin.join(TagEntity_.tagType);
    // Get the columns.
    Path<String> namespaceCodeColumn = namespaceEntityJoin.get(NamespaceEntity_.code);
    Path<String> businessObjectDefinitionNameColumn = businessObjectDefinitionEntityJoin.get(BusinessObjectDefinitionEntity_.name);
    Path<String> businessObjectDefinitionDisplayNameColumn = businessObjectDefinitionEntityJoin.get(BusinessObjectDefinitionEntity_.displayName);
    Path<String> tagTypeCodeColumn = tagTypeEntityJoin.get(TagTypeEntity_.code);
    Path<String> tagCodeColumn = tagEntityJoin.get(TagEntity_.tagCode);
    Path<String> tagDisplayNameColumn = tagEntityJoin.get(TagEntity_.displayName);
    // Create the standard restrictions (i.e. the standard where clauses).
    Predicate predicate = getPredicateForInClause(builder, businessObjectDefinitionTagEntityRoot.get(BusinessObjectDefinitionTagEntity_.tag), tagEntities);
    // Order the results by business object definition display name (an optional column),
    // business object definition namespace, business object definition name, tag display name,
    // and tag type code (since tag display name is unique across a tag type).
    List<Order> orderBy = new ArrayList<>();
    orderBy.add(builder.asc(businessObjectDefinitionDisplayNameColumn));
    orderBy.add(builder.asc(namespaceCodeColumn));
    orderBy.add(builder.asc(businessObjectDefinitionNameColumn));
    orderBy.add(builder.asc(tagDisplayNameColumn));
    orderBy.add(builder.asc(tagTypeCodeColumn));
    // Add the clauses for the query.
    criteria.multiselect(namespaceCodeColumn, businessObjectDefinitionNameColumn, tagTypeCodeColumn, tagCodeColumn).where(predicate).orderBy(orderBy);
    // Run the query to get a list of tuples back.
    List<Tuple> tuples = entityManager.createQuery(criteria).getResultList();
    // Populate the "keys" objects from the returned tuples (i.e. 1 tuple for each row).
    List<BusinessObjectDefinitionTagKey> businessObjectDefinitionTagKeys = new ArrayList<>();
    for (Tuple tuple : tuples) {
        businessObjectDefinitionTagKeys.add(new BusinessObjectDefinitionTagKey(new BusinessObjectDefinitionKey(tuple.get(namespaceCodeColumn), tuple.get(businessObjectDefinitionNameColumn)), new TagKey(tuple.get(tagTypeCodeColumn), tuple.get(tagCodeColumn))));
    }
    return businessObjectDefinitionTagKeys;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Order(javax.persistence.criteria.Order) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) BusinessObjectDefinitionKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionKey) TagTypeEntity(org.finra.herd.model.jpa.TagTypeEntity) ArrayList(java.util.ArrayList) BusinessObjectDefinitionTagKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionTagKey) BusinessObjectDefinitionTagEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionTagEntity) Predicate(javax.persistence.criteria.Predicate) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) TagEntity(org.finra.herd.model.jpa.TagEntity) BusinessObjectDefinitionTagEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionTagEntity) BusinessObjectDefinitionTagKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionTagKey) TagKey(org.finra.herd.model.api.xml.TagKey) Tuple(javax.persistence.Tuple)

Example 12 with BusinessObjectDefinitionTagEntity

use of org.finra.herd.model.jpa.BusinessObjectDefinitionTagEntity in project herd by FINRAOS.

the class BusinessObjectDefinitionTagDaoImpl method getBusinessObjectDefinitionTagByParentEntities.

@Override
public BusinessObjectDefinitionTagEntity getBusinessObjectDefinitionTagByParentEntities(BusinessObjectDefinitionEntity businessObjectDefinitionEntity, TagEntity tagEntity) {
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<BusinessObjectDefinitionTagEntity> criteria = builder.createQuery(BusinessObjectDefinitionTagEntity.class);
    // The criteria root is the business object definition tag.
    Root<BusinessObjectDefinitionTagEntity> businessObjectDefinitionTagEntityRoot = criteria.from(BusinessObjectDefinitionTagEntity.class);
    // Create the standard restrictions (i.e. the standard where clauses).
    List<Predicate> predicates = new ArrayList<>();
    predicates.add(builder.equal(businessObjectDefinitionTagEntityRoot.get(BusinessObjectDefinitionTagEntity_.businessObjectDefinition), businessObjectDefinitionEntity));
    predicates.add(builder.equal(businessObjectDefinitionTagEntityRoot.get(BusinessObjectDefinitionTagEntity_.tag), tagEntity));
    // Add the clauses for the query.
    criteria.select(businessObjectDefinitionTagEntityRoot).where(builder.and(predicates.toArray(new Predicate[predicates.size()])));
    return executeSingleResultQuery(criteria, String.format("Found more than one business object definition tag instance with parameters {namespace=\"%s\", businessObjectDefinitionName=\"%s\"," + " tagType=\"%s\", tagCode=\"%s\"}.", businessObjectDefinitionEntity.getNamespace().getCode(), businessObjectDefinitionEntity.getName(), tagEntity.getTagType().getCode(), tagEntity.getTagCode()));
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) ArrayList(java.util.ArrayList) BusinessObjectDefinitionTagEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionTagEntity) Predicate(javax.persistence.criteria.Predicate)

Example 13 with BusinessObjectDefinitionTagEntity

use of org.finra.herd.model.jpa.BusinessObjectDefinitionTagEntity in project herd by FINRAOS.

the class BusinessObjectDefinitionTagServiceTest method testDeleteBusinessObjectDefinitionTagTrimParameters.

@Test
public void testDeleteBusinessObjectDefinitionTagTrimParameters() {
    // Create a business object definition tag key.
    BusinessObjectDefinitionTagKey businessObjectDefinitionTagKey = new BusinessObjectDefinitionTagKey(new BusinessObjectDefinitionKey(BDEF_NAMESPACE, BDEF_NAME), new TagKey(TAG_TYPE, TAG_CODE));
    // Create and persist a business object definition tag entity.
    BusinessObjectDefinitionTagEntity businessObjectDefinitionTagEntity = businessObjectDefinitionTagDaoTestHelper.createBusinessObjectDefinitionTagEntity(new BusinessObjectDefinitionKey(BDEF_NAMESPACE, BDEF_NAME), new TagKey(TAG_TYPE, TAG_CODE));
    // Validate that this business object definition tag exists.
    assertNotNull(businessObjectDefinitionTagDao.getBusinessObjectDefinitionTagByKey(businessObjectDefinitionTagKey));
    // Delete this business object definition tag using input parameters with leading and trailing empty spaces.
    BusinessObjectDefinitionTag result = businessObjectDefinitionTagService.deleteBusinessObjectDefinitionTag(new BusinessObjectDefinitionTagKey(new BusinessObjectDefinitionKey(addWhitespace(BDEF_NAMESPACE), addWhitespace(BDEF_NAME)), new TagKey(addWhitespace(TAG_TYPE), addWhitespace(TAG_CODE))));
    // Validate the returned object.
    assertEquals(new BusinessObjectDefinitionTag(businessObjectDefinitionTagEntity.getId(), businessObjectDefinitionTagKey), result);
    // Ensure that this business object definition tag is no longer there.
    assertNull(businessObjectDefinitionTagDao.getBusinessObjectDefinitionTagByKey(businessObjectDefinitionTagKey));
}
Also used : BusinessObjectDefinitionTag(org.finra.herd.model.api.xml.BusinessObjectDefinitionTag) BusinessObjectDefinitionKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionKey) BusinessObjectDefinitionTagKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionTagKey) TagKey(org.finra.herd.model.api.xml.TagKey) BusinessObjectDefinitionTagKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionTagKey) BusinessObjectDefinitionTagEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionTagEntity) Test(org.junit.Test)

Example 14 with BusinessObjectDefinitionTagEntity

use of org.finra.herd.model.jpa.BusinessObjectDefinitionTagEntity in project herd by FINRAOS.

the class BusinessObjectDefinitionTagServiceTest method testDeleteBusinessObjectDefinitionTag.

@Test
public void testDeleteBusinessObjectDefinitionTag() {
    // Create a business object definition tag key.
    BusinessObjectDefinitionTagKey businessObjectDefinitionTagKey = new BusinessObjectDefinitionTagKey(new BusinessObjectDefinitionKey(BDEF_NAMESPACE, BDEF_NAME), new TagKey(TAG_TYPE, TAG_CODE));
    // Create and persist a business object definition tag entity.
    BusinessObjectDefinitionTagEntity businessObjectDefinitionTagEntity = businessObjectDefinitionTagDaoTestHelper.createBusinessObjectDefinitionTagEntity(new BusinessObjectDefinitionKey(BDEF_NAMESPACE, BDEF_NAME), new TagKey(TAG_TYPE, TAG_CODE));
    // Validate that this business object definition tag exists.
    assertNotNull(businessObjectDefinitionTagDao.getBusinessObjectDefinitionTagByKey(businessObjectDefinitionTagKey));
    // Delete this business object definition tag.
    BusinessObjectDefinitionTag result = businessObjectDefinitionTagService.deleteBusinessObjectDefinitionTag(businessObjectDefinitionTagKey);
    // Validate the returned object.
    assertEquals(new BusinessObjectDefinitionTag(businessObjectDefinitionTagEntity.getId(), businessObjectDefinitionTagKey), result);
    // Ensure that this business object definition tag is no longer there.
    assertNull(businessObjectDefinitionTagDao.getBusinessObjectDefinitionTagByKey(businessObjectDefinitionTagKey));
}
Also used : BusinessObjectDefinitionTag(org.finra.herd.model.api.xml.BusinessObjectDefinitionTag) BusinessObjectDefinitionKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionKey) BusinessObjectDefinitionTagKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionTagKey) TagKey(org.finra.herd.model.api.xml.TagKey) BusinessObjectDefinitionTagKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionTagKey) BusinessObjectDefinitionTagEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionTagEntity) Test(org.junit.Test)

Example 15 with BusinessObjectDefinitionTagEntity

use of org.finra.herd.model.jpa.BusinessObjectDefinitionTagEntity in project herd by FINRAOS.

the class BusinessObjectDefinitionTagServiceTest method testDeleteBusinessObjectDefinitionTagUpperCaseParameters.

@Test
public void testDeleteBusinessObjectDefinitionTagUpperCaseParameters() {
    // Create a business object definition tag key.
    BusinessObjectDefinitionTagKey businessObjectDefinitionTagKey = new BusinessObjectDefinitionTagKey(new BusinessObjectDefinitionKey(BDEF_NAMESPACE, BDEF_NAME), new TagKey(TAG_TYPE, TAG_CODE));
    // Create and persist a business object definition tag entity.
    BusinessObjectDefinitionTagEntity businessObjectDefinitionTagEntity = businessObjectDefinitionTagDaoTestHelper.createBusinessObjectDefinitionTagEntity(new BusinessObjectDefinitionKey(BDEF_NAMESPACE, BDEF_NAME), new TagKey(TAG_TYPE, TAG_CODE));
    // Validate that this business object definition tag exists.
    assertNotNull(businessObjectDefinitionTagDao.getBusinessObjectDefinitionTagByKey(businessObjectDefinitionTagKey));
    // Delete this business object definition tag using upper case parameter values.
    BusinessObjectDefinitionTag result = businessObjectDefinitionTagService.deleteBusinessObjectDefinitionTag(new BusinessObjectDefinitionTagKey(new BusinessObjectDefinitionKey(BDEF_NAMESPACE.toUpperCase(), BDEF_NAME.toUpperCase()), new TagKey(TAG_TYPE.toUpperCase(), TAG_CODE.toUpperCase())));
    // Validate the returned object.
    assertEquals(new BusinessObjectDefinitionTag(businessObjectDefinitionTagEntity.getId(), businessObjectDefinitionTagKey), result);
    // Ensure that this business object definition tag is no longer there.
    assertNull(businessObjectDefinitionTagDao.getBusinessObjectDefinitionTagByKey(businessObjectDefinitionTagKey));
}
Also used : BusinessObjectDefinitionTag(org.finra.herd.model.api.xml.BusinessObjectDefinitionTag) BusinessObjectDefinitionKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionKey) BusinessObjectDefinitionTagKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionTagKey) TagKey(org.finra.herd.model.api.xml.TagKey) BusinessObjectDefinitionTagKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionTagKey) BusinessObjectDefinitionTagEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionTagEntity) Test(org.junit.Test)

Aggregations

BusinessObjectDefinitionTagEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionTagEntity)18 BusinessObjectDefinitionEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionEntity)9 BusinessObjectDefinitionKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionKey)8 Test (org.junit.Test)8 BusinessObjectDefinitionTagKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionTagKey)7 TagKey (org.finra.herd.model.api.xml.TagKey)7 TagEntity (org.finra.herd.model.jpa.TagEntity)7 ArrayList (java.util.ArrayList)5 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)5 Predicate (javax.persistence.criteria.Predicate)5 BusinessObjectDefinitionTag (org.finra.herd.model.api.xml.BusinessObjectDefinitionTag)4 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)3 TagTypeEntity (org.finra.herd.model.jpa.TagTypeEntity)3 Tuple (javax.persistence.Tuple)2 NamespacePermission (org.finra.herd.model.annotation.NamespacePermission)2 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)2 Order (javax.persistence.criteria.Order)1 AlreadyExistsException (org.finra.herd.model.AlreadyExistsException)1