Package org.onesocialweb.openfire.exception

Examples of org.onesocialweb.openfire.exception.InvalidRelationException


   */
  public void setupRelation(String userJID, PersistentRelation relation) throws InvalidRelationException {
    // Validate the relation request
    // TODO More should be validated here
    if (!relation.hasFrom() || !relation.hasTo() || !relation.hasNature()) {
      throw new InvalidRelationException("Relation is missing required elements");
    }

    // Verify that the from or to is the user making the request
    if (!(relation.getFrom().equals(userJID) || relation.getTo().equals(userJID))) {
      throw new InvalidRelationException("Must be part of the relation to create it");
    }

    // Assign a unique ID to this new relation
    relation.setId(DefaultAtomHelper.generateId());

View Full Code Here


  @SuppressWarnings("unchecked")
  public void updateRelation(String userJID, PersistentRelation relation) throws InvalidRelationException {
    // Validate the relation request
    // TODO More should be validated here
    if (!relation.hasId() || !relation.hasStatus()) {
      throw new InvalidRelationException("Relation is missing required elements");
    }

    // Search for an existing relation with the given ID
    final EntityManager em = OswPlugin.getEmFactory().createEntityManager();
    Query query = em.createQuery("SELECT x FROM Relation x WHERE x.owner = ?1 AND x.guid = ?2");
    query.setParameter(1, userJID);
    query.setParameter(2, relation.getId());
    List<PersistentRelation> relations = query.getResultList();

    // If no match, or more than one, we have an issue
    if (relations.size() != 1) {
      throw new InvalidRelationException("Could not find relationship with id " + relation.getId());
    }

    // We update the persisted relation
    em.getTransaction().begin();
    PersistentRelation storedRelation = relations.get(0);
View Full Code Here

   * @throws InvalidRelationException
   */
  public void handleMessage(String remoteJID, String localJID, Relation relation) throws InvalidRelationException {
    // We need at least a status field
    if (!relation.hasStatus()) {
      throw new InvalidRelationException("Relation is missing a status field");
    }

    // Is this a new request ?
    if (relation.getStatus().equals(Relation.Status.REQUEST)) {
      handleRequestMessage(remoteJID, localJID, relation);
View Full Code Here

  @SuppressWarnings("unchecked")
  private void handleRequestMessage(String remoteJID, String localJID, Relation relation) throws InvalidRelationException {
    // Are required fields for a new relation setup present ?
    if (!relation.hasNature() || !relation.hasStatus() || !relation.hasFrom() || !relation.hasTo() || !relation.hasId()) {
      throw new InvalidRelationException("Relation is missing required elements");
    }

    // The relation should be between the sender and the receiver
    if (getDirection(relation, remoteJID, localJID) == 0) {
      throw new InvalidRelationException("Relation from/to do not match message from/to");
    }

    // Cannot add a relation to yourself
    if (relation.getFrom().equals(relation.getTo())) {
      throw new InvalidRelationException("Cannot add relation to yourself");
    }

    // Verify that this relation is not already here
    final EntityManager em = OswPlugin.getEmFactory().createEntityManager();
    Query query = em.createQuery("SELECT x FROM Relation x WHERE x.owner = ?1 AND x.guid = ?2");
    query.setParameter(1, localJID);
    query.setParameter(2, relation.getId());
    List<PersistentRelation> relations = query.getResultList();

    // If there is a match, we give up
    // TODO Not that fast. The other end may jut have not received any
    // answer and wants to try again
    // we should deal with all these recovery features.
    if (relations.size() > 0) {
      throw new InvalidRelationException("This relation has already been requested");
    }

    // Save the relation
    PersistentRelation persistentRelation = (PersistentRelation) relation;
    persistentRelation.setOwner(localJID);
View Full Code Here

    query.setParameter(2, relation.getId());
    List<PersistentRelation> relations = query.getResultList();

    // If no match, or more than one, we have an issue
    if (relations.size() != 1) {
      throw new InvalidRelationException("Could not find matching relationship");
    }

    // We update the persisted relation
    em.getTransaction().begin();
    PersistentRelation previous = relations.get(0);
View Full Code Here

TOP

Related Classes of org.onesocialweb.openfire.exception.InvalidRelationException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.