Search in sources :

Example 26 with ObjectNotFoundException

use of org.finra.herd.model.ObjectNotFoundException in project herd by FINRAOS.

the class BusinessObjectDataInitiateRestoreHelperServiceTest method testPrepareToInitiateRestoreInvalidParameters.

@Test
public void testPrepareToInitiateRestoreInvalidParameters() {
    // Create a business object data key.
    BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION);
    // Create database entities required for testing.
    businessObjectDataDaoTestHelper.createBusinessObjectDataEntity(businessObjectDataKey, LATEST_VERSION_FLAG_SET, BDATA_STATUS);
    // Validate that this business object data exists.
    assertNotNull(businessObjectDataDao.getBusinessObjectDataByAltKey(businessObjectDataKey));
    // Try to execute a before step for the initiate a business object data restore request using an invalid namespace.
    try {
        businessObjectDataInitiateRestoreHelperService.prepareToInitiateRestore(new BusinessObjectDataKey(I_DO_NOT_EXIST, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION), EXPIRATION_IN_DAYS);
        fail();
    } catch (ObjectNotFoundException e) {
        assertEquals(businessObjectDataServiceTestHelper.getExpectedBusinessObjectDataNotFoundErrorMessage(I_DO_NOT_EXIST, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, NO_BDATA_STATUS), e.getMessage());
    }
    // Try to execute a before step for the initiate a business object data restore request using an invalid business object definition name.
    try {
        businessObjectDataInitiateRestoreHelperService.prepareToInitiateRestore(new BusinessObjectDataKey(BDEF_NAMESPACE, I_DO_NOT_EXIST, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION), EXPIRATION_IN_DAYS);
        fail();
    } catch (ObjectNotFoundException e) {
        assertEquals(businessObjectDataServiceTestHelper.getExpectedBusinessObjectDataNotFoundErrorMessage(BDEF_NAMESPACE, I_DO_NOT_EXIST, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, NO_BDATA_STATUS), e.getMessage());
    }
    // Try to execute a before step for the initiate a business object data restore request using an invalid format usage.
    try {
        businessObjectDataInitiateRestoreHelperService.prepareToInitiateRestore(new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, I_DO_NOT_EXIST, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION), EXPIRATION_IN_DAYS);
        fail();
    } catch (ObjectNotFoundException e) {
        assertEquals(businessObjectDataServiceTestHelper.getExpectedBusinessObjectDataNotFoundErrorMessage(BDEF_NAMESPACE, BDEF_NAME, I_DO_NOT_EXIST, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, NO_BDATA_STATUS), e.getMessage());
    }
    // Try to execute a before step for the initiate a business object data restore request using an invalid format file type.
    try {
        businessObjectDataInitiateRestoreHelperService.prepareToInitiateRestore(new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, I_DO_NOT_EXIST, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION), EXPIRATION_IN_DAYS);
        fail();
    } catch (ObjectNotFoundException e) {
        assertEquals(businessObjectDataServiceTestHelper.getExpectedBusinessObjectDataNotFoundErrorMessage(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, I_DO_NOT_EXIST, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, NO_BDATA_STATUS), e.getMessage());
    }
    // Try to execute a before step for the initiate a business object data restore request using an invalid business object format version.
    try {
        businessObjectDataInitiateRestoreHelperService.prepareToInitiateRestore(new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INVALID_FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION), EXPIRATION_IN_DAYS);
        fail();
    } catch (ObjectNotFoundException e) {
        assertEquals(businessObjectDataServiceTestHelper.getExpectedBusinessObjectDataNotFoundErrorMessage(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INVALID_FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, NO_BDATA_STATUS), e.getMessage());
    }
    // Try to execute a before step for the initiate a business object data restore request using an invalid primary partition value.
    try {
        businessObjectDataInitiateRestoreHelperService.prepareToInitiateRestore(new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, I_DO_NOT_EXIST, SUBPARTITION_VALUES, DATA_VERSION), EXPIRATION_IN_DAYS);
        fail();
    } catch (ObjectNotFoundException e) {
        assertEquals(businessObjectDataServiceTestHelper.getExpectedBusinessObjectDataNotFoundErrorMessage(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, I_DO_NOT_EXIST, SUBPARTITION_VALUES, DATA_VERSION, NO_BDATA_STATUS), e.getMessage());
    }
    // Try to execute a before step for the initiate a business object data restore request using an invalid sub-partition value.
    for (int i = 0; i < SUBPARTITION_VALUES.size(); i++) {
        List<String> testSubPartitionValues = new ArrayList<>(SUBPARTITION_VALUES);
        testSubPartitionValues.set(i, I_DO_NOT_EXIST);
        try {
            businessObjectDataInitiateRestoreHelperService.prepareToInitiateRestore(new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, testSubPartitionValues, DATA_VERSION), EXPIRATION_IN_DAYS);
            fail();
        } catch (ObjectNotFoundException e) {
            assertEquals(businessObjectDataServiceTestHelper.getExpectedBusinessObjectDataNotFoundErrorMessage(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, testSubPartitionValues, DATA_VERSION, NO_BDATA_STATUS), e.getMessage());
        }
    }
    // Try to execute a before step for the initiate a business object data restore request using an invalid business object data version.
    try {
        businessObjectDataInitiateRestoreHelperService.prepareToInitiateRestore(new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, INVALID_DATA_VERSION), EXPIRATION_IN_DAYS);
        fail();
    } catch (ObjectNotFoundException e) {
        assertEquals(businessObjectDataServiceTestHelper.getExpectedBusinessObjectDataNotFoundErrorMessage(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, INVALID_DATA_VERSION, NO_BDATA_STATUS), e.getMessage());
    }
    // Try to execute a before step for the initiate a business object data restore request using an invalid expiration time value.
    try {
        businessObjectDataInitiateRestoreHelperService.prepareToInitiateRestore(new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION), 0);
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals("Expiration in days value must be a positive integer.", e.getMessage());
    }
}
Also used : ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) ArrayList(java.util.ArrayList) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) Test(org.junit.Test)

