Skip to content

Commit

Permalink
Merge pull request #340 in DM/herd from feature/DM-10868v2 to develop
Browse files Browse the repository at this point in the history
* commit '541df0ee1552c77e78cda7369dadb89963e39334':
  DM-10868 Search and manage status of suggested changes to BDef Description
  • Loading branch information
DavidBalash committed Jun 6, 2018
2 parents 5969493 + 541df0e commit 8fe4db5
Show file tree
Hide file tree
Showing 9 changed files with 678 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.finra.herd.model.api.xml.BusinessObjectDefinitionDescriptionSuggestionKey;
import org.finra.herd.model.jpa.BusinessObjectDefinitionDescriptionSuggestionEntity;
import org.finra.herd.model.jpa.BusinessObjectDefinitionDescriptionSuggestionStatusEntity;
import org.finra.herd.model.jpa.BusinessObjectDefinitionEntity;

public interface BusinessObjectDefinitionDescriptionSuggestionDao extends BaseJpaDao
Expand All @@ -43,4 +44,16 @@ BusinessObjectDefinitionDescriptionSuggestionEntity getBusinessObjectDefinitionD
*/
List<BusinessObjectDefinitionDescriptionSuggestionKey> getBusinessObjectDefinitionDescriptionSuggestionsByBusinessObjectDefinitionEntity(
BusinessObjectDefinitionEntity businessObjectDefinitionEntity);

/**
* Gets a collection of business object definition description suggestions by business object definition entity and status.
*
* @param businessObjectDefinitionEntity the business object definition entity associated with the description suggestions
* @param businessObjectDefinitionDescriptionSuggestionStatusEntity the status of the business object definition description suggestions
*
* @return the business object definition description suggestions for the specified business object definition and status
*/
List<BusinessObjectDefinitionDescriptionSuggestionEntity> getBusinessObjectDefinitionDescriptionSuggestionsByBusinessObjectDefinitionEntityAndStatus(
BusinessObjectDefinitionEntity businessObjectDefinitionEntity,
BusinessObjectDefinitionDescriptionSuggestionStatusEntity businessObjectDefinitionDescriptionSuggestionStatusEntity);
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.finra.herd.model.api.xml.BusinessObjectDefinitionDescriptionSuggestionKey;
import org.finra.herd.model.jpa.BusinessObjectDefinitionDescriptionSuggestionEntity;
import org.finra.herd.model.jpa.BusinessObjectDefinitionDescriptionSuggestionEntity_;
import org.finra.herd.model.jpa.BusinessObjectDefinitionDescriptionSuggestionStatusEntity;
import org.finra.herd.model.jpa.BusinessObjectDefinitionEntity;

@Repository
Expand Down Expand Up @@ -108,4 +109,39 @@ public List<BusinessObjectDefinitionDescriptionSuggestionKey> getBusinessObjectD

return businessObjectDefinitionDescriptionSuggestionKeys;
}

