private void AddOrRemoveODRelations(ObjDigComposto odComp, ObjDigSimples odSimples, GISADataset.ObjetoDigitalRow odRow)
 {
     var frdRow = currentNivel.GetFRDBaseRows().Single();
     if (odComp.state == State.added)
     {
         var imgODRow = odRow.GetSFRDImagemObjetoDigitalRows().SingleOrDefault(r => r.IDFRDBase == frdRow.ID);
         if (imgODRow != null) // esta row é nula no caso dos ODs Simples associados a subdocumentos
         {
             imgODRow.SFRDImagemRowParent.Delete();
             imgODRow.Delete();
         }
         GisaDataSetHelper.GetInstance().ObjetoDigitalRelacaoHierarquica.AddObjetoDigitalRelacaoHierarquicaRow(odRow, currentObjetoDigitalRowComp, new byte[] { }, 0);
     }
     else if (odComp.state == State.deleted)
     {
         if (odRow.GetSFRDImagemObjetoDigitalRows().Count() == 0) // se se tratar de um od simples sem estar relacionado com um subdocumento cria-se relacao com a UI selecionada
             FedoraHelper.RelateODtoUI(odSimples, odRow, currentNivel.GetFRDBaseRows().Single());
     }
 }
        private void CreateDatabaseObjDigSimples(ObjDigComposto odComp, GISADataset.ObjetoDigitalRow odRowComp, ObjDigSimples odSimples)
        {
            Debug.Assert(odComp != null);
            Debug.Assert(odSimples != null);
            Debug.Assert(odRowComp != null && odRowComp.RowState != DataRowState.Deleted);

            var orderNr = odComp.objSimples.IndexOf(odSimples);
            var odRow = GisaDataSetHelper.GetInstance().ObjetoDigital.AddObjetoDigitalRow(odSimples.pid, odSimples.titulo, odSimples.publicado, (orderNr + 1), new byte[] { }, 0);


            GisaDataSetHelper.GetInstance().ObjetoDigitalRelacaoHierarquica.AddObjetoDigitalRelacaoHierarquicaRow(odRow, odRowComp, new byte[] { }, 0);
            //PermissoesHelper.AddNewObjDigGrantPermissions(odRow, currentNivel);

            newObjects.Add(odRow, odSimples);
        }
Example #3
0
 public FoxmlExporter(ObjDigSimples document, string owner, string pid, string nmspace)
 {
     this.userName = owner;
     this.pid      = pid;
     this.nmspace  = nmspace;
     this.DoTheFOXML(document);
 }
 private void btnCheckIntegrity_Click(object sender, EventArgs e)
 {
     if (lstVw.SelectedItems.Count == 1)
     {
         Fedora.FedoraHandler.ObjDigSimples objDigital = lstVw.SelectedItems[0].Tag as Fedora.FedoraHandler.ObjDigSimples;
         SessionHelper.AppConfiguration.GetCurrentAppconfiguration().FedoraHelperSingleton.CheckIntegrity(objDigital);
     }
 }
Example #5
0
 public DublinCoreExporter(ObjDigSimples doc)
 {
     this.title = doc.titulo;
     this.type  = doc.tipologia;
     this.ids   = new List <string>()
     {
         doc.pid, doc.gisa_id
     };
     if (doc.parentDocumentTitle != null)
     {
         this.parts.Add(doc.parentDocumentTitle);
     }
     this.subjects = doc.assuntos.ToArray();
     this.daddy    = false;
 }
        public void Load(ObjDigSimples objecto)
        {
            this.objSimples = objecto;

            if (objSimples != null)
            {
                versionBar.Minimum = 0;
                versionBar.Maximum = Math.Max(objSimples.historico.Count - 1, 0);
                versionBar.Value = 0;
                UpdateVersionLabels(false);
                VersionChanged(this, versionBar.Value);
                this.Enabled = true;
            }
            else this.Enabled = false;
        }
