コード例 #1
0
        public virtual IHttpActionResult GetOptionsByObjectIDAndType(int id, EntityType entitytype, OptionType optiontype)
        {
            var itSystemUsage = _usageRepository.GetSystemUsage(id);

            var globalOptionData = _optionRepository
                                   .AsQueryable()
                                   .Where(s => s.IsEnabled);

            var localpersonalData =
                _localOptionRepository
                .AsQueryable()
                .ByOrganizationId(itSystemUsage.OrganizationId)
                .Where(p => p.IsActive)
                .ToList();

            var result = new List <TOption>();

            result.AddRange(globalOptionData.AsQueryable().Where(s => s.IsObligatory));

            foreach (var p in localpersonalData)
            {
                var data = globalOptionData.AsQueryable().FirstOrDefault(s => s.Id == p.OptionId && (s.IsEnabled && !s.IsObligatory));
                if (data != null)
                {
                    result.Add(data);
                }
            }

            return(CreateOptionsResponse(id, entitytype, optiontype, result));
        }
        public Result <ItSystemUsage, OperationError> AssignSystem(DataProcessingRegistration registration, int systemId)
        {
            if (registration == null)
            {
                throw new ArgumentNullException(nameof(registration));
            }

            return(_repository
                   .GetSystemUsage(systemId)
                   .FromNullable()
                   .Match
                   (
                       registration.AssignSystem,
                       () => new OperationError("System ID is not valid", OperationFailure.BadInput)
                   ));
        }
コード例 #3
0
        public Maybe <IEntityWithAdvices> Resolve(DomainModel.Advice.Advice advice)
        {
            if (advice?.Type != null && advice.RelationId != null)
            {
                var adviceRelationId = advice.RelationId.Value;

                switch (advice.Type)
                {
                case RelatedEntityType.itContract:
                    return(_itContractRepository.GetById(adviceRelationId));

                case RelatedEntityType.itSystemUsage:
                    return(_itSystemUsageRepository.GetSystemUsage(adviceRelationId));

                case RelatedEntityType.itProject:
                    return(_itProjectRepository.GetById(adviceRelationId));

                case RelatedEntityType.dataProcessingRegistration:
                    return(_dataProcessingRegistrationRepository.GetById(adviceRelationId).GetValueOrDefault());

                case RelatedEntityType.itInterface:     //Intended fallthrough
                default:
                    throw new NotSupportedException("Unsupported object type:" + advice.Type);
                }
            }

            return(Maybe <IEntityWithAdvices> .None);
        }
コード例 #4
0
        private IHasAttachedOptions GetOwner(EntityType optionObjectType, int optionObjectId)
        {
            switch (optionObjectType)
            {
            case EntityType.ITSYSTEMUSAGE:
                return(_usageRepository.GetSystemUsage(optionObjectId));

            default:
                throw new ArgumentOutOfRangeException(nameof(optionObjectType), optionObjectType, null);
            }
        }
