1 4 package com.openedit.archive.cumulus; 5 6 import java.util.ArrayList ; 7 import java.util.Iterator ; 8 import java.util.List ; 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 inErrorLog) throws Exception 30 { 31 Archive archive = new Archive(); 32 archive.setStore(inStore); 33 archive.setPageManager(getPageManager()); 34 35 String 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 54 public void parseUsers(ServerCatalog inUserCat, Archive inArchive) throws Exception 55 { 56 CatalogCollection col = inUserCat.open(); 57 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 username = user.getName(); 64 65 List includeCatalogList = new ArrayList (); 66 List showCatalogList = new ArrayList (); 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 Field recordFilterField = cat.getFields().getField("Live Filtering Record Query"); 87 if (recordFilterField.hasValue()) 88 { 89 String recordFilter = String.valueOf(recordFilterField.getValue()); 90 String hideRecords[] = recordFilter.split("\nor"); 91 for (int k = 0; k < hideRecords.length; k++) 92 { 93 String hide = hideRecords[k].trim(); 94 if (hide.length() > 0) 95 { 96 String includeCatalog = hide.substring(hide.indexOf("\tis") + 3).trim(); 97 includeCatalogList.add(includeCatalog); 98 } 99 } 100 } 101 102 Field categoryFilterField = cat.getFields().getField( 104 "Live Filtering Category Query"); 105 if (categoryFilterField.hasValue()) 106 { 107 String categoryFilter = String.valueOf(categoryFilterField.getValue()); 108 String hideCatalogs[] = categoryFilter.split("\nor"); 109 for (int k = 0; k < hideCatalogs.length; k++) 110 { 111 String hide = hideCatalogs[k].trim(); 112 if (hide.length() > 0) 113 { 114 String 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 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 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 |