Example #7
0
 public override ObjDigital Clone()
 {
     var theOriginal = new ObjDigSimples();
     theOriginal.titulo = this.titulo;
     theOriginal.tipologia = this.tipologia;
     theOriginal.assuntos = new List<string>(this.assuntos);
     theOriginal.gisa_id = this.gisa_id;
     theOriginal.pid = this.pid;
     theOriginal.publicado = this.publicado;
     theOriginal.parentDocumentTitle = this.parentDocumentTitle;
     theOriginal.fich_associados = new List<Anexo>();
     theOriginal.version = this.version;
     theOriginal.nextDatastreamId = this.nextDatastreamId;
     this.fich_associados.ForEach(anexo => theOriginal.fich_associados.Add(anexo.Clone()));
     this.historico.ForEach(entry => theOriginal.historico.Add(entry.Clone()));
     return theOriginal;
 }
Example #8
0
        public override ObjDigital Clone()
        {
            var theOriginal = new ObjDigSimples();

            theOriginal.titulo              = this.titulo;
            theOriginal.tipologia           = this.tipologia;
            theOriginal.assuntos            = new List <string>(this.assuntos);
            theOriginal.gisa_id             = this.gisa_id;
            theOriginal.pid                 = this.pid;
            theOriginal.publicado           = this.publicado;
            theOriginal.parentDocumentTitle = this.parentDocumentTitle;
            theOriginal.fich_associados     = new List <Anexo>();
            theOriginal.version             = this.version;
            theOriginal.nextDatastreamId    = this.nextDatastreamId;
            this.fich_associados.ForEach(anexo => theOriginal.fich_associados.Add(anexo.Clone()));
            this.historico.ForEach(entry => theOriginal.historico.Add(entry.Clone()));
            return(theOriginal);
        }
        private static void UpdateNvlDocSimplesOrderNr(ObjDigSimples odSimples)
        {
            if (odSimples.gisa_id != null && odSimples.gisa_id.Length > 0)
            {
                var nds = GisaDataSetHelper.GetInstance().NivelDocumentoSimples.Cast<GISADataset.NivelDocumentoSimplesRow>().SingleOrDefault(r => r.RowState != DataRowState.Deleted && r.ID == FedoraHelper.GetGisaID(odSimples.gisa_id));

                if (nds != null)
                    nds.GUIOrder = odSimples.guiorder;
            }
        }
Example #10
0
 public MetsExporter(ObjDigSimples document, string owner, string[] logMessage)
 {
     this.userName = owner;
     DoTheMETS(document, logMessage);
 }
