~ifolder-dev/simias/trunk-packaging

« back to all changes in this revision

Viewing changes to src/core/NU-Tags/.svn/text-base/Query.cs.svn-base

  • Committer: Jorge O. Castro
  • Date: 2007-12-03 06:56:46 UTC
  • Revision ID: jorge@ubuntu.com-20071203065646-mupcnjcwgm5mnhyt
* Remove a bunch of .svn directories we no longer need.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/****************************************************************************
2
 
 |
3
 
 | Copyright (c) 2007 Novell, Inc.
4
 
 | All Rights Reserved.
5
 
 |
6
 
 | This program is free software; you can redistribute it and/or
7
 
 | modify it under the terms of version 2 of the GNU General Public License as
8
 
 | published by the Free Software Foundation.
9
 
 |
10
 
 | This program is distributed in the hope that it will be useful,
11
 
 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 | GNU General Public License for more details.
14
 
 |
15
 
 | You should have received a copy of the GNU General Public License
16
 
 | along with this program; if not, contact Novell, Inc.
17
 
 |
18
 
 | To contact Novell about this file by physical or electronic mail,
19
 
 | you may find current contact information at www.novell.com 
20
 
 |
21
 
 |   Author: Brady Anderson <banderso@novell.com>
22
 
 |***************************************************************************/
23
 
 
24
 
using System;
25
 
using System.Collections;
26
 
 
27
 
using Simias;
28
 
using Simias.Client;
29
 
using Simias.Storage;
30
 
 
31
 
namespace Simias.Tags
32
 
{
33
 
        /// <summary>
34
 
        /// Class used for querying nodes that contain that
35
 
        /// specified tag(s)
36
 
        /// </summary>
37
 
        public class Query
38
 
        {
39
 
                private ArrayList tagList;
40
 
                private Collection collection;
41
 
 
42
 
                #region Constructors
43
 
                /// <summary>
44
 
                /// Constructor will throw an exception if the collection does not exist
45
 
                /// </summary>
46
 
                public Query( string collectionID )
47
 
                {
48
 
                        collection = Store.GetStore().GetCollectionByID( collectionID );
49
 
                        if ( collection == null )
50
 
                        {
51
 
                                throw new SimiasException( "Specified Collection does not exist" );
52
 
                        }
53
 
 
54
 
                        tagList = new ArrayList();
55
 
                }
56
 
 
57
 
                /// <summary>
58
 
                /// Constructor will throw an exception if the collection does not exist
59
 
                /// </summary>
60
 
                public Query( string collectionID, Tag tag )
61
 
                {
62
 
                        collection = Store.GetStore().GetCollectionByID( collectionID );
63
 
                        if ( collection == null )
64
 
                        {
65
 
                                throw new SimiasException( "Specified Collection does not exist" );
66
 
                        }
67
 
 
68
 
                        tagList = new ArrayList();
69
 
                        tagList.Add( tag );
70
 
                }
71
 
                #endregion
72
 
 
73
 
                public bool AddTag( Tag searchTag )
74
 
                {
75
 
                        tagList.Add( searchTag );
76
 
                        return true;
77
 
                }
78
 
 
79
 
                /// <summary>
80
 
                /// Query for all nodes that contain the tag(s) setup in this
81
 
                /// query object.
82
 
                /// </summary>
83
 
                /// <returns>An ICSList object containing the ShallowNode objects for the search results</returns>
84
 
                public ICSList QueryNodes()
85
 
                {
86
 
                        ICSList returnedResults = null;
87
 
                        Property p;
88
 
 
89
 
                        if ( tagList.Count == 1 )
90
 
                        {
91
 
                                Tag tag = tagList[0] as Tag;
92
 
                                Relationship relationshipTag = new Relationship( collection.ID, tag.ID );
93
 
                                p = new Property( "Tag", relationshipTag );
94
 
                                returnedResults = collection.Search( p, SearchOp.Equal );
95
 
                        }
96
 
                        else
97
 
                        if ( tagList.Count > 1 )
98
 
                        {
99
 
                                ICSList queryResults;
100
 
                                Hashtable hashedList = new Hashtable();
101
 
                                foreach( Tag tag in tagList )
102
 
                                {
103
 
                                        Relationship relationshipTag = new Relationship( collection.ID, tag.ID );
104
 
                                        p = new Property( "Tag", relationshipTag );
105
 
                                        queryResults = collection.Search( p, SearchOp.Equal );
106
 
 
107
 
                                        foreach( ShallowNode sn in queryResults )
108
 
                                        {
109
 
                                                if ( hashedList.ContainsKey( sn.ID ) == false )
110
 
                                                {
111
 
                                                        hashedList.Add( sn.ID, sn );
112
 
                                                }
113
 
                                        }
114
 
                                }
115
 
 
116
 
                                if ( hashedList.Count > 0 )
117
 
                                {
118
 
                                        returnedResults = new ICSList();
119
 
                                        foreach( ShallowNode sn in hashedList.Values )
120
 
                                        {
121
 
                                                returnedResults.Add( sn );
122
 
                                        }
123
 
                                }
124
 
                        }
125
 
                        
126
 
                        return returnedResults;
127
 
                }
128
 
 
129
 
                /// <summary>
130
 
                /// Query for all nodes that contain the tag(s) setup in this
131
 
                /// query object.
132
 
                /// </summary>
133
 
                /// <returns>An ICSList object containing the ShallowNode objects for the search results
134
 
                static public ICSList Nodes( string collectionID, Tag searchTag )
135
 
                {
136
 
                        ICSList queryResult = null;
137
 
                        Collection collection = Store.GetStore().GetCollectionByID( collectionID );
138
 
                        if ( collection != null )
139
 
                        {
140
 
                                Relationship relationshipTag = 
141
 
                                        new Relationship( collection.ID, searchTag.ID );
142
 
                                Property p = new Property( "Tag", relationshipTag );
143
 
                                queryResult = collection.Search( p, SearchOp.Equal );
144
 
                        }
145
 
                        
146
 
                        return queryResult;
147
 
                }
148
 
 
149
 
                /// <summary>
150
 
                /// Query for all tags that exist in the collection.
151
 
                /// </summary>
152
 
                /// <returns>An ICSList object containing the ShallowNode objects for the search results
153
 
                static public ICSList Tags( Collection collection )
154
 
                {
155
 
                        return collection.Search( PropertyTags.Types, NodeTypes.TagType, SearchOp.Equal );
156
 
                }
157
 
 
158
 
                /// <summary>
159
 
                /// Query for all tags that exist in the collection.
160
 
                /// </summary>
161
 
                /// <returns>An ICSList object containing the ShallowNode objects for the search results
162
 
                static public ICSList Tags( string collectionID )
163
 
                {
164
 
                        ICSList queryResult = null;
165
 
                        Collection collection = Store.GetStore().GetCollectionByID( collectionID );
166
 
                        if ( collection != null )
167
 
                        {
168
 
                                queryResult =
169
 
                                        collection.Search( PropertyTags.Types, NodeTypes.TagType, SearchOp.Equal );
170
 
                        }
171
 
                        else
172
 
                        {
173
 
                                throw new NotExistException( collectionID );
174
 
                        }
175
 
 
176
 
                        return queryResult;
177
 
                }
178
 
        }
179
 
}