use of org.finra.herd.model.jpa.NamespaceEntity in project herd by FINRAOS.
the class BusinessObjectDefinitionDaoImpl method getBusinessObjectDefinitions.
@Override
public List<BusinessObjectDefinitionEntity> getBusinessObjectDefinitions(List<TagEntity> tagEntities) {
// Create the criteria builder and a tuple style criteria query.
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<BusinessObjectDefinitionEntity> criteria = builder.createQuery(BusinessObjectDefinitionEntity.class);
// The criteria root is the business object definition.
Root<BusinessObjectDefinitionEntity> businessObjectDefinitionEntityRoot = criteria.from(BusinessObjectDefinitionEntity.class);
// Join to the other tables we can filter on.
Join<BusinessObjectDefinitionEntity, NamespaceEntity> namespaceEntity = businessObjectDefinitionEntityRoot.join(BusinessObjectDefinitionEntity_.namespace);
// Get the columns.
Path<String> namespaceCodeColumn = namespaceEntity.get(NamespaceEntity_.code);
Path<String> businessObjectDefinitionNameColumn = businessObjectDefinitionEntityRoot.get(BusinessObjectDefinitionEntity_.name);
Predicate predicate;
if (!CollectionUtils.isEmpty(tagEntities)) {
// join the business object definition tags
Join<BusinessObjectDefinitionEntity, BusinessObjectDefinitionTagEntity> businessObjectDefinitionTagEntityJoin = businessObjectDefinitionEntityRoot.join(BusinessObjectDefinitionEntity_.businessObjectDefinitionTags);
// Create the standard restrictions (i.e. the standard where clauses).
predicate = getPredicateForInClause(builder, businessObjectDefinitionTagEntityJoin.get(BusinessObjectDefinitionTagEntity_.tag), tagEntities);
// Add all clauses to the query.
criteria.select(businessObjectDefinitionEntityRoot).where(predicate).orderBy(builder.asc(businessObjectDefinitionNameColumn), builder.asc(namespaceCodeColumn));
} else {
criteria.select(businessObjectDefinitionEntityRoot).orderBy(builder.asc(businessObjectDefinitionNameColumn), builder.asc(namespaceCodeColumn));
}
// Returns duplicate business object definition. When a bdef is associated with multiple tags.
return entityManager.createQuery(criteria).getResultList();
}
use of org.finra.herd.model.jpa.NamespaceEntity in project herd by FINRAOS.
the class BusinessObjectDefinitionDaoImpl method getAllBusinessObjectDefinitions.
@Override
public List<BusinessObjectDefinitionEntity> getAllBusinessObjectDefinitions(Integer startPosition, Integer maxResult) {
// Create the criteria builder and a tuple style criteria query.
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<BusinessObjectDefinitionEntity> criteria = builder.createQuery(BusinessObjectDefinitionEntity.class);
// The criteria root is the business object definition.
Root<BusinessObjectDefinitionEntity> businessObjectDefinitionEntityRoot = criteria.from(BusinessObjectDefinitionEntity.class);
// Join to the other tables we can filter on.
Join<BusinessObjectDefinitionEntity, NamespaceEntity> namespaceEntity = businessObjectDefinitionEntityRoot.join(BusinessObjectDefinitionEntity_.namespace);
// Get the columns.
Path<String> namespaceCodeColumn = namespaceEntity.get(NamespaceEntity_.code);
Path<String> businessObjectDefinitionNameColumn = businessObjectDefinitionEntityRoot.get(BusinessObjectDefinitionEntity_.name);
// Add all clauses to the query.
criteria.select(businessObjectDefinitionEntityRoot).orderBy(builder.asc(businessObjectDefinitionNameColumn), builder.asc(namespaceCodeColumn));
// Get an instance of the query ready for execution.
TypedQuery<BusinessObjectDefinitionEntity> query = entityManager.createQuery(criteria);
// If start position is specified, set it for the query.
if (startPosition != null) {
query.setFirstResult(startPosition.intValue());
}
// If start position is specified, set it for the query.
if (maxResult != null) {
query.setMaxResults(maxResult.intValue());
}
// Execute the query and return the results.
return query.getResultList();
}
use of org.finra.herd.model.jpa.NamespaceEntity in project herd by FINRAOS.
the class EmrClusterDefinitionDaoTest method testGetEmrClusterDefinitionByAltKeyMultipleRecordsFound.
/**
* Tests the scenario by finding multiple EMR Cluster definition records.
*/
@Test(expected = IllegalArgumentException.class)
public void testGetEmrClusterDefinitionByAltKeyMultipleRecordsFound() throws IOException {
// Create namespace database entities.
NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE);
// Create two EMR cluster definitions different.
for (String definitionName : Arrays.asList(EMR_CLUSTER_DEFINITION_NAME.toUpperCase(), EMR_CLUSTER_DEFINITION_NAME.toLowerCase())) {
// Create a EMR cluster definition entity.
emrClusterDefinitionDaoTestHelper.createEmrClusterDefinitionEntity(namespaceEntity, definitionName, IOUtils.toString(resourceLoader.getResource(EMR_CLUSTER_DEFINITION_XML_FILE_WITH_CLASSPATH).getInputStream()));
}
// Try to retrieve the the job definition.
emrClusterDefinitionDao.getEmrClusterDefinitionByAltKey(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME);
}
use of org.finra.herd.model.jpa.NamespaceEntity in project herd by FINRAOS.
the class JobDefinitionDaoTest method testGetJobDefinitionByProcessDefinitionIdMultipleRecordsFound.
@Test
public void testGetJobDefinitionByProcessDefinitionIdMultipleRecordsFound() {
// Create a namespace database entity.
NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE);
// Create two job definitions with the same process definition id.
for (String jobName : Arrays.asList(JOB_NAME, JOB_NAME_2)) {
jobDefinitionDaoTestHelper.createJobDefinitionEntity(namespaceEntity, jobName, JOB_DESCRIPTION, ACTIVITI_ID);
}
// Try to retrieve a job definition by its process definition id.
try {
jobDefinitionDao.getJobDefinitionByProcessDefinitionId(ACTIVITI_ID);
fail();
} catch (IllegalArgumentException e) {
assertEquals(String.format("Found more than one Activiti job definition with processDefinitionId = \"%s\".", ACTIVITI_ID), e.getMessage());
}
}
use of org.finra.herd.model.jpa.NamespaceEntity in project herd by FINRAOS.
the class JobDefinitionDaoTest method testGetJobDefinitionByAltKeyMultipleRecordsFound.
@Test
public void testGetJobDefinitionByAltKeyMultipleRecordsFound() {
// Create a namespace database entity.
NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE);
// Create duplicate job definitions. Please note that we need to pass unique activity ID value.
for (String jobName : Arrays.asList(JOB_NAME.toUpperCase(), JOB_NAME.toLowerCase())) {
jobDefinitionDaoTestHelper.createJobDefinitionEntity(namespaceEntity, jobName, JOB_DESCRIPTION, jobName + ACTIVITI_ID);
}
// Try to retrieve a job definition.
try {
jobDefinitionDao.getJobDefinitionByAltKey(NAMESPACE, JOB_NAME);
fail();
} catch (IllegalArgumentException e) {
assertEquals(String.format("Found more than one Activiti job definition with parameters {namespace=\"%s\", jobName=\"%s\"}.", NAMESPACE, JOB_NAME), e.getMessage());
}
}
Aggregations