Example #11
0
        private void DoTheFOXML(ObjDigital obj)
        {
            var title = obj.titulo;

            // Construir os headers
            foxml            = new FoxmlDigitalObject("1.1", this.pid);
            foxml.properties = new FoxmlObjectProperties();
            foxml.properties.AddProperty(new FoxmlProperty("info:fedora/fedora-system:def/model#state", "A"));
            foxml.properties.AddProperty(new FoxmlProperty("info:fedora/fedora-system:def/model#label", title));

            // Add the DC datastream
            DublinCoreExporter dcXml;
            MetsExporter       metsXml;

            if (obj.GetType() == typeof(ObjDigSimples))
            {
                ObjDigSimples objSimples = obj as ObjDigSimples;
                metsXml = new MetsExporter(objSimples, userName, new string[] { "Ingestão do documento " + this.pid });
                dcXml   = new DublinCoreExporter(obj as ObjDigSimples);
            }
            else
            {
                ObjDigComposto objComposto = obj as ObjDigComposto;
                metsXml = new MetsExporter(objComposto, userName, new string[] { "Ingestão do documento " + this.pid });
                dcXml   = new DublinCoreExporter(obj as ObjDigComposto);
            }

            FoxmlDatastream        dcStream  = new FoxmlDatastream("DC", FoxmlDatastreamState.Active, FoxmlControlGroup.InlineXML, true);
            FoxmlDatastreamVersion dcStream1 = new FoxmlDatastreamVersion("DC.0", "http://www.openarchives.org/OAI/2.0/oai_dc/", "text/xml", "Metadados em Dublin Core", null, null);

            dcStream1.inlineXML     = dcXml.DublinCore;
            dcStream1.contentDigest = new FoxmlContentDigest(FoxmlChecksumTypes.DEFAULT, null);
            dcStream.AddVersion(dcStream1);
            foxml.AddDatastream(dcStream);

            // Add the RELS-EXT datastream
            FoxmlDatastream        relsStream  = new FoxmlDatastream("RELS-EXT", FoxmlDatastreamState.Active, FoxmlControlGroup.InlineXML, true);
            FoxmlDatastreamVersion relsStream1 = new FoxmlDatastreamVersion("RELS-EXT.0", "info:fedora/fedora-system:FedoraRELSExt-1.0", "application/rdf+xml", "RDF Statements about this object", null, null);

            relsStream1.inlineXML = GetRdf(this.pid, this.nmspace);
            relsStream.AddVersion(relsStream1);
            foxml.AddDatastream(relsStream);

            // Add the METS datastream for this document
            FoxmlDatastream        metsStream  = new FoxmlDatastream("METS", FoxmlDatastreamState.Active, FoxmlControlGroup.InlineXML, true);
            FoxmlDatastreamVersion metsStream1 = new FoxmlDatastreamVersion("METS.0", "http://www.loc.gov/METS/", "text/xml", "Metadados adicionais em METS", null, null);

            metsStream1.inlineXML     = metsXml.METS;
            metsStream1.contentDigest = new FoxmlContentDigest(FoxmlChecksumTypes.DEFAULT, null);
            metsStream.AddVersion(metsStream1);
            foxml.AddDatastream(metsStream);

            // Add the content datastreams
            FoxmlDatastream        datastream;
            FoxmlDatastreamVersion dsversion;

            if (obj.GetType() == typeof(ObjDigSimples))
            {
                int           cnt        = 1;
                ObjDigSimples objSimples = obj as ObjDigSimples;

                foreach (Anexo s in objSimples.fich_associados)
                {
                    string uName = s.dataStreamID;
                    datastream = new FoxmlDatastream(uName, FoxmlDatastreamState.Active, FoxmlControlGroup.ExternallyReferenceContent, true);
                    dsversion  = new FoxmlDatastreamVersion(uName + ".0", null, s.mimeType, null, null, null);
                    dsversion.contentLocation = new FoxmlContentLocation(s.url, "URL");
                    dsversion.contentDigest   = new FoxmlContentDigest(FoxmlChecksumTypes.DEFAULT, null);
                    datastream.AddVersion(dsversion);
                    foxml.AddDatastream(datastream);
                    cnt++;
                }
            }
        }
        private void ObjectToView(ObjDigSimples objDigital)
        {
            txtTitulo.Text = objDigital.titulo;
            chkPublicar.Checked = objDigital.publicado;

            var itemsToBeAdded = new List<ListViewItem>();
            objDigital.fich_associados.ForEach(f =>
            {
                var datastream = f as Anexo;
                var item = ficheirosOrderManager1.CreateItem(datastream.url, datastream);
                itemsToBeAdded.Add(item);
            });

            if (itemsToBeAdded.Count > 0)
            {
                ficheirosOrderManager1.populateItems(itemsToBeAdded);
                ficheirosOrderManager1.selectFirst();
            }
        }
