Search in sources :

Example 31 with ObjectNotFoundException

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

the class BaseJavaDelegate method setSecurityContext.

/**
 * Sets the security context per last updater of the current process instance's job definition.
 *
 * @param execution the current execution context
 */
protected void setSecurityContext(DelegateExecution execution) {
    String processDefinitionId = execution.getProcessDefinitionId();
    // Get process definition by process definition ID from Activiti.
    ProcessDefinition processDefinition = activitiService.getProcessDefinitionById(processDefinitionId);
    // Validate that we retrieved the process definition from Activiti.
    if (processDefinition == null) {
        throw new ObjectNotFoundException(String.format("Failed to find Activiti process definition for processDefinitionId=\"%s\".", processDefinitionId));
    }
    // Retrieve the process definition key.
    String processDefinitionKey = processDefinition.getKey();
    // Get the job definition key.
    JobDefinitionAlternateKeyDto jobDefinitionKey = jobDefinitionHelper.getJobDefinitionKey(processDefinitionKey);
    // Get the job definition from the Herd repository and validate that it exists.
    JobDefinitionEntity jobDefinitionEntity = jobDefinitionDaoHelper.getJobDefinitionEntity(jobDefinitionKey.getNamespace(), jobDefinitionKey.getJobName());
    // Set the security context per last updater of the job definition.
    String updatedByUserId = jobDefinitionEntity.getUpdatedBy();
    ApplicationUser applicationUser = new ApplicationUser(getClass());
    applicationUser.setUserId(updatedByUserId);
    userNamespaceAuthorizationHelper.buildNamespaceAuthorizations(applicationUser);
    SecurityContextHolder.getContext().setAuthentication(new PreAuthenticatedAuthenticationToken(new SecurityUserWrapper(updatedByUserId, "", true, true, true, true, Collections.emptyList(), applicationUser), null));
}
Also used : ApplicationUser(org.finra.herd.model.dto.ApplicationUser) JobDefinitionEntity(org.finra.herd.model.jpa.JobDefinitionEntity) JobDefinitionAlternateKeyDto(org.finra.herd.model.dto.JobDefinitionAlternateKeyDto) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) SecurityUserWrapper(org.finra.herd.model.dto.SecurityUserWrapper) PreAuthenticatedAuthenticationToken(org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition)

Example 32 with ObjectNotFoundException

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

the class StoragePlatformRestControllerTest method testGetStoragePlatformInvalidName.

@Test(expected = ObjectNotFoundException.class)
public void testGetStoragePlatformInvalidName() throws Exception {
    ObjectNotFoundException exception = new ObjectNotFoundException("not found");
    String platform = "invalid" + getRandomSuffix();
    when(storagePlatformService.getStoragePlatform(platform)).thenThrow(exception);
    storagePlatformRestController.getStoragePlatform(platform);
}
Also used : ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) Test(org.junit.Test)

Example 33 with ObjectNotFoundException

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

the class ExpectedPartitionValueServiceImpl method deleteExpectedPartitionValues.

/**
 * Deletes specified expected partition values from an existing partition key group which is identified by name.
 *
 * @param expectedPartitionValuesDeleteRequest the information needed to delete the expected partition values
 *
 * @return the expected partition values that got deleted
 */
@Override
public ExpectedPartitionValuesInformation deleteExpectedPartitionValues(ExpectedPartitionValuesDeleteRequest expectedPartitionValuesDeleteRequest) {
    // Perform request validation and trim request parameters.
    validateExpectedPartitionValuesDeleteRequest(expectedPartitionValuesDeleteRequest);
    // Retrieve and ensure that a partition key group exists with the specified name.
    PartitionKeyGroupEntity partitionKeyGroupEntity = partitionKeyGroupDaoHelper.getPartitionKeyGroupEntity(expectedPartitionValuesDeleteRequest.getPartitionKeyGroupKey());
    // Load all existing expected partition value entities into a map for quick access.
    Map<String, ExpectedPartitionValueEntity> expectedPartitionValueEntityMap = getExpectedPartitionValueEntityMap(partitionKeyGroupEntity.getExpectedPartitionValues());
    // Build a list of all expected partition value entities to be deleted.
    Collection<ExpectedPartitionValueEntity> deletedExpectedPartitionValueEntities = new ArrayList<>();
    for (String expectedPartitionValue : expectedPartitionValuesDeleteRequest.getExpectedPartitionValues()) {
        // Find the relative expected partition entity.
        ExpectedPartitionValueEntity expectedPartitionValueEntity = expectedPartitionValueEntityMap.get(expectedPartitionValue);
        if (expectedPartitionValueEntity != null) {
            deletedExpectedPartitionValueEntities.add(expectedPartitionValueEntity);
        } else {
            throw new ObjectNotFoundException(String.format("Expected partition value \"%s\" doesn't exist in \"%s\" partition key group.", expectedPartitionValue, partitionKeyGroupEntity.getPartitionKeyGroupName()));
        }
    }
    // Perform the actual deletion.
    for (ExpectedPartitionValueEntity expectedPartitionValueEntity : deletedExpectedPartitionValueEntities) {
        partitionKeyGroupEntity.getExpectedPartitionValues().remove(expectedPartitionValueEntity);
        expectedPartitionValueDao.delete(expectedPartitionValueEntity);
    }
    return createExpectedPartitionValuesInformationFromEntities(partitionKeyGroupEntity, deletedExpectedPartitionValueEntities);
}
Also used : ExpectedPartitionValueEntity(org.finra.herd.model.jpa.ExpectedPartitionValueEntity) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) ArrayList(java.util.ArrayList) PartitionKeyGroupEntity(org.finra.herd.model.jpa.PartitionKeyGroupEntity)