Example 27 with ObjectNotFoundException

use of org.finra.herd.model.ObjectNotFoundException in project herd by FINRAOS.

the class JobServiceImpl method createAndStartJob.

@NamespacePermission(fields = "#request?.namespace", permissions = NamespacePermissionEnum.EXECUTE)
@Override
public Job createAndStartJob(JobCreateRequest request) throws Exception {
    // Perform the validation.
    validateJobCreateRequest(request);
    // Get the namespace and ensure it exists.
    NamespaceEntity namespaceEntity = namespaceDaoHelper.getNamespaceEntity(request.getNamespace());
    // Get the job definition and ensure it exists.
    JobDefinitionEntity jobDefinitionEntity = jobDefinitionDao.getJobDefinitionByAltKey(request.getNamespace(), request.getJobName());
    if (jobDefinitionEntity == null) {
        throw new ObjectNotFoundException("Job definition with name \"" + request.getJobName() + "\" doesn't exist for namespace \"" + request.getNamespace() + "\".");
    }
    // Build the parameters map
    Map<String, Object> mergedParameters = getParameters(jobDefinitionEntity, request);
    // Create a process instance holder to check for a handle to the process instance once it is created.
    String processDefinitionId = jobDefinitionEntity.getActivitiId();
    ProcessDefinition processDefinition = activitiService.getProcessDefinitionById(processDefinitionId);
    Assert.notNull(processDefinition, "No process definition found for Id: " + processDefinitionId);
    Assert.isTrue(!processDefinition.isSuspended(), "Cannot start process instance for process definition Id: " + processDefinitionId + " because it is suspended.");
    ProcessInstance processInstance = activitiService.startProcessInstanceByProcessDefinitionId(processDefinitionId, mergedParameters);
    // If we get here, we have a newly created process instance. Log to know it was created successfully.
    LOGGER.info("Created process instance with Id: " + processInstance.getProcessInstanceId() + " for process definition Id: " + processDefinitionId + " with merged parameters: " + mergedParameters);
    // Create and return the job object.
    return createJobFromRequest(namespaceEntity.getCode(), jobDefinitionEntity.getName(), mergedParameters, processInstance.getProcessInstanceId());
}
Also used : JobDefinitionEntity(org.finra.herd.model.jpa.JobDefinitionEntity) NamespaceEntity(org.finra.herd.model.jpa.NamespaceEntity) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) NamespacePermission(org.finra.herd.model.annotation.NamespacePermission)