Example #13
0
        public ObjDigital GetStructureForPid(string pid, string originalTimestamp, bool loadVersions)
        {
            XmlDocument metsDoc;
            XmlDocument dcDoc;
            XmlNamespaceManager nameSpaceManager;
            XmlNamespaceManager dcNameSpaceManager;
            string versionTimestamp = null;
            try {
                versionTimestamp = manager.getDatastream(pid, "METS", originalTimestamp).createDate;

                MIMETypedStream stream = service.getDatastreamDissemination(pid, "METS", originalTimestamp);
                metsDoc = GetXmlFromStream(stream);
                nameSpaceManager = new XmlNamespaceManager(metsDoc.NameTable);
                nameSpaceManager.AddNamespace("mets", "http://www.loc.gov/METS/");
                nameSpaceManager.AddNamespace("xlink", "http://www.w3.org/TR/xlink/");

                // Temos de pedir o DC mais próximo da versão mais actualizada do METS (logo passamos o versionTimestamp)
                MIMETypedStream dcStream = service.getDatastreamDissemination(pid, "DC", versionTimestamp);
                dcDoc = GetXmlFromStream(dcStream);
                dcNameSpaceManager = new XmlNamespaceManager(dcDoc.NameTable);
                dcNameSpaceManager.AddNamespace("dc", "http://purl.org/dc/elements/1.1/");
                dcNameSpaceManager.AddNamespace("oai_dc", "http://www.openarchives.org/OAI/2.0/oai_dc/");
                dcNameSpaceManager.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");

            } catch (Exception ex) { throw new Exception("Datastreams METS e/ou DC inválidos para o objecto " + pid + ".", ex); }

            try {
                XmlNode structMap = metsDoc.SelectSingleNode("mets:mets/mets:structMap", nameSpaceManager);
                XmlNode mainDiv = structMap.SelectSingleNode("mets:div", nameSpaceManager);
                XmlNode recordID = metsDoc.SelectSingleNode("mets:mets/mets:metsHdr/mets:altRecordID", nameSpaceManager);

                string type;
                try { type = structMap.Attributes["TYPE"].Value.ToString().ToUpper();
                } catch { type = "PHYSICAL"; }
                ObjDigital newDocumentType = null;
                if (type == "LOGICAL")
                {
                    newDocumentType = new ObjDigComposto();
                    newDocumentType.state = State.unchanged;
                    newDocumentType.serverState = GetState(pid);
                    ObjDigSimples[] parts = new ObjDigSimples[mainDiv.SelectNodes("mets:div", nameSpaceManager).Count];

                    foreach (XmlNode subDiv in mainDiv.SelectNodes("mets:div", nameSpaceManager))
                    {
                        // Ler objecto directamente
                        XmlNode fptr = subDiv.SelectSingleNode("mets:fptr", nameSpaceManager);
                        ObjDigSimples objSimples = GetStructureForPid(fptr.Attributes["FILEID"].Value, originalTimestamp, true) as ObjDigSimples;
                        parts[int.Parse(subDiv.Attributes["ORDER"].Value) - 1] = objSimples;
                    }

                    ((ObjDigComposto)newDocumentType).objSimples.AddRange(parts);
                }
                else { 
                    newDocumentType = new ObjDigSimples();
                    newDocumentType.state = State.unchanged;
                    newDocumentType.serverState = GetState(pid);
                    Anexo[] parts = new Anexo[mainDiv.SelectNodes("mets:div", nameSpaceManager).Count];

                    foreach (XmlNode subDiv in mainDiv.SelectNodes("mets:div", nameSpaceManager))
                    {
                        XmlNode fptr = subDiv.SelectSingleNode("mets:fptr", nameSpaceManager);
                        Anexo anexo = new Anexo();

                        anexo.pid = pid;
                        anexo.dataStreamID = fptr.Attributes["FILEID"].Value;
                        anexo.mimeType = subDiv.Attributes["TYPE"].Value;
                        parts[int.Parse(subDiv.Attributes["ORDER"].Value) - 1] = anexo;

                        try
                        {
                            Datastream data = manager.getDatastream(pid, anexo.dataStreamID, null);
                            anexo.url = data.location;
                            anexo.checksum = data.checksum;
                        }
                        catch (Exception ex) { Trace.WriteLine(ex.ToString()); throw new Exception("URL de datastream " + anexo.dataStreamID + " no objecto " + pid + " não foi encontrado.", ex);  }
                    }

                    ((ObjDigSimples)newDocumentType).nextDatastreamId = service.listDatastreams(pid, null).Count(ds => ds.ID.Contains("IMG")) + 1;
                    ((ObjDigSimples)newDocumentType).fich_associados.AddRange(parts);

                    if(loadVersions)
                        ((ObjDigSimples)newDocumentType).historico.AddRange(GetHistoric(pid));
                    
                }

                newDocumentType.pid = pid;
                newDocumentType.version = versionTimestamp;
                newDocumentType.titulo = mainDiv.Attributes["LABEL"].Value;
                if (mainDiv.Attributes["TYPE"] != null)
                    newDocumentType.tipologia = mainDiv.Attributes["TYPE"].Value;
                if (recordID != null)  // há objetos que não têm gisa_id
                    newDocumentType.gisa_id = recordID.InnerText;
                else
                    newDocumentType.gisa_id = "";

                XmlNodeList assuntos = dcDoc.SelectNodes("oai_dc:dc/dc:subject", dcNameSpaceManager);
                if (assuntos.Count > 0)
                {
                    List<string> listAssuntos = new List<string>();
                    foreach (XmlNode node in assuntos) listAssuntos.Add(node.InnerText);
                    newDocumentType.assuntos = listAssuntos;
                }

                return newDocumentType;
            }
            catch (Exception ex) { Trace.WriteLine(ex.ToString()); throw new Exception("Erro ao analisar objecto " + pid + ".", ex); }
        }
