use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.
the class AbstractBackupBulkAction method end.
@Override
protected OperationResult end(OperationResult result, Exception exception) {
if (exception != null || (result != null && OperationState.EXECUTED != result.getState())) {
return super.end(result, exception);
}
//
IdmLongRunningTaskDto task = getLongRunningTaskService().get(getLongRunningTaskId());
//
File zipFile = attachmentManager.createTempFile();
try {
// zip file
ZipUtils.compress(zipFolder, zipFile.getPath());
// create attachment
IdmAttachmentDto attachment = new IdmAttachmentDto();
attachment.setInputData(new FileInputStream(zipFile));
attachment.setEncoding(AttachableEntity.DEFAULT_ENCODING);
// zip ~ octet stream
attachment.setMimetype(AttachableEntity.DEFAULT_MIMETYPE);
attachment.setName(String.format("%s.zip", getName()));
attachment = attachmentManager.saveAttachment(task, attachment);
//
ResultModel resultModel = new DefaultResultModel(CoreResultCode.LONG_RUNNING_TASK_PARTITIAL_DOWNLOAD, ImmutableMap.of(AttachableEntity.PARAMETER_DOWNLOAD_URL, String.format("long-running-tasks/%s/download/%s", task.getId(), attachment.getId())));
//
return super.end(new OperationResult.Builder(OperationState.EXECUTED).setModel(resultModel).build(), null);
} catch (IOException ex) {
return super.end(result, ex);
} finally {
FileUtils.deleteQuietly(zipFile);
FileUtils.deleteQuietly(zipFolder);
}
}
use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.
the class AbstractLongRunningTaskExecutor method end.
/**
* Set LRT to executed / exception. Make sure in on end, if method is overriden!
*
* TODO: save result into long running task - blob, text?
*
* @param result
* @param ex
* @return
*/
protected V end(V result, Exception ex) {
Assert.notNull(longRunningTaskId, "LRT has to be persisted before task starts.");
IdmLongRunningTaskDto task = longRunningTaskService.get(longRunningTaskId);
Assert.notNull(task, "Long running task has to be prepared before task is ended");
LOG.debug("Long running task ends [{}] with result [{}].", longRunningTaskId, result, ex);
//
setStateProperties(task);
//
if (ex != null) {
ResultModel resultModel;
if (ex instanceof ResultCodeException) {
resultModel = ((ResultCodeException) ex).getError().getError();
} else {
resultModel = new DefaultResultModel(CoreResultCode.LONG_RUNNING_TASK_FAILED, ImmutableMap.of("taskId", longRunningTaskId, "taskType", task.getTaskType(), ConfigurationService.PROPERTY_INSTANCE_ID, task.getInstanceId()));
}
LOG.error(resultModel.toString(), ex);
task.setResult(new OperationResult.Builder(OperationState.EXCEPTION).setModel(resultModel).setCause(ex).build());
} else if (OperationState.isRunnable(task.getResultState())) {
// executed standardly
LOG.debug("Long running task ended [{}] standardly, previous state [{}], result [{}].", longRunningTaskId, task.getResultState(), result);
OperationResult operationResult;
if (result instanceof OperationResult) {
// operation result is prepared outside as LRT result
operationResult = (OperationResult) result;
} else {
operationResult = new OperationResult(OperationState.RUNNING);
}
if (operationResult.getState().isRunnable()) {
operationResult.setState(OperationState.EXECUTED);
}
//
task.setResult(operationResult);
}
// after update state is send notification with information about end of LRT
task = longRunningTaskService.save(task);
// publish event - LRT ended
// TODO: result is not persisted - propagate him in event?
entityEventManager.publishEvent(new LongRunningTaskEvent(LongRunningTaskEventType.END, task));
//
return result;
}
use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.
the class IdentityContractDeleteProcessor method process.
@Override
public EventResult<IdmIdentityContractDto> process(EntityEvent<IdmIdentityContractDto> event) {
IdmIdentityContractDto contract = event.getContent();
UUID contractId = contract.getId();
Assert.notNull(contractId, "Contract must have a ID!");
boolean forceDelete = getBooleanProperty(PROPERTY_FORCE_DELETE, event.getProperties());
//
// check contract can be deleted - cannot be deleted, when is controlled by slices
IdmContractSliceFilter sliceFilter = new IdmContractSliceFilter();
sliceFilter.setParentContract(contractId);
if (contractSliceService.find(sliceFilter, null).getTotalElements() > 0) {
// Cannot be enforced => contract cannot be deleted at all.
throw new ResultCodeException(CoreResultCode.CONTRACT_IS_CONTROLLED_CANNOT_BE_DELETED, ImmutableMap.of("contractId", contractId));
}
//
// Find all concepts and remove relation on contract
IdmConceptRoleRequestFilter conceptRequestFilter = new IdmConceptRoleRequestFilter();
conceptRequestFilter.setIdentityContractId(contractId);
conceptRequestService.find(conceptRequestFilter, null).getContent().forEach(concept -> {
String message = null;
if (concept.getState().isTerminatedState()) {
message = MessageFormat.format("IdentityContract [{0}] (requested in concept [{1}]) was deleted (not from this role request)!", contractId, concept.getId());
} else {
message = MessageFormat.format("Request change in concept [{0}], was not executed, because requested IdentityContract [{1}] was deleted (not from this role request)!", concept.getId(), contractId);
// Cancel concept and WF
concept = conceptRequestService.cancel(concept);
}
IdmRoleRequestDto request = roleRequestService.get(concept.getRoleRequest());
roleRequestService.addToLog(request, message);
conceptRequestService.addToLog(concept, message);
roleRequestService.save(request);
conceptRequestService.save(concept);
});
//
// delete referenced roles
List<IdmConceptRoleRequestDto> concepts = new ArrayList<>();
identityRoleService.findAllByContract(contractId).forEach(identityRole -> {
// but automatic roles has to be removed in the same request.
if (identityRole.getDirectRole() == null) {
IdmConceptRoleRequestDto conceptRoleRequest = new IdmConceptRoleRequestDto();
conceptRoleRequest.setIdentityRole(identityRole.getId());
conceptRoleRequest.setRole(identityRole.getRole());
conceptRoleRequest.setOperation(ConceptRoleRequestOperation.REMOVE);
// ignore not found
conceptRoleRequest.setIdentityContract(contractId);
//
concepts.add(conceptRoleRequest);
}
});
if (forceDelete) {
// ~ async with force
IdmRoleRequestDto roleRequest = new IdmRoleRequestDto();
roleRequest.setApplicant(contract.getIdentity());
roleRequest.setConceptRoles(concepts);
//
RoleRequestEvent requestEvent = new RoleRequestEvent(RoleRequestEventType.EXCECUTE, roleRequest);
requestEvent.setPriority(PriorityType.HIGH);
//
roleRequestService.startConcepts(requestEvent, event);
} else {
// ~ sync
roleRequestService.executeConceptsImmediate(contract.getIdentity(), concepts);
}
// delete contract guarantees
IdmContractGuaranteeFilter filter = new IdmContractGuaranteeFilter();
filter.setIdentityContractId(contractId);
contractGuaranteeService.find(filter, null).forEach(guarantee -> {
contractGuaranteeService.delete(guarantee);
});
// delete contract positions
IdmContractPositionFilter positionFilter = new IdmContractPositionFilter();
positionFilter.setIdentityContractId(contractId);
contractPositionService.find(positionFilter, null).forEach(position -> {
contractPositionService.delete(position);
});
//
// delete all contract's delegations
IdmDelegationDefinitionFilter delegationFilter = new IdmDelegationDefinitionFilter();
delegationFilter.setDelegatorContractId(contractId);
delegationDefinitionService.find(delegationFilter, null).forEach(delegation -> {
delegationDefinitionService.delete(delegation);
});
// delete identity contract
if (forceDelete) {
LOG.debug("Contract [{}] should be deleted by caller after all asynchronus processes are completed.", contractId);
//
// dirty flag only - will be processed after asynchronous events ends
IdmEntityStateDto stateDeleted = new IdmEntityStateDto();
stateDeleted.setEvent(event.getId());
stateDeleted.setResult(new OperationResultDto.Builder(OperationState.RUNNING).setModel(new DefaultResultModel(CoreResultCode.DELETED)).build());
entityStateManager.saveState(contract, stateDeleted);
//
// set disabled
contract.setState(ContractState.DISABLED);
service.saveInternal(contract);
} else {
service.deleteInternal(contract);
}
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.
the class ContractSliceManagerTest method createDirtyState.
/**
* Create new dirty state for contract slice
*
* @param slice
* @param parameters
* @return
*/
private IdmEntityStateDto createDirtyState(IdmContractSliceDto slice) {
Map<String, Object> transformedMarameters = new HashMap<String, Object>();
transformedMarameters.put("entityId", slice.getId());
DefaultResultModel resultModel = new DefaultResultModel(CoreResultCode.DIRTY_STATE, transformedMarameters);
IdmEntityStateDto dirtyState = new IdmEntityStateDto();
dirtyState.setResult(new OperationResultDto.Builder(OperationState.BLOCKED).setModel(resultModel).build());
return entityStateManager.saveState(slice, dirtyState);
}
use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.
the class IdmMessageDtoUnitTest method testModelWarning.
@Test
public void testModelWarning() {
ResultModel model = new DefaultResultModel(CoreResultCode.BAD_VALUE);
IdmMessageDto message = new IdmMessageDto.Builder().setModel(model).build();
Assert.assertEquals(model.getStatusEnum(), message.getSubject());
Assert.assertEquals(model.getMessage(), message.getTextMessage());
Assert.assertEquals(model.getMessage(), message.getHtmlMessage());
Assert.assertEquals(NotificationLevel.WARNING, message.getLevel());
}
Aggregations