コード例 #5
0
        public Result <ItSystemUsageMigration, OperationFailure> GetSystemUsageMigration(int usageId, int toSystemId)
        {
            if (!CanExecuteMigration())
            {
                return(OperationFailure.Forbidden);
            }

            // Get usage
            var itSystemUsage = _systemUsageRepository.GetSystemUsage(usageId);

            if (itSystemUsage == null)
            {
                return(OperationFailure.BadInput);
            }
            if (!_authorizationContext.AllowReads(itSystemUsage))
            {
                return(OperationFailure.Forbidden);
            }

            // Get system
            var toItSystem = _systemRepository.GetSystem(toSystemId);

            if (toItSystem == null)
            {
                return(OperationFailure.BadInput);
            }
            if (!_authorizationContext.AllowReads(toItSystem))
            {
                return(OperationFailure.Forbidden);
            }

            if (toItSystem.Disabled)
            {
                return(OperationFailure.BadInput);
            }

            // Get contracts
            var contracts = itSystemUsage.Contracts.Select(x => x.ItContract);

            // Map relations
            var relationMigrations = GetRelationMigrations(itSystemUsage);

            return(new ItSystemUsageMigration(
                       systemUsage: itSystemUsage,
                       fromItSystem: itSystemUsage.ItSystem,
                       toItSystem: toItSystem,
                       affectedProjects: itSystemUsage.ItProjects,
                       affectedContracts: contracts,
                       affectedRelations: relationMigrations));
        }
        public Task <Result <string, OperationError> > ExecuteAsync(CancellationToken token = default)
        {
            var completedUpdates = 0;

            try
            {
                var pendingReadModelUpdates = _pendingReadModelUpdateRepository.GetMany(PendingReadModelUpdateSourceCategory.ItSystemUsage, BatchSize).ToList();
                foreach (var pendingReadModelUpdate in pendingReadModelUpdates)
                {
                    if (token.IsCancellationRequested)
                    {
                        break;
                    }
                    using var transaction = _transactionManager.Begin(IsolationLevel.ReadCommitted);
                    _logger.Debug("Rebuilding read model for {category}:{sourceId}", pendingReadModelUpdate.Category, pendingReadModelUpdate.SourceId);
                    var source          = _sourceRepository.GetSystemUsage(pendingReadModelUpdate.SourceId).FromNullable();
                    var readModelResult = _readModelRepository.GetBySourceId(pendingReadModelUpdate.SourceId);
                    if (source.HasValue)
                    {
                        var sourceValue = source.Value;

                        ApplyUpdate(readModelResult, sourceValue);
                    }
                    else
                    {
                        _logger.Information("Source object {category}:{sourceId} has been deleted since the update was scheduled. The update is ignored and readmodel is deleted if present.", pendingReadModelUpdate.Category, pendingReadModelUpdate.SourceId);
                        if (readModelResult.HasValue)
                        {
                            _logger.Information("Deleting orphaned read model with id {id}.", readModelResult.Value.Id);
                            _lowLevelReadModelRepository.Delete(readModelResult.Value);
                        }
                    }
                    completedUpdates++;
                    _lowLevelPendingReadModelRepository.Delete(pendingReadModelUpdate);
                    _databaseControl.SaveChanges();
                    transaction.Commit();
                    _logger.Debug("Finished rebuilding read model for {category}:{sourceId}", pendingReadModelUpdate.Category, pendingReadModelUpdate.SourceId);
                }
            }
            catch (Exception e)
            {
                _logger.Error(e, $"Error while performing rebuilds of {Id}");
                return(Task.FromResult(Result <string, OperationError> .Failure(new OperationError("Error during rebuild", OperationFailure.UnknownError))));
            }
            return(Task.FromResult(Result <string, OperationError> .Success($"Completed {completedUpdates} updates")));
        }
コード例 #7
0
        private bool RelatedEntityExists(int relatedEntityId, RelatedEntityType relatedEntityType)
        {
            switch (relatedEntityType)
            {
            case RelatedEntityType.itContract:
                var contractExists = _contractRepository.GetById(relatedEntityId);
                return(contractExists != null);

            case RelatedEntityType.itProject:
                var projectExists = _projectRepository.GetById(relatedEntityId);
                return(projectExists != null);

            case RelatedEntityType.itSystemUsage:
                var systemUsageExists = _systemUsageRepository.GetSystemUsage(relatedEntityId);
                return(systemUsageExists != null);

            case RelatedEntityType.dataProcessingRegistration:
                var dataProcessingRegistrationExists = _dataProcessingRepository.GetById(relatedEntityId);
                return(dataProcessingRegistrationExists.HasValue);

            default:
                return(false);
            }
        }
コード例 #8
0
ファイル: ReferenceService.cs プロジェクト: Strongminds/kitos
        public Result <IEnumerable <ExternalReference>, OperationFailure> DeleteBySystemUsageId(int usageId)
        {
            var itSystemUsage = _systemUsageRepository.GetSystemUsage(usageId);

            return(DeleteExternalReferences(itSystemUsage));
        }