Example usage for org.aspectj.lang ProceedingJoinPoint getArgs

List of usage examples for org.aspectj.lang ProceedingJoinPoint getArgs

Introduction

In this page you can find the example usage for org.aspectj.lang ProceedingJoinPoint getArgs.

Prototype

Object[] getArgs();

Source Link

Usage

From source file:org.cruk.genologics.api.cache.GenologicsAPICache.java

License:Open Source License

/**
 * Join point for the {@code GenologicsAPI.create} method.
 * Create the object through the API and, if it can be cached, record it
 * in the cache.//from  w  w w  . j  a v  a  2 s.co m
 *
 * @param pjp The join point object.
 *
 * @throws Throwable if there is an error.
 *
 * @see GenologicsAPI#create(Locatable)
 */
public void create(ProceedingJoinPoint pjp) throws Throwable {
    Locatable entity = (Locatable) pjp.getArgs()[0];

    pjp.proceed();

    if (isCacheable(entity)) {
        Ehcache cache = getCache(entity.getClass());

        cache.put(createCacheElement(entity));
    }
}

From source file:org.cruk.genologics.api.cache.GenologicsAPICache.java

License:Open Source License

/**
 * Join point for the {@code GenologicsAPI.createAll} method.
 * Create the objects through the API and, if they can be cached, record them
 * in the cache.//  www.  j  ava  2s. c  o  m
 *
 * @param pjp The join point object.
 *
 * @throws Throwable if there is an error.
 *
 * @see GenologicsAPI#createAll(Collection)
 */
public void createAll(ProceedingJoinPoint pjp) throws Throwable {
    @SuppressWarnings("unchecked")
    Collection<Locatable> entities = (Collection<Locatable>) pjp.getArgs()[0];

    pjp.proceed();

    if (isCacheable(entities)) {
        Ehcache cache = null;

        for (Locatable entity : entities) {
            if (cache == null) {
                cache = getCache(entity.getClass());
            }
            cache.put(createCacheElement(entity));
        }
    }
}

From source file:org.cruk.genologics.api.cache.GenologicsAPICache.java

License:Open Source License

/**
 * Join point for the {@code GenologicsAPI.update} method.
 * Update the object through the API and, if it can be cached, update the record
 * in the cache.// ww w  . ja  va  2 s.  c  o  m
 *
 * @param pjp The join point object.
 *
 * @throws Throwable if there is an error.
 *
 * @see GenologicsAPI#update(Locatable)
 */
public void update(ProceedingJoinPoint pjp) throws Throwable {
    Locatable entity = (Locatable) pjp.getArgs()[0];

    pjp.proceed();

    if (isCacheable(entity)) {
        Ehcache cache = getCache(entity.getClass());
        cache.put(createCacheElement(entity));
    }
}

From source file:org.cruk.genologics.api.cache.GenologicsAPICache.java

License:Open Source License

/**
 * Join point for the {@code GenologicsAPI.updateAll} method.
 * Update the objects through the API and, if they can be cached, update their records
 * in the cache./* w ww .  j ava 2 s.  com*/
 *
 * @param pjp The join point object.
 *
 * @throws Throwable if there is an error.
 *
 * @see GenologicsAPI#updateAll(Collection)
 */
public void updateAll(ProceedingJoinPoint pjp) throws Throwable {
    @SuppressWarnings("unchecked")
    Collection<Locatable> entities = (Collection<Locatable>) pjp.getArgs()[0];

    pjp.proceed();

    if (isCacheable(entities)) {
        Ehcache cache = null;

        for (Locatable entity : entities) {
            if (cache == null) {
                cache = getCache(entity.getClass());
            }
            cache.put(createCacheElement(entity));
        }
    }
}

From source file:org.cruk.genologics.api.cache.GenologicsAPICache.java

License:Open Source License

/**
 * Join point for the {@code GenologicsAPI.delete} method.
 * Delete the object through the API and, if it can be cached, remove it from the cache.
 *
 * @param pjp The join point object.//from w  w  w.  jav  a  2  s  .  c  om
 *
 * @throws Throwable if there is an error.
 *
 * @see GenologicsAPI#delete(Locatable)
 */
