Skip to content

Commit

Permalink
#1263 if container has attributes, they will also apear and store in …
Browse files Browse the repository at this point in the history
…the metadata
  • Loading branch information
DavidBlaa committed Feb 8, 2024
1 parent dad08fd commit 54e9c86
Show file tree
Hide file tree
Showing 7 changed files with 240 additions and 66 deletions.
50 changes: 28 additions & 22 deletions Components/XML/BExIS.Xml.Helpers/XmlMetadataWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,7 @@ public XDocument Update(XDocument metadataXml, BaseUsage attributeUsage, int num
_tempXDoc = metadataXml;

XElement parent = Get(parentXpath);
XElement destination = parent;

if (parent != null)
{
Expand All @@ -909,34 +910,39 @@ public XDocument Update(XDocument metadataXml, BaseUsage attributeUsage, int num
if (attributeRole != null)
{
XElement attribute = Get(attributeTypeName, number, attributeRole);
if(value!=null) attribute.SetValue(value.ToString());
if (value != null) attribute.SetValue(value.ToString());

destination = attribute;

}

}
}

if (xmlAttrs != null)
{
foreach (var kvp in xmlAttrs)
{
//create or replace
if (destination.Attributes().Any(a => a.Name.ToString().Equals(kvp.Key)))
{
XAttribute xattribute = destination.Attributes().FirstOrDefault(a => a.Name.ToString().Equals(kvp.Key));

if (xmlAttrs != null)
//replace
if (xattribute != null) xattribute.Value = kvp.Value;
//create
else
{
foreach (var kvp in xmlAttrs)
{
//create or replace
if (attribute.Attributes().Any(a => a.Name.ToString().Equals(kvp.Key)))
{
XAttribute xattribute = attribute.Attributes().FirstOrDefault(a => a.Name.ToString().Equals(kvp.Key));

//replace
if (xattribute != null) xattribute.Value = kvp.Value;
//create
else
{
attribute.Add(new XAttribute(kvp.Key, kvp.Value));
}
}
else
{
attribute.Add(new XAttribute(kvp.Key, kvp.Value));
}
}
destination.Add(new XAttribute(kvp.Key, kvp.Value));
}
}
else
{
destination.Add(new XAttribute(kvp.Key, kvp.Value));
}
}
}


return _tempXDoc;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ Green 05 #eff7f6
width:auto;
}

.simpleParametersContainer {
padding: 10px;
background-color: var(--bg-color-level-5)
}

.simpleParametersContainer {
padding: 10px 10px 20px 10px;
border-bottom: var(--bg-color-level-2) 1px solid;
}


