View Javadoc

1   /*
2    * Copyright 2010 FatWire Corporation. All Rights Reserved.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *    http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package com.fatwire.gst.foundation.tagging;
17  
18  import java.util.Collection;
19  
20  import com.fatwire.assetapi.data.AssetId;
21  import com.fatwire.gst.foundation.facade.assetapi.listener.RunOnceAssetEventListener;
22  import com.fatwire.gst.foundation.facade.ics.ICSFactory;
23  
24  /**
25   * Cache manager to be used to deal with cache updates
26   * 
27   * @author Tony Field
28   * @author Dolf Dijkstra
29   * @since Jul 28, 2010
30   */
31  public final class CacheMgrTaggedAssetEventListener extends RunOnceAssetEventListener {
32  
33      
34  
35      private AssetTaggingService getService() {
36          return AssetTaggingServiceFactory.getService(ICSFactory.getOrCreateICS());
37      }
38  
39      @Override
40      public void doAssetAdded(AssetId assetId) {
41          if (LOG.isTraceEnabled()) {
42              LOG.trace("Heard assetAdded event for " + assetId);
43          }
44  
45          AssetTaggingService svc = getService();
46          if (svc.isTagged(assetId)) {
47              Collection<Tag> tags = svc.getTags(assetId);
48              svc.clearCacheForTag(tags);
49          }
50      }
51  
52      @Override
53      public void doAssetUpdated(AssetId assetId) {
54          if (LOG.isTraceEnabled()) {
55              LOG.trace("Heard assetUpdated event for " + assetId);
56          }
57          AssetTaggingService svc = getService();
58          if (svc.isTagged(assetId)) {
59              Collection<Tag> tags = svc.getTags(assetId);
60              svc.clearCacheForTag(tags);
61          }
62      }
63  
64      @Override
65      public void doAssetDeleted(AssetId assetId) {
66          if (LOG.isTraceEnabled()) {
67              LOG.trace("Heard assetDeleted event for " + assetId);
68          }
69          AssetTaggingService svc = getService();
70          if (svc.isTagged(assetId)) {
71              Collection<Tag> tags = svc.getTags(assetId);
72              svc.clearCacheForTag(tags);
73          }
74      }
75  
76   
77  }