Skip to content

Commit

Permalink
adding push to Tag Import
Browse files Browse the repository at this point in the history
  • Loading branch information
RudiThoeni committed Nov 19, 2024
1 parent 2ec0275 commit 4763a4c
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 6 deletions.
2 changes: 1 addition & 1 deletion OdhApiImporter/Controllers/UpdateApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,7 @@ public async Task<IActionResult> ImportLTSEventTagsToODHTags(

try
{
LTSApiEventTagsToODHTagImportHelper importhelper = new LTSApiEventTagsToODHTagImportHelper(settings, QueryFactory, "smgtags", UrlGeneratorStatic("LTS/Events/Tags"));
LTSApiEventTagsToODHTagImportHelper importhelper = new LTSApiEventTagsToODHTagImportHelper(settings, QueryFactory, "smgtags", UrlGeneratorStatic("LTS/Events/Tags"), OdhPushnotifier);

updatedetail = await importhelper.SaveDataToODH(null, null, cancellationToken);
var updateResult = GenericResultsHelper.GetSuccessUpdateResult(null, source, operation, updatetype, "Import LTS Events Tags succeeded", otherinfo, updatedetail, true);
Expand Down
45 changes: 45 additions & 0 deletions OdhApiImporter/Helpers/IImportHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using System.Xml.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using OdhNotifier;

namespace OdhApiImporter.Helpers
{
Expand Down Expand Up @@ -165,5 +166,49 @@ public static IDictionary<string, XDocument> LoadXmlFiles(string directory, List

return myxmlfiles;
}

public static async Task<IDictionary<string, NotifierResponse>?> CheckIfObjectChangedAndPush(IOdhPushNotifier OdhPushnotifier, PGCRUDResult myupdateresult, string id, string datatype, IDictionary<string, bool>? additionalpushinfo = null, string pushorigin = "")
{
IDictionary<string, NotifierResponse>? pushresults = default(IDictionary<string, NotifierResponse>);

//Check if data has changed and Push To all channels
if (myupdateresult.objectchanged != null && myupdateresult.objectchanged > 0 && myupdateresult.pushchannels != null && myupdateresult.pushchannels.Count > 0)
{
if (additionalpushinfo == null)
additionalpushinfo = new Dictionary<string, bool>();

//Check if image has changed and add it to the dictionary
if (myupdateresult.objectimagechanged != null && myupdateresult.objectimagechanged.Value > 0)
additionalpushinfo.TryAdd("imageschanged", true);
else
additionalpushinfo.TryAdd("imageschanged", false);

pushresults = await OdhPushnotifier.PushToPublishedOnServices(id, datatype.ToLower(), pushorigin, additionalpushinfo, false, "api", myupdateresult.pushchannels.ToList());
}

return pushresults;
}

public static async Task<IDictionary<string, NotifierResponse>?> CheckIfObjectChangedAndPush(IOdhPushNotifier OdhPushnotifier, UpdateDetail myupdateresult, string id, string datatype, IDictionary<string, bool>? additionalpushinfo = null, string pushorigin = "")
{
IDictionary<string, NotifierResponse>? pushresults = default(IDictionary<string, NotifierResponse>);

//Check if data has changed and Push To all channels
if (myupdateresult.objectchanged != null && myupdateresult.objectchanged > 0 && myupdateresult.pushchannels != null && myupdateresult.pushchannels.Count > 0)
{
if (additionalpushinfo == null)
additionalpushinfo = new Dictionary<string, bool>();

//Check if image has changed and add it to the dictionary
if (myupdateresult.objectimagechanged != null && myupdateresult.objectimagechanged.Value > 0)
additionalpushinfo.TryAdd("imageschanged", true);
else
additionalpushinfo.TryAdd("imageschanged", false);

pushresults = await OdhPushnotifier.PushToPublishedOnServices(id, datatype.ToLower(), pushorigin, additionalpushinfo, false, "api", myupdateresult.pushchannels.ToList());
}

return pushresults;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NINJA.Parser;
using OdhNotifier;
using ServiceReferenceLCS;
using SqlKata.Execution;
using System;
Expand All @@ -24,9 +25,11 @@ namespace OdhApiImporter.Helpers.LTSAPI
{
public class LTSApiEventTagsToODHTagImportHelper : ImportHelper, IImportHelper
{
public LTSApiEventTagsToODHTagImportHelper(ISettings settings, QueryFactory queryfactory, string table, string importerURL) : base(settings, queryfactory, table, importerURL)
{
private IOdhPushNotifier OdhPushnotifier;

public LTSApiEventTagsToODHTagImportHelper(ISettings settings, QueryFactory queryfactory, string table, string importerURL, IOdhPushNotifier odhpushnotifier) : base(settings, queryfactory, table, importerURL)
{
this.OdhPushnotifier = odhpushnotifier;
}

private async Task<List<JObject>> GetEventTagsFromLTSV2()
Expand Down Expand Up @@ -109,9 +112,12 @@ private async Task<UpdateDetail> SaveEventTagsToPG(List<JObject> ltsdata)
objecttosave.PublishedOn = null;
objecttosave.MappedTagIds = null;


var result = await InsertDataToDB(objecttosave, data);

//Push Data if changed
//push modified data to all published Channels
result.pushed = await ImportUtils.CheckIfObjectChangedAndPush(OdhPushnotifier, result, result.id, result.odhtype);

newimportcounter = newimportcounter + result.created ?? 0;
updateimportcounter = updateimportcounter + result.updated ?? 0;
errorimportcounter = errorimportcounter + result.error ?? 0;
Expand Down Expand Up @@ -166,7 +172,7 @@ private async Task<PGCRUDResult> InsertDataToDB(ODHTagLinked objecttosave, LTSEv
//Set PublishedOn
objecttosave.PublishedOn = new List<string>() { "idm-marketplace" };

return await QueryFactory.UpsertData<ODHTagLinked>(objecttosave, new DataInfo("smgtags", CRUDOperation.Create), new EditInfo("importer", "lts"), new CRUDConstraints(), new CompareConfig(false, false));
return await QueryFactory.UpsertData<ODHTagLinked>(objecttosave, new DataInfo("smgtags", CRUDOperation.Create), new EditInfo("importer", "lts"), new CRUDConstraints(), new CompareConfig(true, false));
}
catch (Exception ex)
{
Expand Down
2 changes: 1 addition & 1 deletion OdhApiImporter/Helpers/RAVEN/RAVENImportHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ private async Task<UpdateDetail> SaveRavenDestinationdataObjectToPG<T, V>(T data
return new UpdateDetail() { created = result.created, updated = result.updated, deleted = result.deleted, error = result.error, comparedobjects = result.compareobject != null && result.compareobject.Value ? 1 : 0, objectchanged = result.objectchanged, objectimagechanged = result.objectimagechanged, pushchannels = result.pushchannels, changes = result.changes };
}

private async Task<IDictionary<string, NotifierResponse>?> CheckIfObjectChangedAndPush(UpdateDetail myupdateresult, string id, string datatype, IDictionary<string,bool>? additionalpushinfo = null, string pushorigin = "lts.push")
public async Task<IDictionary<string, NotifierResponse>?> CheckIfObjectChangedAndPush(UpdateDetail myupdateresult, string id, string datatype, IDictionary<string,bool>? additionalpushinfo = null, string pushorigin = "lts.push")
{
IDictionary<string,NotifierResponse>? pushresults = default(IDictionary<string, NotifierResponse>);

Expand Down

0 comments on commit 4763a4c

Please sign in to comment.