예제 #1
0
  public static ClientUser buildUserFromProfile(NativeDocument profile, String username) {
    NativeElement root = profile.getDocumentElement();
    ClientUser currentUser = new ClientUser();
    currentUser.setUsername(username);

    // backwards compatibility for the moment...
    if (root.getElementsByTagName("creds").getLength() != 0) {
      Debug.println("Profile detected Old version...");
      currentUser.setFirstName(root.getElementByTagName("first").getTextContent());
      currentUser.setLastName(root.getElementByTagName("last").getTextContent());
      currentUser.setAffiliation(root.getElementByTagName("affiliation").getTextContent());
    } else {
      Debug.println("Profile detected New shiny version!");
      NativeNodeList nodes = root.getChildNodes();
      for (int i = 0; i < nodes.getLength(); i++) {
        NativeNode curNode = nodes.item(i);
        if (curNode.getNodeType() != NativeNode.ELEMENT_NODE) continue;
        String name = curNode.getNodeName();
        if (name.equals(NewAccountPanel.EMAIL_KEY)) currentUser.setEmail(curNode.getTextContent());
        else if (name.equals(NewAccountPanel.FIRSTNAME_KEY))
          currentUser.setFirstName(curNode.getTextContent());
        else if (name.equals(NewAccountPanel.LASTNAME_KEY))
          currentUser.setLastName(curNode.getTextContent());
        else if (name.equals(NewAccountPanel.AFFILIATION_KEY))
          currentUser.setAffiliation(curNode.getTextContent());
        else currentUser.setProperty(name, curNode.getTextContent());
      }
      if (root.getElementByTagName("quickGroup") == null)
        currentUser.setProperty("quickGroup", "rlu");
    }

    return currentUser;
  }
