public async Task <IActionResult> UploadPreprocessImage([FromRoute] long id, [FromRoute] long dataId,
                                                                [FromBody] AddOutputDataInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(JsonBadRequest("Invalid inputs."));
            }

            // データの存在チェック
            var preprocessHistory = await preprocessHistoryRepository.GetPreprocessIncludeDataAndPreprocessAsync(id, dataId);

            if (preprocessHistory == null)
            {
                return(JsonNotFound($"Preprocessing History about Preprocess {id} to Data {dataId} is not found."));
            }
            var status = ContainerStatus.Convert(preprocessHistory.Status);

            if (status.IsOpened() == false)
            {
                // 追加できるのは開放中のコンテナだけ(ローカルの結果を追加することがあるので、Runningとは限らない)
                return(JsonBadRequest($"Preprocessing History {preprocessHistory.Id} is not opened."));
            }

            // データを追加する
            Data newData = new Data()
            {
                // データ名が未指定であれば、デフォルトの値を入れる
                Name         = string.IsNullOrEmpty(model.Name) ? $"{preprocessHistory.InputData.Name}_{preprocessHistory.Preprocess.Name}" : model.Name,
                Memo         = model.Memo,
                ParentDataId = preprocessHistory.InputDataId
            };

            dataRepository.Add(newData);

            foreach (var file in model.Files)
            {
                dataRepository.AddFile(newData, file.FileName, file.StoredPath);
            }

            // タグの登録
            if (model.Tags != null && model.Tags.Count() > 0)
            {
                tagLogic.CreateDataTags(newData, model.Tags);
            }
            else
            {
                // タグが未指定であれば、前処理名を付ける
                List <string> tags = new List <string>()
                {
                    preprocessHistory.Preprocess.Name
                };
                tagLogic.CreateDataTags(newData, tags);
            }

            preprocessHistoryRepository.AddOutputData(preprocessHistory.Id, newData);

            unitOfWork.Commit();

            return(JsonOK(new HistoriesOutputModel(preprocessHistory)));
        }
Exemple #2
0
        public async Task <IActionResult> AddFile(long id, [FromBody] AddFileInputModel model, [FromServices] IDataSetRepository dataSetRepository)
        {
            //データの入力チェック
            if (!ModelState.IsValid)
            {
                return(JsonBadRequest("Invalid inputs."));
            }

            //データの存在チェック
            var data = await dataRepository.GetDataIncludeAllAsync(id);

            if (data == null)
            {
                return(JsonNotFound($"Data ID {id} is not found."));
            }

            var checkResult = await CheckDataIsLocked(data, dataSetRepository);

            if (checkResult != null)
            {
                return(checkResult);
            }

            //同じファイル名は登録できない
            var file = data.DataProperties.FirstOrDefault(d => d.Key == model.FileName);

            if (file != null)
            {
                return(JsonConflict($"Data {data.Name} has already a file named {model.FileName}."));
            }

            // データファイルの登録
            var property = dataRepository.AddFile(data, model.FileName, model.StoredPath);

            unitOfWork.Commit();

            return(JsonCreated(new DataFileOutputModel {
                Id = id, Key = property.Key, FileId = property.Id, FileName = model.FileName
            }));
        }