use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.
the class ContractSliceSaveRecalculateProcessor method process.
@Override
public EventResult<IdmContractSliceDto> process(EntityEvent<IdmContractSliceDto> event) {
IdmContractSliceDto slice = event.getContent();
IdmContractSliceDto originalSlice = event.getOriginalSource();
// There is conditional for executing this processor
if (this.getBooleanProperty(IdmContractSliceService.SET_DIRTY_STATE_CONTRACT_SLICE, event.getProperties())) {
// If is set slice as using as contract, set this flag to false
if (slice.isUsingAsContract()) {
slice.setUsingAsContract(false);
service.publish(new ContractSliceEvent(ContractSliceEventType.UPDATE, slice, ImmutableMap.of(IdmContractSliceService.SKIP_RECALCULATE_CONTRACT_SLICE, Boolean.TRUE)));
}
Map<String, Serializable> properties = new HashMap<>(event.getProperties());
// save original slice into parameters, executor ClearDirtyFlagForContractSliceTaskExecutor need him for recalculation
properties.put(ClearDirtyStateForContractSliceTaskExecutor.ORIGINAL_SLICE, originalSlice);
// Creates new dirty states, dirty states must be process by executor
createDirtyState(slice, properties);
return new DefaultEventResult<>(event, this);
}
// recalculation
Map<String, Serializable> eventProperties = event.getProperties();
sliceManager.recalculateContractSlice(slice, originalSlice, eventProperties);
event.setContent(service.get(slice.getId()));
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.
the class ContractSliceSaveProcessor method process.
@Override
public EventResult<IdmContractSliceDto> process(EntityEvent<IdmContractSliceDto> event) {
IdmContractSliceDto slice = event.getContent();
slice = service.saveInternal(slice);
event.setContent(slice);
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.
the class ContractGuaranteeSaveAndDeleteProcessorTest method testDeleteGuaranteeOfContractWithSlice.
@Test
public void testDeleteGuaranteeOfContractWithSlice() {
IdmIdentityDto sliceGuarantee = getHelper().createIdentity();
IdmIdentityDto identity = getHelper().createIdentity();
IdmContractSliceDto slice = getHelper().createContractSlice(identity, null, LocalDate.now().minusDays(1), null, null);
UUID contractId = slice.getParentContract();
getHelper().createContractSliceGuarantee(slice.getId(), sliceGuarantee.getId());
IdmContractSliceGuaranteeFilter sliceGuaranteefilter = new IdmContractSliceGuaranteeFilter();
sliceGuaranteefilter.setGuaranteeId(sliceGuarantee.getId());
List<IdmContractSliceGuaranteeDto> sliceGuarantees = contractSliceGuaranteeService.find(sliceGuaranteefilter, null).getContent();
Assert.assertEquals(1, sliceGuarantees.size());
IdmContractGuaranteeFilter guaranteeFilter = new IdmContractGuaranteeFilter();
guaranteeFilter.setIdentityContractId(contractId);
List<IdmContractGuaranteeDto> contractGuarantees = contractGuaranteeService.find(guaranteeFilter, null).getContent();
Assert.assertEquals(1, contractGuarantees.size());
IdmIdentityDto sliceGuaranteeIdent = DtoUtils.getEmbedded(sliceGuarantees.get(0), IdmContractSliceGuarantee_.guarantee);
IdmIdentityDto contractGuaranteeIdent = DtoUtils.getEmbedded(contractGuarantees.get(0), IdmContractSliceGuarantee_.guarantee);
Assert.assertEquals(sliceGuaranteeIdent.getId(), contractGuaranteeIdent.getId());
try {
contractGuaranteeService.delete(contractGuarantees.get(0));
fail("Contract guarantee can't be deleted directly when slice is applied");
} catch (ResultCodeException ex) {
Assert.assertTrue(CoreResultCode.CONTRACT_IS_CONTROLLED_GUARANTEE_CANNOT_BE_DELETED.toString().equals(ex.getError().getErrors().get(0).getStatusEnum()));
}
// guarantee can be still deleted via contract slice operation
contractSliceGuaranteeService.delete(sliceGuarantees.get(0));
sliceGuarantees = contractSliceGuaranteeService.find(sliceGuaranteefilter, null).getContent();
Assert.assertEquals(0, sliceGuarantees.size());
contractGuarantees = contractGuaranteeService.find(guaranteeFilter, null).getContent();
Assert.assertEquals(0, contractGuarantees.size());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.
the class IdmContractSliceController method downloadFormValue.
/**
* Returns input stream to attachment saved in given form value.
*
* @param backendId
* @param formValueId
* @return
* @since 9.4.0
*/
@RequestMapping(value = "/{backendId}/form-values/{formValueId}/download", method = RequestMethod.GET)
@ResponseBody
@PreAuthorize("hasAuthority('" + CoreGroupPermission.CONTRACTSLICE_READ + "')")
@ApiOperation(value = "Download form value attachment", nickname = "downloadFormValue", tags = { IdmContractSliceController.TAG }, notes = "Returns input stream to attachment saved in given form value.", authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.CONTRACTSLICE_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.CONTRACTSLICE_READ, description = "") }) })
public ResponseEntity<InputStreamResource> downloadFormValue(@ApiParam(value = "Slice's uuid identifier.", required = true) @PathVariable String backendId, @ApiParam(value = "Form value identifier.", required = true) @PathVariable String formValueId) {
IdmContractSliceDto dto = getDto(backendId);
if (dto == null) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", backendId));
}
IdmFormValueDto value = formService.getValue(dto, DtoUtils.toUuid(formValueId));
if (value == null) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, formValueId);
}
return formDefinitionController.downloadAttachment(value);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.
the class IdmContractSliceController method previewFormValue.
/**
* Returns input stream to attachment saved in given form value.
*
* @param backendId
* @param formValueId
* @return
* @since 9.4.0
*/
@RequestMapping(value = "/{backendId}/form-values/{formValueId}/preview", method = RequestMethod.GET)
@ResponseBody
@PreAuthorize("hasAuthority('" + CoreGroupPermission.CONTRACTSLICE_READ + "')")
@ApiOperation(value = "Download form value attachment preview", nickname = "downloadFormValue", tags = { IdmContractSliceController.TAG }, notes = "Returns input stream to attachment preview saved in given form value. Preview is supported for the png, jpg and jpeg mime types only", authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.CONTRACTSLICE_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.CONTRACTSLICE_READ, description = "") }) })
public ResponseEntity<InputStreamResource> previewFormValue(@ApiParam(value = "Slice's uuid identifier.", required = true) @PathVariable String backendId, @ApiParam(value = "Form value identifier.", required = true) @PathVariable String formValueId) {
IdmContractSliceDto dto = getDto(backendId);
if (dto == null) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", backendId));
}
IdmFormValueDto value = formService.getValue(dto, DtoUtils.toUuid(formValueId));
if (value == null) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, formValueId);
}
return formDefinitionController.previewAttachment(value);
}
Aggregations