@Override
public List<BusinessObjectDefinitionDescriptionSuggestionEntity> getBusinessObjectDefinitionDescriptionSuggestionsByBusinessObjectDefinitionEntityAndStatus(
BusinessObjectDefinitionEntity businessObjectDefinitionEntity,
BusinessObjectDefinitionDescriptionSuggestionStatusEntity businessObjectDefinitionDescriptionSuggestionStatusEntity)
{
// Create the criteria builder and the criteria.
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<BusinessObjectDefinitionDescriptionSuggestionEntity> criteria =
builder.createQuery(BusinessObjectDefinitionDescriptionSuggestionEntity.class);

// The criteria root is the business object definition description suggestion.
Root<BusinessObjectDefinitionDescriptionSuggestionEntity> businessObjectDefinitionDescriptionSuggestionEntity =
criteria.from(BusinessObjectDefinitionDescriptionSuggestionEntity.class);

// Create the standard restrictions (i.e. the standard where clauses).
List<Predicate> predicates = new ArrayList<>();
predicates.add(builder
.equal(businessObjectDefinitionDescriptionSuggestionEntity.get(BusinessObjectDefinitionDescriptionSuggestionEntity_.businessObjectDefinition),
businessObjectDefinitionEntity));

if (businessObjectDefinitionDescriptionSuggestionStatusEntity != null)
{
predicates.add(builder.equal(businessObjectDefinitionDescriptionSuggestionEntity.get(BusinessObjectDefinitionDescriptionSuggestionEntity_.status),
businessObjectDefinitionDescriptionSuggestionStatusEntity));
}

// Add the clauses for the query.
criteria.select(businessObjectDefinitionDescriptionSuggestionEntity).where(builder.and(predicates.toArray(new Predicate[predicates.size()])));

// Order by business object definition description suggestion id descending. This will list the newest created description suggestions first.
criteria.orderBy(builder.desc(businessObjectDefinitionDescriptionSuggestionEntity.get(BusinessObjectDefinitionDescriptionSuggestionEntity_.id)));

return entityManager.createQuery(criteria).getResultList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,116 @@ public void testGetBusinessObjectDefinitionDescriptionSuggestionByBusinessObject
assertEquals(
businessObjectDefinitionDescriptionSuggestionDao.getBusinessObjectDefinitionDescriptionSuggestionsByBusinessObjectDefinitionEntity(null).size(), 0);
}

@Test
public void testGetBusinessObjectDefinitionDescriptionSuggestionByBusinessObjectDefinitionEntityAndStatus()
{
// Create and persist the relative database entities.
NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE);
BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDaoTestHelper
.createBusinessObjectDefinitionEntity(namespaceEntity.getCode(), BDEF_NAME, DATA_PROVIDER_NAME, BDEF_DESCRIPTION);

BusinessObjectDefinitionDescriptionSuggestionStatusEntity businessObjectDefinitionDescriptionSuggestionStatusEntity =
businessObjectDefinitionDescriptionSuggestionStatusDaoTestHelper
.createBusinessObjectDefinitionDescriptionSuggestionStatusEntity(BDEF_DESCRIPTION_SUGGESTION_STATUS);

BusinessObjectDefinitionDescriptionSuggestionStatusEntity businessObjectDefinitionDescriptionSuggestionStatusEntity2 =
businessObjectDefinitionDescriptionSuggestionStatusDaoTestHelper
.createBusinessObjectDefinitionDescriptionSuggestionStatusEntity(BDEF_DESCRIPTION_SUGGESTION_STATUS_2);

// Create new business object definition description suggestion entities and persist the new entities.
BusinessObjectDefinitionDescriptionSuggestionEntity businessObjectDefinitionDescriptionSuggestionEntity =
new BusinessObjectDefinitionDescriptionSuggestionEntity();
businessObjectDefinitionDescriptionSuggestionEntity.setBusinessObjectDefinition(businessObjectDefinitionEntity);
businessObjectDefinitionDescriptionSuggestionEntity.setDescriptionSuggestion(DESCRIPTION_SUGGESTION);
businessObjectDefinitionDescriptionSuggestionEntity.setUserId(USER_ID);
businessObjectDefinitionDescriptionSuggestionEntity.setStatus(businessObjectDefinitionDescriptionSuggestionStatusEntity);
businessObjectDefinitionDescriptionSuggestionDao.saveAndRefresh(businessObjectDefinitionDescriptionSuggestionEntity);

BusinessObjectDefinitionDescriptionSuggestionEntity businessObjectDefinitionDescriptionSuggestionEntity2 =
new BusinessObjectDefinitionDescriptionSuggestionEntity();
businessObjectDefinitionDescriptionSuggestionEntity2.setBusinessObjectDefinition(businessObjectDefinitionEntity);
businessObjectDefinitionDescriptionSuggestionEntity2.setDescriptionSuggestion(DESCRIPTION_SUGGESTION_2);
businessObjectDefinitionDescriptionSuggestionEntity2.setUserId(USER_ID_2);
businessObjectDefinitionDescriptionSuggestionEntity2.setStatus(businessObjectDefinitionDescriptionSuggestionStatusEntity2);
businessObjectDefinitionDescriptionSuggestionDao.saveAndRefresh(businessObjectDefinitionDescriptionSuggestionEntity2);

