public Element createEdgeElement(
      Document evtDom, Collaboration collaboration, int src, int tar, int index) {

    Element edge = evtDom.createElement("edge");
    edge.setAttribute("id", "e" + Integer.toString(index));
    edge.setAttribute("source", Integer.toString(src));
    edge.setAttribute("target", Integer.toString(tar));

    for (int row = 0; row < edgeAttr.length; row++) {
      Element data = evtDom.createElement("data");
      data.setAttribute("key", edgeAttr[row][0]);

      if (edgeAttr[row][0].equalsIgnoreCase("SourceContributorID"))
        data.setTextContent(Integer.toString(src));
      else if (edgeAttr[row][0].equalsIgnoreCase("TargetContributorID"))
        data.setTextContent(Integer.toString(tar));
      else if (edgeAttr[row][0].equalsIgnoreCase("NumOfCollaboration"))
        data.setTextContent(Integer.toString(collaboration.getCollaborationCount()));
      else if (edgeAttr[row][0].equalsIgnoreCase("FirstDate"))
        data.setTextContent(collaboration.getFirstDate());
      else if (edgeAttr[row][0].equalsIgnoreCase("LastDate"))
        data.setTextContent(collaboration.getLastDate());

      edge.appendChild(data);
    }
    return edge;
  }
Ejemplo n.º 2
0
  /*
   * (non-Javadoc)
   *
   * @see ca.unb.cs.pcsf.db.DBAccessService#updateCollaborationState(ca.unb.cs.pcsf.db.Collaboration,
   * java.lang.String)
   */
  public void updateCollaborationState(Collaboration collaboration, String state) {
    logger.debug(LOGPRE + "updateCollaborationState() start" + LOGPRE);

    logger.info("Updating collaboration <" + collaboration.getName() + "> state to be" + state);
    String domainName = DOMAIN_COLLABORATION;
    String itemName = collaboration.getId();
    List<ReplaceableAttribute> replaceableAttributes = new ArrayList<ReplaceableAttribute>();

    replaceableAttributes.add(
        new ReplaceableAttribute(COLLABORATION_ATTRIBUTE_CURRENT_STATE, state, true));

    sdb.putAttributes(new PutAttributesRequest(domainName, itemName, replaceableAttributes));

    logger.debug(LOGPRE + "updateCollaborationState() end" + LOGPRE);
  }
Ejemplo n.º 3
0
  /*
   * (non-Javadoc)
   *
   * @see ca.unb.cs.pcsf.db.DBAccessService#deleteCollaboration(ca.unb.cs.pcsf.db.Collaboration)
   */
  public void deleteCollaboration(Collaboration collaboration) {
    logger.debug(LOGPRE + "deleteCollaboration() start" + LOGPRE);

    if (isCollaborationExist(collaboration.getName())) {
      logger.info("Deleting participants...");
      List<Participant> participants = collaboration.getParticipants();
      for (Participant p : participants) {
        sdb.deleteAttributes(new DeleteAttributesRequest(DOMAIN_PARTICIPANT, p.getId()));
      }
      sdb.deleteAttributes(
          new DeleteAttributesRequest(DOMAIN_COLLABORATION, collaboration.getId()));

      logger.info("Delete Done!");
      logger.debug(LOGPRE + "deleteCollaboration() end" + LOGPRE);
    }
  }
Ejemplo n.º 4
0
  /*
   * (non-Javadoc)
   *
   * @see ca.unb.cs.pcsf.db.DBAccessService#getCollaborationById(java.lang.String)
   */
  public Collaboration getCollaborationById(String collaborationId) {
    logger.debug(LOGPRE + "getCollaborationById() start" + LOGPRE);

    Collaboration collaboration = new Collaboration();
    String selectRequest = "select * from `" + DOMAIN_COLLABORATION + "`";
    List<Item> items = this.getDataFromDomain(selectRequest);
    Item findItem = new Item();

    if (!items.isEmpty()) {
      for (Item item : items) {
        if (item.getName().equals(collaborationId)) {
          findItem = item;
          break;
        }
      }
    }

    if (findItem != null) {
      List<String> participantNames = new ArrayList<String>();
      List<Participant> participants = new ArrayList<Participant>();

      collaboration.setId(findItem.getName());
      for (Attribute attribute : findItem.getAttributes()) {
        if (attribute.getName().equals(COLLABORATION_ATTRIBUTE_NAME))
          collaboration.setName(attribute.getValue());
        if (attribute.getName().equals(COLLABORATION_ATTRIBUTE_CREATOR_ID))
          collaboration.setCreatorId(attribute.getValue());
        if (attribute.getName().equals(COLLABORATION_ATTRIBUTE_CURRENT_STATE))
          collaboration.setCurrentState(attribute.getValue());
        if (attribute.getName().equals(COLLABORATION_ATTRIBUTE_PARTICIPANT))
          participantNames.add(attribute.getValue());
        if (attribute.getName().equals(COLLABORATION_ATTRIBUTE_WORKFLOW_MODEL))
          collaboration.setWorkflowModel(attribute.getValue());
        if (attribute.getName().equals(COLLABORATION_ATTRIBUTE_PROCESS_DEFINITION_ID))
          collaboration.setProcessDefId(attribute.getValue());
      }

      for (String s : participantNames) {
        Participant p = this.getParticipantByNameAndCollaborationId(s, findItem.getName());
        participants.add(p);
      }

      collaboration.setParticipants(participants);
    }

    logger.debug(LOGPRE + "getCollaborationById() end" + LOGPRE);
    return collaboration;
  }
