Search in sources :

Example 66 with IdmContractSliceDto

use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.

the class IdmContractSliceController method getFormValues.

/**
 * Returns entity's filled form values
 *
 * @param backendId
 * @return
 */
@ResponseBody
@RequestMapping(value = "/{backendId}/form-values", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.CONTRACTSLICE_READ + "')")
@ApiOperation(value = "Contract slice form definition - read values", nickname = "getIdentityContractFormValues", tags = { IdmContractSliceController.TAG }, 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 Resource<?> getFormValues(@ApiParam(value = "Identity's uuid identifier or username.", required = true) @PathVariable @NotNull String backendId, @ApiParam(value = "Code of form definition (default will be used if no code is given).", required = false, defaultValue = FormService.DEFAULT_DEFINITION_CODE) @RequestParam(name = "definitionCode", required = false) String definitionCode) {
    IdmContractSliceDto dto = getDto(backendId);
    if (dto == null) {
        throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", backendId));
    }
    // 
    checkAccess(dto, IdmBasePermission.READ);
    // 
    IdmFormDefinitionDto formDefinition = formDefinitionController.getDefinition(IdmIdentityContract.class, definitionCode);
    // 
    return formDefinitionController.getFormValues(dto, formDefinition);
}
Also used : ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmContractSliceDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 67 with IdmContractSliceDto

use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.

the class IdmContractSliceController method saveFormValue.

/**
 * Save entity's form value
 *
 * @param backendId
 * @param formValues
 * @return
 * @since 9.4.0
 */
@ResponseBody
@PreAuthorize("hasAuthority('" + CoreGroupPermission.CONTRACTSLICE_UPDATE + "')")
@RequestMapping(value = "/{backendId}/form-value", method = { RequestMethod.POST })
@ApiOperation(value = "Role form definition - save value", nickname = "postRoleFormValue", tags = { IdmContractSliceController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.CONTRACTSLICE_UPDATE, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.CONTRACTSLICE_UPDATE, description = "") }) })
public Resource<?> saveFormValue(@ApiParam(value = "Slice's uuid identifier.", required = true) @PathVariable @NotNull String backendId, @RequestBody @Valid IdmFormValueDto formValue) {
    IdmContractSliceDto dto = getDto(backendId);
    if (dto == null) {
        throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", backendId));
    }
    checkAccess(dto, IdmBasePermission.UPDATE);
    // 
    return formDefinitionController.saveFormValue(dto, formValue);
}
Also used : ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmContractSliceDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 68 with IdmContractSliceDto

use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.

the class IdmContractSliceController method saveFormValues.

/**
 * Saves entity's form values
 *
 * @param backendId
 * @param formValues
 * @return
 */
@ResponseBody
@PreAuthorize("hasAuthority('" + CoreGroupPermission.CONTRACTSLICE_UPDATE + "')")
@RequestMapping(value = "/{backendId}/form-values", method = { RequestMethod.POST, RequestMethod.PATCH })
@ApiOperation(value = "Contract slice form definition - save values", nickname = "postIdentityContractFormValues", tags = { IdmContractSliceController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.CONTRACTSLICE_UPDATE, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.CONTRACTSLICE_UPDATE, description = "") }) })
public Resource<?> saveFormValues(@ApiParam(value = "Identity's uuid identifier or username.", required = true) @PathVariable @NotNull String backendId, @ApiParam(value = "Code of form definition (default will be used if no code is given).", required = false, defaultValue = FormService.DEFAULT_DEFINITION_CODE) @RequestParam(name = "definitionCode", required = false) String definitionCode, @ApiParam(value = "Filled form data.", required = true) @RequestBody @Valid List<IdmFormValueDto> formValues) {
    IdmContractSliceDto dto = getDto(backendId);
    if (dto == null) {
        throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", backendId));
    }
    // 
    checkAccess(dto, IdmBasePermission.UPDATE);
    // 
    IdmFormDefinitionDto formDefinition = formDefinitionController.getDefinition(IdmIdentityContract.class, definitionCode);
    // 
    return formDefinitionController.saveFormValues(dto, formDefinition, formValues);
}
Also used : ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmContractSliceDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 69 with IdmContractSliceDto

use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.

the class ClearDirtyStateForContractSliceTaskExecutor method processItem.

/**
 * Process one dirty state for contract slice
 *
 * @param dirtyState
 */