// Get business object definition description suggestion keys and validate the result.
List<BusinessObjectDefinitionDescriptionSuggestionEntity> results = businessObjectDefinitionDescriptionSuggestionDao
.getBusinessObjectDefinitionDescriptionSuggestionsByBusinessObjectDefinitionEntityAndStatus(businessObjectDefinitionEntity,
businessObjectDefinitionDescriptionSuggestionStatusEntity);

// Validate results.
assertEquals("Result size not equal to one.", results.size(), 1);
assertEquals(NAMESPACE, results.get(0).getBusinessObjectDefinition().getNamespace().getCode());
assertEquals(BDEF_NAME, results.get(0).getBusinessObjectDefinition().getName());
assertEquals(USER_ID, results.get(0).getUserId());
assertEquals(DESCRIPTION_SUGGESTION, results.get(0).getDescriptionSuggestion());
assertEquals(businessObjectDefinitionDescriptionSuggestionStatusEntity, results.get(0).getStatus());
assertEquals(businessObjectDefinitionDescriptionSuggestionEntity.getCreatedBy(), results.get(0).getCreatedBy());
assertEquals(businessObjectDefinitionDescriptionSuggestionEntity.getId(), results.get(0).getId());

// Try to retrieve business object definition description suggestions using invalid input parameters.
assertEquals(businessObjectDefinitionDescriptionSuggestionDao
.getBusinessObjectDefinitionDescriptionSuggestionsByBusinessObjectDefinitionEntityAndStatus(null, null).size(), 0);
}

@Test
public void testGetBusinessObjectDefinitionDescriptionSuggestionByBusinessObjectDefinitionEntityAndStatusWithNullStatus()
{
// Create and persist the relative database entities.
NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE);
BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDaoTestHelper
.createBusinessObjectDefinitionEntity(namespaceEntity.getCode(), BDEF_NAME, DATA_PROVIDER_NAME, BDEF_DESCRIPTION);

BusinessObjectDefinitionDescriptionSuggestionStatusEntity businessObjectDefinitionDescriptionSuggestionStatusEntity =
businessObjectDefinitionDescriptionSuggestionStatusDaoTestHelper
.createBusinessObjectDefinitionDescriptionSuggestionStatusEntity(BDEF_DESCRIPTION_SUGGESTION_STATUS);

BusinessObjectDefinitionDescriptionSuggestionStatusEntity businessObjectDefinitionDescriptionSuggestionStatusEntity2 =
businessObjectDefinitionDescriptionSuggestionStatusDaoTestHelper
.createBusinessObjectDefinitionDescriptionSuggestionStatusEntity(BDEF_DESCRIPTION_SUGGESTION_STATUS_2);

// Create new business object definition description suggestion entities and persist the new entities.
BusinessObjectDefinitionDescriptionSuggestionEntity businessObjectDefinitionDescriptionSuggestionEntity =
new BusinessObjectDefinitionDescriptionSuggestionEntity();
businessObjectDefinitionDescriptionSuggestionEntity.setBusinessObjectDefinition(businessObjectDefinitionEntity);
businessObjectDefinitionDescriptionSuggestionEntity.setDescriptionSuggestion(DESCRIPTION_SUGGESTION);
businessObjectDefinitionDescriptionSuggestionEntity.setUserId(USER_ID);
businessObjectDefinitionDescriptionSuggestionEntity.setStatus(businessObjectDefinitionDescriptionSuggestionStatusEntity);
businessObjectDefinitionDescriptionSuggestionDao.saveAndRefresh(businessObjectDefinitionDescriptionSuggestionEntity);