Example #14
0
        private bool Update(ObjDigital objDigital)
        {
            bool          success   = true;
            bool          update    = false;
            var           original  = objDigital.original;
            List <string> changeset = new List <string>();

            // Se objecto não tem modificações, não fazer nada
            if (objDigital.state != State.modified)
            {
                return(true);
            }

            // Mesmo pid?
            if (original.pid != objDigital.pid || original.GetType() != objDigital.GetType())
            {
                Trace.WriteLine("Objecto a atualizar não tem o mesmo PID do objecto original.");
                return(false);
            }

            // Se for simples, verificar imagens
            if (objDigital.GetType() == typeof(ObjDigSimples))
            {
                // Verificar se é um simples e se mexemos nas imagens
                var simpleOriginal = original as ObjDigSimples;
                var simpleChanged  = objDigital as ObjDigSimples;

                // Detectar alterações na ordem (pelo menos dos documentos que se mantiverem da versão anterior)
                for (int i = 0; i < simpleOriginal.fich_associados.Count; i++)
                {
                    if (i + 1 > simpleChanged.fich_associados.Count)
                    {
                        break;
                    }
                    if (simpleChanged.fich_associados[i].url != simpleOriginal.fich_associados[i].url)
                    {
                        AddChange(IMAGES_ORDER, out update, changeset);
                        break;
                    }
                }

                // Adicionar novas datastreams
                if (simpleChanged.fich_associados.Exists(fich => fich.dataStreamID == null))
                {
                    AddChange(IMAGES_NEW, out update, changeset);
                    foreach (Anexo anexo in simpleChanged.fich_associados.Where(anx => anx.dataStreamID == null))
                    {
                        try
                        {
                            anexo.dataStreamID = manager.addDatastream(simpleChanged.pid, "IMG" + simpleChanged.nextDatastreamId, null, null, true, anexo.mimeType, null, anexo.url, "E", "A", "MD5", null, "Adição de imagem");
                            simpleChanged.nextDatastreamId++;
                        }
                        catch (Exception ex)
                        {
                            Trace.WriteLine(ex.ToString());
                            return(false);
                        }
                    }
                }

                // Detectar remoções feitas no objecto
                if (!simpleOriginal.fich_associados.TrueForAll(anexoOriginal => simpleChanged.fich_associados.Exists(anexoNovo => anexoNovo.url == anexoOriginal.url && anexoNovo.dataStreamID == anexoOriginal.dataStreamID)))
                {
                    changeset.Add(IMAGES_DELETE);
                    update = true;
                }

                /* if (simpleOriginal.fich_associados.Count > simpleChanged.fich_associados.Count)
                 * {
                 *  changeset.Add(IMAGES_DELETE);
                 *  update = true;
                 * } */
            }
            else if (objDigital.GetType() == typeof(ObjDigComposto))
            {
                // Se for um composto, verificar também se alteramos o título / tipologia de um dos simples
                var compostoOriginal = original as ObjDigComposto;
                var compostoChanged  = objDigital as ObjDigComposto;

                // Vemos se o composto tem o mesmo número de objectos simples que o original
                if (compostoChanged.objSimples.Count == compostoOriginal.objSimples.Count)
                {
                    for (int i = 0; i < compostoChanged.objSimples.Count; i++)
                    {
                        ObjDigSimples simples         = compostoChanged.objSimples[i];
                        ObjDigSimples simplesOriginal = compostoOriginal.objSimples[i];

                        if (simples.pid != simplesOriginal.pid)
                        {
                            AddChange(DOCUMENT_ORDER, out update, changeset);
                            break;
                        }
                    }

                    // Verificamos se algum dos simples associados a este composto teve o seu título ou tipologia alterada
                    foreach (ObjDigSimples simples in compostoChanged.objSimples)
                    {
                        ObjDigSimples simplesOriginal = simples.original as ObjDigSimples;
                        if (simplesOriginal == null || simples.titulo != simplesOriginal.titulo || simples.tipologia != simplesOriginal.tipologia)
                        {
                            AddChange(METADATA_CHILD, out update, changeset);
                            break;
                        }
                    }

                    // Actualizações ao estado de publicação não ficam registados como nova versão
                    if (compostoChanged.publicado != compostoOriginal.publicado)
                    {
                        PokeObject(compostoChanged);
                    }
                    else
                    {
                        foreach (ObjDigSimples simples in compostoChanged.objSimples)
                        {
                            ObjDigSimples simplesOriginal = simples.original as ObjDigSimples;
                            if (simplesOriginal != null && simples.publicado != simplesOriginal.publicado)
                            {
                                PokeObject(compostoChanged);
                                break;
                            }
                        }
                    }
                }
                else
                {
                    // Neste caso, ou adicionamos novos sub-documentos, ou os removemos
                    if (compostoChanged.objSimples.Count > compostoOriginal.objSimples.Count)
                    {
                        AddChange(DOCUMENT_CHILD_NEW, out update, changeset);
                    }
                    else
                    {
                        AddChange(DOCUMENT_CHILD_DELETE, out update, changeset);
                    }
                    update = true;
                }
            }

            // Verificar alteração na lista de assuntos
            if (original.assuntos.Count != objDigital.assuntos.Count || !objDigital.assuntos.TrueForAll(assunto => original.assuntos.Contains(assunto)))
            {
                AddChange(DOCUMENT_THEME, out update, changeset);
            }

            // A tipologia foi alterada?
            if (original.tipologia != objDigital.tipologia)
            {
                AddChange(DOCUMENT_TYPE, out update, changeset);
            }

            // O título foi alterado?
            if (original.titulo != objDigital.titulo)
            {
                AddChange(DOCUMENT_TITLE, out update, changeset);
            }

            if (update)
            {
                if (changeset.Count == 0)
                {
                    changeset.Add(METADATA_DEFAULT);
                }

                // Refazer DC e METS
                string newStamp;
                success = UpdateMetadata(objDigital, changeset.ToArray(), out newStamp);

                // Actualizar versão, se tudo correu bem
                if (success)
                {
                    objDigital.version = newStamp;
                    objDigital.state   = State.unchanged;
                }
            }

            return(success);
        }