Example 28 with ObjectNotFoundException

use of org.finra.herd.model.ObjectNotFoundException in project herd by FINRAOS.

the class JobServiceImpl method updateJob.

@Override
public Job updateJob(String jobId, JobUpdateRequest jobUpdateRequest) {
    // Validate the input parameters.
    Assert.hasText(jobId, "A job id must be specified.");
    Assert.notNull(jobUpdateRequest, "A job update request must be specified.");
    Assert.notNull(jobUpdateRequest.getAction(), "A job update action must be specified.");
    // Trim input parameters.
    String localJobId = jobId.trim();
    // Get process instance by id.
    ProcessInstance processInstance = activitiService.getProcessInstanceById(localJobId);
    // Perform action as per job update request.
    if (processInstance != null) {
        // Check the namespace permissions for the current user for the given process definition key.
        checkPermissions(processInstance.getProcessDefinitionKey(), new NamespacePermissionEnum[] { NamespacePermissionEnum.EXECUTE });
        // Suspend or resume the process instance per specified job update action.
        if (JobActionEnum.SUSPEND.equals(jobUpdateRequest.getAction())) {
            if (!processInstance.isSuspended()) {
                // Suspend the process instance.
                activitiService.suspendProcessInstance(localJobId);
            } else {
                throw new IllegalArgumentException(String.format("Job with ID \"%s\" is already in a suspended state.", localJobId));
            }
        } else // The job update action is RESUME.
        {
            if (processInstance.isSuspended()) {
                // Resume (activate) the process instance.
                activitiService.resumeProcessInstance(localJobId);
            } else {
                throw new IllegalArgumentException(String.format("Job with ID \"%s\" is already in an active state.", localJobId));
            }
        }
    } else {
        throw new ObjectNotFoundException(String.format("Job with ID \"%s\" does not exist or is already completed.", localJobId));
    }
    return getJob(localJobId, false, false);
}
Also used : ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance)

Example 29 with ObjectNotFoundException

use of org.finra.herd.model.ObjectNotFoundException in project herd by FINRAOS.

the class JobServiceImpl method deleteJob.

@Override
public Job deleteJob(String jobId, JobDeleteRequest jobDeleteRequest) throws Exception {
    Assert.hasText(jobId, "jobId must be specified");
    Assert.notNull(jobDeleteRequest, "jobDeleteRequest must be specified");
    Assert.hasText(jobDeleteRequest.getDeleteReason(), "deleteReason must be specified");
    // Trim input parameters.
    String localJobId = jobId.trim();
    ProcessInstance mainProcessInstance = activitiService.getProcessInstanceById(localJobId);
    if (mainProcessInstance != null) {
        checkPermissions(mainProcessInstance.getProcessDefinitionKey(), new NamespacePermissionEnum[] { NamespacePermissionEnum.EXECUTE });
        // Load all processes (main process and sub-processes) into a deque to be later deleted.
        Deque<String> processInstanceIds = new ArrayDeque<>();
        processInstanceIds.push(mainProcessInstance.getProcessInstanceId());
        Deque<String> superProcessInstanceIds = new ArrayDeque<>();
        superProcessInstanceIds.push(mainProcessInstance.getProcessInstanceId());
        while (!superProcessInstanceIds.isEmpty()) {
            String superProcessInstanceId = superProcessInstanceIds.pop();
            // Get all executions with the parent id equal to the super process instance id.
            for (Execution execution : activitiRuntimeService.createExecutionQuery().parentId(superProcessInstanceId).list()) {
                processInstanceIds.push(execution.getId());
            }
            // Get all active sub-processes for the super process instance id.
            for (ProcessInstance subProcessInstance : activitiRuntimeService.createProcessInstanceQuery().superProcessInstanceId(superProcessInstanceId).active().list()) {
                processInstanceIds.push(subProcessInstance.getId());
                superProcessInstanceIds.push(subProcessInstance.getId());
            }
        }
        // Delete all processes individually in LIFO order.
        while (!processInstanceIds.isEmpty()) {
            activitiService.deleteProcessInstance(processInstanceIds.pop(), jobDeleteRequest.getDeleteReason());
        }
    } else {
        throw new ObjectNotFoundException(String.format("Job with ID \"%s\" does not exist or is already completed.", localJobId));
    }
    return getJob(localJobId, false, false);
}
Also used : Execution(org.activiti.engine.runtime.Execution) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ArrayDeque(java.util.ArrayDeque)