예제 #2
0
  public void fillTable() {
    table.removeAll();
    String fetchList = "";
    for (int i = start; i < start + NUMBER_OF_RESULTS && i < currentResults.getLength(); i++)
      fetchList += ((NativeElement) currentResults.item(i)).getAttribute("id") + ",";

    if (fetchList.length() > 0)
      TaxonomyCache.impl.fetchList(
          fetchList,
          new GenericCallback<String>() {
            public void onFailure(Throwable arg0) {
              WindowUtils.hideLoadingAlert();
              WindowUtils.errorAlert("Error loading results. Inconsistency in index table.");
            }

            public void onSuccess(String arg0) {
              List<String> assessmentList = new ArrayList<String>();
              final String[][] x = new String[20][7];
              for (int i = start;
                  i < start + NUMBER_OF_RESULTS && i < currentResults.getLength();
                  i++) {
                TaxonNode currentNode =
                    TaxonomyCache.impl.getNode(
                        ((NativeElement) currentResults.item(i)).getAttribute("id"));

                x[i - start][0] = currentNode.getFullName();
                if (currentNode.getCommonNames().size() > 0)
                  x[i - start][1] = (currentNode.getCommonNames().get(0)).getName().toLowerCase();
                else x[i - start][1] = "";
                x[i - start][2] = TaxonNode.getDisplayableLevel(currentNode.getLevel());
                x[i - start][4] = String.valueOf(currentNode.getId());
                if (currentNode.getAssessments().size() > 0) {
                  x[i - start][3] = String.valueOf(currentNode.getAssessments().get(0));
                  assessmentList.add(
                      currentNode.getAssessments().get(0)
                          + "_"
                          + BaseAssessment.PUBLISHED_ASSESSMENT_STATUS);
                } else x[i - start][3] = "N/A";
                if (currentNode.getFootprint().length >= 5)
                  x[i - start][5] = currentNode.getFootprint()[4];
                else x[i - start][5] = "N/A";
                if (currentNode.getFootprint().length >= 6)
                  x[i - start][6] = currentNode.getFootprint()[5];
                else x[i - start][5] = "N/A";
              }

              AssessmentCache.impl.fetchAssessments(
                  new AssessmentFetchRequest(assessmentList, null),
                  new GenericCallback<String>() {
                    public void onFailure(Throwable caught) {
                      for (int i = start;
                          i < start + NUMBER_OF_RESULTS && i < currentResults.getLength();
                          i++) {
                        x[i - start][3] = "N/A";
                        TableItem tItem = new TableItem(x[i - start]);
                        table.add(tItem);
                      }
                      // x[i-start][3] = "N/A";
                      // SysDebugger.getInstance().println("FAILURES!");
                      SysDebugger.getInstance().println(caught.getMessage());

                      layout();
                    }

                    public void onSuccess(String result) {
                      for (int i = start;
                          i < start + NUMBER_OF_RESULTS && i < currentResults.getLength();
                          i++) {
                        AssessmentData aData =
                            AssessmentCache.impl.getPublishedAssessment(x[i - start][3], false);
                        if (aData == null) x[i - start][3] = "N/A";
                        else x[i - start][3] = aData.getProperCategoryAbbreviation();
                        TableItem tItem = new TableItem(x[i - start]);
                        table.add(tItem);
                      }

                      layout();
                    }
                  });
            }
          });
  }
  /**
   * Assumes that: - Users have already been converted - Working Sets have already been converted -
   * Working Set IDs have remained the same.
   */
  protected void run() throws Exception {
    userIO = new UserIO(session);
    relationshipIO = new RelationshipIO(session);
    taxonIO = new TaxonIO(session);

    if (isTestMode()) print("### RUNNING IN TEST MODE ###");

    final WorkingSetIO wsIO = new WorkingSetIO(session);

    for (VFSPathToken token : data.getOldVFS().list(new VFSPath("/users"))) {
      final User user = userIO.getUserFromUsername(token.toString());
      if (user == null) printf("## No user exists for data directory %s ==", token);
      else {
        Hibernate.initialize(user.getSubscribedWorkingSets());

        final VFSPath workingSetPath =
            new VFSPath("/users/" + user.getUsername() + "/workingSet.xml");
        final NativeDocument document = new JavaNativeDocument();
        try {
          document.parse(data.getOldVFS().getString(workingSetPath));
        } catch (Exception e) {
          continue;
        }

        printf("== Finding working sets for %s (%s) ==", user.getUsername(), user.getId());

        final NativeNodeList nodes = document.getDocumentElement().getChildNodes();
        for (int i = 0; i < nodes.getLength(); i++) {
          NativeNode node = nodes.item(i);
          if ("public".equals(node.getNodeName())) {
            NativeNodeList children = node.getChildNodes();
            for (int k = 0; k < children.getLength(); k++) {
              NativeNode child = children.item(k);
              if ("workingSet".equals(child.getNodeName())) {
                NativeElement el = (NativeElement) child;
                String id = el.getAttribute("id");
                String creator = el.getAttribute("creator");

                if (!user.getUsername().equals(creator)) {
                  boolean success = wsIO.subscribeToWorkingSet(Integer.valueOf(id), user);
                  if (!success) printf("# Failed to subscribe to ws %s", id);
                  else {
                    printf("Subscribed to ws %s", id);
                    /*if (count.incrementAndGet() % 50 == 0) {
                    	printf("Converted %s working set subscriptions...", count.get());
                    	commitAndStartTransaction();
                    }*/
                  }
                }
              }
            }
          } else if ("private".equals(node.getNodeName())) {
            NativeNodeList children = node.getChildNodes();
            for (int k = 0; k < children.getLength(); k++) {
              NativeNode child = children.item(k);
              if ("workingSet".equals(child.getNodeName())) {
                WorkingSetData data =
                    new WorkingSetParser().parseSingleWorkingSet((NativeElement) node);
                if ("".equals(data.getId())) {
                  continue;
                }
                WorkingSet privateWS =
                    WorkingSetConverter.convertWorkingSetData(
                        data, session, relationshipIO, userIO, taxonIO, user);
                if (privateWS != null) {
                  printf("Created private working set %s", privateWS.getName());
                  session.save(privateWS);
                }
              }
            }
          }
        }
      }
      commitAndStartTransaction();
    }

    // commitAndStartTransaction();
  }