public void delete(ProceedingJoinPoint pjp) throws Throwable {
    Locatable entity = (Locatable) pjp.getArgs()[0];

    String key = keyFromLocatable(entity);

    pjp.proceed();

    if (isCacheable(entity)) {
        Ehcache cache = getCache(entity.getClass());
        cache.remove(key);
    }
}

From source file:org.cruk.genologics.api.cache.GenologicsAPICache.java

License:Open Source License

/**
 * Join point for the {@code GenologicsAPI.deleteAll} method.
 * Delete the objects through the API and, if they can be cached, remove their records
 * from the cache.//from w  w w.  ja va  2s  .  c  om
 *
 * @param pjp The join point object.
 *
 * @throws Throwable if there is an error.
 *
 * @see GenologicsAPI#deleteAll(Collection)
 */
public void deleteAll(ProceedingJoinPoint pjp) throws Throwable {
    @SuppressWarnings("unchecked")
    Collection<Locatable> entities = (Collection<Locatable>) pjp.getArgs()[0];

    Ehcache cache = null;

    List<String> keys = null;
    if (isCacheable(entities)) {
        keys = new ArrayList<String>(entities.size());
        for (Locatable entity : entities) {
            if (entity != null && entity.getUri() != null) {
                keys.add(keyFromLocatable(entity));

                if (cache == null) {
                    cache = getCache(entity.getClass());
                }
            }
        }
    }

    pjp.proceed();

    if (keys != null) {
        assert cache != null : "No cache set";
        cache.removeAll(keys);
    }
}

From source file:org.cruk.genologics.api.cache.GenologicsAPICache.java

License:Open Source License

/**
 * Join point for the {@code GenologicsAPI.deleteAndRemoveFile} method.
 * Call through to the API to do the work and remove the {@code GenologicsFile}
 * object from the cache.//w  w  w.ja  v  a 2  s. c o m
 *
 * @param pjp The join point object.
 *
 * @throws Throwable if there is an error.
 *
 * @see GenologicsAPI#deleteAndRemoveFile(Linkable)
 */
public void deleteAndRemoveFile(ProceedingJoinPoint pjp) throws Throwable {
    Linkable<?> file = (Linkable<?>) pjp.getArgs()[0];

    pjp.proceed();

    if (isCacheable(file)) {
        Ehcache cache = getCache(file.getClass());
        cache.remove(keyFromLocatable(file));
    }
}

From source file:org.cruk.genologics.api.cache.GenologicsAPICacheTest.java

License:Open Source License

@Test
public void testLoadOrRetrieveLatest() throws Throwable {
    checkCredentialsSet();//from  w  w  w  .  j av  a 2 s.c  o m

    cacheAspect.setStatefulBehaviour(CacheStatefulBehaviour.LATEST);

    //CacheManager mockCacheManager = EasyMock.createMock(CacheManager.class);
    //EasyMock.expect(mockCacheManager.getCache(Artifact.class.getName())).andReturn(value);

    cacheAspect.getCache(Artifact.class).removeAll();

    String base = api.getServerApiAddress();

    Signature jpSig = createSignatureMock();

    Artifact a1 = new Artifact();
    a1.setUri(new URI(base + "/artifacts/2-1771911?state=1294907"));
    a1.setLimsid("2-1771911");

    Object[] a1args = { a1.getUri(), a1.getClass() };

    ProceedingJoinPoint pjp1 = EasyMock.createStrictMock(ProceedingJoinPoint.class);
    EasyMock.expect(pjp1.getArgs()).andReturn(a1args).times(3);
    EasyMock.expect(pjp1.getSignature()).andReturn(jpSig).times(0, 1);
    EasyMock.expect(pjp1.proceed()).andReturn(a1).once();

    EasyMock.replay(pjp1, jpSig);

    Object returned = cacheAspect.retrieve(pjp1);

    EasyMock.verify(pjp1, jpSig);
    assertSame("Did not return a1", a1, returned);

    Artifact a2 = new Artifact();
    a2.setUri(new URI(base + "/artifacts/2-1771911?state=1500000"));
    a2.setLimsid("2-1771911");

    Object[] a2args = { a2.getUri(), a2.getClass() };

    jpSig = createSignatureMock();
    ProceedingJoinPoint pjp2 = EasyMock.createStrictMock(ProceedingJoinPoint.class);
    EasyMock.expect(pjp2.getArgs()).andReturn(a2args).times(3);
    EasyMock.expect(pjp2.getSignature()).andReturn(jpSig).times(0, 1);
    EasyMock.expect(pjp2.proceed()).andReturn(a2).once();

    EasyMock.replay(pjp2, jpSig);

    returned = cacheAspect.retrieve(pjp2);
    assertSame("Did not return a2", a2, returned);

    EasyMock.verify(pjp2, jpSig);

    // With an earlier state, expect the later version to be returned regardless.

    Object[] a3args = { base + "/artifacts/2-1771911?state=1101002", a1.getClass() };

    jpSig = createSignatureMock();
    ProceedingJoinPoint pjp3 = EasyMock.createStrictMock(ProceedingJoinPoint.class);
    EasyMock.expect(pjp3.getArgs()).andReturn(a3args).times(3);

    EasyMock.replay(pjp3, jpSig);

    returned = cacheAspect.retrieve(pjp3);

    EasyMock.verify(pjp3, jpSig);
    assertSame("Did not return a2", a2, returned);

    // With no state, expect whichever version is in the cache.

    Object[] a4args = { base + "/artifacts/2-1771911", Artifact.class };

    jpSig = createSignatureMock();
    ProceedingJoinPoint pjp4 = EasyMock.createStrictMock(ProceedingJoinPoint.class);
    EasyMock.expect(pjp4.getArgs()).andReturn(a4args).times(3);

    EasyMock.replay(pjp4, jpSig);

    returned = cacheAspect.retrieve(pjp4);

    EasyMock.verify(pjp4, jpSig);
    assertSame("Did not return a2", a2, returned);
}

