1 4 package com.openedit.archive.cumulus; 5 6 import java.io.File ; 7 import java.util.Date ; 8 import java.util.Iterator ; 9 import java.util.List ; 10 11 import org.apache.commons.logging.Log; 12 import org.apache.commons.logging.LogFactory; 13 14 import com.canto.cumulus.CatalogCollection; 15 import com.canto.cumulus.Field; 16 import com.canto.cumulus.Fields; 17 import com.canto.cumulus.Record; 18 import com.canto.cumulus.Server; 19 import com.canto.cumulus.ServerCatalog; 20 import com.openedit.page.Page; 21 import com.openedit.page.manage.PageManager; 22 import com.openedit.store.BaseArchive; 23 import com.openedit.store.Product; 24 import com.openedit.store.ProductArchive; 25 import com.openedit.store.ProductPathFinder; 26 import com.openedit.store.Store; 27 import com.openedit.store.StoreException; 28 import com.openedit.store.products.Detail; 29 import com.openedit.store.products.PropertyDetails; 30 31 public class CumulusProductArchive extends BaseArchive implements ProductArchive 32 { 33 private static final Log log = LogFactory.getLog(CumulusProductArchive.class); 34 35 protected CumulusConnectionPool fieldCumulusConnectionPool; 36 protected PropertyDetails fieldPropertyDetails; 37 protected PageManager fieldPageManager; 38 protected Store fieldStore; 39 40 public PageManager getPageManager() 41 { 42 return fieldPageManager; 43 } 44 45 public void setPageManager(PageManager inPageManager) 46 { 47 fieldPageManager = inPageManager; 48 } 49 50 51 public PropertyDetails getPropertyDetails() throws StoreException 52 { 53 if ( fieldPropertyDetails == null) 54 { 55 fieldPropertyDetails = new PropertyDetails(); 56 try 58 { 59 Page page = getPageManager().getPage(getStore().getStoreHome() + "/configuration/productproperties.xml"); 60 if ( page.exists() ) 61 { 62 fieldPropertyDetails.addAllDetails(page.getReader()); 63 } 64 } catch ( Exception ex) 65 { 66 throw new StoreException(ex); 67 } 68 } 69 return fieldPropertyDetails; 70 } 71 72 73 public CumulusConnectionPool getCumulusConnectionPool() 74 { 75 return fieldCumulusConnectionPool; 76 } 77 78 public void setCumulusConnectionPool(CumulusConnectionPool inCumulusConnectionPool) 79 { 80 fieldCumulusConnectionPool = inCumulusConnectionPool; 81 } 82 public void saveProduct(Product inProduct) throws StoreException 83 { 84 if( !getCumulusConnectionPool().isEnabled() ) 85 { 86 return; 87 } 88 log.info("Saving to cumulus " + inProduct.getId()); 90 String cumulusid = inProduct.get("cumulusid"); 91 if( cumulusid == null) 92 { 93 log.error("No cumulusid is set for " + inProduct.getId()); 94 } 96 else 97 { 98 Server server = getCumulusConnectionPool().getAvailableServer(); 99 String [] location = cumulusid.split("_"); 100 String catname = location[0]; 101 try 102 { 103 ServerCatalog cat = server.getServerCatalogs().getServerCatalog(catname); 104 CatalogCollection col = cat.open(); 105 String recordid = location[1]; 106 int id = Integer.parseInt(recordid); 107 Record record = col.getRecords().getRecordByID(id); 109 log.info(record + " " + record.getID() + " " + record.getIsReadOnly() ); 110 if( record != null) 111 { 112 Fields fields = record.getFields(); 113 for (Iterator iter = getPropertyDetails().getDetails().iterator(); iter.hasNext();) 114 { 115 Detail detail = (Detail) iter.next(); 116 if( detail.isEditable() ) 117 { 118 String value = inProduct.get(detail.getId()); 119 if( value != null) 120 { 121 Field data = fields.getField(detail.getId()); 122 if( detail.isBoolean()) 123 { 124 data.setValue(new Boolean ( value ) ); 125 } 126 else if( detail.isDate() ) 127 { 128 Date date = detail.getDateFormat().parse(value); 129 data.setValue(date); 130 } 131 else 132 { 133 data.setValue(value); 134 } 135 } 136 } 137 } 138 } 139 record.save(); 140 } 141 catch ( Exception ex) 142 { 143 throw new StoreException(ex); 144 } 145 } 146 } 147 148 149 public void clearProduct(Product inProduct) 150 { 151 } 152 153 public void clearProducts() 154 { 155 } 156 157 public void deleteProduct(Product inItem) throws StoreException 158 { 159 } 160 161 public Product getProduct(String inId) throws StoreException 162 { 163 return null; 164 } 165 166 public ProductPathFinder getProductPathFinder() 167 { 168 return null; 169 } 170 171 public File getStoreDirectory() 172 { 173 return null; 174 } 175 176 public List listAllProductIds() 177 { 178 return null; 179 } 180 181 public String loadDescription(Product inProduct) throws StoreException 182 { 183 return null; 184 } 185 186 public String nextProductNumber(Store inStore) throws StoreException 187 { 188 return null; 189 } 190 191 public void saveBlankProductDescription(Product inProduct) throws StoreException 192 { 193 } 194 195 public void saveProductDescription(Product inProduct, String inDescription) 196 throws StoreException 197 { 198 } 199 200 public void setProductPathFinder(ProductPathFinder inProductPathFinder) 201 { 202 } 203 204 public void setStoreDirectory(File inDir) 205 { 206 } 207 208 public Store getStore() 209 { 210 return fieldStore; 211 } 212 213 public void setStore(Store inStore) 214 { 215 fieldStore = inStore; 216 } 217 218 } 219 | Popular Tags |