1
/****************************************************************************
3
| Copyright (c) 2007 Novell, Inc.
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.
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.
15
| You should have received a copy of the GNU General Public License
16
| along with this program; if not, contact Novell, Inc.
18
| To contact Novell about this file by physical or electronic mail,
19
| you may find current contact information at www.novell.com
21
| Author: Brady Anderson <banderso@novell.com>
22
|***************************************************************************/
25
using System.Collections;
34
/// Class used for querying nodes that contain that
39
private ArrayList tagList;
40
private Collection collection;
44
/// Constructor will throw an exception if the collection does not exist
46
public Query( string collectionID )
48
collection = Store.GetStore().GetCollectionByID( collectionID );
49
if ( collection == null )
51
throw new SimiasException( "Specified Collection does not exist" );
54
tagList = new ArrayList();
58
/// Constructor will throw an exception if the collection does not exist
60
public Query( string collectionID, Tag tag )
62
collection = Store.GetStore().GetCollectionByID( collectionID );
63
if ( collection == null )
65
throw new SimiasException( "Specified Collection does not exist" );
68
tagList = new ArrayList();
73
public bool AddTag( Tag searchTag )
75
tagList.Add( searchTag );
80
/// Query for all nodes that contain the tag(s) setup in this
83
/// <returns>An ICSList object containing the ShallowNode objects for the search results</returns>
84
public ICSList QueryNodes()
86
ICSList returnedResults = null;
89
if ( tagList.Count == 1 )
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 );
97
if ( tagList.Count > 1 )
100
Hashtable hashedList = new Hashtable();
101
foreach( Tag tag in tagList )
103
Relationship relationshipTag = new Relationship( collection.ID, tag.ID );
104
p = new Property( "Tag", relationshipTag );
105
queryResults = collection.Search( p, SearchOp.Equal );
107
foreach( ShallowNode sn in queryResults )
109
if ( hashedList.ContainsKey( sn.ID ) == false )
111
hashedList.Add( sn.ID, sn );
116
if ( hashedList.Count > 0 )
118
returnedResults = new ICSList();
119
foreach( ShallowNode sn in hashedList.Values )
121
returnedResults.Add( sn );
126
return returnedResults;
130
/// Query for all nodes that contain the tag(s) setup in this
133
/// <returns>An ICSList object containing the ShallowNode objects for the search results
134
static public ICSList Nodes( string collectionID, Tag searchTag )
136
ICSList queryResult = null;
137
Collection collection = Store.GetStore().GetCollectionByID( collectionID );
138
if ( collection != null )
140
Relationship relationshipTag =
141
new Relationship( collection.ID, searchTag.ID );
142
Property p = new Property( "Tag", relationshipTag );
143
queryResult = collection.Search( p, SearchOp.Equal );
150
/// Query for all tags that exist in the collection.
152
/// <returns>An ICSList object containing the ShallowNode objects for the search results
153
static public ICSList Tags( Collection collection )
155
return collection.Search( PropertyTags.Types, NodeTypes.TagType, SearchOp.Equal );
159
/// Query for all tags that exist in the collection.
161
/// <returns>An ICSList object containing the ShallowNode objects for the search results
162
static public ICSList Tags( string collectionID )
164
ICSList queryResult = null;
165
Collection collection = Store.GetStore().GetCollectionByID( collectionID );
166
if ( collection != null )
169
collection.Search( PropertyTags.Types, NodeTypes.TagType, SearchOp.Equal );
173
throw new NotExistException( collectionID );