Ejemplo n.º 5
0
  /*
   * (non-Javadoc)
   *
   * @see ca.unb.cs.pcsf.db.DBAccessService#getCollaborationsByCreatorId(java.lang.String)
   */
  public List<Collaboration> getCollaborationsByCreatorId(String creatorId) {
    logger.debug(LOGPRE + "getCollaborationsByCreatorId() start" + LOGPRE);

    List<Collaboration> collaborations = new ArrayList<Collaboration>();
    String selectExpression =
        "select * from `"
            + DOMAIN_COLLABORATION
            + "` where "
            + COLLABORATION_ATTRIBUTE_CREATOR_ID
            + "='"
            + creatorId
            + "'";
    List<Item> items = this.getDataFromDomain(selectExpression);

    if (!items.isEmpty()) {
      for (Item item : items) {
        Collaboration collaboration = new Collaboration();
        List<String> users = new ArrayList<String>();
        List<Participant> participants = new ArrayList<Participant>();
        collaboration.setId(item.getName());
        for (Attribute attribute : item.getAttributes()) {
          if (attribute.getName().equals(COLLABORATION_ATTRIBUTE_NAME))
            collaboration.setName(attribute.getValue());
          if (attribute.getName().equals(COLLABORATION_ATTRIBUTE_CREATOR_ID))
            collaboration.setCreatorId(attribute.getValue());
          if (attribute.getName().equals(COLLABORATION_ATTRIBUTE_CURRENT_STATE))
            collaboration.setCurrentState(attribute.getValue());
          if (attribute.getName().equals(COLLABORATION_ATTRIBUTE_PARTICIPANT))
            users.add(attribute.getValue());
          if (attribute.getName().equals(COLLABORATION_ATTRIBUTE_WORKFLOW_MODEL))
            collaboration.setWorkflowModel(attribute.getValue());
        }

        for (String user : users) {
          Participant p = this.getParticipantByNameAndCollaborationId(user, collaboration.getId());
          participants.add(p);
        }

        collaboration.setParticipants(participants);
        collaborations.add(collaboration);
      }
    }

    logger.debug(LOGPRE + "getCollaborationsByCreatorId() end" + LOGPRE);
    return collaborations;
  }
Ejemplo n.º 6
0
  /*
   * (non-Javadoc)
   *
   * @see ca.unb.cs.pcsf.db.DBAccessService#update(java.lang.Object)
   */
  public void update(Object o) {
    logger.debug(LOGPRE + "update() start" + LOGPRE);

    if (o instanceof Collaboration) {
      Collaboration collaboration = (Collaboration) o;
      logger.info("Updating Collaboration <" + collaboration.getName() + ">...");

      String domainName = DOMAIN_COLLABORATION;
      String itemName = collaboration.getId();
      List<ReplaceableAttribute> replaceableAttributes = new ArrayList<ReplaceableAttribute>();

      replaceableAttributes.add(
          new ReplaceableAttribute(COLLABORATION_ATTRIBUTE_NAME, collaboration.getName(), true));
      for (Participant s : collaboration.getParticipants())
        replaceableAttributes.add(
            new ReplaceableAttribute(COLLABORATION_ATTRIBUTE_PARTICIPANT, s.getName(), true));

      sdb.putAttributes(new PutAttributesRequest(domainName, itemName, replaceableAttributes));
    }

    if (o instanceof Participant) {
      Participant participant = (Participant) o;
      logger.info("Updating participant <" + participant.getName() + ">...");

      String domainName = DOMAIN_PARTICIPANT;
      String itemName = participant.getId();
      List<ReplaceableAttribute> replaceableAttributes = new ArrayList<ReplaceableAttribute>();

      replaceableAttributes.add(
          new ReplaceableAttribute(PARTICIPANT_ATTRIBUTE_IS_REG, participant.getIsReg(), true));

      sdb.putAttributes(new PutAttributesRequest(domainName, itemName, replaceableAttributes));
    }

    logger.debug(LOGPRE + "update() end" + LOGPRE);
  }