Example 34 with ObjectNotFoundException

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

the class SystemJobHelper method runSystemJob.

/**
 * Starts a system job asynchronously.
 *
 * @param jobName the system job name (case-sensitive)
 * @param parameters the list of parameters
 *
 * @throws org.quartz.SchedulerException if fails to schedule the system job
 */
public void runSystemJob(String jobName, List<Parameter> parameters) throws SchedulerException {
    // Validate the system job name.
    AbstractSystemJob systemJob;
    try {
        systemJob = (AbstractSystemJob) applicationContext.getBean(jobName);
    } catch (Exception e) {
        throw new ObjectNotFoundException(String.format("System job with name \"%s\" doesn't exist.", jobName), e);
    }
    // Validate parameters per relative system job.
    systemJob.validateParameters(parameters);
    // Prepare a trigger to run the system job only once.
    TriggerKey triggerKey = TriggerKey.triggerKey(jobName + AbstractSystemJob.RUN_ONCE_TRIGGER_SUFFIX);
    Trigger trigger = newTrigger().withIdentity(triggerKey).forJob(jobName).usingJobData(systemJob.getJobDataMap(parameters)).startNow().build();
    LOGGER.debug(String.format("schedule job with trigger: calendarName: %s, description: %s, endTime: %s, finalFireTime: %s, jobKey: %s, key: %s, " + "misfireInstruction: %s, nextFireTime: %s, previousFireTime: %s, priority: %s, startTime: %s", trigger.getCalendarName(), trigger.getDescription(), trigger.getEndTime(), trigger.getFinalFireTime(), trigger.getJobKey(), trigger.getKey(), trigger.getMisfireInstruction(), trigger.getNextFireTime(), trigger.getPreviousFireTime(), trigger.getPriority(), trigger.getStartTime()));
    // Schedule the system job.
    schedulerFactory.getScheduler().scheduleJob(trigger);
}
Also used : TriggerKey(org.quartz.TriggerKey) TriggerBuilder.newTrigger(org.quartz.TriggerBuilder.newTrigger) Trigger(org.quartz.Trigger) AbstractSystemJob(org.finra.herd.service.systemjobs.AbstractSystemJob) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) SchedulerException(org.quartz.SchedulerException)

Example 35 with ObjectNotFoundException

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

the class SearchIndexDaoHelper method getActiveSearchIndex.

/**
 * Fetches the name of the active index for the specified type
 *
 * @param indexType the type of the search index
 * @return the name of the active index
 */
public String getActiveSearchIndex(String indexType) {
    // Get the search index type and ensure it exists.
    SearchIndexTypeEntity searchIndexTypeEntity = searchIndexTypeDaoHelper.getSearchIndexTypeEntity(indexType);
    // Fetch the list of all search index entities for the specified type and get the active entity
    List<SearchIndexEntity> searchIndexEntities = searchIndexDao.getSearchIndexEntities(searchIndexTypeEntity);
    searchIndexEntities = searchIndexEntities.stream().filter(searchIndexEntity -> searchIndexEntity.getActive() != null && searchIndexEntity.getActive().equals(Boolean.TRUE)).collect(Collectors.toList());
    if (searchIndexEntities.size() == 0) {
        throw new ObjectNotFoundException(String.format("No active search index found for type \"%s\".", indexType));
    }
    return searchIndexEntities.get(0).getName();
}
Also used : ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) SearchIndexTypeEntity(org.finra.herd.model.jpa.SearchIndexTypeEntity) SearchIndexEntity(org.finra.herd.model.jpa.SearchIndexEntity)

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