Example 30 with ObjectNotFoundException

use of org.finra.herd.model.ObjectNotFoundException in project herd by FINRAOS.

the class JobServiceImpl method signalJob.

@Override
public Job signalJob(JobSignalRequest request) throws Exception {
    // Perform the validation.
    validateJobSignalRequest(request);
    Execution execution = activitiService.getExecutionByProcessInstanceIdAndActivitiId(request.getId(), request.getReceiveTaskId());
    if (execution == null) {
        throw new ObjectNotFoundException(String.format("No job found for matching job id: \"%s\" and receive task id: \"%s\".", request.getId(), request.getReceiveTaskId()));
    }
    String processDefinitionKey = activitiService.getProcessInstanceById(execution.getProcessInstanceId()).getProcessDefinitionKey();
    checkPermissions(processDefinitionKey, new NamespacePermissionEnum[] { NamespacePermissionEnum.EXECUTE });
    // Retrieve the job before signaling.
    Job job = getJob(request.getId(), false, false);
    // Build the parameters map
    Map<String, Object> signalParameters = getParameters(request);
    // Signal the workflow.
    activitiService.signal(execution.getId(), signalParameters);
    // Build the parameters map merged with job and signal parameters.
    Map<String, Object> mergedParameters = new HashMap<>();
    for (Parameter jobParam : job.getParameters()) {
        mergedParameters.put(jobParam.getName(), jobParam.getValue());
    }
    mergedParameters.putAll(signalParameters);
    // Update the parameters in job
    populateWorkflowParameters(job, mergedParameters);
    return job;
}
Also used : Execution(org.activiti.engine.runtime.Execution) HashMap(java.util.HashMap) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) Parameter(org.finra.herd.model.api.xml.Parameter) Job(org.finra.herd.model.api.xml.Job)

Aggregations

ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)216 Test (org.junit.Test)193 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)36 ArrayList (java.util.ArrayList)18 BusinessObjectDefinitionKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionKey)16 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)16 BusinessObjectDataAttributeKey (org.finra.herd.model.api.xml.BusinessObjectDataAttributeKey)14 PartitionValueFilter (org.finra.herd.model.api.xml.PartitionValueFilter)12 TagKey (org.finra.herd.model.api.xml.TagKey)11 NotificationRegistrationKey (org.finra.herd.model.api.xml.NotificationRegistrationKey)10 StoragePolicyKey (org.finra.herd.model.api.xml.StoragePolicyKey)10 BusinessObjectDataDdlRequest (org.finra.herd.model.api.xml.BusinessObjectDataDdlRequest)9 StorageUnitEntity (org.finra.herd.model.jpa.StorageUnitEntity)8 InstanceDefinition (org.finra.herd.model.api.xml.InstanceDefinition)7 MasterInstanceDefinition (org.finra.herd.model.api.xml.MasterInstanceDefinition)7 AbstractDaoTest (org.finra.herd.dao.AbstractDaoTest)6 BusinessObjectDefinitionColumnKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionColumnKey)6 BusinessObjectFormatKey (org.finra.herd.model.api.xml.BusinessObjectFormatKey)6 AmazonServiceException (com.amazonaws.AmazonServiceException)5 BusinessObjectData (org.finra.herd.model.api.xml.BusinessObjectData)5