private void processItem(IdmEntityStateDto dirtyState) {
    try {
        if (dirtyState.getOwnerType() == null || !dirtyState.getOwnerType().equals(IdmContractSlice.class.getName())) {
            this.logItemProcessed(dirtyState, new OperationResult.Builder(OperationState.NOT_EXECUTED).build());
            return;
        }
        IdmContractSliceDto contractSliceDto = (IdmContractSliceDto) dirtyState.getEmbedded().get(CURRENT_SLICE);
        if (contractSliceDto == null) {
            contractSliceDto = contractSliceService.get(dirtyState.getOwnerId());
        }
        if (contractSliceDto == null) {
            DefaultResultModel model = new DefaultResultModel(CoreResultCode.NOT_FOUND, ImmutableMap.of("ownerId", dirtyState.getOwnerId()));
            this.logItemProcessed(dirtyState, new OperationResult.Builder(OperationState.NOT_EXECUTED).setModel(model).build());
            return;
        }
        ResultModel resultModel = dirtyState.getResult().getModel();
        Map<String, Object> parameters = new HashMap<>();
        if (resultModel != null) {
            parameters = resultModel.getParameters();
        }
        IdmContractSliceDto originalSlice = null;
        Object originalSliceAsObject = parameters.get(ORIGINAL_SLICE);
        if (originalSliceAsObject instanceof IdmContractSliceDto) {
            originalSlice = (IdmContractSliceDto) originalSliceAsObject;
        }
        // Transform saved parameters into map string and serializable value
        Map<String, Serializable> transformedParameters = transformParameters(parameters);
        // Current using flag was sets to FALSE (during making as dirty), we want to force recalculate
        transformedParameters.put(IdmContractSliceService.FORCE_RECALCULATE_CURRENT_USING_SLICE, Boolean.TRUE);
        // Provisioning skip have to by removed. We need to make a provisioning in this phase.
        // Workaround - skip provisioning is from the ACC module, but work with slices and dirty states is only in core. So this is safe way how remove a skip property.
        transformedParameters.put(SKIP_PROVISIONING, Boolean.FALSE);
        contractSliceManager.recalculateContractSlice(contractSliceDto, originalSlice, transformedParameters);
        this.logItemProcessed(contractSliceDto, new OperationResult.Builder(OperationState.EXECUTED).build());
        entityStateManager.deleteState(dirtyState);
    } catch (Exception e) {
        this.logItemProcessed(dirtyState, new OperationResult.Builder(OperationState.EXCEPTION).setCause(e).build());
    }
}
Also used : Serializable(java.io.Serializable) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) HashMap(java.util.HashMap) IdmContractSlice(eu.bcvsolutions.idm.core.model.entity.IdmContractSlice) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) IdmContractSliceDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto)

Example 70 with IdmContractSliceDto

use of eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto in project CzechIdMng by bcvsolutions.

the class SelectCurrentContractSliceTaskExecutor method process.

@Override
@Transactional
public OperationResult process() {
    // Found all unvalid slices
    List<IdmContractSliceDto> unvalidSlices = contractSliceManager.findUnvalidSlices(null).getContent();
    boolean canContinue = true;
    // 
    this.counter = 0L;
    this.count = Long.valueOf(unvalidSlices.size());
    StringBuilder duplicitiesMessage = null;
    List<UUID> invalidContracts = new ArrayList<>();
    for (IdmContractSliceDto slice : unvalidSlices) {
        // Start recalculation
        List<IdmContractSliceDto> duplicatedSlices = // 
        unvalidSlices.stream().filter(// 
        s -> s.getParentContract() != null && s.getParentContract().equals(slice.getParentContract())).collect(Collectors.toList());
        if (duplicatedSlices.size() > 1) {
            String errorMsg = MessageFormat.format("We found more then once slice [{1}] which should be use as contract. This is not allowed. None from this slices will be used as contract. It means contract [{0}] is in incorrect state now!", slice.getParentContract(), duplicatedSlices.size());
            LOG.warn(errorMsg);
            if (duplicitiesMessage == null) {
                duplicitiesMessage = new StringBuilder();
            }
            if (!invalidContracts.contains(slice.getParentContract())) {
                duplicitiesMessage.append(slice.getParentContract()).append(',');
                invalidContracts.add(slice.getParentContract());
            }
        } else {
            contractSliceManager.setSliceAsCurrentlyUsing(slice, null);
            // 
            counter++;
        }
        canContinue = updateState();
        if (!canContinue) {
            break;
        }
    }
    if (duplicitiesMessage != null) {
        return new OperationResult.Builder(OperationState.EXCEPTION).setException(new ResultCodeException(CoreResultCode.CONTRACT_SLICE_DUPLICATE_CANDIDATES, ImmutableMap.of("contracts", duplicitiesMessage.toString()))).build();
    }
    return new OperationResult.Builder(OperationState.EXECUTED).build();
}
Also used : Logger(org.slf4j.Logger) ImmutableMap(com.google.common.collect.ImmutableMap) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) IdmContractSliceDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto) List(java.util.List) Component(org.springframework.stereotype.Component) AbstractSchedulableTaskExecutor(eu.bcvsolutions.idm.core.scheduler.api.service.AbstractSchedulableTaskExecutor) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) DisallowConcurrentExecution(org.quartz.DisallowConcurrentExecution) ContractSliceManager(eu.bcvsolutions.idm.core.api.service.ContractSliceManager) Transactional(org.springframework.transaction.annotation.Transactional) ArrayList(java.util.ArrayList) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) IdmContractSliceDto(eu.bcvsolutions.idm.core.api.dto.IdmContractSliceDto) UUID(java.util.UUID) Transactional(org.springframework.transaction.annotation.Transactional)

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