Ejemplo n.º 7
0
  /*
   * (non-Javadoc)
   *
   * @see ca.unb.cs.pcsf.db.PcsfSimpleDBAccess#getCollaborationByName(java.lang.String)
   */
  @Override
  public Collaboration getCollaborationByName(String collaborationName) {
    logger.debug(LOGPRE + "getCollaborationByName() start" + LOGPRE);

    Collaboration collaboration = new Collaboration();
    String selectExpression =
        "select * from `"
            + DOMAIN_COLLABORATION
            + "` where "
            + COLLABORATION_ATTRIBUTE_NAME
            + "='"
            + collaborationName
            + "'";
    Item findItem = this.getDataFromDomain(selectExpression).get(0);

    List<String> participantNames = new ArrayList<String>();
    List<Participant> participants = new ArrayList<Participant>();

    collaboration.setId(findItem.getName());
    for (Attribute attribute : findItem.getAttributes()) {
      if (attribute.getName().equals(COLLABORATION_ATTRIBUTE_NAME))
        collaboration.setName(attribute.getValue());
      if (attribute.getName().equals(COLLABORATION_ATTRIBUTE_CREATOR_ID))
        collaboration.setCreatorId(attribute.getValue());
      if (attribute.getName().equals(COLLABORATION_ATTRIBUTE_CURRENT_STATE))
        collaboration.setCurrentState(attribute.getValue());
      if (attribute.getName().equals(COLLABORATION_ATTRIBUTE_PARTICIPANT))
        participantNames.add(attribute.getValue());
      if (attribute.getName().equals(COLLABORATION_ATTRIBUTE_WORKFLOW_MODEL))
        collaboration.setWorkflowModel(attribute.getValue());
    }

    for (String s : participantNames) {
      Participant p = this.getParticipantByNameAndCollaborationId(s, findItem.getName());
      participants.add(p);
    }

    collaboration.setParticipants(participants);

    logger.debug(LOGPRE + "getCollaborationByName() end" + LOGPRE);
    return collaboration;
  }
  @SuppressWarnings("unchecked")
  public Document toGraphMLDOM_org(Document egoDom, String id, int radius, String graphType) {

    Collaborator collaborator = null;

    if (db.connect() == false) {
      throw new RuntimeException("Unable to connect to the database");
    }

    // add the graph element
    Element rootElement = egoDom.getDocumentElement();
    rootElement = createHeaderElements(egoDom, rootElement, graphType);

    Element graph = egoDom.createElement("graph");
    graph.setAttribute("id", "Contributor Network for organisation:" + " ( " + id + " )");
    graph.setAttribute("edgedefault", graphType);
    rootElement.appendChild(graph);

    network = getRawCollaboratorData_org(id, radius);

    if (network != null) {
      // add some additional required information for contributors
      collaborators = getCollaborators(network, "0");

      // get collaboration List
      collaborations = getCollaborations_org(id, network);
    } else return egoDom;

    // create node element in DOM
    for (int i = 0; i < collaborators.size(); i++) {
      Element node = createNodeElement(egoDom, i);
      graph.appendChild(node);
    }

    // we have a list of collaborations.
    // loop through the list, for each - create a collaboration
    //								  - create edge.

    // 1.iterate through the collaboration hashmap
    Iterator contributorIter = collaborations.values().iterator();
    int edgeIndex = 0;
    // collabCheck used to ensure no doubling up of collaborations. (pretty quick hack, ideally this
    // issue would be sorted before this point)
    Vector collabCheck = new Vector();

    while (contributorIter.hasNext()) {
      CollaborationList list = (CollaborationList) contributorIter.next();
      // get the actual collaborations
      if (list != null) {

        Iterator collaborationIter = list.getCollaborations().values().iterator();
        //	loop through the hashmap of collaborations
        while (collaborationIter.hasNext()) {

          Collaboration collaboration = (Collaboration) collaborationIter.next();

          if (!collabCheck.contains(
              collaboration.getPartner() + "-" + collaboration.getCollaborator())) {
            // create an edge for each of them
            Element edge =
                createEdgeElement(
                    egoDom,
                    collaboration,
                    Integer.parseInt(collaboration.getCollaborator()),
                    Integer.parseInt(collaboration.getPartner()),
                    edgeIndex);
            graph.appendChild(edge);
            //	add the collaboration to the list for checking.
            collabCheck.add(collaboration.getCollaborator() + "-" + collaboration.getPartner());
            edgeIndex++;
          }
        }
      }
    }

    return egoDom;
  }