.simpleAttributesContainer
{
text-align:center;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,7 @@ public ActionResult AddComplexUsage(int parentStepId, int number)
model.Number = position;

((MetadataCompoundAttributeModel)model).ConvertMetadataAttributeModels(usage, metadataStructureId, newStep.Id);
((MetadataCompoundAttributeModel)model).ConvertMetadataParameterModels(usage, metadataStructureId, newStep.Id);

//Update metadata xml
//add step to metadataxml
Expand Down Expand Up @@ -3035,13 +3036,16 @@ public ActionResult ValidateMetadataParameterUsage(string value, int id, long at
var pNumber = stepModelHelper.Number;

metadataStructureUsageHelper = new MetadataStructureUsageHelper();

var metadataAttributeUsage = metadataStructureUsageHelper.GetChildren(parentUsage.Id, parentUsage.GetType()).Where(u => u.Id.Equals(attrUsageId)).FirstOrDefault();
var metadataParameterUsage = metadataStructureUsageHelper.GetParameters(attrUsageId, metadataAttributeUsage.GetType()).FirstOrDefault(p=>p.Id.Equals(id));

Type type = metadataAttributeUsage == null ? parentUsage.GetType() : metadataAttributeUsage.GetType();
var destinationUsage = metadataAttributeUsage == null ? parentUsage : metadataAttributeUsage;

var metadataParameterUsage = metadataStructureUsageHelper.GetParameters(attrUsageId, type).FirstOrDefault(p=>p.Id.Equals(id));

//UpdateXml
var metadataStructureId = Convert.ToInt64(TaskManager.Bus[CreateTaskmanager.METADATASTRUCTURE_ID]);
var model = FormHelper.CreateMetadataParameterModel(metadataParameterUsage as BaseUsage, metadataAttributeUsage, metadataStructureId, parentModelNumber, parentStepId);
var model = FormHelper.CreateMetadataParameterModel(metadataParameterUsage as BaseUsage, destinationUsage, metadataStructureId, parentModelNumber, parentStepId);


//check if datatype is a datetime then check display pattern and manipulate the incoming string
Expand All @@ -3060,23 +3064,42 @@ public ActionResult ValidateMetadataParameterUsage(string value, int id, long at

//create para
KeyValuePair<string, string> parameter = new KeyValuePair<string, string>(metadataParameterUsage.Label, value);
UpdateParameter(metadataAttributeUsage, number, value, stepModelHelper.XPath, parameter);
UpdateParameter(destinationUsage, number, value, stepModelHelper.XPath, parameter);

ViewData["Xpath"] = stepModelHelper.XPath; // set Xpath for idbyxapth

// store in stephelper
if (stepModelHelper.Model.MetadataAttributeModels.Any()) // check if metadata Attribute models exist
{
var metadataAttributeModel = stepModelHelper.Model.MetadataAttributeModels.Where(m=>m.Source.Id.Equals(attrUsageId) && m.Number.Equals((long)number)).FirstOrDefault();// get metadata attribute model for this parameter
if (metadataAttributeModel != null)
{
if(metadataAttributeModel.Parameters.Any())
if (metadataAttributeUsage != null)
{
if (stepModelHelper.Model.MetadataAttributeModels.Any()) // check if metadata Attribute models exist
{
var metadataAttributeModel = stepModelHelper.Model.MetadataAttributeModels.Where(m => m.Source.Id.Equals(attrUsageId) && m.Number.Equals((long)number)).FirstOrDefault();// get metadata attribute model for this parameter
if (metadataAttributeModel != null)
{
if (metadataAttributeModel.Parameters.Any())
{
// get stored parameter model and replace it
var storedParameterModel = metadataAttributeModel.Parameters.Where(p => p.Id.Equals(model.Id)).FirstOrDefault();
storedParameterModel.Value = model.Value;
storedParameterModel.Errors = validateParameter(model);
}
}
}
}
else
{
if (stepModelHelper.Model.MetadataParameterModels.Any()) // check if metadata Attribute models exist
{
var parameters = stepModelHelper.Model.MetadataParameterModels;

if (parameters.Any())
{
// get stored parameter model and replace it
var storedParameterModel = metadataAttributeModel.Parameters.Where(p => p.Id.Equals(model.Id)).FirstOrDefault();
var storedParameterModel = parameters.Where(p => p.Id.Equals(model.Id)).FirstOrDefault();
storedParameterModel.Value = model.Value;
storedParameterModel.Errors = validateParameter(model);
}

}
}

Expand Down Expand Up @@ -3301,6 +3324,7 @@ private MetadataCompoundAttributeModel createCompoundModel(int stepId, bool vali

// get children
model.ConvertMetadataAttributeModels(usage, metadataStructureId, stepInfo.Id);
model.ConvertMetadataParameterModels(usage, metadataStructureId, stepInfo.Id);
model.StepInfo = TaskManager.Get(stepId);

if (stepInfo.IsInstanze == false)
Expand Down Expand Up @@ -3345,6 +3369,7 @@ private MetadataPackageModel createPackageModel(int stepId, bool validateIt)

model = FormHelper.CreateMetadataPackageModel(mpu, stepModelHelper.Number);
model.ConvertMetadataAttributeModels(mpu, metadataStructureId, stepId);
model.ConvertMetadataParameterModels(mpu, metadataStructureId, stepId);

if (stepInfo.IsInstanze == false)
{
Expand Down Expand Up @@ -3530,6 +3555,16 @@ private AbstractMetadataStepModel LoadSimpleAttributesForModelFromXml(StepModelH
tempList.Insert(indexOfLastSameAttribute + 1, item);
}

// add parameters
foreach (var item in stepModelHelper.Model.MetadataParameterModels)
{
if (item!=null && complexElement != null && complexElement.HasAttributes)
{
item.Value = complexElement.Attribute(item.DisplayName).Value.ToString();
}
}


return stepModelHelper.Model;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ public class AbstractMetadataStepModel : AbstractStepModel
public int MaxCardinality { get; set; }

public List<MetadataAttributeModel> MetadataAttributeModels { get; set; }
public List<MetadataParameterModel> MetadataParameterModels { get; set; }
public List<MetadataInstanceModel> Instance { get; set; }

public AbstractMetadataStepModel()
{
Instance = new List<MetadataInstanceModel>();
MetadataAttributeModels = new List<MetadataAttributeModel>();
MetadataParameterModels = new List<MetadataParameterModel>();
}

public void ConvertInstance(XDocument metadata, string xpath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class MetadataCompoundAttributeModel : AbstractMetadataStepModel
public MetadataCompoundAttributeModel()
{
MetadataAttributeModels = new List<MetadataAttributeModel>();
MetadataParameterModels = new List<MetadataParameterModel>();
metadataStructureUsageHelper = new MetadataStructureUsageHelper();
}

Expand Down Expand Up @@ -72,5 +73,54 @@ public void ConvertMetadataAttributeModels(BaseUsage source, long metadataStruct
}
}

public void ConvertMetadataParameterModels(BaseUsage source, long metadataStructureId, long stepId)
{
Source = source;

if (Source is MetadataAttributeUsage)
{

MetadataAttributeUsage mau = (MetadataAttributeUsage)Source;

if (mau.MetadataAttribute.Self is MetadataCompoundAttribute)
{
MetadataCompoundAttribute mca = (MetadataCompoundAttribute)mau.MetadataAttribute.Self;

if (mca != null)
{
foreach (MetadataParameterUsage usage in mca.MetadataParameterUsages)
{

var metadataParameterModel = FormHelper.CreateMetadataParameterModel(usage, mau, metadataStructureId, Number, stepId);
MetadataParameterModels.Add(metadataParameterModel);

}
}
}
}

if (Source is MetadataNestedAttributeUsage)
{
MetadataNestedAttributeUsage mnau = (MetadataNestedAttributeUsage)Source;
if (mnau.Member.Self is MetadataCompoundAttribute)
{
MetadataCompoundAttribute mca = (MetadataCompoundAttribute)mnau.Member.Self;

if (mca != null)
{
foreach (MetadataNestedAttributeUsage usage in mca.MetadataNestedAttributeUsages)
{
if (metadataStructureUsageHelper.IsSimple(usage))
{
var metadataParameterModel = FormHelper.CreateMetadataParameterModel(usage, mnau, metadataStructureId, Number, stepId);
MetadataParameterModels.Add(metadataParameterModel);

}
}
}
}
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public MetadataPackageModel()
{
ErrorList = new List<Error>();
metadataStructureUsageHelper = new MetadataStructureUsageHelper();
MetadataParameterModels = new List<MetadataParameterModel>();
}

public void ConvertMetadataAttributeModels(BaseUsage source, long metadataStructureId, int stepId)
Expand All @@ -42,5 +43,54 @@ public void ConvertMetadataAttributeModels(BaseUsage source, long metadataStruct
}
}
}

public void ConvertMetadataParameterModels(BaseUsage source, long metadataStructureId, long stepId)
{
Source = source;

if (Source is MetadataAttributeUsage)
{

MetadataAttributeUsage mau = (MetadataAttributeUsage)Source;

if (mau.MetadataAttribute.Self is MetadataCompoundAttribute)
{
MetadataCompoundAttribute mca = (MetadataCompoundAttribute)mau.MetadataAttribute.Self;

if (mca != null)
{
foreach (MetadataParameterUsage usage in mca.MetadataParameterUsages)
{

var metadataParameterModel = FormHelper.CreateMetadataParameterModel(usage, mau, metadataStructureId, Number, stepId);
MetadataParameterModels.Add(metadataParameterModel);

}
}
}
}

if (Source is MetadataNestedAttributeUsage)
{
MetadataNestedAttributeUsage mnau = (MetadataNestedAttributeUsage)Source;
if (mnau.Member.Self is MetadataCompoundAttribute)
{
MetadataCompoundAttribute mca = (MetadataCompoundAttribute)mnau.Member.Self;

if (mca != null)
{
foreach (MetadataNestedAttributeUsage usage in mca.MetadataNestedAttributeUsages)
{
if (metadataStructureUsageHelper.IsSimple(usage))
{
var metadataParameterModel = FormHelper.CreateMetadataParameterModel(usage, mnau, metadataStructureId, Number, stepId);
MetadataParameterModels.Add(metadataParameterModel);

}
}
}
}
}
}
}
}
Loading

0 comments on commit 54e9c86

Please sign in to comment.