XmlRowReader() public method

wandelt bexis primardaten (rows) in bexis 2 datatuples um
public XmlRowReader ( XmlDocument data, long dataStructureId, int observationIndex ) : DataTuple
data System.Xml.XmlDocument
dataStructureId long
observationIndex int
return BExIS.Dlm.Entities.Data.DataTuple
Example #1
0
        /// <summary>
        /// CAUTION !!!!!!!!!!!!!!!!!
        /// upload bezieht sich derzeit nur auf daten mit einem block (einer tabelle)
        /// umsetzung von mehreren blöckes noch nicht geklärt.
        /// (für einen wert gibt es eine weitere tabelle)
        /// </summary>
        /// <param name="dataSetID"></param>
        /// <param name="DataBase"></param>
        public void uploadData(string dataSetID, string DataBase)
        {
            DatasetManager datasetManager = new DatasetManager();
            DataStructureManager dataStructureManager = new DataStructureManager();
            XmlDataReader xmlDataReader = new XmlDataReader();

            User user = new User();
            string variableNames = "";
            // query metadataAuthor and variable names from explorer.datasets
            queryAuthorAndVariables(ref user, ref variableNames, dataSetID, DataBase);
            List<string> varNames = variableNames.Split(',').ToList();

            // get all dataStructures with equal variables count
            List<StructuredDataStructure> dataStructures = dataStructureManager.StructuredDataStructureRepo.Get(s =>
                varNames.Count().Equals(s.Variables.Count)).ToList();

            // get all Ids of dataStructures with equal variables
            List<long> dataStructureIds = new List<long>();
            foreach (StructuredDataStructure dataStructure in dataStructures)
            {
                bool isSimilarStructure = true;
                foreach (Variable variable in dataStructure.Variables)
                {
                    if (!varNames.Contains(variable.Label))
                    {
                        isSimilarStructure &= false;
                        break;
                    }
                }
                if (isSimilarStructure)
                    dataStructureIds.Add(dataStructure.Id);
            }

            // get the wanted dataset by comparing the old B1 datasetId out of the datasets with similar dataStructure
            Dataset dataset = null;
            List<Dataset> datasets = datasetManager.DatasetRepo.Get(d => dataStructureIds.Contains(d.DataStructure.Id)).ToList();
            foreach (Dataset ds in datasets)
            {
                string oldDatasetId = "";
                try
                {
                    XmlNode extraID = ds.Versions.FirstOrDefault().Metadata.SelectSingleNode("Metadata/general/general/id/id");
                    oldDatasetId = extraID.InnerText;
                }
                catch
                {
                }
                if (oldDatasetId == dataSetID)
                {
                    dataset = ds;
                    break;
                }
            }

            if (dataset != null)
            {
                // get distinct and ascending ordered insertdates from DB
                List<DB2TimeStamp> distInsertDates = queryDistInsertDates(dataSetID, DataBase);

                bool checkObsIds = false;
                foreach (DB2TimeStamp insertDate in distInsertDates)
                {
                    List<DataTuple> createdDataTuples = new List<DataTuple>();
                    List<DataTuple> editedDataTuples = new List<DataTuple>();
                    List<DataTuple> deletedDataTuples = new List<DataTuple>();

                    DatasetVersion workingCopy = datasetManager.GetDatasetLatestVersion(dataset.Id); // get dataset
                    // get obsid, data, deleted and newest for each observation from DB
                    List<Observation> observations = queryObservation(dataSetID, DataBase, insertDate.ToString());
                    Dictionary<long, long> obsIdMapsToTupleId = new Dictionary<long, long>();
                    if (checkObsIds)
                    {
                        // get all EffectiveTupleIds
                        List<long> datasetTupleIds = datasetManager.GetDatasetVersionEffectiveTupleIds(workingCopy).ToList();
                        // id-mapping-list key=obsId, value=TupleId foreach EffectiveTupleId and obsId from Tuple.Extra
                        obsIdMapsToTupleId = idMapping(datasetTupleIds, ref datasetManager);
                    }
                    // observation counter
                    int observationIndex = 0;
                    bool isNewest = true;
                    foreach (Observation observation in observations) //////////////parallel
                    {
                        isNewest = (isNewest && observation.newest != 'Y') ? false : isNewest;
                        // create dataTuple with xmlDataReader
                        // split xml to string list and use DataReader.ReadRow
                        DataTuple dataRow = xmlDataReader.XmlRowReader(observation.data, dataset.DataStructure.Id, observationIndex);
                        // check if observation.obsid is in id-mapping-list
                        long TupleId;
                        if (checkObsIds && obsIdMapsToTupleId.TryGetValue(observation.obsid, out TupleId))
                        {
                            DataTuple dataTuple = datasetManager.DataTupleRepo.Get(TupleId);
                            if (observation.deleted != 'Y')
                            {
                                dataTuple.VariableValues = dataRow.VariableValues;
                                // edit tuple if observation exists as tuple in EffectiveTuple and observation is not deleted
                                editedDataTuples.Add(dataTuple);
                            }
                            else
                            {
                                // delete tuple if observation exists as tuple in EffectiveTuple and observ. is deleted
                                deletedDataTuples.Add(dataTuple);
                            }
                        }
                        else
                        {
                            // write the obsId and oldBExISdatasetId in Extra: <extra><obsid>[obsid]</obsid><oldBExISdatasetId>[dataSetID]</oldBExISdatasetId></extra>
                            dataRow.Extra = oldIdsIntoExtra(observation.obsid, dataSetID, dataRow.Extra);
                            // create tuple if observation exists not in EffectiveTuple
                            createdDataTuples.Add(dataRow);
                        }
                        observationIndex++; // observation counter
                    }
                    checkObsIds = (!checkObsIds && !isNewest) ? true : checkObsIds;

                    // checkOut
                    if (datasetManager.IsDatasetCheckedOutFor(dataset.Id, user.Name) || datasetManager.CheckOutDataset(dataset.Id, user.Name))
                    {
                        workingCopy = datasetManager.GetDatasetWorkingCopy(dataset.Id); // get dataset
                        datasetManager.EditDatasetVersion(workingCopy, createdDataTuples, editedDataTuples, deletedDataTuples); // edit dataset
                        datasetManager.CheckInDataset(dataset.Id, "Primary data row was submited.", user.Name); // checkIn
                    }
                }
            }
        }