Example #15
0
        public ObjDigital GetStructureForPid(string pid, string originalTimestamp, bool loadVersions)
        {
            XmlDocument         metsDoc;
            XmlDocument         dcDoc;
            XmlNamespaceManager nameSpaceManager;
            XmlNamespaceManager dcNameSpaceManager;
            string versionTimestamp = null;

            try {
                versionTimestamp = manager.getDatastream(pid, "METS", originalTimestamp).createDate;

                MIMETypedStream stream = service.getDatastreamDissemination(pid, "METS", originalTimestamp);
                metsDoc          = GetXmlFromStream(stream);
                nameSpaceManager = new XmlNamespaceManager(metsDoc.NameTable);
                nameSpaceManager.AddNamespace("mets", "http://www.loc.gov/METS/");
                nameSpaceManager.AddNamespace("xlink", "http://www.w3.org/TR/xlink/");

                // Temos de pedir o DC mais próximo da versão mais actualizada do METS (logo passamos o versionTimestamp)
                MIMETypedStream dcStream = service.getDatastreamDissemination(pid, "DC", versionTimestamp);
                dcDoc = GetXmlFromStream(dcStream);
                dcNameSpaceManager = new XmlNamespaceManager(dcDoc.NameTable);
                dcNameSpaceManager.AddNamespace("dc", "http://purl.org/dc/elements/1.1/");
                dcNameSpaceManager.AddNamespace("oai_dc", "http://www.openarchives.org/OAI/2.0/oai_dc/");
                dcNameSpaceManager.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
            } catch (Exception ex) { throw new Exception("Datastreams METS e/ou DC inválidos para o objecto " + pid + ".", ex); }

            try {
                XmlNode structMap = metsDoc.SelectSingleNode("mets:mets/mets:structMap", nameSpaceManager);
                XmlNode mainDiv   = structMap.SelectSingleNode("mets:div", nameSpaceManager);
                XmlNode recordID  = metsDoc.SelectSingleNode("mets:mets/mets:metsHdr/mets:altRecordID", nameSpaceManager);

                string type;
                try { type = structMap.Attributes["TYPE"].Value.ToString().ToUpper(); } catch { type = "PHYSICAL"; }
                ObjDigital newDocumentType = null;
                if (type == "LOGICAL")
                {
                    newDocumentType             = new ObjDigComposto();
                    newDocumentType.state       = State.unchanged;
                    newDocumentType.serverState = GetState(pid);
                    ObjDigSimples[] parts = new ObjDigSimples[mainDiv.SelectNodes("mets:div", nameSpaceManager).Count];

                    foreach (XmlNode subDiv in mainDiv.SelectNodes("mets:div", nameSpaceManager))
                    {
                        // Ler objecto directamente
                        XmlNode       fptr       = subDiv.SelectSingleNode("mets:fptr", nameSpaceManager);
                        ObjDigSimples objSimples = GetStructureForPid(fptr.Attributes["FILEID"].Value, originalTimestamp, true) as ObjDigSimples;
                        parts[int.Parse(subDiv.Attributes["ORDER"].Value) - 1] = objSimples;
                    }

                    ((ObjDigComposto)newDocumentType).objSimples.AddRange(parts);
                }
                else
                {
                    newDocumentType             = new ObjDigSimples();
                    newDocumentType.state       = State.unchanged;
                    newDocumentType.serverState = GetState(pid);
                    Anexo[] parts = new Anexo[mainDiv.SelectNodes("mets:div", nameSpaceManager).Count];

                    foreach (XmlNode subDiv in mainDiv.SelectNodes("mets:div", nameSpaceManager))
                    {
                        XmlNode fptr  = subDiv.SelectSingleNode("mets:fptr", nameSpaceManager);
                        Anexo   anexo = new Anexo();

                        anexo.pid          = pid;
                        anexo.dataStreamID = fptr.Attributes["FILEID"].Value;
                        anexo.mimeType     = subDiv.Attributes["TYPE"].Value;
                        parts[int.Parse(subDiv.Attributes["ORDER"].Value) - 1] = anexo;

                        try
                        {
                            Datastream data = manager.getDatastream(pid, anexo.dataStreamID, null);
                            anexo.url      = data.location;
                            anexo.checksum = data.checksum;
                        }
                        catch (Exception ex) { Trace.WriteLine(ex.ToString()); throw new Exception("URL de datastream " + anexo.dataStreamID + " no objecto " + pid + " não foi encontrado.", ex); }
                    }

                    ((ObjDigSimples)newDocumentType).nextDatastreamId = service.listDatastreams(pid, null).Count(ds => ds.ID.Contains("IMG")) + 1;
                    ((ObjDigSimples)newDocumentType).fich_associados.AddRange(parts);

                    if (loadVersions)
                    {
                        ((ObjDigSimples)newDocumentType).historico.AddRange(GetHistoric(pid));
                    }
                }

                newDocumentType.pid     = pid;
                newDocumentType.version = versionTimestamp;
                newDocumentType.titulo  = mainDiv.Attributes["LABEL"].Value;
                if (mainDiv.Attributes["TYPE"] != null)
                {
                    newDocumentType.tipologia = mainDiv.Attributes["TYPE"].Value;
                }
                if (recordID != null)  // há objetos que não têm gisa_id
                {
                    newDocumentType.gisa_id = recordID.InnerText;
                }
                else
                {
                    newDocumentType.gisa_id = "";
                }

                XmlNodeList assuntos = dcDoc.SelectNodes("oai_dc:dc/dc:subject", dcNameSpaceManager);
                if (assuntos.Count > 0)
                {
                    List <string> listAssuntos = new List <string>();
                    foreach (XmlNode node in assuntos)
                    {
                        listAssuntos.Add(node.InnerText);
                    }
                    newDocumentType.assuntos = listAssuntos;
                }

                return(newDocumentType);
            }
            catch (Exception ex) { Trace.WriteLine(ex.ToString()); throw new Exception("Erro ao analisar objecto " + pid + ".", ex); }
        }
        private void CreateDatabaseObjDigSimplesSolto(ObjDigSimples odSimples)
        {
            Debug.Assert(odSimples.guiorder > 0);
            var odRow = GisaDataSetHelper.GetInstance().ObjetoDigital.AddObjetoDigitalRow(odSimples.pid, odSimples.titulo, odSimples.publicado, odSimples.guiorder, new byte[] { }, 0);
            //PermissoesHelper.AddNewObjDigGrantPermissions(odRow, currentNivel);

            FedoraHelper.RelateODtoUI(odSimples, odRow, currentNivel.GetFRDBaseRows().Single());

            newObjects.Add(odRow, odSimples);
        }
