@Test @TestTarget(ServerVersion.AGM) public void testRequestCachedEntity() { EntityRef ref = new EntityRef("defect", 86); Entity entity = new Entity(ref.type, ref.id); entity.setProperty("status", "New"); addEntityListener(new Cache(ref, entity)); handler.async(); entityService.requestCachedEntity(ref, Arrays.asList("status"), new EntityLoaded(handler, "defect", 86, EntityListener.Event.CACHE, new EntityLoaded.Listener() { @Override public void evaluate(Entity entity, EntityListener.Event event) { Assert.assertEquals("New", entity.getPropertyValue("status")); } })); }
public void requestCachedEntity(final EntityRef ref, final List<String> properties, final EntityListener callback) { ApplicationUtil.executeOnPooledThread(new Runnable() { public void run() { final LinkedList<Entity> done = new LinkedList<Entity>(); listeners.fire(new WeakListeners.Action<EntityListener>() { public void fire(EntityListener listener) { if(done.isEmpty() && listener instanceof CachingEntityListener) { Entity cached = ((CachingEntityListener) listener).lookup(ref); if(cached != null) { for(String property: properties) { if(!cached.isInitialized(property)) { return; } } done.add(cached); } } } }); if(done.isEmpty()) { getEntityAsync(ref, callback); } else { callback.entityLoaded(done.getFirst(), EntityListener.Event.CACHE); } } }); }
EntityService { public void requestCachedEntity(final EntityRef ref, final List<String> properties, final EntityListener callback) { ApplicationUtil.executeOnPooledThread(new Runnable() { public void run() { final LinkedList<Entity> done = new LinkedList<Entity>(); listeners.fire(new WeakListeners.Action<EntityListener>() { public void fire(EntityListener listener) { if(done.isEmpty() && listener instanceof CachingEntityListener) { Entity cached = ((CachingEntityListener) listener).lookup(ref); if(cached != null) { for(String property: properties) { if(!cached.isInitialized(property)) { return; } } done.add(cached); } } } }); if(done.isEmpty()) { getEntityAsync(ref, callback); } else { callback.entityLoaded(done.getFirst(), EntityListener.Event.CACHE); } } }); } }
EntityService { public void requestCachedEntity(final EntityRef ref, final List<String> properties, final EntityListener callback) { ApplicationUtil.executeOnPooledThread(new Runnable() { public void run() { final LinkedList<Entity> done = new LinkedList<Entity>(); listeners.fire(new WeakListeners.Action<EntityListener>() { public void fire(EntityListener listener) { if(done.isEmpty() && listener instanceof CachingEntityListener) { Entity cached = ((CachingEntityListener) listener).lookup(ref); if(cached != null) { for(String property: properties) { if(!cached.isInitialized(property)) { return; } } done.add(cached); } } } }); if(done.isEmpty()) { getEntityAsync(ref, callback); } else { callback.entityLoaded(done.getFirst(), EntityListener.Event.CACHE); } } }); } EntityService(Project project, RestService restService, MetadataService metadataService, ErrorService errorService); }
EntityService { public void requestCachedEntity(final EntityRef ref, final List<String> properties, final EntityListener callback) { ApplicationUtil.executeOnPooledThread(new Runnable() { public void run() { final LinkedList<Entity> done = new LinkedList<Entity>(); listeners.fire(new WeakListeners.Action<EntityListener>() { public void fire(EntityListener listener) { if(done.isEmpty() && listener instanceof CachingEntityListener) { Entity cached = ((CachingEntityListener) listener).lookup(ref); if(cached != null) { for(String property: properties) { if(!cached.isInitialized(property)) { return; } } done.add(cached); } } } }); if(done.isEmpty()) { getEntityAsync(ref, callback); } else { callback.entityLoaded(done.getFirst(), EntityListener.Event.CACHE); } } }); } EntityService(Project project, RestService restService, MetadataService metadataService, ErrorService errorService); void addEntityListener(EntityListener listener); void removeEntityListener(EntityListener listener); void refreshEntity(EntityRef ref); void getEntityAsync(EntityRef ref, EntityListener callback); Entity getEntity(EntityRef ref); EntityList query(EntityQuery query); InputStream queryForStream(EntityQuery query); Entity getDefectLink(int defectId, int linkId); Entity updateEntity(Entity entity, Set<String> fieldsToUpdate, boolean silent); Entity updateEntity(Entity entity, Set<String> fieldsToUpdate, boolean silent, boolean reloadOnFailure); Entity updateEntity(Entity entity, Set<String> fieldsToUpdate, boolean silent, boolean reloadOnFailure, boolean fireUpdate); Entity createEntity(Entity entity, boolean silent); Entity lockEntity(Entity entity, boolean silent); boolean deleteEntity(Entity entity); void unlockEntity(Entity entity); void fireEntityLoaded(final Entity entity, final EntityListener.Event event); void fireEntityNotFound(final EntityRef ref, final boolean removed); void requestCachedEntity(final EntityRef ref, final List<String> properties, final EntityListener callback); }
EntityService { public void requestCachedEntity(final EntityRef ref, final List<String> properties, final EntityListener callback) { ApplicationUtil.executeOnPooledThread(new Runnable() { public void run() { final LinkedList<Entity> done = new LinkedList<Entity>(); listeners.fire(new WeakListeners.Action<EntityListener>() { public void fire(EntityListener listener) { if(done.isEmpty() && listener instanceof CachingEntityListener) { Entity cached = ((CachingEntityListener) listener).lookup(ref); if(cached != null) { for(String property: properties) { if(!cached.isInitialized(property)) { return; } } done.add(cached); } } } }); if(done.isEmpty()) { getEntityAsync(ref, callback); } else { callback.entityLoaded(done.getFirst(), EntityListener.Event.CACHE); } } }); } EntityService(Project project, RestService restService, MetadataService metadataService, ErrorService errorService); void addEntityListener(EntityListener listener); void removeEntityListener(EntityListener listener); void refreshEntity(EntityRef ref); void getEntityAsync(EntityRef ref, EntityListener callback); Entity getEntity(EntityRef ref); EntityList query(EntityQuery query); InputStream queryForStream(EntityQuery query); Entity getDefectLink(int defectId, int linkId); Entity updateEntity(Entity entity, Set<String> fieldsToUpdate, boolean silent); Entity updateEntity(Entity entity, Set<String> fieldsToUpdate, boolean silent, boolean reloadOnFailure); Entity updateEntity(Entity entity, Set<String> fieldsToUpdate, boolean silent, boolean reloadOnFailure, boolean fireUpdate); Entity createEntity(Entity entity, boolean silent); Entity lockEntity(Entity entity, boolean silent); boolean deleteEntity(Entity entity); void unlockEntity(Entity entity); void fireEntityLoaded(final Entity entity, final EntityListener.Event event); void fireEntityNotFound(final EntityRef ref, final boolean removed); void requestCachedEntity(final EntityRef ref, final List<String> properties, final EntityListener callback);  }