From source file:org.cruk.genologics.api.cache.GenologicsAPICacheTest.java

License:Open Source License

@Test
public void testLoadOrRetrieveExact() throws Throwable {
    checkCredentialsSet();//from   w  w  w  . j a va2  s  .c om

    cacheAspect.setStatefulBehaviour(CacheStatefulBehaviour.EXACT);
    cacheAspect.getCache(Artifact.class).removeAll();

    String base = api.getServerApiAddress();

    Signature jpSig = createSignatureMock();

    Artifact a1 = new Artifact();
    a1.setUri(new URI(base + "/artifacts/2-1771911?state=1294907"));
    a1.setLimsid("2-1771911");

    Object[] a1args = { a1.getUri(), a1.getClass() };

    ProceedingJoinPoint pjp1 = EasyMock.createStrictMock(ProceedingJoinPoint.class);
    EasyMock.expect(pjp1.getArgs()).andReturn(a1args).times(3);
    EasyMock.expect(pjp1.getSignature()).andReturn(jpSig).times(0, 1);
    EasyMock.expect(pjp1.proceed()).andReturn(a1).once();

    EasyMock.replay(pjp1, jpSig);

    Object returned = cacheAspect.retrieve(pjp1);

    EasyMock.verify(pjp1, jpSig);
    assertSame("Did not return a1", a1, returned);

    Artifact a2 = new Artifact();
    a2.setUri(new URI(base + "/artifacts/2-1771911?state=1500000"));
    a2.setLimsid("2-1771911");

    Object[] a2args = { a2.getUri(), a2.getClass() };

    jpSig = createSignatureMock();
    ProceedingJoinPoint pjp2 = EasyMock.createStrictMock(ProceedingJoinPoint.class);
    EasyMock.expect(pjp2.getArgs()).andReturn(a2args).times(3);
    EasyMock.expect(pjp2.getSignature()).andReturn(jpSig).times(0, 1);
    EasyMock.expect(pjp2.proceed()).andReturn(a2).once();

    EasyMock.replay(pjp2, jpSig);

    returned = cacheAspect.retrieve(pjp2);
    assertSame("Did not return a2", a2, returned);

    EasyMock.verify(pjp2, jpSig);

    // In exact, this request for an earlier version will require another fetch.

    Artifact a3 = new Artifact();
    a3.setUri(new URI(base + "/artifacts/2-1771911?state=1101002"));
    a3.setLimsid("2-1771911");

    Object[] a3args = { a3.getUri(), a3.getClass() };

    jpSig = createSignatureMock();
    ProceedingJoinPoint pjp3 = EasyMock.createStrictMock(ProceedingJoinPoint.class);
    EasyMock.expect(pjp3.getArgs()).andReturn(a3args).times(3);
    EasyMock.expect(pjp3.getSignature()).andReturn(jpSig).times(0, 1);
    EasyMock.expect(pjp3.proceed()).andReturn(a3).once();

    EasyMock.replay(pjp3, jpSig);

    returned = cacheAspect.retrieve(pjp3);

    EasyMock.verify(pjp3, jpSig);
    assertSame("Did not return a3", a3, returned);

    // With no state, expect whichever version is in the cache.

    Object[] a4args = { base + "/artifacts/2-1771911", Artifact.class };

    jpSig = createSignatureMock();
    ProceedingJoinPoint pjp4 = EasyMock.createStrictMock(ProceedingJoinPoint.class);
    EasyMock.expect(pjp4.getArgs()).andReturn(a4args).times(3);

    EasyMock.replay(pjp4, jpSig);

    returned = cacheAspect.retrieve(pjp4);

    EasyMock.verify(pjp4, jpSig);
    assertSame("Did not return a3", a3, returned);
}

