use of org.finra.herd.model.jpa.JobDefinitionEntity in project herd by FINRAOS.
the class JobDefinitionDaoImpl method getJobDefinitionsByFilter.
@Override
public List<JobDefinitionEntity> getJobDefinitionsByFilter(String namespace, String jobName) {
// Create the criteria builder and the criteria.
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<JobDefinitionEntity> criteria = builder.createQuery(JobDefinitionEntity.class);
// The criteria root is the job definition.
Root<JobDefinitionEntity> jobDefinitionEntityRoot = criteria.from(JobDefinitionEntity.class);
// Join to the other tables we can filter on.
Join<JobDefinitionEntity, NamespaceEntity> namespaceEntityJoin = jobDefinitionEntityRoot.join(JobDefinitionEntity_.namespace);
// Create the standard restrictions (i.e. the standard where clauses).
List<Predicate> predicates = new ArrayList<>();
if (StringUtils.isNotBlank(namespace)) {
predicates.add(builder.equal(builder.upper(namespaceEntityJoin.get(NamespaceEntity_.code)), namespace.toUpperCase()));
}
if (StringUtils.isNotBlank(jobName)) {
predicates.add(builder.equal(builder.upper(jobDefinitionEntityRoot.get(JobDefinitionEntity_.name)), jobName.toUpperCase()));
}
// Order the results by namespace and job name.
List<Order> orderBy = new ArrayList<>();
orderBy.add(builder.asc(namespaceEntityJoin.get(NamespaceEntity_.code)));
orderBy.add(builder.asc(jobDefinitionEntityRoot.get(JobDefinitionEntity_.name)));
// Add the clauses for the query.
criteria.select(jobDefinitionEntityRoot).where(builder.and(predicates.toArray(new Predicate[predicates.size()]))).orderBy(orderBy);
// Execute the query and return the result list.
return entityManager.createQuery(criteria).getResultList();
}
use of org.finra.herd.model.jpa.JobDefinitionEntity in project herd by FINRAOS.
the class JobDefinitionDaoTest method testGetJobDefinitionByProcessDefinitionId.
@Test
public void testGetJobDefinitionByProcessDefinitionId() {
// Create a namespace database entity.
NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(NAMESPACE);
// Create and persist a job definition entity.
JobDefinitionEntity jobDefinitionEntity = jobDefinitionDaoTestHelper.createJobDefinitionEntity(namespaceEntity, JOB_NAME, JOB_DESCRIPTION, ACTIVITI_ID);
// Retrieve the job definition by its process definition id.
assertEquals(jobDefinitionEntity, jobDefinitionDao.getJobDefinitionByProcessDefinitionId(ACTIVITI_ID));
// Try to retrieve a job definition by its process definition id in uppercase.
assertNull(jobDefinitionDao.getJobDefinitionByProcessDefinitionId(ACTIVITI_ID.toUpperCase()));
// Try to retrieve a job definition by its process definition id in lowercase.
assertNull(jobDefinitionDao.getJobDefinitionByProcessDefinitionId(ACTIVITI_ID.toLowerCase()));
// Try to retrieve a job definition for a non-existing process definition id.
assertNull(jobDefinitionDao.getJobDefinitionByProcessDefinitionId("I_DO_NOT_EXIST"));
}
use of org.finra.herd.model.jpa.JobDefinitionEntity in project herd by FINRAOS.
the class JobDefinitionDaoTestHelper method createJobDefinitionEntity.
/**
* Creates and persists a new job definition entity.
*
* @param namespaceEntity the namespace entity
* @param jobName the job name
* @param description the job definition description
* @param activitiId the job definition Activiti ID
*
* @return the newly created job definition entity
*/
public JobDefinitionEntity createJobDefinitionEntity(NamespaceEntity namespaceEntity, String jobName, String description, String activitiId) {
JobDefinitionEntity jobDefinitionEntity = new JobDefinitionEntity();
jobDefinitionEntity.setNamespace(namespaceEntity);
jobDefinitionEntity.setName(jobName);
jobDefinitionEntity.setDescription(description);
jobDefinitionEntity.setActivitiId(activitiId);
return jobDefinitionDao.saveAndRefresh(jobDefinitionEntity);
}
use of org.finra.herd.model.jpa.JobDefinitionEntity in project herd by FINRAOS.
the class NotificationRegistrationDaoTestHelper method createBusinessObjectDataNotificationRegistrationEntity.
/**
* Creates and persists a business object data notification registration entity.
*
* @param notificationRegistrationKey the business object data notification registration key
* @param notificationEventTypeCode the notification event type
* @param businessObjectDefinitionNamespace the business object definition namespace
* @param businessObjectDefinitionName the business object definition name
* @param businessObjectFormatUsage the business object usage
* @param businessObjectFormatFileType the business object format file type
* @param businessObjectFormatVersion the business object format version
* @param storageName the storage name
* @param newBusinessObjectDataStatus the new business object data status
* @param oldBusinessObjectDataStatus the old business object data status
* @param jobActions the list of job actions
* @param notificationRegistrationStatus the notification registration status
*
* @return the newly created business object data notification registration entity
*/
public BusinessObjectDataNotificationRegistrationEntity createBusinessObjectDataNotificationRegistrationEntity(NotificationRegistrationKey notificationRegistrationKey, String notificationEventTypeCode, String businessObjectDefinitionNamespace, String businessObjectDefinitionName, String businessObjectFormatUsage, String businessObjectFormatFileType, Integer businessObjectFormatVersion, String storageName, String newBusinessObjectDataStatus, String oldBusinessObjectDataStatus, List<JobAction> jobActions, String notificationRegistrationStatus) {
// Create a namespace entity if needed.
NamespaceEntity namespaceEntity = namespaceDao.getNamespaceByCd(notificationRegistrationKey.getNamespace());
if (namespaceEntity == null) {
namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(notificationRegistrationKey.getNamespace());
}
// Create a notification event type entity if needed.
NotificationEventTypeEntity notificationEventTypeEntity = notificationEventTypeDao.getNotificationEventTypeByCode(notificationEventTypeCode);
if (notificationEventTypeEntity == null) {
notificationEventTypeEntity = createNotificationEventTypeEntity(notificationEventTypeCode);
}
// Create a business object definition entity if needed.
BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDao.getBusinessObjectDefinitionByKey(new BusinessObjectDefinitionKey(businessObjectDefinitionNamespace, businessObjectDefinitionName));
if (businessObjectDefinitionEntity == null) {
businessObjectDefinitionEntity = businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(businessObjectDefinitionNamespace, businessObjectDefinitionName, AbstractDaoTest.DATA_PROVIDER_NAME, AbstractDaoTest.BDEF_DESCRIPTION);
}
// Create a business object format file type entity if needed.
FileTypeEntity fileTypeEntity = null;
if (StringUtils.isNotBlank(businessObjectFormatFileType)) {
fileTypeEntity = fileTypeDao.getFileTypeByCode(businessObjectFormatFileType);
if (fileTypeEntity == null) {
fileTypeEntity = fileTypeDaoTestHelper.createFileTypeEntity(businessObjectFormatFileType);
}
}
// Create a storage entity if needed.
StorageEntity storageEntity = null;
if (StringUtils.isNotBlank(storageName)) {
storageEntity = storageDao.getStorageByName(storageName);
if (storageEntity == null) {
storageEntity = storageDaoTestHelper.createStorageEntity(storageName, StoragePlatformEntity.S3);
}
}
// Create a business object status entity for new status if needed.
BusinessObjectDataStatusEntity newBusinessObjectDataStatusEntity = null;
if (StringUtils.isNotBlank(newBusinessObjectDataStatus)) {
newBusinessObjectDataStatusEntity = businessObjectDataStatusDao.getBusinessObjectDataStatusByCode(newBusinessObjectDataStatus);
if (newBusinessObjectDataStatusEntity == null) {
newBusinessObjectDataStatusEntity = businessObjectDataStatusDaoTestHelper.createBusinessObjectDataStatusEntity(newBusinessObjectDataStatus);
}
}
// Create a business object status entity for new status if needed.
BusinessObjectDataStatusEntity oldBusinessObjectDataStatusEntity = null;
if (StringUtils.isNotBlank(oldBusinessObjectDataStatus)) {
oldBusinessObjectDataStatusEntity = businessObjectDataStatusDao.getBusinessObjectDataStatusByCode(oldBusinessObjectDataStatus);
if (oldBusinessObjectDataStatusEntity == null) {
oldBusinessObjectDataStatusEntity = businessObjectDataStatusDaoTestHelper.createBusinessObjectDataStatusEntity(oldBusinessObjectDataStatus);
}
}
// Create a notification registration status entity if needed.
NotificationRegistrationStatusEntity notificationRegistrationStatusEntity = notificationRegistrationStatusDao.getNotificationRegistrationStatus(notificationRegistrationStatus);
if (notificationRegistrationStatusEntity == null) {
notificationRegistrationStatusEntity = createNotificationRegistrationStatusEntity(notificationRegistrationStatus);
}
// Create a business object data notification registration entity.
BusinessObjectDataNotificationRegistrationEntity businessObjectDataNotificationRegistrationEntity = new BusinessObjectDataNotificationRegistrationEntity();
businessObjectDataNotificationRegistrationEntity.setNamespace(namespaceEntity);
businessObjectDataNotificationRegistrationEntity.setName(notificationRegistrationKey.getNotificationName());
businessObjectDataNotificationRegistrationEntity.setNotificationEventType(notificationEventTypeEntity);
businessObjectDataNotificationRegistrationEntity.setBusinessObjectDefinition(businessObjectDefinitionEntity);
businessObjectDataNotificationRegistrationEntity.setUsage(businessObjectFormatUsage);
businessObjectDataNotificationRegistrationEntity.setFileType(fileTypeEntity);
businessObjectDataNotificationRegistrationEntity.setBusinessObjectFormatVersion(businessObjectFormatVersion);
businessObjectDataNotificationRegistrationEntity.setStorage(storageEntity);
businessObjectDataNotificationRegistrationEntity.setNewBusinessObjectDataStatus(newBusinessObjectDataStatusEntity);
businessObjectDataNotificationRegistrationEntity.setOldBusinessObjectDataStatus(oldBusinessObjectDataStatusEntity);
businessObjectDataNotificationRegistrationEntity.setNotificationRegistrationStatus(notificationRegistrationStatusEntity);
if (!CollectionUtils.isEmpty(jobActions)) {
List<NotificationActionEntity> notificationActionEntities = new ArrayList<>();
businessObjectDataNotificationRegistrationEntity.setNotificationActions(notificationActionEntities);
for (JobAction jobAction : jobActions) {
// Create a job definition entity if needed.
JobDefinitionEntity jobDefinitionEntity = jobDefinitionDao.getJobDefinitionByAltKey(jobAction.getNamespace(), jobAction.getJobName());
if (jobDefinitionEntity == null) {
jobDefinitionEntity = jobDefinitionDaoTestHelper.createJobDefinitionEntity(jobAction.getNamespace(), jobAction.getJobName(), String.format("Description of \"%s.%s\" job definition.", jobAction.getNamespace(), jobAction.getJobName()), String.format("%s.%s.%s", jobAction.getNamespace(), jobAction.getJobName(), AbstractDaoTest.ACTIVITI_ID));
}
NotificationJobActionEntity notificationJobActionEntity = new NotificationJobActionEntity();
notificationActionEntities.add(notificationJobActionEntity);
notificationJobActionEntity.setNotificationRegistration(businessObjectDataNotificationRegistrationEntity);
notificationJobActionEntity.setJobDefinition(jobDefinitionEntity);
notificationJobActionEntity.setCorrelationData(jobAction.getCorrelationData());
}
}
return businessObjectDataNotificationRegistrationDao.saveAndRefresh(businessObjectDataNotificationRegistrationEntity);
}
use of org.finra.herd.model.jpa.JobDefinitionEntity in project herd by FINRAOS.
the class JobDefinitionDaoImpl method getJobDefinitionByAltKey.
@Override
public JobDefinitionEntity getJobDefinitionByAltKey(String namespace, String jobName) {
// Create the criteria builder and the criteria.
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<JobDefinitionEntity> criteria = builder.createQuery(JobDefinitionEntity.class);
// The criteria root is the job definition.
Root<JobDefinitionEntity> jobDefinition = criteria.from(JobDefinitionEntity.class);
// Join to the other tables we can filter on.
Join<JobDefinitionEntity, NamespaceEntity> namespaceJoin = jobDefinition.join(JobDefinitionEntity_.namespace);
// Create the standard restrictions (i.e. the standard where clauses).
Predicate namespaceRestriction = builder.equal(builder.upper(namespaceJoin.get(NamespaceEntity_.code)), namespace.toUpperCase());
Predicate jobNameRestriction = builder.equal(builder.upper(jobDefinition.get(JobDefinitionEntity_.name)), jobName.toUpperCase());
criteria.select(jobDefinition).where(builder.and(namespaceRestriction, jobNameRestriction));
return executeSingleResultQuery(criteria, String.format("Found more than one Activiti job definition with parameters {namespace=\"%s\", jobName=\"%s\"}.", namespace, jobName));
}
Aggregations