Beispiel #1
0
        public static DataSet RegisterNew(Registration reg, string user)
        {
            if (reg == null)
            {
                throw new DataSetException(reg.datasetId, ApiResponseStatus.DatasetNotFound);
            }

            if (reg.jsonSchema == null)
            {
                throw new DataSetException(reg.datasetId, ApiResponseStatus.DatasetJsonSchemaMissing);
            }



            reg.NormalizeShortName();
            var client = Lib.ES.Manager.GetESClient(reg.datasetId, idxType: ES.Manager.IndexType.DataSource);

            if (reg.searchResultTemplate != null && !string.IsNullOrEmpty(reg.searchResultTemplate?.body))
            {
                var errors = reg.searchResultTemplate.GetTemplateErrors();
                if (errors.Count > 0)
                {
                    var err = ApiResponseStatus.DatasetSearchTemplateError;
                    err.error.errorDetail = errors.Aggregate((f, s) => f + "\n" + s);
                    throw new DataSetException(reg.datasetId, err);
                }
            }

            if (reg.detailTemplate != null && !string.IsNullOrEmpty(reg.detailTemplate?.body))
            {
                var errors = reg.detailTemplate.GetTemplateErrors();
                if (errors.Count > 0)
                {
                    var err = ApiResponseStatus.DatasetDetailTemplateError;
                    err.error.errorDetail = errors.Aggregate((f, s) => f + "\n" + s);
                    throw new DataSetException(reg.datasetId, err);
                }
            }

            var ret = client.Indices.Exists(client.ConnectionSettings.DefaultIndex); //todo: es7 check

            if (ret.Exists)
            {
                throw new DataSetException(reg.datasetId, ApiResponseStatus.DatasetRegistered);
            }
            else
            {
                Lib.ES.Manager.CreateIndex(client);
                DataSetDB.Instance.AddData(reg, user);
            }


            return(new DataSet(reg.datasetId));
        }
Beispiel #2
0
            public static ApiResponseStatus Create(Registration dataset, string updatedBy, string jsonSchemaInString = null)
            {
                try
                {
                    Registration reg = dataset;

                    if (reg.jsonSchema == null)
                    {
                        reg.jsonSchema = StringToJSchema(jsonSchemaInString).ToString();
                    }


                    using (System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient())
                    {
                        var m = new System.Net.Mail.MailMessage()
                        {
                            From       = new System.Net.Mail.MailAddress("*****@*****.**"),
                            Subject    = "Nova DATASET registrace od " + updatedBy,
                            IsBodyHtml = false,
                            Body       = Newtonsoft.Json.JsonConvert.SerializeObject(reg)
                        };
                        m.BodyEncoding    = System.Text.Encoding.UTF8;
                        m.SubjectEncoding = System.Text.Encoding.UTF8;

                        m.To.Add("*****@*****.**");
                        try
                        {
                            smtp.Send(m);
                        }
                        catch (Exception)
                        { }
                    }

                    reg.created   = DateTime.Now;
                    reg.createdBy = updatedBy;
                    reg.NormalizeShortName();

                    var newreg = HlidacStatu.Lib.Data.External.DataSets.DataSet.RegisterNew(reg, updatedBy);

                    //HlidacStatu.Web.Framework.TemplateVirtualFileCacheManager.InvalidateTemplateCache(reg.datasetId);

                    return(new ApiResponseStatus()
                    {
                        valid = true, value = newreg.datasetId
                    });
                }
                catch (Newtonsoft.Json.JsonSerializationException jex)
                {
                    var status = ApiResponseStatus.DatasetItemInvalidFormat;
                    status.error.errorDetail = jex.Message;
                    return(status);
                }
                catch (DataSetException dse)
                {
                    return(dse.APIResponse);
                }
                catch (Exception ex)
                {
                    HlidacStatu.Util.Consts.Logger.Error("Dataset API", ex);
                    return(ApiResponseStatus.GeneralExceptionError(ex));
                }
            }