Example #17
0
        private void DoTheMETS(ObjDigital obj, string[] logMessage)
        {
            var idsGisa = new string[] { obj.gisa_id };
            var title   = obj.titulo;
            var type    = obj.tipologia;

            // Ficheiro METS
            mets = new MetsFile(null, null, title, type, null);

            // Header - criador, hora de criação, e IDs alternativos
            mets.header = new MetsHeaderSection(null, null, Utility.Now(), null, null);
            mets.header.AddAgent(new MetsAgent(null, MetsAgentRole.Archivist, null, MetsAgentType.Individual, null, userName, logMessage));
            foreach (string s in idsGisa.Where(id => id.Length > 0))
            {
                string typeID = s.Substring(0, s.IndexOf(':'));
                mets.header.AddAltID(new MetsAlternativeIdentifier(null, typeID, s));
            }

            // Criar a secção de Ficheiros
            mets.fileSection = new MetsFileSection(null);
            MetsFileGroup fileGrp = new MetsFileGroup(null, null, null, "Conteúdos");

            mets.fileSection.AddFileGroupElement(fileGrp);

            MetsStructMap      structa   = null;
            MetsStructDivision largeFile = null;

            if (obj.GetType() == typeof(ObjDigSimples))
            {
                ObjDigSimples objSimples = obj as ObjDigSimples;
                structa   = new MetsStructMap(null, "PHYSICAL", "Estruturação em imagens do " + title);
                largeFile = new MetsStructDivision(null, type, title, null, null, null, null, null, null);

                for (int i = 0; i < objSimples.fich_associados.Count; i++)
                {
                    Anexo ficheiro = objSimples.fich_associados[i];

                    if (ficheiro.dataStreamID == null)
                    {
                        ficheiro.dataStreamID = "IMG" + objSimples.nextDatastreamId;
                        objSimples.nextDatastreamId++;
                    }
                    string uName = ficheiro.dataStreamID;

                    MetsFileElement file = new MetsFileElement(uName, ficheiro.mimeType, (i + 1).ToString(), null, null, null, MetsChecksumType.NONE, null, null, null, null, null);
                    file.AddFLocat(new MetsXLinkElement(null, null, MetsLocatorType.Other, "Nome de Datastream", uName, null, null, null, null, null));
                    fileGrp.AddFileElement(file);

                    MetsStructDivision div = new MetsStructDivision(null, ficheiro.mimeType, title, null, null, (i + 1).ToString(), null, null, null);
                    div.AddFilePointer(new MetsFilePointer(null, uName, null));
                    largeFile.AddDivision(div);
                }
            }
            else
            {
                ObjDigComposto objComposto = obj as ObjDigComposto;
                structa   = new MetsStructMap(null, "LOGICAL", "Estruturação em partes do " + title);
                largeFile = new MetsStructDivision(null, type, title, null, null, null, null, null, null);
                foreach (ObjDigSimples sd in objComposto.objSimples)
                {
                    // Apenas queremos fazer isto se o objecto não estiver marcado como apagado
                    if (sd.state != State.deleted)
                    {
                        string             pid = sd.pid;
                        MetsStructDivision div = new MetsStructDivision(null, sd.tipologia, sd.titulo, null, null, (objComposto.objSimples.IndexOf(sd) + 1).ToString(), null, null, null);
                        div.AddFilePointer(new MetsFilePointer(null, pid, null));
                        largeFile.AddDivision(div);
                    }
                }
            }

            structa.AddDivision(largeFile);
            mets.AddStructMap(structa);
        }