KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > openedit > archive > cumulus > CumulusUserConverter


1 /*
2  * Created on Nov 27, 2006
3  */

4 package com.openedit.archive.cumulus;
5
6 import java.util.ArrayList JavaDoc;
7 import java.util.Iterator JavaDoc;
8 import java.util.List JavaDoc;
9
10 import org.apache.commons.logging.Log;
11 import org.apache.commons.logging.LogFactory;
12
13 import com.canto.cumulus.CatalogCollection;
14 import com.canto.cumulus.Categories;
15 import com.canto.cumulus.Field;
16 import com.canto.cumulus.ServerCatalog;
17 import com.openedit.archive.Archive;
18 import com.openedit.store.Category;
19 import com.openedit.store.Store;
20 import com.openedit.users.Group;
21 import com.openedit.users.User;
22 import com.openedit.users.UserManager;
23
24 public class CumulusUserConverter extends BaseCumulusConvert
25 {
26     protected UserManager fieldUserManager;
27     private static final Log log = LogFactory.getLog(CumulusUserConverter.class);
28
29     public boolean convert(Store inStore, List JavaDoc inErrorLog) throws Exception JavaDoc
30     {
31         Archive archive = new Archive();
32         archive.setStore(inStore);
33         archive.setPageManager(getPageManager());
34
35         String JavaDoc imUsers = archive.getSettings().getChildValue("importusers");
36         if (Boolean.parseBoolean(imUsers))
37         {
38             ServerCatalog cat = getServerCatalogs().getServerCatalog("$Users");
39             parseUsers(cat, archive);
40         }
41
42         return false;
43     }
44
45     /*
46      * Loop over all users
47      * Find Category with parent of $Roles
48      * Add user to that group
49      *
50      * then loop over all the $Roles and update the group accordingly
51      *
52      *
53      */

54     public void parseUsers(ServerCatalog inUserCat, Archive inArchive) throws Exception JavaDoc
55     {
56         CatalogCollection col = inUserCat.open();
57         //loop over each record found
58
com.canto.cumulus.Category roles = col.getCategories().getCategory("$Roles");
59         Categories categories = roles.getSubCategories();
60         for (int i = 0; i < categories.countCategories(); i++)
61         {
62             com.canto.cumulus.Category user = categories.getCategory(i);
63             String JavaDoc username = user.getName();
64
65             List JavaDoc includeCatalogList = new ArrayList JavaDoc();
66             List JavaDoc showCatalogList = new ArrayList JavaDoc();
67
68             User oeUser = getUserManager().getUser(username);
69             if (oeUser == null)
70             {
71                 oeUser = getUserManager().createUser(username, null);
72                 Group guest = getUserManager().getGroup("users");
73                 if (guest != null)
74                 {
75                     oeUser.addGroup(guest);
76                 }
77             }
78             com.canto.cumulus.Category catalogs = user.getSubCategories().getCategory("$Catalogs");
79
80             for (int j = 0; j < catalogs.getSubCategories().countCategories(); j++)
81             {
82
83                 com.canto.cumulus.Category cat = catalogs.getSubCategories().getCategory(j);
84
85                 //hide records
86
Field recordFilterField = cat.getFields().getField("Live Filtering Record Query");
87                 if (recordFilterField.hasValue())
88                 {
89                     String JavaDoc recordFilter = String.valueOf(recordFilterField.getValue());
90                     String JavaDoc hideRecords[] = recordFilter.split("\nor");
91                     for (int k = 0; k < hideRecords.length; k++)
92                     {
93                         String JavaDoc hide = hideRecords[k].trim();
94                         if (hide.length() > 0)
95                         {
96                             String JavaDoc includeCatalog = hide.substring(hide.indexOf("\tis") + 3).trim();
97                             includeCatalogList.add(includeCatalog);
98                         }
99                     }
100                 }
101
102                 //hide catalog
103
Field categoryFilterField = cat.getFields().getField(
104                     "Live Filtering Category Query");
105                 if (categoryFilterField.hasValue())
106                 {
107                     String JavaDoc categoryFilter = String.valueOf(categoryFilterField.getValue());
108                     String JavaDoc hideCatalogs[] = categoryFilter.split("\nor");
109                     for (int k = 0; k < hideCatalogs.length; k++)
110                     {
111                         String JavaDoc hide = hideCatalogs[k].trim();
112                         if (hide.length() > 0)
113                         {
114                             String JavaDoc showCatalog = hide.substring(hide.indexOf("\tis") + 3).trim();
115                             showCatalogList.add(showCatalog);
116                         }
117                     }
118                 }
119
120                 if (includeCatalogList.size() > 0)
121                 {
122                     Category photo = inArchive.getStore().getCatalogArchive().getCatalogByName(
123                         cat.getName());
124                     for (Iterator JavaDoc iterator = photo.getChildren().iterator(); iterator.hasNext();)
125                     {
126                         Category childCat = (Category) iterator.next();
127                         if (!includeCatalogList.contains(childCat.getName()))
128                         {
129                             oeUser.put("excludecatalog:" + childCat.getId(), "true");
130                         }
131                     }
132                 }
133
134                 if (showCatalogList.size() > 0)
135                 {
136                     Category photo = inArchive.getStore().getCatalogArchive().getCatalogByName(
137                         cat.getName());
138                     for (Iterator JavaDoc iterator = photo.getChildren().iterator(); iterator.hasNext();)
139                     {
140                         Category childCat = (Category) iterator.next();
141                         if (!showCatalogList.contains(childCat.getName()))
142                         {
143                             oeUser.put("hidecatalog:" + childCat.getId(), "true");
144                         }
145                     }
146                 }
147             }
148             log.info("Saving user: " + oeUser.getUserName());
149             getUserManager().saveUser(oeUser);
150         }
151
152         col.close();
153
154     }
155
156     public UserManager getUserManager()
157     {
158         return fieldUserManager;
159     }
160
161     public void setUserManager(UserManager inUserManager)
162     {
163         fieldUserManager = inUserManager;
164     }
165
166 }
167
Popular Tags