use of eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto in project CzechIdMng by bcvsolutions.
the class IdentityAddContractGuaranteeBulkActionTest method processByIdsGuaranteeNotSetTwice.
@Test
public void processByIdsGuaranteeNotSetTwice() {
List<IdmIdentityDto> guarantees = this.createIdentities(1);
IdmIdentityDto employee = getHelper().createIdentity();
IdmIdentityContractDto contract1 = getHelper().getPrimeContract(employee);
// set guarantee before reassigned by BA
createContractGuarantees(contract1, guarantees);
Assert.assertTrue(isContractGuarantee(contract1, guarantees).isEmpty());
IdmBulkActionDto bulkAction = this.findBulkAction(IdmIdentity.class, IdentityAddContractGuaranteeBulkAction.NAME);
Set<UUID> ids = this.getIdFromList(Arrays.asList(employee));
bulkAction.setIdentifiers(ids);
Map<String, Object> properties = new HashMap<>();
List<String> uuidStrings = guarantees.stream().map(AbstractDto::getId).map(Object::toString).collect(Collectors.toList());
properties.put(IdentityAddContractGuaranteeBulkAction.PROPERTY_NEW_GUARANTEE, uuidStrings);
bulkAction.setProperties(properties);
bulkActionManager.processAction(bulkAction);
// test guarantees on all contracts
List<IdmContractGuaranteeDto> assigned = getGuaranteesForContract(contract1.getId());
// same guarantee is assigned only once
Assert.assertEquals(guarantees.size(), assigned.size());
Set<UUID> assignedGuarUUID = assigned.stream().map(IdmContractGuaranteeDto::getGuarantee).collect(Collectors.toSet());
guarantees.forEach(guarantee -> {
Assert.assertTrue(assignedGuarUUID.contains(guarantee.getId()));
});
}
use of eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto in project CzechIdMng by bcvsolutions.
the class AbstractBulkActionTest method findBulkActionForDto.
/**
* Find bulk action
*
* @param dto
* @param name
* @return
*/
protected IdmBulkActionDto findBulkActionForDto(Class<? extends BaseDto> dto, String name) {
List<IdmBulkActionDto> actions = bulkActionManager.getAvailableActionsForDto(dto);
assertFalse(actions.isEmpty());
for (IdmBulkActionDto action : actions) {
if (action.getName().equals(name)) {
return action;
}
}
fail("For entity class: " + dto.getSimpleName() + " was not found bulk action: " + name);
return null;
}
use of eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto in project CzechIdMng by bcvsolutions.
the class AbstractExportBulkActionTest method executeExportAndImport.
/**
* Provides export and following import operation for supplied dto It accepts a map of methods in order to supply necessary operation between individual steps.
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
protected <DTO extends AbstractDto> IdmExportImportDto executeExportAndImport(List<DTO> dtos, Class dtoType, String actionName, Map<String, Consumer<DTO>> execute) {
String batchName = getHelper().createName();
Class<? extends BaseEntity> entityClass = getLookupService().getEntityClass(dtoType);
Set<UUID> ids = dtos.stream().map(AbstractDto::getId).collect(Collectors.toSet());
// Bulk action preparation
IdmBulkActionDto bulkAction = findBulkAction(entityClass, actionName);
bulkAction.setIdentifiers(ids);
bulkAction.getProperties().put(AbstractExportBulkAction.PROPERTY_NAME, batchName);
IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
checkResultLrt(processAction, (long) dtos.size(), null, null);
// Export batch is created
IdmExportImportFilter exportImportFilter = new IdmExportImportFilter();
exportImportFilter.setText(batchName);
List<IdmExportImportDto> batches = exportImportService.find(exportImportFilter, null).getContent();
Assert.assertEquals(1, batches.size());
IdmExportImportDto batch = batches.get(0);
Assert.assertEquals(OperationState.EXECUTED, batch.getResult().getState());
Assert.assertNotNull(batch.getData());
// Find export batch as attachment
List<IdmAttachmentDto> attachments = //
attachmentManager.getAttachments(batch.getId(), getLookupService().getEntityClass(IdmExportImportDto.class).getCanonicalName(), //
null).getContent();
Assert.assertEquals(1, attachments.size());
IdmAttachmentDto attachment = attachments.get(0);
// Upload import
IdmExportImportDto importBatch = importManager.uploadImport(attachment.getName(), attachment.getName(), attachmentManager.getAttachmentData(attachment.getId()));
Assert.assertNotNull(importBatch);
Assert.assertEquals(batch.getName(), importBatch.getName());
Assert.assertEquals(ExportImportType.IMPORT, importBatch.getType());
// Get a service corresponding to the DTO type
ReadWriteDtoService<BaseDto, BaseFilter> service = ((ReadWriteDtoService<BaseDto, BaseFilter>) getLookupService().getDtoService(dtoType));
dtos.forEach(dto -> {
// Execute supplied action before original dto deletion
if (execute != null && execute.containsKey(EXECUTE_BEFORE_DTO_DELETE)) {
execute.get(EXECUTE_BEFORE_DTO_DELETE).accept(dto);
}
// Original dto deletion
service.delete(dto);
Assert.assertNull(service.get(dto.getId()));
});
// Execute import
importBatch = importManager.executeImport(importBatch, false);
Assert.assertNotNull(importBatch);
Assert.assertEquals(batch.getName(), importBatch.getName());
Assert.assertEquals(ExportImportType.IMPORT, importBatch.getType());
Assert.assertEquals(OperationState.EXECUTED, importBatch.getResult().getState());
return importBatch;
}
use of eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto in project CzechIdMng by bcvsolutions.
the class AbstractMonitoringIgnoredBulkActionIntegrationTest method testCreateMonitoringIgnoredState.
@Test
public void testCreateMonitoringIgnoredState() {
DTO dto = createDto();
IdmBulkActionDto bulkAction = bulkActionManager.toDto(getBulkAction());
Set<UUID> ids = Sets.newHashSet(dto.getId());
bulkAction.setIdentifiers(ids);
IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
//
checkResultLrt(processAction, 1l, null, null);
//
IdmEntityStateFilter filter = new IdmEntityStateFilter();
filter.setOwnerId(dto.getId());
filter.setResultCode(CoreResultCode.MONITORING_IGNORED.getCode());
//
Assert.assertFalse(entityStateManager.findStates(filter, null).isEmpty());
}
use of eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto in project CzechIdMng by bcvsolutions.
the class BulkActionController method find.
@ResponseBody
@RequestMapping(method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.MODULE_READ + "')")
@ApiOperation(value = "Find all bulk actions", nickname = "findAllBulkActions", tags = { BulkActionController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.MODULE_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.MODULE_READ, description = "") }) }, notes = "Returns all registered bulk actions with state properties (disabled, order).")
@SuppressWarnings({ "unchecked", "rawtypes" })
public Resources<?> find(@RequestParam(required = false) MultiValueMap<String, Object> parameters) {
List<IdmBulkActionDto> records = bulkActionManager.find(toFilter(parameters));
PageImpl page = new PageImpl(records, PageRequest.of(0, records.size() == 0 ? 10 : records.size()), records.size());
if (page.getContent().isEmpty()) {
return pagedResourcesAssembler.toEmptyResource(page, IdmBulkActionDto.class);
}
return pagedResourcesAssembler.toResource(page);
}
Aggregations