Code for fort migration
This commit is contained in:
parent
aedd5f33fa
commit
4ee0eb8e87
@ -14,4 +14,13 @@ namespace Manager.Interfaces.DTO
|
||||
public DateTime dateCreation { get; set; }
|
||||
public string instanceId { get; set; }
|
||||
}
|
||||
|
||||
public class ResourceOLDDTO
|
||||
{
|
||||
public MongoId _id { get; set; }
|
||||
public ResourceType Type { get; set; }
|
||||
public string Label { get; set; }
|
||||
public DateCustom DateCreation { get; set; }
|
||||
public string InstanceId { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,10 @@
|
||||
using Manager.Interfaces.Models;
|
||||
using MongoDB.Bson.IO;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Manager.Interfaces.DTO
|
||||
{
|
||||
@ -27,4 +30,38 @@ namespace Manager.Interfaces.DTO
|
||||
public bool isBeacon { get; set; } // MyVisit - True if section use beacon, false otherwise
|
||||
public int? beaconId { get; set; } // MyVisit - Beacon' identifier
|
||||
}
|
||||
|
||||
public class SectionForJsonDTO
|
||||
{
|
||||
public MongoId _id { get; set; } // Correspond à l'objet _id dans le JSON
|
||||
public string Label { get; set; } // Correspond à "Label" dans le JSON
|
||||
public List<TranslationDTO> Title { get; set; } // Correspond à "Title" dans le JSON
|
||||
public List<TranslationDTO> Description { get; set; } // Correspond à "Description" dans le JSON
|
||||
public string ImageId { get; set; } // Correspond à "ImageId" dans le JSON
|
||||
public string ImageSource { get; set; } // Correspond à "ImageSource" dans le JSON
|
||||
public string ConfigurationId { get; set; } // Correspond à "ConfigurationId" dans le JSON
|
||||
public bool IsSubSection { get; set; } // Correspond à "IsSubSection" dans le JSON
|
||||
public string ParentId { get; set; } // Correspond à "ParentId" dans le JSON
|
||||
public int Type { get; set; } // Correspond à "Type" dans le JSON
|
||||
public string Data { get; set; } // Correspond à "Data" dans le JSON
|
||||
|
||||
public DateCustom DateCreation { get; set; }
|
||||
public int? Order { get; set; } // Correspond à "Order" dans le JSON
|
||||
public string InstanceId { get; set; } // Correspond à "InstanceId" dans le JSON
|
||||
public bool IsBeacon { get; set; } // Correspond à "IsBeacon" dans le JSON
|
||||
public string BeaconId { get; set; } // Correspond à "BeaconId" dans le JSON
|
||||
public string Latitude { get; set; } // Correspond à "Latitude" dans le JSON
|
||||
public string Longitude { get; set; } // Correspond à "Longitude" dans le JSON
|
||||
public int? MeterZoneGPS { get; set; } // Correspond à "MeterZoneGPS" dans le JSON
|
||||
}
|
||||
|
||||
public class MongoId
|
||||
{
|
||||
public string oid { get; set; } // Correspond à "$oid" dans le JSON
|
||||
}
|
||||
|
||||
public class DateCustom
|
||||
{
|
||||
public DateTime date { get; set; } // Correspond à "$oid" dans le JSON
|
||||
}
|
||||
}
|
||||
|
||||
25
Manager.Interfaces/DTO/SubSection/OldArticleDTO.cs
Normal file
25
Manager.Interfaces/DTO/SubSection/OldArticleDTO.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using Manager.Interfaces.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Manager.Interfaces.DTO
|
||||
{
|
||||
public class OldArticleDTO
|
||||
{
|
||||
public List<TranslationDTO> content { get; set; }
|
||||
public bool isContentTop { get; set; } // MyVisit - True if content is displayed at top, false otherwise
|
||||
public List<TranslationDTO> audioIds { get; set; }
|
||||
public bool isReadAudioAuto { get; set; } // MyVisit - True for audio play when open the article / false otherwise
|
||||
public List<OldContentDTO> images { get; set; }
|
||||
}
|
||||
|
||||
public class OldContentDTO
|
||||
{
|
||||
public List<TranslationDTO> title { get; set; }
|
||||
public List<TranslationDTO> description { get; set; }
|
||||
public string resourceId { get; set; }
|
||||
public string source { get; set; }
|
||||
public int order { get; set; } // Order to show
|
||||
}
|
||||
}
|
||||
@ -18,6 +18,7 @@ using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Server.IIS.Core;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using MongoDB.Bson.Serialization.Serializers;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NSwag.Annotations;
|
||||
@ -580,29 +581,61 @@ namespace ManagerService.Controllers
|
||||
{
|
||||
try
|
||||
{
|
||||
string json = System.IO.File.ReadAllText("C:/Users/ThomasFransolet/Documents/Documents/Perso/UNOV/MongoDB 10-10-24 - MyMuseum before migration/TabletDb.Resources.json");
|
||||
var resourceAll = JsonConvert.DeserializeObject<List<ResourceOLDDTO>>(json); // Désérialiser en liste d'objets
|
||||
|
||||
string json = System.IO.File.ReadAllText("C:/Users/ThomasFransolet/Documents/Documents/Perso/MuseeDeLaFraise/Aout 2024/TabletDb.Resources.json");
|
||||
JArray resourceAll = JArray.Parse(json);
|
||||
|
||||
foreach (var resource in resourceAll)
|
||||
using (StreamReader dataFile = new StreamReader("C:/Users/ThomasFransolet/Documents/Documents/Perso/UNOV/MongoDB 10-10-24 - MyMuseum before migration/TabletDb.ResourcesData.json"))
|
||||
using (JsonTextReader dataReader = new JsonTextReader(dataFile))
|
||||
{
|
||||
while (dataReader.Read())
|
||||
{
|
||||
if (dataReader.TokenType == JsonToken.StartObject)
|
||||
{
|
||||
JObject resourceData = JObject.Load(dataReader);
|
||||
|
||||
Resource newResource = new Resource();
|
||||
newResource.Id = (string)resource["_id"]["$oid"];
|
||||
newResource.Id = (string)resourceData["ResourceId"];
|
||||
|
||||
var test = _resourceService.GetById(newResource.Id);
|
||||
if (test == null)
|
||||
{
|
||||
newResource.Type = ResourceType.Image;
|
||||
newResource.DateCreation = (DateTime)resource["DateCreation"]["$date"];
|
||||
newResource.Label = (string)resource["Label"];
|
||||
newResource.InstanceId = "65ccc67265373befd15be511";
|
||||
|
||||
var dataTest = (string)resource["Data"];
|
||||
var downloadUrl = await _firebaseStorageService.UploadBase64Async(dataTest, newResource.Id, newResource.InstanceId);
|
||||
// Rechercher la ressource correspondante dans resourceAll
|
||||
var resource = resourceAll.FirstOrDefault(r => r._id.oid == newResource.Id);
|
||||
|
||||
if (resource != null && resource.InstanceId == "633ee379d9405f32f166f047")
|
||||
{
|
||||
newResource.Type = resource.Type;
|
||||
newResource.DateCreation = resource.DateCreation.date;
|
||||
newResource.Label = resource.Label;
|
||||
newResource.InstanceId = resource.InstanceId;
|
||||
|
||||
var dataTest = (string)resourceData["Data"];
|
||||
try {
|
||||
// Uncomment if needed
|
||||
/*var downloadUrl = await _firebaseStorageService.UploadBase64Async(dataTest, newResource.Id, newResource.InstanceId);
|
||||
newResource.Url = downloadUrl;
|
||||
Resource createdResource = _resourceService.Create(newResource);*/
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine("resource id " + newResource.Id);
|
||||
Console.WriteLine(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Rechercher la ressource correspondante dans resourceAll
|
||||
var resource = resourceAll.FirstOrDefault(r => r._id.oid == newResource.Id);
|
||||
|
||||
// TO Uncomment if needed
|
||||
//Resource createdResource = _resourceService.Create(newResource);
|
||||
if (resource.Type != test.Type)
|
||||
{
|
||||
test.Type = resource.Type;
|
||||
//_resourceService.Update(test.Id, test);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -677,7 +677,7 @@ namespace ManagerService.Controllers
|
||||
{
|
||||
try
|
||||
{
|
||||
List<Section> sections = _sectionService.GetAll("65ccc67265373befd15be511"); // get by instance ID (hardcoded MDLF)
|
||||
List<Section> sections = _sectionService.GetAll("633ee379d9405f32f166f047"); // get by instance ID (hardcoded Fort)
|
||||
foreach (var section in sections)
|
||||
{
|
||||
section.ImageSource = CheckAndUpdateURL(section.ImageSource, _resourceService);
|
||||
@ -752,6 +752,15 @@ namespace ManagerService.Controllers
|
||||
|
||||
break;
|
||||
case SectionType.Menu:
|
||||
break;
|
||||
case SectionType.Article:
|
||||
var articleData = JsonConvert.DeserializeObject<ArticleDTO>(section.Data);
|
||||
foreach (var content in articleData.contents)
|
||||
{
|
||||
content.resourceUrl = CheckAndUpdateURL(content.resourceUrl, _resourceService);
|
||||
}
|
||||
section.Data = JsonConvert.SerializeObject(articleData); // Include all info from specific section as JSON
|
||||
|
||||
break;
|
||||
}
|
||||
// Update DB
|
||||
@ -776,7 +785,7 @@ namespace ManagerService.Controllers
|
||||
|
||||
private string CheckAndUpdateURL(string sourceURL, ResourceDatabaseService resourceDatabaseService)
|
||||
{
|
||||
if (sourceURL != null && (sourceURL.Contains("192.168.1.19") || sourceURL.Contains("localhost")))
|
||||
if (sourceURL != null && (sourceURL.Contains("192.168.1.19") || sourceURL.Contains("localhost") || sourceURL.Contains("https://api.mymuseum.be")))
|
||||
{
|
||||
if (sourceURL.Contains("localhost"))
|
||||
{
|
||||
@ -802,26 +811,28 @@ namespace ManagerService.Controllers
|
||||
{
|
||||
try
|
||||
{
|
||||
var i = 1;
|
||||
string json = System.IO.File.ReadAllText("C:/Users/ThomasFransolet/Documents/Documents/Perso/UNOV/MongoDB 10-10-24 - MyMuseum before migration/TabletDb.Sections.json");
|
||||
|
||||
string json = System.IO.File.ReadAllText("C:/Users/ThomasFransolet/Documents/Documents/Perso/MuseeDeLaFraise/Aout 2024/TabletDb.Sections.json");
|
||||
var sections = JsonConvert.DeserializeObject<SectionDTO[]>(json);
|
||||
var sections = JsonConvert.DeserializeObject<SectionForJsonDTO[]>(json);
|
||||
|
||||
foreach (var sectionJSON in sections)
|
||||
|
||||
foreach (var sectionJSON in sections.Where(s => s.InstanceId == "633ee379d9405f32f166f047"))
|
||||
{
|
||||
// Todo add some verification ?
|
||||
Section section = new Section();
|
||||
section.Id = sectionJSON.id;
|
||||
section.InstanceId = "65ccc67265373befd15be511"; // MDLF hardcoded
|
||||
section.Label = sectionJSON.label;
|
||||
section.ImageId = sectionJSON.imageId;
|
||||
section.ImageSource = sectionJSON.imageSource;
|
||||
section.ConfigurationId = sectionJSON.configurationId;
|
||||
section.DateCreation = sectionJSON.dateCreation;
|
||||
section.IsSubSection = sectionJSON.isSubSection;
|
||||
section.ParentId = sectionJSON.parentId;
|
||||
section.Type = sectionJSON.type;
|
||||
section.Title = sectionJSON.title;
|
||||
section.Description = sectionJSON.description;
|
||||
section.Id = sectionJSON._id.oid;
|
||||
section.InstanceId = "633ee379d9405f32f166f047"; // Fort hardcoded
|
||||
section.Label = sectionJSON.Label;
|
||||
section.ImageId = sectionJSON.ImageId;
|
||||
section.ImageSource = sectionJSON.ImageSource;
|
||||
section.ConfigurationId = sectionJSON.ConfigurationId;
|
||||
section.DateCreation = sectionJSON.DateCreation.date;
|
||||
section.IsSubSection = sectionJSON.IsSubSection;
|
||||
section.ParentId = sectionJSON.ParentId;
|
||||
section.Type = (SectionType)sectionJSON.Type;
|
||||
section.Title = sectionJSON.Title;
|
||||
section.Description = sectionJSON.Description;
|
||||
section.Order = _sectionService.GetAllFromConfiguration(section.ConfigurationId).Count;
|
||||
section.IsBeacon = false;
|
||||
|
||||
@ -840,7 +851,7 @@ namespace ManagerService.Controllers
|
||||
switch (section.Type)
|
||||
{
|
||||
case SectionType.Map:
|
||||
var sectionDataMap = JsonConvert.DeserializeObject<MapDTO>(sectionJSON.data);
|
||||
/*var sectionDataMap = JsonConvert.DeserializeObject<MapDTO>(sectionJSON.Data);
|
||||
var mapDTO = new MapDTO();
|
||||
|
||||
mapDTO.mapType = sectionDataMap.mapType;
|
||||
@ -853,7 +864,7 @@ namespace ManagerService.Controllers
|
||||
|
||||
List<GeoPointDTO> geoPoints = new List<GeoPointDTO>();
|
||||
|
||||
JObject sectionMapp = JObject.Parse(sectionJSON.data);
|
||||
JObject sectionMapp = JObject.Parse(sectionJSON.Data);
|
||||
foreach (var point in sectionMapp["points"])
|
||||
{
|
||||
GeoPointDTO pointDTO = new GeoPointDTO();
|
||||
@ -880,12 +891,12 @@ namespace ManagerService.Controllers
|
||||
|
||||
mapDTO.points = geoPoints;
|
||||
mapDTO.categories = new List<CategorieDTO>();
|
||||
section.Data = JsonConvert.SerializeObject(mapDTO); // Include all info from specific section as JSON
|
||||
section.Data = JsonConvert.SerializeObject(mapDTO); // Include all info from specific section as JSON*/
|
||||
break;
|
||||
case SectionType.Slider:
|
||||
//var sectionSlider = JsonConvert.DeserializeObject(sectionJSON.data);
|
||||
var sliderDTO = new SliderDTO();
|
||||
JObject sectionSlider = JObject.Parse(sectionJSON.data);
|
||||
JObject sectionSlider = JObject.Parse(sectionJSON.Data);
|
||||
|
||||
List<ContentDTO> newContents = new List<ContentDTO>();
|
||||
|
||||
@ -913,19 +924,19 @@ namespace ManagerService.Controllers
|
||||
section.Data = JsonConvert.SerializeObject(sliderDTO); // Include all info from specific section as JSON
|
||||
break;
|
||||
case SectionType.Video:
|
||||
var sectionVideo = JsonConvert.DeserializeObject<VideoDTO>(sectionJSON.data);
|
||||
var sectionVideo = JsonConvert.DeserializeObject<VideoDTO>(sectionJSON.Data);
|
||||
VideoDTO videoDTO = new VideoDTO();
|
||||
videoDTO.source = sectionVideo.source;
|
||||
section.Data = JsonConvert.SerializeObject(videoDTO); // Include all info from specific section as JSON
|
||||
break;
|
||||
case SectionType.Web:
|
||||
var sectionWeb = JsonConvert.DeserializeObject<WebDTO>(sectionJSON.data);
|
||||
var sectionWeb = JsonConvert.DeserializeObject<WebDTO>(sectionJSON.Data);
|
||||
WebDTO webDTO = new WebDTO();
|
||||
webDTO.source = sectionWeb.source;
|
||||
section.Data = JsonConvert.SerializeObject(webDTO); // Include all info from specific section as JSON
|
||||
break;
|
||||
case SectionType.Menu:
|
||||
var sectionMenu = JsonConvert.DeserializeObject<MenuDTO>(sectionJSON.data);
|
||||
var sectionMenu = JsonConvert.DeserializeObject<MenuDTO>(sectionJSON.Data);
|
||||
MenuDTO menuDTO = new MenuDTO();
|
||||
menuDTO.sections = sectionMenu.sections;
|
||||
foreach (var sectionMenuu in menuDTO.sections)
|
||||
@ -1030,7 +1041,8 @@ namespace ManagerService.Controllers
|
||||
section.Data = JsonConvert.SerializeObject(menuDTO); // Include all info from specific section as JSON
|
||||
break;
|
||||
case SectionType.Quizz:
|
||||
var sectionQuizz = JsonConvert.DeserializeObject<QuizzDTO>(sectionJSON.data);
|
||||
// Fort don't use quizz for now piouf :)
|
||||
/*var sectionQuizz = JsonConvert.DeserializeObject<QuizzDTO>(sectionJSON.Data);
|
||||
QuizzDTO quizzDTO = new QuizzDTO();
|
||||
quizzDTO.questions = sectionQuizz.questions;
|
||||
quizzDTO.bad_level = sectionQuizz.bad_level;
|
||||
@ -1038,21 +1050,41 @@ namespace ManagerService.Controllers
|
||||
quizzDTO.good_level = sectionQuizz.medium_level;
|
||||
quizzDTO.great_level = sectionQuizz.great_level;
|
||||
|
||||
section.Data = JsonConvert.SerializeObject(quizzDTO); // Include all info from specific section as JSON
|
||||
section.Data = JsonConvert.SerializeObject(quizzDTO);*/ // Include all info from specific section as JSON
|
||||
break;
|
||||
|
||||
|
||||
|
||||
// NEW CONTENTS AFTER MDLF
|
||||
case SectionType.Article:
|
||||
ArticleDTO articleDTO = new ArticleDTO();
|
||||
articleDTO.contents = new List<ContentDTO>();
|
||||
articleDTO.content = contentArticle;
|
||||
//articleDTO.audioIds = LanguageInit.Init("Audio", languages, true);
|
||||
try {
|
||||
var sectionArticle = JsonConvert.DeserializeObject<OldArticleDTO>(sectionJSON.Data);
|
||||
ArticleDTO newArticle = new ArticleDTO();
|
||||
newArticle.content = sectionArticle.content;
|
||||
newArticle.isContentTop = sectionArticle.isContentTop;
|
||||
newArticle.audioIds = sectionArticle.audioIds;
|
||||
newArticle.isReadAudioAuto = sectionArticle.isReadAudioAuto;
|
||||
newArticle.contents = new List<ContentDTO>();
|
||||
foreach (var image in sectionArticle.images) // Migrate old images to contents
|
||||
{
|
||||
ContentDTO contentDTO = new ContentDTO();
|
||||
|
||||
contentDTO.title = image.title;
|
||||
contentDTO.description = image.description;
|
||||
contentDTO.resourceId = image.resourceId;
|
||||
contentDTO.order = image.order;
|
||||
contentDTO.resourceType = ResourceType.Image;
|
||||
contentDTO.resourceUrl = image.source;
|
||||
newArticle.contents.Add(contentDTO);
|
||||
}
|
||||
|
||||
section.Data = JsonConvert.SerializeObject(newArticle); // Include all info from specific section as JSON
|
||||
} catch (Exception e)
|
||||
{
|
||||
Console.WriteLine("Issue in article with id " + sectionJSON._id + e);
|
||||
|
||||
}
|
||||
|
||||
section.Data = JsonConvert.SerializeObject(articleDTO); // Include all info from specific section as JSON
|
||||
break;
|
||||
case SectionType.PDF:
|
||||
/*case SectionType.PDF:
|
||||
PdfDTO pdfDTO = new PdfDTO();
|
||||
section.Data = JsonConvert.SerializeObject(pdfDTO); // Include all info from specific section as JSON
|
||||
break;
|
||||
@ -1067,11 +1099,20 @@ namespace ManagerService.Controllers
|
||||
case SectionType.Weather:
|
||||
WeatherDTO weatherDTO = new WeatherDTO();
|
||||
section.Data = JsonConvert.SerializeObject(weatherDTO); // Include all info from specific section as JSON
|
||||
break;
|
||||
break;*/
|
||||
}
|
||||
|
||||
if (_configurationService.IsExist(section.ConfigurationId))
|
||||
{
|
||||
i += 1;
|
||||
//Section sectionCreated = _sectionService.Create(section);
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
var test = i;
|
||||
|
||||
return new OkObjectResult(true);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user