BusinessObjectDefinitionDescriptionSuggestionEntity businessObjectDefinitionDescriptionSuggestionEntity2 =
new BusinessObjectDefinitionDescriptionSuggestionEntity();
businessObjectDefinitionDescriptionSuggestionEntity2.setBusinessObjectDefinition(businessObjectDefinitionEntity);
businessObjectDefinitionDescriptionSuggestionEntity2.setDescriptionSuggestion(DESCRIPTION_SUGGESTION_2);
businessObjectDefinitionDescriptionSuggestionEntity2.setUserId(USER_ID_2);
businessObjectDefinitionDescriptionSuggestionEntity2.setStatus(businessObjectDefinitionDescriptionSuggestionStatusEntity2);
businessObjectDefinitionDescriptionSuggestionDao.saveAndRefresh(businessObjectDefinitionDescriptionSuggestionEntity2);

// Get business object definition description suggestion keys and validate the result.
List<BusinessObjectDefinitionDescriptionSuggestionEntity> results = businessObjectDefinitionDescriptionSuggestionDao
.getBusinessObjectDefinitionDescriptionSuggestionsByBusinessObjectDefinitionEntityAndStatus(businessObjectDefinitionEntity,
null);

// Validate results.
assertEquals("Result size not equal to one.", results.size(), 2);

// The most recently created description suggestion should be listed first.
assertEquals(NAMESPACE, results.get(0).getBusinessObjectDefinition().getNamespace().getCode());
assertEquals(BDEF_NAME, results.get(0).getBusinessObjectDefinition().getName());
assertEquals(USER_ID_2, results.get(0).getUserId());
assertEquals(DESCRIPTION_SUGGESTION_2, results.get(0).getDescriptionSuggestion());
assertEquals(businessObjectDefinitionDescriptionSuggestionStatusEntity2, results.get(0).getStatus());
assertEquals(businessObjectDefinitionDescriptionSuggestionEntity2.getCreatedBy(), results.get(0).getCreatedBy());
assertEquals(businessObjectDefinitionDescriptionSuggestionEntity2.getId(), results.get(0).getId());

assertEquals(NAMESPACE, results.get(1).getBusinessObjectDefinition().getNamespace().getCode());
assertEquals(BDEF_NAME, results.get(1).getBusinessObjectDefinition().getName());
assertEquals(USER_ID, results.get(1).getUserId());
assertEquals(DESCRIPTION_SUGGESTION, results.get(1).getDescriptionSuggestion());
assertEquals(businessObjectDefinitionDescriptionSuggestionStatusEntity, results.get(1).getStatus());
assertEquals(businessObjectDefinitionDescriptionSuggestionEntity.getCreatedBy(), results.get(1).getCreatedBy());
assertEquals(businessObjectDefinitionDescriptionSuggestionEntity.getId(), results.get(1).getId());
}
}
9 changes: 7 additions & 2 deletions herd-code/herd-model-api/src/main/resources/herd.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -1775,17 +1775,22 @@
<xs:documentation>The business object definition description suggestion key</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="descriptionSuggestion" type="xs:string">
<xs:element name="descriptionSuggestion" type="xs:string" minOccurs="0">
<xs:annotation>
<xs:documentation>The description suggestion</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="status" type="xs:string">
<xs:element name="status" type="xs:string" minOccurs="0">
<xs:annotation>
<xs:documentation>The status of the business object definition description suggestion. One of the following values: PENDING, ACCEPTED
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="createdByUserId" type="xs:string" minOccurs="0">
<xs:annotation>
<xs:documentation>The User ID of the user who created this business object definition description suggestion</xs:documentation>
</xs:annotation>
</xs:element>
</xs:all>
</xs:complexType>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void testCreateBusinessObjectDefinitionDescriptionSuggestion()

