Search in sources :

Example 1 with IdmContractSliceDto

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);
}
Also used : ContractSliceEvent(eu.bcvsolutions.idm.core.model.event.ContractSliceEvent) Serializable(java.io.Serializable) HashMap(java.util.HashMap) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmContractSliceDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto)

Example 2 with IdmContractSliceDto

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);
}
Also used : DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmContractSliceDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto)

Example 3 with IdmContractSliceDto

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());
}
Also used : IdmContractSliceGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceGuaranteeFilter) IdmContractGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmContractSliceGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceGuaranteeDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) IdmContractGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractGuaranteeFilter) IdmContractSliceDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 4 with IdmContractSliceDto

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);
}
Also used : ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) IdmContractSliceDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 5 with IdmContractSliceDto

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);
}
Also used : ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) IdmContractSliceDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

IdmContractSliceDto (eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto)72 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)44 Test (org.junit.Test)44 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)42 IdmContractSliceFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceFilter)36 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)35 ContractSliceEvent (eu.bcvsolutions.idm.core.model.event.ContractSliceEvent)26 UUID (java.util.UUID)22 IdmContractSliceGuaranteeDto (eu.bcvsolutions.idm.core.api.dto.IdmContractSliceGuaranteeDto)21 IdmContractSliceGuaranteeFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmContractSliceGuaranteeFilter)21 IdmTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)20 OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)19 HashMap (java.util.HashMap)19 ImmutableMap (com.google.common.collect.ImmutableMap)17 SysSyncContractConfigDto (eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto)17 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)17 ContractSliceManager (eu.bcvsolutions.idm.core.api.service.ContractSliceManager)17 List (java.util.List)17 Autowired (org.springframework.beans.factory.annotation.Autowired)17 IdmEntityStateDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto)16