/// <summary> /// Gets the names and IDs of wellbore objects. /// </summary> /// <param name="objectType">Type of the object.</param> /// <param name="parentUri">The parent URI.</param> /// <returns>The names and IDs of wellbore objects of specified type.</returns> public override IEnumerable <IWellboreObject> GetWellboreObjectIds(string objectType, EtpUri parentUri) { var queryIn = GetTemplateAndSetIds(objectType, parentUri, OptionsIn.ReturnElements.IdOnly); var queryOptionsIn = IsVersion131(parentUri) ? OptionsIn.ReturnElements.Requested : OptionsIn.ReturnElements.IdOnly; return(GetObjects <IWellboreObject>(objectType, queryIn.ToString(), optionsIn: queryOptionsIn)); }
/// <summary> /// Partials the delete entity. /// </summary> /// <param name="parser">The parser.</param> /// <param name="uri">The URI.</param> protected void PartialDeleteEntity(WitsmlQueryParser parser, EtpUri uri) { PartialDeleteEntity <T>(DbCollectionName, parser, uri); }
/// <summary> /// Audits the partial delete operation. /// </summary> /// <param name="uri">The URI.</param> protected virtual void AuditPartialDelete(EtpUri uri) { AuditEntity(uri, Witsml141.ReferenceData.ChangeInfoType.update); }
/// <summary> /// Updates an object in the data store. /// </summary> /// <param name="parser">The WITSML query parser.</param> /// <param name="uri">The data object URI.</param> protected void UpdateEntity(WitsmlQueryParser parser, EtpUri uri) { UpdateEntity <T>(DbCollectionName, parser, uri); }
/// <summary> /// Replaces an object in the data store. /// </summary> /// <typeparam name="TObject">The type of the object.</typeparam> /// <param name="dbCollectionName">The name of the database collection.</param> /// <param name="entity">The object to be replaced.</param> /// <param name="uri">The data object URI.</param> /// <param name="ignoreServerProperties">if set to <c>true</c> ignores server properties.</param> /// <exception cref="WitsmlException"></exception> protected void ReplaceEntity <TObject>(string dbCollectionName, TObject entity, EtpUri uri, bool ignoreServerProperties = true) { try { Logger.DebugFormat("Replacing {0} MongoDb collection", dbCollectionName); var collection = GetCollection <TObject>(dbCollectionName); var current = GetEntity <TObject>(uri, dbCollectionName); //var updates = MongoDbUtility.CreateUpdateFields<TObject>(); var ignores = MongoDbUtility.CreateIgnoreFields <TObject>(null, true); if (ignoreServerProperties) { ignores.AddRange(GetIgnoredElementNamesForUpdate(null) ?? Enumerable.Empty <string>()); } var mapper = new DataObjectMapper <TObject>(Container, null, ignores); mapper.Map(current, entity); // Update Last Change Date AuditHistoryAdapter.SetDateTimeLastChange(entity); var filter = GetEntityFilter <TObject>(uri, IdPropertyName); collection.ReplaceOne(filter, entity); var transaction = Transaction; transaction.Attach(MongoDbAction.Update, dbCollectionName, IdPropertyName, current.ToBsonDocument(), uri); transaction.Save(); AuditUpdate(uri); } catch (MongoException ex) { Logger.ErrorFormat("Error replacing {0} MongoDb collection: {1}", dbCollectionName, ex); throw new WitsmlException(ErrorCodes.ErrorReplacingInDataStore, ex); } }
/// <summary> /// Gets the entity filter for the specified URI. /// </summary> /// <param name="uri">The URI.</param> /// <returns>The entity filter.</returns> protected virtual FilterDefinition <T> GetEntityFilter(EtpUri uri) { return(GetEntityFilter <T>(uri, IdPropertyName)); }
/// <summary> /// Inserts an object into the data store. /// </summary> /// <typeparam name="TObject">The data object type.</typeparam> /// <param name="entity">The object to be inserted.</param> /// <param name="dbCollectionName">The name of the database collection.</param> /// <param name="uri">The data object URI.</param> /// <exception cref="WitsmlException"></exception> protected void InsertEntity <TObject>(TObject entity, string dbCollectionName, EtpUri uri) { try { Logger.DebugFormat("Inserting into {0} MongoDb collection.", dbCollectionName); var collection = GetCollection <TObject>(dbCollectionName); collection.InsertOne(entity); var transaction = Transaction; transaction.Attach(MongoDbAction.Add, dbCollectionName, IdPropertyName, null, uri); transaction.Save(); AuditInsert(uri); } catch (MongoException ex) { Logger.ErrorFormat("Error inserting into {0} MongoDb collection:{1}{2}", dbCollectionName, Environment.NewLine, ex); throw new WitsmlException(ErrorCodes.ErrorAddingToDataStore, ex); } }
/// <summary> /// Sets additional default values for the specified data object and URI. /// </summary> /// <param name="dataObject">The data object.</param> /// <param name="uri">The data object URI.</param> partial void SetAdditionalDefaultValues(Well dataObject, EtpUri uri) { dataObject.TimeZone = GetTimeZoneOffset(); }
/// <summary> /// Sets additional default values for the specified data object and URI. /// </summary> /// <param name="dataObject">The data object.</param> /// <param name="uri">The data object URI.</param> partial void SetAdditionalDefaultValues(Tubular dataObject, EtpUri uri);
/// <summary> /// Gets the object details. /// </summary> /// <param name="objectType">Type of the object.</param> /// <param name="uri">The URI.</param> /// <returns>The object detail.</returns> public override IDataObject GetObjectDetails(string objectType, EtpUri uri) { return(GetObjectDetails(objectType, uri, OptionsIn.ReturnElements.All)); }
private bool IsVersion131(EtpUri uri) { return(uri.Version == null?OptionsIn.DataVersion.Version131.Equals(DataSchemaVersion) : OptionsIn.DataVersion.Version131.Equals(uri.Version)); }
/// <summary> /// Gets the growing objects id-only with active status. /// </summary> /// <param name="objectType">Type of the object.</param> /// <param name="parentUri">The parent URI.</param> /// <param name="indexType">Type of the index.</param> /// <returns>The wellbore objects of specified type with header.</returns> public override IEnumerable <IWellboreObject> GetGrowingObjectsWithStatus(string objectType, EtpUri parentUri, string indexType = null) { var queryIn = GetTemplateAndSetIds(objectType, parentUri, OptionsIn.ReturnElements.IdOnly); var xpath = $"//{objectType}"; _template.Add(queryIn, xpath, "objectGrowing"); if (ObjectTypes.Log.EqualsIgnoreCase(objectType)) { _template.Add(queryIn, xpath, "indexType", "startIndex", "endIndex", "startDateTimeIndex", "endDateTimeIndex", "direction", "indexCurve"); _template.Add(queryIn, $"{xpath}/startIndex", "@uom"); _template.Add(queryIn, $"{xpath}/endIndex", "@uom"); try { if (!string.IsNullOrEmpty(indexType)) { var indexTypeName = (LogIndexType)typeof(LogIndexType).ParseEnum(indexType); _template.Set(queryIn, $"{xpath}/indexType", indexTypeName.GetName()); } } catch { //ignore } } else if (ObjectTypes.Trajectory.EqualsIgnoreCase(objectType)) { _template.Add(queryIn, xpath, "mdMn", "mdMx"); _template.Add(queryIn, $"{xpath}/mdMn", "@uom"); _template.Add(queryIn, $"{xpath}/mdMx", "@uom"); } else if (ObjectTypes.MudLog.EqualsIgnoreCase(objectType)) { _template.Add(queryIn, xpath, "startMd", "endMd"); _template.Add(queryIn, $"{xpath}/startMd", "@uom"); _template.Add(queryIn, $"{xpath}/endMd", "@uom"); } AddCommonDataElements(queryIn, xpath); return(GetObjects <IWellboreObject>(objectType, queryIn.ToString(), OptionsIn.ReturnElements.Requested)); }
/// <summary> /// Gets the name and IDs of growing objects with active status. /// </summary> /// <param name="objectType">Type of the object.</param> /// <param name="parentUri">The parent URI.</param> /// <param name="logXmlResponse">If set to <c>true</c> then log the XML response.</param> /// <returns>/// The name and IDs of the wellbore objects of specified type.</returns> public override IEnumerable <IWellboreObject> GetGrowingObjects(string objectType, EtpUri parentUri, bool logXmlResponse = true) { var queryIn = GetTemplateAndSetIds(objectType, parentUri, OptionsIn.ReturnElements.IdOnly); var xpath = $"//{objectType}"; _template.Add(queryIn, xpath, "objectGrowing"); _template.Set(queryIn, $"{xpath}/objectGrowing", true); var queryOptionsIn = IsVersion131(parentUri) ? OptionsIn.ReturnElements.Requested : OptionsIn.ReturnElements.IdOnly; return(GetObjects <IWellboreObject>(objectType, queryIn.ToString(), logXmlResponse: logXmlResponse, returnNullIfError: true, optionsIn: queryOptionsIn)); }
/// <summary> /// Gets the growing object header only. /// </summary> /// <param name="objectType">Type of the object.</param> /// <param name="uri">The URI.</param> /// <returns>The header for the specified growing objects.</returns> public override IWellboreObject GetGrowingObjectHeaderOnly(string objectType, EtpUri uri) { var templateType = OptionsIn.ReturnElements.IdOnly; var queryOptionsIn = OptionsIn.ReturnElements.HeaderOnly; if (IsVersion131(uri)) { templateType = OptionsIn.ReturnElements.HeaderOnly; queryOptionsIn = OptionsIn.ReturnElements.Requested; } var queryIn = GetTemplateAndSetIds(objectType, uri, templateType); return(GetObjects <IWellboreObject>(objectType, queryIn.ToString(), optionsIn: queryOptionsIn).FirstOrDefault()); }
/// <summary> /// Determines whether the entity exists in the data store. /// </summary> /// <param name="uri">The data object URI.</param> /// <param name="dbCollectionName">The name of the database collection.</param> /// <typeparam name="TObject">The data object type.</typeparam> /// <returns>true if the entity exists; otherwise, false</returns> protected bool Exists <TObject>(EtpUri uri, string dbCollectionName) { return(GetEntity <TObject>(uri, dbCollectionName, IdPropertyName) != null); }
/// <summary> /// Sets the default values for the specified data object. /// </summary> /// <param name="dataObject">The data object.</param> /// <param name="uri">The data object URI.</param> protected override void SetDefaultValues(Activity dataObject, EtpUri uri) { base.SetDefaultValues(dataObject, uri); SetAdditionalDefaultValues(dataObject, uri); }
/// <summary> /// Gets an object from the data store by uid /// </summary> /// <param name="uri">The data object URI.</param> /// <param name="fields">The requested fields.</param> /// <returns>The object represented by the UID.</returns> protected T GetEntity(EtpUri uri, params string[] fields) { return(GetEntity <T>(uri, DbCollectionName, fields)); }
/// <summary> /// Sets additional default values for the specified data object and URI. /// </summary> /// <param name="dataObject">The data object.</param> /// <param name="uri">The data object URI.</param> partial void SetAdditionalDefaultValues(Activity dataObject, EtpUri uri);
/// <summary> /// Gets the entity filter for the specified URI. /// </summary> /// <typeparam name="TObject">The type of the object.</typeparam> /// <param name="uri">The URI.</param> /// <param name="idPropertyName">Name of the identifier property.</param> /// <returns>The entity filter.</returns> protected virtual FilterDefinition <TObject> GetEntityFilter <TObject>(EtpUri uri, string idPropertyName) { return(MongoDbUtility.GetEntityFilter <TObject>(uri, idPropertyName)); }
/// <summary> /// Gets the entity id for the specified data object. /// </summary> /// <param name="entity">The data object entity.</param> /// <param name="uri">The data object uri.</param> /// <returns></returns> protected virtual string GetEntityId(T entity, EtpUri uri) { return(uri.ObjectId); }
/// <summary> /// Audits the insert operation. /// </summary> /// <param name="uri">The URI.</param> protected virtual void AuditInsert(EtpUri uri) { AuditEntity(uri, Witsml141.ReferenceData.ChangeInfoType.add); }
/// <summary> /// Builds the entity filter from the specified uri. /// </summary> /// <param name="entity">The data object entity.</param> /// <param name="uri">The data object uri.</param> /// <returns>The filter definition.</returns> protected virtual FilterDefinition <T> BuildEntityFilter(T entity, EtpUri uri) { return(MongoDbUtility.GetEntityFilter <T>(uri, IdPropertyName)); }
/// <summary> /// Replaces an object in the data store. /// </summary> /// <param name="entity">The object to be replaced.</param> /// <param name="uri">The data object URI.</param> /// <param name="ignoreServerProperties">if set to <c>true</c> ignores server properties.</param> protected void ReplaceEntity(T entity, EtpUri uri, bool ignoreServerProperties = true) { ReplaceEntity(DbCollectionName, entity, uri, ignoreServerProperties); }
/// <summary> /// Sets additional default values for the specified data object and URI. /// </summary> /// <param name="dataObject">The data object.</param> /// <param name="uri">The data object URI.</param> partial void SetAdditionalDefaultValues(StimJob dataObject, EtpUri uri);
/// <summary> /// Deletes a data object by the specified identifier. /// </summary> /// <param name="uri">The data object URI.</param> /// <exception cref="WitsmlException"></exception> protected void DeleteEntity(EtpUri uri) { DeleteEntity <T>(uri, DbCollectionName); }
/// <summary> /// Gets a data object by the specified UUID. /// </summary> /// <param name="uri">The data object URI.</param> /// <param name="fields">The requested fields.</param> /// <returns>The data object instance.</returns> public override T Get(EtpUri uri, params string[] fields) { return(GetEntity(uri, fields)); }
/// <summary> /// Partials the delete entity. /// </summary> /// <typeparam name="TObject">The type of the object.</typeparam> /// <param name="dbCollectionName">Name of the database collection.</param> /// <param name="parser">The parser.</param> /// <param name="uri">The URI.</param> /// <exception cref="WitsmlException"></exception> protected void PartialDeleteEntity <TObject>(string dbCollectionName, WitsmlQueryParser parser, EtpUri uri) { try { Logger.DebugFormat("Partial Deleting {0} MongoDb collection", dbCollectionName); var collection = GetCollection <TObject>(dbCollectionName); var current = GetEntity <TObject>(uri, dbCollectionName); var updates = MongoDbUtility.CreateUpdateFields <TObject>(); var ignores = MongoDbUtility.CreateIgnoreFields <TObject>(GetIgnoredElementNamesForUpdate(parser)); var partialDelete = new MongoDbDelete <TObject>(Container, collection, parser, IdPropertyName, ignores); partialDelete.PartialDelete(current, uri, updates); var transaction = Transaction; transaction.Attach(MongoDbAction.Update, dbCollectionName, IdPropertyName, current.ToBsonDocument(), uri); transaction.Save(); AuditPartialDelete(uri); } catch (MongoException ex) { Logger.ErrorFormat("Error partial deleting {0} MongoDb collection: {1}", dbCollectionName, ex); throw new WitsmlException(ErrorCodes.ErrorUpdatingInDataStore, ex); } }
/// <summary> /// Determines whether the entity exists in the data store. /// </summary> /// <param name="uri">The data object URI.</param> /// <returns>true if the entity exists; otherwise, false</returns> public override bool Exists(EtpUri uri) { return(Exists <T>(uri, DbCollectionName)); }
/// <summary> /// Sets additional default values for the specified data object and URI. /// </summary> /// <param name="dataObject">The data object.</param> /// <param name="uri">The data object URI.</param> partial void SetAdditionalDefaultValues(Attachment dataObject, EtpUri uri);
/// <summary> /// Gets the wellbore objects. /// </summary> /// <param name="objectType">Type of the object.</param> /// <param name="parentUri">The parent URI.</param> /// <param name="logXmlResponse">If set to <c>true</c> then log the XML response.</param> /// <returns>The wellbore objects of specified type.</returns> public override IEnumerable <IWellboreObject> GetWellboreObjects(string objectType, EtpUri parentUri, bool logXmlResponse = true) { var queryIn = GetTemplateAndSetIds(objectType, parentUri, OptionsIn.ReturnElements.IdOnly); AddCommonDataElements(queryIn, $"//{objectType}"); return(GetObjects <IWellboreObject>(objectType, queryIn.ToString(), optionsIn: OptionsIn.ReturnElements.Requested, logXmlResponse: logXmlResponse)); }