Esempio n. 1
0
        /*
         * Below are all helper functions used for the generic Test function.
         * Possibly refactor these into each Noun.
         *
         */
        // CopyrightHolder Generics
        CopyrightHolder SetupCopyrightHolder()
        {
            CopyrightHolder item = new CopyrightHolder();

            item.Name = "RESTClient Test CopyrightHolder";
            return(item);
        }
        // Creates a Copyright Holder
        public CopyrightHolder CreateCopyrightHolder(int copyrightPolicyId)
        {
            Console.Write("Creating Copyright Holder: ");
            CopyrightHolder copyrightHolderItem = new CopyrightHolder();

            copyrightHolderItem.Name = this.test_id;
            copyrightHolderItem.CopyrightPolicyId = copyrightPolicyId;
            CopyrightHolder resp = this.conn.SendObject <CopyrightHolder>(copyrightHolderItem, true);

            Console.WriteLine(resp.Id);
            return(resp);
        }
Esempio n. 3
0
 bool CompareCopyrightHolder(CopyrightHolder first, CopyrightHolder second)
 {
     if (first.Id != second.Id)
     {
         return(false);
     }
     if (first.Name != second.Name)
     {
         return(false);
     }
     return(true);
 }
        // Initiates the test
        public void init()
        {
            Category projectCategory = GetProjectCategoryId();

            ProjectKeywordCategory projectKeywordCategory = CreateProjectKeywordCategory();
            ProjectKeyword         projectKeyword         = CreateProjectKeyword(projectKeywordCategory.Id);

            Field projectField = CreateField("project");
            Field imageField   = CreateField("image");

            Project project = CreateProject(projectKeyword, projectField);

            KeywordCategory keywordCategory = CreateKeywordCategory(projectCategory.Id);
            Keyword         keyword         = CreateKeyword(keywordCategory.Id);

            Photographer photographer = CreatePhotographer();
            AccessLevel  accessLevel  = GetRandomAccessLevel();

            CopyrightPolicy copyrightPolicy = CreateCopyrightPolicy();
            CopyrightHolder copyrightHolder = CreateCopyrightHolder(copyrightPolicy.Id);

            File file = UploadFile(projectCategory, project, imageField, keyword, photographer, accessLevel, copyrightHolder);

            Album album       = CreateAlbum(file);
            bool  isHeroImage = AttachHeroImage(file, project);

            List <Search> searches = CreateSearches(file, keywordCategory, keyword, imageField, photographer, copyrightHolder, accessLevel, project, album);

            if (VerifySearches(searches, file))
            {
                BaseNoun[] nouns;
                if (superUser)
                {
                    nouns = new BaseNoun[] { file, photographer, copyrightHolder, copyrightPolicy, album, keyword, keywordCategory, imageField, projectField, projectKeyword, projectKeywordCategory, project };
                }
                else
                {
                    nouns = new BaseNoun[] { file, album, keyword, keywordCategory, imageField, projectField, projectKeyword, projectKeywordCategory, project };
                }

                if (this.deleteObjects)
                {
                    DeleteNouns(nouns);
                }
            }
        }
 /// <summary>
 /// Validate the object.
 /// </summary>
 /// <exception cref="Rest.ValidationException">
 /// Thrown if validation fails
 /// </exception>
 public override void Validate()
 {
     base.Validate();
     if (About != null)
     {
         foreach (var element in About)
         {
             if (element != null)
             {
                 element.Validate();
             }
         }
     }
     if (Mentions != null)
     {
         foreach (var element1 in Mentions)
         {
             if (element1 != null)
             {
                 element1.Validate();
             }
         }
     }
     if (Provider != null)
     {
         foreach (var element2 in Provider)
         {
             if (element2 != null)
             {
                 element2.Validate();
             }
         }
     }
     if (Creator != null)
     {
         Creator.Validate();
     }
     if (MainEntity != null)
     {
         MainEntity.Validate();
     }
     if (CopyrightHolder != null)
     {
         CopyrightHolder.Validate();
     }
 }
        // Creates a list of Search objects to verify insertions
        public List <Search> CreateSearches(File file, KeywordCategory keywordCategory, Keyword keyword, Field field, Photographer photographer, CopyrightHolder copyrightHolder, AccessLevel accessLevel,
                                            Project project, Album album)
        {
            Console.WriteLine("Creating Searches");
            Search        search;
            SearchItem    searchItems;
            List <Search> searchList = new List <Search>();

            search              = new Search();
            searchItems         = new SearchItem();
            search.Saved        = false;
            search.Name         = this.test_id + "_Test_Search_Filename";
            searchItems.Code    = "filename";
            searchItems.Exclude = false;
            searchItems.Values.Add(file.Filename);
            search.SearchItems.Add(searchItems);
            searchList.Add(search);

            search              = new Search();
            searchItems         = new SearchItem();
            search.Saved        = false;
            search.Name         = this.test_id + "_Test_Search_Original_Filename";
            searchItems.Code    = "originalFilename";
            searchItems.Exclude = false;
            searchItems.Values  = new List <String>();
            searchItems.Values.Add(file.OriginalFilename);
            search.SearchItems.Add(searchItems);
            searchList.Add(search);

            search              = new Search();
            searchItems         = new SearchItem();
            search.Saved        = false;
            search.Name         = this.test_id + "_Test_Search_Caption";
            searchItems.Code    = "caption";
            searchItems.Exclude = false;
            searchItems.Values  = new List <String>();
            searchItems.Values.Add(file.Caption);
            search.SearchItems.Add(searchItems);
            searchList.Add(search);

            search              = new Search();
            searchItems         = new SearchItem();
            search.Saved        = false;
            search.Name         = this.test_id + "_Test_Search_Description";
            searchItems.Code    = "description";
            searchItems.Exclude = false;
            searchItems.Values  = new List <String>();
            searchItems.Values.Add(file.Description);
            search.SearchItems.Add(searchItems);
            searchList.Add(search);

            search              = new Search();
            searchItems         = new SearchItem();
            search.Saved        = false;
            search.Name         = this.test_id + "_Test_Search_Photographer";
            searchItems.Code    = "photographer";
            searchItems.Exclude = false;
            searchItems.Ids     = new List <int>();
            searchItems.Ids.Add(photographer.Id);
            search.SearchItems.Add(searchItems);
            searchList.Add(search);

            search              = new Search();
            searchItems         = new SearchItem();
            search.Saved        = false;
            search.Name         = this.test_id + "_Test_Search_Keyword";
            searchItems.Code    = "keyword." + keywordCategory.Id;
            searchItems.Exclude = false;
            searchItems.Ids     = new List <int>();
            searchItems.Ids.Add(keyword.Id);
            search.SearchItems.Add(searchItems);
            searchList.Add(search);

            search              = new Search();
            searchItems         = new SearchItem();
            search.Saved        = false;
            search.Name         = this.test_id + "_Test_Search_Project";
            searchItems.Code    = "project";
            searchItems.Exclude = false;
            searchItems.Ids     = new List <int>();
            searchItems.Ids.Add(project.Id);
            search.SearchItems.Add(searchItems);
            searchList.Add(search);

            search              = new Search();
            searchItems         = new SearchItem();
            search.Saved        = false;
            search.Name         = this.test_id + "_Test_Search_Album";
            searchItems.Code    = "album";
            searchItems.Exclude = false;
            searchItems.Ids     = new List <int>();
            searchItems.Ids.Add(album.Id);
            search.SearchItems.Add(searchItems);
            searchList.Add(search);

            search              = new Search();
            searchItems         = new SearchItem();
            search.Saved        = false;
            search.Name         = this.test_id + "_Test_Search_CopyrightHolder";
            searchItems.Code    = "copyrightHolder";
            searchItems.Exclude = false;
            searchItems.Ids     = new List <int>();
            searchItems.Ids.Add(copyrightHolder.Id);
            search.SearchItems.Add(searchItems);
            searchList.Add(search);

            search              = new Search();
            searchItems         = new SearchItem();
            search.Saved        = false;
            search.Name         = this.test_id + "_Test_Search_Field";
            searchItems.Code    = "field." + field.Id;
            searchItems.Exclude = false;
            searchItems.Values  = field.Values;
            search.SearchItems.Add(searchItems);
            searchList.Add(search);

            return(searchList);
        }
        // Generates and uploads a File to OpenAsset, along with tagging it's field, keyword, photographer, access level, and copyright holder
        public File UploadFile(Category category, Project project, Field field, Keyword keyword, Photographer photographer, AccessLevel accessLevel, CopyrightHolder copyrightHolder)
        {
            string filename = this.test_id;
            string filepath = GenerateImage(filename);

            List <Keyword> keywordList = new List <Keyword>();

            keywordList.Add(keyword);

            List <Field> fieldList = new List <Field>();

            fieldList.Add(field);

            Console.Write("Uploading File: ");
            File fileItem = new File();

            fileItem.Filename         = filepath;
            fileItem.OriginalFilename = filename + ".png";

            fileItem.Caption     = this.test_id + "_Test_Caption";
            fileItem.Description = this.test_id + "_Test_Description";

            fileItem.CategoryId = category.Id;
            fileItem.ProjectId  = project.Id;

            fileItem.Fields   = fieldList;
            fileItem.Keywords = keywordList;

            fileItem.CopyrightHolderId = copyrightHolder.Id;
            fileItem.PhotographerId    = photographer.Id;

            fileItem.AccessLevel = accessLevel.Id;
            fileItem.Rank        = 1;

            File resp = this.conn.SendObject <File>(fileItem, filepath, true);

            Console.WriteLine(resp.Id);
            DeleteImageFile(filepath);
            return(resp);
        }