Ejemplo n.º 9
0
  /*
   * (non-Javadoc)
   *
   * @see ca.unb.cs.pcsf.db.DBAccessService#putDataIntoDomain(java.lang.Object)
   */
  public void putDataIntoDomain(Object object) {
    logger.debug(LOGPRE + "putDataIntoDomain() start" + LOGPRE);

    if (object instanceof Participant) {
      Participant participant = (Participant) object;
      List<ReplaceableItem> items = new ArrayList<ReplaceableItem>();
      items.add(
          new ReplaceableItem(participant.getId())
              .withAttributes(
                  new ReplaceableAttribute(PARTICIPANT_ATTRIBUTE_NAME, participant.getName(), true),
                  new ReplaceableAttribute(
                      PARTICIPANT_ATTRIBUTE_EMAIL, participant.getEmail(), true),
                  new ReplaceableAttribute(
                      PARTICIPANT_ATTRIBUTE_COLLABORATION_ID,
                      participant.getCollaborationId(),
                      false),
                  new ReplaceableAttribute(
                      PARTICIPANT_ATTRIBUTE_IS_REG, participant.getIsReg(), true)));

      logger.info("Putting participant <" + participant.getName() + "> into domain...");
      sdb.batchPutAttributes(new BatchPutAttributesRequest(DOMAIN_PARTICIPANT, items));
    }

    if (object instanceof Creator) {
      Creator creator = (Creator) object;
      if (!isCreatorExist(creator.getName())) {
        List<ReplaceableItem> items = new ArrayList<ReplaceableItem>();
        items.add(
            new ReplaceableItem(creator.getId())
                .withAttributes(
                    new ReplaceableAttribute(CREATOR_ATTRIBUTE_NAME, creator.getName(), true),
                    new ReplaceableAttribute(
                        CREATOR_ATTRIBUTE_PASSWORD, creator.getPassword(), true),
                    new ReplaceableAttribute(CREATOR_ATTRIBUTE_EMAIL, creator.getEmail(), true)));

        logger.info("Putting creator <" + creator.getName() + "> into domain...");
        sdb.batchPutAttributes(new BatchPutAttributesRequest(DOMAIN_CREATOR, items));
      }
    }

    if (object instanceof Collaboration) {
      Collaboration collaboration = (Collaboration) object;

      if (!isCollaborationExist(collaboration.getName())) {
        List<ReplaceableItem> items = new ArrayList<ReplaceableItem>();
        ReplaceableItem item = new ReplaceableItem(collaboration.getId());
        item.withAttributes(
            new ReplaceableAttribute(COLLABORATION_ATTRIBUTE_NAME, collaboration.getName(), true),
            new ReplaceableAttribute(
                COLLABORATION_ATTRIBUTE_CREATOR_ID, collaboration.getCreatorId(), true),
            new ReplaceableAttribute(
                COLLABORATION_ATTRIBUTE_CURRENT_STATE, collaboration.getCurrentState(), true),
            new ReplaceableAttribute(
                COLLABORATION_ATTRIBUTE_WORKFLOW_MODEL, collaboration.getWorkflowModel(), true));

        List<Participant> participants = collaboration.getParticipants();
        for (Participant participant : participants)
          item.withAttributes(
              new ReplaceableAttribute(
                  COLLABORATION_ATTRIBUTE_PARTICIPANT, participant.getName(), true));

        items.add(item);

        logger.info("Putting collaboration <" + collaboration.getName() + "> into domain...");
        sdb.batchPutAttributes(new BatchPutAttributesRequest(DOMAIN_COLLABORATION, items));
      }
    }

    logger.debug(LOGPRE + "putDataIntoDomain() end" + LOGPRE);
  }