From source file:org.cruk.genologics.api.cache.GenologicsAPICacheTest.java

License:Open Source License

@Test
public void testLoadOrRetrieveAny() throws Throwable {
    checkCredentialsSet();/*w ww. j  a va2 s .co m*/

    cacheAspect.setStatefulBehaviour(CacheStatefulBehaviour.ANY);
    cacheAspect.getCache(Artifact.class).removeAll();

    String base = api.getServerApiAddress();

    Signature jpSig = createSignatureMock();

    Artifact a1 = new Artifact();
    a1.setUri(new URI(base + "/artifacts/2-1771911?state=1294907"));
    a1.setLimsid("2-1771911");

    Object[] a1args = { a1.getUri(), a1.getClass() };

    ProceedingJoinPoint pjp1 = EasyMock.createStrictMock(ProceedingJoinPoint.class);
    EasyMock.expect(pjp1.getArgs()).andReturn(a1args).times(3);
    EasyMock.expect(pjp1.getSignature()).andReturn(jpSig).times(0, 1);
    EasyMock.expect(pjp1.proceed()).andReturn(a1).once();

    EasyMock.replay(pjp1, jpSig);

    Object returned = cacheAspect.retrieve(pjp1);

    EasyMock.verify(pjp1, jpSig);
    assertSame("Did not return a1", a1, returned);

    // Asking for a later state in ANY mode will just return what it has.

    Object[] a2args = { base + "/artifacts/2-1771911?state=1500000", a1.getClass() };

    jpSig = createSignatureMock();
    ProceedingJoinPoint pjp2 = EasyMock.createStrictMock(ProceedingJoinPoint.class);
    EasyMock.expect(pjp2.getArgs()).andReturn(a2args).times(3);

    EasyMock.replay(pjp2, jpSig);

    returned = cacheAspect.retrieve(pjp2);
    assertSame("Did not return a1", a1, returned);

    EasyMock.verify(pjp2, jpSig);

    // With an earlier state, it'll be the same object again.

    Object[] a3args = { base + "/artifacts/2-1771911?state=1101002", a1.getClass() };

    jpSig = createSignatureMock();
    ProceedingJoinPoint pjp3 = EasyMock.createStrictMock(ProceedingJoinPoint.class);
    EasyMock.expect(pjp3.getArgs()).andReturn(a3args).times(3);

    EasyMock.replay(pjp3, jpSig);

    returned = cacheAspect.retrieve(pjp3);

    EasyMock.verify(pjp3, jpSig);
    assertSame("Did not return a1", a1, returned);

    // With no state, expect whichever version is in the cache.

    Object[] a4args = { base + "/artifacts/2-1771911", Artifact.class };

    jpSig = createSignatureMock();
    ProceedingJoinPoint pjp4 = EasyMock.createStrictMock(ProceedingJoinPoint.class);
    EasyMock.expect(pjp4.getArgs()).andReturn(a4args).times(3);

    EasyMock.replay(pjp4, jpSig);

    returned = cacheAspect.retrieve(pjp4);

    EasyMock.verify(pjp4, jpSig);
    assertSame("Did not return a1", a1, returned);
}