// Create the business object definition description suggestion.
BusinessObjectDefinitionDescriptionSuggestion businessObjectDefinitionDescriptionSuggestion =
new BusinessObjectDefinitionDescriptionSuggestion(ID, key, DESCRIPTION_SUGGESTION, BDEF_DESCRIPTION_SUGGESTION_STATUS);
new BusinessObjectDefinitionDescriptionSuggestion(ID, key, DESCRIPTION_SUGGESTION, BDEF_DESCRIPTION_SUGGESTION_STATUS, USER_ID);

// Mock calls to external method.
when(businessObjectDefinitionDescriptionSuggestionService.createBusinessObjectDefinitionDescriptionSuggestion(request))
Expand All @@ -100,7 +100,7 @@ public void testDeleteBusinessObjectDefinitionDescriptionSuggestion()

// Create the business object definition description suggestion.
BusinessObjectDefinitionDescriptionSuggestion businessObjectDefinitionDescriptionSuggestion =
new BusinessObjectDefinitionDescriptionSuggestion(ID, key, DESCRIPTION_SUGGESTION, BDEF_DESCRIPTION_SUGGESTION_STATUS);
new BusinessObjectDefinitionDescriptionSuggestion(ID, key, DESCRIPTION_SUGGESTION, BDEF_DESCRIPTION_SUGGESTION_STATUS, USER_ID);

// Mock calls to external method.
when(businessObjectDefinitionDescriptionSuggestionService.deleteBusinessObjectDefinitionDescriptionSuggestion(key))
Expand Down Expand Up @@ -157,7 +157,7 @@ public void testGetBusinessObjectDefinitionDescriptionSuggestionByKey()

// Create the business object definition description suggestion.
BusinessObjectDefinitionDescriptionSuggestion businessObjectDefinitionDescriptionSuggestion =
new BusinessObjectDefinitionDescriptionSuggestion(ID, key, DESCRIPTION_SUGGESTION, BDEF_DESCRIPTION_SUGGESTION_STATUS);
new BusinessObjectDefinitionDescriptionSuggestion(ID, key, DESCRIPTION_SUGGESTION, BDEF_DESCRIPTION_SUGGESTION_STATUS, USER_ID);

// Mock calls to external method.
when(businessObjectDefinitionDescriptionSuggestionService.getBusinessObjectDefinitionDescriptionSuggestionByKey(key))
Expand Down Expand Up @@ -192,7 +192,7 @@ public void testSearchBusinessObjectDefinitionDescriptionSuggestions()

// Create the business object definition description suggestion.
BusinessObjectDefinitionDescriptionSuggestion businessObjectDefinitionDescriptionSuggestion =
new BusinessObjectDefinitionDescriptionSuggestion(ID, key, DESCRIPTION_SUGGESTION, BDEF_DESCRIPTION_SUGGESTION_STATUS);
new BusinessObjectDefinitionDescriptionSuggestion(ID, key, DESCRIPTION_SUGGESTION, BDEF_DESCRIPTION_SUGGESTION_STATUS, USER_ID);

// Create the business object definition description suggestion search response.
BusinessObjectDefinitionDescriptionSuggestionSearchResponse businessObjectDefinitionDescriptionSuggestionSearchResponse =
Expand Down Expand Up @@ -232,7 +232,7 @@ public void testUpdateBusinessObjectDefinitionDescriptionSuggestion()

// Create the business object definition description suggestion.
BusinessObjectDefinitionDescriptionSuggestion businessObjectDefinitionDescriptionSuggestion =
new BusinessObjectDefinitionDescriptionSuggestion(ID, key, DESCRIPTION_SUGGESTION, BDEF_DESCRIPTION_SUGGESTION_STATUS);
new BusinessObjectDefinitionDescriptionSuggestion(ID, key, DESCRIPTION_SUGGESTION, BDEF_DESCRIPTION_SUGGESTION_STATUS, USER_ID);

// Mock calls to external method.
when(businessObjectDefinitionDescriptionSuggestionService.updateBusinessObjectDefinitionDescriptionSuggestion(key, request))
Expand Down
Loading

0 comments on commit 8fe4db5

Please sign in to comment.