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));
}
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);
}
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);
}
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);
}
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();
}
Aggregations