Ejemplo n.º 1
0
        /// <summary>
        /// Helper method to get the identifier from merrit.
        /// </summary>
        /// <param name="postFileData"></param>
        /// <param name="authorization"></param>
        /// <returns></returns>
        protected string GetIdentifier(PublishMessage postFileData, string authorization, string identifierUrl, Citation citation)
        {
            Check.IsNotNull(postFileData, "postFileData");
            Check.IsNotNull(authorization, "authorization");
            Check.IsNotNull(identifierUrl, "identifierUrl");
            var file = this.GetFileByFileId(postFileData.FileId);

            MerritQueryData queryData = new MerritQueryData();

            queryData.KeyValuePair = new List<DKeyValuePair<string, string>>()
            {
                         new DKeyValuePair<string, string> { Key = "Profile", Value = "oneshare_ark_only" },
                         new DKeyValuePair<string, string> { Key = "Who", Value = citation.Publisher },
                         new DKeyValuePair<string, string> { Key = "What", Value = citation.Title},
                         new DKeyValuePair<string, string> { Key = "When", Value = DateTime.UtcNow.ToString(CultureInfo.InvariantCulture) }
            }.ToArray();

            RepositoryModel repositoryModel = new RepositoryModel()
            {
                Authorization = authorization,
                RepositoryLink = identifierUrl,
                RepositoryName = MerritConstants.OneShare
            };

            return this.RepositoryAdapter.GetIdentifier(queryData, repositoryModel);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Helper method to get the post query data.
        /// </summary>
        /// <param name="identifier">Unique identifier.</param>
        /// <param name="fileData">File information.</param>
        /// <param name="postFileData">Post file indormation.</param>
        /// <returns></returns>
        protected MerritQueryData GetPostQueryData(string identifier, DM.File fileData, Citation citation, Repository repository, PublishMessage postFileData)
        {
            Check.IsNotNull(identifier, "identifier");

            MerritQueryData queryData = new MerritQueryData();

            // TODO: Currently hard coded, needs to be replaced with specific value
            queryData.MetadataXML = @"<eml:eml packageId=""doi:10.5072/12345?"" system=""DCXL"" xmlns:eml=""eml://ecoinformatics.org/eml2.1.0"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xsi:schemaLocation=""eml://ecoinformatics.org/eml-2.1.0 eml.xsd"">    <dataset id=""doi:10.5072/12345"">        <creator>            <!-- http://knb.ecoinformatics.org/software/eml/eml-2.1.0/eml-resource.html#creator -->            <!-- multiple creators allowed -->            <individualName>                <givenName></givenName>                <surName></surName>            </individualName>            <address>                <deliveryPoint></deliveryPoint>                <city></city>                <administrativeArea></administrativeArea><postalCode></postalCode><country></country></address><phone></phone><electronicMailAddress></electronicMailAddress><organizationName></organizationName></creator><title></title><pubDate></pubDate><abstract><para></para></abstract><publisher><para></para></publisher><url></url><contact><individualName><givenName></givenName><surName></surName></individualName><address><deliveryPoint></deliveryPoint><city></city><administrativeArea></administrativeArea><postalCode></postalCode><country></country></address><phone></phone><electronicMailAddress></electronicMailAddress><organizationName></organizationName></contact><keywordSet><keyword></keyword><keywordThesaurus></keywordThesaurus></keywordSet><coverage><!-- http://knb.ecoinformatics.org/software/eml/eml-2.1.0/eml-resource.html#coverage -->  <geographicCoverage><geographicDescription></geographicDescription><boundingCoordinates><westBoundingCoordinate></westBoundingCoordinate><eastBoundingCoordinate></eastBoundingCoordinate><northBoundingCoordinate></northBoundingCoordinate><southBoundingCoordinate></southBoundingCoordinate></boundingCoordinates></geographicCoverage><temporalCoverage id=""tempcov""><rangeOfDates> <beginDate><calendarDate></calendarDate></beginDate><endDate><calendarDate></calendarDate></endDate></rangeOfDates></temporalCoverage></coverage><project><!-- http://knb.ecoinformatics.org/software/eml/eml-2.1.0/eml-dataset.html#project --><title></title><abstract><para></para></abstract><funding><para></para></funding></project>        <intellectualRights>            <para></para>        </intellectualRights>        <dataTable>            <!-- http://knb.ecoinformatics.org/software/eml/eml-2.1.0/eml-dataTable.html#dataTable -->            <!-- dataTable is equivalent to a single tab in the excel spreadsheet.         One can have multiple data tables within the document. -->            <entityName></entityName>            <entityDescription></entityDescription>            <attributeList>                <!-- http://knb.ecoinformatics.org/software/eml/eml-2.1.0/eml-dataTable.html#attributeList -->                <!-- attribute list is equivalent to the parameter table from the requirements document.         One can have many attributes in a single table. -->                <attribute>                    <attributeName>                        <!-- non-empty string --></attributeName>                    <attributeDefinition>                        <!-- non-empty string --></attributeDefinition>                </attribute>            </attributeList>        </dataTable>    </dataset>    <additionalMetadata>        <describes>tempcov</describes>        <metadata>            <description>                <!-- non-empty string describing temporal coverage -->            </description>        </metadata>    </additionalMetadata>    <additionalMetadata>        <metadata>            <formattedCitation>                <!-- non-empty string -->            </formattedCitation>        </metadata>    </additionalMetadata></eml:eml>";

            List<DKeyValuePair<string, string>> content = new List<DKeyValuePair<string, string>>();

            Check.IsNotNull<DM.Repository>(repository, "selectedRepository");

            var repositoryMetadata = repository.RepositoryMetadata.FirstOrDefault();
            if (repositoryMetadata != null)
            {
                foreach (var repositoryMetaData in repositoryMetadata.RepositoryMetadataFields)
                {
                    DKeyValuePair<string, string> metadata = new DKeyValuePair<string, string>();
                    metadata.Key = repositoryMetaData.Name;
                    var metadataField = fileData.FileMetadataFields.Where(f => f.RepositoryMetadataFieldId == repositoryMetaData.RepositoryMetadataFieldId).FirstOrDefault();

                    if (metadataField != null)
                    {
                        metadata.Value = fileData.FileMetadataFields.Where(f => f.RepositoryMetadataFieldId == repositoryMetaData.RepositoryMetadataFieldId).FirstOrDefault().MetadataValue;
                    }

                    content.Add(metadata);
                }
            }

            //set the data to filemetadata fields
            //postFileData.FileMetaDataFields = fileData.FileMetadataFields;

            content.Add(new DKeyValuePair<string, string>() { Key = "Profile", Value = ConfigReader<string>.GetSetting("Profile_Post") });
            content.Add(new DKeyValuePair<string, string>() { Key = "who", Value = citation.Publisher });
            content.Add(new DKeyValuePair<string, string>() { Key = "what", Value = citation.Title });
            content.Add(new DKeyValuePair<string, string>() { Key = "when", Value = DateTime.UtcNow.ToString(CultureInfo.InvariantCulture) });
            content.Add(new DKeyValuePair<string, string>() { Key = "where", Value = identifier });
            content.Add(new DKeyValuePair<string, string>() { Key = "ARK", Value = identifier });

            queryData.KeyValuePair = content.ToArray();

            return queryData;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Method to publish file
        /// </summary>
        /// <param name="postFileData">PublishMessage object</param>
        /// <returns>returns File Identifier</returns>
        public override string PublishFile(PublishMessage postFileData)
        {
            var file = this.GetFileByFileId(postFileData.FileId);
            IEnumerable<DM.FileColumnType> fileColumnTypes = null;
            IEnumerable<DM.FileColumnUnit> fileColumnUnits = null;
            OperationStatus status = null;

            Encoding encoding = Encoding.UTF8;
            string identifier = string.Empty;

            var repository = this.RepositoryService.GetRepositoryById(postFileData.RepositoryId);

            // TODO: Needs to check Filling repository credintials in case of system provided repository type
            if (repository.BaseRepositoryId == Constants.MerritRepositoryTypeID && repository.IsImpersonating == true)
            {
                postFileData.UserName = repository.ImpersonatingUserName;
                postFileData.Password = repository.ImpersonatingPassword;
            }

            string authorization = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(postFileData.UserName /*UserName*/ + ":" + postFileData.Password /*Password*/));

            string baseRepoName = this.RepositoryDetails.GetBaseRepositoryName(repository.BaseRepositoryId);
            this.RepositoryAdapter = new MerritAdapter();

            // This is a temporary fix to initialize citation for
            // Merritt repository.
            // TBD: move this to the base class
            Citation citation = default(Citation);
            if (string.IsNullOrWhiteSpace(file.Citation))
            {
                User user = this.userService.GetUserById(postFileData.UserId);
                citation = new Citation();
                citation.Title = Path.GetFileNameWithoutExtension(file.Name);
                citation.Publisher = string.Join(",", user.LastName, user.FirstName);
            }
            else
            {
                citation = JsonConvert.DeserializeObject<Citation>(file.Citation);
            }

            identifier = this.GetIdentifier(postFileData, authorization, repository.HttpIdentifierUriTemplate, citation);

            if (identifier.StartsWith("true"))
            {
                identifier = identifier.Substring(identifier.IndexOf("ark:", StringComparison.Ordinal)).Trim();

                var postQueryData = GetPostQueryData(identifier, file, citation, repository, postFileData);
                var dataFile = this.GetDataFile(file);
                var repositoryModel = GetRepositoryModel(repository, authorization);

                if (file.FileColumns != null && file.FileColumns.Count > 0)
                {
                    // before posting the file set file column units and types
                    fileColumnTypes = this.RetrieveFileColumnTypes();
                    fileColumnUnits = this.RetrieveFileColumnUnits();
                }

                PublishMerritFileModel publishMerritFileModel = new PublishMerritFileModel()
                {
                    File = dataFile,
                    RepositoryModel = repositoryModel,
                    FileColumnTypes = fileColumnTypes,
                    FileColumnUnits = fileColumnUnits,
                    MerritQueryData = postQueryData
                };

                //post the file
                status = this.RepositoryAdapter.PostFile(publishMerritFileModel);
            }
            else
            {
                string message = identifier.Replace("false|", "");

                // Todo need to throw a custom exception
                throw new SystemException(message);
            }

            return identifier;
        }
Ejemplo n.º 4
0
        public HttpResponseMessage SaveCitation(int fileId, Citation citation)
        {
            HttpResponseMessage httpResponseMessage;

            try
            {
                Check.IsNotNull(citation, "citation");

                DM.File file = this.fileService.GetFileByFileId(fileId);
                if (null == file)
                {
                    diagnostics.WriteErrorTrace(TraceEventId.Exception, "File is null");
                    return Request.CreateErrorResponse(HttpStatusCode.NotFound, MessageStrings.Invalid_File_Id);
                }

                file.Citation = JsonConvert.SerializeObject(citation);
                file.ModifiedOn = DateTime.UtcNow;
                fileService.UpdateFile(file);
                httpResponseMessage = Request.CreateResponse(HttpStatusCode.OK, true);
            }
            catch (ArgumentException ex)
            {
                diagnostics.WriteErrorTrace(TraceEventId.Exception, ex);
                message = string.Format(CultureInfo.CurrentCulture, MessageStrings.Argument_Error_Message_Template, ex.ParamName);
                httpResponseMessage = Request.CreateErrorResponse(HttpStatusCode.BadRequest, message);
            }

            return httpResponseMessage;
        }
Ejemplo n.º 5
0
        public HttpResponseMessage GetCitation(int fileId, int repositoryId)
        {
            DM.File file = fileService.GetFileByFileId(fileId);
            if (file == null)
            {
                return Request.CreateErrorResponse(HttpStatusCode.NotFound, MessageStrings.FileNotFound);
            }

            DM.Repository repository = this.repositoryService.GetRepositoryById(repositoryId);
            if (repository == null)
            {
                return Request.CreateErrorResponse(HttpStatusCode.NotFound, MessageStrings.Repository_Not_Found);
            }
            else if (repository.BaseRepository.BaseRepositoryId != 1)
            {
                return Request.CreateErrorResponse(HttpStatusCode.NotImplemented, string.Format(MessageStrings.CitationNotSupportedMessage, repository.BaseRepository.Name));
            }

            Citation citation = new Citation()
            {
                PublicationYear = DateTime.Now.Year.ToString(),
                Title = file.Title,
                Publisher = string.Concat(this.user.LastName, ", ", this.user.FirstName)
            };
            if (!string.IsNullOrWhiteSpace(file.Citation))
            {
                citation = JsonConvert.DeserializeObject<Citation>(file.Citation);
            }

            return Request.CreateResponse(HttpStatusCode.OK, citation);
        }
Ejemplo n.º 6
0
        public HttpResponseMessage GetFiles(int id)
        {
            // Check if the model binding was successful and is in a valid state
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, string.Empty);
            }

            try
            {
                // Check if the file service is valid
                Check.IsNotNull(this.fileService, "fileService");

                IEnumerable<DM.File> filesList = this.fileService.GetAllFiles(this.user.UserId);
                foreach (DM.File file in filesList)
                {
                    if (file.Status.Equals(FileStatus.Posted.ToString(), StringComparison.OrdinalIgnoreCase))
                    {
                        Citation citation = new Citation();
                        if (!string.IsNullOrWhiteSpace(file.Citation))
                        {
                            citation = JsonConvert.DeserializeObject<Citation>(file.Citation);
                        }

                        file.Citation = string.Format(Constants.CitationStringFormat, citation.Publisher ?? string.Empty, citation.PublicationYear ?? string.Empty, citation.Title ?? string.Empty, citation.Version ?? string.Empty, file.Identifier ?? string.Empty);
                    }
                }

                return Request.CreateResponse<IEnumerable<DM.File>>(status, filesList);
            }
            catch (ArgumentNullException ane)
            {
                if (ane.ParamName.Equals("fileService"))
                {
                    message = MessageStrings.File_Service_Is_Null;
                    status = HttpStatusCode.InternalServerError;
                }
                message = MessageStrings.Invalid_File_Id;
                status = HttpStatusCode.BadRequest;
            }
            catch (Exception ex)
            {
                message = ex.Message + ex.StackTrace + ex.GetType().ToString();
                if (null != ex.InnerException)
                {
                    message += ex.InnerException.Message + ex.InnerException.StackTrace + ex.InnerException.GetType().ToString();
                }
                status = HttpStatusCode.InternalServerError;
            }

            return Request.CreateErrorResponse(status, message);
        }