Esempio n. 8
0
 CopyrightHolder ModifyCopyrightHolder(CopyrightHolder item)
 {
     item.Name = "RESTClient Test CopyrightHolder - PUT Test #" + Guid.NewGuid().ToString();
     return(item);
 }
Esempio n. 9
0
        /// <summary>
        /// This examples creates a NewsML-G2 News Item as shown in the QuickStart NewsML-G2 Text
        /// document in this package http://www.iptc.org/std/NewsML-G2/2.15/documentation/IPTC-NewsML-G2-QuickStartGuides_2014.zip
        /// </summary>
        private void GenerateQuickStartTextExample1()
        // Code History:
        // 2014-03-03 mws
        {
            // variables global only to this method
            XmlNode foundNode = null;

            // *** create an object for the NewsML-G2 News Item
            var g2NI = new NewsItemPwrXml();

            // * add the GUID and the version number to it
            g2NI.InitEmptyXMLDoc("urn:newsml:acmenews.com:20131121:US-FINANCE-FED", 3);
            g2NI.SetRootXmlLang("en-US");

            // * add the catalogRefs to it
            g2NI.AddCatalogRef("http://www.iptc.org/std/catalog/catalog.IPTC-G2-Standards_22.xml");
            g2NI.AddCatalogRef("http://catalog.acmenews.com/news/ANM_G2_CODES_2.xml");

            // ** add a rightsInfo element as wrapper of properties
            g2NI.CheckAddNarWrapper1(NarDocXml.PropsWrapping1.RightsInfo);

            // ** add a copyrightHolder
            // * create a plain object for the copyrightHolder property
            var copyrightHolder = new CopyrightHolder();
            // * create a placeholder for the copyrightHolder element
            XmlElement copyrightHolderXe = null;

            // * add the copyrightHolder property to the rightsInfo wrapper and get the new XML element returned
            g2NI.AddNarPropertyToWrapper1(NarDocXml.PropsWrapping1.RightsInfo, copyrightHolder, out copyrightHolderXe);
            // * create a structured object for the copyrightHolder element
            var copyrightHolderSe = new ConceptStructProp()
            {
                Uri = "http://www.acmenews.com/about.html#copyright"
            };
            // * property with a value in the text node
            var crName = new Name("Acme News and Media LLC");

            copyrightHolderSe.Names.Add(crName);
            // * apply this structure to the already created copyrightHolder element
            copyrightHolderSe.ApplyToElement(g2NI, copyrightHolderXe);
            // * property with a value in the text node
            var copyrightNotice = new CopyrightNotice("(c) 2013 Copyright Acme News and Media LLC");

            g2NI.AddNarPropertyToWrapper1(NarDocXml.PropsWrapping1.RightsInfo, copyrightNotice);

            // ** add an itemMeta element as wrapper of properties
            g2NI.CheckAddNarWrapper1(NarDocXml.PropsWrapping1.ItemMeta);

            // ** add a sequence of properties as children of itemMeta
            // * property using the qcode attribute
            var itemClass = new ItemClass {
                qcode = "ninat:text"
            };

            g2NI.AddNarPropertyToWrapper1(NarDocXml.PropsWrapping1.ItemMeta, itemClass);
            // * property using the uri attribute
            var provider = new Provider {
                uri = "http://www.acmenews.com/about/"
            };

            g2NI.AddNarPropertyToWrapper1(NarDocXml.PropsWrapping1.ItemMeta, provider);
            var versionCreated = new VersionCreated("2013-11-21T16:25:32-05:00");

            g2NI.AddNarPropertyToWrapper1(NarDocXml.PropsWrapping1.ItemMeta, versionCreated);
            var embargoed = new Embargoed("2013-11-26T12:00:00-05:00");

            g2NI.AddNarPropertyToWrapper1(NarDocXml.PropsWrapping1.ItemMeta, embargoed);
            var pubStatus = new PubStatus {
                qcode = "stat:usable"
            };

            g2NI.AddNarPropertyToWrapper1(NarDocXml.PropsWrapping1.ItemMeta, pubStatus);


            // ** add a contentMeta element as wrapper of properties
            g2NI.CheckAddNarWrapper1(NarDocXml.PropsWrapping1.ContentMeta);

            // ** add a sequence of properties as children of itemMeta
            var contentCreated = new ContentCreated("2013-11-21T15:21:06-05:00");

            g2NI.AddNarPropertyToWrapper1(NarDocXml.PropsWrapping1.ContentMeta, contentCreated);

            var contentModified = new ContentModified("2013-11-21T16:22:45-05:00");

            g2NI.AddNarPropertyToWrapper1(NarDocXml.PropsWrapping1.ContentMeta, contentModified);

            // * a structured property
            var located = new Located {
                qcode = "geoloc:NYC"
            };
            XmlElement locatedXe = null;

            g2NI.AddNarPropertyToWrapper1(NarDocXml.PropsWrapping1.ContentMeta, located, out locatedXe);
            var locatedSe = new ConceptStructProp();

            locatedSe.Names.Add(new Name("New York, NY"));
            locatedSe.ApplyToElement(g2NI, locatedXe);

            var creator = new Creator {
                uri = "http://www.acmenews.com/staff/mjameson"
            };
            XmlElement creatorXe = null;

            g2NI.AddNarPropertyToWrapper1(NarDocXml.PropsWrapping1.ContentMeta, creator, out creatorXe);
            var creatorSe = new ConceptStructProp();

            creatorSe.Names.Add(new Name("Meredith Jameson"));
            creatorSe.ApplyToElement(g2NI, creatorXe);

            var infoSource = new InfoSource {
                qcode = "is:AP"
            };
            XmlElement infoSourceXe = null;

            g2NI.AddNarPropertyToWrapper1(NarDocXml.PropsWrapping1.ContentMeta, infoSource, out infoSourceXe);
            var infoSourceSe = new ConceptStructProp();

            infoSourceSe.Names.Add(new Name("Associated Press"));
            infoSourceSe.ApplyToElement(g2NI, infoSourceXe);

            var language = new Language {
                tag = "en-US"
            };

            g2NI.AddNarPropertyToWrapper1(NarDocXml.PropsWrapping1.ContentMeta, language);

            var subject = new Subject {
                qcode = "medtop:04000000"
            };
            XmlElement subjectXe = null;

            g2NI.AddNarPropertyToWrapper1(NarDocXml.PropsWrapping1.ContentMeta, subject, out subjectXe);
            var subjectSe = new ConceptStructProp();

            subjectSe.Names.Add(new Name("economy, business and finance"));
            subjectSe.ApplyToElement(g2NI, subjectXe);

            // * note: as this is another subject the type definitions of the variables have been removed
            subject = new Subject {
                qcode = "medtop:20000350"
            };
            subjectXe = null;
            g2NI.AddNarPropertyToWrapper1(NarDocXml.PropsWrapping1.ContentMeta, subject, out subjectXe);
            subjectSe = new ConceptStructProp();
            subjectSe.Names.Add(new Name("central bank"));
            subjectSe.ApplyToElement(g2NI, subjectXe);

            subject = new Subject {
                qcode = "medtop:20000379"
            };
            subjectXe = null;
            g2NI.AddNarPropertyToWrapper1(NarDocXml.PropsWrapping1.ContentMeta, subject, out subjectXe);
            subjectSe = new ConceptStructProp();
            subjectSe.Names.Add(new Name("money and monetary policy"));
            subjectSe.ApplyToElement(g2NI, subjectXe);

            var slugline = new Slugline("US-Finance-Fed");

            g2NI.AddNarPropertyToWrapper1(NarDocXml.PropsWrapping1.ContentMeta, slugline);

            var headline = new Headline("Fed to halt QE to avert \"bubble\"");

            g2NI.AddNarPropertyToWrapper1(NarDocXml.PropsWrapping1.ContentMeta, headline);

            // ** add a contentMeta element as wrapper of properties representing the content of the News Item
            g2NI.CheckAddNarWrapper1(NarDocXml.PropsWrapping1.ContentSet);

            // ** an inlineXML holds any kind of XML - in its own namespace.
            var        inlineXML   = new InlineXML();
            XmlElement inlineXmlXe = null;

            g2NI.AddNarPropertyToWrapper1(NarDocXml.PropsWrapping1.ContentSet, inlineXML, out inlineXmlXe);
            // * the XML content of inlineXML goes into the inner XML of the element
            inlineXmlXe.InnerXml =
                "<nitf xmlns='http://iptc.org/std/NITF/2006-10-18/'> <body> <body.head> <hedline> <hl1>Fed to halt QE to avert \"bubble\"</hl1> </hedline> <byline>By Meredith Jameson, <byttl>Staff Reporter</byttl> </byline> </body.head> <body.content> <p>(New York, NY - November 21) Et, sent luptat luptat, commy Nim zzriureet vendreetue modo dolenis ex euisis nosto et lan ullandit lum doloreet vulla. </p> <p>Ugiating ea feugait utat, venim velent nim quis nulluptat num Volorem inci enim dolobor eetuer sendre ercin utpatio dolorpercing. </p> </body.content> </body> </nitf>";
            g2NI.AddNarPropertyToWrapper1(NarDocXml.PropsWrapping1.ContentSet, inlineXML);

            // *** all metadata properties and elements providing the news content have been added

            // *** Save the serialized XML document
            g2NI.SaveToFile("QS-Text_1.0-ExampleFull1-generated.xml", true);
            qsTextEx1Lbl.Text = "Example News Item created.";
        } // GenerateQuickStartTextExample1