Search in sources :

Example 16 with JobDefinitionEntity

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();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Order(javax.persistence.criteria.Order) JobDefinitionEntity(org.finra.herd.model.jpa.JobDefinitionEntity) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) ArrayList(java.util.ArrayList) Predicate(javax.persistence.criteria.Predicate)

Example 17 with JobDefinitionEntity

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"));
}
Also used : JobDefinitionEntity(org.finra.herd.model.jpa.JobDefinitionEntity) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) Test(org.junit.Test)

Example 18 with JobDefinitionEntity

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);
}
Also used : JobDefinitionEntity(org.finra.herd.model.jpa.JobDefinitionEntity)

Example 19 with 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);
}
Also used : NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) BusinessObjectDefinitionKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionKey) FileTypeEntity(org.finra.herd.model.jpa.FileTypeEntity) BusinessObjectDataStatusEntity(org.finra.herd.model.jpa.BusinessObjectDataStatusEntity) ArrayList(java.util.ArrayList) StorageEntity(org.finra.herd.model.jpa.StorageEntity) NotificationJobActionEntity(org.finra.herd.model.jpa.NotificationJobActionEntity) NotificationEventTypeEntity(org.finra.herd.model.jpa.NotificationEventTypeEntity) JobDefinitionEntity(org.finra.herd.model.jpa.JobDefinitionEntity) JobAction(org.finra.herd.model.api.xml.JobAction) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) NotificationRegistrationStatusEntity(org.finra.herd.model.jpa.NotificationRegistrationStatusEntity) BusinessObjectDataNotificationRegistrationEntity(org.finra.herd.model.jpa.BusinessObjectDataNotificationRegistrationEntity) NotificationActionEntity(org.finra.herd.model.jpa.NotificationActionEntity)

Example 20 with JobDefinitionEntity

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));
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) JobDefinitionEntity(org.finra.herd.model.jpa.JobDefinitionEntity) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) Predicate(javax.persistence.criteria.Predicate)

Aggregations

JobDefinitionEntity (org.finra.herd.model.jpa.JobDefinitionEntity)36 NamespaceEntity (org.finra.herd.model.jpa.NamespaceEntity)18 Test (org.junit.Test)17 ArrayList (java.util.ArrayList)12 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)11 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)7 Collection (java.util.Collection)6 HashSet (java.util.HashSet)6 JobDefinition (org.finra.herd.model.api.xml.JobDefinition)5 JobStatusEnum (org.finra.herd.model.api.xml.JobStatusEnum)5 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)4 Predicate (javax.persistence.criteria.Predicate)4 NamespacePermission (org.finra.herd.model.annotation.NamespacePermission)4 JobAction (org.finra.herd.model.api.xml.JobAction)4 JobDefinitionCreateRequest (org.finra.herd.model.api.xml.JobDefinitionCreateRequest)4 JobSummaries (org.finra.herd.model.api.xml.JobSummaries)4 JobSummary (org.finra.herd.model.api.xml.JobSummary)4 NotificationActionEntity (org.finra.herd.model.jpa.NotificationActionEntity)4 NotificationJobActionEntity (org.finra.herd.model.jpa.NotificationJobActionEntity)4 Date (java.util.Date)3