Class ClarityAPIPlaybackAspect

java.lang.Object
org.cruk.clarity.api.playback.ClarityAPIPlaybackAspect

@Component("clarityPlaybackAspect") public class ClarityAPIPlaybackAspect extends Object
Aspect for replaying server exchanges from a directory containing XML representations of entities as would be returned from a real Clarity server.
  • Constructor Details

    • ClarityAPIPlaybackAspect

      public ClarityAPIPlaybackAspect()
      Constructor.
    • ClarityAPIPlaybackAspect

      public ClarityAPIPlaybackAspect(File messageDirectory)
      Constructor.
      Parameters:
      messageDirectory - The message directory.
  • Method Details

    • getMessageDirectory

      public File getMessageDirectory()
      Get the directory the messages are being read from.
      Returns:
      The message directory.
    • setMessageDirectory

      public void setMessageDirectory(File messageDirectory)
      Set the directory the messages are being written to. Also sets the search directory if it is not already set.
      Parameters:
      messageDirectory - The message directory.
    • getUpdatesDirectory

      public File getUpdatesDirectory()
      Get the directory the updated entities are being written to.
      Returns:
      The updates directory.
    • setUpdatesDirectory

      public void setUpdatesDirectory(File updatesDirectory)
      Set the directory the updated entities are being written to. If this is set to null, no updates will be written. By default this is the case: one needs to set the directory to write them.
      Parameters:
      updatesDirectory - The updates directory.
    • isFailOnMissingSearch

      public boolean isFailOnMissingSearch()
      Whether to fail if there is no result recorded for a search, or whether to simply return no results. Saves having to save every search with no results, and helps when something changes to add another value to search for that will return nothing.
      Returns:
      true if a missing search recording will fail, false if it will return no results.
      Since:
      2.31.6
      See Also:
    • setFailOnMissingSearch

      public void setFailOnMissingSearch(boolean failOnMissingSearch)
      Get whether this aspect should fail if a search doesn't have a recording.
      Parameters:
      failOnMissingSearch - true if a missing search recording will fail, false if it will return no results.
      Since:
      2.31.6
    • setClarityUnmarshaller

      @Autowired @Qualifier("clarityJaxbUnmarshaller") public void setClarityUnmarshaller(Unmarshaller unmarshaller)
      Inject the JAXB unmarshaller.
      Parameters:
      unmarshaller - The unmarshaller.
    • setClarityMarshaller

      @Autowired @Qualifier("clarityJaxbMarshaller") public void setClarityMarshaller(Marshaller marshaller)
      Inject the JAXB marshaller.
      Parameters:
      marshaller - The marshaller.
    • setClarityAPI

      @Autowired @Qualifier("clarityAPI") public void setClarityAPI(ClarityAPI api)
      Set the public interface access to the API.
      Parameters:
      api - The API bean, through its public interface.
    • setInternalClarityAPI

      @Autowired @Qualifier("clarityAPI") public void setInternalClarityAPI(ClarityAPIInternal internalApi)
      Set the internal interface access to the API.
      Parameters:
      internalApi - The API bean, but through its internal interface.
    • doGet

      public Object doGet(org.aspectj.lang.ProceedingJoinPoint pjp) throws Throwable
      Join point around the Spring REST client's getForObject() methods. Looks for a file named with the required class's short name (no package) plus either its LIMS id (if there is one) or the identifier given at the end of the path of the URI.
      Parameters:
      pjp - The join point.
      Returns:
      The unmarshalled entity from the file found.
      Throws:
      NoRecordingException - if there is no file recorded for the object.
      Throwable - if there is anything else that fails.
    • doGetEntity

      public ResponseEntity<?> doGetEntity(org.aspectj.lang.ProceedingJoinPoint pjp) throws Throwable
      Join point around the Spring REST client's getForEntity() methods. Works as doGet(ProceedingJoinPoint), except rather than throwing a NoRecordingException, it throws a ClarityException with a not found status. This is what would happen if the call was made to a real API.
      Parameters:
      pjp - The join point.
      Returns:
      A ResponseEntity object containing the unmarshalled entity and an "OK" code if the file exists.
      Throws:
      ClarityException - with a "not found" status if there is no recorded file for the entity.
      Throwable - if there is anything that fails.
    • doLoadAll

      public List<?> doLoadAll(org.aspectj.lang.ProceedingJoinPoint pjp) throws Throwable
      Join point around calls to the API's loadAll method. Iterates through the links asking the API for them individually, before returning a collection of the entities.

      This slightly convoluted route allows the cache to return cache hits if it is in use. The actual loading, when there is a cache miss, comes from the call coming through this object again but via the doGet(ProceedingJoinPoint) method, which loads the entity from file.

      Parameters:
      pjp - The join point.
      Returns:
      A list of the entities loaded from the links.
      Throws:
      NoRecordingException - if there is no entity file recorded for any of the links.
      Throwable - if there is anything else that fails.
    • doFind

      public <E extends Locatable> List<LimsLink<E>> doFind(org.aspectj.lang.ProceedingJoinPoint pjp) throws Throwable
      Join point around the Clarity client's find() method. Tries to find a prerecorded search in the search directory that matches the search parameters of this call.
      Type Parameters:
      E - The type of entity being searched for.
      Parameters:
      pjp - The join point.
      Returns:
      The result of the search (a list of links).
      Throws:
      NoRecordingException - if there is no search recorded for the parameters given and the aspect is set to fail on no recorded search.
      Throwable - if there is anything else that fails.
    • doList

      public <E extends Locatable, L extends LimsLink<E>, BH extends Batch<L>> List<L> doList(org.aspectj.lang.ProceedingJoinPoint pjp) throws Throwable
      Join point around the listAll and listSome methods load the list of links from a serialised Batch object in XML file in the messages directory.

      No reference is made to the numbers in the listSome parameters. All the links stored in the file are returned regardless.

      Type Parameters:
      E - The type of entity to list.
      L - The type of link to the entity returned from the API.
      BH - The batch class that is used to hold the links returned from the API.
      Parameters:
      pjp - The join point.
      Returns:
      The result of the search (a list of links). If there was no file recorded for a list of these entities, an empty list is returned.
      Throws:
      NoRecordingException - if there is no list recorded for this type of entity.
      Throwable - if there is an error invoking the underlying method.
    • blockWrite

      public void blockWrite(org.aspectj.lang.ProceedingJoinPoint pjp)
      Join point around methods that would cause a change in Clarity (create, update, delete, upload). These methods are not helpful when running from prerecorded messages, and should be quietly ignored (a warning is logged).
      Parameters:
      pjp - The join point.
    • doUpdate

      public void doUpdate(org.aspectj.lang.ProceedingJoinPoint pjp) throws Throwable
      Join point around the Clarity client's update() method. Writes to the message directory this new version of the entity. There will be versions of the entity written to the directory, incrementing with each call.
      Parameters:
      pjp - The join point.
      Throws:
      Throwable - if there is anything fails.
    • doUpdateAll

      public void doUpdateAll(org.aspectj.lang.ProceedingJoinPoint pjp) throws Throwable
      Join point around the Clarity client's updateAll() method. Writes to the message directory the new versions of the entities. There will be versions of each entity written to the directory, incrementing with each call (numbers per entity, not an overall counter).
      Parameters:
      pjp - The join point.
      Throws:
      Throwable - if there is anything fails.