Class NewsAgent

java.lang.Object
de.uplanet.lucy.server.newsagent.NewsAgent

@Scriptable public final class NewsAgent extends Object
Handles messages that exist beyond application scope.

Users MUST call done() when finished using the agent to ensure that all resources such as SQL statements are properly closed and freed.

  • Method Details

    • createInstance

      public static NewsAgent createInstance(de.uplanet.jdbc.JdbcConnection p_conn)
      Factory method for creating a news agent.
      Returns:
      The newly generated news agent.
    • done

      @Deprecated public void done()
      Deprecated.
      This method must not be called anymore.
    • createNewMessage

      public Message createNewMessage()
      Create a new message.
      Returns:
      The newly created message.
    • createNewMessage

      public Message createNewMessage(String p_strMessageId)
      Create a new message with the given message identifier.

      The newly created message is not inserted into the messages collection.

      Returns:
      The newly created message.
      Throws:
      IllegalArgumentException - If the given message ID is not a GUID.
    • markRead

      public void markRead(String p_strMessageId, String p_strUserId)
      Mark a message as read for the specified user.

      Either of the parameters may be null, however the method does nothing in these cases.

      Parameters:
      p_strMessageId - The GUID of the message.
      p_strUserId - The GUID of the user.
      Throws:
      IllegalArgumentException - If the given message or user ID is not a GUID.
    • markDeleted

      public void markDeleted(String p_strMessageId, String p_strUserId)
      Mark a message as deleted for the specified user.

      Either of the parameters may be null, however the method does nothing in these cases.

      Parameters:
      p_strMessageId - The GUID of the message.
      p_strUserId - The GUID of the user.
      Throws:
      IllegalArgumentException - If the given message or user ID is not a GUID.
    • load

      public int load(IFilter p_filter, IOrder p_order, int p_iMaxCount)
      Load messages from the database.
      Parameters:
      p_filter - The filter to be applied when loading.
      p_order - The order in which the messages should be loaded.
      p_iMaxCount - The maximum number of messages to be loaded or -1 if all messages should be loaded.
      Returns:
      The number of messages that where actually loaded.
    • loadMessage

      public Message loadMessage(String p_strMessageId)
      Load the specified message from the database.

      The internal state of the news agent is not affected by calling this method. In particular, the content of the messages collection and of the filtered messages collection is not changed.

      Parameters:
      p_strMessageId - The GUID of the message to be loaded.
      Returns:
      The message or null if the message could not be found.
      Throws:
      IllegalArgumentException - If the given message ID is not a GUID.
    • save

      public boolean save(Message p_message)
      Save the message to the database.
      Parameters:
      p_message - The message to save.
      Returns:
      true if the message was saved, false otherwise.
    • registerTarget

      public boolean registerTarget(String p_strAppGuid, String p_strTargetGuid)
      Register or re-register a link target for an application.
      Parameters:
      p_strAppGuid - The application for which the target should be registered.
      p_strTargetGuid - The identifier of the link target.
    • unregisterTarget

      public void unregisterTarget(String p_strAppGuid)
      Unregister the link target for the given application.

      Call this method whenever an application is deleted.

      Parameters:
      p_strAppGuid - The GUID of the application.
    • getTarget

      public String getTarget(String p_strAppGuid)
      Get the registered target GUID for an application.
      Parameters:
      p_strAppGuid - The application GUID.
      Returns:
      The registered target identifier.
    • deleteMessage

      public boolean deleteMessage(String p_strMessageId)
      Delete the specified message.
      Parameters:
      p_strMessageId - The GUID of the message that should be deleted.
      Returns:
      true if the message could be deleted, false otherwise.
      Throws:
      IllegalArgumentException - If the given message ID is not a GUID.
    • deleteMessagesForApplication

      public boolean deleteMessagesForApplication(String p_strAppGuid)
      Delete all messages that belong to the specified application GUID.
      Parameters:
      p_strAppGuid - The application GUID for which the messages should be deleted.
      Returns:
      true if the the messages could be deleted, false otherwise.
    • deleteMessagesForUser

      public boolean deleteMessagesForUser(String p_strUserId)
      Delete all messages that are addressed to the specified user.
      Parameters:
      p_strUserId - The GUID of the user for whom the messages should be deleted.
      Returns:
      true if the the messages could be deleted, false otherwise.
      Throws:
      IllegalArgumentException - If the given user ID is not a GUID.
    • sort

      public void sort(IOrder p_order)
      Sort the messages in the filtered messages collection.
      Parameters:
      p_order - The sorting criterion.
    • filter

      public int filter(IFilter p_filter)
      Filter the messages that have already being loaded.
      Parameters:
      p_filter - The filter criterion.
      Returns:
      The number of messages in the filtered collection, i.e. the value of size().
    • size

      public int size()
      Get the number of messages in the filtered collection.
      Returns:
      The number of messages in the filtered collection.
    • get

      public Message get(int p_iIndex)
      Get the message at the specified index out of the filtered collection.
      Parameters:
      p_iIndex - The index of the message.
      Returns:
      The message with the specified index or null if there are no filtered messages available or an error occurred.
    • getRichSiteSummary

      public void getRichSiteSummary(Writer p_writer, String p_strResourceUrl, String p_strEncodingDecl, int p_iMaxCount)
      Create a Rich Site Summary containing all news for which the anonymous user is a recipient.

      Calling this method does not affect the internal state of this object.

      Parameters:
      p_writer - The stream where to write the data to.
      p_strResourceUrl - The URL for this resource (rdf:about).
      p_strEncodingDecl - The encoding declaration to be used in the XML text declaration.
      p_iMaxCount - The maximum number of news to be contained in the summary. -1 indicates that this count is unlimited.
    • dump

      public String dump()
      Dump this object to a String.

      Note: This method is provided for debugging purposes only.